@sixtyninecommerce/admin 0.10.0 → 0.11.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 (247) hide show
  1. package/README.md +4347 -171
  2. package/dist/catalog/assets.d.ts +120 -8
  3. package/dist/catalog/assets.js +98 -12
  4. package/dist/catalog/collections.d.ts +279 -14
  5. package/dist/catalog/collections.js +246 -15
  6. package/dist/catalog/index.d.ts +9 -2
  7. package/dist/catalog/index.js +4 -0
  8. package/dist/catalog/products.d.ts +159 -19
  9. package/dist/catalog/products.js +88 -13
  10. package/dist/catalog/properties.d.ts +102 -14
  11. package/dist/catalog/properties.js +13 -0
  12. package/dist/catalog/recommendations.d.ts +261 -0
  13. package/dist/catalog/recommendations.js +145 -0
  14. package/dist/catalog/reviews.d.ts +368 -0
  15. package/dist/catalog/reviews.js +318 -0
  16. package/dist/catalog/types.d.ts +17 -1
  17. package/dist/catalog/types.js +10 -0
  18. package/dist/catalog/variant-find.d.ts +136 -0
  19. package/dist/catalog/variant-find.js +239 -0
  20. package/dist/catalog/variants.d.ts +233 -26
  21. package/dist/catalog/variants.js +125 -7
  22. package/dist/catalog/visibility.d.ts +20 -5
  23. package/dist/catalog/visibility.js +19 -1
  24. package/dist/client.d.ts +95 -9
  25. package/dist/client.js +35 -7
  26. package/dist/content/assets.d.ts +286 -0
  27. package/dist/content/assets.js +181 -0
  28. package/dist/content/items.d.ts +269 -0
  29. package/dist/content/items.js +170 -0
  30. package/dist/content/types.d.ts +282 -0
  31. package/dist/content/types.js +100 -0
  32. package/dist/customers/age-verification.d.ts +66 -0
  33. package/dist/customers/age-verification.js +79 -0
  34. package/dist/customers/credit.d.ts +263 -0
  35. package/dist/customers/credit.js +244 -0
  36. package/dist/customers/delivery-preferences.d.ts +120 -0
  37. package/dist/customers/delivery-preferences.js +97 -0
  38. package/dist/customers/groups.d.ts +207 -0
  39. package/dist/customers/groups.js +438 -0
  40. package/dist/customers/index.d.ts +447 -37
  41. package/dist/customers/index.js +313 -40
  42. package/dist/customers/invitation-status.d.ts +57 -0
  43. package/dist/customers/invitation-status.js +21 -0
  44. package/dist/customers/notes.d.ts +67 -0
  45. package/dist/customers/notes.js +51 -0
  46. package/dist/customers/notification-recipients.d.ts +97 -0
  47. package/dist/customers/notification-recipients.js +84 -0
  48. package/dist/customers/saved-lists.d.ts +42 -0
  49. package/dist/customers/saved-lists.js +61 -0
  50. package/dist/customers/vat.d.ts +83 -0
  51. package/dist/customers/vat.js +46 -0
  52. package/dist/customers/wire.d.ts +20 -0
  53. package/dist/customers/wire.js +35 -0
  54. package/dist/documents/ar.d.ts +307 -0
  55. package/dist/documents/ar.js +254 -0
  56. package/dist/documents/index.d.ts +731 -21
  57. package/dist/documents/index.js +436 -24
  58. package/dist/documents/pdf.d.ts +2 -0
  59. package/dist/documents/pdf.js +11 -0
  60. package/dist/fulfillments/create.d.ts +167 -0
  61. package/dist/fulfillments/create.js +216 -0
  62. package/dist/fulfillments/index.d.ts +44 -10
  63. package/dist/fulfillments/index.js +11 -2
  64. package/dist/fulfillments/payment-policy.d.ts +64 -0
  65. package/dist/fulfillments/payment-policy.js +140 -0
  66. package/dist/fulfillments/warehouse.d.ts +724 -0
  67. package/dist/fulfillments/warehouse.js +914 -0
  68. package/dist/geo/index.d.ts +119 -0
  69. package/dist/geo/index.js +107 -0
  70. package/dist/index.d.ts +123 -35
  71. package/dist/index.js +45 -12
  72. package/dist/integrations/afas-actions.d.ts +234 -0
  73. package/dist/integrations/afas-actions.js +310 -0
  74. package/dist/integrations/afas-types.d.ts +483 -0
  75. package/dist/integrations/afas-types.js +5 -0
  76. package/dist/integrations/afas.d.ts +234 -0
  77. package/dist/integrations/afas.js +290 -0
  78. package/dist/integrations/connections.d.ts +103 -0
  79. package/dist/integrations/connections.js +55 -0
  80. package/dist/integrations/esp.d.ts +313 -0
  81. package/dist/integrations/esp.js +169 -0
  82. package/dist/integrations/exact-online-types.d.ts +423 -0
  83. package/dist/integrations/exact-online-types.js +6 -0
  84. package/dist/integrations/exact-online.d.ts +248 -0
  85. package/dist/integrations/exact-online.js +376 -0
  86. package/dist/integrations/index.d.ts +29 -3
  87. package/dist/integrations/index.js +18 -3
  88. package/dist/integrations/pipeline-keys.d.ts +13 -0
  89. package/dist/integrations/pipeline-keys.js +22 -0
  90. package/dist/integrations/pipelines.d.ts +15 -14
  91. package/dist/integrations/pipelines.js +6 -22
  92. package/dist/integrations/types.d.ts +146 -0
  93. package/dist/locations/index.d.ts +66 -0
  94. package/dist/locations/index.js +31 -0
  95. package/dist/meta/index.d.ts +162 -0
  96. package/dist/orders/cancel-with-money.d.ts +227 -0
  97. package/dist/orders/cancel-with-money.js +153 -0
  98. package/dist/orders/commit-edit.d.ts +7 -1
  99. package/dist/orders/commit-edit.js +5 -1
  100. package/dist/orders/drafts.d.ts +800 -0
  101. package/dist/orders/drafts.js +771 -0
  102. package/dist/orders/fields.d.ts +245 -0
  103. package/dist/orders/fields.js +188 -0
  104. package/dist/orders/get.d.ts +29 -19
  105. package/dist/orders/get.js +17 -8
  106. package/dist/orders/index.d.ts +49 -9
  107. package/dist/orders/index.js +22 -2
  108. package/dist/orders/lifecycle.d.ts +128 -0
  109. package/dist/orders/lifecycle.js +158 -0
  110. package/dist/orders/line-price-preview.d.ts +7 -2
  111. package/dist/orders/list.d.ts +222 -0
  112. package/dist/orders/list.js +377 -0
  113. package/dist/orders/manual-pricing.d.ts +5 -0
  114. package/dist/orders/order-entry.d.ts +20 -7
  115. package/dist/orders/plan-edit.d.ts +1 -1
  116. package/dist/orders/plan-edit.js +4 -1
  117. package/dist/orders/settings.d.ts +201 -0
  118. package/dist/orders/settings.js +325 -0
  119. package/dist/orders/status.d.ts +159 -13
  120. package/dist/orders/status.js +21 -0
  121. package/dist/orders/surcharges.d.ts +8 -1
  122. package/dist/orders/surcharges.js +3 -2
  123. package/dist/payments/account-credit.d.ts +30 -0
  124. package/dist/payments/account-credit.js +19 -0
  125. package/dist/payments/ar.d.ts +292 -0
  126. package/dist/payments/ar.js +223 -0
  127. package/dist/payments/connected-account.d.ts +47 -0
  128. package/dist/payments/connected-account.js +61 -0
  129. package/dist/payments/credit-noted-fields.d.ts +12 -0
  130. package/dist/payments/credit-noted-fields.js +37 -0
  131. package/dist/payments/index.d.ts +257 -11
  132. package/dist/payments/index.js +131 -1
  133. package/dist/payments/methods.d.ts +303 -8
  134. package/dist/payments/methods.js +337 -7
  135. package/dist/payments/mollie-methods.d.ts +159 -0
  136. package/dist/payments/mollie-methods.js +141 -0
  137. package/dist/payments/payment-links.d.ts +180 -0
  138. package/dist/payments/payment-links.js +97 -0
  139. package/dist/payments/provider-keys.d.ts +150 -0
  140. package/dist/payments/provider-keys.js +118 -0
  141. package/dist/payments/providers.d.ts +86 -11
  142. package/dist/payments/providers.js +29 -0
  143. package/dist/payments/requests.d.ts +144 -0
  144. package/dist/payments/requests.js +92 -0
  145. package/dist/payments/store-credit-fields.d.ts +15 -0
  146. package/dist/payments/store-credit-fields.js +51 -0
  147. package/dist/pickups/index.d.ts +104 -0
  148. package/dist/pickups/index.js +105 -0
  149. package/dist/platform/channels.d.ts +132 -0
  150. package/dist/platform/channels.js +128 -0
  151. package/dist/platform/geo.d.ts +123 -0
  152. package/dist/platform/geo.js +144 -0
  153. package/dist/platform/tax.d.ts +154 -0
  154. package/dist/platform/tax.js +139 -0
  155. package/dist/pos/anomalies.d.ts +158 -0
  156. package/dist/pos/anomalies.js +64 -0
  157. package/dist/pos/assisted-selling.d.ts +79 -0
  158. package/dist/pos/assisted-selling.js +38 -0
  159. package/dist/pos/exchanges.d.ts +103 -0
  160. package/dist/pos/exchanges.js +22 -0
  161. package/dist/pos/gift-cards.d.ts +135 -0
  162. package/dist/pos/gift-cards.js +47 -0
  163. package/dist/pos/index.d.ts +2125 -32
  164. package/dist/pos/index.js +742 -4
  165. package/dist/pos/no-receipt.d.ts +94 -0
  166. package/dist/pos/no-receipt.js +25 -0
  167. package/dist/pos/offline-sales.d.ts +187 -0
  168. package/dist/pos/offline-sales.js +116 -0
  169. package/dist/pos/pay-by-link.d.ts +143 -0
  170. package/dist/pos/pay-by-link.js +57 -0
  171. package/dist/pos/quick-keys.d.ts +103 -0
  172. package/dist/pos/quick-keys.js +45 -0
  173. package/dist/pos/reports.d.ts +360 -0
  174. package/dist/pos/reports.js +62 -0
  175. package/dist/pos/returns.d.ts +217 -0
  176. package/dist/pos/returns.js +53 -0
  177. package/dist/pricing/bulk-coupons.d.ts +139 -0
  178. package/dist/pricing/bulk-coupons.js +112 -0
  179. package/dist/pricing/index.d.ts +174 -4
  180. package/dist/pricing/index.js +174 -1
  181. package/dist/pricing/price-lists.d.ts +604 -0
  182. package/dist/pricing/price-lists.js +600 -0
  183. package/dist/purchasing/alerts.d.ts +89 -0
  184. package/dist/purchasing/alerts.js +62 -0
  185. package/dist/purchasing/cost.d.ts +110 -0
  186. package/dist/purchasing/cost.js +86 -0
  187. package/dist/purchasing/index.d.ts +36 -0
  188. package/dist/purchasing/index.js +16 -0
  189. package/dist/purchasing/purchase-orders.d.ts +548 -0
  190. package/dist/purchasing/purchase-orders.js +491 -0
  191. package/dist/purchasing/replenishment.d.ts +281 -0
  192. package/dist/purchasing/replenishment.js +240 -0
  193. package/dist/purchasing/settings.d.ts +152 -0
  194. package/dist/purchasing/settings.js +181 -0
  195. package/dist/purchasing/suppliers.d.ts +476 -0
  196. package/dist/purchasing/suppliers.js +438 -0
  197. package/dist/quotes/index.d.ts +501 -0
  198. package/dist/quotes/index.js +439 -0
  199. package/dist/reports/index.d.ts +71 -8
  200. package/dist/reports/index.js +74 -11
  201. package/dist/returns/index.d.ts +614 -21
  202. package/dist/returns/index.js +695 -11
  203. package/dist/search/index.d.ts +76 -1
  204. package/dist/search/index.js +63 -0
  205. package/dist/shipping/definitions.d.ts +29 -0
  206. package/dist/shipping/definitions.js +47 -0
  207. package/dist/shipping/fulfillment-profiles.d.ts +174 -0
  208. package/dist/shipping/fulfillment-profiles.js +104 -0
  209. package/dist/shipping/hendriks.d.ts +97 -0
  210. package/dist/shipping/hendriks.js +50 -0
  211. package/dist/shipping/index.d.ts +48 -0
  212. package/dist/shipping/index.js +25 -0
  213. package/dist/shipping/methods.d.ts +198 -0
  214. package/dist/shipping/methods.js +240 -0
  215. package/dist/shipping/myparcel.d.ts +254 -0
  216. package/dist/shipping/myparcel.js +178 -0
  217. package/dist/shipping/parcel-count-suggestion.d.ts +2 -0
  218. package/dist/shipping/parcel-rule.d.ts +6 -5
  219. package/dist/shipping/parcel-rule.js +21 -23
  220. package/dist/shipping/rate-tables.d.ts +179 -0
  221. package/dist/shipping/rate-tables.js +184 -0
  222. package/dist/stock/index.d.ts +10 -3
  223. package/dist/stock/index.js +3 -0
  224. package/dist/stock/locations.d.ts +144 -0
  225. package/dist/stock/locations.js +168 -0
  226. package/dist/stock/transfers.d.ts +216 -43
  227. package/dist/stock/transfers.js +140 -13
  228. package/dist/stored-value/index.d.ts +214 -4
  229. package/dist/stored-value/index.js +152 -0
  230. package/dist/subscriptions/index.d.ts +682 -0
  231. package/dist/subscriptions/index.js +815 -0
  232. package/dist/tax/index.d.ts +76 -1
  233. package/dist/tax/index.js +50 -0
  234. package/dist/tenant/email-style.d.ts +102 -0
  235. package/dist/tenant/email-style.js +72 -0
  236. package/dist/tenant/email-templates.d.ts +66 -0
  237. package/dist/tenant/email-templates.js +54 -0
  238. package/dist/tenant/notifications.d.ts +23 -17
  239. package/dist/tenant/settings-sources.d.ts +1 -1
  240. package/dist/tenant/time-zone.d.ts +17 -0
  241. package/dist/tenant/time-zone.js +11 -0
  242. package/dist/types.d.ts +50 -3
  243. package/dist/users/index.d.ts +3 -0
  244. package/dist/users/index.js +2 -0
  245. package/dist/users/warehouses.d.ts +50 -0
  246. package/dist/users/warehouses.js +51 -0
  247. package/package.json +2 -2
