@payloadcms/plugin-ecommerce 3.67.0-internal.87c53da → 3.67.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (68) hide show
  1. package/dist/collections/addresses/createAddressesCollection.d.ts +1 -5
  2. package/dist/collections/addresses/createAddressesCollection.d.ts.map +1 -1
  3. package/dist/collections/addresses/createAddressesCollection.js +7 -6
  4. package/dist/collections/addresses/createAddressesCollection.js.map +1 -1
  5. package/dist/collections/carts/beforeChange.d.ts.map +1 -1
  6. package/dist/collections/carts/beforeChange.js +13 -1
  7. package/dist/collections/carts/beforeChange.js.map +1 -1
  8. package/dist/collections/carts/createCartsCollection.d.ts +6 -4
  9. package/dist/collections/carts/createCartsCollection.d.ts.map +1 -1
  10. package/dist/collections/carts/createCartsCollection.js +36 -5
  11. package/dist/collections/carts/createCartsCollection.js.map +1 -1
  12. package/dist/collections/carts/hasCartSecretAccess.d.ts +10 -0
  13. package/dist/collections/carts/hasCartSecretAccess.d.ts.map +1 -0
  14. package/dist/collections/carts/hasCartSecretAccess.js +24 -0
  15. package/dist/collections/carts/hasCartSecretAccess.js.map +1 -0
  16. package/dist/collections/orders/createOrdersCollection.d.ts +1 -5
  17. package/dist/collections/orders/createOrdersCollection.d.ts.map +1 -1
  18. package/dist/collections/orders/createOrdersCollection.js +9 -8
  19. package/dist/collections/orders/createOrdersCollection.js.map +1 -1
  20. package/dist/collections/products/createProductsCollection.d.ts +1 -4
  21. package/dist/collections/products/createProductsCollection.d.ts.map +1 -1
  22. package/dist/collections/products/createProductsCollection.js +5 -5
  23. package/dist/collections/products/createProductsCollection.js.map +1 -1
  24. package/dist/collections/transactions/createTransactionsCollection.d.ts +1 -3
  25. package/dist/collections/transactions/createTransactionsCollection.d.ts.map +1 -1
  26. package/dist/collections/transactions/createTransactionsCollection.js +5 -5
  27. package/dist/collections/transactions/createTransactionsCollection.js.map +1 -1
  28. package/dist/collections/variants/createVariantOptionsCollection.d.ts +1 -4
  29. package/dist/collections/variants/createVariantOptionsCollection.d.ts.map +1 -1
  30. package/dist/collections/variants/createVariantOptionsCollection.js +5 -5
  31. package/dist/collections/variants/createVariantOptionsCollection.js.map +1 -1
  32. package/dist/collections/variants/createVariantTypesCollection.d.ts +1 -4
  33. package/dist/collections/variants/createVariantTypesCollection.d.ts.map +1 -1
  34. package/dist/collections/variants/createVariantTypesCollection.js +5 -5
  35. package/dist/collections/variants/createVariantTypesCollection.js.map +1 -1
  36. package/dist/collections/variants/createVariantsCollection/index.d.ts +1 -4
  37. package/dist/collections/variants/createVariantsCollection/index.d.ts.map +1 -1
  38. package/dist/collections/variants/createVariantsCollection/index.js +5 -5
  39. package/dist/collections/variants/createVariantsCollection/index.js.map +1 -1
  40. package/dist/index.d.ts.map +1 -1
  41. package/dist/index.js +10 -33
  42. package/dist/index.js.map +1 -1
  43. package/dist/react/provider/index.d.ts +3 -0
  44. package/dist/react/provider/index.d.ts.map +1 -1
  45. package/dist/react/provider/index.js +261 -156
  46. package/dist/react/provider/index.js.map +1 -1
  47. package/dist/translations/en.d.ts.map +1 -1
  48. package/dist/translations/en.js +1 -0
  49. package/dist/translations/en.js.map +1 -1
  50. package/dist/types/index.d.ts +43 -25
  51. package/dist/types/index.d.ts.map +1 -1
  52. package/dist/types/index.js.map +1 -1
  53. package/dist/utilities/accessComposition.d.ts +55 -0
  54. package/dist/utilities/accessComposition.d.ts.map +1 -0
  55. package/dist/utilities/accessComposition.js +103 -0
  56. package/dist/utilities/accessComposition.js.map +1 -0
  57. package/dist/utilities/accessComposition.spec.js +803 -0
  58. package/dist/utilities/accessComposition.spec.js.map +1 -0
  59. package/dist/utilities/defaultProductsValidation.spec.js +383 -0
  60. package/dist/utilities/defaultProductsValidation.spec.js.map +1 -0
  61. package/dist/utilities/getCollectionSlugMap.spec.js +159 -0
  62. package/dist/utilities/getCollectionSlugMap.spec.js.map +1 -0
  63. package/dist/utilities/sanitizePluginConfig.d.ts.map +1 -1
  64. package/dist/utilities/sanitizePluginConfig.js +10 -2
  65. package/dist/utilities/sanitizePluginConfig.js.map +1 -1
  66. package/dist/utilities/sanitizePluginConfig.spec.js +515 -0
  67. package/dist/utilities/sanitizePluginConfig.spec.js.map +1 -0
  68. package/package.json +7 -7
