@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.
Files changed (96) hide show
  1. package/dist/app.d.ts +52 -2
  2. package/dist/app.js +29 -2
  3. package/dist/app.js.map +1 -1
  4. package/dist/appboundry/build.d.ts +5 -1
  5. package/dist/appboundry/build.js +16 -24
  6. package/dist/appboundry/build.js.map +1 -1
  7. package/dist/appboundry/guest-index.d.ts +1 -0
  8. package/dist/appboundry/guest-index.js +1 -0
  9. package/dist/appboundry/guest-index.js.map +1 -1
  10. package/dist/appboundry/guest-tenancy.d.ts +40 -0
  11. package/dist/appboundry/guest-tenancy.js +162 -0
  12. package/dist/appboundry/guest-tenancy.js.map +1 -0
  13. package/dist/appboundry/guest.js +22 -1
  14. package/dist/appboundry/guest.js.map +1 -1
  15. package/dist/appboundry/host.d.ts +24 -0
  16. package/dist/appboundry/host.js +157 -5
  17. package/dist/appboundry/host.js.map +1 -1
  18. package/dist/cli/deploy-appboundry.d.ts +55 -0
  19. package/dist/cli/deploy-appboundry.js +77 -1
  20. package/dist/cli/deploy-appboundry.js.map +1 -1
  21. package/dist/cli/main.js +202 -15
  22. package/dist/cli/main.js.map +1 -1
  23. package/dist/index.d.ts +3 -1
  24. package/dist/index.js +2 -0
  25. package/dist/index.js.map +1 -1
  26. package/dist/platform/server.js +5 -3
  27. package/dist/platform/server.js.map +1 -1
  28. package/dist/react/auth.js +3 -2
  29. package/dist/react/auth.js.map +1 -1
  30. package/dist/runtime/agent.d.ts +14 -0
  31. package/dist/runtime/agent.js +59 -9
  32. package/dist/runtime/agent.js.map +1 -1
  33. package/dist/runtime/content.d.ts +1 -0
  34. package/dist/runtime/context.d.ts +29 -0
  35. package/dist/runtime/credentials.d.ts +76 -0
  36. package/dist/runtime/credentials.js +87 -2
  37. package/dist/runtime/credentials.js.map +1 -1
  38. package/dist/runtime/data.d.ts +1 -24
  39. package/dist/runtime/data.js +4 -67
  40. package/dist/runtime/data.js.map +1 -1
  41. package/dist/runtime/integrations.d.ts +3 -0
  42. package/dist/runtime/integrations.js +31 -4
  43. package/dist/runtime/integrations.js.map +1 -1
  44. package/dist/runtime/job-context.d.ts +26 -0
  45. package/dist/runtime/job-context.js +24 -0
  46. package/dist/runtime/job-context.js.map +1 -0
  47. package/dist/runtime/oauth-credentials.d.ts +68 -0
  48. package/dist/runtime/oauth-credentials.js +496 -0
  49. package/dist/runtime/oauth-credentials.js.map +1 -0
  50. package/dist/runtime/paged-read.d.ts +35 -0
  51. package/dist/runtime/paged-read.js +69 -0
  52. package/dist/runtime/paged-read.js.map +1 -0
  53. package/dist/runtime/runtime.d.ts +3 -0
  54. package/dist/runtime/runtime.js +64 -12
  55. package/dist/runtime/runtime.js.map +1 -1
  56. package/dist/runtime/services.d.ts +14 -38
  57. package/dist/runtime/services.js +124 -17
  58. package/dist/runtime/services.js.map +1 -1
  59. package/dist/runtime/sha256.d.ts +1 -0
  60. package/dist/runtime/sha256.js +91 -0
  61. package/dist/runtime/sha256.js.map +1 -0
  62. package/dist/runtime/tenancy.d.ts +34 -1
  63. package/dist/runtime/tenancy.js +62 -11
  64. package/dist/runtime/tenancy.js.map +1 -1
  65. package/dist/runtime/transactions.d.ts +2 -0
  66. package/dist/runtime/transactions.js +2 -1
  67. package/dist/runtime/transactions.js.map +1 -1
  68. package/dist/server/admin.d.ts +3 -0
  69. package/dist/server/admin.js +129 -18
  70. package/dist/server/admin.js.map +1 -1
  71. package/dist/server/index.d.ts +7 -0
  72. package/dist/server/index.js +44 -14
  73. package/dist/server/index.js.map +1 -1
  74. package/dist/server/ports.d.ts +43 -0
  75. package/dist/server/ports.js +96 -0
  76. package/dist/server/ports.js.map +1 -0
  77. package/dist/server/project.d.ts +8 -1
  78. package/dist/server/project.js +6 -9
  79. package/dist/server/project.js.map +1 -1
  80. package/dist/server/tenancy.js +2 -1
  81. package/dist/server/tenancy.js.map +1 -1
  82. package/dist/testing/index.d.ts +36 -2
  83. package/dist/testing/index.js +17 -4
  84. package/dist/testing/index.js.map +1 -1
  85. package/dist/words.d.ts +9 -0
  86. package/dist/words.js +15 -0
  87. package/dist/words.js.map +1 -0
  88. package/docs/APPBOUNDRY.md +15 -6
  89. package/docs/AUTH.md +16 -3
  90. package/docs/GUARANTEES.md +23 -2
  91. package/docs/PATH-TO-PRODUCTION.md +1 -1
  92. package/docs/README.md +2 -2
  93. package/package.json +3 -3
  94. package/skills/.claude-plugin/marketplace.json +1 -1
  95. package/skills/.claude-plugin/plugin.json +1 -1
  96. package/skills/feltkit-services/SKILL.md +1 -1
