@payloadcms/plugin-ecommerce 4.0.0-internal.d28e9fb → 4.0.0-internal.d927017

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.
Files changed (51) hide show
  1. package/LICENSE.md +1 -1
  2. package/dist/collections/addresses/hooks/beforeChange.d.ts.map +1 -1
  3. package/dist/collections/addresses/hooks/beforeChange.js +3 -2
  4. package/dist/collections/addresses/hooks/beforeChange.js.map +1 -1
  5. package/dist/collections/carts/endpoints/addItem.d.ts.map +1 -1
  6. package/dist/collections/carts/endpoints/clearCart.d.ts.map +1 -1
  7. package/dist/collections/carts/endpoints/mergeCart.d.ts.map +1 -1
  8. package/dist/collections/carts/endpoints/removeItem.d.ts.map +1 -1
  9. package/dist/collections/carts/endpoints/updateItem.d.ts.map +1 -1
  10. package/dist/collections/carts/hasCartSecretAccess.d.ts.map +1 -1
  11. package/dist/collections/carts/operations/addItem.d.ts.map +1 -1
  12. package/dist/collections/carts/operations/clearCart.d.ts.map +1 -1
  13. package/dist/collections/carts/operations/createRequestWithSecret.d.ts.map +1 -1
  14. package/dist/collections/carts/operations/mergeCart.d.ts.map +1 -1
  15. package/dist/collections/carts/operations/removeItem.d.ts.map +1 -1
  16. package/dist/collections/carts/operations/updateItem.d.ts.map +1 -1
  17. package/dist/endpoints/confirmOrder.d.ts.map +1 -1
  18. package/dist/endpoints/confirmOrder.js.map +1 -1
  19. package/dist/endpoints/initiatePayment.d.ts.map +1 -1
  20. package/dist/endpoints/initiatePayment.js.map +1 -1
  21. package/dist/exports/types.d.ts +1 -1
  22. package/dist/exports/types.d.ts.map +1 -1
  23. package/dist/exports/types.js.map +1 -1
  24. package/dist/fields/pricesField.d.ts.map +1 -1
  25. package/dist/fields/pricesField.js +39 -39
  26. package/dist/fields/pricesField.js.map +1 -1
  27. package/dist/index.d.ts +1 -2
  28. package/dist/index.d.ts.map +1 -1
  29. package/dist/index.js +24 -24
  30. package/dist/index.js.map +1 -1
  31. package/dist/react/provider/index.d.ts.map +1 -1
  32. package/dist/react/provider/index.js.map +1 -1
  33. package/dist/react/provider/utilities.d.ts.map +1 -1
  34. package/dist/types/index.d.ts +11 -2
  35. package/dist/types/index.d.ts.map +1 -1
  36. package/dist/types/index.js.map +1 -1
  37. package/dist/ui/PriceInput/FormattedInput.js +2 -2
  38. package/dist/ui/PriceInput/FormattedInput.js.map +1 -1
  39. package/dist/ui/PriceInput/index.css +19 -31
  40. package/dist/ui/PriceInput/index.d.ts.map +1 -1
  41. package/dist/ui/PriceInput/index.js.map +1 -1
  42. package/dist/ui/PriceRowLabel/index.css +2 -2
  43. package/dist/ui/VariantOptionsSelector/index.css +8 -10
  44. package/dist/ui/utilities.d.ts.map +1 -1
  45. package/dist/utilities/accessComposition.d.ts.map +1 -1
  46. package/dist/utilities/getCollectionSlugMap.d.ts.map +1 -1
  47. package/dist/utilities/pushTypeScriptProperties.d.ts.map +1 -1
  48. package/dist/utilities/pushTypeScriptProperties.js +1 -1
  49. package/dist/utilities/pushTypeScriptProperties.js.map +1 -1
  50. package/dist/utilities/sanitizePluginConfig.d.ts.map +1 -1
  51. package/package.json +7 -7
