{"version":3,"file":"validateTranscendAuth-CAO5ktnu.mjs","names":[],"sources":["../src/lib/api-keys/validateTranscendAuth.ts"],"sourcesContent":["import { existsSync, readFileSync } from 'node:fs';\n\nimport { decodeCodec } from '@transcend-io/type-utils';\nimport colors from 'colors';\nimport * as t from 'io-ts';\n\nimport { StoredApiKey } from '../../codecs.js';\nimport { logger } from '../../logger.js';\n\n/**\n * Determine if the `--auth` parameter is an API key or a path to a JSON\n * file containing a list of API keys.\n *\n * @param auth - Raw auth parameter\n * @returns The API key or the list API keys\n */\nexport function validateTranscendAuth(auth: string): string | StoredApiKey[] {\n  // Ensure auth is passed\n  if (!auth) {\n    logger.error(\n      colors.red(\n        'A Transcend API key must be provided. You can specify using --auth=$TRANSCEND_API_KEY',\n      ),\n    );\n    process.exit(1);\n  }\n\n  // Read from disk\n  if (existsSync(auth)) {\n    // validate that file is a list of API keys\n    return decodeCodec(t.array(StoredApiKey), readFileSync(auth, 'utf-8'));\n  }\n\n  // Return as single API key\n  return auth;\n}\n"],"mappings":"iPAgBA,SAAgB,EAAsB,EAAuC,CAkB3E,OAhBK,IACH,EAAO,MACL,EAAO,IACL,wFACD,CACF,CACD,QAAQ,KAAK,EAAE,EAIb,EAAW,EAAK,CAEX,EAAY,EAAE,MAAM,EAAa,CAAE,EAAa,EAAM,QAAQ,CAAC,CAIjE"}