sahab-utils 2.1.7 → 2.1.8

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.
@@ -1,6 +1,7 @@
1
1
  import { DocumentReference, GeoPoint, Timestamp } from 'firebase/firestore';
2
2
  import type { TapLicenseType } from '../ts/tap';
3
3
  import type { OrderSizeAdjustmentFields } from '../ts/orderAdjustment';
4
+ import type { LoyaltyCheckFields } from '../ts/loyalty';
4
5
  export type GeoPointType = GeoPoint;
5
6
  export type TimestampType = Timestamp;
6
7
  export type DistenceDueration = {
@@ -183,6 +184,9 @@ export type Order = {
183
184
  linkDeadline?: TimestampType;
184
185
  paidAt?: TimestampType;
185
186
  }>;
187
+ loyaltyChecks?: Array<LoyaltyCheckFields & {
188
+ checkedAt?: TimestampType;
189
+ }>;
186
190
  };
187
191
  export type ReduxOrder = {
188
192
  orderId?: string;
@@ -22,6 +22,19 @@ export declare function loyaltyQualifyingAmount(order: Order): number;
22
22
  /** Whether a finished order earns a stamp. For a multi-visit package this is asked per visit: every
23
23
  * completed visit earns one, not the package once. A redemption order earns none. */
24
24
  export declare function orderEarnsLoyaltyStamp(order: Order | undefined, offer: Discount | undefined): boolean;
25
+ export type LoyaltyCheckResult = 'stamped' | 'not_eligible' | 'already_counted';
26
+ /** One offer's verdict on a completed order, kept on `order.loyaltyChecks`. The offer can be edited later, so its
27
+ * terms are copied; the parts with no Firestore dependency — the server adds `checkedAt`. */
28
+ export type LoyaltyCheckFields = {
29
+ promoCodeId: string;
30
+ buyQuantity: number;
31
+ minOrderAmount: number;
32
+ /** What the minimum was compared against (`loyaltyQualifyingAmount`). */
33
+ qualifyingAmount: number;
34
+ result: LoyaltyCheckResult;
35
+ };
36
+ /** The verdict to record for `order` against `offer`, with the terms in force right now. */
37
+ export declare function loyaltyCheckFields(order: Order, offer: Discount, result: LoyaltyCheckResult): LoyaltyCheckFields;
25
38
  /** Whether buying a gift earns the giver a stamp. Awarded at purchase, not redemption — the reward
26
39
  * shouldn't hinge on whether the recipient ever spends it. The minimum is fair here since the giver really paid it. */
27
40
  export declare function giftEarnsLoyaltyStamp(gift: Gift | undefined, offer: Discount | undefined): boolean;
@@ -9,6 +9,7 @@ exports.isLoyaltyRedemption = isLoyaltyRedemption;
9
9
  exports.isPackageVisit = isPackageVisit;
10
10
  exports.loyaltyQualifyingAmount = loyaltyQualifyingAmount;
11
11
  exports.orderEarnsLoyaltyStamp = orderEarnsLoyaltyStamp;
12
+ exports.loyaltyCheckFields = loyaltyCheckFields;
12
13
  exports.giftEarnsLoyaltyStamp = giftEarnsLoyaltyStamp;
13
14
  exports.emptyLoyaltyProgress = emptyLoyaltyProgress;
14
15
  exports.applyLoyaltyStamp = applyLoyaltyStamp;
@@ -100,6 +101,17 @@ function orderEarnsLoyaltyStamp(order, offer) {
100
101
  return false;
101
102
  return true;
102
103
  }
104
+ /** The verdict to record for `order` against `offer`, with the terms in force right now. */
105
+ function loyaltyCheckFields(order, offer, result) {
106
+ var _a, _b, _c;
107
+ return {
108
+ promoCodeId: (_a = offer.promoCodeId) !== null && _a !== void 0 ? _a : '',
109
+ buyQuantity: (0, utils_1.preventNaN)((_b = offer.loyalty) === null || _b === void 0 ? void 0 : _b.buyQuantity),
110
+ minOrderAmount: (0, utils_1.preventNaN)((_c = offer.loyalty) === null || _c === void 0 ? void 0 : _c.minOrderAmount),
111
+ qualifyingAmount: loyaltyQualifyingAmount(order),
112
+ result,
113
+ };
114
+ }
103
115
  /** Whether buying a gift earns the giver a stamp. Awarded at purchase, not redemption — the reward
104
116
  * shouldn't hinge on whether the recipient ever spends it. The minimum is fair here since the giver really paid it. */
105
117
  function giftEarnsLoyaltyStamp(gift, offer) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sahab-utils",
3
- "version": "2.1.7",
3
+ "version": "2.1.8",
4
4
  "description": "This package contains types and utils functions",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",