@somewhere-cloud/cli 0.38.127 → 0.38.128
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/CHANGELOG.md +5 -0
- package/dist/lib/bundle.js +262 -219
- package/dist/lib/bundle.js.map +3 -3
- package/npm-shrinkwrap.json +2 -2
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+
## 0.38.128
|
|
2
|
+
|
|
3
|
+
- A claim connection can work on saved apps and create new ones. It can work on other existing apps when the owner selects that option.
|
|
4
|
+
- Show the approved access after connecting and list the apps and their deploy availability with `somewhere projects`.
|
|
5
|
+
|
|
1
6
|
## 0.38.127
|
|
2
7
|
|
|
3
8
|
- Starter test checks continue after independent failures and explain skipped prerequisites. Use `somewhere test --fail-fast` to stop each app-check script after its first failure.
|
package/dist/lib/bundle.js
CHANGED
|
@@ -36599,6 +36599,9 @@ var init_client = __esm({
|
|
|
36599
36599
|
* API_KEY_EXPIRED. */
|
|
36600
36600
|
async refreshAccessKey(timeoutMs) {
|
|
36601
36601
|
const config2 = loadConfig();
|
|
36602
|
+
if (config2?.claim_access && config2.token === this.token) {
|
|
36603
|
+
throw new CliApiError("SESSION_EXPIRED", `This app connection expired. Run \`${cliInvocation()} login\` and ask the account owner to approve it.`, 401);
|
|
36604
|
+
}
|
|
36602
36605
|
const refreshToken = config2?.refresh_token;
|
|
36603
36606
|
if (!refreshToken) {
|
|
36604
36607
|
throw new CliApiError("SESSION_EXPIRED", `Your somewhere session expired and there is no refresh token saved (old login format). Run \`${cliInvocation()} login\` to sign in again \u2014 that upgrades your config so sessions refresh automatically from now on.`, 401);
|
|
@@ -36692,7 +36695,9 @@ var init_client = __esm({
|
|
|
36692
36695
|
if (typeof retry_after_ms === "number" && Number.isFinite(retry_after_ms)) {
|
|
36693
36696
|
meta3.retryAfterMs = retry_after_ms;
|
|
36694
36697
|
}
|
|
36695
|
-
|
|
36698
|
+
const agentSignIn = `Run \`${cliInvocation()} login\` and ask the account owner to approve it.`;
|
|
36699
|
+
const agentMessage = error3 === "PROJECT_AGENT_OPERATION_FORBIDDEN" ? `This app connection cannot use that feature. ${agentSignIn}` : error3 === "PROJECT_AGENT_PROJECT_FORBIDDEN" ? `This app is outside this connection or no longer available. ${agentSignIn}` : void 0;
|
|
36700
|
+
throw new CliApiError(error3 ?? "UNKNOWN", agentMessage ?? (error3 === void 0 && message3 === void 0 ? unclassifiedResponseMessage(res.status, text) : message3 ?? "Unknown error"), res.status, data2 ?? extraData, hint, meta3);
|
|
36696
36701
|
}
|
|
36697
36702
|
/** Like call(), but returns the raw response TEXT instead of JSON-parsing it
|
|
36698
36703
|
* — for endpoints that legitimately return non-JSON (e.g. a SQL db dump). A
|
|
@@ -46551,6 +46556,200 @@ var init_link = __esm({
|
|
|
46551
46556
|
}
|
|
46552
46557
|
});
|
|
46553
46558
|
|
|
46559
|
+
// dist/lib/claim-handoff.js
|
|
46560
|
+
import { createDecipheriv, createHash as createHash3, randomBytes as randomBytes2 } from "node:crypto";
|
|
46561
|
+
function readClaimConnection(client) {
|
|
46562
|
+
return client.call("GET", "/auth/temp-claim/status", void 0, void 0, { refresh: false });
|
|
46563
|
+
}
|
|
46564
|
+
function verifierHash(verifier) {
|
|
46565
|
+
return createHash3("sha256").update(verifier, "utf8").digest("hex");
|
|
46566
|
+
}
|
|
46567
|
+
function newVerifier() {
|
|
46568
|
+
return randomBytes2(32).toString("base64url");
|
|
46569
|
+
}
|
|
46570
|
+
function decodeCredentials(state, response) {
|
|
46571
|
+
if (!state.handoff_id || response.project_id !== state.project_id) {
|
|
46572
|
+
throw new Error("Claim continuation returned a different project. No credential was installed.");
|
|
46573
|
+
}
|
|
46574
|
+
const key = createHash3("sha256").update(`claim-cli-handoff:v1:${state.verifier}`, "utf8").digest();
|
|
46575
|
+
const combined = Buffer.from(response.ciphertext, "base64");
|
|
46576
|
+
if (combined.length <= 16)
|
|
46577
|
+
throw new Error("Claim continuation returned an invalid credential payload.");
|
|
46578
|
+
const encrypted = combined.subarray(0, -16);
|
|
46579
|
+
const tag = combined.subarray(-16);
|
|
46580
|
+
const decipher = createDecipheriv("aes-256-gcm", key, Buffer.from(response.iv, "base64"));
|
|
46581
|
+
decipher.setAAD(Buffer.from(`${state.handoff_id}:${state.project_id}`, "utf8"));
|
|
46582
|
+
decipher.setAuthTag(tag);
|
|
46583
|
+
const plaintext = Buffer.concat([decipher.update(encrypted), decipher.final()]).toString("utf8");
|
|
46584
|
+
const parsed = JSON.parse(plaintext);
|
|
46585
|
+
const projects = parsed.scope?.projects;
|
|
46586
|
+
const agent = parsed.credential_kind === "project_agent";
|
|
46587
|
+
if (typeof parsed.token !== "string" || !parsed.token || typeof parsed.expires_at !== "string" || typeof parsed.email !== "string" || parsed.project_id !== state.project_id || parsed.approved_scope !== void 0 && parsed.approved_scope !== "project" || !Array.isArray(projects) || !projects.includes(state.project_id) || projects.some((project) => typeof project !== "string" || !project) || (agent ? parsed.refresh_token !== null || parsed.claim_access !== "new_projects" && parsed.claim_access !== "all_projects" : parsed.credential_kind !== void 0 || parsed.claim_access !== void 0 || typeof parsed.refresh_token !== "string" || projects.length !== 1)) {
|
|
46588
|
+
throw new Error("Claim continuation credential did not match the approved project. Nothing was installed.");
|
|
46589
|
+
}
|
|
46590
|
+
return parsed;
|
|
46591
|
+
}
|
|
46592
|
+
async function post(path3, body, token) {
|
|
46593
|
+
const response = await fetchWithProxy(`${API_BASE_URL}${path3}`, {
|
|
46594
|
+
method: "POST",
|
|
46595
|
+
headers: {
|
|
46596
|
+
"Content-Type": "application/json",
|
|
46597
|
+
...token ? { Authorization: `Bearer ${token}` } : {}
|
|
46598
|
+
},
|
|
46599
|
+
body: JSON.stringify(body),
|
|
46600
|
+
signal: AbortSignal.timeout(15e3)
|
|
46601
|
+
}, 15e3);
|
|
46602
|
+
const envelope = await response.json();
|
|
46603
|
+
return { response, envelope };
|
|
46604
|
+
}
|
|
46605
|
+
async function ensureClaimHandoff(projectId) {
|
|
46606
|
+
const config2 = loadConfig();
|
|
46607
|
+
if (!config2?.temporary || !config2.token)
|
|
46608
|
+
return null;
|
|
46609
|
+
let state = config2.claim_handoff;
|
|
46610
|
+
if (!state || state.project_id !== projectId) {
|
|
46611
|
+
state = { project_id: projectId, verifier: newVerifier() };
|
|
46612
|
+
saveConfig({ ...config2, claim_handoff: state });
|
|
46613
|
+
}
|
|
46614
|
+
if (state.handoff_id)
|
|
46615
|
+
return state;
|
|
46616
|
+
const { response, envelope } = await post("/auth/temp-handoff/register", {
|
|
46617
|
+
project_id: projectId,
|
|
46618
|
+
verifier_hash: verifierHash(state.verifier),
|
|
46619
|
+
device_name: getDeviceKeyName(),
|
|
46620
|
+
client: { hostname: describeThisDevice().hostname },
|
|
46621
|
+
capabilities: ["claim_project_agent_v1"]
|
|
46622
|
+
}, config2.token);
|
|
46623
|
+
if (!response.ok || !envelope.ok || !envelope.data) {
|
|
46624
|
+
throw new Error(envelope.message || envelope.error || `CLI continuation registration failed (HTTP ${response.status}).`);
|
|
46625
|
+
}
|
|
46626
|
+
const registered = { ...state, handoff_id: envelope.data.handoff_id, expires_at: envelope.data.expires_at };
|
|
46627
|
+
const current = loadConfig();
|
|
46628
|
+
if (!current?.temporary || current.claim_handoff?.verifier !== state.verifier)
|
|
46629
|
+
return null;
|
|
46630
|
+
saveConfig({ ...current, claim_handoff: registered });
|
|
46631
|
+
return registered;
|
|
46632
|
+
}
|
|
46633
|
+
async function acknowledge(handoffId, verifier) {
|
|
46634
|
+
try {
|
|
46635
|
+
const { response, envelope } = await post("/auth/temp-handoff/ack", {
|
|
46636
|
+
handoff_id: handoffId,
|
|
46637
|
+
verifier
|
|
46638
|
+
});
|
|
46639
|
+
return response.ok && envelope.ok && envelope.data?.acknowledged === true;
|
|
46640
|
+
} catch {
|
|
46641
|
+
return false;
|
|
46642
|
+
}
|
|
46643
|
+
}
|
|
46644
|
+
function clearCurrentAcknowledgement(expected) {
|
|
46645
|
+
const current = loadConfig();
|
|
46646
|
+
if (!current)
|
|
46647
|
+
return null;
|
|
46648
|
+
if (current.claim_handoff_ack?.handoff_id !== expected.handoff_id || current.claim_handoff_ack.verifier !== expected.verifier)
|
|
46649
|
+
return current;
|
|
46650
|
+
const { claim_handoff_ack: _removed, ...clean } = current;
|
|
46651
|
+
saveConfig(clean);
|
|
46652
|
+
return clean;
|
|
46653
|
+
}
|
|
46654
|
+
function dropExpiredHandoff(token, state) {
|
|
46655
|
+
const current = loadConfig();
|
|
46656
|
+
if (!current?.temporary || current.token !== token || current.claim_handoff?.handoff_id !== state.handoff_id || current.claim_handoff?.verifier !== state.verifier)
|
|
46657
|
+
return;
|
|
46658
|
+
const { claim_handoff: _expired, ...rest } = current;
|
|
46659
|
+
saveConfig(rest);
|
|
46660
|
+
}
|
|
46661
|
+
async function recoverClaimHandoff() {
|
|
46662
|
+
let config2 = loadConfig();
|
|
46663
|
+
if (!config2)
|
|
46664
|
+
return { kind: "none" };
|
|
46665
|
+
if (config2.claim_handoff_ack) {
|
|
46666
|
+
const ack = config2.claim_handoff_ack;
|
|
46667
|
+
if (await acknowledge(ack.handoff_id, ack.verifier)) {
|
|
46668
|
+
config2 = clearCurrentAcknowledgement(ack);
|
|
46669
|
+
if (!config2)
|
|
46670
|
+
return { kind: "none" };
|
|
46671
|
+
}
|
|
46672
|
+
}
|
|
46673
|
+
const state = config2.temporary ? config2.claim_handoff : void 0;
|
|
46674
|
+
if (!state?.handoff_id)
|
|
46675
|
+
return { kind: "none" };
|
|
46676
|
+
let response;
|
|
46677
|
+
let envelope;
|
|
46678
|
+
try {
|
|
46679
|
+
({ response, envelope } = await post("/auth/temp-handoff/exchange", {
|
|
46680
|
+
handoff_id: state.handoff_id,
|
|
46681
|
+
verifier: state.verifier
|
|
46682
|
+
}));
|
|
46683
|
+
} catch {
|
|
46684
|
+
return { kind: "none" };
|
|
46685
|
+
}
|
|
46686
|
+
if (envelope.error === "CLAIM_CLI_ACCOUNT_SCOPE_FORBIDDEN" || envelope.data?.approved_scope !== void 0 && envelope.data.approved_scope !== "project") {
|
|
46687
|
+
return {
|
|
46688
|
+
kind: "manual",
|
|
46689
|
+
message: `This claim approval cannot be used to sign in. Run \`${cliInvocation()} login\` and ask the account owner to approve it.`
|
|
46690
|
+
};
|
|
46691
|
+
}
|
|
46692
|
+
if (!response.ok || !envelope.ok || !envelope.data) {
|
|
46693
|
+
if (["CLAIM_CLI_HANDOFF_PENDING", "CLAIM_CLI_HANDOFF_IN_PROGRESS"].includes(envelope.error || "")) {
|
|
46694
|
+
return { kind: "none" };
|
|
46695
|
+
}
|
|
46696
|
+
if (envelope.error === "CLAIM_CLI_HANDOFF_EXPIRED" && temporaryConfigExpired(config2)) {
|
|
46697
|
+
dropExpiredHandoff(config2.token, state);
|
|
46698
|
+
return {
|
|
46699
|
+
kind: "stale",
|
|
46700
|
+
message: `The temporary workspace on this machine expired at ${config2.temp_expires_at}. If you claimed it in the browser, \`${cliInvocation()} login\` signs in to it.`
|
|
46701
|
+
};
|
|
46702
|
+
}
|
|
46703
|
+
if (["CLAIM_CLI_HANDOFF_DENIED", "CLAIM_CLI_HANDOFF_EXPIRED", "CLAIM_CLI_HANDOFF_CONSUMED", "CLAIM_CLI_HANDOFF_OWNERSHIP_MISMATCH"].includes(envelope.error || "")) {
|
|
46704
|
+
return {
|
|
46705
|
+
kind: "manual",
|
|
46706
|
+
message: envelope.message || `Run \`${cliInvocation()} login\` in this directory. Keep the existing project link; do not unlink or redeploy.`
|
|
46707
|
+
};
|
|
46708
|
+
}
|
|
46709
|
+
return { kind: "none" };
|
|
46710
|
+
}
|
|
46711
|
+
const delivered = decodeCredentials(state, envelope.data);
|
|
46712
|
+
const current = loadConfig();
|
|
46713
|
+
if (!current?.temporary || current.token !== config2.token || current.claim_handoff?.project_id !== state.project_id || current.claim_handoff.verifier !== state.verifier || current.claim_handoff.handoff_id !== state.handoff_id) {
|
|
46714
|
+
return { kind: "none" };
|
|
46715
|
+
}
|
|
46716
|
+
const next = {
|
|
46717
|
+
token: delivered.token,
|
|
46718
|
+
...delivered.credential_kind === "project_agent" ? { claim_access: delivered.claim_access } : { refresh_token: delivered.refresh_token, access_expires_at: delivered.expires_at },
|
|
46719
|
+
user: { email: delivered.email, username: "" },
|
|
46720
|
+
claim_handoff_ack: { handoff_id: state.handoff_id, verifier: state.verifier }
|
|
46721
|
+
};
|
|
46722
|
+
saveConfig(next);
|
|
46723
|
+
if (await acknowledge(state.handoff_id, state.verifier)) {
|
|
46724
|
+
clearCurrentAcknowledgement(next.claim_handoff_ack);
|
|
46725
|
+
}
|
|
46726
|
+
return {
|
|
46727
|
+
kind: "recovered",
|
|
46728
|
+
message: delivered.claim_access === "new_projects" ? "Connected. You can work on the saved apps and create new apps in this account." : delivered.claim_access === "all_projects" ? "Connected. You can work on the apps already in this account and create new ones." : `Connected. You can work on the saved app. Run \`${cliInvocation()} login\` for account access.`
|
|
46729
|
+
};
|
|
46730
|
+
}
|
|
46731
|
+
var init_claim_handoff = __esm({
|
|
46732
|
+
"dist/lib/claim-handoff.js"() {
|
|
46733
|
+
"use strict";
|
|
46734
|
+
init_cli_invocation();
|
|
46735
|
+
init_config();
|
|
46736
|
+
init_device();
|
|
46737
|
+
init_device_login();
|
|
46738
|
+
init_client();
|
|
46739
|
+
init_http();
|
|
46740
|
+
__name(readClaimConnection, "readClaimConnection");
|
|
46741
|
+
__name(verifierHash, "verifierHash");
|
|
46742
|
+
__name(newVerifier, "newVerifier");
|
|
46743
|
+
__name(decodeCredentials, "decodeCredentials");
|
|
46744
|
+
__name(post, "post");
|
|
46745
|
+
__name(ensureClaimHandoff, "ensureClaimHandoff");
|
|
46746
|
+
__name(acknowledge, "acknowledge");
|
|
46747
|
+
__name(clearCurrentAcknowledgement, "clearCurrentAcknowledgement");
|
|
46748
|
+
__name(dropExpiredHandoff, "dropExpiredHandoff");
|
|
46749
|
+
__name(recoverClaimHandoff, "recoverClaimHandoff");
|
|
46750
|
+
}
|
|
46751
|
+
});
|
|
46752
|
+
|
|
46554
46753
|
// dist/lib/allowed-origins.js
|
|
46555
46754
|
function isExactOrigin(value) {
|
|
46556
46755
|
const trimmed = value.trim();
|
|
@@ -46825,6 +47024,30 @@ async function listProjects(opts = {}) {
|
|
|
46825
47024
|
const client = new ApiClient(getToken());
|
|
46826
47025
|
const spinner = opts.json ? null : ora("Fetching projects...").start();
|
|
46827
47026
|
try {
|
|
47027
|
+
if (loadConfig()?.claim_access) {
|
|
47028
|
+
const connection = await readClaimConnection(client);
|
|
47029
|
+
spinner?.stop();
|
|
47030
|
+
if (connection.state !== "claimed_connected") {
|
|
47031
|
+
throw new Error(`This app connection is closed. Run \`${cliInvocation()} login\` and ask the account owner to approve it.`);
|
|
47032
|
+
}
|
|
47033
|
+
if (opts.json)
|
|
47034
|
+
printJson(connection);
|
|
47035
|
+
else {
|
|
47036
|
+
const apps = connection.projects ?? [];
|
|
47037
|
+
if (apps.length)
|
|
47038
|
+
table(["App", "ID", "URL", "Deploy"], apps.map((app) => [
|
|
47039
|
+
app.name,
|
|
47040
|
+
app.project_id,
|
|
47041
|
+
app.url,
|
|
47042
|
+
app.can_deploy ? "Available" : app.reason === "private_configuration" ? "Paused for private configuration" : "Unavailable"
|
|
47043
|
+
]));
|
|
47044
|
+
else
|
|
47045
|
+
info("This connection has no apps yet.");
|
|
47046
|
+
if (connection.can_create_projects)
|
|
47047
|
+
info(`Create an app with \`${cliInvocation()} init --name <name>\`.`);
|
|
47048
|
+
}
|
|
47049
|
+
return;
|
|
47050
|
+
}
|
|
46828
47051
|
const result = await client.call("GET", "/projects");
|
|
46829
47052
|
spinner?.stop();
|
|
46830
47053
|
if (opts.json) {
|
|
@@ -46873,6 +47096,7 @@ var init_project = __esm({
|
|
|
46873
47096
|
init_spinner();
|
|
46874
47097
|
init_client();
|
|
46875
47098
|
init_config();
|
|
47099
|
+
init_claim_handoff();
|
|
46876
47100
|
init_output();
|
|
46877
47101
|
init_project_urls();
|
|
46878
47102
|
init_platform_command();
|
|
@@ -76028,11 +76252,11 @@ var init_typecheck2 = __esm({
|
|
|
76028
76252
|
});
|
|
76029
76253
|
|
|
76030
76254
|
// dist/lib/base-files.js
|
|
76031
|
-
import { createHash as
|
|
76255
|
+
import { createHash as createHash4 } from "node:crypto";
|
|
76032
76256
|
import { existsSync as existsSync17, mkdirSync as mkdirSync10, readFileSync as readFileSync18, rmSync as rmSync5, writeFileSync as writeFileSync13 } from "node:fs";
|
|
76033
76257
|
import { join as join20 } from "node:path";
|
|
76034
76258
|
function sha2562(content) {
|
|
76035
|
-
return
|
|
76259
|
+
return createHash4("sha256").update(content).digest("hex");
|
|
76036
76260
|
}
|
|
76037
76261
|
function hashFiles(dir, paths) {
|
|
76038
76262
|
const out = {};
|
|
@@ -76308,7 +76532,7 @@ var init_build_errors = __esm({
|
|
|
76308
76532
|
});
|
|
76309
76533
|
|
|
76310
76534
|
// dist/lib/temp-auth.js
|
|
76311
|
-
import { createHash as
|
|
76535
|
+
import { createHash as createHash5 } from "node:crypto";
|
|
76312
76536
|
function leadingZeroBits(buf) {
|
|
76313
76537
|
let bits = 0;
|
|
76314
76538
|
for (const byte of buf) {
|
|
@@ -76329,7 +76553,7 @@ function solvePow(nonce, difficulty) {
|
|
|
76329
76553
|
let i = 0;
|
|
76330
76554
|
for (; ; ) {
|
|
76331
76555
|
const suffix = (i++).toString(36);
|
|
76332
|
-
const hash2 =
|
|
76556
|
+
const hash2 = createHash5("sha256").update(`${nonce}:${suffix}`, "utf8").digest();
|
|
76333
76557
|
if (leadingZeroBits(hash2) >= difficulty) {
|
|
76334
76558
|
return { suffix, hash: hash2.toString("hex") };
|
|
76335
76559
|
}
|
|
@@ -76374,194 +76598,6 @@ var init_temp_auth = __esm({
|
|
|
76374
76598
|
}
|
|
76375
76599
|
});
|
|
76376
76600
|
|
|
76377
|
-
// dist/lib/claim-handoff.js
|
|
76378
|
-
import { createDecipheriv, createHash as createHash5, randomBytes as randomBytes2 } from "node:crypto";
|
|
76379
|
-
function verifierHash(verifier) {
|
|
76380
|
-
return createHash5("sha256").update(verifier, "utf8").digest("hex");
|
|
76381
|
-
}
|
|
76382
|
-
function newVerifier() {
|
|
76383
|
-
return randomBytes2(32).toString("base64url");
|
|
76384
|
-
}
|
|
76385
|
-
function decodeCredentials(state, response) {
|
|
76386
|
-
if (!state.handoff_id || response.project_id !== state.project_id) {
|
|
76387
|
-
throw new Error("Claim continuation returned a different project. No credential was installed.");
|
|
76388
|
-
}
|
|
76389
|
-
const key = createHash5("sha256").update(`claim-cli-handoff:v1:${state.verifier}`, "utf8").digest();
|
|
76390
|
-
const combined = Buffer.from(response.ciphertext, "base64");
|
|
76391
|
-
if (combined.length <= 16)
|
|
76392
|
-
throw new Error("Claim continuation returned an invalid credential payload.");
|
|
76393
|
-
const encrypted = combined.subarray(0, -16);
|
|
76394
|
-
const tag = combined.subarray(-16);
|
|
76395
|
-
const decipher = createDecipheriv("aes-256-gcm", key, Buffer.from(response.iv, "base64"));
|
|
76396
|
-
decipher.setAAD(Buffer.from(`${state.handoff_id}:${state.project_id}`, "utf8"));
|
|
76397
|
-
decipher.setAuthTag(tag);
|
|
76398
|
-
const plaintext = Buffer.concat([decipher.update(encrypted), decipher.final()]).toString("utf8");
|
|
76399
|
-
const parsed = JSON.parse(plaintext);
|
|
76400
|
-
if (typeof parsed.token !== "string" || typeof parsed.refresh_token !== "string" || typeof parsed.expires_at !== "string" || typeof parsed.email !== "string" || parsed.project_id !== state.project_id || parsed.approved_scope !== void 0 && parsed.approved_scope !== "project" || parsed.scope?.projects?.length !== 1 || parsed.scope.projects[0] !== state.project_id) {
|
|
76401
|
-
throw new Error("Claim continuation credential did not match the approved project. Nothing was installed.");
|
|
76402
|
-
}
|
|
76403
|
-
return parsed;
|
|
76404
|
-
}
|
|
76405
|
-
async function post(path3, body, token) {
|
|
76406
|
-
const response = await fetchWithProxy(`${API_BASE_URL}${path3}`, {
|
|
76407
|
-
method: "POST",
|
|
76408
|
-
headers: {
|
|
76409
|
-
"Content-Type": "application/json",
|
|
76410
|
-
...token ? { Authorization: `Bearer ${token}` } : {}
|
|
76411
|
-
},
|
|
76412
|
-
body: JSON.stringify(body),
|
|
76413
|
-
signal: AbortSignal.timeout(15e3)
|
|
76414
|
-
}, 15e3);
|
|
76415
|
-
const envelope = await response.json();
|
|
76416
|
-
return { response, envelope };
|
|
76417
|
-
}
|
|
76418
|
-
async function ensureClaimHandoff(projectId) {
|
|
76419
|
-
const config2 = loadConfig();
|
|
76420
|
-
if (!config2?.temporary || !config2.token)
|
|
76421
|
-
return null;
|
|
76422
|
-
let state = config2.claim_handoff;
|
|
76423
|
-
if (!state || state.project_id !== projectId) {
|
|
76424
|
-
state = { project_id: projectId, verifier: newVerifier() };
|
|
76425
|
-
saveConfig({ ...config2, claim_handoff: state });
|
|
76426
|
-
}
|
|
76427
|
-
if (state.handoff_id)
|
|
76428
|
-
return state;
|
|
76429
|
-
const { response, envelope } = await post("/auth/temp-handoff/register", {
|
|
76430
|
-
project_id: projectId,
|
|
76431
|
-
verifier_hash: verifierHash(state.verifier),
|
|
76432
|
-
device_name: getDeviceKeyName(),
|
|
76433
|
-
client: describeThisDevice()
|
|
76434
|
-
}, config2.token);
|
|
76435
|
-
if (!response.ok || !envelope.ok || !envelope.data) {
|
|
76436
|
-
throw new Error(envelope.message || envelope.error || `CLI continuation registration failed (HTTP ${response.status}).`);
|
|
76437
|
-
}
|
|
76438
|
-
const registered = { ...state, handoff_id: envelope.data.handoff_id, expires_at: envelope.data.expires_at };
|
|
76439
|
-
const current = loadConfig();
|
|
76440
|
-
if (!current?.temporary || current.claim_handoff?.verifier !== state.verifier)
|
|
76441
|
-
return null;
|
|
76442
|
-
saveConfig({ ...current, claim_handoff: registered });
|
|
76443
|
-
return registered;
|
|
76444
|
-
}
|
|
76445
|
-
async function acknowledge(handoffId, verifier) {
|
|
76446
|
-
try {
|
|
76447
|
-
const { response, envelope } = await post("/auth/temp-handoff/ack", {
|
|
76448
|
-
handoff_id: handoffId,
|
|
76449
|
-
verifier
|
|
76450
|
-
});
|
|
76451
|
-
return response.ok && envelope.ok && envelope.data?.acknowledged === true;
|
|
76452
|
-
} catch {
|
|
76453
|
-
return false;
|
|
76454
|
-
}
|
|
76455
|
-
}
|
|
76456
|
-
function clearCurrentAcknowledgement(expected) {
|
|
76457
|
-
const current = loadConfig();
|
|
76458
|
-
if (!current)
|
|
76459
|
-
return null;
|
|
76460
|
-
if (current.claim_handoff_ack?.handoff_id !== expected.handoff_id || current.claim_handoff_ack.verifier !== expected.verifier)
|
|
76461
|
-
return current;
|
|
76462
|
-
const { claim_handoff_ack: _removed, ...clean } = current;
|
|
76463
|
-
saveConfig(clean);
|
|
76464
|
-
return clean;
|
|
76465
|
-
}
|
|
76466
|
-
function dropExpiredHandoff(token, state) {
|
|
76467
|
-
const current = loadConfig();
|
|
76468
|
-
if (!current?.temporary || current.token !== token || current.claim_handoff?.handoff_id !== state.handoff_id || current.claim_handoff?.verifier !== state.verifier)
|
|
76469
|
-
return;
|
|
76470
|
-
const { claim_handoff: _expired, ...rest } = current;
|
|
76471
|
-
saveConfig(rest);
|
|
76472
|
-
}
|
|
76473
|
-
async function recoverClaimHandoff() {
|
|
76474
|
-
let config2 = loadConfig();
|
|
76475
|
-
if (!config2)
|
|
76476
|
-
return { kind: "none" };
|
|
76477
|
-
if (config2.claim_handoff_ack) {
|
|
76478
|
-
const ack = config2.claim_handoff_ack;
|
|
76479
|
-
if (await acknowledge(ack.handoff_id, ack.verifier)) {
|
|
76480
|
-
config2 = clearCurrentAcknowledgement(ack);
|
|
76481
|
-
if (!config2)
|
|
76482
|
-
return { kind: "none" };
|
|
76483
|
-
}
|
|
76484
|
-
}
|
|
76485
|
-
const state = config2.temporary ? config2.claim_handoff : void 0;
|
|
76486
|
-
if (!state?.handoff_id)
|
|
76487
|
-
return { kind: "none" };
|
|
76488
|
-
let response;
|
|
76489
|
-
let envelope;
|
|
76490
|
-
try {
|
|
76491
|
-
({ response, envelope } = await post("/auth/temp-handoff/exchange", {
|
|
76492
|
-
handoff_id: state.handoff_id,
|
|
76493
|
-
verifier: state.verifier
|
|
76494
|
-
}));
|
|
76495
|
-
} catch {
|
|
76496
|
-
return { kind: "none" };
|
|
76497
|
-
}
|
|
76498
|
-
if (envelope.error === "CLAIM_CLI_ACCOUNT_SCOPE_FORBIDDEN" || envelope.data?.approved_scope !== void 0 && envelope.data.approved_scope !== "project") {
|
|
76499
|
-
return {
|
|
76500
|
-
kind: "manual",
|
|
76501
|
-
message: `A claim link connects this CLI only to the claimed project. Run \`${cliInvocation()} login\` for account access.`
|
|
76502
|
-
};
|
|
76503
|
-
}
|
|
76504
|
-
if (!response.ok || !envelope.ok || !envelope.data) {
|
|
76505
|
-
if (["CLAIM_CLI_HANDOFF_PENDING", "CLAIM_CLI_HANDOFF_IN_PROGRESS"].includes(envelope.error || "")) {
|
|
76506
|
-
return { kind: "none" };
|
|
76507
|
-
}
|
|
76508
|
-
if (envelope.error === "CLAIM_CLI_HANDOFF_EXPIRED" && temporaryConfigExpired(config2)) {
|
|
76509
|
-
dropExpiredHandoff(config2.token, state);
|
|
76510
|
-
return {
|
|
76511
|
-
kind: "stale",
|
|
76512
|
-
message: `The temporary workspace on this machine expired at ${config2.temp_expires_at}. If you claimed it in the browser, \`${cliInvocation()} login\` signs in to it.`
|
|
76513
|
-
};
|
|
76514
|
-
}
|
|
76515
|
-
if (["CLAIM_CLI_HANDOFF_DENIED", "CLAIM_CLI_HANDOFF_EXPIRED", "CLAIM_CLI_HANDOFF_CONSUMED", "CLAIM_CLI_HANDOFF_OWNERSHIP_MISMATCH"].includes(envelope.error || "")) {
|
|
76516
|
-
return {
|
|
76517
|
-
kind: "manual",
|
|
76518
|
-
message: envelope.message || `Run \`${cliInvocation()} login\` in this directory. Keep the existing project link; do not unlink or redeploy.`
|
|
76519
|
-
};
|
|
76520
|
-
}
|
|
76521
|
-
return { kind: "none" };
|
|
76522
|
-
}
|
|
76523
|
-
const delivered = decodeCredentials(state, envelope.data);
|
|
76524
|
-
const current = loadConfig();
|
|
76525
|
-
if (!current?.temporary || current.token !== config2.token || current.claim_handoff?.project_id !== state.project_id || current.claim_handoff.verifier !== state.verifier || current.claim_handoff.handoff_id !== state.handoff_id) {
|
|
76526
|
-
return { kind: "none" };
|
|
76527
|
-
}
|
|
76528
|
-
const next = {
|
|
76529
|
-
token: delivered.token,
|
|
76530
|
-
refresh_token: delivered.refresh_token,
|
|
76531
|
-
access_expires_at: delivered.expires_at,
|
|
76532
|
-
user: { email: delivered.email, username: "" },
|
|
76533
|
-
claim_handoff_ack: { handoff_id: state.handoff_id, verifier: state.verifier }
|
|
76534
|
-
};
|
|
76535
|
-
saveConfig(next);
|
|
76536
|
-
if (await acknowledge(state.handoff_id, state.verifier)) {
|
|
76537
|
-
clearCurrentAcknowledgement(next.claim_handoff_ack);
|
|
76538
|
-
}
|
|
76539
|
-
return {
|
|
76540
|
-
kind: "recovered",
|
|
76541
|
-
message: `Connected to ${delivered.email} for this project only. The existing project link was kept. Run \`${cliInvocation()} login\` for account access.`
|
|
76542
|
-
};
|
|
76543
|
-
}
|
|
76544
|
-
var init_claim_handoff = __esm({
|
|
76545
|
-
"dist/lib/claim-handoff.js"() {
|
|
76546
|
-
"use strict";
|
|
76547
|
-
init_cli_invocation();
|
|
76548
|
-
init_config();
|
|
76549
|
-
init_device();
|
|
76550
|
-
init_device_login();
|
|
76551
|
-
init_client();
|
|
76552
|
-
init_http();
|
|
76553
|
-
__name(verifierHash, "verifierHash");
|
|
76554
|
-
__name(newVerifier, "newVerifier");
|
|
76555
|
-
__name(decodeCredentials, "decodeCredentials");
|
|
76556
|
-
__name(post, "post");
|
|
76557
|
-
__name(ensureClaimHandoff, "ensureClaimHandoff");
|
|
76558
|
-
__name(acknowledge, "acknowledge");
|
|
76559
|
-
__name(clearCurrentAcknowledgement, "clearCurrentAcknowledgement");
|
|
76560
|
-
__name(dropExpiredHandoff, "dropExpiredHandoff");
|
|
76561
|
-
__name(recoverClaimHandoff, "recoverClaimHandoff");
|
|
76562
|
-
}
|
|
76563
|
-
});
|
|
76564
|
-
|
|
76565
76601
|
// dist/lib/project-notices.js
|
|
76566
76602
|
import { existsSync as existsSync19, mkdirSync as mkdirSync11, readFileSync as readFileSync20, writeFileSync as writeFileSync14 } from "node:fs";
|
|
76567
76603
|
import { dirname as dirname8, join as join22 } from "node:path";
|
|
@@ -82478,7 +82514,7 @@ Existing project: \`${cliInvocation()} init --link --project <ref>\` (see \`${cl
|
|
|
82478
82514
|
} else if (linkedProjectEntry && projectConfigMatchesRef(linkedProjectEntry.config, projectId)) {
|
|
82479
82515
|
deployStateEntry = linkedProjectEntry;
|
|
82480
82516
|
}
|
|
82481
|
-
const stopPrestart = projectId && !tempSession && !opts.dryRun ? startDeployPrestart(client, projectId) : () => void 0;
|
|
82517
|
+
const stopPrestart = projectId && !tempSession && !opts.dryRun && !storedConfig?.claim_access ? startDeployPrestart(client, projectId) : () => void 0;
|
|
82482
82518
|
let explicitProjectId = null;
|
|
82483
82519
|
const earlyLiveBase = opts.project && projectId && !tempSession && !opts.force && CANONICAL_PROJECT_ID.test(projectId) && !readSourceBase(targetProjectConfig, projectId) ? { projectId, read: readExplicitProjectLiveBase(client, projectId) } : null;
|
|
82484
82520
|
if (opts.project && projectId && !tempSession) {
|
|
@@ -82937,11 +82973,11 @@ ${dim("Build")}`);
|
|
|
82937
82973
|
info(formatTempExpiry(tempSession.expiresAt, tempSession.ttlSeconds));
|
|
82938
82974
|
const link = teal(tempSession.claimUrl);
|
|
82939
82975
|
if (tempSession.handoffReady) {
|
|
82940
|
-
info(`Open ${link} and select "Save and connect agent" to
|
|
82976
|
+
info(`Open ${link} and select "Save and connect agent" to work on the saved apps and create new ones. You can choose to include your other apps.`);
|
|
82941
82977
|
} else if (besideRealLogin) {
|
|
82942
|
-
info(`Open ${link} to save the
|
|
82978
|
+
info(`Open ${link} to save the app to your account, then run \`${cliInvocation()} init --link --project ${projectId}\` in an unlinked folder to work on it.`);
|
|
82943
82979
|
} else {
|
|
82944
|
-
info(`Open ${link} to save the
|
|
82980
|
+
info(`Open ${link} to save the app to your account, then run \`${cliInvocation()} login\` to connect this terminal.`);
|
|
82945
82981
|
}
|
|
82946
82982
|
}
|
|
82947
82983
|
if (hasFunctionErrors) {
|
|
@@ -87144,6 +87180,7 @@ function registerStatus(program2) {
|
|
|
87144
87180
|
program2.command("status [project]").description("Show project and workspace status").option("--project <ref>", "Project ID, name, slug, or subdomain \u2014 the same flag every other command takes. The positional form still works.").option("--json", "Print the raw status responses as JSON").action(async (projectArg, opts) => {
|
|
87145
87181
|
const token = getToken();
|
|
87146
87182
|
const client = new ApiClient(token);
|
|
87183
|
+
const claimConnection = Boolean(loadConfig()?.claim_access);
|
|
87147
87184
|
const chosen = chooseProjectRef(projectArg, opts.project);
|
|
87148
87185
|
if (chosen.kind === "conflict") {
|
|
87149
87186
|
error(projectRefConflictMessage(chosen));
|
|
@@ -87167,7 +87204,7 @@ function registerStatus(program2) {
|
|
|
87167
87204
|
try {
|
|
87168
87205
|
const p2 = await client.call("GET", `/projects/${encodeURIComponent(projectId)}`);
|
|
87169
87206
|
projectStatus = p2;
|
|
87170
|
-
const servingUrl = await getProjectServingUrl(client, projectId).catch(() => fallbackProjectServingUrl(p2));
|
|
87207
|
+
const servingUrl = claimConnection ? fallbackProjectServingUrl(p2) : await getProjectServingUrl(client, projectId).catch(() => fallbackProjectServingUrl(p2));
|
|
87171
87208
|
if (!opts.json) {
|
|
87172
87209
|
console.log(`
|
|
87173
87210
|
Project: ${teal(p2.name)} (${statusDot(p2.status)})`);
|
|
@@ -87184,7 +87221,7 @@ function registerStatus(program2) {
|
|
|
87184
87221
|
process.exitCode = 1;
|
|
87185
87222
|
}
|
|
87186
87223
|
try {
|
|
87187
|
-
const deployment = unwrapPlatformData(await callPlatformTool("deploy_status", { project_id: projectId }, { allTools: true }));
|
|
87224
|
+
const deployment = claimConnection ? await client.call("GET", "/deploy/status", void 0, { project_id: projectId }) : unwrapPlatformData(await callPlatformTool("deploy_status", { project_id: projectId }, { allTools: true }));
|
|
87188
87225
|
if (!isRecord(deployment))
|
|
87189
87226
|
throw new Error("deploy_status returned an unexpected response.");
|
|
87190
87227
|
deploymentStatus = deployment;
|
|
@@ -87234,24 +87271,25 @@ function registerStatus(program2) {
|
|
|
87234
87271
|
process.exitCode = 1;
|
|
87235
87272
|
}
|
|
87236
87273
|
}
|
|
87237
|
-
|
|
87238
|
-
|
|
87239
|
-
|
|
87240
|
-
|
|
87241
|
-
|
|
87242
|
-
|
|
87243
|
-
|
|
87244
|
-
|
|
87245
|
-
|
|
87274
|
+
if (!claimConnection)
|
|
87275
|
+
try {
|
|
87276
|
+
const ws2 = await client.call("GET", "/hosted/status");
|
|
87277
|
+
workspaceStatus = ws2;
|
|
87278
|
+
if (!opts.json) {
|
|
87279
|
+
console.log("");
|
|
87280
|
+
const wsStatus = ws2.status === "ready" ? "running" : `${ws2.status} (starting)`;
|
|
87281
|
+
info(`Dev workspace: ${wsStatus} ${dim("\u2014 optional code workspace; your deployed app serves regardless")}`);
|
|
87282
|
+
if (ws2.terminal_url) {
|
|
87283
|
+
info(`Terminal: ${dim(ws2.terminal_url)}`);
|
|
87284
|
+
}
|
|
87246
87285
|
}
|
|
87286
|
+
} catch {
|
|
87247
87287
|
}
|
|
87248
|
-
} catch {
|
|
87249
|
-
}
|
|
87250
87288
|
if (opts.json) {
|
|
87251
87289
|
let appUrl = null;
|
|
87252
87290
|
let appUrlError = null;
|
|
87253
87291
|
try {
|
|
87254
|
-
appUrl = await getAuthoritativeAppUrl(client, projectId);
|
|
87292
|
+
appUrl = claimConnection ? projectStatus && fallbackProjectServingUrl(projectStatus) : await getAuthoritativeAppUrl(client, projectId);
|
|
87255
87293
|
if (!appUrl)
|
|
87256
87294
|
appUrlError = { code: "APP_URL_NOT_REPORTED", message: "The platform reported no https app URL for this project. Deploy it, then run this again." };
|
|
87257
87295
|
} catch (err) {
|
|
@@ -87358,10 +87396,10 @@ var init_open2 = __esm({
|
|
|
87358
87396
|
|
|
87359
87397
|
// dist/commands/claim.js
|
|
87360
87398
|
function registerClaim(program2) {
|
|
87361
|
-
program2.command("claim").description("Print the claim URL
|
|
87399
|
+
program2.command("claim").description("Print the claim URL for this computer's temporary apps").option("--json", "Print { claim_url, expires_at } as JSON").action((opts) => {
|
|
87362
87400
|
const config2 = loadConfig();
|
|
87363
87401
|
if (!config2?.temporary || !config2.claim_url) {
|
|
87364
|
-
const message3 = config2?.token ? `This terminal has no temporary workspace to claim. Run \`${cliInvocation()} projects\` to see the
|
|
87402
|
+
const message3 = config2?.token ? `This terminal has no temporary workspace to claim. Run \`${cliInvocation()} projects\` to see the apps it can access.` : `This terminal has no temporary workspace. If you deployed signed out from another terminal, run \`${cliInvocation()} claim\` there. Run \`${cliInvocation()} deploy\` here to start one.`;
|
|
87365
87403
|
if (opts.json)
|
|
87366
87404
|
printJson({ ok: false, error: config2?.token ? "NOT_TEMPORARY" : "NO_TEMPORARY_WORKSPACE", message: message3 });
|
|
87367
87405
|
else
|
|
@@ -87376,17 +87414,18 @@ function registerClaim(program2) {
|
|
|
87376
87414
|
return;
|
|
87377
87415
|
}
|
|
87378
87416
|
if (expired) {
|
|
87379
|
-
error(`This computer's temporary workspace expired at ${config2.temp_expires_at}
|
|
87417
|
+
error(`This computer's temporary workspace expired at ${config2.temp_expires_at}. Unclaimed apps are gone. Run \`${cliInvocation()} deploy\` to start a new one.`);
|
|
87380
87418
|
process.exit(1);
|
|
87381
87419
|
}
|
|
87382
87420
|
info(`Claim URL: ${teal(config2.claim_url)}`);
|
|
87383
87421
|
if (config2.temp_expires_at)
|
|
87384
87422
|
info(`Expires at: ${config2.temp_expires_at} (UTC)`);
|
|
87385
|
-
info("Open it in a browser and sign in or create an account to keep these
|
|
87423
|
+
info("Open it in a browser and sign in or create an account to keep these apps.");
|
|
87386
87424
|
if (config2.claim_handoff?.handoff_id) {
|
|
87387
|
-
info('Choose "Save and connect agent" to
|
|
87425
|
+
info('Choose "Save and connect agent" to work on the saved apps and create new ones. You can choose to include your other apps.');
|
|
87426
|
+
} else {
|
|
87427
|
+
info(`Run \`${cliInvocation()} login\` to connect this terminal after saving.`);
|
|
87388
87428
|
}
|
|
87389
|
-
info(`Run \`${cliInvocation()} login\` for account access.`);
|
|
87390
87429
|
});
|
|
87391
87430
|
}
|
|
87392
87431
|
var init_claim = __esm({
|
|
@@ -132318,8 +132357,12 @@ Run ${cliInvocation()} <command> --help for full command details.`);
|
|
|
132318
132357
|
program2.enablePositionalOptions();
|
|
132319
132358
|
const skipRecovery = ["lint", "upgrade", "update", "login", "signup", "logout", "docs", "help", "--help", "-h", "--version", "-V"].includes(command);
|
|
132320
132359
|
const recovery = skipRecovery ? { kind: "none" } : await recoverClaimHandoff();
|
|
132321
|
-
if (recovery.kind === "recovered" && recovery.message
|
|
132322
|
-
|
|
132360
|
+
if (recovery.kind === "recovered" && recovery.message) {
|
|
132361
|
+
if (jsonOutputRequested || command === "file")
|
|
132362
|
+
console.error(recovery.message);
|
|
132363
|
+
else
|
|
132364
|
+
info(recovery.message);
|
|
132365
|
+
}
|
|
132323
132366
|
if (recovery.kind === "stale" && recovery.message) {
|
|
132324
132367
|
if (jsonOutputRequested || command === "file")
|
|
132325
132368
|
console.error(recovery.message);
|