@sixtyninecommerce/admin 0.8.0 → 0.10.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 (179) hide show
  1. package/README.md +2739 -17
  2. package/dist/api-tokens/index.d.ts +15 -5
  3. package/dist/api-tokens/index.js +1 -0
  4. package/dist/apps/event-subscription.d.ts +59 -0
  5. package/dist/apps/event-subscription.js +32 -0
  6. package/dist/apps/hook-secret.d.ts +22 -0
  7. package/dist/apps/hook-secret.js +36 -0
  8. package/dist/apps/index.d.ts +54 -3
  9. package/dist/apps/index.js +17 -0
  10. package/dist/audit/index.d.ts +7 -0
  11. package/dist/auth/queries.d.ts +5 -1
  12. package/dist/auth/queries.js +6 -0
  13. package/dist/bulk/index.d.ts +323 -0
  14. package/dist/bulk/index.js +162 -0
  15. package/dist/catalog/assets.d.ts +147 -0
  16. package/dist/catalog/assets.js +164 -0
  17. package/dist/catalog/collections.d.ts +109 -0
  18. package/dist/catalog/collections.js +91 -0
  19. package/dist/catalog/facets.d.ts +103 -0
  20. package/dist/catalog/facets.js +100 -0
  21. package/dist/catalog/index.d.ts +115 -0
  22. package/dist/catalog/index.js +21 -0
  23. package/dist/catalog/options.d.ts +89 -0
  24. package/dist/catalog/options.js +88 -0
  25. package/dist/catalog/products-bulk.d.ts +21 -0
  26. package/dist/catalog/products-bulk.js +58 -0
  27. package/dist/catalog/products.d.ts +650 -0
  28. package/dist/catalog/products.js +458 -0
  29. package/dist/catalog/properties.d.ts +234 -0
  30. package/dist/catalog/properties.js +158 -0
  31. package/dist/catalog/types.d.ts +174 -0
  32. package/dist/catalog/types.js +141 -0
  33. package/dist/catalog/variants.d.ts +324 -0
  34. package/dist/catalog/variants.js +288 -0
  35. package/dist/catalog/visibility.d.ts +57 -0
  36. package/dist/catalog/visibility.js +59 -0
  37. package/dist/client.d.ts +192 -3
  38. package/dist/client.js +87 -12
  39. package/dist/compliance/index.d.ts +88 -0
  40. package/dist/compliance/index.js +88 -0
  41. package/dist/customer-data-redaction.d.ts +14 -0
  42. package/dist/customer-data-redaction.js +22 -0
  43. package/dist/customers/index.d.ts +428 -17
  44. package/dist/customers/index.js +322 -15
  45. package/dist/documents/index.d.ts +513 -16
  46. package/dist/documents/index.js +229 -3
  47. package/dist/events/index.d.ts +259 -0
  48. package/dist/events/index.js +147 -0
  49. package/dist/feeds/ai.d.ts +46 -0
  50. package/dist/feeds/ai.js +43 -0
  51. package/dist/feeds/categories.d.ts +50 -0
  52. package/dist/feeds/categories.js +56 -0
  53. package/dist/feeds/configs.d.ts +54 -0
  54. package/dist/feeds/configs.js +85 -0
  55. package/dist/feeds/identifier-fields.d.ts +25 -0
  56. package/dist/feeds/identifier-fields.js +29 -0
  57. package/dist/feeds/index.d.ts +54 -0
  58. package/dist/feeds/index.js +46 -0
  59. package/dist/feeds/preserve.d.ts +38 -0
  60. package/dist/feeds/preserve.js +74 -0
  61. package/dist/feeds/rules.d.ts +42 -0
  62. package/dist/feeds/rules.js +56 -0
  63. package/dist/feeds/types.d.ts +654 -0
  64. package/dist/feeds/types.js +135 -0
  65. package/dist/fulfillments/index.d.ts +437 -0
  66. package/dist/fulfillments/index.js +534 -0
  67. package/dist/heads/index.d.ts +60 -0
  68. package/dist/heads/index.js +45 -0
  69. package/dist/hooks/assignments.d.ts +90 -0
  70. package/dist/hooks/assignments.js +53 -0
  71. package/dist/hooks/index.d.ts +97 -0
  72. package/dist/hooks/index.js +76 -0
  73. package/dist/index.d.ts +95 -9
  74. package/dist/index.js +21 -1
  75. package/dist/integrations/index.d.ts +14 -0
  76. package/dist/integrations/index.js +9 -0
  77. package/dist/integrations/pipelines.d.ts +113 -0
  78. package/dist/integrations/pipelines.js +62 -0
  79. package/dist/integrations/types.d.ts +176 -0
  80. package/dist/integrations/types.js +8 -0
  81. package/dist/jobs/bulk-action-run.d.ts +74 -0
  82. package/dist/jobs/bulk-action-run.js +69 -0
  83. package/dist/locations/index.d.ts +6 -2
  84. package/dist/meta/index.d.ts +32 -0
  85. package/dist/orders/bulk.d.ts +75 -0
  86. package/dist/orders/bulk.js +150 -0
  87. package/dist/orders/commit-edit.d.ts +123 -0
  88. package/dist/orders/commit-edit.js +142 -0
  89. package/dist/orders/deposit-policy.d.ts +103 -0
  90. package/dist/orders/deposit-policy.js +202 -0
  91. package/dist/orders/get.d.ts +722 -0
  92. package/dist/orders/get.js +530 -0
  93. package/dist/orders/index.d.ts +186 -21
  94. package/dist/orders/index.js +57 -0
  95. package/dist/orders/line-price-preview.d.ts +297 -0
  96. package/dist/orders/line-price-preview.js +50 -0
  97. package/dist/orders/manual-discounts.d.ts +141 -0
  98. package/dist/orders/manual-discounts.js +97 -0
  99. package/dist/orders/manual-pricing.d.ts +192 -0
  100. package/dist/orders/manual-pricing.js +72 -0
  101. package/dist/orders/order-entry.d.ts +566 -0
  102. package/dist/orders/order-entry.js +129 -0
  103. package/dist/orders/parcel-charge.d.ts +45 -0
  104. package/dist/orders/parcel-charge.js +55 -0
  105. package/dist/orders/plan-edit.d.ts +489 -0
  106. package/dist/orders/plan-edit.js +93 -0
  107. package/dist/orders/status.d.ts +235 -0
  108. package/dist/orders/status.js +96 -0
  109. package/dist/orders/surcharges.d.ts +75 -2
  110. package/dist/orders/surcharges.js +110 -4
  111. package/dist/payments/account-credit.d.ts +171 -0
  112. package/dist/payments/account-credit.js +107 -0
  113. package/dist/payments/index.d.ts +241 -9
  114. package/dist/payments/index.js +92 -0
  115. package/dist/payments/methods.d.ts +37 -0
  116. package/dist/payments/methods.js +33 -0
  117. package/dist/platform/catalog.d.ts +148 -0
  118. package/dist/platform/catalog.js +74 -0
  119. package/dist/platform/entitlements.d.ts +111 -0
  120. package/dist/platform/entitlements.js +86 -0
  121. package/dist/platform/legal-entities.d.ts +139 -0
  122. package/dist/platform/legal-entities.js +126 -0
  123. package/dist/platform/legal-entity-numbering.d.ts +103 -0
  124. package/dist/platform/legal-entity-numbering.js +101 -0
  125. package/dist/platform/organization-membership.d.ts +80 -0
  126. package/dist/platform/organization-membership.js +71 -0
  127. package/dist/platform/organization-settings.d.ts +33 -0
  128. package/dist/platform/organization-settings.js +42 -0
  129. package/dist/platform/organization-sharing.d.ts +172 -0
  130. package/dist/platform/organization-sharing.js +120 -0
  131. package/dist/platform/organizations.d.ts +205 -0
  132. package/dist/platform/organizations.js +180 -0
  133. package/dist/platform/provision-store.d.ts +88 -8
  134. package/dist/platform/provision-store.js +12 -0
  135. package/dist/platform/reports.d.ts +46 -0
  136. package/dist/platform/reports.js +31 -0
  137. package/dist/platform/server-metrics.d.ts +58 -0
  138. package/dist/platform/server-metrics.js +11 -0
  139. package/dist/pos/index.d.ts +567 -0
  140. package/dist/pos/index.js +205 -0
  141. package/dist/pricing/index.d.ts +408 -0
  142. package/dist/pricing/index.js +353 -0
  143. package/dist/pricing/vouchers.d.ts +103 -0
  144. package/dist/pricing/vouchers.js +69 -0
  145. package/dist/provenance/index.d.ts +93 -0
  146. package/dist/provenance/index.js +53 -0
  147. package/dist/reports/index.d.ts +199 -0
  148. package/dist/reports/index.js +154 -0
  149. package/dist/returns/index.d.ts +225 -0
  150. package/dist/returns/index.js +160 -0
  151. package/dist/search/index.d.ts +99 -0
  152. package/dist/search/index.js +62 -0
  153. package/dist/shipping/parcel-count-suggestion.d.ts +52 -0
  154. package/dist/shipping/parcel-count-suggestion.js +73 -0
  155. package/dist/shipping/parcel-rule.d.ts +48 -0
  156. package/dist/shipping/parcel-rule.js +91 -0
  157. package/dist/stock/index.d.ts +166 -0
  158. package/dist/stock/index.js +115 -0
  159. package/dist/stock/transfers.d.ts +520 -0
  160. package/dist/stock/transfers.js +437 -0
  161. package/dist/stored-value/index.d.ts +154 -0
  162. package/dist/stored-value/index.js +130 -0
  163. package/dist/tenant/capabilities.d.ts +10 -0
  164. package/dist/tenant/entitlements.d.ts +35 -0
  165. package/dist/tenant/entitlements.js +15 -0
  166. package/dist/tenant/field-groups.d.ts +64 -0
  167. package/dist/tenant/field-groups.js +34 -0
  168. package/dist/tenant/legal-entity.d.ts +32 -0
  169. package/dist/tenant/legal-entity.js +41 -0
  170. package/dist/tenant/notifications.d.ts +148 -0
  171. package/dist/tenant/notifications.js +79 -0
  172. package/dist/tenant/retention.d.ts +10 -4
  173. package/dist/tenant/settings-sources.d.ts +103 -0
  174. package/dist/tenant/settings-sources.js +92 -0
  175. package/dist/types.d.ts +86 -11
  176. package/dist/uploads/index.d.ts +11 -7
  177. package/dist/users/index.d.ts +104 -0
  178. package/dist/users/index.js +80 -0
  179. package/package.json +3 -2