@@ -1,8 +1,14 @@
1
1
  import { createPage, idempotencyKey as mintIdempotencyKey, pageFromVendureList, readOffsetCursor, ValidationError, } from '@sixtyninecommerce/core';
2
+ import { storeCreditAware } from '../payments/store-credit-fields.js';
3
+ import { createArDocumentsModule } from './ar.js';
4
+ import { decodePdf } from './pdf.js';
5
+ // Also what `documents.ar.pdf` decodes with (headless W10-30).
6
+ export { decodePdf };
2
7
  const API_DOCUMENT_TYPE = {
3
8
  invoice: 'INVOICE',
4
9
  'credit-note': 'CREDIT_NOTE',
5
10
  'packing-slip': 'PACKING_SLIP',
11
+ 'purchase-order': 'PURCHASE_ORDER',
6
12
  };
7
13
  /**
8
14
  * Most blocks one document may carry. A longer list refuses the whole document
@@ -10,6 +16,12 @@ const API_DOCUMENT_TYPE = {
10
16
  * dropped the overflow — a document is a page, not a feed.
11
17
  */
12
18
  export const MAX_DOCUMENT_EXTENSIONS = 10;
19
+ /** Every {@link DocumentEmailEvent}, in the order the server's enum declares them. */
20
+ export const DOCUMENT_EMAIL_EVENTS = [
21
+ 'invoice_generated',
22
+ 'credit_note_issued',
23
+ 'proforma',
24
+ ];
13
25
  const DOCUMENT_LINE_FIELDS = /* GraphQL */ `
14
26
  description
15
27
  sku
@@ -40,6 +52,8 @@ const INVOICE_FIELDS = /* GraphQL */ `
40
52
  supplementsInvoiceId
