@diia-inhouse/utils 3.5.0

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 (48) hide show
  1. package/LICENCE.md +287 -0
  2. package/README.md +93 -0
  3. package/dist/applicationUtils.js +376 -0
  4. package/dist/applicationUtils.js.map +1 -0
  5. package/dist/asserts.js +20 -0
  6. package/dist/asserts.js.map +1 -0
  7. package/dist/guards.js +50 -0
  8. package/dist/guards.js.map +1 -0
  9. package/dist/index.js +43 -0
  10. package/dist/index.js.map +1 -0
  11. package/dist/integration.js +10 -0
  12. package/dist/integration.js.map +1 -0
  13. package/dist/interfaces/asserts.js +3 -0
  14. package/dist/interfaces/asserts.js.map +1 -0
  15. package/dist/interfaces/publicService.js +12 -0
  16. package/dist/interfaces/publicService.js.map +1 -0
  17. package/dist/network.js +72 -0
  18. package/dist/network.js.map +1 -0
  19. package/dist/payment.js +22 -0
  20. package/dist/payment.js.map +1 -0
  21. package/dist/pdfUtils.js +10 -0
  22. package/dist/pdfUtils.js.map +1 -0
  23. package/dist/phoneticChecker/index.js +22 -0
  24. package/dist/phoneticChecker/index.js.map +1 -0
  25. package/dist/phoneticChecker/metaphone.js +42 -0
  26. package/dist/phoneticChecker/metaphone.js.map +1 -0
  27. package/dist/publicService.js +80 -0
  28. package/dist/publicService.js.map +1 -0
  29. package/dist/session.js +24 -0
  30. package/dist/session.js.map +1 -0
  31. package/dist/typeUtils.js +15 -0
  32. package/dist/typeUtils.js.map +1 -0
  33. package/dist/types/applicationUtils.d.ts +88 -0
  34. package/dist/types/asserts.d.ts +2 -0
  35. package/dist/types/guards.d.ts +15 -0
  36. package/dist/types/index.d.ts +27 -0
  37. package/dist/types/integration.d.ts +3 -0
  38. package/dist/types/interfaces/asserts.d.ts +5 -0
  39. package/dist/types/interfaces/publicService.d.ts +7 -0
  40. package/dist/types/network.d.ts +13 -0
  41. package/dist/types/payment.d.ts +5 -0
  42. package/dist/types/pdfUtils.d.ts +3 -0
  43. package/dist/types/phoneticChecker/index.d.ts +6 -0
  44. package/dist/types/phoneticChecker/metaphone.d.ts +6 -0
  45. package/dist/types/publicService.d.ts +9 -0
  46. package/dist/types/session.d.ts +3 -0
  47. package/dist/types/typeUtils.d.ts +5 -0
  48. package/package.json +95 -0
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PaymentUtils = void 0;
4
+ const applicationUtils_1 = require("./applicationUtils");
5
+ class PaymentUtils {
6
+ static config = {
7
+ defaultMinCommission: 1,
8
+ commissionPercent: 1.5,
9
+ };
10
+ static getPaymentPayCommission(amount) {
11
+ const { commissionPercent, defaultMinCommission } = this.config;
12
+ const rawAmount = Math.ceil(amount * commissionPercent);
13
+ const rawCommission = rawAmount / 100;
14
+ const commission = Math.max(rawCommission, defaultMinCommission);
15
+ return applicationUtils_1.ApplicationUtils.toDecimalPlaces(commission, 2);
16
+ }
17
+ static getPaymentTotalAmount(amount, commission) {
18
+ return applicationUtils_1.ApplicationUtils.toDecimalPlaces(amount + commission, 2);
19
+ }
20
+ }
21
+ exports.PaymentUtils = PaymentUtils;
22
+ //# sourceMappingURL=payment.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"payment.js","sourceRoot":"","sources":["../src/payment.ts"],"names":[],"mappings":";;;AAAA,yDAAqD;AAErD,MAAa,YAAY;IACb,MAAM,CAAU,MAAM,GAAG;QAC7B,oBAAoB,EAAE,CAAC;QACvB,iBAAiB,EAAE,GAAG;KACzB,CAAA;IAED,MAAM,CAAC,uBAAuB,CAAC,MAAc;QACzC,MAAM,EAAE,iBAAiB,EAAE,oBAAoB,EAAE,GAAG,IAAI,CAAC,MAAM,CAAA;QAE/D,MAAM,SAAS,GAAG,IAAI,CAAC,IAAI,CAAC,MAAM,GAAG,iBAAiB,CAAC,CAAA;QACvD,MAAM,aAAa,GAAG,SAAS,GAAG,GAAG,CAAA;QAErC,MAAM,UAAU,GAAG,IAAI,CAAC,GAAG,CAAC,aAAa,EAAE,oBAAoB,CAAC,CAAA;QAEhE,OAAO,mCAAgB,CAAC,eAAe,CAAC,UAAU,EAAE,CAAC,CAAC,CAAA;IAC1D,CAAC;IAED,MAAM,CAAC,qBAAqB,CAAC,MAAc,EAAE,UAAkB;QAC3D,OAAO,mCAAgB,CAAC,eAAe,CAAC,MAAM,GAAG,UAAU,EAAE,CAAC,CAAC,CAAA;IACnE,CAAC;;AAnBL,oCAoBC"}
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PdfUtils = void 0;
4
+ const applicationUtils_1 = require("./applicationUtils");
5
+ exports.PdfUtils = {
6
+ getPdfFileName(name, id, requestDateTime) {
7
+ return `${applicationUtils_1.ApplicationUtils.getFileName(name, id, requestDateTime)}.pdf`;
8
+ },
9
+ };
10
+ //# sourceMappingURL=pdfUtils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pdfUtils.js","sourceRoot":"","sources":["../src/pdfUtils.ts"],"names":[],"mappings":";;;AAAA,yDAAqD;AAExC,QAAA,QAAQ,GAAG;IACpB,cAAc,CAAC,IAAY,EAAE,EAAU,EAAE,eAAwB;QAC7D,OAAO,GAAG,mCAAgB,CAAC,WAAW,CAAC,IAAI,EAAE,EAAE,EAAE,eAAe,CAAC,MAAM,CAAA;IAC3E,CAAC;CACJ,CAAA"}
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
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
+ getEqualityCoefficient(etalonValue, slaveValue) {
11
+ const etalonValuePhone = metaphone_1.metaphone.process(etalonValue);
12
+ const slaveValuePhone = metaphone_1.metaphone.process(slaveValue);
13
+ const distance = this.getLevenshteinDistance(etalonValuePhone, slaveValuePhone);
14
+ const etalonLength = etalonValue.length;
15
+ return (etalonLength - distance) / etalonLength;
16
+ }
17
+ getLevenshteinDistance(str1, str2) {
18
+ return fast_levenshtein_1.default.get(str1, str2);
19
+ }
20
+ }
21
+ exports.phoneticChecker = new PhoneticChecker();
22
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/phoneticChecker/index.ts"],"names":[],"mappings":";;;;;;AAAA,wEAA2C;AAE3C,2CAAuC;AAEvC,MAAM,eAAe;IACjB,sBAAsB,CAAC,WAAmB,EAAE,UAAkB;QAC1D,MAAM,gBAAgB,GAAG,qBAAS,CAAC,OAAO,CAAC,WAAW,CAAC,CAAA;QACvD,MAAM,eAAe,GAAG,qBAAS,CAAC,OAAO,CAAC,UAAU,CAAC,CAAA;QAErD,MAAM,QAAQ,GAAG,IAAI,CAAC,sBAAsB,CAAC,gBAAgB,EAAE,eAAe,CAAC,CAAA;QAE/E,MAAM,YAAY,GAAG,WAAW,CAAC,MAAM,CAAA;QAEvC,OAAO,CAAC,YAAY,GAAG,QAAQ,CAAC,GAAG,YAAY,CAAA;IACnD,CAAC;IAEO,sBAAsB,CAAC,IAAY,EAAE,IAAY;QACrD,OAAO,0BAAY,CAAC,GAAG,CAAC,IAAI,EAAE,IAAI,CAAC,CAAA;IACvC,CAAC;CACJ;AAEY,QAAA,eAAe,GAAG,IAAI,eAAe,EAAE,CAAA"}
@@ -0,0 +1,42 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.metaphone = void 0;
4
+ /* eslint-disable regexp/prefer-character-class */
5
+ class Metaphone {
6
+ process(word) {
7
+ let normalizedValue = word.toUpperCase();
8
+ const operations = [
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, 'В'),
17
+ this.modifyOperation(/П([БГДЖЗ])/g, 'Б$1'),
18
+ this.modifyOperation(/С([БГДЖЗ])/g, 'З$1'),
19
+ this.modifyOperation(/Х([БГДЖЗ])/g, 'Г$1'),
20
+ this.modifyOperation(/Т([БГДЖЗ])/g, 'Д$1'),
21
+ this.modifyOperation(/Ш([БГДЖЗ])/g, 'Ж$1'),
22
+ this.modifyOperation(/ХВ/g, 'Ф'),
23
+ this.modifyOperation(/(С|Ж)Ч/g, 'Щ'),
24
+ this.modifyOperation(/(ШЧ[^Н])/, 'Щ'),
25
+ this.modifyOperation(/С(Т|Л)Н/g, 'СН'),
26
+ this.modifyOperation(/ЗДН/g, 'ЗH'),
27
+ this.modifyOperation(/СТЛ/g, 'СЛ'),
28
+ this.modifyOperation(/ШЧН/g, 'ШН'),
29
+ this.modifyOperation(/ЦВ/g, 'Ц'),
30
+ this.modifyOperation(/(\w)\1+/g, '$1'),
31
+ ];
32
+ for (const operation of operations) {
33
+ normalizedValue = operation(normalizedValue);
34
+ }
35
+ return normalizedValue;
36
+ }
37
+ modifyOperation(pattern, replaceValue) {
38
+ return (token) => token.replace(pattern, replaceValue);
39
+ }
40
+ }
41
+ exports.metaphone = new Metaphone();
42
+ //# sourceMappingURL=metaphone.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"metaphone.js","sourceRoot":"","sources":["../../src/phoneticChecker/metaphone.ts"],"names":[],"mappings":";;;AAAA,kDAAkD;AAClD,MAAM,SAAS;IACX,OAAO,CAAC,IAAY;QAChB,IAAI,eAAe,GAAG,IAAI,CAAC,WAAW,EAAE,CAAA;QAExC,MAAM,UAAU,GAAG;YACf,IAAI,CAAC,eAAe,CAA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eAAe,GAAG,SAAS,CAAC,eAAe,CAAC,CAAA;SAC/C;QAED,OAAO,eAAe,CAAA;IAC1B,CAAC;IAEO,eAAe,CAAC,OAAe,EAAE,YAAoB;QACzD,OAAO,CAAC,KAAa,EAAU,EAAE,CAAC,KAAK,CAAC,OAAO,CAAC,OAAO,EAAE,YAAY,CAAC,CAAA;IAC1E,CAAC;CACJ;AAEY,QAAA,SAAS,GAAG,IAAI,SAAS,EAAE,CAAA"}
@@ -0,0 +1,80 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PublicServiceUtils = void 0;
4
+ const compare_versions_1 = require("compare-versions");
5
+ const types_1 = require("@diia-inhouse/types");
6
+ const applicationUtils_1 = require("./applicationUtils");
7
+ const publicService_1 = require("./interfaces/publicService");
8
+ const session_1 = require("./session");
9
+ class PublicServiceUtils {
10
+ static serviceAvailabilityStrategies = {
11
+ ['officeOfficialWorkspace']: (features) => features[types_1.ProfileFeature.office]?.googleWorkspace === 'true',
12
+ };
13
+ static getContacts(user) {
14
+ const { phoneNumber, email } = user;
15
+ return {
16
+ title: 'Контактні дані',
17
+ text: this.getContactsText(user),
18
+ phoneNumber,
19
+ email,
20
+ attentionMessage: undefined,
21
+ };
22
+ }
23
+ static getContactsText(user) {
24
+ const { phoneNumber, email, authEntryPoint } = user;
25
+ const { isBankId, target } = authEntryPoint || {};
26
+ const isBankApp = [publicService_1.AuthProviderName.PrivatBank, publicService_1.AuthProviderName.Monobank].includes(target);
27
+ const isAuthorizedWithBank = isBankId || isBankApp;
28
+ if (isAuthorizedWithBank && phoneNumber && email) {
29
+ return isBankId
30
+ ? 'Дані заповнені з вашого BankID. Перевірте їх та виправте за потреби.'
31
+ : 'Дані заповнені з вашого банку. Перевірте їх та виправте за потреби.';
32
+ }
33
+ return 'Будь ласка, заповніть контактні дані.';
34
+ }
35
+ static extractContextMenu(settings, appVersion) {
36
+ const { contextMenu } = settings;
37
+ if (!contextMenu) {
38
+ return contextMenu;
39
+ }
40
+ return applicationUtils_1.ApplicationUtils.filterByAppVersions(contextMenu, appVersion);
41
+ }
42
+ static extractNavigationPanel(settings, appVersion, header) {
43
+ const { name } = settings;
44
+ const contextMenu = this.extractContextMenu(settings, appVersion) ?? [];
45
+ return {
46
+ header: header || name,
47
+ contextMenu,
48
+ };
49
+ }
50
+ static isAvailable(settings, user, platformAppVersion, userFeatures = {}) {
51
+ const { code, status, sessionTypes, profileFeature, platformMinVersion, appVersions } = settings;
52
+ const { sessionType } = user;
53
+ const { platformType, platformVersion, appVersion } = platformAppVersion;
54
+ if (status !== types_1.PublicServiceStatus.active) {
55
+ return false;
56
+ }
57
+ if (!sessionTypes.includes(sessionType)) {
58
+ return false;
59
+ }
60
+ const featuresList = (0, session_1.profileFeaturesToList)(userFeatures);
61
+ if (profileFeature && !featuresList?.includes(profileFeature)) {
62
+ return false;
63
+ }
64
+ const strategy = this.serviceAvailabilityStrategies[code];
65
+ if (strategy && !strategy(userFeatures)) {
66
+ return false;
67
+ }
68
+ const platformMinVersionValue = platformMinVersion?.[platformType];
69
+ if (platformMinVersionValue && (0, compare_versions_1.compare)(platformVersion, platformMinVersionValue, '<')) {
70
+ return false;
71
+ }
72
+ const appVersionsBySession = appVersions?.[sessionType];
73
+ if (!appVersionsBySession) {
74
+ return true;
75
+ }
76
+ return applicationUtils_1.ApplicationUtils.isAppVersionMatch(appVersion, platformType, appVersionsBySession);
77
+ }
78
+ }
79
+ exports.PublicServiceUtils = PublicServiceUtils;
80
+ //# sourceMappingURL=publicService.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"publicService.js","sourceRoot":"","sources":["../src/publicService.ts"],"names":[],"mappings":";;;AAAA,uDAA0C;AAE1C,+CAW4B;AAE5B,yDAAqD;AACrD,8DAA6D;AAC7D,uCAAiD;AAEjD,MAAa,kBAAkB;IACnB,MAAM,CAAU,6BAA6B,GAAiE;QAClH,CAAC,yBAAyB,CAAC,EAAE,CAAC,QAAQ,EAAE,EAAE,CAAC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vD,IAAI,CAAC,oBAAoB,EAAE;YACvB,OAAO,IAAI,CAAA;SACd;QAED,OAAO,mCAAgB,CAAC,iBAAiB,CAAC,UAAU,EAAE,YAAY,EAAE,oBAAoB,CAAC,CAAA;IAC7F,CAAC;;AAlGL,gDAmGC"}
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.extractProfileFeatures = exports.profileFeaturesToList = void 0;
4
+ const types_1 = require("@diia-inhouse/types");
5
+ function profileFeaturesToList(features) {
6
+ const featuresList = Object.entries(features)
7
+ .filter(([, value]) => value)
8
+ .map(([key]) => key);
9
+ return featuresList.filter((feature) => {
10
+ if (feature !== types_1.ProfileFeature.office) {
11
+ return true;
12
+ }
13
+ return features?.[feature]?.status === types_1.DiiaOfficeStatus.ACTIVE;
14
+ });
15
+ }
16
+ exports.profileFeaturesToList = profileFeaturesToList;
17
+ function extractProfileFeatures(session) {
18
+ if (!('features' in session) || !session.features) {
19
+ return [];
20
+ }
21
+ return profileFeaturesToList(session.features);
22
+ }
23
+ exports.extractProfileFeatures = extractProfileFeatures;
24
+ //# sourceMappingURL=session.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"session.js","sourceRoot":"","sources":["../src/session.ts"],"names":[],"mappings":";;;AAAA,+CAAmH;AAEnH,SAAgB,qBAAqB,CAAC,QAAsB;IACxD,MAAM,YAAY,GAAG,MAAM,CAAC,OAAO,CAAC,QAAQ,CAAC;SACxC,MAAM,CAAC,CAAC,CAAC,EAAE,KAAK,CAAC,EAAE,EAAE,CAAC,KAAK,CAAC;SAC5B,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,EAAE,EAAE,CAAiB,GAAG,CAAC,CAAA;IAExC,OAAO,YAAY,CAAC,MAAM,CAAC,CAAC,OAAO,EAAE,EAAE;QACnC,IAAI,OAAO,KAAK,sBAAc,CAAC,MAAM,EAAE;YACnC,OAAO,IAAI,CAAA;SACd;QAED,OAAO,QAAQ,EAAE,CAAC,OAAO,CAAC,EAAE,MAAM,KAAK,wBAAgB,CAAC,MAAM,CAAA;IAClE,CAAC,CAAC,CAAA;AACN,CAAC;AAZD,sDAYC;AAED,SAAgB,sBAAsB,CAAC,OAAuC;IAC1E,IAAI,CAAC,CAAC,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,QAAQ,EAAE;QAC/C,OAAO,EAAE,CAAA;KACZ;IAED,OAAO,qBAAqB,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAA;AAClD,CAAC;AAND,wDAMC"}
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TypeUtils = void 0;
4
+ exports.TypeUtils = {
5
+ isObject(value) {
6
+ return value && typeof value === 'object' && value.constructor === Object;
7
+ },
8
+ isArray(value) {
9
+ return value && typeof value === 'object' && value.constructor === Array;
10
+ },
11
+ isBuffer(value) {
12
+ return value && (value.type === 'Buffer' || Buffer.isBuffer(value));
13
+ },
14
+ };
15
+ //# sourceMappingURL=typeUtils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"typeUtils.js","sourceRoot":"","sources":["../src/typeUtils.ts"],"names":[],"mappings":";;;AAAa,QAAA,SAAS,GAAG;IACrB,QAAQ,CAAC,KAAU;QACf,OAAO,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,CAAC,WAAW,KAAK,MAAM,CAAA;IAC7E,CAAC;IAED,OAAO,CAAC,KAAU;QACd,OAAO,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,CAAC,WAAW,KAAK,KAAK,CAAA;IAC5E,CAAC;IAED,QAAQ,CAAC,KAAU;QACf,OAAO,KAAK,IAAI,CAAC,KAAK,CAAC,IAAI,KAAK,QAAQ,IAAI,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAA;IACvE,CAAC;CACJ,CAAA"}
@@ -0,0 +1,88 @@
1
+ import { ToRelativeUnit } from 'luxon';
2
+ import { ApiError } from '@diia-inhouse/errors';
3
+ import { ActHeaders, ActionSession, ActionVersion, AppVersions, Gender, HashedFile, HashedFileWithSignature, PlatformType, SignedItem, TokenData, Units, UserTokenData, WithAppVersions } from '@diia-inhouse/types';
4
+ export declare class ApplicationUtils {
5
+ private static documentTypeToCamelCaseExceptions;
6
+ private static camelCaseToDocumentTypeExceptions;
7
+ private static defaultItnDate;
8
+ private static defaultFormat;
9
+ private static readonly nameDelimiters;
10
+ private static readonly cyrillicToLatin;
11
+ static documentTypeToCamelCase(documentType: string): string;
12
+ static camelCaseToDocumentType(camelCaseDocumentType: string): string;
13
+ static isItnChecksumValid(itn: string): boolean;
14
+ static getBirthDayFromItn(itn: string): string;
15
+ static getGenderFromItn(itn: string): Gender;
16
+ static isItnFormatValid(itn: string): boolean;
17
+ static capitalizeName(name: string): string;
18
+ static capitalizeFirstLetter(str: string): string;
19
+ static lowerFirstLetter(str: string): string;
20
+ static mapCyrillic(value: string): string;
21
+ static mapLatin(value: string): string;
22
+ static isIbanNumberValid(iban: string): boolean;
23
+ static getStreetName(street: string, streetType: string): string;
24
+ static toHashedFilesWithSignatures(hashedFiles: HashedFile[], signedItems: SignedItem[]): [HashedFileWithSignature[], string[]];
25
+ static handleError<T = never>(err: unknown, cb: (err: ApiError) => T): T;
26
+ static makeSession(data: TokenData): ActionSession;
27
+ static getActionNameWithVersion(actionName: string, actionVersion?: ActionVersion): string;
28
+ static getGreeting(fName: string, skipEmogi?: boolean): string;
29
+ /**
30
+ * Get age from birth date. Powered by {@link https://moment.github.io/luxon/#/ luxon}
31
+ *
32
+ * @param birthDay Input birth date.
33
+ * @param format `birthDay` format (https://moment.github.io/luxon/#/formatting?id=table-of-tokens). Default - 'dd.MM.yyyy'
34
+ * @param unitOfTime Unit of time to return. Default - 'years'
35
+ *
36
+ * @returns Age in years if other `unitOfTime` is not specified
37
+ * @throws If input date is invalid
38
+ */
39
+ static getAge(birthDay: string, format?: string, unitOfTime?: ToRelativeUnit): number;
40
+ static getFullName(lastName: string, firstName: string, middleName?: string, separator?: string): string;
41
+ static getShortName(lastName: string, firstName: string, middleName?: string): string;
42
+ static getUserFullName(user: UserTokenData): string;
43
+ static getPassportFullName({ lastNameUA, firstNameUA, middleNameUA, }: {
44
+ lastNameUA: string;
45
+ firstNameUA: string;
46
+ middleNameUA?: string;
47
+ }): string;
48
+ static getChildFullName({ child: { lastName, firstName, middleName }, }: {
49
+ child: {
50
+ lastName: string;
51
+ firstName: string;
52
+ middleName?: string;
53
+ };
54
+ }): string;
55
+ static encodeObjectToBase64<T>(object: T): string;
56
+ static decodeObjectFromBase64<T>(encodedObject: string): T;
57
+ /**
58
+ * Format string or Date to the specified string format. Powered by {@link https://moment.github.io/luxon/#/ luxon}
59
+ *
60
+ * @param date Input date
61
+ * @param format Output date format (https://moment.github.io/luxon/#/formatting?id=table-of-tokens)
62
+ * @param fromFormat Input date format (https://moment.github.io/luxon/#/formatting?id=table-of-tokens). Used for string `date`. Default - 'dd.MM.yyyy'
63
+ *
64
+ * @throws If input date is invalid
65
+ */
66
+ static formatDate(date: string | Date, format: string, fromFormat?: string): string;
67
+ /**
68
+ * Check if the input date is valid. Powered by {@link https://moment.github.io/luxon/#/ luxon}
69
+ *
70
+ * @param date Input date.
71
+ * @param format `date` format (https://moment.github.io/luxon/#/formatting?id=table-of-tokens). Default - 'yyyy-MM-dd'
72
+ *
73
+ * @throws If input date is invalid
74
+ */
75
+ static validateDate(date: string, format?: string): void | never;
76
+ static formatPhoneNumber(rawPhone: string, separator?: string, prefix?: string): string;
77
+ static formatAmountWithThousandsSeparator(amount: number, units?: Units, minimumFractionDigits?: number): string;
78
+ static convertToPennies(amount: number): number;
79
+ static convertFromPennies(amount: number): number;
80
+ static multiplySum(amount: number, multiplier: number, decimalPlaces?: number): number;
81
+ static toDecimalPlaces(amount: number, decimalPlaces?: number): number;
82
+ static filterByAppVersions<T extends WithAppVersions>(items: T[], headers: Pick<ActHeaders, 'appVersion' | 'platformType'> | undefined): T[];
83
+ static isAppVersionMatch(appVersion: string, platformType: PlatformType, appVersions: AppVersions): boolean;
84
+ static getFileName(name: string, id: string, requestDateTime?: string, postFix?: string): string;
85
+ static sanitizeString(input: string): string;
86
+ private static mod97;
87
+ private static toApiError;
88
+ }
@@ -0,0 +1,2 @@
1
+ import { AssertsContainer } from './interfaces/asserts';
2
+ export declare const Asserts: AssertsContainer;
@@ -0,0 +1,15 @@
1
+ import { ApiError } from '@diia-inhouse/errors';
2
+ import { AcquirerSession, ActionSession, OnBeforeApplicationShutdown, OnDestroy, OnHealthCheck, OnInit, OnRegistrationsFinished, ServiceEntranceSession, UserSession } from '@diia-inhouse/types';
3
+ export declare const Guards: {
4
+ isError(value: unknown): value is Error;
5
+ apiError(err: Error): err is ApiError;
6
+ isUserSession(session: ActionSession | undefined): session is UserSession;
7
+ isAcquirerSession(session: ActionSession | undefined): session is AcquirerSession<import("bson").ObjectId>;
8
+ isServiceEntranceSession(session: ActionSession | undefined): session is ServiceEntranceSession<import("bson").ObjectId>;
9
+ hasOnInitHook(instance: unknown): instance is OnInit;
10
+ hasOnHealthCheckHook(instance: unknown): instance is OnHealthCheck;
11
+ hasOnDestroyHook(instance: unknown): instance is OnDestroy;
12
+ hasOnRegistrationsFinishedHook(instance: unknown): instance is OnRegistrationsFinished;
13
+ hasOnBeforeApplicationShutdownHook(instance: unknown): instance is OnBeforeApplicationShutdown;
14
+ isSettledError(value: PromiseSettledResult<unknown>): value is PromiseRejectedResult;
15
+ };
@@ -0,0 +1,27 @@
1
+ import { ApplicationUtils } from './applicationUtils';
2
+ declare const asserts: import("./interfaces/asserts").AssertsContainer;
3
+ declare const guards: {
4
+ isError(value: unknown): value is Error;
5
+ apiError(err: Error): err is import("@diia-inhouse/errors").ApiError;
6
+ isUserSession(session: import("@diia-inhouse/types").ActionSession | undefined): session is import("@diia-inhouse/types").UserSession;
7
+ isAcquirerSession(session: import("@diia-inhouse/types").ActionSession | undefined): session is import("@diia-inhouse/types").AcquirerSession<import("bson").ObjectId>;
8
+ isServiceEntranceSession(session: import("@diia-inhouse/types").ActionSession | undefined): session is import("@diia-inhouse/types").ServiceEntranceSession<import("bson").ObjectId>;
9
+ hasOnInitHook(instance: unknown): instance is import("@diia-inhouse/types").OnInit;
10
+ hasOnHealthCheckHook(instance: unknown): instance is import("@diia-inhouse/types").OnHealthCheck;
11
+ hasOnDestroyHook(instance: unknown): instance is import("@diia-inhouse/types").OnDestroy;
12
+ hasOnRegistrationsFinishedHook(instance: unknown): instance is import("@diia-inhouse/types").OnRegistrationsFinished;
13
+ hasOnBeforeApplicationShutdownHook(instance: unknown): instance is import("@diia-inhouse/types").OnBeforeApplicationShutdown;
14
+ isSettledError(value: PromiseSettledResult<unknown>): value is PromiseRejectedResult;
15
+ };
16
+ declare const utils: typeof ApplicationUtils;
17
+ declare const pdfUtils: {
18
+ getPdfFileName(name: string, id: string, requestDateTime?: string | undefined): string;
19
+ };
20
+ export { asserts, guards, utils, pdfUtils };
21
+ export { TypeUtils } from './typeUtils';
22
+ export { PaymentUtils } from './payment';
23
+ export { PublicServiceUtils } from './publicService';
24
+ export { phoneticChecker } from './phoneticChecker/index';
25
+ export { NetworkUtils } from './network';
26
+ export { IntegrationUtils } from './integration';
27
+ export * from './session';
@@ -0,0 +1,3 @@
1
+ export declare const IntegrationUtils: {
2
+ getRetryDelay(retry: number, timeLeft: number, initDelay: number, maxDelay: number, multiplier: number): number;
3
+ };
@@ -0,0 +1,5 @@
1
+ import { TokenData, VerifiedBaseTokenData } from '@diia-inhouse/types';
2
+ export interface AssertsContainer {
3
+ isRefreshTokenExists(tokenData: TokenData): asserts tokenData is VerifiedBaseTokenData<TokenData>;
4
+ assertObjectHasOnlyOneOf<T extends object>(object: T, ...keys: (keyof T)[]): void | never;
5
+ }
@@ -0,0 +1,7 @@
1
+ export declare enum AuthProviderName {
2
+ Monobank = "monobank",
3
+ PrivatBank = "privatbank",
4
+ PhotoId = "photoid",
5
+ BankId = "bankid",
6
+ Nfc = "nfc"
7
+ }
@@ -0,0 +1,13 @@
1
+ import { GrpcStatusCode } from '@diia-inhouse/types';
2
+ export declare class NetworkUtils {
3
+ private static readonly grpcStatusCodes;
4
+ private static readonly httpStatusCodeToGrpcCode;
5
+ /**
6
+ * @see https://gist.github.com/hamakn/708b9802ca845eb59f3975dbb3ae2a01
7
+ */
8
+ private static readonly grpcCodeToHttpStatusCode;
9
+ static isHttpCode(code: number | undefined): boolean;
10
+ static isGrpcCode(code: number | undefined): boolean;
11
+ static getHttpStatusCodeByGrpcCode(code: GrpcStatusCode): number;
12
+ static getGrpcCodeByHttpStatusCode(code: number): GrpcStatusCode;
13
+ }
@@ -0,0 +1,5 @@
1
+ export declare class PaymentUtils {
2
+ private static readonly config;
3
+ static getPaymentPayCommission(amount: number): number;
4
+ static getPaymentTotalAmount(amount: number, commission: number): number;
5
+ }
@@ -0,0 +1,3 @@
1
+ export declare const PdfUtils: {
2
+ getPdfFileName(name: string, id: string, requestDateTime?: string): string;
3
+ };
@@ -0,0 +1,6 @@
1
+ declare class PhoneticChecker {
2
+ getEqualityCoefficient(etalonValue: string, slaveValue: string): number;
3
+ private getLevenshteinDistance;
4
+ }
5
+ export declare const phoneticChecker: PhoneticChecker;
6
+ export {};
@@ -0,0 +1,6 @@
1
+ declare class Metaphone {
2
+ process(word: string): string;
3
+ private modifyOperation;
4
+ }
5
+ export declare const metaphone: Metaphone;
6
+ export {};
@@ -0,0 +1,9 @@
1
+ import { AppUser, ContactsResponse, NavigationPanel, PlatformAppVersion, PublicServiceContextMenu, PublicServiceSettings, UserFeatures, UserTokenData } from '@diia-inhouse/types';
2
+ export declare class PublicServiceUtils {
3
+ private static readonly serviceAvailabilityStrategies;
4
+ static getContacts(user: UserTokenData): ContactsResponse;
5
+ static getContactsText(user: UserTokenData): string;
6
+ static extractContextMenu(settings: PublicServiceSettings, appVersion: PlatformAppVersion | undefined): PublicServiceContextMenu[] | undefined;
7
+ static extractNavigationPanel(settings: PublicServiceSettings, appVersion: PlatformAppVersion | undefined, header?: string): NavigationPanel | undefined;
8
+ static isAvailable(settings: PublicServiceSettings, user: AppUser, platformAppVersion: PlatformAppVersion, userFeatures?: UserFeatures): boolean;
9
+ }
@@ -0,0 +1,3 @@
1
+ import { EResidentSession, ProfileFeature, UserFeatures, UserSession } from '@diia-inhouse/types';
2
+ export declare function profileFeaturesToList(features: UserFeatures): ProfileFeature[];
3
+ export declare function extractProfileFeatures(session: UserSession | EResidentSession): ProfileFeature[];
@@ -0,0 +1,5 @@
1
+ export declare const TypeUtils: {
2
+ isObject(value: any): boolean;
3
+ isArray(value: any): boolean;
4
+ isBuffer(value: any): boolean;
5
+ };
package/package.json ADDED
@@ -0,0 +1,95 @@
1
+ {
2
+ "name": "@diia-inhouse/utils",
3
+ "version": "3.5.0",
4
+ "description": "Generic utils",
5
+ "main": "dist/index.js",
6
+ "types": "dist/types/index.d.ts",
7
+ "repository": "https://github.com/diia-open-source/be-pkg-utils.git",
8
+ "author": "Diia",
9
+ "license": "SEE LICENSE IN LICENSE.md",
10
+ "files": [
11
+ "dist"
12
+ ],
13
+ "engines": {
14
+ "node": ">=18"
15
+ },
16
+ "scripts": {
17
+ "prebuild": "rimraf dist",
18
+ "build": "tsc",
19
+ "semantic-release": "semantic-release",
20
+ "start": "npm run build && node dist/index.js",
21
+ "lint": "eslint --ext .ts . && prettier --check .",
22
+ "lint-fix": "eslint '*/**/*.{js,ts}' --fix && prettier --write .",
23
+ "lint:lockfile": "lockfile-lint --path package-lock.json --allowed-hosts registry.npmjs.org --validate-https",
24
+ "prepare": "npm run build",
25
+ "test": "jest",
26
+ "test:unit": "npm run test --selectProjects unit --",
27
+ "test:coverage": "npm run test --selectProjects unit --coverage",
28
+ "find-circulars": "madge --circular --extensions ts ./"
29
+ },
30
+ "dependencies": {
31
+ "@types/luxon": "3.4.2",
32
+ "bson": "6.2.0",
33
+ "compare-versions": "6.1.0",
34
+ "fast-levenshtein": "3.0.0",
35
+ "lodash": "4.17.21",
36
+ "luxon": "3.4.4",
37
+ "moment": "2.30.1"
38
+ },
39
+ "peerDependencies": {
40
+ "@diia-inhouse/errors": ">=1.4.1",
41
+ "@diia-inhouse/types": ">=4.4.1",
42
+ "@diia-inhouse/validators": ">=1.5.0"
43
+ },
44
+ "devDependencies": {
45
+ "@diia-inhouse/configs": "1.31.1",
46
+ "@diia-inhouse/errors": "1.9.0",
47
+ "@diia-inhouse/eslint-config": "5.1.0",
48
+ "@diia-inhouse/test": "6.3.0",
49
+ "@diia-inhouse/types": "6.24.0",
50
+ "@diia-inhouse/validators": "1.17.0",
51
+ "@types/fast-levenshtein": "0.0.4",
52
+ "@types/lodash": "4.17.0",
53
+ "@types/node": "20.11.24",
54
+ "@typescript-eslint/typescript-estree": "7.0.1",
55
+ "lockfile-lint": "4.13.2",
56
+ "madge": "6.1.0",
57
+ "protobufjs": "7.2.6",
58
+ "rimraf": "5.0.5"
59
+ },
60
+ "release": {
61
+ "extends": "@diia-inhouse/configs/dist/semantic-release/package",
62
+ "branches": [
63
+ "main"
64
+ ]
65
+ },
66
+ "commitlint": {
67
+ "extends": "@diia-inhouse/configs/dist/commitlint"
68
+ },
69
+ "eslintConfig": {
70
+ "extends": "@diia-inhouse/eslint-config",
71
+ "rules": {
72
+ "@typescript-eslint/no-explicit-any": "warn"
73
+ },
74
+ "overrides": [
75
+ {
76
+ "files": [
77
+ "*.ts"
78
+ ],
79
+ "parserOptions": {
80
+ "project": [
81
+ "./tsconfig.json",
82
+ "./tests/tsconfig.json"
83
+ ]
84
+ }
85
+ }
86
+ ]
87
+ },
88
+ "jest": {
89
+ "preset": "@diia-inhouse/configs/dist/jest"
90
+ },
91
+ "prettier": "@diia-inhouse/eslint-config/prettier",
92
+ "madge": {
93
+ "tsConfig": "./tsconfig.json"
94
+ }
95
+ }