@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.
- package/README.md +4347 -171
- 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/index.d.ts +9 -2
- package/dist/catalog/index.js +4 -0
- package/dist/catalog/products.d.ts +159 -19
- package/dist/catalog/products.js +88 -13
- package/dist/catalog/properties.d.ts +102 -14
- package/dist/catalog/properties.js +13 -0
- package/dist/catalog/recommendations.d.ts +261 -0
- package/dist/catalog/recommendations.js +145 -0
- package/dist/catalog/reviews.d.ts +368 -0
- package/dist/catalog/reviews.js +318 -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 +233 -26
- package/dist/catalog/variants.js +125 -7
- package/dist/catalog/visibility.d.ts +20 -5
- package/dist/catalog/visibility.js +19 -1
- package/dist/client.d.ts +95 -9
- package/dist/client.js +35 -7
- package/dist/content/assets.d.ts +286 -0
- package/dist/content/assets.js +181 -0
- package/dist/content/items.d.ts +269 -0
- package/dist/content/items.js +170 -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/groups.d.ts +207 -0
- package/dist/customers/groups.js +438 -0
- package/dist/customers/index.d.ts +447 -37
- package/dist/customers/index.js +313 -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/index.d.ts +731 -21
- package/dist/documents/index.js +436 -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 +44 -10
- package/dist/fulfillments/index.js +11 -2
- 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 +123 -35
- package/dist/index.js +45 -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 +423 -0
- package/dist/integrations/exact-online-types.js +6 -0
- package/dist/integrations/exact-online.d.ts +248 -0
- package/dist/integrations/exact-online.js +376 -0
- package/dist/integrations/index.d.ts +29 -3
- package/dist/integrations/index.js +18 -3
- package/dist/integrations/pipeline-keys.d.ts +13 -0
- package/dist/integrations/pipeline-keys.js +22 -0
- package/dist/integrations/pipelines.d.ts +15 -14
- package/dist/integrations/pipelines.js +6 -22
- package/dist/integrations/types.d.ts +146 -0
- package/dist/locations/index.d.ts +66 -0
- package/dist/locations/index.js +31 -0
- package/dist/meta/index.d.ts +162 -0
- package/dist/orders/cancel-with-money.d.ts +227 -0
- package/dist/orders/cancel-with-money.js +153 -0
- package/dist/orders/commit-edit.d.ts +7 -1
- package/dist/orders/commit-edit.js +5 -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 +49 -9
- package/dist/orders/index.js +22 -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 +222 -0
- package/dist/orders/list.js +377 -0
- package/dist/orders/manual-pricing.d.ts +5 -0
- package/dist/orders/order-entry.d.ts +20 -7
- package/dist/orders/plan-edit.d.ts +1 -1
- package/dist/orders/plan-edit.js +4 -1
- 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 +8 -1
- package/dist/orders/surcharges.js +3 -2
- package/dist/payments/account-credit.d.ts +30 -0
- package/dist/payments/account-credit.js +19 -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 +12 -0
- package/dist/payments/credit-noted-fields.js +37 -0
- package/dist/payments/index.d.ts +257 -11
- package/dist/payments/index.js +131 -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 +144 -0
- package/dist/payments/requests.js +92 -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 +104 -0
- package/dist/pickups/index.js +105 -0
- package/dist/platform/channels.d.ts +132 -0
- package/dist/platform/channels.js +128 -0
- package/dist/platform/geo.d.ts +123 -0
- package/dist/platform/geo.js +144 -0
- package/dist/platform/tax.d.ts +154 -0
- package/dist/platform/tax.js +139 -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 +103 -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 +2125 -32
- package/dist/pos/index.js +742 -4
- package/dist/pos/no-receipt.d.ts +94 -0
- package/dist/pos/no-receipt.js +25 -0
- package/dist/pos/offline-sales.d.ts +187 -0
- package/dist/pos/offline-sales.js +116 -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 +217 -0
- package/dist/pos/returns.js +53 -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 +604 -0
- package/dist/pricing/price-lists.js +600 -0
- package/dist/purchasing/alerts.d.ts +89 -0
- package/dist/purchasing/alerts.js +62 -0
- package/dist/purchasing/cost.d.ts +110 -0
- package/dist/purchasing/cost.js +86 -0
- package/dist/purchasing/index.d.ts +36 -0
- package/dist/purchasing/index.js +16 -0
- package/dist/purchasing/purchase-orders.d.ts +548 -0
- package/dist/purchasing/purchase-orders.js +491 -0
- package/dist/purchasing/replenishment.d.ts +281 -0
- package/dist/purchasing/replenishment.js +240 -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 +501 -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 +614 -21
- package/dist/returns/index.js +695 -11
- package/dist/search/index.d.ts +76 -1
- package/dist/search/index.js +63 -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 +48 -0
- package/dist/shipping/index.js +25 -0
- package/dist/shipping/methods.d.ts +198 -0
- package/dist/shipping/methods.js +240 -0
- package/dist/shipping/myparcel.d.ts +254 -0
- package/dist/shipping/myparcel.js +178 -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 +179 -0
- package/dist/shipping/rate-tables.js +184 -0
- package/dist/stock/index.d.ts +10 -3
- package/dist/stock/index.js +3 -0
- package/dist/stock/locations.d.ts +144 -0
- package/dist/stock/locations.js +168 -0
- package/dist/stock/transfers.d.ts +216 -43
- package/dist/stock/transfers.js +140 -13
- package/dist/stored-value/index.d.ts +214 -4
- package/dist/stored-value/index.js +152 -0
- package/dist/subscriptions/index.d.ts +682 -0
- package/dist/subscriptions/index.js +815 -0
- package/dist/tax/index.d.ts +76 -1
- package/dist/tax/index.js +50 -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 +66 -0
- package/dist/tenant/email-templates.js +54 -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,263 @@
|
|
|
1
|
+
import { type Page, type Transport } from '@sixtyninecommerce/core';
|
|
2
|
+
import type { OrderPaymentTerms } from '../orders/get.js';
|
|
3
|
+
import type { Call, ListOptions } from '../types.js';
|
|
4
|
+
/**
|
|
5
|
+
* A customer's B2B credit: the account the store keeps them in its accounts-receivable ledger,
|
|
6
|
+
* their credit limit and payment terms, and what they owe (`admin.customers.credit`, headless
|
|
7
|
+
* W10-30). The documents of that ledger are `admin.documents.ar`; its payments
|
|
8
|
+
* `admin.payments.ar`.
|
|
9
|
+
*
|
|
10
|
+
* Everything here is for a store that keeps its own AR ledger (`settings.get().enabled`). A write
|
|
11
|
+
* on any other store is refused `AR_LEDGER_NOT_ENABLED` (→ `BusinessRuleError`, 422); a customer
|
|
12
|
+
* the store does not hold, `CUSTOMER_NOT_FOUND` (→ `NotFoundError`). Money is in integer minor
|
|
13
|
+
* units of the currency named beside it, never added across currencies.
|
|
14
|
+
*/
|
|
15
|
+
/** Whether the store keeps an accounts-receivable ledger at all. */
|
|
16
|
+
export interface CustomerCreditSettings {
|
|
17
|
+
/** The store's B2B credit switch (`Channel.customFields.b2bCreditEnabled`). */
|
|
18
|
+
enabled: boolean;
|
|
19
|
+
/** The store's default currency, the one a new credit account is opened in. */
|
|
20
|
+
defaultCurrencyCode: string;
|
|
21
|
+
}
|
|
22
|
+
/** `per_order` (an invoice per placed order) or `statement` (one per period). */
|
|
23
|
+
export type InvoicingMode = 'per_order' | 'statement' | (string & {});
|
|
24
|
+
/** A customer's stored credit-account settings. */
|
|
25
|
+
export interface CreditAccount {
|
|
26
|
+
id: string;
|
|
27
|
+
customerId: string;
|
|
28
|
+
/** Minor units of `currencyCode`; null when unlimited. */
|
|
29
|
+
creditLimit: number | null;
|
|
30
|
+
defaultPaymentTermsDays: number | null;
|
|
31
|
+
invoicingMode: InvoicingMode;
|
|
32
|
+
/** Day of the month (1-28) the statement run invoices this customer; null when it does not. */
|
|
33
|
+
statementDayOfMonth: number | null;
|
|
34
|
+
/** True when the customer is invoiced in the store's ERP, which keeps their balance. */
|
|
35
|
+
erpLinked: boolean;
|
|
36
|
+
/** The account's currency: the credit limit's. */
|
|
37
|
+
currencyCode: string;
|
|
38
|
+
externalInvoicesSyncedAt: string | null;
|
|
39
|
+
externalInvoicesSyncError: string | null;
|
|
40
|
+
createdAt: string;
|
|
41
|
+
updatedAt: string;
|
|
42
|
+
}
|
|
43
|
+
/** One currency's signed balance. */
|
|
44
|
+
export interface CurrencyBalance {
|
|
45
|
+
currencyCode: string;
|
|
46
|
+
/** Signed, minor units of `currencyCode`: above 0 the customer owes, below 0 is a credit. */
|
|
47
|
+
balance: number;
|
|
48
|
+
}
|
|
49
|
+
/** A customer's position as the ledger states it. */
|
|
50
|
+
export interface CreditAccountSummary {
|
|
51
|
+
customerId: string;
|
|
52
|
+
/** The account's currency. */
|
|
53
|
+
currencyCode: string;
|
|
54
|
+
/** The signed ledger balance in `currencyCode` only; every currency is in `balances`. */
|
|
55
|
+
balance: number;
|
|
56
|
+
balances: CurrencyBalance[];
|
|
57
|
+
creditLimit: number | null;
|
|
58
|
+
defaultPaymentTermsDays: number | null;
|
|
59
|
+
invoicingMode: InvoicingMode;
|
|
60
|
+
erpLinked: boolean;
|
|
61
|
+
openInvoiceCount: number;
|
|
62
|
+
overdueInvoiceCount: number;
|
|
63
|
+
}
|
|
64
|
+
/** Where a credit status's balance came from. */
|
|
65
|
+
export type CreditBalanceSource = 'LOCAL_LEDGER' | 'ERP_LIVE' | 'ERP_UNLINKED';
|
|
66
|
+
/**
|
|
67
|
+
* A customer's credit status: exposure (ledger balance plus what placed, not-yet-invoiced orders
|
|
68
|
+
* still owe) against the credit limit. Every figure is in `currencyCode`, other currencies
|
|
69
|
+
* converted at the store's rate. Warning only: it never blocks an order.
|
|
70
|
+
*/
|
|
71
|
+
export interface CreditStatus {
|
|
72
|
+
customerId: string;
|
|
73
|
+
currencyCode: string;
|
|
74
|
+
/** Signed; the ledger's balance PLUS {@link setAsideMinor}. */
|
|
75
|
+
balance: number;
|
|
76
|
+
uninvoicedOrdersTotal: number;
|
|
77
|
+
/** `balance + uninvoicedOrdersTotal`. */
|
|
78
|
+
exposure: number;
|
|
79
|
+
creditLimit: number | null;
|
|
80
|
+
/** `creditLimit - exposure`; null without a limit. */
|
|
81
|
+
available: number | null;
|
|
82
|
+
overdueInvoiceCount: number;
|
|
83
|
+
overLimit: boolean;
|
|
84
|
+
hasOverdue: boolean;
|
|
85
|
+
balanceSource: CreditBalanceSource;
|
|
86
|
+
/** The exposure per currency before conversion, the account's currency included. */
|
|
87
|
+
exposureByCurrency: Array<{
|
|
88
|
+
currencyCode: string;
|
|
89
|
+
balance: number;
|
|
90
|
+
uninvoicedOrdersTotal: number;
|
|
91
|
+
}>;
|
|
92
|
+
/** Currencies left out for want of an exchange rate (only ever without a credit limit). */
|
|
93
|
+
unconvertedCurrencies: string[];
|
|
94
|
+
/**
|
|
95
|
+
* The refund credit `balance` sets aside: the credit notes of refunds on orders not yet
|
|
96
|
+
* invoiced, which those orders' own figure already reflects. 0 on an ERP balance. Say "credit
|
|
97
|
+
* from refunds on orders not yet invoiced is left out" when this is above 0; never infer it
|
|
98
|
+
* from two balances.
|
|
99
|
+
*/
|
|
100
|
+
setAsideMinor: number;
|
|
101
|
+
/**
|
|
102
|
+
* The ledger's balance in every currency, read in the SAME request as the status, so the two
|
|
103
|
+
* can be compared without a payment or invoice recorded in between.
|
|
104
|
+
*/
|
|
105
|
+
ledgerBalances: CurrencyBalance[];
|
|
106
|
+
}
|
|
107
|
+
/** What a credit-account update may change. `null` clears a field. */
|
|
108
|
+
export interface UpdateCreditAccountInput {
|
|
109
|
+
creditLimit?: number | null;
|
|
110
|
+
defaultPaymentTermsDays?: number | null;
|
|
111
|
+
invoicingMode?: InvoicingMode;
|
|
112
|
+
statementDayOfMonth?: number | null;
|
|
113
|
+
erpLinked?: boolean;
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Payment terms as the store resolves them (an ERP's condition, else its own): the order's
|
|
117
|
+
* frozen-terms shape (`orders.get`) without what only an order carries.
|
|
118
|
+
*/
|
|
119
|
+
export type PaymentTerms = Omit<OrderPaymentTerms, 'resolvedAt' | 'remoteConditionCode' | 'remoteConfirmedAt' | 'remoteMismatch'>;
|
|
120
|
+
/** A customer's resolved payment terms. */
|
|
121
|
+
export interface CustomerPaymentTerms extends PaymentTerms {
|
|
122
|
+
customerId: string | null;
|
|
123
|
+
/**
|
|
124
|
+
* The due date (`YYYY-MM-DD`) an AR invoice issued today, in the store's zone, would carry
|
|
125
|
+
* under these terms, or null when they state no single due date: such an invoice is refused
|
|
126
|
+
* (`INVOICE_PAYMENT_TERMS_UNREPRESENTABLE`) unless it states its own terms. The engine's own
|
|
127
|
+
* judgement, the one `InvoiceableOrder.dueOn` gives an order's frozen terms; never re-judge it.
|
|
128
|
+
* It is the CUSTOMER's terms: an order that froze none may be invoiced under its own condition
|
|
129
|
+
* or days instead, so it does not decide alone whether such an order's invoice is refused.
|
|
130
|
+
*/
|
|
131
|
+
dueOn: string | null;
|
|
132
|
+
}
|
|
133
|
+
/** A placed order an AR invoice or statement may still bill. */
|
|
134
|
+
export interface InvoiceableOrder {
|
|
135
|
+
id: string;
|
|
136
|
+
code: string;
|
|
137
|
+
state: string;
|
|
138
|
+
currencyCode: string;
|
|
139
|
+
orderPlacedAt: string | null;
|
|
140
|
+
/** What an invoice of the order bills: its total with the goodwill rounding folded in. */
|
|
141
|
+
billableTotalWithTax: number;
|
|
142
|
+
/**
|
|
143
|
+
* The due date (`YYYY-MM-DD`) an AR invoice issued today, in the store's zone, would carry
|
|
144
|
+
* under the order's frozen terms. Null when it froze none (the invoice resolves the customer's
|
|
145
|
+
* terms when issued) or when they state no single due date (pass explicit terms to
|
|
146
|
+
* `documents.ar.generateInvoice`, or it is refused).
|
|
147
|
+
*/
|
|
148
|
+
dueOn: string | null;
|
|
149
|
+
paymentTerms: OrderPaymentTerms | null;
|
|
150
|
+
}
|
|
151
|
+
export interface DefaultPaymentTermsModule {
|
|
152
|
+
/**
|
|
153
|
+
* The store's fallback payment terms in days, used only for a customer no ERP governs and
|
|
154
|
+
* whose account has none; null when the store has configured none. Needs `ReadSettings`.
|
|
155
|
+
*
|
|
156
|
+
* @effect read
|
|
157
|
+
* @permission ReadSettings
|
|
158
|
+
*/
|
|
159
|
+
get(options?: Call): Promise<{
|
|
160
|
+
defaultPaymentTermsDays: number | null;
|
|
161
|
+
}>;
|
|
162
|
+
/**
|
|
163
|
+
* Set the store's fallback payment terms, 0 to 365 days, or clear them with null. Needs
|
|
164
|
+
* `UpdateSettings`.
|
|
165
|
+
*
|
|
166
|
+
* @effect write
|
|
167
|
+
* @permission UpdateSettings
|
|
168
|
+
*/
|
|
169
|
+
set(defaultPaymentTermsDays: number | null, options?: Call): Promise<{
|
|
170
|
+
defaultPaymentTermsDays: number | null;
|
|
171
|
+
}>;
|
|
172
|
+
}
|
|
173
|
+
export interface CustomerCreditSettingsModule {
|
|
174
|
+
/**
|
|
175
|
+
* Whether the active store keeps an accounts-receivable ledger. Writing the switch is the
|
|
176
|
+
* store settings' (ruling G80: a later `.set()`).
|
|
177
|
+
*
|
|
178
|
+
* @effect read
|
|
179
|
+
*/
|
|
180
|
+
get(options?: Call): Promise<CustomerCreditSettings>;
|
|
181
|
+
}
|
|
182
|
+
export interface CustomerCreditModule {
|
|
183
|
+
settings: CustomerCreditSettingsModule;
|
|
184
|
+
/**
|
|
185
|
+
* The customer's stored credit-account settings, or null when none were ever saved. Needs
|
|
186
|
+
* `ReadOrder`.
|
|
187
|
+
*
|
|
188
|
+
* @effect read
|
|
189
|
+
* @permission ReadOrder
|
|
190
|
+
*/
|
|
191
|
+
account(customerId: string, options?: Call): Promise<CreditAccount | null>;
|
|
192
|
+
/**
|
|
193
|
+
* The customer's position as the ledger states it: the balance in the account's currency and
|
|
194
|
+
* in every other, the limit, the terms and the invoice counts. Needs `ReadOrder`. The SDK
|
|
195
|
+
* caches nothing: every call reads the ledger as it is.
|
|
196
|
+
*
|
|
197
|
+
* @effect read
|
|
198
|
+
* @permission ReadOrder
|
|
199
|
+
*/
|
|
200
|
+
summary(customerId: string, options?: Call): Promise<CreditAccountSummary>;
|
|
201
|
+
/**
|
|
202
|
+
* The customer's credit status (exposure against the limit), with the ledger's balances read
|
|
203
|
+
* in the same request (`ledgerBalances`). Needs `ReadOrder`.
|
|
204
|
+
*
|
|
205
|
+
* Refused `EXCHANGE_RATE_UNAVAILABLE` (→ `BusinessRuleError`) when the customer has a credit
|
|
206
|
+
* limit and owes money in a currency with no exchange rate to the account's. An engine older
|
|
207
|
+
* than `setAsideMinor` fails the document's validation.
|
|
208
|
+
*
|
|
209
|
+
* @effect read
|
|
210
|
+
* @permission ReadOrder
|
|
211
|
+
*/
|
|
212
|
+
status(customerId: string, options?: Call): Promise<CreditStatus>;
|
|
213
|
+
/**
|
|
214
|
+
* Create or change the customer's credit account: limit, terms, invoicing mode, statement
|
|
215
|
+
* day, ERP link. Needs `UpdateOrder`. `AR_LEDGER_NOT_ENABLED`, `CUSTOMER_NOT_FOUND`.
|
|
216
|
+
*
|
|
217
|
+
* A credit limit moves no money; the AI tools treat it as an ordinary write (ruling Q2,
|
|
218
|
+
* flagged for the orchestrator).
|
|
219
|
+
*
|
|
220
|
+
* @effect write
|
|
221
|
+
* @permission UpdateOrder
|
|
222
|
+
*/
|
|
223
|
+
update(customerId: string, input: UpdateCreditAccountInput, options?: Call): Promise<CreditAccount>;
|
|
224
|
+
/**
|
|
225
|
+
* The customer's resolved payment terms (an ERP's condition, the account's own, else the
|
|
226
|
+
* store's default), or null when nothing resolves, with the due date an AR invoice issued today
|
|
227
|
+
* would carry under them (`dueOn`, null when they give none). Needs `ReadCustomer`.
|
|
228
|
+
* `CUSTOMER_NOT_FOUND`. An engine older than `dueOn` is asked again without it, and the
|
|
229
|
+
* answer carries `dueOn: null`.
|
|
230
|
+
*
|
|
231
|
+
* @effect read
|
|
232
|
+
* @permission ReadCustomer
|
|
233
|
+
*/
|
|
234
|
+
paymentTerms(customerId: string, options?: Call): Promise<CustomerPaymentTerms | null>;
|
|
235
|
+
defaultPaymentTerms: DefaultPaymentTermsModule;
|
|
236
|
+
/**
|
|
237
|
+
* The customer's orders `documents.ar.generateInvoice` would invoice: no LIVE invoice bills them
|
|
238
|
+
* yet, on either ledger, newest placement first, paged (`limit` up to 100; walk the pages for
|
|
239
|
+
* the rest). An order is billed by one ledger, so an order a live store invoice bills is not
|
|
240
|
+
* listed. An order whose only invoice was voided is listed; a draft, a cart or a cancelled order
|
|
241
|
+
* is not, as the invoice door refuses it (`INVOICE_ORDER_STATE_BLOCKS_ISSUE`; an older engine
|
|
242
|
+
* listed a cancelled one and a store-invoiced one). Every state the door invoices is listed,
|
|
243
|
+
* a parked order included (an older engine left out every order not yet placed). Each says
|
|
244
|
+
* what its invoice would bill and the due date it would carry. Needs `ReadOrder`.
|
|
245
|
+
* `CUSTOMER_NOT_FOUND`. An engine older than this method fails the document's validation.
|
|
246
|
+
*
|
|
247
|
+
* @effect read
|
|
248
|
+
* @permission ReadOrder
|
|
249
|
+
*/
|
|
250
|
+
invoiceableOrders(customerId: string, options?: ListOptions): Promise<Page<InvoiceableOrder>>;
|
|
251
|
+
}
|
|
252
|
+
export declare const CUSTOMER_CREDIT_SETTINGS_QUERY = "\n query CustomerCreditSettings {\n activeChannel {\n id\n defaultCurrencyCode\n customFields {\n b2bCreditEnabled\n }\n }\n }\n";
|
|
253
|
+
export declare const CREDIT_ACCOUNT_QUERY = "\n query B2bCreditAccount($customerId: ID!) {\n b2bCreditAccount(customerId: $customerId) { \n id\n customerId\n creditLimit\n defaultPaymentTermsDays\n invoicingMode\n statementDayOfMonth\n erpLinked\n currencyCode\n externalInvoicesSyncedAt\n externalInvoicesSyncError\n createdAt\n updatedAt\n }\n }\n";
|
|
254
|
+
export declare const CREDIT_ACCOUNT_SUMMARY_QUERY = "\n query B2bCreditAccountSummary($customerId: ID!) {\n b2bCreditAccountSummary(customerId: $customerId) {\n customerId\n currencyCode\n balance\n balances {\n currencyCode\n balance\n }\n creditLimit\n defaultPaymentTermsDays\n invoicingMode\n erpLinked\n openInvoiceCount\n overdueInvoiceCount\n }\n }\n";
|
|
255
|
+
export declare const CREDIT_STATUS_QUERY = "\n query B2bCreditStatus($customerId: ID!) {\n b2bCreditStatus(customerId: $customerId) {\n customerId\n currencyCode\n balance\n uninvoicedOrdersTotal\n exposure\n creditLimit\n available\n overdueInvoiceCount\n overLimit\n hasOverdue\n balanceSource\n exposureByCurrency {\n currencyCode\n balance\n uninvoicedOrdersTotal\n }\n unconvertedCurrencies\n setAsideMinor\n }\n # The ledger as of this same request, so the two answers are one moment's.\n ledger: b2bCreditAccountSummary(customerId: $customerId) {\n balances {\n currencyCode\n balance\n }\n }\n }\n";
|
|
256
|
+
export declare const UPDATE_CREDIT_ACCOUNT_MUTATION = "\n mutation UpdateB2bCreditAccount($customerId: ID!, $input: UpdateB2bCreditAccountInput!) {\n updateB2bCreditAccount(customerId: $customerId, input: $input) { \n id\n customerId\n creditLimit\n defaultPaymentTermsDays\n invoicingMode\n statementDayOfMonth\n erpLinked\n currencyCode\n externalInvoicesSyncedAt\n externalInvoicesSyncError\n createdAt\n updatedAt\n }\n }\n";
|
|
257
|
+
export declare const CUSTOMER_PAYMENT_TERMS_QUERY = "\n query CustomerPaymentTerms($customerId: ID!) {\n customerPaymentTerms(customerId: $customerId) {\n customerId\n \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 dueOn\n }\n }\n";
|
|
258
|
+
/** {@link CUSTOMER_PAYMENT_TERMS_QUERY} for an engine older than `dueOn`. */
|
|
259
|
+
export declare const CUSTOMER_PAYMENT_TERMS_LEGACY_QUERY = "\n query CustomerPaymentTerms($customerId: ID!) {\n customerPaymentTerms(customerId: $customerId) {\n customerId\n \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 }\n }\n";
|
|
260
|
+
export declare const DEFAULT_PAYMENT_TERMS_QUERY = "\n query ChannelPaymentTermsDefault {\n channelPaymentTermsDefault {\n defaultPaymentTermsDays\n }\n }\n";
|
|
261
|
+
export declare const SET_DEFAULT_PAYMENT_TERMS_MUTATION = "\n mutation SetChannelPaymentTermsDefault($input: SetChannelPaymentTermsDefaultInput!) {\n setChannelPaymentTermsDefault(input: $input) {\n defaultPaymentTermsDays\n }\n }\n";
|
|
262
|
+
export declare const INVOICEABLE_ORDERS_QUERY = "\n query ArInvoiceableOrders($customerId: ID!, $options: ArListOptions) {\n arInvoiceableOrders(customerId: $customerId, options: $options) {\n items {\n id\n code\n state\n currencyCode\n orderPlacedAt\n billableTotalWithTax\n dueOn\n paymentTerms {\n \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 resolvedAt\n remoteConditionCode\n remoteConfirmedAt\n remoteMismatch\n }\n }\n totalItems\n }\n }\n";
|
|
263
|
+
export declare function createCustomerCreditModule(transport: Transport): CustomerCreditModule;
|
|
@@ -0,0 +1,244 @@
|
|
|
1
|
+
import { pageFromVendureList, readOffsetCursor, ValidationError, } from '@sixtyninecommerce/core';
|
|
2
|
+
const ACCOUNT_FIELDS = /* GraphQL */ `
|
|
3
|
+
id
|
|
4
|
+
customerId
|
|
5
|
+
creditLimit
|
|
6
|
+
defaultPaymentTermsDays
|
|
7
|
+
invoicingMode
|
|
8
|
+
statementDayOfMonth
|
|
9
|
+
erpLinked
|
|
10
|
+
currencyCode
|
|
11
|
+
externalInvoicesSyncedAt
|
|
12
|
+
externalInvoicesSyncError
|
|
13
|
+
createdAt
|
|
14
|
+
updatedAt
|
|
15
|
+
`;
|
|
16
|
+
const PAYMENT_TERMS_FIELDS = /* GraphQL */ `
|
|
17
|
+
source
|
|
18
|
+
managedExternally
|
|
19
|
+
status
|
|
20
|
+
conditionCode
|
|
21
|
+
conditionDescription
|
|
22
|
+
summary
|
|
23
|
+
classification
|
|
24
|
+
paymentDays
|
|
25
|
+
paymentEndOfMonths
|
|
26
|
+
paymentMethod
|
|
27
|
+
percentage
|
|
28
|
+
discountPaymentDays
|
|
29
|
+
discountPercentage
|
|
30
|
+
paymentDiscountType
|
|
31
|
+
stale
|
|
32
|
+
syncedAt
|
|
33
|
+
error
|
|
34
|
+
`;
|
|
35
|
+
export const CUSTOMER_CREDIT_SETTINGS_QUERY = /* GraphQL */ `
|
|
36
|
+
query CustomerCreditSettings {
|
|
37
|
+
activeChannel {
|
|
38
|
+
id
|
|
39
|
+
defaultCurrencyCode
|
|
40
|
+
customFields {
|
|
41
|
+
b2bCreditEnabled
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
`;
|
|
46
|
+
export const CREDIT_ACCOUNT_QUERY = /* GraphQL */ `
|
|
47
|
+
query B2bCreditAccount($customerId: ID!) {
|
|
48
|
+
b2bCreditAccount(customerId: $customerId) { ${ACCOUNT_FIELDS} }
|
|
49
|
+
}
|
|
50
|
+
`;
|
|
51
|
+
export const CREDIT_ACCOUNT_SUMMARY_QUERY = /* GraphQL */ `
|
|
52
|
+
query B2bCreditAccountSummary($customerId: ID!) {
|
|
53
|
+
b2bCreditAccountSummary(customerId: $customerId) {
|
|
54
|
+
customerId
|
|
55
|
+
currencyCode
|
|
56
|
+
balance
|
|
57
|
+
balances {
|
|
58
|
+
currencyCode
|
|
59
|
+
balance
|
|
60
|
+
}
|
|
61
|
+
creditLimit
|
|
62
|
+
defaultPaymentTermsDays
|
|
63
|
+
invoicingMode
|
|
64
|
+
erpLinked
|
|
65
|
+
openInvoiceCount
|
|
66
|
+
overdueInvoiceCount
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
`;
|
|
70
|
+
export const CREDIT_STATUS_QUERY = /* GraphQL */ `
|
|
71
|
+
query B2bCreditStatus($customerId: ID!) {
|
|
72
|
+
b2bCreditStatus(customerId: $customerId) {
|
|
73
|
+
customerId
|
|
74
|
+
currencyCode
|
|
75
|
+
balance
|
|
76
|
+
uninvoicedOrdersTotal
|
|
77
|
+
exposure
|
|
78
|
+
creditLimit
|
|
79
|
+
available
|
|
80
|
+
overdueInvoiceCount
|
|
81
|
+
overLimit
|
|
82
|
+
hasOverdue
|
|
83
|
+
balanceSource
|
|
84
|
+
exposureByCurrency {
|
|
85
|
+
currencyCode
|
|
86
|
+
balance
|
|
87
|
+
uninvoicedOrdersTotal
|
|
88
|
+
}
|
|
89
|
+
unconvertedCurrencies
|
|
90
|
+
setAsideMinor
|
|
91
|
+
}
|
|
92
|
+
# The ledger as of this same request, so the two answers are one moment's.
|
|
93
|
+
ledger: b2bCreditAccountSummary(customerId: $customerId) {
|
|
94
|
+
balances {
|
|
95
|
+
currencyCode
|
|
96
|
+
balance
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
`;
|
|
101
|
+
export const UPDATE_CREDIT_ACCOUNT_MUTATION = /* GraphQL */ `
|
|
102
|
+
mutation UpdateB2bCreditAccount($customerId: ID!, $input: UpdateB2bCreditAccountInput!) {
|
|
103
|
+
updateB2bCreditAccount(customerId: $customerId, input: $input) { ${ACCOUNT_FIELDS} }
|
|
104
|
+
}
|
|
105
|
+
`;
|
|
106
|
+
export const CUSTOMER_PAYMENT_TERMS_QUERY = /* GraphQL */ `
|
|
107
|
+
query CustomerPaymentTerms($customerId: ID!) {
|
|
108
|
+
customerPaymentTerms(customerId: $customerId) {
|
|
109
|
+
customerId
|
|
110
|
+
${PAYMENT_TERMS_FIELDS}
|
|
111
|
+
dueOn
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
`;
|
|
115
|
+
/** {@link CUSTOMER_PAYMENT_TERMS_QUERY} for an engine older than `dueOn`. */
|
|
116
|
+
export const CUSTOMER_PAYMENT_TERMS_LEGACY_QUERY = /* GraphQL */ `
|
|
117
|
+
query CustomerPaymentTerms($customerId: ID!) {
|
|
118
|
+
customerPaymentTerms(customerId: $customerId) {
|
|
119
|
+
customerId
|
|
120
|
+
${PAYMENT_TERMS_FIELDS}
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
`;
|
|
124
|
+
/**
|
|
125
|
+
* Whether a failure is "this engine does not know that field yet": the document refused before
|
|
126
|
+
* it ran, never an execution-time refusal or a transient failure (the purchasing module's rule).
|
|
127
|
+
*/
|
|
128
|
+
function isUnknownFieldRejection(error) {
|
|
129
|
+
if (!(error instanceof ValidationError) || error.service !== 'vendure')
|
|
130
|
+
return false;
|
|
131
|
+
return (error.code === 'BAD_REQUEST' ||
|
|
132
|
+
error.code === 'GRAPHQL_VALIDATION_FAILED' ||
|
|
133
|
+
/Cannot query field/i.test(error.message));
|
|
134
|
+
}
|
|
135
|
+
export const DEFAULT_PAYMENT_TERMS_QUERY = /* GraphQL */ `
|
|
136
|
+
query ChannelPaymentTermsDefault {
|
|
137
|
+
channelPaymentTermsDefault {
|
|
138
|
+
defaultPaymentTermsDays
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
`;
|
|
142
|
+
export const SET_DEFAULT_PAYMENT_TERMS_MUTATION = /* GraphQL */ `
|
|
143
|
+
mutation SetChannelPaymentTermsDefault($input: SetChannelPaymentTermsDefaultInput!) {
|
|
144
|
+
setChannelPaymentTermsDefault(input: $input) {
|
|
145
|
+
defaultPaymentTermsDays
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
`;
|
|
149
|
+
export const INVOICEABLE_ORDERS_QUERY = /* GraphQL */ `
|
|
150
|
+
query ArInvoiceableOrders($customerId: ID!, $options: ArListOptions) {
|
|
151
|
+
arInvoiceableOrders(customerId: $customerId, options: $options) {
|
|
152
|
+
items {
|
|
153
|
+
id
|
|
154
|
+
code
|
|
155
|
+
state
|
|
156
|
+
currencyCode
|
|
157
|
+
orderPlacedAt
|
|
158
|
+
billableTotalWithTax
|
|
159
|
+
dueOn
|
|
160
|
+
paymentTerms {
|
|
161
|
+
${PAYMENT_TERMS_FIELDS}
|
|
162
|
+
resolvedAt
|
|
163
|
+
remoteConditionCode
|
|
164
|
+
remoteConfirmedAt
|
|
165
|
+
remoteMismatch
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
totalItems
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
`;
|
|
172
|
+
/** The engine caps an AR list page at 100 (`clampTake`). */
|
|
173
|
+
const AR_PAGE_LIMIT = 100;
|
|
174
|
+
const INVOICEABLE_PAGE_SIZE = 25;
|
|
175
|
+
export function createCustomerCreditModule(transport) {
|
|
176
|
+
const invoiceablePage = async (customerId, skip, take, options) => {
|
|
177
|
+
const data = await transport.graphql({
|
|
178
|
+
api: 'admin',
|
|
179
|
+
query: INVOICEABLE_ORDERS_QUERY,
|
|
180
|
+
variables: { customerId, options: { skip, take } },
|
|
181
|
+
}, options);
|
|
182
|
+
return pageFromVendureList(data.arInvoiceableOrders, skip, take, (cursor) => invoiceablePage(customerId, readOffsetCursor(cursor), take, options));
|
|
183
|
+
};
|
|
184
|
+
return {
|
|
185
|
+
settings: {
|
|
186
|
+
async get(options) {
|
|
187
|
+
const data = await transport.graphql({ api: 'admin', query: CUSTOMER_CREDIT_SETTINGS_QUERY }, options);
|
|
188
|
+
return {
|
|
189
|
+
enabled: data.activeChannel.customFields?.b2bCreditEnabled === true,
|
|
190
|
+
defaultCurrencyCode: data.activeChannel.defaultCurrencyCode,
|
|
191
|
+
};
|
|
192
|
+
},
|
|
193
|
+
},
|
|
194
|
+
async account(customerId, options) {
|
|
195
|
+
const data = await transport.graphql({ api: 'admin', query: CREDIT_ACCOUNT_QUERY, variables: { customerId } }, options);
|
|
196
|
+
return data.b2bCreditAccount;
|
|
197
|
+
},
|
|
198
|
+
async summary(customerId, options) {
|
|
199
|
+
const data = await transport.graphql({ api: 'admin', query: CREDIT_ACCOUNT_SUMMARY_QUERY, variables: { customerId } }, options);
|
|
200
|
+
return data.b2bCreditAccountSummary;
|
|
201
|
+
},
|
|
202
|
+
async status(customerId, options) {
|
|
203
|
+
const data = await transport.graphql({ api: 'admin', query: CREDIT_STATUS_QUERY, variables: { customerId } }, options);
|
|
204
|
+
return { ...data.b2bCreditStatus, ledgerBalances: data.ledger.balances };
|
|
205
|
+
},
|
|
206
|
+
async update(customerId, input, options) {
|
|
207
|
+
const data = await transport.graphql({ api: 'admin', query: UPDATE_CREDIT_ACCOUNT_MUTATION, variables: { customerId, input } }, options);
|
|
208
|
+
return data.updateB2bCreditAccount;
|
|
209
|
+
},
|
|
210
|
+
async paymentTerms(customerId, options) {
|
|
211
|
+
try {
|
|
212
|
+
const data = await transport.graphql({ api: 'admin', query: CUSTOMER_PAYMENT_TERMS_QUERY, variables: { customerId } }, options);
|
|
213
|
+
return data.customerPaymentTerms;
|
|
214
|
+
}
|
|
215
|
+
catch (error) {
|
|
216
|
+
// An engine older than `dueOn` refuses the whole document; the terms are still readable.
|
|
217
|
+
if (!isUnknownFieldRejection(error))
|
|
218
|
+
throw error;
|
|
219
|
+
const data = await transport.graphql({ api: 'admin', query: CUSTOMER_PAYMENT_TERMS_LEGACY_QUERY, variables: { customerId } }, options);
|
|
220
|
+
return data.customerPaymentTerms ? { ...data.customerPaymentTerms, dueOn: null } : null;
|
|
221
|
+
}
|
|
222
|
+
},
|
|
223
|
+
defaultPaymentTerms: {
|
|
224
|
+
async get(options) {
|
|
225
|
+
const data = await transport.graphql({ api: 'admin', query: DEFAULT_PAYMENT_TERMS_QUERY }, options);
|
|
226
|
+
return data.channelPaymentTermsDefault;
|
|
227
|
+
},
|
|
228
|
+
async set(defaultPaymentTermsDays, options) {
|
|
229
|
+
const data = await transport.graphql({
|
|
230
|
+
api: 'admin',
|
|
231
|
+
query: SET_DEFAULT_PAYMENT_TERMS_MUTATION,
|
|
232
|
+
variables: { input: { defaultPaymentTermsDays } },
|
|
233
|
+
}, options);
|
|
234
|
+
return data.setChannelPaymentTermsDefault;
|
|
235
|
+
},
|
|
236
|
+
},
|
|
237
|
+
invoiceableOrders(customerId, options) {
|
|
238
|
+
// The Admin API is offset-paged; the offset hides inside the cursor (spec §9.3).
|
|
239
|
+
const take = Math.min(options?.limit ?? INVOICEABLE_PAGE_SIZE, AR_PAGE_LIMIT);
|
|
240
|
+
const skip = options?.after === undefined ? 0 : readOffsetCursor(options.after);
|
|
241
|
+
return invoiceablePage(customerId, skip, take, options);
|
|
242
|
+
},
|
|
243
|
+
};
|
|
244
|
+
}
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A customer's saved delivery preferences (headless spec §9.2 `customers` "delivery
|
|
3
|
+
* preferences"; W10-33): reusable values for one fulfilment handler's form, which the
|
|
4
|
+
* create-fulfilment flow pre-fills from.
|
|
5
|
+
*/
|
|
6
|
+
import type { Transport } from '@sixtyninecommerce/core';
|
|
7
|
+
import type { Call } from '../types.js';
|
|
8
|
+
export interface CustomerDeliveryPreference {
|
|
9
|
+
id: string;
|
|
10
|
+
/** ISO-8601 with offset. */
|
|
11
|
+
createdAt: string;
|
|
12
|
+
/** ISO-8601 with offset. */
|
|
13
|
+
updatedAt: string;
|
|
14
|
+
/** The fulfilment handler the values are for (`manual-fulfillment`, a carrier's code, …). */
|
|
15
|
+
fulfillmentHandlerCode: string;
|
|
16
|
+
name: string;
|
|
17
|
+
/** The handler's fields by name, as its schema declares them; stored and answered verbatim. */
|
|
18
|
+
values: Record<string, unknown>;
|
|
19
|
+
/** At most one preference per customer and handler is the default. */
|
|
20
|
+
isDefault: boolean;
|
|
21
|
+
/**
|
|
22
|
+
* Set when the caller's customer-data level blanked `name` and `values` (an app installation
|
|
23
|
+
* below `full`): they then mean "not granted". Never write such a preference back.
|
|
24
|
+
*/
|
|
25
|
+
redacted?: true;
|
|
26
|
+
}
|
|
27
|
+
export interface CreateDeliveryPreferenceInput {
|
|
28
|
+
customerId: string;
|
|
29
|
+
fulfillmentHandlerCode: string;
|
|
30
|
+
/** 1 to 255 characters after trimming. */
|
|
31
|
+
name: string;
|
|
32
|
+
values: Record<string, unknown>;
|
|
33
|
+
/** Making one the default takes the mark off the customer's other one for the handler. */
|
|
34
|
+
isDefault?: boolean;
|
|
35
|
+
}
|
|
36
|
+
export interface UpdateDeliveryPreferenceInput {
|
|
37
|
+
name?: string;
|
|
38
|
+
/** Replaces the stored values as a whole. */
|
|
39
|
+
values?: Record<string, unknown>;
|
|
40
|
+
isDefault?: boolean;
|
|
41
|
+
}
|
|
42
|
+
/** One selectable value of a select field. */
|
|
43
|
+
export interface DeliveryPreferenceFieldOption {
|
|
44
|
+
value: string;
|
|
45
|
+
label: string;
|
|
46
|
+
}
|
|
47
|
+
/** One field of a fulfilment handler's delivery preference form. */
|
|
48
|
+
export interface DeliveryPreferenceField {
|
|
49
|
+
/** The key the value is stored under in a preference's `values`. */
|
|
50
|
+
name: string;
|
|
51
|
+
/** `string`, `int` or `boolean`. */
|
|
52
|
+
type: string;
|
|
53
|
+
/** A rendering hint (`text-form-input`, `select-form-input`, `switch-form-input`, …). */
|
|
54
|
+
uiComponent: string;
|
|
55
|
+
label: string;
|
|
56
|
+
/** Present for a select field. */
|
|
57
|
+
options: DeliveryPreferenceFieldOption[] | null;
|
|
58
|
+
defaultValue: string | number | boolean | null;
|
|
59
|
+
}
|
|
60
|
+
/** The fields one fulfilment handler saves per customer. */
|
|
61
|
+
export interface DeliveryPreferenceSchema {
|
|
62
|
+
handlerCode: string;
|
|
63
|
+
fields: DeliveryPreferenceField[];
|
|
64
|
+
}
|
|
65
|
+
export interface CustomerDeliveryPreferencesModule {
|
|
66
|
+
/**
|
|
67
|
+
* The customer's delivery preferences in this store, oldest first; `[]` for a customer with
|
|
68
|
+
* none, and for one the store does not hold. `handlerCode` keeps one handler's. Needs
|
|
69
|
+
* `ReadCustomer`.
|
|
70
|
+
*
|
|
71
|
+
* @effect read
|
|
72
|
+
*/
|
|
73
|
+
list(customerId: string, options?: Call & {
|
|
74
|
+
handlerCode?: string;
|
|
75
|
+
}): Promise<CustomerDeliveryPreference[]>;
|
|
76
|
+
/**
|
|
77
|
+
* The preference form of each fulfilment handler the platform runs: which fields a
|
|
78
|
+
* preference's `values` may carry. The same for every store. Needs `ReadOrder` or
|
|
79
|
+
* `ReadCustomer`.
|
|
80
|
+
*
|
|
81
|
+
* @effect read
|
|
82
|
+
*/
|
|
83
|
+
schemas(options?: Call): Promise<DeliveryPreferenceSchema[]>;
|
|
84
|
+
/**
|
|
85
|
+
* Save a delivery preference for a customer. Needs `UpdateCustomer`.
|
|
86
|
+
*
|
|
87
|
+
* Refused with the engine's sentence (`ValidationError`, `USER_INPUT_ERROR`, 400): an empty
|
|
88
|
+
* or over-long name or handler code, or a customer that already has 50. A handler of a plugin
|
|
89
|
+
* the store does not have is `PLUGIN_ACCESS_DENIED` (`PermissionDeniedError`, 403). A customer
|
|
90
|
+
* this store does not hold is a `NotFoundError` (`ENTITY_NOT_FOUND`); an engine older than
|
|
91
|
+
* that check saved the preference under any id, where no read ever showed it.
|
|
92
|
+
*
|
|
93
|
+
* @effect write
|
|
94
|
+
*/
|
|
95
|
+
create(input: CreateDeliveryPreferenceInput, options?: Call): Promise<CustomerDeliveryPreference>;
|
|
96
|
+
/**
|
|
97
|
+
* Change a preference; what is left out is kept. Needs `UpdateCustomer`. An id that is not a
|
|
98
|
+
* preference of this store is refused with the engine's sentence (`ValidationError`,
|
|
99
|
+
* `USER_INPUT_ERROR`, 400).
|
|
100
|
+
*
|
|
101
|
+
* @effect write
|
|
102
|
+
*/
|
|
103
|
+
update(id: string, input: UpdateDeliveryPreferenceInput, options?: Call): Promise<CustomerDeliveryPreference>;
|
|
104
|
+
/**
|
|
105
|
+
* Remove a preference. Needs `UpdateCustomer`.
|
|
106
|
+
*
|
|
107
|
+
* Refused `CUSTOMER_DELIVERY_PREFERENCE_NOT_DELETED` (`ConflictError`, 409) with the engine's
|
|
108
|
+
* own reason when this store has no such preference.
|
|
109
|
+
*
|
|
110
|
+
* @effect destructive
|
|
111
|
+
*/
|
|
112
|
+
delete(id: string, options?: Call): Promise<void>;
|
|
113
|
+
}
|
|
114
|
+
export declare const DELIVERY_PREFERENCE_FIELDS = "\n id\n createdAt\n updatedAt\n fulfillmentHandlerCode\n name\n values\n isDefault\n";
|
|
115
|
+
export declare const DELIVERY_PREFERENCES_QUERY = "\n query CustomerDeliveryPreferences($id: ID!, $fulfillmentHandlerCode: String) {\n customer(id: $id) {\n id\n deliveryPreferences(fulfillmentHandlerCode: $fulfillmentHandlerCode) {\n \n id\n createdAt\n updatedAt\n fulfillmentHandlerCode\n name\n values\n isDefault\n\n }\n }\n }\n";
|
|
116
|
+
export declare const DELIVERY_PREFERENCE_SCHEMAS_QUERY = "\n query DeliveryPreferenceSchemas {\n deliveryPreferenceSchemas {\n handlerCode\n fields {\n name\n type\n uiComponent\n label\n options {\n value\n label\n }\n defaultValue\n }\n }\n }\n";
|
|
117
|
+
export declare const CREATE_DELIVERY_PREFERENCE_MUTATION = "\n mutation CreateCustomerDeliveryPreference($input: CreateCustomerDeliveryPreferenceInput!) {\n createCustomerDeliveryPreference(input: $input) {\n \n id\n createdAt\n updatedAt\n fulfillmentHandlerCode\n name\n values\n isDefault\n\n }\n }\n";
|
|
118
|
+
export declare const UPDATE_DELIVERY_PREFERENCE_MUTATION = "\n mutation UpdateCustomerDeliveryPreference($input: UpdateCustomerDeliveryPreferenceInput!) {\n updateCustomerDeliveryPreference(input: $input) {\n \n id\n createdAt\n updatedAt\n fulfillmentHandlerCode\n name\n values\n isDefault\n\n }\n }\n";
|
|
119
|
+
export declare const DELETE_DELIVERY_PREFERENCE_MUTATION = "\n mutation DeleteCustomerDeliveryPreference($id: ID!) {\n deleteCustomerDeliveryPreference(id: $id) {\n result\n message\n }\n }\n";
|
|
120
|
+
export declare function createCustomerDeliveryPreferencesModule(transport: Transport): CustomerDeliveryPreferencesModule;
|