@fire-spark/core 0.3.3 → 0.3.5

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 CHANGED
@@ -1,4 +1,4 @@
1
- import { PaymentAdapter, PaymentCollectAt, PaymentContext, PaymentResult, PaymentStorage, PaymentUI, isRealPaymentMethod } from "@fire-spark/payments";
1
+ import { PaymentAdapter, PaymentCollectAt, PaymentContext, PaymentResult, PaymentStorage, PaymentUI, isRealPaymentMethod, orderPaymentRedeems } from "@fire-spark/payments";
2
2
  import { AndConditions, CheckoutMode, CheckoutResolved, CmsBlock, Condition, Customer, CustomerIdentifyInput, CustomerRegisterInput, CustomerUpdateInput, Fulfillment, FulfillmentListInput, GroupDisplayType, KioskDeviceConfig, KioskDeviceOverrides, KioskHealthBatchInput, KioskHealthBatchResult, KioskHeartbeatInput, KioskHeartbeatResult, KioskRealtimeToken, MatchResult, MatchableRule, Menu, Menu as Menu$1, MenuLookup, MenuLookup as MenuLookup$1, MerchantPayment, ModifierControlType, ModifierGroup, OrConditions, Order as Order$1, Order as Order$2, OrderFulfillment, OrderInsertInput, OrderLine, OrderListInput, OrderRecordPaymentInput, OrderRedeem, OrderRedemptionStep, OrderReorderInput, OrderTotals, OrderUpdateInput, OrderValidateInput, OrderValidateOutput, PaymentCollectAt as PaymentCollectAt$1, PaymentIntentPutInput, PaymentMethod, PaymentProvider, PaymentTender, PaymentTenderInput, PlaceOrderResult, PosCatalog, PosHealthBatchInput, PosHealthBatchResult, PosHeartbeatInput, PosHeartbeatResult, PosKioskOrder, PosKioskSettleInput, PosKioskSettleResult, PosOrderInput, PosOrderResult, PricingModifier, Product, Product as Product$1, Recommendation, RecurringDateCronResult, RecurringDateCronValues, RulesEngineOrderLine, RulesEngineParams, RulesEngineRuntime, Schedule, SdkLogContext, SdkLogErrorInfo, SdkLogLevel, SdkLogOptions, Store, StoreGetInput, StoreListInput, StoreNearbyInput, StorefrontAvailability, StorefrontMenu, StorefrontMenuScope, StorefrontMenuStreamOptions, StorefrontPaymentsListInput, StorefrontPreferences, TenderRefundInput, TenderReplaceInput, TenderVoidInput, Variant, VariantGroup } from "@fire-spark/types";
3
3
  import { Big } from "big.js";
4
4
  //#region src/productCustomization/types.d.ts
@@ -556,8 +556,9 @@ declare class Order {
556
556
  refundOrder(): Promise<void>;
557
557
  validateOrder(): Promise<void>;
558
558
  /**
559
- * Tenders of the next intent: real ones plus one per payment redeem.
560
- * When the payment redeems cover the total, only REDEMPTION tenders.
559
+ * Tenders of the next intent: real ones plus one per payment redeem
560
+ * `payment_id`, on the order or on a line. When the payment redeems
561
+ * cover the total, only REDEMPTION tenders.
561
562
  */
562
563
  getTenders(payment?: PlaceOrderInput["payment"]): PaymentTenderInput[];
563
564
  /**
@@ -1318,4 +1319,4 @@ declare const validateCardholderName: (value: string) => CardholderNameError | n
1318
1319
  */
1319
1320
  declare const cardPreviewGroups: (value: string) => CardPreviewSlot[][];
1320
1321
  //#endregion
1321
- 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 };
1322
+ 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, orderPaymentRedeems, 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, discountRedeems, groupPaymentRedeems, isDeliveryFee, isPaymentError, isPaymentRedeem, isRealPaymentMethod, isRealPaymentMethod as isRealPaymentMethod$1, isTenderSettled, isTipFee, liveTenders, memoryPaymentStorage, missingDeviceFields, paymentRedeemsCoverTotal, 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, discountRedeems, groupPaymentRedeems, isDeliveryFee, isPaymentError, isPaymentRedeem, isRealPaymentMethod, isRealPaymentMethod as isRealPaymentMethod$1, isTenderSettled, isTipFee, liveTenders, memoryPaymentStorage, missingDeviceFields, orderPaymentRedeems, orderPaymentRedeems as orderPaymentRedeems$1, paymentRedeemsCoverTotal, 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";
@@ -3471,6 +3471,15 @@ const redemptionCap = (order) => {
3471
3471
  return Math.max(roundTo(order.totals.total - primaryOnly, decimals), 0);
3472
3472
  };
3473
3473
  /**
3474
+ * Room left for order-level payment redeems: the D18 cap minus what the
3475
+ * payment redeems kept on lines already cover.
3476
+ */
3477
+ const orderRedeemCap = (order) => {
3478
+ const used = orderPaymentRedeems({ lines: order.lines }).reduce((sum, item) => sum + (item.amount ?? 0), 0);
3479
+ const decimals = currencyDecimals(order.totals.currency);
3480
+ return Math.max(roundTo(redemptionCap(order) - used, decimals), 0);
3481
+ };
3482
+ /**
3474
3483
  * Trims payment redeems in application order so their sum fits the cap;
3475
3484
  * points shrink in proportion. Discount redeems are left untouched.
3476
3485
  */
