@diia-inhouse/test 7.3.23 → 8.0.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 (68) hide show
  1. package/dist/dbUtilsBuilder.d.ts +29 -0
  2. package/dist/dbUtilsBuilder.js +81 -114
  3. package/dist/documentsGenerator.d.ts +8 -0
  4. package/dist/documentsGenerator.js +14 -21
  5. package/dist/index.d.ts +16 -0
  6. package/dist/index.js +19 -27
  7. package/dist/interfaces/index.d.ts +6 -0
  8. package/dist/publicServiceGenerator.d.ts +9 -0
  9. package/dist/publicServiceGenerator.js +25 -23
  10. package/dist/randomGenerator.d.ts +7 -0
  11. package/dist/randomGenerator.js +14 -18
  12. package/dist/sessionGenerator.d.ts +37 -0
  13. package/dist/sessionGenerator.js +340 -335
  14. package/dist/stubs/documents/index.js +13 -16
  15. package/package.json +28 -31
  16. package/vitest/extend-expect.ts +1 -2
  17. package/vitest/matchers/toBeDesignSystemElement/index.ts +1 -1
  18. package/vitest/tsconfig.json +1 -0
  19. package/dist/dbUtilsBuilder.js.map +0 -1
  20. package/dist/documentsGenerator.js.map +0 -1
  21. package/dist/index.js.map +0 -1
  22. package/dist/interfaces/documents/driverLicense.js +0 -63
  23. package/dist/interfaces/documents/driverLicense.js.map +0 -1
  24. package/dist/interfaces/documents/foreignPassport.js +0 -20
  25. package/dist/interfaces/documents/foreignPassport.js.map +0 -1
  26. package/dist/interfaces/documents/index.js +0 -40
  27. package/dist/interfaces/documents/index.js.map +0 -1
  28. package/dist/interfaces/documents/internalPassport.js +0 -19
  29. package/dist/interfaces/documents/internalPassport.js.map +0 -1
  30. package/dist/interfaces/documents/taxpayerCard.js +0 -3
  31. package/dist/interfaces/documents/taxpayerCard.js.map +0 -1
  32. package/dist/interfaces/index.js +0 -3
  33. package/dist/interfaces/index.js.map +0 -1
  34. package/dist/publicServiceGenerator.js.map +0 -1
  35. package/dist/randomGenerator.js.map +0 -1
  36. package/dist/sessionGenerator.js.map +0 -1
  37. package/dist/stubs/documents/driverLicense.js +0 -233
  38. package/dist/stubs/documents/driverLicense.js.map +0 -1
  39. package/dist/stubs/documents/foreignPassport.js +0 -63
  40. package/dist/stubs/documents/foreignPassport.js.map +0 -1
  41. package/dist/stubs/documents/index.js.map +0 -1
  42. package/dist/stubs/documents/internalPassport.js +0 -59
  43. package/dist/stubs/documents/internalPassport.js.map +0 -1
  44. package/dist/stubs/documents/taxpayerCard.js +0 -20
  45. package/dist/stubs/documents/taxpayerCard.js.map +0 -1
  46. package/dist/stubs/photo.js +0 -5
  47. package/dist/stubs/photo.js.map +0 -1
  48. package/dist/stubs/signature.js +0 -5
  49. package/dist/stubs/signature.js.map +0 -1
  50. package/dist/types/dbUtilsBuilder.d.ts +0 -29
  51. package/dist/types/documentsGenerator.d.ts +0 -4
  52. package/dist/types/index.d.ts +0 -13
  53. package/dist/types/interfaces/documents/driverLicense.d.ts +0 -120
  54. package/dist/types/interfaces/documents/foreignPassport.d.ts +0 -87
  55. package/dist/types/interfaces/documents/index.d.ts +0 -82
  56. package/dist/types/interfaces/documents/internalPassport.d.ts +0 -49
  57. package/dist/types/interfaces/documents/taxpayerCard.d.ts +0 -17
  58. package/dist/types/interfaces/index.d.ts +0 -7
  59. package/dist/types/publicServiceGenerator.d.ts +0 -5
  60. package/dist/types/randomGenerator.d.ts +0 -4
  61. package/dist/types/sessionGenerator.d.ts +0 -33
  62. package/dist/types/stubs/documents/driverLicense.d.ts +0 -3
  63. package/dist/types/stubs/documents/foreignPassport.d.ts +0 -3
  64. package/dist/types/stubs/documents/index.d.ts +0 -2
  65. package/dist/types/stubs/documents/internalPassport.d.ts +0 -3
  66. package/dist/types/stubs/documents/taxpayerCard.d.ts +0 -3
  67. package/dist/types/stubs/photo.d.ts +0 -2
  68. package/dist/types/stubs/signature.d.ts +0 -2