@@ -0,0 +1,202 @@
1
+ import { errorFromErrorResult, isErrorResult, ValidationError, } from '@sixtyninecommerce/core';
2
+ // The bounds of the meta catalog's `order_deposit_policy` schema
3
+ // (`packages/shared/src/meta-catalog/settings-schemas.ts`), which the spec reads
4
+ // back from that schema. Nothing on the engine validates the column on write, so
5
+ // these are the only check a value gets before the engine reads it.
6
+ /** The fewest days `autoCancelAfterDays` may be; `null` means never. */
7
+ export const DEPOSIT_POLICY_AUTO_CANCEL_DAYS_MIN = 1;
8
+ /** The largest `storefront.minimumPercent`: a whole percentage of the order total. */
9
+ export const DEPOSIT_POLICY_MINIMUM_PERCENT_MAX = 100;
10
+ /** The most payment method codes `storefront.methods` may name. */
11
+ export const DEPOSIT_POLICY_STOREFRONT_METHODS_MAX = 50;
12
+ /**
13
+ * The policy of a store that never set one, and of every field that cannot be
14
+ * read: deposits off, no minimum, no zero-deposit park, the reason kept from the
15
+ * shopper, never auto-cancelled, no online deposits.
16
+ */
17
+ export const DEFAULT_ORDER_DEPOSIT_POLICY = Object.freeze({
18
+ enabled: false,
19
+ minimum: 0,
20
+ allowZeroDepositPark: false,
21
+ showParkReasonToCustomer: false,
22
+ autoCancelAfterDays: null,
23
+ storefront: Object.freeze({ enabled: false, methods: [], minimumPercent: 0 }),
24
+ });
25
+ const POLICY_FIELDS = /* GraphQL */ `
26
+ id
27
+ customFields {
28
+ orderDepositPolicy
29
+ }
30
+ `;
31
+ export const ORDER_DEPOSIT_POLICY_QUERY = /* GraphQL */ `
32
+ query OrderDepositPolicy {
33
+ activeChannel { ${POLICY_FIELDS} }
34
+ }
35
+ `;
36
+ export const SET_ORDER_DEPOSIT_POLICY_MUTATION = /* GraphQL */ `
37
+ mutation SetOrderDepositPolicy($input: UpdateChannelInput!) {
38
+ updateChannel(input: $input) {
39
+ ... on Channel { ${POLICY_FIELDS} }
40
+ ... on ErrorResult { errorCode message }
41
+ }
42
+ }
43
+ `;
44
+ function isRecord(value) {
45
+ return typeof value === 'object' && value !== null && !Array.isArray(value);
46
+ }
47
+ const isWhole = (value) => typeof value === 'number' && Number.isSafeInteger(value);
48
+ /**
49
+ * The column, read as the engine reads it (`resolveDepositPolicy` in
50
+ * `services/vendure/src/payment/deposit-policy.ts`): anything unreadable is its
51
+ * default.
52
+ */
53
+ function readOrderDepositPolicy(raw) {
54
+ let parsed = raw;
55
+ if (typeof raw === 'string') {
56
+ try {
57
+ parsed = JSON.parse(raw);
58
+ }
59
+ catch {
60
+ parsed = null;
61
+ }
62
+ }
63
+ if (!isRecord(parsed))
64
+ return copyOf(DEFAULT_ORDER_DEPOSIT_POLICY);
65
+ return {
66
+ enabled: parsed.enabled === true,
67
+ minimum: isWhole(parsed.minimum) && parsed.minimum >= 0 ? parsed.minimum : 0,
68
+ allowZeroDepositPark: parsed.allowZeroDepositPark === true,
69
+ showParkReasonToCustomer: parsed.showParkReasonToCustomer === true,
70
+ autoCancelAfterDays: isWhole(parsed.autoCancelAfterDays) &&
71
+ parsed.autoCancelAfterDays >= DEPOSIT_POLICY_AUTO_CANCEL_DAYS_MIN
72
+ ? parsed.autoCancelAfterDays
73
+ : null,
74
+ storefront: readStorefront(parsed.storefront),
75
+ };
76
+ }
77
+ function readStorefront(raw) {
78
+ if (!isRecord(raw))
79
+ return { enabled: false, methods: [], minimumPercent: 0 };
80
+ // Only non-blank string codes, once each and at most 50: a stray `null` or a
81
+ // number must not allow a method nobody named.
82
+ const methods = Array.isArray(raw.methods)
83
+ ? [
84
+ ...new Set(raw.methods.filter((code) => typeof code === 'string' && code.trim() !== '')),
85
+ ].slice(0, DEPOSIT_POLICY_STOREFRONT_METHODS_MAX)
86
+ : [];
87
+ const percent = raw.minimumPercent;
88
+ return {
89
+ enabled: raw.enabled === true,
90
+ methods,
91
+ minimumPercent: isWhole(percent) && percent >= 0 && percent <= DEPOSIT_POLICY_MINIMUM_PERCENT_MAX
92
+ ? percent
93
+ : 0,
94
+ };
95
+ }
96
+ function copyOf(policy) {
97
+ return {
98
+ ...policy,
99
+ storefront: { ...policy.storefront, methods: [...policy.storefront.methods] },
100
+ };
101
+ }
102
+ /** Every way `policy` breaks the schema, one entry per field. */
103
+ function problemsOf(policy) {
104
+ const problems = [];
105
+ const add = (field, message) => problems.push({ field, code: 'DEPOSIT_POLICY_INVALID', message });
106
+ if (!isRecord(policy)) {
107
+ add('policy', 'Pass the whole policy as an object: read it with get(), change it, send it back.');
108
+ return problems;
109
+ }
110
+ for (const field of ['enabled', 'allowZeroDepositPark', 'showParkReasonToCustomer']) {
111
+ if (typeof policy[field] !== 'boolean')
112
+ add(field, `${field} must be true or false.`);
113
+ }
114
+ if (!(isWhole(policy.minimum) && policy.minimum >= 0)) {
115
+ add('minimum', 'minimum must be a whole number of minor units, 0 or more.');
116
+ }
117
+ const days = policy.autoCancelAfterDays;
118
+ if (days !== null && !(isWhole(days) && days >= DEPOSIT_POLICY_AUTO_CANCEL_DAYS_MIN)) {
119
+ add('autoCancelAfterDays', 'autoCancelAfterDays must be null (never) or a whole number of days, 1 or more.');
120
+ }
121
+ const storefront = policy.storefront;
122
+ if (!isRecord(storefront)) {
123
+ add('storefront', 'storefront must be an object: { enabled, methods, minimumPercent }.');
124
+ return problems;
125
+ }
126
+ if (typeof storefront.enabled !== 'boolean') {
127
+ add('storefront.enabled', 'storefront.enabled must be true or false.');
128
+ }
129
+ const methods = storefront.methods;
130
+ if (!Array.isArray(methods)) {
131
+ add('storefront.methods', 'storefront.methods must be an array of payment method codes.');
132
+ }
133
+ else if (methods.some((code) => typeof code !== 'string' || code.trim() === '')) {
134
+ add('storefront.methods', 'storefront.methods may hold only non-blank payment method codes.');
135
+ }
136
+ else if (new Set(methods).size !== methods.length) {
137
+ add('storefront.methods', 'storefront.methods names a payment method code more than once.');
138
+ }
139
+ else if (methods.length > DEPOSIT_POLICY_STOREFRONT_METHODS_MAX) {
140
+ add('storefront.methods', `storefront.methods may name at most ${String(DEPOSIT_POLICY_STOREFRONT_METHODS_MAX)} payment methods.`);
141
+ }
142
+ const percent = storefront.minimumPercent;
143
+ if (!(isWhole(percent) && percent >= 0 && percent <= DEPOSIT_POLICY_MINIMUM_PERCENT_MAX)) {
144
+ add('storefront.minimumPercent', 'storefront.minimumPercent must be a whole percentage from 0 to 100.');
145
+ }
146
+ return problems;
147
+ }
148
+ /** Exactly the schema's fields, in its order: what the column stores. */
149
+ function storedOf(policy) {
150
+ return {
151
+ enabled: policy.enabled,
152
+ minimum: policy.minimum,
153
+ allowZeroDepositPark: policy.allowZeroDepositPark,
154
+ showParkReasonToCustomer: policy.showParkReasonToCustomer,
155
+ autoCancelAfterDays: policy.autoCancelAfterDays,
156
+ storefront: {
157
+ enabled: policy.storefront.enabled,
158
+ methods: [...policy.storefront.methods],
159
+ minimumPercent: policy.storefront.minimumPercent,
160
+ },
161
+ };
162
+ }
163
+ export function createOrderDepositPolicyModule(transport) {
164
+ const read = async (options) => {
165
+ const data = await transport.graphql({ api: 'admin', query: ORDER_DEPOSIT_POLICY_QUERY }, options);
166
+ return data.activeChannel;
167
+ };
168
+ return {
169
+ async get(options) {
170
+ const channel = await read(options);
171
+ return readOrderDepositPolicy(channel.customFields?.orderDepositPolicy ?? null);
172
+ },
173
+ async set(policy, options) {
174
+ const problems = problemsOf(policy);
175
+ if (problems.length > 0) {
176
+ throw new ValidationError({
177
+ code: 'DEPOSIT_POLICY_INVALID',
178
+ message: problems.map((problem) => problem.message).join(' '),
179
+ status: 400,
180
+ service: 'vendure',
181
+ details: problems,
182
+ });
183
+ }
184
+ // `updateChannel` needs the id, and the active channel is the one the
185
+ // client is scoped to — read it with the SAME call options, so a per-call
186
+ // tenant writes its own channel rather than the client's.
187
+ const { id } = await read(options);
188
+ const data = await transport.graphql({
189
+ api: 'admin',
190
+ query: SET_ORDER_DEPOSIT_POLICY_MUTATION,
191
+ variables: {
192
+ // The column is `text` holding JSON (the schema describes the
193
+ // DECODED value), so it is sent as a string.
194
+ input: { id, customFields: { orderDepositPolicy: JSON.stringify(storedOf(policy)) } },
195
+ },
196
+ }, options);
197
+ if (isErrorResult(data.updateChannel))
198
+ throw errorFromErrorResult(data.updateChannel);
199
+ return readOrderDepositPolicy(data.updateChannel.customFields?.orderDepositPolicy ?? null);
200
+ },
201
+ };
202
+ }