sahab-utils 2.1.6 → 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;
package/dist/ts/cash.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { Order, PaymentConfigs } from '../constants/types';
2
- /** Cash payment — the shared rules. The fee is set from `payment_methods/configs`; the app only shows it
2
+ /** Cash payment — the shared rules. The fee is set from `configs/payment_methods`; the app only shows it
3
3
  * and cloudFun is what charges it, so both must reach the same number from the same config. */
4
4
  /** A fee above this is read as a typo (5000 for 5.00) and ignored rather than charged to customers. */
5
5
  export declare const MAX_CASH_FEE = 50;
package/dist/ts/cash.js CHANGED
@@ -7,7 +7,7 @@ exports.cashAmountToCollect = cashAmountToCollect;
7
7
  const types_1 = require("../constants/types");
8
8
  const calcs_1 = require("./calcs");
9
9
  const utils_1 = require("./utils");
10
- /** Cash payment — the shared rules. The fee is set from `payment_methods/configs`; the app only shows it
10
+ /** Cash payment — the shared rules. The fee is set from `configs/payment_methods`; the app only shows it
11
11
  * and cloudFun is what charges it, so both must reach the same number from the same config. */
12
12
  /** A fee above this is read as a typo (5000 for 5.00) and ignored rather than charged to customers. */
13
13
  exports.MAX_CASH_FEE = 50;
@@ -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) {
@@ -2,6 +2,8 @@ export declare function preventNaN(x?: number | string): number;
2
2
  export declare const toFixed: (num: any) => string;
3
3
  export declare const isEmpty: (text: any) => boolean;
4
4
  export declare const compareVersions: (version1: string, version2: string) => number;
5
+ /** A plain dotted version such as `2.1.0`: digits and dots only. The one rule for saving a minimum version and for reading it. */
6
+ export declare const isValidVersion: (value: unknown) => value is string;
5
7
  /** Fails open on a missing/malformed version — a second, independent guard (the admin UI already
6
8
  * validates before saving) against a hand-edit or future write path bricking every install with a typo. */
7
9
  export declare function shouldForceUpdate(minVer?: string, currentVersion?: string): boolean;
package/dist/ts/utils.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.compareVersions = exports.isEmpty = exports.toFixed = void 0;
3
+ exports.isValidVersion = exports.compareVersions = exports.isEmpty = exports.toFixed = void 0;
4
4
  exports.preventNaN = preventNaN;
5
5
  exports.shouldForceUpdate = shouldForceUpdate;
6
6
  function preventNaN(x) {
@@ -39,12 +39,15 @@ const compareVersions = (version1, version2) => {
39
39
  };
40
40
  exports.compareVersions = compareVersions;
41
41
  const VERSION_RE = /^\d+(\.\d+)*$/;
42
+ /** A plain dotted version such as `2.1.0`: digits and dots only. The one rule for saving a minimum version and for reading it. */
43
+ const isValidVersion = (value) => typeof value === 'string' && value.length <= 20 && VERSION_RE.test(value);
44
+ exports.isValidVersion = isValidVersion;
42
45
  /** Fails open on a missing/malformed version — a second, independent guard (the admin UI already
43
46
  * validates before saving) against a hand-edit or future write path bricking every install with a typo. */
44
47
  function shouldForceUpdate(minVer, currentVersion) {
45
48
  if (!minVer || !currentVersion)
46
49
  return false;
47
- if (!VERSION_RE.test(minVer) || !VERSION_RE.test(currentVersion))
50
+ if (!(0, exports.isValidVersion)(minVer) || !(0, exports.isValidVersion)(currentVersion))
48
51
  return false;
49
52
  return (0, exports.compareVersions)(minVer, currentVersion) > 0;
50
53
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sahab-utils",
3
- "version": "2.1.6",
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",