@feltdb/feltkit 0.3.14 → 0.3.15

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/cli/main.js CHANGED
@@ -83,7 +83,8 @@ ${c.bold("Commands")}
83
83
  start Run the production build (environment: production)
84
84
  test Run the project's tests against an isolated test environment
85
85
  inspect Show what the application is, where its state lives, and what it's doing
86
- deploy Build a verified deployment: one container, an app container + FeltDB, Vercel, Cloudflare, or Fly.io
86
+ deploy Deploy to AppBoundry, or build a verified deployment: one container, an app container + FeltDB, Vercel, Cloudflare, Fly.io
87
+ status What AppBoundry says about the last deployment from this project
87
88
  vercel <action> Set a Vercel project's environment from FeltDB's values, deploy, and sign you in
88
89
  cloudflare <action> Set a Cloudflare Worker's secrets from FeltDB's values, deploy, and sign you in
89
90
  fly <action> Create the Fly.io app (and volume), set its secrets, deploy, and sign you in
@@ -161,7 +162,7 @@ const COMMAND_HELP = {
161
162
  " Writes the FeltDB application contract: this application's collections, FeltKit's own records, and FeltDB's\n" +
162
163
  " agent state. Managed FeltDB stores only what the promoted contract declares; publish it with\n" +
163
164
  " `feltdb publish --contract feltdb.contract.json`. --check exits 1 when the file is out of date.",
164
- deploy: "feltkit deploy [--target container|hosted|self-hosted|vercel|cloudflare|fly] [--data volume|managed|self-hosted] [--instances <n>] [--out <dir>] [--yes]\n" +
165
+ deploy: "feltkit deploy [--target appboundry|container|hosted|self-hosted|vercel|cloudflare|fly|appboundry-self-hosted] [--portal <url>] [--host <id>] [--data volume|managed|self-hosted] [--instances <n>] [--out <dir>] [--yes]\n" +
165
166
  " Builds, verifies the build boots, and writes .feltkit/deploy for how you run it:\n" +
166
167
  " container everything in one container: the app and its FeltDB state on a volume (default)\n" +
167
168
  " hosted a separate app container; data in Managed FeltDB (with feltdb.contract.json)\n" +
@@ -171,7 +172,11 @@ const COMMAND_HELP = {
171
172
  " --instances <n> spreads requests over n containers (default 1)\n" +
172
173
  " fly Fly.io Machines; data on a Fly volume beside the app, one machine (default; --data managed:\n" +
173
174
  " Managed FeltDB, --data self-hosted: your FeltDB server; any number of machines)\n" +
174
- " Each has a Dockerfile, docker-compose.yml, fly.toml, .env.example and DEPLOY.md. Asks which in a terminal.",
175
+ " appboundry sends the verified artifact to AppBoundry, which deploys and operates it: uploads it (AppBoundry\n" +
176
+ " verifies and stores it), requests a deployment, waits for the runtime's evidence. Needs\n" +
177
+ " APPBOUNDRY_URL, APPBOUNDRY_TOKEN and APPBOUNDRY_HOST (or --portal/--host). Then: feltkit status\n" +
178
+ " appboundry-self-hosted the artifact with the AppBoundry runtime in one Docker container you operate\n" +
179
+ " Each has a Dockerfile, docker-compose.yml and DEPLOY.md. Asks which in a terminal.",
175
180
  vercel: "feltkit vercel env [--from <file>[,<file>]] [--environment production|preview|development] [--dry-run]\n" +
176
181
  " For an artifact built with `feltkit deploy --target vercel`: uploads the variables it needs to the linked\n" +
177
182
  " Vercel project, from .env.local (what `feltdb init-managed` wrote), the environment, or --from files.\n" +
@@ -891,11 +896,38 @@ export async function main(argv = process.argv.slice(2), deps = {}) {
891
896
  printInspect(value, source);
892
897
  return 0;
893
898
  }
899
+ case "status": {
900
+ const { appboundryStatus } = await import("./deploy-appboundry.js");
901
+ const s = await appboundryStatus({ projectDir, ...(flags.portal ? { connection: { portal: String(flags.portal) } } : {}) });
902
+ if (!s) {
903
+ line(`${symbols.info} No AppBoundry deployment has been requested from this project.`);
904
+ line(c.dim("Deploy with: npx feltkit deploy --target appboundry"));
905
+ return json ? (line(JSON.stringify({ ok: false, deployment: null })), 0) : 0;
906
+ }
907
+ const d = s.deployment;
908
+ if (json) {
909
+ line(JSON.stringify({ ok: s.verified, portal: s.note.portal, application: s.note.applicationId, artifactId: s.note.artifactId, module: `sha256:${s.note.moduleSha256}`, deployment: d, verified: s.verified }, null, 2));
910
+ return 0;
911
+ }
912
+ line(`${c.bold(s.note.applicationId)} on AppBoundry ${c.dim(s.note.portal)}`);
913
+ line(` Deployment ${d.deploymentId} ${s.verified ? c.green(d.state) : d.state === "Failed" ? c.red(d.state) : d.state} ${c.dim(`host ${d.hostId}, attempt ${d.attempt ?? 1}`)}`);
914
+ line(` Artifact ${s.note.artifactId.slice(0, 16)}… module sha256:${s.note.moduleSha256.slice(0, 16)}…`);
915
+ line(` Runtime ${d.runtime ? `${d.runtime.package} ${d.runtime.version}` : "unknown"}`);
916
+ if (d.evidence)
917
+ line(` Evidence the runtime reported module sha256:${d.evidence.observedModuleSha256.slice(0, 16)}… ${d.evidence.health} at ${d.evidence.observedAt}${s.verified ? c.dim(" (matches this build)") : c.red(" (does not match this build)")}`);
918
+ else
919
+ line(` Evidence ${c.dim("none yet: AppBoundry reports Running only when the runtime itself names the module")}`);
920
+ if (d.failure)
921
+ line(` Failure ${d.failure.code}: ${d.failure.message}`);
922
+ return 0;
923
+ }
894
924
  case "deploy": {
895
925
  // How it will run: --target, else asked in a terminal, else one container.
896
926
  let target = flags.target ? String(flags.target) : undefined;
897
927
  if (!target && process.stdin.isTTY && process.stdout.isTTY && !flags.yes) {
898
- const choices = Object.entries(DEPLOY_TARGETS);
928
+ const { APPBOUNDRY_TARGET_TITLE } = await import("./deploy-appboundry.js");
929
+ const { APPBOUNDRY_SELF_HOSTED_TITLE } = await import("./deploy-appboundry-self-hosted.js");
930
+ const choices = [["appboundry", APPBOUNDRY_TARGET_TITLE], ...Object.entries(DEPLOY_TARGETS), ["appboundry-self-hosted", APPBOUNDRY_SELF_HOSTED_TITLE]];
899
931
  line(c.bold("How do you want to run it?"));
900
932
  choices.forEach(([name, text], i) => line(` ${i + 1}) ${text} ${c.dim(`(--target ${name})`)}`));
901
933
  const rl = createInterface({ input: process.stdin, output: process.stdout });
@@ -905,6 +937,67 @@ export async function main(argv = process.argv.slice(2), deps = {}) {
905
937
  if (!target)
906
938
  throw new FeltKitError("INVALID_ARGUMENT", `Answer 1-${choices.length}.`);
907
939
  }
940
+ if (target === "appboundry") {
941
+ if (flags.data !== undefined || flags.instances !== undefined || flags.out !== undefined)
942
+ throw new FeltKitError("INVALID_ARGUMENT", "--data, --instances and --out do not apply to --target appboundry: AppBoundry deploys and operates the artifact.");
943
+ const { appboundryConnection, deployToAppBoundry } = await import("./deploy-appboundry.js");
944
+ const connection = appboundryConnection({ ...(flags.portal ? { portal: String(flags.portal) } : {}), ...(flags.host ? { hostId: String(flags.host) } : {}) });
945
+ if (!json)
946
+ line(`${c.bold("feltkit deploy")} ${c.dim(`→ AppBoundry at ${connection.portal}`)}`);
947
+ const r = await deployToAppBoundry({ projectDir, connection, onProgress: json ? undefined : (e) => {
948
+ if (e.step === "built")
949
+ line(`${symbols.ok} Built the application and its artifact ${c.dim(e.detail)}`);
950
+ else if (e.step === "uploaded")
951
+ line(`${symbols.ok} Uploaded AppBoundry verified the artifact and stored it immutably ${c.dim(e.detail)}`);
952
+ else if (e.step === "requested")
953
+ line(`${symbols.ok} Requested ${c.dim(e.detail)}`);
954
+ else
955
+ line(` ${c.dim("→")} ${e.detail}`);
956
+ } });
957
+ if (json) {
958
+ line(JSON.stringify({ ok: r.outcome === "running", outcome: r.outcome, target: "appboundry", portal: r.portal, application: r.applicationId, artifactId: r.artifact.artifactId, module: `sha256:${r.artifact.moduleSha256}`, deployment: r.deployment, sdk: SDK_VERSION }, null, 2));
959
+ return r.outcome === "failed" ? 1 : 0;
960
+ }
961
+ if (r.outcome === "running") {
962
+ line(`${symbols.ok} Running on ${r.deployment.hostId}; the runtime reports module sha256:${r.deployment.evidence.observedModuleSha256.slice(0, 16)}…, the module this build produced`);
963
+ line(c.dim(`\nAppBoundry operates it from here. Check it any time: npx feltkit status`));
964
+ return 0;
965
+ }
966
+ if (r.outcome === "pending") {
967
+ line(`${symbols.info} ${r.deployment.state}: AppBoundry has the deployment; its runtime has not reported ready yet.`);
968
+ line(c.dim("Check it with: npx feltkit status"));
969
+ return 0;
970
+ }
971
+ line(`${symbols.fail} ${r.deployment.state}${r.deployment.failure ? `: ${r.deployment.failure.message} (${r.deployment.failure.code})` : ""}`);
972
+ return 1;
973
+ }
974
+ if (target === "appboundry-self-hosted") {
975
+ if (flags.data !== undefined || flags.instances !== undefined)
976
+ throw new FeltKitError("INVALID_ARGUMENT", "--data and --instances do not apply to --target appboundry-self-hosted: the runtime keeps the state on the container's volume.");
977
+ const { accessCommands, deployAppBoundrySelfHosted } = await import("./deploy-appboundry-self-hosted.js");
978
+ const ab = await deployAppBoundrySelfHosted({ projectDir, ...(flags.out ? { out: String(flags.out) } : {}) });
979
+ const m = ab.manifest;
980
+ if (json) {
981
+ line(JSON.stringify({ ok: true, dir: relative(projectDir, ab.dir) || ".", target: "appboundry-self-hosted", application: ab.application, artifact: relative(projectDir, ab.artifact), module: `sha256:${m.module.sha256}`, runtime: { package: "@appport/appboundry", version: ab.runtime }, verified: { check: "guest-load", functions: m.functions.length }, sdk: SDK_VERSION }, null, 2));
982
+ return 0;
983
+ }
984
+ const at = relative(process.cwd(), ab.dir) || ".";
985
+ line(`${symbols.ok} Built and verified: the artifact's module loaded in the guest engine and defines exactly its manifest's ${m.functions.length} functions.`);
986
+ line(`${symbols.ok} Artifact ${c.bold(relative(process.cwd(), ab.artifact))} ${c.dim(`(module sha256:${m.module.sha256.slice(0, 16)}…, imports nothing; ${m.collections.length} collections, ${m.functions.filter((f) => f.capability).length} capabilities)`)}`);
987
+ line(`${symbols.ok} Runtime @appport/appboundry ${ab.runtime} ${c.dim("(installed in the image; no FeltKit code runs in the deployment)")}`);
988
+ line(`${symbols.ok} Self-hosted deployment (the AppBoundry runtime in one container you operate; data on a volume): ${c.bold(ab.dir)}${flags.out ? "" : c.dim(" (replaced on every deploy; the state is on the container's volume)")}`);
989
+ for (const note of ab.omitted)
990
+ line(` ${symbols.info} ${c.dim(`Not in the artifact: ${note}`)}`);
991
+ const composeFile = join(at, "docker-compose.yml");
992
+ line(`\n${c.bold("Run it yourself")} ${c.dim("(refuses any other module, verifies the artifact, creates the operator on first start)")}`);
993
+ line(` docker compose -f ${composeFile} up --build`);
994
+ line(`\n${c.bold("Give someone access")} ${c.dim("(an operator adds a user with one of the app's roles and issues their session)")}`);
995
+ for (const command of accessCommands(composeFile))
996
+ line(` ${command}`);
997
+ line(c.dim(`\nThen open http://localhost:3000 and paste the session. The contract (identity, upgrades, limits): ${join(at, "DEPLOY.md")}.`));
998
+ line(c.dim("To have AppBoundry deploy and operate it instead, with no container to run: npx feltkit deploy --target appboundry"));
999
+ return 0;
1000
+ }
908
1001
  const result = await deploy({ projectDir, ...(flags.out ? { out: String(flags.out) } : {}), ...(target ? { target: target } : {}), ...(flags.data ? { data: String(flags.data) } : {}), ...(flags.instances !== undefined ? { instances: Number(flags.instances) } : {}) });
909
1002
  if (json) {
910
1003
  // What a caller (the platform's change.apply) can rely on: deploy() returns only after the
@@ -980,7 +1073,7 @@ export async function main(argv = process.argv.slice(2), deps = {}) {
980
1073
  line(c.dim(result.target === "vercel" || result.target === "cloudflare" || result.target === "fly"
981
1074
  ? `\nLater: \`npx feltkit manage\` opens production Studio again. The whole setup, the target's contract (state, recovery, upgrades), and its limits: ${join(at, "DEPLOY.md")}.`
982
1075
  : `\nThen open http://localhost:3000. The target's contract (state, recovery, upgrades), Fly.io and other hosts: ${join(at, "DEPLOY.md")}.`));
983
- line(c.dim(`Other ways to run it: ${Object.keys(DEPLOY_TARGETS).filter((id) => id !== result.target).map((id) => `npx feltkit deploy --target ${id}`).join(" | ")}`));
1076
+ line(c.dim(`Other ways to run it: ${["appboundry", ...Object.keys(DEPLOY_TARGETS).filter((id) => id !== result.target)].map((id) => `npx feltkit deploy --target ${id}`).join(" | ")}`));
984
1077
  if (result.target === "vercel")
985
1078
  line(c.dim("Vercel's container runtime is in beta. Its limits (stream length, body size, scale to zero): DEPLOY.md."));
986
1079
  if (result.target === "cloudflare")