@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
package/dist/returns/index.js
CHANGED
|
@@ -1,3 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `admin.returns`: the returns (RMA) plugin. The reads (one return, an order's
|
|
3
|
+
* returns, the list, the open count, what of an order can be returned) and the
|
|
4
|
+
* plan for settling one (headless W9-47); every non-money step of a return's life
|
|
5
|
+
* (create, approve, reject, cancel, record a receipt, add a note), the store's
|
|
6
|
+
* return policy and the RMA numbering (headless W10-27). Settling moves money and
|
|
7
|
+
* is its own keyed call (`settle`, headless W10-28). Money is in MINOR UNITS
|
|
8
|
+
* throughout, as everywhere in this SDK.
|
|
9
|
+
*
|
|
10
|
+
* Every value set below is the engine's own and grows over time, so each field
|
|
11
|
+
* that carries one also accepts a string this version does not name: treat an
|
|
12
|
+
* unknown value as "not available".
|
|
13
|
+
*/
|
|
14
|
+
import { NotFoundError, ValidationError } from '@sixtyninecommerce/core';
|
|
1
15
|
/** A return's state: the latest row of its status log. */
|
|
2
16
|
export const RETURN_STATES = [
|
|
3
17
|
'requested',
|
|
@@ -13,9 +27,24 @@ export const RETURN_STATES = [
|
|
|
13
27
|
* How a return is settled. `refund` gives money back to an original payment.
|
|
14
28
|
* `store_credit` issues a credit note: on a store with an accounts-receivable
|
|
15
29
|
* ledger it credits the customer's account, elsewhere it credits the order's
|
|
16
|
-
* invoice and moves no money.
|
|
30
|
+
* invoice and moves no money. `account` puts the order's settled money on the
|
|
31
|
+
* customer's account as unapplied cash and makes no refund (an engine released
|
|
32
|
+
* before 2026-10-10 never answers it).
|
|
17
33
|
*/
|
|
18
|
-
export const RETURN_SETTLEMENT_METHODS = ['refund', 'store_credit'];
|
|
34
|
+
export const RETURN_SETTLEMENT_METHODS = ['refund', 'store_credit', 'account'];
|
|
35
|
+
/**
|
|
36
|
+
* A step of a return's life, as `allowedActions` names it. `CLOSE_CREDITED` is
|
|
37
|
+
* {@link ReturnsModule.closeAlreadyCredited}: closing a return invoice corrections already
|
|
38
|
+
* credited in full, moving no money.
|
|
39
|
+
*/
|
|
40
|
+
export const RETURN_ACTIONS = [
|
|
41
|
+
'APPROVE',
|
|
42
|
+
'REJECT',
|
|
43
|
+
'RECORD_RECEIPT',
|
|
44
|
+
'CANCEL',
|
|
45
|
+
'SETTLE',
|
|
46
|
+
'CLOSE_CREDITED',
|
|
47
|
+
];
|
|
19
48
|
/** Why a return cannot be settled now, in the order the engine checks them. */
|
|
20
49
|
export const RETURN_SETTLEMENT_BLOCKERS = [
|
|
21
50
|
'OUTCOME_UNKNOWN',
|
|
@@ -70,10 +99,31 @@ const RETURN_FIELDS = /* GraphQL */ `
|
|
|
70
99
|
updatedAt
|
|
71
100
|
}
|
|
72
101
|
`;
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
102
|
+
/** The fields of a `ReturnCoveringCreditNote` (a selection, spliced into several documents). */
|
|
103
|
+
const COVERING_CREDIT_NOTE_FIELDS = /* GraphQL */ `
|
|
104
|
+
creditNoteId
|
|
105
|
+
creditNoteNumber
|
|
106
|
+
ledger
|
|
107
|
+
`;
|
|
108
|
+
/** What `get` and `list` add to a return's fields (engines from 2026-10-11). */
|
|
109
|
+
const READ_FIELDS = /* GraphQL */ `
|
|
110
|
+
refundEstimate
|
|
111
|
+
customer {
|
|
112
|
+
id
|
|
113
|
+
firstName
|
|
114
|
+
lastName
|
|
115
|
+
emailAddress
|
|
116
|
+
addresses {
|
|
117
|
+
company
|
|
118
|
+
defaultBillingAddress
|
|
119
|
+
defaultShippingAddress
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
lines {
|
|
123
|
+
refundEstimate
|
|
124
|
+
}
|
|
125
|
+
`;
|
|
126
|
+
const HISTORY_FIELDS = /* GraphQL */ `
|
|
77
127
|
history {
|
|
78
128
|
state
|
|
79
129
|
actor
|
|
@@ -81,18 +131,247 @@ export const RETURN_QUERY = /* GraphQL */ `
|
|
|
81
131
|
reason
|
|
82
132
|
createdAt
|
|
83
133
|
}
|
|
134
|
+
`;
|
|
135
|
+
export const RETURN_QUERY = /* GraphQL */ `
|
|
136
|
+
query SdkOrderReturn($id: ID!) {
|
|
137
|
+
orderReturn(id: $id) {
|
|
138
|
+
${RETURN_FIELDS}
|
|
139
|
+
alreadyCreditedBy {
|
|
140
|
+
${COVERING_CREDIT_NOTE_FIELDS}
|
|
141
|
+
}
|
|
142
|
+
${HISTORY_FIELDS}
|
|
143
|
+
${READ_FIELDS}
|
|
144
|
+
allowedActions {
|
|
145
|
+
action
|
|
146
|
+
allowed
|
|
147
|
+
reasonCode
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
`;
|
|
152
|
+
/**
|
|
153
|
+
* {@link RETURN_QUERY} for an engine with `alreadyCreditedBy` (ruling U15) but released before
|
|
154
|
+
* `allowedActions`, `refundEstimate` and `customer` (2026-10-11).
|
|
155
|
+
*/
|
|
156
|
+
export const RETURN_QUERY_BEFORE_ACTIONS = /* GraphQL */ `
|
|
157
|
+
query SdkOrderReturnBeforeActions($id: ID!) {
|
|
158
|
+
orderReturn(id: $id) {
|
|
159
|
+
${RETURN_FIELDS}
|
|
160
|
+
alreadyCreditedBy {
|
|
161
|
+
${COVERING_CREDIT_NOTE_FIELDS}
|
|
162
|
+
}
|
|
163
|
+
${HISTORY_FIELDS}
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
`;
|
|
167
|
+
/** {@link RETURN_QUERY} for an engine released before `alreadyCreditedBy` (ruling U15). */
|
|
168
|
+
export const RETURN_QUERY_LEGACY = /* GraphQL */ `
|
|
169
|
+
query SdkOrderReturnLegacy($id: ID!) {
|
|
170
|
+
orderReturn(id: $id) {
|
|
171
|
+
${RETURN_FIELDS}
|
|
172
|
+
${HISTORY_FIELDS}
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
`;
|
|
176
|
+
export const RETURNS_LIST_QUERY = /* GraphQL */ `
|
|
177
|
+
query SdkOrderReturns($options: OrderReturnListOptions) {
|
|
178
|
+
orderReturns(options: $options) {
|
|
179
|
+
items {
|
|
180
|
+
${RETURN_FIELDS}
|
|
181
|
+
alreadyCreditedBy {
|
|
182
|
+
${COVERING_CREDIT_NOTE_FIELDS}
|
|
183
|
+
}
|
|
184
|
+
${READ_FIELDS}
|
|
185
|
+
}
|
|
186
|
+
totalItems
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
`;
|
|
190
|
+
/** {@link RETURNS_LIST_QUERY} for an engine with `alreadyCreditedBy` but released before 2026-10-11. */
|
|
191
|
+
export const RETURNS_LIST_QUERY_BEFORE_ACTIONS = /* GraphQL */ `
|
|
192
|
+
query SdkOrderReturnsBeforeActions($options: OrderReturnListOptions) {
|
|
193
|
+
orderReturns(options: $options) {
|
|
194
|
+
items {
|
|
195
|
+
${RETURN_FIELDS}
|
|
196
|
+
alreadyCreditedBy {
|
|
197
|
+
${COVERING_CREDIT_NOTE_FIELDS}
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
totalItems
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
`;
|
|
204
|
+
/** {@link RETURNS_LIST_QUERY} for an engine released before `alreadyCreditedBy`. */
|
|
205
|
+
export const RETURNS_LIST_QUERY_LEGACY = /* GraphQL */ `
|
|
206
|
+
query SdkOrderReturnsLegacy($options: OrderReturnListOptions) {
|
|
207
|
+
orderReturns(options: $options) {
|
|
208
|
+
items {
|
|
209
|
+
${RETURN_FIELDS}
|
|
210
|
+
}
|
|
211
|
+
totalItems
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
`;
|
|
215
|
+
export const OPEN_RETURNS_COUNT_QUERY = /* GraphQL */ `
|
|
216
|
+
query SdkOpenReturnsCount {
|
|
217
|
+
orderReturns(options: { take: 1, state: requested }) {
|
|
218
|
+
totalItems
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
`;
|
|
222
|
+
export const CREATE_RETURN_MUTATION = /* GraphQL */ `
|
|
223
|
+
mutation SdkCreateReturn($input: CreateReturnInput!) {
|
|
224
|
+
createReturn(input: $input) {
|
|
225
|
+
${RETURN_FIELDS}
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
`;
|
|
229
|
+
export const APPROVE_RETURN_MUTATION = /* GraphQL */ `
|
|
230
|
+
mutation SdkApproveReturn($input: ApproveReturnInput!) {
|
|
231
|
+
approveReturn(input: $input) {
|
|
232
|
+
${RETURN_FIELDS}
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
`;
|
|
236
|
+
export const REJECT_RETURN_MUTATION = /* GraphQL */ `
|
|
237
|
+
mutation SdkRejectReturn($id: ID!, $reason: String!) {
|
|
238
|
+
rejectReturn(id: $id, reason: $reason) {
|
|
239
|
+
${RETURN_FIELDS}
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
`;
|
|
243
|
+
export const CANCEL_RETURN_MUTATION = /* GraphQL */ `
|
|
244
|
+
mutation SdkCancelReturn($id: ID!, $reason: String) {
|
|
245
|
+
cancelReturn(id: $id, reason: $reason) {
|
|
246
|
+
${RETURN_FIELDS}
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
`;
|
|
250
|
+
export const RECORD_RETURN_RECEIPT_MUTATION = /* GraphQL */ `
|
|
251
|
+
mutation SdkRecordReturnReceipt($input: RecordReturnReceiptInput!) {
|
|
252
|
+
recordReturnReceipt(input: $input) {
|
|
253
|
+
${RETURN_FIELDS}
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
`;
|
|
257
|
+
export const SETTLE_RETURN_MUTATION = /* GraphQL */ `
|
|
258
|
+
mutation SdkSettleReturn($input: SettleReturnInput!, $idempotencyKey: String) {
|
|
259
|
+
settleReturn(input: $input, idempotencyKey: $idempotencyKey) {
|
|
260
|
+
${RETURN_FIELDS}
|
|
261
|
+
${HISTORY_FIELDS}
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
`;
|
|
265
|
+
export const ADD_RETURN_NOTE_MUTATION = /* GraphQL */ `
|
|
266
|
+
mutation SdkAddReturnNote($id: ID!, $note: String!) {
|
|
267
|
+
addReturnNote(id: $id, note: $note) {
|
|
268
|
+
${RETURN_FIELDS}
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
`;
|
|
272
|
+
const NUMBERING_FIELDS = /* GraphQL */ `
|
|
273
|
+
prefix
|
|
274
|
+
suffix
|
|
275
|
+
digits
|
|
276
|
+
yearFormat
|
|
277
|
+
yearReset
|
|
278
|
+
`;
|
|
279
|
+
export const RETURN_NUMBERING_QUERY = /* GraphQL */ `
|
|
280
|
+
query SdkReturnNumberingConfig {
|
|
281
|
+
returnNumberingConfig {
|
|
282
|
+
${NUMBERING_FIELDS}
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
`;
|
|
286
|
+
export const UPDATE_RETURN_NUMBERING_MUTATION = /* GraphQL */ `
|
|
287
|
+
mutation SdkUpdateReturnNumberingConfig($input: UpdateReturnNumberingConfigInput!) {
|
|
288
|
+
updateReturnNumberingConfig(input: $input) {
|
|
289
|
+
${NUMBERING_FIELDS}
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
`;
|
|
293
|
+
export const RETURNS_SETTINGS_QUERY = /* GraphQL */ `
|
|
294
|
+
query SdkReturnsSettings {
|
|
295
|
+
activeChannel {
|
|
296
|
+
id
|
|
297
|
+
customFields {
|
|
298
|
+
returnsEnabled
|
|
299
|
+
returnWindowDays
|
|
300
|
+
returnsAutoApprove
|
|
301
|
+
returnsRequireReceiptBeforeSettle
|
|
302
|
+
returnsDefaultRestockLocationId
|
|
303
|
+
}
|
|
84
304
|
}
|
|
85
305
|
}
|
|
86
306
|
`;
|
|
87
307
|
export const RETURNS_FOR_ORDER_QUERY = /* GraphQL */ `
|
|
88
308
|
query SdkReturnsForOrder($orderId: ID!) {
|
|
309
|
+
returnsForOrder(orderId: $orderId) {
|
|
310
|
+
${RETURN_FIELDS}
|
|
311
|
+
alreadyCreditedBy {
|
|
312
|
+
${COVERING_CREDIT_NOTE_FIELDS}
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
`;
|
|
317
|
+
/** {@link RETURNS_FOR_ORDER_QUERY} for an engine released before `alreadyCreditedBy`. */
|
|
318
|
+
export const RETURNS_FOR_ORDER_QUERY_LEGACY = /* GraphQL */ `
|
|
319
|
+
query SdkReturnsForOrderLegacy($orderId: ID!) {
|
|
89
320
|
returnsForOrder(orderId: $orderId) {
|
|
90
321
|
${RETURN_FIELDS}
|
|
91
322
|
}
|
|
92
323
|
}
|
|
93
324
|
`;
|
|
325
|
+
export const CLOSE_RETURN_ALREADY_CREDITED_MUTATION = /* GraphQL */ `
|
|
326
|
+
mutation SdkCloseReturnAlreadyCredited($input: CloseReturnAlreadyCreditedInput!) {
|
|
327
|
+
closeReturnAlreadyCredited(input: $input) {
|
|
328
|
+
${RETURN_FIELDS}
|
|
329
|
+
alreadyCreditedBy {
|
|
330
|
+
${COVERING_CREDIT_NOTE_FIELDS}
|
|
331
|
+
}
|
|
332
|
+
${HISTORY_FIELDS}
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
`;
|
|
336
|
+
/** The fields of a `ReturnLineCorrectionCredit` (a selection, spliced into two documents). */
|
|
337
|
+
const CORRECTION_CREDIT_FIELDS = /* GraphQL */ `
|
|
338
|
+
orderLineId
|
|
339
|
+
creditNoteId
|
|
340
|
+
creditNoteNumber
|
|
341
|
+
ledger
|
|
342
|
+
quantity
|
|
343
|
+
amount
|
|
344
|
+
`;
|
|
94
345
|
export const RETURN_ELIGIBILITY_QUERY = /* GraphQL */ `
|
|
95
346
|
query SdkReturnEligibility($orderId: ID!) {
|
|
347
|
+
returnEligibilityForOrder(orderId: $orderId) {
|
|
348
|
+
orderId
|
|
349
|
+
eligible
|
|
350
|
+
reason
|
|
351
|
+
returnWindowEndsAt
|
|
352
|
+
lines {
|
|
353
|
+
orderLineId
|
|
354
|
+
productVariantId
|
|
355
|
+
productVariantName
|
|
356
|
+
productVariantSku
|
|
357
|
+
fulfilledQty
|
|
358
|
+
returnableQty
|
|
359
|
+
creditedQty
|
|
360
|
+
correctionCredits {
|
|
361
|
+
${CORRECTION_CREDIT_FIELDS}
|
|
362
|
+
}
|
|
363
|
+
unitPriceWithTax
|
|
364
|
+
unitPriceWithTaxUnrounded
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
`;
|
|
369
|
+
/**
|
|
370
|
+
* {@link RETURN_ELIGIBILITY_QUERY} for an engine released before 2026-10-09, which has no
|
|
371
|
+
* `creditedQty`/`correctionCredits`: GraphQL refuses a whole document over one unknown field.
|
|
372
|
+
*/
|
|
373
|
+
export const RETURN_ELIGIBILITY_QUERY_LEGACY = /* GraphQL */ `
|
|
374
|
+
query SdkReturnEligibilityLegacy($orderId: ID!) {
|
|
96
375
|
returnEligibilityForOrder(orderId: $orderId) {
|
|
97
376
|
orderId
|
|
98
377
|
eligible
|
|
@@ -133,28 +412,433 @@ export const RETURN_SETTLEMENT_OPTIONS_QUERY = /* GraphQL */ `
|
|
|
133
412
|
reasonCode
|
|
134
413
|
invoiceNumber
|
|
135
414
|
}
|
|
415
|
+
account {
|
|
416
|
+
available
|
|
417
|
+
reasonCode
|
|
418
|
+
message
|
|
419
|
+
held
|
|
420
|
+
book
|
|
421
|
+
}
|
|
422
|
+
initialMethod
|
|
423
|
+
defaultAmount
|
|
424
|
+
amountCeiling
|
|
425
|
+
correctionCredits {
|
|
426
|
+
${CORRECTION_CREDIT_FIELDS}
|
|
427
|
+
}
|
|
428
|
+
shippingCeiling
|
|
429
|
+
alreadyCredited {
|
|
430
|
+
available
|
|
431
|
+
reasonCode
|
|
432
|
+
creditNotes {
|
|
433
|
+
${COVERING_CREDIT_NOTE_FIELDS}
|
|
434
|
+
}
|
|
435
|
+
}
|
|
436
|
+
}
|
|
437
|
+
}
|
|
438
|
+
`;
|
|
439
|
+
/**
|
|
440
|
+
* {@link RETURN_SETTLEMENT_OPTIONS_QUERY} for an engine with `alreadyCredited` but released before
|
|
441
|
+
* the account option named the store's book (incentives sprint 8 PR 4).
|
|
442
|
+
*/
|
|
443
|
+
export const RETURN_SETTLEMENT_OPTIONS_QUERY_BEFORE_BOOK = /* GraphQL */ `
|
|
444
|
+
query SdkReturnSettlementOptionsBeforeBook($returnId: ID!) {
|
|
445
|
+
returnSettlementOptions(returnId: $returnId) {
|
|
446
|
+
returnId
|
|
447
|
+
currencyCode
|
|
448
|
+
settleable
|
|
449
|
+
blockedBy
|
|
450
|
+
refund {
|
|
451
|
+
available
|
|
452
|
+
reasonCode
|
|
453
|
+
payments {
|
|
454
|
+
paymentId
|
|
455
|
+
method
|
|
456
|
+
refundable
|
|
457
|
+
}
|
|
458
|
+
}
|
|
459
|
+
creditNote {
|
|
460
|
+
available
|
|
461
|
+
ledger
|
|
462
|
+
reasonCode
|
|
463
|
+
invoiceNumber
|
|
464
|
+
}
|
|
465
|
+
account {
|
|
466
|
+
available
|
|
467
|
+
reasonCode
|
|
468
|
+
message
|
|
469
|
+
held
|
|
470
|
+
}
|
|
471
|
+
initialMethod
|
|
472
|
+
defaultAmount
|
|
473
|
+
amountCeiling
|
|
474
|
+
correctionCredits {
|
|
475
|
+
${CORRECTION_CREDIT_FIELDS}
|
|
476
|
+
}
|
|
477
|
+
shippingCeiling
|
|
478
|
+
alreadyCredited {
|
|
479
|
+
available
|
|
480
|
+
reasonCode
|
|
481
|
+
creditNotes {
|
|
482
|
+
${COVERING_CREDIT_NOTE_FIELDS}
|
|
483
|
+
}
|
|
484
|
+
}
|
|
485
|
+
}
|
|
486
|
+
}
|
|
487
|
+
`;
|
|
488
|
+
/**
|
|
489
|
+
* {@link RETURN_SETTLEMENT_OPTIONS_QUERY} for an engine with the account settlement (2026-10-10)
|
|
490
|
+
* but released before `alreadyCredited` (ruling U15).
|
|
491
|
+
*/
|
|
492
|
+
export const RETURN_SETTLEMENT_OPTIONS_QUERY_BEFORE_CLOSE = /* GraphQL */ `
|
|
493
|
+
query SdkReturnSettlementOptionsBeforeClose($returnId: ID!) {
|
|
494
|
+
returnSettlementOptions(returnId: $returnId) {
|
|
495
|
+
returnId
|
|
496
|
+
currencyCode
|
|
497
|
+
settleable
|
|
498
|
+
blockedBy
|
|
499
|
+
refund {
|
|
500
|
+
available
|
|
501
|
+
reasonCode
|
|
502
|
+
payments {
|
|
503
|
+
paymentId
|
|
504
|
+
method
|
|
505
|
+
refundable
|
|
506
|
+
}
|
|
507
|
+
}
|
|
508
|
+
creditNote {
|
|
509
|
+
available
|
|
510
|
+
ledger
|
|
511
|
+
reasonCode
|
|
512
|
+
invoiceNumber
|
|
513
|
+
}
|
|
514
|
+
account {
|
|
515
|
+
available
|
|
516
|
+
reasonCode
|
|
517
|
+
message
|
|
518
|
+
held
|
|
519
|
+
}
|
|
136
520
|
initialMethod
|
|
137
521
|
defaultAmount
|
|
522
|
+
amountCeiling
|
|
523
|
+
correctionCredits {
|
|
524
|
+
${CORRECTION_CREDIT_FIELDS}
|
|
525
|
+
}
|
|
526
|
+
shippingCeiling
|
|
138
527
|
}
|
|
139
528
|
}
|
|
140
529
|
`;
|
|
530
|
+
/**
|
|
531
|
+
* {@link RETURN_SETTLEMENT_OPTIONS_QUERY} for an engine with `shippingCeiling` but released before
|
|
532
|
+
* the account settlement (2026-10-10).
|
|
533
|
+
*/
|
|
534
|
+
export const RETURN_SETTLEMENT_OPTIONS_QUERY_BEFORE_ACCOUNT = /* GraphQL */ `
|
|
535
|
+
query SdkReturnSettlementOptionsBeforeAccount($returnId: ID!) {
|
|
536
|
+
returnSettlementOptions(returnId: $returnId) {
|
|
537
|
+
returnId
|
|
538
|
+
currencyCode
|
|
539
|
+
settleable
|
|
540
|
+
blockedBy
|
|
541
|
+
refund {
|
|
542
|
+
available
|
|
543
|
+
reasonCode
|
|
544
|
+
payments {
|
|
545
|
+
paymentId
|
|
546
|
+
method
|
|
547
|
+
refundable
|
|
548
|
+
}
|
|
549
|
+
}
|
|
550
|
+
creditNote {
|
|
551
|
+
available
|
|
552
|
+
ledger
|
|
553
|
+
reasonCode
|
|
554
|
+
invoiceNumber
|
|
555
|
+
}
|
|
556
|
+
initialMethod
|
|
557
|
+
defaultAmount
|
|
558
|
+
amountCeiling
|
|
559
|
+
correctionCredits {
|
|
560
|
+
${CORRECTION_CREDIT_FIELDS}
|
|
561
|
+
}
|
|
562
|
+
shippingCeiling
|
|
563
|
+
}
|
|
564
|
+
}
|
|
565
|
+
`;
|
|
566
|
+
/**
|
|
567
|
+
* {@link RETURN_SETTLEMENT_OPTIONS_QUERY} for an engine with the correction credits (2026-10-09)
|
|
568
|
+
* but released before `shippingCeiling`.
|
|
569
|
+
*/
|
|
570
|
+
export const RETURN_SETTLEMENT_OPTIONS_QUERY_BEFORE_SHIPPING = /* GraphQL */ `
|
|
571
|
+
query SdkReturnSettlementOptionsBeforeShipping($returnId: ID!) {
|
|
572
|
+
returnSettlementOptions(returnId: $returnId) {
|
|
573
|
+
returnId
|
|
574
|
+
currencyCode
|
|
575
|
+
settleable
|
|
576
|
+
blockedBy
|
|
577
|
+
refund {
|
|
578
|
+
available
|
|
579
|
+
reasonCode
|
|
580
|
+
payments {
|
|
581
|
+
paymentId
|
|
582
|
+
method
|
|
583
|
+
refundable
|
|
584
|
+
}
|
|
585
|
+
}
|
|
586
|
+
creditNote {
|
|
587
|
+
available
|
|
588
|
+
ledger
|
|
589
|
+
reasonCode
|
|
590
|
+
invoiceNumber
|
|
591
|
+
}
|
|
592
|
+
initialMethod
|
|
593
|
+
defaultAmount
|
|
594
|
+
amountCeiling
|
|
595
|
+
correctionCredits {
|
|
596
|
+
${CORRECTION_CREDIT_FIELDS}
|
|
597
|
+
}
|
|
598
|
+
}
|
|
599
|
+
}
|
|
600
|
+
`;
|
|
601
|
+
/**
|
|
602
|
+
* {@link RETURN_SETTLEMENT_OPTIONS_QUERY} for an engine with the plan (W9-47) but released before
|
|
603
|
+
* 2026-10-09, which has no `amountCeiling`/`correctionCredits`.
|
|
604
|
+
*/
|
|
605
|
+
export const RETURN_SETTLEMENT_OPTIONS_QUERY_LEGACY = /* GraphQL */ `
|
|
606
|
+
query SdkReturnSettlementOptionsLegacy($returnId: ID!) {
|
|
607
|
+
returnSettlementOptions(returnId: $returnId) {
|
|
608
|
+
returnId
|
|
609
|
+
currencyCode
|
|
610
|
+
settleable
|
|
611
|
+
blockedBy
|
|
612
|
+
refund {
|
|
613
|
+
available
|
|
614
|
+
reasonCode
|
|
615
|
+
payments {
|
|
616
|
+
paymentId
|
|
617
|
+
method
|
|
618
|
+
refundable
|
|
619
|
+
}
|
|
620
|
+
}
|
|
621
|
+
creditNote {
|
|
622
|
+
available
|
|
623
|
+
ledger
|
|
624
|
+
reasonCode
|
|
625
|
+
invoiceNumber
|
|
626
|
+
}
|
|
627
|
+
initialMethod
|
|
628
|
+
defaultAmount
|
|
629
|
+
}
|
|
630
|
+
}
|
|
631
|
+
`;
|
|
632
|
+
/**
|
|
633
|
+
* Whether a failure is "this engine does not know that field yet": the document refused before
|
|
634
|
+
* it ran, never an execution-time refusal or a transient failure (degrading on those would hide
|
|
635
|
+
* an outage behind silently missing fields). graphql-js answers a validation failure with HTTP
|
|
636
|
+
* 400, which reaches the SDK as `BAD_REQUEST`, or coded `GRAPHQL_VALIDATION_FAILED` (the storefront
|
|
637
|
+
* SDK's `isUnknownFieldRejection` reads the same two).
|
|
638
|
+
*/
|
|
639
|
+
function isUnknownFieldRejection(error) {
|
|
640
|
+
if (!(error instanceof ValidationError) || error.service !== 'vendure')
|
|
641
|
+
return false;
|
|
642
|
+
return (error.code === 'BAD_REQUEST' ||
|
|
643
|
+
error.code === 'GRAPHQL_VALIDATION_FAILED' ||
|
|
644
|
+
/Cannot query field/i.test(error.message));
|
|
645
|
+
}
|
|
646
|
+
/** The plan's documents, newest first: each drops the newest field the one before it asks. */
|
|
647
|
+
const SETTLEMENT_OPTIONS_DOCUMENTS = [
|
|
648
|
+
RETURN_SETTLEMENT_OPTIONS_QUERY,
|
|
649
|
+
RETURN_SETTLEMENT_OPTIONS_QUERY_BEFORE_BOOK,
|
|
650
|
+
RETURN_SETTLEMENT_OPTIONS_QUERY_BEFORE_CLOSE,
|
|
651
|
+
RETURN_SETTLEMENT_OPTIONS_QUERY_BEFORE_ACCOUNT,
|
|
652
|
+
RETURN_SETTLEMENT_OPTIONS_QUERY_BEFORE_SHIPPING,
|
|
653
|
+
RETURN_SETTLEMENT_OPTIONS_QUERY_LEGACY,
|
|
654
|
+
];
|
|
141
655
|
export function createReturnsModule(transport) {
|
|
656
|
+
/**
|
|
657
|
+
* Latched once the engine proved it predates the correction-credit fields, so the downgrade
|
|
658
|
+
* costs one refused request per client.
|
|
659
|
+
*/
|
|
660
|
+
let correctionCreditsUnsupported = false;
|
|
661
|
+
/** Which of {@link SETTLEMENT_OPTIONS_DOCUMENTS} this engine answers (latched, never back up). */
|
|
662
|
+
let settlementOptionsTier = 0;
|
|
663
|
+
/** Latched once the engine proved it predates `alreadyCreditedBy` (one refused request per client). */
|
|
664
|
+
let alreadyCreditedByUnsupported = false;
|
|
665
|
+
/** Sends the current document, or the legacy one once the engine refused the new fields. */
|
|
666
|
+
async function withFallback(query, legacy, variables, options) {
|
|
667
|
+
if (!correctionCreditsUnsupported) {
|
|
668
|
+
try {
|
|
669
|
+
return await transport.graphql({ api: 'admin', query, variables }, options);
|
|
670
|
+
}
|
|
671
|
+
catch (error) {
|
|
672
|
+
if (!isUnknownFieldRejection(error))
|
|
673
|
+
throw error;
|
|
674
|
+
}
|
|
675
|
+
}
|
|
676
|
+
const data = await transport.graphql({ api: 'admin', query: legacy, variables }, options);
|
|
677
|
+
correctionCreditsUnsupported = true;
|
|
678
|
+
return data;
|
|
679
|
+
}
|
|
680
|
+
/** The return reads: with `alreadyCreditedBy`, or without it once the engine refused it. */
|
|
681
|
+
async function readReturns(query, legacy, variables, options) {
|
|
682
|
+
if (!alreadyCreditedByUnsupported) {
|
|
683
|
+
try {
|
|
684
|
+
return await transport.graphql({ api: 'admin', query, variables }, options);
|
|
685
|
+
}
|
|
686
|
+
catch (error) {
|
|
687
|
+
if (!isUnknownFieldRejection(error))
|
|
688
|
+
throw error;
|
|
689
|
+
}
|
|
690
|
+
}
|
|
691
|
+
const data = await transport.graphql({ api: 'admin', query: legacy, variables }, options);
|
|
692
|
+
alreadyCreditedByUnsupported = true;
|
|
693
|
+
return data;
|
|
694
|
+
}
|
|
695
|
+
/**
|
|
696
|
+
* Which tier of the `get`/`list` documents this engine answers (latched, never back up): 0 has
|
|
697
|
+
* `allowedActions`/`refundEstimate`/`customer` (2026-10-11), 1 only `alreadyCreditedBy`
|
|
698
|
+
* (U15), 2 neither. Tier 2 also latches `alreadyCreditedByUnsupported`, as `forOrder` reads it.
|
|
699
|
+
*/
|
|
700
|
+
let returnReadTier = 0;
|
|
701
|
+
async function readTiered(documents, variables, options) {
|
|
702
|
+
if (alreadyCreditedByUnsupported)
|
|
703
|
+
returnReadTier = 2;
|
|
704
|
+
for (;;) {
|
|
705
|
+
const tier = returnReadTier;
|
|
706
|
+
try {
|
|
707
|
+
const data = await transport.graphql({ api: 'admin', query: documents[tier], variables }, options);
|
|
708
|
+
if (tier === 2)
|
|
709
|
+
alreadyCreditedByUnsupported = true;
|
|
710
|
+
return data;
|
|
711
|
+
}
|
|
712
|
+
catch (error) {
|
|
713
|
+
if (tier === 2 || !isUnknownFieldRejection(error))
|
|
714
|
+
throw error;
|
|
715
|
+
// A refused document names no field the SDK can read (the transport answers a generic
|
|
716
|
+
// 400), so each older tier is asked in turn, once per client.
|
|
717
|
+
returnReadTier = tier + 1;
|
|
718
|
+
}
|
|
719
|
+
}
|
|
720
|
+
}
|
|
721
|
+
/** One write that answers the return it changed. */
|
|
722
|
+
async function write(field, query, variables, options) {
|
|
723
|
+
const data = await transport.graphql({ api: 'admin', query, variables }, options);
|
|
724
|
+
return data[field];
|
|
725
|
+
}
|
|
142
726
|
return {
|
|
143
727
|
async get(id, options) {
|
|
144
|
-
const data = await
|
|
728
|
+
const data = await readTiered([RETURN_QUERY, RETURN_QUERY_BEFORE_ACTIONS, RETURN_QUERY_LEGACY], { id }, options);
|
|
145
729
|
return data.orderReturn;
|
|
146
730
|
},
|
|
731
|
+
async list(filter, options) {
|
|
732
|
+
const data = await readTiered([RETURNS_LIST_QUERY, RETURNS_LIST_QUERY_BEFORE_ACTIONS, RETURNS_LIST_QUERY_LEGACY], { options: filter ?? {} }, options);
|
|
733
|
+
return data.orderReturns;
|
|
734
|
+
},
|
|
147
735
|
async forOrder(orderId, options) {
|
|
148
|
-
const data = await
|
|
736
|
+
const data = await readReturns(RETURNS_FOR_ORDER_QUERY, RETURNS_FOR_ORDER_QUERY_LEGACY, { orderId }, options);
|
|
149
737
|
return data.returnsForOrder;
|
|
150
738
|
},
|
|
151
739
|
async eligibility(orderId, options) {
|
|
152
|
-
const data = await
|
|
740
|
+
const data = await withFallback(RETURN_ELIGIBILITY_QUERY, RETURN_ELIGIBILITY_QUERY_LEGACY, { orderId }, options);
|
|
153
741
|
return data.returnEligibilityForOrder;
|
|
154
742
|
},
|
|
155
743
|
async settlementOptions(returnId, options) {
|
|
156
|
-
const
|
|
157
|
-
|
|
744
|
+
const last = SETTLEMENT_OPTIONS_DOCUMENTS.length - 1;
|
|
745
|
+
// An engine that refused the correction credits on `eligibility` predates every newer tier.
|
|
746
|
+
if (correctionCreditsUnsupported)
|
|
747
|
+
settlementOptionsTier = last;
|
|
748
|
+
for (;;) {
|
|
749
|
+
const tier = settlementOptionsTier;
|
|
750
|
+
try {
|
|
751
|
+
const data = await transport.graphql({
|
|
752
|
+
api: 'admin',
|
|
753
|
+
query: SETTLEMENT_OPTIONS_DOCUMENTS[tier],
|
|
754
|
+
variables: { returnId },
|
|
755
|
+
}, options);
|
|
756
|
+
if (tier === last)
|
|
757
|
+
correctionCreditsUnsupported = true;
|
|
758
|
+
return data.returnSettlementOptions;
|
|
759
|
+
}
|
|
760
|
+
catch (error) {
|
|
761
|
+
if (tier === last || !isUnknownFieldRejection(error))
|
|
762
|
+
throw error;
|
|
763
|
+
settlementOptionsTier = tier + 1;
|
|
764
|
+
}
|
|
765
|
+
}
|
|
766
|
+
},
|
|
767
|
+
async openCount(options) {
|
|
768
|
+
const data = await transport.graphql({ api: 'admin', query: OPEN_RETURNS_COUNT_QUERY }, options);
|
|
769
|
+
return data.orderReturns.totalItems;
|
|
770
|
+
},
|
|
771
|
+
create: (input, options) => write('createReturn', CREATE_RETURN_MUTATION, { input }, options),
|
|
772
|
+
approve: (id, input, options) => write('approveReturn', APPROVE_RETURN_MUTATION, { input: { id, ...input } }, options),
|
|
773
|
+
reject: (id, reason, options) => write('rejectReturn', REJECT_RETURN_MUTATION, { id, reason }, options),
|
|
774
|
+
cancel: (id, input, options) => write('cancelReturn', CANCEL_RETURN_MUTATION, { id, reason: input?.reason ?? null }, options),
|
|
775
|
+
recordReceipt: (id, input, options) => write('recordReturnReceipt', RECORD_RETURN_RECEIPT_MUTATION, { input: { id, lines: input.lines } }, options),
|
|
776
|
+
addNote: (id, note, options) => write('addReturnNote', ADD_RETURN_NOTE_MUTATION, { id, note }, options),
|
|
777
|
+
async settle(returnId, input, options) {
|
|
778
|
+
const data = await transport.graphql({
|
|
779
|
+
api: 'admin',
|
|
780
|
+
query: SETTLE_RETURN_MUTATION,
|
|
781
|
+
variables: {
|
|
782
|
+
input: {
|
|
783
|
+
id: returnId,
|
|
784
|
+
method: input.method,
|
|
785
|
+
...(input.paymentId != null ? { paymentId: input.paymentId } : {}),
|
|
786
|
+
...(input.amountOverride != null ? { amountOverride: input.amountOverride } : {}),
|
|
787
|
+
...(input.shippingRefundAmount != null
|
|
788
|
+
? { shippingRefundAmount: input.shippingRefundAmount }
|
|
789
|
+
: {}),
|
|
790
|
+
...(input.reason != null ? { reason: input.reason } : {}),
|
|
791
|
+
},
|
|
792
|
+
// A variable, not a header: the Admin API takes the key as an argument. `undefined`
|
|
793
|
+
// when omitted, never null: `JSON.stringify` drops it, so no key stays off the wire.
|
|
794
|
+
idempotencyKey: options?.idempotencyKey,
|
|
795
|
+
},
|
|
796
|
+
}, options);
|
|
797
|
+
return data.settleReturn;
|
|
798
|
+
},
|
|
799
|
+
numbering: {
|
|
800
|
+
async get(options) {
|
|
801
|
+
const data = await transport.graphql({ api: 'admin', query: RETURN_NUMBERING_QUERY }, options);
|
|
802
|
+
return data.returnNumberingConfig;
|
|
803
|
+
},
|
|
804
|
+
async set(input, options) {
|
|
805
|
+
const data = await transport.graphql({ api: 'admin', query: UPDATE_RETURN_NUMBERING_MUTATION, variables: { input } }, options);
|
|
806
|
+
return data.updateReturnNumberingConfig;
|
|
807
|
+
},
|
|
808
|
+
},
|
|
809
|
+
settings: {
|
|
810
|
+
async get(options) {
|
|
811
|
+
const data = await transport.graphql({ api: 'admin', query: RETURNS_SETTINGS_QUERY }, options);
|
|
812
|
+
const channel = data.activeChannel;
|
|
813
|
+
if (!channel) {
|
|
814
|
+
throw new NotFoundError({
|
|
815
|
+
code: 'CHANNEL_NOT_FOUND',
|
|
816
|
+
message: 'No store is active for this session, so it has no return policy to read.',
|
|
817
|
+
status: 404,
|
|
818
|
+
service: 'vendure',
|
|
819
|
+
});
|
|
820
|
+
}
|
|
821
|
+
const fields = channel.customFields;
|
|
822
|
+
return {
|
|
823
|
+
channelId: channel.id,
|
|
824
|
+
// The engine's own defaults (the plugin's field declarations) for a field it answers null.
|
|
825
|
+
returnsEnabled: fields?.returnsEnabled === true,
|
|
826
|
+
returnWindowDays: fields?.returnWindowDays ?? 30,
|
|
827
|
+
returnsAutoApprove: fields?.returnsAutoApprove === true,
|
|
828
|
+
returnsRequireReceiptBeforeSettle: fields?.returnsRequireReceiptBeforeSettle !== false,
|
|
829
|
+
returnsDefaultRestockLocationId: fields?.returnsDefaultRestockLocationId ?? null,
|
|
830
|
+
};
|
|
831
|
+
},
|
|
832
|
+
},
|
|
833
|
+
async closeAlreadyCredited(returnId, input, options) {
|
|
834
|
+
const data = await transport.graphql({
|
|
835
|
+
api: 'admin',
|
|
836
|
+
query: CLOSE_RETURN_ALREADY_CREDITED_MUTATION,
|
|
837
|
+
variables: {
|
|
838
|
+
input: { id: returnId, ...(input?.reason != null ? { reason: input.reason } : {}) },
|
|
839
|
+
},
|
|
840
|
+
}, options);
|
|
841
|
+
return data.closeReturnAlreadyCredited;
|
|
158
842
|
},
|
|
159
843
|
};
|
|
160
844
|
}
|