@diia-inhouse/utils 5.3.30 → 6.0.9
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/address.d.ts +7 -0
- package/dist/address.js +38 -41
- package/dist/applicationUtils.d.ts +225 -0
- package/dist/applicationUtils.js +576 -678
- package/dist/asserts.d.ts +6 -0
- package/dist/asserts.js +12 -19
- package/dist/dictionaries/phoneCodes.js +2435 -2442
- package/dist/guards.d.ts +22 -0
- package/dist/guards.js +58 -74
- package/dist/index.d.ts +36 -0
- package/dist/index.js +34 -70
- package/dist/integration.d.ts +6 -0
- package/dist/integration.js +7 -10
- package/dist/interfaces/asserts.d.ts +9 -0
- package/dist/interfaces/publicService.d.ts +11 -0
- package/dist/interfaces/slack.d.ts +6 -0
- package/dist/network.d.ts +17 -0
- package/dist/network.js +64 -72
- package/dist/payment.d.ts +8 -0
- package/dist/payment.js +19 -22
- package/dist/pdfUtils.d.ts +6 -0
- package/dist/pdfUtils.js +7 -10
- package/dist/phoneticChecker/index.d.ts +9 -0
- package/dist/phoneticChecker/index.js +18 -23
- package/dist/phoneticChecker/metaphone.js +38 -41
- package/dist/publicService.d.ts +59 -0
- package/dist/publicService.js +137 -150
- package/dist/random.d.ts +7 -0
- package/dist/random.js +11 -10
- package/dist/session.d.ts +7 -0
- package/dist/session.js +10 -19
- package/dist/slackFormatting.d.ts +13 -0
- package/dist/slackFormatting.js +41 -24
- package/dist/typeUtils.d.ts +8 -0
- package/dist/typeUtils.js +13 -15
- package/package.json +42 -27
- package/dist/address.js.map +0 -1
- package/dist/applicationUtils.js.map +0 -1
- package/dist/asserts.js.map +0 -1
- package/dist/dictionaries/phoneCodes.js.map +0 -1
- package/dist/guards.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/integration.js.map +0 -1
- package/dist/interfaces/applicationUtils.js +0 -3
- package/dist/interfaces/applicationUtils.js.map +0 -1
- package/dist/interfaces/asserts.js +0 -3
- package/dist/interfaces/asserts.js.map +0 -1
- package/dist/interfaces/error.js +0 -3
- package/dist/interfaces/error.js.map +0 -1
- package/dist/interfaces/publicService.js +0 -12
- package/dist/interfaces/publicService.js.map +0 -1
- package/dist/interfaces/slack.js +0 -3
- package/dist/interfaces/slack.js.map +0 -1
- package/dist/network.js.map +0 -1
- package/dist/payment.js.map +0 -1
- package/dist/pdfUtils.js.map +0 -1
- package/dist/phoneticChecker/index.js.map +0 -1
- package/dist/phoneticChecker/metaphone.js.map +0 -1
- package/dist/publicService.js.map +0 -1
- package/dist/random.js.map +0 -1
- package/dist/session.js.map +0 -1
- package/dist/slackFormatting.js.map +0 -1
- package/dist/typeUtils.js.map +0 -1
- package/dist/types/address.d.ts +0 -4
- package/dist/types/applicationUtils.d.ts +0 -212
- package/dist/types/asserts.d.ts +0 -2
- package/dist/types/dictionaries/phoneCodes.d.ts +0 -2
- package/dist/types/guards.d.ts +0 -18
- package/dist/types/index.d.ts +0 -86
- package/dist/types/integration.d.ts +0 -3
- package/dist/types/interfaces/applicationUtils.d.ts +0 -1
- package/dist/types/interfaces/asserts.d.ts +0 -5
- package/dist/types/interfaces/error.d.ts +0 -7
- package/dist/types/interfaces/publicService.d.ts +0 -15
- package/dist/types/interfaces/slack.d.ts +0 -3
- package/dist/types/network.d.ts +0 -13
- package/dist/types/payment.d.ts +0 -5
- package/dist/types/pdfUtils.d.ts +0 -3
- package/dist/types/phoneticChecker/index.d.ts +0 -7
- package/dist/types/phoneticChecker/metaphone.d.ts +0 -6
- package/dist/types/publicService.d.ts +0 -55
- package/dist/types/random.d.ts +0 -5
- package/dist/types/session.d.ts +0 -3
- package/dist/types/slackFormatting.d.ts +0 -7
- package/dist/types/typeUtils.d.ts +0 -5
|
@@ -1,24 +1,19 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
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
|
-
|
|
6
|
-
|
|
7
|
-
|
|
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
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
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 };
|
package/dist/publicService.js
CHANGED
|
@@ -1,151 +1,138 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const
|
|
5
|
-
|
|
6
|
-
const
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
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
|
-
//#
|
|
137
|
+
//#endregion
|
|
138
|
+
export { PublicServiceUtils };
|
package/dist/random.d.ts
ADDED
package/dist/random.js
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
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
|
-
//#
|
|
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
|
-
|
|
2
|
-
|
|
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
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
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
|
-
|
|
19
|
-
|
|
20
|
-
}
|
|
21
|
-
return profileFeaturesToList(session.features);
|
|
10
|
+
if (!("features" in session) || !session.features) return [];
|
|
11
|
+
return profileFeaturesToList(session.features);
|
|
22
12
|
}
|
|
23
|
-
//#
|
|
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 };
|
package/dist/slackFormatting.js
CHANGED
|
@@ -1,24 +1,41 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
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 };
|