@payloadcms/plugin-ecommerce 0.0.1-beta.0 → 3.57.0-internal.36ffe2b

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 (284) hide show
  1. package/dist/collections/addresses/createAddressesCollection.d.ts +21 -0
  2. package/dist/collections/addresses/createAddressesCollection.d.ts.map +1 -0
  3. package/dist/collections/addresses/createAddressesCollection.js +71 -0
  4. package/dist/collections/addresses/createAddressesCollection.js.map +1 -0
  5. package/dist/collections/addresses/defaultAddressFields.d.ts +3 -0
  6. package/dist/collections/addresses/defaultAddressFields.d.ts.map +1 -0
  7. package/dist/collections/addresses/defaultAddressFields.js +72 -0
  8. package/dist/collections/addresses/defaultAddressFields.js.map +1 -0
  9. package/dist/collections/addresses/defaultCountries.d.ts +9 -0
  10. package/dist/collections/addresses/defaultCountries.d.ts.map +1 -0
  11. package/dist/collections/addresses/defaultCountries.js +169 -0
  12. package/dist/collections/addresses/defaultCountries.js.map +1 -0
  13. package/dist/collections/addresses/hooks/beforeChange.d.ts +8 -0
  14. package/dist/collections/addresses/hooks/beforeChange.d.ts.map +1 -0
  15. package/dist/collections/addresses/hooks/beforeChange.js +12 -0
  16. package/dist/collections/addresses/hooks/beforeChange.js.map +1 -0
  17. package/dist/collections/carts/beforeChange.d.ts +8 -0
  18. package/dist/collections/carts/beforeChange.d.ts.map +1 -0
  19. package/dist/collections/carts/beforeChange.js +37 -0
  20. package/dist/collections/carts/beforeChange.js.map +1 -0
  21. package/dist/collections/carts/createCartsCollection.d.ts +29 -0
  22. package/dist/collections/carts/createCartsCollection.d.ts.map +1 -0
  23. package/dist/collections/carts/createCartsCollection.js +138 -0
  24. package/dist/collections/carts/createCartsCollection.js.map +1 -0
  25. package/dist/collections/carts/statusBeforeRead.d.ts +3 -0
  26. package/dist/collections/carts/statusBeforeRead.d.ts.map +1 -0
  27. package/dist/collections/carts/statusBeforeRead.js +18 -0
  28. package/dist/collections/carts/statusBeforeRead.js.map +1 -0
  29. package/dist/collections/orders/createOrdersCollection.d.ts +34 -0
  30. package/dist/collections/orders/createOrdersCollection.d.ts.map +1 -0
  31. package/dist/collections/orders/createOrdersCollection.js +162 -0
  32. package/dist/collections/orders/createOrdersCollection.js.map +1 -0
  33. package/dist/collections/products/createProductsCollection.d.ts +26 -0
  34. package/dist/collections/products/createProductsCollection.d.ts.map +1 -0
  35. package/dist/collections/products/createProductsCollection.js +62 -0
  36. package/dist/collections/products/createProductsCollection.js.map +1 -0
  37. package/dist/collections/transactions/createTransactionsCollection.d.ts +40 -0
  38. package/dist/collections/transactions/createTransactionsCollection.d.ts.map +1 -0
  39. package/dist/collections/transactions/createTransactionsCollection.js +157 -0
  40. package/dist/collections/transactions/createTransactionsCollection.js.map +1 -0
  41. package/dist/collections/variants/createVariantOptionsCollection.d.ts +15 -0
  42. package/dist/collections/variants/createVariantOptionsCollection.d.ts.map +1 -0
  43. package/dist/collections/variants/createVariantOptionsCollection.js +53 -0
  44. package/dist/collections/variants/createVariantOptionsCollection.js.map +1 -0
  45. package/dist/collections/variants/createVariantTypesCollection.d.ts +15 -0
  46. package/dist/collections/variants/createVariantTypesCollection.d.ts.map +1 -0
  47. package/dist/collections/variants/createVariantTypesCollection.js +49 -0
  48. package/dist/collections/variants/createVariantTypesCollection.js.map +1 -0
  49. package/dist/collections/variants/createVariantsCollection/hooks/beforeChange.d.ts +8 -0
  50. package/dist/collections/variants/createVariantsCollection/hooks/beforeChange.d.ts.map +1 -0
  51. package/dist/collections/variants/createVariantsCollection/hooks/beforeChange.js +38 -0
  52. package/dist/collections/variants/createVariantsCollection/hooks/beforeChange.js.map +1 -0
  53. package/dist/collections/variants/createVariantsCollection/hooks/validateOptions.d.ts +7 -0
  54. package/dist/collections/variants/createVariantsCollection/hooks/validateOptions.d.ts.map +1 -0
  55. package/dist/collections/variants/createVariantsCollection/hooks/validateOptions.js +53 -0
  56. package/dist/collections/variants/createVariantsCollection/hooks/validateOptions.js.map +1 -0
  57. package/dist/collections/variants/createVariantsCollection/index.d.ts +24 -0
  58. package/dist/collections/variants/createVariantsCollection/index.d.ts.map +1 -0
  59. package/dist/collections/variants/createVariantsCollection/index.js +101 -0
  60. package/dist/collections/variants/createVariantsCollection/index.js.map +1 -0
  61. package/dist/currencies/index.d.ts +5 -0
  62. package/dist/currencies/index.d.ts.map +1 -0
  63. package/dist/currencies/index.js +20 -0
  64. package/dist/currencies/index.js.map +1 -0
  65. package/dist/endpoints/confirmOrder.d.ts +42 -0
  66. package/dist/endpoints/confirmOrder.d.ts.map +1 -0
  67. package/dist/endpoints/confirmOrder.js +143 -0
  68. package/dist/endpoints/confirmOrder.js.map +1 -0
  69. package/dist/endpoints/initiatePayment.d.ts +43 -0
  70. package/dist/endpoints/initiatePayment.d.ts.map +1 -0
  71. package/dist/endpoints/initiatePayment.js +220 -0
  72. package/dist/endpoints/initiatePayment.js.map +1 -0
  73. package/dist/exports/client/index.d.ts +3 -0
  74. package/dist/exports/client/index.d.ts.map +1 -0
  75. package/dist/exports/client/index.js +4 -0
  76. package/dist/exports/client/index.js.map +1 -0
  77. package/dist/exports/client/react.d.ts +4 -0
  78. package/dist/exports/client/react.d.ts.map +1 -0
  79. package/dist/exports/client/react.js +5 -0
  80. package/dist/exports/client/react.js.map +1 -0
  81. package/dist/exports/payments/stripe.d.ts +2 -0
  82. package/dist/exports/payments/stripe.d.ts.map +1 -0
  83. package/dist/exports/payments/stripe.js +3 -0
  84. package/dist/exports/payments/stripe.js.map +1 -0
  85. package/dist/exports/rsc.d.ts +3 -0
  86. package/dist/exports/rsc.d.ts.map +1 -0
  87. package/dist/exports/rsc.js +4 -0
  88. package/dist/exports/rsc.js.map +1 -0
  89. package/dist/exports/translations.d.ts +2 -0
  90. package/dist/exports/translations.d.ts.map +1 -0
  91. package/dist/exports/translations.js +3 -0
  92. package/dist/exports/translations.js.map +1 -0
  93. package/dist/exports/types.d.ts +2 -0
  94. package/dist/exports/types.d.ts.map +1 -0
  95. package/dist/exports/types.js +3 -0
  96. package/dist/exports/types.js.map +1 -0
  97. package/dist/fields/amountField.d.ts +13 -0
  98. package/dist/fields/amountField.d.ts.map +1 -0
  99. package/dist/fields/amountField.js +33 -0
  100. package/dist/fields/amountField.js.map +1 -0
  101. package/dist/fields/cartItemsField.d.ts +26 -0
  102. package/dist/fields/cartItemsField.d.ts.map +1 -0
  103. package/dist/fields/cartItemsField.js +55 -0
  104. package/dist/fields/cartItemsField.js.map +1 -0
  105. package/dist/fields/currencyField.d.ts +9 -0
  106. package/dist/fields/currencyField.d.ts.map +1 -0
  107. package/dist/fields/currencyField.js +29 -0
  108. package/dist/fields/currencyField.js.map +1 -0
  109. package/dist/fields/inventoryField.d.ts +7 -0
  110. package/dist/fields/inventoryField.d.ts.map +1 -0
  111. package/dist/fields/inventoryField.js +16 -0
  112. package/dist/fields/inventoryField.js.map +1 -0
  113. package/dist/fields/pricesField.d.ts +12 -0
  114. package/dist/fields/pricesField.d.ts.map +1 -0
  115. package/dist/fields/pricesField.js +54 -0
  116. package/dist/fields/pricesField.js.map +1 -0
  117. package/dist/fields/statusField.d.ts +8 -0
  118. package/dist/fields/statusField.d.ts.map +1 -0
  119. package/dist/fields/statusField.js +49 -0
  120. package/dist/fields/statusField.js.map +1 -0
  121. package/dist/fields/variantsFields.d.ts +14 -0
  122. package/dist/fields/variantsFields.d.ts.map +1 -0
  123. package/dist/fields/variantsFields.js +48 -0
  124. package/dist/fields/variantsFields.js.map +1 -0
  125. package/dist/index.d.ts +19 -0
  126. package/dist/index.d.ts.map +1 -0
  127. package/dist/index.js +238 -0
  128. package/dist/index.js.map +1 -0
  129. package/dist/payments/adapters/stripe/confirmOrder.d.ts +11 -0
  130. package/dist/payments/adapters/stripe/confirmOrder.d.ts.map +1 -0
  131. package/dist/payments/adapters/stripe/confirmOrder.js +101 -0
  132. package/dist/payments/adapters/stripe/confirmOrder.js.map +1 -0
  133. package/dist/payments/adapters/stripe/endpoints/webhooks.d.ts +13 -0
  134. package/dist/payments/adapters/stripe/endpoints/webhooks.d.ts.map +1 -0
  135. package/dist/payments/adapters/stripe/endpoints/webhooks.js +53 -0
  136. package/dist/payments/adapters/stripe/endpoints/webhooks.js.map +1 -0
  137. package/dist/payments/adapters/stripe/index.d.ts +60 -0
  138. package/dist/payments/adapters/stripe/index.d.ts.map +1 -0
  139. package/dist/payments/adapters/stripe/index.js +68 -0
  140. package/dist/payments/adapters/stripe/index.js.map +1 -0
  141. package/dist/payments/adapters/stripe/initiatePayment.d.ts +11 -0
  142. package/dist/payments/adapters/stripe/initiatePayment.d.ts.map +1 -0
  143. package/dist/payments/adapters/stripe/initiatePayment.js +102 -0
  144. package/dist/payments/adapters/stripe/initiatePayment.js.map +1 -0
  145. package/dist/react/provider/index.d.ts +41 -0
  146. package/dist/react/provider/index.d.ts.map +1 -0
  147. package/dist/react/provider/index.js +790 -0
  148. package/dist/react/provider/index.js.map +1 -0
  149. package/dist/react/provider/types.d.ts +171 -0
  150. package/dist/react/provider/types.d.ts.map +1 -0
  151. package/dist/react/provider/types.js +3 -0
  152. package/dist/react/provider/types.js.map +1 -0
  153. package/dist/react/provider/utilities.d.ts +9 -0
  154. package/dist/react/provider/utilities.d.ts.map +1 -0
  155. package/dist/react/provider/utilities.js +13 -0
  156. package/dist/react/provider/utilities.js.map +1 -0
  157. package/dist/translations/en.d.ts +3 -0
  158. package/dist/translations/en.d.ts.map +1 -0
  159. package/dist/translations/en.js +86 -0
  160. package/dist/translations/en.js.map +1 -0
  161. package/dist/translations/index.d.ts +7 -0
  162. package/dist/translations/index.d.ts.map +1 -0
  163. package/dist/translations/index.js +6 -0
  164. package/dist/translations/index.js.map +1 -0
  165. package/dist/types.d.ts +658 -0
  166. package/dist/types.d.ts.map +1 -0
  167. package/dist/types.js +3 -0
  168. package/dist/types.js.map +1 -0
  169. package/dist/ui/PriceCell/index.d.ts +12 -0
  170. package/dist/ui/PriceCell/index.d.ts.map +1 -0
  171. package/dist/ui/PriceCell/index.js +38 -0
  172. package/dist/ui/PriceCell/index.js.map +1 -0
  173. package/dist/ui/PriceInput/FormattedInput.d.ts +17 -0
  174. package/dist/ui/PriceInput/FormattedInput.d.ts.map +1 -0
  175. package/dist/ui/PriceInput/FormattedInput.js +146 -0
  176. package/dist/ui/PriceInput/FormattedInput.js.map +1 -0
  177. package/{src/ui/PriceInput/index.scss → dist/ui/PriceInput/index.css} +7 -0
  178. package/dist/ui/PriceInput/index.d.ts +11 -0
  179. package/dist/ui/PriceInput/index.d.ts.map +1 -0
  180. package/dist/ui/PriceInput/index.js +20 -0
  181. package/dist/ui/PriceInput/index.js.map +1 -0
  182. package/dist/ui/PriceRowLabel/index.d.ts +8 -0
  183. package/dist/ui/PriceRowLabel/index.d.ts.map +1 -0
  184. package/dist/ui/PriceRowLabel/index.js +66 -0
  185. package/dist/ui/PriceRowLabel/index.js.map +1 -0
  186. package/dist/ui/VariantOptionsSelector/ErrorBox.d.ts +8 -0
  187. package/dist/ui/VariantOptionsSelector/ErrorBox.d.ts.map +1 -0
  188. package/dist/ui/VariantOptionsSelector/ErrorBox.js +28 -0
  189. package/dist/ui/VariantOptionsSelector/ErrorBox.js.map +1 -0
  190. package/dist/ui/VariantOptionsSelector/OptionsSelect.d.ts +13 -0
  191. package/dist/ui/VariantOptionsSelector/OptionsSelect.d.ts.map +1 -0
  192. package/dist/ui/VariantOptionsSelector/OptionsSelect.js +71 -0
  193. package/dist/ui/VariantOptionsSelector/OptionsSelect.js.map +1 -0
  194. package/dist/ui/VariantOptionsSelector/index.d.ts +6 -0
  195. package/dist/ui/VariantOptionsSelector/index.d.ts.map +1 -0
  196. package/dist/ui/VariantOptionsSelector/index.js +78 -0
  197. package/dist/ui/VariantOptionsSelector/index.js.map +1 -0
  198. package/dist/ui/utilities.d.ts +16 -0
  199. package/dist/ui/utilities.d.ts.map +1 -0
  200. package/dist/ui/utilities.js +26 -0
  201. package/dist/ui/utilities.js.map +1 -0
  202. package/dist/utilities/defaultProductsValidation.d.ts +3 -0
  203. package/dist/utilities/defaultProductsValidation.d.ts.map +1 -0
  204. package/dist/utilities/defaultProductsValidation.js +40 -0
  205. package/dist/utilities/defaultProductsValidation.js.map +1 -0
  206. package/dist/utilities/errorCodes.d.ts +3 -0
  207. package/dist/utilities/errorCodes.d.ts.map +1 -0
  208. package/dist/utilities/errorCodes.js +4 -0
  209. package/dist/utilities/errorCodes.js.map +1 -0
  210. package/dist/utilities/getCollectionSlugMap.d.ts +11 -0
  211. package/dist/utilities/getCollectionSlugMap.d.ts.map +1 -0
  212. package/dist/utilities/getCollectionSlugMap.js +25 -0
  213. package/dist/utilities/getCollectionSlugMap.js.map +1 -0
  214. package/dist/utilities/sanitizePluginConfig.d.ts +7 -0
  215. package/dist/utilities/sanitizePluginConfig.d.ts.map +1 -0
  216. package/dist/utilities/sanitizePluginConfig.js +67 -0
  217. package/dist/utilities/sanitizePluginConfig.js.map +1 -0
  218. package/package.json +98 -1
  219. package/.prettierignore +0 -12
  220. package/.swcrc +0 -24
  221. package/eslint.config.js +0 -18
  222. package/src/addresses/addressesCollection.ts +0 -76
  223. package/src/addresses/defaultAddressFields.ts +0 -83
  224. package/src/addresses/defaultCountries.ts +0 -50
  225. package/src/carts/beforeChange.ts +0 -51
  226. package/src/carts/cartsCollection.ts +0 -146
  227. package/src/currencies/index.ts +0 -29
  228. package/src/endpoints/confirmOrder.ts +0 -312
  229. package/src/endpoints/initiatePayment.ts +0 -322
  230. package/src/exports/addresses.ts +0 -2
  231. package/src/exports/currencies.ts +0 -1
  232. package/src/exports/fields.ts +0 -5
  233. package/src/exports/orders.ts +0 -1
  234. package/src/exports/payments/stripe.ts +0 -1
  235. package/src/exports/plugin.ts +0 -1
  236. package/src/exports/products.ts +0 -1
  237. package/src/exports/react.ts +0 -8
  238. package/src/exports/transactions.ts +0 -1
  239. package/src/exports/translations.ts +0 -1
  240. package/src/exports/types.ts +0 -7
  241. package/src/exports/ui.ts +0 -3
  242. package/src/exports/variants.ts +0 -5
  243. package/src/fields/amountField.ts +0 -43
  244. package/src/fields/cartItemsField.ts +0 -84
  245. package/src/fields/currencyField.ts +0 -39
  246. package/src/fields/inventoryField.ts +0 -22
  247. package/src/fields/pricesField.ts +0 -65
  248. package/src/fields/statusField.ts +0 -57
  249. package/src/fields/variantsFields.ts +0 -56
  250. package/src/index.ts +0 -275
  251. package/src/orders/ordersCollection.ts +0 -157
  252. package/src/payments/adapters/stripe/confirmOrder.ts +0 -123
  253. package/src/payments/adapters/stripe/endpoints/webhooks.ts +0 -69
  254. package/src/payments/adapters/stripe/index.ts +0 -135
  255. package/src/payments/adapters/stripe/initiatePayment.ts +0 -131
  256. package/src/products/productsCollection.ts +0 -78
  257. package/src/react/provider/index.tsx +0 -893
  258. package/src/react/provider/types.ts +0 -184
  259. package/src/react/provider/utilities.ts +0 -22
  260. package/src/transactions/transactionsCollection.ts +0 -166
  261. package/src/translations/en.ts +0 -64
  262. package/src/translations/index.ts +0 -11
  263. package/src/types.ts +0 -403
  264. package/src/ui/PriceInput/FormattedInput.tsx +0 -134
  265. package/src/ui/PriceInput/index.tsx +0 -43
  266. package/src/ui/PriceInput/utilities.ts +0 -46
  267. package/src/ui/PriceRowLabel/index.tsx +0 -56
  268. package/src/ui/VariantOptionsSelector/ErrorBox.tsx +0 -27
  269. package/src/ui/VariantOptionsSelector/OptionsSelect.tsx +0 -78
  270. package/src/ui/VariantOptionsSelector/index.tsx +0 -83
  271. package/src/utilities/defaultProductsValidation.ts +0 -42
  272. package/src/utilities/errorCodes.ts +0 -14
  273. package/src/utilities/getCollectionSlugMap.ts +0 -84
  274. package/src/utilities/sanitizePluginConfig.ts +0 -80
  275. package/src/variants/variantOptionsCollection.ts +0 -59
  276. package/src/variants/variantTypesCollection.ts +0 -55
  277. package/src/variants/variantsCollection/hooks/beforeChange.ts +0 -47
  278. package/src/variants/variantsCollection/hooks/validateOptions.ts +0 -72
  279. package/src/variants/variantsCollection/index.ts +0 -119
  280. package/tsconfig.json +0 -7
  281. package/tsconfig.tsbuildinfo +0 -1
  282. /package/{src → dist}/translations/translation-schema.json +0 -0
  283. /package/{src → dist}/ui/PriceRowLabel/index.css +0 -0
  284. /package/{src → dist}/ui/VariantOptionsSelector/index.css +0 -0
