@payloadcms/plugin-ecommerce 4.0.0-internal.183b315 → 4.0.0-internal.1ccb6d5

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 (158) hide show
  1. package/LICENSE.md +1 -1
  2. package/README.md +6 -0
  3. package/dist/collections/addresses/createAddressesCollection.d.ts.map +1 -1
  4. package/dist/collections/addresses/createAddressesCollection.js +1 -0
  5. package/dist/collections/addresses/createAddressesCollection.js.map +1 -1
  6. package/dist/collections/addresses/hooks/beforeChange.d.ts.map +1 -1
  7. package/dist/collections/addresses/hooks/beforeChange.js +3 -2
  8. package/dist/collections/addresses/hooks/beforeChange.js.map +1 -1
  9. package/dist/collections/carts/beforeChange.d.ts.map +1 -1
  10. package/dist/collections/carts/beforeChange.js +2 -0
  11. package/dist/collections/carts/beforeChange.js.map +1 -1
  12. package/dist/collections/carts/createCartsCollection.d.ts.map +1 -1
  13. package/dist/collections/carts/createCartsCollection.js +1 -0
  14. package/dist/collections/carts/createCartsCollection.js.map +1 -1
  15. package/dist/collections/carts/endpoints/addItem.d.ts.map +1 -1
  16. package/dist/collections/carts/endpoints/clearCart.d.ts.map +1 -1
  17. package/dist/collections/carts/endpoints/mergeCart.d.ts.map +1 -1
  18. package/dist/collections/carts/endpoints/removeItem.d.ts.map +1 -1
  19. package/dist/collections/carts/endpoints/updateItem.d.ts.map +1 -1
  20. package/dist/collections/carts/hasCartSecretAccess.d.ts.map +1 -1
  21. package/dist/collections/carts/operations/addItem.d.ts.map +1 -1
  22. package/dist/collections/carts/operations/clearCart.d.ts.map +1 -1
  23. package/dist/collections/carts/operations/createRequestWithSecret.d.ts.map +1 -1
  24. package/dist/collections/carts/operations/createRequestWithSecret.js.map +1 -1
  25. package/dist/collections/carts/operations/mergeCart.d.ts.map +1 -1
  26. package/dist/collections/carts/operations/mergeCart.js.map +1 -1
  27. package/dist/collections/carts/operations/removeItem.d.ts.map +1 -1
  28. package/dist/collections/carts/operations/updateItem.d.ts.map +1 -1
  29. package/dist/collections/orders/createOrdersCollection.d.ts.map +1 -1
  30. package/dist/collections/orders/createOrdersCollection.js +1 -0
  31. package/dist/collections/orders/createOrdersCollection.js.map +1 -1
  32. package/dist/collections/products/createProductsCollection.d.ts.map +1 -1
  33. package/dist/collections/products/createProductsCollection.js +1 -0
  34. package/dist/collections/products/createProductsCollection.js.map +1 -1
  35. package/dist/collections/transactions/createTransactionsCollection.d.ts.map +1 -1
  36. package/dist/collections/transactions/createTransactionsCollection.js +1 -0
  37. package/dist/collections/transactions/createTransactionsCollection.js.map +1 -1
  38. package/dist/collections/variants/createVariantOptionsCollection.d.ts.map +1 -1
  39. package/dist/collections/variants/createVariantOptionsCollection.js +1 -0
  40. package/dist/collections/variants/createVariantOptionsCollection.js.map +1 -1
  41. package/dist/collections/variants/createVariantTypesCollection.d.ts.map +1 -1
  42. package/dist/collections/variants/createVariantTypesCollection.js +1 -0
  43. package/dist/collections/variants/createVariantTypesCollection.js.map +1 -1
  44. package/dist/collections/variants/createVariantsCollection/hooks/beforeChange.d.ts.map +1 -1
  45. package/dist/collections/variants/createVariantsCollection/hooks/beforeChange.js +2 -0
  46. package/dist/collections/variants/createVariantsCollection/hooks/beforeChange.js.map +1 -1
  47. package/dist/collections/variants/createVariantsCollection/hooks/validateOptions.d.ts.map +1 -1
  48. package/dist/collections/variants/createVariantsCollection/hooks/validateOptions.js +1 -0
  49. package/dist/collections/variants/createVariantsCollection/hooks/validateOptions.js.map +1 -1
  50. package/dist/collections/variants/createVariantsCollection/index.d.ts.map +1 -1
  51. package/dist/collections/variants/createVariantsCollection/index.js +1 -0
  52. package/dist/collections/variants/createVariantsCollection/index.js.map +1 -1
  53. package/dist/endpoints/confirmOrder.d.ts.map +1 -1
  54. package/dist/endpoints/confirmOrder.js +306 -44
  55. package/dist/endpoints/confirmOrder.js.map +1 -1
  56. package/dist/endpoints/initiatePayment.d.ts.map +1 -1
  57. package/dist/endpoints/initiatePayment.js +2 -0
  58. package/dist/endpoints/initiatePayment.js.map +1 -1
  59. package/dist/exports/types.d.ts +1 -1
  60. package/dist/exports/types.d.ts.map +1 -1
  61. package/dist/exports/types.js.map +1 -1
  62. package/dist/fields/pricesField.d.ts.map +1 -1
  63. package/dist/fields/pricesField.js +39 -39
  64. package/dist/fields/pricesField.js.map +1 -1
  65. package/dist/fields/statusField.d.ts.map +1 -1
  66. package/dist/fields/statusField.js +5 -0
  67. package/dist/fields/statusField.js.map +1 -1
  68. package/dist/index.d.ts +1 -2
  69. package/dist/index.d.ts.map +1 -1
  70. package/dist/index.js +7 -2
  71. package/dist/index.js.map +1 -1
  72. package/dist/payments/adapters/stripe/confirmOrder.d.ts.map +1 -1
  73. package/dist/payments/adapters/stripe/confirmOrder.js +108 -75
  74. package/dist/payments/adapters/stripe/confirmOrder.js.map +1 -1
  75. package/dist/payments/adapters/stripe/initiatePayment.d.ts.map +1 -1
  76. package/dist/payments/adapters/stripe/initiatePayment.js +1 -0
  77. package/dist/payments/adapters/stripe/initiatePayment.js.map +1 -1
  78. package/dist/payments/adapters/stripe/validateSettlement.d.ts +37 -0
  79. package/dist/payments/adapters/stripe/validateSettlement.d.ts.map +1 -0
  80. package/dist/payments/adapters/stripe/validateSettlement.js +157 -0
  81. package/dist/payments/adapters/stripe/validateSettlement.js.map +1 -0
  82. package/dist/react/provider/index.d.ts.map +1 -1
  83. package/dist/react/provider/index.js +75 -34
  84. package/dist/react/provider/index.js.map +1 -1
  85. package/dist/react/provider/utilities.d.ts.map +1 -1
  86. package/dist/translations/languages/ar.d.ts.map +1 -1
  87. package/dist/translations/languages/az.d.ts.map +1 -1
  88. package/dist/translations/languages/bg.d.ts.map +1 -1
  89. package/dist/translations/languages/ca.d.ts.map +1 -1
  90. package/dist/translations/languages/cs.d.ts.map +1 -1
  91. package/dist/translations/languages/da.d.ts.map +1 -1
  92. package/dist/translations/languages/de.d.ts.map +1 -1
  93. package/dist/translations/languages/en.d.ts.map +1 -1
  94. package/dist/translations/languages/es.d.ts.map +1 -1
  95. package/dist/translations/languages/et.d.ts.map +1 -1
  96. package/dist/translations/languages/fa.d.ts.map +1 -1
  97. package/dist/translations/languages/fr.d.ts.map +1 -1
  98. package/dist/translations/languages/he.d.ts.map +1 -1
  99. package/dist/translations/languages/hr.d.ts.map +1 -1
  100. package/dist/translations/languages/hu.d.ts.map +1 -1
  101. package/dist/translations/languages/hy.d.ts.map +1 -1
  102. package/dist/translations/languages/is.d.ts.map +1 -1
  103. package/dist/translations/languages/it.d.ts.map +1 -1
  104. package/dist/translations/languages/ja.d.ts.map +1 -1
  105. package/dist/translations/languages/ko.d.ts.map +1 -1
  106. package/dist/translations/languages/lt.d.ts.map +1 -1
  107. package/dist/translations/languages/my.d.ts.map +1 -1
  108. package/dist/translations/languages/nb.d.ts.map +1 -1
  109. package/dist/translations/languages/nl.d.ts.map +1 -1
  110. package/dist/translations/languages/pl.d.ts.map +1 -1
  111. package/dist/translations/languages/pt.d.ts.map +1 -1
  112. package/dist/translations/languages/ro.d.ts.map +1 -1
  113. package/dist/translations/languages/rs.d.ts.map +1 -1
  114. package/dist/translations/languages/rsLatin.d.ts.map +1 -1
  115. package/dist/translations/languages/ru.d.ts.map +1 -1
  116. package/dist/translations/languages/sk.d.ts.map +1 -1
  117. package/dist/translations/languages/sl.d.ts.map +1 -1
  118. package/dist/translations/languages/sv.d.ts.map +1 -1
  119. package/dist/translations/languages/ta.d.ts.map +1 -1
  120. package/dist/translations/languages/th.d.ts.map +1 -1
  121. package/dist/translations/languages/tr.d.ts.map +1 -1
  122. package/dist/translations/languages/uk.d.ts.map +1 -1
  123. package/dist/translations/languages/vi.d.ts.map +1 -1
  124. package/dist/translations/languages/zh.d.ts.map +1 -1
  125. package/dist/translations/languages/zhTw.d.ts.map +1 -1
  126. package/dist/types/index.d.ts +33 -7
  127. package/dist/types/index.d.ts.map +1 -1
  128. package/dist/types/index.js.map +1 -1
  129. package/dist/ui/PriceInput/FormattedInput.js +2 -2
  130. package/dist/ui/PriceInput/FormattedInput.js.map +1 -1
  131. package/dist/ui/PriceInput/index.css +19 -31
  132. package/dist/ui/PriceInput/index.d.ts.map +1 -1
  133. package/dist/ui/PriceInput/index.js.map +1 -1
  134. package/dist/ui/PriceRowLabel/index.css +2 -2
  135. package/dist/ui/VariantOptionsSelector/index.css +8 -10
  136. package/dist/ui/VariantOptionsSelector/index.d.ts.map +1 -1
  137. package/dist/ui/VariantOptionsSelector/index.js +3 -1
  138. package/dist/ui/VariantOptionsSelector/index.js.map +1 -1
  139. package/dist/ui/utilities.d.ts.map +1 -1
  140. package/dist/utilities/accessComposition.d.ts.map +1 -1
  141. package/dist/utilities/getCollectionSlugMap.d.ts.map +1 -1
  142. package/dist/utilities/pushTypeScriptProperties.d.ts.map +1 -1
  143. package/dist/utilities/sanitizePluginConfig.d.ts.map +1 -1
  144. package/package.json +29 -32
  145. package/dist/@types/assets.d.js +0 -2
  146. package/dist/@types/assets.d.js.map +0 -1
  147. package/dist/collections/carts/operations/defaultCartItemMatcher.spec.js +0 -358
  148. package/dist/collections/carts/operations/defaultCartItemMatcher.spec.js.map +0 -1
  149. package/dist/payments/adapters/stripe/confirmOrder.spec.js +0 -166
  150. package/dist/payments/adapters/stripe/confirmOrder.spec.js.map +0 -1
  151. package/dist/utilities/accessComposition.spec.js +0 -765
  152. package/dist/utilities/accessComposition.spec.js.map +0 -1
  153. package/dist/utilities/defaultProductsValidation.spec.js +0 -384
  154. package/dist/utilities/defaultProductsValidation.spec.js.map +0 -1
  155. package/dist/utilities/getCollectionSlugMap.spec.js +0 -254
  156. package/dist/utilities/getCollectionSlugMap.spec.js.map +0 -1
  157. package/dist/utilities/sanitizePluginConfig.spec.js +0 -516
  158. package/dist/utilities/sanitizePluginConfig.spec.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/collections/variants/createVariantOptionsCollection.ts"],"sourcesContent":["import type { CollectionConfig, Field } from 'payload'\n\nimport type { AccessConfig } from '../../types/index.js'\n\ntype Props = {\n access: Pick<AccessConfig, 'isAdmin' | 'publicAccess'>\n /**\n * Slug of the variant types collection, defaults to 'variantTypes'.\n */\n variantTypesSlug?: string\n}\n\nexport const createVariantOptionsCollection: (props: Props) => CollectionConfig = (props) => {\n const { access, variantTypesSlug = 'variantTypes' } = props || {}\n\n const fields: Field[] = [\n {\n name: 'variantType',\n type: 'relationship',\n admin: {\n readOnly: true,\n },\n relationTo: variantTypesSlug,\n required: true,\n },\n {\n name: 'label',\n type: 'text',\n required: true,\n },\n {\n name: 'value',\n type: 'text',\n admin: {\n description: 'should be defaulted or dynamic based on label',\n },\n required: true,\n },\n ]\n\n const baseConfig: CollectionConfig = {\n slug: 'variantOptions',\n access: {\n create: access.isAdmin,\n delete: access.isAdmin,\n read: access.publicAccess,\n update: access.isAdmin,\n },\n admin: {\n group: false,\n useAsTitle: 'label',\n },\n fields,\n labels: {\n plural: ({ t }) =>\n // @ts-expect-error - translations are not typed in plugins yet\n t('plugin-ecommerce:variantOptions'),\n singular: ({ t }) =>\n // @ts-expect-error - translations are not typed in plugins yet\n t('plugin-ecommerce:variantOption'),\n },\n trash: true,\n }\n\n return { ...baseConfig }\n}\n"],"names":["createVariantOptionsCollection","props","access","variantTypesSlug","fields","name","type","admin","readOnly","relationTo","required","description","baseConfig","slug","create","isAdmin","delete","read","publicAccess","update","group","useAsTitle","labels","plural","t","singular","trash"],"mappings":"AAYA,OAAO,MAAMA,iCAAqE,CAACC;IACjF,MAAM,EAAEC,MAAM,EAAEC,mBAAmB,cAAc,EAAE,GAAGF,SAAS,CAAC;IAEhE,MAAMG,SAAkB;QACtB;YACEC,MAAM;YACNC,MAAM;YACNC,OAAO;gBACLC,UAAU;YACZ;YACAC,YAAYN;YACZO,UAAU;QACZ;QACA;YACEL,MAAM;YACNC,MAAM;YACNI,UAAU;QACZ;QACA;YACEL,MAAM;YACNC,MAAM;YACNC,OAAO;gBACLI,aAAa;YACf;YACAD,UAAU;QACZ;KACD;IAED,MAAME,aAA+B;QACnCC,MAAM;QACNX,QAAQ;YACNY,QAAQZ,OAAOa,OAAO;YACtBC,QAAQd,OAAOa,OAAO;YACtBE,MAAMf,OAAOgB,YAAY;YACzBC,QAAQjB,OAAOa,OAAO;QACxB;QACAR,OAAO;YACLa,OAAO;YACPC,YAAY;QACd;QACAjB;QACAkB,QAAQ;YACNC,QAAQ,CAAC,EAAEC,CAAC,EAAE,GACZ,+DAA+D;gBAC/DA,EAAE;YACJC,UAAU,CAAC,EAAED,CAAC,EAAE,GACd,+DAA+D;gBAC/DA,EAAE;QACN;QACAE,OAAO;IACT;IAEA,OAAO;QAAE,GAAGd,UAAU;IAAC;AACzB,EAAC"}
1
+ {"version":3,"sources":["../../../src/collections/variants/createVariantOptionsCollection.ts"],"sourcesContent":["import type { CollectionConfig, Field } from 'payload'\n\nimport type { AccessConfig } from '../../types/index.js'\n\ntype Props = {\n access: Pick<AccessConfig, 'isAdmin' | 'publicAccess'>\n /**\n * Slug of the variant types collection, defaults to 'variantTypes'.\n */\n variantTypesSlug?: string\n}\n\nexport const createVariantOptionsCollection: (props: Props) => CollectionConfig = (props) => {\n const { access, variantTypesSlug = 'variantTypes' } = props || {}\n\n const fields: Field[] = [\n {\n name: 'variantType',\n type: 'relationship',\n admin: {\n readOnly: true,\n },\n relationTo: variantTypesSlug,\n required: true,\n },\n {\n name: 'label',\n type: 'text',\n required: true,\n },\n {\n name: 'value',\n type: 'text',\n admin: {\n description: 'should be defaulted or dynamic based on label',\n },\n required: true,\n },\n ]\n\n const baseConfig: CollectionConfig = {\n slug: 'variantOptions',\n access: {\n create: access.isAdmin,\n delete: access.isAdmin,\n read: access.publicAccess,\n update: access.isAdmin,\n },\n admin: {\n group: false,\n useAsTitle: 'label',\n },\n authorship: false,\n fields,\n labels: {\n plural: ({ t }) =>\n // @ts-expect-error - translations are not typed in plugins yet\n t('plugin-ecommerce:variantOptions'),\n singular: ({ t }) =>\n // @ts-expect-error - translations are not typed in plugins yet\n t('plugin-ecommerce:variantOption'),\n },\n trash: true,\n }\n\n return { ...baseConfig }\n}\n"],"names":["createVariantOptionsCollection","props","access","variantTypesSlug","fields","name","type","admin","readOnly","relationTo","required","description","baseConfig","slug","create","isAdmin","delete","read","publicAccess","update","group","useAsTitle","authorship","labels","plural","t","singular","trash"],"mappings":"AAYA,OAAO,MAAMA,iCAAqE,CAACC;IACjF,MAAM,EAAEC,MAAM,EAAEC,mBAAmB,cAAc,EAAE,GAAGF,SAAS,CAAC;IAEhE,MAAMG,SAAkB;QACtB;YACEC,MAAM;YACNC,MAAM;YACNC,OAAO;gBACLC,UAAU;YACZ;YACAC,YAAYN;YACZO,UAAU;QACZ;QACA;YACEL,MAAM;YACNC,MAAM;YACNI,UAAU;QACZ;QACA;YACEL,MAAM;YACNC,MAAM;YACNC,OAAO;gBACLI,aAAa;YACf;YACAD,UAAU;QACZ;KACD;IAED,MAAME,aAA+B;QACnCC,MAAM;QACNX,QAAQ;YACNY,QAAQZ,OAAOa,OAAO;YACtBC,QAAQd,OAAOa,OAAO;YACtBE,MAAMf,OAAOgB,YAAY;YACzBC,QAAQjB,OAAOa,OAAO;QACxB;QACAR,OAAO;YACLa,OAAO;YACPC,YAAY;QACd;QACAC,YAAY;QACZlB;QACAmB,QAAQ;YACNC,QAAQ,CAAC,EAAEC,CAAC,EAAE,GACZ,+DAA+D;gBAC/DA,EAAE;YACJC,UAAU,CAAC,EAAED,CAAC,EAAE,GACd,+DAA+D;gBAC/DA,EAAE;QACN;QACAE,OAAO;IACT;IAEA,OAAO;QAAE,GAAGf,UAAU;IAAC;AACzB,EAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"createVariantTypesCollection.d.ts","sourceRoot":"","sources":["../../../src/collections/variants/createVariantTypesCollection.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAS,MAAM,SAAS,CAAA;AAEtD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAA;AAExD,KAAK,KAAK,GAAG;IACX,MAAM,EAAE,IAAI,CAAC,YAAY,EAAE,SAAS,GAAG,cAAc,CAAC,CAAA;IACtD;;OAEG;IACH,kBAAkB,CAAC,EAAE,MAAM,CAAA;CAC5B,CAAA;AAED,eAAO,MAAM,4BAA4B,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,gBAiD5D,CAAA"}
1
+ {"version":3,"file":"createVariantTypesCollection.d.ts","sourceRoot":"","sources":["../../../src/collections/variants/createVariantTypesCollection.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAS,MAAM,SAAS,CAAA;AAEtD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAA;AAExD,KAAK,KAAK,GAAG;IACX,MAAM,EAAE,IAAI,CAAC,YAAY,EAAE,SAAS,GAAG,cAAc,CAAC,CAAA;IACtD;;OAEG;IACH,kBAAkB,CAAC,EAAE,MAAM,CAAA;CAC5B,CAAA;AAED,eAAO,MAAM,4BAA4B,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,gBAkD5D,CAAA"}
@@ -32,6 +32,7 @@ export const createVariantTypesCollection = (props)=>{
32
32
  group: false,
33
33
  useAsTitle: 'label'
34
34
  },
35
+ authorship: false,
35
36
  fields,
36
37
  labels: {
37
38
  plural: ({ t })=>// @ts-expect-error - translations are not typed in plugins yet
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/collections/variants/createVariantTypesCollection.ts"],"sourcesContent":["import type { CollectionConfig, Field } from 'payload'\n\nimport type { AccessConfig } from '../../types/index.js'\n\ntype Props = {\n access: Pick<AccessConfig, 'isAdmin' | 'publicAccess'>\n /**\n * Slug of the variant options collection, defaults to 'variantOptions'.\n */\n variantOptionsSlug?: string\n}\n\nexport const createVariantTypesCollection: (props: Props) => CollectionConfig = (props) => {\n const { access, variantOptionsSlug = 'variantOptions' } = props || {}\n\n const fields: Field[] = [\n {\n name: 'label',\n type: 'text',\n required: true,\n },\n {\n name: 'name',\n type: 'text',\n required: true,\n },\n {\n name: 'options',\n type: 'join',\n collection: variantOptionsSlug,\n maxDepth: 2,\n on: 'variantType',\n orderable: true,\n },\n ]\n\n const baseConfig: CollectionConfig = {\n slug: 'variantTypes',\n access: {\n create: access.isAdmin,\n delete: access.isAdmin,\n read: access.publicAccess,\n update: access.isAdmin,\n },\n admin: {\n group: false,\n useAsTitle: 'label',\n },\n fields,\n labels: {\n plural: ({ t }) =>\n // @ts-expect-error - translations are not typed in plugins yet\n t('plugin-ecommerce:variantTypes'),\n singular: ({ t }) =>\n // @ts-expect-error - translations are not typed in plugins yet\n t('plugin-ecommerce:variantType'),\n },\n trash: true,\n }\n\n return { ...baseConfig }\n}\n"],"names":["createVariantTypesCollection","props","access","variantOptionsSlug","fields","name","type","required","collection","maxDepth","on","orderable","baseConfig","slug","create","isAdmin","delete","read","publicAccess","update","admin","group","useAsTitle","labels","plural","t","singular","trash"],"mappings":"AAYA,OAAO,MAAMA,+BAAmE,CAACC;IAC/E,MAAM,EAAEC,MAAM,EAAEC,qBAAqB,gBAAgB,EAAE,GAAGF,SAAS,CAAC;IAEpE,MAAMG,SAAkB;QACtB;YACEC,MAAM;YACNC,MAAM;YACNC,UAAU;QACZ;QACA;YACEF,MAAM;YACNC,MAAM;YACNC,UAAU;QACZ;QACA;YACEF,MAAM;YACNC,MAAM;YACNE,YAAYL;YACZM,UAAU;YACVC,IAAI;YACJC,WAAW;QACb;KACD;IAED,MAAMC,aAA+B;QACnCC,MAAM;QACNX,QAAQ;YACNY,QAAQZ,OAAOa,OAAO;YACtBC,QAAQd,OAAOa,OAAO;YACtBE,MAAMf,OAAOgB,YAAY;YACzBC,QAAQjB,OAAOa,OAAO;QACxB;QACAK,OAAO;YACLC,OAAO;YACPC,YAAY;QACd;QACAlB;QACAmB,QAAQ;YACNC,QAAQ,CAAC,EAAEC,CAAC,EAAE,GACZ,+DAA+D;gBAC/DA,EAAE;YACJC,UAAU,CAAC,EAAED,CAAC,EAAE,GACd,+DAA+D;gBAC/DA,EAAE;QACN;QACAE,OAAO;IACT;IAEA,OAAO;QAAE,GAAGf,UAAU;IAAC;AACzB,EAAC"}
1
+ {"version":3,"sources":["../../../src/collections/variants/createVariantTypesCollection.ts"],"sourcesContent":["import type { CollectionConfig, Field } from 'payload'\n\nimport type { AccessConfig } from '../../types/index.js'\n\ntype Props = {\n access: Pick<AccessConfig, 'isAdmin' | 'publicAccess'>\n /**\n * Slug of the variant options collection, defaults to 'variantOptions'.\n */\n variantOptionsSlug?: string\n}\n\nexport const createVariantTypesCollection: (props: Props) => CollectionConfig = (props) => {\n const { access, variantOptionsSlug = 'variantOptions' } = props || {}\n\n const fields: Field[] = [\n {\n name: 'label',\n type: 'text',\n required: true,\n },\n {\n name: 'name',\n type: 'text',\n required: true,\n },\n {\n name: 'options',\n type: 'join',\n collection: variantOptionsSlug,\n maxDepth: 2,\n on: 'variantType',\n orderable: true,\n },\n ]\n\n const baseConfig: CollectionConfig = {\n slug: 'variantTypes',\n access: {\n create: access.isAdmin,\n delete: access.isAdmin,\n read: access.publicAccess,\n update: access.isAdmin,\n },\n admin: {\n group: false,\n useAsTitle: 'label',\n },\n authorship: false,\n fields,\n labels: {\n plural: ({ t }) =>\n // @ts-expect-error - translations are not typed in plugins yet\n t('plugin-ecommerce:variantTypes'),\n singular: ({ t }) =>\n // @ts-expect-error - translations are not typed in plugins yet\n t('plugin-ecommerce:variantType'),\n },\n trash: true,\n }\n\n return { ...baseConfig }\n}\n"],"names":["createVariantTypesCollection","props","access","variantOptionsSlug","fields","name","type","required","collection","maxDepth","on","orderable","baseConfig","slug","create","isAdmin","delete","read","publicAccess","update","admin","group","useAsTitle","authorship","labels","plural","t","singular","trash"],"mappings":"AAYA,OAAO,MAAMA,+BAAmE,CAACC;IAC/E,MAAM,EAAEC,MAAM,EAAEC,qBAAqB,gBAAgB,EAAE,GAAGF,SAAS,CAAC;IAEpE,MAAMG,SAAkB;QACtB;YACEC,MAAM;YACNC,MAAM;YACNC,UAAU;QACZ;QACA;YACEF,MAAM;YACNC,MAAM;YACNC,UAAU;QACZ;QACA;YACEF,MAAM;YACNC,MAAM;YACNE,YAAYL;YACZM,UAAU;YACVC,IAAI;YACJC,WAAW;QACb;KACD;IAED,MAAMC,aAA+B;QACnCC,MAAM;QACNX,QAAQ;YACNY,QAAQZ,OAAOa,OAAO;YACtBC,QAAQd,OAAOa,OAAO;YACtBE,MAAMf,OAAOgB,YAAY;YACzBC,QAAQjB,OAAOa,OAAO;QACxB;QACAK,OAAO;YACLC,OAAO;YACPC,YAAY;QACd;QACAC,YAAY;QACZnB;QACAoB,QAAQ;YACNC,QAAQ,CAAC,EAAEC,CAAC,EAAE,GACZ,+DAA+D;gBAC/DA,EAAE;YACJC,UAAU,CAAC,EAAED,CAAC,EAAE,GACd,+DAA+D;gBAC/DA,EAAE;QACN;QACAE,OAAO;IACT;IAEA,OAAO;QAAE,GAAGhB,UAAU;IAAC;AACzB,EAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"beforeChange.d.ts","sourceRoot":"","sources":["../../../../../src/collections/variants/createVariantsCollection/hooks/beforeChange.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,SAAS,CAAA;AAEzD,KAAK,KAAK,GAAG;IACX,YAAY,EAAE,MAAM,CAAA;IACpB,kBAAkB,EAAE,MAAM,CAAA;CAC3B,CAAA;AAED,eAAO,MAAM,8BAA8B,EAAE,CAAC,IAAI,EAAE,KAAK,KAAK,0BA2C3D,CAAA"}
1
+ {"version":3,"file":"beforeChange.d.ts","sourceRoot":"","sources":["../../../../../src/collections/variants/createVariantsCollection/hooks/beforeChange.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,SAAS,CAAA;AAEzD,KAAK,KAAK,GAAG;IACX,YAAY,EAAE,MAAM,CAAA;IACpB,kBAAkB,EAAE,MAAM,CAAA;CAC3B,CAAA;AAED,eAAO,MAAM,8BAA8B,EAAE,CAAC,IAAI,EAAE,KAAK,KAAK,0BA6C3D,CAAA"}
@@ -6,6 +6,7 @@ export const variantsCollectionBeforeChange = ({ productsSlug, variantOptionsSlu
6
6
  id: productID,
7
7
  collection: productsSlug,
8
8
  depth: 0,
9
+ overrideAccess: true,
9
10
  select: {
10
11
  title: true,
11
12
  variantTypes: true
@@ -19,6 +20,7 @@ export const variantsCollectionBeforeChange = ({ productsSlug, variantOptionsSlu
19
20
  id: option,
20
21
  collection: variantOptionsSlug,
21
22
  depth: 0,
23
+ overrideAccess: true,
22
24
  select: {
23
25
  label: true
24
26
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../src/collections/variants/createVariantsCollection/hooks/beforeChange.ts"],"sourcesContent":["import type { CollectionBeforeChangeHook } from 'payload'\n\ntype Props = {\n productsSlug: string\n variantOptionsSlug: string\n}\n\nexport const variantsCollectionBeforeChange: (args: Props) => CollectionBeforeChangeHook =\n ({ productsSlug, variantOptionsSlug }) =>\n async ({ data, req }) => {\n if (data?.options?.length && data.options.length > 0) {\n const titleArray: string[] = []\n const productID = data.product\n const product = await req.payload.findByID({\n id: productID,\n collection: productsSlug,\n depth: 0,\n select: {\n title: true,\n variantTypes: true,\n },\n })\n\n if (product.title && typeof product.title === 'string') {\n titleArray.push(product.title)\n }\n\n for (const option of data.options) {\n const variantOption = await req.payload.findByID({\n id: option,\n collection: variantOptionsSlug,\n depth: 0,\n select: {\n label: true,\n },\n })\n\n if (!variantOption) {\n continue\n }\n\n if (variantOption.label && typeof variantOption.label === 'string') {\n titleArray.push(variantOption.label)\n }\n }\n\n data.title = titleArray.join(' — ')\n }\n\n return data\n }\n"],"names":["variantsCollectionBeforeChange","productsSlug","variantOptionsSlug","data","req","options","length","titleArray","productID","product","payload","findByID","id","collection","depth","select","title","variantTypes","push","option","variantOption","label","join"],"mappings":"AAOA,OAAO,MAAMA,iCACX,CAAC,EAAEC,YAAY,EAAEC,kBAAkB,EAAE,GACrC,OAAO,EAAEC,IAAI,EAAEC,GAAG,EAAE;QAClB,IAAID,MAAME,SAASC,UAAUH,KAAKE,OAAO,CAACC,MAAM,GAAG,GAAG;YACpD,MAAMC,aAAuB,EAAE;YAC/B,MAAMC,YAAYL,KAAKM,OAAO;YAC9B,MAAMA,UAAU,MAAML,IAAIM,OAAO,CAACC,QAAQ,CAAC;gBACzCC,IAAIJ;gBACJK,YAAYZ;gBACZa,OAAO;gBACPC,QAAQ;oBACNC,OAAO;oBACPC,cAAc;gBAChB;YACF;YAEA,IAAIR,QAAQO,KAAK,IAAI,OAAOP,QAAQO,KAAK,KAAK,UAAU;gBACtDT,WAAWW,IAAI,CAACT,QAAQO,KAAK;YAC/B;YAEA,KAAK,MAAMG,UAAUhB,KAAKE,OAAO,CAAE;gBACjC,MAAMe,gBAAgB,MAAMhB,IAAIM,OAAO,CAACC,QAAQ,CAAC;oBAC/CC,IAAIO;oBACJN,YAAYX;oBACZY,OAAO;oBACPC,QAAQ;wBACNM,OAAO;oBACT;gBACF;gBAEA,IAAI,CAACD,eAAe;oBAClB;gBACF;gBAEA,IAAIA,cAAcC,KAAK,IAAI,OAAOD,cAAcC,KAAK,KAAK,UAAU;oBAClEd,WAAWW,IAAI,CAACE,cAAcC,KAAK;gBACrC;YACF;YAEAlB,KAAKa,KAAK,GAAGT,WAAWe,IAAI,CAAC;QAC/B;QAEA,OAAOnB;IACT,EAAC"}
1
+ {"version":3,"sources":["../../../../../src/collections/variants/createVariantsCollection/hooks/beforeChange.ts"],"sourcesContent":["import type { CollectionBeforeChangeHook } from 'payload'\n\ntype Props = {\n productsSlug: string\n variantOptionsSlug: string\n}\n\nexport const variantsCollectionBeforeChange: (args: Props) => CollectionBeforeChangeHook =\n ({ productsSlug, variantOptionsSlug }) =>\n async ({ data, req }) => {\n if (data?.options?.length && data.options.length > 0) {\n const titleArray: string[] = []\n const productID = data.product\n const product = await req.payload.findByID({\n id: productID,\n collection: productsSlug,\n depth: 0,\n overrideAccess: true,\n select: {\n title: true,\n variantTypes: true,\n },\n })\n\n if (product.title && typeof product.title === 'string') {\n titleArray.push(product.title)\n }\n\n for (const option of data.options) {\n const variantOption = await req.payload.findByID({\n id: option,\n collection: variantOptionsSlug,\n depth: 0,\n overrideAccess: true,\n select: {\n label: true,\n },\n })\n\n if (!variantOption) {\n continue\n }\n\n if (variantOption.label && typeof variantOption.label === 'string') {\n titleArray.push(variantOption.label)\n }\n }\n\n data.title = titleArray.join(' — ')\n }\n\n return data\n }\n"],"names":["variantsCollectionBeforeChange","productsSlug","variantOptionsSlug","data","req","options","length","titleArray","productID","product","payload","findByID","id","collection","depth","overrideAccess","select","title","variantTypes","push","option","variantOption","label","join"],"mappings":"AAOA,OAAO,MAAMA,iCACX,CAAC,EAAEC,YAAY,EAAEC,kBAAkB,EAAE,GACrC,OAAO,EAAEC,IAAI,EAAEC,GAAG,EAAE;QAClB,IAAID,MAAME,SAASC,UAAUH,KAAKE,OAAO,CAACC,MAAM,GAAG,GAAG;YACpD,MAAMC,aAAuB,EAAE;YAC/B,MAAMC,YAAYL,KAAKM,OAAO;YAC9B,MAAMA,UAAU,MAAML,IAAIM,OAAO,CAACC,QAAQ,CAAC;gBACzCC,IAAIJ;gBACJK,YAAYZ;gBACZa,OAAO;gBACPC,gBAAgB;gBAChBC,QAAQ;oBACNC,OAAO;oBACPC,cAAc;gBAChB;YACF;YAEA,IAAIT,QAAQQ,KAAK,IAAI,OAAOR,QAAQQ,KAAK,KAAK,UAAU;gBACtDV,WAAWY,IAAI,CAACV,QAAQQ,KAAK;YAC/B;YAEA,KAAK,MAAMG,UAAUjB,KAAKE,OAAO,CAAE;gBACjC,MAAMgB,gBAAgB,MAAMjB,IAAIM,OAAO,CAACC,QAAQ,CAAC;oBAC/CC,IAAIQ;oBACJP,YAAYX;oBACZY,OAAO;oBACPC,gBAAgB;oBAChBC,QAAQ;wBACNM,OAAO;oBACT;gBACF;gBAEA,IAAI,CAACD,eAAe;oBAClB;gBACF;gBAEA,IAAIA,cAAcC,KAAK,IAAI,OAAOD,cAAcC,KAAK,KAAK,UAAU;oBAClEf,WAAWY,IAAI,CAACE,cAAcC,KAAK;gBACrC;YACF;YAEAnB,KAAKc,KAAK,GAAGV,WAAWgB,IAAI,CAAC;QAC/B;QAEA,OAAOpB;IACT,EAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"validateOptions.d.ts","sourceRoot":"","sources":["../../../../../src/collections/variants/createVariantsCollection/hooks/validateOptions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAA;AAEvC,KAAK,KAAK,GAAG;IACX,sBAAsB,CAAC,EAAE,MAAM,CAAA;CAChC,CAAA;AAED,eAAO,MAAM,eAAe,EAAE,CAAC,KAAK,CAAC,EAAE,KAAK,KAAK,QAoE9C,CAAA"}
1
+ {"version":3,"file":"validateOptions.d.ts","sourceRoot":"","sources":["../../../../../src/collections/variants/createVariantsCollection/hooks/validateOptions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAA;AAEvC,KAAK,KAAK,GAAG;IACX,sBAAsB,CAAC,EAAE,MAAM,CAAA;CAChC,CAAA;AAED,eAAO,MAAM,eAAe,EAAE,CAAC,KAAK,CAAC,EAAE,KAAK,KAAK,QAqE9C,CAAA"}
@@ -28,6 +28,7 @@ export const validateOptions = (props)=>async (values, { data, req })=>{
28
28
  }
29
29
  }
30
30
  },
31
+ overrideAccess: true,
31
32
  select: {
32
33
  variants: true,
33
34
  variantTypes: true
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../src/collections/variants/createVariantsCollection/hooks/validateOptions.ts"],"sourcesContent":["import type { Validate } from 'payload'\n\ntype Props = {\n productsCollectionSlug?: string\n}\n\nexport const validateOptions: (props?: Props) => Validate =\n (props) =>\n async (values, { data, req }) => {\n const { productsCollectionSlug = 'products' } = props || {}\n const { t } = req\n\n if (!values || values.length === 0) {\n // @ts-expect-error - TODO: Fix types\n return t('ecommerce:variantOptionsRequired')\n }\n\n const productID = data.product\n\n if (!productID) {\n // @ts-expect-error - TODO: Fix types\n return t('ecommerce:productRequired')\n }\n\n const product = await req.payload.findByID({\n id: productID,\n collection: productsCollectionSlug,\n depth: 1,\n joins: {\n variants: {\n where: {\n deletedAt: { exists: false },\n ...(data.id && {\n id: {\n not_equals: data.id, // exclude the current variant from the search\n },\n }),\n },\n },\n },\n select: {\n variants: true,\n variantTypes: true,\n },\n user: req.user,\n })\n\n // @ts-expect-error - TODO: Fix types\n const variants = product.variants?.docs ?? []\n\n // @ts-expect-error - TODO: Fix types\n if (values.length < product?.variantTypes?.length) {\n // @ts-expect-error - TODO: Fix types\n return t('ecommerce:variantOptionsRequiredAll')\n }\n\n if (variants.length > 0) {\n const existingOptions: (number | string)[][] = []\n\n variants.forEach((variant: any) => {\n existingOptions.push(variant.options)\n })\n\n const exists = existingOptions.some(\n (combo) => combo.length === values.length && combo.every((val) => values.includes(val)),\n )\n\n if (exists) {\n // @ts-expect-error - TODO: Fix types\n return t('ecommerce:variantOptionsAlreadyExists')\n }\n }\n\n return true\n }\n"],"names":["validateOptions","props","values","data","req","productsCollectionSlug","t","length","productID","product","payload","findByID","id","collection","depth","joins","variants","where","deletedAt","exists","not_equals","select","variantTypes","user","docs","existingOptions","forEach","variant","push","options","some","combo","every","val","includes"],"mappings":"AAMA,OAAO,MAAMA,kBACX,CAACC,QACD,OAAOC,QAAQ,EAAEC,IAAI,EAAEC,GAAG,EAAE;QAC1B,MAAM,EAAEC,yBAAyB,UAAU,EAAE,GAAGJ,SAAS,CAAC;QAC1D,MAAM,EAAEK,CAAC,EAAE,GAAGF;QAEd,IAAI,CAACF,UAAUA,OAAOK,MAAM,KAAK,GAAG;YAClC,qCAAqC;YACrC,OAAOD,EAAE;QACX;QAEA,MAAME,YAAYL,KAAKM,OAAO;QAE9B,IAAI,CAACD,WAAW;YACd,qCAAqC;YACrC,OAAOF,EAAE;QACX;QAEA,MAAMG,UAAU,MAAML,IAAIM,OAAO,CAACC,QAAQ,CAAC;YACzCC,IAAIJ;YACJK,YAAYR;YACZS,OAAO;YACPC,OAAO;gBACLC,UAAU;oBACRC,OAAO;wBACLC,WAAW;4BAAEC,QAAQ;wBAAM;wBAC3B,GAAIhB,KAAKS,EAAE,IAAI;4BACbA,IAAI;gCACFQ,YAAYjB,KAAKS,EAAE;4BACrB;wBACF,CAAC;oBACH;gBACF;YACF;YACAS,QAAQ;gBACNL,UAAU;gBACVM,cAAc;YAChB;YACAC,MAAMnB,IAAImB,IAAI;QAChB;QAEA,qCAAqC;QACrC,MAAMP,WAAWP,QAAQO,QAAQ,EAAEQ,QAAQ,EAAE;QAE7C,qCAAqC;QACrC,IAAItB,OAAOK,MAAM,GAAGE,SAASa,cAAcf,QAAQ;YACjD,qCAAqC;YACrC,OAAOD,EAAE;QACX;QAEA,IAAIU,SAAST,MAAM,GAAG,GAAG;YACvB,MAAMkB,kBAAyC,EAAE;YAEjDT,SAASU,OAAO,CAAC,CAACC;gBAChBF,gBAAgBG,IAAI,CAACD,QAAQE,OAAO;YACtC;YAEA,MAAMV,SAASM,gBAAgBK,IAAI,CACjC,CAACC,QAAUA,MAAMxB,MAAM,KAAKL,OAAOK,MAAM,IAAIwB,MAAMC,KAAK,CAAC,CAACC,MAAQ/B,OAAOgC,QAAQ,CAACD;YAGpF,IAAId,QAAQ;gBACV,qCAAqC;gBACrC,OAAOb,EAAE;YACX;QACF;QAEA,OAAO;IACT,EAAC"}
1
+ {"version":3,"sources":["../../../../../src/collections/variants/createVariantsCollection/hooks/validateOptions.ts"],"sourcesContent":["import type { Validate } from 'payload'\n\ntype Props = {\n productsCollectionSlug?: string\n}\n\nexport const validateOptions: (props?: Props) => Validate =\n (props) =>\n async (values, { data, req }) => {\n const { productsCollectionSlug = 'products' } = props || {}\n const { t } = req\n\n if (!values || values.length === 0) {\n // @ts-expect-error - TODO: Fix types\n return t('ecommerce:variantOptionsRequired')\n }\n\n const productID = data.product\n\n if (!productID) {\n // @ts-expect-error - TODO: Fix types\n return t('ecommerce:productRequired')\n }\n\n const product = await req.payload.findByID({\n id: productID,\n collection: productsCollectionSlug,\n depth: 1,\n joins: {\n variants: {\n where: {\n deletedAt: { exists: false },\n ...(data.id && {\n id: {\n not_equals: data.id, // exclude the current variant from the search\n },\n }),\n },\n },\n },\n overrideAccess: true,\n select: {\n variants: true,\n variantTypes: true,\n },\n user: req.user,\n })\n\n // @ts-expect-error - TODO: Fix types\n const variants = product.variants?.docs ?? []\n\n // @ts-expect-error - TODO: Fix types\n if (values.length < product?.variantTypes?.length) {\n // @ts-expect-error - TODO: Fix types\n return t('ecommerce:variantOptionsRequiredAll')\n }\n\n if (variants.length > 0) {\n const existingOptions: (number | string)[][] = []\n\n variants.forEach((variant: any) => {\n existingOptions.push(variant.options)\n })\n\n const exists = existingOptions.some(\n (combo) => combo.length === values.length && combo.every((val) => values.includes(val)),\n )\n\n if (exists) {\n // @ts-expect-error - TODO: Fix types\n return t('ecommerce:variantOptionsAlreadyExists')\n }\n }\n\n return true\n }\n"],"names":["validateOptions","props","values","data","req","productsCollectionSlug","t","length","productID","product","payload","findByID","id","collection","depth","joins","variants","where","deletedAt","exists","not_equals","overrideAccess","select","variantTypes","user","docs","existingOptions","forEach","variant","push","options","some","combo","every","val","includes"],"mappings":"AAMA,OAAO,MAAMA,kBACX,CAACC,QACD,OAAOC,QAAQ,EAAEC,IAAI,EAAEC,GAAG,EAAE;QAC1B,MAAM,EAAEC,yBAAyB,UAAU,EAAE,GAAGJ,SAAS,CAAC;QAC1D,MAAM,EAAEK,CAAC,EAAE,GAAGF;QAEd,IAAI,CAACF,UAAUA,OAAOK,MAAM,KAAK,GAAG;YAClC,qCAAqC;YACrC,OAAOD,EAAE;QACX;QAEA,MAAME,YAAYL,KAAKM,OAAO;QAE9B,IAAI,CAACD,WAAW;YACd,qCAAqC;YACrC,OAAOF,EAAE;QACX;QAEA,MAAMG,UAAU,MAAML,IAAIM,OAAO,CAACC,QAAQ,CAAC;YACzCC,IAAIJ;YACJK,YAAYR;YACZS,OAAO;YACPC,OAAO;gBACLC,UAAU;oBACRC,OAAO;wBACLC,WAAW;4BAAEC,QAAQ;wBAAM;wBAC3B,GAAIhB,KAAKS,EAAE,IAAI;4BACbA,IAAI;gCACFQ,YAAYjB,KAAKS,EAAE;4BACrB;wBACF,CAAC;oBACH;gBACF;YACF;YACAS,gBAAgB;YAChBC,QAAQ;gBACNN,UAAU;gBACVO,cAAc;YAChB;YACAC,MAAMpB,IAAIoB,IAAI;QAChB;QAEA,qCAAqC;QACrC,MAAMR,WAAWP,QAAQO,QAAQ,EAAES,QAAQ,EAAE;QAE7C,qCAAqC;QACrC,IAAIvB,OAAOK,MAAM,GAAGE,SAASc,cAAchB,QAAQ;YACjD,qCAAqC;YACrC,OAAOD,EAAE;QACX;QAEA,IAAIU,SAAST,MAAM,GAAG,GAAG;YACvB,MAAMmB,kBAAyC,EAAE;YAEjDV,SAASW,OAAO,CAAC,CAACC;gBAChBF,gBAAgBG,IAAI,CAACD,QAAQE,OAAO;YACtC;YAEA,MAAMX,SAASO,gBAAgBK,IAAI,CACjC,CAACC,QAAUA,MAAMzB,MAAM,KAAKL,OAAOK,MAAM,IAAIyB,MAAMC,KAAK,CAAC,CAACC,MAAQhC,OAAOiC,QAAQ,CAACD;YAGpF,IAAIf,QAAQ;gBACV,qCAAqC;gBACrC,OAAOb,EAAE;YACX;QACF;QAEA,OAAO;IACT,EAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/collections/variants/createVariantsCollection/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAS,MAAM,SAAS,CAAA;AAEtD,OAAO,KAAK,EAAE,YAAY,EAAE,gBAAgB,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAA;AAO9F,KAAK,KAAK,GAAG;IACX,MAAM,EAAE,IAAI,CAAC,YAAY,EAAE,wBAAwB,GAAG,SAAS,CAAC,CAAA;IAChE,gBAAgB,CAAC,EAAE,gBAAgB,CAAA;IACnC;;OAEG;IACH,SAAS,CAAC,EAAE,OAAO,GAAG,eAAe,CAAA;IACrC;;OAEG;IACH,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB;;OAEG;IACH,kBAAkB,CAAC,EAAE,MAAM,CAAA;IAC3B;;OAEG;IACH,gBAAgB,CAAC,EAAE,MAAM,CAAA;CAC1B,CAAA;AAED,eAAO,MAAM,wBAAwB,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,gBA0GxD,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/collections/variants/createVariantsCollection/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAS,MAAM,SAAS,CAAA;AAEtD,OAAO,KAAK,EAAE,YAAY,EAAE,gBAAgB,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAA;AAO9F,KAAK,KAAK,GAAG;IACX,MAAM,EAAE,IAAI,CAAC,YAAY,EAAE,wBAAwB,GAAG,SAAS,CAAC,CAAA;IAChE,gBAAgB,CAAC,EAAE,gBAAgB,CAAA;IACnC;;OAEG;IACH,SAAS,CAAC,EAAE,OAAO,GAAG,eAAe,CAAA;IACrC;;OAEG;IACH,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB;;OAEG;IACH,kBAAkB,CAAC,EAAE,MAAM,CAAA;IAC3B;;OAEG;IACH,gBAAgB,CAAC,EAAE,MAAM,CAAA;CAC1B,CAAA;AAED,eAAO,MAAM,wBAAwB,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,gBA2GxD,CAAA"}
@@ -79,6 +79,7 @@ export const createVariantsCollection = (props)=>{
79
79
  group: false,
80
80
  useAsTitle: 'title'
81
81
  },
82
+ authorship: false,
82
83
  fields,
83
84
  hooks: {
84
85
  beforeChange: [
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/collections/variants/createVariantsCollection/index.ts"],"sourcesContent":["import type { CollectionConfig, Field } from 'payload'\n\nimport type { AccessConfig, CurrenciesConfig, InventoryConfig } from '../../../types/index.js'\n\nimport { inventoryField } from '../../../fields/inventoryField.js'\nimport { pricesField } from '../../../fields/pricesField.js'\nimport { variantsCollectionBeforeChange as beforeChange } from './hooks/beforeChange.js'\nimport { validateOptions } from './hooks/validateOptions.js'\n\ntype Props = {\n access: Pick<AccessConfig, 'adminOrPublishedStatus' | 'isAdmin'>\n currenciesConfig?: CurrenciesConfig\n /**\n * Enables inventory tracking for variants. Defaults to true.\n */\n inventory?: boolean | InventoryConfig\n /**\n * Slug of the products collection, defaults to 'products'.\n */\n productsSlug?: string\n /**\n * Slug of the variant options collection, defaults to 'variantOptions'.\n */\n variantOptionsSlug?: string\n /**\n * Slug of the variant types collection, defaults to 'variantTypes'.\n */\n variantTypesSlug?: string\n}\n\nexport const createVariantsCollection: (props: Props) => CollectionConfig = (props) => {\n const {\n access,\n currenciesConfig,\n inventory = true,\n productsSlug = 'products',\n variantOptionsSlug = 'variantOptions',\n variantTypesSlug = 'variantTypes',\n } = props || {}\n const { supportedCurrencies } = currenciesConfig || {}\n\n const fields: Field[] = [\n {\n name: 'title',\n type: 'text',\n admin: {\n description:\n 'Used for administrative purposes, not shown to customers. This is populated by default.',\n },\n },\n {\n name: 'product',\n type: 'relationship',\n admin: {\n position: 'sidebar',\n readOnly: true,\n },\n relationTo: productsSlug,\n required: true,\n },\n {\n // This might need to be a custom component, to show a selector for each variant that is\n // enabled on the parent product\n // - separate select inputs, each showing only a specific variant (w/ options)\n // - it will save data to the DB as IDs in this relationship field\n // and needs a validate function as well which enforces that the options are fully specified, and accurate\n name: 'options',\n type: 'relationship',\n admin: {\n components: {\n Field: {\n path: '@payloadcms/plugin-ecommerce/rsc#VariantOptionsSelector',\n },\n },\n },\n custom: {\n productsSlug,\n variantTypesSlug,\n },\n hasMany: true,\n label: 'Variant options',\n relationTo: variantOptionsSlug,\n required: true,\n validate: validateOptions({ productsCollectionSlug: productsSlug }),\n },\n ...(inventory ? [inventoryField()] : []),\n ]\n\n if (supportedCurrencies?.length && supportedCurrencies.length > 0) {\n const currencyOptions: string[] = []\n\n supportedCurrencies.forEach((currency) => {\n currencyOptions.push(currency.code)\n })\n\n if (currenciesConfig) {\n fields.push(...pricesField({ currenciesConfig }))\n }\n }\n\n const baseConfig: CollectionConfig = {\n slug: 'variants',\n access: {\n create: access.isAdmin,\n delete: access.isAdmin,\n read: access.adminOrPublishedStatus,\n update: access.isAdmin,\n },\n admin: {\n description: ({ t }) =>\n // @ts-expect-error - translations are not typed in plugins yet\n t('plugin-ecommerce:variantsCollectionDescription'),\n group: false,\n useAsTitle: 'title',\n },\n fields,\n hooks: {\n beforeChange: [beforeChange({ productsSlug, variantOptionsSlug })],\n },\n labels: {\n plural: ({ t }) =>\n // @ts-expect-error - translations are not typed in plugins yet\n t('plugin-ecommerce:variants'),\n singular: ({ t }) =>\n // @ts-expect-error - translations are not typed in plugins yet\n t('plugin-ecommerce:variant'),\n },\n trash: true,\n versions: {\n drafts: {\n autosave: true,\n },\n },\n }\n\n return baseConfig\n}\n"],"names":["inventoryField","pricesField","variantsCollectionBeforeChange","beforeChange","validateOptions","createVariantsCollection","props","access","currenciesConfig","inventory","productsSlug","variantOptionsSlug","variantTypesSlug","supportedCurrencies","fields","name","type","admin","description","position","readOnly","relationTo","required","components","Field","path","custom","hasMany","label","validate","productsCollectionSlug","length","currencyOptions","forEach","currency","push","code","baseConfig","slug","create","isAdmin","delete","read","adminOrPublishedStatus","update","t","group","useAsTitle","hooks","labels","plural","singular","trash","versions","drafts","autosave"],"mappings":"AAIA,SAASA,cAAc,QAAQ,oCAAmC;AAClE,SAASC,WAAW,QAAQ,iCAAgC;AAC5D,SAASC,kCAAkCC,YAAY,QAAQ,0BAAyB;AACxF,SAASC,eAAe,QAAQ,6BAA4B;AAuB5D,OAAO,MAAMC,2BAA+D,CAACC;IAC3E,MAAM,EACJC,MAAM,EACNC,gBAAgB,EAChBC,YAAY,IAAI,EAChBC,eAAe,UAAU,EACzBC,qBAAqB,gBAAgB,EACrCC,mBAAmB,cAAc,EAClC,GAAGN,SAAS,CAAC;IACd,MAAM,EAAEO,mBAAmB,EAAE,GAAGL,oBAAoB,CAAC;IAErD,MAAMM,SAAkB;QACtB;YACEC,MAAM;YACNC,MAAM;YACNC,OAAO;gBACLC,aACE;YACJ;QACF;QACA;YACEH,MAAM;YACNC,MAAM;YACNC,OAAO;gBACLE,UAAU;gBACVC,UAAU;YACZ;YACAC,YAAYX;YACZY,UAAU;QACZ;QACA;YACE,wFAAwF;YACxF,gCAAgC;YAChC,8EAA8E;YAC9E,kEAAkE;YAClE,0GAA0G;YAC1GP,MAAM;YACNC,MAAM;YACNC,OAAO;gBACLM,YAAY;oBACVC,OAAO;wBACLC,MAAM;oBACR;gBACF;YACF;YACAC,QAAQ;gBACNhB;gBACAE;YACF;YACAe,SAAS;YACTC,OAAO;YACPP,YAAYV;YACZW,UAAU;YACVO,UAAUzB,gBAAgB;gBAAE0B,wBAAwBpB;YAAa;QACnE;WACID,YAAY;YAACT;SAAiB,GAAG,EAAE;KACxC;IAED,IAAIa,qBAAqBkB,UAAUlB,oBAAoBkB,MAAM,GAAG,GAAG;QACjE,MAAMC,kBAA4B,EAAE;QAEpCnB,oBAAoBoB,OAAO,CAAC,CAACC;YAC3BF,gBAAgBG,IAAI,CAACD,SAASE,IAAI;QACpC;QAEA,IAAI5B,kBAAkB;YACpBM,OAAOqB,IAAI,IAAIlC,YAAY;gBAAEO;YAAiB;QAChD;IACF;IAEA,MAAM6B,aAA+B;QACnCC,MAAM;QACN/B,QAAQ;YACNgC,QAAQhC,OAAOiC,OAAO;YACtBC,QAAQlC,OAAOiC,OAAO;YACtBE,MAAMnC,OAAOoC,sBAAsB;YACnCC,QAAQrC,OAAOiC,OAAO;QACxB;QACAvB,OAAO;YACLC,aAAa,CAAC,EAAE2B,CAAC,EAAE,GACjB,+DAA+D;gBAC/DA,EAAE;YACJC,OAAO;YACPC,YAAY;QACd;QACAjC;QACAkC,OAAO;YACL7C,cAAc;gBAACA,aAAa;oBAAEO;oBAAcC;gBAAmB;aAAG;QACpE;QACAsC,QAAQ;YACNC,QAAQ,CAAC,EAAEL,CAAC,EAAE,GACZ,+DAA+D;gBAC/DA,EAAE;YACJM,UAAU,CAAC,EAAEN,CAAC,EAAE,GACd,+DAA+D;gBAC/DA,EAAE;QACN;QACAO,OAAO;QACPC,UAAU;YACRC,QAAQ;gBACNC,UAAU;YACZ;QACF;IACF;IAEA,OAAOlB;AACT,EAAC"}
1
+ {"version":3,"sources":["../../../../src/collections/variants/createVariantsCollection/index.ts"],"sourcesContent":["import type { CollectionConfig, Field } from 'payload'\n\nimport type { AccessConfig, CurrenciesConfig, InventoryConfig } from '../../../types/index.js'\n\nimport { inventoryField } from '../../../fields/inventoryField.js'\nimport { pricesField } from '../../../fields/pricesField.js'\nimport { variantsCollectionBeforeChange as beforeChange } from './hooks/beforeChange.js'\nimport { validateOptions } from './hooks/validateOptions.js'\n\ntype Props = {\n access: Pick<AccessConfig, 'adminOrPublishedStatus' | 'isAdmin'>\n currenciesConfig?: CurrenciesConfig\n /**\n * Enables inventory tracking for variants. Defaults to true.\n */\n inventory?: boolean | InventoryConfig\n /**\n * Slug of the products collection, defaults to 'products'.\n */\n productsSlug?: string\n /**\n * Slug of the variant options collection, defaults to 'variantOptions'.\n */\n variantOptionsSlug?: string\n /**\n * Slug of the variant types collection, defaults to 'variantTypes'.\n */\n variantTypesSlug?: string\n}\n\nexport const createVariantsCollection: (props: Props) => CollectionConfig = (props) => {\n const {\n access,\n currenciesConfig,\n inventory = true,\n productsSlug = 'products',\n variantOptionsSlug = 'variantOptions',\n variantTypesSlug = 'variantTypes',\n } = props || {}\n const { supportedCurrencies } = currenciesConfig || {}\n\n const fields: Field[] = [\n {\n name: 'title',\n type: 'text',\n admin: {\n description:\n 'Used for administrative purposes, not shown to customers. This is populated by default.',\n },\n },\n {\n name: 'product',\n type: 'relationship',\n admin: {\n position: 'sidebar',\n readOnly: true,\n },\n relationTo: productsSlug,\n required: true,\n },\n {\n // This might need to be a custom component, to show a selector for each variant that is\n // enabled on the parent product\n // - separate select inputs, each showing only a specific variant (w/ options)\n // - it will save data to the DB as IDs in this relationship field\n // and needs a validate function as well which enforces that the options are fully specified, and accurate\n name: 'options',\n type: 'relationship',\n admin: {\n components: {\n Field: {\n path: '@payloadcms/plugin-ecommerce/rsc#VariantOptionsSelector',\n },\n },\n },\n custom: {\n productsSlug,\n variantTypesSlug,\n },\n hasMany: true,\n label: 'Variant options',\n relationTo: variantOptionsSlug,\n required: true,\n validate: validateOptions({ productsCollectionSlug: productsSlug }),\n },\n ...(inventory ? [inventoryField()] : []),\n ]\n\n if (supportedCurrencies?.length && supportedCurrencies.length > 0) {\n const currencyOptions: string[] = []\n\n supportedCurrencies.forEach((currency) => {\n currencyOptions.push(currency.code)\n })\n\n if (currenciesConfig) {\n fields.push(...pricesField({ currenciesConfig }))\n }\n }\n\n const baseConfig: CollectionConfig = {\n slug: 'variants',\n access: {\n create: access.isAdmin,\n delete: access.isAdmin,\n read: access.adminOrPublishedStatus,\n update: access.isAdmin,\n },\n admin: {\n description: ({ t }) =>\n // @ts-expect-error - translations are not typed in plugins yet\n t('plugin-ecommerce:variantsCollectionDescription'),\n group: false,\n useAsTitle: 'title',\n },\n authorship: false,\n fields,\n hooks: {\n beforeChange: [beforeChange({ productsSlug, variantOptionsSlug })],\n },\n labels: {\n plural: ({ t }) =>\n // @ts-expect-error - translations are not typed in plugins yet\n t('plugin-ecommerce:variants'),\n singular: ({ t }) =>\n // @ts-expect-error - translations are not typed in plugins yet\n t('plugin-ecommerce:variant'),\n },\n trash: true,\n versions: {\n drafts: {\n autosave: true,\n },\n },\n }\n\n return baseConfig\n}\n"],"names":["inventoryField","pricesField","variantsCollectionBeforeChange","beforeChange","validateOptions","createVariantsCollection","props","access","currenciesConfig","inventory","productsSlug","variantOptionsSlug","variantTypesSlug","supportedCurrencies","fields","name","type","admin","description","position","readOnly","relationTo","required","components","Field","path","custom","hasMany","label","validate","productsCollectionSlug","length","currencyOptions","forEach","currency","push","code","baseConfig","slug","create","isAdmin","delete","read","adminOrPublishedStatus","update","t","group","useAsTitle","authorship","hooks","labels","plural","singular","trash","versions","drafts","autosave"],"mappings":"AAIA,SAASA,cAAc,QAAQ,oCAAmC;AAClE,SAASC,WAAW,QAAQ,iCAAgC;AAC5D,SAASC,kCAAkCC,YAAY,QAAQ,0BAAyB;AACxF,SAASC,eAAe,QAAQ,6BAA4B;AAuB5D,OAAO,MAAMC,2BAA+D,CAACC;IAC3E,MAAM,EACJC,MAAM,EACNC,gBAAgB,EAChBC,YAAY,IAAI,EAChBC,eAAe,UAAU,EACzBC,qBAAqB,gBAAgB,EACrCC,mBAAmB,cAAc,EAClC,GAAGN,SAAS,CAAC;IACd,MAAM,EAAEO,mBAAmB,EAAE,GAAGL,oBAAoB,CAAC;IAErD,MAAMM,SAAkB;QACtB;YACEC,MAAM;YACNC,MAAM;YACNC,OAAO;gBACLC,aACE;YACJ;QACF;QACA;YACEH,MAAM;YACNC,MAAM;YACNC,OAAO;gBACLE,UAAU;gBACVC,UAAU;YACZ;YACAC,YAAYX;YACZY,UAAU;QACZ;QACA;YACE,wFAAwF;YACxF,gCAAgC;YAChC,8EAA8E;YAC9E,kEAAkE;YAClE,0GAA0G;YAC1GP,MAAM;YACNC,MAAM;YACNC,OAAO;gBACLM,YAAY;oBACVC,OAAO;wBACLC,MAAM;oBACR;gBACF;YACF;YACAC,QAAQ;gBACNhB;gBACAE;YACF;YACAe,SAAS;YACTC,OAAO;YACPP,YAAYV;YACZW,UAAU;YACVO,UAAUzB,gBAAgB;gBAAE0B,wBAAwBpB;YAAa;QACnE;WACID,YAAY;YAACT;SAAiB,GAAG,EAAE;KACxC;IAED,IAAIa,qBAAqBkB,UAAUlB,oBAAoBkB,MAAM,GAAG,GAAG;QACjE,MAAMC,kBAA4B,EAAE;QAEpCnB,oBAAoBoB,OAAO,CAAC,CAACC;YAC3BF,gBAAgBG,IAAI,CAACD,SAASE,IAAI;QACpC;QAEA,IAAI5B,kBAAkB;YACpBM,OAAOqB,IAAI,IAAIlC,YAAY;gBAAEO;YAAiB;QAChD;IACF;IAEA,MAAM6B,aAA+B;QACnCC,MAAM;QACN/B,QAAQ;YACNgC,QAAQhC,OAAOiC,OAAO;YACtBC,QAAQlC,OAAOiC,OAAO;YACtBE,MAAMnC,OAAOoC,sBAAsB;YACnCC,QAAQrC,OAAOiC,OAAO;QACxB;QACAvB,OAAO;YACLC,aAAa,CAAC,EAAE2B,CAAC,EAAE,GACjB,+DAA+D;gBAC/DA,EAAE;YACJC,OAAO;YACPC,YAAY;QACd;QACAC,YAAY;QACZlC;QACAmC,OAAO;YACL9C,cAAc;gBAACA,aAAa;oBAAEO;oBAAcC;gBAAmB;aAAG;QACpE;QACAuC,QAAQ;YACNC,QAAQ,CAAC,EAAEN,CAAC,EAAE,GACZ,+DAA+D;gBAC/DA,EAAE;YACJO,UAAU,CAAC,EAAEP,CAAC,EAAE,GACd,+DAA+D;gBAC/DA,EAAE;QACN;QACAQ,OAAO;QACPC,UAAU;YACRC,QAAQ;gBACNC,UAAU;YACZ;QACF;IACF;IAEA,OAAOnB;AACT,EAAC"}
@@ -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,gBAAgB,EAAE,gBAAgB,CAAA;IAClC;;OAEG;IACH,aAAa,CAAC,EAAE,MAAM,CAAA;IACtB;;OAEG;IACH,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,aAAa,EAAE,cAAc,CAAA;IAC7B;;OAEG;IACH,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB;;OAEG;IACH,kBAAkB,CAAC,EAAE,kBAAkB,CAAA;IACvC;;OAEG;IACH,gBAAgB,CAAC,EAAE,MAAM,CAAA;IACzB;;OAEG;IACH,YAAY,CAAC,EAAE,MAAM,CAAA;CACtB,CAAA;AAED,KAAK,mBAAmB,GAAG,CAAC,IAAI,EAAE,IAAI,KAAK,QAAQ,CAAC,SAAS,CAAC,CAAA;AAE9D;;;GAGG;AACH,eAAO,MAAM,mBAAmB,EAAE,mBA0L/B,CAAA"}
1
+ {"version":3,"file":"confirmOrder.d.ts","sourceRoot":"","sources":["../../src/endpoints/confirmOrder.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,KAAK,QAAQ,EAGd,MAAM,SAAS,CAAA;AAEhB,OAAO,KAAK,EACV,gBAAgB,EAChB,cAAc,EACd,kBAAkB,EAEnB,MAAM,mBAAmB,CAAA;AAS1B,KAAK,IAAI,GAAG;IACV;;OAEG;IACH,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,gBAAgB,EAAE,gBAAgB,CAAA;IAClC;;OAEG;IACH,aAAa,CAAC,EAAE,MAAM,CAAA;IACtB;;OAEG;IACH,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,aAAa,EAAE,cAAc,CAAA;IAC7B;;OAEG;IACH,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB;;OAEG;IACH,kBAAkB,CAAC,EAAE,kBAAkB,CAAA;IACvC;;OAEG;IACH,gBAAgB,CAAC,EAAE,MAAM,CAAA;IACzB;;OAEG;IACH,YAAY,CAAC,EAAE,MAAM,CAAA;CACtB,CAAA;AAED,KAAK,mBAAmB,GAAG,CAAC,IAAI,EAAE,IAAI,KAAK,QAAQ,CAAC,SAAS,CAAC,CAAA;AAE9D;;;GAGG;AACH,eAAO,MAAM,mBAAmB,EAAE,mBAgQ/B,CAAA"}
@@ -1,4 +1,6 @@
1
- import { addDataAndFileToRequest } from 'payload';
1
+ import { addDataAndFileToRequest, commitTransaction, initTransaction, killTransaction } from 'payload';
2
+ const SETTLEMENT_POLL_INTERVAL_MS = 25;
3
+ const SETTLEMENT_WAIT_TIMEOUT_MS = 500;
2
4
  /**
3
5
  * 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.
4
6
  * This is the first step in the payment process.
@@ -26,7 +28,7 @@ import { addDataAndFileToRequest } from 'payload';
26
28
  }
27
29
  } else {
28
30
  // Get the email from the data if user is not available
29
- if (data?.customerEmail && typeof data.customerEmail === 'string') {
31
+ if (typeof data?.customerEmail === 'string' && normalizeEmail(data.customerEmail).length > 0) {
30
32
  customerEmail = data.customerEmail;
31
33
  } else {
32
34
  return Response.json({
@@ -83,62 +85,105 @@ import { addDataAndFileToRequest } from 'payload';
83
85
  status: 400
84
86
  });
85
87
  }
88
+ let shouldCommit = false;
86
89
  try {
90
+ const canonicalCartID = cart.id;
91
+ if (canonicalCartID === null || canonicalCartID === undefined || typeof canonicalCartID === 'string' && canonicalCartID.trim() === '') {
92
+ throw new Error('Canonical cart ID is required.');
93
+ }
94
+ const cartCustomerEmail = 'customerEmail' in cart ? cart.customerEmail : undefined;
95
+ const normalizedCartCustomerEmail = normalizeEmail(cartCustomerEmail);
96
+ const normalizedSubmittedCustomerEmail = normalizeEmail(customerEmail);
97
+ const canonicalEmail = user ? normalizeEmail(user.email) : normalizedCartCustomerEmail || normalizedSubmittedCustomerEmail;
98
+ if (!user && normalizedCartCustomerEmail && normalizedSubmittedCustomerEmail !== normalizedCartCustomerEmail) {
99
+ throw new Error('Customer email does not match the cart.');
100
+ }
101
+ shouldCommit = await initTransaction(req);
102
+ const hadActiveTransaction = Boolean(await req.transactionID);
103
+ let didCallFinalizeOrder = false;
104
+ let didFinalizeOrder = false;
105
+ let didRecoverTransientConflict = false;
106
+ let finalizedTransactionID;
107
+ const finalizeOrder = async ({ orderData, transactionID })=>{
108
+ if (didCallFinalizeOrder) {
109
+ throw new Error('Order settlement was already finalized for this request.');
110
+ }
111
+ didCallFinalizeOrder = true;
112
+ finalizedTransactionID = transactionID;
113
+ let order;
114
+ try {
115
+ order = await finalizeTransactionOrder({
116
+ cartID: canonicalCartID,
117
+ cartsSlug,
118
+ orderData,
119
+ ordersSlug,
120
+ productsSlug,
121
+ req,
122
+ transactionID,
123
+ transactionsSlug,
124
+ variantsSlug
125
+ });
126
+ } catch (error) {
127
+ if (!shouldCommit || !isTransientTransactionConflict(error)) {
128
+ throw error;
129
+ }
130
+ // MongoDB reports a losing transactional claim as a transient write conflict rather
131
+ // than a null compare-and-set result. Leave the aborted snapshot before polling.
132
+ await killTransaction(req);
133
+ shouldCommit = false;
134
+ order = await waitForCanonicalOrder({
135
+ ordersSlug,
136
+ req,
137
+ transactionID,
138
+ transactionsSlug
139
+ });
140
+ didRecoverTransientConflict = true;
141
+ }
142
+ didFinalizeOrder = true;
143
+ return order;
144
+ };
87
145
  const paymentResponse = await paymentMethod.confirmOrder({
88
146
  cartsSlug,
89
147
  customersSlug,
90
148
  data: {
91
149
  ...data,
92
- customerEmail
150
+ cartID: canonicalCartID,
151
+ customerEmail: canonicalEmail
93
152
  },
153
+ finalizeOrder,
94
154
  ordersSlug,
95
155
  req,
96
156
  transactionsSlug
97
157
  });
98
- if (paymentResponse.transactionID) {
99
- const transaction = await payload.findByID({
100
- id: paymentResponse.transactionID,
101
- collection: transactionsSlug,
102
- depth: 0,
103
- select: {
104
- id: true,
105
- items: true
106
- }
107
- });
108
- if (transaction && Array.isArray(transaction.items) && transaction.items.length > 0) {
109
- for (const item of transaction.items){
110
- if (item.variant) {
111
- const id = typeof item.variant === 'object' ? item.variant.id : item.variant;
112
- await payload.db.updateOne({
113
- id,
114
- collection: variantsSlug,
115
- data: {
116
- inventory: {
117
- $inc: item.quantity * -1
118
- }
119
- }
120
- });
121
- } else if (item.product) {
122
- const id = typeof item.product === 'object' ? item.product.id : item.product;
123
- await payload.db.updateOne({
124
- id,
125
- collection: productsSlug,
126
- data: {
127
- inventory: {
128
- $inc: item.quantity * -1
129
- }
130
- }
131
- });
132
- }
133
- }
134
- }
158
+ const hasActiveTransaction = Boolean(await req.transactionID);
159
+ const transactionID = paymentResponse.transactionID;
160
+ if (!isValidDocumentID(transactionID)) {
161
+ throw new Error('Transaction ID is missing or invalid.');
162
+ }
163
+ if (!didCallFinalizeOrder) {
164
+ throw new Error('Payment adapter did not finalize the order.');
165
+ }
166
+ if (!didFinalizeOrder) {
167
+ throw new Error('Order settlement did not complete successfully.');
168
+ }
169
+ if (didFinalizeOrder && getRelationshipID(transactionID) !== getRelationshipID(finalizedTransactionID)) {
170
+ throw new Error('Confirmation response transaction does not match the settlement.');
135
171
  }
136
- if ('paymentResponse.transactionID' in paymentResponse && paymentResponse.transactionID) {
137
- delete paymentResponse.transactionID;
172
+ if (hadActiveTransaction && !hasActiveTransaction && !didRecoverTransientConflict) {
173
+ throw new Error('Order confirmation lost its active transaction.');
174
+ }
175
+ if (shouldCommit && hasActiveTransaction) {
176
+ await commitTransaction(req);
138
177
  }
139
178
  return Response.json(paymentResponse);
140
- } catch (error) {
141
- payload.logger.error(error, 'Error confirming order.');
179
+ } catch (err) {
180
+ if (shouldCommit) {
181
+ await killTransaction(req);
182
+ }
183
+ payload.logger.error({
184
+ err,
185
+ msg: 'Error confirming order.'
186
+ });
142
187
  return Response.json({
143
188
  message: 'Error confirming order.'
144
189
  }, {
@@ -146,5 +191,222 @@ import { addDataAndFileToRequest } from 'payload';
146
191
  });
147
192
  }
148
193
  };
194
+ const normalizeEmail = (email)=>typeof email === 'string' ? email.trim().toLowerCase() : '';
195
+ const isValidDocumentID = (id)=>typeof id === 'number' && Number.isFinite(id) || typeof id === 'string' && id.trim().length > 0;
196
+ const finalizeTransactionOrder = async ({ cartID, cartsSlug, orderData, ordersSlug, productsSlug, req, transactionID, transactionsSlug, variantsSlug })=>{
197
+ if (!isValidDocumentID(transactionID)) {
198
+ throw new Error('Transaction ID is missing or invalid.');
199
+ }
200
+ if (!isRecord(orderData)) {
201
+ throw new Error('Order data is missing or invalid.');
202
+ }
203
+ const claimedTransaction = await req.payload.db.updateOne({
204
+ collection: transactionsSlug,
205
+ data: {
206
+ status: 'processing'
207
+ },
208
+ options: {
209
+ atomic: true
210
+ },
211
+ req,
212
+ where: {
213
+ and: [
214
+ {
215
+ id: {
216
+ equals: transactionID
217
+ }
218
+ },
219
+ {
220
+ status: {
221
+ equals: 'pending'
222
+ }
223
+ },
224
+ {
225
+ order: {
226
+ exists: false
227
+ }
228
+ }
229
+ ]
230
+ }
231
+ });
232
+ if (!claimedTransaction) {
233
+ return waitForCanonicalOrder({
234
+ ordersSlug,
235
+ req,
236
+ transactionID,
237
+ transactionsSlug
238
+ });
239
+ }
240
+ if (getRelationshipID(claimedTransaction.id) !== getRelationshipID(transactionID)) {
241
+ throw new Error('Claimed transaction does not match the requested transaction.');
242
+ }
243
+ const transaction = await req.payload.findByID({
244
+ id: transactionID,
245
+ collection: transactionsSlug,
246
+ depth: 0,
247
+ overrideAccess: true,
248
+ req
249
+ });
250
+ if (!transaction || getRelationshipID(transaction.id) !== getRelationshipID(transactionID) || transaction.status !== 'processing') {
251
+ throw new Error('Claimed transaction could not be loaded for settlement.');
252
+ }
253
+ const referencedOrders = await req.payload.find({
254
+ collection: ordersSlug,
255
+ depth: 0,
256
+ limit: 1,
257
+ overrideAccess: true,
258
+ pagination: false,
259
+ req,
260
+ where: {
261
+ transactions: {
262
+ equals: transactionID
263
+ }
264
+ }
265
+ });
266
+ if (referencedOrders.totalDocs !== 0 || referencedOrders.docs.length !== 0) {
267
+ throw new Error('An order already references the claimed transaction.');
268
+ }
269
+ const order = await req.payload.create({
270
+ collection: ordersSlug,
271
+ data: {
272
+ ...orderData,
273
+ transactions: [
274
+ transactionID
275
+ ]
276
+ },
277
+ overrideAccess: true,
278
+ req
279
+ });
280
+ const orderID = requireDocumentID({
281
+ fieldName: 'order ID',
282
+ value: order.id
283
+ });
284
+ await req.payload.update({
285
+ id: cartID,
286
+ collection: cartsSlug,
287
+ data: {
288
+ purchasedAt: new Date().toISOString()
289
+ },
290
+ overrideAccess: true,
291
+ req
292
+ });
293
+ await decrementInventory({
294
+ items: transaction.items,
295
+ productsSlug,
296
+ req,
297
+ variantsSlug
298
+ });
299
+ await req.payload.update({
300
+ id: transactionID,
301
+ collection: transactionsSlug,
302
+ data: {
303
+ order: orderID,
304
+ status: 'succeeded'
305
+ },
306
+ overrideAccess: true,
307
+ req
308
+ });
309
+ return order;
310
+ };
311
+ const decrementInventory = async ({ items, productsSlug, req, variantsSlug })=>{
312
+ if (!Array.isArray(items) || items.length === 0) {
313
+ throw new Error('Inventory transaction items are missing or invalid.');
314
+ }
315
+ for (const item of items){
316
+ if (!isRecord(item) || typeof item.quantity !== 'number' || !Number.isFinite(item.quantity) || item.quantity <= 0) {
317
+ throw new Error('Inventory item quantity is missing or invalid.');
318
+ }
319
+ const hasVariant = item.variant !== null && item.variant !== undefined;
320
+ const id = hasVariant ? item.variant : item.product;
321
+ if (!isValidDocumentID(id)) {
322
+ throw new Error('Inventory item target is missing or invalid.');
323
+ }
324
+ const updatedInventory = await req.payload.db.updateOne({
325
+ id,
326
+ collection: hasVariant ? variantsSlug : productsSlug,
327
+ data: {
328
+ inventory: {
329
+ $inc: item.quantity * -1
330
+ }
331
+ },
332
+ req
333
+ });
334
+ if (!updatedInventory) {
335
+ throw new Error('Inventory item could not be updated.');
336
+ }
337
+ }
338
+ };
339
+ const waitForCanonicalOrder = async ({ ordersSlug, req, transactionID, transactionsSlug })=>{
340
+ const deadline = Date.now() + SETTLEMENT_WAIT_TIMEOUT_MS;
341
+ do {
342
+ const transaction = await req.payload.findByID({
343
+ id: transactionID,
344
+ collection: transactionsSlug,
345
+ depth: 0,
346
+ overrideAccess: true,
347
+ req
348
+ });
349
+ if (!transaction) {
350
+ throw new Error('Canonical transaction was not found.');
351
+ }
352
+ if (transaction.status === 'succeeded') {
353
+ return findExactlyLinkedOrder({
354
+ orderID: transaction.order,
355
+ ordersSlug,
356
+ req,
357
+ transactionID
358
+ });
359
+ }
360
+ if (transaction.status !== 'pending' && transaction.status !== 'processing') {
361
+ throw new Error('Transaction is not available for settlement.');
362
+ }
363
+ if (Date.now() >= deadline) {
364
+ break;
365
+ }
366
+ await new Promise((resolve)=>setTimeout(resolve, Math.min(SETTLEMENT_POLL_INTERVAL_MS, deadline - Date.now())));
367
+ }while (Date.now() <= deadline)
368
+ throw new Error('Transaction settlement did not complete in time.');
369
+ };
370
+ const findExactlyLinkedOrder = async ({ orderID, ordersSlug, req, transactionID })=>{
371
+ const canonicalOrderID = requireDocumentID({
372
+ fieldName: 'order ID',
373
+ value: orderID
374
+ });
375
+ const result = await req.payload.find({
376
+ collection: ordersSlug,
377
+ depth: 0,
378
+ limit: 2,
379
+ overrideAccess: true,
380
+ pagination: false,
381
+ req,
382
+ where: {
383
+ transactions: {
384
+ equals: transactionID
385
+ }
386
+ }
387
+ });
388
+ if (result.totalDocs !== 1 || result.docs.length !== 1 || getRelationshipID(result.docs[0]?.id) !== getRelationshipID(canonicalOrderID)) {
389
+ throw new Error('Transaction does not have exactly one canonical linked order.');
390
+ }
391
+ return result.docs[0];
392
+ };
393
+ const getRelationshipID = (value)=>{
394
+ const id = isRecord(value) ? value.id : value;
395
+ return isValidDocumentID(id) ? String(id) : undefined;
396
+ };
397
+ const requireDocumentID = ({ fieldName, value })=>{
398
+ const id = isRecord(value) ? value.id : value;
399
+ if (!isValidDocumentID(id)) {
400
+ throw new Error(`${fieldName} is missing or invalid.`);
401
+ }
402
+ return id;
403
+ };
404
+ const isRecord = (value)=>typeof value === 'object' && value !== null && !Array.isArray(value);
405
+ const isTransientTransactionConflict = (error)=>{
406
+ if (!isRecord(error)) {
407
+ return false;
408
+ }
409
+ return error.code === 112 || error.codeName === 'WriteConflict' || Array.isArray(error.errorLabels) && error.errorLabels.includes('TransientTransactionError');
410
+ };
149
411
 
150
412
  //# sourceMappingURL=confirmOrder.js.map