sahab-utils 2.1.3 → 2.1.6
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 +9 -7
- package/dist/ts/broadcast.d.ts +1 -2
- package/dist/ts/broadcast.js +1 -3
- package/dist/ts/crossedOrder.d.ts +3 -2
- package/dist/ts/crossedOrder.js +14 -12
- package/dist/ts/payLink.d.ts +8 -0
- package/dist/ts/push.d.ts +2 -6
- package/dist/ts/push.js +1 -16
- 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;
|
|
@@ -174,6 +173,11 @@ export type Order = {
|
|
|
174
173
|
payLinkDeadline?: TimestampType;
|
|
175
174
|
payLinkSmsCount?: number;
|
|
176
175
|
createdByStaff?: string;
|
|
176
|
+
createdByProvider?: string;
|
|
177
|
+
createdByProviderName?: string;
|
|
178
|
+
crossedOrder?: boolean;
|
|
179
|
+
payLinkShortUrl?: string;
|
|
180
|
+
priceSource?: 'provider';
|
|
177
181
|
sizeAdjustments?: Array<OrderSizeAdjustmentFields & {
|
|
178
182
|
createdAt?: TimestampType;
|
|
179
183
|
linkDeadline?: TimestampType;
|
|
@@ -235,6 +239,10 @@ export type ReduxOrder = {
|
|
|
235
239
|
};
|
|
236
240
|
providerPhoneNumber?: string;
|
|
237
241
|
providerLogoUrl?: string;
|
|
242
|
+
createdByProvider?: string;
|
|
243
|
+
paymentLinkUrl?: string;
|
|
244
|
+
payLinkShortUrl?: string;
|
|
245
|
+
payLinkDeadline?: TimestampType;
|
|
238
246
|
};
|
|
239
247
|
export type MoneyMovement = {
|
|
240
248
|
movementId: string;
|
|
@@ -841,12 +849,6 @@ export type AppSettings = {
|
|
|
841
849
|
minimumBalanceToUse?: number;
|
|
842
850
|
/** The one live cashback campaign, if any — nested here rather than its own collection. */
|
|
843
851
|
cashback?: CashbackOffer;
|
|
844
|
-
/** Kill switch for the order Live Activity / Android Live Update pushes. Off unless true. */
|
|
845
|
-
liveActivitiesEnabled?: boolean;
|
|
846
|
-
/** Which transport delivers push: OneSignal (default when unset), FCM/APNs per recipient that has a token, or FCM only. */
|
|
847
|
-
pushTransport?: PushTransport;
|
|
848
|
-
/** Kill switch for staff push broadcasts. Off unless true; test sends to the dev team still work. */
|
|
849
|
-
broadcastEnabled?: boolean;
|
|
850
852
|
};
|
|
851
853
|
export type OrderReview = {
|
|
852
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;
|
|
@@ -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/payLink.d.ts
CHANGED
|
@@ -12,6 +12,14 @@ export type PayLinkOrderFields<TTimestamp> = {
|
|
|
12
12
|
payLinkDeadline?: TTimestamp;
|
|
13
13
|
payLinkSmsCount?: number;
|
|
14
14
|
createdByStaff?: string;
|
|
15
|
+
/** Set when a provider (or its driver) made the order from the provider app: the creator's id, shown as "created by provider". */
|
|
16
|
+
createdByProvider?: string;
|
|
17
|
+
createdByProviderName?: string;
|
|
18
|
+
crossedOrder?: boolean;
|
|
19
|
+
/** The shortened link the customer was texted; `paymentLinkUrl` is the full Checkout link. */
|
|
20
|
+
payLinkShortUrl?: string;
|
|
21
|
+
/** Audit flag: the price was typed by the provider, not read from its catalogue. */
|
|
22
|
+
priceSource?: 'provider';
|
|
15
23
|
};
|
|
16
24
|
export type CreatePayLinkOrderRequest = {
|
|
17
25
|
clientUid: string;
|
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,
|