@hive3/cli 0.1.1-beta.0 → 0.2.0
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/package.json +1 -1
- package/src/api-client.js +3 -0
- package/src/commands.js +19 -2
- package/src/config.js +3 -2
package/package.json
CHANGED
package/src/api-client.js
CHANGED
|
@@ -196,6 +196,9 @@ export function createApiClient(options) {
|
|
|
196
196
|
requestAccountExport() {
|
|
197
197
|
return request("POST", "/account/export");
|
|
198
198
|
},
|
|
199
|
+
revokeCurrentKey() {
|
|
200
|
+
return request("DELETE", "/account/keys/current");
|
|
201
|
+
},
|
|
199
202
|
saveBuilder(kind, config) {
|
|
200
203
|
return request("PATCH", `/profile/${kind}`, { body: { config } });
|
|
201
204
|
},
|
package/src/commands.js
CHANGED
|
@@ -424,8 +424,9 @@ async function runUpload(args, deps) {
|
|
|
424
424
|
const fileName = path.basename(filePath);
|
|
425
425
|
const client = await authenticatedClient(deps);
|
|
426
426
|
const issued = await client.createUploadUrl({ byteSize: fileStat.size, contentType, fileName, purpose });
|
|
427
|
+
const { uploadUrl, ...issuedSafe } = issued.data;
|
|
427
428
|
const bytes = await readFile(filePath);
|
|
428
|
-
const response = await deps.fetch(
|
|
429
|
+
const response = await deps.fetch(uploadUrl, {
|
|
429
430
|
body: new Blob([bytes], { type: contentType }),
|
|
430
431
|
headers: { "Content-Type": contentType },
|
|
431
432
|
method: "POST",
|
|
@@ -435,7 +436,7 @@ async function runUpload(args, deps) {
|
|
|
435
436
|
if (!response.ok) {
|
|
436
437
|
throw new HiveApiError(`Upload failed with status ${response.status}`, { code: "upload_failed", status: response.status });
|
|
437
438
|
}
|
|
438
|
-
writeJson(deps.stdout, { data: { ...
|
|
439
|
+
writeJson(deps.stdout, { data: { ...issuedSafe, ...parsed } });
|
|
439
440
|
}
|
|
440
441
|
|
|
441
442
|
async function runAccount(args, deps) {
|
|
@@ -551,6 +552,22 @@ export async function main(argv, overrides = {}) {
|
|
|
551
552
|
return 0;
|
|
552
553
|
}
|
|
553
554
|
if (command === "logout") {
|
|
555
|
+
try {
|
|
556
|
+
const config = await loadConfig({ env: deps.env, homeDir: deps.homeDir, platform: deps.platform });
|
|
557
|
+
if (config?.apiKey) {
|
|
558
|
+
await createApiClient({
|
|
559
|
+
apiBaseUrl: config.apiBaseUrl,
|
|
560
|
+
apiKey: config.apiKey,
|
|
561
|
+
fetch: deps.fetch,
|
|
562
|
+
}).revokeCurrentKey();
|
|
563
|
+
writeLine(deps.stdout, "Revoked the server credential.");
|
|
564
|
+
}
|
|
565
|
+
} catch {
|
|
566
|
+
writeLine(
|
|
567
|
+
deps.stderr,
|
|
568
|
+
"Warning: could not revoke the server credential. Revoke it at Settings → Developer credentials.",
|
|
569
|
+
);
|
|
570
|
+
}
|
|
554
571
|
const file = await clearConfig({ env: deps.env, homeDir: deps.homeDir, platform: deps.platform });
|
|
555
572
|
writeLine(deps.stdout, `Removed Hive CLI credential at ${file}.`);
|
|
556
573
|
return 0;
|
package/src/config.js
CHANGED
|
@@ -78,8 +78,9 @@ export async function saveCredential(credential, options, overrides = {}) {
|
|
|
78
78
|
keyPrefix: credential.keyPrefix,
|
|
79
79
|
scopes: credential.scopes,
|
|
80
80
|
};
|
|
81
|
-
|
|
82
|
-
await fs.
|
|
81
|
+
const tmp = `${file}.${process.pid}.tmp`;
|
|
82
|
+
await fs.writeFile(tmp, `${JSON.stringify(body, null, 2)}\n`, { mode: 0o600 });
|
|
83
|
+
await fs.rename(tmp, file);
|
|
83
84
|
return file;
|
|
84
85
|
}
|
|
85
86
|
|