donebear 0.3.6 → 0.3.8
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/AGENTS.md +3 -3
- package/dist/cli.mjs +3364 -251
- package/dist/cli.mjs.map +1 -1
- package/dist/context-store-CK4yIl9e.mjs +3 -0
- package/dist/{context-store-DH561Z1u.mjs → context-store-DuCNavgl.mjs} +3 -3
- package/dist/context-store-DuCNavgl.mjs.map +1 -0
- package/dist/prompt-B7mDo4K7.mjs +3 -0
- package/dist/{prompt-BrfcK2Ry.mjs → prompt-GfcWO85b.mjs} +2 -2
- package/dist/prompt-GfcWO85b.mjs.map +1 -0
- package/package.json +8 -12
- package/dist/context-store-D0Z9vbaU.mjs +0 -3
- package/dist/context-store-DH561Z1u.mjs.map +0 -1
- package/dist/prompt-BrfcK2Ry.mjs.map +0 -1
- package/dist/prompt-FRvfbinv.mjs +0 -3
|
@@ -98,13 +98,13 @@ const writeContext = async (context) => {
|
|
|
98
98
|
recursive: true
|
|
99
99
|
});
|
|
100
100
|
await writeFile(CONTEXT_FILE_PATH, `${JSON.stringify(payload, null, 2)}\n`, {
|
|
101
|
-
encoding: "
|
|
101
|
+
encoding: "utf-8",
|
|
102
102
|
mode: 384
|
|
103
103
|
});
|
|
104
104
|
};
|
|
105
105
|
const readLocalContext = async () => {
|
|
106
106
|
try {
|
|
107
|
-
return parseContextFile(await readFile(CONTEXT_FILE_PATH, "
|
|
107
|
+
return parseContextFile(await readFile(CONTEXT_FILE_PATH, "utf-8")).context;
|
|
108
108
|
} catch (error) {
|
|
109
109
|
if (isRecord(error) && error.code === "ENOENT") return null;
|
|
110
110
|
if (error instanceof CliError) throw error;
|
|
@@ -132,4 +132,4 @@ const setCurrentWorkspace = async (workspaceId) => {
|
|
|
132
132
|
//#endregion
|
|
133
133
|
export { DONEBEAR_OAUTH_CLIENT_ID_ENV as _, toCliError as a, DONEBEAR_TOKEN_ENV as b, CLI_OAUTH_CLIENT_ID as c, DEFAULT_OAUTH_CALLBACK_PATH as d, DEFAULT_OAUTH_CALLBACK_PORT as f, DONEBEAR_DEBUG_ENV as g, DONEBEAR_API_URL_ENV as h, EXIT_CODES as i, CONFIG_DIR as l, DEFAULT_SUPABASE_URL as m, setCurrentWorkspace as n, AUTH_FILE_PATH as o, DEFAULT_SUPABASE_PUBLISHABLE_KEY as p, CliError as r, CLI_NAME as s, ensureLocalContext as t, DEFAULT_API_URL as u, DONEBEAR_SUPABASE_KEY_ENV as v, DONEBEAR_SUPABASE_URL_ENV as y };
|
|
134
134
|
|
|
135
|
-
//# sourceMappingURL=context-store-
|
|
135
|
+
//# sourceMappingURL=context-store-DuCNavgl.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context-store-DuCNavgl.mjs","names":[],"sources":["../src/constants.ts","../src/errors.ts","../src/context-store.ts"],"sourcesContent":["import { homedir } from \"node:os\";\nimport { join } from \"node:path\";\n\nexport const CLI_NAME = \"donebear\";\n\nexport const DONEBEAR_TOKEN_ENV = \"DONEBEAR_TOKEN\";\nexport const DONEBEAR_DEBUG_ENV = \"DONEBEAR_DEBUG\";\nconst DONEBEAR_CONFIG_DIR_ENV = \"DONEBEAR_CONFIG_DIR\";\nexport const DONEBEAR_SUPABASE_URL_ENV = \"DONEBEAR_SUPABASE_URL\";\nexport const DONEBEAR_SUPABASE_KEY_ENV = \"DONEBEAR_SUPABASE_PUBLISHABLE_KEY\";\nexport const DONEBEAR_API_URL_ENV = \"DONEBEAR_API_URL\";\n\nexport const DEFAULT_API_URL = \"https://api.donebear.com\";\n\nexport const DEFAULT_SUPABASE_URL = \"https://kdarvputxmlxqemisnbh.supabase.co\";\nexport const DEFAULT_SUPABASE_PUBLISHABLE_KEY =\n \"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6ImtkYXJ2cHV0eG1seHFlbWlzbmJoIiwicm9sZSI6ImFub24iLCJpYXQiOjE3NzIzNTcyNjcsImV4cCI6MjA4NzkzMzI2N30.A8sDPWNe_1EcCy0-GsUw4h1icxSGz_VDc9E9tPTYEU8\";\n\nexport const CLI_OAUTH_CLIENT_ID = \"9cc84e5c-6a0e-4a6d-93a2-334d8d307122\";\nexport const DONEBEAR_OAUTH_CLIENT_ID_ENV = \"DONEBEAR_OAUTH_CLIENT_ID\";\n\nexport const DEFAULT_OAUTH_CALLBACK_PORT = 8787;\nexport const DEFAULT_OAUTH_CALLBACK_PATH = \"/auth/callback\";\nexport const DEFAULT_OAUTH_TIMEOUT_SECONDS = 180;\n\nconst getDefaultConfigBaseDir = (): string => {\n if (process.platform === \"win32\") {\n return process.env.APPDATA ?? join(homedir(), \"AppData\", \"Roaming\");\n }\n\n return process.env.XDG_CONFIG_HOME ?? join(homedir(), \".config\");\n};\n\nconst configBaseDir = getDefaultConfigBaseDir();\n\nexport const CONFIG_DIR =\n process.env[DONEBEAR_CONFIG_DIR_ENV] ?? join(configBaseDir, CLI_NAME);\n\nexport const AUTH_FILE_PATH = join(CONFIG_DIR, \"auth.json\");\nexport const CONTEXT_FILE_PATH = join(CONFIG_DIR, \"context.json\");\n","export const EXIT_CODES = {\n AUTH_REQUIRED: 4,\n CANCELLED: 2,\n ERROR: 1,\n NETWORK: 5,\n SUCCESS: 0,\n VALIDATION: 3,\n} as const;\n\ntype ExitCode = (typeof EXIT_CODES)[keyof typeof EXIT_CODES];\n\ntype ErrorCode =\n | \"unknown_error\"\n | \"cancelled\"\n | \"validation_error\"\n | \"auth_error\"\n | \"network_error\";\n\nconst EXIT_CODE_TO_ERROR_CODE: Record<ExitCode, ErrorCode> = {\n [EXIT_CODES.SUCCESS]: \"unknown_error\",\n [EXIT_CODES.ERROR]: \"unknown_error\",\n [EXIT_CODES.CANCELLED]: \"cancelled\",\n [EXIT_CODES.VALIDATION]: \"validation_error\",\n [EXIT_CODES.AUTH_REQUIRED]: \"auth_error\",\n [EXIT_CODES.NETWORK]: \"network_error\",\n};\n\nconst exitCodeToErrorCode = (exitCode: ExitCode): ErrorCode =>\n EXIT_CODE_TO_ERROR_CODE[exitCode] ?? \"unknown_error\";\n\nexport class CliError extends Error {\n readonly exitCode: ExitCode;\n readonly code: ErrorCode;\n readonly hint: string | null;\n\n constructor(\n message: string,\n exitCode: ExitCode = EXIT_CODES.ERROR,\n hint?: string\n ) {\n super(message);\n this.name = \"CliError\";\n this.exitCode = exitCode;\n this.code = exitCodeToErrorCode(exitCode);\n this.hint = hint ?? null;\n }\n}\n\nexport const toCliError = (error: unknown): CliError => {\n if (error instanceof CliError) {\n return error;\n }\n\n if (error instanceof Error) {\n // Network errors (fetch failures)\n if (error instanceof TypeError && error.message.includes(\"fetch\")) {\n return new CliError(\n \"Cannot connect to Done Bear API.\",\n EXIT_CODES.NETWORK,\n \"Check your internet connection and API URL configuration.\"\n );\n }\n\n // Timeout errors\n if (error.name === \"TimeoutError\" || error.name === \"AbortError\") {\n return new CliError(\n \"Request timed out.\",\n EXIT_CODES.NETWORK,\n \"The API may be unavailable. Try again later.\"\n );\n }\n\n return new CliError(error.message, EXIT_CODES.ERROR);\n }\n\n return new CliError(\"Unknown error\", EXIT_CODES.ERROR);\n};\n","import { randomUUID } from \"node:crypto\";\nimport { mkdir, readFile, writeFile } from \"node:fs/promises\";\n\nimport { CONFIG_DIR, CONTEXT_FILE_PATH } from \"./constants\";\nimport { CliError, EXIT_CODES } from \"./errors\";\nimport type { CliContextFileData, LocalCliContext } from \"./types\";\n\nconst isRecord = (value: unknown): value is Record<string, unknown> =>\n typeof value === \"object\" && value !== null;\n\nconst parseLocalContext = (value: unknown): LocalCliContext | null => {\n if (!isRecord(value)) {\n return null;\n }\n\n if (value.workspaceId !== null && typeof value.workspaceId !== \"string\") {\n return null;\n }\n\n if (typeof value.clientId !== \"string\" || value.clientId.length === 0) {\n return null;\n }\n\n return {\n clientId: value.clientId,\n workspaceId: value.workspaceId,\n };\n};\n\nconst parseContextFile = (payload: string): CliContextFileData => {\n const parsed = JSON.parse(payload) as unknown;\n\n if (!isRecord(parsed) || parsed.version !== 1) {\n throw new CliError(\n `Invalid CLI context format in ${CONTEXT_FILE_PATH}`,\n EXIT_CODES.ERROR\n );\n }\n\n const context = parseLocalContext(parsed.context);\n\n if (!context) {\n throw new CliError(\n `Invalid CLI context in ${CONTEXT_FILE_PATH}`,\n EXIT_CODES.ERROR\n );\n }\n\n return {\n context,\n version: 1,\n };\n};\n\nconst writeContext = async (context: LocalCliContext): Promise<void> => {\n const payload: CliContextFileData = {\n context,\n version: 1,\n };\n\n await mkdir(CONFIG_DIR, {\n mode: 0o700,\n recursive: true,\n });\n\n await writeFile(CONTEXT_FILE_PATH, `${JSON.stringify(payload, null, 2)}\\n`, {\n encoding: \"utf-8\",\n mode: 0o600,\n });\n};\n\nconst readLocalContext = async (): Promise<LocalCliContext | null> => {\n try {\n const raw = await readFile(CONTEXT_FILE_PATH, \"utf-8\");\n return parseContextFile(raw).context;\n } catch (error) {\n if (isRecord(error) && error.code === \"ENOENT\") {\n return null;\n }\n\n if (error instanceof CliError) {\n throw error;\n }\n\n throw new CliError(\n `Failed to read context from ${CONTEXT_FILE_PATH}`,\n EXIT_CODES.ERROR\n );\n }\n};\n\nexport const ensureLocalContext = async (): Promise<LocalCliContext> => {\n const existing = await readLocalContext();\n\n if (existing) {\n return existing;\n }\n\n const created: LocalCliContext = {\n clientId: randomUUID(),\n workspaceId: null,\n };\n\n await writeContext(created);\n return created;\n};\n\nexport const setCurrentWorkspace = async (\n workspaceId: string | null\n): Promise<LocalCliContext> => {\n const context = await ensureLocalContext();\n\n const nextContext: LocalCliContext = {\n ...context,\n workspaceId,\n };\n\n await writeContext(nextContext);\n return nextContext;\n};\n"],"mappings":";;;;;;AAGA,MAAa,WAAW;AAExB,MAAa,qBAAqB;AAClC,MAAa,qBAAqB;AAClC,MAAM,0BAA0B;AAChC,MAAa,4BAA4B;AACzC,MAAa,4BAA4B;AACzC,MAAa,uBAAuB;AAEpC,MAAa,kBAAkB;AAE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,MAAM,kBAAkB;CAEzC,IAAI,UACF,OAAO;CAGT,MAAM,UAA2B;EAC/B,UAAU,YAAY;EACtB,aAAa;EACd;CAED,MAAM,aAAa,QAAQ;CAC3B,OAAO;;AAGT,MAAa,sBAAsB,OACjC,gBAC6B;CAG7B,MAAM,cAA+B;EACnC,GAAG,MAHiB,oBAAoB;EAIxC;EACD;CAED,MAAM,aAAa,YAAY;CAC/B,OAAO"}
|
|
@@ -27,10 +27,10 @@ const readStdin = async () => {
|
|
|
27
27
|
if (process.stdin.isTTY) return null;
|
|
28
28
|
const chunks = [];
|
|
29
29
|
for await (const chunk of process.stdin) chunks.push(chunk);
|
|
30
|
-
const text = Buffer.concat(chunks).toString("
|
|
30
|
+
const text = Buffer.concat(chunks).toString("utf-8").trim();
|
|
31
31
|
return text.length > 0 ? text : null;
|
|
32
32
|
};
|
|
33
33
|
//#endregion
|
|
34
34
|
export { readStdin as n, promptForValue as t };
|
|
35
35
|
|
|
36
|
-
//# sourceMappingURL=prompt-
|
|
36
|
+
//# sourceMappingURL=prompt-GfcWO85b.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prompt-GfcWO85b.mjs","names":[],"sources":["../src/prompt.ts"],"sourcesContent":["import { createInterface } from \"node:readline\";\n\nimport type { CliContext } from \"./types\";\n\n/**\n * Prompt for a value interactively.\n * Returns null if not in a TTY or if the user enters an empty string.\n */\nexport const promptForValue = (\n context: CliContext,\n label: string\n): Promise<string | null> => {\n if (!process.stdin.isTTY || context.json || context.quiet) {\n return Promise.resolve(null);\n }\n\n const rl = createInterface({\n input: process.stdin,\n output: process.stderr,\n });\n\n return new Promise((resolve) => {\n rl.question(`${label}: `, (answer) => {\n rl.close();\n const trimmed = answer.trim();\n resolve(trimmed.length > 0 ? trimmed : null);\n });\n });\n};\n\n/**\n * Read all of stdin as a string. Returns null if stdin is a TTY\n * (nothing piped) or if it's empty.\n */\nexport const readStdin = async (): Promise<string | null> => {\n if (process.stdin.isTTY) {\n return null;\n }\n\n const chunks: Buffer[] = [];\n\n for await (const chunk of process.stdin) {\n chunks.push(chunk as Buffer);\n }\n\n const text = Buffer.concat(chunks).toString(\"utf-8\").trim();\n return text.length > 0 ? text : null;\n};\n"],"mappings":";;;;;;;AAQA,MAAa,kBACX,SACA,UAC2B;CAC3B,IAAI,CAAC,QAAQ,MAAM,SAAS,QAAQ,QAAQ,QAAQ,OAClD,OAAO,QAAQ,QAAQ,KAAK;CAG9B,MAAM,KAAK,gBAAgB;EACzB,OAAO,QAAQ;EACf,QAAQ,QAAQ;EACjB,CAAC;CAEF,OAAO,IAAI,SAAS,YAAY;EAC9B,GAAG,SAAS,GAAG,MAAM,MAAM,WAAW;GACpC,GAAG,OAAO;GACV,MAAM,UAAU,OAAO,MAAM;GAC7B,QAAQ,QAAQ,SAAS,IAAI,UAAU,KAAK;IAC5C;GACF;;;;;;AAOJ,MAAa,YAAY,YAAoC;CAC3D,IAAI,QAAQ,MAAM,OAChB,OAAO;CAGT,MAAM,SAAmB,EAAE;CAE3B,WAAW,MAAM,SAAS,QAAQ,OAChC,OAAO,KAAK,MAAgB;CAG9B,MAAM,OAAO,OAAO,OAAO,OAAO,CAAC,SAAS,QAAQ,CAAC,MAAM;CAC3D,OAAO,KAAK,SAAS,IAAI,OAAO"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "donebear",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.8",
|
|
4
4
|
"description": "Done Bear CLI with OAuth authentication",
|
|
5
5
|
"homepage": "https://github.com/mblode/donebear#readme",
|
|
6
6
|
"bugs": {
|
|
@@ -35,28 +35,24 @@
|
|
|
35
35
|
"build": "tsdown",
|
|
36
36
|
"dev": "tsdown --watch",
|
|
37
37
|
"start": "node dist/cli.mjs",
|
|
38
|
-
"lint": "oxlint .",
|
|
39
|
-
"lint:fix": "oxlint --fix .",
|
|
40
|
-
"format": "oxfmt --write .",
|
|
41
|
-
"format:check": "oxfmt --check .",
|
|
42
38
|
"check-types": "tsc --noEmit",
|
|
43
39
|
"test": "vitest run"
|
|
44
40
|
},
|
|
45
41
|
"dependencies": {
|
|
46
|
-
"better-sqlite3": "^12.
|
|
42
|
+
"better-sqlite3": "^12.9.0",
|
|
47
43
|
"commander": "^14.0.3",
|
|
48
|
-
"dotenv": "^17.
|
|
44
|
+
"dotenv": "^17.4.2",
|
|
49
45
|
"jmespath": "^0.16.0",
|
|
50
46
|
"rrule": "^2.8.1",
|
|
51
|
-
"yaml": "^2.
|
|
47
|
+
"yaml": "^2.9.0"
|
|
52
48
|
},
|
|
53
49
|
"devDependencies": {
|
|
54
50
|
"@types/better-sqlite3": "^7.6.13",
|
|
55
51
|
"@types/jmespath": "^0.15.2",
|
|
56
|
-
"@types/node": "^25.
|
|
57
|
-
"tsdown": "^0.
|
|
58
|
-
"typescript": "^
|
|
59
|
-
"vitest": "^4.1.
|
|
52
|
+
"@types/node": "^25.7.0",
|
|
53
|
+
"tsdown": "^0.22.0",
|
|
54
|
+
"typescript": "^6.0.3",
|
|
55
|
+
"vitest": "^4.1.6"
|
|
60
56
|
},
|
|
61
57
|
"engines": {
|
|
62
58
|
"node": ">=18"
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"context-store-DH561Z1u.mjs","names":[],"sources":["../src/constants.ts","../src/errors.ts","../src/context-store.ts"],"sourcesContent":["import { homedir } from \"node:os\";\nimport { join } from \"node:path\";\n\nexport const CLI_NAME = \"donebear\";\n\nexport const DONEBEAR_TOKEN_ENV = \"DONEBEAR_TOKEN\";\nexport const DONEBEAR_DEBUG_ENV = \"DONEBEAR_DEBUG\";\nconst DONEBEAR_CONFIG_DIR_ENV = \"DONEBEAR_CONFIG_DIR\";\nexport const DONEBEAR_SUPABASE_URL_ENV = \"DONEBEAR_SUPABASE_URL\";\nexport const DONEBEAR_SUPABASE_KEY_ENV = \"DONEBEAR_SUPABASE_PUBLISHABLE_KEY\";\nexport const DONEBEAR_API_URL_ENV = \"DONEBEAR_API_URL\";\n\nexport const DEFAULT_API_URL = \"https://api.donebear.com\";\n\nexport const DEFAULT_SUPABASE_URL = \"https://kdarvputxmlxqemisnbh.supabase.co\";\nexport const DEFAULT_SUPABASE_PUBLISHABLE_KEY =\n \"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6ImtkYXJ2cHV0eG1seHFlbWlzbmJoIiwicm9sZSI6ImFub24iLCJpYXQiOjE3NzIzNTcyNjcsImV4cCI6MjA4NzkzMzI2N30.A8sDPWNe_1EcCy0-GsUw4h1icxSGz_VDc9E9tPTYEU8\";\n\nexport const CLI_OAUTH_CLIENT_ID = \"9cc84e5c-6a0e-4a6d-93a2-334d8d307122\";\nexport const DONEBEAR_OAUTH_CLIENT_ID_ENV = \"DONEBEAR_OAUTH_CLIENT_ID\";\n\nexport const DEFAULT_OAUTH_CALLBACK_PORT = 8787;\nexport const DEFAULT_OAUTH_CALLBACK_PATH = \"/auth/callback\";\nexport const DEFAULT_OAUTH_TIMEOUT_SECONDS = 180;\n\nconst getDefaultConfigBaseDir = (): string => {\n if (process.platform === \"win32\") {\n return process.env.APPDATA ?? join(homedir(), \"AppData\", \"Roaming\");\n }\n\n return process.env.XDG_CONFIG_HOME ?? join(homedir(), \".config\");\n};\n\nconst configBaseDir = getDefaultConfigBaseDir();\n\nexport const CONFIG_DIR =\n process.env[DONEBEAR_CONFIG_DIR_ENV] ?? join(configBaseDir, CLI_NAME);\n\nexport const AUTH_FILE_PATH = join(CONFIG_DIR, \"auth.json\");\nexport const CONTEXT_FILE_PATH = join(CONFIG_DIR, \"context.json\");\n","export const EXIT_CODES = {\n AUTH_REQUIRED: 4,\n CANCELLED: 2,\n ERROR: 1,\n NETWORK: 5,\n SUCCESS: 0,\n VALIDATION: 3,\n} as const;\n\nexport type ExitCode = (typeof EXIT_CODES)[keyof typeof EXIT_CODES];\n\nexport type ErrorCode =\n | \"unknown_error\"\n | \"cancelled\"\n | \"validation_error\"\n | \"auth_error\"\n | \"network_error\";\n\nconst EXIT_CODE_TO_ERROR_CODE: Record<ExitCode, ErrorCode> = {\n [EXIT_CODES.SUCCESS]: \"unknown_error\",\n [EXIT_CODES.ERROR]: \"unknown_error\",\n [EXIT_CODES.CANCELLED]: \"cancelled\",\n [EXIT_CODES.VALIDATION]: \"validation_error\",\n [EXIT_CODES.AUTH_REQUIRED]: \"auth_error\",\n [EXIT_CODES.NETWORK]: \"network_error\",\n};\n\nexport const exitCodeToErrorCode = (exitCode: ExitCode): ErrorCode =>\n EXIT_CODE_TO_ERROR_CODE[exitCode] ?? \"unknown_error\";\n\nexport class CliError extends Error {\n readonly exitCode: ExitCode;\n readonly code: ErrorCode;\n readonly hint: string | null;\n\n constructor(\n message: string,\n exitCode: ExitCode = EXIT_CODES.ERROR,\n hint?: string\n ) {\n super(message);\n this.name = \"CliError\";\n this.exitCode = exitCode;\n this.code = exitCodeToErrorCode(exitCode);\n this.hint = hint ?? null;\n }\n}\n\nexport const toCliError = (error: unknown): CliError => {\n if (error instanceof CliError) {\n return error;\n }\n\n if (error instanceof Error) {\n // Network errors (fetch failures)\n if (error instanceof TypeError && error.message.includes(\"fetch\")) {\n return new CliError(\n \"Cannot connect to Done Bear API.\",\n EXIT_CODES.NETWORK,\n \"Check your internet connection and API URL configuration.\"\n );\n }\n\n // Timeout errors\n if (error.name === \"TimeoutError\" || error.name === \"AbortError\") {\n return new CliError(\n \"Request timed out.\",\n EXIT_CODES.NETWORK,\n \"The API may be unavailable. Try again later.\"\n );\n }\n\n return new CliError(error.message, EXIT_CODES.ERROR);\n }\n\n return new CliError(\"Unknown error\", EXIT_CODES.ERROR);\n};\n","import { randomUUID } from \"node:crypto\";\nimport { mkdir, readFile, writeFile } from \"node:fs/promises\";\n\nimport { CONFIG_DIR, CONTEXT_FILE_PATH } from \"./constants\";\nimport { CliError, EXIT_CODES } from \"./errors\";\nimport type { CliContextFileData, LocalCliContext } from \"./types\";\n\nconst isRecord = (value: unknown): value is Record<string, unknown> =>\n typeof value === \"object\" && value !== null;\n\nconst parseLocalContext = (value: unknown): LocalCliContext | null => {\n if (!isRecord(value)) {\n return null;\n }\n\n if (value.workspaceId !== null && typeof value.workspaceId !== \"string\") {\n return null;\n }\n\n if (typeof value.clientId !== \"string\" || value.clientId.length === 0) {\n return null;\n }\n\n return {\n clientId: value.clientId,\n workspaceId: value.workspaceId,\n };\n};\n\nconst parseContextFile = (payload: string): CliContextFileData => {\n const parsed = JSON.parse(payload) as unknown;\n\n if (!isRecord(parsed) || parsed.version !== 1) {\n throw new CliError(\n `Invalid CLI context format in ${CONTEXT_FILE_PATH}`,\n EXIT_CODES.ERROR\n );\n }\n\n const context = parseLocalContext(parsed.context);\n\n if (!context) {\n throw new CliError(\n `Invalid CLI context in ${CONTEXT_FILE_PATH}`,\n EXIT_CODES.ERROR\n );\n }\n\n return {\n context,\n version: 1,\n };\n};\n\nconst writeContext = async (context: LocalCliContext): Promise<void> => {\n const payload: CliContextFileData = {\n context,\n version: 1,\n };\n\n await mkdir(CONFIG_DIR, {\n mode: 0o700,\n recursive: true,\n });\n\n await writeFile(CONTEXT_FILE_PATH, `${JSON.stringify(payload, null, 2)}\\n`, {\n encoding: \"utf8\",\n mode: 0o600,\n });\n};\n\nconst readLocalContext = async (): Promise<LocalCliContext | null> => {\n try {\n const raw = await readFile(CONTEXT_FILE_PATH, \"utf8\");\n return parseContextFile(raw).context;\n } catch (error) {\n if (isRecord(error) && error.code === \"ENOENT\") {\n return null;\n }\n\n if (error instanceof CliError) {\n throw error;\n }\n\n throw new CliError(\n `Failed to read context from ${CONTEXT_FILE_PATH}`,\n EXIT_CODES.ERROR\n );\n }\n};\n\nexport const ensureLocalContext = async (): Promise<LocalCliContext> => {\n const existing = await readLocalContext();\n\n if (existing) {\n return existing;\n }\n\n const created: LocalCliContext = {\n clientId: randomUUID(),\n workspaceId: null,\n };\n\n await writeContext(created);\n return created;\n};\n\nexport const setCurrentWorkspace = async (\n workspaceId: string | null\n): Promise<LocalCliContext> => {\n const context = await ensureLocalContext();\n\n const nextContext: LocalCliContext = {\n ...context,\n workspaceId,\n };\n\n await writeContext(nextContext);\n return nextContext;\n};\n"],"mappings":";;;;;;AAGA,MAAa,WAAW;AAExB,MAAa,qBAAqB;AAClC,MAAa,qBAAqB;AAClC,MAAM,0BAA0B;AAChC,MAAa,4BAA4B;AACzC,MAAa,4BAA4B;AACzC,MAAa,uBAAuB;AAEpC,MAAa,kBAAkB;AAE/B,MAAa,uBAAuB;AACpC,MAAa,mCACX;AAEF,MAAa,sBAAsB;AACnC,MAAa,+BAA+B;AAE5C,MAAa,8BAA8B;AAC3C,MAAa,8BAA8B;AAG3C,MAAM,gCAAwC;AAC5C,KAAI,QAAQ,aAAa,QACvB,QAAO,QAAQ,IAAI,WAAW,KAAK,SAAS,EAAE,WAAW,UAAU;AAGrE,QAAO,QAAQ,IAAI,mBAAmB,KAAK,SAAS,EAAE,UAAU;;AAGlE,MAAM,gBAAgB,yBAAyB;AAE/C,MAAa,aACX,QAAQ,IAAI,4BAA4B,KAAK,eAAA,WAAwB;AAEvE,MAAa,iBAAiB,KAAK,YAAY,YAAY;AAC3D,MAAa,oBAAoB,KAAK,YAAY,eAAe;;;ACvCjE,MAAa,aAAa;CACxB,eAAe;CACf,WAAW;CACX,OAAO;CACP,SAAS;CACT,SAAS;CACT,YAAY;CACb;AAWD,MAAM,0BAAuD;EAC1D,WAAW,UAAU;EACrB,WAAW,QAAQ;EACnB,WAAW,YAAY;EACvB,WAAW,aAAa;EACxB,WAAW,gBAAgB;EAC3B,WAAW,UAAU;CACvB;AAED,MAAa,uBAAuB,aAClC,wBAAwB,aAAa;AAEvC,IAAa,WAAb,cAA8B,MAAM;CAClC;CACA;CACA;CAEA,YACE,SACA,WAAqB,WAAW,OAChC,MACA;AACA,QAAM,QAAQ;AACd,OAAK,OAAO;AACZ,OAAK,WAAW;AAChB,OAAK,OAAO,oBAAoB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AC1E,UAAU;EACV,MAAM;EACP,CAAC;;AAGJ,MAAM,mBAAmB,YAA6C;AACpE,KAAI;AAEF,SAAO,iBADK,MAAM,SAAS,mBAAmB,OAAO,CACzB,CAAC;UACtB,OAAO;AACd,MAAI,SAAS,MAAM,IAAI,MAAM,SAAS,SACpC,QAAO;AAGT,MAAI,iBAAiB,SACnB,OAAM;AAGR,QAAM,IAAI,SACR,+BAA+B,qBAC/B,WAAW,MACZ;;;AAIL,MAAa,qBAAqB,YAAsC;CACtE,MAAM,WAAW,MAAM,kBAAkB;AAEzC,KAAI,SACF,QAAO;CAGT,MAAM,UAA2B;EAC/B,UAAU,YAAY;EACtB,aAAa;EACd;AAED,OAAM,aAAa,QAAQ;AAC3B,QAAO;;AAGT,MAAa,sBAAsB,OACjC,gBAC6B;CAG7B,MAAM,cAA+B;EACnC,GAHc,MAAM,oBAAoB;EAIxC;EACD;AAED,OAAM,aAAa,YAAY;AAC/B,QAAO"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"prompt-BrfcK2Ry.mjs","names":[],"sources":["../src/prompt.ts"],"sourcesContent":["import { createInterface } from \"node:readline\";\n\nimport type { CliContext } from \"./types\";\n\n/**\n * Prompt for a value interactively.\n * Returns null if not in a TTY or if the user enters an empty string.\n */\nexport const promptForValue = (\n context: CliContext,\n label: string\n): Promise<string | null> => {\n if (!process.stdin.isTTY || context.json || context.quiet) {\n return Promise.resolve(null);\n }\n\n const rl = createInterface({\n input: process.stdin,\n output: process.stderr,\n });\n\n // oxlint-disable-next-line avoid-new -- wrapping callback API in promise\n return new Promise((resolve) => {\n rl.question(`${label}: `, (answer) => {\n rl.close();\n const trimmed = answer.trim();\n resolve(trimmed.length > 0 ? trimmed : null);\n });\n });\n};\n\n/**\n * Read all of stdin as a string. Returns null if stdin is a TTY\n * (nothing piped) or if it's empty.\n */\nexport const readStdin = async (): Promise<string | null> => {\n if (process.stdin.isTTY) {\n return null;\n }\n\n const chunks: Buffer[] = [];\n\n for await (const chunk of process.stdin) {\n chunks.push(chunk as Buffer);\n }\n\n const text = Buffer.concat(chunks).toString(\"utf8\").trim();\n return text.length > 0 ? text : null;\n};\n"],"mappings":";;;;;;;AAQA,MAAa,kBACX,SACA,UAC2B;AAC3B,KAAI,CAAC,QAAQ,MAAM,SAAS,QAAQ,QAAQ,QAAQ,MAClD,QAAO,QAAQ,QAAQ,KAAK;CAG9B,MAAM,KAAK,gBAAgB;EACzB,OAAO,QAAQ;EACf,QAAQ,QAAQ;EACjB,CAAC;AAGF,QAAO,IAAI,SAAS,YAAY;AAC9B,KAAG,SAAS,GAAG,MAAM,MAAM,WAAW;AACpC,MAAG,OAAO;GACV,MAAM,UAAU,OAAO,MAAM;AAC7B,WAAQ,QAAQ,SAAS,IAAI,UAAU,KAAK;IAC5C;GACF;;;;;;AAOJ,MAAa,YAAY,YAAoC;AAC3D,KAAI,QAAQ,MAAM,MAChB,QAAO;CAGT,MAAM,SAAmB,EAAE;AAE3B,YAAW,MAAM,SAAS,QAAQ,MAChC,QAAO,KAAK,MAAgB;CAG9B,MAAM,OAAO,OAAO,OAAO,OAAO,CAAC,SAAS,OAAO,CAAC,MAAM;AAC1D,QAAO,KAAK,SAAS,IAAI,OAAO"}
|
package/dist/prompt-FRvfbinv.mjs
DELETED