( json: string, profileName: string = 'default', )
| 53 | * Parse user from JSON string |
| 54 | */ |
| 55 | const userFromJson = ( |
| 56 | json: string, |
| 57 | profileName: string = 'default', |
| 58 | ): User | undefined => { |
| 59 | try { |
| 60 | const allCredentials = credentialsSchema.parse(JSON.parse(json)) |
| 61 | const profile = allCredentials[profileName] |
| 62 | // Validate that the profile matches the user schema |
| 63 | const parsed = userSchema.safeParse(profile) |
| 64 | return parsed.success ? parsed.data : undefined |
| 65 | } catch (error) { |
| 66 | logger.error( |
| 67 | { |
| 68 | errorMessage: error instanceof Error ? error.message : String(error), |
| 69 | errorStack: error instanceof Error ? error.stack : undefined, |
| 70 | profileName, |
| 71 | }, |
| 72 | 'Error parsing user JSON', |
| 73 | ) |
| 74 | return |
| 75 | } |
| 76 | } |
| 77 | |
| 78 | /** |
| 79 | * Get user credentials from file system |
no test coverage detected