@payloadcms/plugin-stripe 3.38.0-internal.78d3ba4 → 3.38.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -31,7 +31,7 @@ export const createNewInStripe = async (args)=>{
31
31
  }, {});
32
32
  syncedFields = deepen(syncedFields);
33
33
  // api version can only be the latest, stripe recommends ts ignoring it
34
- const stripe = new Stripe(pluginConfig.stripeSecretKey || '', {
34
+ const stripe = new Stripe(pluginConfig?.stripeSecretKey || '', {
35
35
  apiVersion: '2022-08-01'
36
36
  });
37
37
  if (operation === 'update') {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/hooks/createNewInStripe.ts"],"sourcesContent":["import type { CollectionBeforeValidateHook, CollectionConfig } from 'payload'\n\nimport { APIError } from 'payload'\nimport Stripe from 'stripe'\n\nimport type { StripePluginConfig } from '../types.js'\n\nimport { deepen } from '../utilities/deepen.js'\n\ntype HookArgsWithCustomCollection = {\n collection: CollectionConfig\n} & Omit<Parameters<CollectionBeforeValidateHook>[0], 'collection'>\n\nexport type CollectionBeforeValidateHookWithArgs = (\n args: {\n collection?: CollectionConfig\n pluginConfig?: StripePluginConfig\n } & HookArgsWithCustomCollection,\n) => Promise<Partial<any>>\n\nexport const createNewInStripe: CollectionBeforeValidateHookWithArgs = async (args) => {\n const { collection, data, operation, pluginConfig, req } = args\n\n const { logs, sync } = pluginConfig || {}\n\n const payload = req?.payload\n\n const dataRef = data || {}\n\n if (process.env.NODE_ENV === 'test') {\n dataRef.stripeID = 'test'\n return dataRef\n }\n\n if (payload) {\n if (data?.skipSync) {\n if (logs) {\n payload.logger.info(`Bypassing collection-level hooks.`)\n }\n } else {\n // initialize as 'false' so that all Payload admin events sync to Stripe\n // then conditionally set to 'true' to for events that originate from webhooks\n // this will prevent webhook events from triggering an unnecessary sync / infinite loop\n dataRef.skipSync = false\n\n const { slug: collectionSlug } = collection || {}\n const syncConfig = sync?.find((conf) => conf.collection === collectionSlug)\n\n if (syncConfig) {\n // combine all fields of this object and match their respective values within the document\n let syncedFields = syncConfig.fields.reduce(\n (acc, field) => {\n const { fieldPath, stripeProperty } = field\n\n acc[stripeProperty] = dataRef[fieldPath]\n return acc\n },\n {} as Record<string, any>,\n )\n\n syncedFields = deepen(syncedFields)\n\n // api version can only be the latest, stripe recommends ts ignoring it\n const stripe = new Stripe(pluginConfig.stripeSecretKey || '', { apiVersion: '2022-08-01' })\n\n if (operation === 'update') {\n if (logs) {\n payload.logger.info(\n `A '${collectionSlug}' document has changed in Payload with ID: '${data?.id}', syncing with Stripe...`,\n )\n }\n\n // NOTE: the Stripe document will be created in the \"afterChange\" hook, so create a new stripe document here if no stripeID exists\n if (!dataRef.stripeID) {\n try {\n // NOTE: Typed as \"any\" because the \"create\" method is not standard across all Stripe resources\n const stripeResource = await stripe?.[syncConfig.stripeResourceType]?.create(\n // @ts-expect-error\n syncedFields,\n )\n\n if (logs) {\n payload.logger.info(\n `✅ Successfully created new '${syncConfig.stripeResourceType}' resource in Stripe with ID: '${stripeResource.id}'.`,\n )\n }\n\n dataRef.stripeID = stripeResource.id\n\n // NOTE: this is to prevent sync in the \"afterChange\" hook\n dataRef.skipSync = true\n } catch (error: unknown) {\n const msg = error instanceof Error ? error.message : error\n if (logs) {\n payload.logger.error(`- Error creating Stripe document: ${msg}`)\n }\n }\n }\n }\n\n if (operation === 'create') {\n if (logs) {\n payload.logger.info(\n `A new '${collectionSlug}' document was created in Payload with ID: '${data?.id}', syncing with Stripe...`,\n )\n }\n\n try {\n if (logs) {\n payload.logger.info(\n `- Creating new '${syncConfig.stripeResourceType}' resource in Stripe...`,\n )\n }\n\n // NOTE: Typed as \"any\" because the \"create\" method is not standard across all Stripe resources\n const stripeResource = await stripe?.[syncConfig.stripeResourceType]?.create(\n // @ts-expect-error\n syncedFields,\n )\n\n if (logs) {\n payload.logger.info(\n `✅ Successfully created new '${syncConfig.stripeResourceType}' resource in Stripe with ID: '${stripeResource.id}'.`,\n )\n }\n\n dataRef.stripeID = stripeResource.id\n\n // IMPORTANT: this is to prevent sync in the \"afterChange\" hook\n dataRef.skipSync = true\n } catch (error: unknown) {\n const msg = error instanceof Error ? error.message : error\n throw new APIError(\n `Failed to create new '${syncConfig.stripeResourceType}' resource in Stripe: ${msg}`,\n )\n }\n }\n }\n }\n }\n\n return dataRef\n}\n"],"names":["APIError","Stripe","deepen","createNewInStripe","args","collection","data","operation","pluginConfig","req","logs","sync","payload","dataRef","process","env","NODE_ENV","stripeID","skipSync","logger","info","slug","collectionSlug","syncConfig","find","conf","syncedFields","fields","reduce","acc","field","fieldPath","stripeProperty","stripe","stripeSecretKey","apiVersion","id","stripeResource","stripeResourceType","create","error","msg","Error","message"],"mappings":"AAEA,SAASA,QAAQ,QAAQ,UAAS;AAClC,OAAOC,YAAY,SAAQ;AAI3B,SAASC,MAAM,QAAQ,yBAAwB;AAa/C,OAAO,MAAMC,oBAA0D,OAAOC;IAC5E,MAAM,EAAEC,UAAU,EAAEC,IAAI,EAAEC,SAAS,EAAEC,YAAY,EAAEC,GAAG,EAAE,GAAGL;IAE3D,MAAM,EAAEM,IAAI,EAAEC,IAAI,EAAE,GAAGH,gBAAgB,CAAC;IAExC,MAAMI,UAAUH,KAAKG;IAErB,MAAMC,UAAUP,QAAQ,CAAC;IAEzB,IAAIQ,QAAQC,GAAG,CAACC,QAAQ,KAAK,QAAQ;QACnCH,QAAQI,QAAQ,GAAG;QACnB,OAAOJ;IACT;IAEA,IAAID,SAAS;QACX,IAAIN,MAAMY,UAAU;YAClB,IAAIR,MAAM;gBACRE,QAAQO,MAAM,CAACC,IAAI,CAAC,CAAC,iCAAiC,CAAC;YACzD;QACF,OAAO;YACL,wEAAwE;YACxE,8EAA8E;YAC9E,uFAAuF;YACvFP,QAAQK,QAAQ,GAAG;YAEnB,MAAM,EAAEG,MAAMC,cAAc,EAAE,GAAGjB,cAAc,CAAC;YAChD,MAAMkB,aAAaZ,MAAMa,KAAK,CAACC,OAASA,KAAKpB,UAAU,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ACRE,QAAQO,MAAM,CAACC,IAAI,CACjB,CAAC,OAAO,EAAEE,eAAe,4CAA4C,EAAEhB,MAAM8B,GAAG,yBAAyB,CAAC;oBAE9G;oBAEA,IAAI;wBACF,IAAI1B,MAAM;4BACRE,QAAQO,MAAM,CAACC,IAAI,CACjB,CAAC,gBAAgB,EAAEG,WAAWe,kBAAkB,CAAC,uBAAuB,CAAC;wBAE7E;wBAEA,+FAA+F;wBAC/F,MAAMD,iBAAiB,MAAMJ,QAAQ,CAACV,WAAWe,kBAAkB,CAAC,EAAEC,OACpE,mBAAmB;wBACnBb;wBAGF,IAAIhB,MAAM;4BACRE,QAAQO,MAAM,CAACC,IAAI,CACjB,CAAC,4BAA4B,EAAEG,WAAWe,kBAAkB,CAAC,+BAA+B,EAAED,eAAeD,EAAE,CAAC,EAAE,CAAC;wBAEvH;wBAEAvB,QAAQI,QAAQ,GAAGoB,eAAeD,EAAE;wBAEpC,+DAA+D;wBAC/DvB,QAAQK,QAAQ,GAAG;oBACrB,EAAE,OAAOsB,OAAgB;wBACvB,MAAMC,MAAMD,iBAAiBE,QAAQF,MAAMG,OAAO,GAAGH;wBACrD,MAAM,IAAIxC,SACR,CAAC,sBAAsB,EAAEuB,WAAWe,kBAAkB,CAAC,sBAAsB,EAAEG,KAAK;oBAExF;gBACF;YACF;QACF;IACF;IAEA,OAAO5B;AACT,EAAC"}
1
+ {"version":3,"sources":["../../src/hooks/createNewInStripe.ts"],"sourcesContent":["import type { CollectionBeforeValidateHook, CollectionConfig } from 'payload'\n\nimport { APIError } from 'payload'\nimport Stripe from 'stripe'\n\nimport type { StripePluginConfig } from '../types.js'\n\nimport { deepen } from '../utilities/deepen.js'\n\ntype HookArgsWithCustomCollection = {\n collection: CollectionConfig\n} & Omit<Parameters<CollectionBeforeValidateHook>[0], 'collection'>\n\nexport type CollectionBeforeValidateHookWithArgs = (\n args: {\n collection?: CollectionConfig\n pluginConfig?: StripePluginConfig\n } & HookArgsWithCustomCollection,\n) => Promise<Partial<any>>\n\nexport const createNewInStripe: CollectionBeforeValidateHookWithArgs = async (args) => {\n const { collection, data, operation, pluginConfig, req } = args\n\n const { logs, sync } = pluginConfig || {}\n\n const payload = req?.payload\n\n const dataRef = data || {}\n\n if (process.env.NODE_ENV === 'test') {\n dataRef.stripeID = 'test'\n return dataRef\n }\n\n if (payload) {\n if (data?.skipSync) {\n if (logs) {\n payload.logger.info(`Bypassing collection-level hooks.`)\n }\n } else {\n // initialize as 'false' so that all Payload admin events sync to Stripe\n // then conditionally set to 'true' to for events that originate from webhooks\n // this will prevent webhook events from triggering an unnecessary sync / infinite loop\n dataRef.skipSync = false\n\n const { slug: collectionSlug } = collection || {}\n const syncConfig = sync?.find((conf) => conf.collection === collectionSlug)\n\n if (syncConfig) {\n // combine all fields of this object and match their respective values within the document\n let syncedFields = syncConfig.fields.reduce(\n (acc, field) => {\n const { fieldPath, stripeProperty } = field\n\n acc[stripeProperty] = dataRef[fieldPath]\n return acc\n },\n {} as Record<string, any>,\n )\n\n syncedFields = deepen(syncedFields)\n\n // api version can only be the latest, stripe recommends ts ignoring it\n const stripe = new Stripe(pluginConfig?.stripeSecretKey || '', { apiVersion: '2022-08-01' })\n\n if (operation === 'update') {\n if (logs) {\n payload.logger.info(\n `A '${collectionSlug}' document has changed in Payload with ID: '${data?.id}', syncing with Stripe...`,\n )\n }\n\n // NOTE: the Stripe document will be created in the \"afterChange\" hook, so create a new stripe document here if no stripeID exists\n if (!dataRef.stripeID) {\n try {\n // NOTE: Typed as \"any\" because the \"create\" method is not standard across all Stripe resources\n const stripeResource = await stripe?.[syncConfig.stripeResourceType]?.create(\n // @ts-expect-error\n syncedFields,\n )\n\n if (logs) {\n payload.logger.info(\n `✅ Successfully created new '${syncConfig.stripeResourceType}' resource in Stripe with ID: '${stripeResource.id}'.`,\n )\n }\n\n dataRef.stripeID = stripeResource.id\n\n // NOTE: this is to prevent sync in the \"afterChange\" hook\n dataRef.skipSync = true\n } catch (error: unknown) {\n const msg = error instanceof Error ? error.message : error\n if (logs) {\n payload.logger.error(`- Error creating Stripe document: ${msg}`)\n }\n }\n }\n }\n\n if (operation === 'create') {\n if (logs) {\n payload.logger.info(\n `A new '${collectionSlug}' document was created in Payload with ID: '${data?.id}', syncing with Stripe...`,\n )\n }\n\n try {\n if (logs) {\n payload.logger.info(\n `- Creating new '${syncConfig.stripeResourceType}' resource in Stripe...`,\n )\n }\n\n // NOTE: Typed as \"any\" because the \"create\" method is not standard across all Stripe resources\n const stripeResource = await stripe?.[syncConfig.stripeResourceType]?.create(\n // @ts-expect-error\n syncedFields,\n )\n\n if (logs) {\n payload.logger.info(\n `✅ Successfully created new '${syncConfig.stripeResourceType}' resource in Stripe with ID: '${stripeResource.id}'.`,\n )\n }\n\n dataRef.stripeID = stripeResource.id\n\n // IMPORTANT: this is to prevent sync in the \"afterChange\" hook\n dataRef.skipSync = true\n } catch (error: unknown) {\n const msg = error instanceof Error ? error.message : error\n throw new APIError(\n `Failed to create new '${syncConfig.stripeResourceType}' resource in Stripe: ${msg}`,\n )\n }\n }\n }\n }\n }\n\n return dataRef\n}\n"],"names":["APIError","Stripe","deepen","createNewInStripe","args","collection","data","operation","pluginConfig","req","logs","sync","payload","dataRef","process","env","NODE_ENV","stripeID","skipSync","logger","info","slug","collectionSlug","syncConfig","find","conf","syncedFields","fields","reduce","acc","field","fieldPath","stripeProperty","stripe","stripeSecretKey","apiVersion","id","stripeResource","stripeResourceType","create","error","msg","Error","message"],"mappings":"AAEA,SAASA,QAAQ,QAAQ,UAAS;AAClC,OAAOC,YAAY,SAAQ;AAI3B,SAASC,MAAM,QAAQ,yBAAwB;AAa/C,OAAO,MAAMC,oBAA0D,OAAOC;IAC5E,MAAM,EAAEC,UAAU,EAAEC,IAAI,EAAEC,SAAS,EAAEC,YAAY,EAAEC,GAAG,EAAE,GAAGL;IAE3D,MAAM,EAAEM,IAAI,EAAEC,IAAI,EAAE,GAAGH,gBAAgB,CAAC;IAExC,MAAMI,UAAUH,KAAKG;IAErB,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AC,sBAAsB,EAAEG,KAAK;oBAExF;gBACF;YACF;QACF;IACF;IAEA,OAAO5B;AACT,EAAC"}
@@ -16,7 +16,7 @@ export const deleteFromStripe = async (args)=>{
16
16
  if (syncConfig) {
17
17
  try {
18
18
  // api version can only be the latest, stripe recommends ts ignoring it
19
- const stripe = new Stripe(pluginConfig.stripeSecretKey || '', {
19
+ const stripe = new Stripe(pluginConfig?.stripeSecretKey || '', {
20
20
  apiVersion: '2022-08-01'
21
21
  });
22
22
  const found = await stripe?.[syncConfig.stripeResourceType]?.retrieve(doc.stripeID);
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/hooks/deleteFromStripe.ts"],"sourcesContent":["import type { CollectionAfterDeleteHook, CollectionConfig } from 'payload'\n\nimport { APIError } from 'payload'\nimport Stripe from 'stripe'\n\nimport type { StripePluginConfig } from '../types.js'\n\ntype HookArgsWithCustomCollection = {\n collection: CollectionConfig\n} & Omit<Parameters<CollectionAfterDeleteHook>[0], 'collection'>\n\nexport type CollectionAfterDeleteHookWithArgs = (\n args: {\n collection?: CollectionConfig\n pluginConfig?: StripePluginConfig\n } & HookArgsWithCustomCollection,\n) => Promise<void>\n\nexport const deleteFromStripe: CollectionAfterDeleteHookWithArgs = async (args) => {\n const { collection, doc, pluginConfig, req } = args\n\n const { logs, sync } = pluginConfig || {}\n\n const { payload } = req\n const { slug: collectionSlug } = collection || {}\n\n if (logs) {\n payload.logger.info(\n `Document with ID: '${doc?.id}' in collection: '${collectionSlug}' has been deleted, deleting from Stripe...`,\n )\n }\n\n if (process.env.NODE_ENV !== 'test') {\n if (logs) {\n payload.logger.info(`- Deleting Stripe document with ID: '${doc.stripeID}'...`)\n }\n\n const syncConfig = sync?.find((conf) => conf.collection === collectionSlug)\n\n if (syncConfig) {\n try {\n // api version can only be the latest, stripe recommends ts ignoring it\n const stripe = new Stripe(pluginConfig.stripeSecretKey || '', { apiVersion: '2022-08-01' })\n\n const found = await stripe?.[syncConfig.stripeResourceType]?.retrieve(doc.stripeID)\n\n if (found) {\n await stripe?.[syncConfig.stripeResourceType]?.del(doc.stripeID)\n if (logs) {\n payload.logger.info(\n `✅ Successfully deleted Stripe document with ID: '${doc.stripeID}'.`,\n )\n }\n } else {\n if (logs) {\n payload.logger.info(\n `- Stripe document with ID: '${doc.stripeID}' not found, skipping...`,\n )\n }\n }\n } catch (error: unknown) {\n const msg = error instanceof Error ? error.message : error\n throw new APIError(`Failed to delete Stripe document with ID: '${doc.stripeID}': ${msg}`)\n }\n }\n }\n}\n"],"names":["APIError","Stripe","deleteFromStripe","args","collection","doc","pluginConfig","req","logs","sync","payload","slug","collectionSlug","logger","info","id","process","env","NODE_ENV","stripeID","syncConfig","find","conf","stripe","stripeSecretKey","apiVersion","found","stripeResourceType","retrieve","del","error","msg","Error","message"],"mappings":"AAEA,SAASA,QAAQ,QAAQ,UAAS;AAClC,OAAOC,YAAY,SAAQ;AAe3B,OAAO,MAAMC,mBAAsD,OAAOC;IACxE,MAAM,EAAEC,UAAU,EAAEC,GAAG,EAAEC,YAAY,EAAEC,GAAG,EAAE,GAAGJ;IAE/C,MAAM,EAAEK,IAAI,EAAEC,IAAI,EAAE,GAAGH,gBAAgB,CAAC;IAExC,MAAM,EAAEI,OAAO,EAAE,GAAGH;IACpB,MAAM,EAAEI,MAAMC,cAAc,EAAE,GAAGR,cAAc,CAAC;IAEhD,IAAII,MAAM;QACRE,QAAQG,MAAM,CAACC,IAAI,CACjB,CAAC,mBAAmB,EAAET,KAAKU,GAAG,kBAAkB,EAAEH,eAAe,2CAA2C,CAAC;IAEjH;IAEA,IAAII,QAAQC,GAAG,CAACC,QAAQ,KAAK,QAAQ;QACnC,IAAIV,MAAM;YACRE,QAAQG,MAAM,CAACC,IAAI,CAAC,CAAC,qCAAqC,EAAET,IAAIc,QAAQ,CAAC,IAAI,CAAC;QAChF;QAEA,MAAMC,aAAaX,MAAMY,KAAK,CAACC,OAASA,KAAKlB,UAAU,KAAKQ;QAE5D,IAAIQ,YAAY;YACd,IAAI;gBACF,uEAAuE;gBACvE,MAAMG,SAAS,IAAItB,OAAOK,aAAakB,eAAe,IAAI,IAAI;oBAAEC,YAAY;gBAAa;gBAEzF,MAAMC,QAAQ,MAAMH,QAAQ,CAACH,WAAWO,kBAAkB,CAAC,EAAEC,SAASvB,IAAIc,QAAQ;gBAElF,IAAIO,OAAO;oBACT,MAAMH,QAAQ,CAACH,WAAWO,kBAAkB,CAAC,EAAEE,IAAIxB,IAAIc,QAAQ;oBAC/D,IAAIX,MAAM;wBACRE,QAAQG,MAAM,CAACC,IAAI,CACjB,CAAC,iDAAiD,EAAET,IAAIc,QAAQ,CAAC,EAAE,CAAC;oBAExE;gBACF,OAAO;oBACL,IAAIX,MAAM;wBACRE,QAAQG,MAAM,CAACC,IAAI,CACjB,CAAC,4BAA4B,EAAET,IAAIc,QAAQ,CAAC,wBAAwB,CAAC;oBAEzE;gBACF;YACF,EAAE,OAAOW,OAAgB;gBACvB,MAAMC,MAAMD,iBAAiBE,QAAQF,MAAMG,OAAO,GAAGH;gBACrD,MAAM,IAAI9B,SAAS,CAAC,2CAA2C,EAAEK,IAAIc,QAAQ,CAAC,GAAG,EAAEY,KAAK;YAC1F;QACF;IACF;AACF,EAAC"}
1
+ {"version":3,"sources":["../../src/hooks/deleteFromStripe.ts"],"sourcesContent":["import type { CollectionAfterDeleteHook, CollectionConfig } from 'payload'\n\nimport { APIError } from 'payload'\nimport Stripe from 'stripe'\n\nimport type { StripePluginConfig } from '../types.js'\n\ntype HookArgsWithCustomCollection = {\n collection: CollectionConfig\n} & Omit<Parameters<CollectionAfterDeleteHook>[0], 'collection'>\n\nexport type CollectionAfterDeleteHookWithArgs = (\n args: {\n collection?: CollectionConfig\n pluginConfig?: StripePluginConfig\n } & HookArgsWithCustomCollection,\n) => Promise<void>\n\nexport const deleteFromStripe: CollectionAfterDeleteHookWithArgs = async (args) => {\n const { collection, doc, pluginConfig, req } = args\n\n const { logs, sync } = pluginConfig || {}\n\n const { payload } = req\n const { slug: collectionSlug } = collection || {}\n\n if (logs) {\n payload.logger.info(\n `Document with ID: '${doc?.id}' in collection: '${collectionSlug}' has been deleted, deleting from Stripe...`,\n )\n }\n\n if (process.env.NODE_ENV !== 'test') {\n if (logs) {\n payload.logger.info(`- Deleting Stripe document with ID: '${doc.stripeID}'...`)\n }\n\n const syncConfig = sync?.find((conf) => conf.collection === collectionSlug)\n\n if (syncConfig) {\n try {\n // api version can only be the latest, stripe recommends ts ignoring it\n const stripe = new Stripe(pluginConfig?.stripeSecretKey || '', { apiVersion: '2022-08-01' })\n\n const found = await stripe?.[syncConfig.stripeResourceType]?.retrieve(doc.stripeID)\n\n if (found) {\n await stripe?.[syncConfig.stripeResourceType]?.del(doc.stripeID)\n if (logs) {\n payload.logger.info(\n `✅ Successfully deleted Stripe document with ID: '${doc.stripeID}'.`,\n )\n }\n } else {\n if (logs) {\n payload.logger.info(\n `- Stripe document with ID: '${doc.stripeID}' not found, skipping...`,\n )\n }\n }\n } catch (error: unknown) {\n const msg = error instanceof Error ? error.message : error\n throw new APIError(`Failed to delete Stripe document with ID: '${doc.stripeID}': ${msg}`)\n }\n }\n }\n}\n"],"names":["APIError","Stripe","deleteFromStripe","args","collection","doc","pluginConfig","req","logs","sync","payload","slug","collectionSlug","logger","info","id","process","env","NODE_ENV","stripeID","syncConfig","find","conf","stripe","stripeSecretKey","apiVersion","found","stripeResourceType","retrieve","del","error","msg","Error","message"],"mappings":"AAEA,SAASA,QAAQ,QAAQ,UAAS;AAClC,OAAOC,YAAY,SAAQ;AAe3B,OAAO,MAAMC,mBAAsD,OAAOC;IACxE,MAAM,EAAEC,UAAU,EAAEC,GAAG,EAAEC,YAAY,EAAEC,GAAG,EAAE,GAAGJ;IAE/C,MAAM,EAAEK,IAAI,EAAEC,IAAI,EAAE,GAAGH,gBAAgB,CAAC;IAExC,MAAM,EAAEI,OAAO,EAAE,GAAGH;IACpB,MAAM,EAAEI,MAAMC,cAAc,EAAE,GAAGR,cAAc,CAAC;IAEhD,IAAII,MAAM;QACRE,QAAQG,MAAM,CAACC,IAAI,CACjB,CAAC,mBAAmB,EAAET,KAAKU,GAAG,kBAAkB,EAAEH,eAAe,2CAA2C,CAAC;IAEjH;IAEA,IAAII,QAAQC,GAAG,CAACC,QAAQ,KAAK,QAAQ;QACnC,IAAIV,MAAM;YACRE,QAAQG,MAAM,CAACC,IAAI,CAAC,CAAC,qCAAqC,EAAET,IAAIc,QAAQ,CAAC,IAAI,CAAC;QAChF;QAEA,MAAMC,aAAaX,MAAMY,KAAK,CAACC,OAASA,KAAKlB,UAAU,KAAKQ;QAE5D,IAAIQ,YAAY;YACd,IAAI;gBACF,uEAAuE;gBACvE,MAAMG,SAAS,IAAItB,OAAOK,cAAckB,mBAAmB,IAAI;oBAAEC,YAAY;gBAAa;gBAE1F,MAAMC,QAAQ,MAAMH,QAAQ,CAACH,WAAWO,kBAAkB,CAAC,EAAEC,SAASvB,IAAIc,QAAQ;gBAElF,IAAIO,OAAO;oBACT,MAAMH,QAAQ,CAACH,WAAWO,kBAAkB,CAAC,EAAEE,IAAIxB,IAAIc,QAAQ;oBAC/D,IAAIX,MAAM;wBACRE,QAAQG,MAAM,CAACC,IAAI,CACjB,CAAC,iDAAiD,EAAET,IAAIc,QAAQ,CAAC,EAAE,CAAC;oBAExE;gBACF,OAAO;oBACL,IAAIX,MAAM;wBACRE,QAAQG,MAAM,CAACC,IAAI,CACjB,CAAC,4BAA4B,EAAET,IAAIc,QAAQ,CAAC,wBAAwB,CAAC;oBAEzE;gBACF;YACF,EAAE,OAAOW,OAAgB;gBACvB,MAAMC,MAAMD,iBAAiBE,QAAQF,MAAMG,OAAO,GAAGH;gBACrD,MAAM,IAAI9B,SAAS,CAAC,2CAA2C,EAAEK,IAAIc,QAAQ,CAAC,GAAG,EAAEY,KAAK;YAC1F;QACF;IACF;AACF,EAAC"}
@@ -31,7 +31,7 @@ export const syncExistingWithStripe = async (args)=>{
31
31
  }
32
32
  try {
33
33
  // api version can only be the latest, stripe recommends ts ignoring it
34
- const stripe = new Stripe(pluginConfig.stripeSecretKey || '', {
34
+ const stripe = new Stripe(pluginConfig?.stripeSecretKey || '', {
35
35
  apiVersion: '2022-08-01'
36
36
  });
37
37
  const stripeResource = await stripe?.[syncConfig?.stripeResourceType]?.update(data.stripeID, syncedFields);
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/hooks/syncExistingWithStripe.ts"],"sourcesContent":["import type { CollectionBeforeChangeHook, CollectionConfig } from 'payload'\n\nimport { APIError } from 'payload'\nimport Stripe from 'stripe'\n\nimport type { StripePluginConfig } from '../types.js'\n\nimport { deepen } from '../utilities/deepen.js'\n\ntype HookArgsWithCustomCollection = {\n collection: CollectionConfig\n} & Omit<Parameters<CollectionBeforeChangeHook>[0], 'collection'>\n\nexport type CollectionBeforeChangeHookWithArgs = (\n args: {\n collection?: CollectionConfig\n pluginConfig?: StripePluginConfig\n } & HookArgsWithCustomCollection,\n) => Promise<Partial<any>>\n\nexport const syncExistingWithStripe: CollectionBeforeChangeHookWithArgs = async (args) => {\n const { collection, data, operation, originalDoc, pluginConfig, req } = args\n\n const { logs, sync } = pluginConfig || {}\n\n const { payload } = req\n\n const { slug: collectionSlug } = collection || {}\n\n if (process.env.NODE_ENV !== 'test' && !data.skipSync) {\n const syncConfig = sync?.find((conf) => conf.collection === collectionSlug)\n\n if (syncConfig) {\n if (operation === 'update') {\n // combine all fields of this object and match their respective values within the document\n let syncedFields = syncConfig.fields.reduce(\n (acc, field) => {\n const { fieldPath, stripeProperty } = field\n\n acc[stripeProperty] = data[fieldPath]\n return acc\n },\n {} as Record<string, any>,\n )\n\n syncedFields = deepen(syncedFields)\n\n if (logs) {\n payload.logger.info(\n `A '${collectionSlug}' document has changed in Payload with ID: '${originalDoc?._id}', syncing with Stripe...`,\n )\n }\n\n if (!data.stripeID) {\n // NOTE: the \"beforeValidate\" hook populates this\n if (logs) {\n payload.logger.error(`- There is no Stripe ID for this document, skipping.`)\n }\n } else {\n if (logs) {\n payload.logger.info(`- Syncing to Stripe resource with ID: '${data.stripeID}'...`)\n }\n\n try {\n // api version can only be the latest, stripe recommends ts ignoring it\n const stripe = new Stripe(pluginConfig.stripeSecretKey || '', {\n apiVersion: '2022-08-01',\n })\n\n const stripeResource = await stripe?.[syncConfig?.stripeResourceType]?.update(\n data.stripeID,\n syncedFields,\n )\n\n if (logs) {\n payload.logger.info(\n `✅ Successfully synced Stripe resource with ID: '${stripeResource.id}'.`,\n )\n }\n } catch (error: unknown) {\n const msg = error instanceof Error ? error.message : error\n throw new APIError(`Failed to sync document with ID: '${data.id}' to Stripe: ${msg}`)\n }\n }\n }\n }\n }\n\n // Set back to 'false' so that all changes continue to sync to Stripe, see note in './createNewInStripe.ts'\n data.skipSync = false\n\n return data\n}\n"],"names":["APIError","Stripe","deepen","syncExistingWithStripe","args","collection","data","operation","originalDoc","pluginConfig","req","logs","sync","payload","slug","collectionSlug","process","env","NODE_ENV","skipSync","syncConfig","find","conf","syncedFields","fields","reduce","acc","field","fieldPath","stripeProperty","logger","info","_id","stripeID","error","stripe","stripeSecretKey","apiVersion","stripeResource","stripeResourceType","update","id","msg","Error","message"],"mappings":"AAEA,SAASA,QAAQ,QAAQ,UAAS;AAClC,OAAOC,YAAY,SAAQ;AAI3B,SAASC,MAAM,QAAQ,yBAAwB;AAa/C,OAAO,MAAMC,yBAA6D,OAAOC;IAC/E,MAAM,EAAEC,UAAU,EAAEC,IAAI,EAAEC,SAAS,EAAEC,WAAW,EAAEC,YAAY,EAAEC,GAAG,EAAE,GAAGN;IAExE,MAAM,EAAEO,IAAI,EAAEC,IAAI,EAAE,GAAGH,gBAAgB,CAAC;IAExC,MAAM,EAAEI,OAAO,EAAE,GAAGH;IAEpB,MAAM,EAAEI,MAAMC,cAAc,EAAE,GAAGV,cAAc,CAAC;IAEhD,IAAIW,QAAQC,GAAG,CAACC,QAAQ,KAAK,UAAU,CAACZ,KAAKa,QAAQ,EAAE;QACrD,MAAMC,aAAaR,MAAMS,KAAK,CAACC,OAASA,KA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AEC,KAAK;oBACtF;gBACF;YACF;QACF;IACF;IAEA,2GAA2G;IAC3GpC,KAAKa,QAAQ,GAAG;IAEhB,OAAOb;AACT,EAAC"}
1
+ {"version":3,"sources":["../../src/hooks/syncExistingWithStripe.ts"],"sourcesContent":["import type { CollectionBeforeChangeHook, CollectionConfig } from 'payload'\n\nimport { APIError } from 'payload'\nimport Stripe from 'stripe'\n\nimport type { StripePluginConfig } from '../types.js'\n\nimport { deepen } from '../utilities/deepen.js'\n\ntype HookArgsWithCustomCollection = {\n collection: CollectionConfig\n} & Omit<Parameters<CollectionBeforeChangeHook>[0], 'collection'>\n\nexport type CollectionBeforeChangeHookWithArgs = (\n args: {\n collection?: CollectionConfig\n pluginConfig?: StripePluginConfig\n } & HookArgsWithCustomCollection,\n) => Promise<Partial<any>>\n\nexport const syncExistingWithStripe: CollectionBeforeChangeHookWithArgs = async (args) => {\n const { collection, data, operation, originalDoc, pluginConfig, req } = args\n\n const { logs, sync } = pluginConfig || {}\n\n const { payload } = req\n\n const { slug: collectionSlug } = collection || {}\n\n if (process.env.NODE_ENV !== 'test' && !data.skipSync) {\n const syncConfig = sync?.find((conf) => conf.collection === collectionSlug)\n\n if (syncConfig) {\n if (operation === 'update') {\n // combine all fields of this object and match their respective values within the document\n let syncedFields = syncConfig.fields.reduce(\n (acc, field) => {\n const { fieldPath, stripeProperty } = field\n\n acc[stripeProperty] = data[fieldPath]\n return acc\n },\n {} as Record<string, any>,\n )\n\n syncedFields = deepen(syncedFields)\n\n if (logs) {\n payload.logger.info(\n `A '${collectionSlug}' document has changed in Payload with ID: '${originalDoc?._id}', syncing with Stripe...`,\n )\n }\n\n if (!data.stripeID) {\n // NOTE: the \"beforeValidate\" hook populates this\n if (logs) {\n payload.logger.error(`- There is no Stripe ID for this document, skipping.`)\n }\n } else {\n if (logs) {\n payload.logger.info(`- Syncing to Stripe resource with ID: '${data.stripeID}'...`)\n }\n\n try {\n // api version can only be the latest, stripe recommends ts ignoring it\n const stripe = new Stripe(pluginConfig?.stripeSecretKey || '', {\n apiVersion: '2022-08-01',\n })\n\n const stripeResource = await stripe?.[syncConfig?.stripeResourceType]?.update(\n data.stripeID,\n syncedFields,\n )\n\n if (logs) {\n payload.logger.info(\n `✅ Successfully synced Stripe resource with ID: '${stripeResource.id}'.`,\n )\n }\n } catch (error: unknown) {\n const msg = error instanceof Error ? error.message : error\n throw new APIError(`Failed to sync document with ID: '${data.id}' to Stripe: ${msg}`)\n }\n }\n }\n }\n }\n\n // Set back to 'false' so that all changes continue to sync to Stripe, see note in './createNewInStripe.ts'\n data.skipSync = false\n\n return data\n}\n"],"names":["APIError","Stripe","deepen","syncExistingWithStripe","args","collection","data","operation","originalDoc","pluginConfig","req","logs","sync","payload","slug","collectionSlug","process","env","NODE_ENV","skipSync","syncConfig","find","conf","syncedFields","fields","reduce","acc","field","fieldPath","stripeProperty","logger","info","_id","stripeID","error","stripe","stripeSecretKey","apiVersion","stripeResource","stripeResourceType","update","id","msg","Error","message"],"mappings":"AAEA,SAASA,QAAQ,QAAQ,UAAS;AAClC,OAAOC,YAAY,SAAQ;AAI3B,SAASC,MAAM,QAAQ,yBAAwB;AAa/C,OAAO,MAAMC,yBAA6D,OAAOC;IAC/E,MAAM,EAAEC,UAAU,EAAEC,IAAI,EAAEC,SAAS,EAAEC,WAAW,EAAEC,YAAY,EAAEC,GAAG,EAAE,GAAGN;IAExE,MAAM,EAAEO,IAAI,EAAEC,IAAI,EAAE,GAAGH,gBAAgB,CAAC;IAExC,MAAM,EAAEI,OAAO,EAAE,GAAGH;IAEpB,MAAM,EAAEI,MAAMC,cAAc,EAAE,GAAGV,cAAc,CAAC;IAEhD,IAAIW,QAAQC,GAAG,CAACC,QAAQ,KAAK,UAAU,CAACZ,KAAKa,QAAQ,EAAE;QACrD,MAAMC,aAAaR,MAAMS,KAAK,CAACC,OAASA,KAAKjB,UAAU,KAAKU;QAE5D,IAAIK,YAAY;YACd,IAAIb,cAAc,UAAU;gBAC1B,0FAA0F;gBAC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,OAAOb;AACT,EAAC"}
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts"],"sourcesContent":["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"],"names":["getFields","createNewInStripe","deleteFromStripe","syncExistingWithStripe","stripeREST","stripeWebhooks","stripeProxy","stripePlugin","incomingStripeConfig","config","collections","pluginConfig","rest","sync","endpoints","handler","req","res","method","path","push","collection","hooks","existingHooks","syncConfig","find","slug","fields","afterDelete","args","beforeChange","beforeValidate"],"mappings":"AAIA,SAASA,SAAS,QAAQ,wBAAuB;AACjD,SAASC,iBAAiB,QAAQ,+BAA8B;AAChE,SAASC,gBAAgB,QAAQ,8BAA6B;AAC9D,SAASC,sBAAsB,QAAQ,oCAAmC;AAC1E,SAASC,UAAU,QAAQ,mBAAkB;AAC7C,SAASC,cAAc,QAAQ,uBAAsB;AAErD,SAASC,WAAW,QAAQ,6BAA4B;AAExD,OAAO,MAAMC,eACX,CAACC,uBACD,CAACC;QACC,MAAM,EAAEC,WAAW,EAAE,GAAGD;QAExB,2BAA2B;QAC3B,MAAME,eAA4C;YAChD,GAAGH,oBAAoB;YACvBI,MAAMJ,sBAAsBI,QAAQ;YACpCC,MAAML,sBAAsBK,QAAQ,EAAE;QACxC;QAEA,6GAA6G;QAC7G,wGAAwG;QACxG,0EAA0E;QAE1E,MAAMC,YAAwB;eACxBL,QAAQK,aAAa,EAAE;YAC3B;gBACEC,SAAS,OAAOC;oBACd,MAAMC,MAAM,MAAMZ,eAAe;wBAC/BI;wBACAE;wBACAK;oBACF;oBAEA,OAAOC;gBACT;gBACAC,QAAQ;gBACRC,MAAM;YACR;SACD;QAED,IAAIX,sBAAsBI,MAAM;YAC9BE,UAAUM,IAAI,CAAC;gBACbL,SAAS,OAAOC;oBACd,MAAMC,MAAM,MAAMb,WAAW;wBAC3BO;wBACAK;oBACF;oBAEA,OAAOC;gBACT;gBACAC,QAAQ;gBACRC,MAAM;YACR;QACF;QAEA,KAAK,MAAME,cAAcX,YAAa;YACpC,MAAM,EAAEY,OAAOC,aAAa,EAAE,GAAGF;YAEjC,MAAMG,aAAab,aAAaE,IAAI,EAAEY,KAAK,CAACZ,OAASA,KAAKQ,UAAU,KAAKA,WAAWK,IAAI;YAExF,IAAI,CAACF,YAAY;gBACf;YACF;YACA,MAAMG,SAAS3B,UAAU;gBACvBqB;gBACAV;gBACAa;YACF;YACAH,WAAWM,MAAM,GAAGA;YAEpB,IAAI,CAACN,WAAWC,KAAK,EAAE;gBACrBD,WAAWC,KAAK,GAAG,CAAC;YACtB;YAEAD,WAAWC,KAAK,CAACM,WAAW,GAAG;mBACzBL,eAAeK,eAAe,EAAE;gBACpC,CAACC,OACC3B,iBAAiB;wBACf,GAAG2B,IAAI;wBACPR;wBACAV;oBACF;aACH;YACDU,WAAWC,KAAK,CAACQ,YAAY,GAAG;mBAC1BP,eAAeO,gBAAgB,EAAE;gBACrC,CAACD,OACC1B,uBAAuB;wBACrB,GAAG0B,IAAI;wBACPR;wBACAV;oBACF;aACH;YACDU,WAAWC,KAAK,CAACS,cAAc,GAAG;mBAC5BR,eAAeQ,kBAAkB,EAAE;gBACvC,CAACF,OACC5B,kBAAkB;wBAChB,GAAG4B,IAAI;wBACPR;wBACAV;oBACF;aACH;QACH;QAEAF,OAAOK,SAAS,GAAGA;QAEnB,OAAOL;IACT,EAAC"}
1
+ {"version":3,"sources":["../src/index.ts"],"sourcesContent":["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"],"names":["getFields","createNewInStripe","deleteFromStripe","syncExistingWithStripe","stripeREST","stripeWebhooks","stripeProxy","stripePlugin","incomingStripeConfig","config","collections","pluginConfig","rest","sync","endpoints","handler","req","res","method","path","push","collection","hooks","existingHooks","syncConfig","find","slug","fields","afterDelete","args","beforeChange","beforeValidate"],"mappings":"AAIA,SAASA,SAAS,QAAQ,wBAAuB;AACjD,SAASC,iBAAiB,QAAQ,+BAA8B;AAChE,SAASC,gBAAgB,QAAQ,8BAA6B;AAC9D,SAASC,sBAAsB,QAAQ,oCAAmC;AAC1E,SAASC,UAAU,QAAQ,mBAAkB;AAC7C,SAASC,cAAc,QAAQ,uBAAsB;AAErD,SAASC,WAAW,QAAQ,6BAA4B;AAExD,OAAO,MAAMC,eACX,CAACC,uBACD,CAACC;QACC,MAAM,EAAEC,WAAW,EAAE,GAAGD;QAExB,2BAA2B;QAC3B,MAAME,eAA4C;YAChD,GAAGH,oBAAoB;YACvBI,MAAMJ,sBAAsBI,QAAQ;YACpCC,MAAML,sBAAsBK,QAAQ,EAAE;QACxC;QAEA,6GAA6G;QAC7G,wGAAwG;QACxG,0EAA0E;QAE1E,MAAMC,YAAwB;eACxBL,QAAQK,aAAa,EAAE;YAC3B;gBACEC,SAAS,OAAOC;oBACd,MAAMC,MAAM,MAAMZ,eAAe;wBAC/BI;wBACAE;wBACAK;oBACF;oBAEA,OAAOC;gBACT;gBACAC,QAAQ;gBACRC,MAAM;YACR;SACD;QAED,IAAIX,sBAAsBI,MAAM;YAC9BE,UAAUM,IAAI,CAAC;gBACbL,SAAS,OAAOC;oBACd,MAAMC,MAAM,MAAMb,WAAW;wBAC3BO;wBACAK;oBACF;oBAEA,OAAOC;gBACT;gBACAC,QAAQ;gBACRC,MAAM;YACR;QACF;QAEA,KAAK,MAAME,cAAcX,YAAc;YACrC,MAAM,EAAEY,OAAOC,aAAa,EAAE,GAAGF;YAEjC,MAAMG,aAAab,aAAaE,IAAI,EAAEY,KAAK,CAACZ,OAASA,KAAKQ,UAAU,KAAKA,WAAWK,IAAI;YAExF,IAAI,CAACF,YAAY;gBACf;YACF;YACA,MAAMG,SAAS3B,UAAU;gBACvBqB;gBACAV;gBACAa;YACF;YACAH,WAAWM,MAAM,GAAGA;YAEpB,IAAI,CAACN,WAAWC,KAAK,EAAE;gBACrBD,WAAWC,KAAK,GAAG,CAAC;YACtB;YAEAD,WAAWC,KAAK,CAACM,WAAW,GAAG;mBACzBL,eAAeK,eAAe,EAAE;gBACpC,CAACC,OACC3B,iBAAiB;wBACf,GAAG2B,IAAI;wBACPR;wBACAV;oBACF;aACH;YACDU,WAAWC,KAAK,CAACQ,YAAY,GAAG;mBAC1BP,eAAeO,gBAAgB,EAAE;gBACrC,CAACD,OACC1B,uBAAuB;wBACrB,GAAG0B,IAAI;wBACPR;wBACAV;oBACF;aACH;YACDU,WAAWC,KAAK,CAACS,cAAc,GAAG;mBAC5BR,eAAeQ,kBAAkB,EAAE;gBACvC,CAACF,OACC5B,kBAAkB;wBAChB,GAAG4B,IAAI;wBACPR;wBACAV;oBACF;aACH;QACH;QAEAF,OAAOK,SAAS,GAAGA;QAEnB,OAAOL;IACT,EAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"rest.d.ts","sourceRoot":"","sources":["../../src/routes/rest.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,SAAS,CAAA;AAI7C,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAA;AAIrD,eAAO,MAAM,UAAU,SAAgB;IACrC,YAAY,EAAE,kBAAkB,CAAA;IAChC,GAAG,EAAE,cAAc,CAAA;CACpB,KAAG,OAAO,CAAC,GAAG,CAiDd,CAAA"}
1
+ {"version":3,"file":"rest.d.ts","sourceRoot":"","sources":["../../src/routes/rest.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,SAAS,CAAA;AAI7C,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAA;AAIrD,eAAO,MAAM,UAAU,SAAgB;IACrC,YAAY,EAAE,kBAAkB,CAAA;IAChC,GAAG,EAAE,cAAc,CAAA;CACpB,KAAG,OAAO,CAAC,GAAG,CAyCd,CAAA"}
@@ -6,7 +6,7 @@ export const stripeREST = async (args)=>{
6
6
  const { pluginConfig, req } = args;
7
7
  await addDataAndFileToRequest(req);
8
8
  const requestWithData = req;
9
- const { data: { stripeArgs, stripeMethod }, payload, user } = requestWithData;
9
+ const { data, payload, user } = requestWithData;
10
10
  const { stripeSecretKey } = pluginConfig;
11
11
  try {
12
12
  if (!user) {
@@ -14,8 +14,8 @@ export const stripeREST = async (args)=>{
14
14
  throw new Forbidden(req.t);
15
15
  }
16
16
  responseJSON = await stripeProxy({
17
- stripeArgs,
18
- stripeMethod,
17
+ stripeArgs: data?.stripeArgs,
18
+ stripeMethod: data?.stripeMethod,
19
19
  stripeSecretKey
20
20
  });
21
21
  const { status } = responseJSON;
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/routes/rest.ts"],"sourcesContent":["import type { PayloadRequest } from 'payload'\n\nimport { addDataAndFileToRequest, Forbidden } from 'payload'\n\nimport type { StripePluginConfig } from '../types.js'\n\nimport { stripeProxy } from '../utilities/stripeProxy.js'\n\nexport const stripeREST = async (args: {\n pluginConfig: StripePluginConfig\n req: PayloadRequest\n}): Promise<any> => {\n let responseStatus = 200\n let responseJSON\n\n const { pluginConfig, req } = args\n\n await addDataAndFileToRequest(req)\n\n const requestWithData = req\n\n const {\n data: {\n stripeArgs, // example: ['cus_MGgt3Tuj3D66f2'] or [{ limit: 100 }, { stripeAccount: 'acct_1J9Z4pKZ4Z4Z4Z4Z' }]\n stripeMethod, // example: 'subscriptions.list',\n },\n payload,\n user,\n } = requestWithData\n\n const { stripeSecretKey } = pluginConfig\n\n try {\n if (!user) {\n // TODO: make this customizable from the config\n throw new Forbidden(req.t)\n }\n\n responseJSON = await stripeProxy({\n stripeArgs,\n stripeMethod,\n stripeSecretKey,\n })\n\n const { status } = responseJSON\n responseStatus = status\n } catch (error: unknown) {\n const message = `An error has occurred in the Stripe plugin REST handler: '${JSON.stringify(\n error,\n )}'`\n payload.logger.error(message)\n responseStatus = 500\n responseJSON = {\n message,\n }\n }\n\n return Response.json(responseJSON, {\n status: responseStatus,\n })\n}\n"],"names":["addDataAndFileToRequest","Forbidden","stripeProxy","stripeREST","args","responseStatus","responseJSON","pluginConfig","req","requestWithData","data","stripeArgs","stripeMethod","payload","user","stripeSecretKey","t","status","error","message","JSON","stringify","logger","Response","json"],"mappings":"AAEA,SAASA,uBAAuB,EAAEC,SAAS,QAAQ,UAAS;AAI5D,SAASC,WAAW,QAAQ,8BAA6B;AAEzD,OAAO,MAAMC,aAAa,OAAOC;IAI/B,IAAIC,iBAAiB;IACrB,IAAIC;IAEJ,MAAM,EAAEC,YAAY,EAAEC,GAAG,EAAE,GAAGJ;IAE9B,MAAMJ,wBAAwBQ;IAE9B,MAAMC,kBAAkBD;IAExB,MAAM,EACJE,MAAM,EACJC,UAAU,EACVC,YAAY,EACb,EACDC,OAAO,EACPC,IAAI,EACL,GAAGL;IAEJ,MAAM,EAAEM,eAAe,EAAE,GAAGR;IAE5B,IAAI;QACF,IAAI,CAACO,MAAM;YACT,+CAA+C;YAC/C,MAAM,IAAIb,UAAUO,IAAIQ,CAAC;QAC3B;QAEAV,eAAe,MAAMJ,YAAY;YAC/BS;YACAC;YACAG;QACF;QAEA,MAAM,EAAEE,MAAM,EAAE,GAAGX;QACnBD,iBAAiBY;IACnB,EAAE,OAAOC,OAAgB;QACvB,MAAMC,UAAU,CAAC,0DAA0D,EAAEC,KAAKC,SAAS,CACzFH,OACA,CAAC,CAAC;QACJL,QAAQS,MAAM,CAACJ,KAAK,CAACC;QACrBd,iBAAiB;QACjBC,eAAe;YACba;QACF;IACF;IAEA,OAAOI,SAASC,IAAI,CAAClB,cAAc;QACjCW,QAAQZ;IACV;AACF,EAAC"}
1
+ {"version":3,"sources":["../../src/routes/rest.ts"],"sourcesContent":["import type { PayloadRequest } from 'payload'\n\nimport { addDataAndFileToRequest, Forbidden } from 'payload'\n\nimport type { StripePluginConfig } from '../types.js'\n\nimport { stripeProxy } from '../utilities/stripeProxy.js'\n\nexport const stripeREST = async (args: {\n pluginConfig: StripePluginConfig\n req: PayloadRequest\n}): Promise<any> => {\n let responseStatus = 200\n let responseJSON\n\n const { pluginConfig, req } = args\n\n await addDataAndFileToRequest(req)\n\n const requestWithData = req\n const { data, payload, user } = requestWithData\n\n const { stripeSecretKey } = pluginConfig\n\n try {\n if (!user) {\n // TODO: make this customizable from the config\n throw new Forbidden(req.t)\n }\n\n responseJSON = await stripeProxy({\n stripeArgs: data?.stripeArgs, // example: ['cus_MGgt3Tuj3D66f2'] or [{ limit: 100 }, { stripeAccount: 'acct_1J9Z4pKZ4Z4Z4Z4Z' }]\n stripeMethod: data?.stripeMethod, // example: 'subscriptions.list',\n stripeSecretKey,\n })\n\n const { status } = responseJSON\n responseStatus = status\n } catch (error: unknown) {\n const message = `An error has occurred in the Stripe plugin REST handler: '${JSON.stringify(\n error,\n )}'`\n payload.logger.error(message)\n responseStatus = 500\n responseJSON = {\n message,\n }\n }\n\n return Response.json(responseJSON, {\n status: responseStatus,\n })\n}\n"],"names":["addDataAndFileToRequest","Forbidden","stripeProxy","stripeREST","args","responseStatus","responseJSON","pluginConfig","req","requestWithData","data","payload","user","stripeSecretKey","t","stripeArgs","stripeMethod","status","error","message","JSON","stringify","logger","Response","json"],"mappings":"AAEA,SAASA,uBAAuB,EAAEC,SAAS,QAAQ,UAAS;AAI5D,SAASC,WAAW,QAAQ,8BAA6B;AAEzD,OAAO,MAAMC,aAAa,OAAOC;IAI/B,IAAIC,iBAAiB;IACrB,IAAIC;IAEJ,MAAM,EAAEC,YAAY,EAAEC,GAAG,EAAE,GAAGJ;IAE9B,MAAMJ,wBAAwBQ;IAE9B,MAAMC,kBAAkBD;IACxB,MAAM,EAAEE,IAAI,EAAEC,OAAO,EAAEC,IAAI,EAAE,GAAGH;IAEhC,MAAM,EAAEI,eAAe,EAAE,GAAGN;IAE5B,IAAI;QACF,IAAI,CAACK,MAAM;YACT,+CAA+C;YAC/C,MAAM,IAAIX,UAAUO,IAAIM,CAAC;QAC3B;QAEAR,eAAe,MAAMJ,YAAY;YAC/Ba,YAAYL,MAAMK;YAClBC,cAAcN,MAAMM;YACpBH;QACF;QAEA,MAAM,EAAEI,MAAM,EAAE,GAAGX;QACnBD,iBAAiBY;IACnB,EAAE,OAAOC,OAAgB;QACvB,MAAMC,UAAU,CAAC,0DAA0D,EAAEC,KAAKC,SAAS,CACzFH,OACA,CAAC,CAAC;QACJP,QAAQW,MAAM,CAACJ,KAAK,CAACC;QACrBd,iBAAiB;QACjBC,eAAe;YACba;QACF;IACF;IAEA,OAAOI,SAASC,IAAI,CAAClB,cAAc;QACjCW,QAAQZ;IACV;AACF,EAAC"}
@@ -25,7 +25,7 @@ export const stripeWebhooks = async (args)=>{
25
25
  returnStatus = 400;
26
26
  }
27
27
  if (event) {
28
- handleWebhooks({
28
+ void handleWebhooks({
29
29
  config,
30
30
  event,
31
31
  payload: req.payload,
@@ -35,7 +35,7 @@ export const stripeWebhooks = async (args)=>{
35
35
  });
36
36
  // Fire external webhook handlers if they exist
37
37
  if (typeof webhooks === 'function') {
38
- webhooks({
38
+ void webhooks({
39
39
  config,
40
40
  event,
41
41
  payload: req.payload,
@@ -47,7 +47,7 @@ export const stripeWebhooks = async (args)=>{
47
47
  if (typeof webhooks === 'object') {
48
48
  const webhookEventHandler = webhooks[event.type];
49
49
  if (typeof webhookEventHandler === 'function') {
50
- webhookEventHandler({
50
+ void webhookEventHandler({
51
51
  config,
52
52
  event,
53
53
  payload: req.payload,
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/routes/webhooks.ts"],"sourcesContent":["import type { Config as PayloadConfig, PayloadRequest } from 'payload'\n\nimport Stripe from 'stripe'\n\nimport type { StripePluginConfig } from '../types.js'\n\nimport { handleWebhooks } from '../webhooks/index.js'\n\nexport const stripeWebhooks = async (args: {\n config: PayloadConfig\n pluginConfig: StripePluginConfig\n req: PayloadRequest\n}): Promise<any> => {\n const { config, pluginConfig, req } = args\n let returnStatus = 200\n\n const { stripeSecretKey, stripeWebhooksEndpointSecret, webhooks } = pluginConfig\n\n if (stripeWebhooksEndpointSecret) {\n const stripe = new Stripe(stripeSecretKey, {\n // api version can only be the latest, stripe recommends ts ignoring it\n apiVersion: '2022-08-01',\n appInfo: {\n name: 'Stripe Payload Plugin',\n url: 'https://payloadcms.com',\n },\n })\n\n const body = await req.text()\n const stripeSignature = req.headers.get('stripe-signature')\n\n if (stripeSignature) {\n let event: Stripe.Event | undefined\n\n try {\n event = stripe.webhooks.constructEvent(body, stripeSignature, stripeWebhooksEndpointSecret)\n } catch (err: unknown) {\n const msg: string = err instanceof Error ? err.message : JSON.stringify(err)\n req.payload.logger.error(`Error constructing Stripe event: ${msg}`)\n returnStatus = 400\n }\n\n if (event) {\n handleWebhooks({\n config,\n event,\n payload: req.payload,\n pluginConfig,\n req,\n stripe,\n })\n\n // Fire external webhook handlers if they exist\n if (typeof webhooks === 'function') {\n webhooks({\n config,\n event,\n payload: req.payload,\n pluginConfig,\n req,\n stripe,\n })\n }\n\n if (typeof webhooks === 'object') {\n const webhookEventHandler = webhooks[event.type]\n if (typeof webhookEventHandler === 'function') {\n webhookEventHandler({\n config,\n event,\n payload: req.payload,\n pluginConfig,\n req,\n stripe,\n })\n }\n }\n }\n }\n }\n\n return Response.json(\n { received: true },\n {\n status: returnStatus,\n },\n )\n}\n"],"names":["Stripe","handleWebhooks","stripeWebhooks","args","config","pluginConfig","req","returnStatus","stripeSecretKey","stripeWebhooksEndpointSecret","webhooks","stripe","apiVersion","appInfo","name","url","body","text","stripeSignature","headers","get","event","constructEvent","err","msg","Error","message","JSON","stringify","payload","logger","error","webhookEventHandler","type","Response","json","received","status"],"mappings":"AAEA,OAAOA,YAAY,SAAQ;AAI3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C;4BACAK;wBACF;oBACF;gBACF;YACF;QACF;IACF;IAEA,OAAOuB,SAASC,IAAI,CAClB;QAAEC,UAAU;IAAK,GACjB;QACEC,QAAQ9B;IACV;AAEJ,EAAC"}
1
+ {"version":3,"sources":["../../src/routes/webhooks.ts"],"sourcesContent":["import type { Config as PayloadConfig, PayloadRequest } from 'payload'\n\nimport Stripe from 'stripe'\n\nimport type { StripePluginConfig } from '../types.js'\n\nimport { handleWebhooks } from '../webhooks/index.js'\n\nexport const stripeWebhooks = async (args: {\n config: PayloadConfig\n pluginConfig: StripePluginConfig\n req: PayloadRequest\n}): Promise<any> => {\n const { config, pluginConfig, req } = args\n let returnStatus = 200\n\n const { stripeSecretKey, stripeWebhooksEndpointSecret, webhooks } = pluginConfig\n\n if (stripeWebhooksEndpointSecret) {\n const stripe = new Stripe(stripeSecretKey, {\n // api version can only be the latest, stripe recommends ts ignoring it\n apiVersion: '2022-08-01',\n appInfo: {\n name: 'Stripe Payload Plugin',\n url: 'https://payloadcms.com',\n },\n })\n\n const body = await req.text!()\n const stripeSignature = req.headers.get('stripe-signature')\n\n if (stripeSignature) {\n let event: Stripe.Event | undefined\n\n try {\n event = stripe.webhooks.constructEvent(body, stripeSignature, stripeWebhooksEndpointSecret)\n } catch (err: unknown) {\n const msg: string = err instanceof Error ? err.message : JSON.stringify(err)\n req.payload.logger.error(`Error constructing Stripe event: ${msg}`)\n returnStatus = 400\n }\n\n if (event) {\n void handleWebhooks({\n config,\n event,\n payload: req.payload,\n pluginConfig,\n req,\n stripe,\n })\n\n // Fire external webhook handlers if they exist\n if (typeof webhooks === 'function') {\n void webhooks({\n config,\n event,\n payload: req.payload,\n pluginConfig,\n req,\n stripe,\n })\n }\n\n if (typeof webhooks === 'object') {\n const webhookEventHandler = webhooks[event.type]\n if (typeof webhookEventHandler === 'function') {\n void webhookEventHandler({\n config,\n event,\n payload: req.payload,\n pluginConfig,\n req,\n stripe,\n })\n }\n }\n }\n }\n }\n\n return Response.json(\n { received: true },\n {\n status: returnStatus,\n },\n )\n}\n"],"names":["Stripe","handleWebhooks","stripeWebhooks","args","config","pluginConfig","req","returnStatus","stripeSecretKey","stripeWebhooksEndpointSecret","webhooks","stripe","apiVersion","appInfo","name","url","body","text","stripeSignature","headers","get","event","constructEvent","err","msg","Error","message","JSON","stringify","payload","logger","error","webhookEventHandler","type","Response","json","received","status"],"mappings":"AAEA,OAAOA,YAAY,SAAQ;AAI3B,SAASC,cAAc,QAAQ,uBAAsB;AAErD,OAAO,MAAMC,iBAAiB,OAAOC;IAKnC,MAAM,EAAEC,MAAM,EAAEC,YAAY,EAAEC,GAAG,EAAE,GAAGH;IACtC,IAAII,eAAe;IAEnB,MAAM,EAAEC,eAAe,EAAEC,4BAA4B,EAAEC,QAAQ,EAAE,GAAGL;IAEpE,IAAII,8BAA8B;QAChC,MAAME,SAAS,IAAIX,OAAOQ,iBAAiB;YACzC,uEAAuE;YACvEI,YAAY;YACZC,SAAS;gBACPC,MAAM;gBACNC,KAAK;YACP;QACF;QAEA,MAAMC,OAAO,MAAMV,IAAIW,IAAI;QAC3B,MAAMC,kBAAkBZ,IAAIa,OAAO,CAACC,GAAG,CAAC;QAExC,IAAIF,iBAAiB;YACnB,IAAIG;YAEJ,IAAI;gBACFA,QAAQV,OAAOD,QAAQ,CAACY,cAAc,CAACN,MAAME,iBAAiBT;YAChE,EAAE,OAAOc,KAAc;gBACrB,MAAMC,MAAcD,eAAeE,QAAQF,IAAIG,OAAO,GAAGC,KAAKC,SAAS,CAACL;gBACxEjB,IAAIuB,OAAO,CAACC,MAAM,CAACC,KAAK,CAAC,CAAC,iCAAiC,EAAEP,KAAK;gBAClEjB,eAAe;YACjB;YAEA,IAAIc,OAAO;gBACT,KAAKpB,eAAe;oBAClBG;oBACAiB;oBACAQ,SAASvB,IAAIuB,OAAO;oBACpBxB;oBACAC;oBACAK;gBACF;gBAEA,+CAA+C;gBAC/C,IAAI,OAAOD,aAAa,YAAY;oBAClC,KAAKA,SAAS;wBACZN;wBACAiB;wBACAQ,SAASvB,IAAIuB,OAAO;wBACpBxB;wBACAC;wBACAK;oBACF;gBACF;gBAEA,IAAI,OAAOD,aAAa,UAAU;oBAChC,MAAMsB,sBAAsBtB,QAAQ,CAACW,MAAMY,IAAI,CAAC;oBAChD,IAAI,OAAOD,wBAAwB,YAAY;wBAC7C,KAAKA,oBAAoB;4BACvB5B;4BACAiB;4BACAQ,SAASvB,IAAIuB,OAAO;4BACpBxB;4BACAC;4BACAK;wBACF;oBACF;gBACF;YACF;QACF;IACF;IAEA,OAAOuB,SAASC,IAAI,CAClB;QAAEC,UAAU;IAAK,GACjB;QACEC,QAAQ9B;IACV;AAEJ,EAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@payloadcms/plugin-stripe",
3
- "version": "3.38.0-internal.78d3ba4",
3
+ "version": "3.38.0",
4
4
  "description": "Stripe plugin for Payload",
5
5
  "keywords": [
6
6
  "payload",
@@ -54,20 +54,20 @@
54
54
  "lodash.get": "^4.4.2",
55
55
  "stripe": "^10.2.0",
56
56
  "uuid": "10.0.0",
57
- "@payloadcms/translations": "3.38.0-internal.78d3ba4",
58
- "@payloadcms/ui": "3.38.0-internal.78d3ba4"
57
+ "@payloadcms/translations": "3.38.0",
58
+ "@payloadcms/ui": "3.38.0"
59
59
  },
60
60
  "devDependencies": {
61
61
  "@types/lodash.get": "^4.4.7",
62
62
  "@types/react": "19.1.0",
63
63
  "@types/react-dom": "19.1.2",
64
64
  "@types/uuid": "10.0.0",
65
- "payload": "3.38.0-internal.78d3ba4",
66
- "@payloadcms/next": "3.38.0-internal.78d3ba4",
67
- "@payloadcms/eslint-config": "3.28.0"
65
+ "@payloadcms/next": "3.38.0",
66
+ "@payloadcms/eslint-config": "3.28.0",
67
+ "payload": "3.38.0"
68
68
  },
69
69
  "peerDependencies": {
70
- "payload": "3.38.0-internal.78d3ba4"
70
+ "payload": "3.38.0"
71
71
  },
72
72
  "publishConfig": {
73
73
  "registry": "https://registry.npmjs.org/"