MCPcopy Index your code
hub / github.com/simstudioai/sim / parseServiceAccount

Function parseServiceAccount

apps/sim/lib/data-drains/destinations/utils.ts:63–83  ·  view source on GitHub ↗
(json: string)

Source from the content-addressed store, hash-verified

61 * BigQuery so a fix in one place applies to both.
62 */
63export function parseServiceAccount(json: string): ParsedServiceAccount {
64 let parsed: unknown
65 try {
66 parsed = JSON.parse(json)
67 } catch (error) {
68 throw new Error(`serviceAccountJson is not valid JSON: ${toError(error).message}`)
69 }
70 if (typeof parsed !== 'object' || parsed === null) {
71 throw new Error('serviceAccountJson must be a JSON object')
72 }
73 const obj = parsed as Record<string, unknown>
74 const clientEmail = obj.client_email
75 const privateKey = obj.private_key
76 if (typeof clientEmail !== 'string' || clientEmail.length === 0) {
77 throw new Error('serviceAccountJson is missing client_email')
78 }
79 if (typeof privateKey !== 'string' || privateKey.length === 0) {
80 throw new Error('serviceAccountJson is missing private_key')
81 }
82 return { clientEmail, privateKey }
83}
84
85/**
86 * Zod `superRefine` helper that validates a service-account JSON key string

Callers 4

testFunction · 0.90
openSessionFunction · 0.90
testFunction · 0.90
openSessionFunction · 0.90

Calls 2

toErrorFunction · 0.90
parseMethod · 0.80

Tested by 2

testFunction · 0.72
testFunction · 0.72