41
53
  lines { ${DOCUMENT_LINE_FIELDS} }
42
54
  numberingProvider
55
+ amountPaid
56
+ amountDue
43
57
  createdAt
44
58
  `;
45
59
  const CREDIT_NOTE_FIELDS = /* GraphQL */ `
@@ -172,8 +186,8 @@ export const ORDER_CREDIT_NOTE_EMAIL_SENDS_QUERY = /* GraphQL */ `
172
186
  }
173
187
  `;
174
188
  export const ISSUE_PARTIAL_CREDIT_NOTE_MUTATION = /* GraphQL */ `
175
- mutation IssuePartialCreditNote($input: IssuePartialCreditNoteInput!) {
176
- issuePartialCreditNote(input: $input) { ${CREDIT_NOTE_FIELDS} }
189
+ mutation IssuePartialCreditNote($input: IssuePartialCreditNoteInput!, $idempotencyKey: String) {
190
+ issuePartialCreditNote(input: $input, idempotencyKey: $idempotencyKey) { ${CREDIT_NOTE_FIELDS} }
177
191
  }
178
192
  `;
179
193
  export const ISSUE_SUPPLEMENTARY_INVOICE_MUTATION = /* GraphQL */ `
@@ -232,9 +246,43 @@ const INVOICE_CORRECTION_PLAN_FIELDS = /* GraphQL */ `
232
246
  options { paymentId method amount refundable }
