sahab-utils 1.9.1 → 1.9.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 +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/dist/ts/capacity.d.ts +12 -0
- package/dist/ts/capacity.js +23 -0
- package/dist/ts/cash.d.ts +3 -0
- package/dist/ts/cash.js +11 -0
- package/dist/ts/tap.d.ts +6 -0
- package/dist/ts/tap.js +36 -0
- package/package.json +2 -2
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { DocumentReference, GeoPoint, Timestamp } from 'firebase/firestore';
|
|
2
2
|
import type { PushTransport } from '../ts/push';
|
|
3
|
+
import type { TapLicenseType } from '../ts/tap';
|
|
3
4
|
export type GeoPointType = GeoPoint;
|
|
4
5
|
export type TimestampType = Timestamp;
|
|
5
6
|
export type DistenceDueration = {
|
|
@@ -493,7 +494,6 @@ export declare const INTEGRATION_KEYS: {
|
|
|
493
494
|
export type IntegrationKey = (typeof INTEGRATION_KEYS)[keyof typeof INTEGRATION_KEYS];
|
|
494
495
|
export type TapKycStatus = 'draft' | 'documents_uploaded' | 'lead_created' | 'account_created' | 'payout_enabled' | 'rejected';
|
|
495
496
|
export type TapDocumentPurpose = 'commercial_registration' | 'national_id' | 'bank_statement' | 'iban_certificate';
|
|
496
|
-
export type TapLicenseType = 'LLC' | 'SOLE_PROPRIETORSHIP' | 'JOINT_STOCK' | 'PARTNERSHIP' | 'OTHER';
|
|
497
497
|
export type TapApplicationFile = {
|
|
498
498
|
purpose: TapDocumentPurpose;
|
|
499
499
|
fileId: string;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export * from './constants/types';
|
|
2
2
|
export * from './ts/broadcast';
|
|
3
|
+
export * from './ts/capacity';
|
|
3
4
|
export * from './ts/calcs';
|
|
4
5
|
export * from './ts/cash';
|
|
5
6
|
export * from './ts/cashback';
|
|
@@ -9,6 +10,7 @@ export * from './ts/loyalty';
|
|
|
9
10
|
export * from './ts/offerings';
|
|
10
11
|
export * from './ts/orderActivity';
|
|
11
12
|
export * from './ts/payLink';
|
|
13
|
+
export * from './ts/tap';
|
|
12
14
|
export * from './ts/push';
|
|
13
15
|
export * from './ts/utils';
|
|
14
16
|
export * from './ts/wheel';
|
package/dist/index.js
CHANGED
|
@@ -16,6 +16,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./constants/types"), exports);
|
|
18
18
|
__exportStar(require("./ts/broadcast"), exports);
|
|
19
|
+
__exportStar(require("./ts/capacity"), exports);
|
|
19
20
|
__exportStar(require("./ts/calcs"), exports);
|
|
20
21
|
__exportStar(require("./ts/cash"), exports);
|
|
21
22
|
__exportStar(require("./ts/cashback"), exports);
|
|
@@ -25,6 +26,7 @@ __exportStar(require("./ts/loyalty"), exports);
|
|
|
25
26
|
__exportStar(require("./ts/offerings"), exports);
|
|
26
27
|
__exportStar(require("./ts/orderActivity"), exports);
|
|
27
28
|
__exportStar(require("./ts/payLink"), exports);
|
|
29
|
+
__exportStar(require("./ts/tap"), exports);
|
|
28
30
|
__exportStar(require("./ts/push"), exports);
|
|
29
31
|
__exportStar(require("./ts/utils"), exports);
|
|
30
32
|
__exportStar(require("./ts/wheel"), exports);
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Provider } from '../constants/types';
|
|
2
|
+
/** Whether a carwash takes orders itself: on unless the owner switched it off, so a record with no flag counts as on. */
|
|
3
|
+
export declare const providerReceivesOrders: (provider?: Pick<Provider, "receiveOrders"> | null) => boolean;
|
|
4
|
+
/** How many orders a slot can hold: the explicit drivers on the booking, else the drivers near the customer, else every
|
|
5
|
+
* active driver, plus the owner when they take orders themselves. The server lists slots and validates bookings with this, and
|
|
6
|
+
* the provider app shows it, so they cannot disagree. */
|
|
7
|
+
export declare function computeAllowedOrdersPerSlot(params: {
|
|
8
|
+
providerReceiveOrders?: boolean;
|
|
9
|
+
totalActiveDrivers: number;
|
|
10
|
+
driverIdsFromClient?: string[];
|
|
11
|
+
nearbyDriverCount?: number;
|
|
12
|
+
}): number;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.providerReceivesOrders = void 0;
|
|
4
|
+
exports.computeAllowedOrdersPerSlot = computeAllowedOrdersPerSlot;
|
|
5
|
+
/** Whether a carwash takes orders itself: on unless the owner switched it off, so a record with no flag counts as on. */
|
|
6
|
+
const providerReceivesOrders = (provider) => (provider === null || provider === void 0 ? void 0 : provider.receiveOrders) !== false;
|
|
7
|
+
exports.providerReceivesOrders = providerReceivesOrders;
|
|
8
|
+
/** How many orders a slot can hold: the explicit drivers on the booking, else the drivers near the customer, else every
|
|
9
|
+
* active driver, plus the owner when they take orders themselves. The server lists slots and validates bookings with this, and
|
|
10
|
+
* the provider app shows it, so they cannot disagree. */
|
|
11
|
+
function computeAllowedOrdersPerSlot(params) {
|
|
12
|
+
const { providerReceiveOrders, totalActiveDrivers, driverIdsFromClient, nearbyDriverCount } = params;
|
|
13
|
+
if (driverIdsFromClient && driverIdsFromClient.length > 0) {
|
|
14
|
+
return providerReceiveOrders ? driverIdsFromClient.length + 1 : driverIdsFromClient.length;
|
|
15
|
+
}
|
|
16
|
+
if (nearbyDriverCount != null && nearbyDriverCount > 0) {
|
|
17
|
+
return providerReceiveOrders ? nearbyDriverCount + 1 : nearbyDriverCount;
|
|
18
|
+
}
|
|
19
|
+
if (providerReceiveOrders) {
|
|
20
|
+
return totalActiveDrivers + 1;
|
|
21
|
+
}
|
|
22
|
+
return totalActiveDrivers === 0 ? 1 : totalActiveDrivers;
|
|
23
|
+
}
|
package/dist/ts/cash.d.ts
CHANGED
|
@@ -11,3 +11,6 @@ export declare const isFreeOrder: (order?: Partial<Order>) => boolean;
|
|
|
11
11
|
export declare function resolveCashFee(configs?: Pick<PaymentConfigs, 'cashFee'> | null): number;
|
|
12
12
|
/** The fee this order would carry if paid in cash: none when there is nothing to collect. */
|
|
13
13
|
export declare function cashFeeForOrder(order: Partial<Order> | undefined, configs?: Pick<PaymentConfigs, 'cashFee'> | null): number;
|
|
14
|
+
/** What the washer takes from the customer for a cash order, and what the server records as collected when the order is finished:
|
|
15
|
+
* nothing for a free order, else the order's total to pay. Undefined for an online order, which was paid up front. */
|
|
16
|
+
export declare function cashAmountToCollect(order?: Partial<Order>): number | undefined;
|
package/dist/ts/cash.js
CHANGED
|
@@ -3,8 +3,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.isFreeOrder = exports.getOrderTotalWithoutCashFee = exports.MAX_CASH_FEE = void 0;
|
|
4
4
|
exports.resolveCashFee = resolveCashFee;
|
|
5
5
|
exports.cashFeeForOrder = cashFeeForOrder;
|
|
6
|
+
exports.cashAmountToCollect = cashAmountToCollect;
|
|
6
7
|
const types_1 = require("../constants/types");
|
|
7
8
|
const calcs_1 = require("./calcs");
|
|
9
|
+
const utils_1 = require("./utils");
|
|
8
10
|
/** Cash payment — the shared rules. The fee is set from `payment_methods/configs`; the app only shows it
|
|
9
11
|
* and cloudFun is what charges it, so both must reach the same number from the same config. */
|
|
10
12
|
/** A fee above this is read as a typo (5000 for 5.00) and ignored rather than charged to customers. */
|
|
@@ -26,3 +28,12 @@ function resolveCashFee(configs) {
|
|
|
26
28
|
function cashFeeForOrder(order, configs) {
|
|
27
29
|
return (0, exports.isFreeOrder)(order) ? 0 : resolveCashFee(configs);
|
|
28
30
|
}
|
|
31
|
+
/** What the washer takes from the customer for a cash order, and what the server records as collected when the order is finished:
|
|
32
|
+
* nothing for a free order, else the order's total to pay. Undefined for an online order, which was paid up front. */
|
|
33
|
+
function cashAmountToCollect(order) {
|
|
34
|
+
if ((order === null || order === void 0 ? void 0 : order.paymentType) !== types_1.OrderPaymentType.CASH)
|
|
35
|
+
return undefined;
|
|
36
|
+
if ((0, exports.isFreeOrder)(order))
|
|
37
|
+
return 0;
|
|
38
|
+
return Math.max(0, (0, utils_1.preventNaN)((0, calcs_1.getCustomerTotalToPay)(order)));
|
|
39
|
+
}
|
package/dist/ts/tap.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/** The only `entity.license.type` values Tap's Create Lead API accepts, spelled exactly as Tap lists them. */
|
|
2
|
+
export declare const TAP_LICENSE_TYPES: readonly ["Establishment", "Trust", "Partnership", "LLC", "JSC", "Foreign JSC Branch", "Mix LLC", "Foreign LLC", "GCC Partnership", "GCC LLC", "GCC JSC", "Foreign LLC Branch", "Profession LLC", "Freelancer"];
|
|
3
|
+
export type TapLicenseType = (typeof TAP_LICENSE_TYPES)[number];
|
|
4
|
+
export declare const isTapLicenseType: (value: unknown) => value is TapLicenseType;
|
|
5
|
+
/** A stored or submitted license type as one Tap accepts, or undefined when it maps to none. */
|
|
6
|
+
export declare function normalizeTapLicenseType(value: unknown): TapLicenseType | undefined;
|
package/dist/ts/tap.js
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isTapLicenseType = exports.TAP_LICENSE_TYPES = void 0;
|
|
4
|
+
exports.normalizeTapLicenseType = normalizeTapLicenseType;
|
|
5
|
+
/** The only `entity.license.type` values Tap's Create Lead API accepts, spelled exactly as Tap lists them. */
|
|
6
|
+
exports.TAP_LICENSE_TYPES = [
|
|
7
|
+
'Establishment',
|
|
8
|
+
'Trust',
|
|
9
|
+
'Partnership',
|
|
10
|
+
'LLC',
|
|
11
|
+
'JSC',
|
|
12
|
+
'Foreign JSC Branch',
|
|
13
|
+
'Mix LLC',
|
|
14
|
+
'Foreign LLC',
|
|
15
|
+
'GCC Partnership',
|
|
16
|
+
'GCC LLC',
|
|
17
|
+
'GCC JSC',
|
|
18
|
+
'Foreign LLC Branch',
|
|
19
|
+
'Profession LLC',
|
|
20
|
+
'Freelancer',
|
|
21
|
+
];
|
|
22
|
+
const isTapLicenseType = (value) => exports.TAP_LICENSE_TYPES.includes(value);
|
|
23
|
+
exports.isTapLicenseType = isTapLicenseType;
|
|
24
|
+
// Applications saved before the list was corrected hold the dashboard's old names. There is no Tap value for
|
|
25
|
+
// "other", so that one stays unresolved and the form must ask again.
|
|
26
|
+
const LEGACY_LICENSE_TYPES = {
|
|
27
|
+
SOLE_PROPRIETORSHIP: 'Establishment',
|
|
28
|
+
JOINT_STOCK: 'JSC',
|
|
29
|
+
PARTNERSHIP: 'Partnership',
|
|
30
|
+
};
|
|
31
|
+
/** A stored or submitted license type as one Tap accepts, or undefined when it maps to none. */
|
|
32
|
+
function normalizeTapLicenseType(value) {
|
|
33
|
+
if ((0, exports.isTapLicenseType)(value))
|
|
34
|
+
return value;
|
|
35
|
+
return typeof value === 'string' ? LEGACY_LICENSE_TYPES[value] : undefined;
|
|
36
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "sahab-utils",
|
|
3
|
-
"version": "1.9.
|
|
3
|
+
"version": "1.9.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"
|
|
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"
|
|
12
12
|
},
|
|
13
13
|
"repository": {
|
|
14
14
|
"type": "git",
|