@dypt/cli 0.1.12 → 0.1.14
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/index.js +45 -16
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
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.
|
|
12
|
+
version: "0.1.14",
|
|
13
13
|
description: "Command-line interface for dypt task management",
|
|
14
14
|
license: "SEE LICENSE IN LICENSE",
|
|
15
15
|
homepage: "https://dypt.app",
|
|
@@ -42,9 +42,9 @@ var package_default = {
|
|
|
42
42
|
typecheck: "tsc --noEmit"
|
|
43
43
|
},
|
|
44
44
|
dependencies: {
|
|
45
|
-
"@trpc/client": "^11.
|
|
45
|
+
"@trpc/client": "^11.18.0",
|
|
46
46
|
commander: "^15.0.0",
|
|
47
|
-
"string-width": "^8.2.
|
|
47
|
+
"string-width": "^8.2.2",
|
|
48
48
|
superjson: "^2.2.6"
|
|
49
49
|
},
|
|
50
50
|
devDependencies: {
|
|
@@ -64,7 +64,7 @@ function getConfigDir() {
|
|
|
64
64
|
}
|
|
65
65
|
function getScopedTokenFilePath(baseUrl) {
|
|
66
66
|
const url = new URL(baseUrl);
|
|
67
|
-
const scope = `${url.hostname}${url.port ? `-${url.port}` : ""}`.replace(/[^a-zA-Z0-9.-]/g, "-").toLowerCase();
|
|
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
70
|
function getBaseUrl() {
|
|
@@ -86,9 +86,21 @@ var MACOS_ACCOUNT_NAME_PREFIX = "dypt-cli";
|
|
|
86
86
|
function isMissingFileError(error) {
|
|
87
87
|
return typeof error === "object" && error !== null && "code" in error && error.code === "ENOENT";
|
|
88
88
|
}
|
|
89
|
+
function isMissingKeychainItemError(error) {
|
|
90
|
+
return typeof error === "object" && error !== null && "code" in error && error.code === 44;
|
|
91
|
+
}
|
|
89
92
|
async function ensureParentDirectory(filePath) {
|
|
90
93
|
await mkdir(path2.dirname(filePath), { recursive: true });
|
|
91
94
|
}
|
|
95
|
+
async function removeFallbackTokenFile(filePath) {
|
|
96
|
+
try {
|
|
97
|
+
await rm(filePath);
|
|
98
|
+
} catch (error) {
|
|
99
|
+
if (!isMissingFileError(error)) {
|
|
100
|
+
throw error;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
}
|
|
92
104
|
function getCredentialScope(baseUrl = getBaseUrl()) {
|
|
93
105
|
const url = new URL(baseUrl);
|
|
94
106
|
return `${url.protocol}//${url.host}`;
|
|
@@ -146,7 +158,7 @@ async function saveMacOsKeychainToken(accessToken, expiresAt, baseUrl) {
|
|
|
146
158
|
}
|
|
147
159
|
async function clearMacOsKeychainToken(baseUrl) {
|
|
148
160
|
if (process.platform !== "darwin") {
|
|
149
|
-
return
|
|
161
|
+
return;
|
|
150
162
|
}
|
|
151
163
|
try {
|
|
152
164
|
await execFileAsync("security", [
|
|
@@ -156,9 +168,10 @@ async function clearMacOsKeychainToken(baseUrl) {
|
|
|
156
168
|
"-s",
|
|
157
169
|
getMacOsServiceName(baseUrl)
|
|
158
170
|
]);
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
171
|
+
} catch (error) {
|
|
172
|
+
if (!isMissingKeychainItemError(error)) {
|
|
173
|
+
throw error;
|
|
174
|
+
}
|
|
162
175
|
}
|
|
163
176
|
}
|
|
164
177
|
async function readCliToken(baseUrl = getBaseUrl(), filePath = getScopedTokenFilePath(baseUrl)) {
|
|
@@ -190,6 +203,7 @@ async function saveCliToken(accessToken, expiresAt, baseUrl = getBaseUrl(), file
|
|
|
190
203
|
baseUrl
|
|
191
204
|
);
|
|
192
205
|
if (wroteToKeychain) {
|
|
206
|
+
await removeFallbackTokenFile(filePath);
|
|
193
207
|
return;
|
|
194
208
|
}
|
|
195
209
|
await ensureParentDirectory(filePath);
|
|
@@ -203,16 +217,25 @@ async function saveCliToken(accessToken, expiresAt, baseUrl = getBaseUrl(), file
|
|
|
203
217
|
);
|
|
204
218
|
}
|
|
205
219
|
async function clearCliToken(baseUrl = getBaseUrl(), filePath = getScopedTokenFilePath(baseUrl)) {
|
|
206
|
-
const
|
|
207
|
-
|
|
208
|
-
|
|
220
|
+
const cleanupErrors = [];
|
|
221
|
+
try {
|
|
222
|
+
await clearMacOsKeychainToken(baseUrl);
|
|
223
|
+
} catch (error) {
|
|
224
|
+
cleanupErrors.push(error);
|
|
209
225
|
}
|
|
210
226
|
try {
|
|
211
|
-
await
|
|
227
|
+
await removeFallbackTokenFile(filePath);
|
|
212
228
|
} catch (error) {
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
229
|
+
cleanupErrors.push(error);
|
|
230
|
+
}
|
|
231
|
+
if (cleanupErrors.length === 1) {
|
|
232
|
+
throw cleanupErrors[0];
|
|
233
|
+
}
|
|
234
|
+
if (cleanupErrors.length > 1) {
|
|
235
|
+
throw new AggregateError(
|
|
236
|
+
cleanupErrors,
|
|
237
|
+
"Could not clear all stored CLI credentials"
|
|
238
|
+
);
|
|
216
239
|
}
|
|
217
240
|
}
|
|
218
241
|
|
|
@@ -293,6 +316,7 @@ async function createCliApi(options = {}) {
|
|
|
293
316
|
const cliClient = client;
|
|
294
317
|
return {
|
|
295
318
|
getAuthStatus: () => cliClient.cli.v1.auth.status.query(),
|
|
319
|
+
revokeCurrentToken: () => cliClient.cli.v1.auth.logout.mutate(),
|
|
296
320
|
createTask: (input) => cliClient.cli.v1.tasks.create.mutate(input),
|
|
297
321
|
updateTask: (input) => cliClient.cli.v1.tasks.update.mutate(input),
|
|
298
322
|
reorderTasks: (input) => cliClient.cli.v1.tasks.reorder.mutate(input),
|
|
@@ -376,6 +400,10 @@ async function runLogin(input, deps = createDefaultLoginDeps()) {
|
|
|
376
400
|
// src/commands/auth/logout.ts
|
|
377
401
|
function createDefaultLogoutDeps() {
|
|
378
402
|
return {
|
|
403
|
+
revokeToken: async () => {
|
|
404
|
+
const api = await createCliApi({ baseUrl: getBaseUrl() });
|
|
405
|
+
await api.revokeCurrentToken();
|
|
406
|
+
},
|
|
379
407
|
clearToken: () => clearCliToken(getBaseUrl()),
|
|
380
408
|
writeLine: (message) => {
|
|
381
409
|
process.stdout.write(`${message}
|
|
@@ -384,6 +412,7 @@ function createDefaultLogoutDeps() {
|
|
|
384
412
|
};
|
|
385
413
|
}
|
|
386
414
|
async function runLogout(deps = createDefaultLogoutDeps()) {
|
|
415
|
+
await deps.revokeToken();
|
|
387
416
|
await deps.clearToken();
|
|
388
417
|
deps.writeLine?.("Signed out of dypt CLI.");
|
|
389
418
|
}
|
|
@@ -2673,7 +2702,7 @@ function buildCli() {
|
|
|
2673
2702
|
}
|
|
2674
2703
|
);
|
|
2675
2704
|
});
|
|
2676
|
-
auth.command("logout").description("
|
|
2705
|
+
auth.command("logout").description("Revoke the current CLI session").action(async () => {
|
|
2677
2706
|
await runLogout(createDefaultLogoutDeps());
|
|
2678
2707
|
});
|
|
2679
2708
|
const agent = addGroupHelpAction(
|