@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,437 @@
1
+ import { pageFromVendureList, readOffsetCursor, } from '@sixtyninecommerce/core';
2
+ import { decodeBase64, MYPARCEL_LABEL_TIMEOUT_MS, toUnretractedShipments, UNRETRACTED_SHIPMENT_FIELDS, } from '../fulfillments/index.js';
3
+ const TRANSFER_FIELDS = /* GraphQL */ `
4
+ id
5
+ code
6
+ kind
7
+ state
8
+ sourceLocation { id name }
9
+ destinationLocation { id name }
10
+ label
11
+ note
12
+ carrier
13
+ trackingCode
14
+ estimatedArrivalAt
15
+ shippedAt
16
+ receivedAt
17
+ cancelledAt
18
+ cancelReason
19
+ deliveryAddress {
20
+ contactName
21
+ company
22
+ streetLine1
23
+ streetLine2
24
+ city
25
+ province
26
+ postalCode
27
+ countryCode
28
+ phoneNumber
29
+ }
30
+ createdAt
31
+ updatedAt
32
+ items {
33
+ id
34
+ productVariant { id sku }
35
+ quantity
36
+ receivedQuantity
37
+ lostQuantity
38
+ outstandingQuantity
39
+ }
40
+ totalQuantity
41
+ totalReceivedQuantity
42
+ totalLostQuantity
43
+ `;
44
+ export const STOCK_TRANSFERS_QUERY = /* GraphQL */ `
45
+ query StockTransfers($options: StockTransferListOptions) {
46
+ stockTransfers(options: $options) { items { ${TRANSFER_FIELDS} } totalItems }
47
+ }
48
+ `;
49
+ export const STOCK_TRANSFER_QUERY = /* GraphQL */ `
50
+ query StockTransfer($id: ID!) { stockTransfer(id: $id) { ${TRANSFER_FIELDS} } }
51
+ `;
52
+ export const CREATE_STOCK_TRANSFER_MUTATION = /* GraphQL */ `
53
+ mutation CreateStockTransfer($input: CreateStockTransferInput!) {
54
+ createStockTransfer(input: $input) { ${TRANSFER_FIELDS} }
55
+ }
56
+ `;
57
+ export const UPDATE_STOCK_TRANSFER_MUTATION = /* GraphQL */ `
58
+ mutation UpdateStockTransfer($id: ID!, $input: UpdateStockTransferInput!) {
59
+ updateStockTransfer(id: $id, input: $input) { ${TRANSFER_FIELDS} }
60
+ }
61
+ `;
62
+ export const SHIP_STOCK_TRANSFER_MUTATION = /* GraphQL */ `
63
+ mutation ShipStockTransfer($id: ID!, $input: ShipStockTransferInput) {
64
+ shipStockTransfer(id: $id, input: $input) { ${TRANSFER_FIELDS} }
65
+ }
66
+ `;
67
+ export const POST_STOCK_TRANSFER_CONSUMPTION_MUTATION = /* GraphQL */ `
68
+ mutation PostStockTransferConsumption($id: ID!) {
69
+ postStockTransferConsumption(id: $id) { ${TRANSFER_FIELDS} }
70
+ }
71
+ `;
72
+ export const RECEIVE_STOCK_TRANSFER_LINES_MUTATION = /* GraphQL */ `
73
+ mutation ReceiveStockTransferLines($id: ID!, $lines: [ReceiveStockTransferLineInput!]!) {
74
+ receiveStockTransferLines(id: $id, lines: $lines) { ${TRANSFER_FIELDS} }
75
+ }
76
+ `;
77
+ export const CLOSE_STOCK_TRANSFER_MUTATION = /* GraphQL */ `
78
+ mutation CloseStockTransfer($id: ID!, $acceptShortfallAsLost: Boolean) {
79
+ closeStockTransfer(id: $id, acceptShortfallAsLost: $acceptShortfallAsLost) { ${TRANSFER_FIELDS} }
80
+ }
81
+ `;
82
+ /**
83
+ * Its own document: it declares `$shortfall`, which an engine without per-line
84
+ * dispositions refuses as a whole. A close without dispositions keeps sending
85
+ * the document above.
86
+ */
87
+ export const CLOSE_STOCK_TRANSFER_WITH_SHORTFALL_MUTATION = /* GraphQL */ `
88
+ mutation CloseStockTransferWithShortfall(
89
+ $id: ID!
90
+ $acceptShortfallAsLost: Boolean
91
+ $shortfall: [StockTransferShortfallLineInput!]!
92
+ ) {
93
+ closeStockTransfer(
94
+ id: $id
95
+ acceptShortfallAsLost: $acceptShortfallAsLost
96
+ shortfall: $shortfall
97
+ ) { ${TRANSFER_FIELDS} }
98
+ }
99
+ `;
100
+ export const CANCEL_STOCK_TRANSFER_MUTATION = /* GraphQL */ `
101
+ mutation CancelStockTransfer($id: ID!, $reason: String) {
102
+ cancelStockTransfer(id: $id, reason: $reason) { ${TRANSFER_FIELDS} }
103
+ }
104
+ `;
105
+ export const CREATE_STOCK_TRANSFER_RETURN_MUTATION = /* GraphQL */ `
106
+ mutation CreateStockTransferReturn($id: ID!, $input: CreateStockTransferReturnInput!) {
107
+ createStockTransferReturn(id: $id, input: $input) { ${TRANSFER_FIELDS} }
108
+ }
109
+ `;
110
+ /**
111
+ * The return fields, in a document of their own like the parcel fields below:
112
+ * `get`/`list` keep working against an engine without them.
113
+ */
114
+ const RETURN_REF_FIELDS = /* GraphQL */ `
115
+ id
116
+ code
117
+ state
118
+ label
119
+ sourceLocation { id name }
120
+ destinationLocation { id name }
121
+ createdAt
122
+ totalQuantity
123
+ `;
124
+ export const STOCK_TRANSFER_RETURNS_QUERY = /* GraphQL */ `
125
+ query StockTransferReturns($id: ID!) {
126
+ stockTransfer(id: $id) {
127
+ returnOfTransferId
128
+ returnOf { ${RETURN_REF_FIELDS} }
129
+ returns { ${RETURN_REF_FIELDS} }
130
+ returnableLines {
131
+ productVariantId
132
+ productVariant { name sku }
133
+ receivedQuantity
134
+ returnedQuantity
135
+ returnableQuantity
136
+ }
137
+ }
138
+ }
139
+ `;
140
+ /** The per-line settlement fields, in a document of their own like the return fields. */
141
+ export const STOCK_TRANSFER_SHORTFALL_QUERY = /* GraphQL */ `
142
+ query StockTransferShortfall($id: ID!) {
143
+ stockTransfer(id: $id) {
144
+ id
145
+ state
146
+ items {
147
+ id
148
+ productVariant { id sku }
149
+ quantity
150
+ receivedQuantity
151
+ lostQuantity
152
+ returnedToSourceQuantity
153
+ outstandingQuantity
154
+ }
155
+ totalLostQuantity
156
+ totalReturnedToSourceQuantity
157
+ }
158
+ }
159
+ `;
160
+ function toShortfall(raw) {
161
+ return {
162
+ transferId: raw.id,
163
+ state: raw.state,
164
+ lines: raw.items.map(({ id, productVariant, ...quantities }) => ({
165
+ lineId: id,
166
+ variantId: productVariant.id,
167
+ sku: productVariant.sku,
168
+ ...quantities,
169
+ })),
170
+ totalLostQuantity: raw.totalLostQuantity,
171
+ totalReturnedToSourceQuantity: raw.totalReturnedToSourceQuantity,
172
+ };
173
+ }
174
+ /**
175
+ * The cancellation fields, in a document of their own like the return and
176
+ * parcel fields: `cancelledBy` is newer than the transfer module, and
177
+ * `get`/`list`/`cancel` keep working against an engine without it.
178
+ */
179
+ export const STOCK_TRANSFER_CANCELLATION_QUERY = /* GraphQL */ `
180
+ query StockTransferCancellation($id: ID!) {
181
+ stockTransfer(id: $id) {
182
+ id
183
+ state
184
+ cancelledAt
185
+ cancelReason
186
+ cancelledBy { id firstName lastName }
187
+ fulfillmentHandlerCode
188
+ hendriksRemotePath
189
+ hendriksBluJayOrderNumber
190
+ }
191
+ }
192
+ `;
193
+ /**
194
+ * The parcel fields, in documents of their own: `TRANSFER_FIELDS` stays what
195
+ * every engine since the transfer module answers, so `get`/`list` keep working
196
+ * against an engine one version behind.
197
+ */
198
+ const PARCEL_FIELDS = /* GraphQL */ `
199
+ id
200
+ state
201
+ fulfillmentHandlerCode
202
+ parcelCount
203
+ myparcelParcels { ordinal shipmentId barcode labelReady lastError }
204
+ trackingCodes
205
+ myparcelBarcode
206
+ myparcelLastError
207
+ myparcelUnretractedShipments { ${UNRETRACTED_SHIPMENT_FIELDS} }
208
+ `;
209
+ export const STOCK_TRANSFER_PARCELS_QUERY = /* GraphQL */ `
210
+ query StockTransferParcels($id: ID!) { stockTransfer(id: $id) { ${PARCEL_FIELDS} } }
211
+ `;
212
+ export const RETRY_STOCK_TRANSFER_MYPARCEL_SHIPMENTS_MUTATION = /* GraphQL */ `
213
+ mutation RetryStockTransferMyparcelShipments($id: ID!) {
214
+ retryStockTransferMyparcelShipments(id: $id) { ${PARCEL_FIELDS} }
215
+ }
216
+ `;
217
+ export const LABEL_STOCK_TRANSFER_MYPARCEL_PARCELS_MUTATION = /* GraphQL */ `
218
+ mutation LabelStockTransferMyparcelParcels($id: ID!) {
219
+ labelStockTransferMyparcelParcels(id: $id) { ${PARCEL_FIELDS} }
220
+ }
221
+ `;
222
+ export const MYPARCEL_STOCK_TRANSFER_LABEL_MUTATION = /* GraphQL */ `
223
+ mutation MyparcelStockTransferLabel($transferId: ID!, $format: StockTransferLabelFormat!) {
224
+ getMyparcelStockTransferLabel(transferId: $transferId, format: $format) {
225
+ format
226
+ base64
227
+ contentType
228
+ filename
229
+ }
230
+ }
231
+ `;
232
+ const MYPARCEL_HANDLER_CODE = 'myparcel';
233
+ /**
234
+ * A MyParcel ship and its retry book every parcel at MyParcel before they
235
+ * answer (per parcel an adopt-by-reference lookup of up to 3 × 10s plus two
236
+ * capped waits, and a 30s POST), and a cancel voids every parcel there. The
237
+ * default 15s aborted calls the engine went on to finish, so the caller saw a
238
+ * failure for a ship, booking or cancel that succeeded.
239
+ */
240
+ const CARRIER_CALL_TIMEOUT_MS = 120_000;
241
+ /**
242
+ * A transfer shipped before per-parcel labels keeps no parcel map: its label
243
+ * job records the one barcode on the transfer (`myparcelBarcode`) only, so the
244
+ * engine lists its single parcel without one for ever. Fold it in — for a
245
+ * single parcel only: with several, `myparcelBarcode` may be ANOTHER parcel's
246
+ * (the first one known).
247
+ */
248
+ function withLegacyBarcode(parcels, trackingCodes, transferBarcode) {
249
+ const only = parcels.length === 1 ? parcels[0] : undefined;
250
+ const barcode = transferBarcode?.trim();
251
+ if (!only || only.barcode || !barcode)
252
+ return { parcels, trackingCodes };
253
+ return {
254
+ parcels: [{ ...only, barcode }],
255
+ trackingCodes: trackingCodes.includes(barcode) ? trackingCodes : [barcode, ...trackingCodes],
256
+ };
257
+ }
258
+ function toParcels(raw) {
259
+ const { parcels, trackingCodes } = withLegacyBarcode([...(raw.myparcelParcels ?? [])].sort((a, b) => a.ordinal - b.ordinal), raw.trackingCodes ?? [], raw.myparcelBarcode);
260
+ // The engine stores what was ASKED; a count below the parcels actually
261
+ // booked (a row an older writer left) must not hide one of them.
262
+ const hasShipment = raw.fulfillmentHandlerCode === MYPARCEL_HANDLER_CODE ||
263
+ parcels.length > 0 ||
264
+ raw.parcelCount !== null;
265
+ return {
266
+ transferId: raw.id,
267
+ state: raw.state,
268
+ fulfillmentHandlerCode: raw.fulfillmentHandlerCode,
269
+ parcelCount: hasShipment ? Math.max(raw.parcelCount ?? 1, parcels.length) : null,
270
+ parcels,
271
+ trackingCodes,
272
+ lastError: raw.myparcelLastError,
273
+ unretractedShipments: toUnretractedShipments(raw.myparcelUnretractedShipments),
274
+ };
275
+ }
276
+ const HENDRIKS_HANDLER_CODE = 'hendriks-3pl';
277
+ function toCancellation(raw) {
278
+ // The engine's own rule (its cancel warning): an export is on record only
279
+ // with its remote path. A removed shipment clears the path but keeps the
280
+ // BluJay number for a re-ship, so the number alone proves no export.
281
+ const exported = raw.fulfillmentHandlerCode === HENDRIKS_HANDLER_CODE && Boolean(raw.hendriksRemotePath);
282
+ return {
283
+ transferId: raw.id,
284
+ state: raw.state,
285
+ cancelledAt: raw.cancelledAt,
286
+ cancelReason: raw.cancelReason,
287
+ cancelledBy: raw.cancelledBy,
288
+ hendriksExport: exported ? { bluJayOrderNumber: raw.hendriksBluJayOrderNumber } : null,
289
+ };
290
+ }
291
+ function toTransfer(raw) {
292
+ return {
293
+ ...raw,
294
+ items: raw.items.map(({ productVariant, ...line }) => ({
295
+ ...line,
296
+ variantId: productVariant.id,
297
+ sku: productVariant.sku,
298
+ })),
299
+ };
300
+ }
301
+ function toReturns(raw) {
302
+ return {
303
+ returnOfTransferId: raw.returnOfTransferId,
304
+ returnOf: raw.returnOf,
305
+ returns: raw.returns,
306
+ returnableLines: raw.returnableLines.map(({ productVariantId, productVariant, ...quantities }) => ({
307
+ variantId: productVariantId,
308
+ sku: productVariant.sku,
309
+ variantName: productVariant.name,
310
+ ...quantities,
311
+ })),
312
+ };
313
+ }
314
+ const toLines = (lines) => lines.map((line) => ({ productVariantId: line.variantId, quantity: line.quantity }));
315
+ const DEFAULT_PAGE_SIZE = 25;
316
+ export function createStockTransfersModule(transport) {
317
+ const one = async (field, query, variables, options) => {
318
+ const data = await transport.graphql({ api: 'admin', query, variables }, options);
319
+ return toTransfer(data[field]);
320
+ };
321
+ const listPage = async (skip, take, filter) => {
322
+ const data = await transport.graphql({
323
+ api: 'admin',
324
+ query: STOCK_TRANSFERS_QUERY,
325
+ variables: {
326
+ options: {
327
+ skip,
328
+ take,
329
+ locationId: filter?.locationId,
330
+ sourceLocationId: filter?.sourceLocationId,
331
+ destinationLocationId: filter?.destinationLocationId,
332
+ state: filter?.state,
333
+ dateFrom: filter?.dateFrom,
334
+ dateTo: filter?.dateTo,
335
+ search: filter?.search,
336
+ // Only when set: an engine without returns refuses an unknown
337
+ // input field, which would fail every list against it.
338
+ ...(filter?.returnOfTransferId === undefined
339
+ ? {}
340
+ : { returnOfTransferId: filter.returnOfTransferId }),
341
+ ...(filter?.isReturn === undefined ? {} : { isReturn: filter.isReturn }),
342
+ },
343
+ },
344
+ }, filter);
345
+ return pageFromVendureList({
346
+ items: data.stockTransfers.items.map(toTransfer),
347
+ totalItems: data.stockTransfers.totalItems,
348
+ }, skip, take, (cursor) => listPage(readOffsetCursor(cursor), take, filter));
349
+ };
350
+ return {
351
+ list(filter) {
352
+ const take = filter?.limit ?? DEFAULT_PAGE_SIZE;
353
+ const skip = filter?.after === undefined ? 0 : readOffsetCursor(filter.after);
354
+ return listPage(skip, take, filter);
355
+ },
356
+ async get(id, options) {
357
+ const data = await transport.graphql({ api: 'admin', query: STOCK_TRANSFER_QUERY, variables: { id } }, options);
358
+ return data.stockTransfer === null ? null : toTransfer(data.stockTransfer);
359
+ },
360
+ create(input, options) {
361
+ const { lines, ...rest } = input;
362
+ return one('createStockTransfer', CREATE_STOCK_TRANSFER_MUTATION, { input: { ...rest, lines: toLines(lines) } }, options);
363
+ },
364
+ update(id, input, options) {
365
+ const { lines, ...rest } = input;
366
+ return one('updateStockTransfer', UPDATE_STOCK_TRANSFER_MUTATION, { id, input: { ...rest, ...(lines === undefined ? {} : { lines: toLines(lines) }) } }, options);
367
+ },
368
+ ship(id, input, options) {
369
+ return one('shipStockTransfer', SHIP_STOCK_TRANSFER_MUTATION, { id, input }, { timeoutMs: CARRIER_CALL_TIMEOUT_MS, ...options });
370
+ },
371
+ postConsumption(id, options) {
372
+ return one('postStockTransferConsumption', POST_STOCK_TRANSFER_CONSUMPTION_MUTATION, { id }, options);
373
+ },
374
+ receive(id, lines, options) {
375
+ return one('receiveStockTransferLines', RECEIVE_STOCK_TRANSFER_LINES_MUTATION, { id, lines }, options);
376
+ },
377
+ close(id, options) {
378
+ const shortfall = options?.shortfall ?? [];
379
+ if (shortfall.length === 0) {
380
+ return one('closeStockTransfer', CLOSE_STOCK_TRANSFER_MUTATION, { id, acceptShortfallAsLost: options?.acceptShortfallAsLost }, options);
381
+ }
382
+ return one('closeStockTransfer', CLOSE_STOCK_TRANSFER_WITH_SHORTFALL_MUTATION, {
383
+ id,
384
+ acceptShortfallAsLost: options?.acceptShortfallAsLost,
385
+ shortfall: shortfall.map(({ lineId, disposition }) => ({ lineId, disposition })),
386
+ }, options);
387
+ },
388
+ cancel(id, options) {
389
+ return one('cancelStockTransfer', CANCEL_STOCK_TRANSFER_MUTATION, { id, reason: options?.reason }, { timeoutMs: CARRIER_CALL_TIMEOUT_MS, ...options });
390
+ },
391
+ createReturn(id, input, options) {
392
+ const { lines, ...rest } = input;
393
+ return one('createStockTransferReturn', CREATE_STOCK_TRANSFER_RETURN_MUTATION, { id, input: { ...rest, lines: toLines(lines) } }, options);
394
+ },
395
+ async returns(id, options) {
396
+ const data = await transport.graphql({ api: 'admin', query: STOCK_TRANSFER_RETURNS_QUERY, variables: { id } }, options);
397
+ return data.stockTransfer === null ? null : toReturns(data.stockTransfer);
398
+ },
399
+ async shortfall(id, options) {
400
+ const data = await transport.graphql({ api: 'admin', query: STOCK_TRANSFER_SHORTFALL_QUERY, variables: { id } }, options);
401
+ return data.stockTransfer === null ? null : toShortfall(data.stockTransfer);
402
+ },
403
+ async cancellation(id, options) {
404
+ const data = await transport.graphql({ api: 'admin', query: STOCK_TRANSFER_CANCELLATION_QUERY, variables: { id } }, options);
405
+ return data.stockTransfer === null ? null : toCancellation(data.stockTransfer);
406
+ },
407
+ async parcels(id, options) {
408
+ const data = await transport.graphql({ api: 'admin', query: STOCK_TRANSFER_PARCELS_QUERY, variables: { id } }, options);
409
+ return data.stockTransfer === null ? null : toParcels(data.stockTransfer);
410
+ },
411
+ async retryMyparcelShipments(id, options) {
412
+ const data = await transport.graphql({
413
+ api: 'admin',
414
+ query: RETRY_STOCK_TRANSFER_MYPARCEL_SHIPMENTS_MUTATION,
415
+ variables: { id },
416
+ }, { timeoutMs: CARRIER_CALL_TIMEOUT_MS, ...options });
417
+ return toParcels(data.retryStockTransferMyparcelShipments);
418
+ },
419
+ async labelMyparcelParcels(id, options) {
420
+ const data = await transport.graphql({
421
+ api: 'admin',
422
+ query: LABEL_STOCK_TRANSFER_MYPARCEL_PARCELS_MUTATION,
423
+ variables: { id },
424
+ }, options);
425
+ return toParcels(data.labelStockTransferMyparcelParcels);
426
+ },
427
+ async myparcelLabel(id, format, options) {
428
+ const data = await transport.graphql({
429
+ api: 'admin',
430
+ query: MYPARCEL_STOCK_TRANSFER_LABEL_MUTATION,
431
+ variables: { transferId: id, format },
432
+ }, { timeoutMs: MYPARCEL_LABEL_TIMEOUT_MS, ...options });
433
+ const { base64, ...document } = data.getMyparcelStockTransferLabel;
434
+ return { ...document, bytes: decodeBase64(base64) };
435
+ },
436
+ };
437
+ }
@@ -0,0 +1,154 @@
1
+ import type { Transport } from '@sixtyninecommerce/core';
2
+ import type { Call } from '../types.js';
3
+ /**
4
+ * Stored value (incentives program decisions 1 and 2): gift cards, store credit and points on one
5
+ * ledger. A balance is the sum of its entries, never a stored figure, and is spent as a PAYMENT on
6
+ * an order (`redeem`), never as a discount.
7
+ *
8
+ * Every amount is in minor units of the account's `unit` (an ISO 4217 code, or `PTS` for points).
9
+ * Refusals arrive as coded errors (`STORED_VALUE_*`); an id of another store is not found.
10
+ */
11
+ export interface StoredValueAccount {
12
+ id: string;
13
+ createdAt: string;
14
+ updatedAt: string;
15
+ kind: 'gift_card' | 'store_credit' | 'points';
16
+ unit: string;
17
+ customerId: string | null;
18
+ codeLast4: string | null;
19
+ /** The instant the value stops being spendable (start of the day after `expiresOn`). */
20
+ expiresAt: string | null;
21
+ /** The last day (`YYYY-MM-DD`, store zone) the value is valid through; refund lots never expire. */
22
+ expiresOn: string | null;
23
+ status: 'active' | 'blocked';
24
+ balance: number;
25
+ /** What can be spent now: the balance less expired value the daily job has not booked yet. */
26
+ spendable: number;
27
+ }
28
+ export interface StoredValueEntry {
29
+ id: string;
30
+ createdAt: string;
31
+ occurredAt: string;
32
+ entryType: 'issue' | 'redeem' | 'reversal' | 'adjustment' | 'expiry' | 'forfeit';
33
+ /** Signed: credits positive, debits negative. */
34
+ amount: number;
35
+ balanceAfter: number;
36
+ unit: string;
37
+ sourceType: string;
38
+ sourceId: string | null;
39
+ paymentId: string | null;
40
+ orderId: string | null;
41
+ locationId: string | null;
42
+ actorType: string;
43
+ actorId: string | null;
44
+ onBehalfOfRef: string | null;
45
+ deviceRef: string | null;
46
+ reason: string | null;
47
+ }
48
+ export interface StoredValueStatement {
49
+ account: StoredValueAccount;
50
+ openingBalance: number;
51
+ closingBalance: number;
52
+ entries: StoredValueEntry[];
53
+ totalItems: number;
54
+ }
55
+ /** `outstanding = issued − redeemed + reversed + adjusted − expired − forfeited`. */
56
+ export interface StoredValueLiability {
57
+ unit: string;
58
+ kind: string;
59
+ accounts: number;
60
+ issued: number;
61
+ redeemed: number;
62
+ reversed: number;
63
+ adjusted: number;
64
+ expired: number;
65
+ forfeited: number;
66
+ outstanding: number;
67
+ }
68
+ export interface IssueStoredValueInput {
69
+ /** Credit this account; omit to credit the customer's wallet of `kind` and `unit`. */
70
+ accountId?: string;
71
+ customerId?: string;
72
+ kind?: 'gift_card' | 'store_credit' | 'points';
73
+ unit?: string;
74
+ amount: number;
75
+ reason: string;
76
+ /** Sets the account's expiry: valid through this day (`YYYY-MM-DD`) in the store's time zone. */
77
+ expiresOn?: string;
78
+ }
79
+ export interface RedeemStoredValueInput {
80
+ orderId: string;
81
+ accountId: string;
82
+ /** Minor units of the order's currency, which must be the account's unit. */
83
+ amount: number;
84
+ /** The code of the store's payment method on the `stored-value` handler. */
85
+ method: string;
86
+ }
87
+ export interface StoredValueModule {
88
+ accounts(filter?: {
89
+ customerId?: string;
90
+ kind?: string;
91
+ take?: number;
92
+ skip?: number;
93
+ }, options?: Call): Promise<{
94
+ items: StoredValueAccount[];
95
+ totalItems: number;
96
+ }>;
97
+ account(id: string, options?: Call): Promise<StoredValueAccount | null>;
98
+ statement(accountId: string, window?: {
99
+ from?: string;
100
+ to?: string;
101
+ take?: number;
102
+ skip?: number;
103
+ }, options?: Call): Promise<StoredValueStatement>;
104
+ liability(
105
+ /** `locationId`: only redemptions and refunds of orders sold at that stock location. */
106
+ filter?: {
107
+ at?: string;
108
+ kind?: string;
109
+ locationId?: string;
110
+ }, options?: Call): Promise<StoredValueLiability[]>;
111
+ /** Requires ManageStoredValue. Send an `idempotencyKey`: a repeat returns the first result. */
112
+ issue(input: IssueStoredValueInput, options?: Call): Promise<StoredValueAccount>;
113
+ /** Requires ManageStoredValue. Signed; a debit may not take the balance below zero. */
114
+ adjust(input: {
115
+ accountId: string;
116
+ amount: number;
117
+ reason: string;
118
+ expiresOn?: string;
119
+ }, options?: Call): Promise<StoredValueAccount>;
120
+ /**
121
+ * Requires ManageStoredValue. The account's value is valid through `expiresOn` (`YYYY-MM-DD`,
122
+ * store zone); `null` clears it. A day already over is refused (`STORED_VALUE_EXPIRY_INVALID`);
123
+ * value the job already booked as expired stays booked.
124
+ */
125
+ setExpiry(id: string, expiresOn: string | null, reason: string, options?: Call): Promise<StoredValueAccount>;
126
+ block(id: string, reason: string, options?: Call): Promise<StoredValueAccount>;
127
+ unblock(id: string, reason: string, options?: Call): Promise<StoredValueAccount>;
128
+ /**
129
+ * Pay part (or all) of an order from an account (`redeemStoredValue`), through the platform's
130
+ * payment position: the order lock, the outstanding bound and the store's deposit policy apply,
131
+ * and the ledger is debited in the payment's own transaction. Requires UpdateOrder. Answers the
132
+ * payment the SERVER recorded for this call; a repeat under the same key answers the same one.
133
+ */
134
+ redeem(input: RedeemStoredValueInput, options?: Call): Promise<StoredValueRedemption>;
135
+ }
136
+ /** What a redemption recorded: the order, the payment this call created, the account and amount. */
137
+ export interface StoredValueRedemption {
138
+ orderId: string;
139
+ paymentId: string;
140
+ accountId: string;
141
+ /** Minor units of the order's currency. Read the account itself with `account` (ReadStoredValue). */
142
+ amount: number;
143
+ }
144
+ export declare const STORED_VALUE_ACCOUNTS_QUERY = "\n query StoredValueAccounts($customerId: ID, $kind: String, $take: Int, $skip: Int) {\n storedValueAccounts(customerId: $customerId, kind: $kind, take: $take, skip: $skip) {\n items { \n id\n createdAt\n updatedAt\n kind\n unit\n customerId\n codeLast4\n expiresAt\n expiresOn\n status\n balance\n spendable\n }\n totalItems\n }\n }\n";
145
+ export declare const STORED_VALUE_ACCOUNT_QUERY = "\n query StoredValueAccount($id: ID!) {\n storedValueAccount(id: $id) { \n id\n createdAt\n updatedAt\n kind\n unit\n customerId\n codeLast4\n expiresAt\n expiresOn\n status\n balance\n spendable\n }\n }\n";
146
+ export declare const STORED_VALUE_STATEMENT_QUERY = "\n query StoredValueStatement($accountId: ID!, $from: DateTime, $to: DateTime, $take: Int, $skip: Int) {\n storedValueStatement(accountId: $accountId, from: $from, to: $to, take: $take, skip: $skip) {\n account { \n id\n createdAt\n updatedAt\n kind\n unit\n customerId\n codeLast4\n expiresAt\n expiresOn\n status\n balance\n spendable\n }\n openingBalance\n closingBalance\n totalItems\n entries {\n id createdAt occurredAt entryType amount balanceAfter unit sourceType sourceId paymentId\n orderId locationId actorType actorId onBehalfOfRef deviceRef reason\n }\n }\n }\n";
147
+ export declare const STORED_VALUE_LIABILITY_QUERY = "\n query StoredValueLiability($at: DateTime, $kind: String, $locationId: ID) {\n storedValueLiability(at: $at, kind: $kind, locationId: $locationId) {\n unit kind accounts issued redeemed reversed adjusted expired forfeited outstanding\n }\n }\n";
148
+ export declare const ISSUE_STORED_VALUE_MUTATION = "\n mutation IssueStoredValue($input: IssueStoredValueInput!, $idempotencyKey: String) {\n issueStoredValue(input: $input, idempotencyKey: $idempotencyKey) { \n id\n createdAt\n updatedAt\n kind\n unit\n customerId\n codeLast4\n expiresAt\n expiresOn\n status\n balance\n spendable\n }\n }\n";
149
+ export declare const ADJUST_STORED_VALUE_MUTATION = "\n mutation AdjustStoredValue($input: AdjustStoredValueInput!, $idempotencyKey: String) {\n adjustStoredValue(input: $input, idempotencyKey: $idempotencyKey) { \n id\n createdAt\n updatedAt\n kind\n unit\n customerId\n codeLast4\n expiresAt\n expiresOn\n status\n balance\n spendable\n }\n }\n";
150
+ export declare const BLOCK_STORED_VALUE_MUTATION = "\n mutation BlockStoredValueAccount($id: ID!, $reason: String!) {\n blockStoredValueAccount(id: $id, reason: $reason) { \n id\n createdAt\n updatedAt\n kind\n unit\n customerId\n codeLast4\n expiresAt\n expiresOn\n status\n balance\n spendable\n }\n }\n";
151
+ export declare const UNBLOCK_STORED_VALUE_MUTATION = "\n mutation UnblockStoredValueAccount($id: ID!, $reason: String!) {\n unblockStoredValueAccount(id: $id, reason: $reason) { \n id\n createdAt\n updatedAt\n kind\n unit\n customerId\n codeLast4\n expiresAt\n expiresOn\n status\n balance\n spendable\n }\n }\n";
152
+ export declare const SET_STORED_VALUE_EXPIRY_MUTATION = "\n mutation SetStoredValueAccountExpiry(\n $id: ID!\n $expiresOn: String\n $reason: String!\n $idempotencyKey: String\n ) {\n setStoredValueAccountExpiry(\n id: $id\n expiresOn: $expiresOn\n reason: $reason\n idempotencyKey: $idempotencyKey\n ) { \n id\n createdAt\n updatedAt\n kind\n unit\n customerId\n codeLast4\n expiresAt\n expiresOn\n status\n balance\n spendable\n }\n }\n";
153
+ export declare const REDEEM_STORED_VALUE_MUTATION = "\n mutation RedeemStoredValue($input: RedeemStoredValueInput!, $idempotencyKey: String) {\n redeemStoredValue(input: $input, idempotencyKey: $idempotencyKey) {\n orderId\n paymentId\n accountId\n amount\n }\n }\n";
154
+ export declare function createStoredValueModule(transport: Transport): StoredValueModule;