@@ -1,335 +1,340 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const node_crypto_1 = require("node:crypto");
4
- const bson_1 = require("bson");
5
- const luxon_1 = require("luxon");
6
- const types_1 = require("@diia-inhouse/types");
7
- class SessionGenerator {
8
- random;
9
- dateFormat = 'dd.MM.yyyy';
10
- constructor(random) {
11
- this.random = random;
12
- }
13
- getUserActionArguments(user = {}, headers = {}, ops = {}) {
14
- return {
15
- session: this.getUserSession(user, ops.validItn),
16
- headers: this.getHeaders(headers),
17
- params: [],
18
- };
19
- }
20
- getAuthEntryPoint(authEntryPoint = {}) {
21
- return {
22
- target: 'bankid',
23
- isBankId: true,
24
- bankName: 'diia bank',
25
- document: types_1.AuthDocumentType.ForeignPassport,
26
- ...authEntryPoint,
27
- };
28
- }
29
- getUserSession(tokenData = {}, validItn = false) {
30
- const sessionType = types_1.SessionType.User;
31
- const userData = this.getUserData(tokenData, validItn);
32
- const { itn } = userData;
33
- const result = {
34
- ...userData,
35
- mobileUid: (0, node_crypto_1.randomUUID)(),
36
- document: { type: types_1.AuthDocumentType.ForeignPassport, value: '12345' },
37
- sessionType,
38
- identifier: this.createIdentifier(itn),
39
- authEntryPoint: this.getAuthEntryPoint(),
40
- refreshToken: {
41
- value: (0, node_crypto_1.randomUUID)(),
42
- expirationTime: Date.now() + 300000,
43
- },
44
- ...tokenData,
45
- };
46
- return { sessionType, user: result };
47
- }
48
- getDiiaOfficeUserSession(tokenData = {}, validItn = false, features = {}) {
49
- return {
50
- ...this.getUserSession(tokenData, validItn),
51
- features: {
52
- [types_1.ProfileFeature.office]: {
53
- officeIdentifier: (0, node_crypto_1.randomUUID)(),
54
- profileId: (0, node_crypto_1.randomUUID)(),
55
- organizationId: (0, node_crypto_1.randomUUID)(),
56
- unitId: (0, node_crypto_1.randomUUID)(),
57
- isOrganizationAdmin: false,
58
- scopes: ['auth'],
59
- status: types_1.DiiaOfficeStatus.ACTIVE,
60
- tokenFailedAt: undefined,
61
- },
62
- ...features,
63
- },
64
- };
65
- }
66
- getEResidentSession(tokenData = {}, validItn = false) {
67
- const sessionType = types_1.SessionType.EResident;
68
- const userData = this.getUserData(tokenData, validItn);
69
- const { itn } = userData;
70
- const result = {
71
- ...userData,
72
- mobileUid: (0, node_crypto_1.randomUUID)(),
73
- document: { type: types_1.AuthDocumentType.EResidency, value: '12345' },
74
- sessionType,
75
- identifier: this.createIdentifier(itn, { prefix: types_1.IdentifierPrefix.EResident }),
76
- authEntryPoint: this.getAuthEntryPoint(),
77
- refreshToken: {
78
- value: (0, node_crypto_1.randomUUID)(),
79
- expirationTime: Date.now() + 300000,
80
- },
81
- ...tokenData,
82
- };
83
- return { sessionType, user: result };
84
- }
85
- getEResidentApplicantSession(tokenData = {}) {
86
- const email = tokenData.email || 'eresident-applicant@mail.com';
87
- const sessionType = types_1.SessionType.EResidentApplicant;
88
- const result = {
89
- email,
90
- sessionType,
91
- document: { type: types_1.AuthDocumentType.EResidentApplicantEmail, value: email },
92
- mobileUid: (0, node_crypto_1.randomUUID)(),
93
- identifier: this.createIdentifier(email, { prefix: types_1.IdentifierPrefix.EResidentApplicant }),
94
- authEntryPoint: this.getAuthEntryPoint(),
95
- refreshToken: {
96
- value: (0, node_crypto_1.randomUUID)(),
97
- expirationTime: Date.now() + 300000,
98
- },
99
- ...tokenData,
100
- };
101
- return { sessionType, user: result };
102
- }
103
- /** @deprecated use getAcquirerSessionStringId after diia-app v15 */
104
- getAcquirerSession(tokenData = {}) {
105
- const sessionType = types_1.SessionType.Acquirer;
106
- const result = {
107
- sessionType,
108
- refreshToken: {
109
- value: (0, node_crypto_1.randomUUID)(),
110
- expirationTime: Date.now() + 300000,
111
- },
112
- _id: new bson_1.ObjectId().toString(),
113
- ...tokenData,
114
- };
115
- return { sessionType, acquirer: result };
116
- }
117
- getAcquirerSessionStringId(tokenData = {}) {
118
- const sessionType = types_1.SessionType.Acquirer;
119
- const result = {
120
- sessionType,
121
- refreshToken: {
122
- value: (0, node_crypto_1.randomUUID)(),
123
- expirationTime: Date.now() + 300000,
124
- },
125
- _id: new bson_1.ObjectId().toString(),
126
- ...tokenData,
127
- };
128
- return { sessionType, acquirer: result };
129
- }
130
- /** @deprecated use getPartnerSessionStringId after diia-app v15 */
131
- getPartnerSession(tokenData = {}) {
132
- const sessionType = types_1.SessionType.Partner;
133
- const result = {
134
- _id: new bson_1.ObjectId().toString(),
135
- scopes: {},
136
- sessionType,
137
- refreshToken: {
138
- value: (0, node_crypto_1.randomUUID)(),
139
- expirationTime: Date.now() + 300000,
140
- },
141
- ...tokenData,
142
- };
143
- return { sessionType, partner: result };
144
- }
145
- getPartnerSessionStringId(tokenData = {}) {
146
- const sessionType = types_1.SessionType.Partner;
147
- const result = {
148
- _id: new bson_1.ObjectId().toString(),
149
- scopes: {},
150
- sessionType,
151
- refreshToken: {
152
- value: (0, node_crypto_1.randomUUID)(),
153
- expirationTime: Date.now() + 300000,
154
- },
155
- ...tokenData,
156
- };
157
- return { sessionType, partner: result };
158
- }
159
- getTemporarySession(tokenData = {}) {
160
- const sessionType = types_1.SessionType.Temporary;
161
- const result = {
162
- sessionType,
163
- refreshToken: {
164
- value: (0, node_crypto_1.randomUUID)(),
165
- expirationTime: Date.now() + 300000,
166
- },
167
- mobileUid: (0, node_crypto_1.randomUUID)(),
168
- jti: (0, node_crypto_1.randomUUID)(),
169
- scope: [],
170
- ...tokenData,
171
- };
172
- return { sessionType, temporary: result };
173
- }
174
- getServiceEntranceSession(tokenData = {}) {
175
- const sessionType = types_1.SessionType.ServiceEntrance;
176
- const result = {
177
- acquirerId: new bson_1.ObjectId().toString(),
178
- branchHashId: (0, node_crypto_1.randomUUID)(),
179
- offerHashId: (0, node_crypto_1.randomUUID)(),
180
- offerRequestHashId: (0, node_crypto_1.randomUUID)(),
181
- mobileUid: (0, node_crypto_1.randomUUID)(),
182
- sessionType,
183
- refreshToken: {
184
- value: (0, node_crypto_1.randomUUID)(),
185
- expirationTime: Date.now() + 300000,
186
- },
187
- ...tokenData,
188
- };
189
- return { sessionType, entrance: result };
190
- }
191
- getPortalUserSession(tokenData = {}, validItn = false) {
192
- const sessionType = types_1.SessionType.PortalUser;
193
- const birthDate = tokenData.birthDay || this.getBirthDate();
194
- const gender = this.getGender();
195
- const itn = this.generateItn(birthDate, gender, validItn);
196
- const result = {
197
- sessionType,
198
- refreshToken: {
199
- value: (0, node_crypto_1.randomUUID)(),
200
- expirationTime: Date.now() + 300000,
201
- },
202
- fName: 'Дія',
203
- lName: 'Надія',
204
- mName: 'Володимирівна',
205
- itn,
206
- birthDay: birthDate,
207
- identifier: (0, node_crypto_1.randomUUID)(),
208
- ...tokenData,
209
- };
210
- return { sessionType, user: result };
211
- }
212
- getServiceUserSession(tokenData = {}) {
213
- const sessionType = types_1.SessionType.ServiceUser;
214
- const result = {
215
- sessionType,
216
- refreshToken: {
217
- value: (0, node_crypto_1.randomUUID)(),
218
- expirationTime: Date.now() + 300000,
219
- },
220
- login: 'test-login',
221
- ...tokenData,
222
- };
223
- return { sessionType, serviceUser: result };
224
- }
225
- getSessionBySessionType(sessionType, tokenData = {}, validItn = false) {
226
- switch (sessionType) {
227
- case types_1.SessionType.Acquirer: {
228
- return this.getAcquirerSession(tokenData);
229
- }
230
- case types_1.SessionType.EResident: {
231
- return this.getEResidentSession(tokenData, validItn);
232
- }
233
- case types_1.SessionType.EResidentApplicant: {
234
- return this.getEResidentApplicantSession(tokenData);
235
- }
236
- case types_1.SessionType.Partner: {
237
- return this.getPartnerSession(tokenData);
238
- }
239
- case types_1.SessionType.PortalUser: {
240
- return this.getPortalUserSession(tokenData, validItn);
241
- }
242
- case types_1.SessionType.ServiceEntrance: {
243
- return this.getServiceEntranceSession(tokenData);
244
- }
245
- case types_1.SessionType.ServiceUser: {
246
- return this.getServiceUserSession(tokenData);
247
- }
248
- case types_1.SessionType.Temporary: {
249
- return this.getTemporarySession(tokenData);
250
- }
251
- case types_1.SessionType.User: {
252
- return this.getUserSession(tokenData, validItn);
253
- }
254
- default: {
255
- return undefined;
256
- }
257
- }
258
- }
259
- getHeaders(headers = {}) {
260
- return {
261
- mobileUid: (0, node_crypto_1.randomUUID)(),
262
- traceId: (0, node_crypto_1.randomUUID)(),
263
- token: (0, node_crypto_1.randomUUID)(),
264
- platformType: types_1.PlatformType.Android,
265
- platformVersion: '13',
266
- appVersion: '3.0.55.981',
267
- actionVersion: types_1.ActionVersion.V3,
268
- ...headers,
269
- };
270
- }
271
- getBirthDate() {
272
- const fromDate = luxon_1.DateTime.fromFormat('31.12.1899', this.dateFormat);
273
- const untilDate = luxon_1.DateTime.fromFormat('14.12.2004', this.dateFormat);
274
- const interval = luxon_1.Interval.fromDateTimes(fromDate, untilDate);
275
- const randomDay = this.random.getRandomInt(0, interval.length('days'));
276
- return fromDate.plus({ days: randomDay }).toFormat(this.dateFormat);
277
- }
278
- getGender() {
279
- return this.random.getRandomInt(0, 1) === 0 ? types_1.Gender.male : types_1.Gender.female;
280
- }
281
- generateItn(birthDate, gender, validItn) {
282
- if (!validItn) {
283
- return Math.floor(Math.random() * 10000000000).toString();
284
- }
285
- const fromDate = luxon_1.DateTime.fromFormat('31.12.1899', this.dateFormat);
286
- const interval = luxon_1.Interval.fromDateTimes(fromDate, luxon_1.DateTime.fromFormat(birthDate, this.dateFormat));
287
- const firstPart = interval.length('days').toString().padStart(5, '0');
288
- const secondPart = this.getItnSeqNumber(gender).toString().padStart(4, '0');
289
- const baseNumber = firstPart.concat(secondPart);
290
- const [a, b, c, d, e, f, g, h, i] = baseNumber.split('').map((item) => Number.parseInt(item, 10));
291
- const checksum = -a + 5 * b + 7 * c + 9 * d + 4 * e + 6 * f + 10 * g + 5 * h + 7 * i;
292
- const controlNumber = (checksum - 11 * Math.floor(checksum / 11)) % 10;
293
- return baseNumber.concat(controlNumber.toString());
294
- }
295
- getUserData(tokenData = {}, validItn = false) {
296
- const birthDate = tokenData.birthDay || this.getBirthDate();
297
- const gender = tokenData.gender || this.getGender();
298
- const itn = this.generateItn(birthDate, gender, validItn);
299
- return {
300
- itn,
301
- gender,
302
- fName: 'Надія',
303
- lName: 'Дія',
304
- mName: 'Володимирівна',
305
- phoneNumber: '+380999999999',
306
- email: 'test@test.com',
307
- passport: '12345',
308
- document: { type: types_1.AuthDocumentType.ForeignPassport, value: '12345' },
309
- birthDay: birthDate,
310
- addressOfRegistration: '',
311
- addressOfBirth: '',
312
- ...tokenData,
313
- };
314
- }
315
- getItnSeqNumber(gender) {
316
- const seqNumber = this.random.getRandomInt(1, 9998);
317
- const isOdd = this.isOdd(seqNumber);
318
- if (isOdd) {
319
- return gender === types_1.Gender.male ? seqNumber : seqNumber + 1;
320
- }
321
- return gender === types_1.Gender.male ? seqNumber + 1 : seqNumber;
322
- }
323
- isOdd(number) {
324
- return number % 2 === 1;
325
- }
326
- createIdentifier(itn, ops = {}) {
327
- const { customSalt, prefix = '' } = ops;
328
- const hmac = (0, node_crypto_1.createHmac)('sha512', customSalt || 'salt');
329
- hmac.update(itn);
330
- const hash = hmac.digest('hex');
331
- return `${prefix}${hash}`;
332
- }
333
- }
334
- exports.default = SessionGenerator;
335
- //# sourceMappingURL=sessionGenerator.js.map
1
+ import { createHmac, randomInt, randomUUID } from "node:crypto";
2
+ import { ObjectId } from "bson";
3
+ import { DateTime, Interval } from "luxon";
4
+ import { ActionVersion, AuthDocumentType, DiiaOfficeStatus, Gender, IdentifierPrefix, PlatformType, ProfileFeature, SessionType } from "@diia-inhouse/types";
5
+ //#region src/sessionGenerator.ts
6
+ var SessionGenerator = class {
7
+ random;
8
+ dateFormat = "dd.MM.yyyy";
9
+ constructor(random) {
10
+ this.random = random;
11
+ }
12
+ getUserActionArguments(user = {}, headers = {}, ops = {}) {
13
+ return {
14
+ session: this.getUserSession(user, ops.validItn),
15
+ headers: this.getHeaders(headers),
16
+ params: []
17
+ };
18
+ }
19
+ getAuthEntryPoint(authEntryPoint = {}) {
20
+ return {
21
+ target: "bankid",
22
+ isBankId: true,
23
+ bankName: "diia bank",
24
+ document: AuthDocumentType.ForeignPassport,
25
+ ...authEntryPoint
26
+ };
27
+ }
28
+ getUserSession(tokenData = {}, validItn = false) {
29
+ const sessionType = SessionType.User;
30
+ const userData = this.getUserData(tokenData, validItn);
31
+ const { itn } = userData;
32
+ return {
33
+ sessionType,
34
+ user: {
35
+ ...userData,
36
+ mobileUid: randomUUID(),
37
+ document: {
38
+ type: AuthDocumentType.ForeignPassport,
39
+ value: "12345"
40
+ },
41
+ sessionType,
42
+ identifier: this.createIdentifier(itn),
43
+ authEntryPoint: this.getAuthEntryPoint(),
44
+ refreshToken: {
45
+ value: randomUUID(),
46
+ expirationTime: Date.now() + 3e5
47
+ },
48
+ ...tokenData
49
+ }
50
+ };
51
+ }
52
+ getDiiaOfficeUserSession(tokenData = {}, validItn = false, features = {}) {
53
+ return {
54
+ ...this.getUserSession(tokenData, validItn),
55
+ features: {
56
+ [ProfileFeature.office]: {
57
+ officeIdentifier: randomUUID(),
58
+ profileId: randomUUID(),
59
+ organizationId: randomUUID(),
60
+ unitId: randomUUID(),
61
+ isOrganizationAdmin: false,
62
+ scopes: ["auth"],
63
+ status: DiiaOfficeStatus.ACTIVE,
64
+ tokenFailedAt: void 0
65
+ },
66
+ ...features
67
+ }
68
+ };
69
+ }
70
+ getEResidentSession(tokenData = {}, validItn = false) {
71
+ const sessionType = SessionType.EResident;
72
+ const userData = this.getUserData(tokenData, validItn);
73
+ const { itn } = userData;
74
+ return {
75
+ sessionType,
76
+ user: {
77
+ ...userData,
78
+ mobileUid: randomUUID(),
79
+ document: {
80
+ type: AuthDocumentType.EResidency,
81
+ value: "12345"
82
+ },
83
+ sessionType,
84
+ identifier: this.createIdentifier(itn, { prefix: IdentifierPrefix.EResident }),
85
+ authEntryPoint: this.getAuthEntryPoint(),
86
+ refreshToken: {
87
+ value: randomUUID(),
88
+ expirationTime: Date.now() + 3e5
89
+ },
90
+ ...tokenData
91
+ }
92
+ };
93
+ }
94
+ getEResidentApplicantSession(tokenData = {}) {
95
+ const email = tokenData.email || "eresident-applicant@mail.com";
96
+ const sessionType = SessionType.EResidentApplicant;
97
+ return {
98
+ sessionType,
99
+ user: {
100
+ email,
101
+ sessionType,
102
+ document: {
103
+ type: AuthDocumentType.EResidentApplicantEmail,
104
+ value: email
105
+ },
106
+ mobileUid: randomUUID(),
107
+ identifier: this.createIdentifier(email, { prefix: IdentifierPrefix.EResidentApplicant }),
108
+ authEntryPoint: this.getAuthEntryPoint(),
109
+ refreshToken: {
110
+ value: randomUUID(),
111
+ expirationTime: Date.now() + 3e5
112
+ },
113
+ ...tokenData
114
+ }
115
+ };
116
+ }
117
+ /** @deprecated use getAcquirerSessionStringId after diia-app v15 */
118
+ getAcquirerSession(tokenData = {}) {
119
+ const sessionType = SessionType.Acquirer;
120
+ return {
121
+ sessionType,
122
+ acquirer: {
123
+ sessionType,
124
+ refreshToken: {
125
+ value: randomUUID(),
126
+ expirationTime: Date.now() + 3e5
127
+ },
128
+ _id: new ObjectId().toString(),
129
+ ...tokenData
130
+ }
131
+ };
132
+ }
133
+ getAcquirerSessionStringId(tokenData = {}) {
134
+ const sessionType = SessionType.Acquirer;
135
+ return {
136
+ sessionType,
137
+ acquirer: {
138
+ sessionType,
139
+ refreshToken: {
140
+ value: randomUUID(),
141
+ expirationTime: Date.now() + 3e5
142
+ },
143
+ _id: new ObjectId().toString(),
144
+ ...tokenData
145
+ }
146
+ };
147
+ }
148
+ /** @deprecated use getPartnerSessionStringId after diia-app v15 */
149
+ getPartnerSession(tokenData = {}) {
150
+ const sessionType = SessionType.Partner;
151
+ return {
152
+ sessionType,
153
+ partner: {
154
+ _id: new ObjectId().toString(),
155
+ scopes: {},
156
+ sessionType,
157
+ refreshToken: {
158
+ value: randomUUID(),
159
+ expirationTime: Date.now() + 3e5
160
+ },
161
+ ...tokenData
162
+ }
163
+ };
164
+ }
165
+ getPartnerSessionStringId(tokenData = {}) {
166
+ const sessionType = SessionType.Partner;
167
+ return {
168
+ sessionType,
169
+ partner: {
170
+ _id: new ObjectId().toString(),
171
+ scopes: {},
172
+ sessionType,
173
+ refreshToken: {
174
+ value: randomUUID(),
175
+ expirationTime: Date.now() + 3e5
176
+ },
177
+ ...tokenData
178
+ }
179
+ };
180
+ }
181
+ getTemporarySession(tokenData = {}) {
182
+ const sessionType = SessionType.Temporary;
183
+ return {
184
+ sessionType,
185
+ temporary: {
186
+ sessionType,
187
+ refreshToken: {
188
+ value: randomUUID(),
189
+ expirationTime: Date.now() + 3e5
190
+ },
191
+ mobileUid: randomUUID(),
192
+ jti: randomUUID(),
193
+ scope: [],
194
+ ...tokenData
195
+ }
196
+ };
197
+ }
198
+ getServiceEntranceSession(tokenData = {}) {
199
+ const sessionType = SessionType.ServiceEntrance;
200
+ return {
201
+ sessionType,
202
+ entrance: {
203
+ acquirerId: new ObjectId().toString(),
204
+ branchHashId: randomUUID(),
205
+ offerHashId: randomUUID(),
206
+ offerRequestHashId: randomUUID(),
207
+ mobileUid: randomUUID(),
208
+ sessionType,
209
+ refreshToken: {
210
+ value: randomUUID(),
211
+ expirationTime: Date.now() + 3e5
212
+ },
213
+ ...tokenData
214
+ }
215
+ };
216
+ }
217
+ getPortalUserSession(tokenData = {}, validItn = false) {
218
+ const sessionType = SessionType.PortalUser;
219
+ const birthDate = tokenData.birthDay || this.getBirthDate();
220
+ const gender = this.getGender();
221
+ const itn = this.generateItn(birthDate, gender, validItn);
222
+ return {
223
+ sessionType,
224
+ user: {
225
+ sessionType,
226
+ refreshToken: {
227
+ value: randomUUID(),
228
+ expirationTime: Date.now() + 3e5
229
+ },
230
+ fName: "Дія",
231
+ lName: "Надія",
232
+ mName: "Володимирівна",
233
+ itn,
234
+ birthDay: birthDate,
235
+ identifier: randomUUID(),
236
+ ...tokenData
237
+ }
238
+ };
239
+ }
240
+ getServiceUserSession(tokenData = {}) {
241
+ const sessionType = SessionType.ServiceUser;
242
+ return {
243
+ sessionType,
244
+ serviceUser: {
245
+ sessionType,
246
+ refreshToken: {
247
+ value: randomUUID(),
248
+ expirationTime: Date.now() + 3e5
249
+ },
250
+ login: "test-login",
251
+ ...tokenData
252
+ }
253
+ };
254
+ }
255
+ getSessionBySessionType(sessionType, tokenData = {}, validItn = false) {
256
+ switch (sessionType) {
257
+ case SessionType.Acquirer: return this.getAcquirerSession(tokenData);
258
+ case SessionType.EResident: return this.getEResidentSession(tokenData, validItn);
259
+ case SessionType.EResidentApplicant: return this.getEResidentApplicantSession(tokenData);
260
+ case SessionType.Partner: return this.getPartnerSession(tokenData);
261
+ case SessionType.PortalUser: return this.getPortalUserSession(tokenData, validItn);
262
+ case SessionType.ServiceEntrance: return this.getServiceEntranceSession(tokenData);
263
+ case SessionType.ServiceUser: return this.getServiceUserSession(tokenData);
264
+ case SessionType.Temporary: return this.getTemporarySession(tokenData);
265
+ case SessionType.User: return this.getUserSession(tokenData, validItn);
266
+ default: return;
267
+ }
268
+ }
269
+ getHeaders(headers = {}) {
270
+ return {
271
+ mobileUid: randomUUID(),
272
+ traceId: randomUUID(),
273
+ token: randomUUID(),
274
+ platformType: PlatformType.Android,
275
+ platformVersion: "13",
276
+ appVersion: "3.0.55.981",
277
+ actionVersion: ActionVersion.V3,
278
+ ...headers
279
+ };
280
+ }
281
+ getBirthDate() {
282
+ const fromDate = DateTime.fromFormat("31.12.1899", this.dateFormat);
283
+ const untilDate = DateTime.fromFormat("14.12.2004", this.dateFormat);
284
+ const interval = Interval.fromDateTimes(fromDate, untilDate);
285
+ const randomDay = this.random.getRandomInt(0, interval.length("days"));
286
+ return fromDate.plus({ days: randomDay }).toFormat(this.dateFormat);
287
+ }
288
+ getGender() {
289
+ return this.random.getRandomInt(0, 1) === 0 ? Gender.male : Gender.female;
290
+ }
291
+ generateItn(birthDate, gender, validItn) {
292
+ if (!validItn) return randomInt(1e10).toString();
293
+ const fromDate = DateTime.fromFormat("31.12.1899", this.dateFormat);
294
+ const firstPart = Interval.fromDateTimes(fromDate, DateTime.fromFormat(birthDate, this.dateFormat)).length("days").toString().padStart(5, "0");
295
+ const secondPart = this.getItnSeqNumber(gender).toString().padStart(4, "0");
296
+ const baseNumber = firstPart.concat(secondPart);
297
+ const [a, b, c, d, e, f, g, h, i] = baseNumber.split("").map((item) => Number.parseInt(item, 10));
298
+ const checksum = -a + 5 * b + 7 * c + 9 * d + 4 * e + 6 * f + 10 * g + 5 * h + 7 * i;
299
+ const controlNumber = (checksum - 11 * Math.floor(checksum / 11)) % 10;
300
+ return baseNumber.concat(controlNumber.toString());
301
+ }
302
+ getUserData(tokenData = {}, validItn = false) {
303
+ const birthDate = tokenData.birthDay || this.getBirthDate();
304
+ const gender = tokenData.gender || this.getGender();
305
+ return {
306
+ itn: this.generateItn(birthDate, gender, validItn),
307
+ gender,
308
+ fName: "Надія",
309
+ lName: "Дія",
310
+ mName: "Володимирівна",
311
+ phoneNumber: "+380999999999",
312
+ email: "test@test.com",
313
+ passport: "12345",
314
+ document: {
315
+ type: AuthDocumentType.ForeignPassport,
316
+ value: "12345"
317
+ },
318
+ birthDay: birthDate,
319
+ addressOfRegistration: "",
320
+ addressOfBirth: "",
321
+ ...tokenData
322
+ };
323
+ }
324
+ getItnSeqNumber(gender) {
325
+ const seqNumber = this.random.getRandomInt(1, 9998);
326
+ if (this.isOdd(seqNumber)) return gender === Gender.male ? seqNumber : seqNumber + 1;
327
+ return gender === Gender.male ? seqNumber + 1 : seqNumber;
328
+ }
329
+ isOdd(number) {
330
+ return number % 2 === 1;
331
+ }
332
+ createIdentifier(itn, ops = {}) {
333
+ const { customSalt, prefix = "" } = ops;
334
+ const hmac = createHmac("sha512", customSalt || "salt");
335
+ hmac.update(itn);
336
+ return `${prefix}${hmac.digest("hex")}`;
337
+ }
338
+ };
339
+ //#endregion
340
+ export { SessionGenerator as default };