@canaryai/cli 0.1.11 → 0.1.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{chunk-HJ2JWIJ7.js → chunk-2T64Z2NI.js} +7 -1
- package/dist/chunk-2T64Z2NI.js.map +1 -0
- package/dist/{chunk-G2X3H7AM.js → chunk-L26U3BST.js} +231 -132
- package/dist/chunk-L26U3BST.js.map +1 -0
- package/dist/{chunk-VYBCH4ZP.js → chunk-V7U52ISX.js} +2 -2
- package/dist/{feature-flag-PN5IFFQR.js → feature-flag-MFTRYRYX.js} +2 -2
- package/dist/index.js +32 -16
- package/dist/index.js.map +1 -1
- package/dist/{knobs-DAG7HD2F.js → knobs-T3O4Z3ZB.js} +2 -2
- package/dist/{local-browser-VOBIUIGT.js → local-browser-SYPTG6IQ.js} +3 -3
- package/dist/{mcp-I6FCGDDR.js → mcp-TMD2R5Z6.js} +4 -4
- package/dist/{psql-A3BADRQN.js → psql-6IFVXM3A.js} +2 -2
- package/dist/{redis-N2DSDDQU.js → redis-HZC32IEO.js} +2 -2
- package/dist/release-WOD3DAX4.js +249 -0
- package/dist/release-WOD3DAX4.js.map +1 -0
- package/package.json +1 -1
- package/dist/chunk-G2X3H7AM.js.map +0 -1
- package/dist/chunk-HJ2JWIJ7.js.map +0 -1
- /package/dist/{chunk-VYBCH4ZP.js.map → chunk-V7U52ISX.js.map} +0 -0
- /package/dist/{feature-flag-PN5IFFQR.js.map → feature-flag-MFTRYRYX.js.map} +0 -0
- /package/dist/{knobs-DAG7HD2F.js.map → knobs-T3O4Z3ZB.js.map} +0 -0
- /package/dist/{local-browser-VOBIUIGT.js.map → local-browser-SYPTG6IQ.js.map} +0 -0
- /package/dist/{mcp-I6FCGDDR.js.map → mcp-TMD2R5Z6.js.map} +0 -0
- /package/dist/{psql-A3BADRQN.js.map → psql-6IFVXM3A.js.map} +0 -0
- /package/dist/{redis-N2DSDDQU.js.map → redis-HZC32IEO.js.map} +0 -0
|
@@ -55,6 +55,11 @@ async function readStoredApiUrl(profile) {
|
|
|
55
55
|
const auth = await readStoredAuth(profile);
|
|
56
56
|
return auth?.apiUrl ?? null;
|
|
57
57
|
}
|
|
58
|
+
async function readAllStoredTokens() {
|
|
59
|
+
const auth = await readAuthFile();
|
|
60
|
+
if (!auth) return [];
|
|
61
|
+
return Object.values(auth.profiles).map((p) => p.token).filter((t) => !!t);
|
|
62
|
+
}
|
|
58
63
|
async function saveAuth(auth, profile) {
|
|
59
64
|
await fs.mkdir(AUTH_DIR, { recursive: true, mode: 448 });
|
|
60
65
|
let existing;
|
|
@@ -86,6 +91,7 @@ export {
|
|
|
86
91
|
readStoredAuth,
|
|
87
92
|
readStoredToken,
|
|
88
93
|
readStoredApiUrl,
|
|
94
|
+
readAllStoredTokens,
|
|
89
95
|
saveAuth
|
|
90
96
|
};
|
|
91
|
-
//# sourceMappingURL=chunk-
|
|
97
|
+
//# sourceMappingURL=chunk-2T64Z2NI.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/auth.ts"],"sourcesContent":["import fs from \"node:fs/promises\";\nimport os from \"node:os\";\nimport path from \"node:path\";\n\ntype StoredAuth = {\n token?: string;\n apiUrl?: string;\n orgId?: string;\n orgName?: string;\n};\n\n/** Multi-profile auth file format */\ntype MultiProfileAuth = {\n profiles: Record<string, StoredAuth>;\n default: string;\n};\n\n/** Legacy flat format (single profile) */\ntype LegacyAuth = StoredAuth;\n\nconst AUTH_DIR = path.join(os.homedir(), \".config\", \"canary-cli\");\nconst AUTH_FILE = path.join(AUTH_DIR, \"auth.json\");\n\n/** Environment URL mappings shared across CLI commands */\nexport const ENV_URLS: Record<string, { api: string; app: string }> = {\n prod: {\n api: \"https://api.trycanary.ai\",\n app: \"https://app.trycanary.ai\",\n },\n production: {\n api: \"https://api.trycanary.ai\",\n app: \"https://app.trycanary.ai\",\n },\n dev: {\n api: \"https://api.dev.trycanary.ai\",\n app: \"https://app.dev.trycanary.ai\",\n },\n local: {\n api: \"http://localhost:3000\",\n app: \"http://localhost:5173\",\n },\n};\n\nfunction isMultiProfile(data: unknown): data is MultiProfileAuth {\n return typeof data === \"object\" && data !== null && \"profiles\" in data;\n}\n\n/** Read the raw auth file and normalize to multi-profile format */\nasync function readAuthFile(): Promise<MultiProfileAuth | null> {\n try {\n const content = await fs.readFile(AUTH_FILE, \"utf8\");\n const data = JSON.parse(content) as unknown;\n\n if (isMultiProfile(data)) {\n return data;\n }\n\n // Legacy flat format — treat as the \"default\" profile\n const legacy = data as LegacyAuth;\n return {\n profiles: { default: legacy },\n default: \"default\",\n };\n } catch {\n return null;\n }\n}\n\nexport async function readStoredAuth(profile?: string): Promise<StoredAuth | null> {\n const auth = await readAuthFile();\n if (!auth) return null;\n\n const key = profile ?? auth.default;\n return auth.profiles[key] ?? null;\n}\n\nexport async function readStoredToken(profile?: string): Promise<string | null> {\n const auth = await readStoredAuth(profile);\n return auth?.token ?? null;\n}\n\nexport async function readStoredApiUrl(profile?: string): Promise<string | null> {\n const auth = await readStoredAuth(profile);\n return auth?.apiUrl ?? null;\n}\n\n/** Return all stored tokens across every profile */\nexport async function readAllStoredTokens(): Promise<string[]> {\n const auth = await readAuthFile();\n if (!auth) return [];\n return Object.values(auth.profiles)\n .map((p) => p.token)\n .filter((t): t is string => !!t);\n}\n\nexport async function saveAuth(auth: StoredAuth, profile?: string): Promise<string> {\n await fs.mkdir(AUTH_DIR, { recursive: true, mode: 0o700 });\n\n // Read existing file (may be legacy or multi-profile)\n let existing: MultiProfileAuth;\n try {\n const content = await fs.readFile(AUTH_FILE, \"utf8\");\n const data = JSON.parse(content) as unknown;\n\n if (isMultiProfile(data)) {\n existing = data;\n } else {\n // Migrate legacy flat format into profiles.default\n existing = {\n profiles: { default: data as LegacyAuth },\n default: \"default\",\n };\n }\n } catch {\n existing = { profiles: {}, default: \"default\" };\n }\n\n const key = profile ?? \"default\";\n existing.profiles[key] = auth;\n\n // Set default to this profile if no default exists yet\n if (!existing.profiles[existing.default]) {\n existing.default = key;\n }\n\n await fs.writeFile(AUTH_FILE, JSON.stringify(existing, null, 2), { encoding: \"utf8\", mode: 0o600 });\n return AUTH_FILE;\n}\n"],"mappings":";AAAA,OAAO,QAAQ;AACf,OAAO,QAAQ;AACf,OAAO,UAAU;AAkBjB,IAAM,WAAW,KAAK,KAAK,GAAG,QAAQ,GAAG,WAAW,YAAY;AAChE,IAAM,YAAY,KAAK,KAAK,UAAU,WAAW;AAG1C,IAAM,WAAyD;AAAA,EACpE,MAAM;AAAA,IACJ,KAAK;AAAA,IACL,KAAK;AAAA,EACP;AAAA,EACA,YAAY;AAAA,IACV,KAAK;AAAA,IACL,KAAK;AAAA,EACP;AAAA,EACA,KAAK;AAAA,IACH,KAAK;AAAA,IACL,KAAK;AAAA,EACP;AAAA,EACA,OAAO;AAAA,IACL,KAAK;AAAA,IACL,KAAK;AAAA,EACP;AACF;AAEA,SAAS,eAAe,MAAyC;AAC/D,SAAO,OAAO,SAAS,YAAY,SAAS,QAAQ,cAAc;AACpE;AAGA,eAAe,eAAiD;AAC9D,MAAI;AACF,UAAM,UAAU,MAAM,GAAG,SAAS,WAAW,MAAM;AACnD,UAAM,OAAO,KAAK,MAAM,OAAO;AAE/B,QAAI,eAAe,IAAI,GAAG;AACxB,aAAO;AAAA,IACT;AAGA,UAAM,SAAS;AACf,WAAO;AAAA,MACL,UAAU,EAAE,SAAS,OAAO;AAAA,MAC5B,SAAS;AAAA,IACX;AAAA,EACF,QAAQ;AACN,WAAO;AAAA,EACT;AACF;AAEA,eAAsB,eAAe,SAA8C;AACjF,QAAM,OAAO,MAAM,aAAa;AAChC,MAAI,CAAC,KAAM,QAAO;AAElB,QAAM,MAAM,WAAW,KAAK;AAC5B,SAAO,KAAK,SAAS,GAAG,KAAK;AAC/B;AAEA,eAAsB,gBAAgB,SAA0C;AAC9E,QAAM,OAAO,MAAM,eAAe,OAAO;AACzC,SAAO,MAAM,SAAS;AACxB;AAEA,eAAsB,iB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