@dypt/cli 0.1.13 → 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 +36 -13
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
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",
|
|
@@ -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
|
|