@feltdb/feltkit 0.3.27 → 0.3.29
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/app.d.ts +50 -7
- package/dist/app.js +21 -0
- package/dist/app.js.map +1 -1
- package/dist/cli/deploy-appboundry.d.ts +55 -0
- package/dist/cli/deploy-appboundry.js +77 -1
- package/dist/cli/deploy-appboundry.js.map +1 -1
- package/dist/cli/main.js +229 -10
- package/dist/cli/main.js.map +1 -1
- package/dist/dashboard/assets/{index-Clsfddp8.js → index-UuZ63NA6.js} +9 -9
- package/dist/dashboard/index.html +1 -1
- package/dist/runtime/application-authority.d.ts +9 -1
- package/dist/runtime/application-authority.js +7 -1
- package/dist/runtime/application-authority.js.map +1 -1
- package/dist/runtime/contract.js +4 -0
- package/dist/runtime/contract.js.map +1 -1
- package/dist/runtime/credentials.d.ts +158 -2
- package/dist/runtime/credentials.js +322 -27
- package/dist/runtime/credentials.js.map +1 -1
- package/dist/runtime/integrations.d.ts +18 -2
- package/dist/runtime/integrations.js +59 -8
- package/dist/runtime/integrations.js.map +1 -1
- package/dist/runtime/oauth-credentials.d.ts +68 -0
- package/dist/runtime/oauth-credentials.js +467 -0
- package/dist/runtime/oauth-credentials.js.map +1 -0
- package/dist/runtime/readiness.js +22 -0
- package/dist/runtime/readiness.js.map +1 -1
- package/dist/runtime/runtime.d.ts +3 -0
- package/dist/runtime/runtime.js +19 -3
- package/dist/runtime/runtime.js.map +1 -1
- package/dist/runtime/services.d.ts +12 -0
- package/dist/runtime/services.js +28 -0
- package/dist/runtime/services.js.map +1 -1
- package/dist/server/admin.d.ts +3 -0
- package/dist/server/admin.js +151 -6
- package/dist/server/admin.js.map +1 -1
- package/dist/server/index.js +26 -0
- package/dist/server/index.js.map +1 -1
- package/docs/README.md +2 -2
- package/package.json +2 -2
- package/skills/.claude-plugin/marketplace.json +1 -1
- package/skills/.claude-plugin/plugin.json +1 -1
package/dist/cli/main.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* The `feltkit` command.
|
|
3
3
|
*/
|
|
4
4
|
import { spawn } from "node:child_process";
|
|
5
|
-
import { existsSync, mkdirSync, readdirSync, readFileSync, renameSync, rmSync, writeFileSync } from "node:fs";
|
|
5
|
+
import { chmodSync, existsSync, mkdirSync, readdirSync, readFileSync, renameSync, rmSync, writeFileSync } from "node:fs";
|
|
6
6
|
import { dirname, extname, join, relative, resolve } from "node:path";
|
|
7
7
|
import { createHash, randomUUID } from "node:crypto";
|
|
8
8
|
import { fileURLToPath } from "node:url";
|
|
@@ -97,6 +97,8 @@ ${c.bold("Commands")}
|
|
|
97
97
|
inspect Show what the application is, where its state lives, and what it's doing
|
|
98
98
|
deploy Deploy to AppBoundry, or build a verified deployment: one container, an app container + FeltDB, Vercel, Cloudflare, Fly.io
|
|
99
99
|
status What AppBoundry says about the last deployment from this project
|
|
100
|
+
releases The application's releases on AppBoundry: lineage, rollbacks, which one serves
|
|
101
|
+
rollback Run an earlier release again on AppBoundry (--to <deploymentId>); refused if its schema cannot read today's data
|
|
100
102
|
vercel <action> Set a Vercel project's environment from FeltDB's values, deploy, and sign you in
|
|
101
103
|
cloudflare <action> Set a Cloudflare Worker's secrets from FeltDB's values, deploy, and sign you in
|
|
102
104
|
fly <action> Create the Fly.io app (and volume), set its secrets, deploy, and sign you in
|
|
@@ -235,6 +237,10 @@ const COMMAND_HELP = {
|
|
|
235
237
|
" FELTKIT_CREDENTIAL_VAULT=1 and FELTKIT_CREDENTIAL_VAULT_KEY are set. FELTKIT_CREDENTIAL_<ID> always wins.\n" +
|
|
236
238
|
"feltkit credential status [credential-ref:<id>…] [--env development] [--json]\n" +
|
|
237
239
|
" Every credential reference, what uses it, whether it is set, where, and its version. Never a value.\n" +
|
|
240
|
+
"feltkit credential set <credential-ref:<id>> --oauth\n" +
|
|
241
|
+
" Import an OAuth 2.0 grant: the provider's token response (JSON: access_token, refresh_token, expires_in, scope) at the prompt or on stdin.\n" +
|
|
242
|
+
"feltkit credential connect <integration> [--env development]\n" +
|
|
243
|
+
" Connect an integration's OAuth 2.0 grant (credential.oauth2): prints the provider's authorization address; FeltKit stores and renews the grant.\n" +
|
|
238
244
|
"feltkit credential remove <credential-ref:<id>|provider> [--env development]\n" +
|
|
239
245
|
" Erases a stored value (the reference then reports \"revoked\").",
|
|
240
246
|
config: "feltkit config export [--env development] [--out <file>]\n" +
|
|
@@ -246,7 +252,11 @@ const COMMAND_HELP = {
|
|
|
246
252
|
" created: attach each listed one in the target and set its FELTKIT_CREDENTIAL_<ID>. Schedules are not imported\n" +
|
|
247
253
|
" (they run as their creator). Run it on the host, with the server stopped, for production. Exit code 1 on\n" +
|
|
248
254
|
" conflicts or failures.",
|
|
249
|
-
operator: "feltkit operator grant --id <id> --role <role>
|
|
255
|
+
operator: "feltkit operator signin [--grant <grant> | --id <id> --role <role>] [--url <server>] [--env production]\n" +
|
|
256
|
+
" Signs in to a running server as an operator. Production commands (inspect, readiness, session list|revoke,\n" +
|
|
257
|
+
" backup create, config set) then run online against it, authorized as that operator, with no stop.\n" +
|
|
258
|
+
"feltkit operator signout\n" +
|
|
259
|
+
"feltkit operator grant --id <id> --role <role>[,<role>] [--name <display name>] [--ttl <minutes>] [--env production] [--json]\n" +
|
|
250
260
|
" Signs a one-time grant with this environment's operator key (FELTKIT_OPERATOR_KEY from the environment or, for a\n" +
|
|
251
261
|
" deployment, .env.local; else .feltkit/<env>/operator-key). With a recorded deployment it prints a link that signs\n" +
|
|
252
262
|
" in with it; otherwise paste it into Studio. It becomes an operator session holding exactly these declared roles.",
|
|
@@ -266,14 +276,28 @@ const COMMAND_HELP = {
|
|
|
266
276
|
"feltkit platform session revoke <ref> | --principal <id>\n" +
|
|
267
277
|
" Profiles: inspect (feltkit.platform.read), develop (+ feltkit.platform.develop: propose and verify change sets),\n" +
|
|
268
278
|
" deploy:<project>/<environment> (+ apply change sets to that project and environment only), owner (everything).",
|
|
279
|
+
call: "feltkit call <module:function> [--input '<json>'] [--as <dev user>] [--env development]\n" +
|
|
280
|
+
" Runs one of the application's functions. In production, as the signed-in operator (`feltkit operator signin`),\n" +
|
|
281
|
+
" through the function's own access rule, recorded as activity. In development, as a dev user (--as).",
|
|
269
282
|
session: "feltkit session create --id <id> --role <role> [--type agent|user|service] [--label <text>] [--ttl <hours>] [--env development]\n" +
|
|
283
|
+
" In production: services and agents only, declared roles only, and --ttl is required (at most 90 days = 2160).\n" +
|
|
270
284
|
" --env production acts on what the deployment uses: for a Vercel or other FeltDB-backed deployment, its FeltDB,\n" +
|
|
271
285
|
" with the settings in .env.local (refused when they are missing, never this machine's .feltkit/production).\n" +
|
|
272
286
|
"feltkit session list [--env development]\n" +
|
|
273
287
|
"feltkit session revoke <ref> [--env development]",
|
|
274
288
|
};
|
|
289
|
+
function adminHeaders(record, token) {
|
|
290
|
+
if ("operator" in record) {
|
|
291
|
+
const session = record.operator;
|
|
292
|
+
return {
|
|
293
|
+
authorization: `Bearer ${session.token}`, origin: new URL(record.url).origin, "x-feltkit-environment": session.environment,
|
|
294
|
+
"x-feltkit-csrf": createHash("sha256").update(`feltkit-csrf:${session.token}`).digest("base64url").slice(0, 32),
|
|
295
|
+
};
|
|
296
|
+
}
|
|
297
|
+
return { "x-feltkit-admin": token };
|
|
298
|
+
}
|
|
275
299
|
async function adminRequest(record, token, path, init = {}) {
|
|
276
|
-
const response = await fetch(`${record.url}/_feltkit/api${path}`, { ...init, headers: {
|
|
300
|
+
const response = await fetch(`${record.url}/_feltkit/api${path}`, { ...init, headers: { ...adminHeaders(record, token), "Content-Type": "application/json", ...(init.headers ?? {}) }, ...(init.method && init.method !== "GET" && init.body === undefined ? { body: "{}" } : {}) });
|
|
277
301
|
const body = (await response.json());
|
|
278
302
|
if (!response.ok)
|
|
279
303
|
throw new FeltKitError(body?.error?.code ?? "INTERNAL", body?.error?.message ?? `Admin API answered ${response.status}`);
|
|
@@ -281,7 +305,7 @@ async function adminRequest(record, token, path, init = {}) {
|
|
|
281
305
|
}
|
|
282
306
|
/** A running server's backup (POST /backup, NDJSON), passed line by line to `sink`. Returns its header. */
|
|
283
307
|
async function adminBackup(record, token, sink) {
|
|
284
|
-
const response = await fetch(`${record.url}/_feltkit/api/backup`, { method: "POST", headers: {
|
|
308
|
+
const response = await fetch(`${record.url}/_feltkit/api/backup`, { method: "POST", headers: { ...adminHeaders(record, token), "Content-Type": "application/json" }, body: "{}" });
|
|
285
309
|
if (!response.ok || !response.body) {
|
|
286
310
|
const body = (await response.json().catch(() => null));
|
|
287
311
|
throw new FeltKitError(body?.error?.code ?? "INTERNAL", body?.error?.message ?? `Admin API answered ${response.status}`);
|
|
@@ -307,10 +331,15 @@ async function adminBackup(record, token, sink) {
|
|
|
307
331
|
async function withEnvironment(projectDir, envName, remote, local) {
|
|
308
332
|
const runtimeDir = join(projectDir, ".feltkit", envName);
|
|
309
333
|
const record = readRuntimeRecord(runtimeDir);
|
|
334
|
+
// An operator signed in to a running production server (`feltkit operator signin`): online, as that operator.
|
|
335
|
+
const session = envName === "production" ? readOperatorSession(projectDir) : null;
|
|
336
|
+
if (session) {
|
|
337
|
+
return { value: await remote({ url: session.url, operator: { token: session.token, environment: session.environment } }, ""), source: `running server (${session.url}), as operator ${session.operator}` };
|
|
338
|
+
}
|
|
310
339
|
if (record) {
|
|
311
340
|
if (envName === "production") {
|
|
312
341
|
throw new FeltKitError("CONFIGURATION", `A production server is running (pid ${record.pid}). Its admin API answers verified operators only, not the admin token.`, {
|
|
313
|
-
hint: "Sign in
|
|
342
|
+
hint: "Sign in as an operator, online: `feltkit operator signin --id <you> --role <role> --url <server>`. Or stop the server to inspect its state directly.",
|
|
314
343
|
});
|
|
315
344
|
}
|
|
316
345
|
const token = readAdminToken(runtimeDir);
|
|
@@ -334,6 +363,23 @@ async function withEnvironment(projectDir, envName, remote, local) {
|
|
|
334
363
|
await runtime.close();
|
|
335
364
|
}
|
|
336
365
|
}
|
|
366
|
+
const operatorSessionPath = (projectDir) => join(projectDir, ".feltkit", "production", "operator-session.json");
|
|
367
|
+
function readOperatorSession(projectDir) {
|
|
368
|
+
const path = operatorSessionPath(projectDir);
|
|
369
|
+
if (!existsSync(path))
|
|
370
|
+
return null;
|
|
371
|
+
const session = JSON.parse(readFileSync(path, "utf8"));
|
|
372
|
+
if (session.expiresAt && Date.parse(session.expiresAt) <= Date.now()) {
|
|
373
|
+
rmSync(path, { force: true });
|
|
374
|
+
return null;
|
|
375
|
+
}
|
|
376
|
+
return session;
|
|
377
|
+
}
|
|
378
|
+
function writeOperatorSession(projectDir, session) {
|
|
379
|
+
mkdirSync(join(projectDir, ".feltkit", "production"), { recursive: true });
|
|
380
|
+
writeFileSync(operatorSessionPath(projectDir), JSON.stringify(session, null, 2) + "\n", { mode: 0o600 });
|
|
381
|
+
chmodSync(operatorSessionPath(projectDir), 0o600);
|
|
382
|
+
}
|
|
337
383
|
function waitForShutdown(close) {
|
|
338
384
|
return new Promise((done) => {
|
|
339
385
|
let closing = false;
|
|
@@ -826,9 +872,15 @@ export async function main(argv = process.argv.slice(2), deps = {}) {
|
|
|
826
872
|
let source;
|
|
827
873
|
const file = fileSink(partial);
|
|
828
874
|
try {
|
|
829
|
-
|
|
875
|
+
const session = envName === "production" ? readOperatorSession(projectDir) : null;
|
|
876
|
+
if (session) {
|
|
877
|
+
// Online, as the signed-in operator: the running server reads it with calls paused.
|
|
878
|
+
header = await adminBackup({ url: session.url, operator: { token: session.token, environment: session.environment } }, "", file.sink);
|
|
879
|
+
source = `running server (${session.url}; calls paused while it read), as operator ${session.operator}`;
|
|
880
|
+
}
|
|
881
|
+
else if (record) {
|
|
830
882
|
if (envName === "production")
|
|
831
|
-
throw new FeltKitError("CONFIGURATION", `A production server is running (pid ${record.pid}); its admin API answers verified operators only
|
|
883
|
+
throw new FeltKitError("CONFIGURATION", `A production server is running (pid ${record.pid}); its admin API answers verified operators only.`, { hint: "Sign in as an operator to back it up online: `feltkit operator signin --url <server>`. Or stop it to back up its state directly." });
|
|
832
884
|
const token = readAdminToken(runtimeDir);
|
|
833
885
|
if (!token)
|
|
834
886
|
throw new FeltKitError("CONFIGURATION", `A ${envName} server is running (pid ${record.pid}) but its admin token is missing.`);
|
|
@@ -975,11 +1027,57 @@ export async function main(argv = process.argv.slice(2), deps = {}) {
|
|
|
975
1027
|
line(` Evidence ${c.dim("none yet: AppBoundry reports Running only when the runtime itself names the module")}`);
|
|
976
1028
|
if (d.failure)
|
|
977
1029
|
line(` Failure ${d.failure.code}: ${d.failure.message}`);
|
|
978
|
-
|
|
1030
|
+
// Running is the runtime; reachable is the route, verified by AppBoundry over HTTPS. Never one for the other.
|
|
1031
|
+
const routing = d.routing;
|
|
1032
|
+
if (routing && routing.status !== "unavailable") {
|
|
1033
|
+
const failure = routing.failure ? `${routing.failure.category} failure: ${routing.failure.code}: ${routing.failure.message}` : "";
|
|
1034
|
+
const state = routing.status === "active" ? c.green(`active, verified over HTTPS${routing.verifiedAt ? ` at ${routing.verifiedAt}` : ""}`) : routing.status === "failed" ? c.red(failure || "failed") : `${routing.status}${routing.reason ? `: ${routing.reason}` : ""}`;
|
|
1035
|
+
line(` Routing ${routing.hostname ? `${routing.hostname} ` : ""}${state}`);
|
|
1036
|
+
}
|
|
1037
|
+
line(` Address ${d.address ?? c.dim(`none${routing?.status === "unavailable" && routing.reason ? `: ${routing.reason}` : routing?.status && routing.status !== "active" ? ": not verified reachable" : ""}`)}`);
|
|
979
1038
|
if (!s.verified && s.outcome === "pending")
|
|
980
1039
|
line(c.dim(" Pending: AppBoundry has not observed a ready runtime for this build yet."));
|
|
981
1040
|
return s.outcome === "failed" ? 1 : 0;
|
|
982
1041
|
}
|
|
1042
|
+
case "releases": {
|
|
1043
|
+
const { appboundryReleases } = await import("./deploy-appboundry.js");
|
|
1044
|
+
const r = await appboundryReleases({ projectDir, ...(flags.portal ? { connection: { portal: String(flags.portal) } } : {}) });
|
|
1045
|
+
if (json) {
|
|
1046
|
+
line(JSON.stringify({ ok: true, ...r }, null, 2));
|
|
1047
|
+
return 0;
|
|
1048
|
+
}
|
|
1049
|
+
line(`${c.bold(r.applicationId)} on AppBoundry ${c.dim(r.portal)}`);
|
|
1050
|
+
if (!r.releases.length) {
|
|
1051
|
+
line(c.dim(" No deployments yet."));
|
|
1052
|
+
return 0;
|
|
1053
|
+
}
|
|
1054
|
+
for (const rel of r.releases) {
|
|
1055
|
+
const mark = rel.serving ? c.green("● serving") : rel.state === "Failed" ? c.red(rel.state) : rel.state;
|
|
1056
|
+
line(` ${rel.deploymentId} ${mark} artifact ${rel.artifactId.slice(0, 12)}… ${c.dim(rel.requestedAt ?? "")}`);
|
|
1057
|
+
const lineage = [rel.rollbackOf ? `rollback of ${rel.rollbackOf}` : "", rel.previousDeploymentId ? `replaced ${rel.previousDeploymentId}` : "", rel.trust ? `trusted (${rel.trust})` : "", rel.requestedBy ? `by ${rel.requestedBy}` : ""].filter(Boolean).join(" · ");
|
|
1058
|
+
if (lineage)
|
|
1059
|
+
line(c.dim(` ${lineage}`));
|
|
1060
|
+
if (rel.failure)
|
|
1061
|
+
line(c.dim(` ${rel.failure}`));
|
|
1062
|
+
}
|
|
1063
|
+
return 0;
|
|
1064
|
+
}
|
|
1065
|
+
case "rollback": {
|
|
1066
|
+
const { appboundryRollback } = await import("./deploy-appboundry.js");
|
|
1067
|
+
const r = await appboundryRollback({ projectDir, ...(flags.to ? { to: String(flags.to) } : {}), ...(flags.portal ? { connection: { portal: String(flags.portal) } } : {}), ...(json ? {} : { onProgress: (d) => line(` ${c.dim("→")} ${d}`) }) });
|
|
1068
|
+
if (json) {
|
|
1069
|
+
line(JSON.stringify({ ok: r.outcome === "rolled-back", ...r }, null, 2));
|
|
1070
|
+
return r.outcome === "rolled-back" ? 0 : 1;
|
|
1071
|
+
}
|
|
1072
|
+
if (r.outcome === "rolled-back")
|
|
1073
|
+
line(`${symbols.ok} Rolled back: ${r.deployment.deploymentId} runs artifact ${r.deployment.artifactId.slice(0, 16)}… with the runtime's evidence`);
|
|
1074
|
+
else if (r.outcome === "pending")
|
|
1075
|
+
line(`${symbols.info} Requested ${r.deployment.deploymentId}; AppBoundry has not observed it running yet (feltkit status).`);
|
|
1076
|
+
else
|
|
1077
|
+
line(`${symbols.fail} Refused: ${r.deployment.failure ? `${r.deployment.failure.code}: ${r.deployment.failure.message}` : r.deployment.state}. Nothing was rolled back.`);
|
|
1078
|
+
line(` Serving ${r.serving ? `${r.serving.deploymentId} (artifact ${r.serving.artifactId.slice(0, 12)}…)` : c.dim("nothing AppBoundry has verified")}`);
|
|
1079
|
+
return r.outcome === "rolled-back" ? 0 : 1;
|
|
1080
|
+
}
|
|
983
1081
|
case "deploy": {
|
|
984
1082
|
// How it will run: --target, else asked in a terminal, else one container.
|
|
985
1083
|
let target = flags.target ? String(flags.target) : undefined;
|
|
@@ -1356,6 +1454,35 @@ export async function main(argv = process.argv.slice(2), deps = {}) {
|
|
|
1356
1454
|
line(COMMAND_HELP.session);
|
|
1357
1455
|
return 1;
|
|
1358
1456
|
}
|
|
1457
|
+
case "call": {
|
|
1458
|
+
const name = positional[0];
|
|
1459
|
+
if (!name || !/^[\w/-]+:[\w]+$/.test(name)) {
|
|
1460
|
+
line(COMMAND_HELP.call);
|
|
1461
|
+
return 1;
|
|
1462
|
+
}
|
|
1463
|
+
let args = {};
|
|
1464
|
+
if (flags.input !== undefined) {
|
|
1465
|
+
try {
|
|
1466
|
+
args = JSON.parse(String(flags.input));
|
|
1467
|
+
}
|
|
1468
|
+
catch {
|
|
1469
|
+
throw new FeltKitError("INVALID_ARGUMENT", "--input is JSON (an object of the function's arguments).");
|
|
1470
|
+
}
|
|
1471
|
+
}
|
|
1472
|
+
const { value, source } = await withEnvironment(projectDir, envName, (record, token) => "operator" in record
|
|
1473
|
+
? adminRequest(record, token, "/functions/call", { method: "POST", body: JSON.stringify({ name, args }) })
|
|
1474
|
+
: adminRequest(record, token, "/functions/run", { method: "POST", body: JSON.stringify({ name, args, as: flags.as }) }), async () => {
|
|
1475
|
+
throw new FeltKitError("FAILED_PRECONDITION", "`feltkit call` runs against the running server: start it (`feltkit dev`), or sign in to production (`feltkit operator signin`).");
|
|
1476
|
+
});
|
|
1477
|
+
const result = value;
|
|
1478
|
+
if (json)
|
|
1479
|
+
line(JSON.stringify(result, null, 2));
|
|
1480
|
+
else if (result.ok)
|
|
1481
|
+
line(`${symbols.ok} ${name} ${c.dim(`— ${source}`)}\n${JSON.stringify(result.value ?? null, null, 2)}`);
|
|
1482
|
+
else
|
|
1483
|
+
line(`${symbols.fail} ${name}: ${result.error?.code}: ${result.error?.message} ${c.dim(`— ${source}`)}`);
|
|
1484
|
+
return result.ok ? 0 : 1;
|
|
1485
|
+
}
|
|
1359
1486
|
case "readiness": {
|
|
1360
1487
|
const { value, source } = await withEnvironment(projectDir, envName, (record, token) => adminRequest(record, token, "/readiness"), (runtime) => assessReadiness(runtime, { projectDir, dashboard: process.env.FELTKIT_DASHBOARD === "1" }));
|
|
1361
1488
|
if (json)
|
|
@@ -1431,17 +1558,40 @@ export async function main(argv = process.argv.slice(2), deps = {}) {
|
|
|
1431
1558
|
if (looksLikeSecret(positional[1]))
|
|
1432
1559
|
throw new FeltKitError("INVALID_ARGUMENT", "That argument looks like an API key, not a reference. Nothing was stored. Run `feltkit credential set <provider>` and enter the key at the prompt or on stdin.");
|
|
1433
1560
|
const ref = toCredentialRef(positional[1]);
|
|
1434
|
-
const
|
|
1561
|
+
const oauth = flags.oauth === true || flags.oauth === "true";
|
|
1562
|
+
const value = await readSecret(oauth ? `OAuth 2.0 token response (JSON) for ${ref} (input hidden): ` : `Value for ${ref} (input hidden): `);
|
|
1435
1563
|
if (!value)
|
|
1436
1564
|
throw new FeltKitError("INVALID_ARGUMENT", "No value was entered; nothing was stored.");
|
|
1437
1565
|
const provider = ref.slice("credential-ref:".length);
|
|
1438
|
-
const
|
|
1566
|
+
const kind = oauth ? { kind: "oauth2" } : {};
|
|
1567
|
+
const { value: stored, source } = await withEnvironment(projectDir, envName, (record, token) => adminRequest(record, token, "/credentials", { method: "POST", body: JSON.stringify({ ref, value, provider, ...kind }) }).then((b) => b.stored), (runtime) => storeCredential(runtime, { ref, value, provider, ...kind }, HOST_CUSTODY, "cli"));
|
|
1439
1568
|
if (json)
|
|
1440
1569
|
line(JSON.stringify(stored, null, 2));
|
|
1441
1570
|
else
|
|
1442
1571
|
line(`${symbols.ok} ${envName}: ${stored.ref} set (${stored.location ?? "custody"}, version ${stored.version}) ${c.dim(`— ${source}`)}`);
|
|
1443
1572
|
return 0;
|
|
1444
1573
|
}
|
|
1574
|
+
if (action === "connect") {
|
|
1575
|
+
// An integration's OAuth 2.0 grant: the running server starts authorization code with PKCE and
|
|
1576
|
+
// receives the provider's callback; this prints the address to open. Nothing secret is shown.
|
|
1577
|
+
const name = positional[1];
|
|
1578
|
+
if (!name) {
|
|
1579
|
+
line(COMMAND_HELP.credential);
|
|
1580
|
+
return 1;
|
|
1581
|
+
}
|
|
1582
|
+
const { value, source } = await withEnvironment(projectDir, envName, (record, token) => adminRequest(record, token, `/integrations/${encodeURIComponent(name)}/connect`, { method: "POST", body: JSON.stringify({}) }), async () => {
|
|
1583
|
+
throw new FeltKitError("FAILED_PRECONDITION", "Connecting needs the running server (it receives the provider's callback). Start it with `feltkit dev` (or sign in as an operator for production), then run this again.");
|
|
1584
|
+
});
|
|
1585
|
+
const v = value;
|
|
1586
|
+
if (json)
|
|
1587
|
+
line(JSON.stringify(v, null, 2));
|
|
1588
|
+
else {
|
|
1589
|
+
line(`${symbols.ok} ${envName}: open this address and approve access ${c.dim(`— ${source}`)}`);
|
|
1590
|
+
line(` ${v.url}`);
|
|
1591
|
+
line(c.dim(` The provider returns to ${v.redirectUri} (register it with the provider). Valid until ${v.expiresAt}, once.`));
|
|
1592
|
+
}
|
|
1593
|
+
return 0;
|
|
1594
|
+
}
|
|
1445
1595
|
if (action === "remove") {
|
|
1446
1596
|
if (!positional[1]) {
|
|
1447
1597
|
line(COMMAND_HELP.credential);
|
|
@@ -1468,6 +1618,17 @@ export async function main(argv = process.argv.slice(2), deps = {}) {
|
|
|
1468
1618
|
for (const x of items) {
|
|
1469
1619
|
const mark = x.present ? symbols.ok : symbols.fail;
|
|
1470
1620
|
line(` ${mark} ${x.ref}: ${x.state}${x.present ? ` (${x.location}${x.version ? `, version ${x.version}` : ""})` : ""}${x.usedBy?.length ? c.dim(` — used by ${x.usedBy.join(", ")}`) : ""}`);
|
|
1621
|
+
if (x.kind === "oauth2") {
|
|
1622
|
+
const o = x.oauth;
|
|
1623
|
+
if (!o)
|
|
1624
|
+
line(` OAuth 2.0 grant: not connected`);
|
|
1625
|
+
else {
|
|
1626
|
+
const expiry = o.expiresAt ? `expires ${o.expiresAt}` : "expiry not stated by the provider";
|
|
1627
|
+
line(` OAuth 2.0 grant: ${o.state === "active" ? "active" : "RECONNECT REQUIRED"}; ${expiry}; ${o.renewable ? "renewable" : "not renewable"}; ${o.refreshes} renewal(s)${o.refreshedAt ? `, last ${o.refreshedAt}` : ""}; ${o.source}${o.scope ? `; scope ${o.scope}` : ""}`);
|
|
1628
|
+
if (o.failure)
|
|
1629
|
+
line(` last failure: ${o.failure.kind} at ${o.failure.at}: ${o.failure.message}${o.failure.retryAt ? ` (retry after ${o.failure.retryAt})` : ""}`);
|
|
1630
|
+
}
|
|
1631
|
+
}
|
|
1471
1632
|
}
|
|
1472
1633
|
}
|
|
1473
1634
|
return items.every((x) => x.present || !x.usedBy?.length) ? 0 : 1;
|
|
@@ -1477,6 +1638,19 @@ export async function main(argv = process.argv.slice(2), deps = {}) {
|
|
|
1477
1638
|
}
|
|
1478
1639
|
case "config": {
|
|
1479
1640
|
const action = positional[0];
|
|
1641
|
+
if (action === "set") {
|
|
1642
|
+
// One variable, on the running server, as the signed-in operator (AppPort Services authorizes and records it).
|
|
1643
|
+
const [name, value] = [positional[1], positional[2]];
|
|
1644
|
+
if (!name || value === undefined)
|
|
1645
|
+
throw new FeltKitError("INVALID_ARGUMENT", "Usage: feltkit config set <NAME> <value> --env production (after `feltkit operator signin`)");
|
|
1646
|
+
const { source } = await withEnvironment(projectDir, envName, (record, token) => {
|
|
1647
|
+
if (!("operator" in record))
|
|
1648
|
+
throw new FeltKitError("FAILED_PRECONDITION", "`config set` changes a running production server as a signed-in operator; in development use Studio → Services → Configuration.");
|
|
1649
|
+
return adminRequest(record, token, `/configuration/${encodeURIComponent(name)}`, { method: "PUT", body: JSON.stringify({ value }) });
|
|
1650
|
+
}, async () => { throw new FeltKitError("FAILED_PRECONDITION", "No signed-in operator session: run `feltkit operator signin` first, or `feltkit config import` with the server stopped."); });
|
|
1651
|
+
line(`${symbols.ok} ${name} set ${c.dim(`— ${source}`)}`);
|
|
1652
|
+
return 0;
|
|
1653
|
+
}
|
|
1480
1654
|
if (action === "export") {
|
|
1481
1655
|
const { value, source } = await withEnvironment(projectDir, envName, (record, token) => adminRequest(record, token, "/configuration/export"), (runtime) => runtime.services.exportConfiguration());
|
|
1482
1656
|
const text = `${JSON.stringify(value, null, 2)}\n`;
|
|
@@ -1525,6 +1699,51 @@ export async function main(argv = process.argv.slice(2), deps = {}) {
|
|
|
1525
1699
|
return 1;
|
|
1526
1700
|
}
|
|
1527
1701
|
case "operator": {
|
|
1702
|
+
if (positional[0] === "signout") {
|
|
1703
|
+
const session = readOperatorSession(projectDir);
|
|
1704
|
+
if (session) {
|
|
1705
|
+
await adminRequest({ url: session.url, operator: { token: session.token, environment: session.environment } }, "", "/operator/signout", { method: "POST" }).catch(() => undefined);
|
|
1706
|
+
rmSync(operatorSessionPath(projectDir), { force: true });
|
|
1707
|
+
}
|
|
1708
|
+
line(`${symbols.ok} Signed out${session ? ` of ${session.url}` : ""}.`);
|
|
1709
|
+
return 0;
|
|
1710
|
+
}
|
|
1711
|
+
if (positional[0] === "signin") {
|
|
1712
|
+
// A grant (from --grant, or signed here with the deployment's operator key) becomes an operator session on the
|
|
1713
|
+
// running server. The session token is kept in .feltkit/production/operator-session.json (mode 0600), never printed.
|
|
1714
|
+
const env = String(flags.env ?? "production");
|
|
1715
|
+
let grant = flags.grant ? String(flags.grant) : "";
|
|
1716
|
+
let url = flags.url ? String(flags.url).replace(/\/+$/, "") : "";
|
|
1717
|
+
if (!grant) {
|
|
1718
|
+
if (!flags.id || !flags.role) {
|
|
1719
|
+
line(COMMAND_HELP.operator);
|
|
1720
|
+
return 1;
|
|
1721
|
+
}
|
|
1722
|
+
const link = await studioLink(projectDir, { id: String(flags.id), roles: String(flags.role) });
|
|
1723
|
+
grant = link.grant;
|
|
1724
|
+
if (!url && link.url)
|
|
1725
|
+
url = new URL(link.url).origin;
|
|
1726
|
+
}
|
|
1727
|
+
if (!url)
|
|
1728
|
+
url = readRuntimeRecord(join(projectDir, ".feltkit", env))?.url ?? "";
|
|
1729
|
+
if (!url)
|
|
1730
|
+
throw new FeltKitError("INVALID_ARGUMENT", "No running server to sign in to: pass --url <server URL>.");
|
|
1731
|
+
const response = await fetch(`${url}/_feltkit/api/operator/signin`, { method: "POST", headers: { "content-type": "application/json", origin: new URL(url).origin, "x-feltkit-environment": env }, body: JSON.stringify({ grant }) });
|
|
1732
|
+
const body = (await response.json().catch(() => ({})));
|
|
1733
|
+
if (!response.ok)
|
|
1734
|
+
throw new FeltKitError(body?.error?.code ?? "UNAUTHORIZED", body?.error?.message ?? `Sign-in answered ${response.status}`, {
|
|
1735
|
+
hint: "A production server serves its operator API only when started with FELTKIT_DASHBOARD=1; the grant must be signed with that deployment's operator key and used within its lifetime.",
|
|
1736
|
+
});
|
|
1737
|
+
const cookie = /feltkit_operator[^=]*=([^;]+)/.exec(response.headers.get("set-cookie") ?? "")?.[1];
|
|
1738
|
+
if (!cookie)
|
|
1739
|
+
throw new FeltKitError("INTERNAL", "The server signed the operator in but returned no session.");
|
|
1740
|
+
writeOperatorSession(projectDir, { url, environment: env, token: decodeURIComponent(cookie), operator: String(body.operator?.id ?? ""), expiresAt: String(body.expiresAt ?? "") });
|
|
1741
|
+
if (json)
|
|
1742
|
+
line(JSON.stringify({ ok: true, url, operator: body.operator, permissions: body.permissions, expiresAt: body.expiresAt }, null, 2));
|
|
1743
|
+
else
|
|
1744
|
+
line(`${symbols.ok} Signed in to ${url} as operator ${c.bold(String(body.operator?.id ?? ""))} until ${body.expiresAt}. Production commands now run online, as this operator.`);
|
|
1745
|
+
return 0;
|
|
1746
|
+
}
|
|
1528
1747
|
if (positional[0] !== "grant" || !flags.id || !flags.role) {
|
|
1529
1748
|
line(COMMAND_HELP.operator);
|
|
1530
1749
|
return 1;
|