sahab-utils 2.1.2 → 2.1.3
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/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/ts/crossedOrder.d.ts +88 -0
- package/dist/ts/crossedOrder.js +138 -0
- package/dist/ts/payLink.d.ts +3 -1
- package/dist/ts/payLink.js +10 -8
- package/package.json +2 -2
|
@@ -406,6 +406,8 @@ export type ProvidedService = {
|
|
|
406
406
|
en: string;
|
|
407
407
|
};
|
|
408
408
|
price: Price;
|
|
409
|
+
/** Set on a line whose price a provider typed in, instead of taking it from the catalogue. */
|
|
410
|
+
providerSet?: boolean;
|
|
409
411
|
isDone?: boolean;
|
|
410
412
|
finishDate?: TimestampType;
|
|
411
413
|
quantity?: number;
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -23,6 +23,7 @@ __exportStar(require("./ts/calcs"), exports);
|
|
|
23
23
|
__exportStar(require("./ts/carCatalogue"), exports);
|
|
24
24
|
__exportStar(require("./ts/cash"), exports);
|
|
25
25
|
__exportStar(require("./ts/cashback"), exports);
|
|
26
|
+
__exportStar(require("./ts/crossedOrder"), exports);
|
|
26
27
|
__exportStar(require("./ts/gifts"), exports);
|
|
27
28
|
__exportStar(require("./ts/iban"), exports);
|
|
28
29
|
__exportStar(require("./ts/loyalty"), exports);
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { CarSize, OrderStatus, ProvidedService } from '../constants/types';
|
|
2
|
+
import { LatLng } from './payLink';
|
|
3
|
+
/** Crossed slots created by a provider or an allowed driver, optionally with a payment link — the contract between the provider app and cloudFun. */
|
|
4
|
+
/** What the server falls back to when `configs/crossed_orders` has no value for a limit. */
|
|
5
|
+
export declare const CROSSED_DEFAULT_LIMITS: {
|
|
6
|
+
customTotalMinSar: number;
|
|
7
|
+
customTotalMaxSar: number;
|
|
8
|
+
durationMinMinutes: number;
|
|
9
|
+
durationMaxMinutes: number;
|
|
10
|
+
smsPerProviderPerDay: number;
|
|
11
|
+
smsPerPhonePerDay: number;
|
|
12
|
+
payablePerProviderPerDay: number;
|
|
13
|
+
};
|
|
14
|
+
export type CrossedLimits = typeof CROSSED_DEFAULT_LIMITS;
|
|
15
|
+
export declare const CROSSED_SMS_MAX_CHARS = 200;
|
|
16
|
+
type CrossedBase = {
|
|
17
|
+
/** 16–64 characters minted by the app, one per slot; the server derives the order id from it, so a retry cannot create a second order. */
|
|
18
|
+
requestId: string;
|
|
19
|
+
providerId: string;
|
|
20
|
+
/** Start of the slot, epoch ms. */
|
|
21
|
+
orderDate: number;
|
|
22
|
+
servedById?: string;
|
|
23
|
+
locationUrl?: string;
|
|
24
|
+
/** The customer's language when the number is not a customer's yet. */
|
|
25
|
+
language?: 'ar' | 'en';
|
|
26
|
+
durationMinutes?: number;
|
|
27
|
+
};
|
|
28
|
+
/** A slot held for the provider, as today's dummy order; a phone number only triggers the message. */
|
|
29
|
+
export type CrossedSlotRequest = CrossedBase & {
|
|
30
|
+
sendPayLink: false;
|
|
31
|
+
phone?: string;
|
|
32
|
+
};
|
|
33
|
+
/** A normal order the customer pays through a link: either services from the provider's catalogue or one provider price. */
|
|
34
|
+
export type CrossedPayRequest = CrossedBase & {
|
|
35
|
+
sendPayLink: true;
|
|
36
|
+
phone: string;
|
|
37
|
+
coordinates?: LatLng;
|
|
38
|
+
} & ({
|
|
39
|
+
customPrice: number;
|
|
40
|
+
} | {
|
|
41
|
+
carSize: CarSize;
|
|
42
|
+
serviceIds: string[];
|
|
43
|
+
addonIds?: string[];
|
|
44
|
+
});
|
|
45
|
+
export type CreateCrossedOrderRequest = CrossedSlotRequest | CrossedPayRequest;
|
|
46
|
+
export type CrossedSlotResponse = {
|
|
47
|
+
orderId: string;
|
|
48
|
+
smsSent: boolean;
|
|
49
|
+
};
|
|
50
|
+
/** Nothing here says whether the number belongs to a customer. */
|
|
51
|
+
export type CrossedPayResponse = {
|
|
52
|
+
orderId: string;
|
|
53
|
+
orderStatus: OrderStatus;
|
|
54
|
+
paymentLinkUrl: string;
|
|
55
|
+
/** Epoch ms after which the unpaid order is cancelled. */
|
|
56
|
+
payLinkDeadline: number;
|
|
57
|
+
smsSent: boolean;
|
|
58
|
+
};
|
|
59
|
+
export type CrossedOptionsResponse = {
|
|
60
|
+
canChargeCustomTotal: boolean;
|
|
61
|
+
limits: CrossedLimits;
|
|
62
|
+
};
|
|
63
|
+
export declare const isSaudiMobile: (e164: unknown) => e164 is string;
|
|
64
|
+
export declare const isValidRequestId: (value: unknown) => value is string;
|
|
65
|
+
/** A provider price in SAR: within the limits and to the halala. */
|
|
66
|
+
export declare function isValidCustomPrice(price: unknown, limits?: Pick<CrossedLimits, 'customTotalMinSar' | 'customTotalMaxSar'>): price is number;
|
|
67
|
+
/** The first reason a request cannot be accepted, or undefined. The same check runs in the app and the server; `limits` are the server's. */
|
|
68
|
+
export declare function crossedPayloadProblem(body: Record<string, unknown> | null | undefined, nowMs: number, limits?: CrossedLimits): string | undefined;
|
|
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
|
+
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 the app. One wording for the server's SMS. */
|
|
72
|
+
export declare function crossedOrderSms(lang: 'ar' | 'en' | string | undefined, { providerName, payUrl }?: {
|
|
73
|
+
providerName?: string;
|
|
74
|
+
payUrl?: string;
|
|
75
|
+
}): string;
|
|
76
|
+
/** The push for a customer who already has the app; each device shows its own language. */
|
|
77
|
+
export declare function crossedOrderPush(providerName?: string): {
|
|
78
|
+
title: {
|
|
79
|
+
en: string;
|
|
80
|
+
ar: string;
|
|
81
|
+
};
|
|
82
|
+
body: {
|
|
83
|
+
en: string;
|
|
84
|
+
ar: string;
|
|
85
|
+
};
|
|
86
|
+
};
|
|
87
|
+
export declare function crossedCancelledMessage(lang: 'ar' | 'en' | string | undefined, providerName?: string): string;
|
|
88
|
+
export {};
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isValidRequestId = exports.isSaudiMobile = exports.CROSSED_SMS_MAX_CHARS = exports.CROSSED_DEFAULT_LIMITS = void 0;
|
|
4
|
+
exports.isValidCustomPrice = isValidCustomPrice;
|
|
5
|
+
exports.crossedPayloadProblem = crossedPayloadProblem;
|
|
6
|
+
exports.customServiceLine = customServiceLine;
|
|
7
|
+
exports.crossedOrderSms = crossedOrderSms;
|
|
8
|
+
exports.crossedOrderPush = crossedOrderPush;
|
|
9
|
+
exports.crossedCancelledMessage = crossedCancelledMessage;
|
|
10
|
+
const types_1 = require("../constants/types");
|
|
11
|
+
const calcs_1 = require("./calcs");
|
|
12
|
+
const payLink_1 = require("./payLink");
|
|
13
|
+
/** Crossed slots created by a provider or an allowed driver, optionally with a payment link — the contract between the provider app and cloudFun. */
|
|
14
|
+
/** What the server falls back to when `configs/crossed_orders` has no value for a limit. */
|
|
15
|
+
exports.CROSSED_DEFAULT_LIMITS = {
|
|
16
|
+
customTotalMinSar: 5,
|
|
17
|
+
customTotalMaxSar: 2000,
|
|
18
|
+
durationMinMinutes: 15,
|
|
19
|
+
durationMaxMinutes: 180,
|
|
20
|
+
smsPerProviderPerDay: 40,
|
|
21
|
+
smsPerPhonePerDay: 3,
|
|
22
|
+
payablePerProviderPerDay: 40,
|
|
23
|
+
};
|
|
24
|
+
exports.CROSSED_SMS_MAX_CHARS = 200;
|
|
25
|
+
const SMS_NAME_MAX = 24;
|
|
26
|
+
const SITE_URL = 'https://sahabapp.net';
|
|
27
|
+
const DAY_MS = 24 * 60 * 60 * 1000;
|
|
28
|
+
const isSaudiMobile = (e164) => typeof e164 === 'string' && /^\+9665\d{8}$/.test(e164);
|
|
29
|
+
exports.isSaudiMobile = isSaudiMobile;
|
|
30
|
+
const isValidRequestId = (value) => typeof value === 'string' && /^[A-Za-z0-9_-]{16,64}$/.test(value);
|
|
31
|
+
exports.isValidRequestId = isValidRequestId;
|
|
32
|
+
/** A provider price in SAR: within the limits and to the halala. */
|
|
33
|
+
function isValidCustomPrice(price, limits = exports.CROSSED_DEFAULT_LIMITS) {
|
|
34
|
+
if (typeof price !== 'number' || !Number.isFinite(price))
|
|
35
|
+
return false;
|
|
36
|
+
if (price < limits.customTotalMinSar || price > limits.customTotalMaxSar)
|
|
37
|
+
return false;
|
|
38
|
+
return Math.abs(price * 100 - Math.round(price * 100)) < 1e-6;
|
|
39
|
+
}
|
|
40
|
+
const isNonEmptyId = (value) => typeof value === 'string' && value.length > 0 && value.length <= 128 && !value.includes('/');
|
|
41
|
+
const isIdList = (value) => Array.isArray(value) && value.length > 0 && value.every(isNonEmptyId);
|
|
42
|
+
const PAYABLE_ONLY = ['customPrice', 'carSize', 'serviceIds', 'addonIds', 'coordinates'];
|
|
43
|
+
/** The first reason a request cannot be accepted, or undefined. The same check runs in the app and the server; `limits` are the server's. */
|
|
44
|
+
function crossedPayloadProblem(body, nowMs, limits = exports.CROSSED_DEFAULT_LIMITS) {
|
|
45
|
+
if (!body || typeof body !== 'object')
|
|
46
|
+
return 'invalid_request';
|
|
47
|
+
if (!(0, exports.isValidRequestId)(body.requestId))
|
|
48
|
+
return 'invalid_request_id';
|
|
49
|
+
if (!isNonEmptyId(body.providerId))
|
|
50
|
+
return 'invalid_provider';
|
|
51
|
+
if (body.servedById !== undefined && body.servedById !== '' && !isNonEmptyId(body.servedById))
|
|
52
|
+
return 'invalid_served_by';
|
|
53
|
+
if (typeof body.orderDate !== 'number' || !Number.isFinite(body.orderDate))
|
|
54
|
+
return 'invalid_order_date';
|
|
55
|
+
if (body.locationUrl !== undefined && (typeof body.locationUrl !== 'string' || body.locationUrl.length > 500))
|
|
56
|
+
return 'invalid_location_url';
|
|
57
|
+
if (body.language !== undefined && body.language !== 'ar' && body.language !== 'en')
|
|
58
|
+
return 'invalid_language';
|
|
59
|
+
if (body.durationMinutes !== undefined) {
|
|
60
|
+
const minutes = body.durationMinutes;
|
|
61
|
+
if (typeof minutes !== 'number' || !Number.isInteger(minutes) || minutes < limits.durationMinMinutes || minutes > limits.durationMaxMinutes)
|
|
62
|
+
return 'invalid_duration';
|
|
63
|
+
}
|
|
64
|
+
if (body.phone !== undefined && body.phone !== '' && (typeof body.phone !== 'string' || !/^\+\d{8,15}$/.test(body.phone)))
|
|
65
|
+
return 'invalid_phone';
|
|
66
|
+
if (typeof body.sendPayLink !== 'boolean')
|
|
67
|
+
return 'invalid_send_pay_link';
|
|
68
|
+
if (!body.sendPayLink)
|
|
69
|
+
return PAYABLE_ONLY.some((key) => body[key] !== undefined) ? 'payable_fields_on_slot' : undefined;
|
|
70
|
+
if (!(0, exports.isSaudiMobile)(body.phone))
|
|
71
|
+
return 'not_saudi_mobile';
|
|
72
|
+
if (body.orderDate < nowMs + payLink_1.PAY_LINK_WINDOW_MINUTES * 60000)
|
|
73
|
+
return 'slot_too_soon';
|
|
74
|
+
if (body.orderDate > nowMs + 366 * DAY_MS)
|
|
75
|
+
return 'invalid_order_date';
|
|
76
|
+
if (body.coordinates !== undefined && !(0, payLink_1.isValidLatLng)(body.coordinates))
|
|
77
|
+
return 'invalid_coordinates';
|
|
78
|
+
const hasPrice = body.customPrice !== undefined;
|
|
79
|
+
const hasServices = body.carSize !== undefined || body.serviceIds !== undefined || body.addonIds !== undefined;
|
|
80
|
+
if (hasPrice && hasServices)
|
|
81
|
+
return 'price_and_services';
|
|
82
|
+
if (!hasPrice && !hasServices)
|
|
83
|
+
return 'need_price_or_services';
|
|
84
|
+
if (hasPrice)
|
|
85
|
+
return isValidCustomPrice(body.customPrice, limits) ? undefined : 'price_out_of_range';
|
|
86
|
+
if (body.carSize === undefined || !Number.isInteger(body.carSize) || body.carSize < 0)
|
|
87
|
+
return 'invalid_car_size';
|
|
88
|
+
if (!isIdList(body.serviceIds))
|
|
89
|
+
return 'invalid_services';
|
|
90
|
+
if (body.addonIds !== undefined && !(Array.isArray(body.addonIds) && body.addonIds.every(isNonEmptyId)))
|
|
91
|
+
return 'invalid_services';
|
|
92
|
+
return undefined;
|
|
93
|
+
}
|
|
94
|
+
/** 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. */
|
|
95
|
+
function customServiceLine(providerPrice, minutes, size = types_1.CarSize.MEDIUM) {
|
|
96
|
+
return {
|
|
97
|
+
name: { ar: 'خدمة', en: 'Service' },
|
|
98
|
+
price: { size, price: (0, calcs_1.customerPriceFromProviderPrice)(providerPrice) },
|
|
99
|
+
type: 'service',
|
|
100
|
+
time: minutes,
|
|
101
|
+
providerSet: true,
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
const shortName = (name) => {
|
|
105
|
+
const t = (name !== null && name !== void 0 ? name : '').trim().replace(/\s+/g, ' ');
|
|
106
|
+
return t.length > SMS_NAME_MAX ? `${t.slice(0, SMS_NAME_MAX - 1).replace(/\s+$/, '')}…` : t;
|
|
107
|
+
};
|
|
108
|
+
/** The text to the customer: the booking, optionally the link, and where to get the app. One wording for the server's SMS. */
|
|
109
|
+
function crossedOrderSms(lang, { providerName, payUrl } = {}) {
|
|
110
|
+
const name = shortName(providerName);
|
|
111
|
+
if (lang === 'en') {
|
|
112
|
+
const head = name ? `Sahab: ${name} booked a car wash for you.` : 'Sahab: a car wash was booked for you.';
|
|
113
|
+
return payUrl
|
|
114
|
+
? [head, `Pay within ${payLink_1.PAY_LINK_WINDOW_MINUTES} minutes to confirm your booking:`, payUrl, 'Get the app to follow your order:', SITE_URL].join('\n')
|
|
115
|
+
: [head, 'Get the app and sign in with this number to follow your order:', SITE_URL].join('\n');
|
|
116
|
+
}
|
|
117
|
+
const head = name ? `سحاب: ${name} حجز لك موعد غسيل.` : 'سحاب: تم حجز موعد غسيل لك.';
|
|
118
|
+
return payUrl
|
|
119
|
+
? [head, `ادفع خلال ${payLink_1.PAY_LINK_WINDOW_MINUTES} دقيقة عشان يتأكد حجزك:`, payUrl, 'وحمّل التطبيق لمتابعة طلبك:', SITE_URL].join('\n')
|
|
120
|
+
: [head, 'حمّل التطبيق وسجّل بنفس رقمك عشان تتابع طلبك:', SITE_URL].join('\n');
|
|
121
|
+
}
|
|
122
|
+
/** The push for a customer who already has the app; each device shows its own language. */
|
|
123
|
+
function crossedOrderPush(providerName) {
|
|
124
|
+
const name = shortName(providerName);
|
|
125
|
+
return {
|
|
126
|
+
title: { en: 'A car wash was booked for you', ar: 'وصلك حجز غسيل' },
|
|
127
|
+
body: {
|
|
128
|
+
en: name ? `${name} booked a wash for you. Follow it in the app.` : 'A wash was booked for you. Follow it in the app.',
|
|
129
|
+
ar: name ? `${name} حجز لك موعد غسيل. تابعه من التطبيق.` : 'تم حجز موعد غسيل لك. تابعه من التطبيق.',
|
|
130
|
+
},
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
function crossedCancelledMessage(lang, providerName) {
|
|
134
|
+
const name = shortName(providerName);
|
|
135
|
+
if (lang === 'en')
|
|
136
|
+
return name ? `Sahab: ${name} cancelled your booking. You will not be charged.` : 'Sahab: your booking was cancelled. You will not be charged.';
|
|
137
|
+
return name ? `سحاب: ${name} ألغى حجزك. ما راح يتسحب منك أي مبلغ.` : 'سحاب: تم إلغاء حجزك. ما راح يتسحب منك أي مبلغ.';
|
|
138
|
+
}
|
package/dist/ts/payLink.d.ts
CHANGED
|
@@ -2,6 +2,8 @@ import { CarSize, Order, OrderStatus, Provider, ProvidedAddon, ProvidedService }
|
|
|
2
2
|
/** Back-office orders paid by a link — the shared contract between sahab-website and cloudFun. */
|
|
3
3
|
export declare const PAY_LINK_WINDOW_MINUTES = 15;
|
|
4
4
|
export declare const PAY_LINK_CANCEL_REASON = "payment not completed";
|
|
5
|
+
/** Why a provider withdrew a waiting order; like `PAY_LINK_CANCEL_REASON` it means no money was ever taken. */
|
|
6
|
+
export declare const PROVIDER_CANCEL_REASON = "cancelled by provider";
|
|
5
7
|
/** Fields a pay-link order carries. Generic over the timestamp because cloudFun stores firebase-admin Timestamps and the
|
|
6
8
|
* apps/website read firebase web ones. Server-only bookkeeping (task name, run token) stays in cloudFun. */
|
|
7
9
|
export type PayLinkOrderFields<TTimestamp> = {
|
|
@@ -67,5 +69,5 @@ export type PayLinkLinesResult = {
|
|
|
67
69
|
/** Order lines priced exactly as the customer app's setProvidedService/setProvidedAddon build them: the
|
|
68
70
|
* provider's price for this car size plus the client percentage. Hidden items and packages are refused. */
|
|
69
71
|
export declare function buildPayLinkOrderLines(provider: Pick<Provider, 'services' | 'addons'>, carSize: CarSize, serviceIds: string[], addonIds?: string[]): PayLinkLinesResult;
|
|
70
|
-
/** A pay-link order that never took money — still waiting, or cancelled for non-payment. Statements and KPIs leave these out. */
|
|
72
|
+
/** A pay-link order that never took money — still waiting, or cancelled for non-payment or by the provider. Statements and KPIs leave these out. */
|
|
71
73
|
export declare const isNeverPaidPayLinkOrder: (order?: Pick<Order, "orderStatus" | "cancelReason" | "isPaid">) => boolean;
|
package/dist/ts/payLink.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isNeverPaidPayLinkOrder = exports.isPayLinkAmountExact = exports.toMinorUnits = exports.payLinkDeadlineMs = exports.isValidLatLng = exports.payLinkCancelledMessage = exports.payLinkMessage = exports.PAY_LINK_CANCEL_REASON = exports.PAY_LINK_WINDOW_MINUTES = void 0;
|
|
3
|
+
exports.isNeverPaidPayLinkOrder = exports.isPayLinkAmountExact = exports.toMinorUnits = exports.payLinkDeadlineMs = exports.isValidLatLng = exports.payLinkCancelledMessage = exports.payLinkMessage = exports.PROVIDER_CANCEL_REASON = exports.PAY_LINK_CANCEL_REASON = exports.PAY_LINK_WINDOW_MINUTES = void 0;
|
|
4
4
|
exports.whatsAppShareUrl = whatsAppShareUrl;
|
|
5
5
|
exports.parseLatLng = parseLatLng;
|
|
6
6
|
exports.buildPayLinkOrderLines = buildPayLinkOrderLines;
|
|
@@ -9,6 +9,8 @@ const offerings_1 = require("./offerings");
|
|
|
9
9
|
/** Back-office orders paid by a link — the shared contract between sahab-website and cloudFun. */
|
|
10
10
|
exports.PAY_LINK_WINDOW_MINUTES = 15;
|
|
11
11
|
exports.PAY_LINK_CANCEL_REASON = 'payment not completed';
|
|
12
|
+
/** Why a provider withdrew a waiting order; like `PAY_LINK_CANCEL_REASON` it means no money was ever taken. */
|
|
13
|
+
exports.PROVIDER_CANCEL_REASON = 'cancelled by provider';
|
|
12
14
|
/** The message carrying the link — one wording for the server's SMS and the back office's copy/WhatsApp share. */
|
|
13
15
|
const payLinkMessage = (lang, url) => lang === 'en'
|
|
14
16
|
? `Sahab: pay within ${exports.PAY_LINK_WINDOW_MINUTES} minutes to confirm your car wash booking\n${url}`
|
|
@@ -51,7 +53,7 @@ exports.isPayLinkAmountExact = isPayLinkAmountExact;
|
|
|
51
53
|
/** Order lines priced exactly as the customer app's setProvidedService/setProvidedAddon build them: the
|
|
52
54
|
* provider's price for this car size plus the client percentage. Hidden items and packages are refused. */
|
|
53
55
|
function buildPayLinkOrderLines(provider, carSize, serviceIds, addonIds = []) {
|
|
54
|
-
var _a, _b, _c, _d
|
|
56
|
+
var _a, _b, _c, _d;
|
|
55
57
|
if (!serviceIds.length)
|
|
56
58
|
return { ok: false, reason: 'NO_SERVICE' };
|
|
57
59
|
const lines = [];
|
|
@@ -59,25 +61,25 @@ function buildPayLinkOrderLines(provider, carSize, serviceIds, addonIds = []) {
|
|
|
59
61
|
const service = (_a = provider.services) === null || _a === void 0 ? void 0 : _a.find((s) => s.serviceId === id && !s.hide);
|
|
60
62
|
if (!service)
|
|
61
63
|
return { ok: false, reason: 'UNKNOWN_ITEM' };
|
|
62
|
-
if ((
|
|
64
|
+
if ((0, offerings_1.serviceVisitCount)(service) > 1)
|
|
63
65
|
return { ok: false, reason: 'PACKAGE_NOT_SUPPORTED' };
|
|
64
66
|
const line = (0, offerings_1.setProvidedService)(service, { size: carSize });
|
|
65
|
-
if (!((
|
|
67
|
+
if (!((_b = line.price) === null || _b === void 0 ? void 0 : _b.price))
|
|
66
68
|
return { ok: false, reason: 'NO_PRICE_FOR_SIZE' };
|
|
67
69
|
lines.push((0, offerings_1.withoutUndefined)(line));
|
|
68
70
|
}
|
|
69
71
|
for (const id of addonIds) {
|
|
70
|
-
const addon = (
|
|
72
|
+
const addon = (_c = provider.addons) === null || _c === void 0 ? void 0 : _c.find((a) => a.addonId === id && !a.hide);
|
|
71
73
|
if (!addon)
|
|
72
74
|
return { ok: false, reason: 'UNKNOWN_ITEM' };
|
|
73
75
|
const line = (0, offerings_1.setProvidedAddon)(addon, { size: carSize });
|
|
74
|
-
if (!((
|
|
76
|
+
if (!((_d = line.price) === null || _d === void 0 ? void 0 : _d.price))
|
|
75
77
|
return { ok: false, reason: 'NO_PRICE_FOR_SIZE' };
|
|
76
78
|
lines.push((0, offerings_1.withoutUndefined)(line));
|
|
77
79
|
}
|
|
78
80
|
return { ok: true, lines };
|
|
79
81
|
}
|
|
80
|
-
/** A pay-link order that never took money — still waiting, or cancelled for non-payment. Statements and KPIs leave these out. */
|
|
82
|
+
/** A pay-link order that never took money — still waiting, or cancelled for non-payment or by the provider. Statements and KPIs leave these out. */
|
|
81
83
|
const isNeverPaidPayLinkOrder = (order) => (order === null || order === void 0 ? void 0 : order.orderStatus) === types_1.OrderStatus.PENDING_PAYMENT ||
|
|
82
|
-
((order === null || order === void 0 ? void 0 : order.orderStatus) === types_1.OrderStatus.CANCELLED && order.cancelReason === exports.PAY_LINK_CANCEL_REASON && !order.isPaid);
|
|
84
|
+
((order === null || order === void 0 ? void 0 : order.orderStatus) === types_1.OrderStatus.CANCELLED && (order.cancelReason === exports.PAY_LINK_CANCEL_REASON || order.cancelReason === exports.PROVIDER_CANCEL_REASON) && !order.isPaid);
|
|
83
85
|
exports.isNeverPaidPayLinkOrder = isNeverPaidPayLinkOrder;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "sahab-utils",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.3",
|
|
4
4
|
"description": "This package contains types and utils functions",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
"build": "tsc",
|
|
9
9
|
"prepublishOnly": "npm run build",
|
|
10
10
|
"deploy": "npm run build && npm publish",
|
|
11
|
-
"test": "npm run build && node tests/loyalty.test.js && node tests/gifts.test.js && node tests/cashback.test.js && node tests/utils.test.js && node tests/wheel.test.js && node tests/calcs.test.js && node tests/orderActivity.test.js && node tests/push.test.js && node tests/broadcast.test.js && node tests/iban.test.js && node tests/cash.test.js && node tests/workingHours.test.js && node tests/payLink.test.js && node tests/offerings.test.js && node tests/capacity.test.js && node tests/tap.test.js && node tests/orderAdjustment.test.js && node tests/adminNotifications.test.js && node tests/staffAccess.test.js && node tests/carCatalogue.test.js"
|
|
11
|
+
"test": "npm run build && node tests/loyalty.test.js && node tests/gifts.test.js && node tests/cashback.test.js && node tests/utils.test.js && node tests/wheel.test.js && node tests/calcs.test.js && node tests/orderActivity.test.js && node tests/push.test.js && node tests/broadcast.test.js && node tests/iban.test.js && node tests/cash.test.js && node tests/workingHours.test.js && node tests/payLink.test.js && node tests/offerings.test.js && node tests/capacity.test.js && node tests/tap.test.js && node tests/orderAdjustment.test.js && node tests/adminNotifications.test.js && node tests/staffAccess.test.js && node tests/carCatalogue.test.js && node tests/crossedOrder.test.js"
|
|
12
12
|
},
|
|
13
13
|
"repository": {
|
|
14
14
|
"type": "git",
|