@sixtyninecommerce/admin 0.8.0 → 0.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2739 -17
- package/dist/api-tokens/index.d.ts +15 -5
- package/dist/api-tokens/index.js +1 -0
- package/dist/apps/event-subscription.d.ts +59 -0
- package/dist/apps/event-subscription.js +32 -0
- package/dist/apps/hook-secret.d.ts +22 -0
- package/dist/apps/hook-secret.js +36 -0
- package/dist/apps/index.d.ts +54 -3
- package/dist/apps/index.js +17 -0
- package/dist/audit/index.d.ts +7 -0
- package/dist/auth/queries.d.ts +5 -1
- package/dist/auth/queries.js +6 -0
- package/dist/bulk/index.d.ts +323 -0
- package/dist/bulk/index.js +162 -0
- package/dist/catalog/assets.d.ts +147 -0
- package/dist/catalog/assets.js +164 -0
- package/dist/catalog/collections.d.ts +109 -0
- package/dist/catalog/collections.js +91 -0
- package/dist/catalog/facets.d.ts +103 -0
- package/dist/catalog/facets.js +100 -0
- package/dist/catalog/index.d.ts +115 -0
- package/dist/catalog/index.js +21 -0
- package/dist/catalog/options.d.ts +89 -0
- package/dist/catalog/options.js +88 -0
- package/dist/catalog/products-bulk.d.ts +21 -0
- package/dist/catalog/products-bulk.js +58 -0
- package/dist/catalog/products.d.ts +650 -0
- package/dist/catalog/products.js +458 -0
- package/dist/catalog/properties.d.ts +234 -0
- package/dist/catalog/properties.js +158 -0
- package/dist/catalog/types.d.ts +174 -0
- package/dist/catalog/types.js +141 -0
- package/dist/catalog/variants.d.ts +324 -0
- package/dist/catalog/variants.js +288 -0
- package/dist/catalog/visibility.d.ts +57 -0
- package/dist/catalog/visibility.js +59 -0
- package/dist/client.d.ts +192 -3
- package/dist/client.js +87 -12
- package/dist/compliance/index.d.ts +88 -0
- package/dist/compliance/index.js +88 -0
- package/dist/customer-data-redaction.d.ts +14 -0
- package/dist/customer-data-redaction.js +22 -0
- package/dist/customers/index.d.ts +428 -17
- package/dist/customers/index.js +322 -15
- package/dist/documents/index.d.ts +513 -16
- package/dist/documents/index.js +229 -3
- package/dist/events/index.d.ts +259 -0
- package/dist/events/index.js +147 -0
- package/dist/feeds/ai.d.ts +46 -0
- package/dist/feeds/ai.js +43 -0
- package/dist/feeds/categories.d.ts +50 -0
- package/dist/feeds/categories.js +56 -0
- package/dist/feeds/configs.d.ts +54 -0
- package/dist/feeds/configs.js +85 -0
- package/dist/feeds/identifier-fields.d.ts +25 -0
- package/dist/feeds/identifier-fields.js +29 -0
- package/dist/feeds/index.d.ts +54 -0
- package/dist/feeds/index.js +46 -0
- package/dist/feeds/preserve.d.ts +38 -0
- package/dist/feeds/preserve.js +74 -0
- package/dist/feeds/rules.d.ts +42 -0
- package/dist/feeds/rules.js +56 -0
- package/dist/feeds/types.d.ts +654 -0
- package/dist/feeds/types.js +135 -0
- package/dist/fulfillments/index.d.ts +437 -0
- package/dist/fulfillments/index.js +534 -0
- package/dist/heads/index.d.ts +60 -0
- package/dist/heads/index.js +45 -0
- package/dist/hooks/assignments.d.ts +90 -0
- package/dist/hooks/assignments.js +53 -0
- package/dist/hooks/index.d.ts +97 -0
- package/dist/hooks/index.js +76 -0
- package/dist/index.d.ts +95 -9
- package/dist/index.js +21 -1
- package/dist/integrations/index.d.ts +14 -0
- package/dist/integrations/index.js +9 -0
- package/dist/integrations/pipelines.d.ts +113 -0
- package/dist/integrations/pipelines.js +62 -0
- package/dist/integrations/types.d.ts +176 -0
- package/dist/integrations/types.js +8 -0
- package/dist/jobs/bulk-action-run.d.ts +74 -0
- package/dist/jobs/bulk-action-run.js +69 -0
- package/dist/locations/index.d.ts +6 -2
- package/dist/meta/index.d.ts +32 -0
- package/dist/orders/bulk.d.ts +75 -0
- package/dist/orders/bulk.js +150 -0
- package/dist/orders/commit-edit.d.ts +123 -0
- package/dist/orders/commit-edit.js +142 -0
- package/dist/orders/deposit-policy.d.ts +103 -0
- package/dist/orders/deposit-policy.js +202 -0
- package/dist/orders/get.d.ts +722 -0
- package/dist/orders/get.js +530 -0
- package/dist/orders/index.d.ts +186 -21
- package/dist/orders/index.js +57 -0
- package/dist/orders/line-price-preview.d.ts +297 -0
- package/dist/orders/line-price-preview.js +50 -0
- package/dist/orders/manual-discounts.d.ts +141 -0
- package/dist/orders/manual-discounts.js +97 -0
- package/dist/orders/manual-pricing.d.ts +192 -0
- package/dist/orders/manual-pricing.js +72 -0
- package/dist/orders/order-entry.d.ts +566 -0
- package/dist/orders/order-entry.js +129 -0
- package/dist/orders/parcel-charge.d.ts +45 -0
- package/dist/orders/parcel-charge.js +55 -0
- package/dist/orders/plan-edit.d.ts +489 -0
- package/dist/orders/plan-edit.js +93 -0
- package/dist/orders/status.d.ts +235 -0
- package/dist/orders/status.js +96 -0
- package/dist/orders/surcharges.d.ts +75 -2
- package/dist/orders/surcharges.js +110 -4
- package/dist/payments/account-credit.d.ts +171 -0
- package/dist/payments/account-credit.js +107 -0
- package/dist/payments/index.d.ts +241 -9
- package/dist/payments/index.js +92 -0
- package/dist/payments/methods.d.ts +37 -0
- package/dist/payments/methods.js +33 -0
- package/dist/platform/catalog.d.ts +148 -0
- package/dist/platform/catalog.js +74 -0
- package/dist/platform/entitlements.d.ts +111 -0
- package/dist/platform/entitlements.js +86 -0
- package/dist/platform/legal-entities.d.ts +139 -0
- package/dist/platform/legal-entities.js +126 -0
- package/dist/platform/legal-entity-numbering.d.ts +103 -0
- package/dist/platform/legal-entity-numbering.js +101 -0
- package/dist/platform/organization-membership.d.ts +80 -0
- package/dist/platform/organization-membership.js +71 -0
- package/dist/platform/organization-settings.d.ts +33 -0
- package/dist/platform/organization-settings.js +42 -0
- package/dist/platform/organization-sharing.d.ts +172 -0
- package/dist/platform/organization-sharing.js +120 -0
- package/dist/platform/organizations.d.ts +205 -0
- package/dist/platform/organizations.js +180 -0
- package/dist/platform/provision-store.d.ts +88 -8
- package/dist/platform/provision-store.js +12 -0
- package/dist/platform/reports.d.ts +46 -0
- package/dist/platform/reports.js +31 -0
- package/dist/platform/server-metrics.d.ts +58 -0
- package/dist/platform/server-metrics.js +11 -0
- package/dist/pos/index.d.ts +567 -0
- package/dist/pos/index.js +205 -0
- package/dist/pricing/index.d.ts +408 -0
- package/dist/pricing/index.js +353 -0
- package/dist/pricing/vouchers.d.ts +103 -0
- package/dist/pricing/vouchers.js +69 -0
- package/dist/provenance/index.d.ts +93 -0
- package/dist/provenance/index.js +53 -0
- package/dist/reports/index.d.ts +199 -0
- package/dist/reports/index.js +154 -0
- package/dist/returns/index.d.ts +225 -0
- package/dist/returns/index.js +160 -0
- package/dist/search/index.d.ts +99 -0
- package/dist/search/index.js +62 -0
- package/dist/shipping/parcel-count-suggestion.d.ts +52 -0
- package/dist/shipping/parcel-count-suggestion.js +73 -0
- package/dist/shipping/parcel-rule.d.ts +48 -0
- package/dist/shipping/parcel-rule.js +91 -0
- package/dist/stock/index.d.ts +166 -0
- package/dist/stock/index.js +115 -0
- package/dist/stock/transfers.d.ts +520 -0
- package/dist/stock/transfers.js +437 -0
- package/dist/stored-value/index.d.ts +154 -0
- package/dist/stored-value/index.js +130 -0
- package/dist/tenant/capabilities.d.ts +10 -0
- package/dist/tenant/entitlements.d.ts +35 -0
- package/dist/tenant/entitlements.js +15 -0
- package/dist/tenant/field-groups.d.ts +64 -0
- package/dist/tenant/field-groups.js +34 -0
- package/dist/tenant/legal-entity.d.ts +32 -0
- package/dist/tenant/legal-entity.js +41 -0
- package/dist/tenant/notifications.d.ts +148 -0
- package/dist/tenant/notifications.js +79 -0
- package/dist/tenant/retention.d.ts +10 -4
- package/dist/tenant/settings-sources.d.ts +103 -0
- package/dist/tenant/settings-sources.js +92 -0
- package/dist/types.d.ts +86 -11
- package/dist/uploads/index.d.ts +11 -7
- package/dist/users/index.d.ts +104 -0
- package/dist/users/index.js +80 -0
- package/package.json +3 -2
|
@@ -0,0 +1,489 @@
|
|
|
1
|
+
import type { Transport } from '@sixtyninecommerce/core';
|
|
2
|
+
import type { Call } from '../types.js';
|
|
3
|
+
import type { OverpaymentOption } from './surcharges.js';
|
|
4
|
+
/**
|
|
5
|
+
* How a one-time discount is stated. A whole-order discount is `PERCENTAGE` or
|
|
6
|
+
* `FIXED_AMOUNT`, never `FIXED_PRICE`.
|
|
7
|
+
*/
|
|
8
|
+
export type OrderEditDiscountType = 'PERCENTAGE' | 'FIXED_AMOUNT' | 'FIXED_PRICE';
|
|
9
|
+
/** A manual unit price. */
|
|
10
|
+
export interface OrderEditPriceOverride {
|
|
11
|
+
/**
|
|
12
|
+
* Minor units, a whole number of 0 or more, in the LINE's tax basis.
|
|
13
|
+
* `orders.previewLinePrices` answers a line's basis and converts a price
|
|
14
|
+
* stated in the other one.
|
|
15
|
+
*/
|
|
16
|
+
unitPriceOverride: number;
|
|
17
|
+
priceOverrideReason?: string | null;
|
|
18
|
+
}
|
|
19
|
+
/** A one-time discount: on one line's product, or on the whole order. */
|
|
20
|
+
export interface OrderEditDiscount {
|
|
21
|
+
discountType: OrderEditDiscountType;
|
|
22
|
+
/**
|
|
23
|
+
* A whole number. `PERCENTAGE`: basis points, 1 to 10000. `FIXED_AMOUNT` and
|
|
24
|
+
* `FIXED_PRICE`: minor units in the store's tax basis.
|
|
25
|
+
*/
|
|
26
|
+
discountValue: number;
|
|
27
|
+
/** Kept once for the order's one-time pricing. Left out keeps the stored one. */
|
|
28
|
+
reason?: string | null;
|
|
29
|
+
/**
|
|
30
|
+
* One of the store's discount reasons (`discountReasons`), by code, for THIS
|
|
31
|
+
* discount. A store that requires a reason refuses a lowered price without
|
|
32
|
+
* one: the plan answers the blocker `DISCOUNT_REASON_REQUIRED`. See
|
|
33
|
+
* {@link OrderEditDiff.discountReasonCode} for one that covers the whole edit.
|
|
34
|
+
*/
|
|
35
|
+
reasonCode?: string | null;
|
|
36
|
+
}
|
|
37
|
+
/** A surcharge, or with a negative price a discount, on the order. */
|
|
38
|
+
export interface OrderEditSurcharge {
|
|
39
|
+
description: string;
|
|
40
|
+
/** Minor units, negative for a discount, never 0. */
|
|
41
|
+
price: number;
|
|
42
|
+
priceIncludesTax: boolean;
|
|
43
|
+
/** A percentage from 0 to 100. Left out writes no tax line. */
|
|
44
|
+
taxRate?: number | null;
|
|
45
|
+
taxDescription?: string | null;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* The fields of an order address an edit may change. A field that is left out
|
|
49
|
+
* or `null` keeps what the order has.
|
|
50
|
+
*/
|
|
51
|
+
export interface OrderEditAddressPatch {
|
|
52
|
+
fullName?: string | null;
|
|
53
|
+
company?: string | null;
|
|
54
|
+
streetLine1?: string | null;
|
|
55
|
+
streetLine2?: string | null;
|
|
56
|
+
city?: string | null;
|
|
57
|
+
province?: string | null;
|
|
58
|
+
postalCode?: string | null;
|
|
59
|
+
countryCode?: string | null;
|
|
60
|
+
phoneNumber?: string | null;
|
|
61
|
+
}
|
|
62
|
+
export interface OrderEditAddress {
|
|
63
|
+
address: OrderEditAddressPatch;
|
|
64
|
+
/**
|
|
65
|
+
* Also write the address to the customer's saved addresses: the entry the
|
|
66
|
+
* order's address came from is updated, or a new one is added. Needs
|
|
67
|
+
* `UpdateCustomer` or `CreateCustomer` beside `UpdateOrder`; without it the
|
|
68
|
+
* plan answers the blocker `ORDER_EDIT_PERMISSION_REQUIRED`.
|
|
69
|
+
*/
|
|
70
|
+
applyToCustomer?: boolean | null;
|
|
71
|
+
/**
|
|
72
|
+
* `true`: the address is for this order only and is never offered as a saved
|
|
73
|
+
* address. `false`: it is not. Left out leaves the order's flag as it is.
|
|
74
|
+
* Refused together with `applyToCustomer: true`.
|
|
75
|
+
*/
|
|
76
|
+
markTemporary?: boolean | null;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* What an edit of a placed order should change, as intents. It never names the
|
|
80
|
+
* operation that carries a change out: the server decides that.
|
|
81
|
+
*
|
|
82
|
+
* Every list holds at most 500 entries, and an id appears once per list. A
|
|
83
|
+
* list that is left out, `null` or empty changes nothing, with one exception:
|
|
84
|
+
* `couponCodes` is the COMPLETE list the order should end with, so an empty
|
|
85
|
+
* list removes every coupon and only left out or `null` leaves them alone.
|
|
86
|
+
*
|
|
87
|
+
* `orderDiscount` has three states: left out keeps the stored whole-order
|
|
88
|
+
* discount, `null` removes it, a value sets it. The SDK sends the diff as
|
|
89
|
+
* given; a key set to `undefined` counts as left out.
|
|
90
|
+
*/
|
|
91
|
+
export interface OrderEditDiff {
|
|
92
|
+
/** The quantity each named line should have. 0 removes the line. */
|
|
93
|
+
adjustLines?: Array<{
|
|
94
|
+
orderLineId: string;
|
|
95
|
+
quantity: number;
|
|
96
|
+
}> | null;
|
|
97
|
+
/**
|
|
98
|
+
* Items to add, each 1 or more. An item with no stated price joins the line
|
|
99
|
+
* of its variant when the order has one; with a stated price it is a line of
|
|
100
|
+
* its own (0 makes it a free line).
|
|
101
|
+
*/
|
|
102
|
+
addItems?: Array<{
|
|
103
|
+
productVariantId: string;
|
|
104
|
+
quantity: number;
|
|
105
|
+
priceOverride?: OrderEditPriceOverride | null;
|
|
106
|
+
}> | null;
|
|
107
|
+
/** A manual unit price per named line. */
|
|
108
|
+
priceOverrides?: Array<{
|
|
109
|
+
orderLineId: string;
|
|
110
|
+
} & OrderEditPriceOverride> | null;
|
|
111
|
+
/**
|
|
112
|
+
* The one-time discount of each named line's product. An entry with
|
|
113
|
+
* `discount` left out or `null` REMOVES that line's one-time discount: an
|
|
114
|
+
* entry names the line, so there is no "leave it" inside one. Leave a line
|
|
115
|
+
* out of the list to keep what it has.
|
|
116
|
+
*/
|
|
117
|
+
lineDiscounts?: Array<{
|
|
118
|
+
orderLineId: string;
|
|
119
|
+
discount?: OrderEditDiscount | null;
|
|
120
|
+
}> | null;
|
|
121
|
+
/** The whole-order one-time discount. Three states: see {@link OrderEditDiff}. */
|
|
122
|
+
orderDiscount?: OrderEditDiscount | null;
|
|
123
|
+
/**
|
|
124
|
+
* `true` removes the tax, `false` forces the standard rate. Left out or
|
|
125
|
+
* `null` leaves the order's tax as it is.
|
|
126
|
+
*/
|
|
127
|
+
removeTax?: boolean | null;
|
|
128
|
+
addSurcharges?: OrderEditSurcharge[] | null;
|
|
129
|
+
updateSurcharges?: Array<{
|
|
130
|
+
surchargeId: string;
|
|
131
|
+
} & OrderEditSurcharge> | null;
|
|
132
|
+
removeSurchargeIds?: string[] | null;
|
|
133
|
+
shippingAddress?: OrderEditAddress | null;
|
|
134
|
+
billingAddress?: OrderEditAddress | null;
|
|
135
|
+
/** The complete list of coupon codes the order should end with. */
|
|
136
|
+
couponCodes?: string[] | null;
|
|
137
|
+
/** A note for the order's history. A note alone is not a change. */
|
|
138
|
+
note?: string | null;
|
|
139
|
+
/**
|
|
140
|
+
* The warehouse each named line should ship from. `stockLocationId` left out
|
|
141
|
+
* or `null` clears the line's pick. A pick also moves what the line reserves
|
|
142
|
+
* now.
|
|
143
|
+
*/
|
|
144
|
+
preferredLocations?: Array<{
|
|
145
|
+
orderLineId: string;
|
|
146
|
+
stockLocationId?: string | null;
|
|
147
|
+
}> | null;
|
|
148
|
+
/**
|
|
149
|
+
* How the stock a named line reserves is split over warehouses. The
|
|
150
|
+
* quantities must add up to what the line reserves; a row of 0 is dropped. A
|
|
151
|
+
* split clears the line's pick.
|
|
152
|
+
*/
|
|
153
|
+
allocationSplits?: Array<{
|
|
154
|
+
orderLineId: string;
|
|
155
|
+
allocations: Array<{
|
|
156
|
+
stockLocationId: string;
|
|
157
|
+
quantity: number;
|
|
158
|
+
}>;
|
|
159
|
+
}> | null;
|
|
160
|
+
/**
|
|
161
|
+
* One of the store's discount reasons, by code, for the edit as a whole: it
|
|
162
|
+
* covers every line whose price a manual unit price or the one-time pricing
|
|
163
|
+
* lowers and that names no reason of its own (a removed discount included).
|
|
164
|
+
* A code the store does not have, or deactivated, is the blocker
|
|
165
|
+
* `DISCOUNT_REASON_UNKNOWN`. A manual unit price lowered through the order
|
|
166
|
+
* modification (an order money was collected for) is recorded with this reason
|
|
167
|
+
* but never refused for lacking one.
|
|
168
|
+
*/
|
|
169
|
+
discountReasonCode?: string | null;
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* How one step of an edit is carried out. A plan lists its steps in the order
|
|
173
|
+
* they run. A string on the wire: an engine newer than this SDK may answer a
|
|
174
|
+
* kind this list does not have.
|
|
175
|
+
*
|
|
176
|
+
* - `CANCEL_LINES`: units are taken off lines by a partial cancellation
|
|
177
|
+
* (restocked, no refund).
|
|
178
|
+
* - `LINE_PRICE_OVERRIDES`: manual unit prices are written on the named lines.
|
|
179
|
+
* - `ONE_TIME_PRICING`: the order's one-time pricing is written to its
|
|
180
|
+
* complete desired state.
|
|
181
|
+
* - `TAX_REMOVAL`: the remove-tax flag is written and every line is re-taxed.
|
|
182
|
+
* - `MODIFY_ORDER`: the order is modified through the engine's order
|
|
183
|
+
* modification, and returns to the plan's `returnState`.
|
|
184
|
+
* - `CUSTOMER_ADDRESSES`: the customer's saved addresses and the order's links
|
|
185
|
+
* to them are written.
|
|
186
|
+
* - `SURCHARGE_UPDATE`, `SURCHARGE_REMOVE`, `SURCHARGE_ADD`: one surcharge each.
|
|
187
|
+
* - `WAREHOUSE_PREFERENCES`, `WAREHOUSE_MOVES`, `WAREHOUSE_SPLITS`: where the
|
|
188
|
+
* named lines ship from.
|
|
189
|
+
*/
|
|
190
|
+
export type OrderEditStepKind = 'CANCEL_LINES' | 'LINE_PRICE_OVERRIDES' | 'ONE_TIME_PRICING' | 'TAX_REMOVAL' | 'MODIFY_ORDER' | 'CUSTOMER_ADDRESSES' | 'SURCHARGE_UPDATE' | 'SURCHARGE_REMOVE' | 'SURCHARGE_ADD' | 'WAREHOUSE_PREFERENCES' | 'WAREHOUSE_MOVES' | 'WAREHOUSE_SPLITS' | (string & {});
|
|
191
|
+
export interface OrderEditStep {
|
|
192
|
+
kind: OrderEditStepKind;
|
|
193
|
+
/**
|
|
194
|
+
* What the step is handed: ids, quantities and the values the diff staged.
|
|
195
|
+
* Its shape follows `kind` and is for showing the step, not a contract to
|
|
196
|
+
* build on. It holds no id made up while planning, so two plans of the same
|
|
197
|
+
* edit of an unchanged order state the same input.
|
|
198
|
+
*/
|
|
199
|
+
input: Record<string, unknown>;
|
|
200
|
+
/**
|
|
201
|
+
* The change this step makes to the order's total with tax, in minor units.
|
|
202
|
+
* `null` for a step the preview did not reach because an earlier one was
|
|
203
|
+
* refused, and for every step when a blocker was found before any step ran.
|
|
204
|
+
*/
|
|
205
|
+
moneyEffect: number | null;
|
|
206
|
+
}
|
|
207
|
+
/**
|
|
208
|
+
* The refund an edit of a paid order ends with: what the edit as a whole takes
|
|
209
|
+
* off the total and a lowered surcharge does not account for, never more than
|
|
210
|
+
* the customer would then have paid beyond what the order bills (an order
|
|
211
|
+
* still owing pays that down first). A plan computes it and never asks a
|
|
212
|
+
* payment provider for anything.
|
|
213
|
+
*/
|
|
214
|
+
export interface OrderEditRefund {
|
|
215
|
+
/** The one payment that carries the whole amount. An edit never splits a refund. */
|
|
216
|
+
paymentId: string;
|
|
217
|
+
/** Minor units in the order's currency. */
|
|
218
|
+
amount: number;
|
|
219
|
+
}
|
|
220
|
+
/**
|
|
221
|
+
* What a lowered or removed surcharge leaves the customer of a PAID order
|
|
222
|
+
* overpaid by, and the two ways the merchant may settle it: `REFUND` to the
|
|
223
|
+
* customer's payment, or `ACCOUNT_CREDIT` to their account as unapplied cash.
|
|
224
|
+
* Ask the merchant, then pass the answer to `commitEdit` as
|
|
225
|
+
* `overpaymentChoice`. The edit's other cuts (item prices and quantities)
|
|
226
|
+
* refund automatically, in the plan's `refund`.
|
|
227
|
+
*/
|
|
228
|
+
export interface OrderEditOverpayment {
|
|
229
|
+
/**
|
|
230
|
+
* The surcharges' share of what the edit gives back, minor units. Never more
|
|
231
|
+
* than the edit as a whole adds to what the customer has paid beyond what
|
|
232
|
+
* the order bills: an order still owing, or one already overpaid before the
|
|
233
|
+
* edit, gets back only that.
|
|
234
|
+
*/
|
|
235
|
+
amount: number;
|
|
236
|
+
currencyCode: string;
|
|
237
|
+
/** The surcharges the edit lowers or removes. */
|
|
238
|
+
surchargeIds: string[];
|
|
239
|
+
/**
|
|
240
|
+
* Whether `REFUND` is open; when not, `code` is the refusal choosing it would
|
|
241
|
+
* answer: `REFUND_EXCEEDS_PAYMENT` (no one payment can return this amount
|
|
242
|
+
* together with the plan's `refund`), `REFUND_METHOD_UNAVAILABLE` (the
|
|
243
|
+
* payment's method can no longer be reached), `REFUND_PAYMENT_HOLDS_NO_MONEY`,
|
|
244
|
+
* or `ORDER_OVERPAYMENT_REFUND_UNRECONCILED`.
|
|
245
|
+
*/
|
|
246
|
+
refund: OverpaymentOption;
|
|
247
|
+
/**
|
|
248
|
+
* Whether `ACCOUNT_CREDIT` is open; when not, the account's own refusal:
|
|
249
|
+
* `AR_LEDGER_NOT_ENABLED`, `AR_ACCOUNT_REQUIRED`, `AR_ACCOUNT_IN_ERP` (the
|
|
250
|
+
* customer's balance is kept in the ERP: refund only),
|
|
251
|
+
* `AR_ORDER_ALREADY_INVOICED`, `ACCOUNT_CREDIT_NO_CUSTOMER`,
|
|
252
|
+
* `ACCOUNT_CREDIT_EXCEEDS_OVERPAYMENT`, `ACCOUNT_CREDIT_NOTHING_OVERPAID`, or
|
|
253
|
+
* `ORDER_OVERPAYMENT_REFUND_UNRECONCILED`.
|
|
254
|
+
*/
|
|
255
|
+
accountCredit: OverpaymentOption;
|
|
256
|
+
/**
|
|
257
|
+
* The ONE refund the edit ends with when `REFUND` is chosen: this amount and
|
|
258
|
+
* the plan's `refund` together, on one payment. `null` when `REFUND` is not
|
|
259
|
+
* open.
|
|
260
|
+
*/
|
|
261
|
+
refundWhenChosen: OrderEditRefund | null;
|
|
262
|
+
}
|
|
263
|
+
/**
|
|
264
|
+
* Why an edit cannot be carried out, as a stable code. A string on the wire. A
|
|
265
|
+
* step the preview saw refused carries the refusing operation's OWN code when
|
|
266
|
+
* it has one (for example `VARIANT_NOT_FOR_SALE_IN_CURRENCY`, or a core
|
|
267
|
+
* ErrorResult code such as `INSUFFICIENT_STOCK_ERROR`), and
|
|
268
|
+
* `ORDER_EDIT_STEP_REFUSED` when it has none.
|
|
269
|
+
*
|
|
270
|
+
* - `ORDER_EDIT_NOT_ALLOWED`: the order's state, invoice lock or lifecycle
|
|
271
|
+
* does not allow an edit. `details.reasonCode` and `details.state` say which.
|
|
272
|
+
* - `ORDER_EDIT_NOTHING_TO_CHANGE`: the diff changes nothing the order does
|
|
273
|
+
* not already have.
|
|
274
|
+
* - `ORDER_EDIT_FULFILLED_FLOOR`: a line would go below what its fulfillments
|
|
275
|
+
* hold. `details.lines` names each such line.
|
|
276
|
+
* - `ORDER_EDIT_REFUND_TARGET_MISSING`: the edit lowers the total and no
|
|
277
|
+
* payment of the order can be refunded.
|
|
278
|
+
* - `ORDER_EDIT_REFUND_EXCEEDS_PAYMENT`: the edit lowers the total by more than
|
|
279
|
+
* any one payment can still return. `details` has `amount`,
|
|
280
|
+
* `largestHeadroom` and `refundable`.
|
|
281
|
+
* - `ORDER_EDIT_OVERPAYMENT_NOT_SETTLEABLE`: a surcharge is lowered or removed
|
|
282
|
+
* on a paid order, and neither a refund nor an account credit can settle
|
|
283
|
+
* what that leaves the customer overpaid by. `details` has `amount`,
|
|
284
|
+
* `currencyCode`, and `refund` / `accountCredit` with each closed option's
|
|
285
|
+
* `code`; the plan's `overpayment` says why in words.
|
|
286
|
+
* - `ORDER_EDIT_OVERPAYMENT_CHOICE_REQUIRED`: answered only by an engine
|
|
287
|
+
* before the overpayment choice: a surcharge lowered or removed on a paid
|
|
288
|
+
* order, overpaying the customer by `details.amount`. A current engine
|
|
289
|
+
* answers `overpayment` instead, and refuses a `commitEdit` that gives no
|
|
290
|
+
* `overpaymentChoice` for it with this code.
|
|
291
|
+
* - `ORDER_EDIT_PERMISSION_REQUIRED`: the caller may edit the order and lacks
|
|
292
|
+
* `details.permission` for another write the edit includes.
|
|
293
|
+
* - `ORDER_EDIT_STEP_REFUSED`: `details.step` was refused; `message` is the
|
|
294
|
+
* refusing operation's own sentence.
|
|
295
|
+
* - `ORDER_OVERPAYMENT_REFUND_UNRECONCILED`: the edit gives money back while a
|
|
296
|
+
* refund on the order has an outcome nobody knows yet (`details.unreconciled`
|
|
297
|
+
* names each). Record the provider's answer first
|
|
298
|
+
* (`admin.payments.reconcileRefund`).
|
|
299
|
+
* - `ORDER_EDIT_PAYMENT_STATE_UNREACHABLE`: the edit leaves a paid order owing
|
|
300
|
+
* on a payment collected online, so the order must wait for the payment in
|
|
301
|
+
* `ArrangingAdditionalPayment`, and either it cannot be moved there from
|
|
302
|
+
* `details.fromState`, or the payment could not be recorded once it waits
|
|
303
|
+
* there: part of it is an existing surcharge changed or removed
|
|
304
|
+
* (`details.outsideModifications`) beside the order's modification, and
|
|
305
|
+
* `details.outstanding` and `details.unsettledModifications` would differ.
|
|
306
|
+
* When the payment could not be recorded (`details.outsideModifications` is
|
|
307
|
+
* set): if the edit's other changes (items, quantities, prices, coupons,
|
|
308
|
+
* addresses, tax, an added surcharge) also change the total, save the change or
|
|
309
|
+
* removal of the existing surcharges as an edit of its own; if they do not, an
|
|
310
|
+
* earlier edit's changes are unpaid: record what the order owes for them first.
|
|
311
|
+
*/
|
|
312
|
+
export type OrderEditBlockerCode = 'ORDER_EDIT_NOT_ALLOWED' | 'ORDER_EDIT_NOTHING_TO_CHANGE' | 'ORDER_EDIT_FULFILLED_FLOOR' | 'ORDER_EDIT_REFUND_TARGET_MISSING' | 'ORDER_EDIT_REFUND_EXCEEDS_PAYMENT' | 'ORDER_EDIT_OVERPAYMENT_CHOICE_REQUIRED' | 'ORDER_EDIT_OVERPAYMENT_NOT_SETTLEABLE' | 'ORDER_EDIT_PERMISSION_REQUIRED' | 'ORDER_EDIT_STEP_REFUSED' | 'ORDER_OVERPAYMENT_REFUND_UNRECONCILED' | 'ORDER_EDIT_PAYMENT_STATE_UNREACHABLE' | (string & {});
|
|
313
|
+
export interface OrderEditBlocker {
|
|
314
|
+
/** Map this to your own wording. */
|
|
315
|
+
code: OrderEditBlockerCode;
|
|
316
|
+
/** The platform's sentence, written for a merchant. */
|
|
317
|
+
message: string;
|
|
318
|
+
details: Record<string, unknown> | null;
|
|
319
|
+
}
|
|
320
|
+
/**
|
|
321
|
+
* Something the merchant should know that does not stop the edit. A string on
|
|
322
|
+
* the wire.
|
|
323
|
+
*
|
|
324
|
+
* - `ORDER_EDIT_TAX_UNCHANGED`: the tax choice already matches the order's tax.
|
|
325
|
+
* - `ORDER_EDIT_CUSTOMER_ADDRESS_NOT_SAVED`: the order's address is updated,
|
|
326
|
+
* and the customer's saved address is not, because the address is incomplete.
|
|
327
|
+
* - `ORDER_EDIT_PAYMENT_OWED`: the edit raises a paid order's total on a credit
|
|
328
|
+
* or manual payment. The order stays paid and the customer owes
|
|
329
|
+
* `details.amount`, collected by hand or billed.
|
|
330
|
+
* - `ORDER_EDIT_ADDITIONAL_PAYMENT_REQUIRED`: the edit raises a paid order's
|
|
331
|
+
* total on a payment collected online (a card, a POS terminal, a method the
|
|
332
|
+
* store no longer has). The order waits in `ArrangingAdditionalPayment`, and
|
|
333
|
+
* cannot ship, until `details.amount` is paid.
|
|
334
|
+
*/
|
|
335
|
+
export type OrderEditNoticeCode = 'ORDER_EDIT_TAX_UNCHANGED' | 'ORDER_EDIT_CUSTOMER_ADDRESS_NOT_SAVED' | 'ORDER_EDIT_PAYMENT_OWED' | 'ORDER_EDIT_ADDITIONAL_PAYMENT_REQUIRED' | (string & {});
|
|
336
|
+
export interface OrderEditNotice {
|
|
337
|
+
code: OrderEditNoticeCode;
|
|
338
|
+
message: string;
|
|
339
|
+
details: Record<string, unknown> | null;
|
|
340
|
+
}
|
|
341
|
+
/** Whether money was collected for the order, which decides how its total may be lowered. */
|
|
342
|
+
export interface OrderEditPayment {
|
|
343
|
+
collected: boolean;
|
|
344
|
+
/**
|
|
345
|
+
* Why it counts as collected: `settled`, `gateway-hold`, or
|
|
346
|
+
* `unresolved-method` (an authorized payment whose method is no longer on
|
|
347
|
+
* the store). `null` when nothing was collected.
|
|
348
|
+
*/
|
|
349
|
+
reason: 'settled' | 'gateway-hold' | 'unresolved-method' | (string & {}) | null;
|
|
350
|
+
/** The payment method the reason is about, when it has one. */
|
|
351
|
+
method: string | null;
|
|
352
|
+
}
|
|
353
|
+
export interface OrderEditTaxSummaryLine {
|
|
354
|
+
description: string;
|
|
355
|
+
/** A percentage. */
|
|
356
|
+
taxRate: number;
|
|
357
|
+
taxBase: number;
|
|
358
|
+
taxTotal: number;
|
|
359
|
+
}
|
|
360
|
+
/**
|
|
361
|
+
* The order's totals after the edit, as the pricing engine computes them.
|
|
362
|
+
* Every figure is minor units in `currencyCode`.
|
|
363
|
+
*/
|
|
364
|
+
export interface OrderEditPreview {
|
|
365
|
+
currencyCode: string;
|
|
366
|
+
/** Lines and surcharges, net. */
|
|
367
|
+
subTotal: number;
|
|
368
|
+
subTotalWithTax: number;
|
|
369
|
+
shipping: number;
|
|
370
|
+
shippingWithTax: number;
|
|
371
|
+
/** The order's surcharges, net. Already part of `subTotal`. */
|
|
372
|
+
surcharges: number;
|
|
373
|
+
surchargesWithTax: number;
|
|
374
|
+
total: number;
|
|
375
|
+
totalWithTax: number;
|
|
376
|
+
taxSummary: OrderEditTaxSummaryLine[];
|
|
377
|
+
/** The order's total with tax before the edit. */
|
|
378
|
+
totalWithTaxBefore: number;
|
|
379
|
+
}
|
|
380
|
+
export interface OrderEditPlan {
|
|
381
|
+
orderId: string;
|
|
382
|
+
/**
|
|
383
|
+
* Names this plan of this edit of the order as it stands. `commitEdit` is
|
|
384
|
+
* handed it and refuses (`ORDER_EDIT_PLAN_CONFLICT`) a plan that moved.
|
|
385
|
+
*/
|
|
386
|
+
planHash: string;
|
|
387
|
+
/**
|
|
388
|
+
* Names the order as the plan read it. It moves when anything a plan depends
|
|
389
|
+
* on moves, and stays for a change a plan does not read (a note, for one).
|
|
390
|
+
*/
|
|
391
|
+
orderVersion: string;
|
|
392
|
+
steps: OrderEditStep[];
|
|
393
|
+
/**
|
|
394
|
+
* The refund the edit ends with when nothing is chosen into it: what it
|
|
395
|
+
* gives back automatically (item prices and quantities cut). With an
|
|
396
|
+
* `overpayment` settled by `REFUND`, the edit ends with
|
|
397
|
+
* `overpayment.refundWhenChosen` instead.
|
|
398
|
+
*/
|
|
399
|
+
refund: OrderEditRefund | null;
|
|
400
|
+
/**
|
|
401
|
+
* On a paid order whose edit lowers or removes a surcharge: what that leaves
|
|
402
|
+
* the customer overpaid by, and how it may be settled. `commitEdit` needs
|
|
403
|
+
* `overpaymentChoice` for it. `null` when there is nothing to choose.
|
|
404
|
+
*/
|
|
405
|
+
overpayment: OrderEditOverpayment | null;
|
|
406
|
+
/**
|
|
407
|
+
* The state the order is left in: the one it returns to after a
|
|
408
|
+
* `MODIFY_ORDER` step, or `ArrangingAdditionalPayment` when the edit raises
|
|
409
|
+
* what the customer of a paid order owes on a payment collected online.
|
|
410
|
+
* `null` when the order's state does not change.
|
|
411
|
+
*/
|
|
412
|
+
returnState: string | null;
|
|
413
|
+
/** Everything that stops this edit from being carried out, as far as running its steps shows. */
|
|
414
|
+
blockers: OrderEditBlocker[];
|
|
415
|
+
notices: OrderEditNotice[];
|
|
416
|
+
payment: OrderEditPayment;
|
|
417
|
+
/** `null` when a blocker kept the preview from reaching the end. */
|
|
418
|
+
preview: OrderEditPreview | null;
|
|
419
|
+
}
|
|
420
|
+
/**
|
|
421
|
+
* Its own document on purpose: `planOrderEdit` exists only on an engine with
|
|
422
|
+
* the order-edit plan, so on an older one this call alone fails validation and
|
|
423
|
+
* no other order call does.
|
|
424
|
+
*/
|
|
425
|
+
export declare const PLAN_ORDER_EDIT_QUERY = "\n query PlanOrderEdit($orderId: ID!, $diff: OrderEditDiffInput!) {\n planOrderEdit(orderId: $orderId, diff: $diff) {\n orderId\n planHash\n orderVersion\n steps {\n kind\n input\n moneyEffect\n }\n refund {\n paymentId\n amount\n }\n overpayment {\n amount\n currencyCode\n surchargeIds\n refund {\n available\n code\n message\n }\n accountCredit {\n available\n code\n message\n }\n refundWhenChosen {\n paymentId\n amount\n }\n }\n returnState\n blockers {\n code\n message\n details\n }\n notices {\n code\n message\n details\n }\n payment {\n collected\n reason\n method\n }\n preview {\n currencyCode\n subTotal\n subTotalWithTax\n shipping\n shippingWithTax\n surcharges\n surchargesWithTax\n total\n totalWithTax\n taxSummary {\n description\n taxRate\n taxBase\n taxTotal\n }\n totalWithTaxBefore\n }\n }\n }\n";
|
|
426
|
+
export interface OrderPlanEditModule {
|
|
427
|
+
/**
|
|
428
|
+
* How an edit of a placed order would be carried out, and what the order
|
|
429
|
+
* would cost after it. Needs `UpdateOrder`, and an engine that serves
|
|
430
|
+
* `planOrderEdit`.
|
|
431
|
+
*
|
|
432
|
+
* State what should change as a `diff` of intents. The server decides the
|
|
433
|
+
* steps: which changes are a cancellation, which are written directly
|
|
434
|
+
* because no money was collected, which go through an order modification,
|
|
435
|
+
* and what is refunded. It then runs those steps in a transaction it always
|
|
436
|
+
* rolls back, so `preview` holds the pricing engine's own totals and a step
|
|
437
|
+
* the engine would refuse is found here.
|
|
438
|
+
*
|
|
439
|
+
* Nothing is saved, no event is published and no payment provider is
|
|
440
|
+
* contacted. A store's tax provider app may be asked, as it is for any
|
|
441
|
+
* re-price. Call it after the merchant stops typing, not on every keystroke.
|
|
442
|
+
*
|
|
443
|
+
* Read `blockers` first. It lists every reason the edit cannot be carried
|
|
444
|
+
* out: it is an answer, not an error, so that a head can show them all beside
|
|
445
|
+
* the steps. `preview` is `null` when a blocker kept the run from reaching
|
|
446
|
+
* the end; it is still answered for a plan with no steps (the order as it
|
|
447
|
+
* is), and beside `ORDER_EDIT_REFUND_EXCEEDS_PAYMENT` and
|
|
448
|
+
* `ORDER_EDIT_OVERPAYMENT_NOT_SETTLEABLE` (what the edit would cost).
|
|
449
|
+
*
|
|
450
|
+
* `steps` are in the order they run, each with its `moneyEffect` on the
|
|
451
|
+
* order's total with tax. `refund` is what an edit of a paid order returns
|
|
452
|
+
* to the customer automatically, on the one payment that can carry the
|
|
453
|
+
* whole amount.
|
|
454
|
+
*
|
|
455
|
+
* `overpayment` is set when the edit lowers or removes a surcharge on a paid
|
|
456
|
+
* order: the merchant chooses, before saving, whether that difference is
|
|
457
|
+
* refunded to the customer's payment or credited to their account. Show the
|
|
458
|
+
* amount and both options (a closed one with its `message`), and pass the
|
|
459
|
+
* answer to `commitEdit` as `overpaymentChoice`.
|
|
460
|
+
*
|
|
461
|
+
* While it runs the plan holds the order: another change of the same order
|
|
462
|
+
* waits for it, and a plan that cannot get the order within a few seconds is
|
|
463
|
+
* refused with `ORDER_BUSY`. Nothing was read or changed then, so asking
|
|
464
|
+
* again is safe.
|
|
465
|
+
*
|
|
466
|
+
* Keep `planHash` with what you show: `commitEdit` carries the edit out and
|
|
467
|
+
* names it, so what is saved is what the merchant saw.
|
|
468
|
+
*
|
|
469
|
+
* Refusals of the call:
|
|
470
|
+
* - `ORDER_EDIT_ORDER_NOT_FOUND`, `ORDER_EDIT_LINE_NOT_FOUND`,
|
|
471
|
+
* `ORDER_EDIT_SURCHARGE_NOT_FOUND` and `ORDER_EDIT_VARIANT_NOT_FOUND`
|
|
472
|
+
* (`NotFoundError`, 404). An order of another store answers like a missing
|
|
473
|
+
* one, and so does a line or surcharge of another order and a deleted
|
|
474
|
+
* variant. An id that is not a uuid is refused before that with core's
|
|
475
|
+
* `ENTITY_NOT_FOUND`, also a `NotFoundError`: branch on the class for
|
|
476
|
+
* not-found, not on one code.
|
|
477
|
+
* - `INVALID_ORDER_EDIT_DIFF` (`ValidationError`, 400), with a message that
|
|
478
|
+
* names the field: a quantity or amount out of range, an id given twice in
|
|
479
|
+
* one list, a change staged on a line the same diff removes, a
|
|
480
|
+
* `FIXED_PRICE` whole-order discount, a surcharge of 0, `applyToCustomer`
|
|
481
|
+
* together with `markTemporary: true`, more than 500 entries in a list.
|
|
482
|
+
* - `ORDER_EDIT_CHANNEL_NOT_ALLOWED` (`PermissionDeniedError`, 403): the call
|
|
483
|
+
* was made from the default channel instead of the order's own.
|
|
484
|
+
* - `ORDER_BUSY` (`ConflictError`, 409): another change of the order was
|
|
485
|
+
* still being applied. Ask again.
|
|
486
|
+
*/
|
|
487
|
+
planEdit(orderId: string, diff: OrderEditDiff, options?: Call): Promise<OrderEditPlan>;
|
|
488
|
+
}
|
|
489
|
+
export declare function createOrderPlanEditModule(transport: Transport): OrderPlanEditModule;
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Its own document on purpose: `planOrderEdit` exists only on an engine with
|
|
3
|
+
* the order-edit plan, so on an older one this call alone fails validation and
|
|
4
|
+
* no other order call does.
|
|
5
|
+
*/
|
|
6
|
+
export const PLAN_ORDER_EDIT_QUERY = /* GraphQL */ `
|
|
7
|
+
query PlanOrderEdit($orderId: ID!, $diff: OrderEditDiffInput!) {
|
|
8
|
+
planOrderEdit(orderId: $orderId, diff: $diff) {
|
|
9
|
+
orderId
|
|
10
|
+
planHash
|
|
11
|
+
orderVersion
|
|
12
|
+
steps {
|
|
13
|
+
kind
|
|
14
|
+
input
|
|
15
|
+
moneyEffect
|
|
16
|
+
}
|
|
17
|
+
refund {
|
|
18
|
+
paymentId
|
|
19
|
+
amount
|
|
20
|
+
}
|
|
21
|
+
overpayment {
|
|
22
|
+
amount
|
|
23
|
+
currencyCode
|
|
24
|
+
surchargeIds
|
|
25
|
+
refund {
|
|
26
|
+
available
|
|
27
|
+
code
|
|
28
|
+
message
|
|
29
|
+
}
|
|
30
|
+
accountCredit {
|
|
31
|
+
available
|
|
32
|
+
code
|
|
33
|
+
message
|
|
34
|
+
}
|
|
35
|
+
refundWhenChosen {
|
|
36
|
+
paymentId
|
|
37
|
+
amount
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
returnState
|
|
41
|
+
blockers {
|
|
42
|
+
code
|
|
43
|
+
message
|
|
44
|
+
details
|
|
45
|
+
}
|
|
46
|
+
notices {
|
|
47
|
+
code
|
|
48
|
+
message
|
|
49
|
+
details
|
|
50
|
+
}
|
|
51
|
+
payment {
|
|
52
|
+
collected
|
|
53
|
+
reason
|
|
54
|
+
method
|
|
55
|
+
}
|
|
56
|
+
preview {
|
|
57
|
+
currencyCode
|
|
58
|
+
subTotal
|
|
59
|
+
subTotalWithTax
|
|
60
|
+
shipping
|
|
61
|
+
shippingWithTax
|
|
62
|
+
surcharges
|
|
63
|
+
surchargesWithTax
|
|
64
|
+
total
|
|
65
|
+
totalWithTax
|
|
66
|
+
taxSummary {
|
|
67
|
+
description
|
|
68
|
+
taxRate
|
|
69
|
+
taxBase
|
|
70
|
+
taxTotal
|
|
71
|
+
}
|
|
72
|
+
totalWithTaxBefore
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
`;
|
|
77
|
+
export function createOrderPlanEditModule(transport) {
|
|
78
|
+
return {
|
|
79
|
+
async planEdit(orderId, diff, options) {
|
|
80
|
+
const data = await transport.graphql({
|
|
81
|
+
api: 'admin',
|
|
82
|
+
query: PLAN_ORDER_EDIT_QUERY,
|
|
83
|
+
// The diff goes out as given, never normalised: `orderDiscount` left
|
|
84
|
+
// out, `null` and a value are three different requests to the engine
|
|
85
|
+
// (keep, remove, set). `JSON.stringify` drops a key that is
|
|
86
|
+
// `undefined` and keeps a `null`, so a default here would turn
|
|
87
|
+
// "keep" into "remove".
|
|
88
|
+
variables: { orderId, diff },
|
|
89
|
+
}, options);
|
|
90
|
+
return data.planOrderEdit;
|
|
91
|
+
},
|
|
92
|
+
};
|
|
93
|
+
}
|