@capybara-hq/kernel 0.1.0-rc.60 → 0.1.0-rc.62
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/admin/admin.module.js +3 -0
- package/dist/admin/extensions.controller.d.ts +32 -1
- package/dist/admin/extensions.controller.js +72 -3
- package/dist/admin/health.service.d.ts +2 -2
- package/dist/admin/health.service.js +6 -2
- package/dist/catalog/marketplaces.service.d.ts +1 -1
- package/dist/config/schema.d.ts +6 -0
- package/dist/config/schema.js +12 -0
- package/dist/conversations/attachments.controller.d.ts +11 -3
- package/dist/conversations/attachments.controller.js +18 -5
- package/dist/conversations/conversations.controller.d.ts +11 -2
- package/dist/conversations/conversations.controller.js +17 -4
- package/dist/conversations/conversations.schemas.d.ts +8 -0
- package/dist/conversations/conversations.schemas.js +6 -0
- package/dist/conversations/event-log.d.ts +12 -3
- package/dist/conversations/event-log.js +17 -5
- package/dist/ctx/secrets.d.ts +10 -5
- package/dist/ctx/secrets.js +16 -5
- package/dist/db/kernel-schema.d.ts +34 -2
- package/dist/errors.d.ts +7 -0
- package/dist/errors.js +7 -0
- package/dist/extensions/config-hash.d.ts +2 -0
- package/dist/extensions/config-hash.js +1 -1
- package/dist/extensions/guide-places.d.ts +5 -1
- package/dist/extensions/guide-places.js +9 -2
- package/dist/extensions/permission-view.d.ts +6 -4
- package/dist/extensions/permission-view.js +6 -3
- package/dist/extensions/plugin-guides.d.ts +20 -0
- package/dist/extensions/plugin-guides.js +49 -1
- package/dist/extensions/registry.js +1 -0
- package/dist/http/api.module.js +7 -0
- package/dist/http/meta.controller.d.ts +7 -1
- package/dist/http/meta.controller.js +14 -3
- package/dist/identity/accounts.js +5 -0
- package/dist/identity/sessions.d.ts +7 -0
- package/dist/identity/sessions.js +26 -4
- package/dist/inbox/platform-inbox.service.d.ts +21 -11
- package/dist/inbox/platform-inbox.service.js +27 -12
- package/dist/inbox/platform-notices.d.ts +15 -1
- package/dist/inbox/platform-notices.js +20 -0
- package/dist/infra/config/kernel-config.service.js +2 -0
- package/dist/infra/outbox/registry.d.ts +36 -0
- package/dist/infra/outbox/registry.js +30 -0
- package/dist/infra/queue/queue-names.d.ts +1 -1
- package/dist/infra/queue/queue-names.js +1 -0
- package/dist/orgs/offboarding.js +3 -0
- package/dist/overrides.d.ts +4 -0
- package/dist/overrides.js +2 -0
- package/dist/platform/exclusions.js +15 -0
- package/dist/platform/ops/extensions-admin.ops.d.ts +5 -1
- package/dist/platform/ops/extensions-admin.ops.js +97 -2
- package/dist/platform/ops/inbox.ops.d.ts +1 -1
- package/dist/platform/ops/inbox.ops.js +17 -7
- package/dist/platform/ops/platform.ops.d.ts +4 -2
- package/dist/platform/ops/platform.ops.js +55 -3
- package/dist/platform/platform-ops.module.js +2 -0
- package/dist/platform/route-schemas.js +3 -0
- package/dist/push/delivery.d.ts +88 -0
- package/dist/push/delivery.js +269 -0
- package/dist/push/fanout.d.ts +29 -0
- package/dist/push/fanout.js +95 -0
- package/dist/push/jobs.d.ts +43 -0
- package/dist/push/jobs.js +19 -0
- package/dist/push/preferences.service.d.ts +18 -0
- package/dist/push/preferences.service.js +82 -0
- package/dist/push/provider-host.d.ts +34 -0
- package/dist/push/provider-host.js +94 -0
- package/dist/push/push-owed.d.ts +33 -0
- package/dist/push/push-owed.js +93 -0
- package/dist/push/push-processor.d.ts +40 -0
- package/dist/push/push-processor.js +114 -0
- package/dist/push/push.controller.d.ts +28 -0
- package/dist/push/push.controller.js +92 -0
- package/dist/push/push.module.d.ts +6 -0
- package/dist/push/push.module.js +29 -0
- package/dist/push/push.schemas.d.ts +88 -0
- package/dist/push/push.schemas.js +53 -0
- package/dist/push/recipients.d.ts +29 -0
- package/dist/push/recipients.js +263 -0
- package/dist/push/registration-cleanup.d.ts +9 -0
- package/dist/push/registration-cleanup.js +16 -0
- package/dist/push/registrations.service.d.ts +55 -0
- package/dist/push/registrations.service.js +254 -0
- package/dist/push/stale.job.d.ts +25 -0
- package/dist/push/stale.job.js +76 -0
- package/dist/push/texts.d.ts +31 -0
- package/dist/push/texts.js +46 -0
- package/dist/push/token-store.d.ts +31 -0
- package/dist/push/token-store.js +52 -0
- package/dist/push/triggers.d.ts +19 -0
- package/dist/push/triggers.js +30 -0
- package/dist/roles/worker-role.d.ts +7 -4
- package/dist/roles/worker-role.js +12 -5
- package/dist/roles/worker.module.d.ts +1 -1
- package/dist/roles/worker.module.js +4 -1
- package/dist/schedules/run-tracker.d.ts +10 -2
- package/dist/schedules/run-tracker.js +18 -4
- package/dist/setup/setup-checks.schemas.d.ts +29 -0
- package/dist/setup/setup-checks.schemas.js +32 -0
- package/dist/setup/setup-checks.service.d.ts +36 -3
- package/dist/setup/setup-checks.service.js +137 -29
- package/package.json +4 -4
- package/src/migrations/0172_push.sql +40 -0
- package/src/migrations/0173_push_auth_notice.sql +10 -0
|
@@ -13,6 +13,7 @@ import { Inject, Injectable, Optional } from "@nestjs/common";
|
|
|
13
13
|
import { ChannelConnections } from "../channels/connections.service.js";
|
|
14
14
|
import { secretValues } from "../config/fields.js";
|
|
15
15
|
import { ApiError } from "../errors.js";
|
|
16
|
+
import { canonicalJson } from "../extensions/config-hash.js";
|
|
16
17
|
import { EffectiveConfigs } from "../extensions/effective-config.js";
|
|
17
18
|
import { isExtensionEnabled } from "../extensions/enabled.js";
|
|
18
19
|
import { deepFreeze } from "../extensions/hooks.js";
|
|
@@ -54,6 +55,7 @@ const REASONS = {
|
|
|
54
55
|
unavailable: text("Checks are temporarily unavailable; retry later.", "检查暂时不可用,请稍后重试。"),
|
|
55
56
|
notRunning: (plugin) => text(`The ${plugin} plugin is not running on this server right now; retry later.`, `插件 ${plugin} 此刻没有在这台服务器上运行,请稍后重试。`),
|
|
56
57
|
disabled: (plugin) => text(`The ${plugin} plugin is not enabled in this organization; an org admin enables it under Plugins.`, `插件 ${plugin} 没有在本组织启用;组织管理员可以在「插件」里启用。`),
|
|
58
|
+
notRunningDeployment: (plugin) => text(`The ${plugin} extension is not running on this server; check its status and deployment config on this page.`, `扩展 ${plugin} 没有在这台服务器上运行;请在本页面查看它的状态和部署配置。`),
|
|
57
59
|
needsConfig: (plugin) => text(`The ${plugin} plugin needs configuration in this organization; an org admin configures it under Plugins.`, `插件 ${plugin} 需要在本组织完成配置;组织管理员可以在「插件」里配置。`),
|
|
58
60
|
unregistered: text("This check needs a newer version of the plugin.", "这项检查需要更新版本的插件。"),
|
|
59
61
|
otherPlace: text("This check does not apply on this page.", "这项检查不适用于本页面。"),
|
|
@@ -63,6 +65,8 @@ const REASONS = {
|
|
|
63
65
|
targetGone: text("The connection's stored settings could not be read; save them again.", "无法读取这个连接已保存的设置,请重新保存。"),
|
|
64
66
|
};
|
|
65
67
|
const unknownState = (reason) => ({ status: "unknown", reason });
|
|
68
|
+
/** The cache scope of the `extension-deployment` place in Redis keys (an org id elsewhere). */
|
|
69
|
+
const DEPLOYMENT_SCOPE = "deployment";
|
|
66
70
|
/**
|
|
67
71
|
* Whether a check's cache keys and fingerprint carry the caller's account: every check of the
|
|
68
72
|
* member audience, and every kernel check (it gets the caller's account whatever the audience,
|
|
@@ -141,7 +145,29 @@ let SetupChecksService = class SetupChecksService {
|
|
|
141
145
|
* run holds the lock. Redis down: every row `unknown` ("temporarily unavailable").
|
|
142
146
|
*/
|
|
143
147
|
async states(caller, itemId, guideId, q) {
|
|
144
|
-
|
|
148
|
+
return this.statesOf(await this.prepare(caller, itemId, guideId, q));
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* The cached state of every check of an extension's `extension-deployment` guide (`GET
|
|
152
|
+
* /admin/extensions/:name/guides/:guideId/checks`, super admins: the route's guard); nothing
|
|
153
|
+
* runs. Cached for the deployment, shared by every super admin.
|
|
154
|
+
*/
|
|
155
|
+
async deploymentStates(accountId, plugin, guideId) {
|
|
156
|
+
return this.statesOf(await this.prepareDeployment(accountId, plugin, guideId));
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* Runs one check of an extension's `extension-deployment` guide (`POST
|
|
160
|
+
* /admin/extensions/:name/guides/:guideId/checks/:checkId/run`, super admins: the route's
|
|
161
|
+
* guard) with the extension's platform deployment config, `orgId: null`. The cache, single
|
|
162
|
+
* flight, cooldown and concurrency cap are the org places', keyed by the deployment; the
|
|
163
|
+
* per-account limit is shared with every other run. A kernel check (`capybara:*`) does not apply
|
|
164
|
+
* here.
|
|
165
|
+
*/
|
|
166
|
+
async deploymentRun(accountId, plugin, guideId, checkId, body) {
|
|
167
|
+
const p = await this.prepareDeployment(accountId, plugin, guideId, checkId);
|
|
168
|
+
return this.runPrepared(p, checkId, body);
|
|
169
|
+
}
|
|
170
|
+
async statesOf(p) {
|
|
145
171
|
const ids = [...new Set(p.checks)];
|
|
146
172
|
const out = {};
|
|
147
173
|
if (ids.length === 0)
|
|
@@ -195,11 +221,14 @@ let SetupChecksService = class SetupChecksService {
|
|
|
195
221
|
*/
|
|
196
222
|
async run(caller, itemId, guideId, checkId, body) {
|
|
197
223
|
const p = await this.prepare(caller, itemId, guideId, body, checkId);
|
|
224
|
+
return this.runPrepared(p, checkId, body);
|
|
225
|
+
}
|
|
226
|
+
async runPrepared(p, checkId, body) {
|
|
198
227
|
// the per-account budget, for the HTTP route and the Platform tool alike (an answer from the
|
|
199
228
|
// cache counts too); Redis down: nothing runs
|
|
200
229
|
let allowed;
|
|
201
230
|
try {
|
|
202
|
-
allowed = await this.allowRun(
|
|
231
|
+
allowed = await this.allowRun(p.accountId);
|
|
203
232
|
}
|
|
204
233
|
catch (err) {
|
|
205
234
|
this.log.warn("setup checks: Redis unavailable", { err: describeCheckError(err, (s) => s) });
|
|
@@ -209,10 +238,11 @@ let SetupChecksService = class SetupChecksService {
|
|
|
209
238
|
throw new ApiError("rate_limited", "Too many setup check runs; try again in a minute");
|
|
210
239
|
}
|
|
211
240
|
// a plugin check: the extension must run here, be on in the org and have a valid effective
|
|
212
|
-
// config
|
|
241
|
+
// config (the deployment: run here, its loaded deployment config) before its registration is
|
|
242
|
+
// even looked at (nothing is called otherwise)
|
|
213
243
|
let config;
|
|
214
244
|
if (!checkId.startsWith("capybara:")) {
|
|
215
|
-
const gate = await this.pluginGate(
|
|
245
|
+
const gate = p.orgId === null ? this.deploymentGate(p.plugin) : await this.pluginGate(p.orgId, p.plugin);
|
|
216
246
|
if ("state" in gate)
|
|
217
247
|
return gate.state;
|
|
218
248
|
config = gate.config;
|
|
@@ -222,6 +252,9 @@ let SetupChecksService = class SetupChecksService {
|
|
|
222
252
|
return unknownState(REASONS.unregistered);
|
|
223
253
|
if (check.place !== "any" && check.place !== p.place)
|
|
224
254
|
return unknownState(REASONS.otherPlace);
|
|
255
|
+
// kernel checks are about an org's targets; the deployment has none
|
|
256
|
+
if (check.source === "kernel" && p.orgId === null)
|
|
257
|
+
return unknownState(REASONS.otherPlace);
|
|
225
258
|
const keys = this.keys(p, checkId);
|
|
226
259
|
const revision = await this.revision(p, accountScoped(p, checkId));
|
|
227
260
|
const fingerprint = this.fingerprint(p, revision);
|
|
@@ -242,7 +275,7 @@ let SetupChecksService = class SetupChecksService {
|
|
|
242
275
|
return stateOf(fresh.result, fresh.checkedAt, new Date(Date.now() + cooldownMs).toISOString());
|
|
243
276
|
}
|
|
244
277
|
const token = randomUUID();
|
|
245
|
-
const orgSlots = `capk:setup-check-org:${
|
|
278
|
+
const orgSlots = `capk:setup-check-org:${p.orgId ?? DEPLOYMENT_SCOPE}`;
|
|
246
279
|
let locked = false;
|
|
247
280
|
let slot = false;
|
|
248
281
|
try {
|
|
@@ -306,7 +339,8 @@ let SetupChecksService = class SetupChecksService {
|
|
|
306
339
|
]);
|
|
307
340
|
}
|
|
308
341
|
return {
|
|
309
|
-
caller,
|
|
342
|
+
orgId: caller.orgId,
|
|
343
|
+
accountId: caller.accountId,
|
|
310
344
|
plugin: guide.plugin,
|
|
311
345
|
itemId: guide.itemId,
|
|
312
346
|
version: guide.version,
|
|
@@ -319,6 +353,43 @@ let SetupChecksService = class SetupChecksService {
|
|
|
319
353
|
perAccount: guide.audience === "member",
|
|
320
354
|
};
|
|
321
355
|
}
|
|
356
|
+
/**
|
|
357
|
+
* The deployment guide (`PluginGuides.renderForDeployment`: the extension's catalog item has an
|
|
358
|
+
* `extension-deployment` guide with that id, else 404), then the check's presence in it (404
|
|
359
|
+
* `catalog.check_not_found`). The caller is a super admin (the route's and the operation's
|
|
360
|
+
* guard); the target is the plugin's own deployment.
|
|
361
|
+
*/
|
|
362
|
+
async prepareDeployment(accountId, plugin, guideId, checkId) {
|
|
363
|
+
const guide = await this.guides.renderForDeployment(plugin, guideId, { locale: "en" });
|
|
364
|
+
const checks = guide.checks.map((c) => c.id);
|
|
365
|
+
if (checkId !== undefined && !checks.includes(checkId)) {
|
|
366
|
+
throw new ApiError("catalog.check_not_found", "The check is not in this setup guide");
|
|
367
|
+
}
|
|
368
|
+
return {
|
|
369
|
+
orgId: null,
|
|
370
|
+
accountId,
|
|
371
|
+
plugin: guide.plugin,
|
|
372
|
+
itemId: guide.itemId,
|
|
373
|
+
version: guide.version,
|
|
374
|
+
place: guide.place,
|
|
375
|
+
template: null,
|
|
376
|
+
mode: null,
|
|
377
|
+
audience: "admin",
|
|
378
|
+
target: { kind: "extension-deployment", id: guide.plugin },
|
|
379
|
+
checks,
|
|
380
|
+
perAccount: false,
|
|
381
|
+
};
|
|
382
|
+
}
|
|
383
|
+
/**
|
|
384
|
+
* A deployment check runs only where its extension runs on this replica (so its deployment
|
|
385
|
+
* config is valid and loaded): that config, as the extension's `ctx.config` holds it.
|
|
386
|
+
*/
|
|
387
|
+
deploymentGate(plugin) {
|
|
388
|
+
const inst = this.extensions.current(plugin);
|
|
389
|
+
if (!inst)
|
|
390
|
+
return { state: unknownState(REASONS.notRunningDeployment(plugin)) };
|
|
391
|
+
return { config: inst.config };
|
|
392
|
+
}
|
|
322
393
|
/**
|
|
323
394
|
* A plugin check runs only where its extension runs on this replica, is enabled in the org and
|
|
324
395
|
* has a valid effective config there (nothing is called otherwise): the effective config, or the
|
|
@@ -341,13 +412,13 @@ let SetupChecksService = class SetupChecksService {
|
|
|
341
412
|
/** The Redis keys of a check of the prepared target (spec §10.7). */
|
|
342
413
|
keys(p, checkId) {
|
|
343
414
|
const base = [
|
|
344
|
-
p.
|
|
415
|
+
p.orgId ?? DEPLOYMENT_SCOPE,
|
|
345
416
|
p.target.kind,
|
|
346
417
|
p.target.id,
|
|
347
418
|
p.plugin,
|
|
348
419
|
checkId,
|
|
349
420
|
p.mode ?? "-",
|
|
350
|
-
...(accountScoped(p, checkId) ? [p.
|
|
421
|
+
...(accountScoped(p, checkId) ? [p.accountId] : []),
|
|
351
422
|
].join(":");
|
|
352
423
|
return {
|
|
353
424
|
result: `capk:setup-check:${base}`,
|
|
@@ -357,39 +428,51 @@ let SetupChecksService = class SetupChecksService {
|
|
|
357
428
|
}
|
|
358
429
|
/**
|
|
359
430
|
* The input revision of a prepared target (spec §10.4): the target's and its credentials'
|
|
360
|
-
* `updated_at`, the org's extension config and copy revisions; never a value.
|
|
431
|
+
* `updated_at`, the org's extension config and copy revisions; never a value. The deployment's:
|
|
432
|
+
* a keyed digest of the extension's loaded deployment config.
|
|
361
433
|
*/
|
|
362
434
|
async revision(p, scoped) {
|
|
435
|
+
// the deployment's only input is its loaded config, secrets included: the loaded config
|
|
436
|
+
// digest (`configHash`) leaves secrets out, and a replaced key must not answer from the cache.
|
|
437
|
+
// A keyed HMAC of it, so the revision can neither be reversed nor confirm a guessed secret
|
|
438
|
+
if (p.orgId === null) {
|
|
439
|
+
const loaded = this.extensions.current(p.plugin)?.config;
|
|
440
|
+
return createHmac("sha256", this.keyring.deriveKey("setup-check-fingerprint").current)
|
|
441
|
+
.update(`${DEPLOYMENT_SCOPE}\0${canonicalJson(loaded ?? null)}`)
|
|
442
|
+
.digest("hex");
|
|
443
|
+
}
|
|
444
|
+
const orgId = p.orgId;
|
|
445
|
+
const op = { ...p, orgId };
|
|
363
446
|
const target = p.target.kind === "channel-connection"
|
|
364
|
-
? await this.channelRevision(
|
|
365
|
-
: await this.connectorRevision(
|
|
447
|
+
? await this.channelRevision(op)
|
|
448
|
+
: await this.connectorRevision(op, scoped);
|
|
366
449
|
const org = await this.db
|
|
367
450
|
.selectFrom("extension_org_configs")
|
|
368
451
|
.select("updated_at")
|
|
369
|
-
.where("org_id", "=",
|
|
452
|
+
.where("org_id", "=", orgId)
|
|
370
453
|
.where("plugin", "=", p.plugin)
|
|
371
454
|
.executeTakeFirst();
|
|
372
455
|
const copy = await this.db
|
|
373
456
|
.selectFrom("extension_org_overrides")
|
|
374
457
|
.select("updated_at")
|
|
375
|
-
.where("org_id", "=",
|
|
458
|
+
.where("org_id", "=", orgId)
|
|
376
459
|
.where("plugin", "=", p.plugin)
|
|
377
460
|
.executeTakeFirst();
|
|
378
461
|
const iso = (d) => d === undefined ? "-" : new Date(d).toISOString();
|
|
379
462
|
return [target, iso(org?.updated_at), iso(copy?.updated_at)].join("|");
|
|
380
463
|
}
|
|
381
464
|
channelRevision(p) {
|
|
382
|
-
return this.channels.checkRevision(p.
|
|
465
|
+
return this.channels.checkRevision(p.orgId, p.plugin, p.target.id);
|
|
383
466
|
}
|
|
384
467
|
async connectorRevision(p, scoped) {
|
|
385
468
|
const row = await this.db
|
|
386
469
|
.selectFrom("connectors")
|
|
387
470
|
.select("updated_at")
|
|
388
471
|
.where("id", "=", p.target.id)
|
|
389
|
-
.where("org_id", "=", p.
|
|
472
|
+
.where("org_id", "=", p.orgId)
|
|
390
473
|
.executeTakeFirst();
|
|
391
474
|
// the client and org credential rows, and the caller's own row for account-scoped checks
|
|
392
|
-
const creds = await this.credentials.checkRevision(p.
|
|
475
|
+
const creds = await this.credentials.checkRevision(p.orgId, p.target.id, scoped ? p.accountId : null);
|
|
393
476
|
return `${row ? new Date(row.updated_at).toISOString() : "-"}|${creds}`;
|
|
394
477
|
}
|
|
395
478
|
/**
|
|
@@ -445,25 +528,29 @@ let SetupChecksService = class SetupChecksService {
|
|
|
445
528
|
const secrets = [
|
|
446
529
|
...material.secrets,
|
|
447
530
|
...this.configSecrets(p.plugin, config),
|
|
448
|
-
...(await this.orgConfigSecrets(p.
|
|
531
|
+
...(p.orgId === null ? [] : await this.orgConfigSecrets(p.orgId, p.plugin)),
|
|
449
532
|
];
|
|
450
533
|
const redact = checkRedactor(secrets);
|
|
451
|
-
const fields = { plugin: p.plugin, checkId: check.id, orgId: p.
|
|
534
|
+
const fields = { plugin: p.plugin, checkId: check.id, orgId: p.orgId };
|
|
452
535
|
const timeout = AbortSignal.timeout(this.timeoutMs);
|
|
453
536
|
let answer;
|
|
454
537
|
if (check.source === "plugin") {
|
|
455
538
|
const signal = AbortSignal.any([timeout, check.signal]);
|
|
456
|
-
// the org's language: a result is cached for every viewer of the org
|
|
457
|
-
|
|
539
|
+
// the org's language: a result is cached for every viewer of the org (the deployment's for
|
|
540
|
+
// every super admin, in English; a result carries both languages when the plugin wrote them)
|
|
541
|
+
const locale = p.orgId === null ? "en" : (await readOrgSettings(this.db.db, p.orgId)).locale;
|
|
458
542
|
answer = await raceSignal(signal,
|
|
459
543
|
// the in-flight tracker merges the instance's abort into the signal the check gets
|
|
460
544
|
() => check.inflight.run(signal, (s) => check.run(this.pluginArgs(p, material, config, locale, s))), () => (check.signal.aborted ? "unloaded" : "timeout"));
|
|
461
545
|
}
|
|
462
546
|
else {
|
|
547
|
+
// refused for the deployment before the lock (`runPrepared`)
|
|
548
|
+
if (p.orgId === null)
|
|
549
|
+
throw new Error("a kernel check has no deployment target");
|
|
463
550
|
const signal = timeout;
|
|
464
551
|
const args = Object.freeze({
|
|
465
|
-
orgId: p.
|
|
466
|
-
accountId: p.
|
|
552
|
+
orgId: p.orgId,
|
|
553
|
+
accountId: p.accountId,
|
|
467
554
|
mode: p.mode,
|
|
468
555
|
target: kernelTarget(p, material),
|
|
469
556
|
signal,
|
|
@@ -505,11 +592,15 @@ let SetupChecksService = class SetupChecksService {
|
|
|
505
592
|
* The target material: for a channel connection its revision and stored secret values (and, for
|
|
506
593
|
* a plugin check, the connection config decrypted exactly as `channel@1` verify gets it); for a
|
|
507
594
|
* connector its credentials' values (redaction only), the manual OAuth client id and the
|
|
508
|
-
* template id
|
|
595
|
+
* template id; for the deployment nothing (its config's secrets are added by the caller). A
|
|
596
|
+
* `result` when the material cannot be read (the check is not called).
|
|
509
597
|
*/
|
|
510
598
|
async material(p, check) {
|
|
599
|
+
if (p.orgId === null)
|
|
600
|
+
return { secrets: [] };
|
|
601
|
+
const orgId = p.orgId;
|
|
511
602
|
if (p.target.kind === "channel-connection") {
|
|
512
|
-
const stored = await this.channels.checkSecrets(
|
|
603
|
+
const stored = await this.channels.checkSecrets(orgId, p.plugin, p.target.id);
|
|
513
604
|
if (check.source === "kernel")
|
|
514
605
|
return { secrets: stored };
|
|
515
606
|
let rt;
|
|
@@ -529,7 +620,7 @@ let SetupChecksService = class SetupChecksService {
|
|
|
529
620
|
throw err;
|
|
530
621
|
}
|
|
531
622
|
// the connection of this org on the check's plugin only (render checked it; checked again)
|
|
532
|
-
if (rt.row.orgId !==
|
|
623
|
+
if (rt.row.orgId !== orgId || rt.row.plugin !== p.plugin) {
|
|
533
624
|
throw new ApiError("channel.not_found", "Channel connection not found");
|
|
534
625
|
}
|
|
535
626
|
return {
|
|
@@ -546,7 +637,7 @@ let SetupChecksService = class SetupChecksService {
|
|
|
546
637
|
.innerJoin("platform_connector_templates as t", "t.id", "c.platform_template_id")
|
|
547
638
|
.select(["c.auth", "t.template_id"])
|
|
548
639
|
.where("c.id", "=", p.target.id)
|
|
549
|
-
.where("c.org_id", "=",
|
|
640
|
+
.where("c.org_id", "=", orgId)
|
|
550
641
|
.where("c.deleted_at", "is", null)
|
|
551
642
|
.where("t.catalog_item_id", "=", p.itemId)
|
|
552
643
|
.where("t.template_id", "=", p.template)
|
|
@@ -555,7 +646,7 @@ let SetupChecksService = class SetupChecksService {
|
|
|
555
646
|
if (!row)
|
|
556
647
|
throw new ApiError("connector.not_found", "Connector not found");
|
|
557
648
|
const auth = row.auth;
|
|
558
|
-
const m = await this.credentials.checkMaterial(
|
|
649
|
+
const m = await this.credentials.checkMaterial(orgId, p.target.id);
|
|
559
650
|
const manual = auth.type === "oauth_code" && auth.client === "manual";
|
|
560
651
|
return {
|
|
561
652
|
secrets: m.secrets,
|
|
@@ -589,6 +680,23 @@ let SetupChecksService = class SetupChecksService {
|
|
|
589
680
|
}
|
|
590
681
|
/** The frozen arguments of a plugin check (the target built field by field). */
|
|
591
682
|
pluginArgs(p, m, config, locale, signal) {
|
|
683
|
+
if (p.orgId === null) {
|
|
684
|
+
// the extension's own deployment config, as its ctx.config holds it, in a frozen copy: what
|
|
685
|
+
// the check gets cannot change the kernel's object or another call's
|
|
686
|
+
const own = deepFreeze(structuredClone(config));
|
|
687
|
+
return Object.freeze({
|
|
688
|
+
orgId: null,
|
|
689
|
+
config: own,
|
|
690
|
+
locale,
|
|
691
|
+
mode: null,
|
|
692
|
+
target: Object.freeze({
|
|
693
|
+
kind: "extension-deployment",
|
|
694
|
+
plugin: p.plugin,
|
|
695
|
+
config: own,
|
|
696
|
+
}),
|
|
697
|
+
signal,
|
|
698
|
+
});
|
|
699
|
+
}
|
|
592
700
|
const target = p.target.kind === "channel-connection"
|
|
593
701
|
? Object.freeze({
|
|
594
702
|
kind: "channel-connection",
|
|
@@ -600,10 +708,10 @@ let SetupChecksService = class SetupChecksService {
|
|
|
600
708
|
connectorId: p.target.id,
|
|
601
709
|
templateId: m.templateId ?? "",
|
|
602
710
|
clientId: m.clientId ?? null,
|
|
603
|
-
accountId: p.perAccount ? p.
|
|
711
|
+
accountId: p.perAccount ? p.accountId : null,
|
|
604
712
|
});
|
|
605
713
|
return Object.freeze({
|
|
606
|
-
orgId: p.
|
|
714
|
+
orgId: p.orgId,
|
|
607
715
|
config,
|
|
608
716
|
locale,
|
|
609
717
|
mode: p.mode,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@capybara-hq/kernel",
|
|
3
|
-
"version": "0.1.0-rc.
|
|
3
|
+
"version": "0.1.0-rc.62",
|
|
4
4
|
"description": "Capybara kernel: config, database, plugin host and HTTP API of the Capybara agent platform",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"repository": {
|
|
@@ -66,7 +66,7 @@
|
|
|
66
66
|
"yaml": "^2.9.1",
|
|
67
67
|
"yauzl": "3.4.0",
|
|
68
68
|
"zod": "^4.6.7",
|
|
69
|
-
"@capybara-hq/plugin-sdk": "^0.1.0-rc.
|
|
69
|
+
"@capybara-hq/plugin-sdk": "^0.1.0-rc.47"
|
|
70
70
|
},
|
|
71
71
|
"devDependencies": {
|
|
72
72
|
"@langchain/langgraph-checkpoint-validation": "^1.2.0",
|
|
@@ -75,8 +75,8 @@
|
|
|
75
75
|
"@types/ws": "^8.18.2",
|
|
76
76
|
"@types/yauzl": "3.4.0",
|
|
77
77
|
"ws": "^8.22.0",
|
|
78
|
-
"@capybara-hq/device": "0.1.0-rc.
|
|
79
|
-
"@capybara-hq/testing": "0.1.0-rc.
|
|
78
|
+
"@capybara-hq/device": "0.1.0-rc.25",
|
|
79
|
+
"@capybara-hq/testing": "0.1.0-rc.30"
|
|
80
80
|
},
|
|
81
81
|
"scripts": {
|
|
82
82
|
"build": "tsc -b"
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
-- Push notifications (spec 2026-11-20-mobile-app-design.md §9.3): a person's mobile app
|
|
2
|
+
-- registrations and their per-category push preferences. Expand-only.
|
|
3
|
+
--
|
|
4
|
+
-- A registration belongs to the account, not an org: one serves every org the person is in. It
|
|
5
|
+
-- records the session that posted it (revoking that session deletes it). The device's push token
|
|
6
|
+
-- is sealed with the master keyring (AES-256-GCM, AAD `capybara:push-token:<id>`, so a ciphertext
|
|
7
|
+
-- moved to another row fails to unwrap) and is unique per channel and app through its sha256 hash;
|
|
8
|
+
-- `capybara secrets rewrap` rewraps it after a master key rotation. A registration not seen for 60
|
|
9
|
+
-- days is deleted by a locked daily job (index on last_seen_at).
|
|
10
|
+
CREATE TABLE IF NOT EXISTS capybara.push_registrations (
|
|
11
|
+
id text PRIMARY KEY,
|
|
12
|
+
account_id text NOT NULL REFERENCES capybara.accounts(id) ON DELETE CASCADE,
|
|
13
|
+
session_id text REFERENCES capybara.sessions(id) ON DELETE SET NULL,
|
|
14
|
+
platform text NOT NULL CHECK (platform IN ('ios', 'android')),
|
|
15
|
+
app_id text NOT NULL,
|
|
16
|
+
provider text NOT NULL,
|
|
17
|
+
token_hash text NOT NULL,
|
|
18
|
+
master_key_id text NOT NULL,
|
|
19
|
+
token_ciphertext bytea NOT NULL,
|
|
20
|
+
locale text NOT NULL CHECK (locale IN ('zh', 'en')),
|
|
21
|
+
device_name text NOT NULL,
|
|
22
|
+
created_at timestamptz NOT NULL DEFAULT now(),
|
|
23
|
+
last_seen_at timestamptz NOT NULL DEFAULT now(),
|
|
24
|
+
UNIQUE (provider, app_id, token_hash)
|
|
25
|
+
);
|
|
26
|
+
CREATE INDEX IF NOT EXISTS push_registrations_account_idx
|
|
27
|
+
ON capybara.push_registrations (account_id);
|
|
28
|
+
CREATE INDEX IF NOT EXISTS push_registrations_session_idx
|
|
29
|
+
ON capybara.push_registrations (session_id) WHERE session_id IS NOT NULL;
|
|
30
|
+
CREATE INDEX IF NOT EXISTS push_registrations_last_seen_idx
|
|
31
|
+
ON capybara.push_registrations (last_seen_at);
|
|
32
|
+
|
|
33
|
+
-- One row per category the person switched; an absent row means the category is on.
|
|
34
|
+
CREATE TABLE IF NOT EXISTS capybara.push_preferences (
|
|
35
|
+
account_id text NOT NULL REFERENCES capybara.accounts(id) ON DELETE CASCADE,
|
|
36
|
+
category text NOT NULL CHECK (category IN ('waiting', 'replies', 'tasks', 'schedules')),
|
|
37
|
+
enabled boolean NOT NULL,
|
|
38
|
+
updated_at timestamptz NOT NULL DEFAULT now(),
|
|
39
|
+
PRIMARY KEY (account_id, category)
|
|
40
|
+
);
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
-- The platform notice `push_auth_failed` (mobile app spec §9.2, push plan task C6): a push
|
|
2
|
+
-- provider's credentials were refused on a delivery, so the super admins are told. Expand-only:
|
|
3
|
+
-- the kind check widens, and a partial unique index keeps at most one open notice per plugin, so
|
|
4
|
+
-- deliveries failing on several replicas at once insert one (`ON CONFLICT DO NOTHING`).
|
|
5
|
+
ALTER TABLE platform_notices DROP CONSTRAINT IF EXISTS platform_notices_kind_check;
|
|
6
|
+
ALTER TABLE platform_notices ADD CONSTRAINT platform_notices_kind_check
|
|
7
|
+
CHECK (kind IN ('ownership_transferred', 'push_auth_failed'));
|
|
8
|
+
CREATE UNIQUE INDEX IF NOT EXISTS platform_notices_push_auth_open_idx
|
|
9
|
+
ON platform_notices ((detail ->> 'plugin'))
|
|
10
|
+
WHERE kind = 'push_auth_failed' AND dismissed_at IS NULL;
|