@mudrichenkoevgeny/shared-foundation 0.0.48 → 0.0.49

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 (5) hide show
  1. package/README.md +37 -4
  2. package/index.d.ts +602 -32
  3. package/index.js +869 -1
  4. package/index.mjs +869 -1
  5. package/package.json +1 -1
package/index.mjs CHANGED
@@ -144,6 +144,204 @@ export const clientDeviceIdSchema = z.string().transform((val, ctx) => {
144
144
  return result;
145
145
  });
146
146
 
147
+ export function toDecryptedStringOrNull(value) {
148
+ if (!value || typeof value !== 'string' || value.trim() === '') {
149
+ return null;
150
+ }
151
+ return value;
152
+ }
153
+
154
+ export function toDecryptedStringOrThrow(value) {
155
+ const result = toDecryptedStringOrNull(value);
156
+ if (!result) {
157
+ throw new Error('DecryptedString value must not be blank.');
158
+ }
159
+ return result;
160
+ }
161
+
162
+ export const decryptedStringSchema = z.string().transform((val, ctx) => {
163
+ const result = toDecryptedStringOrNull(val);
164
+ if (!result) {
165
+ ctx.addIssue({ code: z.ZodIssueCode.custom, message: 'Invalid DecryptedString' });
166
+ return z.NEVER;
167
+ }
168
+ return result;
169
+ });
170
+
171
+ export function toEncryptedStringOrNull(value) {
172
+ if (!value || typeof value !== 'string' || value.trim() === '') {
173
+ return null;
174
+ }
175
+ return value;
176
+ }
177
+
178
+ export function toEncryptedStringOrThrow(value) {
179
+ const result = toEncryptedStringOrNull(value);
180
+ if (!result) {
181
+ throw new Error('EncryptedString value must not be blank.');
182
+ }
183
+ return result;
184
+ }
185
+
186
+ export const encryptedStringSchema = z.string().transform((val, ctx) => {
187
+ const result = toEncryptedStringOrNull(val);
188
+ if (!result) {
189
+ ctx.addIssue({ code: z.ZodIssueCode.custom, message: 'Invalid EncryptedString' });
190
+ return z.NEVER;
191
+ }
192
+ return result;
193
+ });
194
+
195
+ export function toPasswordHashOrNull(value) {
196
+ if (!value || typeof value !== 'string' || value.trim() === '') {
197
+ return null;
198
+ }
199
+ return value;
200
+ }
201
+
202
+ export function toPasswordHashOrThrow(value) {
203
+ const result = toPasswordHashOrNull(value);
204
+ if (!result) {
205
+ throw new Error('PasswordHash value must not be blank.');
206
+ }
207
+ return result;
208
+ }
209
+
210
+ export const passwordHashSchema = z.string().transform((val, ctx) => {
211
+ const result = toPasswordHashOrNull(val);
212
+ if (!result) {
213
+ ctx.addIssue({ code: z.ZodIssueCode.custom, message: 'Invalid PasswordHash' });
214
+ return z.NEVER;
215
+ }
216
+ return result;
217
+ });
218
+
219
+ export function toAccessTokenOrNull(value) {
220
+ if (!value || typeof value !== 'string' || value.trim() === '') {
221
+ return null;
222
+ }
223
+ return value;
224
+ }
225
+
226
+ export function toAccessTokenOrThrow(value) {
227
+ const result = toAccessTokenOrNull(value);
228
+ if (!result) {
229
+ throw new Error('AccessToken value must not be blank.');
230
+ }
231
+ return result;
232
+ }
233
+
234
+ export const accessTokenSchema = z.string().transform((val, ctx) => {
235
+ const result = toAccessTokenOrNull(val);
236
+ if (!result) {
237
+ ctx.addIssue({ code: z.ZodIssueCode.custom, message: 'Invalid AccessToken' });
238
+ return z.NEVER;
239
+ }
240
+ return result;
241
+ });
242
+
243
+ export function toRefreshTokenOrNull(value) {
244
+ if (!value || typeof value !== 'string' || value.trim() === '') {
245
+ return null;
246
+ }
247
+ return value;
248
+ }
249
+
250
+ export function toRefreshTokenOrThrow(value) {
251
+ const result = toRefreshTokenOrNull(value);
252
+ if (!result) {
253
+ throw new Error('RefreshToken value must not be blank.');
254
+ }
255
+ return result;
256
+ }
257
+
258
+ export const refreshTokenSchema = z.string().transform((val, ctx) => {
259
+ const result = toRefreshTokenOrNull(val);
260
+ if (!result) {
261
+ ctx.addIssue({ code: z.ZodIssueCode.custom, message: 'Invalid RefreshToken' });
262
+ return z.NEVER;
263
+ }
264
+ return result;
265
+ });
266
+
267
+ export function toRefreshTokenHashOrNull(value) {
268
+ if (!value || typeof value !== 'string' || value.trim() === '') {
269
+ return null;
270
+ }
271
+ return value;
272
+ }
273
+
274
+ export function toRefreshTokenHashOrThrow(value) {
275
+ const result = toRefreshTokenHashOrNull(value);
276
+ if (!result) {
277
+ throw new Error('RefreshTokenHash value must not be blank.');
278
+ }
279
+ return result;
280
+ }
281
+
282
+ export const refreshTokenHashSchema = z.string().transform((val, ctx) => {
283
+ const result = toRefreshTokenHashOrNull(val);
284
+ if (!result) {
285
+ ctx.addIssue({ code: z.ZodIssueCode.custom, message: 'Invalid RefreshTokenHash' });
286
+ return z.NEVER;
287
+ }
288
+ return result;
289
+ });
290
+
291
+ export class CompositeAuditActionTypeParser {
292
+ constructor(auditActionTypes) {
293
+ this.auditActionTypes = auditActionTypes;
294
+ }
295
+
296
+ fromValueOrThrow(value) {
297
+ for (const parse of this.auditActionTypes) {
298
+ const result = typeof parse === 'function'
299
+ ? parse(value)
300
+ : (parse && typeof parse.parseOrNull === 'function' ? parse.parseOrNull(value) : null);
301
+ if (result !== null && result !== undefined) {
302
+ return result;
303
+ }
304
+ }
305
+ throw new Error("Unknown value of AuditActionType: '" + value + "'");
306
+ }
307
+ }
308
+
309
+ export class CompositeAuditMetadataKeyParser {
310
+ constructor(metadataKeys) {
311
+ this.metadataKeys = metadataKeys;
312
+ }
313
+
314
+ fromValueOrThrow(value) {
315
+ for (const parse of this.metadataKeys) {
316
+ const result = typeof parse === 'function'
317
+ ? parse(value)
318
+ : (parse && typeof parse.parseOrNull === 'function' ? parse.parseOrNull(value) : null);
319
+ if (result !== null && result !== undefined) {
320
+ return result;
321
+ }
322
+ }
323
+ throw new Error("Unknown value of AuditMetadataKey: '" + value + "'");
324
+ }
325
+ }
326
+
327
+ export class CompositeAuditResourceTypeParser {
328
+ constructor(auditResourceTypes) {
329
+ this.auditResourceTypes = auditResourceTypes;
330
+ }
331
+
332
+ fromValueOrThrow(value) {
333
+ for (const parse of this.auditResourceTypes) {
334
+ const result = typeof parse === 'function'
335
+ ? parse(value)
336
+ : (parse && typeof parse.parseOrNull === 'function' ? parse.parseOrNull(value) : null);
337
+ if (result !== null && result !== undefined) {
338
+ return result;
339
+ }
340
+ }
341
+ throw new Error("Unknown value of AuditResourceType: '" + value + "'");
342
+ }
343
+ }
344
+
147
345
  export const ManagementRoutes = {
148
346
  BASE_MANAGEMENT_ROUTE: "/management"
149
347
  };