@@ -13,7 +13,7 @@ import { defaultOwnerId, studioLink } from "./production.js";
13
13
  import { readJSON, safeEqual, sendError, sendJSON, startSSE } from "./http.js";
14
14
  import { INTELLIGENCE_CATALOG, getIntelligenceProvider } from "@appport/services";
15
15
  import { systemPrincipal } from "../runtime/authority.js";
16
- import { credentialId, looksLikeSecret } from "../runtime/credentials.js";
16
+ import { credentialId, looksLikeSecret, parseGrant } from "../runtime/credentials.js";
17
17
  import { assessReadiness } from "../runtime/readiness.js";
18
18
  import { INTEGRATION_CALLS } from "../runtime/integrations.js";
19
19
  import { SAVED_MODELS } from "../runtime/decisions.js";
@@ -312,19 +312,6 @@ export async function handleAdmin(ctx, request, response, path, url) {
312
312
  if (method === "GET" && segments[0] === "services" && segments[1] === "catalog" && segments.length === 2) {
313
313
  return sendJSON(response, 200, await servicesCatalog(runtime));
314
314
  }
315
- // An inbound webhook source (services.webhooks.inbound), as the dev identity named in
316
- // `x-feltkit-as`. AppPort Services' management contract has no route for integrations; this is the
317
- // development twin of the production route POST /services/webhooks/integrations.
318
- if (method === "POST" && segments.join("/") === "services/webhooks/integrations") {
319
- requireDevelopment("Registering an inbound webhook source from Studio");
320
- const principal = identityFor(runtime, request.headers["x-feltkit-as"]);
321
- if (!principal)
322
- throw new FeltKitError("INVALID_ARGUMENT", "Choose a dev identity; the registration is authorized as that identity.");
323
- const body = await readJSON(request);
324
- await studioSession(runtime, principal);
325
- const item = await runtime.services.invoke("webhooks.integrations.register", { provider: body.provider, signingCredentialRef: body.signingCredentialRef }, principal);
326
- return sendJSON(response, 201, { item });
327
- }
328
315
  // Studio's Services screens: AppPort Services' own management contract (the routes its
329
316
  // packaged pages call), as the dev identity named in `x-feltkit-as`. Authorized by the
330
317
  // services' gateway; FeltKit adds no second authorization layer.
@@ -544,9 +531,16 @@ export async function handleAdmin(ctx, request, response, path, url) {
544
531
  const principal = body.as !== undefined ? identityFor(runtime, body.as) : HOST_CUSTODY;
545
532
  if (!principal)
546
533
  throw new FeltKitError("INVALID_ARGUMENT", "Choose a dev identity; the key is stored as that identity.");
547
- const stored = await storeCredential(runtime, { ref: body.ref, value: body.value, provider: body.provider }, principal, "dashboard");
534
+ const stored = await storeCredential(runtime, { ref: body.ref, value: body.value, provider: body.provider, kind: body.kind }, principal, "dashboard");
548
535
  return sendJSON(response, 200, { stored, ...(await credentialsView(runtime)) });
549
536
  }
537
+ if (method === "POST" && segments[0] === "integrations" && segments[2] === "connect" && segments.length === 3) {
538
+ const body = await readJSON(request);
539
+ const principal = body.as !== undefined ? identityFor(runtime, body.as) : HOST_CUSTODY;
540
+ if (!principal)
541
+ throw new FeltKitError("INVALID_ARGUMENT", "Choose a dev identity; the grant is stored as that identity.");
542
+ return sendJSON(response, 200, await runtime.oauth.connect(segments[1], principal, "dashboard"));
543
+ }
550
544
  if (method === "DELETE" && segments[0] === "credentials" && segments[1] && segments.length === 2) {
551
545
  const principal = identityFor(runtime, url.searchParams.get("as") ?? undefined) ?? HOST_CUSTODY;
552
546
  await removeCredential(runtime, segments[1], principal, "dashboard");
@@ -795,7 +789,17 @@ export async function storeCredential(runtime, input, principal, via) {
795
789
  const started = Date.now();
796
790
  const who = { id: principal.id, type: principal.type, roles: principal.roles };
797
791
  try {
798
- const result = await runtime.services.storeCredential({ ref, value: input.value, ...(typeof input.provider === "string" && input.provider ? { provider: input.provider } : {}) }, principal, requestId);
792
+ if (input.kind !== undefined && input.kind !== "oauth2")
793
+ throw new FeltKitError("INVALID_ARGUMENT", 'The only credential kind is "oauth2" (an OAuth 2.0 token response).');
794
+ if (input.kind === "oauth2") {
795
+ try {
796
+ parseGrant(input.value);
797
+ }
798
+ catch (error) {
799
+ throw new FeltKitError("INVALID_ARGUMENT", `${error.message} Nothing was stored.`);
800
+ }
801
+ }
802
+ const result = await runtime.services.storeCredential({ ref, value: input.value, ...(typeof input.provider === "string" && input.provider ? { provider: input.provider } : {}), ...(input.kind === "oauth2" ? { kind: "oauth2" } : {}) }, principal, requestId);
799
803
  const described = runtime.credentials.describe(ref);
800
804
  runtime.activity.record({ kind: "service", name: "credential.store", via, requestId, principal: who, outcome: "success", durationMs: Date.now() - started, detail: { ref, version: result.version, location: described.location } });
801
805
  void runtime.changes.check();
@@ -828,6 +832,8 @@ export async function removeCredential(runtime, refInput, principal, via) {
828
832
  throw new FeltKitError("FORBIDDEN", `${principal.id} may not remove credentials (credential.store).`);
829
833
  }
830
834
  }
835
+ // An OAuth 2.0 grant: the provider is asked to revoke it first (best effort, recorded); it is erased here regardless.
836
+ const revocation = await runtime.oauth.revokeAtProvider(ref).catch(() => ({ revoked: "failed" }));
831
837
  try {
832
838
  await runtime.credentials.remove({ reference: { secretId: id }, context: { principalId: principal.id, purpose: "credential.remove" } });
833
839
  }
@@ -837,7 +843,7 @@ export async function removeCredential(runtime, refInput, principal, via) {
837
843
  throw new FeltKitError("CUSTODY_READ_ONLY", error.message);
838
844
  throw new FeltKitError("INVALID_ARGUMENT", error.message);
839
845
  }
840
- runtime.activity.record({ kind: "service", name: "credential.remove", via, requestId, principal: who, outcome: "success", durationMs: 0, detail: { ref } });
846
+ runtime.activity.record({ kind: "service", name: "credential.remove", via, requestId, principal: who, outcome: "success", durationMs: 0, detail: { ref, ...(revocation.revoked !== "not-oauth" ? { providerRevocation: revocation.revoked } : {}) } });
841
847
  void runtime.changes.check();
842
848
  }
843
849
  /** Only a failed job whose handler is registered is retried: AppPort Services resets a job in any state. */
@@ -868,7 +874,7 @@ async function handleProduction(ctx, request, response, path, url) {
868
874
  const { runtime } = ctx;
869
875
  const method = request.method ?? "GET";
870
876
  const segments = path.split("/").filter(Boolean).map(decodeURIComponent);
871
- const route = `${method} /${segments.map((s, i) => (i >= 1 && /^(tasks|jobs|deliveries|activity)$/.test(segments[i - 1] ?? "") ? ":id" : s)).join("/")}`;
877
+ const route = `${method} /${segments.map((s, i) => (i >= 1 && /^(tasks|jobs|deliveries|activity|inbound|events)$/.test(segments[i - 1] ?? "") ? ":id" : s)).join("/")}`;
872
878
  const environment = { name: runtime.environment.name, production: true, development: false };
873
879
  // Signing in and out.
874
880
  if (route === "GET /operator/session") {
@@ -965,6 +971,63 @@ async function handleProduction(ctx, request, response, path, url) {
965
971
  }
966
972
  throw new FeltKitError("NOT_FOUND", `${method} /${segments.join("/")} is not available in production.`);
967
973
  }
974
+ // Online administration of a running production server, by a verified operator: the same
975
+ // operations the CLI performs against a development server, so production needs no stop.
976
+ // Reads need feltkit.operations.read; changes need feltkit.operations.write and pass
977
+ // checkWrite (JSON, same origin, CSRF, environment). Each change is recorded as activity.
978
+ const evidence = (p, name, outcome, detail, started) => runtime.activity.record({ kind: "admin", name, via: "dashboard", requestId: newRequestId(), principal: { id: p.id, type: p.type, roles: p.roles ?? [] }, outcome, durationMs: Date.now() - started, detail });
979
+ if (segments[0] === "sessions" && segments.length === 1 && method === "GET") {
980
+ await read();
981
+ return sendJSON(response, 200, { sessions: await runtime.sessions.list() });
982
+ }
983
+ if (segments[0] === "sessions" && segments.length === 2 && method === "DELETE") {
984
+ const started = Date.now();
985
+ const { p } = await write();
986
+ const revoked = await runtime.sessions.revoke(segments[1]);
987
+ evidence(p, "session.revoked", revoked ? "success" : "error", { ref: segments[1] }, started);
988
+ return sendJSON(response, revoked ? 200 : 404, revoked ? { revoked } : { error: { code: "NOT_FOUND", message: `No session matches ${segments[1]}.` } });
989
+ }
990
+ if (segments[0] === "configuration" && segments.length === 2 && method === "PUT") {
991
+ const started = Date.now();
992
+ const { p, body } = await write();
993
+ if (typeof body.value !== "string")
994
+ throw new FeltKitError("INVALID_ARGUMENT", "PUT /configuration/<name> takes {\"value\": \"…\"}.");
995
+ // As the operator: AppPort Services' gateway authorizes the change and records its own evidence.
996
+ await runtime.services.setConfigurationAs(p, segments[1], body.value);
997
+ evidence(p, "configuration.set", "success", { name: segments[1] }, started);
998
+ return sendJSON(response, 200, { name: segments[1], set: true });
999
+ }
1000
+ if (segments[0] === "backup" && segments.length === 1 && method === "POST") {
1001
+ // The environment's backup (docs/BACKUP.md), read with calls paused, streamed as NDJSON, as in
1002
+ // development. It holds every record, so it needs the operations write permission.
1003
+ const started = Date.now();
1004
+ const { p } = await write();
1005
+ let begun = false;
1006
+ const out = (chunk) => new Promise((resolve) => (response.write(chunk) ? resolve() : response.once("drain", resolve)));
1007
+ try {
1008
+ await runtime.backupTo(async (line) => {
1009
+ if (!begun) {
1010
+ begun = true;
1011
+ response.writeHead(200, { "Content-Type": "application/x-ndjson", "Cache-Control": "no-store" });
1012
+ }
1013
+ await out(`${line}\n`);
1014
+ });
1015
+ evidence(p, "backup.created", "success", {}, started);
1016
+ response.end();
1017
+ }
1018
+ catch (error) {
1019
+ evidence(p, "backup.created", "error", { message: String(error.message ?? error) }, started);
1020
+ if (!begun)
1021
+ throw error;
1022
+ const e = error;
1023
+ response.end(`${JSON.stringify({ error: { code: typeof e?.code === "string" ? e.code : "INTERNAL", message: String(e?.message ?? error) } })}\n`);
1024
+ }
1025
+ return;
1026
+ }
1027
+ if (segments[0] === "schema" && segments.length === 1 && method === "GET") {
1028
+ await read();
1029
+ return sendJSON(response, 200, { schema: runtime.schema, plan: await runtime.schemaPlan(), history: await runtime.schemaHistory() });
1030
+ }
968
1031
  switch (route) {
969
1032
  case "GET /overview": {
970
1033
  const p = await read();
@@ -1052,6 +1115,54 @@ async function handleProduction(ctx, request, response, path, url) {
1052
1115
  throw error;
1053
1116
  }
1054
1117
  }
1118
+ // Inbound integrations (services.webhooks.inbound): AppPort Services' own registry and lifecycle,
1119
+ // managed as the signed-in operator, so the services' gateway authorizes each operation
1120
+ // (webhooks.integrations.read/.remove/.rotate, webhooks.inbound.retry). Only credential references
1121
+ // are returned. Development serves the same through AppPort's routes under /services/manage.
1122
+ case "GET /services/inbound":
1123
+ case "GET /services/inbound/:id/events":
1124
+ case "POST /services/inbound/:id/disable":
1125
+ case "POST /services/inbound/:id/rotate":
1126
+ case "POST /services/inbound/:id/events/:id/retry": {
1127
+ const hooks = runtime.services.webhooks;
1128
+ if (!hooks)
1129
+ throw new FeltKitError("NOT_FOUND", "Webhooks are not enabled.");
1130
+ const reading = method === "GET";
1131
+ const { p, body } = reading ? { p: await read(), body: {} } : await write();
1132
+ const id = segments[2] ?? "";
1133
+ const capability = route === "POST /services/inbound/:id/disable" ? "webhooks.integrations.remove" : route === "POST /services/inbound/:id/rotate" ? "webhooks.integrations.rotate" : route.endsWith("/retry") ? "webhooks.inbound.retry" : "webhooks.integrations.read";
1134
+ const requestId = newRequestId();
1135
+ const started = Date.now();
1136
+ const who = { id: p.id, type: p.type, roles: p.roles };
1137
+ try {
1138
+ const result = await runtime.services.asPrincipal(p, async (verified) => {
1139
+ if (route === "GET /services/inbound") {
1140
+ const integrations = await hooks.listIntegrations({}, verified);
1141
+ return { items: await Promise.all(integrations.map(async (i) => ({ ...i, dead: (await hooks.listInboundEvents({ integrationId: i.id, state: "dead", limit: 200 }, verified)).length }))) };
1142
+ }
1143
+ if (route === "GET /services/inbound/:id/events") {
1144
+ const state = url.searchParams.get("state");
1145
+ return { items: await hooks.listInboundEvents({ integrationId: id, ...(state ? { state: state } : {}) }, verified) };
1146
+ }
1147
+ if (route === "POST /services/inbound/:id/disable")
1148
+ return { item: await hooks.disableIntegration({ id }, verified) };
1149
+ if (route === "POST /services/inbound/:id/rotate")
1150
+ return { item: await hooks.rotateIntegrationCredential({ id, signingCredentialRef: String(body.signingCredentialRef ?? "") }, verified) };
1151
+ return { item: await hooks.retryInboundEvent({ integrationId: id, eventId: segments[4] ?? "" }, verified) };
1152
+ }, requestId);
1153
+ if (!reading)
1154
+ runtime.activity.record({ kind: "service", name: capability, via: "dashboard", requestId, principal: who, outcome: "success", durationMs: Date.now() - started, detail: { id } });
1155
+ return sendJSON(response, 200, result);
1156
+ }
1157
+ catch (error) {
1158
+ const denied = isDenied(error);
1159
+ if (!reading)
1160
+ runtime.activity.record({ kind: "service", name: capability, via: "dashboard", requestId, principal: who, outcome: denied ? "denied" : "error", durationMs: Date.now() - started, error: { code: denied ? "FORBIDDEN" : (error.code ?? "INTERNAL"), message: error.message }, detail: { id } });
1161
+ if (denied)
1162
+ throw new FeltKitError("FORBIDDEN", `${p.id} may not ${capability.replace(/\./g, " ")}.`);
1163
+ throw error;
1164
+ }
1165
+ }
1055
1166
  case "POST /services/deliveries/:id/replay": {
1056
1167
  await requireOperator(runtime, operator, OPERATOR_PERMISSIONS.write);
1057
1168
  throw new FeltKitError("FORBIDDEN", REPLAY_DISABLED);