@escapenavigator/utils 2.1.20 → 2.1.22

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.
@@ -1,2 +1,3 @@
1
1
  import { ProfileCurrencyEnum } from '@escapenavigator/types/dist/profile/enum/profile-currency';
2
+ export declare const roundDisplayAmount: (amount: number) => number;
2
3
  export declare const formatAmount: (amount: number, currency: ProfileCurrencyEnum | string) => string;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.formatAmount = void 0;
3
+ exports.formatAmount = exports.roundDisplayAmount = void 0;
4
4
  const profile_currency_1 = require("@escapenavigator/types/dist/profile/enum/profile-currency");
5
5
  const getCurrency = (currency) => {
6
6
  const res = {
@@ -57,6 +57,18 @@ const currencyFirst = (currency) => currency === 'USD' ||
57
57
  currency === 'GEL' ||
58
58
  currency === 'UAH';
59
59
  const THINSP = String.fromCharCode(8201);
60
+ /**
61
+ * Копейки у крупных сумм только шумят: 4+ цифры в целой части (≥ 1000)
62
+ * округляем до целых единиц. Меньше — оставляем как есть.
63
+ */
64
+ const LARGE_MAJOR_THRESHOLD = 100_000;
65
+ const roundDisplayAmount = (amount) => {
66
+ const value = +amount || 0;
67
+ if (Math.abs(value) < LARGE_MAJOR_THRESHOLD)
68
+ return value;
69
+ return Math.round(value / 100) * 100;
70
+ };
71
+ exports.roundDisplayAmount = roundDisplayAmount;
60
72
  const formatAmount = (amount, currency) => {
61
73
  const [major, minor] = ((+amount || 0) / 100).toFixed(2).split('.');
62
74
  const value = +minor;
package/dist/index.d.ts CHANGED
@@ -38,6 +38,7 @@ export * from './role-chat-permissions';
38
38
  export * from './role-comment-permissions';
39
39
  export * from './role-employee-report-permissions';
40
40
  export * from './role-export-permissions';
41
+ export * from './role-finance-permissions';
41
42
  export * from './role-lead-permissions';
42
43
  export * from './role-payment-delete-permissions';
43
44
  export * from './role-refund-permissions';
package/dist/index.js CHANGED
@@ -54,6 +54,7 @@ __exportStar(require("./role-chat-permissions"), exports);
54
54
  __exportStar(require("./role-comment-permissions"), exports);
55
55
  __exportStar(require("./role-employee-report-permissions"), exports);
56
56
  __exportStar(require("./role-export-permissions"), exports);
57
+ __exportStar(require("./role-finance-permissions"), exports);
57
58
  __exportStar(require("./role-lead-permissions"), exports);
58
59
  __exportStar(require("./role-payment-delete-permissions"), exports);
59
60
  __exportStar(require("./role-refund-permissions"), exports);
@@ -0,0 +1,12 @@
1
+ import { RoleRO } from '@escapenavigator/types/dist/role/role.ro';
2
+ export type RoleFinancePermissions = Pick<RoleRO, 'totalAccess' | 'accessToFinanceSection' | 'financePaymentsOnly'>;
3
+ /**
4
+ * Вкладка платежей и сам раздел бухгалтерии.
5
+ * Владелец (`totalAccess`) — как будто доступ включён.
6
+ */
7
+ export declare const canAccessFinance: (role?: RoleFinancePermissions | null) => boolean;
8
+ /**
9
+ * Кассы, статьи, схемы зарплат и партнёры.
10
+ * `financePaymentsOnly` оставляет только платежи. На владельца не действует.
11
+ */
12
+ export declare const canAccessFullFinance: (role?: RoleFinancePermissions | null) => boolean;
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.canAccessFullFinance = exports.canAccessFinance = void 0;
4
+ /**
5
+ * Вкладка платежей и сам раздел бухгалтерии.
6
+ * Владелец (`totalAccess`) — как будто доступ включён.
7
+ */
8
+ const canAccessFinance = (role) => !!role?.totalAccess || !!role?.accessToFinanceSection;
9
+ exports.canAccessFinance = canAccessFinance;
10
+ /**
11
+ * Кассы, статьи, схемы зарплат и партнёры.
12
+ * `financePaymentsOnly` оставляет только платежи. На владельца не действует.
13
+ */
14
+ const canAccessFullFinance = (role) => !!role?.totalAccess || (!!role?.accessToFinanceSection && !role?.financePaymentsOnly);
15
+ exports.canAccessFullFinance = canAccessFullFinance;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,51 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const role_finance_permissions_1 = require("./role-finance-permissions");
4
+ describe('canAccessFinance', () => {
5
+ it('закрыт без роли и без флага', () => {
6
+ expect((0, role_finance_permissions_1.canAccessFinance)()).toBe(false);
7
+ expect((0, role_finance_permissions_1.canAccessFinance)(null)).toBe(false);
8
+ expect((0, role_finance_permissions_1.canAccessFinance)({
9
+ totalAccess: false,
10
+ accessToFinanceSection: false,
11
+ financePaymentsOnly: false,
12
+ })).toBe(false);
13
+ });
14
+ it('открыт при доступе к бухгалтерии', () => {
15
+ expect((0, role_finance_permissions_1.canAccessFinance)({
16
+ totalAccess: false,
17
+ accessToFinanceSection: true,
18
+ financePaymentsOnly: true,
19
+ })).toBe(true);
20
+ });
21
+ it('открыт владельцу', () => {
22
+ expect((0, role_finance_permissions_1.canAccessFinance)({
23
+ totalAccess: true,
24
+ accessToFinanceSection: false,
25
+ financePaymentsOnly: true,
26
+ })).toBe(true);
27
+ });
28
+ });
29
+ describe('canAccessFullFinance', () => {
30
+ it('закрыт, если бухгалтерия сужена до платежей', () => {
31
+ expect((0, role_finance_permissions_1.canAccessFullFinance)({
32
+ totalAccess: false,
33
+ accessToFinanceSection: true,
34
+ financePaymentsOnly: true,
35
+ })).toBe(false);
36
+ });
37
+ it('открыт при полном доступе к бухгалтерии', () => {
38
+ expect((0, role_finance_permissions_1.canAccessFullFinance)({
39
+ totalAccess: false,
40
+ accessToFinanceSection: true,
41
+ financePaymentsOnly: false,
42
+ })).toBe(true);
43
+ });
44
+ it('владелец видит весь раздел', () => {
45
+ expect((0, role_finance_permissions_1.canAccessFullFinance)({
46
+ totalAccess: true,
47
+ accessToFinanceSection: false,
48
+ financePaymentsOnly: true,
49
+ })).toBe(true);
50
+ });
51
+ });
@@ -27,6 +27,11 @@ export type UtmFields = {
27
27
  fbclid?: string | null;
28
28
  ttclid?: string | null;
29
29
  msclkid?: string | null;
30
+ /**
31
+ * ClientID Яндекс.Метрики. Как click-id: в touchpoint-нормализацию
32
+ * не входит, пишется в денорм-колонку заказа / продажи сертификата.
33
+ */
34
+ ymClientId?: string | null;
30
35
  };
31
36
  /**
32
37
  * Нормализация одного UTM-поля для индекса/поиска: trim + lowercase.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@escapenavigator/utils",
3
- "version": "2.1.20",
3
+ "version": "2.1.22",
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.1.19",
17
+ "@escapenavigator/types": "^2.1.22",
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": "a75a26ab79572607871d7b9f6f0ae9c7ee4715dd"
32
+ "gitHead": "a4d5c142ffa0a99936093b991f5ee87cf8359d7e"
33
33
  }