@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,103 @@
|
|
|
1
|
+
import type { Transport } from '@sixtyninecommerce/core';
|
|
2
|
+
import type { Call } from '../types.js';
|
|
3
|
+
import type { PosReturnLeg, PosReturnLineInput, PosReturnQuoteLine, PosReturnRefund } from './returns.js';
|
|
4
|
+
/**
|
|
5
|
+
* Till exchanges (POS engine sprint 21): a completed till sale's items come back and their value
|
|
6
|
+
* pays an OPEN till cart as its LAST tender, carried as settled exchange-credit payments (no
|
|
7
|
+
* provider is asked for what is carried), any excess refunded to the sale's own payments. A
|
|
8
|
+
* headless till (a machine principal with `x-location`) is a supported caller: its CREDENTIAL is
|
|
9
|
+
* the manager gate, so no staff or approval token is sent. Money is integer minor units.
|
|
10
|
+
*
|
|
11
|
+
* `quote` is a read: the credit, what the cart owes, what would be carried, the excess and its
|
|
12
|
+
* refunds, and why it cannot be done now (`blockedBy`, never thrown:
|
|
13
|
+
* `POS_EXCHANGE_BALANCE_DUE` while the cart owes more than the credit — tender the difference
|
|
14
|
+
* first). `create` re-computes under the sale's money turn and refuses figures other than
|
|
15
|
+
* `expectedCredit` / `expectedApplied` (`POS_EXCHANGE_AMOUNT_CHANGED`). Then complete the cart
|
|
16
|
+
* with `sale.complete`. Refusals that mean NOTHING moved: `POS_EXCHANGE_INVALID`
|
|
17
|
+
* (`extensions.reason`: not_till_cart, same_order, currency, nothing_owed), the `POS_RETURN_*`
|
|
18
|
+
* refusals of `returns.create`, `POS_CART_HELD`. `IDEMPOTENCY_OUTCOME_UNKNOWN`: an excess card
|
|
19
|
+
* refund reached the provider and the outcome is unknown; never retry under a new key.
|
|
20
|
+
*/
|
|
21
|
+
export interface PosExchangeQuoteInput {
|
|
22
|
+
/** The completed till sale the items come back from. */
|
|
23
|
+
returnOrderId: string;
|
|
24
|
+
/** The open till cart the credit goes to. */
|
|
25
|
+
orderId: string;
|
|
26
|
+
lines?: Array<{
|
|
27
|
+
orderLineId: string;
|
|
28
|
+
quantity: number;
|
|
29
|
+
}>;
|
|
30
|
+
cashFirst?: boolean;
|
|
31
|
+
}
|
|
32
|
+
export interface PosExchangeCarry {
|
|
33
|
+
/** The returned sale's payment the credit comes from. */
|
|
34
|
+
sourcePaymentId: string;
|
|
35
|
+
/** cash, card or other. More may come. */
|
|
36
|
+
kind: string;
|
|
37
|
+
method: string;
|
|
38
|
+
amount: number;
|
|
39
|
+
/** The exchange payment on the cart; null in a quote. */
|
|
40
|
+
paymentId: string | null;
|
|
41
|
+
}
|
|
42
|
+
export interface PosExchangeQuote {
|
|
43
|
+
returnOrderId: string;
|
|
44
|
+
orderId: string;
|
|
45
|
+
currencyCode: string;
|
|
46
|
+
receiptNumber: string | null;
|
|
47
|
+
lines: PosReturnQuoteLine[];
|
|
48
|
+
credit: number;
|
|
49
|
+
newSaleTotal: number;
|
|
50
|
+
newSalePaid: number;
|
|
51
|
+
/** Still to pay before the exchange: tender it first. */
|
|
52
|
+
due: number;
|
|
53
|
+
applied: number;
|
|
54
|
+
excess: number;
|
|
55
|
+
carries: PosExchangeCarry[];
|
|
56
|
+
legs: PosReturnLeg[];
|
|
57
|
+
cashPaidOut: number;
|
|
58
|
+
returnWindowEndsAt: string | null;
|
|
59
|
+
outsideWindow: boolean;
|
|
60
|
+
refundedOutsideReturns: number;
|
|
61
|
+
restockLocationName: string | null;
|
|
62
|
+
/** A POS_EXCHANGE_* / POS_RETURN_* code, or null. More may come. */
|
|
63
|
+
blockedBy: string | null;
|
|
64
|
+
blockedReason: string | null;
|
|
65
|
+
}
|
|
66
|
+
export interface PosExchangeCreateInput {
|
|
67
|
+
returnOrderId: string;
|
|
68
|
+
orderId: string;
|
|
69
|
+
lines: PosReturnLineInput[];
|
|
70
|
+
/** `quote(...).credit` as shown. */
|
|
71
|
+
expectedCredit: number;
|
|
72
|
+
/** `quote(...).applied` as shown. */
|
|
73
|
+
expectedApplied: number;
|
|
74
|
+
overrideWindow?: boolean;
|
|
75
|
+
cashFirst?: boolean;
|
|
76
|
+
}
|
|
77
|
+
export interface PosExchangeResult {
|
|
78
|
+
returnOrderId: string;
|
|
79
|
+
orderId: string;
|
|
80
|
+
returnId: string;
|
|
81
|
+
/** The return's RMA code. */
|
|
82
|
+
returnCode: string;
|
|
83
|
+
credit: number;
|
|
84
|
+
applied: number;
|
|
85
|
+
excess: number;
|
|
86
|
+
carries: PosExchangeCarry[];
|
|
87
|
+
refunds: PosReturnRefund[];
|
|
88
|
+
cashPaidOut: number;
|
|
89
|
+
/** What the cart still owes: 0. Complete it with `sale.complete`. */
|
|
90
|
+
remaining: number;
|
|
91
|
+
complete: boolean;
|
|
92
|
+
}
|
|
93
|
+
export interface PosExchangesModule {
|
|
94
|
+
/** What an exchange would do now. Writes nothing. */
|
|
95
|
+
quote(input: PosExchangeQuoteInput, options?: Call): Promise<PosExchangeQuote>;
|
|
96
|
+
/** Exchange the items: the key is REQUIRED (`options.idempotencyKey`). */
|
|
97
|
+
create(input: PosExchangeCreateInput, options: Call & {
|
|
98
|
+
idempotencyKey: string;
|
|
99
|
+
}): Promise<PosExchangeResult>;
|
|
100
|
+
}
|
|
101
|
+
export declare const POS_EXCHANGE_QUOTE_QUERY = "query PosExchangeQuote($input: PosExchangeQuoteInput!) { posExchangeQuote(input: $input) { returnOrderId orderId currencyCode receiptNumber lines { orderLineId name sku customItem restockable soldQuantity returnedQuantity returnableQuantity quantity refundAmount } credit newSaleTotal newSalePaid due applied excess carries { sourcePaymentId kind method amount paymentId } legs { paymentId kind method amount } cashPaidOut returnWindowEndsAt outsideWindow refundedOutsideReturns restockLocationName blockedBy blockedReason } }";
|
|
102
|
+
export declare const POS_EXCHANGE_MUTATION = "mutation PosExchange($input: PosExchangeInput!) { posExchange(input: $input) { returnOrderId orderId returnId returnCode credit applied excess carries { sourcePaymentId kind method amount paymentId } refunds { paymentId kind method amount refundId outcome } cashPaidOut remaining complete } }";
|
|
103
|
+
export declare function createPosExchangesModule(transport: Transport): PosExchangesModule;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
const CARRY_FIELDS = 'sourcePaymentId kind method amount paymentId';
|
|
2
|
+
const QUOTE_FIELDS = `returnOrderId orderId currencyCode receiptNumber lines { orderLineId name sku customItem restockable soldQuantity returnedQuantity returnableQuantity quantity refundAmount } credit newSaleTotal newSalePaid due applied excess carries { ${CARRY_FIELDS} } legs { paymentId kind method amount } cashPaidOut returnWindowEndsAt outsideWindow refundedOutsideReturns restockLocationName blockedBy blockedReason`;
|
|
3
|
+
const RESULT_FIELDS = `returnOrderId orderId returnId returnCode credit applied excess carries { ${CARRY_FIELDS} } refunds { paymentId kind method amount refundId outcome } cashPaidOut remaining complete`;
|
|
4
|
+
export const POS_EXCHANGE_QUOTE_QUERY = `query PosExchangeQuote($input: PosExchangeQuoteInput!) { posExchangeQuote(input: $input) { ${QUOTE_FIELDS} } }`;
|
|
5
|
+
export const POS_EXCHANGE_MUTATION = `mutation PosExchange($input: PosExchangeInput!) { posExchange(input: $input) { ${RESULT_FIELDS} } }`;
|
|
6
|
+
export function createPosExchangesModule(transport) {
|
|
7
|
+
const gql = async (query, variables, options) => transport.graphql({ api: 'admin', query, variables }, options);
|
|
8
|
+
return {
|
|
9
|
+
async quote(input, options) {
|
|
10
|
+
const data = await gql(POS_EXCHANGE_QUOTE_QUERY, { input }, options);
|
|
11
|
+
return data.posExchangeQuote;
|
|
12
|
+
},
|
|
13
|
+
async create(input, options) {
|
|
14
|
+
const key = options?.idempotencyKey;
|
|
15
|
+
if (typeof key !== 'string' || key.trim() === '') {
|
|
16
|
+
throw new TypeError('pos.exchanges.create needs options.idempotencyKey (a fresh UUIDv7 per exchange; reuse it only to retry the same one).');
|
|
17
|
+
}
|
|
18
|
+
const data = await gql(POS_EXCHANGE_MUTATION, { input: { ...input, idempotencyKey: key } }, options);
|
|
19
|
+
return data.posExchange;
|
|
20
|
+
},
|
|
21
|
+
};
|
|
22
|
+
}
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import type { Transport } from '@sixtyninecommerce/core';
|
|
2
|
+
import type { Call } from '../types.js';
|
|
3
|
+
/**
|
|
4
|
+
* Gift cards at the till (engine C6): a headless till sells a gift card like any item, takes one
|
|
5
|
+
* as payment by its CODE, checks a card's balance, and hands a sale's codes over itself.
|
|
6
|
+
*
|
|
7
|
+
* - **Selling to anyone.** A sale whose buyer has no email address may sell a gift card when the
|
|
8
|
+
* till hands the codes over itself: call `setHandover` before the sale's first tender (a
|
|
9
|
+
* printer, or any way your till shows the code once). The sale's cards are then issued when it
|
|
10
|
+
* completes, and `completeSale` answers their codes in its FIRST answer only.
|
|
11
|
+
* - **The code is shown once and kept nowhere.** The engine stores no code; a retry of the same
|
|
12
|
+
* completion key answers the cards with `code: null`. Hand the codes to your customer (print
|
|
13
|
+
* them) straight from that first answer, and never log, cache or persist them: this SDK keeps
|
|
14
|
+
* none. A lost first answer loses the codes; a back-office `giftCards.reissueCode` gives the card
|
|
15
|
+
* a new one.
|
|
16
|
+
* - **Paying by code.** `tender` resolves the code on the engine and pays from that card; the
|
|
17
|
+
* payment never names the card's account (an account id is not a way to spend a card).
|
|
18
|
+
*
|
|
19
|
+
* Every money call is keyed (`idempotencyKey`). Each lookup and each tender spends one of the
|
|
20
|
+
* caller's gift-card lookups (rate limited per credential and per address). An engine before C6
|
|
21
|
+
* answers every call `GRAPHQL_VALIDATION_FAILED`.
|
|
22
|
+
*/
|
|
23
|
+
/** A gift card as a till sees it: masked, never its code. */
|
|
24
|
+
export interface PosGiftCardBalance {
|
|
25
|
+
/** `••••-••••-••••-K2Q7`. */
|
|
26
|
+
maskedCode: string;
|
|
27
|
+
/** What it can spend now, minor units of `currencyCode`. */
|
|
28
|
+
spendable: number;
|
|
29
|
+
currencyCode: string;
|
|
30
|
+
/** The last valid day (`YYYY-MM-DD`, store zone); null for no expiry. */
|
|
31
|
+
expiresOn: string | null;
|
|
32
|
+
/** `active`, `blocked` or `voided`; more may come (treat an unknown one as not usable). */
|
|
33
|
+
status: string;
|
|
34
|
+
/** Whether it can pay the sale named by `orderId` now; false without one. */
|
|
35
|
+
canPay: boolean;
|
|
36
|
+
/**
|
|
37
|
+
* Why not: `NO_SALE`, `EXPIRED`, `BLOCKED`, `CURRENCY`, `EMPTY`, `SALE_SELLS_GIFT_CARD`,
|
|
38
|
+
* `NOT_ACCEPTED`, `NOTHING_DUE`, `NOT_USABLE`; more may come. Null when it can pay.
|
|
39
|
+
*/
|
|
40
|
+
cannotPayReason: string | null;
|
|
41
|
+
}
|
|
42
|
+
/** What a till needs to sell a sale's gift cards. */
|
|
43
|
+
export interface PosGiftCardSale {
|
|
44
|
+
/** Gift-card units on the sale. */
|
|
45
|
+
units: number;
|
|
46
|
+
/** The till hands this sale's codes over itself (`setHandover`). */
|
|
47
|
+
handover: boolean;
|
|
48
|
+
/** The sale's customer can receive the codes by email (not the walk-in, not a placeholder). */
|
|
49
|
+
buyerHasEmail: boolean;
|
|
50
|
+
/** The store can issue gift cards now. */
|
|
51
|
+
canIssue: boolean;
|
|
52
|
+
}
|
|
53
|
+
/** A gift card a completed sale issued. */
|
|
54
|
+
export interface PosIssuedGiftCard {
|
|
55
|
+
maskedCode: string;
|
|
56
|
+
/** `XXXX-XXXX-XXXX-XXXX` in the first answer of a handed-over sale only; null otherwise. */
|
|
57
|
+
code: string | null;
|
|
58
|
+
faceValue: number;
|
|
59
|
+
currencyCode: string;
|
|
60
|
+
expiresOn: string | null;
|
|
61
|
+
}
|
|
62
|
+
/** A completed sale with its gift cards. */
|
|
63
|
+
export interface PosCompletedSaleWithGiftCards {
|
|
64
|
+
orderId: string;
|
|
65
|
+
orderCode: string;
|
|
66
|
+
receiptNumber: string;
|
|
67
|
+
state: string;
|
|
68
|
+
giftCards: PosIssuedGiftCard[];
|
|
69
|
+
/**
|
|
70
|
+
* The till hands this sale's codes over itself: they come in the first answer only, so a repeat
|
|
71
|
+
* answering them null cannot show them again. False for cards that went by email.
|
|
72
|
+
*/
|
|
73
|
+
giftCardsHandedOver: boolean;
|
|
74
|
+
}
|
|
75
|
+
/** A gift card's payment, as every tender answers. */
|
|
76
|
+
export interface PosGiftCardTenderResult {
|
|
77
|
+
orderId: string;
|
|
78
|
+
paymentId: string;
|
|
79
|
+
covered: boolean;
|
|
80
|
+
outstanding: number;
|
|
81
|
+
change: number;
|
|
82
|
+
}
|
|
83
|
+
/** A till call's cashier: a paired DEVICE's PIN session; a machine principal omits it. */
|
|
84
|
+
type TillCall = Call & {
|
|
85
|
+
staffToken?: string;
|
|
86
|
+
};
|
|
87
|
+
export interface PosGiftCardsModule {
|
|
88
|
+
/**
|
|
89
|
+
* This store's card for `code`, masked; null for an unknown, malformed or other store's code.
|
|
90
|
+
* With `orderId` (the tender screen's who-rule), `canPay` says whether it can pay what that sale
|
|
91
|
+
* still owes. Spends one gift-card lookup.
|
|
92
|
+
*/
|
|
93
|
+
byCode(code: string, sale?: {
|
|
94
|
+
orderId?: string | null;
|
|
95
|
+
}, options?: Call): Promise<PosGiftCardBalance | null>;
|
|
96
|
+
/** What the tender screen needs to sell the sale's gift cards. */
|
|
97
|
+
sale(orderId: string, options?: Call): Promise<PosGiftCardSale>;
|
|
98
|
+
/**
|
|
99
|
+
* Pay `amount` (at most what the card can spend and the sale still owes) from the card `code`
|
|
100
|
+
* names. Keyed: a repeat answers the same payment; the same key with another card is
|
|
101
|
+
* `IDEMPOTENCY_CONFLICT`. Refusals: `POS_GIFT_CARD_NOT_FOUND` (unknown, malformed or another
|
|
102
|
+
* store's code), `POS_STORED_VALUE_UNAVAILABLE`, `POS_TENDER_EXCEEDS_OUTSTANDING`, and the
|
|
103
|
+
* ledger's (`STORED_VALUE_INSUFFICIENT_BALANCE`, `STORED_VALUE_ACCOUNT_EXPIRED`,
|
|
104
|
+
* `STORED_VALUE_ACCOUNT_BLOCKED`, `STORED_VALUE_GIFT_CARD_PURCHASE_NOT_ALLOWED`, ...). Spends one
|
|
105
|
+
* gift-card lookup.
|
|
106
|
+
*/
|
|
107
|
+
tender(input: {
|
|
108
|
+
orderId: string;
|
|
109
|
+
code: string;
|
|
110
|
+
amount: number;
|
|
111
|
+
}, options: TillCall & {
|
|
112
|
+
idempotencyKey: string;
|
|
113
|
+
}): Promise<PosGiftCardTenderResult>;
|
|
114
|
+
/**
|
|
115
|
+
* The till hands this sale's codes over itself: before the first tender of an open till sale,
|
|
116
|
+
* one-way. Refusals: `POS_GIFT_CARD_HANDOVER_TOO_LATE` (money is in),
|
|
117
|
+
* `STORED_VALUE_GIFT_CARD_NOT_CONFIGURED` (the store cannot issue gift cards now).
|
|
118
|
+
*/
|
|
119
|
+
setHandover(orderId: string, options?: TillCall): Promise<PosGiftCardSale>;
|
|
120
|
+
/**
|
|
121
|
+
* `sale.complete` with the sale's gift cards: a handed-over sale's codes are in this call's
|
|
122
|
+
* FIRST answer only (a retry of the same key answers `code: null`). Hand them over at once and
|
|
123
|
+
* keep them nowhere; this SDK stores none.
|
|
124
|
+
*/
|
|
125
|
+
completeSale(orderId: string, options: TillCall & {
|
|
126
|
+
idempotencyKey: string;
|
|
127
|
+
}): Promise<PosCompletedSaleWithGiftCards>;
|
|
128
|
+
}
|
|
129
|
+
export declare const POS_GIFT_CARD_BY_CODE_QUERY = "query PosGiftCardByCode($code: String!, $orderId: ID) { posGiftCardByCode(code: $code, orderId: $orderId) { maskedCode spendable currencyCode expiresOn status canPay cannotPayReason } }";
|
|
130
|
+
export declare const POS_GIFT_CARD_SALE_QUERY = "query PosGiftCardSale($orderId: ID!) { posGiftCardSale(orderId: $orderId) { units handover buyerHasEmail canIssue } }";
|
|
131
|
+
export declare const POS_TENDER_GIFT_CARD_MUTATION = "mutation PosTenderGiftCard($input: PosTenderGiftCardInput!, $staffToken: String) { posTenderGiftCard(input: $input, staffToken: $staffToken) { orderId paymentId covered outstanding change } }";
|
|
132
|
+
export declare const POS_SET_GIFT_CARD_HANDOVER_MUTATION = "mutation PosSetGiftCardHandover($orderId: ID!, $staffToken: String) { posSetGiftCardHandover(orderId: $orderId, staffToken: $staffToken) { units handover buyerHasEmail canIssue } }";
|
|
133
|
+
export declare const POS_COMPLETE_SALE_WITH_GIFT_CARDS_MUTATION = "mutation PosCompleteSaleWithGiftCards($input: PosCompleteSaleInput!, $staffToken: String) { posCompleteSale(input: $input, staffToken: $staffToken) { orderId orderCode receiptNumber state giftCards { maskedCode code faceValue currencyCode expiresOn } giftCardsHandedOver } }";
|
|
134
|
+
export declare function createPosGiftCardsModule(transport: Transport): PosGiftCardsModule;
|
|
135
|
+
export {};
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
const BALANCE_FIELDS = 'maskedCode spendable currencyCode expiresOn status canPay cannotPayReason';
|
|
2
|
+
const SALE_FIELDS = 'units handover buyerHasEmail canIssue';
|
|
3
|
+
const TENDER_FIELDS = 'orderId paymentId covered outstanding change';
|
|
4
|
+
const ISSUED_FIELDS = 'maskedCode code faceValue currencyCode expiresOn';
|
|
5
|
+
export const POS_GIFT_CARD_BY_CODE_QUERY = `query PosGiftCardByCode($code: String!, $orderId: ID) { posGiftCardByCode(code: $code, orderId: $orderId) { ${BALANCE_FIELDS} } }`;
|
|
6
|
+
export const POS_GIFT_CARD_SALE_QUERY = `query PosGiftCardSale($orderId: ID!) { posGiftCardSale(orderId: $orderId) { ${SALE_FIELDS} } }`;
|
|
7
|
+
export const POS_TENDER_GIFT_CARD_MUTATION = `mutation PosTenderGiftCard($input: PosTenderGiftCardInput!, $staffToken: String) { posTenderGiftCard(input: $input, staffToken: $staffToken) { ${TENDER_FIELDS} } }`;
|
|
8
|
+
export const POS_SET_GIFT_CARD_HANDOVER_MUTATION = `mutation PosSetGiftCardHandover($orderId: ID!, $staffToken: String) { posSetGiftCardHandover(orderId: $orderId, staffToken: $staffToken) { ${SALE_FIELDS} } }`;
|
|
9
|
+
export const POS_COMPLETE_SALE_WITH_GIFT_CARDS_MUTATION = `mutation PosCompleteSaleWithGiftCards($input: PosCompleteSaleInput!, $staffToken: String) { posCompleteSale(input: $input, staffToken: $staffToken) { orderId orderCode receiptNumber state giftCards { ${ISSUED_FIELDS} } giftCardsHandedOver } }`;
|
|
10
|
+
function requireKey(method, options) {
|
|
11
|
+
const key = options?.idempotencyKey;
|
|
12
|
+
if (typeof key !== 'string' || key.trim() === '') {
|
|
13
|
+
throw new TypeError(`giftCards.${method} needs options.idempotencyKey (a fresh UUIDv7 per call; resend it only to retry the same one).`);
|
|
14
|
+
}
|
|
15
|
+
return key;
|
|
16
|
+
}
|
|
17
|
+
export function createPosGiftCardsModule(transport) {
|
|
18
|
+
const gql = async (query, variables, options) => transport.graphql({ api: 'admin', query, variables }, options);
|
|
19
|
+
return {
|
|
20
|
+
async byCode(code, sale, options) {
|
|
21
|
+
const data = await gql(POS_GIFT_CARD_BY_CODE_QUERY, { code, orderId: sale?.orderId ?? null }, options);
|
|
22
|
+
return data.posGiftCardByCode;
|
|
23
|
+
},
|
|
24
|
+
async sale(orderId, options) {
|
|
25
|
+
const data = await gql(POS_GIFT_CARD_SALE_QUERY, { orderId }, options);
|
|
26
|
+
return data.posGiftCardSale;
|
|
27
|
+
},
|
|
28
|
+
async tender(input, options) {
|
|
29
|
+
const idempotencyKey = requireKey('tender', options);
|
|
30
|
+
const data = await gql(POS_TENDER_GIFT_CARD_MUTATION, { input: { ...input, idempotencyKey }, staffToken: options.staffToken }, options);
|
|
31
|
+
return data.posTenderGiftCard;
|
|
32
|
+
},
|
|
33
|
+
async setHandover(orderId, options) {
|
|
34
|
+
const data = await gql(POS_SET_GIFT_CARD_HANDOVER_MUTATION, { orderId, staffToken: options?.staffToken }, options);
|
|
35
|
+
return data.posSetGiftCardHandover;
|
|
36
|
+
},
|
|
37
|
+
async completeSale(orderId, options) {
|
|
38
|
+
const idempotencyKey = requireKey('completeSale', options);
|
|
39
|
+
const data = await gql(POS_COMPLETE_SALE_WITH_GIFT_CARDS_MUTATION, { input: { orderId, idempotencyKey }, staffToken: options.staffToken }, options);
|
|
40
|
+
return {
|
|
41
|
+
...data.posCompleteSale,
|
|
42
|
+
giftCards: data.posCompleteSale.giftCards ?? [],
|
|
43
|
+
giftCardsHandedOver: data.posCompleteSale.giftCardsHandedOver === true,
|
|
44
|
+
};
|
|
45
|
+
},
|
|
46
|
+
};
|
|
47
|
+
}
|