@capybara-hq/kernel 0.1.0-rc.80 → 0.1.0-rc.82
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/bootstrap.json +29 -29
- package/dist/admin/outbox-dead.service.js +133 -120
- package/dist/background/store.js +78 -67
- package/dist/background/tasks.service.d.ts +6 -0
- package/dist/background/tasks.service.js +3 -0
- package/dist/catalog/marketplaces.service.d.ts +1 -1
- package/dist/catalog/plugin-import.js +45 -40
- package/dist/catalog/scope-sync-workers.js +3 -0
- package/dist/channels/inbound.d.ts +6 -1
- package/dist/channels/inbound.js +18 -1
- package/dist/client/client-reports.service.js +9 -6
- package/dist/config/schema.d.ts +5 -0
- package/dist/config/schema.js +6 -0
- package/dist/conversations/attachments.service.js +101 -96
- package/dist/conversations/events.d.ts +7 -0
- package/dist/conversations/events.js +9 -0
- package/dist/ctx/bus.js +5 -3
- package/dist/ctx/queue.js +4 -2
- package/dist/db/pool.d.ts +6 -0
- package/dist/db/pool.js +3 -2
- package/dist/devices/legacy-cleanup.job.js +73 -70
- package/dist/dial-in/gateway.d.ts +8 -0
- package/dist/dial-in/gateway.js +22 -2
- package/dist/extensions/admin-ops.js +22 -19
- package/dist/extensions/lifecycle-hooks.js +3 -1
- package/dist/http/app.js +3 -1
- package/dist/http/plugin-dispatch.js +8 -0
- package/dist/identity/auth.guard.js +13 -3
- package/dist/index.d.ts +2 -0
- package/dist/index.js +1 -0
- package/dist/infra/database/database.module.js +1 -0
- package/dist/infra/database/org-scope.d.ts +59 -0
- package/dist/infra/database/org-scope.js +68 -0
- package/dist/infra/database/rls-role.d.ts +11 -0
- package/dist/infra/database/rls-role.js +33 -0
- package/dist/infra/database/scoped-dialect.d.ts +18 -0
- package/dist/infra/database/scoped-dialect.js +245 -0
- package/dist/infra/outbox/outbox.dispatcher.js +98 -90
- package/dist/infra/outbox/outbox.service.js +29 -26
- package/dist/infra/queue/run-job.d.ts +8 -2
- package/dist/infra/queue/run-job.js +16 -3
- package/dist/infra/schedule/locked-tick.js +12 -4
- package/dist/infra/schedule/scheduled-runs.js +3 -1
- package/dist/lifecycle/kernel-lifecycle.d.ts +1 -0
- package/dist/lifecycle/kernel-lifecycle.js +16 -1
- package/dist/orgs/org.guard.js +4 -0
- package/dist/platform/sealed-reveals.js +9 -6
- package/dist/runtime/maintenance.js +6 -1
- package/dist/runtime/run-execution.d.ts +1 -0
- package/dist/runtime/run-execution.js +5 -0
- package/dist/runtime/run-orphan-check.job.js +20 -15
- package/dist/sandbox/legacy-retirement.js +438 -397
- package/dist/sandbox/modes.d.ts +10 -0
- package/dist/sandbox/modes.js +23 -0
- package/dist/sandbox/operation-reconcile.job.d.ts +14 -1
- package/dist/sandbox/operation-reconcile.job.js +35 -3
- package/dist/sandbox/permission-config-publication.js +83 -77
- package/dist/sandbox/sandbox.service.d.ts +24 -0
- package/dist/sandbox/sandbox.service.js +159 -62
- package/dist/schedules/store.js +17 -14
- package/dist/tools/builtins/sandbox/bash.js +16 -1
- package/dist/tools/drift.js +31 -24
- package/dist/tools/outputs.js +20 -17
- package/package.json +2 -2
- package/src/migrations/0182_rls_policies.sql +202 -0
package/dist/background/store.js
CHANGED
|
@@ -10,6 +10,7 @@ var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
|
10
10
|
import { Inject, Injectable } from "@nestjs/common";
|
|
11
11
|
import { sql } from "kysely";
|
|
12
12
|
import { KernelDb } from "../infra/database/kernel-db.js";
|
|
13
|
+
import { asPlatform } from "../infra/database/org-scope.js";
|
|
13
14
|
import { TransactionHost } from "../infra/database/transaction-host.js";
|
|
14
15
|
import { Transactional } from "../infra/database/transactional.decorator.js";
|
|
15
16
|
import { BackgroundLaunchLock } from "./launch-lock.js";
|
|
@@ -196,30 +197,32 @@ let BackgroundTaskStore = class BackgroundTaskStore {
|
|
|
196
197
|
// org-filter: deployment-wide background-task poller sweep across all orgs; each row is
|
|
197
198
|
// handled in its own org
|
|
198
199
|
async failAbandonedLaunches(before) {
|
|
199
|
-
|
|
200
|
-
.
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
200
|
+
return asPlatform("deployment-wide background-task poller sweep across all orgs", async () => {
|
|
201
|
+
const r = await this.db
|
|
202
|
+
.updateTable("background_tasks")
|
|
203
|
+
.set({
|
|
204
|
+
status: "failed",
|
|
205
|
+
finished_at: sql `now()`,
|
|
206
|
+
lost_reason: "launch_abandoned",
|
|
207
|
+
stopping_at: null,
|
|
208
|
+
// a managed reservation that never dispatched settles; dispatch is conditional on
|
|
209
|
+
// `pending`, so a launch racing this update either wins or is refused before effects
|
|
210
|
+
launch_state: sql `CASE WHEN launch_state = 'pending' THEN 'terminal' ELSE launch_state END`,
|
|
211
|
+
})
|
|
212
|
+
.where("status", "=", "running")
|
|
213
|
+
.where("sid", "is", null)
|
|
214
|
+
// never a dispatched, acknowledged or cancel-pending managed task
|
|
215
|
+
.where("launch_state", "in", ["legacy", "pending"])
|
|
216
|
+
.where(unclaimed)
|
|
217
|
+
.where("started_at", "<", before)
|
|
218
|
+
.returning(["id", "conversation_id", "sandbox_conversation_id"])
|
|
219
|
+
.execute();
|
|
220
|
+
return r.map((x) => ({
|
|
221
|
+
id: x.id,
|
|
222
|
+
conversationId: x.conversation_id,
|
|
223
|
+
sandboxConversationId: x.sandbox_conversation_id,
|
|
224
|
+
}));
|
|
225
|
+
});
|
|
223
226
|
}
|
|
224
227
|
/**
|
|
225
228
|
* Inserts a legacy row: no launch writes one any more; only rows from before (and tests of their
|
|
@@ -308,17 +311,19 @@ let BackgroundTaskStore = class BackgroundTaskStore {
|
|
|
308
311
|
// org-filter: deployment-wide background-task poller sweep across all orgs; each row is
|
|
309
312
|
// handled in its own org
|
|
310
313
|
async runningLegacy() {
|
|
311
|
-
|
|
312
|
-
.
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
314
|
+
return asPlatform("deployment-wide background-task poller sweep across all orgs", async () => {
|
|
315
|
+
const rows = await this.db
|
|
316
|
+
.selectFrom("background_tasks")
|
|
317
|
+
.selectAll()
|
|
318
|
+
.where("status", "=", "running")
|
|
319
|
+
.where("launch_state", "=", "legacy")
|
|
320
|
+
.where("sandbox_created_at", "is not", null)
|
|
321
|
+
.where(unclaimed)
|
|
322
|
+
.orderBy("started_at", "asc")
|
|
323
|
+
.orderBy("id", "asc")
|
|
324
|
+
.execute();
|
|
325
|
+
return rows.map(toRow);
|
|
326
|
+
});
|
|
322
327
|
}
|
|
323
328
|
/**
|
|
324
329
|
* Every running acknowledged managed task with no live stop claim, oldest first: what the
|
|
@@ -327,17 +332,19 @@ let BackgroundTaskStore = class BackgroundTaskStore {
|
|
|
327
332
|
// org-filter: deployment-wide background-task poller sweep across all orgs; each row is
|
|
328
333
|
// handled in its own org
|
|
329
334
|
async runningManaged() {
|
|
330
|
-
|
|
331
|
-
.
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
335
|
+
return asPlatform("deployment-wide background-task poller sweep across all orgs", async () => {
|
|
336
|
+
const rows = await this.db
|
|
337
|
+
.selectFrom("background_tasks")
|
|
338
|
+
.selectAll()
|
|
339
|
+
.where("status", "=", "running")
|
|
340
|
+
.where("launch_state", "=", "acknowledged")
|
|
341
|
+
.where("execution_ref", "is not", null)
|
|
342
|
+
.where(unclaimed)
|
|
343
|
+
.orderBy("started_at", "asc")
|
|
344
|
+
.orderBy("id", "asc")
|
|
345
|
+
.execute();
|
|
346
|
+
return rows.map(toRow);
|
|
347
|
+
});
|
|
341
348
|
}
|
|
342
349
|
/**
|
|
343
350
|
* The running managed tasks that owe an exact stop (`cancel-pending` with a ref, no live stop
|
|
@@ -347,20 +354,22 @@ let BackgroundTaskStore = class BackgroundTaskStore {
|
|
|
347
354
|
// org-filter: deployment-wide background-task poller sweep across all orgs; each row is
|
|
348
355
|
// handled in its own org
|
|
349
356
|
async owedCancels() {
|
|
350
|
-
|
|
351
|
-
.
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
357
|
+
return asPlatform("deployment-wide background-task poller sweep across all orgs", async () => {
|
|
358
|
+
const rows = await this.db
|
|
359
|
+
.selectFrom("background_tasks")
|
|
360
|
+
.selectAll("background_tasks")
|
|
361
|
+
.leftJoin("device_instances", "device_instances.device_id", "background_tasks.device_id")
|
|
362
|
+
.where("background_tasks.status", "=", "running")
|
|
363
|
+
.where("background_tasks.launch_state", "=", "cancel-pending")
|
|
364
|
+
.where("background_tasks.execution_ref", "is not", null)
|
|
365
|
+
.where(sql `(background_tasks.stopping_at IS NULL OR background_tasks.stopping_at < now() - ${STOP_CLAIM_TTL_MS}::integer * interval '1 millisecond')`)
|
|
366
|
+
.where(sql `NOT (device_instances.status IS NOT DISTINCT FROM 'suspended' AND floor(extract(epoch from device_instances.created_at) * 1000)::bigint::text = background_tasks.instance_generation)`)
|
|
367
|
+
.orderBy(sql `background_tasks.cancel_attempted_at ASC NULLS FIRST`)
|
|
368
|
+
.orderBy("background_tasks.started_at", "asc")
|
|
369
|
+
.orderBy("background_tasks.id", "asc")
|
|
370
|
+
.execute();
|
|
371
|
+
return rows.map(toRow);
|
|
372
|
+
});
|
|
364
373
|
}
|
|
365
374
|
/** Records that an exact stop of the task is being attempted now (its owed-stop turn moves back). */
|
|
366
375
|
// org-filter: by task id: callers check ownership first (ownedTask: the calling conversation;
|
|
@@ -524,13 +533,15 @@ let BackgroundTaskStore = class BackgroundTaskStore {
|
|
|
524
533
|
*/
|
|
525
534
|
// org-filter: deployment-wide retention sweep across all orgs (finished rows past their age)
|
|
526
535
|
async pruneFinished(before) {
|
|
527
|
-
|
|
528
|
-
.
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
536
|
+
return asPlatform("deployment-wide retention sweep across all orgs", async () => {
|
|
537
|
+
const r = await this.db
|
|
538
|
+
.deleteFrom("background_tasks")
|
|
539
|
+
.where("status", "<>", "running")
|
|
540
|
+
.where("launch_state", "in", ["legacy", "terminal"])
|
|
541
|
+
.where("finished_at", "<", before)
|
|
542
|
+
.executeTakeFirst();
|
|
543
|
+
return Number(r.numDeletedRows);
|
|
544
|
+
});
|
|
534
545
|
}
|
|
535
546
|
};
|
|
536
547
|
__decorate([
|
|
@@ -26,6 +26,12 @@ export interface BackgroundTaskView {
|
|
|
26
26
|
finishedAt: string | null;
|
|
27
27
|
/** True while a stop has claimed the task and it is still running. */
|
|
28
28
|
stopping: boolean;
|
|
29
|
+
/**
|
|
30
|
+
* True while the task's start was sent but not yet confirmed (a managed launch without its
|
|
31
|
+
* exact ref, still `running`): the kernel is reconciling it under its original identity, and it
|
|
32
|
+
* either becomes a confirmed running task or ends (`lost` when given up).
|
|
33
|
+
*/
|
|
34
|
+
starting: boolean;
|
|
29
35
|
}
|
|
30
36
|
/**
|
|
31
37
|
* Why a task's output cannot be read live: `starting` (the start has not been acknowledged with
|
|
@@ -90,6 +90,9 @@ let BackgroundTasks = class BackgroundTasks {
|
|
|
90
90
|
// a managed task's owed cancellation is a stop in progress too
|
|
91
91
|
stopping: task.status === "running" &&
|
|
92
92
|
(task.stoppingAt !== null || task.launchState === "cancel-pending"),
|
|
93
|
+
starting: task.status === "running" &&
|
|
94
|
+
task.executionRef === null &&
|
|
95
|
+
(task.launchState === "pending" || task.launchState === "dispatched"),
|
|
93
96
|
};
|
|
94
97
|
}
|
|
95
98
|
async owned(orgId, conversationId, accountId, taskId) {
|
|
@@ -208,7 +208,7 @@ export declare function headsToResolve(entries: readonly MarketplaceEntry[], imp
|
|
|
208
208
|
/** The host versions (an entry's `minKernel` is judged against them). */
|
|
209
209
|
export declare const HOST_VERSIONS: {
|
|
210
210
|
readonly kernel: string;
|
|
211
|
-
readonly sdk: "0.1.0-rc.
|
|
211
|
+
readonly sdk: "0.1.0-rc.68";
|
|
212
212
|
};
|
|
213
213
|
/** Whether this deployment satisfies the entry's `minKernel`. */
|
|
214
214
|
export declare const entryCompatible: (e: Pick<MarketplaceEntry, "minKernel">) => boolean;
|
|
@@ -32,6 +32,7 @@ import { SuperAdminLock } from "../identity/super-admin.js";
|
|
|
32
32
|
import { KernelConfigService } from "../infra/config/kernel-config.service.js";
|
|
33
33
|
import { afterCommit } from "../infra/database/after-commit.js";
|
|
34
34
|
import { KernelDb } from "../infra/database/kernel-db.js";
|
|
35
|
+
import { asPlatform } from "../infra/database/org-scope.js";
|
|
35
36
|
import { TransactionHost } from "../infra/database/transaction-host.js";
|
|
36
37
|
import { Transactional } from "../infra/database/transactional.decorator.js";
|
|
37
38
|
import { OutboxService } from "../infra/outbox/outbox.service.js";
|
|
@@ -1284,33 +1285,35 @@ let PluginImport = class PluginImport {
|
|
|
1284
1285
|
/** The expired staging rows, batch by batch; returns the rows deleted. */
|
|
1285
1286
|
// org-filter: deployment-wide expiry sweep (maintenance job) over every org's staging rows
|
|
1286
1287
|
async cleanupStagingRows() {
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
.
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1288
|
+
return asPlatform("deployment-wide expiry sweep", async () => {
|
|
1289
|
+
let total = 0;
|
|
1290
|
+
for (;;) {
|
|
1291
|
+
const batch = await this.db
|
|
1292
|
+
.selectFrom("plugin_import_staging")
|
|
1293
|
+
.select(["id", "object_prefix"])
|
|
1294
|
+
.where("expires_at", "<=", sql `now()`)
|
|
1295
|
+
.orderBy("expires_at")
|
|
1296
|
+
.limit(CLEANUP_BATCH)
|
|
1297
|
+
.execute();
|
|
1298
|
+
if (batch.length === 0)
|
|
1299
|
+
return total;
|
|
1300
|
+
let progressed = 0;
|
|
1301
|
+
for (const r of batch) {
|
|
1302
|
+
try {
|
|
1303
|
+
const done = await this.cleanupOne(r);
|
|
1304
|
+
if (done) {
|
|
1305
|
+
total++;
|
|
1306
|
+
progressed++;
|
|
1307
|
+
}
|
|
1308
|
+
}
|
|
1309
|
+
catch (err) {
|
|
1310
|
+
this.log.warn("cannot clean up an expired plugin import", { stagingId: r.id, err });
|
|
1305
1311
|
}
|
|
1306
1312
|
}
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
}
|
|
1313
|
+
if (progressed === 0 || batch.length < CLEANUP_BATCH)
|
|
1314
|
+
return total;
|
|
1310
1315
|
}
|
|
1311
|
-
|
|
1312
|
-
return total;
|
|
1313
|
-
}
|
|
1316
|
+
});
|
|
1314
1317
|
}
|
|
1315
1318
|
/**
|
|
1316
1319
|
* One expired staging row (row lock, `SKIP LOCKED`): its objects, then the row; false when another
|
|
@@ -1318,22 +1321,24 @@ let PluginImport = class PluginImport {
|
|
|
1318
1321
|
*/
|
|
1319
1322
|
// org-filter: deployment-wide expiry sweep; the row id comes from the sweep's own read
|
|
1320
1323
|
async cleanupOne(r) {
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
|
|
1324
|
+
return asPlatform("deployment-wide expiry sweep", async () => {
|
|
1325
|
+
const t = this.db;
|
|
1326
|
+
const locked = await t
|
|
1327
|
+
.selectFrom("plugin_import_staging")
|
|
1328
|
+
.select(["id", "org_id", "review", "manifest"])
|
|
1329
|
+
.where("id", "=", r.id)
|
|
1330
|
+
.where("expires_at", "<=", sql `now()`)
|
|
1331
|
+
.forUpdate()
|
|
1332
|
+
.skipLocked()
|
|
1333
|
+
.executeTakeFirst();
|
|
1334
|
+
if (!locked)
|
|
1335
|
+
return false;
|
|
1336
|
+
if (r.object_prefix)
|
|
1337
|
+
await this.files.deployment().deletePrefix(r.object_prefix);
|
|
1338
|
+
await t.deleteFrom("plugin_import_staging").where("id", "=", r.id).execute();
|
|
1339
|
+
await this.dropOrgPackage(locked);
|
|
1340
|
+
return true;
|
|
1341
|
+
});
|
|
1337
1342
|
}
|
|
1338
1343
|
/**
|
|
1339
1344
|
* An expired org staging's extension package (an org upload stores it at prepare, P3-10): removed
|
|
@@ -41,6 +41,9 @@ let PluginScopeSyncProcessor = class PluginScopeSyncProcessor extends WorkerHost
|
|
|
41
41
|
finalAttempt: job.attemptsMade + 1 >= (job.opts.attempts ?? 1),
|
|
42
42
|
signal: this.stopping.signal,
|
|
43
43
|
});
|
|
44
|
+
}, {
|
|
45
|
+
// an item or chunk job spans the orgs of a platform item; an org job carries its orgId
|
|
46
|
+
platform: "plugin scope sync of a platform item",
|
|
44
47
|
});
|
|
45
48
|
}
|
|
46
49
|
/** Starts consuming (worker role, after the extensions loaded; built with `autorun: false`). */
|
|
@@ -71,8 +71,13 @@ export declare class ChannelInbound {
|
|
|
71
71
|
* not create a second run; it means a redelivery is never acked before the job is really queued.
|
|
72
72
|
*/
|
|
73
73
|
private dedupeAndEnqueue;
|
|
74
|
-
/**
|
|
74
|
+
/**
|
|
75
|
+
* Handles one inbound job (on a worker; a throw makes the queue retry). The event works in the
|
|
76
|
+
* org of its connection (RLS spec §5.3: each inbound event enters its org once resolved); the
|
|
77
|
+
* job itself runs in the platform scope, since its data names only the connection.
|
|
78
|
+
*/
|
|
75
79
|
handle(connectionId: string, e: InboundEvent): Promise<void>;
|
|
80
|
+
private handleInOrg;
|
|
76
81
|
private message;
|
|
77
82
|
/**
|
|
78
83
|
* Direct-message `/device` (environments spec §4.2 item 8): lists the person's usable devices,
|
package/dist/channels/inbound.js
CHANGED
|
@@ -20,6 +20,7 @@ import { IdentityBinding } from "../identity/binding.js";
|
|
|
20
20
|
import { ExternalIdentities } from "../identity/external.js";
|
|
21
21
|
import { KernelConfigService } from "../infra/config/kernel-config.service.js";
|
|
22
22
|
import { KernelDb } from "../infra/database/kernel-db.js";
|
|
23
|
+
import { asPlatform, withOrgScope, withoutOrgScope } from "../infra/database/org-scope.js";
|
|
23
24
|
import { LockService } from "../infra/lock/lock.service.js";
|
|
24
25
|
import { KERNEL_LOGGER, REDIS } from "../infra/tokens.js";
|
|
25
26
|
import { DirectorySync } from "../orgs/directory-sync.js";
|
|
@@ -187,8 +188,24 @@ let ChannelInbound = class ChannelInbound {
|
|
|
187
188
|
}
|
|
188
189
|
await this.redis.set(key, DEDUPE_DONE, "EX", MESSAGE_DEDUPE_TTL_SECONDS);
|
|
189
190
|
}
|
|
190
|
-
/**
|
|
191
|
+
/**
|
|
192
|
+
* Handles one inbound job (on a worker; a throw makes the queue retry). The event works in the
|
|
193
|
+
* org of its connection (RLS spec §5.3: each inbound event enters its org once resolved); the
|
|
194
|
+
* job itself runs in the platform scope, since its data names only the connection.
|
|
195
|
+
*/
|
|
191
196
|
async handle(connectionId, e) {
|
|
197
|
+
// org-filter: resolves the org of a kernel-held connection id (the inbound job's own), the
|
|
198
|
+
// one lookup made before the event's org scope is known
|
|
199
|
+
const conn = await asPlatform("inbound event: resolve the connection's org", () => this.kdb
|
|
200
|
+
.selectFrom("channel_connections")
|
|
201
|
+
.select("org_id")
|
|
202
|
+
.where("id", "=", connectionId)
|
|
203
|
+
.executeTakeFirst());
|
|
204
|
+
const run = () => this.handleInOrg(connectionId, e);
|
|
205
|
+
// a connection gone meanwhile: nothing to scope to, and no platform fallback
|
|
206
|
+
return conn ? withOrgScope(conn.org_id, run) : withoutOrgScope(run);
|
|
207
|
+
}
|
|
208
|
+
async handleInOrg(connectionId, e) {
|
|
192
209
|
if (e.type === "directory_changed") {
|
|
193
210
|
const row = await this.connections.row(connectionId);
|
|
194
211
|
if (row?.status === "active" && row.pluginEnabled) {
|
|
@@ -12,6 +12,7 @@ import { sql } from "kysely";
|
|
|
12
12
|
import { ApiError } from "../errors.js";
|
|
13
13
|
import { enabledExtensionsQuery } from "../extensions/enabled.js";
|
|
14
14
|
import { KernelDb } from "../infra/database/kernel-db.js";
|
|
15
|
+
import { asPlatform } from "../infra/database/org-scope.js";
|
|
15
16
|
import { TransactionHost } from "../infra/database/transaction-host.js";
|
|
16
17
|
import { Transactional } from "../infra/database/transactional.decorator.js";
|
|
17
18
|
import { ClientAccess } from "./client-access.service.js";
|
|
@@ -82,12 +83,14 @@ let ClientReports = class ClientReports {
|
|
|
82
83
|
}
|
|
83
84
|
/** Deletes the reports last seen more than {@link REPORT_RETENTION_DAYS} days ago; the count. */
|
|
84
85
|
async prune() {
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
.
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
86
|
+
return asPlatform("deployment-wide retention sweep over every org's reports", async () => {
|
|
87
|
+
// org-filter: deployment-wide retention sweep over every org's reports (maintenance job)
|
|
88
|
+
const r = await this.db.db
|
|
89
|
+
.deleteFrom("extension_client_reports")
|
|
90
|
+
.where("last_at", "<", sql `now() - make_interval(days => ${REPORT_RETENTION_DAYS})`)
|
|
91
|
+
.executeTakeFirst();
|
|
92
|
+
return Number(r.numDeletedRows);
|
|
93
|
+
});
|
|
91
94
|
}
|
|
92
95
|
};
|
|
93
96
|
__decorate([
|
package/dist/config/schema.d.ts
CHANGED
|
@@ -70,6 +70,11 @@ export declare const KernelConfigSchema: z.ZodObject<{
|
|
|
70
70
|
poolMax: z.ZodDefault<z.ZodNumber>;
|
|
71
71
|
connectTimeoutMs: z.ZodDefault<z.ZodNumber>;
|
|
72
72
|
idleTimeoutMs: z.ZodDefault<z.ZodNumber>;
|
|
73
|
+
rls: z.ZodDefault<z.ZodEnum<{
|
|
74
|
+
enforce: "enforce";
|
|
75
|
+
off: "off";
|
|
76
|
+
scoped: "scoped";
|
|
77
|
+
}>>;
|
|
73
78
|
}, z.core.$strict>>;
|
|
74
79
|
redis: z.ZodPrefault<z.ZodObject<{
|
|
75
80
|
url: z.ZodString;
|
package/dist/config/schema.js
CHANGED
|
@@ -345,6 +345,12 @@ export const KernelConfigSchema = z.strictObject({
|
|
|
345
345
|
.meta(meta({
|
|
346
346
|
description: "How long an idle PostgreSQL connection stays in the pool, in milliseconds",
|
|
347
347
|
})),
|
|
348
|
+
rls: z
|
|
349
|
+
.enum(["off", "scoped", "enforce"])
|
|
350
|
+
.default("off")
|
|
351
|
+
.meta(meta({
|
|
352
|
+
description: "Row level security (RLS spec, issue #115): off sends nothing; scoped sets the caller's org scope on every PostgreSQL connection (one extra round trip per pool query and per transaction) while the policies admit every row; enforce makes the policies filter every org-scoped table by that scope once row level security is enabled on the tables (RLS spec phase 5; until then the kernel warns at start and nothing is filtered). Needs a session-capable connection (no PgBouncer transaction pooling) unless off; PostgreSQL applies no policy to a superuser or BYPASSRLS role",
|
|
353
|
+
})),
|
|
348
354
|
})
|
|
349
355
|
.prefault({}),
|
|
350
356
|
redis: z
|