sahab-utils 1.8.9 → 1.8.10
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/payLink.d.ts +12 -2
- package/dist/ts/payLink.js +20 -1
- package/package.json +1 -1
package/dist/ts/payLink.d.ts
CHANGED
|
@@ -14,8 +14,10 @@ export type PayLinkOrderFields<TTimestamp> = {
|
|
|
14
14
|
export type CreatePayLinkOrderRequest = {
|
|
15
15
|
clientUid: string;
|
|
16
16
|
carId: string;
|
|
17
|
-
/** Index into the client's saved `locations
|
|
18
|
-
locationIndex
|
|
17
|
+
/** Index into the client's saved `locations` — send this or `coordinates`, not both. */
|
|
18
|
+
locationIndex?: number;
|
|
19
|
+
/** A spot typed in by staff, for a customer with no saved location that fits. */
|
|
20
|
+
coordinates?: LatLng;
|
|
19
21
|
providerId: string;
|
|
20
22
|
serviceIds: string[];
|
|
21
23
|
addonIds?: string[];
|
|
@@ -42,6 +44,14 @@ export declare const payLinkMessage: (lang: string | undefined, url: string) =>
|
|
|
42
44
|
export declare const payLinkCancelledMessage: (lang: string | undefined) => string;
|
|
43
45
|
/** wa.me wants the international number as digits only; local 05… numbers are Saudi. */
|
|
44
46
|
export declare function whatsAppShareUrl(phone: string | undefined, text: string): string;
|
|
47
|
+
export type LatLng = {
|
|
48
|
+
lat: number;
|
|
49
|
+
lng: number;
|
|
50
|
+
};
|
|
51
|
+
export declare const isValidLatLng: (p?: Partial<LatLng> | null) => p is LatLng;
|
|
52
|
+
/** "24.7136, 46.6753" (comma, space or both; a pasted Google Maps pair) → coordinates, or undefined when it does not
|
|
53
|
+
* read as one valid point. 0,0 is refused: it is what an empty or failed lookup produces, never a real wash. */
|
|
54
|
+
export declare function parseLatLng(text: string | undefined): LatLng | undefined;
|
|
45
55
|
export declare const payLinkDeadlineMs: (createdMs: number) => number;
|
|
46
56
|
/** Checkout amounts are integer minor units; rounding here keeps the link and the webhook check in agreement. */
|
|
47
57
|
export declare const toMinorUnits: (sar: number) => number;
|
package/dist/ts/payLink.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isNeverPaidPayLinkOrder = exports.isPayLinkAmountExact = exports.toMinorUnits = exports.payLinkDeadlineMs = 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.PAY_LINK_CANCEL_REASON = exports.PAY_LINK_WINDOW_MINUTES = void 0;
|
|
4
4
|
exports.whatsAppShareUrl = whatsAppShareUrl;
|
|
5
|
+
exports.parseLatLng = parseLatLng;
|
|
5
6
|
exports.buildPayLinkOrderLines = buildPayLinkOrderLines;
|
|
6
7
|
const types_1 = require("../constants/types");
|
|
7
8
|
const calcs_1 = require("./calcs");
|
|
@@ -21,6 +22,24 @@ function whatsAppShareUrl(phone, text) {
|
|
|
21
22
|
const international = digits.startsWith('0') ? `966${digits.slice(1)}` : digits;
|
|
22
23
|
return `https://wa.me/${international}?text=${encodeURIComponent(text)}`;
|
|
23
24
|
}
|
|
25
|
+
const isValidLatLng = (p) => !!p &&
|
|
26
|
+
typeof p.lat === 'number' &&
|
|
27
|
+
typeof p.lng === 'number' &&
|
|
28
|
+
Number.isFinite(p.lat) &&
|
|
29
|
+
Number.isFinite(p.lng) &&
|
|
30
|
+
Math.abs(p.lat) <= 90 &&
|
|
31
|
+
Math.abs(p.lng) <= 180 &&
|
|
32
|
+
!(p.lat === 0 && p.lng === 0);
|
|
33
|
+
exports.isValidLatLng = isValidLatLng;
|
|
34
|
+
/** "24.7136, 46.6753" (comma, space or both; a pasted Google Maps pair) → coordinates, or undefined when it does not
|
|
35
|
+
* read as one valid point. 0,0 is refused: it is what an empty or failed lookup produces, never a real wash. */
|
|
36
|
+
function parseLatLng(text) {
|
|
37
|
+
const parts = (text !== null && text !== void 0 ? text : '').trim().replace(/[()]/g, '').split(/[\s,]+/).filter(Boolean);
|
|
38
|
+
if (parts.length !== 2 || !parts.every((x) => /^[-+]?\d+(\.\d+)?$/.test(x)))
|
|
39
|
+
return undefined;
|
|
40
|
+
const point = { lat: Number(parts[0]), lng: Number(parts[1]) };
|
|
41
|
+
return (0, exports.isValidLatLng)(point) ? point : undefined;
|
|
42
|
+
}
|
|
24
43
|
const payLinkDeadlineMs = (createdMs) => createdMs + exports.PAY_LINK_WINDOW_MINUTES * 60000;
|
|
25
44
|
exports.payLinkDeadlineMs = payLinkDeadlineMs;
|
|
26
45
|
/** Checkout amounts are integer minor units; rounding here keeps the link and the webhook check in agreement. */
|