@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
@@ -0,0 +1,307 @@
1
+ import { type Page, type Transport } from '@sixtyninecommerce/core';
2
+ import type { PaymentTerms } from '../customers/credit.js';
3
+ import type { Call, ListOptions } from '../types.js';
4
+ /**
5
+ * The documents of the store's accounts-receivable ledger (`admin.documents.ar`, headless
6
+ * W10-30): AR invoices and statements, AR credit notes, and the open invoices an ERP keeps for an
7
+ * ERP-linked customer. Correcting an AR invoice is `documents.planCorrection` /
8
+ * `commitCorrection` with `ledger: 'AR'`.
9
+ *
10
+ * Every write needs `UpdateOrder` and a store that keeps its AR ledger (else
11
+ * `AR_LEDGER_NOT_ENABLED`, → `BusinessRuleError`); every read `ReadOrder`. A customer the store
12
+ * does not hold is `CUSTOMER_NOT_FOUND` (→ `NotFoundError`). Money is in integer minor units of
13
+ * the document's own currency.
14
+ *
15
+ * **Keys.** `issueCreditNote`, `generateInvoice` and `generateStatement` take
16
+ * `options.idempotencyKey`: a repeat under the same key answers the first call's document instead
17
+ * of issuing another (a retry after a timeout draws no second number), and another request under
18
+ * the key is refused `IDEMPOTENCY_CONFLICT` (→ `ConflictError`, 409); one that arrives while the
19
+ * first still runs, `IDEMPOTENCY_IN_PROGRESS`. Without a key `issueCreditNote` is NOT
20
+ * de-duplicated: a double submit issues two credit notes.
21
+ */
22
+ /** One frozen line of an issued AR document, minor units. */
23
+ export interface ArDocumentLine {
24
+ description: string;
25
+ /** Empty for a free-form row. */
26
+ sku: string;
27
+ orderLineId: string | null;
28
+ quantity: number;
29
+ unitPriceNet: number;
30
+ unitPriceWithTax: number;
31
+ /** Percentage, may be fractional. */
32
+ taxRate: number;
33
+ lineTotalNet: number;
34
+ lineTotalWithTax: number;
35
+ /** `net` or `gross`: the side that is exact. */
36
+ unitPriceBasis: string;
37
+ }
38
+ export type ArInvoiceStatus = 'open' | 'partially_paid' | 'paid' | 'overdue' | 'voided';
39
+ /** An AR invoice or statement, with its settlement figures. */
40
+ export interface ArInvoice {
41
+ id: string;
42
+ invoiceNumber: string;
43
+ /** `platform`, or the ERP that numbered it. */
44
+ numberingProvider: string;
45
+ customerId: string;
46
+ issuedOn: string;
47
+ dueOn: string;
48
+ paymentTermsDays: number;
49
+ paymentTerms: (PaymentTerms & {
50
+ customerId: string | null;
51
+ }) | null;
52
+ currencyCode: string;
53
+ totalWithTax: number;
54
+ /** Payments allocated: money that arrived. */
55
+ allocatedAmount: number;
56
+ /** Partial credit notes: collectable reduced with no money in. */
57
+ creditedAmount: number;
58
+ /** Still collectable; 0 once voided. */
59
+ outstandingAmount: number;
60
+ status: ArInvoiceStatus;
61
+ notes: string | null;
62
+ hasPdf: boolean;
63
+ orderIds: string[];
64
+ voidedOn: string | null;
65
+ reversedByCreditNoteId: string | null;
66
+ supersededByInvoiceId: string | null;
67
+ reissueOfInvoiceId: string | null;
68
+ /** `standard` or `supplementary`. */
69
+ kind: string;
70
+ supplementsInvoiceId: string | null;
71
+ lines: ArDocumentLine[] | null;
72
+ /** SEPA direct debit: the day the debtor was told it would be collected. */
73
+ collectOn: string | null;
74
+ prenotifiedAt: string | null;
75
+ prenotifiedAmount: number | null;
76
+ createdAt: string;
77
+ updatedAt: string;
78
+ }
79
+ /** An AR credit note. */
80
+ export interface ArCreditNote {
81
+ id: string;
82
+ creditNoteNumber: string;
83
+ numberingProvider: string;
84
+ customerId: string;
85
+ issuedOn: string;
86
+ currencyCode: string;
87
+ amount: number;
88
+ reason: string;
89
+ orderId: string | null;
90
+ hasPdf: boolean;
91
+ /** `correction`, `cancellation`, `return` or `adjustment`. */
92
+ kind: string;
93
+ invoiceId: string | null;
94
+ reversalOfInvoiceId: string | null;
95
+ lines: ArDocumentLine[] | null;
96
+ refundId: string | null;
97
+ /** False only for the fiscal note of a refund that went back to a card. */
98
+ creditsAccount: boolean;
99
+ createdAt: string;
100
+ updatedAt: string;
101
+ }
102
+ /**
103
+ * An ERP-mirrored invoice's status, judged against today in the STORE's zone: `credit_note`
104
+ * (outstanding below zero), `overdue`, `partially_paid`, `open`. Never `paid`: the ERP drops a
105
+ * paid invoice.
106
+ */
107
+ export type ArExternalInvoiceStatus = 'credit_note' | 'overdue' | 'partially_paid' | 'open';
108
+ /** An open invoice the ERP keeps for an ERP-linked customer (a read-only mirror). */
109
+ export interface ArExternalInvoice {
110
+ id: string;
111
+ customerId: string;
112
+ /** The ERP, e.g. `afas`. */
113
+ source: string;
114
+ externalDebtorId: string;
115
+ externalInvoiceNumber: string;
116
+ issuedOn: string;
117
+ dueOn: string;
118
+ currencyCode: string;
119
+ totalWithTax: number;
120
+ /** Signed: below zero is a credit note. */
121
+ outstandingAmount: number;
122
+ description: string | null;
123
+ administrationUnit: number | null;
124
+ syncedAt: string;
125
+ status: ArExternalInvoiceStatus;
126
+ }
127
+ export interface ArExternalInvoiceSyncResult {
128
+ /** True when the ERP answered and the mirror was replaced. */
129
+ synced: boolean;
130
+ upserted: number;
131
+ removed: number;
132
+ /** Why nothing was synced (no provider, no ERP data, a read error); null when it was. */
133
+ skippedReason: string | null;
134
+ }
135
+ /** A filter on an AR document list: one customer, or the whole store. */
136
+ export interface ArDocumentListOptions extends ListOptions {
137
+ customerId?: string;
138
+ }
139
+ export interface IssueArCreditNoteInput {
140
+ customerId: string;
141
+ /** Minor units, above zero. */
142
+ amount: number;
143
+ reason: string;
144
+ /** The order it relates to; bounded by what that order's live invoices billed. */
145
+ orderId?: string | null;
146
+ /** `YYYY-MM-DD`; defaults to today in the store's zone. */
147
+ issuedOn?: string;
148
+ }
149
+ /** Explicit terms for an invoice: days, or an ERP condition code, never both. */
150
+ export interface ArInvoiceTermsInput {
151
+ paymentTermsDays?: number;
152
+ paymentConditionCode?: string;
153
+ /** `YYYY-MM-DD`; defaults to today in the store's zone. */
154
+ issuedOn?: string;
155
+ notes?: string | null;
156
+ }
157
+ export interface GenerateArInvoiceInput extends ArInvoiceTermsInput {
158
+ orderId: string;
159
+ }
160
+ export interface GenerateArStatementInput extends ArInvoiceTermsInput {
161
+ customerId: string;
162
+ /** The orders it bills, all in one currency (`customers.credit.invoiceableOrders`). */
163
+ orderIds: string[];
164
+ }
165
+ /** The displayed shape of the store's AR credit-note numbers. */
166
+ export interface ArCreditNoteNumbering {
167
+ prefix: string;
168
+ suffix: string;
169
+ /** 3 to 8. */
170
+ digits: number;
171
+ /** `none`, `short` or `full`. */
172
+ yearFormat: string;
173
+ yearReset: boolean;
174
+ }
175
+ export type UpdateArCreditNoteNumberingInput = Partial<ArCreditNoteNumbering>;
176
+ export interface ArCreditNoteNumberingModule {
177
+ /**
178
+ * The store's AR credit-note number format (created with defaults on first read).
179
+ *
180
+ * @effect read
181
+ * @permission ReadOrder
182
+ */
183
+ get(options?: Call): Promise<ArCreditNoteNumbering>;
184
+ /**
185
+ * Change the format. `digits` is clamped to 3..8; a `yearFormat` other than `none`, `short`
186
+ * or `full` is refused, as is a change that would make numbers repeat
187
+ * (`NUMBERING_RESTART_WOULD_REPEAT`). The counter itself never moves here.
188
+ *
189
+ * @effect write
190
+ * @permission UpdateOrder
191
+ */
192
+ set(input: UpdateArCreditNoteNumberingInput, options?: Call): Promise<ArCreditNoteNumbering>;
193
+ }
194
+ export interface ArDocumentsModule {
195
+ /**
196
+ * AR invoices and statements, newest first, one customer's or the store's, paged (`limit` up
197
+ * to 100). Voided ones are listed with `status: 'voided'`.
198
+ *
199
+ * @effect read
200
+ * @permission ReadOrder
201
+ */
202
+ invoices(options?: ArDocumentListOptions): Promise<Page<ArInvoice>>;
203
+ /**
204
+ * AR credit notes, newest first, one customer's or the store's, paged (`limit` up to 100).
205
+ *
206
+ * @effect read
207
+ * @permission ReadOrder
208
+ */
209
+ creditNotes(options?: ArDocumentListOptions): Promise<Page<ArCreditNote>>;
210
+ /**
211
+ * The open invoices the ERP keeps for an ERP-linked customer, as last mirrored, each with its
212
+ * status judged against the store's today. An engine older than `status` fails the
213
+ * document's validation.
214
+ *
215
+ * @effect read
216
+ * @permission ReadOrder
217
+ */
218
+ externalInvoices(customerId: string, options?: Call): Promise<ArExternalInvoice[]>;
219
+ /**
220
+ * Refresh a customer's ERP invoice mirror now. A skipped sync is an answer
221
+ * (`skippedReason`), not an error.
222
+ *
223
+ * @effect write
224
+ * @permission UpdateOrder
225
+ */
226
+ syncExternal(customerId: string, options?: Call): Promise<ArExternalInvoiceSyncResult>;
227
+ /**
228
+ * An AR invoice's or credit note's rendered PDF, or null when none is stored yet. A document
229
+ * of another store answers null.
230
+ *
231
+ * @effect read
232
+ * @permission ReadOrder
233
+ */
234
+ pdf(id: string, kind: 'invoice' | 'credit-note', options?: Call): Promise<Uint8Array | null>;
235
+ /**
236
+ * Issue a lump-sum AR credit note, posting a ledger credit that lowers the customer's balance.
237
+ * It draws a number (an ERP's, on a store whose ERP numbers credit notes). Pass
238
+ * `options.idempotencyKey`: without one a repeat issues a second note. With an `orderId` it is
239
+ * held to what that order's live invoices still bill (`AR_ORDER_CREDIT_EXCEEDS_BILLED`), and to
240
+ * what each of those invoices billed (`INVOICE_CREDIT_EXCEEDS_INVOICE`). Their sentence states
241
+ * money in the document's currency (an older engine stated minor units); their one `details`
242
+ * entry restates the figures in minor units.
243
+ *
244
+ * Refusals: `AR_LEDGER_NOT_ENABLED`, `CUSTOMER_NOT_FOUND`, `AR_CURRENCY_MISMATCH`,
245
+ * `ORDER_NOT_FOUND` (an order not in this store; `USER_INPUT_ERROR` on an older engine),
246
+ * `AR_INVOICE_CHANGED_CONFLICT` (the order's invoices were corrected while it waited: nothing was
247
+ * credited, issue it again; the key is released), and a field refusal (`USER_INPUT_ERROR`) for an
248
+ * amount or reason that is not one.
249
+ *
250
+ * @effect money
251
+ * @permission UpdateOrder
252
+ */
253
+ issueCreditNote(input: IssueArCreditNoteInput, options?: Call): Promise<ArCreditNote>;
254
+ /**
255
+ * Invoice one placed order on the AR ledger: draws an invoice number, debits the customer,
256
+ * and applies what was already collected on the order. A repeat under the same key answers
257
+ * the same invoice; without a key a repeat is refused (the order is invoiced already,
258
+ * `INVOICE_ISSUE_CONFLICT` → `ConflictError`; an older engine answered `USER_INPUT_ERROR` with the
259
+ * same sentence). Terms: the order's frozen ones, else the customer's, unless given here.
260
+ * Refused for an ERP-linked customer (`AR_ACCOUNT_IN_ERP`), when the terms state no single due
261
+ * date, for an order in a state no invoice is issued in (a draft, a cart, a cancelled order:
262
+ * `INVOICE_ORDER_STATE_BLOCKS_ISSUE`), and for an order a live STORE invoice bills
263
+ * (`INVOICE_LEDGER_CONFLICT` → `ConflictError`: an order is billed by one ledger; `details`
264
+ * names the order and the invoice). Nothing is numbered on a refusal. An engine before these
265
+ * two refusals ISSUED the AR invoice in both cases. Also refused, coded (each a
266
+ * `USER_INPUT_ERROR`, or for the terms an uncoded server error, on an older engine):
267
+ * `ORDER_NOT_FOUND`, `AR_ORDER_HAS_NO_CUSTOMER`, `AR_PAYMENT_TERMS_MISSING` (no terms resolve
268
+ * and none are given), `INVOICE_PAYMENT_TERMS_UNREPRESENTABLE` (the terms state no single due
269
+ * date), `PAYMENT_TERMS_NOT_ACCEPTED` (days given for a customer an ERP governs, or a condition
270
+ * for one whose terms are kept here), `PAYMENT_CONDITION_UNKNOWN`, `PAYMENT_CONDITION_UNUSABLE`
271
+ * and `PAYMENT_TERMS_UNRESOLVED` (the ERP's terms for the order are not known yet).
272
+ *
273
+ * @effect money
274
+ * @permission UpdateOrder
275
+ */
276
+ generateInvoice(input: GenerateArInvoiceInput, options?: Call): Promise<ArInvoice>;
277
+ /**
278
+ * One statement invoice over several of the customer's orders, all in one currency and on
279
+ * one payment rule. Keys and refusals as {@link generateInvoice}; `CUSTOMER_NOT_FOUND`,
280
+ * `AR_ORDER_CUSTOMER_MISMATCH` (an order of another customer), `AR_CURRENCY_MISMATCH` (orders
281
+ * in two currencies) and `AR_STATEMENT_TERMS_MISMATCH` (different payment rules). One
282
+ * refused order refuses the whole statement: nothing is billed in part, and
283
+ * `INVOICE_LEDGER_CONFLICT` names every order a store invoice bills.
284
+ *
285
+ * @effect money
286
+ * @permission UpdateOrder
287
+ */
288
+ generateStatement(input: GenerateArStatementInput, options?: Call): Promise<ArInvoice>;
289
+ creditNoteNumbering: ArCreditNoteNumberingModule;
290
+ }
291
+ export declare const AR_INVOICES_QUERY = "\n query ArInvoices($options: ArListOptions) {\n arInvoices(options: $options) {\n items { \n id\n invoiceNumber\n numberingProvider\n customerId\n issuedOn\n dueOn\n paymentTermsDays\n paymentTerms {\n customerId\n source\n managedExternally\n status\n conditionCode\n conditionDescription\n summary\n classification\n paymentDays\n paymentEndOfMonths\n paymentMethod\n percentage\n discountPaymentDays\n discountPercentage\n paymentDiscountType\n stale\n syncedAt\n error\n }\n currencyCode\n totalWithTax\n allocatedAmount\n creditedAmount\n outstandingAmount\n status\n notes\n hasPdf\n orderIds\n voidedOn\n reversedByCreditNoteId\n supersededByInvoiceId\n reissueOfInvoiceId\n kind\n supplementsInvoiceId\n lines { \n description\n sku\n orderLineId\n quantity\n unitPriceNet\n unitPriceWithTax\n taxRate\n lineTotalNet\n lineTotalWithTax\n unitPriceBasis\n }\n collectOn\n prenotifiedAt\n prenotifiedAmount\n createdAt\n updatedAt\n }\n totalItems\n }\n }\n";
292
+ export declare const AR_CREDIT_NOTES_QUERY = "\n query ArCreditNotes($options: ArListOptions) {\n arCreditNotes(options: $options) {\n items { \n id\n creditNoteNumber\n numberingProvider\n customerId\n issuedOn\n currencyCode\n amount\n reason\n orderId\n hasPdf\n kind\n invoiceId\n reversalOfInvoiceId\n lines { \n description\n sku\n orderLineId\n quantity\n unitPriceNet\n unitPriceWithTax\n taxRate\n lineTotalNet\n lineTotalWithTax\n unitPriceBasis\n }\n refundId\n creditsAccount\n createdAt\n updatedAt\n }\n totalItems\n }\n }\n";
293
+ export declare const AR_EXTERNAL_INVOICES_QUERY = "\n query ArExternalInvoices($customerId: ID!) {\n arExternalInvoices(customerId: $customerId) {\n items {\n id\n customerId\n source\n externalDebtorId\n externalInvoiceNumber\n issuedOn\n dueOn\n currencyCode\n totalWithTax\n outstandingAmount\n description\n administrationUnit\n syncedAt\n status\n }\n }\n }\n";
294
+ export declare const SYNC_EXTERNAL_INVOICES_MUTATION = "\n mutation SyncExternalInvoices($customerId: ID!) {\n syncExternalInvoices(customerId: $customerId) {\n synced\n upserted\n removed\n skippedReason\n }\n }\n";
295
+ export declare const AR_INVOICE_PDF_QUERY = "\n query ArInvoicePdf($id: ID!) {\n arInvoicePdf(id: $id)\n }\n";
296
+ export declare const AR_CREDIT_NOTE_PDF_QUERY = "\n query ArCreditNotePdf($id: ID!) {\n arCreditNotePdf(id: $id)\n }\n";
297
+ export declare const ISSUE_AR_CREDIT_NOTE_MUTATION = "\n mutation IssueArCreditNote($input: IssueArCreditNoteInput!, $idempotencyKey: String) {\n issueArCreditNote(input: $input, idempotencyKey: $idempotencyKey) { \n id\n creditNoteNumber\n numberingProvider\n customerId\n issuedOn\n currencyCode\n amount\n reason\n orderId\n hasPdf\n kind\n invoiceId\n reversalOfInvoiceId\n lines { \n description\n sku\n orderLineId\n quantity\n unitPriceNet\n unitPriceWithTax\n taxRate\n lineTotalNet\n lineTotalWithTax\n unitPriceBasis\n }\n refundId\n creditsAccount\n createdAt\n updatedAt\n }\n }\n";
298
+ export declare const GENERATE_AR_INVOICE_MUTATION = "\n mutation GenerateArInvoice($input: GenerateArInvoiceInput!, $idempotencyKey: String) {\n generateArInvoice(input: $input, idempotencyKey: $idempotencyKey) { \n id\n invoiceNumber\n numberingProvider\n customerId\n issuedOn\n dueOn\n paymentTermsDays\n paymentTerms {\n customerId\n source\n managedExternally\n status\n conditionCode\n conditionDescription\n summary\n classification\n paymentDays\n paymentEndOfMonths\n paymentMethod\n percentage\n discountPaymentDays\n discountPercentage\n paymentDiscountType\n stale\n syncedAt\n error\n }\n currencyCode\n totalWithTax\n allocatedAmount\n creditedAmount\n outstandingAmount\n status\n notes\n hasPdf\n orderIds\n voidedOn\n reversedByCreditNoteId\n supersededByInvoiceId\n reissueOfInvoiceId\n kind\n supplementsInvoiceId\n lines { \n description\n sku\n orderLineId\n quantity\n unitPriceNet\n unitPriceWithTax\n taxRate\n lineTotalNet\n lineTotalWithTax\n unitPriceBasis\n }\n collectOn\n prenotifiedAt\n prenotifiedAmount\n createdAt\n updatedAt\n }\n }\n";
299
+ export declare const GENERATE_AR_STATEMENT_MUTATION = "\n mutation GenerateArStatement($input: GenerateArStatementInput!, $idempotencyKey: String) {\n generateArStatement(input: $input, idempotencyKey: $idempotencyKey) { \n id\n invoiceNumber\n numberingProvider\n customerId\n issuedOn\n dueOn\n paymentTermsDays\n paymentTerms {\n customerId\n source\n managedExternally\n status\n conditionCode\n conditionDescription\n summary\n classification\n paymentDays\n paymentEndOfMonths\n paymentMethod\n percentage\n discountPaymentDays\n discountPercentage\n paymentDiscountType\n stale\n syncedAt\n error\n }\n currencyCode\n totalWithTax\n allocatedAmount\n creditedAmount\n outstandingAmount\n status\n notes\n hasPdf\n orderIds\n voidedOn\n reversedByCreditNoteId\n supersededByInvoiceId\n reissueOfInvoiceId\n kind\n supplementsInvoiceId\n lines { \n description\n sku\n orderLineId\n quantity\n unitPriceNet\n unitPriceWithTax\n taxRate\n lineTotalNet\n lineTotalWithTax\n unitPriceBasis\n }\n collectOn\n prenotifiedAt\n prenotifiedAmount\n createdAt\n updatedAt\n }\n }\n";
300
+ export declare const AR_CREDIT_NOTE_NUMBERING_QUERY = "\n query CreditNoteNumberingConfig {\n creditNoteNumberingConfig { \n prefix\n suffix\n digits\n yearFormat\n yearReset\n }\n }\n";
301
+ export declare const UPDATE_AR_CREDIT_NOTE_NUMBERING_MUTATION = "\n mutation UpdateCreditNoteNumberingConfig($input: UpdateCreditNoteNumberingConfigInput!) {\n updateCreditNoteNumberingConfig(input: $input) { \n prefix\n suffix\n digits\n yearFormat\n yearReset\n }\n }\n";
302
+ /** `ListOptions` → the engine's offset page (the offset hides inside the cursor, spec §9.3). */
303
+ export declare function arPageWindow(options?: ListOptions): {
304
+ skip: number;
305
+ take: number;
306
+ };
307
+ export declare function createArDocumentsModule(transport: Transport): ArDocumentsModule;
@@ -0,0 +1,254 @@
1
+ import { pageFromVendureList, readOffsetCursor, } from '@sixtyninecommerce/core';
2
+ import { decodePdf } from './pdf.js';
3
+ const DOCUMENT_LINE_FIELDS = /* GraphQL */ `
4
+ description
5
+ sku
6
+ orderLineId
7
+ quantity
8
+ unitPriceNet
9
+ unitPriceWithTax
10
+ taxRate
11
+ lineTotalNet
12
+ lineTotalWithTax
13
+ unitPriceBasis
14
+ `;
15
+ const AR_INVOICE_FIELDS = /* GraphQL */ `
16
+ id
17
+ invoiceNumber
18
+ numberingProvider
19
+ customerId
20
+ issuedOn
21
+ dueOn
22
+ paymentTermsDays
23
+ paymentTerms {
24
+ customerId
25
+ source
26
+ managedExternally
27
+ status
28
+ conditionCode
29
+ conditionDescription
30
+ summary
31
+ classification
32
+ paymentDays
33
+ paymentEndOfMonths
34
+ paymentMethod
35
+ percentage
36
+ discountPaymentDays
37
+ discountPercentage
38
+ paymentDiscountType
39
+ stale
40
+ syncedAt
41
+ error
42
+ }
43
+ currencyCode
44
+ totalWithTax
45
+ allocatedAmount
46
+ creditedAmount
47
+ outstandingAmount
48
+ status
49
+ notes
50
+ hasPdf
51
+ orderIds
52
+ voidedOn
53
+ reversedByCreditNoteId
54
+ supersededByInvoiceId
55
+ reissueOfInvoiceId
56
+ kind
57
+ supplementsInvoiceId
58
+ lines { ${DOCUMENT_LINE_FIELDS} }
59
+ collectOn
60
+ prenotifiedAt
61
+ prenotifiedAmount
62
+ createdAt
63
+ updatedAt
64
+ `;
65
+ const AR_CREDIT_NOTE_FIELDS = /* GraphQL */ `
66
+ id
67
+ creditNoteNumber
68
+ numberingProvider
69
+ customerId
70
+ issuedOn
71
+ currencyCode
72
+ amount
73
+ reason
74
+ orderId
75
+ hasPdf
76
+ kind
77
+ invoiceId
78
+ reversalOfInvoiceId
79
+ lines { ${DOCUMENT_LINE_FIELDS} }
80
+ refundId
81
+ creditsAccount
82
+ createdAt
83
+ updatedAt
84
+ `;
85
+ const NUMBERING_FIELDS = /* GraphQL */ `
86
+ prefix
87
+ suffix
88
+ digits
89
+ yearFormat
90
+ yearReset
91
+ `;
92
+ export const AR_INVOICES_QUERY = /* GraphQL */ `
93
+ query ArInvoices($options: ArListOptions) {
94
+ arInvoices(options: $options) {
95
+ items { ${AR_INVOICE_FIELDS} }
96
+ totalItems
97
+ }
98
+ }
99
+ `;
100
+ export const AR_CREDIT_NOTES_QUERY = /* GraphQL */ `
101
+ query ArCreditNotes($options: ArListOptions) {
102
+ arCreditNotes(options: $options) {
103
+ items { ${AR_CREDIT_NOTE_FIELDS} }
104
+ totalItems
105
+ }
106
+ }
107
+ `;
108
+ export const AR_EXTERNAL_INVOICES_QUERY = /* GraphQL */ `
109
+ query ArExternalInvoices($customerId: ID!) {
110
+ arExternalInvoices(customerId: $customerId) {
111
+ items {
112
+ id
113
+ customerId
114
+ source
115
+ externalDebtorId
116
+ externalInvoiceNumber
117
+ issuedOn
118
+ dueOn
119
+ currencyCode
120
+ totalWithTax
121
+ outstandingAmount
122
+ description
123
+ administrationUnit
124
+ syncedAt
125
+ status
126
+ }
127
+ }
128
+ }
129
+ `;
130
+ export const SYNC_EXTERNAL_INVOICES_MUTATION = /* GraphQL */ `
131
+ mutation SyncExternalInvoices($customerId: ID!) {
132
+ syncExternalInvoices(customerId: $customerId) {
133
+ synced
134
+ upserted
135
+ removed
136
+ skippedReason
137
+ }
138
+ }
139
+ `;
140
+ export const AR_INVOICE_PDF_QUERY = /* GraphQL */ `
141
+ query ArInvoicePdf($id: ID!) {
142
+ arInvoicePdf(id: $id)
143
+ }
144
+ `;
145
+ export const AR_CREDIT_NOTE_PDF_QUERY = /* GraphQL */ `
146
+ query ArCreditNotePdf($id: ID!) {
147
+ arCreditNotePdf(id: $id)
148
+ }
149
+ `;
150
+ export const ISSUE_AR_CREDIT_NOTE_MUTATION = /* GraphQL */ `
151
+ mutation IssueArCreditNote($input: IssueArCreditNoteInput!, $idempotencyKey: String) {
152
+ issueArCreditNote(input: $input, idempotencyKey: $idempotencyKey) { ${AR_CREDIT_NOTE_FIELDS} }
153
+ }
154
+ `;
155
+ export const GENERATE_AR_INVOICE_MUTATION = /* GraphQL */ `
156
+ mutation GenerateArInvoice($input: GenerateArInvoiceInput!, $idempotencyKey: String) {
157
+ generateArInvoice(input: $input, idempotencyKey: $idempotencyKey) { ${AR_INVOICE_FIELDS} }
158
+ }
159
+ `;
160
+ export const GENERATE_AR_STATEMENT_MUTATION = /* GraphQL */ `
161
+ mutation GenerateArStatement($input: GenerateArStatementInput!, $idempotencyKey: String) {
162
+ generateArStatement(input: $input, idempotencyKey: $idempotencyKey) { ${AR_INVOICE_FIELDS} }
163
+ }
164
+ `;
165
+ export const AR_CREDIT_NOTE_NUMBERING_QUERY = /* GraphQL */ `
166
+ query CreditNoteNumberingConfig {
167
+ creditNoteNumberingConfig { ${NUMBERING_FIELDS} }
168
+ }
169
+ `;
170
+ export const UPDATE_AR_CREDIT_NOTE_NUMBERING_MUTATION = /* GraphQL */ `
171
+ mutation UpdateCreditNoteNumberingConfig($input: UpdateCreditNoteNumberingConfigInput!) {
172
+ updateCreditNoteNumberingConfig(input: $input) { ${NUMBERING_FIELDS} }
173
+ }
174
+ `;
175
+ const AR_PAGE_LIMIT = 100;
176
+ const AR_PAGE_SIZE = 25;
177
+ /** `ListOptions` → the engine's offset page (the offset hides inside the cursor, spec §9.3). */
178
+ export function arPageWindow(options) {
179
+ return {
180
+ take: Math.min(options?.limit ?? AR_PAGE_SIZE, AR_PAGE_LIMIT),
181
+ skip: options?.after === undefined ? 0 : readOffsetCursor(options.after),
182
+ };
183
+ }
184
+ /** `undefined`, never null: `JSON.stringify` drops it, so an omitted key stays off the wire. */
185
+ const keyOf = (options) => options?.idempotencyKey;
186
+ export function createArDocumentsModule(transport) {
187
+ const listPage = async (query, field, customerId, skip, take, options) => {
188
+ const data = await transport.graphql({ api: 'admin', query, variables: { options: { customerId, skip, take } } }, options);
189
+ const list = data[field];
190
+ if (!list)
191
+ throw new Error(`The engine answered no ${field}`);
192
+ return pageFromVendureList(list, skip, take, (cursor) => listPage(query, field, customerId, readOffsetCursor(cursor), take, options));
193
+ };
194
+ return {
195
+ invoices(options) {
196
+ const { skip, take } = arPageWindow(options);
197
+ return listPage(AR_INVOICES_QUERY, 'arInvoices', options?.customerId, skip, take, options);
198
+ },
199
+ creditNotes(options) {
200
+ const { skip, take } = arPageWindow(options);
201
+ return listPage(AR_CREDIT_NOTES_QUERY, 'arCreditNotes', options?.customerId, skip, take, options);
202
+ },
203
+ async externalInvoices(customerId, options) {
204
+ const data = await transport.graphql({ api: 'admin', query: AR_EXTERNAL_INVOICES_QUERY, variables: { customerId } }, options);
205
+ return data.arExternalInvoices.items;
206
+ },
207
+ async syncExternal(customerId, options) {
208
+ const data = await transport.graphql({ api: 'admin', query: SYNC_EXTERNAL_INVOICES_MUTATION, variables: { customerId } }, options);
209
+ return data.syncExternalInvoices;
210
+ },
211
+ async pdf(id, kind, options) {
212
+ if (kind === 'invoice') {
213
+ const data = await transport.graphql({ api: 'admin', query: AR_INVOICE_PDF_QUERY, variables: { id } }, options);
214
+ return data.arInvoicePdf === null ? null : decodePdf(data.arInvoicePdf);
215
+ }
216
+ const data = await transport.graphql({ api: 'admin', query: AR_CREDIT_NOTE_PDF_QUERY, variables: { id } }, options);
217
+ return data.arCreditNotePdf === null ? null : decodePdf(data.arCreditNotePdf);
218
+ },
219
+ async issueCreditNote(input, options) {
220
+ const data = await transport.graphql({
221
+ api: 'admin',
222
+ query: ISSUE_AR_CREDIT_NOTE_MUTATION,
223
+ variables: { input, idempotencyKey: keyOf(options) },
224
+ }, options);
225
+ return data.issueArCreditNote;
226
+ },
227
+ async generateInvoice(input, options) {
228
+ const data = await transport.graphql({
229
+ api: 'admin',
230
+ query: GENERATE_AR_INVOICE_MUTATION,
231
+ variables: { input, idempotencyKey: keyOf(options) },
232
+ }, options);
233
+ return data.generateArInvoice;
234
+ },
235
+ async generateStatement(input, options) {
236
+ const data = await transport.graphql({
237
+ api: 'admin',
238
+ query: GENERATE_AR_STATEMENT_MUTATION,
239
+ variables: { input, idempotencyKey: keyOf(options) },
240
+ }, options);
241
+ return data.generateArStatement;
242
+ },
243
+ creditNoteNumbering: {
244
+ async get(options) {
245
+ const data = await transport.graphql({ api: 'admin', query: AR_CREDIT_NOTE_NUMBERING_QUERY }, options);
246
+ return data.creditNoteNumberingConfig;
247
+ },
248
+ async set(input, options) {
249
+ const data = await transport.graphql({ api: 'admin', query: UPDATE_AR_CREDIT_NOTE_NUMBERING_MUTATION, variables: { input } }, options);
250
+ return data.updateCreditNoteNumberingConfig;
251
+ },
252
+ },
253
+ };
254
+ }