@astrojs/db 0.8.2 → 0.8.3
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.
|
@@ -225,7 +225,11 @@ async function promptNewProjectRegion() {
|
|
|
225
225
|
message: `Where should your new database live?`,
|
|
226
226
|
choices: [
|
|
227
227
|
{ title: "North America (East)", value: "NorthAmericaEast" },
|
|
228
|
-
{ title: "North America (West)", value: "NorthAmericaWest" }
|
|
228
|
+
{ title: "North America (West)", value: "NorthAmericaWest" },
|
|
229
|
+
{ title: "Europe (Amsterdam)", value: "EuropeCentral" },
|
|
230
|
+
{ title: "South America (Brazil)", value: "SouthAmericaEast" },
|
|
231
|
+
{ title: "Asia (India)", value: "AsiaSouth" },
|
|
232
|
+
{ title: "Asia (Japan)", value: "AsiaNorthEast" }
|
|
229
233
|
],
|
|
230
234
|
initial: 0
|
|
231
235
|
});
|
package/dist/core/tokens.js
CHANGED
|
@@ -2,8 +2,10 @@ import { readFile } from "node:fs/promises";
|
|
|
2
2
|
import { homedir } from "node:os";
|
|
3
3
|
import { join } from "node:path";
|
|
4
4
|
import { pathToFileURL } from "node:url";
|
|
5
|
+
import { green } from "kleur/colors";
|
|
6
|
+
import ora from "ora";
|
|
5
7
|
import { MISSING_PROJECT_ID_ERROR, MISSING_SESSION_ID_ERROR } from "./errors.js";
|
|
6
|
-
import { getAstroStudioEnv, getAstroStudioUrl,
|
|
8
|
+
import { getAstroStudioEnv, getAstroStudioUrl, safeFetch } from "./utils.js";
|
|
7
9
|
const SESSION_LOGIN_FILE = pathToFileURL(join(homedir(), ".astro", "session-token"));
|
|
8
10
|
const PROJECT_ID_FILE = pathToFileURL(join(process.cwd(), ".astro", "link"));
|
|
9
11
|
class ManagedLocalAppToken {
|
|
@@ -19,17 +21,11 @@ class ManagedLocalAppToken {
|
|
|
19
21
|
class ManagedRemoteAppToken {
|
|
20
22
|
token;
|
|
21
23
|
session;
|
|
22
|
-
region;
|
|
23
24
|
projectId;
|
|
24
25
|
ttl;
|
|
25
26
|
renewTimer;
|
|
26
|
-
static async getRegionCode() {
|
|
27
|
-
const pingResponse = await safeFetch(new URL(`${getRemoteDatabaseUrl()}/ping`));
|
|
28
|
-
const pingResult = await pingResponse.json();
|
|
29
|
-
return pingResult.data.region;
|
|
30
|
-
}
|
|
31
27
|
static async create(sessionToken, projectId) {
|
|
32
|
-
const
|
|
28
|
+
const spinner = ora("Connecting to remote database...").start();
|
|
33
29
|
const response = await safeFetch(
|
|
34
30
|
new URL(`${getAstroStudioUrl()}/auth/cli/token-create`),
|
|
35
31
|
{
|
|
@@ -37,17 +33,18 @@ class ManagedRemoteAppToken {
|
|
|
37
33
|
headers: new Headers({
|
|
38
34
|
Authorization: `Bearer ${sessionToken}`
|
|
39
35
|
}),
|
|
40
|
-
body: JSON.stringify({ projectId
|
|
36
|
+
body: JSON.stringify({ projectId })
|
|
41
37
|
},
|
|
42
38
|
(res) => {
|
|
43
39
|
throw new Error(`Failed to create token: ${res.status} ${res.statusText}`);
|
|
44
40
|
}
|
|
45
41
|
);
|
|
42
|
+
await new Promise((resolve) => setTimeout(resolve, 2e3));
|
|
43
|
+
spinner.succeed(green("Connected to remote database."));
|
|
46
44
|
const { token: shortLivedAppToken, ttl } = await response.json();
|
|
47
45
|
return new ManagedRemoteAppToken({
|
|
48
46
|
token: shortLivedAppToken,
|
|
49
47
|
session: sessionToken,
|
|
50
|
-
region,
|
|
51
48
|
projectId,
|
|
52
49
|
ttl
|
|
53
50
|
});
|
|
@@ -55,7 +52,6 @@ class ManagedRemoteAppToken {
|
|
|
55
52
|
constructor(options) {
|
|
56
53
|
this.token = options.token;
|
|
57
54
|
this.session = options.session;
|
|
58
|
-
this.region = options.region;
|
|
59
55
|
this.projectId = options.projectId;
|
|
60
56
|
this.ttl = options.ttl;
|
|
61
57
|
this.renewTimer = setTimeout(() => this.renew(), 1e3 * 60 * 5 / 2);
|
|
@@ -69,7 +65,7 @@ class ManagedRemoteAppToken {
|
|
|
69
65
|
Authorization: `Bearer ${this.session}`,
|
|
70
66
|
"Content-Type": "application/json"
|
|
71
67
|
},
|
|
72
|
-
body: JSON.stringify(
|
|
68
|
+
body: JSON.stringify(body)
|
|
73
69
|
},
|
|
74
70
|
() => {
|
|
75
71
|
throw new Error(`Failed to fetch ${url}.`);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@astrojs/db",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.3",
|
|
4
4
|
"description": "",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -80,7 +80,7 @@
|
|
|
80
80
|
"mocha": "^10.2.0",
|
|
81
81
|
"typescript": "^5.2.2",
|
|
82
82
|
"vite": "^5.1.4",
|
|
83
|
-
"astro": "4.5.
|
|
83
|
+
"astro": "4.5.4",
|
|
84
84
|
"astro-scripts": "0.0.14"
|
|
85
85
|
},
|
|
86
86
|
"scripts": {
|