{"version":3,"sources":["jsdelivr-header.js","/npm/@payloadcms/plugin-stripe@3.81.0/src/index.ts"],"names":[],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA,OCFS,cAAiB,+BACjB,sBAAyB,sCACzB,qBAAwB,qCACxB,2BAA8B,2CAC9B,eAAkB,0BAClB,mBAAsB,8BAEtB,gBAAmB,oCAErB,MAAM,aACV,GACA,IACC,MAAM,YAAE,GAAgB,EAGlB,EAA4C,IAC7C,EACH,KAAM,GAAsB,OAAQ,EACpC,KAAM,GAAsB,MAAQ,IAOhC,EAAwB,IACxB,GAAQ,WAAa,GACzB,CACE,QAAS,MAAO,SACI,eAAe,CAC/B,SACA,eACA,QAKJ,OAAQ,OACR,KAAM,qBAIN,GAAsB,MACxB,EAAU,KAAK,CACb,QAAS,MAAO,SACI,WAAW,CAC3B,eACA,QAKJ,OAAQ,OACR,KAAM,iBAIV,IAAK,MAAM,KAAc,EAAc,CACrC,MAAQ,MAAO,GAAkB,EAE3B,EAAa,EAAa,MAAM,MAAM,GAAS,EAAK,aAAe,EAAW,OAEpF,IAAK,EACH,SAEF,MAAM,EAAS,UAAU,CACvB,aACA,eACA,eAEF,EAAW,OAAS,EAEf,EAAW,QACd,EAAW,MAAQ,CAAC,GAGtB,EAAW,MAAM,YAAc,IACzB,GAAe,aAAe,GACjC,GACC,iBAAiB,IACZ,EACH,aACA,kBAGN,EAAW,MAAM,aAAe,IAC1B,GAAe,cAAgB,GAClC,GACC,uBAAuB,IAClB,EACH,aACA,kBAGN,EAAW,MAAM,eAAiB,IAC5B,GAAe,gBAAkB,GACpC,GACC,kBAAkB,IACb,EACH,aACA,iBAGR,CAIA,OAFA,EAAO,UAAY,EAEZ","file":"/npm/@payloadcms/plugin-stripe@3.81.0/dist/index.js","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.39.0.\n * Original file: /npm/@payloadcms/plugin-stripe@3.81.0/dist/index.js\n *\n * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files\n */\n","import type { Config, Endpoint } from 'payload'\n\nimport type { SanitizedStripePluginConfig, StripePluginConfig } from './types.js'\n\nimport { getFields } from './fields/getFields.js'\nimport { createNewInStripe } from './hooks/createNewInStripe.js'\nimport { deleteFromStripe } from './hooks/deleteFromStripe.js'\nimport { syncExistingWithStripe } from './hooks/syncExistingWithStripe.js'\nimport { stripeREST } from './routes/rest.js'\nimport { stripeWebhooks } from './routes/webhooks.js'\n\nexport { stripeProxy } from './utilities/stripeProxy.js'\n\nexport const stripePlugin =\n  (incomingStripeConfig: StripePluginConfig) =>\n  (config: Config): Config => {\n    const { collections } = config\n\n    // set config defaults here\n    const pluginConfig: SanitizedStripePluginConfig = {\n      ...incomingStripeConfig,\n      rest: incomingStripeConfig?.rest ?? false,\n      sync: incomingStripeConfig?.sync || [],\n    }\n\n    // NOTE: env variables are never passed to the client, but we need to know if `stripeSecretKey` is a test key\n    // unfortunately we must set the 'isTestKey' property on the config instead of using the following code:\n    // const isTestKey = stripeConfig.stripeSecretKey?.startsWith('sk_test_');\n\n    const endpoints: Endpoint[] = [\n      ...(config?.endpoints || []),\n      {\n        handler: async (req) => {\n          const res = await stripeWebhooks({\n            config,\n            pluginConfig,\n            req,\n          })\n\n          return res\n        },\n        method: 'post',\n        path: '/stripe/webhooks',\n      },\n    ]\n\n    if (incomingStripeConfig?.rest) {\n      endpoints.push({\n        handler: async (req) => {\n          const res = await stripeREST({\n            pluginConfig,\n            req,\n          })\n\n          return res\n        },\n        method: 'post' as Endpoint['method'],\n        path: '/stripe/rest',\n      })\n    }\n\n    for (const collection of collections!) {\n      const { hooks: existingHooks } = collection\n\n      const syncConfig = pluginConfig.sync?.find((sync) => sync.collection === collection.slug)\n\n      if (!syncConfig) {\n        continue\n      }\n      const fields = getFields({\n        collection,\n        pluginConfig,\n        syncConfig,\n      })\n      collection.fields = fields\n\n      if (!collection.hooks) {\n        collection.hooks = {}\n      }\n\n      collection.hooks.afterDelete = [\n        ...(existingHooks?.afterDelete || []),\n        (args) =>\n          deleteFromStripe({\n            ...args,\n            collection,\n            pluginConfig,\n          }),\n      ]\n      collection.hooks.beforeChange = [\n        ...(existingHooks?.beforeChange || []),\n        (args) =>\n          syncExistingWithStripe({\n            ...args,\n            collection,\n            pluginConfig,\n          }),\n      ]\n      collection.hooks.beforeValidate = [\n        ...(existingHooks?.beforeValidate || []),\n        (args) =>\n          createNewInStripe({\n            ...args,\n            collection,\n            pluginConfig,\n          }),\n      ]\n    }\n\n    config.endpoints = endpoints\n\n    return config\n  }\n"]}