@mudrichenkoevgeny/shared-foundation 0.0.50 → 0.0.51

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 +15 -15
  2. package/index.js +68 -54
  3. package/index.mjs +68 -54
  4. package/package.json +1 -1
package/index.d.ts CHANGED
@@ -1165,8 +1165,8 @@ readonly minSupportedAppVersions: Record<string, string>;
1165
1165
  export declare const toOpenGlobalSettings: (payload: OpenGlobalSettingsPayload) => OpenGlobalSettings;
1166
1166
  export declare const toOpenGlobalSettingsPayload: (domain: OpenGlobalSettings) => OpenGlobalSettingsPayload;
1167
1167
 
1168
- export interface AuditEvent {
1169
- readonly id: AuditEventId;
1168
+ export interface AuditEvent {
1169
+ readonly id: AuditEventId;
1170
1170
  readonly actorId: UserId | null;
1171
1171
  readonly actorType: AuditActorType;
1172
1172
  readonly actorUserRole: UserRole | null;
@@ -1178,18 +1178,18 @@ readonly status: AuditStatus;
1178
1178
  readonly metadata: AuditEventMetadata[];
1179
1179
  readonly message: string | null;
1180
1180
  readonly createdAt: Instant;
1181
- }
1182
-
1183
- export declare const toAuditEvent: (payload: AuditEventPayload) => AuditEvent;
1184
- export declare const toAuditEventPayload: (domain: AuditEvent) => AuditEventPayload;
1181
+ }
1182
+
1183
+ export declare const toAuditEvent: (payload: AuditEventPayload, actionTypeParser: CompositeAuditActionTypeParser, resourceTypeParser: CompositeAuditResourceTypeParser, metadataKeyParser: CompositeAuditMetadataKeyParser) => AuditEvent;
1184
+ export declare const toAuditEventPayload: (domain: AuditEvent) => AuditEventPayload;
1185
1185
 
1186
- export interface AuditEventMetadata {
1187
- readonly key: AuditMetadataKey;
1186
+ export interface AuditEventMetadata {
1187
+ readonly key: AuditMetadataKey;
1188
1188
  readonly value: string;
1189
- }
1190
-
1191
- export declare const toAuditEventMetadata: (payload: AuditEventMetadataPayload) => AuditEventMetadata;
1192
- export declare const toAuditEventMetadataPayload: (domain: AuditEventMetadata) => AuditEventMetadataPayload;
1189
+ }
1190
+
1191
+ export declare const toAuditEventMetadata: (payload: AuditEventMetadataPayload, metadataKeyParser: CompositeAuditMetadataKeyParser) => AuditEventMetadata;
1192
+ export declare const toAuditEventMetadataPayload: (domain: AuditEventMetadata) => AuditEventMetadataPayload;
1193
1193
 
