sahab-utils 2.1.4 → 2.1.7
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 +0 -7
- package/dist/ts/broadcast.d.ts +1 -2
- package/dist/ts/broadcast.js +1 -3
- package/dist/ts/cash.d.ts +1 -1
- package/dist/ts/cash.js +1 -1
- package/dist/ts/crossedOrder.d.ts +3 -2
- package/dist/ts/crossedOrder.js +14 -12
- package/dist/ts/push.d.ts +2 -6
- package/dist/ts/push.js +1 -16
- package/dist/ts/utils.d.ts +2 -0
- package/dist/ts/utils.js +5 -2
- package/package.json +1 -1
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { DocumentReference, GeoPoint, Timestamp } from 'firebase/firestore';
|
|
2
|
-
import type { PushTransport } from '../ts/push';
|
|
3
2
|
import type { TapLicenseType } from '../ts/tap';
|
|
4
3
|
import type { OrderSizeAdjustmentFields } from '../ts/orderAdjustment';
|
|
5
4
|
export type GeoPointType = GeoPoint;
|
|
@@ -850,12 +849,6 @@ export type AppSettings = {
|
|
|
850
849
|
minimumBalanceToUse?: number;
|
|
851
850
|
/** The one live cashback campaign, if any — nested here rather than its own collection. */
|
|
852
851
|
cashback?: CashbackOffer;
|
|
853
|
-
/** Kill switch for the order Live Activity / Android Live Update pushes. Off unless true. */
|
|
854
|
-
liveActivitiesEnabled?: boolean;
|
|
855
|
-
/** Which transport delivers push: OneSignal (default when unset), FCM/APNs per recipient that has a token, or FCM only. */
|
|
856
|
-
pushTransport?: PushTransport;
|
|
857
|
-
/** Kill switch for staff push broadcasts. Off unless true; test sends to the dev team still work. */
|
|
858
|
-
broadcastEnabled?: boolean;
|
|
859
852
|
};
|
|
860
853
|
export type OrderReview = {
|
|
861
854
|
ratingId: string;
|
package/dist/ts/broadcast.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { TimestampType } from '../constants/types';
|
|
2
2
|
export type BilingualText = {
|
|
3
3
|
en: string;
|
|
4
4
|
ar: string;
|
|
@@ -66,4 +66,3 @@ export declare const broadcastCountTolerated: (expected: number, actual: number)
|
|
|
66
66
|
export declare const broadcastConfirmPhrase: (deviceCount: number) => string;
|
|
67
67
|
/** Broadcasts never use the provider new-order channel, which plays the horn. */
|
|
68
68
|
export declare const broadcastAndroidChannel: (app: "client" | "provider") => string;
|
|
69
|
-
export declare const isBroadcastEnabled: (settings?: Pick<AppSettings, "broadcastEnabled"> | null) => boolean;
|
package/dist/ts/broadcast.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.broadcastAndroidChannel = exports.broadcastConfirmPhrase = exports.broadcastCountTolerated = exports.validateBroadcastRequest = exports.BROADCAST_LIMITS = void 0;
|
|
4
4
|
const push_1 = require("./push");
|
|
5
5
|
// maxLeadMs is Cloud Tasks' 30-day scheduling horizon; title/body sized for lock-screen truncation.
|
|
6
6
|
exports.BROADCAST_LIMITS = { titleMax: 50, bodyMax: 180, minLeadMs: 5 * 60000, maxLeadMs: 30 * 24 * 3600000, hourlyCapPerStaff: 10 };
|
|
@@ -73,5 +73,3 @@ exports.broadcastConfirmPhrase = broadcastConfirmPhrase;
|
|
|
73
73
|
/** Broadcasts never use the provider new-order channel, which plays the horn. */
|
|
74
74
|
const broadcastAndroidChannel = (app) => (app === 'client' ? push_1.ANDROID_CHANNEL.client : push_1.ANDROID_CHANNEL.provider);
|
|
75
75
|
exports.broadcastAndroidChannel = broadcastAndroidChannel;
|
|
76
|
-
const isBroadcastEnabled = (settings) => (settings === null || settings === void 0 ? void 0 : settings.broadcastEnabled) === true;
|
|
77
|
-
exports.isBroadcastEnabled = isBroadcastEnabled;
|
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
|
|
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
|
|
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;
|
|
@@ -68,10 +68,11 @@ export declare function isValidCustomPrice(price: unknown, limits?: Pick<Crossed
|
|
|
68
68
|
export declare function crossedPayloadProblem(body: Record<string, unknown> | null | undefined, nowMs: number, limits?: CrossedLimits): string | undefined;
|
|
69
69
|
/** One service line for a provider-typed price: the customer pays it plus the client percentage, like any catalogue price. Never valid for a customer checkout. */
|
|
70
70
|
export declare function customServiceLine(providerPrice: number, minutes: number, size?: CarSize): ProvidedService;
|
|
71
|
-
/** The text to the customer: the booking, optionally the link, and where to get
|
|
72
|
-
export declare function crossedOrderSms(lang: 'ar' | 'en' | string | undefined, { providerName, payUrl }?: {
|
|
71
|
+
/** The text to the customer: the booking, optionally the link, and, for someone without the app, where to get it (`hasApp` skips that). One wording for the server's SMS; the sender name already says Sahab, so no prefix. */
|
|
72
|
+
export declare function crossedOrderSms(lang: 'ar' | 'en' | string | undefined, { providerName, payUrl, hasApp }?: {
|
|
73
73
|
providerName?: string;
|
|
74
74
|
payUrl?: string;
|
|
75
|
+
hasApp?: boolean;
|
|
75
76
|
}): string;
|
|
76
77
|
/** The push for a customer who already has the app; each device shows its own language. */
|
|
77
78
|
export declare function crossedOrderPush(providerName?: string): {
|
package/dist/ts/crossedOrder.js
CHANGED
|
@@ -105,19 +105,21 @@ const shortName = (name) => {
|
|
|
105
105
|
const t = (name !== null && name !== void 0 ? name : '').trim().replace(/\s+/g, ' ');
|
|
106
106
|
return t.length > SMS_NAME_MAX ? `${t.slice(0, SMS_NAME_MAX - 1).replace(/\s+$/, '')}…` : t;
|
|
107
107
|
};
|
|
108
|
-
/** The text to the customer: the booking, optionally the link, and where to get
|
|
109
|
-
function crossedOrderSms(lang, { providerName, payUrl } = {}) {
|
|
108
|
+
/** The text to the customer: the booking, optionally the link, and, for someone without the app, where to get it (`hasApp` skips that). One wording for the server's SMS; the sender name already says Sahab, so no prefix. */
|
|
109
|
+
function crossedOrderSms(lang, { providerName, payUrl, hasApp } = {}) {
|
|
110
110
|
const name = shortName(providerName);
|
|
111
111
|
if (lang === 'en') {
|
|
112
|
-
const head = name ?
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
112
|
+
const head = name ? `${name} booked a car wash for you.` : 'A car wash was booked for you.';
|
|
113
|
+
const pay = [`Pay within ${payLink_1.PAY_LINK_WINDOW_MINUTES} minutes to confirm your booking:`, payUrl];
|
|
114
|
+
if (hasApp)
|
|
115
|
+
return (payUrl ? [head, ...pay] : [head, 'Follow it in the Sahab app.']).join('\n');
|
|
116
|
+
return payUrl ? [head, ...pay, 'Get the app to follow your order:', SITE_URL].join('\n') : [head, 'Get the app and sign in with this number to follow your order:', SITE_URL].join('\n');
|
|
116
117
|
}
|
|
117
|
-
const head = name ?
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
118
|
+
const head = name ? `${name} حجز لك موعد غسيل.` : 'تم حجز موعد غسيل لك.';
|
|
119
|
+
const pay = [`ادفع خلال ${payLink_1.PAY_LINK_WINDOW_MINUTES} دقيقة عشان يتأكد حجزك:`, payUrl];
|
|
120
|
+
if (hasApp)
|
|
121
|
+
return (payUrl ? [head, ...pay] : [head, 'تابعه من تطبيق سحاب.']).join('\n');
|
|
122
|
+
return payUrl ? [head, ...pay, 'وحمّل التطبيق لمتابعة طلبك:', SITE_URL].join('\n') : [head, 'حمّل التطبيق وسجّل بنفس رقمك عشان تتابع طلبك:', SITE_URL].join('\n');
|
|
121
123
|
}
|
|
122
124
|
/** The push for a customer who already has the app; each device shows its own language. */
|
|
123
125
|
function crossedOrderPush(providerName) {
|
|
@@ -133,6 +135,6 @@ function crossedOrderPush(providerName) {
|
|
|
133
135
|
function crossedCancelledMessage(lang, providerName) {
|
|
134
136
|
const name = shortName(providerName);
|
|
135
137
|
if (lang === 'en')
|
|
136
|
-
return name ?
|
|
137
|
-
return name ?
|
|
138
|
+
return name ? `${name} cancelled your booking. You will not be charged.` : 'Your booking was cancelled. You will not be charged.';
|
|
139
|
+
return name ? `${name} ألغى حجزك. ما راح يتسحب منك أي مبلغ.` : 'تم إلغاء حجزك. ما راح يتسحب منك أي مبلغ.';
|
|
138
140
|
}
|
package/dist/ts/push.d.ts
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { TimestampType } from '../constants/types';
|
|
2
2
|
import { OrderActivityContent } from './orderActivity';
|
|
3
3
|
export type PushApp = 'client' | 'provider';
|
|
4
4
|
export type PushRole = 'customer' | 'owner' | 'driver';
|
|
5
5
|
export type PushPlatform = 'ios' | 'android';
|
|
6
|
-
export type PushTransport = 'onesignal' | 'auto' | 'fcm';
|
|
7
6
|
export type ApnsEnvironment = 'sandbox' | 'production';
|
|
8
7
|
export type LiveNotificationKind = 'start' | 'update' | 'end';
|
|
9
8
|
export type PushActivityEntry = {
|
|
@@ -52,7 +51,7 @@ export type RegisterActivityTokenBody = {
|
|
|
52
51
|
/** `accepted` counts devices the provider took the message for; it is not proof the phone displayed it. */
|
|
53
52
|
export type TestPushResult = {
|
|
54
53
|
status: 'sent' | 'no_device' | 'failed';
|
|
55
|
-
transport: 'fcm'
|
|
54
|
+
transport: 'fcm';
|
|
56
55
|
devices: number;
|
|
57
56
|
accepted: number;
|
|
58
57
|
};
|
|
@@ -73,9 +72,6 @@ export declare const ANDROID_CHANNEL: {
|
|
|
73
72
|
};
|
|
74
73
|
export declare const APNS_LIVE_ACTIVITY_TOPIC_SUFFIX = ".push-type.liveactivity";
|
|
75
74
|
export declare const LIVE_NOTIFICATION_DATA_KEY = "live_notification";
|
|
76
|
-
/** An absent or unrecognised value is `onesignal`, so the switch defaults to today's behaviour. */
|
|
77
|
-
export declare const pushTransportOf: (settings?: Pick<AppSettings, "pushTransport"> | null) => PushTransport;
|
|
78
|
-
export declare const choosePushTransport: (mode: PushTransport, hasTokens: boolean) => "onesignal" | "fcm";
|
|
79
75
|
export declare const buildLiveNotification: (kind: LiveNotificationKind, orderId: string, content: OrderActivityContent) => {
|
|
80
76
|
key: string;
|
|
81
77
|
event: LiveNotificationKind;
|
package/dist/ts/push.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.sanitizePushUids = exports.buildLiveNotificationData = exports.buildLiveNotification = exports.
|
|
3
|
+
exports.sanitizePushUids = exports.buildLiveNotificationData = exports.buildLiveNotification = exports.LIVE_NOTIFICATION_DATA_KEY = exports.APNS_LIVE_ACTIVITY_TOPIC_SUFFIX = exports.ANDROID_CHANNEL = exports.PUSH_TOKENS_COLLECTION = exports.TEST_PUSH_DAILY_LIMIT = exports.TEST_PUSH_COOLDOWN_S = void 0;
|
|
4
4
|
const orderActivity_1 = require("./orderActivity");
|
|
5
5
|
exports.TEST_PUSH_COOLDOWN_S = 30;
|
|
6
6
|
exports.TEST_PUSH_DAILY_LIMIT = 20;
|
|
@@ -8,21 +8,6 @@ exports.PUSH_TOKENS_COLLECTION = 'pushTokens';
|
|
|
8
8
|
exports.ANDROID_CHANNEL = { client: 'orders', providerNewOrder: 'new-orders', provider: 'general' };
|
|
9
9
|
exports.APNS_LIVE_ACTIVITY_TOPIC_SUFFIX = '.push-type.liveactivity';
|
|
10
10
|
exports.LIVE_NOTIFICATION_DATA_KEY = 'live_notification';
|
|
11
|
-
const PUSH_TRANSPORTS = ['onesignal', 'auto', 'fcm'];
|
|
12
|
-
/** An absent or unrecognised value is `onesignal`, so the switch defaults to today's behaviour. */
|
|
13
|
-
const pushTransportOf = (settings) => {
|
|
14
|
-
const mode = settings === null || settings === void 0 ? void 0 : settings.pushTransport;
|
|
15
|
-
return mode && PUSH_TRANSPORTS.includes(mode) ? mode : 'onesignal';
|
|
16
|
-
};
|
|
17
|
-
exports.pushTransportOf = pushTransportOf;
|
|
18
|
-
const choosePushTransport = (mode, hasTokens) => {
|
|
19
|
-
if (mode === 'fcm')
|
|
20
|
-
return 'fcm';
|
|
21
|
-
if (mode === 'auto' && hasTokens)
|
|
22
|
-
return 'fcm';
|
|
23
|
-
return 'onesignal';
|
|
24
|
-
};
|
|
25
|
-
exports.choosePushTransport = choosePushTransport;
|
|
26
11
|
const buildLiveNotification = (kind, orderId, content) => ({
|
|
27
12
|
key: (0, orderActivity_1.orderActivityId)(orderId),
|
|
28
13
|
event: kind,
|
package/dist/ts/utils.d.ts
CHANGED
|
@@ -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 (!
|
|
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
|
}
|