@feltdb/feltkit 0.0.0-stage → 0.2.0
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/LICENSE +21 -0
- package/README.md +22 -2
- package/bin/feltkit.js +3 -0
- package/dist/app.d.ts +247 -0
- package/dist/app.js +181 -0
- package/dist/app.js.map +1 -0
- package/dist/cli/deploy.d.ts +8 -0
- package/dist/cli/deploy.js +125 -0
- package/dist/cli/deploy.js.map +1 -0
- package/dist/cli/main.d.ts +9 -0
- package/dist/cli/main.js +581 -0
- package/dist/cli/main.js.map +1 -0
- package/dist/cli/output.d.ts +18 -0
- package/dist/cli/output.js +87 -0
- package/dist/cli/output.js.map +1 -0
- package/dist/cli/skills.d.ts +39 -0
- package/dist/cli/skills.js +125 -0
- package/dist/cli/skills.js.map +1 -0
- package/dist/client/index.d.ts +125 -0
- package/dist/client/index.js +306 -0
- package/dist/client/index.js.map +1 -0
- package/dist/dashboard/assets/index--1Tqbv_A.css +1 -0
- package/dist/dashboard/assets/index-Bm4qCYpv.js +15 -0
- package/dist/dashboard/index.html +16 -0
- package/dist/errors.d.ts +33 -0
- package/dist/errors.js +56 -0
- package/dist/errors.js.map +1 -0
- package/dist/index.d.ts +18 -0
- package/dist/index.js +12 -0
- package/dist/index.js.map +1 -0
- package/dist/react/index.d.ts +40 -0
- package/dist/react/index.js +85 -0
- package/dist/react/index.js.map +1 -0
- package/dist/runtime/activity.d.ts +110 -0
- package/dist/runtime/activity.js +113 -0
- package/dist/runtime/activity.js.map +1 -0
- package/dist/runtime/agent.d.ts +353 -0
- package/dist/runtime/agent.js +1345 -0
- package/dist/runtime/agent.js.map +1 -0
- package/dist/runtime/authority.d.ts +98 -0
- package/dist/runtime/authority.js +240 -0
- package/dist/runtime/authority.js.map +1 -0
- package/dist/runtime/changes.d.ts +42 -0
- package/dist/runtime/changes.js +85 -0
- package/dist/runtime/changes.js.map +1 -0
- package/dist/runtime/content.d.ts +33 -0
- package/dist/runtime/content.js +46 -0
- package/dist/runtime/content.js.map +1 -0
- package/dist/runtime/context.d.ts +76 -0
- package/dist/runtime/context.js +2 -0
- package/dist/runtime/context.js.map +1 -0
- package/dist/runtime/credentials.d.ts +42 -0
- package/dist/runtime/credentials.js +32 -0
- package/dist/runtime/credentials.js.map +1 -0
- package/dist/runtime/data.d.ts +145 -0
- package/dist/runtime/data.js +439 -0
- package/dist/runtime/data.js.map +1 -0
- package/dist/runtime/decisions.d.ts +131 -0
- package/dist/runtime/decisions.js +301 -0
- package/dist/runtime/decisions.js.map +1 -0
- package/dist/runtime/environment.d.ts +36 -0
- package/dist/runtime/environment.js +73 -0
- package/dist/runtime/environment.js.map +1 -0
- package/dist/runtime/idempotency.d.ts +37 -0
- package/dist/runtime/idempotency.js +88 -0
- package/dist/runtime/idempotency.js.map +1 -0
- package/dist/runtime/instance.d.ts +82 -0
- package/dist/runtime/instance.js +253 -0
- package/dist/runtime/instance.js.map +1 -0
- package/dist/runtime/integrations.d.ts +120 -0
- package/dist/runtime/integrations.js +412 -0
- package/dist/runtime/integrations.js.map +1 -0
- package/dist/runtime/loader.d.ts +15 -0
- package/dist/runtime/loader.js +121 -0
- package/dist/runtime/loader.js.map +1 -0
- package/dist/runtime/projects.d.ts +52 -0
- package/dist/runtime/projects.js +141 -0
- package/dist/runtime/projects.js.map +1 -0
- package/dist/runtime/readiness.d.ts +29 -0
- package/dist/runtime/readiness.js +154 -0
- package/dist/runtime/readiness.js.map +1 -0
- package/dist/runtime/runtime.d.ts +227 -0
- package/dist/runtime/runtime.js +664 -0
- package/dist/runtime/runtime.js.map +1 -0
- package/dist/runtime/services.d.ts +327 -0
- package/dist/runtime/services.js +686 -0
- package/dist/runtime/services.js.map +1 -0
- package/dist/runtime/sessions.d.ts +44 -0
- package/dist/runtime/sessions.js +109 -0
- package/dist/runtime/sessions.js.map +1 -0
- package/dist/schema.d.ts +56 -0
- package/dist/schema.js +44 -0
- package/dist/schema.js.map +1 -0
- package/dist/server/admin.d.ts +141 -0
- package/dist/server/admin.js +828 -0
- package/dist/server/admin.js.map +1 -0
- package/dist/server/http.d.ts +19 -0
- package/dist/server/http.js +99 -0
- package/dist/server/http.js.map +1 -0
- package/dist/server/index.d.ts +54 -0
- package/dist/server/index.js +305 -0
- package/dist/server/index.js.map +1 -0
- package/dist/server/management.d.ts +12 -0
- package/dist/server/management.js +177 -0
- package/dist/server/management.js.map +1 -0
- package/dist/server/mcp.d.ts +214 -0
- package/dist/server/mcp.js +135 -0
- package/dist/server/mcp.js.map +1 -0
- package/dist/server/operators.d.ts +77 -0
- package/dist/server/operators.js +162 -0
- package/dist/server/operators.js.map +1 -0
- package/dist/server/project.d.ts +60 -0
- package/dist/server/project.js +344 -0
- package/dist/server/project.js.map +1 -0
- package/dist/server/public.d.ts +14 -0
- package/dist/server/public.js +15 -0
- package/dist/server/public.js.map +1 -0
- package/dist/testing/index.d.ts +20 -0
- package/dist/testing/index.js +65 -0
- package/dist/testing/index.js.map +1 -0
- package/package.json +91 -4
- package/skills/.claude-plugin/marketplace.json +16 -0
- package/skills/.claude-plugin/plugin.json +24 -0
- package/skills/README.md +44 -0
- package/skills/feltkit-agent/SKILL.md +84 -0
- package/skills/feltkit-build/SKILL.md +143 -0
- package/skills/feltkit-data/SKILL.md +79 -0
- package/skills/feltkit-operations/SKILL.md +72 -0
- package/skills/feltkit-services/SKILL.md +102 -0
|
@@ -0,0 +1,686 @@
|
|
|
1
|
+
import { createServices, isServiceAuthorityError, parseConfigurationExport, MAX_EVIDENCE_LOOKUP_LIMIT, VERSION, } from "@appport/services";
|
|
2
|
+
import { randomUUID } from "node:crypto";
|
|
3
|
+
import { FeltKitError } from "../errors.js";
|
|
4
|
+
import { FileContent, FILE_CONTENT_COLLECTION } from "./content.js";
|
|
5
|
+
import { EnvironmentCredentials } from "./credentials.js";
|
|
6
|
+
import { systemPrincipal } from "./authority.js";
|
|
7
|
+
export { FILE_CONTENT_COLLECTION };
|
|
8
|
+
export const DEFAULT_MAX_FILE_BYTES = 1024 * 1024;
|
|
9
|
+
export const CONFIGURATION_ENVIRONMENT = {
|
|
10
|
+
development: "development",
|
|
11
|
+
test: "development",
|
|
12
|
+
production: "production",
|
|
13
|
+
};
|
|
14
|
+
function toInfo(file) {
|
|
15
|
+
return {
|
|
16
|
+
id: file.id,
|
|
17
|
+
name: file.name,
|
|
18
|
+
...(file.contentType ? { contentType: file.contentType } : {}),
|
|
19
|
+
size: file.size,
|
|
20
|
+
...(file.checksum ? { checksum: file.checksum } : {}),
|
|
21
|
+
owner: file.owner,
|
|
22
|
+
metadata: (file.metadata ?? {}),
|
|
23
|
+
createdAt: file.createdAt,
|
|
24
|
+
...(file.updatedAt ? { updatedAt: file.updatedAt } : {}),
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
function translate(error) {
|
|
28
|
+
if (isServiceAuthorityError(error)) {
|
|
29
|
+
const code = error.code;
|
|
30
|
+
if (code === "DENIED")
|
|
31
|
+
throw new FeltKitError("FORBIDDEN", error.message, { cause: error });
|
|
32
|
+
if (code === "UNAUTHENTICATED")
|
|
33
|
+
throw new FeltKitError("UNAUTHORIZED", error.message, { cause: error });
|
|
34
|
+
if (code === "INVALID_REQUEST")
|
|
35
|
+
throw new FeltKitError("INVALID_ARGUMENT", error.message, { cause: error });
|
|
36
|
+
throw new FeltKitError("UNAVAILABLE", error.message, { cause: error });
|
|
37
|
+
}
|
|
38
|
+
const name = String(error?.name ?? "");
|
|
39
|
+
const message = error?.message ?? String(error);
|
|
40
|
+
if (name.endsWith("NotFoundError"))
|
|
41
|
+
throw new FeltKitError("NOT_FOUND", message, { cause: error });
|
|
42
|
+
if (name.endsWith("ValidationError") || name.endsWith("SensitiveDataError"))
|
|
43
|
+
throw new FeltKitError("INVALID_ARGUMENT", message, { cause: error });
|
|
44
|
+
if (name.endsWith("AuthorizationError"))
|
|
45
|
+
throw new FeltKitError("FORBIDDEN", message, { cause: error });
|
|
46
|
+
throw error;
|
|
47
|
+
}
|
|
48
|
+
export class ServicesHost {
|
|
49
|
+
gateway;
|
|
50
|
+
files;
|
|
51
|
+
notifications;
|
|
52
|
+
configuration;
|
|
53
|
+
apiKeys;
|
|
54
|
+
webhooks;
|
|
55
|
+
jobs;
|
|
56
|
+
schedules;
|
|
57
|
+
intelligence;
|
|
58
|
+
credentials;
|
|
59
|
+
/** Roles a request authenticated by an API key holds. */
|
|
60
|
+
apiKeyRoles;
|
|
61
|
+
/** Job type → FeltKit function. */
|
|
62
|
+
jobHandlers;
|
|
63
|
+
/** The instance handle every service store uses (`services.db`, checked with `usesInstance`). */
|
|
64
|
+
db;
|
|
65
|
+
#official;
|
|
66
|
+
#content;
|
|
67
|
+
#environment;
|
|
68
|
+
#tenantId;
|
|
69
|
+
#applicationId;
|
|
70
|
+
#maxBytes;
|
|
71
|
+
/** requestId → principal for invocations currently allowed to cause service effects */
|
|
72
|
+
#bound = new Map();
|
|
73
|
+
#lastError;
|
|
74
|
+
#lastChecked;
|
|
75
|
+
constructor(options) {
|
|
76
|
+
this.#applicationId = options.applicationId;
|
|
77
|
+
this.#tenantId = options.applicationId;
|
|
78
|
+
this.#content = new FileContent(options.contentDb);
|
|
79
|
+
this.#environment = CONFIGURATION_ENVIRONMENT[options.environment] ?? "staging";
|
|
80
|
+
this.credentials = options.credentials ?? new EnvironmentCredentials();
|
|
81
|
+
const config = options.config;
|
|
82
|
+
this.#maxBytes = typeof config.files === "object" ? config.files.maxBytes ?? DEFAULT_MAX_FILE_BYTES : DEFAULT_MAX_FILE_BYTES;
|
|
83
|
+
this.apiKeyRoles = Object.freeze([...(typeof config.apiKeys === "object" ? config.apiKeys.roles ?? [] : [])]);
|
|
84
|
+
this.jobHandlers = Object.freeze({ ...(typeof config.jobs === "object" ? config.jobs.handlers ?? {} : {}) });
|
|
85
|
+
const resolveDurable = options.resolveDurable;
|
|
86
|
+
const authorizer = options.authority.serviceAuthorizer(async (request) => {
|
|
87
|
+
if (request.durable)
|
|
88
|
+
return resolveDurable ? resolveDurable(request.subjectId, request.subjectKind) : null;
|
|
89
|
+
return request.runId ? this.#bound.get(request.runId) ?? null : null;
|
|
90
|
+
});
|
|
91
|
+
// The package's own construction, on the shared instance.
|
|
92
|
+
const official = createServices({
|
|
93
|
+
db: options.servicesDb,
|
|
94
|
+
application: options.applicationId,
|
|
95
|
+
authorizer,
|
|
96
|
+
credentials: this.credentials,
|
|
97
|
+
...(options.allowPrivateWebhookDestinations ? { webhookDestinationPolicy: { allowPrivateNetworks: true } } : {}),
|
|
98
|
+
...(options.apiKeyVerifierKey ? { apiKeyVerifierKey: options.apiKeyVerifierKey } : {}),
|
|
99
|
+
});
|
|
100
|
+
if (!official.usesInstance(options.servicesDb) || official.ownsDb) {
|
|
101
|
+
throw new FeltKitError("CONFIGURATION", `@appport/services ${VERSION} did not use the application's FeltDB instance. Refusing to start with a second database.`);
|
|
102
|
+
}
|
|
103
|
+
if (config.schedules && !config.jobs) {
|
|
104
|
+
throw new FeltKitError("CONFIGURATION", "services.schedules needs services.jobs: a schedule creates jobs.");
|
|
105
|
+
}
|
|
106
|
+
this.#official = official;
|
|
107
|
+
this.db = official.db;
|
|
108
|
+
this.gateway = official.gateway;
|
|
109
|
+
this.files = config.files ? official.files : null;
|
|
110
|
+
this.notifications = config.notifications ? official.notifications : null;
|
|
111
|
+
this.configuration = config.configuration ? official.configuration : null;
|
|
112
|
+
this.apiKeys = config.apiKeys ? official.apiKeys : null;
|
|
113
|
+
this.webhooks = config.webhooks ? official.webhooks : null;
|
|
114
|
+
this.jobs = config.jobs ? official.jobs : null;
|
|
115
|
+
this.schedules = config.schedules ? official.schedules : null;
|
|
116
|
+
this.intelligence = config.intelligence ? official.intelligence : null;
|
|
117
|
+
if (this.jobs) {
|
|
118
|
+
for (const [type, fn] of Object.entries(this.jobHandlers)) {
|
|
119
|
+
// Upstream calls this inside gateway.execute('jobs.execute', principal, …): the job is
|
|
120
|
+
// already authorized as its principal; the function is authorized again as itself.
|
|
121
|
+
this.jobs.register(type, async (job, execution) => {
|
|
122
|
+
const principal = await resolveDurable?.(execution.principal.principalId, execution.principal.principalType);
|
|
123
|
+
if (!principal)
|
|
124
|
+
throw new FeltKitError("FORBIDDEN", `The principal behind job ${job.id} can no longer be resolved.`);
|
|
125
|
+
if (!options.runJob)
|
|
126
|
+
throw new FeltKitError("UNAVAILABLE", "No job runner is attached.");
|
|
127
|
+
await options.runJob(fn, job.payload ?? {}, principal, execution.runId);
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* The services the packaged management pages and routes are mounted for: exactly
|
|
134
|
+
* the enabled ones, as the same objects application code uses.
|
|
135
|
+
*/
|
|
136
|
+
management() {
|
|
137
|
+
const out = {};
|
|
138
|
+
for (const key of ["apiKeys", "configuration", "intelligence", "webhooks", "jobs", "notifications", "files", "schedules"]) {
|
|
139
|
+
if (this[key])
|
|
140
|
+
out[key] = this[key];
|
|
141
|
+
}
|
|
142
|
+
return out;
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Run `work` with `principal` bound as a live invocation: any service effect inside is
|
|
146
|
+
* authorized by the gateway as that principal, exactly as from a function.
|
|
147
|
+
*/
|
|
148
|
+
async asPrincipal(principal, work, requestId = `req_${randomUUID()}`) {
|
|
149
|
+
// The request id is the run id of every service effect inside, and so the `runId`
|
|
150
|
+
// of AppPort Services' effect evidence for it.
|
|
151
|
+
const release = this.enter(requestId, principal);
|
|
152
|
+
try {
|
|
153
|
+
return await this.#record(work(this.#verified(principal, requestId)));
|
|
154
|
+
}
|
|
155
|
+
finally {
|
|
156
|
+
release();
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
/** AppPort Services' capability manifest (name, service, effect, invocable). */
|
|
160
|
+
capabilities() {
|
|
161
|
+
return this.#official.capabilities;
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* AppPort Services' own invoke(), as `principal`, for an enabled service only. The
|
|
165
|
+
* gateway authorizes it exactly as it would a function's or the console's request.
|
|
166
|
+
*/
|
|
167
|
+
async invoke(capability, input, principal, signal, requestId) {
|
|
168
|
+
const declared = this.capabilities().find((c) => c.name === capability);
|
|
169
|
+
if (!declared || !declared.invocable)
|
|
170
|
+
throw new FeltKitError("NOT_FOUND", `"${capability}" is not an invocable AppPort Services capability.`);
|
|
171
|
+
if (!(SERVICE_KEY[declared.service] && this[SERVICE_KEY[declared.service]])) {
|
|
172
|
+
throw new FeltKitError("CONFIGURATION", `The ${declared.service} service is not enabled.`);
|
|
173
|
+
}
|
|
174
|
+
return this.asPrincipal(principal, (verified) => abortable(this.#official.invoke(capability, input, { principal: verified }), signal), requestId);
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
* AppPort Services' effect evidence for one run id (a FeltKit request id, a job attempt
|
|
178
|
+
* `<jobId>:<attempt>`, or a delivery attempt `<deliveryId>:<attempt>`), this application
|
|
179
|
+
* and tenant only. `state: "started"` means a completion was never recorded: the
|
|
180
|
+
* outcome is unknown, not failed.
|
|
181
|
+
*/
|
|
182
|
+
evidence(runId) {
|
|
183
|
+
return this.#official.evidence.findByRunId(runId, { tenantId: this.#tenantId, limit: MAX_EVIDENCE_LOOKUP_LIMIT });
|
|
184
|
+
}
|
|
185
|
+
/** AppPort Services' own health for this application's tenant. Trusted host read: counts only, authorizes nothing. */
|
|
186
|
+
health(options = {}) {
|
|
187
|
+
return this.#official.health({ tenantId: this.#tenantId, ...options });
|
|
188
|
+
}
|
|
189
|
+
/** Identity claims for the management router: verified against this gateway, bound to a request. */
|
|
190
|
+
identify(principal, requestId) {
|
|
191
|
+
return this.#verified(principal, requestId);
|
|
192
|
+
}
|
|
193
|
+
/**
|
|
194
|
+
* Drive durable work once: recurring schedules, due jobs, due webhook deliveries.
|
|
195
|
+
* Every attempt is authorized by AppPort Services as its own principal.
|
|
196
|
+
*/
|
|
197
|
+
async tick(workerId) {
|
|
198
|
+
let jobs = 0;
|
|
199
|
+
let deliveries = 0;
|
|
200
|
+
let scheduled = 0;
|
|
201
|
+
if (this.jobs) {
|
|
202
|
+
if (this.schedules)
|
|
203
|
+
scheduled = await this.jobs.processRecurringSchedules(this.#tenantId);
|
|
204
|
+
for (const job of await this.jobs.listDueJobs(this.#tenantId)) {
|
|
205
|
+
await this.jobs.executeJob(this.#tenantId, job.id, workerId);
|
|
206
|
+
jobs += 1;
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
if (this.webhooks) {
|
|
210
|
+
const now = Date.now();
|
|
211
|
+
for (const delivery of await this.webhooks.listWebhookDeliveries(this.#tenantId)) {
|
|
212
|
+
const due = delivery.status === "pending" || (delivery.status === "retrying" && (!delivery.nextAttemptAt || Date.parse(delivery.nextAttemptAt) <= now));
|
|
213
|
+
if (!due)
|
|
214
|
+
continue;
|
|
215
|
+
await this.webhooks.deliverWebhook(this.#tenantId, delivery.id);
|
|
216
|
+
deliveries += 1;
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
return { jobs, deliveries, scheduled };
|
|
220
|
+
}
|
|
221
|
+
get tenantId() {
|
|
222
|
+
return this.#tenantId;
|
|
223
|
+
}
|
|
224
|
+
/** Every credential reference the services hold, what uses it, and whether it resolves. Never a value. */
|
|
225
|
+
async credentialReferences() {
|
|
226
|
+
const refs = new Map();
|
|
227
|
+
const add = (ref, usedBy) => {
|
|
228
|
+
if (!ref)
|
|
229
|
+
return;
|
|
230
|
+
refs.set(ref, [...(refs.get(ref) ?? []), usedBy]);
|
|
231
|
+
};
|
|
232
|
+
if (this.configuration) {
|
|
233
|
+
// Retained private read (docs/UPSTREAM-GAPS.md, S3): health() counts bindings but does not
|
|
234
|
+
// name their references, and configuration.list()/export() are authorized effects that
|
|
235
|
+
// write evidence, which Studio's change-driven refresh would turn into a loop. This is
|
|
236
|
+
// the one AppPort Services collection FeltKit still reads.
|
|
237
|
+
for (const secret of (await this.db.collection("ConfigurationSecrets").find({ tenantId: this.#tenantId }, { limit: 500 })))
|
|
238
|
+
add(secret.credentialRef, `configuration secret ${secret.name}`);
|
|
239
|
+
}
|
|
240
|
+
if (this.webhooks) {
|
|
241
|
+
for (const endpoint of await this.webhooks.listWebhookEndpoints(this.#tenantId))
|
|
242
|
+
if (!endpoint.disabledAt)
|
|
243
|
+
add(endpoint.signingCredentialRef, `webhook ${new URL(endpoint.url).origin}`);
|
|
244
|
+
}
|
|
245
|
+
return [...refs].map(([ref, usedBy]) => ({ ...this.credentials.describe(ref), usedBy }));
|
|
246
|
+
}
|
|
247
|
+
/** The tenant, application, and configuration environment this runtime's services use. */
|
|
248
|
+
get scope() {
|
|
249
|
+
return { tenantId: this.#tenantId, applicationId: this.#applicationId, environment: this.#environment };
|
|
250
|
+
}
|
|
251
|
+
/**
|
|
252
|
+
* This environment's non-secret configuration as AppPort Services' versioned export
|
|
253
|
+
* document (`appport.configuration-export`): variables, credential binding names and
|
|
254
|
+
* references, active webhook endpoints (signing reference only), enabled schedules.
|
|
255
|
+
* Read as FeltKit's host-only transfer principal. Secret values never appear.
|
|
256
|
+
*/
|
|
257
|
+
async exportConfiguration() {
|
|
258
|
+
const service = this.#require(this.configuration, "configuration");
|
|
259
|
+
return this.asPrincipal(TRANSFER_READ, (principal) => service.export({ principal, environment: this.#environment }));
|
|
260
|
+
}
|
|
261
|
+
/**
|
|
262
|
+
* Plan (dryRun) or apply an export document to this environment through AppPort
|
|
263
|
+
* Services' own import: each write goes through its capability, credential bindings
|
|
264
|
+
* are never created (they are reported in `missingSecrets` for a person to attach),
|
|
265
|
+
* and a document carrying a secret value is refused. Schedules are reported as
|
|
266
|
+
* skipped, not imported: a schedule's jobs run as its creator, and the transfer
|
|
267
|
+
* principal is not a person FeltKit can resolve when they run.
|
|
268
|
+
*/
|
|
269
|
+
async importConfiguration(input, options = {}) {
|
|
270
|
+
const service = this.#require(this.configuration, "configuration");
|
|
271
|
+
let document;
|
|
272
|
+
try {
|
|
273
|
+
document = parseConfigurationExport(input);
|
|
274
|
+
}
|
|
275
|
+
catch (error) {
|
|
276
|
+
throw new FeltKitError("INVALID_ARGUMENT", `Not an importable configuration document: ${error.message}`, { cause: error });
|
|
277
|
+
}
|
|
278
|
+
const dryRun = options.dryRun === true;
|
|
279
|
+
const report = await this.asPrincipal(dryRun ? TRANSFER_READ : TRANSFER_WRITE, (principal) => service.import({ ...document, schedules: [] }, { principal, environment: this.#environment, dryRun, overwrite: options.overwrite === true }));
|
|
280
|
+
const skipped = document.schedules.map((schedule) => ({
|
|
281
|
+
kind: "schedule",
|
|
282
|
+
key: `${schedule.type}@${schedule.interval}`,
|
|
283
|
+
action: "skip",
|
|
284
|
+
applied: false,
|
|
285
|
+
reason: "Not imported by FeltKit: a schedule's jobs run as its creator. Create it in this environment as the person whose authority it should run with.",
|
|
286
|
+
}));
|
|
287
|
+
return { ...report, items: [...report.items, ...skipped], summary: { ...report.summary, skip: report.summary.skip + skipped.length } };
|
|
288
|
+
}
|
|
289
|
+
/** Allow `principal` to cause service effects while request `requestId` runs. */
|
|
290
|
+
enter(requestId, principal) {
|
|
291
|
+
if (!principal)
|
|
292
|
+
return () => { };
|
|
293
|
+
this.#bound.set(requestId, principal);
|
|
294
|
+
return () => this.#bound.delete(requestId);
|
|
295
|
+
}
|
|
296
|
+
#verified(principal, requestId) {
|
|
297
|
+
if (!principal)
|
|
298
|
+
throw new FeltKitError("UNAUTHORIZED", "Authentication is required to use services");
|
|
299
|
+
const verified = this.gateway.identify({
|
|
300
|
+
principalId: principal.id,
|
|
301
|
+
principalType: principal.type,
|
|
302
|
+
tenantId: this.#tenantId,
|
|
303
|
+
applicationId: this.#applicationId,
|
|
304
|
+
runId: requestId,
|
|
305
|
+
});
|
|
306
|
+
if (!verified)
|
|
307
|
+
throw new FeltKitError("UNAUTHORIZED", "The principal could not be verified for services");
|
|
308
|
+
return verified;
|
|
309
|
+
}
|
|
310
|
+
#require(service, name) {
|
|
311
|
+
if (!service) {
|
|
312
|
+
throw new FeltKitError("CONFIGURATION", `The ${name} service is not enabled.`, { hint: `Enable it with feltkit({ services: { ${name}: true } }).` });
|
|
313
|
+
}
|
|
314
|
+
return service;
|
|
315
|
+
}
|
|
316
|
+
#requireFiles() {
|
|
317
|
+
if (!this.files) {
|
|
318
|
+
throw new FeltKitError("CONFIGURATION", "The Files service is not enabled.", { hint: "Enable it with feltkit({ services: { files: true } })." });
|
|
319
|
+
}
|
|
320
|
+
return this.files;
|
|
321
|
+
}
|
|
322
|
+
#record(promise) {
|
|
323
|
+
return promise.catch((error) => {
|
|
324
|
+
if (!isServiceAuthorityError(error) || error.code !== "DENIED") {
|
|
325
|
+
this.#lastError = { at: new Date().toISOString(), message: error.message };
|
|
326
|
+
}
|
|
327
|
+
return translate(error);
|
|
328
|
+
});
|
|
329
|
+
}
|
|
330
|
+
/** The `ctx.services` object for one invocation. `reads` collects collections read, for reactivity. */
|
|
331
|
+
bind(principal, requestId, reads, writable, used = new Set()) {
|
|
332
|
+
const notifications = this.#bindNotifications(principal, requestId, reads, writable, used);
|
|
333
|
+
const configuration = this.#bindConfiguration(principal, requestId, reads, writable, used);
|
|
334
|
+
const use = () => used.add("files");
|
|
335
|
+
const reader = {
|
|
336
|
+
list: async (filter = {}) => {
|
|
337
|
+
use();
|
|
338
|
+
const service = this.#requireFiles();
|
|
339
|
+
reads.add("files");
|
|
340
|
+
const items = await this.#record(service.list(this.#tenantId, this.#verified(principal, requestId)));
|
|
341
|
+
const wanted = Object.entries(filter.metadata ?? {});
|
|
342
|
+
return items
|
|
343
|
+
.filter((item) => wanted.every(([key, value]) => item.metadata?.[key] === value))
|
|
344
|
+
.map(toInfo)
|
|
345
|
+
.sort((a, b) => a.createdAt.localeCompare(b.createdAt));
|
|
346
|
+
},
|
|
347
|
+
get: async (id) => {
|
|
348
|
+
use();
|
|
349
|
+
const service = this.#requireFiles();
|
|
350
|
+
reads.add("files");
|
|
351
|
+
return toInfo(await this.#record(service.get(this.#tenantId, id, this.#verified(principal, requestId))));
|
|
352
|
+
},
|
|
353
|
+
read: async (id) => {
|
|
354
|
+
const file = await reader.get(id);
|
|
355
|
+
const storageKey = String((await this.#record(this.#requireFiles().get(this.#tenantId, id, this.#verified(principal, requestId)))).storageKey);
|
|
356
|
+
const { bytes, collection } = await this.#content.read(id, storageKey, file.checksum);
|
|
357
|
+
if (collection)
|
|
358
|
+
reads.add(collection);
|
|
359
|
+
return { file, bytes, text: () => new TextDecoder().decode(bytes) };
|
|
360
|
+
},
|
|
361
|
+
};
|
|
362
|
+
if (!writable)
|
|
363
|
+
return { files: reader, notifications, configuration };
|
|
364
|
+
const writer = {
|
|
365
|
+
...reader,
|
|
366
|
+
upload: async (input) => {
|
|
367
|
+
use();
|
|
368
|
+
const service = this.#requireFiles();
|
|
369
|
+
if (!input || typeof input.name !== "string" || !input.name.trim())
|
|
370
|
+
throw new FeltKitError("INVALID_ARGUMENT", "upload() needs a file name.");
|
|
371
|
+
const bytes = typeof input.content === "string" ? new TextEncoder().encode(input.content) : input.content;
|
|
372
|
+
if (!(bytes instanceof Uint8Array))
|
|
373
|
+
throw new FeltKitError("INVALID_ARGUMENT", "upload() content must be a string or Uint8Array.");
|
|
374
|
+
if (bytes.byteLength > this.#maxBytes) {
|
|
375
|
+
throw new FeltKitError("PAYLOAD_TOO_LARGE", `Files are limited to ${this.#maxBytes} bytes on this runtime (got ${bytes.byteLength}).`);
|
|
376
|
+
}
|
|
377
|
+
const { storageKey, checksum } = await this.#content.store(bytes);
|
|
378
|
+
const verified = this.#verified(principal, requestId);
|
|
379
|
+
try {
|
|
380
|
+
const created = await this.#record(service.create({
|
|
381
|
+
name: input.name.trim(),
|
|
382
|
+
...(input.contentType ? { contentType: input.contentType } : {}),
|
|
383
|
+
size: bytes.byteLength,
|
|
384
|
+
checksum,
|
|
385
|
+
storageKey,
|
|
386
|
+
...(input.metadata ? { metadata: input.metadata } : {}),
|
|
387
|
+
}, verified));
|
|
388
|
+
return toInfo(created);
|
|
389
|
+
}
|
|
390
|
+
catch (error) {
|
|
391
|
+
// No file record points at these bytes; do not leave them behind.
|
|
392
|
+
await this.#content.release(storageKey).catch(() => undefined);
|
|
393
|
+
throw error;
|
|
394
|
+
}
|
|
395
|
+
},
|
|
396
|
+
remove: async (id) => {
|
|
397
|
+
use();
|
|
398
|
+
const service = this.#requireFiles();
|
|
399
|
+
const verified = this.#verified(principal, requestId);
|
|
400
|
+
const current = await this.#record(service.get(this.#tenantId, id, verified));
|
|
401
|
+
await this.#record(service.delete(this.#tenantId, id, verified));
|
|
402
|
+
await this.#content.release(String(current.storageKey));
|
|
403
|
+
},
|
|
404
|
+
};
|
|
405
|
+
return { files: writer, notifications, configuration, jobs: this.#bindJobs(principal, requestId, used), webhooks: this.#bindWebhooks(principal, requestId, used) };
|
|
406
|
+
}
|
|
407
|
+
#bindJobs(principal, requestId, used) {
|
|
408
|
+
return {
|
|
409
|
+
enqueue: async (type, payload = {}, options = {}) => {
|
|
410
|
+
used.add("jobs");
|
|
411
|
+
const service = this.#require(this.jobs, "jobs");
|
|
412
|
+
if (typeof type !== "string" || !type)
|
|
413
|
+
throw new FeltKitError("INVALID_ARGUMENT", "enqueue() needs a job type.");
|
|
414
|
+
if (!this.jobHandlers[type]) {
|
|
415
|
+
throw new FeltKitError("INVALID_ARGUMENT", `No handler for job type "${type}". Declare it in feltkit({ services: { jobs: { handlers: { "${type}": "<module>:<function>" } } } }).`);
|
|
416
|
+
}
|
|
417
|
+
const job = await this.#record(service.enqueue({ type, payload, ...(options.runAt ? { runAt: options.runAt } : {}), ...(options.maxAttempts ? { maxAttempts: options.maxAttempts } : {}) }, this.#verified(principal, requestId)));
|
|
418
|
+
return { id: job.id, status: job.status };
|
|
419
|
+
},
|
|
420
|
+
};
|
|
421
|
+
}
|
|
422
|
+
#bindWebhooks(principal, requestId, used) {
|
|
423
|
+
return {
|
|
424
|
+
emit: async (type, payload) => {
|
|
425
|
+
used.add("webhooks");
|
|
426
|
+
const service = this.#require(this.webhooks, "webhooks");
|
|
427
|
+
const deliveries = await this.#record(service.emitWebhookEvent({ type, payload }, this.#verified(principal, requestId)));
|
|
428
|
+
return { deliveries: deliveries.length };
|
|
429
|
+
},
|
|
430
|
+
};
|
|
431
|
+
}
|
|
432
|
+
#bindNotifications(principal, requestId, reads, writable, used) {
|
|
433
|
+
const service = () => (used.add("notifications"), reads.add("notifications"), this.#require(this.notifications, "notifications"));
|
|
434
|
+
const me = () => this.#verified(principal, requestId);
|
|
435
|
+
const reader = {
|
|
436
|
+
list: async (filter = {}) => {
|
|
437
|
+
const s = service();
|
|
438
|
+
const verified = me();
|
|
439
|
+
const page = await this.#record(s.list(this.#tenantId, { recipient: verified.principalId, ...(filter.unread ? { unread: true } : {}), ...(filter.type ? { type: filter.type } : {}) }, verified));
|
|
440
|
+
return page.items.map(toNotification);
|
|
441
|
+
},
|
|
442
|
+
get: async (id) => toNotification(await this.#record(service().get(this.#tenantId, id, me()))),
|
|
443
|
+
};
|
|
444
|
+
if (!writable)
|
|
445
|
+
return reader;
|
|
446
|
+
return {
|
|
447
|
+
...reader,
|
|
448
|
+
send: async (input) => {
|
|
449
|
+
const s = service();
|
|
450
|
+
if (!input || typeof input.recipient !== "string" || !input.recipient)
|
|
451
|
+
throw new FeltKitError("INVALID_ARGUMENT", "send() needs a recipient.");
|
|
452
|
+
const result = await this.#record(s.notify({
|
|
453
|
+
recipient: input.recipient,
|
|
454
|
+
type: input.type,
|
|
455
|
+
title: input.title,
|
|
456
|
+
...(input.body !== undefined ? { body: input.body } : {}),
|
|
457
|
+
...(input.data !== undefined ? { data: input.data } : {}),
|
|
458
|
+
...(input.priority ? { priority: input.priority } : {}),
|
|
459
|
+
...(input.idempotencyKey ? { idempotencyKey: input.idempotencyKey } : {}),
|
|
460
|
+
channels: ["in-app"],
|
|
461
|
+
}, me()));
|
|
462
|
+
return toNotification(result.notification);
|
|
463
|
+
},
|
|
464
|
+
markRead: async (id) => toNotification(await this.#record(service().markRead(this.#tenantId, id, me()))),
|
|
465
|
+
dismiss: async (id) => toNotification(await this.#record(service().dismiss(this.#tenantId, id, me()))),
|
|
466
|
+
};
|
|
467
|
+
}
|
|
468
|
+
#bindConfiguration(principal, requestId, reads, writable, used) {
|
|
469
|
+
const service = () => (used.add("configuration"), reads.add("ConfigurationVariables"), this.#require(this.configuration, "configuration"));
|
|
470
|
+
const scope = { tenantId: this.#tenantId, applicationId: this.#applicationId, environment: this.#environment };
|
|
471
|
+
const list = async () => {
|
|
472
|
+
const result = await this.#record(service().list(scope, this.#verified(principal, requestId)));
|
|
473
|
+
return Object.fromEntries(result.variables.map((v) => [v.name, v.value]));
|
|
474
|
+
};
|
|
475
|
+
const reader = {
|
|
476
|
+
list,
|
|
477
|
+
get: async (name) => (await list())[name] ?? null,
|
|
478
|
+
};
|
|
479
|
+
if (!writable)
|
|
480
|
+
return reader;
|
|
481
|
+
return {
|
|
482
|
+
...reader,
|
|
483
|
+
set: async (name, value) => {
|
|
484
|
+
const s = service();
|
|
485
|
+
const verified = this.#verified(principal, requestId);
|
|
486
|
+
const existing = await this.#record(s.list(scope, verified));
|
|
487
|
+
const input = { ...scope, name, value };
|
|
488
|
+
if (existing.variables.some((v) => v.name === name))
|
|
489
|
+
await this.#record(s.updateVariable(input, verified));
|
|
490
|
+
else
|
|
491
|
+
await this.#record(s.createVariable(input, verified));
|
|
492
|
+
},
|
|
493
|
+
remove: async (name) => {
|
|
494
|
+
await this.#record(service().delete({ ...scope, name, kind: "variable" }, this.#verified(principal, requestId)));
|
|
495
|
+
},
|
|
496
|
+
};
|
|
497
|
+
}
|
|
498
|
+
/** A live check: AppPort Services' health() answers through the shared instance. Authorizes nothing. */
|
|
499
|
+
async check() {
|
|
500
|
+
const at = new Date().toISOString();
|
|
501
|
+
try {
|
|
502
|
+
await this.health({ countLimit: 1 });
|
|
503
|
+
this.#lastChecked = { at, ok: true, detail: "AppPort Services answered health() through the shared FeltDB instance." };
|
|
504
|
+
}
|
|
505
|
+
catch (error) {
|
|
506
|
+
this.#lastChecked = { at, ok: false, detail: `AppPort Services health() failed: ${error.message}` };
|
|
507
|
+
}
|
|
508
|
+
}
|
|
509
|
+
/**
|
|
510
|
+
* Every service, with an honest state, from AppPort Services' own `health()` for this
|
|
511
|
+
* application's tenant. FeltKit adds only what it alone knows: whether the credential
|
|
512
|
+
* references endpoints sign with resolve in its custody, and which job types have a
|
|
513
|
+
* handler. No value, payload, secret, or credential is read into the result.
|
|
514
|
+
*/
|
|
515
|
+
async status(connected) {
|
|
516
|
+
const at = new Date().toISOString();
|
|
517
|
+
let health = null;
|
|
518
|
+
try {
|
|
519
|
+
health = await this.health();
|
|
520
|
+
this.#lastChecked = { at, ok: true, detail: "AppPort Services answered health() through the shared FeltDB instance." };
|
|
521
|
+
}
|
|
522
|
+
catch (error) {
|
|
523
|
+
this.#lastChecked = { at, ok: false, detail: `AppPort Services health() failed: ${error.message}` };
|
|
524
|
+
}
|
|
525
|
+
// FeltKit's custody: an active endpoint whose signing reference does not resolve cannot sign.
|
|
526
|
+
const unsigned = this.webhooks && health
|
|
527
|
+
? (await this.webhooks.listWebhookEndpoints(this.#tenantId)).filter((e) => !e.disabledAt && (!e.signingCredentialRef || !this.credentials.describe(e.signingCredentialRef).present))
|
|
528
|
+
: [];
|
|
529
|
+
const handlers = Object.keys(this.jobHandlers).length;
|
|
530
|
+
const entry = (id, name, description, collections, capabilities, page) => {
|
|
531
|
+
const enabled = this[id] !== null;
|
|
532
|
+
const own = health?.services[id];
|
|
533
|
+
let state;
|
|
534
|
+
let detail;
|
|
535
|
+
let summary;
|
|
536
|
+
if (!enabled) {
|
|
537
|
+
state = "available";
|
|
538
|
+
detail = `Not enabled. Add services: { ${id}: true } to feltkit({ ... }).`;
|
|
539
|
+
}
|
|
540
|
+
else if (!health || !own) {
|
|
541
|
+
state = "unhealthy";
|
|
542
|
+
detail = this.#lastChecked.detail;
|
|
543
|
+
}
|
|
544
|
+
else {
|
|
545
|
+
summary = { ...own.counts, ...(id === "jobs" ? { handlers } : {}) };
|
|
546
|
+
const capped = health.cappedCounts.filter((c) => c.startsWith(`${id}.`));
|
|
547
|
+
const reasons = own.reasons.map((r) => describeReason(id, r, own.counts)).join(" ");
|
|
548
|
+
if (id === "webhooks" && unsigned.length) {
|
|
549
|
+
state = "unhealthy";
|
|
550
|
+
detail = `${unsigned.length} endpoint(s) cannot sign deliveries: ${unsigned.map((e) => this.credentials.describe(e.signingCredentialRef ?? "").variable ?? "(no reference)").join(", ")} not set.${reasons ? ` ${reasons}` : ""}`;
|
|
551
|
+
}
|
|
552
|
+
else if (own.state === "degraded") {
|
|
553
|
+
state = "unhealthy";
|
|
554
|
+
detail = reasons;
|
|
555
|
+
}
|
|
556
|
+
else if (own.state === "unconfigured" || own.state === "disabled" || (id === "jobs" && handlers === 0)) {
|
|
557
|
+
state = "unconfigured";
|
|
558
|
+
detail = reasons || UNCONFIGURED[id] || "Enabled; nothing set up yet.";
|
|
559
|
+
}
|
|
560
|
+
else {
|
|
561
|
+
state = "configured";
|
|
562
|
+
detail = "Enabled; AppPort Services reports nothing needing attention.";
|
|
563
|
+
}
|
|
564
|
+
if (id === "webhooks")
|
|
565
|
+
detail += " Delivery counts cover every application in this namespace that uses this tenant id.";
|
|
566
|
+
if (capped.length)
|
|
567
|
+
detail += ` At least ${health.countLimit} for: ${capped.join(", ")}.`;
|
|
568
|
+
}
|
|
569
|
+
return {
|
|
570
|
+
id,
|
|
571
|
+
name,
|
|
572
|
+
description,
|
|
573
|
+
package: "@appport/services",
|
|
574
|
+
version: VERSION,
|
|
575
|
+
installed: true,
|
|
576
|
+
configured: state === "configured" || state === "unhealthy",
|
|
577
|
+
connected: connected && enabled,
|
|
578
|
+
healthy: enabled ? state !== "unhealthy" : null,
|
|
579
|
+
available: enabled && connected,
|
|
580
|
+
state,
|
|
581
|
+
detail,
|
|
582
|
+
collections,
|
|
583
|
+
capabilities,
|
|
584
|
+
...(summary && Object.keys(summary).length ? { summary } : {}),
|
|
585
|
+
...(enabled ? { page } : {}),
|
|
586
|
+
...(this.#lastChecked && enabled ? { lastCheckedAt: this.#lastChecked.at } : {}),
|
|
587
|
+
...(this.#lastError && enabled ? { lastError: this.#lastError } : {}),
|
|
588
|
+
};
|
|
589
|
+
};
|
|
590
|
+
return [
|
|
591
|
+
entry("files", "Files", "File records with ownership, audit, and authorization. Bytes are stored in the same FeltDB instance.", ["files", "file_audit_events", "service_effect_evidence", FILE_CONTENT_COLLECTION], ["files.read", "files.write", "files.delete"], "/files"),
|
|
592
|
+
entry("notifications", "Notifications", "Durable in-app notifications. Each principal reads only its own.", ["notifications", "notification_deliveries", "notification_audit_events"], ["notifications.send", "notifications.read", "notifications.update", "notifications.delete"], "/notifications"),
|
|
593
|
+
entry("configuration", "Configuration", `Variables and credential references for this environment (stored as "${this.#environment}").`, ["ConfigurationVariables", "ConfigurationSecrets", "ConfigurationAuditEvents"], ["configuration.read", "configuration.write", "configuration.delete", "credential.attach", "credential.rotate", "credential.detach"], "/configuration"),
|
|
594
|
+
entry("apiKeys", "API keys", "Machine credentials. FeltKit accepts them as an identity holding services.apiKeys.roles.", ["api_keys", "api_key_audit_events"], ["apikeys.read", "apikeys.create", "apikeys.update", "apikeys.rotate", "apikeys.revoke", "apikeys.audit"], "/api-keys"),
|
|
595
|
+
entry("webhooks", "Webhooks", "Signed outbound delivery to registered endpoints, with retries and history.", ["webhook_endpoints", "webhook_deliveries", "webhook_audit_events"], ["webhooks.read", "webhooks.deliveries.read", "webhooks.register", "webhooks.remove", "webhooks.emit", "webhooks.deliver", "webhooks.replay"], "/webhooks"),
|
|
596
|
+
entry("jobs", "Jobs", "Durable background work with leases and retries; each type runs a FeltKit function as its enqueuer.", ["jobs", "job_audit_events"], ["jobs.read", "jobs.create", "jobs.retry", "jobs.execute"], "/jobs"),
|
|
597
|
+
entry("schedules", "Schedules", "Recurring jobs.", ["job_schedules"], ["schedules.read", "schedules.create", "schedules.cancel"], "/schedules"),
|
|
598
|
+
entry("intelligence", "Intelligence", "Model provider configuration. Configuration only: AppPort Services never runs a model.", [], ["intelligence.catalog", "intelligence.read", "intelligence.write", "intelligence.credential.set", "intelligence.credential.remove"], "/intelligence"),
|
|
599
|
+
];
|
|
600
|
+
}
|
|
601
|
+
}
|
|
602
|
+
/** AppPort Services' health reason codes (docs/health.md), as sentences. */
|
|
603
|
+
function describeReason(service, reason, counts) {
|
|
604
|
+
switch (reason) {
|
|
605
|
+
case "failed_deliveries":
|
|
606
|
+
return `${counts.failedDeliveries ?? 0} delivery(ies) failed. Open ${service === "notifications" ? "Notifications" : "Webhooks"} for the error on each.`;
|
|
607
|
+
case "failed_jobs":
|
|
608
|
+
return `${counts.failed ?? 0} job(s) failed. Open Jobs for the error on each, or ask the agent to diagnose one.`;
|
|
609
|
+
case "failed_notifications":
|
|
610
|
+
return `${counts.failedNotifications ?? 0} notification(s) failed.`;
|
|
611
|
+
case "missing_required":
|
|
612
|
+
return `${counts.missingRequired ?? 0} required configuration value(s) have no binding.`;
|
|
613
|
+
case "legacy_secret_values":
|
|
614
|
+
return `${counts.legacySecretValues ?? 0} credential binding(s) still hold a raw value; rotate each to a credential-ref.`;
|
|
615
|
+
case "missing_credential":
|
|
616
|
+
return "The selected provider needs a credential and none is attached.";
|
|
617
|
+
case "not_configured":
|
|
618
|
+
return "Enabled; no provider selected.";
|
|
619
|
+
case "no_endpoints":
|
|
620
|
+
return UNCONFIGURED.webhooks;
|
|
621
|
+
case "all_endpoints_disabled":
|
|
622
|
+
return "Enabled; every endpoint is disabled.";
|
|
623
|
+
case "no_keys":
|
|
624
|
+
return UNCONFIGURED.apiKeys;
|
|
625
|
+
case "no_schedules":
|
|
626
|
+
return UNCONFIGURED.schedules;
|
|
627
|
+
case "all_schedules_disabled":
|
|
628
|
+
return "Enabled; every schedule is disabled.";
|
|
629
|
+
case "no_configuration":
|
|
630
|
+
return UNCONFIGURED.configuration;
|
|
631
|
+
case "authorizer_unconfigured":
|
|
632
|
+
return "No authorizer: AppPort Services refuses every effect.";
|
|
633
|
+
case "credentials_unconfigured":
|
|
634
|
+
return "No credential custody: effects that need a credential fail.";
|
|
635
|
+
default:
|
|
636
|
+
return `AppPort Services reports ${reason}.`;
|
|
637
|
+
}
|
|
638
|
+
}
|
|
639
|
+
/** FeltKit's host-only principals for `feltkit config export|import` (see Authority's system principals). */
|
|
640
|
+
const TRANSFER_READ = systemPrincipal("configuration-transfer", "transfer-read");
|
|
641
|
+
const TRANSFER_WRITE = systemPrincipal("configuration-transfer", "transfer-write");
|
|
642
|
+
/** AppPort Services' service names → this host's fields. */
|
|
643
|
+
const SERVICE_KEY = {
|
|
644
|
+
"api-keys": "apiKeys",
|
|
645
|
+
webhooks: "webhooks",
|
|
646
|
+
jobs: "jobs",
|
|
647
|
+
schedules: "schedules",
|
|
648
|
+
notifications: "notifications",
|
|
649
|
+
files: "files",
|
|
650
|
+
configuration: "configuration",
|
|
651
|
+
intelligence: "intelligence",
|
|
652
|
+
};
|
|
653
|
+
function abortable(promise, signal) {
|
|
654
|
+
if (!signal)
|
|
655
|
+
return promise;
|
|
656
|
+
if (signal.aborted)
|
|
657
|
+
return Promise.reject(Object.assign(new Error(String(signal.reason?.message ?? "cancelled")), { code: "CANCELLED" }));
|
|
658
|
+
return new Promise((resolve, reject) => {
|
|
659
|
+
const onAbort = () => reject(Object.assign(new Error(String(signal.reason?.message ?? "cancelled")), { code: "CANCELLED" }));
|
|
660
|
+
signal.addEventListener("abort", onAbort, { once: true });
|
|
661
|
+
promise.then(resolve, reject).finally(() => signal.removeEventListener("abort", onAbort));
|
|
662
|
+
});
|
|
663
|
+
}
|
|
664
|
+
const UNCONFIGURED = {
|
|
665
|
+
configuration: "Enabled; no variables or secrets yet.",
|
|
666
|
+
apiKeys: "Enabled; no active keys. Create one on the API keys page.",
|
|
667
|
+
webhooks: "Enabled; no endpoints registered.",
|
|
668
|
+
jobs: "Enabled; no job handlers declared (services.jobs.handlers).",
|
|
669
|
+
schedules: "Enabled; no active schedules.",
|
|
670
|
+
};
|
|
671
|
+
function toNotification(item) {
|
|
672
|
+
return {
|
|
673
|
+
id: item.id,
|
|
674
|
+
recipient: item.recipient,
|
|
675
|
+
type: item.type,
|
|
676
|
+
title: item.title,
|
|
677
|
+
...(item.body !== undefined ? { body: item.body } : {}),
|
|
678
|
+
...(item.data !== undefined ? { data: item.data } : {}),
|
|
679
|
+
priority: item.priority ?? "normal",
|
|
680
|
+
status: item.status,
|
|
681
|
+
createdAt: item.createdAt,
|
|
682
|
+
...(item.createdBy ? { createdBy: item.createdBy } : {}),
|
|
683
|
+
...(item.readAt ? { readAt: item.readAt } : {}),
|
|
684
|
+
};
|
|
685
|
+
}
|
|
686
|
+
//# sourceMappingURL=services.js.map
|