Unified · Split
| @@ -21,6 +21,12 @@ type WorkosProfile = { · 20 unmodified lines | |||
| 21 | }; | 21 | }; |
| 22 | 22 | ||
| 23 | const nonEmptyTrimmedStringSchema = z.string().transform((value) => value.trim()).refine((value) => value.length > 0); | 23 | const nonEmptyTrimmedStringSchema = z.string().transform((value) => value.trim()).refine((value) => value.length > 0); |
| 24 | const recordSchema = z.record(z.unknown()); | ||
| 25 | |||
| 26 | function parseRecord(value: unknown): Record<string, unknown> | null { | ||
| 27 | const parsed = recordSchema.safeParse(value); | ||
| 28 | return parsed.success ? parsed.data : null; | ||
| 29 | } | ||
| 24 | 30 | ||
| 25 | function deriveFallbackUserLabel(workosUserId: string): string { | 31 | function deriveFallbackUserLabel(workosUserId: string): string { |
| 26 | return `User ${workosUserId.slice(-6)}`; | 32 | return `User ${workosUserId.slice(-6)}`; |
| @@ -60,7 +66,8 @@ function getIdentityString(identity: Record<string, unknown>, keys: string[]): s · 33 unmodified lines | |||
| 60 | } | 66 | } |
| 61 | 67 | ||
| 62 | const nestedRecords = Object.values(identity) | 68 | const nestedRecords = Object.values(identity) |
| 63 | .filter((value): value is Record<string, unknown> => Boolean(value) && typeof value === "object" && !Array.isArray(value)); | 69 | .map((value) => parseRecord(value)) |
| 70 | .filter((value): value is Record<string, unknown> => value !== null); | ||
| 64 | for (const nestedRecord of nestedRecords) { | 71 | for (const nestedRecord of nestedRecords) { |
| 65 | for (const key of keys) { | 72 | for (const key of keys) { |
| 66 | const parsedValue = nonEmptyTrimmedStringSchema.safeParse(nestedRecord[key]); | 73 | const parsedValue = nonEmptyTrimmedStringSchema.safeParse(nestedRecord[key]); |
| @@ -98,8 +105,8 @@ function getProfileString(profile: WorkosProfile | null, keys: string[]): string · 31 unmodified lines | |||
| 98 | } | 105 | } |
| 99 | 106 | ||
| 100 | const metadata = profileRecord.metadata; | 107 | const metadata = profileRecord.metadata; |
| 101 | if (metadata && typeof metadata === "object") { | 108 | const metadataRecord = parseRecord(metadata); |
| 102 | const metadataRecord = metadata as Record<string, unknown>; | 109 | if (metadataRecord) { |
| 103 | for (const key of keys) { | 110 | for (const key of keys) { |
| 104 | const parsedValue = nonEmptyTrimmedStringSchema.safeParse(metadataRecord[key]); | 111 | const parsedValue = nonEmptyTrimmedStringSchema.safeParse(metadataRecord[key]); |
| 105 | if (parsedValue.success) { | 112 | if (parsedValue.success) { |