@fire-spark/core 0.17.1 → 0.17.3
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 +53 -31
- package/dist/index.js +89 -31
- package/package.json +3 -3
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Money, PaymentAdapter, PaymentCollectAt, PaymentContext, PaymentResult, PaymentReversal, PaymentStorage, PaymentUI, RedeemLike, RedeemSource, isRealPaymentMethod, orderRedeems } from "@fire-spark/payments";
|
|
2
|
-
import { AndConditions, CheckoutMode, CheckoutResolved, CmsBlock, Condition, Customer, CustomerIdentifyInput, CustomerRegisterInput, CustomerUpdateInput, Fulfillment, FulfillmentListInput, GroupDisplayType, KioskDeviceConfig, KioskDeviceConfigInput, KioskDeviceOverrides, KioskHealthBatchInput, KioskHealthBatchResult, KioskHeartbeatInput, KioskHeartbeatResult, KioskRealtimeToken, MasivoTotpCode, MasivoTotpCreateInput, MasivoTotpVerification, MasivoTotpVerifyInput, MatchResult, MatchableRule, Menu, Menu as Menu$1, MenuLookup, MenuLookup as MenuLookup$1, MerchantPayment, ModifierControlType, ModifierGroup, OrConditions, Order as Order$1, Order as Order$2, OrderCancelInput, OrderCancelInput as OrderCancelInput$1, OrderCancelType, OrderCancelType as OrderCancelType$1, OrderDeviceListInput, OrderDeviceListResult, OrderFulfillment, OrderInsertInput, OrderLine, OrderListInput, OrderRecordPaymentInput, OrderRedeem, OrderRedemptionStep, OrderReorderInput, OrderSetCustomerInput, OrderTotals, OrderUpdateInput, OrderValidateInput, OrderValidateOutput, PaymentCollectAt as PaymentCollectAt$1, PaymentIntentPutInput, PaymentMethod, PaymentProvider, PaymentTender, PaymentTenderInput, PlaceOrderResult, PosCatalog, PosFloorInput, PosFloorOccupancy, PosFloorPlan, PosFloorRealtimeToken, PosHealthBatchInput, PosHealthBatchResult, PosHeartbeatInput, PosHeartbeatResult, PosKioskOrder, PosKioskSettleInput, PosKioskSettleResult, PosOrderInput, PosOrderResult, PosTableAttachOrderInput, PosTableCloseInput, PosTableJoinInput, PosTableSeatInput, PosTableSeatReservationInput, PosTableSplitInput, PricingModifier, Product, Product as Product$1, Recommendation, RecurringDateCronResult, RecurringDateCronValues, RulesEngineOrder, RulesEngineOrderLine, RulesEngineParams, RulesEngineRuntime, Schedule, SdkLogContext, SdkLogErrorInfo, SdkLogLevel, SdkLogOptions, Store, StoreGetInput, StoreListInput, StoreNearbyInput, StorefrontAvailability, StorefrontMenu, StorefrontMenuScope, StorefrontMenuStreamOptions, StorefrontPaymentsListInput, StorefrontPreferences, SwitchCustomerArg, SwitchCustomerArg as SwitchCustomerArg$1, SwitchCustomerIdToken, SwitchCustomerResult, SwitchCustomerResult as SwitchCustomerResult$1, TenderRefundInput, TenderReplaceInput, TenderVoidInput, Variant, VariantGroup } from "@fire-spark/types";
|
|
2
|
+
import { AndConditions, CheckoutMode, CheckoutResolved, CmsBlock, Condition, Customer, CustomerIdentifyInput, CustomerRegisterInput, CustomerUpdateInput, Fulfillment, FulfillmentListInput, GroupDisplayType, KioskDeviceConfig, KioskDeviceConfigInput, KioskDeviceOverrides, KioskHealthBatchInput, KioskHealthBatchResult, KioskHeartbeatInput, KioskHeartbeatResult, KioskPickupNameRules, KioskRealtimeToken, MasivoTotpCode, MasivoTotpCreateInput, MasivoTotpVerification, MasivoTotpVerifyInput, MatchResult, MatchableRule, Menu, Menu as Menu$1, MenuLookup, MenuLookup as MenuLookup$1, MerchantPayment, ModifierControlType, ModifierGroup, OrConditions, Order as Order$1, Order as Order$2, OrderCancelInput, OrderCancelInput as OrderCancelInput$1, OrderCancelType, OrderCancelType as OrderCancelType$1, OrderDeviceListInput, OrderDeviceListResult, OrderFulfillment, OrderInsertInput, OrderLine, OrderListInput, OrderRecordPaymentInput, OrderRedeem, OrderRedemptionStep, OrderReorderInput, OrderSetCustomerInput, OrderTotals, OrderUpdateInput, OrderValidateInput, OrderValidateOutput, PaymentCollectAt as PaymentCollectAt$1, PaymentIntentPutInput, PaymentMethod, PaymentProvider, PaymentTender, PaymentTenderInput, PlaceOrderResult, PosCatalog, PosFloorInput, PosFloorOccupancy, PosFloorPlan, PosFloorRealtimeToken, PosHealthBatchInput, PosHealthBatchResult, PosHeartbeatInput, PosHeartbeatResult, PosKioskOrder, PosKioskSettleInput, PosKioskSettleResult, PosOrderInput, PosOrderResult, PosTableAttachOrderInput, PosTableCloseInput, PosTableJoinInput, PosTableSeatInput, PosTableSeatReservationInput, PosTableSplitInput, PricingModifier, Product, Product as Product$1, Recommendation, RecurringDateCronResult, RecurringDateCronValues, RulesEngineOrder, RulesEngineOrderLine, RulesEngineParams, RulesEngineRuntime, Schedule, SdkLogContext, SdkLogErrorInfo, SdkLogLevel, SdkLogOptions, Store, StoreGetInput, StoreListInput, StoreNearbyInput, StorefrontAvailability, StorefrontMenu, StorefrontMenuScope, StorefrontMenuStreamOptions, StorefrontPaymentsListInput, StorefrontPreferences, SwitchCustomerArg, SwitchCustomerArg as SwitchCustomerArg$1, SwitchCustomerIdToken, SwitchCustomerResult, SwitchCustomerResult as SwitchCustomerResult$1, TenderRefundInput, TenderReplaceInput, TenderVoidInput, Variant, VariantGroup } from "@fire-spark/types";
|
|
3
3
|
import { Big } from "big.js";
|
|
4
4
|
//#region src/productCustomization/catalog.utils.d.ts
|
|
5
5
|
/** Image for a product inside one modifier group, else the product image. */
|
|
@@ -559,24 +559,35 @@ type ApplyRedeemInput = {
|
|
|
559
559
|
*/
|
|
560
560
|
quantity: number;
|
|
561
561
|
/**
|
|
562
|
-
*
|
|
562
|
+
* POINTS and DISCOUNT cover money. PRODUCT only links `line_uid` and
|
|
563
|
+
* does not change the payable total. Omit it for a money redeem.
|
|
564
|
+
*/
|
|
565
|
+
type?: "POINTS" | "DISCOUNT" | "PRODUCT";
|
|
566
|
+
/**
|
|
567
|
+
* Default `true`: a money redeem covers at most the pre-tax value of its
|
|
563
568
|
* target (line or order); taxes stay for the customer's method.
|
|
564
|
-
* `false`: it may also cover taxes, up to the full total.
|
|
569
|
+
* `false`: it may also cover taxes, up to the full total. Ignored for
|
|
570
|
+
* a PRODUCT reward.
|
|
565
571
|
*/
|
|
566
572
|
before_taxes?: boolean;
|
|
567
|
-
/**
|
|
573
|
+
/**
|
|
574
|
+
* Root product line the redeem is for. Required for PRODUCT. Omit to
|
|
575
|
+
* apply a POINTS or DISCOUNT redeem to the whole order.
|
|
576
|
+
*/
|
|
568
577
|
line_uid?: string;
|
|
569
578
|
/**
|
|
570
|
-
* Required: the active merchant `REDEMPTION` payment
|
|
571
|
-
*
|
|
579
|
+
* Required: the active merchant `REDEMPTION` payment. Money redeems that
|
|
580
|
+
* share a `payment_id` share one tender. A PRODUCT reward names the same
|
|
581
|
+
* payment and does not add a tender.
|
|
572
582
|
*/
|
|
573
583
|
payment_id: string;
|
|
574
584
|
/**
|
|
575
|
-
*
|
|
576
|
-
* `quantity` unit).
|
|
577
|
-
*
|
|
585
|
+
* POINTS and DISCOUNT: required, > 0, money for the whole entry (every
|
|
586
|
+
* `quantity` unit). Trimmed to the `before_taxes` cap and to total − tip
|
|
587
|
+
* − delivery. PRODUCT: omit it or send 0. It is not a discount and it
|
|
588
|
+
* does not change the line price.
|
|
578
589
|
*/
|
|
579
|
-
amount
|
|
590
|
+
amount?: number;
|
|
580
591
|
/** Provider of the REDEMPTION payment (default `firespark`). */
|
|
581
592
|
provider?: PaymentProvider;
|
|
582
593
|
/** ISO datetime with offset; validation fails once it has passed. */
|
|
@@ -662,14 +673,14 @@ declare class Order {
|
|
|
662
673
|
replaceLine(lineUid: string, lines: OrderLine | OrderLine[]): void;
|
|
663
674
|
emptyOrder(): void;
|
|
664
675
|
/**
|
|
665
|
-
* Applies a redeem
|
|
666
|
-
*
|
|
667
|
-
*
|
|
668
|
-
*
|
|
669
|
-
*
|
|
670
|
-
*
|
|
671
|
-
*
|
|
672
|
-
*
|
|
676
|
+
* Applies a redeem to `line_uid` (root product line) or to the order.
|
|
677
|
+
* POINTS and DISCOUNT need `amount` > 0: that money is the discount,
|
|
678
|
+
* line and order totals stay full, and the REDEMPTION tender of
|
|
679
|
+
* `payment_id` pays it. The customer's method pays the rest (taxes stay
|
|
680
|
+
* out when `before_taxes`, the default). Redeems with the same
|
|
681
|
+
* `payment_id` share one tender (D15, D18, D19). A PRODUCT reward needs
|
|
682
|
+
* `line_uid`. It links that line, keeps the cart price, and adds no
|
|
683
|
+
* tender money.
|
|
673
684
|
*/
|
|
674
685
|
applyRedeem(input: ApplyRedeemInput): void;
|
|
675
686
|
/**
|
|
@@ -740,10 +751,10 @@ declare class Order {
|
|
|
740
751
|
refundOrder(): Promise<void>;
|
|
741
752
|
validateOrder(): Promise<void>;
|
|
742
753
|
/**
|
|
743
|
-
* Tenders of the next intent: one REDEMPTION per
|
|
744
|
-
* (order and lines, capped) plus the customer's method for
|
|
745
|
-
* e.g. the taxes.
|
|
746
|
-
* REDEMPTION tenders.
|
|
754
|
+
* Tenders of the next intent: one REDEMPTION per `payment_id` that
|
|
755
|
+
* covers money (order and lines, capped) plus the customer's method for
|
|
756
|
+
* the rest, e.g. the taxes. PRODUCT rewards add no tender. When the
|
|
757
|
+
* money redeems cover the whole total, only REDEMPTION tenders.
|
|
747
758
|
*/
|
|
748
759
|
getTenders(payment?: PlaceOrderInput["payment"]): PaymentTenderInput[];
|
|
749
760
|
/**
|
|
@@ -935,7 +946,7 @@ declare const isOrderPaymentRequiredError: (error: unknown) => error is OrderPay
|
|
|
935
946
|
//#endregion
|
|
936
947
|
//#region src/order/validate.d.ts
|
|
937
948
|
type OrderLineIssueCode = "PRODUCT_NOT_FOUND" | "HIDDEN" | "OUT_OF_STOCK" | "OUTSIDE_HOURS" | "MODIFIER_NOT_FOUND" | "MODIFIER_RULES_INVALID" | "VARIANT_BASE_NOT_ORDERABLE" | "VARIANT_NOT_OFFERED" | "PRICE_MISMATCH" | "TAX_MISMATCH" | "DISCOUNT_MISMATCH" | "QUANTITY_MISMATCH" | "QUANTITY_BELOW_MINIMUM" | "QUANTITY_ABOVE_MAXIMUM" | "STRUCTURE_MISMATCH" | "FEE_MISMATCH" | "REDEEM_EXPIRED" | RedeemIssueCode;
|
|
938
|
-
type OrderIssueCode = "NO_MENU" | "MENU_CLOSED" | "SCOPE_INACTIVE" | "TOTALS_MISMATCH" | "REDEEM_EXPIRED" | RedeemIssueCode | "REDEMPTION_STEPS_MISMATCH" | "REDEMPTION_MISMATCH" | "EMPTY_ORDER" | "ITEMS_BELOW_MINIMUM" | "ITEMS_ABOVE_MAXIMUM" | "TOTAL_BELOW_MINIMUM" | "TOTAL_ABOVE_MAXIMUM" | "REDEEMS_ABOVE_MAXIMUM" | "REDEEMS_TOTAL_ABOVE_MAXIMUM" | "SHIPPING_REQUIRED" | "BILLING_REQUIRED" | "SHIPPING_FIELD_REQUIRED" | "BILLING_FIELD_REQUIRED" | "CUSTOMER_FIELD_REQUIRED" | "DAILY_ORDER_LIMIT_REACHED" | "MASIVO_REWARD_NOT_REDEEMABLE" | "MASIVO_REDEMPTION_PAYMENT_REQUIRED" | "MASIVO_UNAVAILABLE";
|
|
949
|
+
type OrderIssueCode = "NO_MENU" | "MENU_CLOSED" | "SCOPE_INACTIVE" | "TOTALS_MISMATCH" | "REDEEM_EXPIRED" | RedeemIssueCode | "REDEMPTION_STEPS_MISMATCH" | "REDEMPTION_MISMATCH" | "EMPTY_ORDER" | "ITEMS_BELOW_MINIMUM" | "ITEMS_ABOVE_MAXIMUM" | "TOTAL_BELOW_MINIMUM" | "TOTAL_ABOVE_MAXIMUM" | "REDEEMS_ABOVE_MAXIMUM" | "REDEEMS_TOTAL_ABOVE_MAXIMUM" | "SHIPPING_REQUIRED" | "BILLING_REQUIRED" | "SHIPPING_FIELD_REQUIRED" | "BILLING_FIELD_REQUIRED" | "CUSTOMER_FIELD_REQUIRED" | "DAILY_ORDER_LIMIT_REACHED" | "MASIVO_REWARD_NOT_REDEEMABLE" | "MASIVO_REDEMPTION_PAYMENT_REQUIRED" | "MASIVO_PRODUCT_LINE_MISSING" | "MASIVO_PRODUCT_PAYABLE_REDUCED" | "MASIVO_CHARGE_MISMATCH" | "MASIVO_UNAVAILABLE";
|
|
939
950
|
type OrderLineIssue = {
|
|
940
951
|
code: OrderLineIssueCode;
|
|
941
952
|
field?: string;
|
|
@@ -1073,6 +1084,7 @@ declare const capRedeems: <T extends CapOrder>(order: T) => T & {
|
|
|
1073
1084
|
redeem: {
|
|
1074
1085
|
reward_id: string;
|
|
1075
1086
|
quantity: number;
|
|
1087
|
+
type?: "DISCOUNT" | "POINTS" | "PRODUCT" | undefined;
|
|
1076
1088
|
before_taxes?: boolean | undefined;
|
|
1077
1089
|
expires_at?: string | undefined;
|
|
1078
1090
|
payment_id: string;
|
|
@@ -1104,6 +1116,7 @@ declare const capRedeems: <T extends CapOrder>(order: T) => T & {
|
|
|
1104
1116
|
declare const cappedRedeems: (order: CapOrder) => {
|
|
1105
1117
|
reward_id: string;
|
|
1106
1118
|
quantity: number;
|
|
1119
|
+
type?: "DISCOUNT" | "POINTS" | "PRODUCT" | undefined;
|
|
1107
1120
|
before_taxes?: boolean | undefined;
|
|
1108
1121
|
expires_at?: string | undefined;
|
|
1109
1122
|
payment_id: string;
|
|
@@ -1129,9 +1142,10 @@ declare const redeemsForPayment: <T extends {
|
|
|
1129
1142
|
amount: number;
|
|
1130
1143
|
}>(items: readonly T[], paymentId: string) => T[];
|
|
1131
1144
|
/**
|
|
1132
|
-
* Money
|
|
1133
|
-
*
|
|
1134
|
-
*
|
|
1145
|
+
* Money POINTS and DISCOUNT redeems cover (Σ `amount`). A PRODUCT reward
|
|
1146
|
+
* is not included: it links a line and does not change what the customer
|
|
1147
|
+
* pays. The sum is paid by REDEMPTION tenders, so it is never subtracted
|
|
1148
|
+
* from line or order totals.
|
|
1135
1149
|
*/
|
|
1136
1150
|
declare const redeemedTotal: (redeem?: readonly RedeemLike[] | null) => number;
|
|
1137
1151
|
/** Redeemed money of every redeem of the order (order + root lines). */
|
|
@@ -1160,10 +1174,11 @@ type StepOrder = Parameters<typeof fitRedeems>[0];
|
|
|
1160
1174
|
/**
|
|
1161
1175
|
* One step per redeem with a `payment_id`, in the order `fitRedeems`
|
|
1162
1176
|
* applies them: root-line redeems in line order, then order redeems.
|
|
1163
|
-
* `discount_amount` is the capped `amount
|
|
1164
|
-
* add up to its REDEMPTION tender
|
|
1165
|
-
*
|
|
1166
|
-
*
|
|
1177
|
+
* `discount_amount` is the capped `amount` of a POINTS or DISCOUNT redeem,
|
|
1178
|
+
* so those steps of a `payment_id` add up to its REDEMPTION tender. A
|
|
1179
|
+
* PRODUCT reward is a step with `discount_amount` 0 and action READ: it
|
|
1180
|
+
* links the line and does not change `value`. Lines, taxes and totals keep
|
|
1181
|
+
* their full value; `value` is what the customer's method still pays.
|
|
1167
1182
|
*/
|
|
1168
1183
|
declare const redemptionSteps: (order: StepOrder) => OrderRedemptionStep[];
|
|
1169
1184
|
//#endregion
|
|
@@ -1908,4 +1923,11 @@ declare const validateCardholderName: (value: string) => CardholderNameError | n
|
|
|
1908
1923
|
*/
|
|
1909
1924
|
declare const cardPreviewGroups: (value: string) => CardPreviewSlot[][];
|
|
1910
1925
|
//#endregion
|
|
1911
|
-
|
|
1926
|
+
//#region src/kiosk/pickupName.d.ts
|
|
1927
|
+
type PickupNameIssue = "empty" | "too_short" | "too_long" | "too_many_words" | "invalid_chars";
|
|
1928
|
+
/** Trim, collapse spaces, and uppercase what the customer typed. */
|
|
1929
|
+
declare const normalizePickupName: (raw: string) => string;
|
|
1930
|
+
/** `null` when the name is valid for the given rules. */
|
|
1931
|
+
declare const validatePickupName: (raw: string, rules: KioskPickupNameRules) => PickupNameIssue | null;
|
|
1932
|
+
//#endregion
|
|
1933
|
+
export { type ApplyRedeemInput, type AuthConfigureOptions, type BuildScheduleSlotsConfig, CARD_BRANDS, CUSTOMER_INFO_PLACEHOLDERS, 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, DelegatedSessionExpiredError, type DeunaCallbackUrls, type DeunaOrderStatus, type ExchangeOptions, type FailedCharge, type FlatMenuCategory, type GenOrderIdOptions, type GroupDisplayType, ID_HASH_FORMATS, type IdBuilder, type IdHashFormat, type ListMenusStreamOptions, type ListPaymentsOptions, type Menu, type MenuCategoryNode, type MenuLookup, type MilestoneSteps, type MilestoneTrackItem, type ModifierControlType, type ModifierCtx, type ModifierGroupCtx, type NestedMenuCategory, Order, OrderAuthPinnedError, type OrderCancelInput, type OrderCancelOptions, type OrderCancelResult, type OrderCancelType, type OrderCustomerSource, type OrderDeviceCredential, type OrderDraft, type OrderIssue, type OrderIssueCode, type OrderLineDiff, type OrderLineIssue, type OrderLineIssueCode, OrderNotOpenError, OrderPaymentRequiredError, type OrderScope, OrderSyncPendingError, OrderSyncRejectedError, OrderValidationError, type OrderValidationResult, type PayIntentOptions, type PayIntentResult, type PayOptions, type PaymentCardBrand, type PaymentProgressEvent, type PaymentProgressListener, type PaymentRunOptions, type PaymentSessionOptions, PickupNameIssue, type PricingModifier, type Product, type ProductCtx, type QuantitiesByPath, type RecommendationType, RecurringDateCron, type RedeemPaymentRow, type RemoveRedeemInput, type ReorderOrderOptions, type ResetOptions, type ReversalOutcome, type ReverseAllOptions, RulesEngine, SCHEDULED_AT_ERROR_CODES, SCHEDULED_ORDER_MAX_HORIZON_HOURS, SCHEDULED_ORDER_MAX_HORIZON_MINUTES, SCHEDULED_ORDER_MIN_LEAD_MINUTES, SCHEDULED_ORDER_SLOT_MINUTES, type ScheduleSlot, type ScheduleSlotCart, type ScheduleSlotCartLine, type ScheduleWindow, type SelectionStatus, type SelectionsByPath, type SerializedError, type ServiceHttpOptions, type SimpleTenderPayment, type Snapshot, type StorefrontAccessToken, type StorefrontErrorDetails, StorefrontHttpError, type SwitchCustomerArg, type SwitchCustomerIdToken, type SwitchCustomerResult, type TrackWorkflow, type ValidateOptions, type ValidateOrderAgainstMenuInput, type Variant, type VariantGroup, type VariantGroupCtx, type VariantOptionCtx, type VariantSelection, type VerifyWebhookSignatureInput, type VisitedState, addLines, auth, buildCustomerSnapshot, buildScheduleSlots, cancelTypeOf, capRedeems, cappedRedeems, cardBrandSpec, cardDigits, cardNumberGaps, cardNumberMaxLength, cardPreviewGroups, caretAfterDigits, collectOrderLineDiffs, computeStartingPrice, countCartProducts, coveredAmount, createDeunaWidgetApi, createSession, currentNodes, cvcMaxLength, defaultConditionError, detectCardBrand, fitRedeems, flattenMenuCategories, flushLogs, formatCardNumber, formatCvc, formatExpiry, fromOrderLines, genId, genOrderId, getLogContext, getScheduleWindow, indexMenu, isCardNumberComplete, isCardNumberDefinitelyInvalid, isCheckoutFieldFilled, isCustomerInfoFieldFilled, isCustomerInfoPlaceholder, isCustomerInfoValueValid, isCvcComplete, isDelegatedSessionExpiredError, isDeviceCharged, isDeviceNotLinked, isExpiryComplete, isGenId, isKioskUnauthorized, isMilestoneStepDone, isOnSchedule, isOrderNotOpenError, isOrderPaymentRequiredError, isOrderValidationError, isPosDeviceNotLinked, isPosUnauthorized, isRealPaymentMethod, isScheduleSlot, isScheduledAtError, isStorefrontNotFound, isVariantBase, linePayableTotal, listMenusStream, localizePosError, log, logError, luhnCheck, matchAbsoluteDateOperator, matchBooleanOperator, matchCurrencyOperator, matchEnumOperator, matchNumberOperator, matchRecurringDateOperator, matchRelativeDateOperator, matchStringOperator, milestoneSteps, milestoneTrack, nestMenuCategories, normalizeCardholderName, normalizeCustomerPhone, normalizePickupName, orderPayableTotal, orderRedeemedTotal, orderRedeems, parseExpiry, paymentMatchesClientConditions, rebuildRootGroups, recomputeTotals, redeemedTotal, redeemsForPayment, redemptionCap, redemptionSteps, remainingAmount, removeLine, replaceLine, resolveCheckout, resolveModifierImageUrl, resolveSchedulePrepMinutes, reversePayment, runPaymentAttempt, scheduledInstant, selectablePayments, serializeError, services, setLineQuantity, storefrontJson, toOrderLines, toPaymentCardBrand, validateCardNumber, validateCardholderName, validateCvc, validateExpiry, validateOrderAgainstMenu, validatePickupName, verifyWebhookSignature, visitedStates };
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { DIGITAL_COLLECT_AT, PARTIAL_APPROVAL_ERROR, REDEMPTION_METHOD, activeIntent, createAttemptReference, createPaymentError, currentIntent, defaultReversalFor, groupRedeems, hasRedeemPayment, isDeliveryFee, isManualPayment, isPaymentError, isRealPaymentMethod, isRealPaymentMethod as isRealPaymentMethod$1, isTenderSettled, isTipFee, liveTenders, memoryPaymentStorage, missingDeviceFields, money, moneyMin, moneyNumber, moneyZero, orderRedeems, orderRedeems as orderRedeems$1, redeemsCoverTotal, resolvePaymentPolicy, resolveProviderEnvironment, scopedPaymentStorage, taxBreakdown, toChargeAmount, withTerminalLock } from "@fire-spark/payments";
|
|
1
|
+
import { DIGITAL_COLLECT_AT, PARTIAL_APPROVAL_ERROR, REDEMPTION_METHOD, activeIntent, createAttemptReference, createPaymentError, currentIntent, defaultReversalFor, groupRedeems, hasRedeemPayment, isDeliveryFee, isManualPayment, isPaymentError, isProductReward, isRealPaymentMethod, isRealPaymentMethod as isRealPaymentMethod$1, isTenderSettled, isTipFee, liveTenders, memoryPaymentStorage, missingDeviceFields, money, moneyMin, moneyNumber, moneyZero, orderRedeems, orderRedeems as orderRedeems$1, redeemsCoverTotal, resolvePaymentPolicy, resolveProviderEnvironment, 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";
|
|
@@ -4306,7 +4306,8 @@ const fitRedeems = (order) => {
|
|
|
4306
4306
|
const net = money(redemptionCap(order, true));
|
|
4307
4307
|
let used = moneyZero();
|
|
4308
4308
|
const fit = (item, line, lineUsed) => {
|
|
4309
|
-
if (!hasRedeemPayment(item) ||
|
|
4309
|
+
if (!hasRedeemPayment(item) || isProductReward(item)) return moneyZero();
|
|
4310
|
+
if (!(item.amount > 0)) return moneyZero();
|
|
4310
4311
|
const beforeTaxes = item.before_taxes ?? true;
|
|
4311
4312
|
let room = (beforeTaxes ? net : gross).minus(used);
|
|
4312
4313
|
if (line) {
|
|
@@ -4332,6 +4333,7 @@ const fitRedeems = (order) => {
|
|
|
4332
4333
|
};
|
|
4333
4334
|
const keepFitted = (items, fitted) => {
|
|
4334
4335
|
return items.flatMap((item, index) => {
|
|
4336
|
+
if (isProductReward(item)) return [item];
|
|
4335
4337
|
const fits = fitted[index] ?? moneyZero();
|
|
4336
4338
|
if (fits.lte(0)) return [];
|
|
4337
4339
|
if (fits.eq(item.amount)) return [item];
|
|
@@ -4368,8 +4370,9 @@ const cappedRedeems = (order) => {
|
|
|
4368
4370
|
return orderRedeems(capRedeems(order));
|
|
4369
4371
|
};
|
|
4370
4372
|
/**
|
|
4371
|
-
* One REDEMPTION tender per `payment_id` (D15, D19)
|
|
4372
|
-
*
|
|
4373
|
+
* One REDEMPTION tender per `payment_id` that covers money (D15, D19).
|
|
4374
|
+
* PRODUCT rewards are left out, so a payment that only links products
|
|
4375
|
+
* gets no tender. `details.rewards[]` lists the money redeems.
|
|
4373
4376
|
*/
|
|
4374
4377
|
const redemptionTenderInputs = (redeem, providers = /* @__PURE__ */ new Map()) => {
|
|
4375
4378
|
return groupRedeems(redeem).map(({ payment_id, details }) => {
|
|
@@ -5746,21 +5749,34 @@ const collectRecommendations = (config) => {
|
|
|
5746
5749
|
};
|
|
5747
5750
|
//#endregion
|
|
5748
5751
|
//#region src/order/redemptions.ts
|
|
5752
|
+
const REWARD_TYPES = /* @__PURE__ */ new Set([
|
|
5753
|
+
"POINTS",
|
|
5754
|
+
"DISCOUNT",
|
|
5755
|
+
"PRODUCT"
|
|
5756
|
+
]);
|
|
5749
5757
|
/** Same rules as `vOrders.redeem()`; throws on invalid input. */
|
|
5750
5758
|
const buildRedeem = (input) => {
|
|
5751
|
-
const { reward_id, quantity, payment_id,
|
|
5759
|
+
const { reward_id, quantity, payment_id, type } = input;
|
|
5752
5760
|
const { before_taxes, expires_at } = input;
|
|
5753
5761
|
if (typeof reward_id !== "string" || !reward_id.trim()) throw new Error("Redeem requires reward_id");
|
|
5754
5762
|
if (!Number.isInteger(quantity) || quantity < 1) throw new Error("Redeem quantity must be an integer ≥ 1");
|
|
5755
5763
|
if (typeof payment_id !== "string" || !payment_id.trim()) throw new Error("Redeem requires payment_id");
|
|
5756
|
-
if (
|
|
5764
|
+
if (type !== void 0 && !REWARD_TYPES.has(type)) throw new Error("Redeem type must be POINTS, DISCOUNT or PRODUCT");
|
|
5765
|
+
const product = type === "PRODUCT";
|
|
5766
|
+
let amount = input.amount;
|
|
5767
|
+
if (product) {
|
|
5768
|
+
if (amount === void 0) amount = 0;
|
|
5769
|
+
if (typeof amount !== "number" || !Number.isFinite(amount) || amount < 0) throw new Error("Product reward amount must be ≥ 0");
|
|
5770
|
+
} else if (typeof amount !== "number" || !(amount > 0)) throw new Error("Redeem requires amount > 0");
|
|
5757
5771
|
if (expires_at !== void 0 && Number.isNaN(Date.parse(expires_at))) throw new Error("Redeem expires_at must be an ISO datetime");
|
|
5772
|
+
if (typeof amount !== "number") throw new Error("Redeem requires amount > 0");
|
|
5758
5773
|
const redeem = {
|
|
5759
5774
|
reward_id,
|
|
5760
5775
|
quantity,
|
|
5761
5776
|
payment_id,
|
|
5762
5777
|
amount
|
|
5763
5778
|
};
|
|
5779
|
+
if (type !== void 0) redeem.type = type;
|
|
5764
5780
|
if (before_taxes !== void 0) redeem.before_taxes = before_taxes;
|
|
5765
5781
|
if (expires_at !== void 0) redeem.expires_at = expires_at;
|
|
5766
5782
|
return redeem;
|
|
@@ -5831,13 +5847,14 @@ const subtractRedeem = (items, reward_id, quantity) => {
|
|
|
5831
5847
|
return kept;
|
|
5832
5848
|
};
|
|
5833
5849
|
/**
|
|
5834
|
-
* Money
|
|
5835
|
-
*
|
|
5836
|
-
*
|
|
5850
|
+
* Money POINTS and DISCOUNT redeems cover (Σ `amount`). A PRODUCT reward
|
|
5851
|
+
* is not included: it links a line and does not change what the customer
|
|
5852
|
+
* pays. The sum is paid by REDEMPTION tenders, so it is never subtracted
|
|
5853
|
+
* from line or order totals.
|
|
5837
5854
|
*/
|
|
5838
5855
|
const redeemedTotal = (redeem = []) => {
|
|
5839
5856
|
return (redeem ?? []).reduce((sum, item) => {
|
|
5840
|
-
if (!hasRedeemPayment(item)) return sum;
|
|
5857
|
+
if (!hasRedeemPayment(item) || isProductReward(item)) return sum;
|
|
5841
5858
|
return sum.plus(item.amount ?? 0);
|
|
5842
5859
|
}, new Big(0)).toNumber();
|
|
5843
5860
|
};
|
|
@@ -5934,10 +5951,11 @@ const stateOf = (target) => {
|
|
|
5934
5951
|
/**
|
|
5935
5952
|
* One step per redeem with a `payment_id`, in the order `fitRedeems`
|
|
5936
5953
|
* applies them: root-line redeems in line order, then order redeems.
|
|
5937
|
-
* `discount_amount` is the capped `amount
|
|
5938
|
-
* add up to its REDEMPTION tender
|
|
5939
|
-
*
|
|
5940
|
-
*
|
|
5954
|
+
* `discount_amount` is the capped `amount` of a POINTS or DISCOUNT redeem,
|
|
5955
|
+
* so those steps of a `payment_id` add up to its REDEMPTION tender. A
|
|
5956
|
+
* PRODUCT reward is a step with `discount_amount` 0 and action READ: it
|
|
5957
|
+
* links the line and does not change `value`. Lines, taxes and totals keep
|
|
5958
|
+
* their full value; `value` is what the customer's method still pays.
|
|
5941
5959
|
*/
|
|
5942
5960
|
const redemptionSteps = (order) => {
|
|
5943
5961
|
const fitted = fitRedeems(order);
|
|
@@ -5967,10 +5985,12 @@ const redemptionSteps = (order) => {
|
|
|
5967
5985
|
before,
|
|
5968
5986
|
after: stateOf(whole)
|
|
5969
5987
|
};
|
|
5988
|
+
const typed = item.type ? { type: item.type } : {};
|
|
5970
5989
|
return {
|
|
5971
5990
|
...s1,
|
|
5972
5991
|
...s2,
|
|
5973
5992
|
...s3,
|
|
5993
|
+
...typed,
|
|
5974
5994
|
...s4,
|
|
5975
5995
|
...s5,
|
|
5976
5996
|
targetBefore
|
|
@@ -6556,19 +6576,20 @@ var Order = class Order {
|
|
|
6556
6576
|
});
|
|
6557
6577
|
}
|
|
6558
6578
|
/**
|
|
6559
|
-
* Applies a redeem
|
|
6560
|
-
*
|
|
6561
|
-
*
|
|
6562
|
-
*
|
|
6563
|
-
*
|
|
6564
|
-
*
|
|
6565
|
-
*
|
|
6566
|
-
*
|
|
6579
|
+
* Applies a redeem to `line_uid` (root product line) or to the order.
|
|
6580
|
+
* POINTS and DISCOUNT need `amount` > 0: that money is the discount,
|
|
6581
|
+
* line and order totals stay full, and the REDEMPTION tender of
|
|
6582
|
+
* `payment_id` pays it. The customer's method pays the rest (taxes stay
|
|
6583
|
+
* out when `before_taxes`, the default). Redeems with the same
|
|
6584
|
+
* `payment_id` share one tender (D15, D18, D19). A PRODUCT reward needs
|
|
6585
|
+
* `line_uid`. It links that line, keeps the cart price, and adds no
|
|
6586
|
+
* tender money.
|
|
6567
6587
|
*/
|
|
6568
6588
|
applyRedeem(input) {
|
|
6569
6589
|
if (this.deleted) return;
|
|
6570
6590
|
const { line_uid, provider, ...rest } = input;
|
|
6571
6591
|
const redeem = buildRedeem(rest);
|
|
6592
|
+
if (redeem.type === "PRODUCT" && line_uid === void 0) throw new Error("Product reward requires a root product line");
|
|
6572
6593
|
if (provider) this.redemptionProviders.set(redeem.payment_id, provider);
|
|
6573
6594
|
if (line_uid === void 0) {
|
|
6574
6595
|
this.commitLines({ redeem: [...this.appliedRedeem(), redeem] });
|
|
@@ -6853,10 +6874,10 @@ var Order = class Order {
|
|
|
6853
6874
|
await services.orders.validate(body, this.http);
|
|
6854
6875
|
}
|
|
6855
6876
|
/**
|
|
6856
|
-
* Tenders of the next intent: one REDEMPTION per
|
|
6857
|
-
* (order and lines, capped) plus the customer's method for
|
|
6858
|
-
* e.g. the taxes.
|
|
6859
|
-
* REDEMPTION tenders.
|
|
6877
|
+
* Tenders of the next intent: one REDEMPTION per `payment_id` that
|
|
6878
|
+
* covers money (order and lines, capped) plus the customer's method for
|
|
6879
|
+
* the rest, e.g. the taxes. PRODUCT rewards add no tender. When the
|
|
6880
|
+
* money redeems cover the whole total, only REDEMPTION tenders.
|
|
6860
6881
|
*/
|
|
6861
6882
|
getTenders(payment) {
|
|
6862
6883
|
const redeem = cappedRedeems(this.draft);
|
|
@@ -8423,9 +8444,11 @@ const paymentProblem = (payment_id, payments) => {
|
|
|
8423
8444
|
return null;
|
|
8424
8445
|
};
|
|
8425
8446
|
/**
|
|
8426
|
-
* Every redeem needs `payment_id
|
|
8427
|
-
*
|
|
8428
|
-
*
|
|
8447
|
+
* Every redeem needs `payment_id`. POINTS and DISCOUNT also need
|
|
8448
|
+
* `amount > 0`, already trimmed to the `before_taxes` cap (`fitted`).
|
|
8449
|
+
* A PRODUCT reward may send `amount` 0: it links the line and covers no
|
|
8450
|
+
* money. With `payments`, the payment must exist, be active and be a
|
|
8451
|
+
* REDEMPTION method.
|
|
8429
8452
|
*/
|
|
8430
8453
|
const redeemIssues = (items, fitted, payments) => {
|
|
8431
8454
|
const issues = [];
|
|
@@ -8439,6 +8462,20 @@ const redeemIssues = (items, fitted, payments) => {
|
|
|
8439
8462
|
});
|
|
8440
8463
|
return;
|
|
8441
8464
|
}
|
|
8465
|
+
if (isProductReward(item)) {
|
|
8466
|
+
const problem = payments ? paymentProblem(payment_id, payments) : null;
|
|
8467
|
+
if (!problem) return;
|
|
8468
|
+
const b1 = {
|
|
8469
|
+
code: "REDEEM_PAYMENT_METHOD_NOT_CONFIGURED",
|
|
8470
|
+
field: `${prefix}.payment_id`
|
|
8471
|
+
};
|
|
8472
|
+
issues.push({
|
|
8473
|
+
...b1,
|
|
8474
|
+
expected: REDEMPTION_METHOD,
|
|
8475
|
+
actual: problem
|
|
8476
|
+
});
|
|
8477
|
+
return;
|
|
8478
|
+
}
|
|
8442
8479
|
if (!(typeof item.amount === "number" && item.amount > 0)) {
|
|
8443
8480
|
issues.push({
|
|
8444
8481
|
code: "REDEEM_PAYMENT_REQUIRED",
|
|
@@ -8500,9 +8537,11 @@ const flattenStep = (step) => {
|
|
|
8500
8537
|
before_taxes: String(step.before_taxes)
|
|
8501
8538
|
};
|
|
8502
8539
|
const b2 = { discount_amount: bigStr(step.discount_amount) };
|
|
8540
|
+
const b3 = { type: step.type ?? "" };
|
|
8503
8541
|
const out = {
|
|
8504
8542
|
...b1,
|
|
8505
|
-
...b2
|
|
8543
|
+
...b2,
|
|
8544
|
+
...b3
|
|
8506
8545
|
};
|
|
8507
8546
|
for (const key of STATE_KEYS) flattenState(key, step[key], out);
|
|
8508
8547
|
return out;
|
|
@@ -11243,4 +11282,23 @@ const cardPreviewGroups = (value) => {
|
|
|
11243
11282
|
return groups;
|
|
11244
11283
|
};
|
|
11245
11284
|
//#endregion
|
|
11246
|
-
|
|
11285
|
+
//#region src/kiosk/pickupName.ts
|
|
11286
|
+
const LETTERS_ONLY = /^[\p{L}\p{M} ]+$/u;
|
|
11287
|
+
const LETTERS_AND_DIGITS = /^[\p{L}\p{M}0-9 ]+$/u;
|
|
11288
|
+
/** Trim, collapse spaces, and uppercase what the customer typed. */
|
|
11289
|
+
const normalizePickupName = (raw) => {
|
|
11290
|
+
return raw.trim().replace(/\s+/g, " ").toLocaleUpperCase();
|
|
11291
|
+
};
|
|
11292
|
+
/** `null` when the name is valid for the given rules. */
|
|
11293
|
+
const validatePickupName = (raw, rules) => {
|
|
11294
|
+
const name = normalizePickupName(raw);
|
|
11295
|
+
if (!name) return "empty";
|
|
11296
|
+
if (!(rules.allow_numbers ? LETTERS_AND_DIGITS : LETTERS_ONLY).test(name)) return "invalid_chars";
|
|
11297
|
+
if (name.split(" ").length > rules.max_words) return "too_many_words";
|
|
11298
|
+
const length = name.replace(/ /g, "").length;
|
|
11299
|
+
if (length < rules.min_length) return "too_short";
|
|
11300
|
+
if (length > rules.max_length) return "too_long";
|
|
11301
|
+
return null;
|
|
11302
|
+
};
|
|
11303
|
+
//#endregion
|
|
11304
|
+
export { CARD_BRANDS, CUSTOMER_INFO_PLACEHOLDERS, DEFAULT_RECOMMENDATION_TYPES, DelegatedSessionExpiredError, ID_HASH_FORMATS, Order, OrderAuthPinnedError, OrderNotOpenError, OrderPaymentRequiredError, OrderSyncPendingError, OrderSyncRejectedError, OrderValidationError, RecurringDateCron, RulesEngine, SCHEDULED_AT_ERROR_CODES, SCHEDULED_ORDER_MAX_HORIZON_HOURS, SCHEDULED_ORDER_MAX_HORIZON_MINUTES, SCHEDULED_ORDER_MIN_LEAD_MINUTES, SCHEDULED_ORDER_SLOT_MINUTES, StorefrontHttpError, addLines, auth, buildCustomerSnapshot, buildScheduleSlots, cancelTypeOf, capRedeems, cappedRedeems, cardBrandSpec, cardDigits, cardNumberGaps, cardNumberMaxLength, cardPreviewGroups, caretAfterDigits, collectOrderLineDiffs, computeStartingPrice, countCartProducts, coveredAmount, createDeunaWidgetApi, createSession, currentNodes, cvcMaxLength, defaultConditionError, detectCardBrand, fitRedeems, flattenMenuCategories, flushLogs, formatCardNumber, formatCvc, formatExpiry, fromOrderLines, genId, genOrderId, getLogContext, getScheduleWindow, indexMenu, isCardNumberComplete, isCardNumberDefinitelyInvalid, isCheckoutFieldFilled, isCustomerInfoFieldFilled, isCustomerInfoPlaceholder, isCustomerInfoValueValid, isCvcComplete, isDelegatedSessionExpiredError, isDeviceCharged, isDeviceNotLinked, isExpiryComplete, isGenId, isKioskUnauthorized, isMilestoneStepDone, isOnSchedule, isOrderNotOpenError, isOrderPaymentRequiredError, isOrderValidationError, isPosDeviceNotLinked, isPosUnauthorized, isRealPaymentMethod, isScheduleSlot, isScheduledAtError, isStorefrontNotFound, isVariantBase, linePayableTotal, listMenusStream, localizePosError, log, logError, luhnCheck, matchAbsoluteDateOperator, matchBooleanOperator, matchCurrencyOperator, matchEnumOperator, matchNumberOperator, matchRecurringDateOperator, matchRelativeDateOperator, matchStringOperator, milestoneSteps, milestoneTrack, nestMenuCategories, normalizeCardholderName, normalizeCustomerPhone, normalizePickupName, orderPayableTotal, orderRedeemedTotal, orderRedeems, parseExpiry, paymentMatchesClientConditions, rebuildRootGroups, recomputeTotals, redeemedTotal, redeemsForPayment, redemptionCap, redemptionSteps, remainingAmount, removeLine, replaceLine, resolveCheckout, resolveModifierImageUrl, resolveSchedulePrepMinutes, reversePayment, runPaymentAttempt, scheduledInstant, selectablePayments, serializeError, services, setLineQuantity, storefrontJson, toOrderLines, toPaymentCardBrand, validateCardNumber, validateCardholderName, validateCvc, validateExpiry, validateOrderAgainstMenu, validatePickupName, verifyWebhookSignature, visitedStates };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fire-spark/core",
|
|
3
|
-
"version": "0.17.
|
|
3
|
+
"version": "0.17.3",
|
|
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.17.
|
|
24
|
-
"@fire-spark/types": "^0.17.
|
|
23
|
+
"@fire-spark/payments": "^0.17.3",
|
|
24
|
+
"@fire-spark/types": "^0.17.3"
|
|
25
25
|
},
|
|
26
26
|
"devDependencies": {
|
|
27
27
|
"tsdown": "^0.22.14",
|