@diia-inhouse/utils 5.3.29 → 6.0.8

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.
Files changed (85) hide show
  1. package/dist/address.d.ts +7 -0
  2. package/dist/address.js +38 -41
  3. package/dist/applicationUtils.d.ts +225 -0
  4. package/dist/applicationUtils.js +576 -678
  5. package/dist/asserts.d.ts +6 -0
  6. package/dist/asserts.js +12 -19
  7. package/dist/dictionaries/phoneCodes.js +2435 -2442
  8. package/dist/guards.d.ts +22 -0
  9. package/dist/guards.js +58 -74
  10. package/dist/index.d.ts +36 -0
  11. package/dist/index.js +34 -70
  12. package/dist/integration.d.ts +6 -0
  13. package/dist/integration.js +7 -10
  14. package/dist/interfaces/asserts.d.ts +9 -0
  15. package/dist/interfaces/publicService.d.ts +11 -0
  16. package/dist/interfaces/slack.d.ts +6 -0
  17. package/dist/network.d.ts +17 -0
  18. package/dist/network.js +64 -72
  19. package/dist/payment.d.ts +8 -0
  20. package/dist/payment.js +19 -22
  21. package/dist/pdfUtils.d.ts +6 -0
  22. package/dist/pdfUtils.js +7 -10
  23. package/dist/phoneticChecker/index.d.ts +9 -0
  24. package/dist/phoneticChecker/index.js +18 -23
  25. package/dist/phoneticChecker/metaphone.js +38 -41
  26. package/dist/publicService.d.ts +59 -0
  27. package/dist/publicService.js +137 -150
  28. package/dist/random.d.ts +7 -0
  29. package/dist/random.js +11 -10
  30. package/dist/session.d.ts +7 -0
  31. package/dist/session.js +10 -19
  32. package/dist/slackFormatting.d.ts +13 -0
  33. package/dist/slackFormatting.js +41 -24
  34. package/dist/typeUtils.d.ts +8 -0
  35. package/dist/typeUtils.js +13 -15
  36. package/package.json +42 -27
  37. package/dist/address.js.map +0 -1
  38. package/dist/applicationUtils.js.map +0 -1
  39. package/dist/asserts.js.map +0 -1
  40. package/dist/dictionaries/phoneCodes.js.map +0 -1
  41. package/dist/guards.js.map +0 -1
  42. package/dist/index.js.map +0 -1
  43. package/dist/integration.js.map +0 -1
  44. package/dist/interfaces/applicationUtils.js +0 -3
  45. package/dist/interfaces/applicationUtils.js.map +0 -1
  46. package/dist/interfaces/asserts.js +0 -3
  47. package/dist/interfaces/asserts.js.map +0 -1
  48. package/dist/interfaces/error.js +0 -3
  49. package/dist/interfaces/error.js.map +0 -1
  50. package/dist/interfaces/publicService.js +0 -12
  51. package/dist/interfaces/publicService.js.map +0 -1
  52. package/dist/interfaces/slack.js +0 -3
  53. package/dist/interfaces/slack.js.map +0 -1
  54. package/dist/network.js.map +0 -1
  55. package/dist/payment.js.map +0 -1
  56. package/dist/pdfUtils.js.map +0 -1
  57. package/dist/phoneticChecker/index.js.map +0 -1
  58. package/dist/phoneticChecker/metaphone.js.map +0 -1
  59. package/dist/publicService.js.map +0 -1
  60. package/dist/random.js.map +0 -1
  61. package/dist/session.js.map +0 -1
  62. package/dist/slackFormatting.js.map +0 -1
  63. package/dist/typeUtils.js.map +0 -1
  64. package/dist/types/address.d.ts +0 -4
  65. package/dist/types/applicationUtils.d.ts +0 -212
  66. package/dist/types/asserts.d.ts +0 -2
  67. package/dist/types/dictionaries/phoneCodes.d.ts +0 -2
  68. package/dist/types/guards.d.ts +0 -18
  69. package/dist/types/index.d.ts +0 -86
  70. package/dist/types/integration.d.ts +0 -3
  71. package/dist/types/interfaces/applicationUtils.d.ts +0 -1
  72. package/dist/types/interfaces/asserts.d.ts +0 -5
  73. package/dist/types/interfaces/error.d.ts +0 -7
  74. package/dist/types/interfaces/publicService.d.ts +0 -15
  75. package/dist/types/interfaces/slack.d.ts +0 -3
  76. package/dist/types/network.d.ts +0 -13
  77. package/dist/types/payment.d.ts +0 -5
  78. package/dist/types/pdfUtils.d.ts +0 -3
  79. package/dist/types/phoneticChecker/index.d.ts +0 -7
  80. package/dist/types/phoneticChecker/metaphone.d.ts +0 -6
  81. package/dist/types/publicService.d.ts +0 -55
  82. package/dist/types/random.d.ts +0 -5
  83. package/dist/types/session.d.ts +0 -3
  84. package/dist/types/slackFormatting.d.ts +0 -7
  85. package/dist/types/typeUtils.d.ts +0 -5