@@ -194,6 +392,14 @@ LOGIN_BY_TOTP: "/management/auth/login/totp",
194
392
  LOGIN_BY_TOTP_RECOVERY_CODE: "/management/auth/login/totp-recovery-code"
195
393
  };
196
394
 
395
+ export const OpenRefreshTokenRoutes = {
396
+ REFRESH_TOKEN: "/auth/refresh"
397
+ };
398
+
399
+ export const SelfManagementRefreshTokenRoutes = {
400
+ REFRESH_TOKEN: "/management/auth/refresh"
401
+ };
402
+
197
403
  export const OpenRegisterRoutes = {
198
404
  REGISTER_BY_EMAIL_ROUTE: "/auth/register/email",
199
405
  REGISTER_BY_EMAIL: "/auth/register/email",
@@ -342,6 +548,18 @@ UPDATE_MANAGEMENT_AUTH_SETTINGS: "/management/auth/settings",
342
548
  RESET_MANAGEMENT_AUTH_SETTINGS: "/management/auth/settings/reset"
343
549
  };
344
550
 
551
+ export const OpenAuthSettingsRoutes = {
552
+ GET_OPEN_AUTH_SETTINGS: "/auth/settings"
553
+ };
554
+
555
+ export const OpenUserConfigurationRoutes = {
556
+ GET_CONFIGURATION: "user-configuration"
557
+ };
558
+
559
+ export const ManagementUserConfigurationRoutes = {
560
+ GET_CONFIGURATION: "/management/user-configuration"
561
+ };
562
+
345
563
  export const CommonApiFields = {
346
564
  ITEMS: "items",
347
565
  TOTAL_COUNT: "total_count",
@@ -533,6 +751,72 @@ MANAGEMENT_SECURITY_SETTINGS_UPDATED: "MANAGEMENT_SECURITY_SETTINGS_UPDATED"
533
751
  MANAGEMENT_GLOBAL_SETTINGS_UPDATED: "MANAGEMENT_GLOBAL_SETTINGS_UPDATED"
534
752
  };
535
753
 
754
+ export const UserWebSocketCloseReasons = {
755
+ AUTH_FAILED: "Auth failed",
756
+ SESSION_EXPIRED: "Session expired",
757
+ SESSION_DELETED: "Session deleted",
758
+ USER_BANNED: "User banned"
759
+ };
760
+
761
+ export const UserWebSocketEventTypes = {
762
+ UNAUTHORIZED: "UNAUTHORIZED",
763
+ OPEN_AUTH_SETTINGS_UPDATED: "OPEN_AUTH_SETTINGS_UPDATED",
764
+ MANAGEMENT_AUTH_SETTINGS_UPDATED: "MANAGEMENT_AUTH_SETTINGS_UPDATED",
765
+ USER_UPDATED: "USER_UPDATED",
766
+ SESSION_DELETED: "SESSION_DELETED"
767
+ };
768
+
769
+ export const UserApiPaths = {
770
+ USER_ID: "user_id",
771
+ SESSION_ID: "session_id",
772
+ USER_IDENTIFIER_ID: "user_identifier_id"
773
+ };
774
+
775
+ export const UserApiQueryParams = {
776
+ ACCESS_TOKEN: "token"
777
+ };
778
+
779
+ export const UserAuthSpec = {
780
+ TOKEN_TYPE_BEARER: "Bearer"
781
+ };
782
+
783
+ export const AuditApiPaths = {
784
+ EVENT_ID: "event_id"
785
+ };
786
+
787
+ export const UserRoleDefaultAuthorityLevel = {
788
+
789
+ };
790
+
791
+ export const SecurityAuditMetadataDeniedReasonValues = {
792
+ RATE_LIMIT: "rate_limit",
793
+ PASSWORD_TOO_WEAK: "password_too_weak",
794
+ MFA_TOKEN_EXPIRED: "mfa_token_expired",
795
+ TOTP_ALREADY_ENABLED: "totp_already_enabled",
796
+ TOTP_NOT_ENABLED: "totp_not_enabled",
797
+ RECOVERY_CODE_ALREADY_USED: "recovery_code_already_used",
798
+ MFA_REQUIRED: "mfa_required"
799
+ };
800
+
801
+ export const UserAuditMetadataDeniedReasonValues = {
802
+ USER_READ_ONLY: "user_read_only",
803
+ USER_BANNED: "user_banned",
804
+ USER_LOCKED: "user_locked",
805
+ USER_SECURITY_HOLD: "user_security_hold",
806
+ USER_PENDING_DELETION: "user_pending_deletion",
807
+ USER_NOT_FOUND: "user_not_found",
808
+ USER_ROLE_NOT_ALLOWED: "user_role_not_allowed",
809
+ USER_MISSING_PERMISSIONS: "user_missing_permissions",
810
+ USER_INSUFFICIENT_AUTHORITY_LEVEL: "user_insufficient_authority_level",
811
+ USER_ILLEGAL_ACCOUNT_STATUS: "user_illegal_account_status",
812
+ USER_FORBIDDEN: "user_forbidden",
813
+ USER_IDENTIFIER_LIMIT_REACHED: "user_identifier_limit_reached",
814
+ TOTAL_USER_IDENTIFIERS_LIMIT_REACHED: "total_user_identifier_limit_reached",
815
+ PASSWORD_SETUP_REQUIRED: "password_setup_required",
816
+ USER_IDENTIFIER_PASSWORD_NOT_SUPPORTED: "user_identifier_password_not_supported",
817
+ USER_IDENTIFIER_PASSWORD_NOT_SET: "user_identifier_password_not_set"
818
+ };
819
+
536
820
  export const ListingParamNames = {
537
821
  PAGE_NUMBER: "page_number",
538
822
  PAGE_SIZE: "page_size",
@@ -548,6 +832,52 @@ export const ListingParamNames = {
548
832
  }
549
833
  };
