@escapenavigator/utils 2.0.42 → 2.0.45
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/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/dist/is-valid-pt-nif.d.ts +5 -0
- package/dist/is-valid-pt-nif.js +18 -0
- package/dist/is-valid-pt-nif.spec.d.ts +1 -0
- package/dist/is-valid-pt-nif.spec.js +21 -0
- package/dist/role-bonus-permissions.d.ts +7 -0
- package/dist/role-bonus-permissions.js +9 -0
- package/dist/role-bonus-permissions.spec.d.ts +1 -0
- package/dist/role-bonus-permissions.spec.js +16 -0
- package/package.json +3 -3
package/dist/index.d.ts
CHANGED
|
@@ -22,12 +22,14 @@ export * from './image-url';
|
|
|
22
22
|
export * from './is-axios-error';
|
|
23
23
|
export * from './is-network-error';
|
|
24
24
|
export * from './is-stale-chunk-error';
|
|
25
|
+
export * from './is-valid-pt-nif';
|
|
25
26
|
export * from './phone';
|
|
26
27
|
export * from './pick';
|
|
27
28
|
export * from './promocode-error-codes';
|
|
28
29
|
export * from './promocode-nominal-rules';
|
|
29
30
|
export * from './redirect';
|
|
30
31
|
export * from './resolve-calendar-location-id';
|
|
32
|
+
export * from './role-bonus-permissions';
|
|
31
33
|
export * from './role-chat-permissions';
|
|
32
34
|
export * from './role-comment-permissions';
|
|
33
35
|
export * from './role-export-permissions';
|
package/dist/index.js
CHANGED
|
@@ -38,12 +38,14 @@ __exportStar(require("./image-url"), exports);
|
|
|
38
38
|
__exportStar(require("./is-axios-error"), exports);
|
|
39
39
|
__exportStar(require("./is-network-error"), exports);
|
|
40
40
|
__exportStar(require("./is-stale-chunk-error"), exports);
|
|
41
|
+
__exportStar(require("./is-valid-pt-nif"), exports);
|
|
41
42
|
__exportStar(require("./phone"), exports);
|
|
42
43
|
__exportStar(require("./pick"), exports);
|
|
43
44
|
__exportStar(require("./promocode-error-codes"), exports);
|
|
44
45
|
__exportStar(require("./promocode-nominal-rules"), exports);
|
|
45
46
|
__exportStar(require("./redirect"), exports);
|
|
46
47
|
__exportStar(require("./resolve-calendar-location-id"), exports);
|
|
48
|
+
__exportStar(require("./role-bonus-permissions"), exports);
|
|
47
49
|
__exportStar(require("./role-chat-permissions"), exports);
|
|
48
50
|
__exportStar(require("./role-comment-permissions"), exports);
|
|
49
51
|
__exportStar(require("./role-export-permissions"), exports);
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isValidPtNif = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Portuguese NIF checksum (9 digits).
|
|
6
|
+
* Used for company bookings that must appear on a fatura.
|
|
7
|
+
*/
|
|
8
|
+
const isValidPtNif = (value) => {
|
|
9
|
+
const nif = (value || '').replace(/\s+/g, '');
|
|
10
|
+
if (!/^\d{9}$/.test(nif))
|
|
11
|
+
return false;
|
|
12
|
+
const digits = nif.split('').map(Number);
|
|
13
|
+
const sum = digits.slice(0, 8).reduce((acc, digit, index) => acc + digit * (9 - index), 0);
|
|
14
|
+
const check = 11 - (sum % 11);
|
|
15
|
+
const expected = check >= 10 ? 0 : check;
|
|
16
|
+
return digits[8] === expected;
|
|
17
|
+
};
|
|
18
|
+
exports.isValidPtNif = isValidPtNif;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const is_valid_pt_nif_1 = require("./is-valid-pt-nif");
|
|
4
|
+
describe('isValidPtNif', () => {
|
|
5
|
+
it('принимает валидный NIF и контрольную сумму Consumidor final', () => {
|
|
6
|
+
expect((0, is_valid_pt_nif_1.isValidPtNif)('123456789')).toBe(true);
|
|
7
|
+
expect((0, is_valid_pt_nif_1.isValidPtNif)('999999990')).toBe(true);
|
|
8
|
+
});
|
|
9
|
+
it('игнорирует пробелы', () => {
|
|
10
|
+
expect((0, is_valid_pt_nif_1.isValidPtNif)('123 456 789')).toBe(true);
|
|
11
|
+
});
|
|
12
|
+
it('отклоняет неверную контрольную сумму и мусор', () => {
|
|
13
|
+
expect((0, is_valid_pt_nif_1.isValidPtNif)('123456780')).toBe(false);
|
|
14
|
+
expect((0, is_valid_pt_nif_1.isValidPtNif)('12345678')).toBe(false);
|
|
15
|
+
expect((0, is_valid_pt_nif_1.isValidPtNif)('1234567890')).toBe(false);
|
|
16
|
+
expect((0, is_valid_pt_nif_1.isValidPtNif)('abcdefghi')).toBe(false);
|
|
17
|
+
expect((0, is_valid_pt_nif_1.isValidPtNif)('')).toBe(false);
|
|
18
|
+
expect((0, is_valid_pt_nif_1.isValidPtNif)(null)).toBe(false);
|
|
19
|
+
expect((0, is_valid_pt_nif_1.isValidPtNif)(undefined)).toBe(false);
|
|
20
|
+
});
|
|
21
|
+
});
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { RoleRO } from '@escapenavigator/types/dist/role/role.ro';
|
|
2
|
+
export type RoleBonusPermissions = Pick<RoleRO, 'totalAccess' | 'canAwardBonuses'>;
|
|
3
|
+
/**
|
|
4
|
+
* Право вручную начислять или списывать бонусы клиента.
|
|
5
|
+
* Владелец (`totalAccess`) — как будто флаг включён.
|
|
6
|
+
*/
|
|
7
|
+
export declare const canAwardBonuses: (role?: RoleBonusPermissions | null) => boolean;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.canAwardBonuses = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Право вручную начислять или списывать бонусы клиента.
|
|
6
|
+
* Владелец (`totalAccess`) — как будто флаг включён.
|
|
7
|
+
*/
|
|
8
|
+
const canAwardBonuses = (role) => !!role?.totalAccess || !!role?.canAwardBonuses;
|
|
9
|
+
exports.canAwardBonuses = canAwardBonuses;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const role_bonus_permissions_1 = require("./role-bonus-permissions");
|
|
4
|
+
describe('canAwardBonuses', () => {
|
|
5
|
+
it('is false without role or flag', () => {
|
|
6
|
+
expect((0, role_bonus_permissions_1.canAwardBonuses)()).toBe(false);
|
|
7
|
+
expect((0, role_bonus_permissions_1.canAwardBonuses)(null)).toBe(false);
|
|
8
|
+
expect((0, role_bonus_permissions_1.canAwardBonuses)({ totalAccess: false, canAwardBonuses: false })).toBe(false);
|
|
9
|
+
});
|
|
10
|
+
it('is true when flag is on', () => {
|
|
11
|
+
expect((0, role_bonus_permissions_1.canAwardBonuses)({ totalAccess: false, canAwardBonuses: true })).toBe(true);
|
|
12
|
+
});
|
|
13
|
+
it('is true for totalAccess even when flag is off', () => {
|
|
14
|
+
expect((0, role_bonus_permissions_1.canAwardBonuses)({ totalAccess: true, canAwardBonuses: false })).toBe(true);
|
|
15
|
+
});
|
|
16
|
+
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@escapenavigator/utils",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.45",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
"test": "jest"
|
|
15
15
|
},
|
|
16
16
|
"dependencies": {
|
|
17
|
-
"@escapenavigator/types": "^2.0.
|
|
17
|
+
"@escapenavigator/types": "^2.0.43",
|
|
18
18
|
"axios": "^0.21.4",
|
|
19
19
|
"class-transformer": "^0.5.1",
|
|
20
20
|
"class-validator": "^0.13.2",
|
|
@@ -29,5 +29,5 @@
|
|
|
29
29
|
"ts-jest": "^29.1.1",
|
|
30
30
|
"typescript": "^5.6"
|
|
31
31
|
},
|
|
32
|
-
"gitHead": "
|
|
32
|
+
"gitHead": "b5ab364dee021328bca9464dc4f9bd56774bcb52"
|
|
33
33
|
}
|