@dosu/cli 0.18.0 → 0.18.1
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/bin/dosu.js +26 -3
- package/package.json +1 -1
package/bin/dosu.js
CHANGED
|
@@ -2083,7 +2083,7 @@ var init_esm = __esm(() => {
|
|
|
2083
2083
|
});
|
|
2084
2084
|
|
|
2085
2085
|
// src/config/config.ts
|
|
2086
|
-
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
2086
|
+
import { existsSync, mkdirSync, readFileSync, renameSync, writeFileSync } from "node:fs";
|
|
2087
2087
|
import { join } from "node:path";
|
|
2088
2088
|
function getConfigDir() {
|
|
2089
2089
|
const dirName = process.env.DOSU_DEV === "true" ? "dosu-cli-dev" : "dosu-cli";
|
|
@@ -2118,7 +2118,9 @@ function saveConfig(cfg) {
|
|
|
2118
2118
|
if (!existsSync(dir)) {
|
|
2119
2119
|
mkdirSync(dir, { recursive: true, mode: 448 });
|
|
2120
2120
|
}
|
|
2121
|
-
|
|
2121
|
+
const tmp = `${path}.${process.pid}.tmp`;
|
|
2122
|
+
writeFileSync(tmp, JSON.stringify(cfg, null, 2), { mode: 384 });
|
|
2123
|
+
renameSync(tmp, path);
|
|
2122
2124
|
}
|
|
2123
2125
|
function isAuthenticated(cfg) {
|
|
2124
2126
|
return cfg.access_token !== "";
|
|
@@ -2247,9 +2249,30 @@ class Client {
|
|
|
2247
2249
|
}
|
|
2248
2250
|
}
|
|
2249
2251
|
async refreshToken() {
|
|
2252
|
+
this.adoptNewerDiskTokens();
|
|
2250
2253
|
if (!this.config.refresh_token) {
|
|
2251
2254
|
throw new Error("no refresh token available");
|
|
2252
2255
|
}
|
|
2256
|
+
try {
|
|
2257
|
+
await this.refreshTokenOnce();
|
|
2258
|
+
} catch (err) {
|
|
2259
|
+
if (!this.adoptNewerDiskTokens()) {
|
|
2260
|
+
throw err;
|
|
2261
|
+
}
|
|
2262
|
+
await this.refreshTokenOnce();
|
|
2263
|
+
}
|
|
2264
|
+
}
|
|
2265
|
+
adoptNewerDiskTokens() {
|
|
2266
|
+
const disk = loadConfig();
|
|
2267
|
+
if (!disk.refresh_token || disk.refresh_token === this.config.refresh_token) {
|
|
2268
|
+
return false;
|
|
2269
|
+
}
|
|
2270
|
+
this.config.access_token = disk.access_token;
|
|
2271
|
+
this.config.refresh_token = disk.refresh_token;
|
|
2272
|
+
this.config.expires_at = disk.expires_at;
|
|
2273
|
+
return true;
|
|
2274
|
+
}
|
|
2275
|
+
async refreshTokenOnce() {
|
|
2253
2276
|
const supabaseURL = getSupabaseURL();
|
|
2254
2277
|
const endpoint = `${supabaseURL}/auth/v1/token?grant_type=refresh_token`;
|
|
2255
2278
|
const resp = await fetch(endpoint, {
|
|
@@ -4525,7 +4548,7 @@ var init_dist4 = __esm(() => {
|
|
|
4525
4548
|
function getVersionString() {
|
|
4526
4549
|
return `v${VERSION}`;
|
|
4527
4550
|
}
|
|
4528
|
-
var VERSION = "0.18.
|
|
4551
|
+
var VERSION = "0.18.1";
|
|
4529
4552
|
|
|
4530
4553
|
// src/debug/logger.ts
|
|
4531
4554
|
import {
|