"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getWebhookBundle = void 0;
const extensions_core_1 = require("@awell-health/extensions-core");
const errorHandler_1 = require("../../shared/errorHandler");
const fields_1 = require("./fields");
const validation_1 = require("./validation");
const dataPoints_1 = require("./dataPoints");
const fetchBundle_1 = require("./fetchBundle");
exports.getWebhookBundle = {
    key: 'getWebhookBundle',
    category: extensions_core_1.Category.EHR_INTEGRATIONS,
    title: 'Get Webhook Bundle',
    description: 'Fetches the FHIR bundle from a Metriport webhook payload URL (e.g. the Encounter Bundle from an ADT notification, or a discharge summary). The URL is provided by the enrollment webhook on the `bundleUrl` data point and is only valid for 10 minutes.',
    fields: fields_1.fields,
    previewable: true,
    supports_automated_retries: true,
    dataPoints: dataPoints_1.dataPoints,
    onActivityCreated: async (payload, onComplete, onError) => {
        try {
            const { url } = validation_1.getWebhookBundleSchema.parse(payload.fields);
            const bundle = await (0, fetchBundle_1.fetchBundle)(url);
            await onComplete({
                data_points: {
                    bundle: JSON.stringify(bundle),
                },
            });
        }
        catch (err) {
            await (0, errorHandler_1.handleErrorMessage)(err, onError);
        }
    },
};
//# sourceMappingURL=getWebhookBundle.js.map