@fire-spark/core 0.3.0 → 0.3.2
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/dist/index.d.ts +51 -8
- package/dist/index.js +84 -30
- package/package.json +3 -3
package/dist/index.d.ts
CHANGED
|
@@ -264,6 +264,13 @@ declare const updateOrder: (id: string, body: OrderUpdateInput, options?: Servic
|
|
|
264
264
|
declare const cancelOrder: (id: string, options?: ServiceHttpOptions) => Promise<Order$1>;
|
|
265
265
|
declare const refundOrder: (id: string, options?: ServiceHttpOptions) => Promise<Order$1>;
|
|
266
266
|
declare const reorderOrder: (id: string, body?: OrderReorderInput, options?: ServiceHttpOptions) => Promise<Order$1>;
|
|
267
|
+
/**
|
|
268
|
+
* `POST /storefront/v1/orders/:id/reopen`: voids every payment of a placed,
|
|
269
|
+
* unpaid order, cancels it (`VOIDED`) and returns the new `OPEN` order with
|
|
270
|
+
* the same content. Rejects with `StorefrontHttpError` 400
|
|
271
|
+
* (`details.code: "ORDER_PAYMENT_CAPTURED"`) when a payment was captured.
|
|
272
|
+
*/
|
|
273
|
+
declare const reopenOrder: (id: string, options?: ServiceHttpOptions) => Promise<Order$1>;
|
|
267
274
|
declare const validateOrder: (body: OrderValidateInput, options?: ServiceHttpOptions) => Promise<OrderValidateOutput>;
|
|
268
275
|
//#endregion
|
|
269
276
|
//#region src/order/payments/orchestrator.d.ts
|
|
@@ -399,7 +406,10 @@ type ReorderOrderOptions = CreateOrderOptions & {
|
|
|
399
406
|
type OrderDraft = Order$2;
|
|
400
407
|
type ApplyRedeemInput = {
|
|
401
408
|
reward_id: string;
|
|
402
|
-
/**
|
|
409
|
+
/**
|
|
410
|
+
* Reward units to redeem (integer ≥ 1). With `payment_id` it is
|
|
411
|
+
* informational: `amount` and `points` already cover every unit.
|
|
412
|
+
*/
|
|
403
413
|
quantity: number;
|
|
404
414
|
/** 0–1, compounded per unit over the remaining value. */
|
|
405
415
|
discount_rate?: number;
|
|
@@ -414,11 +424,16 @@ type ApplyRedeemInput = {
|
|
|
414
424
|
line_uid?: string;
|
|
415
425
|
/**
|
|
416
426
|
* Points / balance: the merchant `REDEMPTION` payment that pays `amount`
|
|
417
|
-
* (a tender, not a discount). Requires `amount` and `points`.
|
|
427
|
+
* (a tender, not a discount). Requires `amount` and `points`. Redeems
|
|
428
|
+
* with the same `payment_id` share one tender (`details.rewards[]`).
|
|
418
429
|
*/
|
|
419
430
|
payment_id?: string;
|
|
420
|
-
/**
|
|
431
|
+
/**
|
|
432
|
+
* Total money the points cover for the whole entry (all `quantity`
|
|
433
|
+
* units, not per unit); trimmed to total − tip − delivery.
|
|
434
|
+
*/
|
|
421
435
|
amount?: number;
|
|
436
|
+
/** Total points spent for the whole entry (not per unit). */
|
|
422
437
|
points?: number;
|
|
423
438
|
program?: string;
|
|
424
439
|
/** Provider of the REDEMPTION payment (default `firespark`). */
|
|
@@ -443,6 +458,7 @@ declare class Order {
|
|
|
443
458
|
private readonly listeners;
|
|
444
459
|
private readonly externalNotify?;
|
|
445
460
|
private readonly http;
|
|
461
|
+
private readonly debounceMs;
|
|
446
462
|
private readonly flush;
|
|
447
463
|
private readonly payments;
|
|
448
464
|
/** Real tenders chosen with `setTenders`; REDEMPTION ones come from redeem. */
|
|
@@ -496,14 +512,19 @@ declare class Order {
|
|
|
496
512
|
/**
|
|
497
513
|
* Appends a redeem to `line_uid` (root line) or to the order. Steps keep
|
|
498
514
|
* the order in which redeems were applied. With `payment_id` (points /
|
|
499
|
-
* balance) it is not a discount:
|
|
500
|
-
*
|
|
515
|
+
* balance) it is not a discount: `amount` and `points` are totals of the
|
|
516
|
+
* whole entry (every unit, not per unit) and `quantity` is informational.
|
|
517
|
+
* Every redeem with the same `payment_id` is paid by one REDEMPTION
|
|
518
|
+
* tender whose `details.rewards[]` lists them; their summed amount is
|
|
519
|
+
* capped at total − tip − delivery (D15, D18, D19).
|
|
501
520
|
*/
|
|
502
521
|
applyRedeem(input: ApplyRedeemInput): void;
|
|
503
522
|
/**
|
|
504
523
|
* Removes `quantity` units of `reward_id` from `line_uid` or the order,
|
|
505
524
|
* latest applied first. Removing more units than applied clears them all
|
|
506
|
-
* (and the REDEMPTION tender of a points / balance redeem).
|
|
525
|
+
* (and the REDEMPTION tender of a points / balance redeem). A points /
|
|
526
|
+
* balance entry that keeps some units keeps the same share of its
|
|
527
|
+
* `amount` and `points`.
|
|
507
528
|
*/
|
|
508
529
|
removeRedeem(input: RemoveRedeemInput): void;
|
|
509
530
|
private rememberLogScope;
|
|
@@ -515,6 +536,17 @@ declare class Order {
|
|
|
515
536
|
billing_info?: Order$1["customer"]["billing_info"];
|
|
516
537
|
}): void;
|
|
517
538
|
cancelOrder(): Promise<void>;
|
|
539
|
+
/**
|
|
540
|
+
* Reopens this placed, unpaid order: the server voids every payment
|
|
541
|
+
* (REDEMPTION points released), cancels it as `VOIDED` and opens a new
|
|
542
|
+
* `OPEN` order with the same content. This instance is closed afterwards;
|
|
543
|
+
* replace it with the returned `Order` (same HTTP options and listener).
|
|
544
|
+
*
|
|
545
|
+
* Rejects with `StorefrontHttpError` 400 and
|
|
546
|
+
* `details.code: "ORDER_PAYMENT_CAPTURED"` when a payment was already
|
|
547
|
+
* captured; nothing changes then and this instance stays usable.
|
|
548
|
+
*/
|
|
549
|
+
reopen(): Promise<Order>;
|
|
518
550
|
refundOrder(): Promise<void>;
|
|
519
551
|
validateOrder(): Promise<void>;
|
|
520
552
|
/** Tenders of the next intent: real ones plus one per payment redeem. */
|
|
@@ -810,7 +842,17 @@ declare const listMenus: (scope?: StorefrontMenuScope, options?: ServiceHttpOpti
|
|
|
810
842
|
declare const listMenusStream: (scope?: StorefrontMenuScope, options?: ListMenusStreamOptions) => AsyncGenerator<StorefrontMenu[], any, any>;
|
|
811
843
|
//#endregion
|
|
812
844
|
//#region src/services/payments.d.ts
|
|
813
|
-
|
|
845
|
+
type ListPaymentsOptions = ServiceHttpOptions & {
|
|
846
|
+
/** Keep `REDEMPTION` payments (points / balance) for redeem flows. */
|
|
847
|
+
includeRedemptions?: boolean;
|
|
848
|
+
};
|
|
849
|
+
/**
|
|
850
|
+
* Payments a customer can pick at checkout. `REDEMPTION` payments are
|
|
851
|
+
* applied through the order's `redeem` entries, never chosen as a method.
|
|
852
|
+
*/
|
|
853
|
+
declare const selectablePayments: <T extends MerchantPayment>(payments: readonly T[]) => T[];
|
|
854
|
+
/** Lists payments without `REDEMPTION` unless `includeRedemptions` is set. */
|
|
855
|
+
declare const listPayments: (input: StorefrontPaymentsListInput, options?: ListPaymentsOptions) => Promise<MerchantPayment[]>;
|
|
814
856
|
type PaymentOperationBody = {
|
|
815
857
|
order_id: string | null;
|
|
816
858
|
attempt_reference: string | null;
|
|
@@ -936,6 +978,7 @@ declare const services: {
|
|
|
936
978
|
cancel: typeof cancelOrder;
|
|
937
979
|
refund: typeof refundOrder;
|
|
938
980
|
reorder: typeof reorderOrder;
|
|
981
|
+
reopen: typeof reopenOrder;
|
|
939
982
|
validate: typeof validateOrder;
|
|
940
983
|
place: typeof placeOrder;
|
|
941
984
|
recordPayment: typeof recordOrderPayment;
|
|
@@ -1263,4 +1306,4 @@ declare const validateCardholderName: (value: string) => CardholderNameError | n
|
|
|
1263
1306
|
*/
|
|
1264
1307
|
declare const cardPreviewGroups: (value: string) => CardPreviewSlot[][];
|
|
1265
1308
|
//#endregion
|
|
1266
|
-
export { type ApplyRedeemInput, type AuthConfigureOptions, CARD_BRANDS, type CardBrand, type CardBrandSpec, type CardCvcError, type CardExpiry, type CardExpiryError, type CardNumberError, type CardPreviewSlot, type CardholderNameError, type CreateOrderOptions, type CreateSessionOptions, type CustomizationPath, type CustomizationSession, DEFAULT_RECOMMENDATION_TYPES, type ExchangeOptions, type FailedCharge, type FlatMenuCategory, type GroupDisplayType, type IdBuilder, type ListMenusStreamOptions, type Menu, type MenuCategoryNode, type MenuLookup, type MilestoneSteps, type MilestoneTrackItem, type ModifierControlType, type ModifierCtx, type ModifierGroupCtx, type NestedMenuCategory, Order, type OrderCustomerSource, type OrderDraft, type OrderIssue, type OrderIssueCode, type OrderLineDiff, type OrderLineIssue, type OrderLineIssueCode, type OrderScope, OrderSyncPendingError, OrderValidationError, type OrderValidationResult, type PayIntentOptions, type PayIntentResult, type PayOptions, type PaymentCardBrand, type PaymentProgressEvent, type PaymentProgressListener, type PaymentRunOptions, type PaymentSessionOptions, type PricingModifier, type Product, type ProductCtx, type QuantitiesByPath, type RecommendationType, RecurringDateCron, type RemoveRedeemInput, type ReorderOrderOptions, type ResetOptions, type ReversalOutcome, type ReverseAllOptions, RulesEngine, type ScheduleWindow, type SelectionStatus, type SelectionsByPath, type SerializedError, type ServiceHttpOptions, type SimpleTenderPayment, type Snapshot, type StorefrontAccessToken, type StorefrontErrorDetails, StorefrontHttpError, type TrackWorkflow, type ValidateOptions, type ValidateOrderAgainstMenuInput, type Variant, type VariantGroup, type VariantGroupCtx, type VariantOptionCtx, type VariantSelection, type VerifyWebhookSignatureInput, type VisitedState, addLines, auth, buildCustomerSnapshot, cardBrandSpec, cardDigits, cardNumberGaps, cardNumberMaxLength, cardPreviewGroups, caretAfterDigits, collectOrderLineDiffs, computeStartingPrice, countCartProducts, coveredAmount, createSession, currentNodes, cvcMaxLength, defaultConditionError, detectCardBrand, flattenMenuCategories, flushLogs, formatCardNumber, formatCvc, formatExpiry, fromOrderLines, genId, genOrderId, getLogContext, getScheduleWindow, indexMenu, isCardNumberComplete, isCardNumberDefinitelyInvalid, isCheckoutFieldFilled, isCvcComplete, isDeviceCharged, isDeviceNotLinked, isExpiryComplete, isKioskUnauthorized, isMilestoneStepDone, isOnSchedule, isOrderValidationError, isPosDeviceNotLinked, isPosUnauthorized, isRealPaymentMethod, isStorefrontNotFound, isVariantBase, listMenusStream, localizePosError, log, logError, luhnCheck, matchAbsoluteDateOperator, matchBooleanOperator, matchCurrencyOperator, matchEnumOperator, matchNumberOperator, matchRecurringDateOperator, matchRelativeDateOperator, matchStringOperator, milestoneSteps, milestoneTrack, nestMenuCategories, normalizeCardholderName, parseExpiry, paymentMatchesClientConditions, recomputeRedemptions, recomputeTotals, redemptionCap, remainingAmount, removeLine, replaceLine, resolveCheckout, reversePayment, runPaymentAttempt, serializeError, services, setLineQuantity, storefrontJson, stripRedemptionLines, toOrderLines, toPaymentCardBrand, validateCardNumber, validateCardholderName, validateCvc, validateExpiry, validateOrderAgainstMenu, verifyWebhookSignature, visitedStates };
|
|
1309
|
+
export { type ApplyRedeemInput, type AuthConfigureOptions, CARD_BRANDS, type CardBrand, type CardBrandSpec, type CardCvcError, type CardExpiry, type CardExpiryError, type CardNumberError, type CardPreviewSlot, type CardholderNameError, type CreateOrderOptions, type CreateSessionOptions, type CustomizationPath, type CustomizationSession, DEFAULT_RECOMMENDATION_TYPES, type ExchangeOptions, type FailedCharge, type FlatMenuCategory, type GroupDisplayType, type IdBuilder, type ListMenusStreamOptions, type ListPaymentsOptions, type Menu, type MenuCategoryNode, type MenuLookup, type MilestoneSteps, type MilestoneTrackItem, type ModifierControlType, type ModifierCtx, type ModifierGroupCtx, type NestedMenuCategory, Order, type OrderCustomerSource, type OrderDraft, type OrderIssue, type OrderIssueCode, type OrderLineDiff, type OrderLineIssue, type OrderLineIssueCode, type OrderScope, OrderSyncPendingError, OrderValidationError, type OrderValidationResult, type PayIntentOptions, type PayIntentResult, type PayOptions, type PaymentCardBrand, type PaymentProgressEvent, type PaymentProgressListener, type PaymentRunOptions, type PaymentSessionOptions, type PricingModifier, type Product, type ProductCtx, type QuantitiesByPath, type RecommendationType, RecurringDateCron, type RemoveRedeemInput, type ReorderOrderOptions, type ResetOptions, type ReversalOutcome, type ReverseAllOptions, RulesEngine, type ScheduleWindow, type SelectionStatus, type SelectionsByPath, type SerializedError, type ServiceHttpOptions, type SimpleTenderPayment, type Snapshot, type StorefrontAccessToken, type StorefrontErrorDetails, StorefrontHttpError, type TrackWorkflow, type ValidateOptions, type ValidateOrderAgainstMenuInput, type Variant, type VariantGroup, type VariantGroupCtx, type VariantOptionCtx, type VariantSelection, type VerifyWebhookSignatureInput, type VisitedState, addLines, auth, buildCustomerSnapshot, cardBrandSpec, cardDigits, cardNumberGaps, cardNumberMaxLength, cardPreviewGroups, caretAfterDigits, collectOrderLineDiffs, computeStartingPrice, countCartProducts, coveredAmount, createSession, currentNodes, cvcMaxLength, defaultConditionError, detectCardBrand, flattenMenuCategories, flushLogs, formatCardNumber, formatCvc, formatExpiry, fromOrderLines, genId, genOrderId, getLogContext, getScheduleWindow, indexMenu, isCardNumberComplete, isCardNumberDefinitelyInvalid, isCheckoutFieldFilled, isCvcComplete, isDeviceCharged, isDeviceNotLinked, isExpiryComplete, isKioskUnauthorized, isMilestoneStepDone, isOnSchedule, isOrderValidationError, isPosDeviceNotLinked, isPosUnauthorized, isRealPaymentMethod, isStorefrontNotFound, isVariantBase, listMenusStream, localizePosError, log, logError, luhnCheck, matchAbsoluteDateOperator, matchBooleanOperator, matchCurrencyOperator, matchEnumOperator, matchNumberOperator, matchRecurringDateOperator, matchRelativeDateOperator, matchStringOperator, milestoneSteps, milestoneTrack, nestMenuCategories, normalizeCardholderName, parseExpiry, paymentMatchesClientConditions, recomputeRedemptions, recomputeTotals, redemptionCap, remainingAmount, removeLine, replaceLine, resolveCheckout, reversePayment, runPaymentAttempt, selectablePayments, serializeError, services, setLineQuantity, storefrontJson, stripRedemptionLines, toOrderLines, toPaymentCardBrand, validateCardNumber, validateCardholderName, validateCvc, validateExpiry, validateOrderAgainstMenu, verifyWebhookSignature, visitedStates };
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { DIGITAL_COLLECT_AT, PARTIAL_APPROVAL_ERROR, activeIntent, amountTolerance, createAttemptReference, createPaymentError, currencyDecimals, currentIntent, defaultReversalFor, isDeliveryFee, isPaymentError, isRealPaymentMethod, isTenderSettled, isTipFee, liveTenders, memoryPaymentStorage, missingDeviceFields, resolvePaymentPolicy, resolveProviderEnvironment, roundTo, scopedPaymentStorage, taxBreakdown, toChargeAmount, withTerminalLock } from "@fire-spark/payments";
|
|
1
|
+
import { DIGITAL_COLLECT_AT, PARTIAL_APPROVAL_ERROR, activeIntent, amountTolerance, createAttemptReference, createPaymentError, currencyDecimals, currentIntent, defaultReversalFor, groupPaymentRedeems, isDeliveryFee, isPaymentError, isRealPaymentMethod, isRealPaymentMethod as isRealPaymentMethod$1, isTenderSettled, isTipFee, liveTenders, memoryPaymentStorage, missingDeviceFields, resolvePaymentPolicy, resolveProviderEnvironment, roundTo, scopedPaymentStorage, taxBreakdown, toChargeAmount, withTerminalLock } from "@fire-spark/payments";
|
|
2
2
|
import advancedFormat from "dayjs/plugin/advancedFormat.js";
|
|
3
3
|
import isBetween from "dayjs/plugin/isBetween.js";
|
|
4
4
|
import isSameOrAfter from "dayjs/plugin/isSameOrAfter.js";
|
|
@@ -2605,6 +2605,15 @@ const reorderOrder = (id, body = {}, options) => {
|
|
|
2605
2605
|
body: JSON.stringify(body)
|
|
2606
2606
|
}, options);
|
|
2607
2607
|
};
|
|
2608
|
+
/**
|
|
2609
|
+
* `POST /storefront/v1/orders/:id/reopen`: voids every payment of a placed,
|
|
2610
|
+
* unpaid order, cancels it (`VOIDED`) and returns the new `OPEN` order with
|
|
2611
|
+
* the same content. Rejects with `StorefrontHttpError` 400
|
|
2612
|
+
* (`details.code: "ORDER_PAYMENT_CAPTURED"`) when a payment was captured.
|
|
2613
|
+
*/
|
|
2614
|
+
const reopenOrder = (id, options) => {
|
|
2615
|
+
return storefrontJson(`${orderPath(id)}/reopen`, { method: "POST" }, options);
|
|
2616
|
+
};
|
|
2608
2617
|
const parseValidationDetails = (body) => {
|
|
2609
2618
|
if (!body || typeof body !== "object") return null;
|
|
2610
2619
|
const details = body.details;
|
|
@@ -2641,10 +2650,21 @@ const validateOrder = async (body, options) => {
|
|
|
2641
2650
|
};
|
|
2642
2651
|
//#endregion
|
|
2643
2652
|
//#region src/services/payments.ts
|
|
2644
|
-
|
|
2653
|
+
/**
|
|
2654
|
+
* Payments a customer can pick at checkout. `REDEMPTION` payments are
|
|
2655
|
+
* applied through the order's `redeem` entries, never chosen as a method.
|
|
2656
|
+
*/
|
|
2657
|
+
const selectablePayments = (payments) => {
|
|
2658
|
+
return payments.filter((payment) => isRealPaymentMethod$1(payment.method.method));
|
|
2659
|
+
};
|
|
2660
|
+
/** Lists payments without `REDEMPTION` unless `includeRedemptions` is set. */
|
|
2661
|
+
const listPayments = async (input, options = {}) => {
|
|
2662
|
+
const { includeRedemptions = false, ...http } = options;
|
|
2645
2663
|
const params = new URLSearchParams();
|
|
2646
2664
|
for (const [key, value] of Object.entries(input)) if (value) params.set(key, value);
|
|
2647
|
-
|
|
2665
|
+
const payments = await storefrontJson(`/api/storefront/v1/payments?${params.toString()}`, {}, http);
|
|
2666
|
+
if (includeRedemptions) return payments;
|
|
2667
|
+
return selectablePayments(payments);
|
|
2648
2668
|
};
|
|
2649
2669
|
/** Server half of an adapter (`POST /payments/:id/operations/:operation`). */
|
|
2650
2670
|
const callPaymentOperation = (paymentId, operation, body, options) => {
|
|
@@ -2929,6 +2949,7 @@ const services = {
|
|
|
2929
2949
|
cancel: cancelOrder,
|
|
2930
2950
|
refund: refundOrder,
|
|
2931
2951
|
reorder: reorderOrder,
|
|
2952
|
+
reopen: reopenOrder,
|
|
2932
2953
|
validate: validateOrder,
|
|
2933
2954
|
place: placeOrder,
|
|
2934
2955
|
recordPayment: recordOrderPayment,
|
|
@@ -3532,6 +3553,22 @@ const buildRedeem = (input) => {
|
|
|
3532
3553
|
if (expires_at !== void 0) redeem.expires_at = expires_at;
|
|
3533
3554
|
return redeem;
|
|
3534
3555
|
};
|
|
3556
|
+
/** Payment redeems hold totals, so the kept units keep their share. */
|
|
3557
|
+
const keepUnits = (item, rest) => {
|
|
3558
|
+
if (!isPaymentRedeem(item) || rest === item.quantity) return {
|
|
3559
|
+
...item,
|
|
3560
|
+
quantity: rest
|
|
3561
|
+
};
|
|
3562
|
+
const ratio = new Big(rest).div(item.quantity);
|
|
3563
|
+
const amount = new Big(item.amount ?? 0).times(ratio).round(6).toNumber();
|
|
3564
|
+
const points = new Big(item.points ?? 0).times(ratio).round(0).toNumber();
|
|
3565
|
+
return {
|
|
3566
|
+
...item,
|
|
3567
|
+
quantity: rest,
|
|
3568
|
+
amount,
|
|
3569
|
+
points
|
|
3570
|
+
};
|
|
3571
|
+
};
|
|
3535
3572
|
/**
|
|
3536
3573
|
* Takes `quantity` units of `reward_id` off the latest entries first, so the
|
|
3537
3574
|
* earlier redeems keep their step position. Entries that reach 0 are removed.
|
|
@@ -3549,10 +3586,7 @@ const subtractRedeem = (items, reward_id, quantity) => {
|
|
|
3549
3586
|
const taken = Math.min(item.quantity, pending);
|
|
3550
3587
|
pending -= taken;
|
|
3551
3588
|
const rest = item.quantity - taken;
|
|
3552
|
-
if (rest > 0) kept.unshift(
|
|
3553
|
-
...item,
|
|
3554
|
-
quantity: rest
|
|
3555
|
-
});
|
|
3589
|
+
if (rest > 0) kept.unshift(keepUnits(item, rest));
|
|
3556
3590
|
}
|
|
3557
3591
|
return kept;
|
|
3558
3592
|
};
|
|
@@ -3888,29 +3922,16 @@ const clampPaymentRedeems = (redeem, cap, currency) => {
|
|
|
3888
3922
|
}];
|
|
3889
3923
|
});
|
|
3890
3924
|
};
|
|
3891
|
-
/**
|
|
3925
|
+
/**
|
|
3926
|
+
* One REDEMPTION tender per `payment_id` of the payment redeems (D15,
|
|
3927
|
+
* D19); its `details.rewards[]` lists every grouped redeem.
|
|
3928
|
+
*/
|
|
3892
3929
|
const redemptionTenderInputs = (redeem, providers = /* @__PURE__ */ new Map()) => {
|
|
3893
|
-
return redeem
|
|
3894
|
-
const payment_id = item.payment_id;
|
|
3930
|
+
return groupPaymentRedeems(redeem).map(({ payment_id, details }) => {
|
|
3895
3931
|
const fallback = DEFAULT_REDEMPTION_PROVIDER;
|
|
3896
|
-
const provider = providers.get(payment_id) ?? fallback;
|
|
3897
|
-
const program = item.program ?? item.reward_id;
|
|
3898
|
-
const d1 = {
|
|
3899
|
-
method: "REDEMPTION",
|
|
3900
|
-
reward_id: item.reward_id
|
|
3901
|
-
};
|
|
3902
|
-
const d2 = {
|
|
3903
|
-
program,
|
|
3904
|
-
points: item.points ?? 0
|
|
3905
|
-
};
|
|
3906
|
-
const details = {
|
|
3907
|
-
...d1,
|
|
3908
|
-
...d2,
|
|
3909
|
-
points_value: item.amount ?? 0
|
|
3910
|
-
};
|
|
3911
3932
|
const t1 = {
|
|
3912
3933
|
method: "REDEMPTION",
|
|
3913
|
-
provider,
|
|
3934
|
+
provider: providers.get(payment_id) ?? fallback,
|
|
3914
3935
|
payment_id
|
|
3915
3936
|
};
|
|
3916
3937
|
const t2 = {
|
|
@@ -5268,6 +5289,7 @@ var Order = class Order {
|
|
|
5268
5289
|
listeners = /* @__PURE__ */ new Set();
|
|
5269
5290
|
externalNotify;
|
|
5270
5291
|
http;
|
|
5292
|
+
debounceMs;
|
|
5271
5293
|
flush;
|
|
5272
5294
|
payments;
|
|
5273
5295
|
/** Real tenders chosen with `setTenders`; REDEMPTION ones come from redeem. */
|
|
@@ -5279,6 +5301,7 @@ var Order = class Order {
|
|
|
5279
5301
|
this.rememberLogScope();
|
|
5280
5302
|
this.persisted = config.persisted;
|
|
5281
5303
|
this.http = config.http;
|
|
5304
|
+
this.debounceMs = config.debounceMs;
|
|
5282
5305
|
this.externalNotify = notify;
|
|
5283
5306
|
this.flush = createFlushController({
|
|
5284
5307
|
getDraft: () => this.draft,
|
|
@@ -5472,8 +5495,11 @@ var Order = class Order {
|
|
|
5472
5495
|
/**
|
|
5473
5496
|
* Appends a redeem to `line_uid` (root line) or to the order. Steps keep
|
|
5474
5497
|
* the order in which redeems were applied. With `payment_id` (points /
|
|
5475
|
-
* balance) it is not a discount:
|
|
5476
|
-
*
|
|
5498
|
+
* balance) it is not a discount: `amount` and `points` are totals of the
|
|
5499
|
+
* whole entry (every unit, not per unit) and `quantity` is informational.
|
|
5500
|
+
* Every redeem with the same `payment_id` is paid by one REDEMPTION
|
|
5501
|
+
* tender whose `details.rewards[]` lists them; their summed amount is
|
|
5502
|
+
* capped at total − tip − delivery (D15, D18, D19).
|
|
5477
5503
|
*/
|
|
5478
5504
|
applyRedeem(input) {
|
|
5479
5505
|
if (this.deleted) return;
|
|
@@ -5499,7 +5525,9 @@ var Order = class Order {
|
|
|
5499
5525
|
/**
|
|
5500
5526
|
* Removes `quantity` units of `reward_id` from `line_uid` or the order,
|
|
5501
5527
|
* latest applied first. Removing more units than applied clears them all
|
|
5502
|
-
* (and the REDEMPTION tender of a points / balance redeem).
|
|
5528
|
+
* (and the REDEMPTION tender of a points / balance redeem). A points /
|
|
5529
|
+
* balance entry that keeps some units keeps the same share of its
|
|
5530
|
+
* `amount` and `points`.
|
|
5503
5531
|
*/
|
|
5504
5532
|
removeRedeem(input) {
|
|
5505
5533
|
if (this.deleted) return;
|
|
@@ -5604,6 +5632,32 @@ var Order = class Order {
|
|
|
5604
5632
|
this.deleted = true;
|
|
5605
5633
|
this.notify();
|
|
5606
5634
|
}
|
|
5635
|
+
/**
|
|
5636
|
+
* Reopens this placed, unpaid order: the server voids every payment
|
|
5637
|
+
* (REDEMPTION points released), cancels it as `VOIDED` and opens a new
|
|
5638
|
+
* `OPEN` order with the same content. This instance is closed afterwards;
|
|
5639
|
+
* replace it with the returned `Order` (same HTTP options and listener).
|
|
5640
|
+
*
|
|
5641
|
+
* Rejects with `StorefrontHttpError` 400 and
|
|
5642
|
+
* `details.code: "ORDER_PAYMENT_CAPTURED"` when a payment was already
|
|
5643
|
+
* captured; nothing changes then and this instance stays usable.
|
|
5644
|
+
*/
|
|
5645
|
+
async reopen() {
|
|
5646
|
+
if (!this.persisted) throw new Error("Only a placed order is reopened");
|
|
5647
|
+
this.flush.cancel();
|
|
5648
|
+
const c1 = {
|
|
5649
|
+
order: await services.orders.reopen(this.draft.id, this.http),
|
|
5650
|
+
http: this.http,
|
|
5651
|
+
debounceMs: this.debounceMs
|
|
5652
|
+
};
|
|
5653
|
+
const reopened = new Order({
|
|
5654
|
+
...c1,
|
|
5655
|
+
persisted: true
|
|
5656
|
+
}, this.externalNotify);
|
|
5657
|
+
this.deleted = true;
|
|
5658
|
+
this.notify();
|
|
5659
|
+
return reopened;
|
|
5660
|
+
}
|
|
5607
5661
|
async refundOrder() {
|
|
5608
5662
|
if (this.deleted) return;
|
|
5609
5663
|
this.flush.cancel();
|
|
@@ -8531,4 +8585,4 @@ const cardPreviewGroups = (value) => {
|
|
|
8531
8585
|
return groups;
|
|
8532
8586
|
};
|
|
8533
8587
|
//#endregion
|
|
8534
|
-
export { CARD_BRANDS, DEFAULT_RECOMMENDATION_TYPES, Order, OrderSyncPendingError, OrderValidationError, RecurringDateCron, RulesEngine, StorefrontHttpError, addLines, auth, buildCustomerSnapshot, cardBrandSpec, cardDigits, cardNumberGaps, cardNumberMaxLength, cardPreviewGroups, caretAfterDigits, collectOrderLineDiffs, computeStartingPrice, countCartProducts, coveredAmount, createSession, currentNodes, cvcMaxLength, defaultConditionError, detectCardBrand, flattenMenuCategories, flushLogs, formatCardNumber, formatCvc, formatExpiry, fromOrderLines, genId, genOrderId, getLogContext, getScheduleWindow, indexMenu, isCardNumberComplete, isCardNumberDefinitelyInvalid, isCheckoutFieldFilled, isCvcComplete, isDeviceCharged, isDeviceNotLinked, isExpiryComplete, isKioskUnauthorized, isMilestoneStepDone, isOnSchedule, isOrderValidationError, isPosDeviceNotLinked, isPosUnauthorized, isRealPaymentMethod, isStorefrontNotFound, isVariantBase, listMenusStream, localizePosError, log, logError, luhnCheck, matchAbsoluteDateOperator, matchBooleanOperator, matchCurrencyOperator, matchEnumOperator, matchNumberOperator, matchRecurringDateOperator, matchRelativeDateOperator, matchStringOperator, milestoneSteps, milestoneTrack, nestMenuCategories, normalizeCardholderName, parseExpiry, paymentMatchesClientConditions, recomputeRedemptions, recomputeTotals, redemptionCap, remainingAmount, removeLine, replaceLine, resolveCheckout, reversePayment, runPaymentAttempt, serializeError, services, setLineQuantity, storefrontJson, stripRedemptionLines, toOrderLines, toPaymentCardBrand, validateCardNumber, validateCardholderName, validateCvc, validateExpiry, validateOrderAgainstMenu, verifyWebhookSignature, visitedStates };
|
|
8588
|
+
export { CARD_BRANDS, DEFAULT_RECOMMENDATION_TYPES, Order, OrderSyncPendingError, OrderValidationError, RecurringDateCron, RulesEngine, StorefrontHttpError, addLines, auth, buildCustomerSnapshot, cardBrandSpec, cardDigits, cardNumberGaps, cardNumberMaxLength, cardPreviewGroups, caretAfterDigits, collectOrderLineDiffs, computeStartingPrice, countCartProducts, coveredAmount, createSession, currentNodes, cvcMaxLength, defaultConditionError, detectCardBrand, flattenMenuCategories, flushLogs, formatCardNumber, formatCvc, formatExpiry, fromOrderLines, genId, genOrderId, getLogContext, getScheduleWindow, indexMenu, isCardNumberComplete, isCardNumberDefinitelyInvalid, isCheckoutFieldFilled, isCvcComplete, isDeviceCharged, isDeviceNotLinked, isExpiryComplete, isKioskUnauthorized, isMilestoneStepDone, isOnSchedule, isOrderValidationError, isPosDeviceNotLinked, isPosUnauthorized, isRealPaymentMethod, isStorefrontNotFound, isVariantBase, listMenusStream, localizePosError, log, logError, luhnCheck, matchAbsoluteDateOperator, matchBooleanOperator, matchCurrencyOperator, matchEnumOperator, matchNumberOperator, matchRecurringDateOperator, matchRelativeDateOperator, matchStringOperator, milestoneSteps, milestoneTrack, nestMenuCategories, normalizeCardholderName, parseExpiry, paymentMatchesClientConditions, recomputeRedemptions, recomputeTotals, redemptionCap, remainingAmount, removeLine, replaceLine, resolveCheckout, reversePayment, runPaymentAttempt, selectablePayments, serializeError, services, setLineQuantity, storefrontJson, stripRedemptionLines, toOrderLines, toPaymentCardBrand, validateCardNumber, validateCardholderName, validateCvc, validateExpiry, validateOrderAgainstMenu, verifyWebhookSignature, visitedStates };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fire-spark/core",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.2",
|
|
4
4
|
"description": "Fire Spark headless SDK",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -20,8 +20,8 @@
|
|
|
20
20
|
"big.js": "6.2.1",
|
|
21
21
|
"dayjs": "1.11.9",
|
|
22
22
|
"@types/big.js": "6.2.2",
|
|
23
|
-
"@fire-spark/payments": "^0.3.
|
|
24
|
-
"@fire-spark/types": "^0.3.
|
|
23
|
+
"@fire-spark/payments": "^0.3.2",
|
|
24
|
+
"@fire-spark/types": "^0.3.2"
|
|
25
25
|
},
|
|
26
26
|
"devDependencies": {
|
|
27
27
|
"tsdown": "^0.22.14",
|