UNPKG

@shopify/shopify-app-express

Version:

Shopify Express Middleware - to simplify the building of Shopify Apps with Express

1 lines 2.41 kB
{"version":3,"file":"index.mjs","sources":["../../../../src/webhooks/index.ts"],"sourcesContent":["import express, {Request, Response} from 'express';\nimport {AddHandlersParams, DeliveryMethod, Shopify} from '@shopify/shopify-api';\n\nimport {AppConfigInterface} from '../config-types';\nimport {ApiAndConfigParams} from '../types';\nimport {AppInstallations} from '../app-installations';\nimport {deleteAppInstallationHandler} from '../middlewares';\n\nimport {\n ProcessWebhooksMiddleware,\n ProcessWebhooksMiddlewareParams,\n WebhookHandlersParam,\n} from './types';\nimport {process} from './process';\n\nexport function processWebhooks({\n api,\n config,\n}: ApiAndConfigParams): ProcessWebhooksMiddleware {\n return function ({webhookHandlers}: ProcessWebhooksMiddlewareParams) {\n mountWebhooks(api, config, webhookHandlers);\n\n return [\n express.text({type: '*/*', limit: '500kb'}),\n async (req: Request, res: Response) => {\n await process({\n req,\n res,\n api,\n config,\n });\n },\n ];\n };\n}\n\nfunction mountWebhooks(\n api: Shopify,\n config: AppConfigInterface,\n handlers: WebhookHandlersParam,\n) {\n api.webhooks.addHandlers(handlers as AddHandlersParams);\n\n // Add our custom app uninstalled webhook\n const appInstallations = new AppInstallations(config);\n\n api.webhooks.addHandlers({\n APP_UNINSTALLED: {\n deliveryMethod: DeliveryMethod.Http,\n callbackUrl: config.webhooks.path,\n callback: deleteAppInstallationHandler(appInstallations, config),\n },\n });\n}\n"],"names":[],"mappings":";;;;;;SAegB,eAAe,CAAC,EAC9B,GAAG,EACH,MAAM,GACa,EAAA;IACnB,OAAO,UAAU,EAAC,eAAe,EAAkC,EAAA;AACjE,QAAA,aAAa,CAAC,GAAG,EAAE,MAAM,EAAE,eAAe,CAAC;QAE3C,OAAO;AACL,YAAA,OAAO,CAAC,IAAI,CAAC,EAAC,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE,OAAO,EAAC,CAAC;AAC3C,YAAA,OAAO,GAAY,EAAE,GAAa,KAAI;AACpC,gBAAA,MAAM,OAAO,CAAC;oBACZ,GAAG;oBACH,GAAG;oBACH,GAAG;oBACH,MAAM;AACP,iBAAA,CAAC;YACJ,CAAC;SACF;AACH,IAAA,CAAC;AACH;AAEA,SAAS,aAAa,CACpB,GAAY,EACZ,MAA0B,EAC1B,QAA8B,EAAA;AAE9B,IAAA,GAAG,CAAC,QAAQ,CAAC,WAAW,CAAC,QAA6B,CAAC;;AAGvD,IAAA,MAAM,gBAAgB,GAAG,IAAI,gBAAgB,CAAC,MAAM,CAAC;AAErD,IAAA,GAAG,CAAC,QAAQ,CAAC,WAAW,CAAC;AACvB,QAAA,eAAe,EAAE;YACf,cAAc,EAAE,cAAc,CAAC,IAAI;AACnC,YAAA,WAAW,EAAE,MAAM,CAAC,QAAQ,CAAC,IAAI;AACjC,YAAA,QAAQ,EAAE,4BAA4B,CAAC,gBAAgB,EAAE,MAAM,CAAC;AACjE,SAAA;AACF,KAAA,CAAC;AACJ;;;;"}