@@ -0,0 +1,55 @@
1
+ import type { Access } from 'payload';
2
+ /**
3
+ * Combines multiple access functions with OR logic.
4
+ *
5
+ * Logic:
6
+ * - If ANY function returns `true` → return `true` (full access, short-circuit)
7
+ * - If ALL functions return `false` → return `false` (no access)
8
+ * - If any functions return `Where` queries → combine them with OR logic
9
+ *
10
+ * @example
11
+ * ```ts
12
+ * const canCreate = or(
13
+ * isAdmin,
14
+ * isAuthenticated,
15
+ * conditional(allowGuestAccess, isGuest)
16
+ * )
17
+ * ```
18
+ */
19
+ export declare const accessOR: (...accessFunctions: Access[]) => Access;
20
+ /**
21
+ * Combines multiple access functions with AND logic.
22
+ *
23
+ * Logic:
24
+ * - If ANY function returns `false` → return `false` (no access, short-circuit)
25
+ * - If ALL functions return `true` → return `true` (full access)
26
+ * - If any functions return `Where` queries → combine them with AND logic
27
+ *
28
+ * @example
29
+ * ```ts
30
+ * const canUpdate = and(
31
+ * isAuthenticated,
32
+ * isDocumentOwner
33
+ * )
34
+ * ```
35
+ */
36
+ export declare const accessAND: (...accessFunctions: Access[]) => Access;
37
+ /**
38
+ * Conditionally applies an access function based on a boolean condition or function.
39
+ *
40
+ * Useful for feature flags and plugin configuration.
41
+ *
42
+ * @param condition - Boolean or function to determine which function to use
43
+ * @param checker - Access function to use if condition is true
44
+ * @param fallback - Access function to use if condition is false (defaults to denying access)
45
+ *
46
+ * @example
47
+ * ```ts
48
+ * const canCreate = or(
49
+ * isAdmin,
50
+ * conditional(allowGuestCarts, isGuest)
51
+ * )
52
+ * ```
53
+ */
54
+ export declare const conditional: (condition: ((args: any) => boolean) | boolean, accessFunction: Access, fallback?: Access) => Access;
55
+ //# sourceMappingURL=accessComposition.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"accessComposition.d.ts","sourceRoot":"","sources":["../../src/utilities/accessComposition.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAS,MAAM,SAAS,CAAA;AAI5C;;;;;;;;;;;;;;;;GAgBG;AACH,eAAO,MAAM,QAAQ,uBAAwB,MAAM,EAAE,KAAG,MA0BvD,CAAA;AAED;;;;;;;;;;;;;;;GAeG;AACH,eAAO,MAAM,SAAS,uBAAwB,MAAM,EAAE,KAAG,MA0BxD,CAAA;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,eAAO,MAAM,WAAW,cACX,CAAC,CAAC,IAAI,EAAE,GAAG,KAAK,OAAO,CAAC,GAAG,OAAO,kBAC7B,MAAM,aACZ,MAAM,KACf,MAQF,CAAA"}
@@ -0,0 +1,103 @@
1
+ import { combineWhereConstraints } from 'payload/shared';
2
+ /**
3
+ * Combines multiple access functions with OR logic.
4
+ *
5
+ * Logic:
6
+ * - If ANY function returns `true` → return `true` (full access, short-circuit)
7
+ * - If ALL functions return `false` → return `false` (no access)
8
+ * - If any functions return `Where` queries → combine them with OR logic
9
+ *
10
+ * @example
11
+ * ```ts
12
+ * const canCreate = or(
13
+ * isAdmin,
14
+ * isAuthenticated,
15
+ * conditional(allowGuestAccess, isGuest)
16
+ * )
17
+ * ```
18
+ */ export const accessOR = (...accessFunctions)=>{
19
+ return async (args)=>{
20
+ const whereQueries = [];
21
+ for (const access of accessFunctions){
22
+ const result = await access(args);
23
+ // Short-circuit on true - full access granted
24
+ if (result === true) {
25
+ return true;
26
+ }
27
+ // Collect Where queries for combination (must be an object, not null/undefined/false)
28
+ if (result && typeof result === 'object') {
29
+ whereQueries.push(result);
30
+ }
31
+ }
32
+ // If we have Where queries, combine them with OR
33
+ if (whereQueries.length > 0) {
34
+ return combineWhereConstraints(whereQueries, 'or');
35
+ }
36
+ // All checkers returned false - no access
37
+ return false;
38
+ };
39
+ };
40
+ /**
41
+ * Combines multiple access functions with AND logic.
42
+ *
43
+ * Logic:
44
+ * - If ANY function returns `false` → return `false` (no access, short-circuit)
45
+ * - If ALL functions return `true` → return `true` (full access)
46
+ * - If any functions return `Where` queries → combine them with AND logic
47
+ *
48
+ * @example
49
+ * ```ts
50
+ * const canUpdate = and(
51
+ * isAuthenticated,
52
+ * isDocumentOwner
53
+ * )
54
+ * ```
55
+ */ export const accessAND = (...accessFunctions)=>{
56
+ return async (args)=>{
57
+ const whereQueries = [];
58
+ for (const access of accessFunctions){
59
+ const result = await access(args);
60
+ // Short-circuit on false - no access
61
+ if (result === false) {
62
+ return false;
63
+ }
64
+ // Collect Where queries for combination (must be an object, not null/undefined/true)
65
+ if (result !== true && result && typeof result === 'object') {
66
+ whereQueries.push(result);
67
+ }
68
+ }
69
+ // If we have Where queries, combine them with AND
70
+ if (whereQueries.length > 0) {
71
+ return combineWhereConstraints(whereQueries, 'and');
72
+ }
73
+ // All checkers returned true - full access
74
+ return true;
75
+ };
76
+ };
77
+ /**
78
+ * Conditionally applies an access function based on a boolean condition or function.
79
+ *
80
+ * Useful for feature flags and plugin configuration.
81
+ *
82
+ * @param condition - Boolean or function to determine which function to use
83
+ * @param checker - Access function to use if condition is true
84
+ * @param fallback - Access function to use if condition is false (defaults to denying access)
85
+ *
86
+ * @example
87
+ * ```ts
88
+ * const canCreate = or(
89
+ * isAdmin,
90
+ * conditional(allowGuestCarts, isGuest)
91
+ * )
92
+ * ```
93
+ */ export const conditional = (condition, accessFunction, fallback = ()=>false)=>{
94
+ return async (args)=>{
95
+ const shouldApply = typeof condition === 'function' ? condition(args) : condition;
96
+ if (shouldApply) {
97
+ return accessFunction(args);
98
+ }
99
+ return fallback(args);
100
+ };
101
+ };
102
+
103
+ //# sourceMappingURL=accessComposition.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/utilities/accessComposition.ts"],"sourcesContent":["import type { Access, Where } from 'payload'\n\nimport { combineWhereConstraints } from 'payload/shared'\n\n/**\n * Combines multiple access functions with OR logic.\n *\n * Logic:\n * - If ANY function returns `true` → return `true` (full access, short-circuit)\n * - If ALL functions return `false` → return `false` (no access)\n * - If any functions return `Where` queries → combine them with OR logic\n *\n * @example\n * ```ts\n * const canCreate = or(\n * isAdmin,\n * isAuthenticated,\n * conditional(allowGuestAccess, isGuest)\n * )\n * ```\n */\nexport const accessOR = (...accessFunctions: Access[]): Access => {\n return async (args) => {\n const whereQueries: Where[] = []\n\n for (const access of accessFunctions) {\n const result = await access(args)\n\n // Short-circuit on true - full access granted\n if (result === true) {\n return true\n }\n\n // Collect Where queries for combination (must be an object, not null/undefined/false)\n if (result && typeof result === 'object') {\n whereQueries.push(result)\n }\n }\n\n // If we have Where queries, combine them with OR\n if (whereQueries.length > 0) {\n return combineWhereConstraints(whereQueries, 'or')\n }\n\n // All checkers returned false - no access\n return false\n }\n}\n\n/**\n * Combines multiple access functions with AND logic.\n *\n * Logic:\n * - If ANY function returns `false` → return `false` (no access, short-circuit)\n * - If ALL functions return `true` → return `true` (full access)\n * - If any functions return `Where` queries → combine them with AND logic\n *\n * @example\n * ```ts\n * const canUpdate = and(\n * isAuthenticated,\n * isDocumentOwner\n * )\n * ```\n */\nexport const accessAND = (...accessFunctions: Access[]): Access => {\n return async (args) => {\n const whereQueries: Where[] = []\n\n for (const access of accessFunctions) {\n const result = await access(args)\n\n // Short-circuit on false - no access\n if (result === false) {\n return false\n }\n\n // Collect Where queries for combination (must be an object, not null/undefined/true)\n if (result !== true && result && typeof result === 'object') {\n whereQueries.push(result)\n }\n }\n\n // If we have Where queries, combine them with AND\n if (whereQueries.length > 0) {\n return combineWhereConstraints(whereQueries, 'and')\n }\n\n // All checkers returned true - full access\n return true\n }\n}\n\n/**\n * Conditionally applies an access function based on a boolean condition or function.\n *\n * Useful for feature flags and plugin configuration.\n *\n * @param condition - Boolean or function to determine which function to use\n * @param checker - Access function to use if condition is true\n * @param fallback - Access function to use if condition is false (defaults to denying access)\n *\n * @example\n * ```ts\n * const canCreate = or(\n * isAdmin,\n * conditional(allowGuestCarts, isGuest)\n * )\n * ```\n */\nexport const conditional = (\n condition: ((args: any) => boolean) | boolean,\n accessFunction: Access,\n fallback: Access = () => false,\n): Access => {\n return async (args) => {\n const shouldApply = typeof condition === 'function' ? condition(args) : condition\n if (shouldApply) {\n return accessFunction(args)\n }\n return fallback(args)\n }\n}\n"],"names":["combineWhereConstraints","accessOR","accessFunctions","args","whereQueries","access","result","push","length","accessAND","conditional","condition","accessFunction","fallback","shouldApply"],"mappings":"AAEA,SAASA,uBAAuB,QAAQ,iBAAgB;AAExD;;;;;;;;;;;;;;;;CAgBC,GACD,OAAO,MAAMC,WAAW,CAAC,GAAGC;IAC1B,OAAO,OAAOC;QACZ,MAAMC,eAAwB,EAAE;QAEhC,KAAK,MAAMC,UAAUH,gBAAiB;YACpC,MAAMI,SAAS,MAAMD,OAAOF;YAE5B,8CAA8C;YAC9C,IAAIG,WAAW,MAAM;gBACnB,OAAO;YACT;YAEA,sFAAsF;YACtF,IAAIA,UAAU,OAAOA,WAAW,UAAU;gBACxCF,aAAaG,IAAI,CAACD;YACpB;QACF;QAEA,iDAAiD;QACjD,IAAIF,aAAaI,MAAM,GAAG,GAAG;YAC3B,OAAOR,wBAAwBI,cAAc;QAC/C;QAEA,0CAA0C;QAC1C,OAAO;IACT;AACF,EAAC;AAED;;;;;;;;;;;;;;;CAeC,GACD,OAAO,MAAMK,YAAY,CAAC,GAAGP;IAC3B,OAAO,OAAOC;QACZ,MAAMC,eAAwB,EAAE;QAEhC,KAAK,MAAMC,UAAUH,gBAAiB;YACpC,MAAMI,SAAS,MAAMD,OAAOF;YAE5B,qCAAqC;YACrC,IAAIG,WAAW,OAAO;gBACpB,OAAO;YACT;YAEA,qFAAqF;YACrF,IAAIA,WAAW,QAAQA,UAAU,OAAOA,WAAW,UAAU;gBAC3DF,aAAaG,IAAI,CAACD;YACpB;QACF;QAEA,kDAAkD;QAClD,IAAIF,aAAaI,MAAM,GAAG,GAAG;YAC3B,OAAOR,wBAAwBI,cAAc;QAC/C;QAEA,2CAA2C;QAC3C,OAAO;IACT;AACF,EAAC;AAED;;;;;;;;;;;;;;;;CAgBC,GACD,OAAO,MAAMM,cAAc,CACzBC,WACAC,gBACAC,WAAmB,IAAM,KAAK;IAE9B,OAAO,OAAOV;QACZ,MAAMW,cAAc,OAAOH,cAAc,aAAaA,UAAUR,QAAQQ;QACxE,IAAIG,aAAa;YACf,OAAOF,eAAeT;QACxB;QACA,OAAOU,SAASV;IAClB;AACF,EAAC"}