233
247
  recommendedPaymentId
234
248
  }
235
- accountCredit { available unavailableCode message }
249
+ accountCredit { available unavailableCode message book }
236
250
  settlement
237
251
  blockers { code message path }
252
+ returnedGoods {
253
+ lines {
254
+ orderLineId
255
+ description
256
+ quantity
257
+ returnedQuantity
258
+ creditedQuantity
259
+ creditableQuantity
260
+ creditableAmount
261
+ returnCodes
262
+ }
263
+ shipping { charged refunded credited creditable returnCodes }
264
+ }
265
+ givenBack {
266
+ lines {
267
+ orderLineId
268
+ description
269
+ quantity
270
+ returnedQuantity
271
+ creditedQuantity
272
+ priceCredited
273
+ creditableQuantity
274
+ creditableAmount
275
+ returnCodes
276
+ creditNoteNumbers
277
+ }
278
+ shipping { charged refunded credited creditable returnCodes creditNoteNumbers }
279
+ }
280
+ paymentTerms {
281
+ invoiced { summary paymentDays conditionCode dueOn }
282
+ replacement { summary paymentDays conditionCode dueOn }
283
+ accepts
284
+ unavailableMessage
285
+ }
238
286
  `;
239
287
  export const PLAN_INVOICE_CORRECTION_QUERY = /* GraphQL */ `
