sahab-utils 1.8.3 → 1.8.5
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/ts/orderActivity.d.ts +7 -0
- package/dist/ts/orderActivity.js +17 -1
- package/dist/ts/push.d.ts +7 -0
- package/package.json +1 -1
|
@@ -7,6 +7,8 @@ export declare const ORDER_LIVE_WINDOW_MS: number;
|
|
|
7
7
|
/** How long the widget keeps saying the car is clean after the order finishes. */
|
|
8
8
|
export declare const ORDER_DONE_VISIBLE_MS: number;
|
|
9
9
|
export declare const ORDER_ACTIVITY_STALE_MS: number;
|
|
10
|
+
/** A status nobody moved on a day after the booked time (on the way, washing) is stuck, not live. */
|
|
11
|
+
export declare const ORDER_STUCK_MS: number;
|
|
10
12
|
/** How long the widget trusts a status it was last told while the app was closed; after that it asks the customer to open the app. */
|
|
11
13
|
export declare const ORDER_WIDGET_FRESH_MS: number;
|
|
12
14
|
/** The id both the server and the app's token registration use for one order's activity. */
|
|
@@ -42,6 +44,11 @@ export declare const ACTIVE_ORDER_STATUSES: OrderStatus[];
|
|
|
42
44
|
export declare function orderActivityLang(language?: string): OrderActivityLang;
|
|
43
45
|
export declare function isOrderActive(status?: OrderStatus): boolean;
|
|
44
46
|
export declare function orderActivityStep(status?: OrderStatus): OrderActivityStep | null;
|
|
47
|
+
/**
|
|
48
|
+
* Whether an order is still worth showing: a booking nobody started stops mattering `ORDER_ACTIVITY_STALE_MS` after its time, and a
|
|
49
|
+
* status stuck on the way or washing stops mattering after `ORDER_STUCK_MS`. Orders left behind (test data, no-shows) otherwise pile up.
|
|
50
|
+
*/
|
|
51
|
+
export declare function isOrderCurrent(status: OrderStatus | undefined, orderDateMs: number, nowMs: number): boolean;
|
|
45
52
|
/** Whether an order deserves a Live Activity right now: on the way / washing, or accepted and due within the live window. */
|
|
46
53
|
export declare function isOrderLive(status: OrderStatus | undefined, orderDateMs: number, nowMs: number): boolean;
|
|
47
54
|
/** What every surface (Live Activity, widget, Android notification) shows for an order. Never includes the driver's name. */
|
package/dist/ts/orderActivity.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ACTIVE_ORDER_STATUSES = exports.ORDER_ACTIVITY_TEXT = exports.orderIdFromDeepLink = exports.orderDeepLink = exports.orderActivityId = exports.ORDER_WIDGET_FRESH_MS = exports.ORDER_ACTIVITY_STALE_MS = exports.ORDER_DONE_VISIBLE_MS = exports.ORDER_LIVE_WINDOW_MS = exports.ORDER_ACTIVITY_STEP_COUNT = exports.ORDER_ACTIVITY_NAME = exports.ORDER_ACTIVITY_TYPE = void 0;
|
|
3
|
+
exports.ACTIVE_ORDER_STATUSES = exports.ORDER_ACTIVITY_TEXT = exports.orderIdFromDeepLink = exports.orderDeepLink = exports.orderActivityId = exports.ORDER_WIDGET_FRESH_MS = exports.ORDER_STUCK_MS = exports.ORDER_ACTIVITY_STALE_MS = exports.ORDER_DONE_VISIBLE_MS = exports.ORDER_LIVE_WINDOW_MS = exports.ORDER_ACTIVITY_STEP_COUNT = exports.ORDER_ACTIVITY_NAME = exports.ORDER_ACTIVITY_TYPE = void 0;
|
|
4
4
|
exports.orderActivityLang = orderActivityLang;
|
|
5
5
|
exports.isOrderActive = isOrderActive;
|
|
6
6
|
exports.orderActivityStep = orderActivityStep;
|
|
7
|
+
exports.isOrderCurrent = isOrderCurrent;
|
|
7
8
|
exports.isOrderLive = isOrderLive;
|
|
8
9
|
exports.buildOrderActivityContent = buildOrderActivityContent;
|
|
9
10
|
exports.pickPrimaryOrder = pickPrimaryOrder;
|
|
@@ -18,6 +19,8 @@ exports.ORDER_LIVE_WINDOW_MS = 15 * 60 * 1000;
|
|
|
18
19
|
/** How long the widget keeps saying the car is clean after the order finishes. */
|
|
19
20
|
exports.ORDER_DONE_VISIBLE_MS = 2 * 60 * 60 * 1000;
|
|
20
21
|
exports.ORDER_ACTIVITY_STALE_MS = 3 * 60 * 60 * 1000;
|
|
22
|
+
/** A status nobody moved on a day after the booked time (on the way, washing) is stuck, not live. */
|
|
23
|
+
exports.ORDER_STUCK_MS = 24 * 60 * 60 * 1000;
|
|
21
24
|
/** How long the widget trusts a status it was last told while the app was closed; after that it asks the customer to open the app. */
|
|
22
25
|
exports.ORDER_WIDGET_FRESH_MS = 45 * 60 * 1000;
|
|
23
26
|
/** The id both the server and the app's token registration use for one order's activity. */
|
|
@@ -84,6 +87,18 @@ function orderActivityStep(status) {
|
|
|
84
87
|
return null;
|
|
85
88
|
}
|
|
86
89
|
}
|
|
90
|
+
/**
|
|
91
|
+
* Whether an order is still worth showing: a booking nobody started stops mattering `ORDER_ACTIVITY_STALE_MS` after its time, and a
|
|
92
|
+
* status stuck on the way or washing stops mattering after `ORDER_STUCK_MS`. Orders left behind (test data, no-shows) otherwise pile up.
|
|
93
|
+
*/
|
|
94
|
+
function isOrderCurrent(status, orderDateMs, nowMs) {
|
|
95
|
+
const step = orderActivityStep(status);
|
|
96
|
+
if (step === null || step === 'DONE' || step === 'CANCELLED')
|
|
97
|
+
return false;
|
|
98
|
+
if (!hasDate(orderDateMs))
|
|
99
|
+
return true;
|
|
100
|
+
return nowMs - orderDateMs <= (step === 'SCHEDULED' ? exports.ORDER_ACTIVITY_STALE_MS : exports.ORDER_STUCK_MS);
|
|
101
|
+
}
|
|
87
102
|
const isWithinLiveWindow = (orderDateMs, nowMs) => orderDateMs - nowMs <= exports.ORDER_LIVE_WINDOW_MS;
|
|
88
103
|
/** Whether an order deserves a Live Activity right now: on the way / washing, or accepted and due within the live window. */
|
|
89
104
|
function isOrderLive(status, orderDateMs, nowMs) {
|
|
@@ -221,6 +236,7 @@ const widgetFreshUntil = (o, syncedAtMs) => {
|
|
|
221
236
|
function buildOrderWidgetContent(active, lastFinished, lang, nowMs = Date.now(), syncedAtMs = nowMs) {
|
|
222
237
|
var _a, _b, _c, _d;
|
|
223
238
|
const text = WIDGET_TEXT[lang];
|
|
239
|
+
active = active.filter((o) => isOrderCurrent(o.orderStatus, o.orderDateMs, nowMs));
|
|
224
240
|
const primary = pickPrimaryOrder(active, nowMs);
|
|
225
241
|
const finish = (state, orderId, title, subtitle, stepIndex, moreText = '') => ({
|
|
226
242
|
state,
|
package/dist/ts/push.d.ts
CHANGED
|
@@ -56,6 +56,13 @@ export type TestPushResult = {
|
|
|
56
56
|
devices: number;
|
|
57
57
|
accepted: number;
|
|
58
58
|
};
|
|
59
|
+
/** The customer app sends nothing. The provider app names who it is, so the server can check that it is that person. */
|
|
60
|
+
export type TestPushBody = {
|
|
61
|
+
app?: PushApp;
|
|
62
|
+
role?: 'owner' | 'driver';
|
|
63
|
+
uid?: string;
|
|
64
|
+
providerUid?: string;
|
|
65
|
+
};
|
|
59
66
|
export declare const TEST_PUSH_COOLDOWN_S = 30;
|
|
60
67
|
export declare const TEST_PUSH_DAILY_LIMIT = 20;
|
|
61
68
|
export declare const PUSH_TOKENS_COLLECTION = "pushTokens";
|