@@ -1,24 +1,19 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
1
+ import { metaphone } from "./metaphone.js";
2
+ import flevenshtein from "fast-levenshtein";
3
+ //#region src/phoneticChecker/index.ts
4
+ var PhoneticChecker = class {
5
+ equalityCoefficientThreshold = .75;
6
+ arePhoneticallySimilar(etalonValue, slaveValue, threshold = this.equalityCoefficientThreshold) {
7
+ return this.getEqualityCoefficient(etalonValue, slaveValue) >= threshold;
8
+ }
9
+ getEqualityCoefficient(etalonValue, slaveValue) {
10
+ const etalonValuePhone = metaphone.process(etalonValue);
11
+ const slaveValuePhone = metaphone.process(slaveValue);
12
+ const distance = flevenshtein.get(etalonValuePhone, slaveValuePhone);
13
+ const etalonLength = etalonValue.length;
14
+ return (etalonLength - distance) / etalonLength;
15
+ }
4
16
  };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.phoneticChecker = void 0;
7
- const fast_levenshtein_1 = __importDefault(require("fast-levenshtein"));
8
- const metaphone_1 = require("./metaphone");
9
- class PhoneticChecker {
10
- equalityCoefficientThreshold = 0.75;
11
- arePhoneticallySimilar(etalonValue, slaveValue, threshold = this.equalityCoefficientThreshold) {
12
- const equalityCoefficient = this.getEqualityCoefficient(etalonValue, slaveValue);
13
- return equalityCoefficient >= threshold;
14
- }
15
- getEqualityCoefficient(etalonValue, slaveValue) {
16
- const etalonValuePhone = metaphone_1.metaphone.process(etalonValue);
17
- const slaveValuePhone = metaphone_1.metaphone.process(slaveValue);
18
- const distance = fast_levenshtein_1.default.get(etalonValuePhone, slaveValuePhone);
19
- const etalonLength = etalonValue.length;
20
- return (etalonLength - distance) / etalonLength;
21
- }
22
- }
23
- exports.phoneticChecker = new PhoneticChecker();
24
- //# sourceMappingURL=index.js.map
17
+ const phoneticChecker = new PhoneticChecker();
18
+ //#endregion
19
+ export { phoneticChecker };
@@ -1,41 +1,38 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.metaphone = void 0;
4
- class Metaphone {
5
- process(word) {
6
- let normalizedValue = word.toUpperCase();
7
- const operations = [
8
- this.modifyOperation(/['`Ь’]/g, ''),
9
- this.modifyOperation(/Ґ/g, 'Г'),
10
- this.modifyOperation(/Е|Є|ЙЕ|ІЕ|ІО/g, 'Е'),
11
- this.modifyOperation(/Я|ІА|ІЯ/g, 'А'),
12
- this.modifyOperation(/І|Ї/g, 'И'),
13
- this.modifyOperation(/Ю/g, 'У'),
14
- this.modifyOperation(/ЙО/g, 'О'),
15
- this.modifyOperation(/У$/g, 'В'),
16
- this.modifyOperation(([БГДЖЗ])/g, 'Б$1'),
17
- this.modifyOperation(([БГДЖЗ])/g, 'З$1'),
18
- this.modifyOperation(([БГДЖЗ])/g, 'Г$1'),
19
- this.modifyOperation(/Т([БГДЖЗ])/g, 'Д$1'),
20
- this.modifyOperation(([БГДЖЗ])/g, 'Ж$1'),
21
- this.modifyOperation(/ХВ/g, 'Ф'),
22
- this.modifyOperation(/(С|Ж)Ч/g, 'Щ'),
23
- this.modifyOperation(/(ШЧ[^Н])/, 'Щ'),
24
- this.modifyOperation(/С(Т|Л)Н/g, 'СН'),
25
- this.modifyOperation(/ЗДН/g, 'ЗH'),
26
- this.modifyOperation(/СТЛ/g, 'СЛ'),
27
- this.modifyOperation(/ШЧН/g, 'ШН'),
28
- this.modifyOperation(/ЦВ/g, 'Ц'),
29
- this.modifyOperation(/(\w)\1+/g, '$1'),
30
- ];
31
- for (const operation of operations) {
32
- normalizedValue = operation(normalizedValue);
33
- }
34
- return normalizedValue;
35
- }
36
- modifyOperation(pattern, replaceValue) {
37
- return (token) => token.replace(pattern, replaceValue);
38
- }
39
- }
40
- exports.metaphone = new Metaphone();
41
- //# sourceMappingURL=metaphone.js.map
1
+ //#region src/phoneticChecker/metaphone.ts
2
+ var Metaphone = class {
3
+ process(word) {
4
+ let normalizedValue = word.toUpperCase();
5
+ const operations = [
6
+ this.modifyOperation(/['`Ь’]/g, ""),
7
+ this.modifyOperation(/Ґ/g, "Г"),
8
+ this.modifyOperation(/Е|Є|ЙЕ|ІЕ|ІО/g, "Е"),
9
+ this.modifyOperation(/Я|ІА|ІЯ/g, "А"),
10
+ this.modifyOperation(/І|Ї/g, "И"),
11
+ this.modifyOperation(/Ю/g, "У"),
12
+ this.modifyOperation(/ЙО/g, "О"),
13
+ this.modifyOperation(/У$/g, "В"),
14
+ this.modifyOperation(/П([БГДЖЗ])/g, "Б$1"),
15
+ this.modifyOperation(/С([БГДЖЗ])/g, "З$1"),
16
+ this.modifyOperation(([БГДЖЗ])/g, "Г$1"),
17
+ this.modifyOperation(([БГДЖЗ])/g, "Д$1"),
18
+ this.modifyOperation(([БГДЖЗ])/g, "Ж$1"),
19
+ this.modifyOperation(/ХВ/g, "Ф"),
20
+ this.modifyOperation(/(С|Ж)Ч/g, "Щ"),
21
+ this.modifyOperation(/(ШЧ[^Н])/, "Щ"),
22
+ this.modifyOperation((Т|Л)Н/g, "СН"),
23
+ this.modifyOperation(/ЗДН/g, "ЗH"),
24
+ this.modifyOperation(/СТЛ/g, "СЛ"),
25
+ this.modifyOperation(/ШЧН/g, "ШН"),
26
+ this.modifyOperation(/ЦВ/g, "Ц"),
27
+ this.modifyOperation(/(\w)\1+/g, "$1")
28
+ ];
29
+ for (const operation of operations) normalizedValue = operation(normalizedValue);
30
+ return normalizedValue;
31
+ }
32
+ modifyOperation(pattern, replaceValue) {
33
+ return (token) => token.replace(pattern, replaceValue);
34
+ }
35
+ };
36
+ const metaphone = new Metaphone();
37
+ //#endregion
38
+ export { metaphone };
@@ -0,0 +1,59 @@
1
+ import { InputPhoneCodeOrgParams } from "./interfaces/publicService.js";
2
+ import { UserTokenData } from "@diia-inhouse/types";
3
+ import { ContactsResponse, DSBodyItem, InputPhoneCodeItem, InputPhoneCodeOrg, InputTextMlc, TextLabelMlc } from "@diia-inhouse/design-system";
4
+
5
+ //#region src/publicService.d.ts
6
+ declare const PublicServiceUtils: {
7
+ getContacts(user: UserTokenData): ContactsResponse;
8
+ getContactsText(user: UserTokenData): string;
9
+ getContactsComponent(user: UserTokenData, inputCode?: string): DSBodyItem;
10
+ /**
11
+ * Creates an InputPhoneCodeOrg with specified parameters
12
+ * @param params.codeIds - Optional array of allowed country code IDs
13
+ * @returns InputPhoneCodeOrg
14
+ * @example
15
+ * // Create a phone input with Ukrainian code
16
+ * const phoneInput = getInputPhoneCodeOrg({
17
+ * inputCode: 'phone',
18
+ * phoneValue: '501234567',
19
+ * codeValueId: 'ua',
20
+ * codeIds: ['ua', 'pl'],
21
+ * hint: 'Enter your phone number'
22
+ * });
23
+ */
24
+ getInputPhoneCodeOrg(params: InputPhoneCodeOrgParams): InputPhoneCodeOrg;
25
+ /**
26
+ * Returns an array of phone code items, optionally filtered by provided code IDs
27
+ * @param filter - Optional array of phone code IDs to filter by
28
+ * @returns Array of phone code items matching the filter criteria, or all phone codes if no filter is provided
29
+ * @example
30
+ * // Get all phone codes
31
+ * const allCodes = getInputPhoneCodeItems();
32
+ *
33
+ * @example
34
+ * // Get only Ukrainian and Polish phone codes
35
+ * const filteredCodes = getInputPhoneCodeItems(['ua', 'pl']);
36
+ */
37
+ getInputPhoneCodeItems(filter?: string[]): InputPhoneCodeItem[];
38
+ getEmailInputTextMlc(emailValue: string, inputCode?: string): InputTextMlc;
39
+ getContactsComponentTextLabel(user: UserTokenData, phoneNumber: string): TextLabelMlc | undefined;
40
+ /**
41
+ * Extracts the phone number from the phone number string
42
+ *
43
+ * @param phoneNumber - Phone number to extract the number from
44
+ * @param phoneCodeValue - Phone country code in ISO 3166-1 alpha-2 format
45
+ * @returns Extracted phone number (without country code)
46
+ *
47
+ * @example
48
+ * extractPhoneNumber('+380123456789', 'ua') // 123456789
49
+ *
50
+ * @example
51
+ * extractPhoneNumber('123456789', 'ua') // throws Error(`Phone number must start with country code 380`)
52
+ *
53
+ * @example
54
+ * extractPhoneNumber('380123456789', 'invalid') // throws Error(`Invalid country code`)
55
+ */
56
+ extractPhoneNumber(phoneNumber: string, phoneCodeValue: string): string | never;
57
+ };
58
+ //#endregion
59
+ export { PublicServiceUtils };
@@ -1,151 +1,138 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.PublicServiceUtils = void 0;
4
- const validators_1 = require("@diia-inhouse/validators");
5
- const phoneCodes_1 = require("./dictionaries/phoneCodes");
6
- const publicService_1 = require("./interfaces/publicService");
7
- exports.PublicServiceUtils = {
8
- getContacts(user) {
9
- const { phoneNumber, email } = user;
10
- return {
11
- title: 'Контактні дані',
12
- text: this.getContactsText(user),
13
- phoneNumber,
14
- email,
15
- attentionMessage: undefined,
16
- };
17
- },
18
- getContactsText(user) {
19
- const { phoneNumber, email, authEntryPoint } = user;
20
- const { isBankId, target } = authEntryPoint || {};
21
- const isBankApp = [publicService_1.AuthProviderName.PrivatBank, publicService_1.AuthProviderName.Monobank].includes(target);
22
- const isAuthorizedWithBank = isBankId || isBankApp;
23
- if (isAuthorizedWithBank && phoneNumber && email) {
24
- return isBankId
25
- ? 'Дані заповнені з вашого BankID. Перевірте їх та виправте за потреби.'
26
- : 'Дані заповнені з вашого банку. Перевірте їх та виправте за потреби.';
27
- }
28
- return 'Будь ласка, заповніть контактні дані.';
29
- },
30
- getContactsComponent(user, inputCode = 'phone') {
31
- const { phoneNumber, email } = user;
32
- const rawPhoneNumber = phoneNumber && phoneNumber.includes('+380') ? phoneNumber.replaceAll(/\+380|\s+/g, '') : '';
33
- const inputPhoneCodeOrg = this.getInputPhoneCodeOrg({ inputCode, phoneValue: rawPhoneNumber, codeValueId: 'ua', codeIds: ['ua'] });
34
- const emailInputTextMlc = this.getEmailInputTextMlc(email);
35
- return {
36
- titleLabelMlc: {
37
- label: 'Контактні дані',
38
- },
39
- textLabelMlc: this.getContactsComponentTextLabel(user, rawPhoneNumber),
40
- attentionMessageMlc: undefined,
41
- questionFormsOrg: {
42
- id: 'question_form',
43
- items: [{ inputPhoneCodeOrg }, { inputTextMlc: emailInputTextMlc }],
44
- },
45
- };
46
- },
47
- /**
48
- * Creates an InputPhoneCodeOrg with specified parameters
49
- * @param params.codeIds - Optional array of allowed country code IDs
50
- * @returns InputPhoneCodeOrg
51
- * @example
52
- * // Create a phone input with Ukrainian code
53
- * const phoneInput = getInputPhoneCodeOrg({
54
- * inputCode: 'phone',
55
- * phoneValue: '501234567',
56
- * codeValueId: 'ua',
57
- * codeIds: ['ua', 'pl'],
58
- * hint: 'Enter your phone number'
59
- * });
60
- */
61
- getInputPhoneCodeOrg(params) {
62
- const { inputCode = 'phone', phoneValue, codeValueId, codeIds = [], hint, codeValueIsEditable = false } = params;
63
- const codes = codeIds.length > 0 ? phoneCodes_1.phoneCodes.filter((code) => codeIds.includes(code.id)) : phoneCodes_1.phoneCodes;
64
- return {
65
- componentId: 'phone_with_code',
66
- label: 'Контактний номер телефону',
67
- mandatory: true,
68
- inputCode,
69
- hint,
70
- inputPhoneMlc: {
71
- componentId: 'phone',
72
- value: phoneValue,
73
- validation: [],
74
- },
75
- codeValueIsEditable,
76
- codeValueId,
77
- codes,
78
- };
79
- },
80
- /**
81
- * Returns an array of phone code items, optionally filtered by provided code IDs
82
- * @param filter - Optional array of phone code IDs to filter by
83
- * @returns Array of phone code items matching the filter criteria, or all phone codes if no filter is provided
84
- * @example
85
- * // Get all phone codes
86
- * const allCodes = getInputPhoneCodeItems();
87
- *
88
- * @example
89
- * // Get only Ukrainian and Polish phone codes
90
- * const filteredCodes = getInputPhoneCodeItems(['ua', 'pl']);
91
- */
92
- getInputPhoneCodeItems(filter = []) {
93
- return filter.length > 0 ? phoneCodes_1.phoneCodes.filter((code) => filter.includes(code.id)) : phoneCodes_1.phoneCodes;
94
- },
95
- getEmailInputTextMlc(emailValue, inputCode = 'email') {
96
- return {
97
- componentId: 'email',
98
- id: 'email',
99
- inputCode,
100
- mandatory: true,
101
- value: emailValue,
102
- label: 'Email',
103
- placeholder: 'hello@diia.gov.ua',
104
- validation: [validators_1.emailValidation, validators_1.emailRuValidation],
105
- };
106
- },
107
- getContactsComponentTextLabel(user, phoneNumber) {
108
- const { email, authEntryPoint } = user;
109
- const { isBankId, target } = authEntryPoint || {};
110
- const isBankApp = [publicService_1.AuthProviderName.PrivatBank, publicService_1.AuthProviderName.Monobank].includes(target);
111
- const isAuthorizedWithBank = isBankId || isBankApp;
112
- if (isAuthorizedWithBank && phoneNumber && email) {
113
- return {
114
- componentId: 'text_label',
115
- parameters: [],
116
- text: 'Дія автоматично підтягнула дані з вашого BankID. Перевірте інформацію та виправте за потреби.',
117
- };
118
- }
119
- },
120
- /**
121
- * Extracts the phone number from the phone number string
122
- *
123
- * @param phoneNumber - Phone number to extract the number from
124
- * @param phoneCodeValue - Phone country code in ISO 3166-1 alpha-2 format
125
- * @returns Extracted phone number (without country code)
126
- *
127
- * @example
128
- * extractPhoneNumber('+380123456789', 'ua') // 123456789
129
- *
130
- * @example
131
- * extractPhoneNumber('123456789', 'ua') // throws Error(`Phone number must start with country code 380`)
132
- *
133
- * @example
134
- * extractPhoneNumber('380123456789', 'invalid') // throws Error(`Invalid country code`)
135
- */
136
- extractPhoneNumber(phoneNumber, phoneCodeValue) {
137
- const cleanPhoneNumber = phoneNumber.replace(/^\+/, '');
138
- if (!/^\d+$/.test(cleanPhoneNumber)) {
139
- throw new Error('Phone number must contain only digits');
140
- }
141
- const countryCode = phoneCodes_1.phoneCodes.find((code) => code.id === phoneCodeValue);
142
- if (!countryCode) {
143
- throw new Error('Invalid country code');
144
- }
145
- if (!cleanPhoneNumber.startsWith(countryCode.value)) {
146
- throw new Error(`Phone number must start with country code ${countryCode.value}`);
147
- }
148
- return cleanPhoneNumber.slice(countryCode.value.length);
149
- },
1
+ import { phoneCodes } from "./dictionaries/phoneCodes.js";
2
+ import { emailRuValidation, emailValidation } from "@diia-inhouse/validators";
3
+ //#region src/publicService.ts
4
+ const PublicServiceUtils = {
5
+ getContacts(user) {
6
+ const { phoneNumber, email } = user;
7
+ return {
8
+ title: "Контактні дані",
9
+ text: this.getContactsText(user),
10
+ phoneNumber,
11
+ email,
12
+ attentionMessage: void 0
13
+ };
14
+ },
15
+ getContactsText(user) {
16
+ const { phoneNumber, email, authEntryPoint } = user;
17
+ const { isBankId, target } = authEntryPoint || {};
18
+ const isBankApp = ["privatbank", "monobank"].includes(target);
19
+ if ((isBankId || isBankApp) && phoneNumber && email) return isBankId ? "Дані заповнені з вашого BankID. Перевірте їх та виправте за потреби." : "Дані заповнені з вашого банку. Перевірте їх та виправте за потреби.";
20
+ return "Будь ласка, заповніть контактні дані.";
21
+ },
22
+ getContactsComponent(user, inputCode = "phone") {
23
+ const { phoneNumber, email } = user;
24
+ const rawPhoneNumber = phoneNumber && phoneNumber.includes("+380") ? phoneNumber.replaceAll(/\+380|\s+/g, "") : "";
25
+ const inputPhoneCodeOrg = this.getInputPhoneCodeOrg({
26
+ inputCode,
27
+ phoneValue: rawPhoneNumber,
28
+ codeValueId: "ua",
29
+ codeIds: ["ua"]
30
+ });
31
+ const emailInputTextMlc = this.getEmailInputTextMlc(email);
32
+ return {
33
+ titleLabelMlc: { label: "Контактні дані" },
34
+ textLabelMlc: this.getContactsComponentTextLabel(user, rawPhoneNumber),
35
+ attentionMessageMlc: void 0,
36
+ questionFormsOrg: {
37
+ id: "question_form",
38
+ items: [{ inputPhoneCodeOrg }, { inputTextMlc: emailInputTextMlc }]
39
+ }
40
+ };
41
+ },
42
+ /**
43
+ * Creates an InputPhoneCodeOrg with specified parameters
44
+ * @param params.codeIds - Optional array of allowed country code IDs
45
+ * @returns InputPhoneCodeOrg
46
+ * @example
47
+ * // Create a phone input with Ukrainian code
48
+ * const phoneInput = getInputPhoneCodeOrg({
49
+ * inputCode: 'phone',
50
+ * phoneValue: '501234567',
51
+ * codeValueId: 'ua',
52
+ * codeIds: ['ua', 'pl'],
53
+ * hint: 'Enter your phone number'
54
+ * });
55
+ */
56
+ getInputPhoneCodeOrg(params) {
57
+ const { inputCode = "phone", phoneValue, codeValueId, codeIds = [], hint, codeValueIsEditable = false } = params;
58
+ const codes = codeIds.length > 0 ? phoneCodes.filter((code) => codeIds.includes(code.id)) : phoneCodes;
59
+ return {
60
+ componentId: "phone_with_code",
61
+ label: "Контактний номер телефону",
62
+ mandatory: true,
63
+ inputCode,
64
+ hint,
65
+ inputPhoneMlc: {
66
+ componentId: "phone",
67
+ value: phoneValue,
68
+ validation: []
69
+ },
70
+ codeValueIsEditable,
71
+ codeValueId,
72
+ codes
73
+ };
74
+ },
75
+ /**
76
+ * Returns an array of phone code items, optionally filtered by provided code IDs
77
+ * @param filter - Optional array of phone code IDs to filter by
78
+ * @returns Array of phone code items matching the filter criteria, or all phone codes if no filter is provided
79
+ * @example
80
+ * // Get all phone codes
81
+ * const allCodes = getInputPhoneCodeItems();
82
+ *
83
+ * @example
84
+ * // Get only Ukrainian and Polish phone codes
85
+ * const filteredCodes = getInputPhoneCodeItems(['ua', 'pl']);
86
+ */
87
+ getInputPhoneCodeItems(filter = []) {
88
+ return filter.length > 0 ? phoneCodes.filter((code) => filter.includes(code.id)) : phoneCodes;
89
+ },
90
+ getEmailInputTextMlc(emailValue, inputCode = "email") {
91
+ return {
92
+ componentId: "email",
93
+ id: "email",
94
+ inputCode,
95
+ mandatory: true,
96
+ value: emailValue,
97
+ label: "Email",
98
+ placeholder: "hello@diia.gov.ua",
99
+ validation: [emailValidation, emailRuValidation]
100
+ };
101
+ },
102
+ getContactsComponentTextLabel(user, phoneNumber) {
103
+ const { email, authEntryPoint } = user;
104
+ const { isBankId, target } = authEntryPoint || {};
105
+ const isBankApp = ["privatbank", "monobank"].includes(target);
106
+ if ((isBankId || isBankApp) && phoneNumber && email) return {
107
+ componentId: "text_label",
108
+ parameters: [],
109
+ text: "Дія автоматично підтягнула дані з вашого BankID. Перевірте інформацію та виправте за потреби."
110
+ };
111
+ },
112
+ /**
113
+ * Extracts the phone number from the phone number string
114
+ *
115
+ * @param phoneNumber - Phone number to extract the number from
116
+ * @param phoneCodeValue - Phone country code in ISO 3166-1 alpha-2 format
117
+ * @returns Extracted phone number (without country code)
118
+ *
119
+ * @example
120
+ * extractPhoneNumber('+380123456789', 'ua') // 123456789
121
+ *
122
+ * @example
123
+ * extractPhoneNumber('123456789', 'ua') // throws Error(`Phone number must start with country code 380`)
124
+ *
125
+ * @example
126
+ * extractPhoneNumber('380123456789', 'invalid') // throws Error(`Invalid country code`)
127
+ */
128
+ extractPhoneNumber(phoneNumber, phoneCodeValue) {
129
+ const cleanPhoneNumber = phoneNumber.replace(/^\+/, "");
130
+ if (!/^\d+$/.test(cleanPhoneNumber)) throw new Error("Phone number must contain only digits");
131
+ const countryCode = phoneCodes.find((code) => code.id === phoneCodeValue);
132
+ if (!countryCode) throw new Error("Invalid country code");
133
+ if (!cleanPhoneNumber.startsWith(countryCode.value)) throw new Error(`Phone number must start with country code ${countryCode.value}`);
134
+ return cleanPhoneNumber.slice(countryCode.value.length);
135
+ }
150
136
  };
151
- //# sourceMappingURL=publicService.js.map
137
+ //#endregion
138
+ export { PublicServiceUtils };
@@ -0,0 +1,7 @@
1
+ //#region src/random.d.ts
2
+ declare const RandomUtils: {
3
+ generateUUID(): string;
4
+ getRandomIntsString(length?: number): string;
5
+ };
6
+ //#endregion
7
+ export { RandomUtils };
package/dist/random.js CHANGED
@@ -1,11 +1,12 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.RandomUtils = void 0;
4
- const node_crypto_1 = require("node:crypto");
5
- exports.RandomUtils = {
6
- generateUUID: node_crypto_1.randomUUID,
7
- getRandomIntsString(length = 6) {
8
- return Array.from({ length }, () => (0, node_crypto_1.randomInt)(0, 10)).join('');
9
- },
1
+ import { randomInt, randomUUID } from "node:crypto";
2
+ //#region src/random.ts
3
+ const RandomUtils = {
4
+ generateUUID() {
5
+ return randomUUID();
6
+ },
7
+ getRandomIntsString(length = 6) {
8
+ return Array.from({ length }, () => randomInt(0, 10)).join("");
9
+ }
10
10
  };
11
- //# sourceMappingURL=random.js.map
11
+ //#endregion
12
+ export { RandomUtils };
@@ -0,0 +1,7 @@
1
+ import { EResidentSession, ProfileFeature, UserFeatures, UserSession } from "@diia-inhouse/types";
2
+
3
+ //#region src/session.d.ts
4
+ declare function profileFeaturesToList(features: UserFeatures): ProfileFeature[];
5
+ declare function extractProfileFeatures(session: UserSession | EResidentSession): ProfileFeature[];
6
+ //#endregion
7
+ export { extractProfileFeatures, profileFeaturesToList };
package/dist/session.js CHANGED
@@ -1,23 +1,14 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.profileFeaturesToList = profileFeaturesToList;
4
- exports.extractProfileFeatures = extractProfileFeatures;
5
- const types_1 = require("@diia-inhouse/types");
1
+ import { DiiaOfficeStatus, ProfileFeature } from "@diia-inhouse/types";
2
+ //#region src/session.ts
6
3
  function profileFeaturesToList(features) {
7
- const featuresList = Object.entries(features)
8
- .filter(([, value]) => value)
9
- .map(([key]) => key);
10
- return featuresList.filter((feature) => {
11
- if (feature !== types_1.ProfileFeature.office) {
12
- return true;
13
- }
14
- return features?.[feature]?.status === types_1.DiiaOfficeStatus.ACTIVE;
15
- });
4
+ return Object.entries(features).filter(([, value]) => value).map(([key]) => key).filter((feature) => {
5
+ if (feature !== ProfileFeature.office) return true;
6
+ return features?.[feature]?.status === DiiaOfficeStatus.ACTIVE;
7
+ });
16
8
  }
17
9
  function extractProfileFeatures(session) {
18
- if (!('features' in session) || !session.features) {
19
- return [];
20
- }
21
- return profileFeaturesToList(session.features);
10
+ if (!("features" in session) || !session.features) return [];
11
+ return profileFeaturesToList(session.features);
22
12
  }
23
- //# sourceMappingURL=session.js.map
13
+ //#endregion
14
+ export { extractProfileFeatures, profileFeaturesToList };
@@ -0,0 +1,13 @@
1
+ import { GetListValueOptions } from "./interfaces/slack.js";
2
+ import { RichTextElement, RichTextEmoji } from "@slack/types";
3
+
4
+ //#region src/slackFormatting.d.ts
5
+ declare class SlackFormattingUtils {
6
+ readonly greenCircleEmoji: RichTextEmoji;
7
+ readonly redCircleEmoji: RichTextEmoji;
8
+ getValue(name: string, value: string | number | undefined, {
9
+ isError
10
+ }?: GetListValueOptions): RichTextElement[];
11
+ }
12
+ //#endregion
13
+ export { SlackFormattingUtils };
@@ -1,24 +1,41 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.SlackFormattingUtils = void 0;
4
- class SlackFormattingUtils {
5
- greenCircleEmoji = { type: 'emoji', name: 'large_green_circle' };
6
- redCircleEmoji = { type: 'emoji', name: 'red_circle' };
7
- getValue(name, value, { isError } = {}) {
8
- const isZero = value === 0;
9
- if (value === undefined) {
10
- return [
11
- isError ? this.greenCircleEmoji : this.redCircleEmoji,
12
- { type: 'text', text: ` ${name}:`, style: { bold: true } },
13
- { type: 'text', text: ' -\n' },
14
- ];
15
- }
16
- return [
17
- isError && !isZero ? this.redCircleEmoji : this.greenCircleEmoji,
18
- { type: 'text', text: ` ${name}: `, style: { bold: true } },
19
- { type: 'text', text: `${value}\n`, style: { code: true } },
20
- ];
21
- }
22
- }
23
- exports.SlackFormattingUtils = SlackFormattingUtils;
24
- //# sourceMappingURL=slackFormatting.js.map
1
+ //#region src/slackFormatting.ts
2
+ var SlackFormattingUtils = class {
3
+ greenCircleEmoji = {
4
+ type: "emoji",
5
+ name: "large_green_circle"
6
+ };
7
+ redCircleEmoji = {
8
+ type: "emoji",
9
+ name: "red_circle"
10
+ };
11
+ getValue(name, value, { isError } = {}) {
12
+ const isZero = value === 0;
13
+ if (value === void 0) return [
14
+ isError ? this.greenCircleEmoji : this.redCircleEmoji,
15
+ {
16
+ type: "text",
17
+ text: ` ${name}:`,
18
+ style: { bold: true }
19
+ },
20
+ {
21
+ type: "text",
22
+ text: " -\n"
23
+ }
24
+ ];
25
+ return [
26
+ isError && !isZero ? this.redCircleEmoji : this.greenCircleEmoji,
27
+ {
28
+ type: "text",
29
+ text: ` ${name}: `,
30
+ style: { bold: true }
31
+ },
32
+ {
33
+ type: "text",
34
+ text: `${value}\n`,
35
+ style: { code: true }
36
+ }
37
+ ];
38
+ }
39
+ };
40
+ //#endregion
41
+ export { SlackFormattingUtils };