package/LICENSE.md CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2018-2025 Payload CMS, Inc. <info@payloadcms.com>
3
+ Copyright (c) 2018-2026 Payload CMS, LLC <info@payloadcms.com>
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining
6
6
  a copy of this software and associated documentation files (the
@@ -1 +1 @@
1
- {"version":3,"file":"beforeChange.d.ts","sourceRoot":"","sources":["../../../../src/collections/addresses/hooks/beforeChange.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,0BAA0B,EAAE,WAAW,EAAE,MAAM,SAAS,CAAA;AAEtE,UAAU,KAAK;IACb,UAAU,CAAC,EAAE,WAAW,CAAA;CACzB;AAED,eAAO,MAAM,YAAY,EAAE,CAAC,IAAI,EAAE,KAAK,KAAK,0BAgBzC,CAAA"}
1
+ {"version":3,"file":"beforeChange.d.ts","sourceRoot":"","sources":["../../../../src/collections/addresses/hooks/beforeChange.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,0BAA0B,EAAE,WAAW,EAAE,MAAM,SAAS,CAAA;AAEtE,UAAU,KAAK;IACb,UAAU,CAAC,EAAE,WAAW,CAAA;CACzB;AAED,eAAO,MAAM,YAAY,EAAE,CAAC,IAAI,EAAE,KAAK,KAAK,0BAiBzC,CAAA"}
@@ -1,9 +1,10 @@
1
- export const beforeChange = ({ isCustomer })=>async ({ data, req })=>{
1
+ export const beforeChange = ({ isCustomer })=>async (hookArgs)=>{
2
+ const { data, req } = hookArgs;
2
3
  if (!isCustomer) {
3
4
  return data;
4
5
  }
5
6
  const userIsCustomer = await isCustomer({
6
- req
7
+ ...hookArgs
7
8
  });
8
9
  // Ensure that the customer field is set to the current user's ID if the user is a customer.
9
10
  // Admins can set to any customer.
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/collections/addresses/hooks/beforeChange.ts"],"sourcesContent":["import type { CollectionBeforeChangeHook, FieldAccess } from 'payload'\n\ninterface Props {\n isCustomer?: FieldAccess\n}\n\nexport const beforeChange: (args: Props) => CollectionBeforeChangeHook =\n ({ isCustomer }) =>\n async ({ data, req }) => {\n if (!isCustomer) {\n return data\n }\n\n const userIsCustomer = await isCustomer({ req })\n\n // Ensure that the customer field is set to the current user's ID if the user is a customer.\n // Admins can set to any customer.\n if (req.user && userIsCustomer) {\n data.customer = req.user.id\n }\n\n return data\n }\n"],"names":["beforeChange","isCustomer","data","req","userIsCustomer","user","customer","id"],"mappings":"AAMA,OAAO,MAAMA,eACX,CAAC,EAAEC,UAAU,EAAE,GACf,OAAO,EAAEC,IAAI,EAAEC,GAAG,EAAE;QAClB,IAAI,CAACF,YAAY;YACf,OAAOC;QACT;QAEA,MAAME,iBAAiB,MAAMH,WAAW;YAAEE;QAAI;QAE9C,4FAA4F;QAC5F,kCAAkC;QAClC,IAAIA,IAAIE,IAAI,IAAID,gBAAgB;YAC9BF,KAAKI,QAAQ,GAAGH,IAAIE,IAAI,CAACE,EAAE;QAC7B;QAEA,OAAOL;IACT,EAAC"}
1
+ {"version":3,"sources":["../../../../src/collections/addresses/hooks/beforeChange.ts"],"sourcesContent":["import type { CollectionBeforeChangeHook, FieldAccess } from 'payload'\n\ninterface Props {\n isCustomer?: FieldAccess\n}\n\nexport const beforeChange: (args: Props) => CollectionBeforeChangeHook =\n ({ isCustomer }) =>\n async (hookArgs) => {\n const { data, req } = hookArgs\n if (!isCustomer) {\n return data\n }\n\n const userIsCustomer = await isCustomer({ ...hookArgs })\n\n // Ensure that the customer field is set to the current user's ID if the user is a customer.\n // Admins can set to any customer.\n if (req.user && userIsCustomer) {\n data.customer = req.user.id\n }\n\n return data\n }\n"],"names":["beforeChange","isCustomer","hookArgs","data","req","userIsCustomer","user","customer","id"],"mappings":"AAMA,OAAO,MAAMA,eACX,CAAC,EAAEC,UAAU,EAAE,GACf,OAAOC;QACL,MAAM,EAAEC,IAAI,EAAEC,GAAG,EAAE,GAAGF;QACtB,IAAI,CAACD,YAAY;YACf,OAAOE;QACT;QAEA,MAAME,iBAAiB,MAAMJ,WAAW;YAAE,GAAGC,QAAQ;QAAC;QAEtD,4FAA4F;QAC5F,kCAAkC;QAClC,IAAIE,IAAIE,IAAI,IAAID,gBAAgB;YAC9BF,KAAKI,QAAQ,GAAGH,IAAIE,IAAI,CAACE,EAAE;QAC7B;QAEA,OAAOL;IACT,EAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"addItem.d.ts","sourceRoot":"","sources":["../../../../src/collections/carts/endpoints/addItem.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAA;AAIvD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAA;AAI7D,KAAK,IAAI,GAAG;IACV,eAAe,CAAC,EAAE,eAAe,CAAA;IACjC,SAAS,EAAE,cAAc,CAAA;CAC1B,CAAA;AAED;;;;;;;;;GASG;AACH,eAAO,MAAM,eAAe,mCAAoC,IAAI,KAAG,QAyCrE,CAAA"}
1
+ {"version":3,"file":"addItem.d.ts","sourceRoot":"","sources":["../../../../src/collections/carts/endpoints/addItem.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAA;AAIvD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAA;AAI7D,KAAK,IAAI,GAAG;IACV,eAAe,CAAC,EAAE,eAAe,CAAA;IACjC,SAAS,EAAE,cAAc,CAAA;CAC1B,CAAA;AAED;;;;;;;;;GASG;AACH,eAAO,MAAM,eAAe,GAAI,gCAAgC,IAAI,KAAG,QAyCrE,CAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"clearCart.d.ts","sourceRoot":"","sources":["../../../../src/collections/carts/endpoints/clearCart.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAA;AAMvD,KAAK,IAAI,GAAG;IACV,SAAS,EAAE,cAAc,CAAA;CAC1B,CAAA;AAED;;;;;;;GAOG;AACH,eAAO,MAAM,iBAAiB,kBAAmB,IAAI,KAAG,QA6BtD,CAAA"}
1
+ {"version":3,"file":"clearCart.d.ts","sourceRoot":"","sources":["../../../../src/collections/carts/endpoints/clearCart.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAA;AAMvD,KAAK,IAAI,GAAG;IACV,SAAS,EAAE,cAAc,CAAA;CAC1B,CAAA;AAED;;;;;;;GAOG;AACH,eAAO,MAAM,iBAAiB,GAAI,eAAe,IAAI,KAAG,QA6BtD,CAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"mergeCart.d.ts","sourceRoot":"","sources":["../../../../src/collections/carts/endpoints/mergeCart.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAA;AAIvD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAA;AAI/D,KAAK,IAAI,GAAG;IACV,eAAe,CAAC,EAAE,aAAa,CAAC,iBAAiB,CAAC,CAAA;IAClD,SAAS,EAAE,cAAc,CAAA;CAC1B,CAAA;AAED;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,iBAAiB,mCAAoC,IAAI,KAAG,QAsDvE,CAAA"}
1
+ {"version":3,"file":"mergeCart.d.ts","sourceRoot":"","sources":["../../../../src/collections/carts/endpoints/mergeCart.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAA;AAIvD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAA;AAI/D,KAAK,IAAI,GAAG;IACV,eAAe,CAAC,EAAE,aAAa,CAAC,iBAAiB,CAAC,CAAA;IAClD,SAAS,EAAE,cAAc,CAAA;CAC1B,CAAA;AAED;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,iBAAiB,GAAI,gCAAgC,IAAI,KAAG,QAsDvE,CAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"removeItem.d.ts","sourceRoot":"","sources":["../../../../src/collections/carts/endpoints/removeItem.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAA;AAMvD,KAAK,IAAI,GAAG;IACV,SAAS,EAAE,cAAc,CAAA;CAC1B,CAAA;AAED;;;;;;;;GAQG;AACH,eAAO,MAAM,kBAAkB,kBAAmB,IAAI,KAAG,QAmCvD,CAAA"}
1
+ {"version":3,"file":"removeItem.d.ts","sourceRoot":"","sources":["../../../../src/collections/carts/endpoints/removeItem.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAA;AAMvD,KAAK,IAAI,GAAG;IACV,SAAS,EAAE,cAAc,CAAA;CAC1B,CAAA;AAED;;;;;;;;GAQG;AACH,eAAO,MAAM,kBAAkB,GAAI,eAAe,IAAI,KAAG,QAmCvD,CAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"updateItem.d.ts","sourceRoot":"","sources":["../../../../src/collections/carts/endpoints/updateItem.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAA;AAQvD,KAAK,IAAI,GAAG;IACV,SAAS,EAAE,cAAc,CAAA;CAC1B,CAAA;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AACH,eAAO,MAAM,kBAAkB,kBAAmB,IAAI,KAAG,QA6DvD,CAAA"}
1
+ {"version":3,"file":"updateItem.d.ts","sourceRoot":"","sources":["../../../../src/collections/carts/endpoints/updateItem.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAA;AAQvD,KAAK,IAAI,GAAG;IACV,SAAS,EAAE,cAAc,CAAA;CAC1B,CAAA;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AACH,eAAO,MAAM,kBAAkB,GAAI,eAAe,IAAI,KAAG,QA6DvD,CAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"hasCartSecretAccess.d.ts","sourceRoot":"","sources":["../../../src/collections/carts/hasCartSecretAccess.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,SAAS,CAAA;AAErC;;;;;;GAMG;AACH,eAAO,MAAM,mBAAmB,oBAAqB,OAAO,KAAG,MAkB9D,CAAA"}
1
+ {"version":3,"file":"hasCartSecretAccess.d.ts","sourceRoot":"","sources":["../../../src/collections/carts/hasCartSecretAccess.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,SAAS,CAAA;AAErC;;;;;;GAMG;AACH,eAAO,MAAM,mBAAmB,GAAI,iBAAiB,OAAO,KAAG,MAkB9D,CAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"addItem.d.ts","sourceRoot":"","sources":["../../../../src/collections/carts/operations/addItem.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAgB,mBAAmB,EAAE,MAAM,YAAY,CAAA;AAKhF;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,eAAO,MAAM,OAAO,SAAgB,WAAW,KAAG,OAAO,CAAC,mBAAmB,CA8E5E,CAAA"}
1
+ {"version":3,"file":"addItem.d.ts","sourceRoot":"","sources":["../../../../src/collections/carts/operations/addItem.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAgB,mBAAmB,EAAE,MAAM,YAAY,CAAA;AAKhF;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,eAAO,MAAM,OAAO,GAAU,MAAM,WAAW,KAAG,OAAO,CAAC,mBAAmB,CA8E5E,CAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"clearCart.d.ts","sourceRoot":"","sources":["../../../../src/collections/carts/operations/clearCart.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,aAAa,EAAE,MAAM,YAAY,CAAA;AAIpE;;;;;;;;;;;;;;;;GAgBG;AACH,eAAO,MAAM,SAAS,SAAgB,aAAa,KAAG,OAAO,CAAC,mBAAmB,CAsChF,CAAA"}
1
+ {"version":3,"file":"clearCart.d.ts","sourceRoot":"","sources":["../../../../src/collections/carts/operations/clearCart.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,aAAa,EAAE,MAAM,YAAY,CAAA;AAIpE;;;;;;;;;;;;;;;;GAgBG;AACH,eAAO,MAAM,SAAS,GAAU,MAAM,aAAa,KAAG,OAAO,CAAC,mBAAmB,CAsChF,CAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"createRequestWithSecret.d.ts","sourceRoot":"","sources":["../../../../src/collections/carts/operations/createRequestWithSecret.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,SAAS,CAAA;AAE7C;;;;;;;GAOG;AACH,eAAO,MAAM,uBAAuB,QAC7B,cAAc,GAAG,SAAS,UACvB,MAAM,GAAG,SAAS,KACzB,cAAc,GAAG,SAYnB,CAAA"}
1
+ {"version":3,"file":"createRequestWithSecret.d.ts","sourceRoot":"","sources":["../../../../src/collections/carts/operations/createRequestWithSecret.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,SAAS,CAAA;AAE7C;;;;;;;GAOG;AACH,eAAO,MAAM,uBAAuB,GAClC,KAAK,cAAc,GAAG,SAAS,EAC/B,QAAQ,MAAM,GAAG,SAAS,KACzB,cAAc,GAAG,SAYnB,CAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"mergeCart.d.ts","sourceRoot":"","sources":["../../../../src/collections/carts/operations/mergeCart.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,qBAAqB,EAAE,OAAO,EAAE,cAAc,EAAE,MAAM,SAAS,CAAA;AAE7F,OAAO,KAAK,EAAE,YAAY,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAA;AAwCnE,MAAM,MAAM,aAAa,GAAG;IAC1B;;;OAGG;IACH,eAAe,CAAC,EAAE,CAAC,IAAI,EAAE;QAAE,YAAY,EAAE,YAAY,CAAC;QAAC,OAAO,EAAE,YAAY,CAAA;KAAE,KAAK,OAAO,CAAA;IAC1F;;OAEG;IACH,SAAS,EAAE,cAAc,CAAA;IACzB;;OAEG;IACH,OAAO,EAAE,OAAO,CAAA;IAChB;;OAEG;IACH,GAAG,CAAC,EAAE,cAAc,CAAA;IACpB;;OAEG;IACH,YAAY,EAAE,qBAAqB,CAAA;IACnC;;OAEG;IACH,YAAY,EAAE,MAAM,CAAA;IACpB;;OAEG;IACH,YAAY,EAAE,qBAAqB,CAAA;CACpC,CAAA;AAED;;;;;;;;;;;;;;;GAeG;AACH,eAAO,MAAM,SAAS,SAAgB,aAAa,KAAG,OAAO,CAAC,mBAAmB,CA+GhF,CAAA"}
1
+ {"version":3,"file":"mergeCart.d.ts","sourceRoot":"","sources":["../../../../src/collections/carts/operations/mergeCart.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,qBAAqB,EAAE,OAAO,EAAE,cAAc,EAAE,MAAM,SAAS,CAAA;AAE7F,OAAO,KAAK,EAAE,YAAY,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAA;AAwCnE,MAAM,MAAM,aAAa,GAAG;IAC1B;;;OAGG;IACH,eAAe,CAAC,EAAE,CAAC,IAAI,EAAE;QAAE,YAAY,EAAE,YAAY,CAAC;QAAC,OAAO,EAAE,YAAY,CAAA;KAAE,KAAK,OAAO,CAAA;IAC1F;;OAEG;IACH,SAAS,EAAE,cAAc,CAAA;IACzB;;OAEG;IACH,OAAO,EAAE,OAAO,CAAA;IAChB;;OAEG;IACH,GAAG,CAAC,EAAE,cAAc,CAAA;IACpB;;OAEG;IACH,YAAY,EAAE,qBAAqB,CAAA;IACnC;;OAEG;IACH,YAAY,EAAE,MAAM,CAAA;IACpB;;OAEG;IACH,YAAY,EAAE,qBAAqB,CAAA;CACpC,CAAA;AAED;;;;;;;;;;;;;;;GAeG;AACH,eAAO,MAAM,SAAS,GAAU,MAAM,aAAa,KAAG,OAAO,CAAC,mBAAmB,CA+GhF,CAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"removeItem.d.ts","sourceRoot":"","sources":["../../../../src/collections/carts/operations/removeItem.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAgB,mBAAmB,EAAE,cAAc,EAAE,MAAM,YAAY,CAAA;AAInF;;;;;;;;;;;;;;;;;GAiBG;AACH,eAAO,MAAM,UAAU,SAAgB,cAAc,KAAG,OAAO,CAAC,mBAAmB,CAuDlF,CAAA"}
1
+ {"version":3,"file":"removeItem.d.ts","sourceRoot":"","sources":["../../../../src/collections/carts/operations/removeItem.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAgB,mBAAmB,EAAE,cAAc,EAAE,MAAM,YAAY,CAAA;AAInF;;;;;;;;;;;;;;;;;GAiBG;AACH,eAAO,MAAM,UAAU,GAAU,MAAM,cAAc,KAAG,OAAO,CAAC,mBAAmB,CAuDlF,CAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"updateItem.d.ts","sourceRoot":"","sources":["../../../../src/collections/carts/operations/updateItem.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAgB,mBAAmB,EAAE,cAAc,EAAE,MAAM,YAAY,CAAA;AAKnF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AACH,eAAO,MAAM,UAAU,SAAgB,cAAc,KAAG,OAAO,CAAC,mBAAmB,CA8ElF,CAAA"}
1
+ {"version":3,"file":"updateItem.d.ts","sourceRoot":"","sources":["../../../../src/collections/carts/operations/updateItem.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAgB,mBAAmB,EAAE,cAAc,EAAE,MAAM,YAAY,CAAA;AAKnF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AACH,eAAO,MAAM,UAAU,GAAU,MAAM,cAAc,KAAG,OAAO,CAAC,mBAAmB,CA8ElF,CAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"confirmOrder.d.ts","sourceRoot":"","sources":["../../src/endpoints/confirmOrder.ts"],"names":[],"mappings":"AAAA,OAAO,EAAuD,KAAK,QAAQ,EAAE,MAAM,SAAS,CAAA;AAE5F,OAAO,KAAK,EAAE,gBAAgB,EAAE,cAAc,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAA;AAE7F,KAAK,IAAI,GAAG;IACV;;OAEG;IACH,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,g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E,IAAI,KAAK,QAAQ,CAAC,SAAS,CAAC,CAAA;AAE9D;;;GAGG;AACH,eAAO,MAAM,mBAAmB,EAAE,mBA0L/B,CAAA"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/endpoints/confirmOrder.ts"],"sourcesContent":["import { addDataAndFileToRequest, type DefaultDocumentIDType, type Endpoint } from 'payload'\n\nimport type { CurrenciesConfig, PaymentAdapter, ProductsValidation } from '../types/index.js'\n\ntype Args = {\n /**\n * The slug of the carts collection, defaults to 'carts'.\n */\n cartsSlug?: string\n currenciesConfig: CurrenciesConfig\n /**\n * The slug of the customers collection, defaults to 'users'.\n */\n customersSlug?: string\n /**\n * The slug of the orders collection, defaults to 'orders'.\n */\n ordersSlug?: string\n paymentMethod: PaymentAdapter\n /**\n * The slug of the products collection, defaults to 'products'.\n */\n productsSlug?: string\n /**\n * Customise the validation used for checking products or variants before a transaction is created.\n */\n productsValidation?: ProductsValidation\n /**\n * The slug of the transactions collection, defaults to 'transactions'.\n */\n transactionsSlug?: string\n /**\n * The slug of the variants collection, defaults to 'variants'.\n */\n variantsSlug?: string\n}\n\ntype ConfirmOrderHandler = (args: Args) => Endpoint['handler']\n\n/**\n * Handles the endpoint for initiating payments. We will handle checking the amount and product and variant prices here before it is sent to the payment provider.\n * This is the first step in the payment process.\n */\nexport const confirmOrderHandler: ConfirmOrderHandler =\n ({\n cartsSlug = 'carts',\n currenciesConfig,\n customersSlug = 'users',\n ordersSlug = 'orders',\n paymentMethod,\n productsSlug = 'products',\n productsValidation,\n transactionsSlug = 'transactions',\n variantsSlug = 'variants',\n }) =>\n async (req) => {\n await addDataAndFileToRequest(req)\n\n const data = req.data\n const payload = req.payload\n const user = req.user\n\n let currency: string = currenciesConfig.defaultCurrency\n let cartID: DefaultDocumentIDType = data?.cartID\n let cart = undefined\n let customerEmail: string = user?.email ?? ''\n const cartSecret = data?.secret\n\n if (user) {\n if (user.cart?.docs && Array.isArray(user.cart.docs) && user.cart.docs.length > 0) {\n if (!cartID && user.cart.docs[0]) {\n // Use the user's cart instead\n if (typeof user.cart.docs[0] === 'object') {\n cartID = user.cart.docs[0].id\n cart = user.cart.docs[0]\n } else {\n cartID = user.cart.docs[0]\n }\n }\n }\n } else {\n // Get the email from the data if user is not available\n if (data?.customerEmail && typeof data.customerEmail === 'string') {\n customerEmail = data.customerEmail\n } else {\n return Response.json(\n {\n message: 'A customer email is required to make a purchase.',\n },\n {\n status: 400,\n },\n )\n }\n }\n\n if (!cart) {\n if (cartID) {\n // Add cart secret to query for guest cart access control\n if (cartSecret && typeof cartSecret === 'string') {\n req.query = req.query || {}\n req.query.secret = cartSecret\n }\n\n cart = await payload.findByID({\n id: cartID,\n collection: cartsSlug,\n depth: 2,\n overrideAccess: false,\n req,\n select: {\n id: true,\n currency: true,\n customerEmail: true,\n items: true,\n subtotal: true,\n },\n })\n\n if (!cart) {\n return Response.json(\n {\n message: `Cart with ID ${cartID} not found.`,\n },\n {\n status: 404,\n },\n )\n }\n } else {\n return Response.json(\n {\n message: 'Cart ID is required.',\n },\n {\n status: 400,\n },\n )\n }\n }\n\n if (cart.currency && typeof cart.currency === 'string') {\n currency = cart.currency\n }\n\n // Ensure the currency is provided or inferred in some way\n if (!currency) {\n return Response.json(\n {\n message: 'Currency is required.',\n },\n {\n status: 400,\n },\n )\n }\n\n try {\n const paymentResponse = await paymentMethod.confirmOrder({\n cartsSlug,\n customersSlug,\n data: {\n ...data,\n customerEmail,\n },\n ordersSlug,\n req,\n transactionsSlug,\n })\n\n if (paymentResponse.transactionID) {\n const transaction = await payload.findByID({\n id: paymentResponse.transactionID,\n collection: transactionsSlug,\n depth: 0,\n select: {\n id: true,\n items: true,\n },\n })\n\n if (transaction && Array.isArray(transaction.items) && transaction.items.length > 0) {\n for (const item of transaction.items) {\n if (item.variant) {\n const id = typeof item.variant === 'object' ? item.variant.id : item.variant\n\n await payload.db.updateOne({\n id,\n collection: variantsSlug,\n data: {\n inventory: {\n $inc: item.quantity * -1,\n },\n },\n })\n } else if (item.product) {\n const id = typeof item.product === 'object' ? item.product.id : item.product\n\n await payload.db.updateOne({\n id,\n collection: productsSlug,\n data: {\n inventory: {\n $inc: item.quantity * -1,\n },\n },\n })\n }\n }\n }\n }\n\n if ('paymentResponse.transactionID' in paymentResponse && paymentResponse.transactionID) {\n delete (paymentResponse as Partial<typeof paymentResponse>).transactionID\n }\n\n return Response.json(paymentResponse)\n } catch (error) {\n payload.logger.error(error, 'Error confirming order.')\n\n return Response.json(\n {\n message: 'Error confirming order.',\n },\n {\n status: 500,\n },\n )\n }\n }\n"],"names":["addDataAndFileToRequest","confirmOrderHandler","cartsSlug","currenciesConfig","customersSlug","ordersSlug","paymentMethod","productsSlug","productsValidation","transactionsSlug","variantsSlug","req","data","payload","user","currency","defaultCurrency","cartID","cart","undefined","customerEmail","email","cartSecret","secret","docs","Array","isArray","length","id","Response","json","message","status","query","findByID","collection","depth","overrideAccess","select","items","subtotal","paymentResponse","confirmOrder","transactionID","transaction","item","variant","db","updateOne","inventory","$inc","quantity","product","error","logger"],"mappings":"AAAA,SAASA,uBAAuB,QAAmD,UAAS;AAuC5F;;;CAGC,GACD,OAAO,MAAMC,sBACX,CAAC,EACCC,YAAY,OAAO,EACnBC,gBAAgB,EAChBC,gBAAgB,OAAO,EACvBC,aAAa,QAAQ,EACrBC,aAAa,EACbC,eAAe,UAAU,EACzBC,kBAAkB,EAClBC,mBAAmB,cAAc,EACjCC,eAAe,UAAU,EAC1B,GACD,OAAOC;QACL,MAAMX,wBAAwBW;QAE9B,MAAMC,OAAOD,IAAIC,IAAI;QACrB,MAAMC,UAAUF,IAAIE,OAAO;QAC3B,MAAMC,OAAOH,IAAIG,IAAI;QAErB,IAAIC,WAAmBZ,iBAAiBa,eAAe;QACvD,IAAIC,SAAgCL,MAAMK;QAC1C,IAAIC,OAAOC;QACX,IAAIC,gBAAwBN,MAAMO,SAAS;QAC3C,MAAMC,aAAaV,MAAMW;QAEzB,IAAIT,MAAM;YACR,IAAIA,KAAKI,I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B,KAAKO,OAAO,KAAK,WAAWP,KAAKO,OAAO,CAACxB,EAAE,GAAGiB,KAAKO,OAAO;4BAE5E,MAAMvC,QAAQkC,EAAE,CAACC,SAAS,CAAC;gCACzBpB;gCACAO,YAAY5B;gCACZK,MAAM;oCACJqC,WAAW;wCACTC,MAAML,KAAKM,QAAQ,GAAG,CAAC;oCACzB;gCACF;4BACF;wBACF;oBACF;gBACF;YACF;YAEA,IAAI,mCAAmCV,mBAAmBA,gBAAgBE,aAAa,EAAE;gBACvF,OAAO,AAACF,gBAAoDE,aAAa;YAC3E;YAEA,OAAOd,SAASC,IAAI,CAACW;QACvB,EAAE,OAAOY,OAAO;YACdxC,QAAQyC,MAAM,CAACD,KAAK,CAACA,OAAO;YAE5B,OAAOxB,SAASC,IAAI,CAClB;gBACEC,SAAS;YACX,GACA;gBACEC,QAAQ;YACV;QAEJ;IACF,EAAC"}
1
+ {"version":3,"sources":["../../src/endpoints/confirmOrder.ts"],"sourcesContent":["import { addDataAndFileToRequest, type DefaultDocumentIDType, type Endpoint } from 'payload'\n\nimport type {\n CurrenciesConfig,\n PaymentAdapter,\n ProductsValidation,\n UserWithCart,\n} from '../types/index.js'\n\ntype Args = {\n /**\n * The slug of the carts collection, defaults to 'carts'.\n */\n cartsSlug?: string\n currenciesConfig: CurrenciesConfig\n /**\n * The slug of the customers collection, defaults to 'users'.\n */\n customersSlug?: string\n /**\n * The slug of the orders collection, defaults to 'orders'.\n */\n ordersSlug?: string\n paymentMethod: PaymentAdapter\n /**\n * The slug of the products collection, defaults to 'products'.\n */\n productsSlug?: string\n /**\n * Customise the validation used for checking products or variants before a transaction is created.\n */\n productsValidation?: ProductsValidation\n /**\n * The slug of the transactions collection, defaults to 'transactions'.\n */\n transactionsSlug?: string\n /**\n * The slug of the variants collection, defaults to 'variants'.\n */\n variantsSlug?: string\n}\n\ntype ConfirmOrderHandler = (args: Args) => Endpoint['handler']\n\n/**\n * Handles the endpoint for initiating payments. We will handle checking the amount and product and variant prices here before it is sent to the payment provider.\n * This is the first step in the payment process.\n */\nexport const confirmOrderHandler: ConfirmOrderHandler =\n ({\n cartsSlug = 'carts',\n currenciesConfig,\n customersSlug = 'users',\n ordersSlug = 'orders',\n paymentMethod,\n productsSlug = 'products',\n productsValidation,\n transactionsSlug = 'transactions',\n variantsSlug = 'variants',\n }) =>\n async (req) => {\n await addDataAndFileToRequest(req)\n\n const data = req.data\n const payload = req.payload\n const user = req.user as null | UserWithCart\n\n let currency: string = currenciesConfig.defaultCurrency\n let cartID: DefaultDocumentIDType = data?.cartID\n let cart = undefined\n let customerEmail: string = user?.email ?? ''\n const cartSecret = data?.secret\n\n if (user) {\n if (user.cart?.docs && Array.isArray(user.cart.docs) && user.cart.docs.length > 0) {\n if (!cartID && user.cart.docs[0]) {\n // Use the user's cart instead\n if (typeof user.cart.docs[0] === 'object') {\n cartID = user.cart.docs[0].id\n cart = user.cart.docs[0]\n } else {\n cartID = user.cart.docs[0]\n }\n }\n }\n } else {\n // Get the email from the data if user is not available\n if (data?.customerEmail && typeof data.customerEmail === 'string') {\n customerEmail = data.customerEmail\n } else {\n return Response.json(\n {\n message: 'A customer email is required to make a purchase.',\n },\n {\n status: 400,\n },\n )\n }\n }\n\n if (!cart) {\n if (cartID) {\n // Add cart secret to query for guest cart access control\n if (cartSecret && typeof cartSecret === 'string') {\n req.query = req.query || {}\n req.query.secret = cartSecret\n }\n\n cart = await payload.findByID({\n id: cartID,\n collection: cartsSlug,\n depth: 2,\n overrideAccess: false,\n req,\n select: {\n id: true,\n currency: true,\n customerEmail: true,\n items: true,\n subtotal: true,\n },\n })\n\n if (!cart) {\n return Response.json(\n {\n message: `Cart with ID ${cartID} not found.`,\n },\n {\n status: 404,\n },\n )\n }\n } else {\n return Response.json(\n {\n message: 'Cart ID is required.',\n },\n {\n status: 400,\n },\n )\n }\n }\n\n if (cart.currency && typeof cart.currency === 'string') {\n currency = cart.currency\n }\n\n // Ensure the currency is provided or inferred in some way\n if (!currency) {\n return Response.json(\n {\n message: 'Currency is required.',\n },\n {\n status: 400,\n },\n )\n }\n\n try {\n const paymentResponse = await paymentMethod.confirmOrder({\n cartsSlug,\n customersSlug,\n data: {\n ...data,\n customerEmail,\n },\n ordersSlug,\n req,\n transactionsSlug,\n })\n\n if (paymentResponse.transactionID) {\n const transaction = await payload.findByID({\n id: paymentResponse.transactionID,\n collection: transactionsSlug,\n depth: 0,\n select: {\n id: true,\n items: true,\n },\n })\n\n if (transaction && Array.isArray(transaction.items) && transaction.items.length > 0) {\n for (const item of transaction.items) {\n if (item.variant) {\n const id = typeof item.variant === 'object' ? item.variant.id : item.variant\n\n await payload.db.updateOne({\n id,\n collection: variantsSlug,\n data: {\n inventory: {\n $inc: item.quantity * -1,\n },\n },\n })\n } else if (item.product) {\n const id = typeof item.product === 'object' ? item.product.id : item.product\n\n await payload.db.updateOne({\n id,\n collection: productsSlug,\n data: {\n inventory: {\n $inc: item.quantity * -1,\n },\n },\n })\n }\n }\n }\n }\n\n if ('paymentResponse.transactionID' in paymentResponse && paymentResponse.transactionID) {\n delete (paymentResponse as Partial<typeof paymentResponse>).transactionID\n }\n\n return Response.json(paymentResponse)\n } catch (error) {\n payload.logger.error(error, 'Error confirming order.')\n\n return Response.json(\n {\n message: 'Error confirming order.',\n },\n {\n status: 500,\n },\n )\n }\n }\n"],"names":["addDataAndFileToRequest","confirmOrderHandler","cartsSlug","currenciesConfig","customersSlug","ordersSlug","paymentMethod","productsSlug","productsValidation","transactionsSlug","variantsSlug","req","data","payload","user","currency","defaultCurrency","cartID","cart","undefined","customerEmail","email","cartSecret","secret","docs","Array","isArray","length","id","Response","json","message","status","query","findByID","collection","depth","overrideAccess","select","items","subtotal","paymentResponse","confirmOrder","transactionID","transaction","item","variant","db","updateOne","inventory","$inc","quantity","product","error","logger"],"mappings":"AAAA,SAASA,uBAAuB,QAAmD,UAAS;AA4C5F;;;CAGC,GACD,OAAO,MAAMC,sBACX,CAAC,EACCC,YAAY,OAAO,EACnBC,gBAAgB,EAChB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AK,KAAKK,YAAYL,KAAK,CAACZ,MAAM,GAAG,GAAG;oBACnF,KAAK,MAAMkB,QAAQD,YAAYL,KAAK,CAAE;wBACpC,IAAIM,KAAKC,OAAO,EAAE;4BAChB,MAAMlB,KAAK,OAAOiB,KAAKC,OAAO,KAAK,WAAWD,KAAKC,OAAO,CAAClB,EAAE,GAAGiB,KAAKC,OAAO;4BAE5E,MAAMjC,QAAQkC,EAAE,CAACC,SAAS,CAAC;gCACzBpB;gCACAO,YAAYzB;gCACZE,MAAM;oCACJqC,WAAW;wCACTC,MAAML,KAAKM,QAAQ,GAAG,CAAC;oCACzB;gCACF;4BACF;wBACF,OAAO,IAAIN,KAAKO,OAAO,EAAE;4BACvB,MAAMxB,KAAK,OAAOiB,KAAKO,OAAO,KAAK,WAAWP,KAAKO,OAAO,CAACxB,EAAE,GAAGiB,KAAKO,OAAO;4BAE5E,MAAMvC,QAAQkC,EAAE,CAACC,SAAS,CAAC;gCACzBpB;gCACAO,YAAY5B;gCACZK,MAAM;oCACJqC,WAAW;wCACTC,MAAML,KAAKM,QAAQ,GAAG,CAAC;oCACzB;gCACF;4BACF;wBACF;oBACF;gBACF;YACF;YAEA,IAAI,mCAAmCV,mBAAmBA,gBAAgBE,aAAa,EAAE;gBACvF,OAAO,AAACF,gBAAoDE,aAAa;YAC3E;YAEA,OAAOd,SAASC,IAAI,CAACW;QACvB,EAAE,OAAOY,OAAO;YACdxC,QAAQyC,MAAM,CAACD,KAAK,CAACA,OAAO;YAE5B,OAAOxB,SAASC,IAAI,CAClB;gBACEC,SAAS;YACX,GACA;gBACEC,QAAQ;YACV;QAEJ;IACF,EAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"initiatePayment.d.ts","sourceRoot":"","sources":["../../src/endpoints/initiatePayment.ts"],"names":[],"mappings":"AAAA,OAAO,EAAuD,KAAK,QAAQ,EAAE,MAAM,SAAS,CAAA;AAE5F,OAAO,KAAK,EACV,gBAAgB,EAChB,cAAc,EACd,kBAAkB,EA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,EAAE,kBAAkB,CAAA;IACvC;;OAEG;IACH,gBAAgB,CAAC,EAAE,MAAM,CAAA;IACzB;;OAEG;IACH,YAAY,CAAC,EAAE,MAAM,CAAA;CACtB,CAAA;AAED,KAAK,eAAe,GAAG,CAAC,IAAI,EAAE,IAAI,KAAK,QAAQ,CAAC,SAAS,CAAC,CAAA;AAE1D;;;GAGG;AACH,eAAO,MAAM,sBAAsB,EAAE,eAiSlC,CAAA"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/endpoints/initiatePayment.ts"],"sourcesContent":["import { addDataAndFileToRequest, type DefaultDocumentIDType, type Endpoint } from 'payload'\n\nimport type {\n CurrenciesConfig,\n PaymentAdapter,\n ProductsValidation,\n SanitizedEcommercePluginConfig,\n} from '../types/index.js'\n\nimport { defaultProductsValidation } from '../utilities/defaultProductsValidation.js'\n\ntype Args = {\n /**\n * The slug of the carts collection, defaults to 'carts'.\n */\n cartsSlug?: string\n currenciesConfig: CurrenciesConfig\n /**\n * The slug of the customers collection, defaults to 'users'.\n */\n customersSlug?: string\n /**\n * Track inventory stock for the products and variants.\n * Accepts an object to override the default field name.\n */\n inventory?: SanitizedEcommercePluginConfig['inventory']\n paymentMethod: PaymentAdapter\n /**\n * The slug of the products collection, defaults to 'products'.\n */\n productsSlug?: string\n /**\n * Customise the validation used for checking products or variants before a transaction is created.\n */\n productsValidation?: ProductsValidation\n /**\n * The slug of the transactions collection, defaults to 'transactions'.\n */\n transactionsSlug?: string\n /**\n * The slug of the variants collection, defaults to 'variants'.\n */\n variantsSlug?: string\n}\n\ntype InitiatePayment = (args: Args) => Endpoint['handler']\n\n/**\n * Handles the endpoint for initiating payments. We will handle checking the amount and product and variant prices here before it is sent to the payment provider.\n * This is the first step in the payment process.\n */\nexport const initiatePaymentHandler: InitiatePayment =\n ({\n cartsSlug = 'carts',\n currenciesConfig,\n customersSlug = 'users',\n paymentMethod,\n productsSlug = 'products',\n productsValidation,\n transactionsSlug = 'transactions',\n variantsSlug = 'variants',\n }) =>\n async (req) => {\n await addDataAndFileToRequest(req)\n const data = req.data\n const payload = req.payload\n const user = req.user\n\n let currency: string = currenciesConfig.defaultCurrency\n let cartID: DefaultDocumentIDType = data?.cartID\n let cart = undefined\n const billingAddress = data?.billingAddress\n const shippingAddress = data?.shippingAddress\n const cartSecret = data?.secret\n\n let customerEmail: string = user?.email ?? ''\n\n if (user) {\n if (user.cart?.docs && Array.isArray(user.cart.docs) && user.cart.docs.length > 0) {\n if (!cartID && user.cart.docs[0]) {\n // Use the user's cart instead\n if (typeof user.cart.docs[0] === 'object') {\n cartID = user.cart.docs[0].id\n cart = user.cart.docs[0]\n } else {\n cartID = user.cart.docs[0]\n }\n }\n }\n } else {\n // Get the email from the data if user is not available\n if (data?.customerEmail && typeof data.customerEmail === 'string') {\n customerEmail = data.customerEmail\n } else {\n return Response.json(\n {\n message: 'A customer email is required to make a purchase.',\n },\n {\n status: 400,\n },\n )\n }\n }\n\n if (!cart) {\n if (cartID) {\n // Add cart secret to query for guest cart access control\n if (cartSecret && typeof cartSecret === 'string') {\n req.query = req.query || {}\n req.query.secret = cartSecret\n }\n\n cart = await payload.findByID({\n id: cartID,\n collection: cartsSlug,\n depth: 2,\n overrideAccess: false,\n req,\n select: {\n id: true,\n currency: true,\n customerEmail: true,\n items: true,\n subtotal: true,\n },\n })\n\n if (!cart) {\n return Response.json(\n {\n message: `Cart with ID ${cartID} not found.`,\n },\n {\n status: 404,\n },\n )\n }\n } else {\n return Response.json(\n {\n message: 'Cart ID is required.',\n },\n {\n status: 400,\n },\n )\n }\n }\n\n if (cart.currency && typeof cart.currency === 'string') {\n currency = cart.currency\n }\n\n // Ensure the currency is provided or inferred in some way\n if (!currency) {\n return Response.json(\n {\n message: 'Currency is required.',\n },\n {\n status: 400,\n },\n )\n }\n\n // Ensure the selected currency is supported\n if (\n !currenciesConfig.supportedCurrencies.find(\n (c) => c.code.toLocaleLowerCase() === currency.toLocaleLowerCase(),\n )\n ) {\n return Response.json(\n {\n message: `Currency ${currency} is not supported.`,\n },\n {\n status: 400,\n },\n )\n }\n\n // Verify the cart is available and items are present in an array\n if (!cart || !cart.items || !Array.isArray(cart.items) || cart.items.length === 0) {\n return Response.json(\n {\n message: 'Cart is required and must contain at least one item.',\n },\n {\n status: 400,\n },\n )\n }\n\n for (const item of cart.items) {\n // Target field to check the price based on the currency so we can validate the total\n const priceField = `priceIn${currency.toUpperCase()}`\n const quantity = item.quantity || 1\n\n // If the item has a product but no variant, we assume the product has a price in the specified currency\n if (item.product && !item.variant) {\n const id = typeof item.product === 'object' ? item.product.id : item.product\n\n const product = await payload.findByID({\n id,\n collection: productsSlug,\n depth: 0,\n select: {\n inventory: true,\n [priceField]: true,\n },\n })\n\n if (!product) {\n return Response.json(\n {\n message: `Product with ID ${item.product} not found.`,\n },\n {\n status: 404,\n },\n )\n }\n\n try {\n if (productsValidation) {\n await productsValidation({ currenciesConfig, currency, product, quantity })\n } else {\n await defaultProductsValidation({\n currenciesConfig,\n currency,\n product,\n quantity,\n })\n }\n } catch (error) {\n payload.logger.error(\n error,\n 'Error validating product or variant during payment initiation.',\n )\n\n return Response.json(\n {\n message: error,\n ...(error instanceof Error ? { cause: error.cause } : {}),\n },\n {\n status: 400,\n },\n )\n }\n\n if (item.variant) {\n const id = typeof item.variant === 'object' ? item.variant.id : item.variant\n\n const variant = await payload.findByID({\n id,\n collection: variantsSlug,\n depth: 0,\n select: {\n inventory: true,\n [priceField]: true,\n },\n })\n\n if (!variant) {\n return Response.json(\n {\n message: `Variant with ID ${item.variant} not found.`,\n },\n {\n status: 404,\n },\n )\n }\n\n try {\n if (productsValidation) {\n await productsValidation({\n currenciesConfig,\n currency,\n product: item.product,\n quantity,\n variant,\n })\n } else {\n await defaultProductsValidation({\n currenciesConfig,\n currency,\n product: item.product,\n quantity,\n variant,\n })\n }\n } catch (error) {\n payload.logger.error(\n error,\n 'Error validating product or variant during payment initiation.',\n )\n\n return Response.json(\n {\n message: error,\n },\n {\n status: 400,\n },\n )\n }\n }\n }\n }\n\n try {\n const paymentResponse = await paymentMethod.initiatePayment({\n customersSlug,\n data: {\n billingAddress,\n cart,\n currency,\n customerEmail,\n shippingAddress,\n },\n req,\n transactionsSlug,\n })\n\n return Response.json(paymentResponse)\n } catch (error) {\n payload.logger.error(error, 'Error initiating payment.')\n\n return Response.json(\n {\n message: 'Error initiating payment.',\n },\n {\n status: 500,\n },\n )\n }\n }\n"],"names":["addDataAndFileToRequest","defaultProductsValidation","initiatePaymentHandler","cartsSlug","currenciesConfig","customersSlug","paymentMethod","productsSlug","productsValidation","transactionsSlug","variantsSlug","req","data","payload","user","currency","defaultCurrency","cartID","cart","undefined","billingAddress","shippingAddress","cartSecret","secret","customerEmail","email","docs","Array","isArray","length","id","Response","json","message","status","query","findByID","collection","depth","overrideAccess","select","items","subtotal","supportedCurrencies","find","c","code","toLocaleLowerCase","item","priceField","toUpperCase","quantity","product","variant","inventory","error","logger","Error","cause","paymentResponse","initiatePayment"],"mappings":"AAAA,SAASA,uBAAuB,QAAmD,UAAS;AAS5F,SAASC,yBAAyB,QAAQ,4CAA2C;AAsCrF;;;CAGC,GACD,OAAO,MAAMC,yBACX,CAAC,EACCC,YAAY,OAAO,EACnBC,gBAAgB,EAChBC,gBAAgB,OAAO,EACvBC,aAAa,EACbC,eAAe,UAAU,EACzBC,kBAAkB,EAClBC,mBAAmB,cAAc,EACjCC,eAAe,UAAU,EAC1B,GACD,OAAOC;QACL,MAAMX,wBAAwBW;QAC9B,MAAMC,OAAOD,IAAIC,IAAI;QACrB,MAAMC,UAAUF,IAAIE,OAAO;QAC3B,MAAMC,OAAOH,IAAIG,IAAI;QAErB,IAAIC,WAAmBX,iBAAiBY,eAAe;QACvD,IAAIC,SAAgCL,MAAMK;QAC1C,IAAIC,OAAOC;QACX,MAAMC,iBAAiBR,MAAMQ;QAC7B,MAAMC,kBAAkBT,MAAMS;QAC9B,MAAMC,aAAaV,MAAMW;QAEzB,IAAIC,gBAAwBV,MAAMW,SAAS;QAE3C,I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oBAEJ;oBAEA,IAAI;wBACF,IAAI1B,oBAAoB;4BACtB,MAAMA,mBAAmB;gCACvBJ;gCACAW;gCACAqC,SAASJ,KAAKI,OAAO;gCACrBD;gCACAE;4BACF;wBACF,OAAO;4BACL,MAAMpD,0BAA0B;gCAC9BG;gCACAW;gCACAqC,SAASJ,KAAKI,OAAO;gCACrBD;gCACAE;4BACF;wBACF;oBACF,EAAE,OAAOE,OAAO;wBACd1C,QAAQ2C,MAAM,CAACD,KAAK,CAClBA,OACA;wBAGF,OAAOxB,SAASC,IAAI,CAClB;4BACEC,SAASsB;wBACX,GACA;4BACErB,QAAQ;wBACV;oBAEJ;gBACF;YACF;QACF;QAEA,IAAI;YACF,MAAMyB,kBAAkB,MAAMrD,cAAcsD,eAAe,CAAC;gBAC1DvD;gBACAO,MAAM;oBACJQ;oBACAF;oBACAH;oBACAS;oBACAH;gBACF;gBACAV;gBACAF;YACF;YAEA,OAAOsB,SAASC,IAAI,CAAC2B;QACvB,EAAE,OAAOJ,OAAO;YACd1C,QAAQ2C,MAAM,CAACD,KAAK,CAACA,OAAO;YAE5B,OAAOxB,SAASC,IAAI,CAClB;gBACEC,SAAS;YACX,GACA;gBACEC,QAAQ;YACV;QAEJ;IACF,EAAC"}
1
+ {"version":3,"sources":["../../src/endpoints/initiatePayment.ts"],"sourcesContent":["import { addDataAndFileToRequest, type DefaultDocumentIDType, type Endpoint } from 'payload'\n\nimport type {\n CurrenciesConfig,\n PaymentAdapter,\n ProductsValidation,\n SanitizedEcommercePluginConfig,\n UserWithCart,\n} from '../types/index.js'\n\nimport { defaultProductsValidation } from '../utilities/defaultProductsValidation.js'\n\ntype Args = {\n /**\n * The slug of the carts collection, defaults to 'carts'.\n */\n cartsSlug?: string\n currenciesConfig: CurrenciesConfig\n /**\n * The slug of the customers collection, defaults to 'users'.\n */\n customersSlug?: string\n /**\n * Track inventory stock for the products and variants.\n * Accepts an object to override the default field name.\n */\n inventory?: SanitizedEcommercePluginConfig['inventory']\n paymentMethod: PaymentAdapter\n /**\n * The slug of the products collection, defaults to 'products'.\n */\n productsSlug?: string\n /**\n * Customise the validation used for checking products or variants before a transaction is created.\n */\n productsValidation?: ProductsValidation\n /**\n * The slug of the transactions collection, defaults to 'transactions'.\n */\n transactionsSlug?: string\n /**\n * The slug of the variants collection, defaults to 'variants'.\n */\n variantsSlug?: string\n}\n\ntype InitiatePayment = (args: Args) => Endpoint['handler']\n\n/**\n * Handles the endpoint for initiating payments. We will handle checking the amount and product and variant prices here before it is sent to the payment provider.\n * This is the first step in the payment process.\n */\nexport const initiatePaymentHandler: InitiatePayment =\n ({\n cartsSlug = 'carts',\n currenciesConfig,\n customersSlug = 'users',\n paymentMethod,\n productsSlug = 'products',\n productsValidation,\n transactionsSlug = 'transactions',\n variantsSlug = 'variants',\n }) =>\n async (req) => {\n await addDataAndFileToRequest(req)\n const data = req.data\n const payload = req.payload\n const user = req.user as null | UserWithCart\n\n let currency: string = currenciesConfig.defaultCurrency\n let cartID: DefaultDocumentIDType = data?.cartID\n let cart: any = undefined\n const billingAddress = data?.billingAddress\n const shippingAddress = data?.shippingAddress\n const cartSecret = data?.secret\n\n let customerEmail: string = user?.email ?? ''\n\n if (user) {\n if (user.cart?.docs && Array.isArray(user.cart.docs) && user.cart.docs.length > 0) {\n if (!cartID && user.cart.docs[0]) {\n // Use the user's cart instead\n if (typeof user.cart.docs[0] === 'object') {\n cartID = user.cart.docs[0].id\n cart = user.cart.docs[0]\n } else {\n cartID = user.cart.docs[0]\n }\n }\n }\n } else {\n // Get the email from the data if user is not available\n if (data?.customerEmail && typeof data.customerEmail === 'string') {\n customerEmail = data.customerEmail\n } else {\n return Response.json(\n {\n message: 'A customer email is required to make a purchase.',\n },\n {\n status: 400,\n },\n )\n }\n }\n\n if (!cart) {\n if (cartID) {\n // Add cart secret to query for guest cart access control\n if (cartSecret && typeof cartSecret === 'string') {\n req.query = req.query || {}\n req.query.secret = cartSecret\n }\n\n cart = await payload.findByID({\n id: cartID,\n collection: cartsSlug,\n depth: 2,\n overrideAccess: false,\n req,\n select: {\n id: true,\n currency: true,\n customerEmail: true,\n items: true,\n subtotal: true,\n },\n })\n\n if (!cart) {\n return Response.json(\n {\n message: `Cart with ID ${cartID} not found.`,\n },\n {\n status: 404,\n },\n )\n }\n } else {\n return Response.json(\n {\n message: 'Cart ID is required.',\n },\n {\n status: 400,\n },\n )\n }\n }\n\n if (cart.currency && typeof cart.currency === 'string') {\n currency = cart.currency\n }\n\n // Ensure the currency is provided or inferred in some way\n if (!currency) {\n return Response.json(\n {\n message: 'Currency is required.',\n },\n {\n status: 400,\n },\n )\n }\n\n // Ensure the selected currency is supported\n if (\n !currenciesConfig.supportedCurrencies.find(\n (c) => c.code.toLocaleLowerCase() === currency.toLocaleLowerCase(),\n )\n ) {\n return Response.json(\n {\n message: `Currency ${currency} is not supported.`,\n },\n {\n status: 400,\n },\n )\n }\n\n // Verify the cart is available and items are present in an array\n if (!cart || !cart.items || !Array.isArray(cart.items) || cart.items.length === 0) {\n return Response.json(\n {\n message: 'Cart is required and must contain at least one item.',\n },\n {\n status: 400,\n },\n )\n }\n\n for (const item of cart.items) {\n // Target field to check the price based on the currency so we can validate the total\n const priceField = `priceIn${currency.toUpperCase()}`\n const quantity = item.quantity || 1\n\n // If the item has a product but no variant, we assume the product has a price in the specified currency\n if (item.product && !item.variant) {\n const id = typeof item.product === 'object' ? item.product.id : item.product\n\n const product = await payload.findByID({\n id,\n collection: productsSlug,\n depth: 0,\n select: {\n inventory: true,\n [priceField]: true,\n },\n })\n\n if (!product) {\n return Response.json(\n {\n message: `Product with ID ${item.product} not found.`,\n },\n {\n status: 404,\n },\n )\n }\n\n try {\n if (productsValidation) {\n await productsValidation({ currenciesConfig, currency, product, quantity })\n } else {\n await defaultProductsValidation({\n currenciesConfig,\n currency,\n product,\n quantity,\n })\n }\n } catch (error) {\n payload.logger.error(\n error,\n 'Error validating product or variant during payment initiation.',\n )\n\n return Response.json(\n {\n message: error,\n ...(error instanceof Error ? { cause: error.cause } : {}),\n },\n {\n status: 400,\n },\n )\n }\n\n if (item.variant) {\n const id = typeof item.variant === 'object' ? item.variant.id : item.variant\n\n const variant = await payload.findByID({\n id,\n collection: variantsSlug,\n depth: 0,\n select: {\n inventory: true,\n [priceField]: true,\n },\n })\n\n if (!variant) {\n return Response.json(\n {\n message: `Variant with ID ${item.variant} not found.`,\n },\n {\n status: 404,\n },\n )\n }\n\n try {\n if (productsValidation) {\n await productsValidation({\n currenciesConfig,\n currency,\n product: item.product,\n quantity,\n variant,\n })\n } else {\n await defaultProductsValidation({\n currenciesConfig,\n currency,\n product: item.product,\n quantity,\n variant,\n })\n }\n } catch (error) {\n payload.logger.error(\n error,\n 'Error validating product or variant during payment initiation.',\n )\n\n return Response.json(\n {\n message: error,\n },\n {\n status: 400,\n },\n )\n }\n }\n }\n }\n\n try {\n const paymentResponse = await paymentMethod.initiatePayment({\n customersSlug,\n data: {\n billingAddress,\n cart,\n currency,\n customerEmail,\n shippingAddress,\n },\n req,\n transactionsSlug,\n })\n\n return Response.json(paymentResponse)\n } catch (error) {\n payload.logger.error(error, 'Error initiating payment.')\n\n return Response.json(\n {\n message: 'Error initiating payment.',\n },\n {\n status: 500,\n },\n )\n }\n }\n"],"names":["addDataAndFileToRequest","defaultProductsValidation","initiatePaymentHandler","cartsSlug","currenciesConfig","customersSlug","paymentMethod","productsSlug","productsValidation","transactionsSlug","variantsSlug","req","data","payload","user","currency","defaultCurrency","cartID","cart","undefined","billingAddress","shippingAddress","cartSecret","secret","customerEmail","email","docs","Array","isArray","length","id","Response","json","message","status","query","findByID","collection","depth","overrideAccess","select","items","subtotal","supportedCurrencies","find","c","code","toLocaleLowerCase","item","priceField","toUpperCase","quantity","product","variant","inventory","error","logger","Error","cause","paymentResponse","initiatePayment"],"mappings":"AAAA,SAASA,uBAAuB,QAAmD,UAAS;AAU5F,SAASC,yBAAyB,QAAQ,4CAA2C;AAsCrF;;;CAGC,GACD,OAAO,MAAMC,yBACX,CAAC,EACCC,Y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X,GACA;gBACEC,QAAQ;YACV;QAEJ;IACF,EAAC"}
@@ -1,3 +1,3 @@
1
- export type { CollectionOverride, CollectionSlugMap, ContextProps, CountryType, CurrenciesConfig, Currency, EcommerceCollections, EcommerceConfig, EcommerceContextType, EcommercePluginConfig, PaymentAdapter, PaymentAdapterArgs, PaymentAdapterClient, PaymentAdapterClientArgs, ProductsValidation, SanitizedEcommercePluginConfig, } from '../types/index.js';
1
+ export type { ClientUserWithCart, CollectionOverride, CollectionSlugMap, ContextProps, CountryType, CurrenciesConfig, Currency, EcommerceCollections, EcommerceConfig, EcommerceContextType, EcommercePluginConfig, PaymentAdapter, PaymentAdapterArgs, PaymentAdapterClient, PaymentAdapterClientArgs, ProductsValidation, SanitizedEcommercePluginConfig, UserWithCart, } from '../types/index.js';
2
2
  export type { TypedEcommerce } from '../types/utilities.js';
3
3
  //# sourceMappingURL=types.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/exports/types.ts"],"names":[],"mappings":"AAAA,YAAY,EACV,kBAAkB,EAClB,iBAAiB,EACjB,YAAY,EACZ,WAAW,EACX,gBAAgB,EAChB,QAAQ,EACR,oBAAoB,EACpB,eAAe,EACf,oBAAoB,EACpB,qBAAqB,EACrB,cAAc,EACd,kBAAkB,EAClB,oBAAoB,EACpB,wBAAwB,EACxB,kBAAkB,EAClB,8BAA8B,GAC/B,MAAM,mBAAmB,CAAA;AAE1B,YAAY,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAA"}
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/exports/types.ts"],"names":[],"mappings":"AAAA,YAAY,EACV,kBAAkB,EAClB,kBAAkB,EAClB,iBAAiB,EACjB,YAAY,EACZ,WAAW,EACX,gBAAgB,EAChB,QAAQ,EACR,oBAAoB,EACpB,eAAe,EACf,oBAAoB,EACpB,qBAAqB,EACrB,cAAc,EACd,kBAAkB,EAClB,oBAAoB,EACpB,wBAAwB,EACxB,kBAAkB,EAClB,8BAA8B,EAC9B,YAAY,GACb,MAAM,mBAAmB,CAAA;AAE1B,YAAY,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAA"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/exports/types.ts"],"sourcesContent":["export type {\n CollectionOverride,\n CollectionSlugMap,\n ContextProps,\n CountryType,\n CurrenciesConfig,\n Currency,\n EcommerceCollections,\n EcommerceConfig,\n EcommerceContextType,\n EcommercePluginConfig,\n PaymentAdapter,\n PaymentAdapterArgs,\n PaymentAdapterClient,\n PaymentAdapterClientArgs,\n ProductsValidation,\n SanitizedEcommercePluginConfig,\n} from '../types/index.js'\n\nexport type { TypedEcommerce } from '../types/utilities.js'\n"],"names":[],"mappings":"AAmBA,WAA2D"}
1
+ {"version":3,"sources":["../../src/exports/types.ts"],"sourcesContent":["export type {\n ClientUserWithCart,\n CollectionOverride,\n CollectionSlugMap,\n ContextProps,\n CountryType,\n CurrenciesConfig,\n Currency,\n EcommerceCollections,\n EcommerceConfig,\n EcommerceContextType,\n EcommercePluginConfig,\n PaymentAdapter,\n PaymentAdapterArgs,\n PaymentAdapterClient,\n PaymentAdapterClientArgs,\n ProductsValidation,\n SanitizedEcommercePluginConfig,\n UserWithCart,\n} from '../types/index.js'\n\nexport type { TypedEcommerce } from '../types/utilities.js'\n"],"names":[],"mappings":"AAqBA,WAA2D"}
@@ -1 +1 @@
1
- {"version":3,"file":"pricesField.d.ts","sourceRoot":"","sources":["../../src/fields/pricesField.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,SAAS,CAAA;AAEzC,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAA;AAIzD,KAAK,KAAK,GAAG;IACX;;OAEG;IACH,eAAe,CAAC,EAAE,MAAM,CAAA;IACxB,gBAAgB,EAAE,gBAAgB,CAAA;CACnC,CAAA;AAED,eAAO,MAAM,WAAW,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,UAAU,EAuDrD,CAAA"}
1
+ {"version":3,"file":"pricesField.d.ts","sourceRoot":"","sources":["../../src/fields/pricesField.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAY,MAAM,SAAS,CAAA;AAEnD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAA;AAIzD,KAAK,KAAK,GAAG;IACX;;OAEG;IACH,eAAe,CAAC,EAAE,MAAM,CAAA;IACxB,gBAAgB,EAAE,gBAAgB,CAAA;CACnC,CAAA;AAED,eAAO,MAAM,WAAW,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,UAAU,EAuDrD,CAAA"}
@@ -1,54 +1,54 @@
1
1
  import { amountField } from './amountField.js';
2
2
  export const pricesField = ({ conditionalPath, currenciesConfig })=>{
3
3
  const currencies = currenciesConfig.supportedCurrencies;
4
- const fields = currencies.map((currency)=>{
4
+ const rows = currencies.map((currency)=>{
5
5
  const name = `priceIn${currency.code}`;
6
6
  const path = conditionalPath ? `${conditionalPath}.${name}Enabled` : `${name}Enabled`;
7
7
  return {
8
- type: 'group',
9
- admin: {
10
- description: 'Prices for this product in different currencies.'
11
- },
8
+ type: 'row',
12
9
  fields: [
13
10
  {
14
- type: 'row',
15
- fields: [
16
- {
17
- name: `${name}Enabled`,
18
- type: 'checkbox',
19
- admin: {
20
- style: {
21
- alignSelf: 'baseline',
22
- flex: '0 0 auto'
23
- }
24
- },
25
- label: ({ t })=>// @ts-expect-error - translations are not typed in plugins yet
26
- t('plugin-ecommerce:enableCurrencyPrice', {
27
- currency: currency.code
28
- })
29
- },
30
- amountField({
31
- currenciesConfig,
32
- currency,
33
- overrides: {
34
- name,
35
- admin: {
36
- condition: (_, siblingData)=>Boolean(siblingData?.[path]),
37
- description: ({ t })=>// @ts-expect-error - translations are not typed in plugins yet
38
- t('plugin-ecommerce:productPriceDescription')
39
- },
40
- // @ts-expect-error - translations are not typed in plugins yet
41
- label: ({ t })=>t('plugin-ecommerce:priceIn', {
42
- currency: currency.code
43
- })
44
- }
11
+ name: `${name}Enabled`,
12
+ type: 'checkbox',
13
+ admin: {
14
+ style: {
15
+ alignSelf: 'baseline',
16
+ flex: '0 0 auto'
17
+ }
18
+ },
19
+ label: ({ t })=>// @ts-expect-error - translations are not typed in plugins yet
20
+ t('plugin-ecommerce:enableCurrencyPrice', {
21
+ currency: currency.code
45
22
  })
46
- ]
47
- }
23
+ },
24
+ amountField({
25
+ currenciesConfig,
26
+ currency,
27
+ overrides: {
28
+ name,
29
+ admin: {
30
+ condition: (_, siblingData)=>Boolean(siblingData?.[path]),
31
+ description: ({ t })=>// @ts-expect-error - translations are not typed in plugins yet
32
+ t('plugin-ecommerce:productPriceDescription')
33
+ },
34
+ // @ts-expect-error - translations are not typed in plugins yet
35
+ label: ({ t })=>t('plugin-ecommerce:priceIn', {
36
+ currency: currency.code
37
+ })
38
+ }
39
+ })
48
40
  ]
49
41
  };
50
42
  });
51
- return fields;
43
+ return [
44
+ {
45
+ type: 'group',
46
+ admin: {
47
+ description: 'Prices for this product in different currencies.'
48
+ },
49
+ fields: rows
50
+ }
51
+ ];
52
52
  };
53
53
 
54
54
  //# sourceMappingURL=pricesField.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/fields/pricesField.ts"],"sourcesContent":["import type { GroupField } from 'payload'\n\nimport type { CurrenciesConfig } from '../types/index.js'\n\nimport { amountField } from './amountField.js'\n\ntype Props = {\n /**\n * Use this to specify a path for the condition.\n */\n conditionalPath?: string\n currenciesConfig: CurrenciesConfig\n}\n\nexport const pricesField: (props: Props) => GroupField[] = ({\n conditionalPath,\n currenciesConfig,\n}) => {\n const currencies = currenciesConfig.supportedCurrencies\n\n const fields: GroupField[] = currencies.map((currency) => {\n const name = `priceIn${currency.code}`\n\n const path = conditionalPath ? `${conditionalPath}.${name}Enabled` : `${name}Enabled`\n\n return {\n type: 'group',\n admin: {\n description: 'Prices for this product in different currencies.',\n },\n fields: [\n {\n type: 'row',\n fields: [\n {\n name: `${name}Enabled`,\n type: 'checkbox',\n admin: {\n style: {\n alignSelf: 'baseline',\n flex: '0 0 auto',\n },\n },\n label: ({ t }) =>\n // @ts-expect-error - translations are not typed in plugins yet\n t('plugin-ecommerce:enableCurrencyPrice', { currency: currency.code }),\n },\n amountField({\n currenciesConfig,\n currency,\n overrides: {\n name,\n admin: {\n condition: (_, siblingData) => Boolean(siblingData?.[path]),\n description: ({ t }) =>\n // @ts-expect-error - translations are not typed in plugins yet\n t('plugin-ecommerce:productPriceDescription'),\n },\n // @ts-expect-error - translations are not typed in plugins yet\n label: ({ t }) => t('plugin-ecommerce:priceIn', { currency: currency.code }),\n },\n }),\n ],\n },\n ],\n }\n })\n\n return fields\n}\n"],"names":["amountField","pricesField","conditionalPath","currenciesConfig","currencies","supportedCurrencies","fields","map","currency","name","code","path","type","admin","description","style","alignSelf","flex","label","t","overrides","condition","_","siblingData","Boolean"],"mappings":"AAIA,SAASA,WAAW,QAAQ,mBAAkB;AAU9C,OAAO,MAAMC,cAA8C,CAAC,EAC1DC,eAAe,EACfC,gBAAgB,EACjB;IACC,MAAMC,aAAaD,iBAAiBE,mBAAmB;IAEvD,MAAMC,SAAuBF,WAAWG,GAAG,CAAC,CAACC;QAC3C,MAAMC,OAAO,CAAC,OAAO,EAAED,SAASE,IAAI,EAAE;QAEtC,MAAMC,OAAOT,kBAAkB,GAAGA,gBAAgB,CAAC,EAAEO,KAAK,OAAO,CAAC,GAAG,GAAGA,KAAK,OAAO,CAAC;QAErF,OAAO;YACLG,MAAM;YACNC,OAAO;gBACLC,aAAa;YACf;YACAR,QAAQ;gBACN;oBACEM,MAAM;oBACNN,QAAQ;wBACN;4BACEG,MAAM,GAAGA,KAAK,OAAO,CAAC;4BACtBG,MAAM;4BACNC,OAAO;gCACLE,OAAO;oCACLC,WAAW;oCACXC,MAAM;gCACR;4BACF;4BACAC,OAAO,CAAC,EAAEC,CAAC,EAAE,GACX,+DAA+D;gCAC/DA,EAAE,wCAAwC;oCAAEX,UAAUA,SAASE,IAAI;gCAAC;wBACxE;wBACAV,YAAY;4BACVG;4BACAK;4BACAY,WAAW;gCACTX;gCACAI,OAAO;oCACLQ,WAAW,CAACC,GAAGC,cAAgBC,QAAQD,aAAa,CAACZ,KAAK;oCAC1DG,aAAa,CAAC,EAAEK,CAAC,EAAE,GACjB,+DAA+D;wCAC/DA,EAAE;gCACN;gCACA,+DAA+D;gCAC/DD,OAAO,CAAC,EAAEC,CAAC,EAAE,GAAKA,EAAE,4BAA4B;wCAAEX,UAAUA,SAASE,IAAI;oCAAC;4BAC5E;wBACF;qBACD;gBACH;aACD;QACH;IACF;IAEA,OAAOJ;AACT,EAAC"}
1
+ {"version":3,"sources":["../../src/fields/pricesField.ts"],"sourcesContent":["import type { GroupField, RowField } from 'payload'\n\nimport type { CurrenciesConfig } from '../types/index.js'\n\nimport { amountField } from './amountField.js'\n\ntype Props = {\n /**\n * Use this to specify a path for the condition.\n */\n conditionalPath?: string\n currenciesConfig: CurrenciesConfig\n}\n\nexport const pricesField: (props: Props) => GroupField[] = ({\n conditionalPath,\n currenciesConfig,\n}) => {\n const currencies = currenciesConfig.supportedCurrencies\n\n const rows: RowField[] = currencies.map((currency) => {\n const name = `priceIn${currency.code}`\n\n const path = conditionalPath ? `${conditionalPath}.${name}Enabled` : `${name}Enabled`\n\n return {\n type: 'row',\n fields: [\n {\n name: `${name}Enabled`,\n type: 'checkbox',\n admin: {\n style: {\n alignSelf: 'baseline',\n flex: '0 0 auto',\n },\n },\n label: ({ t }) =>\n // @ts-expect-error - translations are not typed in plugins yet\n t('plugin-ecommerce:enableCurrencyPrice', { currency: currency.code }),\n },\n amountField({\n currenciesConfig,\n currency,\n overrides: {\n name,\n admin: {\n condition: (_, siblingData) => Boolean(siblingData?.[path]),\n description: ({ t }) =>\n // @ts-expect-error - translations are not typed in plugins yet\n t('plugin-ecommerce:productPriceDescription'),\n },\n // @ts-expect-error - translations are not typed in plugins yet\n label: ({ t }) => t('plugin-ecommerce:priceIn', { currency: currency.code }),\n },\n }),\n ],\n }\n })\n\n return [\n {\n type: 'group',\n admin: {\n description: 'Prices for this product in different currencies.',\n },\n fields: rows,\n },\n ]\n}\n"],"names":["amountField","pricesField","conditionalPath","currenciesConfig","currencies","supportedCurrencies","rows","map","currency","name","code","path","type","fields","admin","style","alignSelf","flex","label","t","overrides","condition","_","siblingData","Boolean","description"],"mappings":"AAIA,SAASA,WAAW,QAAQ,mBAAkB;AAU9C,OAAO,MAAMC,cAA8C,CAAC,EAC1DC,eAAe,EACfC,gBAAgB,EACjB;IACC,MAAMC,aAAaD,iBAAiBE,mBAAmB;IAEvD,MAAMC,OAAmBF,WAAWG,GAAG,CAAC,CAACC;QACvC,MAAMC,OAAO,CAAC,OAAO,EAAED,SAASE,IAAI,EAAE;QAEtC,MAAMC,OAAOT,kBAAkB,GAAGA,gBAAgB,CAAC,EAAEO,KAAK,OAAO,CAAC,GAAG,GAAGA,KAAK,OAAO,CAAC;QAErF,OAAO;YACLG,MAAM;YACNC,QAAQ;gBACN;oBACEJ,MAAM,GAAGA,KAAK,OAAO,CAAC;oBACtBG,MAAM;oBACNE,OAAO;wBACLC,OAAO;4BACLC,WAAW;4BACXC,MAAM;wBACR;oBACF;oBACAC,OAAO,CAAC,EAAEC,CAAC,EAAE,GACX,+DAA+D;wBAC/DA,EAAE,wCAAwC;4BAAEX,UAAUA,SAASE,IAAI;wBAAC;gBACxE;gBACAV,YAAY;oBACVG;oBACAK;oBACAY,WAAW;wBACTX;wBACAK,OAAO;4BACLO,WAAW,CAACC,GAAGC,cAAgBC,QAAQD,aAAa,CAACZ,KAAK;4BAC1Dc,aAAa,CAAC,EAAEN,CAAC,EAAE,GACjB,+DAA+D;gCAC/DA,EAAE;wBACN;wBACA,+DAA+D;wBAC/DD,OAAO,CAAC,EAAEC,CAAC,EAAE,GAAKA,EAAE,4BAA4B;gCAAEX,UAAUA,SAASE,IAAI;4BAAC;oBAC5E;gBACF;aACD;QACH;IACF;IAEA,OAAO;QACL;YACEE,MAAM;YACNE,OAAO;gBACLW,aAAa;YACf;YACAZ,QAAQP;QACV;KACD;AACH,EAAC"}
package/dist/index.d.ts CHANGED
@@ -1,4 +1,3 @@
1
- import type { Config } from 'payload';
2
1
  import type { EcommercePluginConfig } from './types/index.js';
3
2
  import { createAddressesCollection } from './collections/addresses/createAddressesCollection.js';
4
3
  import { createCartsCollection } from './collections/carts/createCartsCollection.js';
@@ -8,7 +7,7 @@ import { createTransactionsCollection } from './collections/transactions/createT
8
7
  import { createVariantOptionsCollection } from './collections/variants/createVariantOptionsCollection.js';
9
8
  import { createVariantsCollection } from './collections/variants/createVariantsCollection/index.js';
10
9
  import { createVariantTypesCollection } from './collections/variants/createVariantTypesCollection.js';
11
- export declare const ecommercePlugin: (pluginConfig?: EcommercePluginConfig) => (incomingConfig: Config) => Promise<Config>;
10
+ export declare const ecommercePlugin: (options?: EcommercePluginConfig | undefined) => import("payload").Plugin;
12
11
  export { createAddressesCollection, createCartsCollection, createOrdersCollection, createProductsCollection, createTransactionsCollection, createVariantOptionsCollection, createVariantsCollection, createVariantTypesCollection, };
13
12
  export { addItem } from './collections/carts/operations/addItem.js';
14
13
  export { clearCart } from './collections/carts/operations/clearCart.js';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAY,MAAM,SAAS,CAAA;AAK/C,OAAO,KAAK,EAAE,qBAAqB,EAAkC,MAAM,kBAAkB,CAAA;AAE7F,OAAO,EAAE,yBAAyB,EAAE,MAAM,sDAAsD,CAAA;AAChG,OAAO,EAAE,qBAAqB,EAAE,MAAM,8CAA8C,CAAA;AACpF,OAAO,EAAE,sBAAsB,EAAE,MAAM,gDAAgD,CAAA;AACvF,OAAO,EAAE,wBAAwB,EAAE,MAAM,oDAAoD,CAAA;AAC7F,OAAO,EAAE,4BAA4B,EAAE,MAAM,4DAA4D,CAAA;AACzG,OAAO,E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AAA;AACrD,OAAO,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAA;AACrD,OAAO,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAA;AACzD,OAAO,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAA;AACrD,OAAO,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAA;AACrD,OAAO,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAA"}
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { deepMergeSimple } from 'payload/shared';
1
+ import { definePlugin } from 'payload';
2
2
  import { createAddressesCollection } from './collections/addresses/createAddressesCollection.js';
3
3
  import { createCartsCollection } from './collections/carts/createCartsCollection.js';
4
4
  import { createOrdersCollection } from './collections/orders/createOrdersCollection.js';
@@ -13,7 +13,9 @@ import { translations } from './translations/index.js';
13
13
  import { getCollectionSlugMap } from './utilities/getCollectionSlugMap.js';
14
14
  import { pushTypeScriptProperties } from './utilities/pushTypeScriptProperties.js';
15
15
  import { sanitizePluginConfig } from './utilities/sanitizePluginConfig.js';
16
- export const ecommercePlugin = (pluginConfig)=>async (incomingConfig)=>{
16
+ export const ecommercePlugin = definePlugin({
17
+ slug: '@payloadcms/plugin-ecommerce',
18
+ plugin: async ({ config: incomingConfig, options: pluginConfig })=>{
17
19
  if (!pluginConfig) {
18
20
  return incomingConfig;
19
21
  }
@@ -202,32 +204,29 @@ export const ecommercePlugin = (pluginConfig)=>async (incomingConfig)=>{
202
204
  if (!incomingConfig.i18n) {
203
205
  incomingConfig.i18n = {};
204
206
  }
205
- if (!incomingConfig.i18n?.translations) {
207
+ if (!incomingConfig.i18n.translations) {
206
208
  incomingConfig.i18n.translations = {};
207
209
  }
208
- incomingConfig.i18n.translations = deepMergeSimple(translations, incomingConfig.i18n?.translations);
209
210
  /**
210
- * Merge plugin translations
211
- */ if (!incomingConfig.i18n) {
212
- incomingConfig.i18n = {};
213
- }
214
- Object.entries(translations).forEach(([locale, pluginI18nObject])=>{
215
- const typedLocale = locale;
216
- if (!incomingConfig.i18n.translations) {
217
- incomingConfig.i18n.translations = {};
218
- }
219
- if (!(typedLocale in incomingConfig.i18n.translations)) {
220
- incomingConfig.i18n.translations[typedLocale] = {};
211
+ * Merge plugin translations — only for languages the user has enabled.
212
+ * Plugins run before sanitize, so `supportedLanguages` may be undefined; sanitize will
213
+ * default it to `{ en }`, so we mirror that here. Plugin-ecommerce translations always
214
+ * win over user-provided ones for the `plugin-ecommerce` namespace.
215
+ */ const supportedLanguageKeys = incomingConfig.i18n?.supportedLanguages ? Object.keys(incomingConfig.i18n.supportedLanguages) : [
216
+ 'en'
217
+ ];
218
+ for (const lang of supportedLanguageKeys){
219
+ const pluginEntry = translations[lang];
220
+ if (!pluginEntry) {
221
+ continue;
221
222
  }
222
- if (!('plugin-ecommerce' in incomingConfig.i18n.translations[typedLocale])) {
223
- ;
224
- incomingConfig.i18n.translations[typedLocale]['plugin-ecommerce'] = {};
225
- }
226
- ;
227
- incomingConfig.i18n.translations[typedLocale]['plugin-ecommerce'] = {
228
- ...pluginI18nObject.translations['plugin-ecommerce']
223
+ const typedLocale = lang;
224
+ const existing = incomingConfig.i18n.translations[typedLocale] ?? {};
225
+ incomingConfig.i18n.translations[typedLocale] = {
226
+ ...existing,
227
+ 'plugin-ecommerce': pluginEntry.translations['plugin-ecommerce']
229
228
  };
230
- });
229
+ }
231
230
  if (!incomingConfig.typescript) {
232
231
  incomingConfig.typescript = {};
233
232
  }
@@ -240,7 +239,8 @@ export const ecommercePlugin = (pluginConfig)=>async (incomingConfig)=>{
240
239
  sanitizedPluginConfig
241
240
  }));
242
241
  return incomingConfig;
243
- };
242
+ }
243
+ });
244
244
  export { createAddressesCollection, createCartsCollection, createOrdersCollection, createProductsCollection, createTransactionsCollection, createVariantOptionsCollection, createVariantsCollection, createVariantTypesCollection, };
245
245
  export { addItem } from './collections/carts/operations/addItem.js';
246
246
  export { clearCart } from './collections/carts/operations/clearCart.js';