deepspace 0.3.6 → 0.3.7
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/cli.js +80 -51
- package/dist/cli.js.map +1 -1
- package/dist/index.d.ts +0 -1
- package/dist/index.js +14 -50
- package/dist/index.js.map +1 -1
- package/dist/worker.d.ts +65 -22
- package/dist/worker.js +6 -6
- package/dist/worker.js.map +1 -1
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -14,7 +14,24 @@ import { join as join2 } from "path";
|
|
|
14
14
|
import { homedir } from "os";
|
|
15
15
|
import { exec } from "child_process";
|
|
16
16
|
import { platform } from "os";
|
|
17
|
+
import * as p2 from "@clack/prompts";
|
|
18
|
+
|
|
19
|
+
// src/cli/lib/spinner.ts
|
|
17
20
|
import * as p from "@clack/prompts";
|
|
21
|
+
function createSpinner() {
|
|
22
|
+
if (process.stdout.isTTY) return p.spinner();
|
|
23
|
+
return {
|
|
24
|
+
start: (msg) => {
|
|
25
|
+
if (msg) console.log(msg);
|
|
26
|
+
},
|
|
27
|
+
stop: (msg) => {
|
|
28
|
+
if (msg) console.log(msg);
|
|
29
|
+
},
|
|
30
|
+
message: (msg) => {
|
|
31
|
+
if (msg) console.log(msg);
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
}
|
|
18
35
|
|
|
19
36
|
// src/cli/env.ts
|
|
20
37
|
import { existsSync, readFileSync, writeFileSync } from "fs";
|
|
@@ -261,36 +278,36 @@ var login_default = defineCommand({
|
|
|
261
278
|
console.log("Logged in");
|
|
262
279
|
return;
|
|
263
280
|
}
|
|
264
|
-
|
|
265
|
-
const s =
|
|
281
|
+
p2.intro("DeepSpace Login");
|
|
282
|
+
const s = createSpinner();
|
|
266
283
|
s.start("Creating login session...");
|
|
267
284
|
const sessionRes = await fetch(`${AUTH_URL}/api/auth/cli/session`, { method: "POST" });
|
|
268
285
|
if (!sessionRes.ok) {
|
|
269
286
|
s.stop("Failed");
|
|
270
|
-
|
|
287
|
+
p2.cancel("Could not create login session");
|
|
271
288
|
process.exit(1);
|
|
272
289
|
}
|
|
273
290
|
const sessionData = await sessionRes.json();
|
|
274
291
|
if (!sessionData.sessionId || !sessionData.loginUrl) {
|
|
275
292
|
s.stop("Failed");
|
|
276
|
-
|
|
293
|
+
p2.cancel("Could not create login session");
|
|
277
294
|
process.exit(1);
|
|
278
295
|
}
|
|
279
296
|
const { sessionId, loginUrl } = sessionData;
|
|
280
297
|
s.stop("Opening browser...");
|
|
281
|
-
|
|
298
|
+
p2.log.info(`If the browser doesn't open, visit:
|
|
282
299
|
${loginUrl}`);
|
|
283
300
|
openBrowser(loginUrl);
|
|
284
301
|
s.start("Waiting for authentication...");
|
|
285
302
|
const result = await pollForCompletion(sessionId);
|
|
286
303
|
if (!result) {
|
|
287
304
|
s.stop("Timed out");
|
|
288
|
-
|
|
305
|
+
p2.cancel("Login timed out. Run `deepspace login` to try again.");
|
|
289
306
|
process.exit(1);
|
|
290
307
|
}
|
|
291
308
|
storeCredentials(result.sessionToken, result.jwt);
|
|
292
309
|
s.stop("Authenticated");
|
|
293
|
-
|
|
310
|
+
p2.outro(`Logged in as ${result.name ?? result.email}`);
|
|
294
311
|
}
|
|
295
312
|
});
|
|
296
313
|
async function pollForCompletion(sessionId) {
|
|
@@ -808,7 +825,7 @@ function resolvePort3(arg) {
|
|
|
808
825
|
|
|
809
826
|
// src/cli/commands/test-accounts.ts
|
|
810
827
|
import { defineCommand as defineCommand6 } from "citty";
|
|
811
|
-
import * as
|
|
828
|
+
import * as p3 from "@clack/prompts";
|
|
812
829
|
import { readFileSync as readFileSync4, writeFileSync as writeFileSync4, existsSync as existsSync6, mkdirSync as mkdirSync3 } from "fs";
|
|
813
830
|
import { join as join7 } from "path";
|
|
814
831
|
import { homedir as homedir4 } from "os";
|
|
@@ -1048,11 +1065,11 @@ var clear = defineCommand6({
|
|
|
1048
1065
|
}
|
|
1049
1066
|
if (!args.yes) {
|
|
1050
1067
|
const subject = args.label ? `${targets.length} test account(s) labeled '${args.label}'` : `all ${targets.length} test account(s)`;
|
|
1051
|
-
const confirmed = await
|
|
1068
|
+
const confirmed = await p3.confirm({
|
|
1052
1069
|
message: `Delete ${subject}? This is not reversible.`,
|
|
1053
1070
|
initialValue: false
|
|
1054
1071
|
});
|
|
1055
|
-
if (
|
|
1072
|
+
if (p3.isCancel(confirmed) || !confirmed) {
|
|
1056
1073
|
console.log("Cancelled.");
|
|
1057
1074
|
return;
|
|
1058
1075
|
}
|
|
@@ -1099,7 +1116,7 @@ import { execSync as execSync2 } from "child_process";
|
|
|
1099
1116
|
import { readFileSync as readFileSync5, readdirSync, existsSync as existsSync7 } from "fs";
|
|
1100
1117
|
import { parse as parseToml2 } from "smol-toml";
|
|
1101
1118
|
import { join as join8, resolve as resolve3, dirname } from "path";
|
|
1102
|
-
import * as
|
|
1119
|
+
import * as p4 from "@clack/prompts";
|
|
1103
1120
|
|
|
1104
1121
|
// src/server/rooms/binding-manifest.ts
|
|
1105
1122
|
var AUTO_PROVISION_SENTINEL = "auto";
|
|
@@ -1373,29 +1390,29 @@ var deploy_default = defineCommand7({
|
|
|
1373
1390
|
},
|
|
1374
1391
|
async run({ args }) {
|
|
1375
1392
|
const appDir = resolve3(args.dir ?? ".");
|
|
1376
|
-
|
|
1393
|
+
p4.intro("Deploying DeepSpace app");
|
|
1377
1394
|
const wranglerPath = join8(appDir, "wrangler.toml");
|
|
1378
1395
|
if (!existsSync7(wranglerPath)) {
|
|
1379
|
-
|
|
1396
|
+
p4.cancel("No wrangler.toml found. Are you in a DeepSpace app directory?");
|
|
1380
1397
|
process.exit(1);
|
|
1381
1398
|
}
|
|
1382
1399
|
const wranglerConfig = parseToml2(readFileSync5(wranglerPath, "utf-8"));
|
|
1383
1400
|
const nameRes = resolveAppName(wranglerConfig.name);
|
|
1384
1401
|
if (!nameRes.ok) {
|
|
1385
|
-
|
|
1402
|
+
p4.cancel(`wrangler.toml: ${nameRes.reason}`);
|
|
1386
1403
|
process.exit(1);
|
|
1387
1404
|
}
|
|
1388
|
-
if (nameRes.warning)
|
|
1405
|
+
if (nameRes.warning) p4.log.warn(nameRes.warning);
|
|
1389
1406
|
const appName = nameRes.name;
|
|
1390
|
-
|
|
1407
|
+
p4.log.info(`App: ${appName}`);
|
|
1391
1408
|
let token;
|
|
1392
1409
|
try {
|
|
1393
1410
|
token = await ensureToken();
|
|
1394
1411
|
} catch (err) {
|
|
1395
|
-
|
|
1412
|
+
p4.cancel(err.message);
|
|
1396
1413
|
process.exit(1);
|
|
1397
1414
|
}
|
|
1398
|
-
const s =
|
|
1415
|
+
const s = createSpinner();
|
|
1399
1416
|
s.start("Building...");
|
|
1400
1417
|
try {
|
|
1401
1418
|
execSync2("npx vite build", { cwd: appDir, stdio: "pipe" });
|
|
@@ -1407,13 +1424,13 @@ var deploy_default = defineCommand7({
|
|
|
1407
1424
|
s.stop("Built");
|
|
1408
1425
|
const deployConfigPath = join8(appDir, ".wrangler", "deploy", "config.json");
|
|
1409
1426
|
if (!existsSync7(deployConfigPath)) {
|
|
1410
|
-
|
|
1427
|
+
p4.cancel("Build output config not found at .wrangler/deploy/config.json");
|
|
1411
1428
|
process.exit(1);
|
|
1412
1429
|
}
|
|
1413
1430
|
const deployConfig = JSON.parse(readFileSync5(deployConfigPath, "utf-8"));
|
|
1414
1431
|
const outputWranglerPath = resolve3(dirname(deployConfigPath), deployConfig.configPath);
|
|
1415
1432
|
if (!existsSync7(outputWranglerPath)) {
|
|
1416
|
-
|
|
1433
|
+
p4.cancel(`Output wrangler.json not found at ${outputWranglerPath}`);
|
|
1417
1434
|
process.exit(1);
|
|
1418
1435
|
}
|
|
1419
1436
|
const outputConfig = JSON.parse(readFileSync5(outputWranglerPath, "utf-8"));
|
|
@@ -1421,11 +1438,11 @@ var deploy_default = defineCommand7({
|
|
|
1421
1438
|
const workerBundlePath = join8(workerDir, outputConfig.main);
|
|
1422
1439
|
const clientDir = outputConfig.assets?.directory ? resolve3(workerDir, outputConfig.assets.directory) : null;
|
|
1423
1440
|
if (!existsSync7(workerBundlePath)) {
|
|
1424
|
-
|
|
1441
|
+
p4.cancel(`Worker bundle not found at ${workerBundlePath}`);
|
|
1425
1442
|
process.exit(1);
|
|
1426
1443
|
}
|
|
1427
1444
|
if (!clientDir || !existsSync7(clientDir)) {
|
|
1428
|
-
|
|
1445
|
+
p4.cancel(`Client assets not found at ${clientDir}`);
|
|
1429
1446
|
process.exit(1);
|
|
1430
1447
|
}
|
|
1431
1448
|
s.start("Collecting assets...");
|
|
@@ -1442,19 +1459,19 @@ var deploy_default = defineCommand7({
|
|
|
1442
1459
|
sqlite: sqliteClasses.has(b.class_name)
|
|
1443
1460
|
}));
|
|
1444
1461
|
if (doManifest?.length) {
|
|
1445
|
-
|
|
1462
|
+
p4.log.info(`DO manifest: ${doManifest.length} binding(s)`);
|
|
1446
1463
|
}
|
|
1447
1464
|
const customBindings = bindingManifestFromOutputConfig(outputConfig);
|
|
1448
1465
|
const validation = validateBindingManifest(customBindings);
|
|
1449
1466
|
if (!validation.valid) {
|
|
1450
|
-
|
|
1467
|
+
p4.cancel(
|
|
1451
1468
|
`Invalid binding(s) in wrangler.toml:
|
|
1452
1469
|
` + validation.errors.map((e) => ` \u2022 ${e.reason}`).join("\n")
|
|
1453
1470
|
);
|
|
1454
1471
|
process.exit(1);
|
|
1455
1472
|
}
|
|
1456
1473
|
if (customBindings.length) {
|
|
1457
|
-
|
|
1474
|
+
p4.log.info(
|
|
1458
1475
|
`Custom bindings: ${customBindings.map((b) => `${b.name} (${b.type})`).join(", ")}`
|
|
1459
1476
|
);
|
|
1460
1477
|
}
|
|
@@ -1466,7 +1483,7 @@ var deploy_default = defineCommand7({
|
|
|
1466
1483
|
try {
|
|
1467
1484
|
userSecrets = parseDevVars(customSection);
|
|
1468
1485
|
} catch (err) {
|
|
1469
|
-
|
|
1486
|
+
p4.cancel(`.dev.vars: ${err.message}`);
|
|
1470
1487
|
process.exit(1);
|
|
1471
1488
|
}
|
|
1472
1489
|
}
|
|
@@ -1478,20 +1495,20 @@ var deploy_default = defineCommand7({
|
|
|
1478
1495
|
]);
|
|
1479
1496
|
for (const name of userSecretNames) {
|
|
1480
1497
|
if (RESERVED_BINDING_NAMES.has(name)) {
|
|
1481
|
-
|
|
1498
|
+
p4.cancel(
|
|
1482
1499
|
`.dev.vars: "${name}" is a reserved binding name and cannot be used as an app secret.`
|
|
1483
1500
|
);
|
|
1484
1501
|
process.exit(1);
|
|
1485
1502
|
}
|
|
1486
1503
|
if (declaredBindingNames.has(name)) {
|
|
1487
|
-
|
|
1504
|
+
p4.cancel(
|
|
1488
1505
|
`.dev.vars: "${name}" collides with a binding declared in wrangler.toml \u2014 rename one or the other.`
|
|
1489
1506
|
);
|
|
1490
1507
|
process.exit(1);
|
|
1491
1508
|
}
|
|
1492
1509
|
}
|
|
1493
1510
|
if (userSecretNames.length) {
|
|
1494
|
-
|
|
1511
|
+
p4.log.info(`App secrets (from .dev.vars): ${userSecretNames.join(", ")}`);
|
|
1495
1512
|
}
|
|
1496
1513
|
s.start(`Deploying to ${appName}.app.space...`);
|
|
1497
1514
|
const form = new FormData();
|
|
@@ -1514,7 +1531,7 @@ var deploy_default = defineCommand7({
|
|
|
1514
1531
|
const body = await res.json().catch(() => ({}));
|
|
1515
1532
|
if (!res.ok || !body.success) {
|
|
1516
1533
|
s.stop("Deploy failed");
|
|
1517
|
-
|
|
1534
|
+
p4.cancel(body.error ?? `Deployment error (${res.status})`);
|
|
1518
1535
|
process.exit(1);
|
|
1519
1536
|
}
|
|
1520
1537
|
if (body.url) {
|
|
@@ -1522,15 +1539,15 @@ var deploy_default = defineCommand7({
|
|
|
1522
1539
|
const ok = await waitForAssetsReady(body.url, 9e4);
|
|
1523
1540
|
if (!ok) {
|
|
1524
1541
|
s.stop("Deployed (edge propagation still in progress after 90s)");
|
|
1525
|
-
|
|
1526
|
-
|
|
1527
|
-
|
|
1542
|
+
p4.log.warn("First requests may briefly hit the assets transitional page; retry in a minute.");
|
|
1543
|
+
p4.log.success(`Live at: ${body.url}`);
|
|
1544
|
+
p4.outro("Done");
|
|
1528
1545
|
return;
|
|
1529
1546
|
}
|
|
1530
1547
|
}
|
|
1531
1548
|
s.stop("Deployed!");
|
|
1532
|
-
|
|
1533
|
-
|
|
1549
|
+
p4.log.success(`Live at: ${body.url}`);
|
|
1550
|
+
p4.outro("Done");
|
|
1534
1551
|
}
|
|
1535
1552
|
});
|
|
1536
1553
|
async function waitForAssetsReady(url, timeoutMs) {
|
|
@@ -1577,7 +1594,7 @@ import { defineCommand as defineCommand8 } from "citty";
|
|
|
1577
1594
|
import { readFileSync as readFileSync6, existsSync as existsSync8 } from "fs";
|
|
1578
1595
|
import { join as join9 } from "path";
|
|
1579
1596
|
import { parse as parseToml3 } from "smol-toml";
|
|
1580
|
-
import * as
|
|
1597
|
+
import * as p5 from "@clack/prompts";
|
|
1581
1598
|
var DEPLOY_URL2 = process.env.DEEPSPACE_DEPLOY_URL ?? ENVS.prod.deploy;
|
|
1582
1599
|
var undeploy_default = defineCommand8({
|
|
1583
1600
|
meta: {
|
|
@@ -1601,18 +1618,18 @@ var undeploy_default = defineCommand8({
|
|
|
1601
1618
|
}
|
|
1602
1619
|
}
|
|
1603
1620
|
if (!appName) {
|
|
1604
|
-
|
|
1621
|
+
p5.cancel("Provide an app name or run from a DeepSpace app directory.");
|
|
1605
1622
|
process.exit(1);
|
|
1606
1623
|
}
|
|
1607
1624
|
let token;
|
|
1608
1625
|
try {
|
|
1609
1626
|
token = await ensureToken();
|
|
1610
1627
|
} catch (err) {
|
|
1611
|
-
|
|
1628
|
+
p5.cancel(err.message);
|
|
1612
1629
|
process.exit(1);
|
|
1613
1630
|
}
|
|
1614
|
-
|
|
1615
|
-
const s =
|
|
1631
|
+
p5.intro(`Undeploying ${appName}`);
|
|
1632
|
+
const s = createSpinner();
|
|
1616
1633
|
s.start("Removing...");
|
|
1617
1634
|
const res = await fetch(`${DEPLOY_URL2}/api/deploy/${appName}`, {
|
|
1618
1635
|
method: "DELETE",
|
|
@@ -1621,11 +1638,11 @@ var undeploy_default = defineCommand8({
|
|
|
1621
1638
|
const body = await res.json().catch(() => ({}));
|
|
1622
1639
|
if (!res.ok || !body.success) {
|
|
1623
1640
|
s.stop("Failed");
|
|
1624
|
-
|
|
1641
|
+
p5.cancel(body.error ?? `Undeploy error (${res.status})`);
|
|
1625
1642
|
process.exit(1);
|
|
1626
1643
|
}
|
|
1627
1644
|
s.stop("Removed");
|
|
1628
|
-
|
|
1645
|
+
p5.outro(`${appName}.app.space has been taken down`);
|
|
1629
1646
|
}
|
|
1630
1647
|
});
|
|
1631
1648
|
|
|
@@ -1796,6 +1813,18 @@ async function api(token, path, init) {
|
|
|
1796
1813
|
}
|
|
1797
1814
|
return JSON.parse(text);
|
|
1798
1815
|
}
|
|
1816
|
+
function scrubInternal(value) {
|
|
1817
|
+
if (Array.isArray(value)) return value.map(scrubInternal);
|
|
1818
|
+
if (value && typeof value === "object") {
|
|
1819
|
+
const out = {};
|
|
1820
|
+
for (const [k, v] of Object.entries(value)) {
|
|
1821
|
+
if (k === "costCents") continue;
|
|
1822
|
+
out[k] = scrubInternal(v);
|
|
1823
|
+
}
|
|
1824
|
+
return out;
|
|
1825
|
+
}
|
|
1826
|
+
return value;
|
|
1827
|
+
}
|
|
1799
1828
|
function fmtCents(cents) {
|
|
1800
1829
|
if (cents === null || cents === void 0) return "\u2014";
|
|
1801
1830
|
return `$${(cents / 100).toFixed(2)}`;
|
|
@@ -1832,7 +1861,7 @@ var search = defineCommand11({
|
|
|
1832
1861
|
`/api/domains/search?q=${encodeURIComponent(args.query)}&limit=${limit}`
|
|
1833
1862
|
);
|
|
1834
1863
|
if (args.json) {
|
|
1835
|
-
process.stdout.write(JSON.stringify(result, null, 2) + "\n");
|
|
1864
|
+
process.stdout.write(JSON.stringify(scrubInternal(result), null, 2) + "\n");
|
|
1836
1865
|
return;
|
|
1837
1866
|
}
|
|
1838
1867
|
if (result.domains.length === 0) {
|
|
@@ -1853,8 +1882,8 @@ var buy = defineCommand11({
|
|
|
1853
1882
|
domain: { type: "positional", description: "Domain to buy", required: true },
|
|
1854
1883
|
app: { type: "string", description: "App to attach (defaults to ./wrangler.toml)" },
|
|
1855
1884
|
yes: { type: "boolean", description: "Skip the confirmation prompt", default: false },
|
|
1856
|
-
|
|
1857
|
-
|
|
1885
|
+
open: { type: "boolean", description: "Open browser at Stripe URL (use --no-open to print URL only)", default: true },
|
|
1886
|
+
wait: { type: "boolean", description: "Poll until provisioning completes (use --no-wait to exit after session creation)", default: true },
|
|
1858
1887
|
json: { type: "boolean", description: "Emit JSON to stdout", default: false }
|
|
1859
1888
|
},
|
|
1860
1889
|
async run({ args }) {
|
|
@@ -1889,14 +1918,14 @@ var buy = defineCommand11({
|
|
|
1889
1918
|
}
|
|
1890
1919
|
);
|
|
1891
1920
|
if (args.json) {
|
|
1892
|
-
process.stdout.write(JSON.stringify({ ...checkout, expectedTime, registrar: result.registrar }, null, 2) + "\n");
|
|
1921
|
+
process.stdout.write(JSON.stringify(scrubInternal({ ...checkout, expectedTime, registrar: result.registrar }), null, 2) + "\n");
|
|
1893
1922
|
} else {
|
|
1894
1923
|
console.log(`Stripe Checkout: ${checkout.url}`);
|
|
1895
1924
|
}
|
|
1896
|
-
if (
|
|
1925
|
+
if (args.open && process.stdin.isTTY) {
|
|
1897
1926
|
openBrowser2(checkout.url);
|
|
1898
1927
|
}
|
|
1899
|
-
if (args
|
|
1928
|
+
if (!args.wait) return;
|
|
1900
1929
|
const timeoutMs = result.registrar === "cloudflare" ? 5 * 60 * 1e3 : 60 * 60 * 1e3;
|
|
1901
1930
|
if (!args.json) {
|
|
1902
1931
|
console.log(`Waiting for payment & provisioning (up to ${expectedTime}). Press Ctrl-C anytime \u2014`);
|
|
@@ -1917,7 +1946,7 @@ var buy = defineCommand11({
|
|
|
1917
1946
|
}
|
|
1918
1947
|
if (detail.domain.status === "active") {
|
|
1919
1948
|
if (args.json) {
|
|
1920
|
-
process.stdout.write(JSON.stringify({ ...checkout, status: "active", domain: args.domain }, null, 2) + "\n");
|
|
1949
|
+
process.stdout.write(JSON.stringify(scrubInternal({ ...checkout, status: "active", domain: args.domain }), null, 2) + "\n");
|
|
1921
1950
|
} else {
|
|
1922
1951
|
console.log(`\u2713 ${args.domain} is live and pointing at ${appName}`);
|
|
1923
1952
|
}
|
|
@@ -1945,7 +1974,7 @@ var list2 = defineCommand11({
|
|
|
1945
1974
|
const token = await ensureToken();
|
|
1946
1975
|
const result = await api(token, "/api/domains");
|
|
1947
1976
|
if (args.json) {
|
|
1948
|
-
process.stdout.write(JSON.stringify(result, null, 2) + "\n");
|
|
1977
|
+
process.stdout.write(JSON.stringify(scrubInternal(result), null, 2) + "\n");
|
|
1949
1978
|
return;
|
|
1950
1979
|
}
|
|
1951
1980
|
if (result.domains.length === 0) {
|
|
@@ -1975,7 +2004,7 @@ var status = defineCommand11({
|
|
|
1975
2004
|
process.exit(1);
|
|
1976
2005
|
}
|
|
1977
2006
|
if (args.json) {
|
|
1978
|
-
process.stdout.write(JSON.stringify(found, null, 2) + "\n");
|
|
2007
|
+
process.stdout.write(JSON.stringify(scrubInternal(found), null, 2) + "\n");
|
|
1979
2008
|
return;
|
|
1980
2009
|
}
|
|
1981
2010
|
console.log(`Domain: ${found.domain}`);
|