550
834
 
835
+ export const AuditFilterValues = {
836
+ AuditEventFilterValues: {
837
+ ACTOR_ID: "actor_id",
838
+ ACTOR_TYPE: "actor_type",
839
+ ACTOR_USER_ROLE: "actor_user_role",
840
+ ACTION: "action",
841
+ RESOURCE: "resource",
842
+ RESOURCE_ID: "resource_id",
843
+ STATUS: "status",
844
+ MESSAGE: "message"
845
+ }
846
+ };
847
+
848
+ export const UserFilterValues = {
849
+ UserFilterValues: {
850
+ ROLE: "role",
851
+ ACCOUNT_STATUS: "account_status",
852
+ ACCOUNT_STATUS_ON_RESTORE: "account_status_on_restore",
853
+ ACCOUNT_LOCKOUT_TYPE: "account_lockout_type",
854
+ AUTHORITY_LEVEL_FROM: "authority_level_from",
855
+ AUTHORITY_LEVEL_TO: "authority_level_to",
856
+ IS_TOTP_ENABLED: "is_totp_enabled",
857
+ PERMISSION_CODES: "permission_codes"
858
+ },
859
+ UserIdentifierFilterValues: {
860
+ USER_ID: "user_id",
861
+ USER_AUTH_PROVIDER: "user_auth_provider",
862
+ IDENTIFIER: "identifier"
863
+ },
864
+ UserSessionFilterValues: {
865
+ USER_ID: "user_id",
866
+ USER_ROLE: "user_role",
867
+ IDENTIFIER_ID: "identifier_id",
868
+ USER_AUTH_PROVIDER: "user_auth_provider",
869
+ CLIENT_TYPE: "client_type",
870
+ USER_AGENT: "user_agent",
871
+ IP_ADDRESS: "ip_address",
872
+ LANGUAGE: "language",
873
+ DEVICE_ID: "device_id",
874
+ DEVICE_NAME: "device_name",
875
+ APP_VERSION: "app_version",
876
+ OPERATION_SYSTEM_VERSION: "operation_system_version",
877
+ IDENTIFIER: "identifier"
878
+ }
879
+ };
880
+
551
881
  export const CommonErrorCodes = {
552
882
  UNKNOWN: "UNKNOWN",
553
883
  INTERNAL: "INTERNAL",
@@ -668,6 +998,512 @@ export const UserPermissionCode = {
668
998
 
669
999
  };
670
1000
 
1001
+ export const toClientInfo = (payload) => ({
1002
+ deviceInfo: toClientDeviceInfo(payload.client_device_info),
1003
+ userAgent: payload.user_agent,
1004
+ ipAddress: payload.ip_address,
1005
+ host: null,
1006
+ origin: null,
1007
+ apiVersion: payload.api_version
1008
+ });
1009
+
1010
+ export const toClientInfoPayload = (domain) => ({
1011
+ client_device_info: toClientDeviceInfoPayload(domain.deviceInfo),
1012
+ user_agent: domain.userAgent,
1013
+ ip_address: domain.ipAddress,
1014
+ api_version: domain.apiVersion
1015
+ });
1016
+
1017
+ export const toClientDeviceInfo = (payload) => ({
1018
+ deviceId: payload.device_id ? toClientDeviceIdOrThrow(payload.device_id) : null,
1019
+ deviceName: payload.device_name,
1020
+ clientType: payload.client_type,
1021
+ language: payload.language,
1022
+ appVersion: payload.app_version,
1023
+ operationSystemVersion: payload.operation_system_version
1024
+ });
1025
+
1026
+ export const toClientDeviceInfoPayload = (domain) => ({
1027
+ client_type: domain.clientType,
1028
+ language: domain.language,
1029
+ device_id: domain.deviceId,
1030
+ device_name: domain.deviceName,
1031
+ app_version: domain.appVersion,
1032
+ operation_system_version: domain.operationSystemVersion
1033
+ });
1034
+
1035
+ export const toAccountLockoutPolicy = (payload) => ({
1036
+ maxFailedPasswordAttempts: payload.max_failed_password_attempts,
1037
+ maxFailedOtpAttempts: payload.max_failed_otp_attempts,
1038
+ maxFailedTotpAttempts: payload.max_failed_totp_attempts,
1039
+ failedAttemptsWindowSeconds: payload.failed_attempts_window_seconds,
1040
+ lockoutDurationSeconds: payload.lockout_duration_seconds,
1041
+ indefiniteLockoutThreshold: payload.indefinite_lockout_threshold,
1042
+ isSelfServiceUnlockEnabled: payload.is_self_service_unlock_enabled
1043
+ });
1044
+
1045
+ export const toAccountLockoutPolicyPayload = (domain) => ({
1046
+ max_failed_password_attempts: domain.maxFailedPasswordAttempts,
1047
+ max_failed_otp_attempts: domain.maxFailedOtpAttempts,
1048
+ max_failed_totp_attempts: domain.maxFailedTotpAttempts,
1049
+ failed_attempts_window_seconds: domain.failedAttemptsWindowSeconds,
1050
+ lockout_duration_seconds: domain.lockoutDurationSeconds,
1051
+ indefinite_lockout_threshold: domain.indefiniteLockoutThreshold,
1052
+ is_self_service_unlock_enabled: domain.isSelfServiceUnlockEnabled
1053
+ });
1054
+
1055
+ export const toIpRestrictionPolicy = (payload) => ({
1056
+ isBlacklistEnabled: payload.is_blacklist_enabled,
1057
+ blacklist: payload.blacklist,
1058
+ isWhitelistEnabled: payload.is_whitelist_enabled,
1059
+ whitelist: payload.whitelist
1060
+ });
1061
+
1062
+ export const toIpRestrictionPolicyPayload = (domain) => ({
1063
+ is_blacklist_enabled: domain.isBlacklistEnabled,
1064
+ blacklist: domain.blacklist,
1065
+ is_whitelist_enabled: domain.isWhitelistEnabled,
1066
+ whitelist: domain.whitelist
1067
+ });
1068
+
1069
+ export const toOtpConfirmation = (payload) => ({
1070
+ retryAfterSeconds: payload.retry_after_seconds,
1071
+ numberOfSymbols: payload.number_of_symbols,
1072
+ expirationSeconds: payload.expiration_seconds
1073
+ });
1074
+
1075
+ export const toOtpConfirmationPayload = (domain) => ({
1076
+ retry_after_seconds: domain.retryAfterSeconds,
1077
+ number_of_symbols: domain.numberOfSymbols,
1078
+ expiration_seconds: domain.expirationSeconds
1079
+ });
1080
+
1081
+ export const toManagementPasswordPolicy = (payload) => ({
1082
+ minLength: payload.min_length,
1083
+ requireLetter: payload.require_letter,
1084
+ requireUpperCase: payload.require_upper_case,
1085
+ requireLowerCase: payload.require_lower_case,
1086
+ requireDigit: payload.require_digit,
1087
+ requireSpecialChar: payload.require_special_char,
1088
+ commonPasswords: payload.common_passwords
1089
+ });
1090
+
1091
+ export const toManagementPasswordPolicyPayload = (domain) => ({
1092
+ min_length: domain.minLength,
1093
+ require_letter: domain.requireLetter,
1094
+ require_upper_case: domain.requireUpperCase,
1095
+ require_lower_case: domain.requireLowerCase,
1096
+ require_digit: domain.requireDigit,
1097
+ require_special_char: domain.requireSpecialChar,
1098
+ common_passwords: domain.commonPasswords
1099
+ });
1100
+
1101
+ export const toOpenPasswordPolicy = (payload) => ({
1102
+ minLength: payload.min_length,
1103
+ requireLetter: payload.require_letter,
1104
+ requireUpperCase: payload.require_upper_case,
1105
+ requireLowerCase: payload.require_lower_case,
1106
+ requireDigit: payload.require_digit,
1107
+ requireSpecialChar: payload.require_special_char
1108
+ });
1109
+
1110
+ export const toOpenPasswordPolicyPayload = (domain) => ({
1111
+ min_length: domain.minLength,
1112
+ require_letter: domain.requireLetter,
1113
+ require_upper_case: domain.requireUpperCase,
1114
+ require_lower_case: domain.requireLowerCase,
1115
+ require_digit: domain.requireDigit,
1116
+ require_special_char: domain.requireSpecialChar
1117
+ });
1118
+
1119
+ export const toManagementSecuritySettings = (payload) => ({
1120
+ recentAuthenticationValiditySecondsForOpenUser: payload.recent_authentication_validity_seconds_for_open_user,
1121
+ recentAuthenticationValiditySecondsForManagementUser: payload.recent_authentication_validity_seconds_for_management_user,
1122
+ passwordPolicy: toManagementPasswordPolicy(payload.management_password_policy),
1123
+ otpConfirmation: toOtpConfirmation(payload.otp_confirmation),
1124
+ accountLockoutPolicy: toAccountLockoutPolicy(payload.account_lockout_policy),
1125
+ accountLockoutCheckIntervalSeconds: payload.account_lockout_check_interval_seconds,
1126
+ openIpRestrictionPolicy: toIpRestrictionPolicy(payload.open_ip_restriction_policy),
1127
+ managementIpRestrictionPolicy: toIpRestrictionPolicy(payload.management_ip_restriction_policy),
1128
+ mfaTokenExpirationSeconds: payload.expiration_seconds,
1129
+ maxRequestsPerPeriod: payload.max_requests_per_period,
1130
+ rateLimitPeriodSeconds: payload.rate_limit_period_seconds,
1131
+ refreshTokenRotationGracePeriodSeconds: payload.refresh_token_rotation_grace_period_seconds
1132
+ });
1133
+
1134
+ export const toManagementSecuritySettingsPayload = (domain) => ({
1135
+ recent_authentication_validity_seconds_for_open_user: domain.recentAuthenticationValiditySecondsForOpenUser,
1136
+ recent_authentication_validity_seconds_for_management_user: domain.recentAuthenticationValiditySecondsForManagementUser,
1137
+ management_password_policy: toManagementPasswordPolicyPayload(domain.passwordPolicy),
1138
+ otp_confirmation: toOtpConfirmationPayload(domain.otpConfirmation),
1139
+ account_lockout_policy: toAccountLockoutPolicyPayload(domain.accountLockoutPolicy),
1140
+ account_lockout_check_interval_seconds: domain.accountLockoutCheckIntervalSeconds,
1141
+ open_ip_restriction_policy: toIpRestrictionPolicyPayload(domain.openIpRestrictionPolicy),
1142
+ management_ip_restriction_policy: toIpRestrictionPolicyPayload(domain.managementIpRestrictionPolicy),
1143
+ expiration_seconds: domain.mfaTokenExpirationSeconds,
1144
+ max_requests_per_period: domain.maxRequestsPerPeriod,
1145
+ rate_limit_period_seconds: domain.rateLimitPeriodSeconds,
1146
+ refresh_token_rotation_grace_period_seconds: domain.refreshTokenRotationGracePeriodSeconds
1147
+ });
1148
+
1149
+ export const toOpenSecuritySettings = (payload) => ({
1150
+ passwordPolicy: toOpenPasswordPolicy(payload.open_password_policy),
1151
+ otpConfirmation: toOtpConfirmation(payload.otp_confirmation)
1152
+ });
1153
+
1154
+ export const toOpenSecuritySettingsPayload = (domain) => ({
1155
+ open_password_policy: toOpenPasswordPolicyPayload(domain.passwordPolicy),
1156
+ otp_confirmation: toOtpConfirmationPayload(domain.otpConfirmation)
1157
+ });
1158
+
1159
+ export const toTotpRecoveryCodes = (payload) => ({
1160
+ codes: payload.totp_recovery_codes
1161
+ });
1162
+
1163
+ export const toTotpRecoveryCodesPayload = (domain) => ({
1164
+ totp_recovery_codes: domain.codes
1165
+ });
1166
+
1167
+ export const toTotpSetup = (payload) => ({
1168
+ secretKey: payload.totp_secret_key,
1169
+ otpAuthUrl: payload.totp_otp_auth_url,
1170
+ mfaToken: payload.mfa_token
1171
+ });
1172
+
1173
+ export const toTotpSetupPayload = (domain) => ({
1174
+ totp_secret_key: domain.secretKey,
1175
+ totp_otp_auth_url: domain.otpAuthUrl,
1176
+ mfa_token: domain.mfaToken
1177
+ });
1178
+
1179
+ export const toVerifyTotp = (payload) => ({
1180
+ mfaToken: payload.mfa_token,
1181
+ code: payload.totp_code
1182
+ });
1183
+
1184
+ export const toVerifyTotpPayload = (domain) => ({
1185
+ mfa_token: domain.mfaToken,
1186
+ totp_code: domain.code
1187
+ });
1188
+
1189
+ export const toManagementGlobalSettings = (payload) => ({
1190
+ privacyPolicyUrl: payload.privacy_policy_url,
1191
+ termsOfServiceUrl: payload.terms_of_service_url,
1192
+ contactSupportEmail: payload.contact_support_email,
1193
+ minSupportedAppVersions: payload.min_supported_app_versions,
1194
+ isTracingEnabled: payload.is_tracing_enabled,
1195
+ isMetricsEnabled: payload.is_metrics_enabled,
1196
+ isVerboseLoggingEnabled: payload.is_verbose_logging_enabled
1197
+ });
1198
+
1199
+ export const toManagementGlobalSettingsPayload = (domain) => ({
1200
+ privacy_policy_url: domain.privacyPolicyUrl,
1201
+ terms_of_service_url: domain.termsOfServiceUrl,
1202
+ contact_support_email: domain.contactSupportEmail,
1203
+ min_supported_app_versions: domain.minSupportedAppVersions,
1204
+ is_tracing_enabled: domain.isTracingEnabled,
1205
+ is_metrics_enabled: domain.isMetricsEnabled,
1206
+ is_verbose_logging_enabled: domain.isVerboseLoggingEnabled
1207
+ });
1208
+
1209
+ export const toOpenGlobalSettings = (payload) => ({
1210
+ privacyPolicyUrl: payload.privacy_policy_url,
1211
+ termsOfServiceUrl: payload.terms_of_service_url,
1212
+ contactSupportEmail: payload.contact_support_email,
1213
+ minSupportedAppVersions: payload.min_supported_app_versions
1214
+ });
1215
+
1216
+ export const toOpenGlobalSettingsPayload = (domain) => ({
1217
+ privacy_policy_url: domain.privacyPolicyUrl,
1218
+ terms_of_service_url: domain.termsOfServiceUrl,
1219
+ contact_support_email: domain.contactSupportEmail,
1220
+ min_supported_app_versions: domain.minSupportedAppVersions
1221
+ });
1222
+
1223
+ export const toAuditEvent = (payload) => ({
1224
+ id: toAuditEventIdOrThrow(payload.id),
1225
+ actorId: payload.actor_id,
1226
+ actorType: payload.actor_type,
1227
+ actorUserRole: payload.actor_user_role,
1228
+ action: payload.action,
1229
+ resource: payload.resource,
1230
+ resourceId: payload.resource_id,
1231
+ resourceValueSensitivity: null,
1232
+ status: payload.status,
1233
+ metadata: payload.metadata ? payload.metadata.map(val => toAuditEventMetadata(val)) : [],
1234
+ message: payload.message,
1235
+ createdAt: payload.created_at
1236
+ });
1237
+
1238
+ export const toAuditEventPayload = (domain) => ({
1239
+ id: domain.id,
1240
+ actor_id: domain.actorId,
1241
+ actor_type: domain.actorType,
1242
+ actor_user_role: domain.actorUserRole,
1243
+ action: domain.action,
1244
+ resource: domain.resource,
1245
+ resource_id: domain.resourceId,
1246
+ status: domain.status,
1247
+ metadata: domain.metadata ? domain.metadata.map(val => toAuditEventMetadataPayload(val)) : [],
1248
+ message: domain.message,
1249
+ created_at: domain.createdAt
1250
+ });
1251
+
1252
+ export const toAuditEventMetadata = (payload) => ({
1253
+ key: payload.key,
1254
+ value: payload.value
1255
+ });
1256
+
1257
+ export const toAuditEventMetadataPayload = (domain) => ({
1258
+ key: domain.key,
1259
+ value: domain.value,
1260
+ value_sensitivity: null
1261
+ });
1262
+
1263
+ export const toAuthData = (payload) => ({
1264
+ userDetails: toUserDetails(payload.user),
1265
+ sessionToken: toSessionToken(payload.session_token)
1266
+ });
1267
+
1268
+ export const toAuthDataPayload = (domain) => ({
1269
+ user: toUserDetailsPayload(domain.userDetails),
1270
+ session_token: toSessionTokenPayload(domain.sessionToken)
1271
+ });
1272
+
1273
+ export const toAvailableAuthProviders = (payload) => ({
1274
+ primary: payload.primary,
1275
+ secondary: payload.secondary
1276
+ });
1277
+
1278
+ export const toAvailableAuthProvidersPayload = (domain) => ({
1279
+ primary: domain.primary,
1280
+ secondary: domain.secondary
1281
+ });
1282
+
1283
+ export const toManagementAuthSettings = (payload) => ({
1284
+ availableAuthProviders: toAvailableAuthProviders(payload.available_auth_providers),
1285
+ maxTotalIdentifiers: payload.max_total_identifiers,
1286
+ maxEmailIdentifiers: payload.max_email_identifiers,
1287
+ maxPhoneIdentifiers: payload.max_phone_identifiers,
1288
+ maxIdentifiersPerExternalProvider: payload.max_identifiers_per_external_provider,
1289
+ maxActiveSessionsForOpenUser: payload.max_active_sessions_for_open_user,
1290
+ maxActiveSessionsForManagementUser: payload.max_active_sessions_for_management_user,
1291
+ accessTokenExpirationSeconds: payload.access_token_validity_seconds,
1292
+ refreshTokenExpirationSeconds: payload.refresh_token_validity_seconds,
1293
+ accountDeletionGracePeriodSeconds: payload.account_deletion_grace_period_seconds,
1294
+ accountDeletionCheckIntervalSeconds: payload.account_deletion_check_interval_seconds,
1295
+ isRegistrationEnabled: payload.is_registration_enabled,
1296
+ openEmailRestrictionPolicy: toEmailRestrictionPolicy(payload.open_email_restriction_policy),
1297
+ managementEmailRestrictionPolicy: toEmailRestrictionPolicy(payload.management_email_restriction_policy)
1298
+ });
1299
+
1300
+ export const toManagementAuthSettingsPayload = (domain) => ({
1301
+ available_auth_providers: toAvailableAuthProvidersPayload(domain.availableAuthProviders),
1302
+ max_total_identifiers: domain.maxTotalIdentifiers,
1303
+ max_email_identifiers: domain.maxEmailIdentifiers,
1304
+ max_phone_identifiers: domain.maxPhoneIdentifiers,
1305
+ max_identifiers_per_external_provider: domain.maxIdentifiersPerExternalProvider,
1306
+ max_active_sessions_for_open_user: domain.maxActiveSessionsForOpenUser,
1307
+ max_active_sessions_for_management_user: domain.maxActiveSessionsForManagementUser,
1308
+ access_token_validity_seconds: domain.accessTokenExpirationSeconds,
1309
+ refresh_token_validity_seconds: domain.refreshTokenExpirationSeconds,
1310
+ account_deletion_grace_period_seconds: domain.accountDeletionGracePeriodSeconds,
1311
+ account_deletion_check_interval_seconds: domain.accountDeletionCheckIntervalSeconds,
1312
+ is_registration_enabled: domain.isRegistrationEnabled,
1313
+ open_email_restriction_policy: toEmailRestrictionPolicyPayload(domain.openEmailRestrictionPolicy),
1314
+ management_email_restriction_policy: toEmailRestrictionPolicyPayload(domain.managementEmailRestrictionPolicy)
1315
+ });
1316
+
1317
+ export const toOpenAuthSettings = (payload) => ({
1318
+ availableAuthProviders: toAvailableAuthProviders(payload.available_auth_providers),
1319
+ maxTotalIdentifiers: payload.max_total_identifiers,
1320
+ maxEmailIdentifiers: payload.max_email_identifiers,
1321
+ maxPhoneIdentifiers: payload.max_phone_identifiers,
1322
+ maxIdentifiersPerExternalProvider: payload.max_identifiers_per_external_provider,
1323
+ isRegistrationEnabled: payload.is_registration_enabled
1324
+ });
1325
+
1326
+ export const toOpenAuthSettingsPayload = (domain) => ({
1327
+ available_auth_providers: toAvailableAuthProvidersPayload(domain.availableAuthProviders),
1328
+ max_total_identifiers: domain.maxTotalIdentifiers,
1329
+ max_email_identifiers: domain.maxEmailIdentifiers,
1330
+ max_phone_identifiers: domain.maxPhoneIdentifiers,
1331
+ max_identifiers_per_external_provider: domain.maxIdentifiersPerExternalProvider,
1332
+ is_registration_enabled: domain.isRegistrationEnabled
1333
+ });
1334
+
1335
+ export const toManagementUserConfiguration = (payload) => ({
1336
+ managementGlobalSettings: toManagementGlobalSettings(payload.management_global_settings),
1337
+ managementSecuritySettings: toManagementSecuritySettings(payload.management_security_settings),
1338
+ managementAuthSettings: toManagementAuthSettings(payload.management_auth_settings)
1339
+ });
1340
+
1341
+ export const toManagementUserConfigurationPayload = (domain) => ({
1342
+ management_global_settings: toManagementGlobalSettingsPayload(domain.managementGlobalSettings),
1343
+ management_security_settings: toManagementSecuritySettingsPayload(domain.managementSecuritySettings),
1344
+ management_auth_settings: toManagementAuthSettingsPayload(domain.managementAuthSettings)
1345
+ });
1346
+
1347
+ export const toOpenUserConfiguration = (payload) => ({
1348
+ openGlobalSettings: toOpenGlobalSettings(payload.open_global_settings),
1349
+ openSecuritySettings: toOpenSecuritySettings(payload.open_security_settings),
1350
+ openAuthSettings: toOpenAuthSettings(payload.open_auth_settings)
1351
+ });
1352
+
1353
+ export const toOpenUserConfigurationPayload = (domain) => ({
1354
+ open_global_settings: toOpenGlobalSettingsPayload(domain.openGlobalSettings),
1355
+ open_security_settings: toOpenSecuritySettingsPayload(domain.openSecuritySettings),
1356
+ open_auth_settings: toOpenAuthSettingsPayload(domain.openAuthSettings)
1357
+ });
1358
+
1359
+ export const toEmailRestrictionPolicy = (payload) => ({
1360
+ isBlacklistEnabled: payload.is_blacklist_enabled,
1361
+ blacklist: payload.blacklist,
1362
+ isWhitelistEnabled: payload.is_whitelist_enabled,
1363
+ whitelist: payload.whitelist
1364
+ });
1365
+
1366
+ export const toEmailRestrictionPolicyPayload = (domain) => ({
1367
+ is_blacklist_enabled: domain.isBlacklistEnabled,
1368
+ blacklist: domain.blacklist,
1369
+ is_whitelist_enabled: domain.isWhitelistEnabled,
1370
+ whitelist: domain.whitelist
1371
+ });
1372
+
1373
+ export const toUserIdentifier = (payload) => ({
1374
+ id: toUserIdentifierIdOrThrow(payload.id),
1375
+ userId: toUserIdOrThrow(payload.user_id),
1376
+ userAuthProvider: payload.user_auth_provider,
1377
+ identifier: payload.identifier,
1378
+ displayName: payload.display_name,
1379
+ externalProviderEmail: payload.external_provider_email,
1380
+ isSensitiveValuesMasked: payload.is_sensitive_values_masked,
1381
+ createdAt: payload.created_at,
1382
+ updatedAt: payload.updated_at
1383
+ });
1384
+
1385
+ export const toUserIdentifierPayload = (domain) => ({
1386
+ id: domain.id,
1387
+ user_id: domain.userId,
1388
+ user_auth_provider: domain.userAuthProvider,
1389
+ identifier: domain.identifier,
1390
+ display_name: domain.displayName,
1391
+ external_provider_email: domain.externalProviderEmail,
1392
+ is_sensitive_values_masked: domain.isSensitiveValuesMasked,
1393
+ created_at: domain.createdAt,
1394
+ updated_at: domain.updatedAt
1395
+ });
1396
+
1397
+ export const toDeletedSessions = (payload) => ({
1398
+ deletedSessionIds: payload.deleted_session_ids ? payload.deleted_session_ids.map(val => toUserSessionIdOrThrow(val)) : []
1399
+ });
1400
+
1401
+ export const toDeletedSessionsPayload = (domain) => ({
1402
+ deleted_session_ids: domain.deletedSessionIds
1403
+ });
1404
+
1405
+ export const toUserSession = (payload) => ({
1406
+ id: toUserSessionIdOrThrow(payload.id),
1407
+ userId: toUserIdOrThrow(payload.user_id),
1408
+ userRole: payload.user_role,
1409
+ identifier: payload.identifier,
1410
+ identifierId: toUserIdentifierIdOrThrow(payload.identifier_id),
1411
+ identifierDisplayName: payload.identifier_display_name,
1412
+ identifierAuthProvider: payload.identifier_auth_provider,
1413
+ deviceInfo: toClientDeviceInfo(payload.client_device_info),
1414
+ userAgent: payload.user_agent,
1415
+ ipAddress: payload.ip_address,
1416
+ expiresAt: payload.expires_at,
1417
+ lastAccessedAt: payload.last_accessed_at,
1418
+ lastReauthenticatedAt: payload.last_reauthenticated_at,
1419
+ isSensitiveValuesMasked: payload.is_sensitive_values_masked,
1420
+ createdAt: payload.created_at,
1421
+ updatedAt: payload.updated_at
1422
+ });
1423
+
1424
+ export const toUserSessionPayload = (domain) => ({
1425
+ id: domain.id,
1426
+ user_id: domain.userId,
1427
+ user_role: domain.userRole,
1428
+ identifier: domain.identifier,
1429
+ identifier_id: domain.identifierId,
1430
+ identifier_display_name: domain.identifierDisplayName,
1431
+ identifier_auth_provider: domain.identifierAuthProvider,
1432
+ client_device_info: toClientDeviceInfoPayload(domain.deviceInfo),
1433
+ user_agent: domain.userAgent,
1434
+ ip_address: domain.ipAddress,
1435
+ expires_at: domain.expiresAt,
1436
+ last_accessed_at: domain.lastAccessedAt,
1437
+ last_reauthenticated_at: domain.lastReauthenticatedAt,
1438
+ is_sensitive_values_masked: domain.isSensitiveValuesMasked,
1439
+ created_at: domain.createdAt,
1440
+ updated_at: domain.updatedAt
1441
+ });
1442
+
1443
+ export const toSessionToken = (payload) => ({
1444
+ accessToken: payload.access_token,
1445
+ refreshToken: payload.refresh_token,
1446
+ expiresAt: payload.expires_at,
1447
+ tokenType: payload.token_type,
1448
+ sessionId: toUserSessionIdOrThrow(payload.session_id),
1449
+ identifierId: toUserIdentifierIdOrThrow(payload.identifier_id)
1450
+ });
1451
+
1452
+ export const toSessionTokenPayload = (domain) => ({
1453
+ access_token: domain.accessToken,
1454
+ refresh_token: domain.refreshToken,
1455
+ expires_at: domain.expiresAt,
1456
+ token_type: domain.tokenType,
1457
+ session_id: domain.sessionId,
1458
+ identifier_id: domain.identifierId
1459
+ });
1460
+
1461
+ export const toUserDetails = (payload) => ({
1462
+ id: toUserIdOrThrow(payload.id),
1463
+ role: payload.role,
1464
+ accountStatus: payload.account_status,
1465
+ accountStatusOnRestore: payload.account_status_on_restore,
1466
+ authorityLevel: payload.authority_level,
1467
+ permissionCodes: payload.permission_codes ? payload.permission_codes.map(val => toPermissionCodeOrThrow(val)) : [],
1468
+ isTotpEnabled: payload.is_totp_enabled,
1469
+ lastLoginAt: payload.last_login_at,
1470
+ lastActiveAt: payload.last_active_at,
1471
+ createdAt: payload.created_at,
1472
+ updatedAt: payload.updated_at,
1473
+ scheduledPermanentDeletionAt: payload.scheduled_permanent_deletion_at,
1474
+ lockoutType: payload.account_lockout_type,
1475
+ temporaryLockoutUntil: payload.temporary_lockout_until
1476
+ });
1477
+
1478
+ export const toUserDetailsPayload = (domain) => ({
1479
+ id: domain.id,
1480
+ role: domain.role,
1481
+ account_status: domain.accountStatus,
1482
+ account_status_on_restore: domain.accountStatusOnRestore,
1483
+ authority_level: domain.authorityLevel,
1484
+ permission_codes: domain.permissionCodes,
1485
+ is_totp_enabled: domain.isTotpEnabled,
1486
+ last_login_at: domain.lastLoginAt,
1487
+ last_active_at: domain.lastActiveAt,
1488
+ created_at: domain.createdAt,
1489
+ updated_at: domain.updatedAt,
1490
+ scheduled_permanent_deletion_at: domain.scheduledPermanentDeletionAt,
1491
+ account_lockout_type: domain.lockoutType,
1492
+ temporary_lockout_until: domain.temporaryLockoutUntil
1493
+ });
1494
+
1495
+ export const toUserPublic = (payload) => ({
1496
+ id: toUserIdOrThrow(payload.id),
1497
+ role: payload.role,
1498
+ accountStatus: payload.account_status
1499
+ });
1500
+
1501
+ export const toUserPublicPayload = (domain) => ({
1502
+ id: domain.id,
1503
+ role: domain.role,
1504
+ account_status: domain.accountStatus
1505
+ });
1506
+
671
1507
  export const clientTypeSchema = z.enum(["web", "android", "ios", "desktop"]);
672
1508
  export const ClientType = {
673
1509
  WEB: "web",
@@ -803,6 +1639,38 @@ SELF_REGENERATE_RECOVERY_CODES: "self_regenerate_recovery_codes",
803
1639
  REFRESH_TOKEN_REUSE_DETECTED: "refresh_token_reuse_detected"
804
1640
  };
805
1641
 
1642
+ export const commonAuditMetadataKeySchema = z.enum(["device_id", "device_name", "client_type", "language", "app_version", "os_version", "user_agent", "key_ip_address", "host", "origin", "api_version", "trace_id", "denied_reason", "error_id", "error_code"]);
1643
+ export const CommonAuditMetadataKey = {
1644
+ DEVICE_ID: "device_id",
1645
+ DEVICE_NAME: "device_name",
1646
+ CLIENT_TYPE: "client_type",
1647
+ LANGUAGE: "language",
1648
+ APP_VERSION: "app_version",
1649
+ OS_VERSION: "os_version",
1650
+ USER_AGENT: "user_agent",
1651
+ IP_ADDRESS: "key_ip_address",
1652
+ HOST: "host",
1653
+ ORIGIN: "origin",
1654
+ API_VERSION: "api_version",
1655
+ TRACE_ID: "trace_id",
1656
+ DENIED_REASON: "denied_reason",
1657
+ ERROR_ID: "error_id",
1658
+ ERROR_CODE: "error_code"
1659
+ };
1660
+
1661
+ export const userAuditMetadataKeySchema = z.enum(["user_id", "session_id", "identifier_id", "email_address", "phone_number", "user_auth_provider", "external_id", "account_lockout_type", "temporary_lockout_until"]);
1662
+ export const UserAuditMetadataKey = {
1663
+ USER_ID: "user_id",
1664
+ SESSION_ID: "session_id",
1665
+ IDENTIFIER_ID: "identifier_id",
1666
+ EMAIL_ADDRESS: "email_address",
1667
+ PHONE_NUMBER: "phone_number",
1668
+ USER_AUTH_PROVIDER: "user_auth_provider",
1669
+ EXTERNAL_ID: "external_id",
1670
+ ACCOUNT_LOCKOUT_TYPE: "account_lockout_type",
1671
+ TEMPORARY_LOCKOUT_UNTIL: "temporary_lockout_until"
1672
+ };
1673
+
806
1674
  export const userAccountStatusSchema = z.enum(["active", "read_only", "banned", "security_hold", "pending_deletion"]);
807
1675
  export const UserAccountStatus = {
808
1676
  ACTIVE: "active",
@@ -1050,7 +1918,7 @@ created_at: z.number()
1050
1918
  export const auditEventMetadataPayloadSchema = z.object({
1051
1919
  key: z.string(),
1052
1920
  value: z.string(),
1053
- value_sensitivity: z.string()
1921
+ value_sensitivity: auditValueSensitivitySchema
1054
1922
  });
1055
1923
 
1056
1924
  export const authDataPayloadSchema = z.object({