sahab-utils 1.7.1 → 1.7.2
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/constants/types.d.ts +2 -0
- package/dist/ts/gifts.d.ts +11 -0
- package/dist/ts/gifts.js +22 -3
- package/package.json +1 -1
|
@@ -817,6 +817,8 @@ export type GiftConfig = {
|
|
|
817
817
|
* Bounded on read: a 0 would expire every gift the moment it was sold.
|
|
818
818
|
*/
|
|
819
819
|
giftExpiryMonths?: number;
|
|
820
|
+
/** Charged when the giver adds a personal message to the SMS. Defaults to `GIFT_MESSAGE_SURCHARGE_DEFAULT` when unset. */
|
|
821
|
+
giftMessageSurcharge?: number;
|
|
820
822
|
};
|
|
821
823
|
export type OrderReview = {
|
|
822
824
|
ratingId: string;
|
package/dist/ts/gifts.d.ts
CHANGED
|
@@ -17,6 +17,17 @@ export declare const MIN_GIFT_EXPIRY_MONTHS = 1;
|
|
|
17
17
|
export declare const MAX_GIFT_EXPIRY_MONTHS = 36;
|
|
18
18
|
/** What the giver pays: every line in the basket. */
|
|
19
19
|
export declare function giftTotal(items?: GiftItem[]): number;
|
|
20
|
+
/** A message longer than this spans more than one Arabic (UCS-2) SMS segment on its own. */
|
|
21
|
+
export declare const GIFT_MESSAGE_MAX_CHARS = 70;
|
|
22
|
+
/** Used when the back office has not set `GiftConfig.giftMessageSurcharge`. */
|
|
23
|
+
export declare const GIFT_MESSAGE_SURCHARGE_DEFAULT = 3;
|
|
24
|
+
/**
|
|
25
|
+
* What a personal message, if any, adds to the gift's price.
|
|
26
|
+
*
|
|
27
|
+
* Zero for a blank or whitespace-only message — writing nothing costs nothing. Otherwise the
|
|
28
|
+
* back-office amount if one is configured, else the default, same shape as `giftExpiryMonths`.
|
|
29
|
+
*/
|
|
30
|
+
export declare function giftMessageSurcharge(message?: string, config?: GiftConfig): number;
|
|
20
31
|
/** The gifted service ids. */
|
|
21
32
|
export declare function giftServiceIds(gift?: Pick<Gift, 'items'>): string[];
|
|
22
33
|
/** The gifted addon ids. */
|
package/dist/ts/gifts.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.MAX_GIFT_EXPIRY_MONTHS = exports.MIN_GIFT_EXPIRY_MONTHS = exports.DEFAULT_GIFT_EXPIRY_MONTHS = void 0;
|
|
3
|
+
exports.GIFT_MESSAGE_SURCHARGE_DEFAULT = exports.GIFT_MESSAGE_MAX_CHARS = exports.MAX_GIFT_EXPIRY_MONTHS = exports.MIN_GIFT_EXPIRY_MONTHS = exports.DEFAULT_GIFT_EXPIRY_MONTHS = void 0;
|
|
4
4
|
exports.giftTotal = giftTotal;
|
|
5
|
+
exports.giftMessageSurcharge = giftMessageSurcharge;
|
|
5
6
|
exports.giftServiceIds = giftServiceIds;
|
|
6
7
|
exports.giftAddonIds = giftAddonIds;
|
|
7
8
|
exports.giftExpiryMonths = giftExpiryMonths;
|
|
@@ -36,6 +37,22 @@ exports.MAX_GIFT_EXPIRY_MONTHS = 36;
|
|
|
36
37
|
function giftTotal(items) {
|
|
37
38
|
return (items !== null && items !== void 0 ? items : []).reduce((sum, item) => sum + (0, utils_1.preventNaN)(item === null || item === void 0 ? void 0 : item.price), 0);
|
|
38
39
|
}
|
|
40
|
+
/** A message longer than this spans more than one Arabic (UCS-2) SMS segment on its own. */
|
|
41
|
+
exports.GIFT_MESSAGE_MAX_CHARS = 70;
|
|
42
|
+
/** Used when the back office has not set `GiftConfig.giftMessageSurcharge`. */
|
|
43
|
+
exports.GIFT_MESSAGE_SURCHARGE_DEFAULT = 3;
|
|
44
|
+
/**
|
|
45
|
+
* What a personal message, if any, adds to the gift's price.
|
|
46
|
+
*
|
|
47
|
+
* Zero for a blank or whitespace-only message — writing nothing costs nothing. Otherwise the
|
|
48
|
+
* back-office amount if one is configured, else the default, same shape as `giftExpiryMonths`.
|
|
49
|
+
*/
|
|
50
|
+
function giftMessageSurcharge(message, config) {
|
|
51
|
+
if (!(message !== null && message !== void 0 ? message : '').trim().length)
|
|
52
|
+
return 0;
|
|
53
|
+
const raw = config === null || config === void 0 ? void 0 : config.giftMessageSurcharge;
|
|
54
|
+
return raw === undefined || raw === null || !isFinite(raw) || raw < 0 ? exports.GIFT_MESSAGE_SURCHARGE_DEFAULT : raw;
|
|
55
|
+
}
|
|
39
56
|
/** The gifted service ids. */
|
|
40
57
|
function giftServiceIds(gift) {
|
|
41
58
|
var _a;
|
|
@@ -105,8 +122,10 @@ function giftDiscount(gift, dates) {
|
|
|
105
122
|
return {
|
|
106
123
|
isPercentage: true,
|
|
107
124
|
amount: 100,
|
|
108
|
-
// Bounds the discount to the
|
|
109
|
-
|
|
125
|
+
// Bounds the discount to what the basket is actually worth, whatever the recipient
|
|
126
|
+
// orders — never to `gift.amount`, which can include a message surcharge that bought
|
|
127
|
+
// no redeemable service and must not inflate how much the voucher can discount.
|
|
128
|
+
maxAmount: giftTotal(gift.items),
|
|
110
129
|
clientIds: gift.recipientUid ? [gift.recipientUid] : [],
|
|
111
130
|
providerUids: gift.providerUid ? [gift.providerUid] : [],
|
|
112
131
|
servicesIds: giftServiceIds(gift),
|