Unified · Split
| @@ -21,6 +21,12 @@ type WorkosProfile = { · 20 unmodified lines | ||
| 21 | 21 | }; |
| 22 | 22 | |
| 23 | 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 | 31 | function deriveFallbackUserLabel(workosUserId: string): string { |
| 26 | 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 | 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 | 71 | for (const nestedRecord of nestedRecords) { |
| 65 | 72 | for (const key of keys) { |
| 66 | 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 | 107 | const metadata = profileRecord.metadata; |
| 101 | − if (metadata && typeof metadata === "object") { | |
| 102 | − const metadataRecord = metadata as Record<string, unknown>; | |
| 108 | + const metadataRecord = parseRecord(metadata); | |
| 109 | + if (metadataRecord) { | |
| 103 | 110 | for (const key of keys) { |
| 104 | 111 | const parsedValue = nonEmptyTrimmedStringSchema.safeParse(metadataRecord[key]); |
| 105 | 112 | if (parsedValue.success) { |