@fire-spark/core 0.3.5 → 0.4.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/dist/index.d.ts CHANGED
@@ -408,7 +408,7 @@ type ApplyRedeemInput = {
408
408
  reward_id: string;
409
409
  /**
410
410
  * Reward units to redeem (integer ≥ 1). With `payment_id` it is
411
- * informational: `amount` and `points` already cover every unit.
411
+ * informational: `amount` already covers every unit.
412
412
  */
413
413
  quantity: number;
414
414
  /** 0–1, compounded per unit over the remaining value. */
@@ -423,19 +423,17 @@ type ApplyRedeemInput = {
423
423
  /** Root line to discount; omit to discount the whole order (prorated). */
424
424
  line_uid?: string;
425
425
  /**
426
- * Points / balance: the merchant `REDEMPTION` payment that pays `amount`
427
- * (a tender, not a discount). Requires `amount` and `points`. Redeems
428
- * with the same `payment_id` share one tender (`details.rewards[]`).
426
+ * Reward paid as a tender (voucher, balance…, not a discount): the
427
+ * merchant `REDEMPTION` payment that pays `amount`. Requires `amount`.
428
+ * Redeems with the same `payment_id` share one tender
429
+ * (`details.rewards[]`).
429
430
  */
430
431
  payment_id?: string;
431
432
  /**
432
- * Total money the points cover for the whole entry (all `quantity`
433
+ * Total money the reward covers for the whole entry (all `quantity`
433
434
  * units, not per unit); trimmed to total − tip − delivery.
434
435
  */
435
436
  amount?: number;
436
- /** Total points spent for the whole entry (not per unit). */
437
- points?: number;
438
- program?: string;
439
437
  /** Provider of the REDEMPTION payment (default `firespark`). */
440
438
  provider?: PaymentProvider;
441
439
  /** ISO datetime with offset; validation fails once it has passed. */
@@ -517,9 +515,9 @@ declare class Order {
517
515
  emptyOrder(): void;
518
516
  /**
519
517
  * Appends a redeem to `line_uid` (root line) or to the order. Steps keep
520
- * the order in which redeems were applied. With `payment_id` (points /
521
- * balance) it is not a discount: `amount` and `points` are totals of the
522
- * whole entry (every unit, not per unit) and `quantity` is informational.
518
+ * the order in which redeems were applied. With `payment_id` (voucher,
519
+ * balance…) it is not a discount: `amount` is the total of the whole
520
+ * entry (every unit, not per unit) and `quantity` is informational.
523
521
  * Every redeem with the same `payment_id` is paid by one REDEMPTION
524
522
  * tender whose `details.rewards[]` lists them; their summed amount is
525
523
  * capped at total − tip − delivery (D15, D18, D19).
@@ -528,9 +526,8 @@ declare class Order {
528
526
  /**
529
527
  * Removes `quantity` units of `reward_id` from `line_uid` or the order,
530
528
  * latest applied first. Removing more units than applied clears them all
531
- * (and the REDEMPTION tender of a points / balance redeem). A points /
532
- * balance entry that keeps some units keeps the same share of its
533
- * `amount` and `points`.
529
+ * (and the REDEMPTION tender of a payment redeem). A payment redeem that
530
+ * keeps some units keeps the same share of its `amount`.
534
531
  */
535
532
  removeRedeem(input: RemoveRedeemInput): void;
536
533
  private rememberLogScope;
@@ -544,7 +541,7 @@ declare class Order {
544
541
  cancelOrder(): Promise<void>;
545
542
  /**
546
543
  * Reopens this placed, unpaid order: the server voids every payment
547
- * (REDEMPTION points released), cancels it as `VOIDED` and opens a new
544
+ * (REDEMPTION rewards released), cancels it as `VOIDED` and opens a new
548
545
  * `OPEN` order with the same content. This instance is closed afterwards;
549
546
  * replace it with the returned `Order` (same HTTP options and listener).
550
547
  *
@@ -856,7 +853,7 @@ declare const listMenusStream: (scope?: StorefrontMenuScope, options?: ListMenus
856
853
  //#endregion
857
854
  //#region src/services/payments.d.ts
858
855
  type ListPaymentsOptions = ServiceHttpOptions & {
859
- /** Keep `REDEMPTION` payments (points / balance) for redeem flows. */
856
+ /** Keep `REDEMPTION` payments (vouchers, balance…) for redeem flows. */
860
857
  includeRedemptions?: boolean;
861
858
  };
862
859
  /**
package/dist/index.js CHANGED
@@ -3480,8 +3480,8 @@ const orderRedeemCap = (order) => {
3480
3480
  return Math.max(roundTo(redemptionCap(order) - used, decimals), 0);
3481
3481
  };
3482
3482
  /**
3483
- * Trims payment redeems in application order so their sum fits the cap;
3484
- * points shrink in proportion. Discount redeems are left untouched.
3483
+ * Trims payment redeems in application order so their sum fits the cap.
3484
+ * Discount redeems are left untouched.
3485
3485
  */
3486
3486
  const clampPaymentRedeems = (redeem, cap, currency) => {
3487
3487
  const decimals = currencyDecimals(currency);
@@ -3493,12 +3493,9 @@ const clampPaymentRedeems = (redeem, cap, currency) => {
3493
3493
  left = roundTo(left - fits, decimals);
3494
3494
  if (fits <= 0) return [];
3495
3495
  if (fits + amountTolerance(currency) >= amount) return [item];
3496
- const ratio = amount > 0 ? fits / amount : 0;
3497
- const points = roundTo((item.points ?? 0) * ratio, 0);
3498
3496
  return [{
3499
3497
  ...item,
3500
- amount: fits,
3501
- points
3498
+ amount: fits
3502
3499
  }];
3503
3500
  });
3504
3501
  };
@@ -4722,17 +4719,14 @@ const emptyTotals = (currency = "USD") => {
4722
4719
  //#region src/order/redemptions.ts
4723
4720
  const ORDER_KEY = "ORDER";
4724
4721
  const buildPaymentRedeem = (input) => {
4725
- const { reward_id, quantity, payment_id, amount, points } = input;
4722
+ const { reward_id, quantity, payment_id, amount } = input;
4726
4723
  if (amount === void 0 || !(amount > 0)) throw new Error("Redeem with payment_id requires amount > 0");
4727
- if (points === void 0 || !(points >= 0)) throw new Error("Redeem with payment_id requires points ≥ 0");
4728
4724
  const redeem = {
4729
4725
  reward_id,
4730
4726
  quantity,
4731
4727
  payment_id,
4732
4728
  amount
4733
4729
  };
4734
- redeem.points = points;
4735
- if (input.program !== void 0) redeem.program = input.program;
4736
4730
  if (input.expires_at !== void 0) redeem.expires_at = input.expires_at;
4737
4731
  return redeem;
4738
4732
  };
@@ -4766,12 +4760,10 @@ const keepUnits = (item, rest) => {
4766
4760
  };
4767
4761
  const ratio = new Big(rest).div(item.quantity);
4768
4762
  const amount = new Big(item.amount ?? 0).times(ratio).round(6).toNumber();
4769
- const points = new Big(item.points ?? 0).times(ratio).round(0).toNumber();
4770
4763
  return {
4771
4764
  ...item,
4772
4765
  quantity: rest,
4773
- amount,
4774
- points
4766
+ amount
4775
4767
  };
4776
4768
  };
4777
4769
  /**
@@ -5094,7 +5086,7 @@ const cloneOrder = (order) => {
5094
5086
  };
5095
5087
  const redeemSignature$1 = (items) => {
5096
5088
  return items.map((item) => {
5097
- return `${`${item.reward_id}:${item.quantity}:${item.payment_id ?? ""}`}:${`${item.amount ?? ""}:${item.points ?? ""}`}:${`${item.discount_rate ?? ""}:${item.discount_amount ?? ""}`}`;
5089
+ return `${`${item.reward_id}:${item.quantity}:${item.payment_id ?? ""}`}:${`${item.amount ?? ""}`}:${`${item.discount_rate ?? ""}:${item.discount_amount ?? ""}`}`;
5098
5090
  }).join("|");
5099
5091
  };
5100
5092
  const buildHttpOptions = (options) => {
@@ -5509,9 +5501,9 @@ var Order = class Order {
5509
5501
  }
5510
5502
  /**
5511
5503
  * Appends a redeem to `line_uid` (root line) or to the order. Steps keep
5512
- * the order in which redeems were applied. With `payment_id` (points /
5513
- * balance) it is not a discount: `amount` and `points` are totals of the
5514
- * whole entry (every unit, not per unit) and `quantity` is informational.
5504
+ * the order in which redeems were applied. With `payment_id` (voucher,
5505
+ * balance…) it is not a discount: `amount` is the total of the whole
5506
+ * entry (every unit, not per unit) and `quantity` is informational.
5515
5507
  * Every redeem with the same `payment_id` is paid by one REDEMPTION
5516
5508
  * tender whose `details.rewards[]` lists them; their summed amount is
5517
5509
  * capped at total − tip − delivery (D15, D18, D19).
@@ -5520,7 +5512,7 @@ var Order = class Order {
5520
5512
  if (this.deleted) return;
5521
5513
  const { line_uid, provider, ...rest } = input;
5522
5514
  const redeem = buildRedeem(rest);
5523
- if (isPaymentRedeem(redeem) && line_uid !== void 0) throw new Error("Points / balance redeems apply to the whole order");
5515
+ if (isPaymentRedeem(redeem) && line_uid !== void 0) throw new Error("Payment redeems apply to the whole order");
5524
5516
  if (redeem.payment_id && provider) this.redemptionProviders.set(redeem.payment_id, provider);
5525
5517
  if (line_uid === void 0) {
5526
5518
  this.commitLines({ redeem: [...this.appliedRedeem(), redeem] });
@@ -5540,9 +5532,8 @@ var Order = class Order {
5540
5532
  /**
5541
5533
  * Removes `quantity` units of `reward_id` from `line_uid` or the order,
5542
5534
  * latest applied first. Removing more units than applied clears them all
5543
- * (and the REDEMPTION tender of a points / balance redeem). A points /
5544
- * balance entry that keeps some units keeps the same share of its
5545
- * `amount` and `points`.
5535
+ * (and the REDEMPTION tender of a payment redeem). A payment redeem that
5536
+ * keeps some units keeps the same share of its `amount`.
5546
5537
  */
5547
5538
  removeRedeem(input) {
5548
5539
  if (this.deleted) return;
@@ -5649,7 +5640,7 @@ var Order = class Order {
5649
5640
  }
5650
5641
  /**
5651
5642
  * Reopens this placed, unpaid order: the server voids every payment
5652
- * (REDEMPTION points released), cancels it as `VOIDED` and opens a new
5643
+ * (REDEMPTION rewards released), cancels it as `VOIDED` and opens a new
5653
5644
  * `OPEN` order with the same content. This instance is closed afterwards;
5654
5645
  * replace it with the returned `Order` (same HTTP options and listener).
5655
5646
  *
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fire-spark/core",
3
- "version": "0.3.5",
3
+ "version": "0.4.0",
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.5",
24
- "@fire-spark/types": "^0.3.5"
23
+ "@fire-spark/payments": "^0.4.0",
24
+ "@fire-spark/types": "^0.4.0"
25
25
  },
26
26
  "devDependencies": {
27
27
  "tsdown": "^0.22.14",