@feltdb/feltkit 0.3.26 → 0.3.28
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 +52 -2
- package/dist/app.js +29 -2
- package/dist/app.js.map +1 -1
- package/dist/appboundry/build.d.ts +5 -1
- package/dist/appboundry/build.js +16 -24
- package/dist/appboundry/build.js.map +1 -1
- package/dist/appboundry/guest-index.d.ts +1 -0
- package/dist/appboundry/guest-index.js +1 -0
- package/dist/appboundry/guest-index.js.map +1 -1
- package/dist/appboundry/guest-tenancy.d.ts +40 -0
- package/dist/appboundry/guest-tenancy.js +162 -0
- package/dist/appboundry/guest-tenancy.js.map +1 -0
- package/dist/appboundry/guest.js +22 -1
- package/dist/appboundry/guest.js.map +1 -1
- package/dist/appboundry/host.d.ts +24 -0
- package/dist/appboundry/host.js +157 -5
- package/dist/appboundry/host.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 +202 -15
- package/dist/cli/main.js.map +1 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/platform/server.js +5 -3
- package/dist/platform/server.js.map +1 -1
- package/dist/react/auth.js +3 -2
- package/dist/react/auth.js.map +1 -1
- package/dist/runtime/agent.d.ts +14 -0
- package/dist/runtime/agent.js +59 -9
- package/dist/runtime/agent.js.map +1 -1
- package/dist/runtime/content.d.ts +1 -0
- package/dist/runtime/context.d.ts +29 -0
- package/dist/runtime/credentials.d.ts +76 -0
- package/dist/runtime/credentials.js +87 -2
- package/dist/runtime/credentials.js.map +1 -1
- package/dist/runtime/data.d.ts +1 -24
- package/dist/runtime/data.js +4 -67
- package/dist/runtime/data.js.map +1 -1
- package/dist/runtime/integrations.d.ts +3 -0
- package/dist/runtime/integrations.js +31 -4
- package/dist/runtime/integrations.js.map +1 -1
- package/dist/runtime/job-context.d.ts +26 -0
- package/dist/runtime/job-context.js +24 -0
- package/dist/runtime/job-context.js.map +1 -0
- package/dist/runtime/oauth-credentials.d.ts +68 -0
- package/dist/runtime/oauth-credentials.js +496 -0
- package/dist/runtime/oauth-credentials.js.map +1 -0
- package/dist/runtime/paged-read.d.ts +35 -0
- package/dist/runtime/paged-read.js +69 -0
- package/dist/runtime/paged-read.js.map +1 -0
- package/dist/runtime/runtime.d.ts +3 -0
- package/dist/runtime/runtime.js +64 -12
- package/dist/runtime/runtime.js.map +1 -1
- package/dist/runtime/services.d.ts +14 -38
- package/dist/runtime/services.js +124 -17
- package/dist/runtime/services.js.map +1 -1
- package/dist/runtime/sha256.d.ts +1 -0
- package/dist/runtime/sha256.js +91 -0
- package/dist/runtime/sha256.js.map +1 -0
- package/dist/runtime/tenancy.d.ts +34 -1
- package/dist/runtime/tenancy.js +62 -11
- package/dist/runtime/tenancy.js.map +1 -1
- package/dist/runtime/transactions.d.ts +2 -0
- package/dist/runtime/transactions.js +2 -1
- package/dist/runtime/transactions.js.map +1 -1
- package/dist/server/admin.d.ts +3 -0
- package/dist/server/admin.js +129 -18
- package/dist/server/admin.js.map +1 -1
- package/dist/server/index.d.ts +7 -0
- package/dist/server/index.js +44 -14
- package/dist/server/index.js.map +1 -1
- package/dist/server/ports.d.ts +43 -0
- package/dist/server/ports.js +96 -0
- package/dist/server/ports.js.map +1 -0
- package/dist/server/project.d.ts +8 -1
- package/dist/server/project.js +6 -9
- package/dist/server/project.js.map +1 -1
- package/dist/server/tenancy.js +2 -1
- package/dist/server/tenancy.js.map +1 -1
- package/dist/testing/index.d.ts +36 -2
- package/dist/testing/index.js +17 -4
- package/dist/testing/index.js.map +1 -1
- package/dist/words.d.ts +9 -0
- package/dist/words.js +15 -0
- package/dist/words.js.map +1 -0
- package/docs/APPBOUNDRY.md +15 -6
- package/docs/AUTH.md +16 -3
- package/docs/GUARANTEES.md +23 -2
- package/docs/PATH-TO-PRODUCTION.md +1 -1
- package/docs/README.md +2 -2
- package/package.json +3 -3
- package/skills/.claude-plugin/marketplace.json +1 -1
- package/skills/.claude-plugin/plugin.json +1 -1
- package/skills/feltkit-services/SKILL.md +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";
|
|
@@ -26,6 +26,7 @@ import { overviewPayload } from "../server/admin.js";
|
|
|
26
26
|
import { BUILD_DIR, SDK_VERSION, artifactEnv, build, codegen, doctor, startDev, startProduction } from "../server/project.js";
|
|
27
27
|
import { scaffold, ScaffoldError } from "create-feltkit";
|
|
28
28
|
import { DEPLOY_TARGETS, deploy, lower } from "./deploy.js";
|
|
29
|
+
import { rejectAssignments, resolvePort } from "../server/ports.js";
|
|
29
30
|
import { createInterface } from "node:readline/promises";
|
|
30
31
|
import { createInterface as createLineReader } from "node:readline";
|
|
31
32
|
import { Readable } from "node:stream";
|
|
@@ -36,6 +37,12 @@ import { c, line, printInspect, symbols } from "./output.js";
|
|
|
36
37
|
import { PACKAGE_PAGE, SHIPPED_DOCS, docFile, docUrl } from "../docs.js";
|
|
37
38
|
/** Flags that may be given more than once; their values are joined with commas (`--role a --role b` = `a,b`). */
|
|
38
39
|
const REPEATABLE = new Set(["role", "manager", "public", "attach", "claim", "require", "param", "include", "exclude", "participant", "entity", "field", "ref", "owned", "unique", "workflow"]);
|
|
40
|
+
/** Where the port came from, when it is not what was asked for at face value (the default moved on). */
|
|
41
|
+
function portNote(request, bound) {
|
|
42
|
+
if (request.source === "default")
|
|
43
|
+
return bound === request.port ? "" : c.dim(` (port ${request.port} was in use)`);
|
|
44
|
+
return request.port === 0 ? c.dim(` (${request.source} 0: chosen by the system)`) : c.dim(` (${request.source})`);
|
|
45
|
+
}
|
|
39
46
|
export function parseArgs(argv) {
|
|
40
47
|
const positional = [];
|
|
41
48
|
const flags = {};
|
|
@@ -90,6 +97,8 @@ ${c.bold("Commands")}
|
|
|
90
97
|
inspect Show what the application is, where its state lives, and what it's doing
|
|
91
98
|
deploy Deploy to AppBoundry, or build a verified deployment: one container, an app container + FeltDB, Vercel, Cloudflare, Fly.io
|
|
92
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
|
|
93
102
|
vercel <action> Set a Vercel project's environment from FeltDB's values, deploy, and sign you in
|
|
94
103
|
cloudflare <action> Set a Cloudflare Worker's secrets from FeltDB's values, deploy, and sign you in
|
|
95
104
|
fly <action> Create the Fly.io app (and volume), set its secrets, deploy, and sign you in
|
|
@@ -113,7 +122,8 @@ ${c.bold("Commands")}
|
|
|
113
122
|
docs [<name>] List FeltKit's documentation (shipped in the package), or print one document
|
|
114
123
|
|
|
115
124
|
${c.bold("Options")}
|
|
116
|
-
--port <n> Port for dev/start (
|
|
125
|
+
--port <n> Port for dev/start: exactly this one, or fail (0: any free port). Without it,
|
|
126
|
+
FELTKIT_PORT, then PORT; else the first free port from 3000 (to 3099)
|
|
117
127
|
--host <h> Interface for dev/start (dev default 127.0.0.1)
|
|
118
128
|
--json Machine-readable output (inspect, session, doctor)
|
|
119
129
|
--help Show help for a command
|
|
@@ -227,6 +237,10 @@ const COMMAND_HELP = {
|
|
|
227
237
|
" FELTKIT_CREDENTIAL_VAULT=1 and FELTKIT_CREDENTIAL_VAULT_KEY are set. FELTKIT_CREDENTIAL_<ID> always wins.\n" +
|
|
228
238
|
"feltkit credential status [credential-ref:<id>…] [--env development] [--json]\n" +
|
|
229
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" +
|
|
230
244
|
"feltkit credential remove <credential-ref:<id>|provider> [--env development]\n" +
|
|
231
245
|
" Erases a stored value (the reference then reports \"revoked\").",
|
|
232
246
|
config: "feltkit config export [--env development] [--out <file>]\n" +
|
|
@@ -238,7 +252,11 @@ const COMMAND_HELP = {
|
|
|
238
252
|
" created: attach each listed one in the target and set its FELTKIT_CREDENTIAL_<ID>. Schedules are not imported\n" +
|
|
239
253
|
" (they run as their creator). Run it on the host, with the server stopped, for production. Exit code 1 on\n" +
|
|
240
254
|
" conflicts or failures.",
|
|
241
|
-
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" +
|
|
242
260
|
" Signs a one-time grant with this environment's operator key (FELTKIT_OPERATOR_KEY from the environment or, for a\n" +
|
|
243
261
|
" deployment, .env.local; else .feltkit/<env>/operator-key). With a recorded deployment it prints a link that signs\n" +
|
|
244
262
|
" in with it; otherwise paste it into Studio. It becomes an operator session holding exactly these declared roles.",
|
|
@@ -264,8 +282,18 @@ const COMMAND_HELP = {
|
|
|
264
282
|
"feltkit session list [--env development]\n" +
|
|
265
283
|
"feltkit session revoke <ref> [--env development]",
|
|
266
284
|
};
|
|
285
|
+
function adminHeaders(record, token) {
|
|
286
|
+
if ("operator" in record) {
|
|
287
|
+
const session = record.operator;
|
|
288
|
+
return {
|
|
289
|
+
authorization: `Bearer ${session.token}`, origin: new URL(record.url).origin, "x-feltkit-environment": session.environment,
|
|
290
|
+
"x-feltkit-csrf": createHash("sha256").update(`feltkit-csrf:${session.token}`).digest("base64url").slice(0, 32),
|
|
291
|
+
};
|
|
292
|
+
}
|
|
293
|
+
return { "x-feltkit-admin": token };
|
|
294
|
+
}
|
|
267
295
|
async function adminRequest(record, token, path, init = {}) {
|
|
268
|
-
const response = await fetch(`${record.url}/_feltkit/api${path}`, { ...init, headers: {
|
|
296
|
+
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: "{}" } : {}) });
|
|
269
297
|
const body = (await response.json());
|
|
270
298
|
if (!response.ok)
|
|
271
299
|
throw new FeltKitError(body?.error?.code ?? "INTERNAL", body?.error?.message ?? `Admin API answered ${response.status}`);
|
|
@@ -273,7 +301,7 @@ async function adminRequest(record, token, path, init = {}) {
|
|
|
273
301
|
}
|
|
274
302
|
/** A running server's backup (POST /backup, NDJSON), passed line by line to `sink`. Returns its header. */
|
|
275
303
|
async function adminBackup(record, token, sink) {
|
|
276
|
-
const response = await fetch(`${record.url}/_feltkit/api/backup`, { method: "POST", headers: {
|
|
304
|
+
const response = await fetch(`${record.url}/_feltkit/api/backup`, { method: "POST", headers: { ...adminHeaders(record, token), "Content-Type": "application/json" }, body: "{}" });
|
|
277
305
|
if (!response.ok || !response.body) {
|
|
278
306
|
const body = (await response.json().catch(() => null));
|
|
279
307
|
throw new FeltKitError(body?.error?.code ?? "INTERNAL", body?.error?.message ?? `Admin API answered ${response.status}`);
|
|
@@ -299,10 +327,15 @@ async function adminBackup(record, token, sink) {
|
|
|
299
327
|
async function withEnvironment(projectDir, envName, remote, local) {
|
|
300
328
|
const runtimeDir = join(projectDir, ".feltkit", envName);
|
|
301
329
|
const record = readRuntimeRecord(runtimeDir);
|
|
330
|
+
// An operator signed in to a running production server (`feltkit operator signin`): online, as that operator.
|
|
331
|
+
const session = envName === "production" ? readOperatorSession(projectDir) : null;
|
|
332
|
+
if (session) {
|
|
333
|
+
return { value: await remote({ url: session.url, operator: { token: session.token, environment: session.environment } }, ""), source: `running server (${session.url}), as operator ${session.operator}` };
|
|
334
|
+
}
|
|
302
335
|
if (record) {
|
|
303
336
|
if (envName === "production") {
|
|
304
337
|
throw new FeltKitError("CONFIGURATION", `A production server is running (pid ${record.pid}). Its admin API answers verified operators only, not the admin token.`, {
|
|
305
|
-
hint: "Sign in
|
|
338
|
+
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.",
|
|
306
339
|
});
|
|
307
340
|
}
|
|
308
341
|
const token = readAdminToken(runtimeDir);
|
|
@@ -326,6 +359,23 @@ async function withEnvironment(projectDir, envName, remote, local) {
|
|
|
326
359
|
await runtime.close();
|
|
327
360
|
}
|
|
328
361
|
}
|
|
362
|
+
const operatorSessionPath = (projectDir) => join(projectDir, ".feltkit", "production", "operator-session.json");
|
|
363
|
+
function readOperatorSession(projectDir) {
|
|
364
|
+
const path = operatorSessionPath(projectDir);
|
|
365
|
+
if (!existsSync(path))
|
|
366
|
+
return null;
|
|
367
|
+
const session = JSON.parse(readFileSync(path, "utf8"));
|
|
368
|
+
if (session.expiresAt && Date.parse(session.expiresAt) <= Date.now()) {
|
|
369
|
+
rmSync(path, { force: true });
|
|
370
|
+
return null;
|
|
371
|
+
}
|
|
372
|
+
return session;
|
|
373
|
+
}
|
|
374
|
+
function writeOperatorSession(projectDir, session) {
|
|
375
|
+
mkdirSync(join(projectDir, ".feltkit", "production"), { recursive: true });
|
|
376
|
+
writeFileSync(operatorSessionPath(projectDir), JSON.stringify(session, null, 2) + "\n", { mode: 0o600 });
|
|
377
|
+
chmodSync(operatorSessionPath(projectDir), 0o600);
|
|
378
|
+
}
|
|
329
379
|
function waitForShutdown(close) {
|
|
330
380
|
return new Promise((done) => {
|
|
331
381
|
let closing = false;
|
|
@@ -555,6 +605,8 @@ export async function main(argv = process.argv.slice(2), deps = {}) {
|
|
|
555
605
|
return checks.every((check) => check.ok) ? 0 : 1;
|
|
556
606
|
}
|
|
557
607
|
case "dev": {
|
|
608
|
+
rejectAssignments("dev", positional);
|
|
609
|
+
const listen = resolvePort(flags.port);
|
|
558
610
|
const failing = doctor(projectDir).filter((check) => !check.ok);
|
|
559
611
|
if (failing.length) {
|
|
560
612
|
for (const check of failing)
|
|
@@ -565,7 +617,7 @@ export async function main(argv = process.argv.slice(2), deps = {}) {
|
|
|
565
617
|
const started = Date.now();
|
|
566
618
|
const dev = await startDev({
|
|
567
619
|
projectDir,
|
|
568
|
-
|
|
620
|
+
listen,
|
|
569
621
|
...(flags.host ? { host: String(flags.host) } : {}),
|
|
570
622
|
...(flags.frontend === false ? { noFrontend: true } : {}),
|
|
571
623
|
onReload: ({ ok, error }) => {
|
|
@@ -582,7 +634,7 @@ export async function main(argv = process.argv.slice(2), deps = {}) {
|
|
|
582
634
|
});
|
|
583
635
|
const overview = dev.runtime.overview();
|
|
584
636
|
line("");
|
|
585
|
-
line(` ${c.bold("App")} ${c.cyan(dev.server.url)}`);
|
|
637
|
+
line(` ${c.bold("App")} ${c.cyan(dev.server.url)}${portNote(listen, dev.server.port)}`);
|
|
586
638
|
if (dev.server.dashboardUrl)
|
|
587
639
|
line(` ${c.bold("Dashboard")} ${c.cyan(dev.server.dashboardUrl)}`);
|
|
588
640
|
line(` ${c.bold("AppPort")} ${dev.server.url}/appport ${c.dim(`(${overview.functions.filter((f) => f.capability).length + [...dev.runtime.app.integrations.values()].reduce((n, i) => n + Object.keys(i.operations).length, 0)} capabilities)`)}`);
|
|
@@ -669,15 +721,17 @@ export async function main(argv = process.argv.slice(2), deps = {}) {
|
|
|
669
721
|
return 0;
|
|
670
722
|
}
|
|
671
723
|
case "start": {
|
|
724
|
+
rejectAssignments("start", positional);
|
|
725
|
+
const listen = resolvePort(flags.port);
|
|
672
726
|
const server = await startProduction({
|
|
673
727
|
projectDir,
|
|
674
728
|
environment: envName,
|
|
675
729
|
...(flags.migrate === false || process.env.FELTKIT_MIGRATE === "manual" ? { migrate: "manual" } : {}),
|
|
676
|
-
|
|
730
|
+
listen,
|
|
677
731
|
...(flags.host ? { host: String(flags.host) } : {}),
|
|
678
732
|
});
|
|
679
733
|
const identity = server.runtime.instance.identity;
|
|
680
|
-
line(`${symbols.ok} ${c.bold(server.runtime.app.name)} serving ${c.cyan(server.server.url)} ${c.dim(`environment: ${server.environment.name}`)}`);
|
|
734
|
+
line(`${symbols.ok} ${c.bold(server.runtime.app.name)} serving ${c.cyan(server.server.url)}${portNote(listen, server.server.port)} ${c.dim(`environment: ${server.environment.name}`)}`);
|
|
681
735
|
line(` ${c.bold("State")} ${identity.mode} ${identity.location}`);
|
|
682
736
|
line(server.server.dashboardUrl ? ` ${c.yellow("Dashboard enabled in production (FELTKIT_DASHBOARD=1); data edits remain disabled.")}` : c.dim(" Dashboard not served in production."));
|
|
683
737
|
await waitForShutdown(() => server.close());
|
|
@@ -814,9 +868,15 @@ export async function main(argv = process.argv.slice(2), deps = {}) {
|
|
|
814
868
|
let source;
|
|
815
869
|
const file = fileSink(partial);
|
|
816
870
|
try {
|
|
817
|
-
|
|
871
|
+
const session = envName === "production" ? readOperatorSession(projectDir) : null;
|
|
872
|
+
if (session) {
|
|
873
|
+
// Online, as the signed-in operator: the running server reads it with calls paused.
|
|
874
|
+
header = await adminBackup({ url: session.url, operator: { token: session.token, environment: session.environment } }, "", file.sink);
|
|
875
|
+
source = `running server (${session.url}; calls paused while it read), as operator ${session.operator}`;
|
|
876
|
+
}
|
|
877
|
+
else if (record) {
|
|
818
878
|
if (envName === "production")
|
|
819
|
-
throw new FeltKitError("CONFIGURATION", `A production server is running (pid ${record.pid}); its admin API answers verified operators only
|
|
879
|
+
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." });
|
|
820
880
|
const token = readAdminToken(runtimeDir);
|
|
821
881
|
if (!token)
|
|
822
882
|
throw new FeltKitError("CONFIGURATION", `A ${envName} server is running (pid ${record.pid}) but its admin token is missing.`);
|
|
@@ -963,11 +1023,57 @@ export async function main(argv = process.argv.slice(2), deps = {}) {
|
|
|
963
1023
|
line(` Evidence ${c.dim("none yet: AppBoundry reports Running only when the runtime itself names the module")}`);
|
|
964
1024
|
if (d.failure)
|
|
965
1025
|
line(` Failure ${d.failure.code}: ${d.failure.message}`);
|
|
966
|
-
|
|
1026
|
+
// Running is the runtime; reachable is the route, verified by AppBoundry over HTTPS. Never one for the other.
|
|
1027
|
+
const routing = d.routing;
|
|
1028
|
+
if (routing && routing.status !== "unavailable") {
|
|
1029
|
+
const failure = routing.failure ? `${routing.failure.category} failure: ${routing.failure.code}: ${routing.failure.message}` : "";
|
|
1030
|
+
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}` : ""}`;
|
|
1031
|
+
line(` Routing ${routing.hostname ? `${routing.hostname} ` : ""}${state}`);
|
|
1032
|
+
}
|
|
1033
|
+
line(` Address ${d.address ?? c.dim(`none${routing?.status === "unavailable" && routing.reason ? `: ${routing.reason}` : routing?.status && routing.status !== "active" ? ": not verified reachable" : ""}`)}`);
|
|
967
1034
|
if (!s.verified && s.outcome === "pending")
|
|
968
1035
|
line(c.dim(" Pending: AppBoundry has not observed a ready runtime for this build yet."));
|
|
969
1036
|
return s.outcome === "failed" ? 1 : 0;
|
|
970
1037
|
}
|
|
1038
|
+
case "releases": {
|
|
1039
|
+
const { appboundryReleases } = await import("./deploy-appboundry.js");
|
|
1040
|
+
const r = await appboundryReleases({ projectDir, ...(flags.portal ? { connection: { portal: String(flags.portal) } } : {}) });
|
|
1041
|
+
if (json) {
|
|
1042
|
+
line(JSON.stringify({ ok: true, ...r }, null, 2));
|
|
1043
|
+
return 0;
|
|
1044
|
+
}
|
|
1045
|
+
line(`${c.bold(r.applicationId)} on AppBoundry ${c.dim(r.portal)}`);
|
|
1046
|
+
if (!r.releases.length) {
|
|
1047
|
+
line(c.dim(" No deployments yet."));
|
|
1048
|
+
return 0;
|
|
1049
|
+
}
|
|
1050
|
+
for (const rel of r.releases) {
|
|
1051
|
+
const mark = rel.serving ? c.green("● serving") : rel.state === "Failed" ? c.red(rel.state) : rel.state;
|
|
1052
|
+
line(` ${rel.deploymentId} ${mark} artifact ${rel.artifactId.slice(0, 12)}… ${c.dim(rel.requestedAt ?? "")}`);
|
|
1053
|
+
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(" · ");
|
|
1054
|
+
if (lineage)
|
|
1055
|
+
line(c.dim(` ${lineage}`));
|
|
1056
|
+
if (rel.failure)
|
|
1057
|
+
line(c.dim(` ${rel.failure}`));
|
|
1058
|
+
}
|
|
1059
|
+
return 0;
|
|
1060
|
+
}
|
|
1061
|
+
case "rollback": {
|
|
1062
|
+
const { appboundryRollback } = await import("./deploy-appboundry.js");
|
|
1063
|
+
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}`) }) });
|
|
1064
|
+
if (json) {
|
|
1065
|
+
line(JSON.stringify({ ok: r.outcome === "rolled-back", ...r }, null, 2));
|
|
1066
|
+
return r.outcome === "rolled-back" ? 0 : 1;
|
|
1067
|
+
}
|
|
1068
|
+
if (r.outcome === "rolled-back")
|
|
1069
|
+
line(`${symbols.ok} Rolled back: ${r.deployment.deploymentId} runs artifact ${r.deployment.artifactId.slice(0, 16)}… with the runtime's evidence`);
|
|
1070
|
+
else if (r.outcome === "pending")
|
|
1071
|
+
line(`${symbols.info} Requested ${r.deployment.deploymentId}; AppBoundry has not observed it running yet (feltkit status).`);
|
|
1072
|
+
else
|
|
1073
|
+
line(`${symbols.fail} Refused: ${r.deployment.failure ? `${r.deployment.failure.code}: ${r.deployment.failure.message}` : r.deployment.state}. Nothing was rolled back.`);
|
|
1074
|
+
line(` Serving ${r.serving ? `${r.serving.deploymentId} (artifact ${r.serving.artifactId.slice(0, 12)}…)` : c.dim("nothing AppBoundry has verified")}`);
|
|
1075
|
+
return r.outcome === "rolled-back" ? 0 : 1;
|
|
1076
|
+
}
|
|
971
1077
|
case "deploy": {
|
|
972
1078
|
// How it will run: --target, else asked in a terminal, else one container.
|
|
973
1079
|
let target = flags.target ? String(flags.target) : undefined;
|
|
@@ -1419,17 +1525,40 @@ export async function main(argv = process.argv.slice(2), deps = {}) {
|
|
|
1419
1525
|
if (looksLikeSecret(positional[1]))
|
|
1420
1526
|
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.");
|
|
1421
1527
|
const ref = toCredentialRef(positional[1]);
|
|
1422
|
-
const
|
|
1528
|
+
const oauth = flags.oauth === true || flags.oauth === "true";
|
|
1529
|
+
const value = await readSecret(oauth ? `OAuth 2.0 token response (JSON) for ${ref} (input hidden): ` : `Value for ${ref} (input hidden): `);
|
|
1423
1530
|
if (!value)
|
|
1424
1531
|
throw new FeltKitError("INVALID_ARGUMENT", "No value was entered; nothing was stored.");
|
|
1425
1532
|
const provider = ref.slice("credential-ref:".length);
|
|
1426
|
-
const
|
|
1533
|
+
const kind = oauth ? { kind: "oauth2" } : {};
|
|
1534
|
+
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"));
|
|
1427
1535
|
if (json)
|
|
1428
1536
|
line(JSON.stringify(stored, null, 2));
|
|
1429
1537
|
else
|
|
1430
1538
|
line(`${symbols.ok} ${envName}: ${stored.ref} set (${stored.location ?? "custody"}, version ${stored.version}) ${c.dim(`— ${source}`)}`);
|
|
1431
1539
|
return 0;
|
|
1432
1540
|
}
|
|
1541
|
+
if (action === "connect") {
|
|
1542
|
+
// An integration's OAuth 2.0 grant: the running server starts authorization code with PKCE and
|
|
1543
|
+
// receives the provider's callback; this prints the address to open. Nothing secret is shown.
|
|
1544
|
+
const name = positional[1];
|
|
1545
|
+
if (!name) {
|
|
1546
|
+
line(COMMAND_HELP.credential);
|
|
1547
|
+
return 1;
|
|
1548
|
+
}
|
|
1549
|
+
const { value, source } = await withEnvironment(projectDir, envName, (record, token) => adminRequest(record, token, `/integrations/${encodeURIComponent(name)}/connect`, { method: "POST", body: JSON.stringify({}) }), async () => {
|
|
1550
|
+
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.");
|
|
1551
|
+
});
|
|
1552
|
+
const v = value;
|
|
1553
|
+
if (json)
|
|
1554
|
+
line(JSON.stringify(v, null, 2));
|
|
1555
|
+
else {
|
|
1556
|
+
line(`${symbols.ok} ${envName}: open this address and approve access ${c.dim(`— ${source}`)}`);
|
|
1557
|
+
line(` ${v.url}`);
|
|
1558
|
+
line(c.dim(` The provider returns to ${v.redirectUri} (register it with the provider). Valid until ${v.expiresAt}, once.`));
|
|
1559
|
+
}
|
|
1560
|
+
return 0;
|
|
1561
|
+
}
|
|
1433
1562
|
if (action === "remove") {
|
|
1434
1563
|
if (!positional[1]) {
|
|
1435
1564
|
line(COMMAND_HELP.credential);
|
|
@@ -1465,6 +1594,19 @@ export async function main(argv = process.argv.slice(2), deps = {}) {
|
|
|
1465
1594
|
}
|
|
1466
1595
|
case "config": {
|
|
1467
1596
|
const action = positional[0];
|
|
1597
|
+
if (action === "set") {
|
|
1598
|
+
// One variable, on the running server, as the signed-in operator (AppPort Services authorizes and records it).
|
|
1599
|
+
const [name, value] = [positional[1], positional[2]];
|
|
1600
|
+
if (!name || value === undefined)
|
|
1601
|
+
throw new FeltKitError("INVALID_ARGUMENT", "Usage: feltkit config set <NAME> <value> --env production (after `feltkit operator signin`)");
|
|
1602
|
+
const { source } = await withEnvironment(projectDir, envName, (record, token) => {
|
|
1603
|
+
if (!("operator" in record))
|
|
1604
|
+
throw new FeltKitError("FAILED_PRECONDITION", "`config set` changes a running production server as a signed-in operator; in development use Studio → Services → Configuration.");
|
|
1605
|
+
return adminRequest(record, token, `/configuration/${encodeURIComponent(name)}`, { method: "PUT", body: JSON.stringify({ value }) });
|
|
1606
|
+
}, async () => { throw new FeltKitError("FAILED_PRECONDITION", "No signed-in operator session: run `feltkit operator signin` first, or `feltkit config import` with the server stopped."); });
|
|
1607
|
+
line(`${symbols.ok} ${name} set ${c.dim(`— ${source}`)}`);
|
|
1608
|
+
return 0;
|
|
1609
|
+
}
|
|
1468
1610
|
if (action === "export") {
|
|
1469
1611
|
const { value, source } = await withEnvironment(projectDir, envName, (record, token) => adminRequest(record, token, "/configuration/export"), (runtime) => runtime.services.exportConfiguration());
|
|
1470
1612
|
const text = `${JSON.stringify(value, null, 2)}\n`;
|
|
@@ -1513,6 +1655,51 @@ export async function main(argv = process.argv.slice(2), deps = {}) {
|
|
|
1513
1655
|
return 1;
|
|
1514
1656
|
}
|
|
1515
1657
|
case "operator": {
|
|
1658
|
+
if (positional[0] === "signout") {
|
|
1659
|
+
const session = readOperatorSession(projectDir);
|
|
1660
|
+
if (session) {
|
|
1661
|
+
await adminRequest({ url: session.url, operator: { token: session.token, environment: session.environment } }, "", "/operator/signout", { method: "POST" }).catch(() => undefined);
|
|
1662
|
+
rmSync(operatorSessionPath(projectDir), { force: true });
|
|
1663
|
+
}
|
|
1664
|
+
line(`${symbols.ok} Signed out${session ? ` of ${session.url}` : ""}.`);
|
|
1665
|
+
return 0;
|
|
1666
|
+
}
|
|
1667
|
+
if (positional[0] === "signin") {
|
|
1668
|
+
// A grant (from --grant, or signed here with the deployment's operator key) becomes an operator session on the
|
|
1669
|
+
// running server. The session token is kept in .feltkit/production/operator-session.json (mode 0600), never printed.
|
|
1670
|
+
const env = String(flags.env ?? "production");
|
|
1671
|
+
let grant = flags.grant ? String(flags.grant) : "";
|
|
1672
|
+
let url = flags.url ? String(flags.url).replace(/\/+$/, "") : "";
|
|
1673
|
+
if (!grant) {
|
|
1674
|
+
if (!flags.id || !flags.role) {
|
|
1675
|
+
line(COMMAND_HELP.operator);
|
|
1676
|
+
return 1;
|
|
1677
|
+
}
|
|
1678
|
+
const link = await studioLink(projectDir, { id: String(flags.id), roles: String(flags.role) });
|
|
1679
|
+
grant = link.grant;
|
|
1680
|
+
if (!url && link.url)
|
|
1681
|
+
url = new URL(link.url).origin;
|
|
1682
|
+
}
|
|
1683
|
+
if (!url)
|
|
1684
|
+
url = readRuntimeRecord(join(projectDir, ".feltkit", env))?.url ?? "";
|
|
1685
|
+
if (!url)
|
|
1686
|
+
throw new FeltKitError("INVALID_ARGUMENT", "No running server to sign in to: pass --url <server URL>.");
|
|
1687
|
+
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 }) });
|
|
1688
|
+
const body = (await response.json().catch(() => ({})));
|
|
1689
|
+
if (!response.ok)
|
|
1690
|
+
throw new FeltKitError(body?.error?.code ?? "UNAUTHORIZED", body?.error?.message ?? `Sign-in answered ${response.status}`, {
|
|
1691
|
+
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.",
|
|
1692
|
+
});
|
|
1693
|
+
const cookie = /feltkit_operator[^=]*=([^;]+)/.exec(response.headers.get("set-cookie") ?? "")?.[1];
|
|
1694
|
+
if (!cookie)
|
|
1695
|
+
throw new FeltKitError("INTERNAL", "The server signed the operator in but returned no session.");
|
|
1696
|
+
writeOperatorSession(projectDir, { url, environment: env, token: decodeURIComponent(cookie), operator: String(body.operator?.id ?? ""), expiresAt: String(body.expiresAt ?? "") });
|
|
1697
|
+
if (json)
|
|
1698
|
+
line(JSON.stringify({ ok: true, url, operator: body.operator, permissions: body.permissions, expiresAt: body.expiresAt }, null, 2));
|
|
1699
|
+
else
|
|
1700
|
+
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.`);
|
|
1701
|
+
return 0;
|
|
1702
|
+
}
|
|
1516
1703
|
if (positional[0] !== "grant" || !flags.id || !flags.role) {
|
|
1517
1704
|
line(COMMAND_HELP.operator);
|
|
1518
1705
|
return 1;
|