240
288
  query PlanInvoiceCorrection($input: InvoiceCorrectionInput!) {
@@ -269,7 +317,7 @@ export const COMMIT_INVOICE_CORRECTION_MUTATION = /* GraphQL */ `
269
317
  numberingProvider
270
318
  }
271
319
  refund { id state total paymentId }
272
- accountCredit { amount currencyCode unappliedCashIds }
320
+ accountCredit { amount currencyCode unappliedCashIds book storeCreditEntryIds }
273
321
  }
274
322
  }
275
323
  `;
@@ -288,6 +336,231 @@ export const DELETE_DOCUMENT_EXTENSION_MUTATION = /* GraphQL */ `
288
336
  deleteDocumentExtension(key: $key)
289
337
  }
290
338
  `;
339
+ /**
340
+ * The invoice config every engine answers. `columnUnitPriceAfterDiscount` arrived after the rest
341
+ * (2026-10-09), and an engine without it refuses the whole document, so each document has a
342
+ * `_LEGACY` twin selecting only these, sent once the engine refused the current one.
343
+ */
344
+ const INVOICE_CONFIG_FIELDS_LEGACY = /* GraphQL */ `
345
+ id
346
+ enabled
347
+ prefix
348
+ suffix
349
+ nextNumber
350
+ digits
351
+ yearFormat
352
+ yearReset
353
+ creditNoteNextNumber
354
+ creditNotePrefix
355
+ creditNoteSuffix
356
+ creditNoteDigits
357
+ creditNoteYearFormat
358
+ creditNoteYearReset
359
+ columnProduct
360
+ columnSku
361
+ columnQuantity
362
+ columnUnitPriceExcl
363
+ columnUnitPriceDiscount
364
+ columnUnitPriceIncl
365
+ columnLineTotal
366
+ columnLineDiscount
367
+ columnTaxRate
368
+ columnTaxAmount
369
+ columnTotal
370
+ showLogo
371
+ legalIdentityBlock
372
+ footerText
373
+ defaultLanguage
374
+ externalNumberOrderField
375
+ invoicingProvider
376
+ `;
377
+ const INVOICE_CONFIG_FIELDS = /* GraphQL */ `
378
+ ${INVOICE_CONFIG_FIELDS_LEGACY}
379
+ columnUnitPriceAfterDiscount
380
+ `;
381
+ export const INVOICE_CONFIG_QUERY = /* GraphQL */ `
382
+ query InvoiceConfig {
383
+ invoiceConfig { ${INVOICE_CONFIG_FIELDS} }
384
+ }
385
+ `;
386
+ export const UPDATE_INVOICE_CONFIG_MUTATION = /* GraphQL */ `
387
+ mutation UpdateInvoiceConfig($input: UpdateInvoiceConfigInput!) {
388
+ updateInvoiceConfig(input: $input) { ${INVOICE_CONFIG_FIELDS} }
389
+ }
390
+ `;
391
+ /** {@link INVOICE_CONFIG_QUERY} for an engine without `columnUnitPriceAfterDiscount`. */
392
+ export const INVOICE_CONFIG_QUERY_LEGACY = /* GraphQL */ `
393
+ query InvoiceConfig {
394
+ invoiceConfig { ${INVOICE_CONFIG_FIELDS_LEGACY} }
395
+ }
396
+ `;
397
+ /** {@link UPDATE_INVOICE_CONFIG_MUTATION} for an engine without `columnUnitPriceAfterDiscount`. */
398
+ export const UPDATE_INVOICE_CONFIG_MUTATION_LEGACY = /* GraphQL */ `
399
+ mutation UpdateInvoiceConfig($input: UpdateInvoiceConfigInput!) {
400
+ updateInvoiceConfig(input: $input) { ${INVOICE_CONFIG_FIELDS_LEGACY} }
401
+ }
402
+ `;
403
+ /** {@link SET_INVOICING_PROVIDER_MUTATION} for an engine without `columnUnitPriceAfterDiscount`. */
404
+ export const SET_INVOICING_PROVIDER_MUTATION_LEGACY = /* GraphQL */ `
405
+ mutation SetInvoicingProvider($code: String!) {
406
+ setInvoicingProvider(code: $code) { ${INVOICE_CONFIG_FIELDS_LEGACY} }
407
+ }
408
+ `;
409
+ export const INVOICING_PROVIDERS_QUERY = /* GraphQL */ `
410
+ query InvoicingProviders {
411
+ invoicingProviders {
412
+ code
413
+ label
414
+ external
415
+ documents
416
+ ready
417
+ notReadyReason
418
+ }
419
+ }
420
+ `;
421
+ export const SET_INVOICING_PROVIDER_MUTATION = /* GraphQL */ `
422
+ mutation SetInvoicingProvider($code: String!) {
423
+ setInvoicingProvider(code: $code) { ${INVOICE_CONFIG_FIELDS} }
424
+ }
425
+ `;
426
+ const FINANCIAL_DOCUMENT_ISSUE_FIELDS = /* GraphQL */ `
427
+ id
428
+ provider
429
+ operationKey
430
+ documentType
431
+ ledger
432
+ orderId
433
+ status
434
+ externalRef
435
+ externalNumber
436
+ documentDate
437
+ attempts
438
+ lastError
439
+ reservedAt
440
+ bookedAt
441
+ recordedAt
442
+ abandonReason
443
+ `;
444
+ export const FINANCIAL_DOCUMENT_ISSUES_QUERY = /* GraphQL */ `
445
+ query FinancialDocumentIssues($unresolvedOnly: Boolean, $take: Int, $skip: Int) {
446
+ financialDocumentIssues(unresolvedOnly: $unresolvedOnly, take: $take, skip: $skip) {
447
+ totalItems
448
+ items { ${FINANCIAL_DOCUMENT_ISSUE_FIELDS} }
449
+ }
450
+ }
451
+ `;
452
+ export const ABANDON_FINANCIAL_DOCUMENT_ISSUE_MUTATION = /* GraphQL */ `
453
+ mutation AbandonFinancialDocumentIssue($id: ID!, $reason: String!) {
454
+ abandonFinancialDocumentIssue(id: $id, reason: $reason) { ${FINANCIAL_DOCUMENT_ISSUE_FIELDS} }
455
+ }
456
+ `;
457
+ export const RESOLVE_FINANCIAL_DOCUMENT_ISSUE_MUTATION = /* GraphQL */ `
458
+ mutation ResolveFinancialDocumentIssue($id: ID!, $reason: String!) {
459
+ resolveFinancialDocumentIssue(id: $id, reason: $reason) { ${FINANCIAL_DOCUMENT_ISSUE_FIELDS} }
460
+ }
461
+ `;
462
+ export const SEND_PROFORMA_INVOICE_MUTATION = /* GraphQL */ `
463
+ mutation SendProformaInvoice($input: SendProformaInvoiceInput!) {
464
+ sendProformaInvoice(input: $input)
465
+ }
466
+ `;
467
+ export const ORDER_PROFORMA_SENDS_QUERY = /* GraphQL */ `
468
+ query OrderProformaSends($orderId: ID!) {
469
+ orderProformaSends(orderId: $orderId) {
470
+ id
471
+ orderId
472
+ recipients
473
+ message
474
+ invoicedOn
475
+ createdAt
476
+ }
477
+ }
478
+ `;
479
+ export const ORDER_INVOICE_EMAIL_SENDS_QUERY = /* GraphQL */ `
480
+ query OrderInvoiceEmailSends($orderId: ID!) {
481
+ orderInvoiceEmailSends(orderId: $orderId) {
482
+ id
483
+ orderId
484
+ recipientsTo
485
+ recipientsCc
486
+ createdAt
487
+ }
488
+ }
489
+ `;
490
+ /** Its own document: `documentEmailRecipients` is new, so on an older engine this call alone fails. */
491
+ export const DOCUMENT_EMAIL_RECIPIENTS_QUERY = /* GraphQL */ `
492
+ query DocumentEmailRecipients($orderId: ID!, $event: DocumentEmailEvent!) {
493
+ documentEmailRecipients(orderId: $orderId, event: $event) {
494
+ to
495
+ cc
496
+ }
497
+ }
498
+ `;
499
+ export const REGENERATE_PACKING_SLIP_MUTATION = /* GraphQL */ `
500
+ mutation RegeneratePackingSlip($fulfillmentId: ID!, $languageCode: String) {
501
+ regeneratePackingSlip(fulfillmentId: $fulfillmentId, languageCode: $languageCode) {
502
+ ${PACKING_SLIP_FIELDS}
503
+ }
504
+ }
505
+ `;
506
+ export const PACKING_SLIP_FIELDS_QUERY = /* GraphQL */ `
507
+ query PackingSlipFulfillmentFields {
508
+ packingSlipFulfillmentFields {
509
+ handlerCode
510
+ handlerName
511
+ fields {
512
+ key
513
+ label
514
+ type
515
+ defaultVisible
516
+ }
517
+ }
518
+ }
519
+ `;
520
+ const PACKING_SLIP_CONFIG_FIELDS = /* GraphQL */ `
521
+ id
522
+ enabled
523
+ prefix
524
+ suffix
525
+ nextNumber
526
+ digits
527
+ yearFormat
528
+ yearReset
529
+ columnRowNumber
530
+ columnProduct
531
+ columnSku
532
+ columnQuantity
533
+ showLogo
534
+ showInvoiceNumber
535
+ fulfillmentFieldVisibility
536
+ footerText
537
+ defaultLanguage
538
+ `;
539
+ export const PACKING_SLIP_CONFIG_QUERY = /* GraphQL */ `
540
+ query PackingSlipConfig {
541
+ packingSlipConfig { ${PACKING_SLIP_CONFIG_FIELDS} }
542
+ }
543
+ `;
544
+ export const UPDATE_PACKING_SLIP_CONFIG_MUTATION = /* GraphQL */ `
545
+ mutation UpdatePackingSlipConfig($input: UpdatePackingSlipConfigInput!) {
546
+ updatePackingSlipConfig(input: $input) { ${PACKING_SLIP_CONFIG_FIELDS} }
547
+ }
548
+ `;
549
+ /**
550
+ * Whether a failure is "this engine does not know that field yet": the document refused before it
551
+ * ran (graphql-js answers a validation failure with HTTP 400 → `BAD_REQUEST`, or coded
552
+ * `GRAPHQL_VALIDATION_FAILED`), never an execution-time refusal or a transient failure. The
553
+ * returns module reads the same signs.
554
+ */
555
+ function isUnknownFieldRejection(error) {
556
+ if (!(error instanceof ValidationError) || error.service !== 'vendure')
557
+ return false;
558
+ return (error.code === 'BAD_REQUEST' ||
559
+ error.code === 'GRAPHQL_VALIDATION_FAILED' ||
560
+ /Cannot query field/i.test(error.message));
561
+ }
562
+ /** The server's default page of booking attempts; the SDK states it so the cursor arithmetic knows the size. */
563
+ const ISSUES_PAGE_SIZE = 50;
291
564
  /** A complete array behind the SDK's page shape (spec §9.2). */
292
565
  function wholeList(items, what) {
293
566
  return createPage(items, { nextCursor: null, hasNext: false, total: items.length }, () => {
@@ -322,19 +595,18 @@ function fromApiTypes(values) {
322
595
  function toSchema(raw) {
323
596
  return { ...raw, documentTypes: fromApiTypes(raw.documentTypes) };
324
597
  }
325
- /** Decode the base64 a PDF-returning mutation answers with. */
326
- function decodePdf(base64) {
327
- // Node and every modern runtime have `atob`; Buffer would tie this package
328
- // to Node, and it ships to browsers as the dashboard's client.
329
- const binary = atob(base64);
330
- const bytes = new Uint8Array(binary.length);
331
- for (let index = 0; index < binary.length; index += 1) {
332
- bytes[index] = binary.charCodeAt(index);
333
- }
334
- return bytes;
335
- }
336
598
  /** The server's default page; the SDK states it so the cursor arithmetic knows the size. */
337
599
  const CUSTOMER_DOCUMENTS_PAGE_SIZE = 25;
600
+ /**
601
+ * The key a caller retries an attempt under, put on the error the attempt threw (when nothing below
602
+ * put one there already). Returns the same error.
603
+ */
604
+ function withAttemptKey(error, key) {
605
+ if (error !== null && typeof error === 'object' && !('idempotencyKey' in error)) {
606
+ Object.defineProperty(error, 'idempotencyKey', { value: key, enumerable: true });
607
+ }
608
+ return error;
609
+ }
338
610
  export function createDocumentsModule(transport) {
339
611
  const customerDocumentsPage = async (customerId, skip, take, options) => {
340
612
  const data = await transport.graphql({
@@ -346,6 +618,31 @@ export function createDocumentsModule(transport) {
346
618
  const items = list.items.map((item) => ({ ...item, type: fromApiType(item.type) }));
347
619
  return pageFromVendureList({ items, totalItems: list.totalItems }, skip, take, (cursor) => customerDocumentsPage(customerId, readOffsetCursor(cursor), take, options));
348
620
  };
621
+ /** Latched once the engine proved it predates `columnUnitPriceAfterDiscount` (one refused request per client). */
622
+ let afterDiscountUnsupported = false;
623
+ /** Sends the current invoice-config document, or its legacy twin once the engine refused the column. */
624
+ async function withInvoiceConfigFallback(query, legacy, variables, options) {
625
+ if (!afterDiscountUnsupported) {
626
+ try {
627
+ return await transport.graphql({ api: 'admin', query, variables }, options);
628
+ }
629
+ catch (error) {
630
+ if (!isUnknownFieldRejection(error))
631
+ throw error;
632
+ }
633
+ }
634
+ const data = await transport.graphql({ api: 'admin', query: legacy, variables }, options);
635
+ afterDiscountUnsupported = true;
636
+ return data;
637
+ }
638
+ const issuesPage = async (skip, take, options) => {
639
+ const data = await transport.graphql({
640
+ api: 'admin',
641
+ query: FINANCIAL_DOCUMENT_ISSUES_QUERY,
642
+ variables: { unresolvedOnly: options?.unresolvedOnly ?? false, take, skip },
643
+ }, options);
644
+ return pageFromVendureList(data.financialDocumentIssues, skip, take, (cursor) => issuesPage(readOffsetCursor(cursor), take, options));
645
+ };
349
646
  return {
350
647
  // One implementation behind the two overloads the interface declares; the
351
648
  // cast is the standard TypeScript shape for that, since an implementation
@@ -460,17 +757,31 @@ export function createDocumentsModule(transport) {
460
757
  return wholeList(data.orderCreditNoteEmailSends, 'orderCreditNoteEmailSends');
461
758
  },
462
759
  async issuePartialCreditNote(input, options) {
463
- const data = await transport.graphql({ api: 'admin', query: ISSUE_PARTIAL_CREDIT_NOTE_MUTATION, variables: { input } }, options);
464
- return data.issuePartialCreditNote;
760
+ const key = options?.idempotencyKey ?? mintIdempotencyKey();
761
+ try {
762
+ const data = await transport.graphql({
763
+ api: 'admin',
764
+ query: ISSUE_PARTIAL_CREDIT_NOTE_MUTATION,
765
+ // A retry of this attempt sends the same input under the same key.
766
+ variables: { input, idempotencyKey: key },
767
+ }, { ...options, idempotencyKey: key });
768
+ return { ...data.issuePartialCreditNote, idempotencyKey: key };
769
+ }
770
+ catch (error) {
771
+ throw withAttemptKey(error, key);
772
+ }
465
773
  },
466
774
  async planCorrection(input, options) {
467
- const data = await transport.graphql({ api: 'admin', query: PLAN_INVOICE_CORRECTION_QUERY, variables: { input } }, options);
775
+ // `book` (incentives sprint 8 PR 4): dropped once for an engine before it.
776
+ const data = await storeCreditAware(transport).graphql({ api: 'admin', query: PLAN_INVOICE_CORRECTION_QUERY, variables: { input } }, options);
468
777
  return data.planInvoiceCorrection;
469
778
  },
470
779
  async commitCorrection(input, options) {
471
780
  const key = options.idempotencyKey ?? mintIdempotencyKey();
472
781
  try {
473
- const data = await transport.graphql({
782
+ // `book` and `storeCreditEntryIds` (sprint 8 PR 4): an engine before them refuses the
783
+ // document before it runs, and it is sent once more without them under the same key.
784
+ const data = await storeCreditAware(transport).graphql({
474
785
  api: 'admin',
475
786
  query: COMMIT_INVOICE_CORRECTION_MUTATION,
476
787
  // The input goes out as given, never normalised: it must be the request the plan was
@@ -480,17 +791,118 @@ export function createDocumentsModule(transport) {
480
791
  return { ...data.commitInvoiceCorrection, idempotencyKey: key };
481
792
  }
482
793
  catch (error) {
483
- // The key the caller retries under, when it did not choose one.
484
- if (error !== null && typeof error === 'object' && !('idempotencyKey' in error)) {
485
- Object.defineProperty(error, 'idempotencyKey', { value: key, enumerable: true });
486
- }
487
- throw error;
794
+ throw withAttemptKey(error, key);
488
795
  }
489
796
  },
490
797
  async issueSupplementaryInvoice(input, options) {
491
798
  const data = await transport.graphql({ api: 'admin', query: ISSUE_SUPPLEMENTARY_INVOICE_MUTATION, variables: { input } }, options);
492
799
  return data.issueSupplementaryInvoice;
493
800
  },
801
+ async sendProforma(orderId, input, options) {
802
+ const data = await transport.graphql({
803
+ api: 'admin',
804
+ query: SEND_PROFORMA_INVOICE_MUTATION,
805
+ variables: {
806
+ input: {
807
+ orderId,
808
+ invoicedOn: input.invoicedOn,
809
+ recipients: input.recipients,
810
+ message: input.message ?? null,
811
+ languageCode: input.languageCode ?? null,
812
+ },
813
+ },
814
+ }, options);
815
+ return data.sendProformaInvoice;
816
+ },
817
+ async proformaSends(orderId, options) {
818
+ const data = await transport.graphql({ api: 'admin', query: ORDER_PROFORMA_SENDS_QUERY, variables: { orderId } }, options);
819
+ return wholeList(data.orderProformaSends, 'orderProformaSends');
820
+ },
821
+ async invoiceEmailSends(orderId, options) {
822
+ const data = await transport.graphql({ api: 'admin', query: ORDER_INVOICE_EMAIL_SENDS_QUERY, variables: { orderId } }, options);
823
+ return wholeList(data.orderInvoiceEmailSends, 'orderInvoiceEmailSends');
824
+ },
825
+ async emailRecipients(orderId, event, options) {
826
+ if (!DOCUMENT_EMAIL_EVENTS.includes(event)) {
827
+ throw new ValidationError({
828
+ code: 'INVALID_DOCUMENT_EMAIL_EVENT',
829
+ message: `"${String(event)}" is not a document email. Expected one of ${DOCUMENT_EMAIL_EVENTS.join(', ')}.`,
830
+ status: 400,
831
+ service: 'vendure',
832
+ });
833
+ }
834
+ const data = await transport.graphql({ api: 'admin', query: DOCUMENT_EMAIL_RECIPIENTS_QUERY, variables: { orderId, event } }, options);
835
+ return data.documentEmailRecipients;
836
+ },
837
+ async regeneratePackingSlip(fulfillmentId, options) {
838
+ const data = await transport.graphql({
839
+ api: 'admin',
840
+ query: REGENERATE_PACKING_SLIP_MUTATION,
841
+ variables: { fulfillmentId, languageCode: options?.languageCode ?? null },
842
+ }, options);
843
+ return data.regeneratePackingSlip;
844
+ },
845
+ async packingSlipFields(options) {
846
+ const data = await transport.graphql({ api: 'admin', query: PACKING_SLIP_FIELDS_QUERY }, options);
847
+ return wholeList(data.packingSlipFulfillmentFields, 'packingSlipFulfillmentFields');
848
+ },
849
+ invoiceConfig: {
850
+ async get(options) {
851
+ const data = await withInvoiceConfigFallback(INVOICE_CONFIG_QUERY, INVOICE_CONFIG_QUERY_LEGACY, {}, options);
852
+ return data.invoiceConfig;
853
+ },
854
+ async update(input, options) {
855
+ // Validation refuses the document before anything runs, so the legacy send is the first
856
+ // attempt, never a repeat.
857
+ const data = await withInvoiceConfigFallback(UPDATE_INVOICE_CONFIG_MUTATION, UPDATE_INVOICE_CONFIG_MUTATION_LEGACY, { input }, options);
858
+ return data.updateInvoiceConfig;
859
+ },
860
+ },
861
+ invoicingProviders: {
862
+ async list(options) {
863
+ const data = await transport.graphql({ api: 'admin', query: INVOICING_PROVIDERS_QUERY }, options);
864
+ return wholeList(data.invoicingProviders, 'invoicingProviders');
865
+ },
866
+ async set(provider, options) {
867
+ const data = await withInvoiceConfigFallback(SET_INVOICING_PROVIDER_MUTATION, SET_INVOICING_PROVIDER_MUTATION_LEGACY, { code: provider }, options);
868
+ return data.setInvoicingProvider;
869
+ },
870
+ },
871
+ issues: {
872
+ list(options) {
873
+ // The Admin API is offset-paged; the offset hides inside the cursor (spec §9.3).
874
+ const take = options?.limit ?? ISSUES_PAGE_SIZE;
875
+ const skip = options?.after === undefined ? 0 : readOffsetCursor(options.after);
876
+ return issuesPage(skip, take, options);
877
+ },
878
+ async abandon(id, reason, options) {
879
+ const data = await transport.graphql({
880
+ api: 'admin',
881
+ query: ABANDON_FINANCIAL_DOCUMENT_ISSUE_MUTATION,
882
+ variables: { id, reason },
883
+ }, options);
884
+ return data.abandonFinancialDocumentIssue;
885
+ },
886
+ async resolve(id, reason, options) {
887
+ const data = await transport.graphql({
888
+ api: 'admin',
889
+ query: RESOLVE_FINANCIAL_DOCUMENT_ISSUE_MUTATION,
890
+ variables: { id, reason },
891
+ }, options);
892
+ return data.resolveFinancialDocumentIssue;
893
+ },
894
+ },
895
+ packingSlipConfig: {
896
+ async get(options) {
897
+ const data = await transport.graphql({ api: 'admin', query: PACKING_SLIP_CONFIG_QUERY }, options);
898
+ return data.packingSlipConfig;
899
+ },
900
+ async update(input, options) {
901
+ const data = await transport.graphql({ api: 'admin', query: UPDATE_PACKING_SLIP_CONFIG_MUTATION, variables: { input } }, options);
902
+ return data.updatePackingSlipConfig;
903
+ },
904
+ },
905
+ ar: createArDocumentsModule(transport),
494
906
  extensions: {
495
907
  async list(options) {
496
908
  const data = await transport.graphql({ api: 'admin', query: DOCUMENT_EXTENSIONS_QUERY }, options);
@@ -0,0 +1,2 @@
1
+ /** Decode the base64 a PDF-returning call answers with (`documents.previewInvoice`, `documents.ar.pdf`). */
2
+ export declare function decodePdf(base64: string): Uint8Array;
@@ -0,0 +1,11 @@
1
+ /** Decode the base64 a PDF-returning call answers with (`documents.previewInvoice`, `documents.ar.pdf`). */
2
+ export function decodePdf(base64) {
3
+ // Node and every modern runtime have `atob`; Buffer would tie this package
4
+ // to Node, and it ships to browsers as the dashboard's client.
5
+ const binary = atob(base64);
6
+ const bytes = new Uint8Array(binary.length);
7
+ for (let index = 0; index < binary.length; index += 1) {
8
+ bytes[index] = binary.charCodeAt(index);
9
+ }
10
+ return bytes;
11
+ }