1194
1194
  export interface AuthData {
1195
1195
  readonly userDetails: UserDetails;
@@ -1369,17 +1369,17 @@ export interface AuditResourceTypeParser {
1369
1369
  }
1370
1370
 
1371
1371
  export declare class CompositeAuditActionTypeParser {
1372
- constructor(auditActionTypes: Array<((value: string) => AuditActionType | null) | AuditActionTypeParser>);
1372
+ constructor(auditActionTypes: Array<((value: string) => AuditActionType | null) | AuditActionTypeParser | Record<string, string>>);
1373
1373
  fromValueOrThrow(value: string): AuditActionType;
1374
1374
  }
1375
1375
 
1376
1376
  export declare class CompositeAuditMetadataKeyParser {
1377
- constructor(metadataKeys: Array<((value: string) => AuditMetadataKey | null) | AuditMetadataKeyParser>);
1377
+ constructor(metadataKeys: Array<((value: string) => AuditMetadataKey | null) | AuditMetadataKeyParser | Record<string, string>>);
1378
1378
  fromValueOrThrow(value: string): AuditMetadataKey;
1379
1379
  }
1380
1380
 
1381
1381
  export declare class CompositeAuditResourceTypeParser {
1382
- constructor(auditResourceTypes: Array<((value: string) => AuditResourceType | null) | AuditResourceTypeParser>);
1382
+ constructor(auditResourceTypes: Array<((value: string) => AuditResourceType | null) | AuditResourceTypeParser | Record<string, string>>);
1383
1383
  fromValueOrThrow(value: string): AuditResourceType;
1384
1384
  }
1385
1385
 
package/index.js CHANGED
@@ -295,11 +295,16 @@ export const refreshTokenHashSchema = z.string().transform((val, ctx) => {
295
295
 
296
296
  fromValueOrThrow(value) {
297
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;
298
+ if (typeof parse === 'function') {
299
+ const result = parse(value);
300
+ if (result !== null && result !== undefined) return result;
301
+ } else if (parse && typeof parse.parseOrNull === 'function') {
302
+ const result = parse.parseOrNull(value);
303
+ if (result !== null && result !== undefined) return result;
304
+ } else if (parse && typeof parse === 'object') {
305
+ // Support passing the enum object directly (e.g. UserAuditActionType)
306
+ const matchedValue = Object.values(parse).find(val => val === value);
307
+ if (matchedValue !== undefined) return matchedValue;
303
308
  }
304
309
  }
305
310
  throw new Error("Unknown value of AuditActionType: '" + value + "'");
@@ -313,11 +318,15 @@ export class CompositeAuditMetadataKeyParser {
313
318
 
314
319
  fromValueOrThrow(value) {
315
320
  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
+ if (typeof parse === 'function') {
322
+ const result = parse(value);
323
+ if (result !== null && result !== undefined) return result;
324
+ } else if (parse && typeof parse.parseOrNull === 'function') {
325
+ const result = parse.parseOrNull(value);
326
+ if (result !== null && result !== undefined) return result;
327
+ } else if (parse && typeof parse === 'object') {
328
+ const matchedValue = Object.values(parse).find(val => val === value);
329
+ if (matchedValue !== undefined) return matchedValue;
321
330
  }
322
331
  }
323
332
  throw new Error("Unknown value of AuditMetadataKey: '" + value + "'");
@@ -331,11 +340,15 @@ export class CompositeAuditResourceTypeParser {
331
340
 
332
341
  fromValueOrThrow(value) {
333
342
  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;
343
+ if (typeof parse === 'function') {
344
+ const result = parse(value);
345
+ if (result !== null && result !== undefined) return result;
346
+ } else if (parse && typeof parse.parseOrNull === 'function') {
347
+ const result = parse.parseOrNull(value);
348
+ if (result !== null && result !== undefined) return result;
349
+ } else if (parse && typeof parse === 'object') {
350
+ const matchedValue = Object.values(parse).find(val => val === value);
351
+ if (matchedValue !== undefined) return matchedValue;
339
352
  }
340
353
  }
341
354
  throw new Error("Unknown value of AuditResourceType: '" + value + "'");
@@ -1220,45 +1233,46 @@ contact_support_email: domain.contactSupportEmail,
1220
1233
  min_supported_app_versions: domain.minSupportedAppVersions
1221
1234
  });
1222
1235
 
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
- });
1236
+ export const toAuditEvent = (payload, actionTypeParser, resourceTypeParser, metadataKeyParser) => ({
1237
+ id: toAuditEventIdOrThrow(payload.id),
1238
+ actorId: payload.actorId,
1239
+ actorType: payload.actorType,
1240
+ actorUserRole: payload.actorUserRole,
1241
+ action: actionTypeParser.fromValueOrThrow(payload.action),
1242
+ resource: resourceTypeParser.fromValueOrThrow(payload.resource),
1243
+ resourceId: payload.resourceId,
1244
+ resourceValueSensitivity: 'non_sensitive',
1245
+ status: payload.status,
1246
+ metadata: payload.metadata ? payload.metadata.map(val => toAuditEventMetadata(val, metadataKeyParser)) : [],
1247
+ message: payload.message,
1248
+ createdAt: payload.createdAt
1249
+ });
1250
+
1251
+ export const toAuditEventPayload = (domain) => ({
1252
+ id: domain.id,
1253
+ actorId: domain.actorId,
1254
+ actorType: domain.actorType,
1255
+ actorUserRole: domain.actorUserRole,
1256
+ action: domain.action,
1257
+ resource: domain.resource,
1258
+ resourceId: domain.resourceId,
1259
+ status: domain.status,
1260
+ metadata: domain.metadata ? domain.metadata.map(val => toAuditEventMetadataPayload(val)) : [],
1261
+ message: domain.message,
1262
+ createdAt: domain.createdAt
1263
+ });
1264
+
1265
+ export const toAuditEventMetadata = (payload, metadataKeyParser) => ({
1266
+ key: metadataKeyParser.fromValueOrThrow(payload.key),
1267
+ value: payload.value,
1268
+ valueSensitivity: payload.valueSensitivity
1269
+ });
1270
+
1271
+ export const toAuditEventMetadataPayload = (domain) => ({
1272
+ key: domain.key,
1273
+ value: domain.value,
1274
+ valueSensitivity: domain.valueSensitivity
1275
+ });
1262
1276
 
1263
1277
  export const toAuthData = (payload) => ({
1264
1278
  userDetails: toUserDetails(payload.user),
package/index.mjs CHANGED
@@ -295,11 +295,16 @@ export const refreshTokenHashSchema = z.string().transform((val, ctx) => {
295
295
 
296
296
  fromValueOrThrow(value) {
297
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;
298
+ if (typeof parse === 'function') {
299
+ const result = parse(value);
300
+ if (result !== null && result !== undefined) return result;
301
+ } else if (parse && typeof parse.parseOrNull === 'function') {
302
+ const result = parse.parseOrNull(value);
303
+ if (result !== null && result !== undefined) return result;
304
+ } else if (parse && typeof parse === 'object') {
305
+ // Support passing the enum object directly (e.g. UserAuditActionType)
306
+ const matchedValue = Object.values(parse).find(val => val === value);
307
+ if (matchedValue !== undefined) return matchedValue;
303
308
  }
304
309
  }
305
310
  throw new Error("Unknown value of AuditActionType: '" + value + "'");
@@ -313,11 +318,15 @@ export class CompositeAuditMetadataKeyParser {
313
318
 
314
319
  fromValueOrThrow(value) {
315
320
  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
+ if (typeof parse === 'function') {
322
+ const result = parse(value);
323
+ if (result !== null && result !== undefined) return result;
324
+ } else if (parse && typeof parse.parseOrNull === 'function') {
325
+ const result = parse.parseOrNull(value);
326
+ if (result !== null && result !== undefined) return result;
327
+ } else if (parse && typeof parse === 'object') {
328
+ const matchedValue = Object.values(parse).find(val => val === value);
329
+ if (matchedValue !== undefined) return matchedValue;
321
330
  }
322
331
  }
323
332
  throw new Error("Unknown value of AuditMetadataKey: '" + value + "'");
@@ -331,11 +340,15 @@ export class CompositeAuditResourceTypeParser {
331
340
 
332
341
  fromValueOrThrow(value) {
333
342
  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;
343
+ if (typeof parse === 'function') {
344
+ const result = parse(value);
345
+ if (result !== null && result !== undefined) return result;
346
+ } else if (parse && typeof parse.parseOrNull === 'function') {
347
+ const result = parse.parseOrNull(value);
348
+ if (result !== null && result !== undefined) return result;
349
+ } else if (parse && typeof parse === 'object') {
350
+ const matchedValue = Object.values(parse).find(val => val === value);
351
+ if (matchedValue !== undefined) return matchedValue;
339
352
  }
340
353
  }
341
354
  throw new Error("Unknown value of AuditResourceType: '" + value + "'");
@@ -1220,45 +1233,46 @@ contact_support_email: domain.contactSupportEmail,
1220
1233
  min_supported_app_versions: domain.minSupportedAppVersions
1221
1234
  });
1222
1235
 
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
- });
1236
+ export const toAuditEvent = (payload, actionTypeParser, resourceTypeParser, metadataKeyParser) => ({
1237
+ id: toAuditEventIdOrThrow(payload.id),
1238
+ actorId: payload.actorId,
1239
+ actorType: payload.actorType,
1240
+ actorUserRole: payload.actorUserRole,
1241
+ action: actionTypeParser.fromValueOrThrow(payload.action),
1242
+ resource: resourceTypeParser.fromValueOrThrow(payload.resource),
1243
+ resourceId: payload.resourceId,
1244
+ resourceValueSensitivity: 'non_sensitive',
1245
+ status: payload.status,
1246
+ metadata: payload.metadata ? payload.metadata.map(val => toAuditEventMetadata(val, metadataKeyParser)) : [],
1247
+ message: payload.message,
1248
+ createdAt: payload.createdAt
1249
+ });
1250
+
1251
+ export const toAuditEventPayload = (domain) => ({
1252
+ id: domain.id,
1253
+ actorId: domain.actorId,
1254
+ actorType: domain.actorType,
1255
+ actorUserRole: domain.actorUserRole,
1256
+ action: domain.action,
1257
+ resource: domain.resource,
1258
+ resourceId: domain.resourceId,
1259
+ status: domain.status,
1260
+ metadata: domain.metadata ? domain.metadata.map(val => toAuditEventMetadataPayload(val)) : [],
1261
+ message: domain.message,
1262
+ createdAt: domain.createdAt
1263
+ });
1264
+
1265
+ export const toAuditEventMetadata = (payload, metadataKeyParser) => ({
1266
+ key: metadataKeyParser.fromValueOrThrow(payload.key),
1267
+ value: payload.value,
1268
+ valueSensitivity: payload.valueSensitivity
1269
+ });
1270
+
1271
+ export const toAuditEventMetadataPayload = (domain) => ({
1272
+ key: domain.key,
1273
+ value: domain.value,
1274
+ valueSensitivity: domain.valueSensitivity
1275
+ });
1262
1276
 
1263
1277
  export const toAuthData = (payload) => ({
1264
1278
  userDetails: toUserDetails(payload.user),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mudrichenkoevgeny/shared-foundation",
3
- "version": "0.0.50",
3
+ "version": "0.0.51",
4
4
  "description": "Shared Foundation - TypeScript & Zod contracts and routes",
5
5
  "main": "index.js",
6
6
  "module": "index.mjs",