@canaryai/cli 0.2.12 → 0.2.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-PWWQGYFG.js → chunk-ACRIE2YR.js} +5 -2
- package/dist/chunk-ACRIE2YR.js.map +1 -0
- package/dist/{chunk-ERSNYLMZ.js → chunk-BOS2YLKH.js} +12 -8
- package/dist/chunk-BOS2YLKH.js.map +1 -0
- package/dist/{chunk-MSMC6UXW.js → chunk-IFOJT3A5.js} +1002 -253
- package/dist/chunk-IFOJT3A5.js.map +1 -0
- package/dist/{chunk-Q7WFBG5C.js → chunk-SVU2XTYZ.js} +19 -5
- package/dist/chunk-SVU2XTYZ.js.map +1 -0
- package/dist/{chunk-A44B2PEA.js → chunk-SYPQF57S.js} +40 -8
- package/dist/chunk-SYPQF57S.js.map +1 -0
- package/dist/{chunk-CEW4BDXD.js → chunk-Z3F373YR.js} +13 -6
- package/dist/chunk-Z3F373YR.js.map +1 -0
- package/dist/{debug-workflow-53ULOFJC.js → debug-workflow-K2LL6CO4.js} +10 -12
- package/dist/debug-workflow-K2LL6CO4.js.map +1 -0
- package/dist/{docs-BEE3LOCO.js → docs-SR7CW24Y.js} +19 -14
- package/dist/docs-SR7CW24Y.js.map +1 -0
- package/dist/{feature-flag-CYTDV4ZB.js → feature-flag-BIPFVVNC.js} +3 -3
- package/dist/index.d.ts +2 -2
- package/dist/index.js +36 -30
- package/dist/index.js.map +1 -1
- package/dist/{init-M6I3MG3D.js → init-KXAVWHYE.js} +4 -4
- package/dist/{issues-NLM72HLU.js → issues-EWVB52CA.js} +37 -18
- package/dist/issues-EWVB52CA.js.map +1 -0
- package/dist/{knobs-O35GAU5M.js → knobs-VYABZESR.js} +3 -3
- package/dist/{list-4K4EIGAT.js → list-RCPYLS36.js} +3 -3
- package/dist/list-RCPYLS36.js.map +1 -0
- package/dist/{local-NHXXPHZ3.js → local-34FX3M5K.js} +6 -6
- package/dist/{local-browser-VAZORCO3.js → local-browser-VPOSJS52.js} +4 -4
- package/dist/{login-ZLP64YQP.js → login-MSIM2VIH.js} +4 -4
- package/dist/{mcp-ZF5G5DCB.js → mcp-YBR7G254.js} +7 -10
- package/dist/mcp-YBR7G254.js.map +1 -0
- package/dist/{psql-2YPIRMDY.js → psql-XO5BB5L5.js} +2 -2
- package/dist/{record-V6QKFFH3.js → record-DXXQHPGT.js} +7 -7
- package/dist/record-DXXQHPGT.js.map +1 -0
- package/dist/{redis-A7GWM23E.js → redis-CQTBPZ6F.js} +2 -2
- package/dist/{release-7TI7EIGD.js → release-DW7RPQSQ.js} +2 -2
- package/dist/runner/preload.js +1 -1
- package/dist/{session-UGNJXRUW.js → session-XQGCLWNC.js} +33 -12
- package/dist/{session-UGNJXRUW.js.map → session-XQGCLWNC.js.map} +1 -1
- package/dist/{skill-ORWAPBDW.js → skill-2TXI3IKP.js} +1 -1
- package/dist/skill-2TXI3IKP.js.map +1 -0
- package/dist/{src-4VIDSK4A.js → src-F7LQ5PY2.js} +8 -2
- package/dist/{start-E532F3BU.js → start-ZOMUD6LW.js} +4 -4
- package/dist/test.js +1 -1
- package/dist/test.js.map +1 -1
- package/dist/{workflow-HXIUXRFI.js → workflow-5UZTKX7X.js} +21 -10
- package/dist/workflow-5UZTKX7X.js.map +1 -0
- package/package.json +1 -2
- package/dist/chunk-A44B2PEA.js.map +0 -1
- package/dist/chunk-CEW4BDXD.js.map +0 -1
- package/dist/chunk-ERSNYLMZ.js.map +0 -1
- package/dist/chunk-MSMC6UXW.js.map +0 -1
- package/dist/chunk-PWWQGYFG.js.map +0 -1
- package/dist/chunk-Q7WFBG5C.js.map +0 -1
- package/dist/debug-workflow-53ULOFJC.js.map +0 -1
- package/dist/docs-BEE3LOCO.js.map +0 -1
- package/dist/issues-NLM72HLU.js.map +0 -1
- package/dist/list-4K4EIGAT.js.map +0 -1
- package/dist/mcp-ZF5G5DCB.js.map +0 -1
- package/dist/record-V6QKFFH3.js.map +0 -1
- package/dist/skill-ORWAPBDW.js.map +0 -1
- package/dist/workflow-HXIUXRFI.js.map +0 -1
- /package/dist/{feature-flag-CYTDV4ZB.js.map → feature-flag-BIPFVVNC.js.map} +0 -0
- /package/dist/{init-M6I3MG3D.js.map → init-KXAVWHYE.js.map} +0 -0
- /package/dist/{knobs-O35GAU5M.js.map → knobs-VYABZESR.js.map} +0 -0
- /package/dist/{local-NHXXPHZ3.js.map → local-34FX3M5K.js.map} +0 -0
- /package/dist/{local-browser-VAZORCO3.js.map → local-browser-VPOSJS52.js.map} +0 -0
- /package/dist/{login-ZLP64YQP.js.map → login-MSIM2VIH.js.map} +0 -0
- /package/dist/{psql-2YPIRMDY.js.map → psql-XO5BB5L5.js.map} +0 -0
- /package/dist/{redis-A7GWM23E.js.map → redis-CQTBPZ6F.js.map} +0 -0
- /package/dist/{release-7TI7EIGD.js.map → release-DW7RPQSQ.js.map} +0 -0
- /package/dist/{src-4VIDSK4A.js.map → src-F7LQ5PY2.js.map} +0 -0
- /package/dist/{start-E532F3BU.js.map → start-ZOMUD6LW.js.map} +0 -0
|
@@ -100,7 +100,10 @@ async function saveAuth(auth, profile) {
|
|
|
100
100
|
if (!existing.profiles[existing.default]) {
|
|
101
101
|
existing.default = key;
|
|
102
102
|
}
|
|
103
|
-
await fs.writeFile(AUTH_FILE, JSON.stringify(existing, null, 2), {
|
|
103
|
+
await fs.writeFile(AUTH_FILE, JSON.stringify(existing, null, 2), {
|
|
104
|
+
encoding: "utf8",
|
|
105
|
+
mode: 384
|
|
106
|
+
});
|
|
104
107
|
return AUTH_FILE;
|
|
105
108
|
}
|
|
106
109
|
async function resolveConfig(argv) {
|
|
@@ -147,4 +150,4 @@ export {
|
|
|
147
150
|
saveAuth,
|
|
148
151
|
resolveConfig
|
|
149
152
|
};
|
|
150
|
-
//# sourceMappingURL=chunk-
|
|
153
|
+
//# sourceMappingURL=chunk-ACRIE2YR.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';\nimport process from 'node:process';\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/* ── Shared argv helpers ─────────────────────────────────────────────── */\n\nexport function getArgValue(argv: string[], key: string): string | undefined {\n const index = argv.indexOf(key);\n if (index === -1 || index >= argv.length - 1) return undefined;\n return argv[index + 1];\n}\n\nexport function hasFlag(argv: string[], ...flags: string[]): boolean {\n return flags.some((flag) => argv.includes(flag));\n}\n\n/* ── Environment / profile mapping ───────────────────────────────────── */\n\n/** Map --env values to profile names for multi-profile auth storage */\nexport function envToProfile(env: string): string {\n if (env === 'prod' || env === 'production') return 'production';\n if (env === 'dev') return 'dev';\n if (env === 'local') return 'local';\n return env;\n}\n\nconst VALID_ENVS = ['prod', 'dev', 'local'];\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), {\n encoding: 'utf8',\n mode: 0o600,\n });\n return AUTH_FILE;\n}\n\n/* ── Shared config resolution ────────────────────────────────────────── */\n\ntype ResolvedConfig = { apiUrl: string; token: string };\n\n/**\n * Resolve API URL and auth token from argv flags, env vars, and stored profiles.\n * Used by knobs, feature-flag, release, and debug-session commands.\n */\nexport async function resolveConfig(argv: string[]): Promise<ResolvedConfig> {\n const env = getArgValue(argv, '--env');\n const profile = env ? envToProfile(env) : undefined;\n\n if (env && !ENV_URLS[env]) {\n console.error(`Unknown environment: ${env}`);\n console.error(`Valid environments: ${VALID_ENVS.join(', ')}`);\n process.exit(1);\n }\n\n const storedApiUrl = await readStoredApiUrl(profile);\n const apiUrl =\n getArgValue(argv, '--api-url') ??\n (env ? ENV_URLS[env].api : undefined) ??\n process.env.CANARY_API_URL ??\n storedApiUrl ??\n 'https://api.trycanary.ai';\n\n // Explicit --token flag always wins\n const explicitToken = getArgValue(argv, '--token');\n\n let token: string | null;\n if (explicitToken) {\n token = explicitToken;\n } else if (profile) {\n // --env was specified: profile token takes priority, env var is fallback\n token = (await readStoredToken(profile)) ?? process.env.CANARY_API_TOKEN ?? null;\n if (!token) {\n console.error(`Error: No token found for \"${env}\" profile.`);\n console.error(`Run: canary login --env ${env}`);\n process.exit(1);\n }\n } else {\n // No --env: env var first, then default profile\n token = process.env.CANARY_API_TOKEN ?? (await readStoredToken()) ?? null;\n if (!token) {\n console.error('Error: No API token found.');\n console.error('Run: canary login');\n process.exit(1);\n }\n }\n\n return { apiUrl, token };\n}\n"],"mappings":";;;AAAA,OAAO,QAAQ;AACf,OAAO,QAAQ;AACf,OAAO,UAAU;AACjB,OAAO,aAAa;AAkBpB,IAAM,WAAW,KAAK,KAAK,GAAG,QAAQ,GAAG,WAAW,YAAY;AAChE,IAAM,YAAY,KAAK,KAAK,UAAU,WAAW;AAI1C,SAAS,YAAY,MAAgB,KAAiC;AAC3E,QAAM,QAAQ,KAAK,QAAQ,GAAG;AAC9B,MAAI,UAAU,MAAM,SAAS,KAAK,SAAS,EAAG,QAAO;AACrD,SAAO,KAAK,QAAQ,CAAC;AACvB;AAEO,SAAS,QAAQ,SAAmB,OAA0B;AACnE,SAAO,MAAM,KAAK,CAAC,SAAS,KAAK,SAAS,IAAI,CAAC;AACjD;AAKO,SAAS,aAAa,KAAqB;AACh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5B,MAAM,SAAS,GAAG,EAAE,MAAM,WAC3B,QAAQ,IAAI,kBACZ,gBACA;AAGF,QAAM,gBAAgB,YAAY,MAAM,SAAS;AAEjD,MAAI;AACJ,MAAI,eAAe;AACjB,YAAQ;AAAA,EACV,WAAW,SAAS;AAElB,YAAS,MAAM,gBAAgB,OAAO,KAAM,QAAQ,IAAI,oBAAoB;AAC5E,QAAI,CAAC,OAAO;AACV,cAAQ,MAAM,8BAA8B,GAAG,YAAY;AAC3D,cAAQ,MAAM,2BAA2B,GAAG,EAAE;AAC9C,cAAQ,KAAK,CAAC;AAAA,IAChB;AAAA,EACF,OAAO;AAEL,YAAQ,QAAQ,IAAI,oBAAqB,MAAM,gBAAgB,KAAM;AACrE,QAAI,CAAC,OAAO;AACV,cAAQ,MAAM,4BAA4B;AAC1C,cAAQ,MAAM,mBAAmB;AACjC,cAAQ,KAAK,CAAC;AAAA,IAChB;AAAA,EACF;AAEA,SAAO,EAAE,QAAQ,MAAM;AACzB;","names":[]}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { createRequire as __cr } from "module"; const require = __cr(import.meta.url);
|
|
2
2
|
import {
|
|
3
3
|
getArgValue
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-ACRIE2YR.js";
|
|
5
5
|
import {
|
|
6
6
|
getCanaryTmpDir
|
|
7
7
|
} from "./chunk-XAA5VQ5N.js";
|
|
@@ -23,7 +23,9 @@ function toLifecycleLabel(stage) {
|
|
|
23
23
|
function parseLifecycleStage(argv) {
|
|
24
24
|
const stage = getArgValue(argv, "--stage");
|
|
25
25
|
if (!stage || !["active", "deprecated", "ready_for_cleanup"].includes(stage)) {
|
|
26
|
-
console.error(
|
|
26
|
+
console.error(
|
|
27
|
+
"Error: --stage is required and must be one of: active, deprecated, ready_for_cleanup"
|
|
28
|
+
);
|
|
27
29
|
process.exit(1);
|
|
28
30
|
}
|
|
29
31
|
return stage;
|
|
@@ -45,10 +47,7 @@ async function apiRequest(apiUrl, token, method, path2, body) {
|
|
|
45
47
|
return await res.json();
|
|
46
48
|
}
|
|
47
49
|
async function downloadStorageState(opts) {
|
|
48
|
-
const tmpFile = path.join(
|
|
49
|
-
getCanaryTmpDir(),
|
|
50
|
-
`${opts.prefix ?? "canary-ss"}-${Date.now()}.json`
|
|
51
|
-
);
|
|
50
|
+
const tmpFile = path.join(getCanaryTmpDir(), `${opts.prefix ?? "canary-ss"}-${Date.now()}.json`);
|
|
52
51
|
try {
|
|
53
52
|
const res = await fetch(
|
|
54
53
|
`${opts.apiUrl}/org/properties/${opts.propertyId}/credentials/${opts.credentialId}/storage-state/download`,
|
|
@@ -67,7 +66,12 @@ async function downloadStorageState(opts) {
|
|
|
67
66
|
return void 0;
|
|
68
67
|
}
|
|
69
68
|
async function selectCredential(apiUrl, token, credentialArg) {
|
|
70
|
-
const credentials = await fetchList(
|
|
69
|
+
const credentials = await fetchList(
|
|
70
|
+
apiUrl,
|
|
71
|
+
token,
|
|
72
|
+
"/org/credentials",
|
|
73
|
+
"items"
|
|
74
|
+
);
|
|
71
75
|
if (credentials.length === 0) {
|
|
72
76
|
console.error("No credentials found. Create one first in the web app.");
|
|
73
77
|
return null;
|
|
@@ -226,4 +230,4 @@ export {
|
|
|
226
230
|
uploadStorageState,
|
|
227
231
|
fetchList
|
|
228
232
|
};
|
|
229
|
-
//# sourceMappingURL=chunk-
|
|
233
|
+
//# sourceMappingURL=chunk-BOS2YLKH.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/cli-helpers.ts"],"sourcesContent":["/**\n * Shared CLI helpers for superadmin management commands (knobs, feature-flags).\n */\n\nimport fs from 'node:fs/promises';\nimport path from 'node:path';\nimport process from 'node:process';\nimport { getCanaryTmpDir } from '@chatsdet/tmp';\nimport { getArgValue } from './auth.js';\n\nexport type LifecycleStage = 'active' | 'deprecated' | 'ready_for_cleanup';\n\nexport function toLifecycleLabel(stage: LifecycleStage): string {\n switch (stage) {\n case 'deprecated':\n return 'deprecated';\n case 'ready_for_cleanup':\n return 'ready_for_cleanup';\n default:\n return 'active';\n }\n}\n\nexport function parseLifecycleStage(argv: string[]): LifecycleStage {\n const stage = getArgValue(argv, '--stage');\n if (!stage || !['active', 'deprecated', 'ready_for_cleanup'].includes(stage)) {\n console.error(\n 'Error: --stage is required and must be one of: active, deprecated, ready_for_cleanup'\n );\n process.exit(1);\n }\n return stage as LifecycleStage;\n}\n\nexport async function apiRequest<T extends { ok: boolean; error?: string }>(\n apiUrl: string,\n token: string,\n method: string,\n path: string,\n body?: Record<string, unknown>\n): Promise<T> {\n const res = await fetch(`${apiUrl}${path}`, {\n method,\n headers: {\n Authorization: `Bearer ${token}`,\n 'Content-Type': 'application/json',\n },\n ...(body ? { body: JSON.stringify(body) } : {}),\n });\n\n if (res.status === 401) {\n console.error('Error: Unauthorized. Your session may have expired.');\n console.error('Run: canary login');\n process.exit(1);\n }\n\n return (await res.json()) as T;\n}\n\nexport async function downloadStorageState(opts: {\n apiUrl: string;\n token: string;\n propertyId: string;\n credentialId: string;\n prefix?: string;\n}): Promise<string | undefined> {\n const tmpFile = path.join(getCanaryTmpDir(), `${opts.prefix ?? 'canary-ss'}-${Date.now()}.json`);\n try {\n const res = await fetch(\n `${opts.apiUrl}/org/properties/${opts.propertyId}/credentials/${opts.credentialId}/storage-state/download`,\n {\n headers: { Authorization: `Bearer ${opts.token}` },\n redirect: 'follow',\n }\n );\n if (res.ok) {\n const body = await res.text();\n await fs.writeFile(tmpFile, body, 'utf-8');\n return tmpFile;\n }\n } catch {\n // Caller handles missing storage state\n }\n return undefined;\n}\n\n/* ── Credential selection ─────────────────────────────────────────────── */\n\nexport interface CredentialListItem {\n id: string;\n name: string;\n propertyId: string;\n propertyName?: string;\n propertyBaseUrl?: string;\n loginUrl?: string;\n storageStateS3Key?: string | null;\n}\n\n/**\n * Fetch org credentials and let the user pick one interactively.\n *\n * @param credentialArg - Credential name or ID to auto-select, or undefined for interactive\n * @returns The selected credential, or null if none found / invalid selection\n */\nexport async function selectCredential(\n apiUrl: string,\n token: string,\n credentialArg?: string\n): Promise<CredentialListItem | null> {\n const credentials = await fetchList<CredentialListItem>(\n apiUrl,\n token,\n '/org/credentials',\n 'items'\n );\n\n if (credentials.length === 0) {\n console.error('No credentials found. Create one first in the web app.');\n return null;\n }\n\n if (credentialArg) {\n const match = credentials.find(\n (c) => c.id === credentialArg || c.name.toLowerCase() === credentialArg.toLowerCase()\n );\n if (!match) {\n console.error(`Credential \"${credentialArg}\" not found.`);\n console.error('Available credentials:');\n for (const c of credentials) {\n const baseUrl = c.propertyBaseUrl ? ` — ${c.propertyBaseUrl}` : '';\n console.error(` - ${c.name} [${c.propertyName ?? c.propertyId}${baseUrl}]`);\n }\n return null;\n }\n return match;\n }\n\n // Interactive selection\n console.log('\\nSelect a credential:\\n');\n const labels = credentials.map((c) => {\n const property = c.propertyName ?? c.propertyId;\n const baseUrl = c.propertyBaseUrl ? ` — ${c.propertyBaseUrl}` : '';\n return `${c.name} [${property}${baseUrl}]`;\n });\n\n const readline = await import('node:readline');\n const rl = readline.createInterface({ input: process.stdin, output: process.stdout });\n const answer = await new Promise<string>((resolve) => {\n for (let i = 0; i < labels.length; i++) {\n console.log(` ${i + 1}. ${labels[i]}`);\n }\n rl.question('\\nEnter number: ', (ans) => {\n rl.close();\n resolve(ans.trim());\n });\n });\n\n const idx = parseInt(answer, 10) - 1;\n if (isNaN(idx) || idx < 0 || idx >= credentials.length) {\n console.error('Invalid selection.');\n return null;\n }\n\n return credentials[idx];\n}\n\n/* ── Property selection ──────────────────────────────────────────────── */\n\ninterface PropertyListItem {\n id: string;\n name: string;\n baseUrl: string;\n}\n\nexport async function fetchProperties(apiUrl: string, token: string): Promise<PropertyListItem[]> {\n return fetchList<PropertyListItem>(apiUrl, token, '/org/properties', 'data');\n}\n\nexport async function selectProperty(\n apiUrl: string,\n token: string,\n hint?: string\n): Promise<PropertyListItem | null> {\n const properties = await fetchProperties(apiUrl, token);\n\n if (properties.length === 0) {\n console.error('No properties found. Create one first in the web app.');\n return null;\n }\n\n if (hint) {\n const match = properties.find(\n (p) => p.id === hint || p.name.toLowerCase() === hint.toLowerCase()\n );\n if (!match) {\n console.error(`Property \"${hint}\" not found.`);\n console.error('Available properties:');\n for (const p of properties) {\n console.error(` - ${p.name} (${p.baseUrl})`);\n }\n return null;\n }\n return match;\n }\n\n if (properties.length === 1) {\n console.log(`Auto-selected property: ${properties[0].name}`);\n return properties[0];\n }\n\n return promptChoice(\n 'Select a property:',\n properties.map((p) => ({ label: `${p.name} — ${p.baseUrl}`, value: p }))\n );\n}\n\n/* ── Interactive prompt helpers ──────────────────────────────────────── */\n\nexport async function promptInput(question: string, defaultValue?: string): Promise<string> {\n const readline = await import('node:readline');\n const rl = readline.createInterface({ input: process.stdin, output: process.stdout });\n const prompt = defaultValue ? `${question} [${defaultValue}]: ` : `${question}: `;\n const answer = await new Promise<string>((resolve) => {\n rl.question(prompt, (ans) => {\n rl.close();\n resolve(ans.trim());\n });\n });\n return answer || defaultValue || '';\n}\n\nexport async function promptChoice<T>(\n question: string,\n options: Array<{ label: string; value: T }>\n): Promise<T | null> {\n console.log(`\\n${question}\\n`);\n for (let i = 0; i < options.length; i++) {\n console.log(` ${i + 1}. ${options[i].label}`);\n }\n const readline = await import('node:readline');\n const rl = readline.createInterface({ input: process.stdin, output: process.stdout });\n const answer = await new Promise<string>((resolve) => {\n rl.question('\\nEnter number: ', (ans) => {\n rl.close();\n resolve(ans.trim());\n });\n });\n\n const idx = parseInt(answer, 10) - 1;\n if (isNaN(idx) || idx < 0 || idx >= options.length) {\n console.error('Invalid selection.');\n return null;\n }\n return options[idx].value;\n}\n\nexport async function uploadStorageState(opts: {\n apiUrl: string;\n token: string;\n propertyId: string;\n credentialId: string;\n storageState: unknown;\n}): Promise<{ ok: boolean; s3Key?: string; error?: string }> {\n const res = await fetch(\n `${opts.apiUrl}/org/properties/${opts.propertyId}/credentials/${opts.credentialId}/storage-state/upload`,\n {\n method: 'PUT',\n headers: {\n Authorization: `Bearer ${opts.token}`,\n 'Content-Type': 'application/json',\n },\n body: JSON.stringify({ storageState: opts.storageState }),\n }\n );\n\n if (res.status === 401) {\n console.error('Error: Unauthorized. Your session may have expired.');\n console.error('Run: canary login');\n process.exit(1);\n }\n\n return (await res.json()) as { ok: boolean; s3Key?: string; error?: string };\n}\n\nexport async function fetchList<T>(\n apiUrl: string,\n token: string,\n path: string,\n listKey: string\n): Promise<T[]> {\n const res = await fetch(`${apiUrl}${path}`, {\n headers: { Authorization: `Bearer ${token}` },\n });\n\n if (res.status === 401) {\n console.error('Error: Unauthorized. Your session may have expired.');\n console.error('Run: canary login');\n process.exit(1);\n }\n\n const json = (await res.json()) as Record<string, unknown>;\n\n if (!json.ok) {\n console.error(`Error: ${json.error}`);\n process.exit(1);\n }\n\n return (json[listKey] as T[]) ?? [];\n}\n"],"mappings":";;;;;;;;;AAIA,OAAO,QAAQ;AACf,OAAO,UAAU;AACjB,OAAO,aAAa;AAMb,SAAS,iBAAiB,OAA+B;AAC9D,UAAQ,OAAO;AAAA,IACb,KAAK;AACH,aAAO;AAAA,IACT,KAAK;AACH,aAAO;AAAA,IACT;AACE,aAAO;AAAA,EACX;AACF;AAEO,SAAS,oBAAoB,MAAgC;AAClE,QAAM,QAAQ,YAAY,MAAM,SAAS;AACzC,MAAI,CAAC,SAAS,CAAC,CAAC,UAAU,cAAc,mBAAmB,EAAE,SAAS,KAAK,GAAG;AAC5E,YAAQ;AAAA,MACN;AAAA,IACF;AACA,YAAQ,KAAK,CAAC;AAAA,EAChB;AACA,SAAO;AACT;AAEA,eAAsB,WACpB,QACA,OACA,QACAA,OACA,MACY;AACZ,QAAM,MAAM,MAAM,MAAM,GAAG,MAAM,GAAGA,KAAI,IAAI;AAAA,IAC1C;AAAA,IACA,SAAS;AAAA,MACP,eAAe,UAAU,KAAK;AAAA,MAC9B,gBAAgB;AAAA,IAClB;AAAA,IACA,GAAI,OAAO,EAAE,MAAM,KAAK,UAAU,IAAI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