@sixtyninecommerce/admin 0.10.0 → 0.12.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.
- package/README.md +5772 -118
- package/dist/auth/index.d.ts +7 -1
- package/dist/auth/index.js +8 -1
- package/dist/catalog/assets.d.ts +120 -8
- package/dist/catalog/assets.js +98 -12
- package/dist/catalog/collections.d.ts +279 -14
- package/dist/catalog/collections.js +246 -15
- package/dist/catalog/documents.d.ts +142 -0
- package/dist/catalog/documents.js +114 -0
- package/dist/catalog/index.d.ts +54 -6
- package/dist/catalog/index.js +10 -1
- package/dist/catalog/metadata.d.ts +244 -0
- package/dist/catalog/metadata.js +220 -0
- package/dist/catalog/products.d.ts +159 -19
- package/dist/catalog/products.js +88 -13
- package/dist/catalog/properties.d.ts +140 -14
- package/dist/catalog/properties.js +65 -1
- package/dist/catalog/recommendations.d.ts +288 -0
- package/dist/catalog/recommendations.js +237 -0
- package/dist/catalog/reviews.d.ts +381 -0
- package/dist/catalog/reviews.js +325 -0
- package/dist/catalog/types.d.ts +17 -1
- package/dist/catalog/types.js +10 -0
- package/dist/catalog/variant-find.d.ts +136 -0
- package/dist/catalog/variant-find.js +239 -0
- package/dist/catalog/variants.d.ts +293 -26
- package/dist/catalog/variants.js +164 -7
- package/dist/catalog/visibility.d.ts +38 -7
- package/dist/catalog/visibility.js +19 -1
- package/dist/client.d.ts +121 -9
- package/dist/client.js +53 -14
- package/dist/content/assets.d.ts +285 -0
- package/dist/content/assets.js +181 -0
- package/dist/content/forms.d.ts +332 -1
- package/dist/content/forms.js +140 -4
- package/dist/content/items.d.ts +292 -0
- package/dist/content/items.js +170 -0
- package/dist/content/menus.d.ts +254 -0
- package/dist/content/menus.js +70 -0
- package/dist/content/strings.d.ts +137 -0
- package/dist/content/strings.js +82 -0
- package/dist/content/types.d.ts +282 -0
- package/dist/content/types.js +100 -0
- package/dist/customers/age-verification.d.ts +66 -0
- package/dist/customers/age-verification.js +79 -0
- package/dist/customers/credit.d.ts +263 -0
- package/dist/customers/credit.js +244 -0
- package/dist/customers/delivery-preferences.d.ts +120 -0
- package/dist/customers/delivery-preferences.js +97 -0
- package/dist/customers/delivery-terms.d.ts +44 -0
- package/dist/customers/delivery-terms.js +32 -0
- package/dist/customers/groups.d.ts +207 -0
- package/dist/customers/groups.js +438 -0
- package/dist/customers/index.d.ts +462 -37
- package/dist/customers/index.js +317 -40
- package/dist/customers/invitation-status.d.ts +57 -0
- package/dist/customers/invitation-status.js +21 -0
- package/dist/customers/notes.d.ts +67 -0
- package/dist/customers/notes.js +51 -0
- package/dist/customers/notification-recipients.d.ts +97 -0
- package/dist/customers/notification-recipients.js +84 -0
- package/dist/customers/saved-lists.d.ts +42 -0
- package/dist/customers/saved-lists.js +61 -0
- package/dist/customers/vat.d.ts +83 -0
- package/dist/customers/vat.js +46 -0
- package/dist/customers/wire.d.ts +20 -0
- package/dist/customers/wire.js +35 -0
- package/dist/documents/ar.d.ts +307 -0
- package/dist/documents/ar.js +254 -0
- package/dist/documents/emails.d.ts +150 -0
- package/dist/documents/emails.js +220 -0
- package/dist/documents/index.d.ts +744 -21
- package/dist/documents/index.js +438 -24
- package/dist/documents/pdf.d.ts +2 -0
- package/dist/documents/pdf.js +11 -0
- package/dist/fulfillments/create.d.ts +167 -0
- package/dist/fulfillments/create.js +216 -0
- package/dist/fulfillments/index.d.ts +163 -11
- package/dist/fulfillments/index.js +135 -6
- package/dist/fulfillments/payment-policy.d.ts +64 -0
- package/dist/fulfillments/payment-policy.js +140 -0
- package/dist/fulfillments/warehouse.d.ts +724 -0
- package/dist/fulfillments/warehouse.js +914 -0
- package/dist/geo/index.d.ts +119 -0
- package/dist/geo/index.js +107 -0
- package/dist/index.d.ts +147 -39
- package/dist/index.js +51 -12
- package/dist/integrations/afas-actions.d.ts +234 -0
- package/dist/integrations/afas-actions.js +310 -0
- package/dist/integrations/afas-types.d.ts +483 -0
- package/dist/integrations/afas-types.js +5 -0
- package/dist/integrations/afas.d.ts +234 -0
- package/dist/integrations/afas.js +290 -0
- package/dist/integrations/connections.d.ts +103 -0
- package/dist/integrations/connections.js +55 -0
- package/dist/integrations/esp.d.ts +313 -0
- package/dist/integrations/esp.js +169 -0
- package/dist/integrations/exact-online-types.d.ts +965 -0
- package/dist/integrations/exact-online-types.js +6 -0
- package/dist/integrations/exact-online.d.ts +784 -0
- package/dist/integrations/exact-online.js +1089 -0
- package/dist/integrations/index.d.ts +44 -3
- package/dist/integrations/index.js +23 -3
- package/dist/integrations/pipeline-discoveries.d.ts +65 -0
- package/dist/integrations/pipeline-discoveries.js +65 -0
- package/dist/integrations/pipeline-keys.d.ts +13 -0
- package/dist/integrations/pipeline-keys.js +22 -0
- package/dist/integrations/pipeline-runs.d.ts +119 -0
- package/dist/integrations/pipeline-runs.js +87 -0
- package/dist/integrations/pipelines.d.ts +87 -15
- package/dist/integrations/pipelines.js +41 -22
- package/dist/integrations/price-import.d.ts +223 -0
- package/dist/integrations/price-import.js +124 -0
- package/dist/integrations/types.d.ts +367 -3
- package/dist/integrations/types.js +4 -3
- package/dist/locations/index.d.ts +66 -0
- package/dist/locations/index.js +31 -0
- package/dist/meta/index.d.ts +172 -0
- package/dist/metafields/index.d.ts +8 -1
- package/dist/metafields/index.js +10 -0
- package/dist/orders/cancel-with-money.d.ts +237 -0
- package/dist/orders/cancel-with-money.js +155 -0
- package/dist/orders/commit-edit.d.ts +23 -1
- package/dist/orders/commit-edit.js +19 -2
- package/dist/orders/deposit-policy.d.ts +3 -1
- package/dist/orders/drafts.d.ts +800 -0
- package/dist/orders/drafts.js +771 -0
- package/dist/orders/fields.d.ts +245 -0
- package/dist/orders/fields.js +188 -0
- package/dist/orders/get.d.ts +29 -19
- package/dist/orders/get.js +17 -8
- package/dist/orders/index.d.ts +66 -15
- package/dist/orders/index.js +25 -2
- package/dist/orders/lifecycle.d.ts +128 -0
- package/dist/orders/lifecycle.js +158 -0
- package/dist/orders/line-price-preview.d.ts +7 -2
- package/dist/orders/list.d.ts +243 -0
- package/dist/orders/list.js +487 -0
- package/dist/orders/manual-discounts.d.ts +13 -5
- package/dist/orders/manual-pricing.d.ts +5 -0
- package/dist/orders/money-view.d.ts +149 -0
- package/dist/orders/money-view.js +99 -0
- package/dist/orders/order-entry.d.ts +20 -7
- package/dist/orders/plan-edit.d.ts +34 -2
- package/dist/orders/plan-edit.js +112 -11
- package/dist/orders/settings.d.ts +201 -0
- package/dist/orders/settings.js +325 -0
- package/dist/orders/status.d.ts +159 -13
- package/dist/orders/status.js +21 -0
- package/dist/orders/surcharges.d.ts +20 -1
- package/dist/orders/surcharges.js +37 -11
- package/dist/payments/account-credit.d.ts +46 -0
- package/dist/payments/account-credit.js +42 -0
- package/dist/payments/ar.d.ts +292 -0
- package/dist/payments/ar.js +223 -0
- package/dist/payments/connected-account.d.ts +47 -0
- package/dist/payments/connected-account.js +61 -0
- package/dist/payments/credit-noted-fields.d.ts +19 -0
- package/dist/payments/credit-noted-fields.js +69 -0
- package/dist/payments/customer-consent.d.ts +30 -0
- package/dist/payments/customer-consent.js +49 -0
- package/dist/payments/index.d.ts +340 -19
- package/dist/payments/index.js +151 -1
- package/dist/payments/methods.d.ts +303 -8
- package/dist/payments/methods.js +337 -7
- package/dist/payments/mollie-methods.d.ts +159 -0
- package/dist/payments/mollie-methods.js +141 -0
- package/dist/payments/payment-links.d.ts +180 -0
- package/dist/payments/payment-links.js +97 -0
- package/dist/payments/provider-keys.d.ts +150 -0
- package/dist/payments/provider-keys.js +118 -0
- package/dist/payments/providers.d.ts +86 -11
- package/dist/payments/providers.js +29 -0
- package/dist/payments/requests.d.ts +147 -0
- package/dist/payments/requests.js +93 -0
- package/dist/payments/store-credit-fields.d.ts +15 -0
- package/dist/payments/store-credit-fields.js +51 -0
- package/dist/pickups/index.d.ts +106 -0
- package/dist/pickups/index.js +108 -0
- package/dist/platform/channels.d.ts +132 -0
- package/dist/platform/channels.js +128 -0
- package/dist/platform/email-gateways.d.ts +165 -0
- package/dist/platform/email-gateways.js +78 -0
- package/dist/platform/geo.d.ts +123 -0
- package/dist/platform/geo.js +144 -0
- package/dist/platform/tax.d.ts +162 -0
- package/dist/platform/tax.js +169 -0
- package/dist/pos/anomalies.d.ts +158 -0
- package/dist/pos/anomalies.js +64 -0
- package/dist/pos/assisted-selling.d.ts +79 -0
- package/dist/pos/assisted-selling.js +38 -0
- package/dist/pos/exchanges.d.ts +108 -0
- package/dist/pos/exchanges.js +22 -0
- package/dist/pos/gift-cards.d.ts +135 -0
- package/dist/pos/gift-cards.js +47 -0
- package/dist/pos/index.d.ts +2370 -58
- package/dist/pos/index.js +854 -7
- package/dist/pos/no-receipt.d.ts +94 -0
- package/dist/pos/no-receipt.js +25 -0
- package/dist/pos/offline-sales.d.ts +228 -0
- package/dist/pos/offline-sales.js +170 -0
- package/dist/pos/pay-by-link.d.ts +143 -0
- package/dist/pos/pay-by-link.js +57 -0
- package/dist/pos/quick-keys.d.ts +103 -0
- package/dist/pos/quick-keys.js +45 -0
- package/dist/pos/reports.d.ts +360 -0
- package/dist/pos/reports.js +62 -0
- package/dist/pos/returns.d.ts +244 -0
- package/dist/pos/returns.js +83 -0
- package/dist/pricing/bulk-coupons.d.ts +139 -0
- package/dist/pricing/bulk-coupons.js +112 -0
- package/dist/pricing/index.d.ts +174 -4
- package/dist/pricing/index.js +174 -1
- package/dist/pricing/price-lists.d.ts +606 -0
- package/dist/pricing/price-lists.js +600 -0
- package/dist/purchasing/alerts.d.ts +104 -0
- package/dist/purchasing/alerts.js +88 -0
- package/dist/purchasing/backorders.d.ts +61 -0
- package/dist/purchasing/backorders.js +92 -0
- package/dist/purchasing/cost.d.ts +110 -0
- package/dist/purchasing/cost.js +86 -0
- package/dist/purchasing/index.d.ts +54 -0
- package/dist/purchasing/index.js +24 -0
- package/dist/purchasing/links.d.ts +263 -0
- package/dist/purchasing/links.js +192 -0
- package/dist/purchasing/purchase-orders.d.ts +551 -0
- package/dist/purchasing/purchase-orders.js +491 -0
- package/dist/purchasing/receipts.d.ts +396 -0
- package/dist/purchasing/receipts.js +287 -0
- package/dist/purchasing/replenishment.d.ts +281 -0
- package/dist/purchasing/replenishment.js +240 -0
- package/dist/purchasing/returns.d.ts +273 -0
- package/dist/purchasing/returns.js +229 -0
- package/dist/purchasing/settings.d.ts +152 -0
- package/dist/purchasing/settings.js +181 -0
- package/dist/purchasing/suppliers.d.ts +476 -0
- package/dist/purchasing/suppliers.js +438 -0
- package/dist/quotes/index.d.ts +518 -0
- package/dist/quotes/index.js +439 -0
- package/dist/reports/index.d.ts +71 -8
- package/dist/reports/index.js +74 -11
- package/dist/returns/index.d.ts +675 -21
- package/dist/returns/index.js +756 -11
- package/dist/search/index.d.ts +76 -1
- package/dist/search/index.js +63 -0
- package/dist/seo/config.d.ts +128 -0
- package/dist/seo/config.js +95 -0
- package/dist/seo/redirects.d.ts +125 -0
- package/dist/seo/redirects.js +60 -1
- package/dist/seo/settings.d.ts +147 -0
- package/dist/seo/settings.js +209 -0
- package/dist/shipping/definitions.d.ts +29 -0
- package/dist/shipping/definitions.js +47 -0
- package/dist/shipping/fulfillment-profiles.d.ts +174 -0
- package/dist/shipping/fulfillment-profiles.js +104 -0
- package/dist/shipping/hendriks.d.ts +97 -0
- package/dist/shipping/hendriks.js +50 -0
- package/dist/shipping/index.d.ts +54 -0
- package/dist/shipping/index.js +27 -0
- package/dist/shipping/methods.d.ts +205 -0
- package/dist/shipping/methods.js +240 -0
- package/dist/shipping/myparcel.d.ts +668 -0
- package/dist/shipping/myparcel.js +466 -0
- package/dist/shipping/parcel-count-suggestion.d.ts +2 -0
- package/dist/shipping/parcel-rule.d.ts +6 -5
- package/dist/shipping/parcel-rule.js +21 -23
- package/dist/shipping/rate-tables.d.ts +324 -0
- package/dist/shipping/rate-tables.js +390 -0
- package/dist/shipping/ship-to-countries.d.ts +75 -0
- package/dist/shipping/ship-to-countries.js +47 -0
- package/dist/stock/by-location.d.ts +86 -0
- package/dist/stock/by-location.js +94 -0
- package/dist/stock/index.d.ts +18 -4
- package/dist/stock/index.js +7 -0
- package/dist/stock/locations.d.ts +144 -0
- package/dist/stock/locations.js +168 -0
- package/dist/stock/settings.d.ts +106 -0
- package/dist/stock/settings.js +103 -0
- package/dist/stock/transfers.d.ts +386 -52
- package/dist/stock/transfers.js +222 -17
- package/dist/stored-value/index.d.ts +312 -11
- package/dist/stored-value/index.js +223 -4
- package/dist/subscriptions/index.d.ts +682 -0
- package/dist/subscriptions/index.js +815 -0
- package/dist/tax/display-policy.d.ts +105 -0
- package/dist/tax/display-policy.js +84 -0
- package/dist/tax/index.d.ts +79 -1
- package/dist/tax/index.js +52 -0
- package/dist/tenant/email-style.d.ts +102 -0
- package/dist/tenant/email-style.js +72 -0
- package/dist/tenant/email-templates.d.ts +287 -0
- package/dist/tenant/email-templates.js +271 -0
- package/dist/tenant/notifications.d.ts +23 -17
- package/dist/tenant/settings-sources.d.ts +1 -1
- package/dist/tenant/time-zone.d.ts +17 -0
- package/dist/tenant/time-zone.js +11 -0
- package/dist/types.d.ts +50 -3
- package/dist/users/index.d.ts +3 -0
- package/dist/users/index.js +2 -0
- package/dist/users/warehouses.d.ts +50 -0
- package/dist/users/warehouses.js +51 -0
- package/package.json +2 -2
|
@@ -0,0 +1,234 @@
|
|
|
1
|
+
import { type Page, type Transport } from '@sixtyninecommerce/core';
|
|
2
|
+
import type { Call } from '../types.js';
|
|
3
|
+
import type { AfasAddressPreview, AfasCustomerBalance, AfasCustomerPreview, AfasCustomerSearchFilter, AfasDebtorLink, AfasDirectInvoiceResult, AfasOrderPreview, AfasOrderState, AfasPushResult, AfasSettleResult, AfasStockTransferInvoiceResult, AfasStockTransferState, CreateAfasDirectInvoiceInput, CreateAfasStockTransferInvoiceInput, SyncAfasCustomerInput, SyncAfasOrderInput } from './afas-types.js';
|
|
4
|
+
/** The most debtors `customers.search` asks AFAS for; the default is 10. */
|
|
5
|
+
export declare const AFAS_CUSTOMER_SEARCH_LIMIT = 50;
|
|
6
|
+
/**
|
|
7
|
+
* An order's AFAS documents (`admin.integrations.afas.orders`). AFAS keeps every document the
|
|
8
|
+
* platform writes into the store's administration: nothing here can be undone from the
|
|
9
|
+
* platform, only in AFAS by the store's accountant.
|
|
10
|
+
*
|
|
11
|
+
* Every method refuses an order the store does not hold with `ENTITY_NOT_FOUND`
|
|
12
|
+
* (`NotFoundError`, 404), and a store whose AFAS is not saved and switched on with
|
|
13
|
+
* `AFAS_NOT_CONFIGURED` (`BusinessRuleError`, 422).
|
|
14
|
+
*/
|
|
15
|
+
export interface AfasOrdersModule {
|
|
16
|
+
/**
|
|
17
|
+
* The AFAS sales order the order was pushed as, read live from AFAS; `null` when it was not
|
|
18
|
+
* pushed as one, or AFAS answered nothing.
|
|
19
|
+
*
|
|
20
|
+
* @effect read
|
|
21
|
+
* @permission UpdateOrder
|
|
22
|
+
*/
|
|
23
|
+
preview(orderId: string, options?: Call): Promise<AfasOrderPreview | null>;
|
|
24
|
+
/**
|
|
25
|
+
* The order's AFAS state, read from the platform (no AFAS call): which path it is on, what
|
|
26
|
+
* AFAS answered, and whether its state lets it be pushed (`stateAllowsPush`,
|
|
27
|
+
* `stateAllowsPrepaidSettlement`), so a screen offers only what the engine accepts.
|
|
28
|
+
*
|
|
29
|
+
* @effect read
|
|
30
|
+
* @permission ReadOrder
|
|
31
|
+
*/
|
|
32
|
+
state(orderId: string, options?: Call): Promise<AfasOrderState>;
|
|
33
|
+
/**
|
|
34
|
+
* Push the order to AFAS as a sales order (`FbSales`), with its customer: an unlinked
|
|
35
|
+
* customer is linked to `customerAfasVrId`, or created as a new AFAS debtor when it is `null`.
|
|
36
|
+
* This writes into the store's AFAS administration and cannot be undone from the platform.
|
|
37
|
+
*
|
|
38
|
+
* Refused, with nothing sent to AFAS:
|
|
39
|
+
* - `AFAS_ORDER_STATE_BLOCKS_PUSH` (`BusinessRuleError`, 422): the order is in `Draft`,
|
|
40
|
+
* `AddingItems`, `ArrangingPayment` (its payment is still being arranged) or `Cancelled`;
|
|
41
|
+
* - `AFAS_ADMINISTRATION_NOT_CONFIGURED` (422): the store's connection names no administration;
|
|
42
|
+
* - `SANDBOX_PUSH_REFUSED` (422): a sandbox store never writes to AFAS.
|
|
43
|
+
*
|
|
44
|
+
* What AFAS itself refuses, and the path rules (an order already a direct invoice, or locked
|
|
45
|
+
* as invoiced), answer `success: false` with the reason in `error` (and `errorCode` when it
|
|
46
|
+
* has one), not a throw.
|
|
47
|
+
*
|
|
48
|
+
* `options.idempotencyKey` is accepted and sent, but the engine does not store it yet: a
|
|
49
|
+
* repeat runs again (an order already pushed answers `alreadySynced`).
|
|
50
|
+
*
|
|
51
|
+
* @effect irreversible
|
|
52
|
+
* @permission UpdateOrder
|
|
53
|
+
*/
|
|
54
|
+
sync(orderId: string, input?: SyncAfasOrderInput, options?: Call): Promise<AfasPushResult>;
|
|
55
|
+
/**
|
|
56
|
+
* Settle the order's AFAS sales order (`FbSettleOrder`): AFAS marks it "Afgehandeld" for the
|
|
57
|
+
* accountant to invoice; it creates no invoice. This writes into the store's AFAS
|
|
58
|
+
* administration and cannot be undone from the platform.
|
|
59
|
+
*
|
|
60
|
+
* Refused with `AFAS_ADMINISTRATION_NOT_CONFIGURED` or `SANDBOX_PUSH_REFUSED` (422). An
|
|
61
|
+
* order with no sales order, already settled, or a direct invoice answers `success: false`
|
|
62
|
+
* with the reason in `error`, as does a refusal from AFAS.
|
|
63
|
+
*
|
|
64
|
+
* `options.idempotencyKey` is accepted and sent, but the engine does not store it yet.
|
|
65
|
+
*
|
|
66
|
+
* @effect irreversible
|
|
67
|
+
* @permission UpdateOrder
|
|
68
|
+
*/
|
|
69
|
+
settle(orderId: string, options?: Call): Promise<AfasSettleResult>;
|
|
70
|
+
/**
|
|
71
|
+
* Create a direct invoice for the order in AFAS (`FbDirectInvoice`): AFAS numbers a packing
|
|
72
|
+
* slip and an invoice in one go. The customer is resolved as in {@link sync}. With
|
|
73
|
+
* `settleAsZeroValue` it is a settlement from prepaid credit instead: a €0 document that books
|
|
74
|
+
* no receivable and keeps the lines, so AFAS deducts the stock. This writes into the store's
|
|
75
|
+
* AFAS administration and cannot be undone from the platform. The engine refuses a second
|
|
76
|
+
* direct invoice for the order, so a repeat writes nothing twice.
|
|
77
|
+
*
|
|
78
|
+
* Refused, with nothing sent to AFAS:
|
|
79
|
+
* - `AFAS_ORDER_STATE_BLOCKS_PUSH` (422): the order is in `Draft`, `AddingItems`,
|
|
80
|
+
* `ArrangingPayment` or `Cancelled`; a settlement from prepaid is allowed in
|
|
81
|
+
* `ArrangingPayment`, since it is one way such an order gets paid;
|
|
82
|
+
* - `AFAS_ADMINISTRATION_NOT_CONFIGURED`, `SANDBOX_PUSH_REFUSED` (422).
|
|
83
|
+
*
|
|
84
|
+
* An order already on an AFAS path, a store whose invoices AFAS numbers (use the invoice
|
|
85
|
+
* door), and a refusal from AFAS answer `success: false` with the reason in `error`.
|
|
86
|
+
*
|
|
87
|
+
* `options.idempotencyKey` is accepted and sent, but the engine does not store it yet.
|
|
88
|
+
*
|
|
89
|
+
* @effect irreversible
|
|
90
|
+
* @permission UpdateOrder
|
|
91
|
+
*/
|
|
92
|
+
createDirectInvoice(orderId: string, input?: CreateAfasDirectInvoiceInput, options?: Call): Promise<AfasDirectInvoiceResult>;
|
|
93
|
+
/**
|
|
94
|
+
* The order's AFAS invoice as PDF bytes, read live from AFAS; `null` when the order has no
|
|
95
|
+
* AFAS invoice number, the store has no invoice report connector, or AFAS answered nothing.
|
|
96
|
+
*
|
|
97
|
+
* @effect read
|
|
98
|
+
* @permission ReadOrder
|
|
99
|
+
*/
|
|
100
|
+
invoicePdf(orderId: string, options?: Call): Promise<Uint8Array | null>;
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* A customer's AFAS debtor (`admin.integrations.afas.customers`). Every method but `balance`
|
|
104
|
+
* refuses a store whose AFAS is not saved and switched on with `AFAS_NOT_CONFIGURED`
|
|
105
|
+
* (`BusinessRuleError`, 422), and a customer the store does not hold with `ENTITY_NOT_FOUND`
|
|
106
|
+
* (`NotFoundError`, 404).
|
|
107
|
+
*/
|
|
108
|
+
export interface AfasCustomersModule {
|
|
109
|
+
/**
|
|
110
|
+
* The AFAS debtor the customer is linked to, read live; `null` when it is not linked, or AFAS
|
|
111
|
+
* answered nothing.
|
|
112
|
+
*
|
|
113
|
+
* @effect read
|
|
114
|
+
* @permission UpdateCustomer
|
|
115
|
+
*/
|
|
116
|
+
preview(customerId: string, options?: Call): Promise<AfasCustomerPreview | null>;
|
|
117
|
+
/**
|
|
118
|
+
* The AFAS delivery address one of the customer's addresses is linked to, read live; `null`
|
|
119
|
+
* when it is not linked.
|
|
120
|
+
*
|
|
121
|
+
* @effect read
|
|
122
|
+
* @permission UpdateCustomer
|
|
123
|
+
*/
|
|
124
|
+
previewAddress(addressId: string, options?: Call): Promise<AfasAddressPreview | null>;
|
|
125
|
+
/**
|
|
126
|
+
* AFAS debtors matching an email, a phone number or a name, read live; most specific first.
|
|
127
|
+
* One page: AFAS answers at most `limit` (default 10, at most
|
|
128
|
+
* {@link AFAS_CUSTOMER_SEARCH_LIMIT}). A filter with nothing to look for answers an empty page.
|
|
129
|
+
* `AFAS_READ_FAILED` (`BusinessRuleError`, 422) when AFAS could not be read at all; the message
|
|
130
|
+
* says what to fix.
|
|
131
|
+
*
|
|
132
|
+
* @effect read
|
|
133
|
+
* @permission UpdateCustomer
|
|
134
|
+
*/
|
|
135
|
+
search(filter: AfasCustomerSearchFilter, options?: Call): Promise<Page<AfasCustomerPreview>>;
|
|
136
|
+
/**
|
|
137
|
+
* Push the customer to AFAS: link it to `afasVrId` and update that debtor from the customer,
|
|
138
|
+
* or create a new debtor when `afasVrId` is `null` or absent. This writes into the store's AFAS
|
|
139
|
+
* administration and cannot be undone from the platform. To attach a customer to an existing
|
|
140
|
+
* debtor WITHOUT changing the debtor, use {@link link}.
|
|
141
|
+
*
|
|
142
|
+
* Refused with `AFAS_ADMINISTRATION_NOT_CONFIGURED` or `SANDBOX_PUSH_REFUSED` (422),
|
|
143
|
+
* nothing sent. A refusal from AFAS answers `success: false` with the reason in `error`.
|
|
144
|
+
*
|
|
145
|
+
* The engine takes no idempotency key for it yet, so `options.idempotencyKey` is not sent: a
|
|
146
|
+
* repeat runs again.
|
|
147
|
+
*
|
|
148
|
+
* @effect irreversible
|
|
149
|
+
* @permission UpdateCustomer
|
|
150
|
+
*/
|
|
151
|
+
sync(customerId: string, input?: SyncAfasCustomerInput, options?: Call): Promise<AfasPushResult>;
|
|
152
|
+
/**
|
|
153
|
+
* Link the customer to an existing AFAS debtor without writing anything to AFAS (the debtor's
|
|
154
|
+
* own data stays as it is), and read its payment condition. `true` when the link changed,
|
|
155
|
+
* `false` when it was already in place. Refused `AFAS_LINK_INVALID` (400) for a blank
|
|
156
|
+
* `afasVrId`; `INVALID_AFAS_INPUT` (`ValidationError`, 400) before sending when it is not a
|
|
157
|
+
* string; `AFAS_ADMINISTRATION_NOT_CONFIGURED` (422).
|
|
158
|
+
*
|
|
159
|
+
* @effect write
|
|
160
|
+
* @permission UpdateCustomer
|
|
161
|
+
*/
|
|
162
|
+
link(customerId: string, debtor: AfasDebtorLink, options?: Call): Promise<boolean>;
|
|
163
|
+
/**
|
|
164
|
+
* Clear the customer's link to its AFAS debtor without writing anything to AFAS. `true` when
|
|
165
|
+
* a link was cleared, `false` when there was none. Refused
|
|
166
|
+
* `AFAS_ADMINISTRATION_NOT_CONFIGURED` (422).
|
|
167
|
+
*
|
|
168
|
+
* @effect write
|
|
169
|
+
* @permission UpdateCustomer
|
|
170
|
+
*/
|
|
171
|
+
unlink(customerId: string, options?: Call): Promise<boolean>;
|
|
172
|
+
/**
|
|
173
|
+
* The customer's outstanding AFAS balance, read live. Never refuses for AFAS: an unreachable
|
|
174
|
+
* AFAS answers `available: false`, AFAS off or an unlinked customer `linked: false`.
|
|
175
|
+
*
|
|
176
|
+
* @effect read
|
|
177
|
+
* @permission ReadCustomer
|
|
178
|
+
*/
|
|
179
|
+
balance(customerId: string, options?: Call): Promise<AfasCustomerBalance>;
|
|
180
|
+
}
|
|
181
|
+
/** A stock transfer's AFAS document (`admin.integrations.afas.stockTransfers`). */
|
|
182
|
+
export interface AfasStockTransfersModule {
|
|
183
|
+
/**
|
|
184
|
+
* The transfer's AFAS state, read from the platform (no AFAS call): whether it was sent, which
|
|
185
|
+
* way its stock moves and on which warehouse, and why it cannot be sent (`blockReason`).
|
|
186
|
+
*
|
|
187
|
+
* @effect read
|
|
188
|
+
* @permission ReadStockLocation
|
|
189
|
+
*/
|
|
190
|
+
state(stockTransferId: string, options?: Call): Promise<AfasStockTransferState>;
|
|
191
|
+
/**
|
|
192
|
+
* Send the transfer to AFAS as a €0 direct invoice booked against `afasDebtorId`, so AFAS
|
|
193
|
+
* moves the stock and books no receivable. This writes into the store's AFAS administration
|
|
194
|
+
* and cannot be undone from the platform. Idempotent per transfer: sending one again answers
|
|
195
|
+
* `alreadyPushed` and writes nothing.
|
|
196
|
+
*
|
|
197
|
+
* What blocks it (`state().blockReason`) and a refusal from AFAS answer `success: false` with
|
|
198
|
+
* the reason in `error`. `INVALID_AFAS_INPUT` (`ValidationError`, 400) before sending when
|
|
199
|
+
* `afasDebtorId` is not a non-empty string.
|
|
200
|
+
*
|
|
201
|
+
* `options.idempotencyKey` is accepted and sent, but the engine does not store it yet; the
|
|
202
|
+
* per-transfer rule above is what makes a repeat safe.
|
|
203
|
+
*
|
|
204
|
+
* @effect irreversible
|
|
205
|
+
* @permission UpdateStockLocation
|
|
206
|
+
*/
|
|
207
|
+
createInvoice(stockTransferId: string, input: CreateAfasStockTransferInvoiceInput, options?: Call): Promise<AfasStockTransferInvoiceResult>;
|
|
208
|
+
}
|
|
209
|
+
export declare const PREVIEW_AFAS_ORDER_QUERY = "\n query PreviewAfasOrder($orderId: ID!) {\n previewAfasOrder(orderId: $orderId) {\n orNu\n debtorBcCo\n reference\n orderDate\n totalAmount\n currency\n status\n settled\n }\n }\n";
|
|
210
|
+
export declare const AFAS_ORDER_STATE_QUERY = "\n query AfasOrderState($orderId: ID!) {\n afasOrderState(orderId: $orderId) {\n path\n afasSalesOrderId\n afasSettled\n afasDirectInvoiceOrNu\n afasInvoiceNumber\n afasInvoiceDate\n hasPdfReport\n stateAllowsPush\n stateAllowsPrepaidSettlement\n }\n }\n";
|
|
211
|
+
export declare const SYNC_ORDER_TO_AFAS_MUTATION = "\n mutation SyncOrderToAfas($input: SyncOrderToAfasInput!, $idempotencyKey: String) {\n syncOrderToAfas(input: $input, idempotencyKey: $idempotencyKey) { \n success\n locked\n alreadySynced\n externalRef\n message\n error\n errorCode\n }\n }\n";
|
|
212
|
+
export declare const SETTLE_AFAS_ORDER_MUTATION = "\n mutation SettleAfasOrder($orderId: ID!, $idempotencyKey: String) {\n settleAfasOrder(orderId: $orderId, idempotencyKey: $idempotencyKey) {\n success\n locked\n afasSettled\n error\n }\n }\n";
|
|
213
|
+
export declare const CREATE_AFAS_DIRECT_INVOICE_MUTATION = "\n mutation CreateAfasDirectInvoice($input: CreateAfasDirectInvoiceInput!, $idempotencyKey: String) {\n createAfasDirectInvoice(input: $input, idempotencyKey: $idempotencyKey) {\n success\n afasDirectInvoiceOrNu\n afasInvoiceNumber\n afasInvoiceDate\n error\n errorCode\n }\n }\n";
|
|
214
|
+
export declare const AFAS_INVOICE_PDF_QUERY = "\n query AfasInvoicePdf($orderId: ID!) {\n afasInvoicePdf(orderId: $orderId)\n }\n";
|
|
215
|
+
export declare const PREVIEW_AFAS_CUSTOMER_QUERY = "\n query PreviewAfasCustomer($customerId: ID!) {\n previewAfasCustomer(customerId: $customerId) { \n bcCo\n debtorId\n name\n kind\n email\n phone\n vatNumber\n kvkNumber\n addressLine1\n addressLine3\n addressLine4\n currency\n paymentCondition\n blocked\n }\n }\n";
|
|
216
|
+
export declare const PREVIEW_AFAS_ADDRESS_QUERY = "\n query PreviewAfasAddress($addressId: ID!) {\n previewAfasAddress(addressId: $addressId) {\n adId\n bcCo\n street\n houseNumber\n postalCode\n city\n countryCode\n }\n }\n";
|
|
217
|
+
export declare const SEARCH_AFAS_CUSTOMERS_QUERY = "\n query SearchAfasCustomers($email: String, $phone: String, $name: String, $limit: Int) {\n searchAfasCustomers(email: $email, phone: $phone, name: $name, limit: $limit) {\n \n bcCo\n debtorId\n name\n kind\n email\n phone\n vatNumber\n kvkNumber\n addressLine1\n addressLine3\n addressLine4\n currency\n paymentCondition\n blocked\n\n }\n }\n";
|
|
218
|
+
export declare const SYNC_CUSTOMER_TO_AFAS_MUTATION = "\n mutation SyncCustomerToAfas($input: SyncCustomerToAfasInput!) {\n syncCustomerToAfas(input: $input) { \n success\n locked\n alreadySynced\n externalRef\n message\n error\n errorCode\n }\n }\n";
|
|
219
|
+
export declare const LINK_CUSTOMER_TO_AFAS_MUTATION = "\n mutation LinkCustomerToAfas(\n $customerId: ID!\n $afasVrId: String!\n $afasBcCo: String\n $afasKind: AfasDebtorKind\n ) {\n linkCustomerToAfas(\n customerId: $customerId\n afasVrId: $afasVrId\n afasBcCo: $afasBcCo\n afasKind: $afasKind\n )\n }\n";
|
|
220
|
+
export declare const UNLINK_CUSTOMER_FROM_AFAS_MUTATION = "\n mutation UnlinkCustomerFromAfas($customerId: ID!) {\n unlinkCustomerFromAfas(customerId: $customerId)\n }\n";
|
|
221
|
+
export declare const AFAS_CUSTOMER_BALANCE_QUERY = "\n query AfasCustomerBalance($customerId: ID!) {\n afasCustomerBalance(customerId: $customerId) {\n linked\n available\n balance\n currencyCode\n debtorId\n }\n }\n";
|
|
222
|
+
/**
|
|
223
|
+
* Only the current document: every engine in production answers the return fields (a read-only
|
|
224
|
+
* probe of production's Admin schema, 2026-10-13, headless W10-54), so the older-engine document
|
|
225
|
+
* without them is gone.
|
|
226
|
+
*/
|
|
227
|
+
export declare const AFAS_STOCK_TRANSFER_STATE_QUERY = "\n query AfasStockTransferState($stockTransferId: ID!) {\n afasStockTransferState(stockTransferId: $stockTransferId) {\n enabled\n pushed\n afasDirectInvoiceOrNu\n afasInvoiceNumber\n afasDebtorId\n pushedAt\n sourceAfasWarehouse\n destinationAfasWarehouse\n isReturn\n stockDirection\n pushable\n blockReason\n }\n }\n";
|
|
228
|
+
export declare const CREATE_AFAS_STOCK_TRANSFER_INVOICE_MUTATION = "\n mutation CreateAfasStockTransferInvoice(\n $input: CreateAfasStockTransferInvoiceInput!\n $idempotencyKey: String\n ) {\n createAfasStockTransferInvoice(input: $input, idempotencyKey: $idempotencyKey) {\n success\n alreadyPushed\n afasDirectInvoiceOrNu\n afasInvoiceNumber\n error\n }\n }\n";
|
|
229
|
+
export interface AfasActionsModules {
|
|
230
|
+
orders: AfasOrdersModule;
|
|
231
|
+
customers: AfasCustomersModule;
|
|
232
|
+
stockTransfers: AfasStockTransfersModule;
|
|
233
|
+
}
|
|
234
|
+
export declare function createAfasActionsModules(transport: Transport): AfasActionsModules;
|
|
@@ -0,0 +1,310 @@
|
|
|
1
|
+
import { createPage, ValidationError } from '@sixtyninecommerce/core';
|
|
2
|
+
import { fieldOf } from '../catalog/types.js';
|
|
3
|
+
import { decodePdf } from '../documents/pdf.js';
|
|
4
|
+
/** The most debtors `customers.search` asks AFAS for; the default is 10. */
|
|
5
|
+
export const AFAS_CUSTOMER_SEARCH_LIMIT = 50;
|
|
6
|
+
const AFAS_CUSTOMER_SEARCH_DEFAULT = 10;
|
|
7
|
+
const PUSH_RESULT_FIELDS = /* GraphQL */ `
|
|
8
|
+
success
|
|
9
|
+
locked
|
|
10
|
+
alreadySynced
|
|
11
|
+
externalRef
|
|
12
|
+
message
|
|
13
|
+
error
|
|
14
|
+
errorCode
|
|
15
|
+
`;
|
|
16
|
+
const CUSTOMER_PREVIEW_FIELDS = /* GraphQL */ `
|
|
17
|
+
bcCo
|
|
18
|
+
debtorId
|
|
19
|
+
name
|
|
20
|
+
kind
|
|
21
|
+
email
|
|
22
|
+
phone
|
|
23
|
+
vatNumber
|
|
24
|
+
kvkNumber
|
|
25
|
+
addressLine1
|
|
26
|
+
addressLine3
|
|
27
|
+
addressLine4
|
|
28
|
+
currency
|
|
29
|
+
paymentCondition
|
|
30
|
+
blocked
|
|
31
|
+
`;
|
|
32
|
+
export const PREVIEW_AFAS_ORDER_QUERY = /* GraphQL */ `
|
|
33
|
+
query PreviewAfasOrder($orderId: ID!) {
|
|
34
|
+
previewAfasOrder(orderId: $orderId) {
|
|
35
|
+
orNu
|
|
36
|
+
debtorBcCo
|
|
37
|
+
reference
|
|
38
|
+
orderDate
|
|
39
|
+
totalAmount
|
|
40
|
+
currency
|
|
41
|
+
status
|
|
42
|
+
settled
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
`;
|
|
46
|
+
export const AFAS_ORDER_STATE_QUERY = /* GraphQL */ `
|
|
47
|
+
query AfasOrderState($orderId: ID!) {
|
|
48
|
+
afasOrderState(orderId: $orderId) {
|
|
49
|
+
path
|
|
50
|
+
afasSalesOrderId
|
|
51
|
+
afasSettled
|
|
52
|
+
afasDirectInvoiceOrNu
|
|
53
|
+
afasInvoiceNumber
|
|
54
|
+
afasInvoiceDate
|
|
55
|
+
hasPdfReport
|
|
56
|
+
stateAllowsPush
|
|
57
|
+
stateAllowsPrepaidSettlement
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
`;
|
|
61
|
+
export const SYNC_ORDER_TO_AFAS_MUTATION = /* GraphQL */ `
|
|
62
|
+
mutation SyncOrderToAfas($input: SyncOrderToAfasInput!, $idempotencyKey: String) {
|
|
63
|
+
syncOrderToAfas(input: $input, idempotencyKey: $idempotencyKey) { ${PUSH_RESULT_FIELDS} }
|
|
64
|
+
}
|
|
65
|
+
`;
|
|
66
|
+
export const SETTLE_AFAS_ORDER_MUTATION = /* GraphQL */ `
|
|
67
|
+
mutation SettleAfasOrder($orderId: ID!, $idempotencyKey: String) {
|
|
68
|
+
settleAfasOrder(orderId: $orderId, idempotencyKey: $idempotencyKey) {
|
|
69
|
+
success
|
|
70
|
+
locked
|
|
71
|
+
afasSettled
|
|
72
|
+
error
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
`;
|
|
76
|
+
export const CREATE_AFAS_DIRECT_INVOICE_MUTATION = /* GraphQL */ `
|
|
77
|
+
mutation CreateAfasDirectInvoice($input: CreateAfasDirectInvoiceInput!, $idempotencyKey: String) {
|
|
78
|
+
createAfasDirectInvoice(input: $input, idempotencyKey: $idempotencyKey) {
|
|
79
|
+
success
|
|
80
|
+
afasDirectInvoiceOrNu
|
|
81
|
+
afasInvoiceNumber
|
|
82
|
+
afasInvoiceDate
|
|
83
|
+
error
|
|
84
|
+
errorCode
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
`;
|
|
88
|
+
export const AFAS_INVOICE_PDF_QUERY = /* GraphQL */ `
|
|
89
|
+
query AfasInvoicePdf($orderId: ID!) {
|
|
90
|
+
afasInvoicePdf(orderId: $orderId)
|
|
91
|
+
}
|
|
92
|
+
`;
|
|
93
|
+
export const PREVIEW_AFAS_CUSTOMER_QUERY = /* GraphQL */ `
|
|
94
|
+
query PreviewAfasCustomer($customerId: ID!) {
|
|
95
|
+
previewAfasCustomer(customerId: $customerId) { ${CUSTOMER_PREVIEW_FIELDS} }
|
|
96
|
+
}
|
|
97
|
+
`;
|
|
98
|
+
export const PREVIEW_AFAS_ADDRESS_QUERY = /* GraphQL */ `
|
|
99
|
+
query PreviewAfasAddress($addressId: ID!) {
|
|
100
|
+
previewAfasAddress(addressId: $addressId) {
|
|
101
|
+
adId
|
|
102
|
+
bcCo
|
|
103
|
+
street
|
|
104
|
+
houseNumber
|
|
105
|
+
postalCode
|
|
106
|
+
city
|
|
107
|
+
countryCode
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
`;
|
|
111
|
+
export const SEARCH_AFAS_CUSTOMERS_QUERY = /* GraphQL */ `
|
|
112
|
+
query SearchAfasCustomers($email: String, $phone: String, $name: String, $limit: Int) {
|
|
113
|
+
searchAfasCustomers(email: $email, phone: $phone, name: $name, limit: $limit) {
|
|
114
|
+
${CUSTOMER_PREVIEW_FIELDS}
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
`;
|
|
118
|
+
export const SYNC_CUSTOMER_TO_AFAS_MUTATION = /* GraphQL */ `
|
|
119
|
+
mutation SyncCustomerToAfas($input: SyncCustomerToAfasInput!) {
|
|
120
|
+
syncCustomerToAfas(input: $input) { ${PUSH_RESULT_FIELDS} }
|
|
121
|
+
}
|
|
122
|
+
`;
|
|
123
|
+
export const LINK_CUSTOMER_TO_AFAS_MUTATION = /* GraphQL */ `
|
|
124
|
+
mutation LinkCustomerToAfas(
|
|
125
|
+
$customerId: ID!
|
|
126
|
+
$afasVrId: String!
|
|
127
|
+
$afasBcCo: String
|
|
128
|
+
$afasKind: AfasDebtorKind
|
|
129
|
+
) {
|
|
130
|
+
linkCustomerToAfas(
|
|
131
|
+
customerId: $customerId
|
|
132
|
+
afasVrId: $afasVrId
|
|
133
|
+
afasBcCo: $afasBcCo
|
|
134
|
+
afasKind: $afasKind
|
|
135
|
+
)
|
|
136
|
+
}
|
|
137
|
+
`;
|
|
138
|
+
export const UNLINK_CUSTOMER_FROM_AFAS_MUTATION = /* GraphQL */ `
|
|
139
|
+
mutation UnlinkCustomerFromAfas($customerId: ID!) {
|
|
140
|
+
unlinkCustomerFromAfas(customerId: $customerId)
|
|
141
|
+
}
|
|
142
|
+
`;
|
|
143
|
+
export const AFAS_CUSTOMER_BALANCE_QUERY = /* GraphQL */ `
|
|
144
|
+
query AfasCustomerBalance($customerId: ID!) {
|
|
145
|
+
afasCustomerBalance(customerId: $customerId) {
|
|
146
|
+
linked
|
|
147
|
+
available
|
|
148
|
+
balance
|
|
149
|
+
currencyCode
|
|
150
|
+
debtorId
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
`;
|
|
154
|
+
/**
|
|
155
|
+
* Only the current document: every engine in production answers the return fields (a read-only
|
|
156
|
+
* probe of production's Admin schema, 2026-10-13, headless W10-54), so the older-engine document
|
|
157
|
+
* without them is gone.
|
|
158
|
+
*/
|
|
159
|
+
export const AFAS_STOCK_TRANSFER_STATE_QUERY = /* GraphQL */ `
|
|
160
|
+
query AfasStockTransferState($stockTransferId: ID!) {
|
|
161
|
+
afasStockTransferState(stockTransferId: $stockTransferId) {
|
|
162
|
+
enabled
|
|
163
|
+
pushed
|
|
164
|
+
afasDirectInvoiceOrNu
|
|
165
|
+
afasInvoiceNumber
|
|
166
|
+
afasDebtorId
|
|
167
|
+
pushedAt
|
|
168
|
+
sourceAfasWarehouse
|
|
169
|
+
destinationAfasWarehouse
|
|
170
|
+
isReturn
|
|
171
|
+
stockDirection
|
|
172
|
+
pushable
|
|
173
|
+
blockReason
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
`;
|
|
177
|
+
export const CREATE_AFAS_STOCK_TRANSFER_INVOICE_MUTATION = /* GraphQL */ `
|
|
178
|
+
mutation CreateAfasStockTransferInvoice(
|
|
179
|
+
$input: CreateAfasStockTransferInvoiceInput!
|
|
180
|
+
$idempotencyKey: String
|
|
181
|
+
) {
|
|
182
|
+
createAfasStockTransferInvoice(input: $input, idempotencyKey: $idempotencyKey) {
|
|
183
|
+
success
|
|
184
|
+
alreadyPushed
|
|
185
|
+
afasDirectInvoiceOrNu
|
|
186
|
+
afasInvoiceNumber
|
|
187
|
+
error
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
`;
|
|
191
|
+
const invalidInput = (message) => new ValidationError({ code: 'INVALID_AFAS_INPUT', message, status: 400, service: 'vendure' });
|
|
192
|
+
const requireId = (value, name) => {
|
|
193
|
+
if (typeof value !== 'string' || value === '') {
|
|
194
|
+
throw invalidInput(`${name} must be a non-empty id.`);
|
|
195
|
+
}
|
|
196
|
+
return value;
|
|
197
|
+
};
|
|
198
|
+
const optionalObject = (value, method) => {
|
|
199
|
+
if (value === undefined)
|
|
200
|
+
return undefined;
|
|
201
|
+
if (typeof value !== 'object' || value === null || Array.isArray(value)) {
|
|
202
|
+
throw invalidInput(`${method} takes an input object.`);
|
|
203
|
+
}
|
|
204
|
+
return value;
|
|
205
|
+
};
|
|
206
|
+
const trimmedOrNull = (value) => value?.trim() || null;
|
|
207
|
+
export function createAfasActionsModules(transport) {
|
|
208
|
+
const read = (document, field, options, variables = {}) => fieldOf(transport, document, field, variables, options);
|
|
209
|
+
return {
|
|
210
|
+
orders: {
|
|
211
|
+
async preview(orderId, options) {
|
|
212
|
+
return ((await read(PREVIEW_AFAS_ORDER_QUERY, 'previewAfasOrder', options, { orderId: requireId(orderId, 'orderId') })) ?? null);
|
|
213
|
+
},
|
|
214
|
+
async state(orderId, options) {
|
|
215
|
+
return read(AFAS_ORDER_STATE_QUERY, 'afasOrderState', options, {
|
|
216
|
+
orderId: requireId(orderId, 'orderId'),
|
|
217
|
+
});
|
|
218
|
+
},
|
|
219
|
+
async sync(orderId, input, options) {
|
|
220
|
+
const given = optionalObject(input, 'orders.sync') ?? {};
|
|
221
|
+
return read(SYNC_ORDER_TO_AFAS_MUTATION, 'syncOrderToAfas', options, {
|
|
222
|
+
input: { ...given, orderId: requireId(orderId, 'orderId') },
|
|
223
|
+
idempotencyKey: options?.idempotencyKey ?? null,
|
|
224
|
+
});
|
|
225
|
+
},
|
|
226
|
+
async settle(orderId, options) {
|
|
227
|
+
return read(SETTLE_AFAS_ORDER_MUTATION, 'settleAfasOrder', options, {
|
|
228
|
+
orderId: requireId(orderId, 'orderId'),
|
|
229
|
+
idempotencyKey: options?.idempotencyKey ?? null,
|
|
230
|
+
});
|
|
231
|
+
},
|
|
232
|
+
async createDirectInvoice(orderId, input, options) {
|
|
233
|
+
const given = optionalObject(input, 'orders.createDirectInvoice') ?? {};
|
|
234
|
+
return read(CREATE_AFAS_DIRECT_INVOICE_MUTATION, 'createAfasDirectInvoice', options, {
|
|
235
|
+
input: { ...given, orderId: requireId(orderId, 'orderId') },
|
|
236
|
+
idempotencyKey: options?.idempotencyKey ?? null,
|
|
237
|
+
});
|
|
238
|
+
},
|
|
239
|
+
async invoicePdf(orderId, options) {
|
|
240
|
+
const base64 = await read(AFAS_INVOICE_PDF_QUERY, 'afasInvoicePdf', options, { orderId: requireId(orderId, 'orderId') });
|
|
241
|
+
return base64 ? decodePdf(base64) : null;
|
|
242
|
+
},
|
|
243
|
+
},
|
|
244
|
+
customers: {
|
|
245
|
+
async preview(customerId, options) {
|
|
246
|
+
return ((await read(PREVIEW_AFAS_CUSTOMER_QUERY, 'previewAfasCustomer', options, { customerId: requireId(customerId, 'customerId') })) ?? null);
|
|
247
|
+
},
|
|
248
|
+
async previewAddress(addressId, options) {
|
|
249
|
+
return ((await read(PREVIEW_AFAS_ADDRESS_QUERY, 'previewAfasAddress', options, { addressId: requireId(addressId, 'addressId') })) ?? null);
|
|
250
|
+
},
|
|
251
|
+
async search(filter, options) {
|
|
252
|
+
const given = optionalObject(filter, 'customers.search') ?? {};
|
|
253
|
+
const email = trimmedOrNull(given.email);
|
|
254
|
+
const phone = trimmedOrNull(given.phone);
|
|
255
|
+
const name = trimmedOrNull(given.name);
|
|
256
|
+
const limit = Math.min(Math.max(Math.trunc(given.limit ?? AFAS_CUSTOMER_SEARCH_DEFAULT), 1), AFAS_CUSTOMER_SEARCH_LIMIT);
|
|
257
|
+
const single = (items) => createPage(items, { nextCursor: null, hasNext: false }, () => {
|
|
258
|
+
throw invalidInput('customers.search answers a single page.');
|
|
259
|
+
});
|
|
260
|
+
// Nothing to look for: the engine would answer [] after an AFAS round trip.
|
|
261
|
+
if (!email && !phone && !name)
|
|
262
|
+
return single([]);
|
|
263
|
+
const items = await read(SEARCH_AFAS_CUSTOMERS_QUERY, 'searchAfasCustomers', options, { email, phone, name, limit });
|
|
264
|
+
return single(items);
|
|
265
|
+
},
|
|
266
|
+
async sync(customerId, input, options) {
|
|
267
|
+
const given = optionalObject(input, 'customers.sync') ?? {};
|
|
268
|
+
return read(SYNC_CUSTOMER_TO_AFAS_MUTATION, 'syncCustomerToAfas', options, {
|
|
269
|
+
input: { ...given, customerId: requireId(customerId, 'customerId') },
|
|
270
|
+
});
|
|
271
|
+
},
|
|
272
|
+
async link(customerId, debtor, options) {
|
|
273
|
+
const given = optionalObject(debtor, 'customers.link');
|
|
274
|
+
if (typeof given?.afasVrId !== 'string') {
|
|
275
|
+
throw invalidInput('customers.link needs the AFAS debtor code (afasVrId).');
|
|
276
|
+
}
|
|
277
|
+
return ((await read(LINK_CUSTOMER_TO_AFAS_MUTATION, 'linkCustomerToAfas', options, {
|
|
278
|
+
customerId: requireId(customerId, 'customerId'),
|
|
279
|
+
afasVrId: given.afasVrId,
|
|
280
|
+
afasBcCo: given.afasBcCo ?? null,
|
|
281
|
+
afasKind: given.afasKind ?? null,
|
|
282
|
+
})) === true);
|
|
283
|
+
},
|
|
284
|
+
async unlink(customerId, options) {
|
|
285
|
+
return ((await read(UNLINK_CUSTOMER_FROM_AFAS_MUTATION, 'unlinkCustomerFromAfas', options, { customerId: requireId(customerId, 'customerId') })) === true);
|
|
286
|
+
},
|
|
287
|
+
async balance(customerId, options) {
|
|
288
|
+
return read(AFAS_CUSTOMER_BALANCE_QUERY, 'afasCustomerBalance', options, { customerId: requireId(customerId, 'customerId') });
|
|
289
|
+
},
|
|
290
|
+
},
|
|
291
|
+
stockTransfers: {
|
|
292
|
+
async state(stockTransferId, options) {
|
|
293
|
+
return read(AFAS_STOCK_TRANSFER_STATE_QUERY, 'afasStockTransferState', options, { stockTransferId: requireId(stockTransferId, 'stockTransferId') });
|
|
294
|
+
},
|
|
295
|
+
async createInvoice(stockTransferId, input, options) {
|
|
296
|
+
const given = optionalObject(input, 'stockTransfers.createInvoice');
|
|
297
|
+
if (typeof given?.afasDebtorId !== 'string' || given.afasDebtorId.trim() === '') {
|
|
298
|
+
throw invalidInput('stockTransfers.createInvoice needs the AFAS relation (afasDebtorId).');
|
|
299
|
+
}
|
|
300
|
+
return read(CREATE_AFAS_STOCK_TRANSFER_INVOICE_MUTATION, 'createAfasStockTransferInvoice', options, {
|
|
301
|
+
input: {
|
|
302
|
+
stockTransferId: requireId(stockTransferId, 'stockTransferId'),
|
|
303
|
+
afasDebtorId: given.afasDebtorId,
|
|
304
|
+
},
|
|
305
|
+
idempotencyKey: options?.idempotencyKey ?? null,
|
|
306
|
+
});
|
|
307
|
+
},
|
|
308
|
+
},
|
|
309
|
+
};
|
|
310
|
+
}
|