@@ -0,0 +1,21 @@
1
+ import type { CollectionConfig, Field } from 'payload';
2
+ import type { AccessConfig, CountryType } from '../../types.js';
3
+ type Props = {
4
+ access: {
5
+ adminOrCustomerOwner: AccessConfig['adminOrCustomerOwner'];
6
+ authenticatedOnly: NonNullable<AccessConfig['authenticatedOnly']>;
7
+ customerOnlyFieldAccess: AccessConfig['customerOnlyFieldAccess'];
8
+ };
9
+ /**
10
+ * Array of fields used for capturing the address data. Use this over overrides to customise the fields here as it's reused across the plugin.
11
+ */
12
+ addressFields: Field[];
13
+ /**
14
+ * Slug of the customers collection, defaults to 'users'.
15
+ */
16
+ customersSlug?: string;
17
+ supportedCountries?: CountryType[];
18
+ };
19
+ export declare const createAddressesCollection: (props: Props) => CollectionConfig;
20
+ export {};
21
+ //# sourceMappingURL=createAddressesCollection.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createAddressesCollection.d.ts","sourceRoot":"","sources":["../../../src/collections/addresses/createAddressesCollection.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,KAAK,EAAE,MAAM,SAAS,CAAA;AAEtD,OAAO,KAAK,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAA;AAK/D,KAAK,KAAK,GAAG;IACX,MAAM,EAAE;QACN,oBAAoB,EAAE,YAAY,CAAC,sBAAsB,CAAC,CAAA;QAC1D,iBAAiB,EAAE,WAAW,CAAC,YAAY,CAAC,mBAAmB,CAAC,CAAC,CAAA;QACjE,uBAAuB,EAAE,YAAY,CAAC,yBAAyB,CAAC,CAAA;KACjE,CAAA;IACD;;OAEG;IACH,aAAa,EAAE,KAAK,EAAE,CAAA;IACtB;;OAEG;IACH,aAAa,CAAC,EAAE,MAAM,CAAA;IACtB,kBAAkB,CAAC,EAAE,WAAW,EAAE,CAAA;CACnC,CAAA;AAED,eAAO,MAAM,yBAAyB,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,gBA4EzD,CAAA"}
@@ -0,0 +1,71 @@
1
+ import { defaultCountries } from './defaultCountries.js';
2
+ import { beforeChange } from './hooks/beforeChange.js';
3
+ export const createAddressesCollection = (props)=>{
4
+ const { access: { adminOrCustomerOwner, authenticatedOnly, customerOnlyFieldAccess }, addressFields, customersSlug = 'users' } = props || {};
5
+ const { supportedCountries: supportedCountriesFromProps } = props || {};
6
+ const supportedCountries = supportedCountriesFromProps || defaultCountries;
7
+ const hasOnlyOneCountry = supportedCountries && supportedCountries.length === 1;
8
+ const fields = [
9
+ {
10
+ name: 'customer',
11
+ type: 'relationship',
12
+ admin: {
13
+ position: 'sidebar'
14
+ },
15
+ label: ({ t })=>// @ts-expect-error - translations are not typed in plugins yet
16
+ t('plugin-ecommerce:customer'),
17
+ relationTo: customersSlug
18
+ },
19
+ ...addressFields.map((field)=>{
20
+ if ('name' in field && field.name === 'country') {
21
+ return {
22
+ name: 'country',
23
+ type: 'select',
24
+ label: ({ t })=>// @ts-expect-error - translations are not typed in plugins yet
25
+ t('plugin-ecommerce:addressCountry'),
26
+ options: supportedCountries || defaultCountries,
27
+ required: true,
28
+ ...supportedCountries && supportedCountries?.[0] && hasOnlyOneCountry ? {
29
+ defaultValue: supportedCountries?.[0].value
30
+ } : {}
31
+ };
32
+ }
33
+ return field;
34
+ })
35
+ ];
36
+ const baseConfig = {
37
+ slug: 'addresses',
38
+ access: {
39
+ create: authenticatedOnly,
40
+ delete: adminOrCustomerOwner,
41
+ read: adminOrCustomerOwner,
42
+ update: adminOrCustomerOwner
43
+ },
44
+ admin: {
45
+ description: ({ t })=>// @ts-expect-error - translations are not typed in plugins yet
46
+ t('plugin-ecommerce:addressesCollectionDescription'),
47
+ group: 'Ecommerce',
48
+ useAsTitle: 'createdAt'
49
+ },
50
+ fields,
51
+ hooks: {
52
+ beforeChange: [
53
+ beforeChange({
54
+ customerOnlyFieldAccess
55
+ })
56
+ ]
57
+ },
58
+ labels: {
59
+ plural: ({ t })=>// @ts-expect-error - translations are not typed in plugins yet
60
+ t('plugin-ecommerce:addresses'),
61
+ singular: ({ t })=>// @ts-expect-error - translations are not typed in plugins yet
62
+ t('plugin-ecommerce:address')
63
+ },
64
+ timestamps: true
65
+ };
66
+ return {
67
+ ...baseConfig
68
+ };
69
+ };
70
+
71
+ //# sourceMappingURL=createAddressesCollection.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/collections/addresses/createAddressesCollection.ts"],"sourcesContent":["import type { CollectionConfig, Field } from 'payload'\n\nimport type { AccessConfig, CountryType } from '../../types.js'\n\nimport { defaultCountries } from './defaultCountries.js'\nimport { beforeChange } from './hooks/beforeChange.js'\n\ntype Props = {\n access: {\n adminOrCustomerOwner: AccessConfig['adminOrCustomerOwner']\n authenticatedOnly: NonNullable<AccessConfig['authenticatedOnly']>\n customerOnlyFieldAccess: AccessConfig['customerOnlyFieldAccess']\n }\n /**\n * Array of fields used for capturing the address data. Use this over overrides to customise the fields here as it's reused across the plugin.\n */\n addressFields: Field[]\n /**\n * Slug of the customers collection, defaults to 'users'.\n */\n customersSlug?: string\n supportedCountries?: CountryType[]\n}\n\nexport const createAddressesCollection: (props: Props) => CollectionConfig = (props) => {\n const {\n access: { adminOrCustomerOwner, authenticatedOnly, customerOnlyFieldAccess },\n addressFields,\n customersSlug = 'users',\n } = props || {}\n\n const { supportedCountries: supportedCountriesFromProps } = props || {}\n const supportedCountries = supportedCountriesFromProps || defaultCountries\n const hasOnlyOneCountry = supportedCountries && supportedCountries.length === 1\n\n const fields: Field[] = [\n {\n name: 'customer',\n type: 'relationship',\n admin: {\n position: 'sidebar',\n },\n label: ({ t }) =>\n // @ts-expect-error - translations are not typed in plugins yet\n t('plugin-ecommerce:customer'),\n relationTo: customersSlug,\n },\n ...addressFields.map((field) => {\n if ('name' in field && field.name === 'country') {\n return {\n name: 'country',\n type: 'select',\n label: ({ t }) =>\n // @ts-expect-error - translations are not typed in plugins yet\n t('plugin-ecommerce:addressCountry'),\n options: supportedCountries || defaultCountries,\n required: true,\n ...(supportedCountries && supportedCountries?.[0] && hasOnlyOneCountry\n ? {\n defaultValue: supportedCountries?.[0].value,\n }\n : {}),\n } as Field\n }\n\n return field\n }),\n ]\n\n const baseConfig: CollectionConfig = {\n slug: 'addresses',\n access: {\n create: authenticatedOnly,\n delete: adminOrCustomerOwner,\n read: adminOrCustomerOwner,\n update: adminOrCustomerOwner,\n },\n admin: {\n description: ({ t }) =>\n // @ts-expect-error - translations are not typed in plugins yet\n t('plugin-ecommerce:addressesCollectionDescription'),\n group: 'Ecommerce',\n useAsTitle: 'createdAt',\n },\n fields,\n hooks: {\n beforeChange: [beforeChange({ customerOnlyFieldAccess })],\n },\n labels: {\n plural: ({ t }) =>\n // @ts-expect-error - translations are not typed in plugins yet\n t('plugin-ecommerce:addresses'),\n singular: ({ t }) =>\n // @ts-expect-error - translations are not typed in plugins yet\n t('plugin-ecommerce:address'),\n },\n timestamps: true,\n }\n\n return { ...baseConfig }\n}\n"],"names":["defaultCountries","beforeChange","createAddressesCollection","props","access","adminOrCustomerOwner","authenticatedOnly","customerOnlyFieldAccess","addressFields","customersSlug","supportedCountries","supportedCountriesFromProps","hasOnlyOneCountry","length","fields","name","type","admin","position","label","t","relationTo","map","field","options","required","defaultValue","value","baseConfig","slug","create","delete","read","update","description","group","useAsTitle","hooks","labels","plural","singular","timestamps"],"mappings":"AAIA,SAASA,gBAAgB,QAAQ,wBAAuB;AACxD,SAASC,YAAY,QAAQ,0BAAyB;AAmBtD,OAAO,MAAMC,4BAAgE,CAACC;IAC5E,MAAM,EACJC,QAAQ,EAAEC,oBAAoB,EAAEC,iBAAiB,EAAEC,uBAAuB,EAAE,EAC5EC,aAAa,EACbC,gBAAgB,OAAO,EACxB,GAAGN,SAAS,CAAC;IAEd,MAAM,EAAEO,oBAAoBC,2BAA2B,EAAE,GAAGR,SAAS,CAAC;IACtE,MAAMO,qBAAqBC,+BAA+BX;IAC1D,MAAMY,oBAAoBF,sBAAsBA,mBAAmBG,MAAM,KAAK;IAE9E,MAAMC,SAAkB;QACtB;YACEC,MAAM;YACNC,MAAM;YACNC,OAAO;gBACLC,UAAU;YACZ;YACAC,OAAO,CAAC,EAAEC,CAAC,EAAE,GACX,+DAA+D;gBAC/DA,EAAE;YACJC,YAAYZ;QACd;WACGD,cAAcc,GAAG,CAAC,CAACC;YACpB,IAAI,UAAUA,SAASA,MAAMR,IAAI,KAAK,WAAW;gBAC/C,OAAO;oBACLA,MAAM;oBACNC,MAAM;oBACNG,OAAO,CAAC,EAAEC,CAAC,EAAE,GACX,+DAA+D;wBAC/DA,EAAE;oBACJI,SAASd,sBAAsBV;oBAC/ByB,UAAU;oBACV,GAAIf,sBAAsBA,oBAAoB,CAAC,EAAE,IAAIE,oBACjD;wBACEc,cAAchB,oBAAoB,CAAC,EAAE,CAACiB;oBACxC,IACA,CAAC,CAAC;gBACR;YACF;YAEA,OAAOJ;QACT;KACD;IAED,MAAMK,aAA+B;QACnCC,MAAM;QACNzB,QAAQ;YACN0B,QAAQxB;YACRyB,QAAQ1B;YACR2B,MAAM3B;YACN4B,QAAQ5B;QACV;QACAY,OAAO;YACLiB,aAAa,CAAC,EAAEd,CAAC,EAAE,GACjB,+DAA+D;gBAC/DA,EAAE;YACJe,OAAO;YACPC,YAAY;QACd;QACAtB;QACAuB,OAAO;YACLpC,cAAc;gBAACA,aAAa;oBAAEM;gBAAwB;aAAG;QAC3D;QACA+B,QAAQ;YACNC,QAAQ,CAAC,EAAEnB,CAAC,EAAE,GACZ,+DAA+D;gBAC/DA,EAAE;YACJoB,UAAU,CAAC,EAAEpB,CAAC,EAAE,GACd,+DAA+D;gBAC/DA,EAAE;QACN;QACAqB,YAAY;IACd;IAEA,OAAO;QAAE,GAAGb,UAAU;IAAC;AACzB,EAAC"}
@@ -0,0 +1,3 @@
1
+ import type { Field } from 'payload';
2
+ export declare const defaultAddressFields: () => Field[];
3
+ //# sourceMappingURL=defaultAddressFields.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"defaultAddressFields.d.ts","sourceRoot":"","sources":["../../../src/collections/addresses/defaultAddressFields.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,SAAS,CAAA;AAEpC,eAAO,MAAM,oBAAoB,EAAE,MAAM,KAAK,EAgF7C,CAAA"}
@@ -0,0 +1,72 @@
1
+ export const defaultAddressFields = ()=>{
2
+ return [
3
+ {
4
+ name: 'title',
5
+ type: 'text',
6
+ label: ({ t })=>// @ts-expect-error - translations are not typed in plugins yet
7
+ t('plugin-ecommerce:addressTitle')
8
+ },
9
+ {
10
+ name: 'firstName',
11
+ type: 'text',
12
+ label: ({ t })=>// @ts-expect-error - translations are not typed in plugins yet
13
+ t('plugin-ecommerce:addressFirstName')
14
+ },
15
+ {
16
+ name: 'lastName',
17
+ type: 'text',
18
+ label: ({ t })=>// @ts-expect-error - translations are not typed in plugins yet
19
+ t('plugin-ecommerce:addressLastName')
20
+ },
21
+ {
22
+ name: 'company',
23
+ type: 'text',
24
+ label: ({ t })=>// @ts-expect-error - translations are not typed in plugins yet
25
+ t('plugin-ecommerce:addressCompany')
26
+ },
27
+ {
28
+ name: 'addressLine1',
29
+ type: 'text',
30
+ label: ({ t })=>// @ts-expect-error - translations are not typed in plugins yet
31
+ t('plugin-ecommerce:addressLine1')
32
+ },
33
+ {
34
+ name: 'addressLine2',
35
+ type: 'text',
36
+ label: ({ t })=>// @ts-expect-error - translations are not typed in plugins yet
37
+ t('plugin-ecommerce:addressLine2')
38
+ },
39
+ {
40
+ name: 'city',
41
+ type: 'text',
42
+ label: ({ t })=>// @ts-expect-error - translations are not typed in plugins yet
43
+ t('plugin-ecommerce:addressCity')
44
+ },
45
+ {
46
+ name: 'state',
47
+ type: 'text',
48
+ label: ({ t })=>// @ts-expect-error - translations are not typed in plugins yet
49
+ t('plugin-ecommerce:addressState')
50
+ },
51
+ {
52
+ name: 'postalCode',
53
+ type: 'text',
54
+ label: ({ t })=>// @ts-expect-error - translations are not typed in plugins yet
55
+ t('plugin-ecommerce:addressPostalCode')
56
+ },
57
+ {
58
+ name: 'country',
59
+ type: 'text',
60
+ label: ({ t })=>// @ts-expect-error - translations are not typed in plugins yet
61
+ t('plugin-ecommerce:addressCountry')
62
+ },
63
+ {
64
+ name: 'phone',
65
+ type: 'text',
66
+ label: ({ t })=>// @ts-expect-error - translations are not typed in plugins yet
67
+ t('plugin-ecommerce:addressPhone')
68
+ }
69
+ ];
70
+ };
71
+
72
+ //# sourceMappingURL=defaultAddressFields.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/collections/addresses/defaultAddressFields.ts"],"sourcesContent":["import type { Field } from 'payload'\n\nexport const defaultAddressFields: () => Field[] = () => {\n return [\n {\n name: 'title',\n type: 'text',\n label: ({ t }) =>\n // @ts-expect-error - translations are not typed in plugins yet\n t('plugin-ecommerce:addressTitle'),\n },\n {\n name: 'firstName',\n type: 'text',\n label: ({ t }) =>\n // @ts-expect-error - translations are not typed in plugins yet\n t('plugin-ecommerce:addressFirstName'),\n },\n {\n name: 'lastName',\n type: 'text',\n label: ({ t }) =>\n // @ts-expect-error - translations are not typed in plugins yet\n t('plugin-ecommerce:addressLastName'),\n },\n {\n name: 'company',\n type: 'text',\n label: ({ t }) =>\n // @ts-expect-error - translations are not typed in plugins yet\n t('plugin-ecommerce:addressCompany'),\n },\n {\n name: 'addressLine1',\n type: 'text',\n label: ({ t }) =>\n // @ts-expect-error - translations are not typed in plugins yet\n t('plugin-ecommerce:addressLine1'),\n },\n {\n name: 'addressLine2',\n type: 'text',\n label: ({ t }) =>\n // @ts-expect-error - translations are not typed in plugins yet\n t('plugin-ecommerce:addressLine2'),\n },\n {\n name: 'city',\n type: 'text',\n label: ({ t }) =>\n // @ts-expect-error - translations are not typed in plugins yet\n t('plugin-ecommerce:addressCity'),\n },\n {\n name: 'state',\n type: 'text',\n label: ({ t }) =>\n // @ts-expect-error - translations are not typed in plugins yet\n t('plugin-ecommerce:addressState'),\n },\n {\n name: 'postalCode',\n type: 'text',\n label: ({ t }) =>\n // @ts-expect-error - translations are not typed in plugins yet\n t('plugin-ecommerce:addressPostalCode'),\n },\n {\n name: 'country',\n type: 'text',\n label: ({ t }) =>\n // @ts-expect-error - translations are not typed in plugins yet\n t('plugin-ecommerce:addressCountry'),\n },\n {\n name: 'phone',\n type: 'text',\n label: ({ t }) =>\n // @ts-expect-error - translations are not typed in plugins yet\n t('plugin-ecommerce:addressPhone'),\n },\n ]\n}\n"],"names":["defaultAddressFields","name","type","label","t"],"mappings":"AAEA,OAAO,MAAMA,uBAAsC;IACjD,OAAO;QACL;YACEC,MAAM;YACNC,MAAM;YACNC,OAAO,CAAC,EAAEC,CAAC,EAAE,GACX,+DAA+D;gBAC/DA,EAAE;QACN;QACA;YACEH,MAAM;YACNC,MAAM;YACNC,OAAO,CAAC,EAAEC,CAAC,EAAE,GACX,+DAA+D;gBAC/DA,EAAE;QACN;QACA;YACEH,MAAM;YACNC,MAAM;YACNC,OAAO,CAAC,EAAEC,CAAC,EAAE,GACX,+DAA+D;gBAC/DA,EAAE;QACN;QACA;YACEH,MAAM;YACNC,MAAM;YACNC,OAAO,CAAC,EAAEC,CAAC,EAAE,GACX,+DAA+D;gBAC/DA,EAAE;QACN;QACA;YACEH,MAAM;YACNC,MAAM;YACNC,OAAO,CAAC,EAAEC,CAAC,EAAE,GACX,+DAA+D;gBAC/DA,EAAE;QACN;QACA;YACEH,MAAM;YACNC,MAAM;YACNC,OAAO,CAAC,EAAEC,CAAC,EAAE,GACX,+DAA+D;gBAC/DA,EAAE;QACN;QACA;YACEH,MAAM;YACNC,MAAM;YACNC,OAAO,CAAC,EAAEC,CAAC,EAAE,GACX,+DAA+D;gBAC/DA,EAAE;QACN;QACA;YACEH,MAAM;YACNC,MAAM;YACNC,OAAO,CAAC,EAAEC,CAAC,EAAE,GACX,+DAA+D;gBAC/DA,EAAE;QACN;QACA;YACEH,MAAM;YACNC,MAAM;YACNC,OAAO,CAAC,EAAEC,CAAC,EAAE,GACX,+DAA+D;gBAC/DA,EAAE;QACN;QACA;YACEH,MAAM;YACNC,MAAM;YACNC,OAAO,CAAC,EAAEC,CAAC,EAAE,GACX,+DAA+D;gBAC/DA,EAAE;QACN;QACA;YACEH,MAAM;YACNC,MAAM;YACNC,OAAO,CAAC,EAAEC,CAAC,EAAE,GACX,+DAA+D;gBAC/DA,EAAE;QACN;KACD;AACH,EAAC"}
@@ -0,0 +1,9 @@
1
+ import type { CountryType } from '../../types.js';
2
+ /**
3
+ * Default list of countries supported for forms and payments.
4
+ * This can be overriden or reused in other parts of the application.
5
+ *
6
+ * The label is the human-readable name of the country, and the value is the ISO 3166-1 alpha-2 code.
7
+ */
8
+ export declare const defaultCountries: CountryType[];
9
+ //# sourceMappingURL=defaultCountries.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"defaultCountries.d.ts","sourceRoot":"","sources":["../../../src/collections/addresses/defaultCountries.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAA;AAEjD;;;;;GAKG;AACH,eAAO,MAAM,gBAAgB,EAAE,WAAW,EAyCzC,CAAA"}
@@ -0,0 +1,169 @@
1
+ /**
2
+ * Default list of countries supported for forms and payments.
3
+ * This can be overriden or reused in other parts of the application.
4
+ *
5
+ * The label is the human-readable name of the country, and the value is the ISO 3166-1 alpha-2 code.
6
+ */ export const defaultCountries = [
7
+ {
8
+ label: 'United States',
9
+ value: 'US'
10
+ },
11
+ {
12
+ label: 'United Kingdom',
13
+ value: 'GB'
14
+ },
15
+ {
16
+ label: 'Canada',
17
+ value: 'CA'
18
+ },
19
+ {
20
+ label: 'Australia',
21
+ value: 'AU'
22
+ },
23
+ {
24
+ label: 'Austria',
25
+ value: 'AT'
26
+ },
27
+ {
28
+ label: 'Belgium',
29
+ value: 'BE'
30
+ },
31
+ {
32
+ label: 'Brazil',
33
+ value: 'BR'
34
+ },
35
+ {
36
+ label: 'Bulgaria',
37
+ value: 'BG'
38
+ },
39
+ {
40
+ label: 'Cyprus',
41
+ value: 'CY'
42
+ },
43
+ {
44
+ label: 'Czech Republic',
45
+ value: 'CZ'
46
+ },
47
+ {
48
+ label: 'Denmark',
49
+ value: 'DK'
50
+ },
51
+ {
52
+ label: 'Estonia',
53
+ value: 'EE'
54
+ },
55
+ {
56
+ label: 'Finland',
57
+ value: 'FI'
58
+ },
59
+ {
60
+ label: 'France',
61
+ value: 'FR'
62
+ },
63
+ {
64
+ label: 'Germany',
65
+ value: 'DE'
66
+ },
67
+ {
68
+ label: 'Greece',
69
+ value: 'GR'
70
+ },
71
+ {
72
+ label: 'Hong Kong',
73
+ value: 'HK'
74
+ },
75
+ {
76
+ label: 'Hungary',
77
+ value: 'HU'
78
+ },
79
+ {
80
+ label: 'India',
81
+ value: 'IN'
82
+ },
83
+ {
84
+ label: 'Ireland',
85
+ value: 'IE'
86
+ },
87
+ {
88
+ label: 'Italy',
89
+ value: 'IT'
90
+ },
91
+ {
92
+ label: 'Japan',
93
+ value: 'JP'
94
+ },
95
+ {
96
+ label: 'Latvia',
97
+ value: 'LV'
98
+ },
99
+ {
100
+ label: 'Lithuania',
101
+ value: 'LT'
102
+ },
103
+ {
104
+ label: 'Luxembourg',
105
+ value: 'LU'
106
+ },
107
+ {
108
+ label: 'Malaysia',
109
+ value: 'MY'
110
+ },
111
+ {
112
+ label: 'Malta',
113
+ value: 'MT'
114
+ },
115
+ {
116
+ label: 'Mexico',
117
+ value: 'MX'
118
+ },
119
+ {
120
+ label: 'Netherlands',
121
+ value: 'NL'
122
+ },
123
+ {
124
+ label: 'New Zealand',
125
+ value: 'NZ'
126
+ },
127
+ {
128
+ label: 'Norway',
129
+ value: 'NO'
130
+ },
131
+ {
132
+ label: 'Poland',
133
+ value: 'PL'
134
+ },
135
+ {
136
+ label: 'Portugal',
137
+ value: 'PT'
138
+ },
139
+ {
140
+ label: 'Romania',
141
+ value: 'RO'
142
+ },
143
+ {
144
+ label: 'Singapore',
145
+ value: 'SG'
146
+ },
147
+ {
148
+ label: 'Slovakia',
149
+ value: 'SK'
150
+ },
151
+ {
152
+ label: 'Slovenia',
153
+ value: 'SI'
154
+ },
155
+ {
156
+ label: 'Spain',
157
+ value: 'ES'
158
+ },
159
+ {
160
+ label: 'Sweden',
161
+ value: 'SE'
162
+ },
163
+ {
164
+ label: 'Switzerland',
165
+ value: 'CH'
166
+ }
167
+ ];
168
+
169
+ //# sourceMappingURL=defaultCountries.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/collections/addresses/defaultCountries.ts"],"sourcesContent":["import type { CountryType } from '../../types.js'\n\n/**\n * Default list of countries supported for forms and payments.\n * This can be overriden or reused in other parts of the application.\n *\n * The label is the human-readable name of the country, and the value is the ISO 3166-1 alpha-2 code.\n */\nexport const defaultCountries: CountryType[] = [\n { label: 'United States', value: 'US' },\n { label: 'United Kingdom', value: 'GB' },\n { label: 'Canada', value: 'CA' },\n { label: 'Australia', value: 'AU' },\n { label: 'Austria', value: 'AT' },\n { label: 'Belgium', value: 'BE' },\n { label: 'Brazil', value: 'BR' },\n { label: 'Bulgaria', value: 'BG' },\n { label: 'Cyprus', value: 'CY' },\n { label: 'Czech Republic', value: 'CZ' },\n { label: 'Denmark', value: 'DK' },\n { label: 'Estonia', value: 'EE' },\n { label: 'Finland', value: 'FI' },\n { label: 'France', value: 'FR' },\n { label: 'Germany', value: 'DE' },\n { label: 'Greece', value: 'GR' },\n { label: 'Hong Kong', value: 'HK' },\n { label: 'Hungary', value: 'HU' },\n { label: 'India', value: 'IN' },\n { label: 'Ireland', value: 'IE' },\n { label: 'Italy', value: 'IT' },\n { label: 'Japan', value: 'JP' },\n { label: 'Latvia', value: 'LV' },\n { label: 'Lithuania', value: 'LT' },\n { label: 'Luxembourg', value: 'LU' },\n { label: 'Malaysia', value: 'MY' },\n { label: 'Malta', value: 'MT' },\n { label: 'Mexico', value: 'MX' },\n { label: 'Netherlands', value: 'NL' },\n { label: 'New Zealand', value: 'NZ' },\n { label: 'Norway', value: 'NO' },\n { label: 'Poland', value: 'PL' },\n { label: 'Portugal', value: 'PT' },\n { label: 'Romania', value: 'RO' },\n { label: 'Singapore', value: 'SG' },\n { label: 'Slovakia', value: 'SK' },\n { label: 'Slovenia', value: 'SI' },\n { label: 'Spain', value: 'ES' },\n { label: 'Sweden', value: 'SE' },\n { label: 'Switzerland', value: 'CH' },\n]\n"],"names":["defaultCountries","label","value"],"mappings":"AAEA;;;;;CAKC,GACD,OAAO,MAAMA,mBAAkC;IAC7C;QAAEC,OAAO;QAAiBC,OAAO;IAAK;IACtC;QAAED,OAAO;QAAkBC,OAAO;IAAK;IACvC;QAAED,OAAO;QAAUC,OAAO;IAAK;IAC/B;QAAED,OAAO;QAAaC,OAAO;IAAK;IAClC;QAAED,OAAO;QAAWC,OAAO;IAAK;IAChC;QAAED,OAAO;QAAWC,OAAO;IAAK;IAChC;QAAED,OAAO;QAAUC,OAAO;IAAK;IAC/B;QAAED,OAAO;QAAYC,OAAO;IAAK;IACjC;QAAED,OAAO;QAAUC,OAAO;IAAK;IAC/B;QAAED,OAAO;QAAkBC,OAAO;IAAK;IACvC;QAAED,OAAO;QAAWC,OAAO;IAAK;IAChC;QAAED,OAAO;QAAWC,OAAO;IAAK;IAChC;QAAED,OAAO;QAAWC,OAAO;IAAK;IAChC;QAAED,OAAO;QAAUC,OAAO;IAAK;IAC/B;QAAED,OAAO;QAAWC,OAAO;IAAK;IAChC;QAAED,OAAO;QAAUC,OAAO;IAAK;IAC/B;QAAED,OAAO;QAAaC,OAAO;IAAK;IAClC;QAAED,OAAO;QAAWC,OAAO;IAAK;IAChC;QAAED,OAAO;QAASC,OAAO;IAAK;IAC9B;QAAED,OAAO;QAAWC,OAAO;IAAK;IAChC;QAAED,OAAO;QAASC,OAAO;IAAK;IAC9B;QAAED,OAAO;QAASC,OAAO;IAAK;IAC9B;QAAED,OAAO;QAAUC,OAAO;IAAK;IAC/B;QAAED,OAAO;QAAaC,OAAO;IAAK;IAClC;QAAED,OAAO;QAAcC,OAAO;IAAK;IACnC;QAAED,OAAO;QAAYC,OAAO;IAAK;IACjC;QAAED,OAAO;QAASC,OAAO;IAAK;IAC9B;QAAED,OAAO;QAAUC,OAAO;IAAK;IAC/B;QAAED,OAAO;QAAeC,OAAO;IAAK;IACpC;QAAED,OAAO;QAAeC,OAAO;IAAK;IACpC;QAAED,OAAO;QAAUC,OAAO;IAAK;IAC/B;QAAED,OAAO;QAAUC,OAAO;IAAK;IAC/B;QAAED,OAAO;QAAYC,OAAO;IAAK;IACjC;QAAED,OAAO;QAAWC,OAAO;IAAK;IAChC;QAAED,OAAO;QAAaC,OAAO;IAAK;IAClC;QAAED,OAAO;QAAYC,OAAO;IAAK;IACjC;QAAED,OAAO;QAAYC,OAAO;IAAK;IACjC;QAAED,OAAO;QAASC,OAAO;IAAK;IAC9B;QAAED,OAAO;QAAUC,OAAO;IAAK;IAC/B;QAAED,OAAO;QAAeC,OAAO;IAAK;CACrC,CAAA"}
@@ -0,0 +1,8 @@
1
+ import type { CollectionBeforeChangeHook } from 'payload';
2
+ import type { AccessConfig } from '../../../types.js';
3
+ interface Props {
4
+ customerOnlyFieldAccess: AccessConfig['customerOnlyFieldAccess'];
5
+ }
6
+ export declare const beforeChange: (args: Props) => CollectionBeforeChangeHook;
7
+ export {};
8
+ //# sourceMappingURL=beforeChange.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"beforeChange.d.ts","sourceRoot":"","sources":["../../../../src/collections/addresses/hooks/beforeChange.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,SAAS,CAAA;AAEzD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AAErD,UAAU,KAAK;IACb,uBAAuB,EAAE,YAAY,CAAC,yBAAyB,CAAC,CAAA;CACjE;AAED,eAAO,MAAM,YAAY,EAAE,CAAC,IAAI,EAAE,KAAK,KAAK,0BAUzC,CAAA"}
@@ -0,0 +1,12 @@
1
+ export const beforeChange = ({ customerOnlyFieldAccess })=>async ({ data, req })=>{
2
+ const isCustomer = await customerOnlyFieldAccess({
3
+ req
4
+ });
5
+ // Ensure that the customer field is set to the current user's ID if the user is a customer.
6
+ // Admins can set to any customer.
7
+ if (req.user && isCustomer) {
8
+ data.customer = req.user.id;
9
+ }
10
+ };
11
+
12
+ //# sourceMappingURL=beforeChange.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../src/collections/addresses/hooks/beforeChange.ts"],"sourcesContent":["import type { CollectionBeforeChangeHook } from 'payload'\n\nimport type { AccessConfig } from '../../../types.js'\n\ninterface Props {\n customerOnlyFieldAccess: AccessConfig['customerOnlyFieldAccess']\n}\n\nexport const beforeChange: (args: Props) => CollectionBeforeChangeHook =\n ({ customerOnlyFieldAccess }) =>\n async ({ data, req }) => {\n const isCustomer = await customerOnlyFieldAccess({ 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 && isCustomer) {\n data.customer = req.user.id\n }\n }\n"],"names":["beforeChange","customerOnlyFieldAccess","data","req","isCustomer","user","customer","id"],"mappings":"AAQA,OAAO,MAAMA,eACX,CAAC,EAAEC,uBAAuB,EAAE,GAC5B,OAAO,EAAEC,IAAI,EAAEC,GAAG,EAAE;QAClB,MAAMC,aAAa,MAAMH,wBAAwB;YAAEE;QAAI;QAEvD,4FAA4F;QAC5F,kCAAkC;QAClC,IAAIA,IAAIE,IAAI,IAAID,YAAY;YAC1BF,KAAKI,QAAQ,GAAGH,IAAIE,IAAI,CAACE,EAAE;QAC7B;IACF,EAAC"}
@@ -0,0 +1,8 @@
1
+ import type { CollectionBeforeChangeHook } from 'payload';
2
+ type Props = {
3
+ productsSlug: string;
4
+ variantsSlug: string;
5
+ };
6
+ export declare const beforeChangeCart: (args: Props) => CollectionBeforeChangeHook;
7
+ export {};
8
+ //# sourceMappingURL=beforeChange.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"beforeChange.d.ts","sourceRoot":"","sources":["../../../src/collections/carts/beforeChange.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,SAAS,CAAA;AAEzD,KAAK,KAAK,GAAG;IACX,YAAY,EAAE,MAAM,CAAA;IACpB,YAAY,EAAE,MAAM,CAAA;CACrB,CAAA;AAED,eAAO,MAAM,gBAAgB,EAAE,CAAC,IAAI,EAAE,KAAK,KAAK,0BA2C7C,CAAA"}
@@ -0,0 +1,37 @@
1
+ export const beforeChangeCart = ({ productsSlug, variantsSlug })=>async ({ data, req })=>{
2
+ // Update subtotal based on items in the cart
3
+ if (data.items && Array.isArray(data.items)) {
4
+ const priceField = `priceIn${data.currency}`;
5
+ let subtotal = 0;
6
+ for (const item of data.items){
7
+ if (item.variant) {
8
+ const id = typeof item.variant === 'object' ? item.variant.id : item.variant;
9
+ const variant = await req.payload.findByID({
10
+ id,
11
+ collection: variantsSlug,
12
+ depth: 0,
13
+ select: {
14
+ [priceField]: true
15
+ }
16
+ });
17
+ subtotal += variant[priceField] * item.quantity;
18
+ } else {
19
+ const id = typeof item.product === 'object' ? item.product.id : item.product;
20
+ const product = await req.payload.findByID({
21
+ id,
22
+ collection: productsSlug,
23
+ depth: 0,
24
+ select: {
25
+ [priceField]: true
26
+ }
27
+ });
28
+ subtotal += product[priceField] * item.quantity;
29
+ }
30
+ }
31
+ data.subtotal = subtotal;
32
+ } else {
33
+ data.subtotal = 0;
34
+ }
35
+ };
36
+
37
+ //# sourceMappingURL=beforeChange.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/collections/carts/beforeChange.ts"],"sourcesContent":["import type { CollectionBeforeChangeHook } from 'payload'\n\ntype Props = {\n productsSlug: string\n variantsSlug: string\n}\n\nexport const beforeChangeCart: (args: Props) => CollectionBeforeChangeHook =\n ({ productsSlug, variantsSlug }) =>\n async ({ data, req }) => {\n // Update subtotal based on items in the cart\n if (data.items && Array.isArray(data.items)) {\n const priceField = `priceIn${data.currency}`\n\n let subtotal = 0\n\n for (const item of data.items) {\n if (item.variant) {\n const id = typeof item.variant === 'object' ? item.variant.id : item.variant\n\n const variant = await req.payload.findByID({\n id,\n collection: variantsSlug,\n depth: 0,\n select: {\n [priceField]: true,\n },\n })\n\n subtotal += variant[priceField] * item.quantity\n } else {\n const id = typeof item.product === 'object' ? item.product.id : item.product\n\n const product = await req.payload.findByID({\n id,\n collection: productsSlug,\n depth: 0,\n select: {\n [priceField]: true,\n },\n })\n\n subtotal += product[priceField] * item.quantity\n }\n }\n\n data.subtotal = subtotal\n } else {\n data.subtotal = 0\n }\n }\n"],"names":["beforeChangeCart","productsSlug","variantsSlug","data","req","items","Array","isArray","priceField","currency","subtotal","item","variant","id","payload","findByID","collection","depth","select","quantity","product"],"mappings":"AAOA,OAAO,MAAMA,mBACX,CAAC,EAAEC,YAAY,EAAEC,YAAY,EAAE,GAC/B,OAAO,EAAEC,IAAI,EAAEC,GAAG,EAAE;QAClB,6CAA6C;QAC7C,IAAID,KAAKE,KAAK,IAAIC,MAAMC,OAAO,CAACJ,KAAKE,KAAK,GAAG;YAC3C,MAAMG,aAAa,CAAC,OAAO,EAAEL,KAAKM,QAAQ,EAAE;YAE5C,IAAIC,WAAW;YAEf,KAAK,MAAMC,QAAQR,KAAKE,KAAK,CAAE;gBAC7B,IAAIM,KAAKC,OAAO,EAAE;oBAChB,MAAMC,KAAK,OAAOF,KAAKC,OAAO,KAAK,WAAWD,KAAKC,OAAO,CAACC,EAAE,GAAGF,KAAKC,OAAO;oBAE5E,MAAMA,UAAU,MAAMR,IAAIU,OAAO,CAACC,QAAQ,CAAC;wBACzCF;wBACAG,YAAYd;wBACZe,OAAO;wBACPC,QAAQ;4BACN,CAACV,WAAW,EAAE;wBAChB;oBACF;oBAEAE,YAAYE,OAAO,CAACJ,WAAW,GAAGG,KAAKQ,QAAQ;gBACjD,OAAO;oBACL,MAAMN,KAAK,OAAOF,KAAKS,OAAO,KAAK,WAAWT,KAAKS,OAAO,CAACP,EAAE,GAAGF,KAAKS,OAAO;oBAE5E,MAAMA,UAAU,MAAMhB,IAAIU,OAAO,CAACC,QAAQ,CAAC;wBACzCF;wBACAG,YAAYf;wBACZgB,OAAO;wBACPC,QAAQ;4BACN,CAACV,WAAW,EAAE;wBAChB;oBACF;oBAEAE,YAAYU,OAAO,CAACZ,WAAW,GAAGG,KAAKQ,QAAQ;gBACjD;YACF;YAEAhB,KAAKO,QAAQ,GAAGA;QAClB,OAAO;YACLP,KAAKO,QAAQ,GAAG;QAClB;IACF,EAAC"}
@@ -0,0 +1,29 @@
1
+ import type { CollectionConfig } from 'payload';
2
+ import type { AccessConfig, CurrenciesConfig } from '../../types.js';
3
+ type Props = {
4
+ access: {
5
+ adminOrCustomerOwner: NonNullable<AccessConfig['adminOrCustomerOwner']>;
6
+ publicAccess: NonNullable<AccessConfig['publicAccess']>;
7
+ };
8
+ currenciesConfig?: CurrenciesConfig;
9
+ /**
10
+ * Slug of the customers collection, defaults to 'users'.
11
+ */
12
+ customersSlug?: string;
13
+ /**
14
+ * Enables support for variants in the cart.
15
+ * Defaults to false.
16
+ */
17
+ enableVariants?: boolean;
18
+ /**
19
+ * Slug of the products collection, defaults to 'products'.
20
+ */
21
+ productsSlug?: string;
22
+ /**
23
+ * Slug of the variants collection, defaults to 'variants'.
24
+ */
25
+ variantsSlug?: string;
26
+ };
27
+ export declare const createCartsCollection: (props: Props) => CollectionConfig;
28
+ export {};
29
+ //# sourceMappingURL=createCartsCollection.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createCartsCollection.d.ts","sourceRoot":"","sources":["../../../src/collections/carts/createCartsCollection.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAS,MAAM,SAAS,CAAA;AAEtD,OAAO,KAAK,EAAE,YAAY,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAA;AAQpE,KAAK,KAAK,GAAG;IACX,MAAM,EAAE;QACN,oBAAoB,EAAE,WAAW,CAAC,YAAY,CAAC,sBAAsB,CAAC,CAAC,CAAA;QACvE,YAAY,EAAE,WAAW,CAAC,YAAY,CAAC,cAAc,CAAC,CAAC,CAAA;KACxD,CAAA;IACD,gBAAgB,CAAC,EAAE,gBAAgB,CAAA;IACnC;;OAEG;IACH,aAAa,CAAC,EAAE,MAAM,CAAA;IACtB;;;OAGG;IACH,cAAc,CAAC,EAAE,OAAO,CAAA;IACxB;;OAEG;IACH,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB;;OAEG;IACH,YAAY,CAAC,EAAE,MAAM,CAAA;CACtB,CAAA;AAED,eAAO,MAAM,qBAAqB,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,gBA8IrD,CAAA"}