@mudrichenkoevgeny/shared-foundation 0.0.46

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 (4) hide show
  1. package/index.d.ts +823 -0
  2. package/index.js +865 -0
  3. package/index.mjs +865 -0
  4. package/package.json +18 -0
package/index.mjs ADDED
@@ -0,0 +1,865 @@
1
+ import { z } from 'zod';
2
+
3
+ export function toPermissionCodeOrNull(value) {
4
+ if (!value || typeof value !== 'string' || value.trim() === '') {
5
+ return null;
6
+ }
7
+ return value;
8
+ }
9
+
10
+ export function toPermissionCodeOrThrow(value) {
11
+ const result = toPermissionCodeOrNull(value);
12
+ if (!result) {
13
+ throw new Error('PermissionCode value must not be blank.');
14
+ }
15
+ return result;
16
+ }
17
+
18
+ export const permissionCodeSchema = z.string().transform((val, ctx) => {
19
+ const result = toPermissionCodeOrNull(val);
20
+ if (!result) {
21
+ ctx.addIssue({ code: z.ZodIssueCode.custom, message: 'Invalid PermissionCode' });
22
+ return z.NEVER;
23
+ }
24
+ return result;
25
+ });
26
+
27
+ export function toUserIdOrNull(value) {
28
+ if (!value || typeof value !== 'string' || value.trim() === '') {
29
+ return null;
30
+ }
31
+ return value;
32
+ }
33
+
34
+ export function toUserIdOrThrow(value) {
35
+ const result = toUserIdOrNull(value);
36
+ if (!result) {
37
+ throw new Error('UserId value must not be blank.');
38
+ }
39
+ return result;
40
+ }
41
+
42
+ export const userIdSchema = z.string().transform((val, ctx) => {
43
+ const result = toUserIdOrNull(val);
44
+ if (!result) {
45
+ ctx.addIssue({ code: z.ZodIssueCode.custom, message: 'Invalid UserId' });
46
+ return z.NEVER;
47
+ }
48
+ return result;
49
+ });
50
+
51
+ export function toUserIdentifierIdOrNull(value) {
52
+ if (!value || typeof value !== 'string' || value.trim() === '') {
53
+ return null;
54
+ }
55
+ return value;
56
+ }
57
+
58
+ export function toUserIdentifierIdOrThrow(value) {
59
+ const result = toUserIdentifierIdOrNull(value);
60
+ if (!result) {
61
+ throw new Error('UserIdentifierId value must not be blank.');
62
+ }
63
+ return result;
64
+ }
65
+
66
+ export const userIdentifierIdSchema = z.string().transform((val, ctx) => {
67
+ const result = toUserIdentifierIdOrNull(val);
68
+ if (!result) {
69
+ ctx.addIssue({ code: z.ZodIssueCode.custom, message: 'Invalid UserIdentifierId' });
70
+ return z.NEVER;
71
+ }
72
+ return result;
73
+ });
74
+
75
+ export function toUserSessionIdOrNull(value) {
76
+ if (!value || typeof value !== 'string' || value.trim() === '') {
77
+ return null;
78
+ }
79
+ return value;
80
+ }
81
+
82
+ export function toUserSessionIdOrThrow(value) {
83
+ const result = toUserSessionIdOrNull(value);
84
+ if (!result) {
85
+ throw new Error('UserSessionId value must not be blank.');
86
+ }
87
+ return result;
88
+ }
89
+
90
+ export const userSessionIdSchema = z.string().transform((val, ctx) => {
91
+ const result = toUserSessionIdOrNull(val);
92
+ if (!result) {
93
+ ctx.addIssue({ code: z.ZodIssueCode.custom, message: 'Invalid UserSessionId' });
94
+ return z.NEVER;
95
+ }
96
+ return result;
97
+ });
98
+
99
+ export function toAuditEventIdOrNull(value) {
100
+ if (!value || typeof value !== 'string' || value.trim() === '') {
101
+ return null;
102
+ }
103
+ return value;
104
+ }
105
+
106
+ export function toAuditEventIdOrThrow(value) {
107
+ const result = toAuditEventIdOrNull(value);
108
+ if (!result) {
109
+ throw new Error('AuditEventId value must not be blank.');
110
+ }
111
+ return result;
112
+ }
113
+
114
+ export const auditEventIdSchema = z.string().transform((val, ctx) => {
115
+ const result = toAuditEventIdOrNull(val);
116
+ if (!result) {
117
+ ctx.addIssue({ code: z.ZodIssueCode.custom, message: 'Invalid AuditEventId' });
118
+ return z.NEVER;
119
+ }
120
+ return result;
121
+ });
122
+
123
+ export function toClientDeviceIdOrNull(value) {
124
+ if (!value || typeof value !== 'string' || value.trim() === '') {
125
+ return null;
126
+ }
127
+ return value;
128
+ }
129
+
130
+ export function toClientDeviceIdOrThrow(value) {
131
+ const result = toClientDeviceIdOrNull(value);
132
+ if (!result) {
133
+ throw new Error('ClientDeviceId value must not be blank.');
134
+ }
135
+ return result;
136
+ }
137
+
138
+ export const clientDeviceIdSchema = z.string().transform((val, ctx) => {
139
+ const result = toClientDeviceIdOrNull(val);
140
+ if (!result) {
141
+ ctx.addIssue({ code: z.ZodIssueCode.custom, message: 'Invalid ClientDeviceId' });
142
+ return z.NEVER;
143
+ }
144
+ return result;
145
+ });
146
+
147
+ export const ManagementRoutes = {
148
+ BASE_MANAGEMENT_ROUTE: "/management"
149
+ };
150
+
151
+ export const ManagementAuditRoutes = {
152
+ BASE_MANAGEMENT_AUDIT_EVENTS_ROUTE: "/management/audit/events",
153
+ GET_AUDIT_EVENTS: "/management/audit/events",
154
+ GET_AUDIT_EVENT: "/management/audit/events/{event_id}"
155
+ };
156
+
157
+ export const ManagementSecuritySettingsRoutes = {
158
+ BASE_MANAGEMENT_SECURITY_SETTINGS_ROUTE: "/management/security/settings",
159
+ GET_MANAGEMENT_SECURITY_SETTINGS: "/management/security/settings",
160
+ UPDATE_MANAGEMENT_SECURITY_SETTINGS: "/management/security/settings",
161
+ RESET_MANAGEMENT_SECURITY_SETTINGS: "/management/security/settings/reset"
162
+ };
163
+
164
+ export const OpenSecuritySettingsRoutes = {
165
+ GET_OPEN_SECURITY_SETTINGS: "/security/settings"
166
+ };
167
+
168
+ export const ManagementGlobalSettingsRoutes = {
169
+ BASE_MANAGEMENT_GLOBAL_SETTINGS_ROUTE: "/management/global-settings",
170
+ GET_MANAGEMENT_GLOBAL_SETTINGS: "/management/global-settings",
171
+ UPDATE_MANAGEMENT_GLOBAL_SETTINGS: "/management/global-settings",
172
+ RESET_MANAGEMENT_GLOBAL_SETTINGS: "/management/global-settings/reset"
173
+ };
174
+
175
+ export const OpenGlobalSettingsRoutes = {
176
+ GET_OPEN_GLOBAL_SETTINGS: "/global-settings"
177
+ };
178
+
179
+ export const OpenLoginRoutes = {
180
+ BASE_LOGIN_ROUTE: "/auth/login",
181
+ BASE_LOGIN_PHONE_ROUTE: "/auth/login/phone",
182
+ LOGIN_BY_EMAIL: "/auth/login/email",
183
+ LOGIN_BY_PHONE: "/auth/login/phone",
184
+ LOGIN_BY_EXTERNAL_AUTH_PROVIDER: "/auth/login/external-auth-provider",
185
+ LOGIN_BY_TOTP: "/auth/login/totp",
186
+ LOGIN_BY_TOTP_RECOVERY_CODE: "/auth/login/totp-recovery-code",
187
+ SEND_LOGIN_CONFIRMATION_TO_PHONE: "/auth/login/phone/confirmation/send-to-phone"
188
+ };
189
+
190
+ export const SelfManagementLoginRoutes = {
191
+ BASE_MANAGEMENT_LOGIN_ROUTE: "/management/auth/login",
192
+ LOGIN_BY_EMAIL: "/management/auth/login/email",
193
+ LOGIN_BY_TOTP: "/management/auth/login/totp",
194
+ LOGIN_BY_TOTP_RECOVERY_CODE: "/management/auth/login/totp-recovery-code"
195
+ };
196
+
197
+ export const OpenRegisterRoutes = {
198
+ REGISTER_BY_EMAIL_ROUTE: "/auth/register/email",
199
+ REGISTER_BY_EMAIL: "/auth/register/email",
200
+ SEND_REGISTER_CONFIRMATION_TO_EMAIL: "/auth/register/email/confirmation/send-to-email"
201
+ };
202
+
203
+ export const OpenResetPasswordRoutes = {
204
+ BASE_RESET_PASSWORD_ROUTE: "/auth/reset-password",
205
+ RESET_EMAIL_PASSWORD: "/auth/reset-password",
206
+ SEND_RESET_EMAIL_PASSWORD_CONFIRMATION: "/auth/reset-password/send-confirmation"
207
+ };
208
+
209
+ export const SelfManagementResetPasswordRoutes = {
210
+ BASE_MANAGEMENT_RESET_PASSWORD_ROUTE: "/management/auth/reset-password",
211
+ RESET_PASSWORD: "/management/auth/reset-password",
212
+ SEND_RESET_PASSWORD_CONFIRMATION: "/management/auth/reset-password/send-confirmation"
213
+ };
214
+
215
+ export const OpenUnlockRoutes = {
216
+ BASE_OPEN_UNLOCK_ROUTE: "/auth/unlock",
217
+ UNLOCK_BY_EMAIL_ROUTE: "/auth/unlock/email",
218
+ UNLOCK_BY_PHONE_ROUTE: "/auth/unlock/phone",
219
+ SEND_UNLOCK_EMAIL_CONFIRMATION: "/auth/unlock/email/send-confirmation",
220
+ UNLOCK_BY_EMAIL: "/auth/unlock/email",
221
+ SEND_UNLOCK_PHONE_CONFIRMATION: "/auth/unlock/phone/send-confirmation",
222
+ UNLOCK_BY_PHONE: "/auth/unlock/phone",
223
+ UNLOCK_BY_EXTERNAL_PROVIDER: "/auth/unlock/external-provider"
224
+ };
225
+
226
+ export const SelfManagementUnlockRoutes = {
227
+ BASE_SELF_MANAGEMENT_UNLOCK_ROUTE: "/management/auth/unlock",
228
+ UNLOCK_BY_EMAIL_ROUTE: "/management/auth/unlock/email",
229
+ UNLOCK_BY_PHONE_ROUTE: "/management/auth/unlock/phone",
230
+ SEND_UNLOCK_EMAIL_CONFIRMATION: "/management/auth/unlock/email/send-confirmation",
231
+ UNLOCK_BY_EMAIL: "/management/auth/unlock/email",
232
+ SEND_UNLOCK_PHONE_CONFIRMATION: "/management/auth/unlock/phone/send-confirmation",
233
+ UNLOCK_BY_PHONE: "/management/auth/unlock/phone",
234
+ UNLOCK_BY_EXTERNAL_PROVIDER: "/management/auth/unlock/external-provider"
235
+ };
236
+
237
+ export const OpenUserSecurityRoutes = {
238
+ BASE_TOTP_ROUTE: "/user/security/totp",
239
+ BASE_RECOVERY_CODES_ROUTE: "/user/security/totp/recovery-codes",
240
+ SETUP_TOTP: "/user/security/totp/setup",
241
+ ENABLE_TOTP: "/user/security/totp/enable",
242
+ DISABLE_TOTP: "/user/security/totp/disable",
243
+ GET_RECOVERY_CODES: "/user/security/totp/recovery-codes",
244
+ REGENERATE_RECOVERY_CODES: "/user/security/totp/recovery-codes/regenerate"
245
+ };
246
+
247
+ export const SelfManagementUserSecurityRoutes = {
248
+ BASE_SELF_TOTP_ROUTE: "/management/self/user/security/totp",
249
+ BASE_SELF_RECOVERY_CODES_ROUTE: "/management/self/user/security/totp/recovery-codes",
250
+ SETUP_TOTP: "/management/self/user/security/totp/setup",
251
+ ENABLE_TOTP: "/management/self/user/security/totp/enable",
252
+ DISABLE_TOTP: "/management/self/user/security/totp/disable",
253
+ GET_RECOVERY_CODES: "/management/self/user/security/totp/recovery-codes",
254
+ REGENERATE_RECOVERY_CODES: "/management/self/user/security/totp/recovery-codes/regenerate"
255
+ };
256
+
257
+ export const ManagementUserSecurityRoutes = {
258
+ DISABLE_TOTP: "/management/users/{user_id}/security/totp/disable"
259
+ };
260
+
261
+ export const OpenIdentifierRoutes = {
262
+ BASE_IDENTIFIER_ROUTE: "/identifier",
263
+ ADD_EMAIL_IDENTIFIER_ROUTE: "/identifier/email",
264
+ BASE_IDENTIFIER_CONFIRMATION_ROUTE: "/identifier/confirmation",
265
+ GET_IDENTIFIER: "/identifier/{user_identifier_id}",
266
+ GET_IDENTIFIERS: "/identifier",
267
+ DELETE_IDENTIFIER: "/identifier/{user_identifier_id}",
268
+ ADD_IDENTIFIER_EMAIL: "/identifier/email",
269
+ ADD_IDENTIFIER_PHONE: "/identifier/phone",
270
+ ADD_IDENTIFIER_EXTERNAL_AUTH_PROVIDER: "/identifier/external-auth-provider",
271
+ SEND_ADD_EMAIL_IDENTIFIER_CONFIRMATION: "/identifier/confirmation/send-to-email",
272
+ SEND_ADD_PHONE_IDENTIFIER_CONFIRMATION: "/identifier/confirmation/send-to-phone",
273
+ IDENTIFIER_EMAIL_CHANGE_PASSWORD: "/identifier/email/password"
274
+ };
275
+
276
+ export const SelfManagementIdentifierRoutes = {
277
+ BASE_SELF_IDENTIFIER_ROUTE: "/management/self/identifier",
278
+ GET_IDENTIFIER: "/management/self/identifier/{user_identifier_id}",
279
+ GET_IDENTIFIERS: "/management/self/identifier",
280
+ IDENTIFIER_EMAIL_CHANGE_PASSWORD: "/management/self/identifier/email/password"
281
+ };
282
+
283
+ export const ManagementIdentifierRoutes = {
284
+ BASE_MANAGEMENT_IDENTIFIERS_ROUTE: "/management/users/identifiers",
285
+ GET_IDENTIFIERS: "/management/users/identifiers",
286
+ GET_IDENTIFIER: "/management/users/identifiers/{user_identifier_id}",
287
+ DELETE_IDENTIFIER: "/management/users/identifiers/{user_identifier_id}",
288
+ DELETE_IDENTIFIER_PASSWORD: "/management/users/identifiers/{user_identifier_id}/password"
289
+ };
290
+
291
+ export const OpenSessionRoutes = {
292
+ BASE_SESSION_ROUTE: "/session",
293
+ LOGOUT: "/session/logout",
294
+ GET_SESSIONS: "/session",
295
+ GET_SESSION: "/session/{session_id}",
296
+ DELETE_SESSION: "/session/{session_id}",
297
+ DELETE_ALL_OTHER_SESSIONS: "/session/delete-others",
298
+ REAUTHENTICATE_SESSION: "/session/reauthenticate"
299
+ };
300
+
301
+ export const SelfManagementSessionRoutes = {
302
+ BASE_SELF_SESSION_ROUTE: "/management/self/session",
303
+ LOGOUT: "/management/self/session/logout",
304
+ GET_SESSIONS: "/management/self/session",
305
+ GET_SESSION: "/management/self/session/{session_id}",
306
+ DELETE_SESSION: "/management/self/session/{session_id}",
307
+ DELETE_ALL_OTHER_SESSIONS: "/management/self/session/delete-others",
308
+ REAUTHENTICATE_SESSION: "/management/self/session/reauthenticate"
309
+ };
310
+
311
+ export const ManagementSessionRoutes = {
312
+ BASE_MANAGEMENT_SESSIONS_ROUTE: "/management/users/sessions",
313
+ GET_SESSIONS: "/management/users/sessions",
314
+ GET_SESSION: "/management/users/sessions/{session_id}",
315
+ DELETE_SESSION: "/management/users/sessions/{session_id}",
316
+ DELETE_ALL_USER_SESSIONS: "/management/users/sessions/delete-all-for-user/{user_id}"
317
+ };
318
+
319
+ export const OpenUserRoutes = {
320
+ BASE_USER_ROUTE: "/user",
321
+ GET_USER: "/user",
322
+ SCHEDULE_DELETION: "/user/schedule-deletion",
323
+ RESTORE_USER: "/user/restore"
324
+ };
325
+
326
+ export const SelfManagementUserRoutes = {
327
+ GET_USER: "/management/self/user"
328
+ };
329
+
330
+ export const ManagementUserRoutes = {
331
+ CREATE_USER: "/management/users",
332
+ GET_USERS: "/management/users",
333
+ GET_USER: "/management/users/{user_id}",
334
+ UPDATE_USER: "/management/users/{user_id}",
335
+ DELETE_USER: "/management/users/{user_id}"
336
+ };
337
+
338
+ export const ManagementAuthSettingsRoutes = {
339
+ BASE_MANAGEMENT_AUTH_SETTINGS_ROUTE: "/management/auth/settings",
340
+ GET_MANAGEMENT_AUTH_SETTINGS: "/management/auth/settings",
341
+ UPDATE_MANAGEMENT_AUTH_SETTINGS: "/management/auth/settings",
342
+ RESET_MANAGEMENT_AUTH_SETTINGS: "/management/auth/settings/reset"
343
+ };
344
+
345
+ export const CommonErrorCodes = {
346
+ UNKNOWN: "UNKNOWN",
347
+ INTERNAL: "INTERNAL",
348
+ NOT_FOUND: "NOT_FOUND",
349
+ SERVICE_UNAVAILABLE: "SERVICE_UNAVAILABLE",
350
+ TOO_MANY_REQUESTS: "TOO_MANY_REQUESTS",
351
+ MISSING_REQUIRED_PARAMETER: "MISSING_REQUIRED_PARAMETER",
352
+ INVALID_PARAMETER_VALUE: "INVALID_PARAMETER_VALUE",
353
+ MISSING_REQUIRED_FIELD: "MISSING_REQUIRED_FIELD",
354
+ BLANK_STRING_FIELD: "BLANK_STRING_FIELD",
355
+ EMPTY_COLLECTION_FIELD: "EMPTY_COLLECTION_FIELD",
356
+ INVALID_FIELD_VALUE: "INVALID_FIELD_VALUE",
357
+ BAD_REQUEST: "BAD_REQUEST",
358
+ INVALID_JSON_BODY: "INVALID_JSON_BODY"
359
+ };
360
+
361
+ export const CommonErrorArgs = {
362
+ MESSAGE: "message",
363
+ PARAMETER_NAME: "parameterName",
364
+ FIELD_NAME: "fieldName",
365
+ RETRY_AFTER_SECONDS: "retryAfterSeconds",
366
+ RATE_LIMIT_ACTION_CODE: "rateLimitActionCode",
367
+ LIMIT: "limit",
368
+ IDENTIFIER: "identifier",
369
+ RESOURCE: "resource"
370
+ };
371
+
372
+ export const SecurityErrorCodes = {
373
+ PASSWORD_TOO_WEAK: "PASSWORD_TOO_WEAK",
374
+ OTP_RETRY_TOO_SOON: "OTP_RETRY_TOO_SOON",
375
+ TOTP_ALREADY_ENABLED: "TOTP_ALREADY_ENABLED",
376
+ TOTP_NOT_ENABLED: "TOTP_NOT_ENABLED",
377
+ MFA_CONFIRMATION_REQUIRED: "MFA_CONFIRMATION_REQUIRED",
378
+ MFA_TOKEN_EXPIRED: "MFA_TOKEN_EXPIRED",
379
+ RECOVERY_CODE_ALREADY_USED: "RECOVERY_CODE_ALREADY_USED",
380
+ INVALID_TOTP_CODE: "INVALID_TOTP_CODE",
381
+ INVALID_MFA_TOKEN: "INVALID_MFA_TOKEN",
382
+ IP_NOT_ALLOWED: "IP_NOT_ALLOWED"
383
+ };
384
+
385
+ export const SecurityErrorArgs = {
386
+ PASSWORD_MIN_LENGTH: "passwordMinLength",
387
+ PASSWORD_FAIL_TOO_SHORT: "passwordTooShort",
388
+ PASSWORD_FAIL_NO_LETTER: "passwordNoLetter",
389
+ PASSWORD_FAIL_NO_UPPERCASE: "passwordNoUpperCase",
390
+ PASSWORD_FAIL_NO_LOWERCASE: "passwordNoLowerCase",
391
+ PASSWORD_FAIL_NO_DIGIT: "passwordNoDigit",
392
+ PASSWORD_FAIL_NO_SPECIAL_CHAR: "passwordNoSpecialChar",
393
+ PASSWORD_FAIL_TOO_COMMON: "passwordTooCommon",
394
+ MFA_TOKEN: "mfaToken"
395
+ };
396
+
397
+ export const UserErrorCodes = {
398
+ INVALID_ACCESS_TOKEN: "INVALID_ACCESS_TOKEN",
399
+ ACCESS_TOKEN_EXPIRED: "ACCESS_TOKEN_EXPIRED",
400
+ INVALID_REFRESH_TOKEN: "INVALID_REFRESH_TOKEN",
401
+ INVALID_SESSION: "INVALID_SESSION",
402
+ USER_ROLE_NOT_ALLOWED: "USER_ROLE_NOT_ALLOWED",
403
+ USER_MISSING_PERMISSIONS: "USER_MISSING_PERMISSIONS",
404
+ USER_INSUFFICIENT_AUTHORITY_LEVEL: "USER_INSUFFICIENT_AUTHORITY_LEVEL",
405
+ USER_ILLEGAL_ACCOUNT_STATUS: "USER_ILLEGAL_ACCOUNT_STATUS",
406
+ USER_BANNED: "USER_BANNED",
407
+ USER_LOCKED: "USER_LOCKED",
408
+ USER_READ_ONLY: "USER_READ_ONLY",
409
+ USER_SECURITY_HOLD: "USER_SECURITY_HOLD",
410
+ USER_PENDING_DELETION: "USER_PENDING_DELETION",
411
+ USER_FORBIDDEN: "USER_FORBIDDEN",
412
+ USER_NOT_FOUND: "USER_NOT_FOUND",
413
+ INVALID_CREDENTIALS: "INVALID_CREDENTIALS",
414
+ CAN_NOT_DELETE_USER_IDENTIFIER: "CAN_NOT_DELETE_USER_IDENTIFIER",
415
+ CAN_NOT_CREATE_USER_IDENTIFIER: "CAN_NOT_CREATE_USER_IDENTIFIER",
416
+ USER_IDENTIFIER_LIMIT_REACHED: "USER_IDENTIFIER_LIMIT_REACHED",
417
+ TOTAL_USER_IDENTIFIERS_LIMIT_REACHED: "TOTAL_USER_IDENTIFIERS_LIMIT_REACHED",
418
+ WRONG_PASSWORD: "WRONG_PASSWORD",
419
+ WRONG_CONFIRMATION_CODE: "WRONG_CONFIRMATION_CODE",
420
+ EXTERNAL_IDENTIFIER_LINKAGE_FAILED: "EXTERNAL_IDENTIFIER_LINKAGE_FAILED",
421
+ REGISTRATION_DISABLED: "REGISTRATION_DISABLED",
422
+ SELF_SERVICE_UNLOCK_DISABLED: "SELF_SERVICE_UNLOCK_DISABLED",
423
+ EMAIL_NOT_ALLOWED: "EMAIL_NOT_ALLOWED",
424
+ PASSWORD_SETUP_REQUIRED: "PASSWORD_SETUP_REQUIRED",
425
+ USER_IDENTIFIER_PASSWORD_NOT_SUPPORTED: "USER_IDENTIFIER_PASSWORD_NOT_SUPPORTED",
426
+ USER_IDENTIFIER_PASSWORD_NOT_SET: "USER_IDENTIFIER_PASSWORD_NOT_SET"
427
+ };
428
+
429
+ export const UserErrorArgs = {
430
+ USER_ID: "userId",
431
+ MAX_NUMBER_OF_IDENTIFIERS: "maxNumberOfIdentifiers",
432
+ USER_AUTH_PROVIDER: "userAuthProvider",
433
+ ACCOUNT_LOCKOUT_TYPE: "accountLockoutType",
434
+ TEMPORARY_LOCKOUT_UNTIL: "temporaryLockoutUntil"
435
+ };
436
+
437
+ export const AuditPermissionCode = {
438
+
439
+ };
440
+
441
+ export const SecurityPermissionCode = {
442
+
443
+ };
444
+
445
+ export const SettingsPermissionCode = {
446
+
447
+ };
448
+
449
+ export const AuthSettingsPermissionCode = {
450
+
451
+ };
452
+
453
+ export const IdentifierPermissionCode = {
454
+
455
+ };
456
+
457
+ export const SessionPermissionCode = {
458
+
459
+ };
460
+
461
+ export const UserPermissionCode = {
462
+
463
+ };
464
+
465
+ export const clientTypeSchema = z.enum(["web", "android", "ios", "desktop"]);
466
+
467
+ export const sortOrderSchema = z.enum(["asc", "desc"]);
468
+
469
+ export const accountLockoutTypeSchema = z.enum(["none", "indefinite", "temporary"]);
470
+
471
+ export const passwordPolicyFailReasonSchema = z.enum(["too_short", "no_letter", "no_uppercase", "no_lowercase", "no_digit", "no_special_char", "too_common"]);
472
+
473
+ export const auditActorTypeSchema = z.enum(["user", "system", "service"]);
474
+
475
+ export const auditValueSensitivitySchema = z.enum(["non_sensitive", "email", "phone_number", "ip_address", "partial_value_mask", "full_value_mask"]);
476
+
477
+ export const auditStatusSchema = z.enum(["success", "failed", "denied"]);
478
+
479
+ export const commonAuditResourceTypeSchema = z.enum(["audit_event", "audit_events"]);
480
+
481
+ export const securityAuditResourceTypeSchema = z.enum(["security_settings"]);
482
+
483
+ export const settingsAuditResourceTypeSchema = z.enum(["global_settings"]);
484
+
485
+ export const userAuditResourceTypeSchema = z.enum(["auth_settings", "user", "email_address", "phone_number", "identifier", "session"]);
486
+
487
+ export const securityAuditActionTypeSchema = z.enum(["management_update_security_settings", "management_reset_security_settings"]);
488
+
489
+ export const settingsAuditActionTypeSchema = z.enum(["management_update_global_settings", "management_reset_global_settings"]);
490
+
491
+ export const userAuditActionTypeSchema = z.enum(["management_update_auth_settings", "management_reset_auth_settings", "management_delete_identifier", "management_delete_identifier_password", "management_delete_session", "management_delete_all_user_sessions", "management_update_user", "management_delete_user", "management_create_user", "management_disable_user_totp", "login_by_email", "login_by_phone", "login_by_external_auth_provider", "login_by_totp", "login_by_totp_recovery_code", "new_device_detected", "register_by_email", "reset_password", "self_unlock_account", "logout", "self_delete_session", "self_delete_other_sessions", "reauthenticate_session", "self_delete_identifier", "add_identifier_email", "add_identifier_phone", "add_identifier_external_auth_provider", "change_password", "self_schedule_user_deletion", "self_restore_user", "self_setup_totp_initiated", "self_enable_totp", "self_disable_totp", "self_get_recovery_codes", "self_regenerate_recovery_codes", "refresh_token_reuse_detected"]);
492
+
493
+ export const userAccountStatusSchema = z.enum(["active", "read_only", "banned", "security_hold", "pending_deletion"]);
494
+
495
+ export const userRoleSchema = z.enum(["user", "staff", "admin"]);
496
+
497
+ export const userAuthProviderSchema = z.enum(["email", "phone", "google", "apple"]);
498
+
499
+ export const externalAuthProviderSchema = z.enum(["google", "apple"]);
500
+
501
+ export function pagedResultSchema(itemSchema) {
502
+ return z.object({
503
+ items: z.array(itemSchema),
504
+ totalCount: z.number(),
505
+ pageNumber: z.number(),
506
+ pageSize: z.number(),
507
+ totalPages: z.number()
508
+ });
509
+ }
510
+
511
+ export const apiErrorResponseSchema = z.object({
512
+ id: userIdSchema,
513
+ code: z.string(),
514
+ message: z.string(),
515
+ args: z.record(z.string(), z.string())
516
+ });
517
+
518
+ export const clientInfoPayloadSchema = z.object({
519
+ client_device_info: clientDeviceInfoPayloadSchema,
520
+ user_agent: z.string().nullable(),
521
+ ip_address: z.string().nullable(),
522
+ api_version: z.string().nullable()
523
+ });
524
+
525
+ export const clientDeviceInfoPayloadSchema = z.object({
526
+ client_type: clientTypeSchema.nullable(),
527
+ language: z.string().nullable(),
528
+ device_id: clientDeviceIdSchema.nullable(),
529
+ device_name: z.string().nullable(),
530
+ app_version: z.string().nullable(),
531
+ operation_system_version: z.string().nullable()
532
+ });
533
+
534
+ export const accountLockoutPolicyPayloadSchema = z.object({
535
+ max_failed_password_attempts: z.number(),
536
+ max_failed_otp_attempts: z.number(),
537
+ max_failed_totp_attempts: z.number(),
538
+ failed_attempts_window_seconds: z.number(),
539
+ lockout_duration_seconds: z.number(),
540
+ indefinite_lockout_threshold: z.number(),
541
+ is_self_service_unlock_enabled: z.boolean()
542
+ });
543
+
544
+ export const ipRestrictionPolicyPayloadSchema = z.object({
545
+ is_blacklist_enabled: z.boolean(),
546
+ blacklist: z.array(z.string()),
547
+ is_whitelist_enabled: z.boolean(),
548
+ whitelist: z.array(z.string())
549
+ });
550
+
551
+ export const otpConfirmationPayloadSchema = z.object({
552
+ retry_after_seconds: z.number(),
553
+ number_of_symbols: z.number(),
554
+ expiration_seconds: z.number()
555
+ });
556
+
557
+ export const managementPasswordPolicyPayloadSchema = z.object({
558
+ min_length: z.number(),
559
+ require_letter: z.boolean(),
560
+ require_upper_case: z.boolean(),
561
+ require_lower_case: z.boolean(),
562
+ require_digit: z.boolean(),
563
+ require_special_char: z.boolean(),
564
+ common_passwords: z.array(z.string())
565
+ });
566
+
567
+ export const openPasswordPolicyPayloadSchema = z.object({
568
+ min_length: z.number(),
569
+ require_letter: z.boolean(),
570
+ require_upper_case: z.boolean(),
571
+ require_lower_case: z.boolean(),
572
+ require_digit: z.boolean(),
573
+ require_special_char: z.boolean()
574
+ });
575
+
576
+ export const managementSecuritySettingsPayloadSchema = z.object({
577
+ recent_authentication_validity_seconds_for_open_user: z.number(),
578
+ recent_authentication_validity_seconds_for_management_user: z.number(),
579
+ management_password_policy: managementPasswordPolicyPayloadSchema,
580
+ otp_confirmation: otpConfirmationPayloadSchema,
581
+ account_lockout_policy: accountLockoutPolicyPayloadSchema,
582
+ account_lockout_check_interval_seconds: z.number(),
583
+ open_ip_restriction_policy: ipRestrictionPolicyPayloadSchema,
584
+ management_ip_restriction_policy: ipRestrictionPolicyPayloadSchema,
585
+ expiration_seconds: z.number(),
586
+ max_requests_per_period: z.number(),
587
+ rate_limit_period_seconds: z.number(),
588
+ refresh_token_rotation_grace_period_seconds: z.number()
589
+ });
590
+
591
+ export const openSecuritySettingsPayloadSchema = z.object({
592
+ open_password_policy: openPasswordPolicyPayloadSchema,
593
+ otp_confirmation: otpConfirmationPayloadSchema
594
+ });
595
+
596
+ export const totpRecoveryCodesPayloadSchema = z.object({
597
+ totp_recovery_codes: z.array(z.string())
598
+ });
599
+
600
+ export const totpSetupPayloadSchema = z.object({
601
+ totp_secret_key: z.string(),
602
+ totp_otp_auth_url: z.string(),
603
+ mfa_token: z.string()
604
+ });
605
+
606
+ export const verifyTotpPayloadSchema = z.object({
607
+ mfa_token: z.string(),
608
+ totp_code: z.string()
609
+ });
610
+
611
+ export const managementGlobalSettingsPayloadSchema = z.object({
612
+ privacy_policy_url: z.string().nullable(),
613
+ terms_of_service_url: z.string().nullable(),
614
+ contact_support_email: z.string().nullable(),
615
+ min_supported_app_versions: z.record(z.string(), z.string()),
616
+ is_tracing_enabled: z.boolean(),
617
+ is_metrics_enabled: z.boolean(),
618
+ is_verbose_logging_enabled: z.boolean()
619
+ });
620
+
621
+ export const openGlobalSettingsPayloadSchema = z.object({
622
+ privacy_policy_url: z.string().nullable(),
623
+ terms_of_service_url: z.string().nullable(),
624
+ contact_support_email: z.string().nullable(),
625
+ min_supported_app_versions: z.record(z.string(), z.string())
626
+ });
627
+
628
+ export const auditEventPayloadSchema = z.object({
629
+ id: auditEventIdSchema,
630
+ actor_id: userIdSchema.nullable(),
631
+ actor_type: auditActorTypeSchema,
632
+ actor_user_role: userRoleSchema.nullable(),
633
+ action: z.string(),
634
+ resource: z.string(),
635
+ resource_id: z.string().nullable(),
636
+ status: auditStatusSchema,
637
+ metadata: z.array(auditEventMetadataPayloadSchema),
638
+ message: z.string().nullable(),
639
+ created_at: z.number()
640
+ });
641
+
642
+ export const auditEventMetadataPayloadSchema = z.object({
643
+ key: z.string(),
644
+ value: z.string(),
645
+ value_sensitivity: z.string()
646
+ });
647
+
648
+ export const authDataPayloadSchema = z.object({
649
+ user: userDetailsPayloadSchema,
650
+ session_token: sessionTokenPayloadSchema
651
+ });
652
+
653
+ export const availableAuthProvidersPayloadSchema = z.object({
654
+ primary: z.array(z.string()),
655
+ secondary: z.array(z.string())
656
+ });
657
+
658
+ export const managementAuthSettingsPayloadSchema = z.object({
659
+ available_auth_providers: availableAuthProvidersPayloadSchema,
660
+ max_total_identifiers: z.number(),
661
+ max_email_identifiers: z.number(),
662
+ max_phone_identifiers: z.number(),
663
+ max_identifiers_per_external_provider: z.number(),
664
+ max_active_sessions_for_open_user: z.number(),
665
+ max_active_sessions_for_management_user: z.number(),
666
+ access_token_validity_seconds: z.number(),
667
+ refresh_token_validity_seconds: z.number(),
668
+ account_deletion_grace_period_seconds: z.number(),
669
+ account_deletion_check_interval_seconds: z.number(),
670
+ is_registration_enabled: z.boolean(),
671
+ open_email_restriction_policy: emailRestrictionPolicyPayloadSchema,
672
+ management_email_restriction_policy: emailRestrictionPolicyPayloadSchema
673
+ });
674
+
675
+ export const openAuthSettingsPayloadSchema = z.object({
676
+ available_auth_providers: availableAuthProvidersPayloadSchema,
677
+ max_total_identifiers: z.number(),
678
+ max_email_identifiers: z.number(),
679
+ max_phone_identifiers: z.number(),
680
+ max_identifiers_per_external_provider: z.number(),
681
+ is_registration_enabled: z.boolean()
682
+ });
683
+
684
+ export const managementUserConfigurationPayloadSchema = z.object({
685
+ management_global_settings: managementGlobalSettingsPayloadSchema,
686
+ management_security_settings: managementSecuritySettingsPayloadSchema,
687
+ management_auth_settings: managementAuthSettingsPayloadSchema
688
+ });
689
+
690
+ export const openUserConfigurationPayloadSchema = z.object({
691
+ open_global_settings: openGlobalSettingsPayloadSchema,
692
+ open_security_settings: openSecuritySettingsPayloadSchema,
693
+ open_auth_settings: openAuthSettingsPayloadSchema
694
+ });
695
+
696
+ export const emailRestrictionPolicyPayloadSchema = z.object({
697
+ is_blacklist_enabled: z.boolean(),
698
+ blacklist: z.array(z.string()),
699
+ is_whitelist_enabled: z.boolean(),
700
+ whitelist: z.array(z.string())
701
+ });
702
+
703
+ export const userIdentifierPayloadSchema = z.object({
704
+ id: userIdentifierIdSchema,
705
+ user_id: userIdSchema,
706
+ user_auth_provider: userAuthProviderSchema,
707
+ identifier: z.string(),
708
+ display_name: z.string(),
709
+ external_provider_email: z.string().nullable(),
710
+ is_sensitive_values_masked: z.boolean(),
711
+ created_at: z.number(),
712
+ updated_at: z.number().nullable()
713
+ });
714
+
715
+ export const deletedSessionsPayloadSchema = z.object({
716
+ deleted_session_ids: z.array(z.string())
717
+ });
718
+
719
+ export const userSessionPayloadSchema = z.object({
720
+ id: userSessionIdSchema,
721
+ user_id: userIdSchema,
722
+ user_role: userRoleSchema,
723
+ identifier: z.string(),
724
+ identifier_id: userIdentifierIdSchema,
725
+ identifier_display_name: z.string(),
726
+ identifier_auth_provider: userAuthProviderSchema,
727
+ client_device_info: clientDeviceInfoPayloadSchema,
728
+ user_agent: z.string().nullable(),
729
+ ip_address: z.string().nullable(),
730
+ expires_at: z.number(),
731
+ last_accessed_at: z.number(),
732
+ last_reauthenticated_at: z.number(),
733
+ is_sensitive_values_masked: z.boolean(),
734
+ created_at: z.number(),
735
+ updated_at: z.number().nullable()
736
+ });
737
+
738
+ export const refreshTokenPayloadSchema = z.object({
739
+ refresh_token: z.string()
740
+ });
741
+
742
+ export const sessionTokenPayloadSchema = z.object({
743
+ access_token: z.string(),
744
+ refresh_token: z.string(),
745
+ expires_at: z.number(),
746
+ token_type: z.string(),
747
+ session_id: userSessionIdSchema,
748
+ identifier_id: userIdentifierIdSchema
749
+ });
750
+
751
+ export const userDetailsPayloadSchema = z.object({
752
+ id: userIdSchema,
753
+ role: userRoleSchema,
754
+ account_status: userAccountStatusSchema,
755
+ account_status_on_restore: userAccountStatusSchema.nullable(),
756
+ authority_level: z.number(),
757
+ permission_codes: z.array(permissionCodeSchema),
758
+ is_totp_enabled: z.boolean(),
759
+ last_login_at: z.number().nullable(),
760
+ last_active_at: z.number().nullable(),
761
+ created_at: z.number(),
762
+ updated_at: z.number().nullable(),
763
+ scheduled_permanent_deletion_at: z.number().nullable(),
764
+ account_lockout_type: accountLockoutTypeSchema,
765
+ temporary_lockout_until: z.number().nullable()
766
+ });
767
+
768
+ export const userPublicPayloadSchema = z.object({
769
+ id: userIdSchema,
770
+ role: userRoleSchema,
771
+ account_status: userAccountStatusSchema
772
+ });
773
+
774
+ export const createByEmailRequestSchema = z.object({
775
+ email: z.string(),
776
+ password: z.string().nullable(),
777
+ role: userRoleSchema,
778
+ account_status: z.string(),
779
+ authority_level: z.number(),
780
+ permission_codes: z.array(permissionCodeSchema)
781
+ });
782
+
783
+ export const loginByEmailRequestSchema = z.object({
784
+ email: z.string(),
785
+ password: z.string()
786
+ });
787
+
788
+ export const loginByExternalAuthProviderRequestSchema = z.object({
789
+ auth_provider: z.string(),
790
+ external_provider_token: z.string()
791
+ });
792
+
793
+ export const loginByPhoneRequestSchema = z.object({
794
+ phone_number: z.string(),
795
+ confirmation_code: z.string()
796
+ });
797
+
798
+ export const resetPasswordRequestSchema = z.object({
799
+ email: z.string(),
800
+ confirmation_code: z.string(),
801
+ new_password: z.string()
802
+ });
803
+
804
+ export const sendResetPasswordConfirmationRequestSchema = z.object({
805
+ email: z.string()
806
+ });
807
+
808
+ export const registerByEmailRequestSchema = z.object({
809
+ email: z.string(),
810
+ password: z.string(),
811
+ confirmation_code: z.string()
812
+ });
813
+
814
+ export const unlockByEmailConfirmationRequestSchema = z.object({
815
+ email: z.string(),
816
+ confirmation_code: z.string()
817
+ });
818
+
819
+ export const unlockByExternalAuthProviderRequestSchema = z.object({
820
+ auth_provider: z.string(),
821
+ external_provider_token: z.string()
822
+ });
823
+
824
+ export const unlockByPhoneConfirmationRequestSchema = z.object({
825
+ phone_number: z.string(),
826
+ confirmation_code: z.string()
827
+ });
828
+
829
+ export const sendConfirmationToEmailRequestSchema = z.object({
830
+ email: z.string()
831
+ });
832
+
833
+ export const sendConfirmationToPhoneRequestSchema = z.object({
834
+ phone_number: z.string()
835
+ });
836
+
837
+ export const emailPasswordChangeRequestSchema = z.object({
838
+ email: z.string(),
839
+ old_password: z.string(),
840
+ new_password: z.string()
841
+ });
842
+
843
+ export const addUserIdentifierEmailRequestSchema = z.object({
844
+ email: z.string(),
845
+ password: z.string(),
846
+ confirmation_code: z.string()
847
+ });
848
+
849
+ export const addUserIdentifierExternalAuthProviderRequestSchema = z.object({
850
+ auth_provider: z.string(),
851
+ external_provider_token: z.string()
852
+ });
853
+
854
+ export const addUserIdentifierPhoneRequestSchema = z.object({
855
+ phone_number: z.string(),
856
+ confirmation_code: z.string()
857
+ });
858
+
859
+ export const updateUserRequestSchema = z.object({
860
+ account_status: userAccountStatusSchema.nullable(),
861
+ authority_level: z.number().nullable(),
862
+ permission_codes: z.array(permissionCodeSchema).nullable(),
863
+ account_lockout_type: accountLockoutTypeSchema.nullable(),
864
+ temporary_lockout_until: z.number().nullable()
865
+ });