@dypt/cli 0.1.19 → 0.1.20

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/README.md CHANGED
@@ -25,6 +25,21 @@ dypt auth login
25
25
  dypt auth status
26
26
  ```
27
27
 
28
+ By default on macOS, dypt stores CLI credentials in Keychain and falls back to
29
+ the URL-scoped file under `~/.config/dypt/tokens` only when Keychain is
30
+ unavailable. To deliberately use one file and skip Keychain entirely, set an
31
+ absolute path:
32
+
33
+ ```bash
34
+ DYPT_TOKEN_FILE=/absolute/path/to/dypt-token.json dypt auth login
35
+ ```
36
+
37
+ Keep `DYPT_TOKEN_FILE` set to the same path for subsequent commands and
38
+ `dypt auth logout`. When explicitly configured, a missing or invalid file does
39
+ not fall back to Keychain or another identity. The token file is created with
40
+ owner-only permissions; its containing directory and any sandbox access to the
41
+ file remain the user's responsibility.
42
+
28
43
  ### List tasks
29
44
 
30
45
  See tasks from your account:
package/dist/index.js CHANGED
@@ -9,7 +9,7 @@ import { Argument, Command, Option } from "commander";
9
9
  // package.json
10
10
  var package_default = {
11
11
  name: "@dypt/cli",
12
- version: "0.1.19",
12
+ version: "0.1.20",
13
13
  description: "Command-line interface for dypt task management",
14
14
  license: "SEE LICENSE IN LICENSE",
15
15
  homepage: "https://dypt.app",
@@ -67,6 +67,17 @@ function getScopedTokenFilePath(baseUrl) {
67
67
  const scope = `${url.protocol.slice(0, -1)}-${url.hostname}${url.port ? `-${url.port}` : ""}`.replace(/[^a-zA-Z0-9.-]/g, "-").toLowerCase();
68
68
  return path.join(getConfigDir(), "tokens", `${scope}.json`);
69
69
  }
70
+ function getConfiguredTokenFilePath() {
71
+ const configuredPath = process.env.DYPT_TOKEN_FILE;
72
+ if (configuredPath === void 0) {
73
+ return null;
74
+ }
75
+ const normalizedPath = configuredPath.trim();
76
+ if (!normalizedPath || !path.isAbsolute(normalizedPath)) {
77
+ throw new Error("DYPT_TOKEN_FILE must be a non-empty absolute path");
78
+ }
79
+ return path.normalize(normalizedPath);
80
+ }
70
81
  function getBaseUrl() {
71
82
  return (process.env.DYPT_BASE_URL ?? process.env.NEXT_PUBLIC_URL ?? "https://dypt.app").replace(/\/+$/, "");
72
83
  }
@@ -101,6 +112,19 @@ async function removeFallbackTokenFile(filePath) {
101
112
  }
102
113
  }
103
114
  }
115
+ function resolveTokenStorage(baseUrl, filePath) {
116
+ if (filePath !== void 0) {
117
+ return { filePath, useKeychain: true };
118
+ }
119
+ const configuredFilePath = getConfiguredTokenFilePath();
120
+ if (configuredFilePath) {
121
+ return { filePath: configuredFilePath, useKeychain: false };
122
+ }
123
+ return {
124
+ filePath: getScopedTokenFilePath(baseUrl),
125
+ useKeychain: true
126
+ };
127
+ }
104
128
  function getCredentialScope(baseUrl = getBaseUrl()) {
105
129
  const url = new URL(baseUrl);
106
130
  return `${url.protocol}//${url.host}`;
@@ -174,13 +198,16 @@ async function clearMacOsKeychainToken(baseUrl) {
174
198
  }
175
199
  }
176
200
  }