@@ -5704,11 +5713,12 @@ var Order = class Order {
5704
5713
  await services.orders.validate(body, this.http);
5705
5714
  }
5706
5715
  /**
5707
- * Tenders of the next intent: real ones plus one per payment redeem.
5708
- * When the payment redeems cover the total, only REDEMPTION tenders.
5716
+ * Tenders of the next intent: real ones plus one per payment redeem
5717
+ * `payment_id`, on the order or on a line. When the payment redeems
5718
+ * cover the total, only REDEMPTION tenders.
5709
5719
  */
5710
5720
  getTenders(payment) {
5711
- const redeem = this.draft.redeem ?? [];
5721
+ const redeem = orderPaymentRedeems$1(this.draft);
5712
5722
  const providers = this.redemptionProviders;
5713
5723
  const redemption = redemptionTenderInputs(redeem, providers);
5714
5724
  if (paymentRedeemsCoverTotal(redeem, this.draft.totals)) return redemption;
@@ -5890,7 +5900,7 @@ var Order = class Order {
5890
5900
  redemption_steps: steps,
5891
5901
  currency
5892
5902
  });
5893
- const redeem = clampPaymentRedeems(applied, redemptionCap({
5903
+ const redeem = clampPaymentRedeems(applied, orderRedeemCap({
5894
5904
  lines,
5895
5905
  totals
5896
5906
  }), currency);
@@ -7083,15 +7093,13 @@ const orderTotal = (condition, total) => {
7083
7093
  };
7084
7094
  //#endregion
7085
7095
  //#region src/rules/customMatcher.ts
7086
- const MULTI_CUSTOM_TYPES = [
7087
- "Fulfillments",
7088
- "Stores",
7089
- "Channels",
7090
- "Brands",
7091
- "Payments"
7096
+ const MULTI_OPERATORS = [
7097
+ "is any of",
7098
+ "is none of",
7099
+ "is all of"
7092
7100
  ];
7093
- const isMultiCustomType = (type) => {
7094
- return MULTI_CUSTOM_TYPES.includes(type);
7101
+ const isMultiOperator = (operator) => {
7102
+ return MULTI_OPERATORS.includes(operator);
7095
7103
  };
7096
7104
  const splitCsv = (value) => {
7097
7105
  return value.split(",").map((part) => part.trim()).filter(Boolean);
@@ -7114,15 +7122,25 @@ const matchCustomMulti = (condition, matcher) => {
7114
7122
  assert(typeof value === "string", "Invalid custom value");
7115
7123
  const allowed = splitCsv(value);
7116
7124
  if (allowed.length === 0) return false;
7117
- const candidates = [matcher];
7125
+ const candidates = typeof matcher === "object" ? matcher : [matcher];
7126
+ if (candidates.length === 0) return false;
7118
7127
  if (operator === "is any of") return allowed.some((id) => candidates.includes(id));
7119
7128
  if (operator === "is none of") return !allowed.some((id) => candidates.includes(id));
7120
7129
  if (operator === "is all of") return allowed.every((id) => candidates.includes(id));
7121
7130
  throw new Error(`Operator ${operator} not supported in custom matcher`);
7122
7131
  };
7132
+ /**
7133
+ * The operator picks the arity: `Payment` is single-select in order rules and
7134
+ * multi-select in fulfillment workflows. `matcher` may be a set (one id per
7135
+ * tender): `is` matches when some id matches, `is not` when none does.
7136
+ */
7123
7137
  const matchCustom = (condition, matcher) => {
7124
- if (isMultiCustomType(condition.type)) return matchCustomMulti(condition, matcher);
7125
- return matchCustomEquality(condition, matcher);
7138
+ if (isMultiOperator(condition.operator)) return matchCustomMulti(condition, matcher);
7139
+ if (typeof matcher === "undefined" || typeof matcher === "string") return matchCustomEquality(condition, matcher);
7140
+ if (matcher.length === 0) return false;
7141
+ const matches = (id) => matchCustomEquality(condition, id);
7142
+ if (condition.operator === "is not") return matcher.every(matches);
7143
+ return matcher.some(matches);
7126
7144
  };
7127
7145
  const assertCustom = (condition, order) => {
7128
7146
  const { type } = condition;
@@ -8000,9 +8018,9 @@ var RulesEngine = class {
8000
8018
  throw new Error(msg);
8001
8019
  };
8002
8020
  assertCustom = (condition) => {
8003
- if (condition.type === "Payment" || condition.type === "Payments") {
8021
+ if (condition.type === "Payment") {
8004
8022
  const payment = this.getDependency("payment", condition.type);
8005
- return matchCustom(condition, payment.id);
8023
+ return matchCustom(condition, payment.ids ?? payment.id);
8006
8024
  }
8007
8025
  const order = this.getDependency("order", condition.type);
8008
8026
  return assertCustom(condition, order);
@@ -8607,4 +8625,4 @@ const cardPreviewGroups = (value) => {
8607
8625
  return groups;
8608
8626
  };
8609
8627
  //#endregion
8610
- 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 };
8628
+ 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, orderPaymentRedeems, 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",
3
+ "version": "0.3.5",
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.3",
24
- "@fire-spark/types": "^0.3.3"
23
+ "@fire-spark/payments": "^0.3.5",
24
+ "@fire-spark/types": "^0.3.5"
25
25
  },
26
26
  "devDependencies": {
27
27
  "tsdown": "^0.22.14",