177
- async function readCliToken(baseUrl = getBaseUrl(), filePath = getScopedTokenFilePath(baseUrl)) {
178
- const keychainRecord = await readMacOsKeychainToken(baseUrl);
179
- if (keychainRecord) {
180
- return keychainRecord;
201
+ async function readCliToken(baseUrl = getBaseUrl(), filePath) {
202
+ const storage = resolveTokenStorage(baseUrl, filePath);
203
+ if (storage.useKeychain) {
204
+ const keychainRecord = await readMacOsKeychainToken(baseUrl);
205
+ if (keychainRecord) {
206
+ return keychainRecord;
207
+ }
181
208
  }
182
209
  try {
183
- const raw = await readFile(filePath, "utf8");
210
+ const raw = await readFile(storage.filePath, "utf8");
184
211
  const parsed = JSON.parse(raw);
185
212
  if (!parsed.accessToken || !parsed.expiresAt) {
186
213
  return null;
@@ -196,19 +223,22 @@ async function readCliToken(baseUrl = getBaseUrl(), filePath = getScopedTokenFil
196
223
  throw error;
197
224
  }
198
225
  }
199
- async function saveCliToken(accessToken, expiresAt, baseUrl = getBaseUrl(), filePath = getScopedTokenFilePath(baseUrl)) {
200
- const wroteToKeychain = await saveMacOsKeychainToken(
201
- accessToken,
202
- expiresAt,
203
- baseUrl
204
- );
205
- if (wroteToKeychain) {
206
- await removeFallbackTokenFile(filePath);
207
- return;
226
+ async function saveCliToken(accessToken, expiresAt, baseUrl = getBaseUrl(), filePath) {
227
+ const storage = resolveTokenStorage(baseUrl, filePath);
228
+ if (storage.useKeychain) {
229
+ const wroteToKeychain = await saveMacOsKeychainToken(
230
+ accessToken,
231
+ expiresAt,
232
+ baseUrl
233
+ );
234
+ if (wroteToKeychain) {
235
+ await removeFallbackTokenFile(storage.filePath);
236
+ return;
237
+ }
208
238
  }
209
- await ensureParentDirectory(filePath);
239
+ await ensureParentDirectory(storage.filePath);
210
240
  await writeFile(
211
- filePath,
241
+ storage.filePath,
212
242
  `${JSON.stringify({ accessToken, expiresAt }, null, 2)}
213
243
  `,
214
244
  {
@@ -216,15 +246,18 @@ async function saveCliToken(accessToken, expiresAt, baseUrl = getBaseUrl(), file
216
246
  }
217
247
  );
218
248
  }
219
- async function clearCliToken(baseUrl = getBaseUrl(), filePath = getScopedTokenFilePath(baseUrl)) {
249
+ async function clearCliToken(baseUrl = getBaseUrl(), filePath) {
250
+ const storage = resolveTokenStorage(baseUrl, filePath);
220
251
  const cleanupErrors = [];
221
- try {
222
- await clearMacOsKeychainToken(baseUrl);
223
- } catch (error) {
224
- cleanupErrors.push(error);
252
+ if (storage.useKeychain) {
253
+ try {
254
+ await clearMacOsKeychainToken(baseUrl);
255
+ } catch (error) {
256
+ cleanupErrors.push(error);
257
+ }
225
258
  }
226
259
  try {
227
- await removeFallbackTokenFile(filePath);
260
+ await removeFallbackTokenFile(storage.filePath);
228
261
  } catch (error) {
229
262
  cleanupErrors.push(error);
230
263
  }
@@ -1246,7 +1279,10 @@ async function runTaskArchive(input, deps) {
1246
1279
 
1247
1280
  // src/commands/task/delete.ts
1248
1281
  async function runTaskDelete(input, deps) {
1249
- if (deps.isTty && !input.yes) {
1282
+ if (!input.yes && !deps.isTty) {
1283
+ throw new Error("Non-interactive task deletion requires --yes.");
1284
+ }
1285
+ if (!input.yes) {
1250
1286
  const accepted = await deps.confirm(`Delete task ${input.ref}?`);
1251
1287
  if (!accepted) {
1252
1288
  return;
@@ -1257,10 +1293,11 @@ async function runTaskDelete(input, deps) {
1257
1293
 
1258
1294
  // src/commands/task/deleteMany.ts
1259
1295
  async function runTaskDeleteMany(input, deps) {
1260
- if (deps.isTty && !input.yes) {
1261
- const accepted = await deps.confirm(
1262
- `Delete ${input.refs.length} tasks?`
1263
- );
1296
+ if (!input.yes && !deps.isTty) {
1297
+ throw new Error("Non-interactive bulk deletion requires --yes.");
1298
+ }
1299
+ if (!input.yes) {
1300
+ const accepted = await deps.confirm(`Delete ${input.refs.length} tasks?`);
1264
1301
  if (!accepted) {
1265
1302
  return;
1266
1303
  }
@@ -1559,7 +1596,10 @@ async function runTaskCleanupApply(input, deps) {
1559
1596
  plan: input.plan,
1560
1597
  planFile: input.planFile
1561
1598
  });
1562
- if (!input.yes && deps.isTty) {
1599
+ if (!input.yes && !deps.isTty) {
1600
+ throw new Error("Non-interactive cleanup apply requires --yes.");
1601
+ }
1602
+ if (!input.yes) {
1563
1603
  const confirmed = await deps.confirm(
1564
1604
  `Apply cleanup plan with ${summarizeCleanupPlan(plan)}?`
1565
1605
  );