@capybara-hq/kernel 0.1.0-rc.136 → 0.1.0-rc.138
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/audit-log.service.d.ts +96 -12
- package/dist/admin/audit-log.service.js +508 -44
- package/dist/admin/audit-targets.d.ts +17 -0
- package/dist/admin/audit-targets.js +84 -0
- package/dist/admin/audit.controller.d.ts +12 -9
- package/dist/admin/audit.controller.js +29 -8
- package/dist/admin/audit.schemas.d.ts +20 -4
- package/dist/admin/audit.schemas.js +42 -17
- package/dist/admin/extensions.controller.d.ts +5 -2
- package/dist/admin/extensions.controller.js +10 -1
- package/dist/admin/extensions.schemas.d.ts +4 -0
- package/dist/admin/extensions.schemas.js +9 -0
- package/dist/admin/health.service.d.ts +1 -1
- package/dist/admin/health.service.js +3 -3
- package/dist/agents/templates.js +3 -10
- package/dist/app.d.ts +3 -1
- package/dist/app.js +1 -0
- package/dist/automations/automations.service.js +4 -5
- package/dist/catalog/catalog-content.d.ts +6 -8
- package/dist/catalog/catalog-content.js +17 -22
- package/dist/catalog/catalog-items.d.ts +5 -10
- package/dist/catalog/catalog-items.js +27 -51
- package/dist/catalog/catalog-scope.service.d.ts +4 -2
- package/dist/catalog/catalog-scope.service.js +109 -145
- package/dist/catalog/catalog.module.js +7 -4
- package/dist/catalog/catalog.service.d.ts +10 -4
- package/dist/catalog/catalog.service.js +52 -10
- package/dist/catalog/cli.js +17 -0
- package/dist/catalog/component-promotion.js +8 -4
- package/dist/catalog/component-scope.service.d.ts +3 -1
- package/dist/catalog/component-scope.service.js +101 -140
- package/dist/catalog/component-state.d.ts +10 -8
- package/dist/catalog/component-state.js +42 -30
- package/dist/catalog/dependency-edges.d.ts +25 -0
- package/dist/catalog/dependency-edges.js +125 -0
- package/dist/catalog/effect-work.d.ts +27 -0
- package/dist/catalog/effect-work.js +151 -0
- package/dist/catalog/jobs.d.ts +4 -1
- package/dist/catalog/jobs.js +14 -4
- package/dist/catalog/org-catalog.service.d.ts +5 -1
- package/dist/catalog/org-catalog.service.js +101 -106
- package/dist/catalog/org-intent.d.ts +45 -0
- package/dist/catalog/org-intent.js +205 -0
- package/dist/catalog/owned-items.d.ts +6 -2
- package/dist/catalog/owned-items.js +27 -32
- package/dist/catalog/ownership.d.ts +2 -3
- package/dist/catalog/ownership.js +10 -28
- package/dist/catalog/platform-components.d.ts +3 -1
- package/dist/catalog/platform-components.js +9 -1
- package/dist/catalog/plugin-import.d.ts +4 -2
- package/dist/catalog/plugin-import.js +22 -21
- package/dist/catalog/plugin-install.d.ts +19 -54
- package/dist/catalog/plugin-install.js +221 -271
- package/dist/catalog/plugin-upgrade.d.ts +10 -5
- package/dist/catalog/plugin-upgrade.js +80 -67
- package/dist/catalog/request-rules.js +20 -8
- package/dist/catalog/scope-orgs.js +2 -7
- package/dist/catalog/scope-state.d.ts +6 -6
- package/dist/catalog/scope-state.js +24 -43
- package/dist/catalog/scope-sync-workers.d.ts +7 -11
- package/dist/catalog/scope-sync-workers.js +10 -26
- package/dist/catalog/scope-sync.d.ts +19 -116
- package/dist/catalog/scope-sync.js +228 -275
- package/dist/catalog/scope-writer.d.ts +87 -0
- package/dist/catalog/scope-writer.js +239 -0
- package/dist/catalog/template-connector-ensure.js +1 -1
- package/dist/catalog/unshare.js +9 -43
- package/dist/channels/connections.service.js +6 -6
- package/dist/channels/supervisor.js +3 -7
- package/dist/client/client-access.service.js +2 -12
- package/dist/config/schema.d.ts +6 -0
- package/dist/config/schema.js +32 -1
- package/dist/ctx/create-ctx.d.ts +2 -2
- package/dist/ctx/create-ctx.js +2 -60
- package/dist/ctx/guard-db.d.ts +6 -0
- package/dist/ctx/guard-db.js +55 -0
- package/dist/db/extension-handoff-schema.d.ts +1 -1
- package/dist/db/extension-handoff-schema.js +48 -10
- package/dist/db/extension-schema-transfer.js +5 -2
- package/dist/db/kernel-schema.d.ts +32 -6
- package/dist/device-access/host-services.d.ts +2 -2
- package/dist/device-access/host-services.js +5 -6
- package/dist/erasure/org-catalog.js +2 -2
- package/dist/erasure/org-rules.js +7 -0
- package/dist/extensions/admin-ops.d.ts +10 -6
- package/dist/extensions/admin-ops.js +53 -9
- package/dist/extensions/admin-view.d.ts +4 -1
- package/dist/extensions/admin-view.js +27 -14
- package/dist/extensions/bootstrap.d.ts +1 -1
- package/dist/extensions/bootstrap.js +6 -4
- package/dist/extensions/cli.js +1 -0
- package/dist/extensions/effective-config.js +1 -4
- package/dist/extensions/enabled.d.ts +183 -29
- package/dist/extensions/enabled.js +148 -62
- package/dist/extensions/host.d.ts +65 -45
- package/dist/extensions/host.js +446 -128
- package/dist/extensions/installs.d.ts +9 -0
- package/dist/extensions/installs.js +23 -0
- package/dist/extensions/isolated/admission.d.ts +10 -0
- package/dist/extensions/isolated/admission.js +206 -0
- package/dist/extensions/isolated/authorization.d.ts +45 -0
- package/dist/extensions/isolated/authorization.js +191 -0
- package/dist/extensions/isolated/broker.d.ts +15 -0
- package/dist/extensions/isolated/broker.js +471 -0
- package/dist/extensions/isolated/child-protocol.d.ts +84 -0
- package/dist/extensions/isolated/child-protocol.js +21 -0
- package/dist/extensions/isolated/child-registration.d.ts +22 -0
- package/dist/extensions/isolated/child-registration.js +152 -0
- package/dist/extensions/isolated/child-session.d.ts +6 -0
- package/dist/extensions/isolated/child-session.js +343 -0
- package/dist/extensions/isolated/child-streams.d.ts +4 -0
- package/dist/extensions/isolated/child-streams.js +142 -0
- package/dist/extensions/isolated/child.d.ts +1 -0
- package/dist/extensions/isolated/child.js +10 -0
- package/dist/extensions/isolated/configured-package.d.ts +15 -0
- package/dist/extensions/isolated/configured-package.js +73 -0
- package/dist/extensions/isolated/engine-binds.d.ts +9 -0
- package/dist/extensions/isolated/engine-binds.js +82 -0
- package/dist/extensions/isolated/engine-policy.d.ts +85 -0
- package/dist/extensions/isolated/engine-policy.js +75 -0
- package/dist/extensions/isolated/engine-proxy-main.d.ts +1 -0
- package/dist/extensions/isolated/engine-proxy-main.js +20 -0
- package/dist/extensions/isolated/engine-proxy.d.ts +7 -0
- package/dist/extensions/isolated/engine-proxy.js +408 -0
- package/dist/extensions/isolated/engine-vaults.d.ts +12 -0
- package/dist/extensions/isolated/engine-vaults.js +93 -0
- package/dist/extensions/isolated/lanes.d.ts +108 -0
- package/dist/extensions/isolated/lanes.js +726 -0
- package/dist/extensions/isolated/postgres-gate.d.ts +15 -0
- package/dist/extensions/isolated/postgres-gate.js +255 -0
- package/dist/extensions/isolated/revision.d.ts +32 -0
- package/dist/extensions/isolated/revision.js +359 -0
- package/dist/extensions/isolated/rpc-frame.d.ts +50 -0
- package/dist/extensions/isolated/rpc-frame.js +193 -0
- package/dist/extensions/isolated/rpc.d.ts +66 -0
- package/dist/extensions/isolated/rpc.js +314 -0
- package/dist/extensions/isolated/sandbox.d.ts +39 -0
- package/dist/extensions/isolated/sandbox.js +356 -0
- package/dist/extensions/isolated/tier.d.ts +6 -0
- package/dist/extensions/isolated/tier.js +45 -0
- package/dist/extensions/ledger.d.ts +1 -1
- package/dist/extensions/lifecycle-topics.d.ts +2 -0
- package/dist/extensions/lifecycle-topics.js +2 -0
- package/dist/extensions/lifecycle.d.ts +3 -1
- package/dist/extensions/lifecycle.js +53 -5
- package/dist/extensions/locks.d.ts +2 -0
- package/dist/extensions/locks.js +7 -0
- package/dist/extensions/org-config.d.ts +17 -27
- package/dist/extensions/org-config.js +114 -129
- package/dist/extensions/permission-view.d.ts +6 -1
- package/dist/extensions/plugin-guides.d.ts +5 -10
- package/dist/extensions/plugin-guides.js +18 -37
- package/dist/extensions/plugin-icons.d.ts +3 -21
- package/dist/extensions/plugin-icons.js +9 -44
- package/dist/extensions/plugin-items.d.ts +10 -30
- package/dist/extensions/plugin-items.js +32 -73
- package/dist/extensions/source-intent.d.ts +14 -0
- package/dist/extensions/source-intent.js +77 -0
- package/dist/inbox/platform-inbox.service.js +16 -27
- package/dist/index.d.ts +2 -1
- package/dist/index.js +2 -1
- package/dist/infra/database/database.module.js +6 -1
- package/dist/infra/database/kernel-db.d.ts +3 -1
- package/dist/infra/database/kernel-db.js +4 -0
- package/dist/infra/events/kernel-events.d.ts +4 -0
- package/dist/infra/outbox/registry.d.ts +3 -36
- package/dist/infra/outbox/registry.js +4 -49
- package/dist/infra/paging/paged-read.d.ts +56 -0
- package/dist/infra/paging/paged-read.js +78 -0
- package/dist/infra/queue/queue-names.d.ts +1 -1
- package/dist/infra/queue/queue-names.js +1 -1
- package/dist/kernel.d.ts +3 -2
- package/dist/kernel.js +21 -2
- package/dist/lifecycle/kernel-lifecycle.d.ts +3 -1
- package/dist/lifecycle/kernel-lifecycle.js +22 -12
- package/dist/lifecycle/tokens.d.ts +8 -0
- package/dist/lifecycle/tokens.js +2 -0
- package/dist/orgs/directory-sync.js +1 -4
- package/dist/orgs/org-lock.d.ts +3 -1
- package/dist/orgs/org-lock.js +3 -1
- package/dist/orgs/orgs.service.d.ts +3 -1
- package/dist/orgs/orgs.service.js +15 -8
- package/dist/overrides.d.ts +0 -3
- package/dist/overrides.js +0 -2
- package/dist/platform/ops/admin.ops.js +14 -3
- package/dist/platform/ops/extensions-admin.ops.js +20 -3
- package/dist/platform/ops/org-plugins.ops.js +5 -2
- package/dist/platform/ops/orgs.ops.js +13 -3
- package/dist/platform/ops/plugins.ops.js +11 -10
- package/dist/setup/setup-checks.service.js +3 -2
- package/dist/skills/usable.js +41 -30
- package/dist/themes/theme-state.js +3 -3
- package/dist/tools/registry.d.ts +2 -2
- package/dist/tools/registry.js +7 -3
- package/package.json +2 -2
- package/src/migrations/0228_extension_org_switches.sql +56 -0
- package/src/migrations/0229_catalog_dependency_edges.sql +17 -0
- package/src/migrations/0230_audit_filter_idx.sql +18 -0
- package/src/migrations/0231_plugin_effect_work.sql +171 -0
- package/dist/catalog/install-status.d.ts +0 -6
- package/dist/catalog/install-status.js +0 -6
- package/dist/catalog/scope-jobs.d.ts +0 -59
- package/dist/catalog/scope-jobs.js +0 -78
|
@@ -13,13 +13,13 @@ import { Inject, Injectable } from "@nestjs/common";
|
|
|
13
13
|
import { sql } from "kysely";
|
|
14
14
|
import { readCatalogDisplayFiles } from "../catalog/catalog-content.js";
|
|
15
15
|
import { readDisplayFiles } from "../catalog/catalog-files.js";
|
|
16
|
+
import { orgSees } from "../catalog/org-intent.js";
|
|
16
17
|
import { ApiError } from "../errors.js";
|
|
17
18
|
import { KernelConfigService } from "../infra/config/kernel-config.service.js";
|
|
18
19
|
import { KernelDb } from "../infra/database/kernel-db.js";
|
|
19
20
|
import { KERNEL_LOGGER } from "../infra/tokens.js";
|
|
20
21
|
import { can, roleAtLeast } from "../orgs/roles.js";
|
|
21
22
|
import { PLACE_ACTIONS, resolvePlace, } from "./guide-places.js";
|
|
22
|
-
import { orgVisibleItems } from "./plugin-icons.js";
|
|
23
23
|
export { PLACE_ACTIONS } from "./guide-places.js";
|
|
24
24
|
const UUID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
25
25
|
const GUIDE_ID_RE = /^[a-z0-9][a-z0-9-]{0,63}$/;
|
|
@@ -28,26 +28,16 @@ const itemNotFound = () => new ApiError("catalog.item_not_found", "Catalog item
|
|
|
28
28
|
const guideNotFound = () => new ApiError("catalog.guide_not_found", "The plugin has no such setup guide");
|
|
29
29
|
const invalidQuery = (path, message) => new ApiError("validation_failed", "Request validation failed", [{ path, message }]);
|
|
30
30
|
/** The live items (with their latest version) by name or id. */
|
|
31
|
-
function latestItems(db, by, keys) {
|
|
32
|
-
|
|
31
|
+
function latestItems(db, by, keys, org) {
|
|
32
|
+
const query = db
|
|
33
33
|
.selectFrom("catalog_items as i")
|
|
34
34
|
.innerJoin("catalog_item_versions as v", (j) => j.onRef("v.item_id", "=", "i.id").onRef("v.version", "=", "i.latest_version"))
|
|
35
|
-
.select([
|
|
36
|
-
"i.id",
|
|
37
|
-
"i.name",
|
|
38
|
-
"i.scope",
|
|
39
|
-
"i.builtin",
|
|
40
|
-
"i.disabled",
|
|
41
|
-
"i.shown_to_others",
|
|
42
|
-
"i.owner_org_id",
|
|
43
|
-
"i.shareable",
|
|
44
|
-
"i.latest_version",
|
|
45
|
-
"v.manifest",
|
|
46
|
-
"v.files",
|
|
47
|
-
])
|
|
35
|
+
.select(["i.id", "i.name", "i.latest_version", "v.manifest", "v.files"])
|
|
48
36
|
.where(by === "name" ? "i.name" : "i.id", "in", [...new Set(keys)])
|
|
49
|
-
.where("i.deleted_at", "is", null)
|
|
50
|
-
|
|
37
|
+
.where("i.deleted_at", "is", null);
|
|
38
|
+
return (org === undefined
|
|
39
|
+
? query
|
|
40
|
+
: query.where("i.id", "in", orgSees(db.db, org.orgId, roleAtLeast(org.role, "admin")).select("item.id"))).execute();
|
|
51
41
|
}
|
|
52
42
|
/** Whether a stored `setupGuides` entry is a v2 one (the SDK's strict shape). */
|
|
53
43
|
function isV2Guide(g) {
|
|
@@ -95,7 +85,7 @@ const docMeta = (row, id, locale) => {
|
|
|
95
85
|
* catalog item (the item of the same name, its latest version), renders a guide document for a
|
|
96
86
|
* place, audience, mode and target with the place's safe variables (`guide-places.ts`; never a
|
|
97
87
|
* secret), and computes the drift hashes targets record to tell when an upgrade changed their
|
|
98
|
-
* setup. Org reads follow the catalog icon's visibility ({@link
|
|
88
|
+
* setup. Org reads follow the catalog icon's visibility ({@link orgSees}), the platform
|
|
99
89
|
* preview any live item. Stateless: everything comes from PG (version rows, target rows, the
|
|
100
90
|
* documents in `catalog_files`).
|
|
101
91
|
*/
|
|
@@ -108,14 +98,8 @@ let PluginGuides = PluginGuides_1 = class PluginGuides {
|
|
|
108
98
|
this.config = config;
|
|
109
99
|
this.log = log;
|
|
110
100
|
}
|
|
111
|
-
latest(by, keys) {
|
|
112
|
-
return latestItems(this.db, by, keys);
|
|
113
|
-
}
|
|
114
|
-
/** The rows the org's catalog shows ({@link orgVisibleItems}); all of them without an org. */
|
|
115
|
-
visibleTo(rows, org) {
|
|
116
|
-
return org === undefined
|
|
117
|
-
? rows
|
|
118
|
-
: orgVisibleItems(this.db, rows, org.orgId, roleAtLeast(org.role, "admin"));
|
|
101
|
+
latest(by, keys, org) {
|
|
102
|
+
return latestItems(this.db, by, keys, org);
|
|
119
103
|
}
|
|
120
104
|
/** The English documents of guides, by `<itemId>/<guideId>` (one PG read); absent when not stored. */
|
|
121
105
|
async englishSources(pairs) {
|
|
@@ -152,7 +136,7 @@ let PluginGuides = PluginGuides_1 = class PluginGuides {
|
|
|
152
136
|
* also when the org's catalog does not show the item, the guide read's rule.
|
|
153
137
|
*/
|
|
154
138
|
async currentAck(plugin, place, o) {
|
|
155
|
-
const [row] = await this.
|
|
139
|
+
const [row] = await this.latest("name", [plugin], o.org);
|
|
156
140
|
const guide = row && guideFor(row.manifest, place, o.templateId);
|
|
157
141
|
if (!row || !guide)
|
|
158
142
|
return null;
|
|
@@ -190,7 +174,7 @@ let PluginGuides = PluginGuides_1 = class PluginGuides {
|
|
|
190
174
|
async templateAck(itemId, templateId, org) {
|
|
191
175
|
if (!UUID_RE.test(itemId))
|
|
192
176
|
return null;
|
|
193
|
-
const [row] = await this.
|
|
177
|
+
const [row] = await this.latest("id", [itemId], org);
|
|
194
178
|
const guide = row && guideFor(row.manifest, "connector-template", templateId);
|
|
195
179
|
if (!row || !guide)
|
|
196
180
|
return null;
|
|
@@ -235,9 +219,7 @@ let PluginGuides = PluginGuides_1 = class PluginGuides {
|
|
|
235
219
|
const ids = [
|
|
236
220
|
...new Set(connectors.flatMap((c) => (c.itemId !== null && c.templateId !== null ? [c.itemId] : []))),
|
|
237
221
|
].filter((id) => UUID_RE.test(id));
|
|
238
|
-
const rows = ids.length === 0
|
|
239
|
-
? []
|
|
240
|
-
: await orgVisibleItems(this.db, await this.latest("id", ids), org.orgId, roleAtLeast(org.role, "admin"));
|
|
222
|
+
const rows = ids.length === 0 ? [] : await this.latest("id", ids, org);
|
|
241
223
|
const byId = new Map(rows.map((r) => [r.id, r]));
|
|
242
224
|
const guideOf = (c) => {
|
|
243
225
|
const row = c.itemId === null ? undefined : byId.get(c.itemId);
|
|
@@ -356,10 +338,10 @@ let PluginGuides = PluginGuides_1 = class PluginGuides {
|
|
|
356
338
|
const out = new Map();
|
|
357
339
|
if (names.length === 0)
|
|
358
340
|
return out;
|
|
359
|
-
const
|
|
360
|
-
const visible = await orgVisibleItems(this.db, rows, org.orgId, roleAtLeast(org.role, "admin"));
|
|
361
|
-
for (const r of visible) {
|
|
341
|
+
for (const r of await this.latest("name", names, org)) {
|
|
362
342
|
const guide = guideFor(r.manifest, place);
|
|
343
|
+
if (guide === undefined)
|
|
344
|
+
continue;
|
|
363
345
|
out.set(r.name, {
|
|
364
346
|
itemId: r.id,
|
|
365
347
|
guideId: guide.id,
|
|
@@ -456,8 +438,7 @@ let PluginGuides = PluginGuides_1 = class PluginGuides {
|
|
|
456
438
|
async render(org, itemId, guideId, q) {
|
|
457
439
|
if (!UUID_RE.test(itemId))
|
|
458
440
|
throw itemNotFound();
|
|
459
|
-
const
|
|
460
|
-
const [row] = await orgVisibleItems(this.db, rows, org.orgId, roleAtLeast(org.role, "admin"));
|
|
441
|
+
const [row] = await this.latest("id", [itemId], org);
|
|
461
442
|
if (!row)
|
|
462
443
|
throw itemNotFound();
|
|
463
444
|
this.warnSkipped(row);
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { type CatalogIcon } from "../catalog/catalog-content.js";
|
|
2
|
-
import { type PluginScope } from "../catalog/scope.js";
|
|
3
2
|
import { type TemplateDescription } from "../catalog/template-description.js";
|
|
4
3
|
import { KernelDb } from "../infra/database/kernel-db.js";
|
|
5
4
|
import { type OrgRole } from "../orgs/roles.js";
|
|
@@ -23,23 +22,6 @@ export interface IconRef {
|
|
|
23
22
|
templateId: string | null;
|
|
24
23
|
itemId: string | null;
|
|
25
24
|
}
|
|
26
|
-
/** The catalog item columns {@link orgVisibleItems} reads. */
|
|
27
|
-
export interface OrgVisibilityRow {
|
|
28
|
-
id: string;
|
|
29
|
-
scope: PluginScope;
|
|
30
|
-
builtin: boolean;
|
|
31
|
-
disabled: boolean;
|
|
32
|
-
shown_to_others: boolean;
|
|
33
|
-
owner_org_id: string | null;
|
|
34
|
-
shareable: boolean;
|
|
35
|
-
}
|
|
36
|
-
/**
|
|
37
|
-
* The rows of live catalog items the org's catalog shows (one query for the org's list rows):
|
|
38
|
-
* members never see disabled items, an upload waiting for confirmation only its owner, another
|
|
39
|
-
* org's item only when shareable or listed here (the share gate), a `named` item only its listed
|
|
40
|
-
* orgs or as requestable. Shared by the plugin icons and the setup guides.
|
|
41
|
-
*/
|
|
42
|
-
export declare function orgVisibleItems<T extends OrgVisibilityRow>(db: KernelDb, rows: T[], orgId: string, isAdmin: boolean): Promise<T[]>;
|
|
43
25
|
/**
|
|
44
26
|
* Plugin icons for the things a plugin brings (channels, extensions, model providers; maintainer
|
|
45
27
|
* decision 2026-11-08): extension name -> the URL of its plugin's icon, the catalog item of the
|
|
@@ -49,7 +31,7 @@ export declare function orgVisibleItems<T extends OrgVisibilityRow>(db: KernelDb
|
|
|
49
31
|
* its catalog shows (members never see disabled items, a `named` item only for its listed orgs or
|
|
50
32
|
* as requestable, an org-owned item only for its owner or through the share gate, an upload
|
|
51
33
|
* waiting for confirmation only for its owner). The URL carries the version, so a new icon is not
|
|
52
|
-
* hidden by the browser cache. Stateless; one query
|
|
34
|
+
* hidden by the browser cache. Stateless; one query for platform reads and a batched visibility projection for org reads.
|
|
53
35
|
*/
|
|
54
36
|
export declare class PluginIcons {
|
|
55
37
|
private readonly db;
|
|
@@ -127,11 +109,11 @@ export declare class PluginIcons {
|
|
|
127
109
|
private sourceUrl;
|
|
128
110
|
/** Template id -> its version, for the templates with an own icon the reader may see. */
|
|
129
111
|
private templateIconVersions;
|
|
130
|
-
/** Live platform connector templates
|
|
112
|
+
/** Live platform connector templates and their parent item IDs. */
|
|
131
113
|
private templateRows;
|
|
132
114
|
/**
|
|
133
115
|
* The templates the reader may see: every one for the admin scope; for an org, those whose
|
|
134
|
-
* plugin its catalog shows ({@link
|
|
116
|
+
* plugin its catalog shows ({@link visibleCatalogRows}) and that pass the template's own share gate
|
|
135
117
|
* (the platform's, the org's own, or shared by its owner).
|
|
136
118
|
*/
|
|
137
119
|
private visibleTemplates;
|
|
@@ -10,8 +10,8 @@ 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 { readCatalogDisplayFiles, readCatalogIcon, } from "../catalog/catalog-content.js";
|
|
13
|
+
import { visibleCatalogRows } from "../catalog/org-intent.js";
|
|
13
14
|
import { iconProblem } from "../catalog/plugin-package.js";
|
|
14
|
-
import { requestable } from "../catalog/scope.js";
|
|
15
15
|
import { templateDescription } from "../catalog/template-description.js";
|
|
16
16
|
import { ApiError } from "../errors.js";
|
|
17
17
|
import { KernelDb } from "../infra/database/kernel-db.js";
|
|
@@ -25,30 +25,6 @@ export const orgIconScope = (org) => ({
|
|
|
25
25
|
isAdmin: roleAtLeast(org.role, "admin"),
|
|
26
26
|
});
|
|
27
27
|
const enc = encodeURIComponent;
|
|
28
|
-
/**
|
|
29
|
-
* The rows of live catalog items the org's catalog shows (one query for the org's list rows):
|
|
30
|
-
* members never see disabled items, an upload waiting for confirmation only its owner, another
|
|
31
|
-
* org's item only when shareable or listed here (the share gate), a `named` item only its listed
|
|
32
|
-
* orgs or as requestable. Shared by the plugin icons and the setup guides.
|
|
33
|
-
*/
|
|
34
|
-
export async function orgVisibleItems(db, rows, orgId, isAdmin) {
|
|
35
|
-
if (rows.length === 0)
|
|
36
|
-
return [];
|
|
37
|
-
const listed = new Set((await db
|
|
38
|
-
.selectFrom("catalog_item_scope_orgs")
|
|
39
|
-
.select("item_id")
|
|
40
|
-
.where("org_id", "=", orgId)
|
|
41
|
-
.where("item_id", "in", rows.map((r) => r.id))
|
|
42
|
-
.execute()).map((r) => r.item_id));
|
|
43
|
-
return rows.filter((r) => {
|
|
44
|
-
const inList = listed.has(r.id);
|
|
45
|
-
const own = r.owner_org_id === orgId;
|
|
46
|
-
return ((isAdmin || !r.disabled) &&
|
|
47
|
-
// the share gate: another org's item reaches this org only when shareable or listed here
|
|
48
|
-
(r.owner_org_id === null || own || r.shareable || inList) &&
|
|
49
|
-
(r.builtin || r.scope !== "named" || inList || requestable(r, inList)));
|
|
50
|
-
});
|
|
51
|
-
}
|
|
52
28
|
/**
|
|
53
29
|
* Plugin icons for the things a plugin brings (channels, extensions, model providers; maintainer
|
|
54
30
|
* decision 2026-11-08): extension name -> the URL of its plugin's icon, the catalog item of the
|
|
@@ -58,7 +34,7 @@ export async function orgVisibleItems(db, rows, orgId, isAdmin) {
|
|
|
58
34
|
* its catalog shows (members never see disabled items, a `named` item only for its listed orgs or
|
|
59
35
|
* as requestable, an org-owned item only for its owner or through the share gate, an upload
|
|
60
36
|
* waiting for confirmation only for its owner). The URL carries the version, so a new icon is not
|
|
61
|
-
* hidden by the browser cache. Stateless; one query
|
|
37
|
+
* hidden by the browser cache. Stateless; one query for platform reads and a batched visibility projection for org reads.
|
|
62
38
|
*/
|
|
63
39
|
let PluginIcons = class PluginIcons {
|
|
64
40
|
db;
|
|
@@ -169,8 +145,9 @@ let PluginIcons = class PluginIcons {
|
|
|
169
145
|
throw new ApiError("catalog.icon_not_found", "This connector has no icon");
|
|
170
146
|
if (s.kind === "template")
|
|
171
147
|
return this.readTemplateIcon(s.id, scope);
|
|
172
|
-
|
|
173
|
-
|
|
148
|
+
return scope.kind === "org"
|
|
149
|
+
? readCatalogIcon(this.db.db, s.id, scope.isAdmin, scope.orgId)
|
|
150
|
+
: readCatalogIcon(this.db.db, s.id, true);
|
|
174
151
|
}
|
|
175
152
|
/**
|
|
176
153
|
* Reads a connector template's own icon (served only through kernel routes with nosniff and a
|
|
@@ -233,7 +210,7 @@ let PluginIcons = class PluginIcons {
|
|
|
233
210
|
const rows = (await this.templateRows(ids)).filter((r) => r.iconFile !== undefined);
|
|
234
211
|
return new Map((await this.visibleTemplates(rows, scope)).map((r) => [r.templateId, r.version]));
|
|
235
212
|
}
|
|
236
|
-
/** Live platform connector templates
|
|
213
|
+
/** Live platform connector templates and their parent item IDs. */
|
|
237
214
|
async templateRows(ids) {
|
|
238
215
|
const unique = [...new Set(ids)].filter((id) => UUID_RE.test(id));
|
|
239
216
|
if (unique.length === 0)
|
|
@@ -251,12 +228,6 @@ let PluginIcons = class PluginIcons {
|
|
|
251
228
|
sql `t.file->'description'`.as("description"),
|
|
252
229
|
"v.files",
|
|
253
230
|
"i.id",
|
|
254
|
-
"i.scope",
|
|
255
|
-
"i.builtin",
|
|
256
|
-
"i.disabled",
|
|
257
|
-
"i.shown_to_others",
|
|
258
|
-
"i.owner_org_id",
|
|
259
|
-
"i.shareable",
|
|
260
231
|
])
|
|
261
232
|
.where("t.id", "in", unique)
|
|
262
233
|
.where("t.deleted_at", "is", null)
|
|
@@ -275,7 +246,7 @@ let PluginIcons = class PluginIcons {
|
|
|
275
246
|
}
|
|
276
247
|
/**
|
|
277
248
|
* The templates the reader may see: every one for the admin scope; for an org, those whose
|
|
278
|
-
* plugin its catalog shows ({@link
|
|
249
|
+
* plugin its catalog shows ({@link visibleCatalogRows}) and that pass the template's own share gate
|
|
279
250
|
* (the platform's, the org's own, or shared by its owner).
|
|
280
251
|
*/
|
|
281
252
|
async visibleTemplates(rows, scope) {
|
|
@@ -284,7 +255,7 @@ let PluginIcons = class PluginIcons {
|
|
|
284
255
|
const shared = rows.filter((r) => r.template_owner_org_id === null ||
|
|
285
256
|
r.template_owner_org_id === scope.orgId ||
|
|
286
257
|
r.template_shareable);
|
|
287
|
-
return
|
|
258
|
+
return visibleCatalogRows(this.db.db, shared, scope.orgId, scope.isAdmin);
|
|
288
259
|
}
|
|
289
260
|
async resolve(by, keys, scope) {
|
|
290
261
|
const out = [];
|
|
@@ -297,12 +268,6 @@ let PluginIcons = class PluginIcons {
|
|
|
297
268
|
.select([
|
|
298
269
|
"i.id",
|
|
299
270
|
"i.name",
|
|
300
|
-
"i.scope",
|
|
301
|
-
"i.builtin",
|
|
302
|
-
"i.disabled",
|
|
303
|
-
"i.shown_to_others",
|
|
304
|
-
"i.owner_org_id",
|
|
305
|
-
"i.shareable",
|
|
306
271
|
"i.latest_version",
|
|
307
272
|
sql `v.manifest->>'icon'`.as("icon"),
|
|
308
273
|
"v.files",
|
|
@@ -325,7 +290,7 @@ let PluginIcons = class PluginIcons {
|
|
|
325
290
|
}
|
|
326
291
|
return out;
|
|
327
292
|
}
|
|
328
|
-
for (const r of await
|
|
293
|
+
for (const r of await visibleCatalogRows(this.db.db, withIcon, scope.orgId, scope.isAdmin)) {
|
|
329
294
|
const url = `/api/v1/orgs/${enc(scope.orgId)}/catalog/${enc(r.id)}/icon?v=${enc(r.latest_version)}`;
|
|
330
295
|
out.push({ id: r.id, name: r.name, url, version: r.latest_version });
|
|
331
296
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { type
|
|
1
|
+
import { type Expression } from "kysely";
|
|
2
|
+
import type { PluginScope } from "../catalog/scope.js";
|
|
2
3
|
import type { KernelSchemaDb } from "../db/kernel-schema.js";
|
|
3
4
|
/** The catalog item (the plugin) an extension ships in. */
|
|
4
5
|
export interface ExtensionPluginItem {
|
|
@@ -7,6 +8,13 @@ export interface ExtensionPluginItem {
|
|
|
7
8
|
builtin: boolean;
|
|
8
9
|
disabled: boolean;
|
|
9
10
|
}
|
|
11
|
+
/** All recorded sources, including retired items so they cannot masquerade as standalone. */
|
|
12
|
+
export declare function extensionSourcesQuery(db: KernelSchemaDb, plugin?: string | Expression<string>): import("kysely").SelectQueryBuilder<import("../db/kernel-schema.js").KernelDatabase & {
|
|
13
|
+
source_install: import("../db/kernel-schema.js").ExtensionInstallsTable;
|
|
14
|
+
}, "source_install", {
|
|
15
|
+
item_id: string;
|
|
16
|
+
plugin: string;
|
|
17
|
+
}>;
|
|
10
18
|
/**
|
|
11
19
|
* The live catalog items of each extension in `names`, the one recorded on its install
|
|
12
20
|
* (`extension_installs.catalog_item_id`) first, then its other `extension_catalog_sources` by id.
|
|
@@ -23,35 +31,7 @@ export declare const itemLocked: (i: ExtensionPluginItem) => boolean;
|
|
|
23
31
|
* The catalog item whose org install brings the extension into an org, or null when the
|
|
24
32
|
* extension has no such plugin path: a required bootstrap plugin, a config-declared extension (no
|
|
25
33
|
* live item), one several live items bring, and one whose item is builtin (on in every org without
|
|
26
|
-
* an install). With a plugin path the extension's org switch needs that plugin
|
|
34
|
+
* an install). With a plugin path the extension's org switch needs that plugin usable in the
|
|
27
35
|
* org (extension switch spec 2026-12-02 §3.1).
|
|
28
36
|
*/
|
|
29
37
|
export declare function pluginPathItem(items: readonly ExtensionPluginItem[] | undefined, required: boolean): string | null;
|
|
30
|
-
/**
|
|
31
|
-
* Whether the extension's plugin is installed in the org, as the org's lists read it:
|
|
32
|
-
* `installed` / `not_installed` for an extension with a plugin path ({@link pluginPathItem}), null
|
|
33
|
-
* without one. `liveItems`: the items with a live install in the org ({@link liveInstalledItems}).
|
|
34
|
-
*/
|
|
35
|
-
export declare function pluginInstallOf(items: readonly ExtensionPluginItem[] | undefined, required: boolean, liveItems: ReadonlySet<string>): "installed" | "not_installed" | null;
|
|
36
|
-
/** The ids of the catalog items with a live install (installing or installed) in the org. */
|
|
37
|
-
export declare function liveInstalledItems(db: KernelSchemaDb, orgId: string): Promise<Set<string>>;
|
|
38
|
-
/**
|
|
39
|
-
* Whether an org may see an extension with these live catalog items (`listed`: the items whose
|
|
40
|
-
* `named` list has the org): one visible item is enough; without an item (config-declared, or its
|
|
41
|
-
* items deleted) it is visible. A builtin item counts as `all`.
|
|
42
|
-
*/
|
|
43
|
-
export declare function itemsVisible(items: readonly ExtensionPluginItem[] | undefined, listed: ReadonlySet<string>): boolean;
|
|
44
|
-
/**
|
|
45
|
-
* Whether the org's extension list shows an extension (`OrgExtensionConfigs.list`, which the org
|
|
46
|
-
* readiness reads for the model providers an org admin can fix): a required bootstrap plugin
|
|
47
|
-
* always; else under its catalog items' scope, and, while it is off in the org, only when none of
|
|
48
|
-
* its items is disabled (nothing can newly enable it then, Ruling M-5; one already on stays).
|
|
49
|
-
*/
|
|
50
|
-
export declare const offeredToOrg: (e: {
|
|
51
|
-
required: boolean;
|
|
52
|
-
enabled: boolean;
|
|
53
|
-
items: readonly ExtensionPluginItem[] | undefined;
|
|
54
|
-
listed: ReadonlySet<string>;
|
|
55
|
-
}) => boolean;
|
|
56
|
-
/** The ids of the catalog items whose `named` list has `orgId`. `db` may be a transaction. */
|
|
57
|
-
export declare function scopeListedFor(db: KernelSchemaDb, orgId: string): Promise<Set<string>>;
|
|
@@ -1,5 +1,20 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import { sql } from "kysely";
|
|
2
|
+
/** All recorded sources, including retired items so they cannot masquerade as standalone. */
|
|
3
|
+
export function extensionSourcesQuery(db, plugin) {
|
|
4
|
+
const installed = db
|
|
5
|
+
.selectFrom("extension_installs as source_install")
|
|
6
|
+
.select(["source_install.name as plugin", "source_install.catalog_item_id as item_id"])
|
|
7
|
+
.where("source_install.catalog_item_id", "is not", null)
|
|
8
|
+
.$narrowType();
|
|
9
|
+
const associated = db
|
|
10
|
+
.selectFrom("extension_catalog_sources as source_catalog")
|
|
11
|
+
.select(["source_catalog.plugin", "source_catalog.item_id"]);
|
|
12
|
+
return plugin === undefined
|
|
13
|
+
? installed.union(associated)
|
|
14
|
+
: installed
|
|
15
|
+
.where("source_install.name", "=", plugin)
|
|
16
|
+
.union(associated.where("source_catalog.plugin", "=", plugin));
|
|
17
|
+
}
|
|
3
18
|
/**
|
|
4
19
|
* The live catalog items of each extension in `names`, the one recorded on its install
|
|
5
20
|
* (`extension_installs.catalog_item_id`) first, then its other `extension_catalog_sources` by id.
|
|
@@ -10,31 +25,23 @@ export async function pluginItemsOf(db, names) {
|
|
|
10
25
|
const out = new Map();
|
|
11
26
|
if (names.length === 0)
|
|
12
27
|
return out;
|
|
13
|
-
const
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
const own = await db
|
|
20
|
-
.selectFrom("extension_installs as e")
|
|
21
|
-
.innerJoin("catalog_items as i", "i.id", "e.catalog_item_id")
|
|
22
|
-
.select(["e.name as plugin", "i.id", "i.scope", "i.builtin", "i.disabled"])
|
|
23
|
-
.where("e.name", "in", [...names])
|
|
24
|
-
.where("i.deleted_at", "is", null)
|
|
25
|
-
.execute();
|
|
26
|
-
for (const r of own)
|
|
27
|
-
add(r.plugin, r);
|
|
28
|
-
const sources = await db
|
|
29
|
-
.selectFrom("extension_catalog_sources as s")
|
|
30
|
-
.innerJoin("catalog_items as i", "i.id", "s.item_id")
|
|
31
|
-
.select(["s.plugin", "i.id", "i.scope", "i.builtin", "i.disabled"])
|
|
32
|
-
.where("s.plugin", "in", [...names])
|
|
28
|
+
const rows = await db
|
|
29
|
+
.selectFrom(extensionSourcesQuery(db).as("source"))
|
|
30
|
+
.innerJoin("catalog_items as i", "i.id", "source.item_id")
|
|
31
|
+
.leftJoin("extension_installs as e", "e.name", "source.plugin")
|
|
32
|
+
.select(["source.plugin", "i.id", "i.scope", "i.builtin", "i.disabled"])
|
|
33
|
+
.where("source.plugin", "in", [...names])
|
|
33
34
|
.where("i.deleted_at", "is", null)
|
|
35
|
+
.orderBy(sql `(i.id = e.catalog_item_id) desc nulls last`)
|
|
34
36
|
.orderBy("i.id")
|
|
35
37
|
.execute();
|
|
36
|
-
for (const
|
|
37
|
-
|
|
38
|
+
for (const { plugin, ...item } of rows) {
|
|
39
|
+
const sources = out.get(plugin);
|
|
40
|
+
if (sources === undefined)
|
|
41
|
+
out.set(plugin, [item]);
|
|
42
|
+
else
|
|
43
|
+
sources.push(item);
|
|
44
|
+
}
|
|
38
45
|
return out;
|
|
39
46
|
}
|
|
40
47
|
/**
|
|
@@ -46,7 +53,7 @@ export const itemLocked = (i) => i.builtin;
|
|
|
46
53
|
* The catalog item whose org install brings the extension into an org, or null when the
|
|
47
54
|
* extension has no such plugin path: a required bootstrap plugin, a config-declared extension (no
|
|
48
55
|
* live item), one several live items bring, and one whose item is builtin (on in every org without
|
|
49
|
-
* an install). With a plugin path the extension's org switch needs that plugin
|
|
56
|
+
* an install). With a plugin path the extension's org switch needs that plugin usable in the
|
|
50
57
|
* org (extension switch spec 2026-12-02 §3.1).
|
|
51
58
|
*/
|
|
52
59
|
export function pluginPathItem(items, required) {
|
|
@@ -55,51 +62,3 @@ export function pluginPathItem(items, required) {
|
|
|
55
62
|
const [only] = items;
|
|
56
63
|
return only === undefined || itemLocked(only) ? null : only.id;
|
|
57
64
|
}
|
|
58
|
-
/**
|
|
59
|
-
* Whether the extension's plugin is installed in the org, as the org's lists read it:
|
|
60
|
-
* `installed` / `not_installed` for an extension with a plugin path ({@link pluginPathItem}), null
|
|
61
|
-
* without one. `liveItems`: the items with a live install in the org ({@link liveInstalledItems}).
|
|
62
|
-
*/
|
|
63
|
-
export function pluginInstallOf(items, required, liveItems) {
|
|
64
|
-
const item = pluginPathItem(items, required);
|
|
65
|
-
if (item === null)
|
|
66
|
-
return null;
|
|
67
|
-
return liveItems.has(item) ? "installed" : "not_installed";
|
|
68
|
-
}
|
|
69
|
-
/** The ids of the catalog items with a live install (installing or installed) in the org. */
|
|
70
|
-
export async function liveInstalledItems(db, orgId) {
|
|
71
|
-
const rows = await db
|
|
72
|
-
.selectFrom("plugin_installs")
|
|
73
|
-
.select("item_id")
|
|
74
|
-
.where("org_id", "=", orgId)
|
|
75
|
-
.where("status", "in", [...LIVE_INSTALL_STATUSES])
|
|
76
|
-
.execute();
|
|
77
|
-
return new Set(rows.map((r) => r.item_id));
|
|
78
|
-
}
|
|
79
|
-
/**
|
|
80
|
-
* Whether an org may see an extension with these live catalog items (`listed`: the items whose
|
|
81
|
-
* `named` list has the org): one visible item is enough; without an item (config-declared, or its
|
|
82
|
-
* items deleted) it is visible. A builtin item counts as `all`.
|
|
83
|
-
*/
|
|
84
|
-
export function itemsVisible(items, listed) {
|
|
85
|
-
if (!items)
|
|
86
|
-
return true;
|
|
87
|
-
return items.some((i) => visibleTo({ scope: i.builtin ? "all" : i.scope }, listed.has(i.id)));
|
|
88
|
-
}
|
|
89
|
-
/**
|
|
90
|
-
* Whether the org's extension list shows an extension (`OrgExtensionConfigs.list`, which the org
|
|
91
|
-
* readiness reads for the model providers an org admin can fix): a required bootstrap plugin
|
|
92
|
-
* always; else under its catalog items' scope, and, while it is off in the org, only when none of
|
|
93
|
-
* its items is disabled (nothing can newly enable it then, Ruling M-5; one already on stays).
|
|
94
|
-
*/
|
|
95
|
-
export const offeredToOrg = (e) => e.required ||
|
|
96
|
-
(itemsVisible(e.items, e.listed) && (e.enabled || !(e.items ?? []).some((i) => i.disabled)));
|
|
97
|
-
/** The ids of the catalog items whose `named` list has `orgId`. `db` may be a transaction. */
|
|
98
|
-
export async function scopeListedFor(db, orgId) {
|
|
99
|
-
const rows = await db
|
|
100
|
-
.selectFrom("catalog_item_scope_orgs")
|
|
101
|
-
.select("item_id")
|
|
102
|
-
.where("org_id", "=", orgId)
|
|
103
|
-
.execute();
|
|
104
|
-
return new Set(rows.map((r) => r.item_id));
|
|
105
|
-
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { KernelSchemaDb } from "../db/kernel-schema.js";
|
|
2
|
+
type SourceMode = "standalone" | "single" | "multiple" | "retired" | "locked";
|
|
3
|
+
interface SourceIntent {
|
|
4
|
+
mode: SourceMode;
|
|
5
|
+
defaults: {
|
|
6
|
+
org_id: string;
|
|
7
|
+
enabled: boolean;
|
|
8
|
+
}[];
|
|
9
|
+
}
|
|
10
|
+
/** Capture effective defaults before a source association changes under the extension install lock. */
|
|
11
|
+
export declare function captureSourceIntent(db: KernelSchemaDb, plugin: string, change: "add" | "retire"): Promise<SourceIntent>;
|
|
12
|
+
/** Keep prior defaults when the new source shape authorizes the same state. */
|
|
13
|
+
export declare function restoreSourceIntent(db: KernelSchemaDb, plugin: string, before: SourceIntent, actor: string | null): Promise<void>;
|
|
14
|
+
export {};
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { sql } from "kysely";
|
|
2
|
+
import { asPlatform } from "../infra/database/org-scope.js";
|
|
3
|
+
import { alwaysOnExtensionsQuery, extensionIntent, extensionSwitch } from "./enabled.js";
|
|
4
|
+
import { extensionSourcesQuery } from "./plugin-items.js";
|
|
5
|
+
async function sourceMode(db, plugin) {
|
|
6
|
+
const alwaysOn = await alwaysOnExtensionsQuery(db, plugin).executeTakeFirst();
|
|
7
|
+
if (alwaysOn)
|
|
8
|
+
return "locked";
|
|
9
|
+
const { sources, live } = await db
|
|
10
|
+
.selectFrom(extensionSourcesQuery(db, plugin).as("source"))
|
|
11
|
+
.innerJoin("catalog_items as item", "item.id", "source.item_id")
|
|
12
|
+
.select(({ fn, eb }) => [
|
|
13
|
+
fn.countAll().as("sources"),
|
|
14
|
+
fn
|
|
15
|
+
.countAll()
|
|
16
|
+
.filterWhere(eb("item.deleted_at", "is", null))
|
|
17
|
+
.as("live"),
|
|
18
|
+
])
|
|
19
|
+
.executeTakeFirstOrThrow();
|
|
20
|
+
if (Number(sources) === 0)
|
|
21
|
+
return "standalone";
|
|
22
|
+
if (Number(live) === 0)
|
|
23
|
+
return "retired";
|
|
24
|
+
return Number(live) === 1 ? "single" : "multiple";
|
|
25
|
+
}
|
|
26
|
+
/** Capture effective defaults before a source association changes under the extension install lock. */
|
|
27
|
+
export function captureSourceIntent(db, plugin, change) {
|
|
28
|
+
// org-filter: deployment-wide conversion of default extension intent after changing its sources
|
|
29
|
+
return asPlatform("capture extension intent before changing sources", async () => {
|
|
30
|
+
const mode = await sourceMode(db, plugin);
|
|
31
|
+
const canChangeDefault = change === "add" ? mode === "standalone" || mode === "single" : mode === "multiple";
|
|
32
|
+
if (!canChangeDefault)
|
|
33
|
+
return { mode, defaults: [] };
|
|
34
|
+
const defaults = await db
|
|
35
|
+
.selectFrom("orgs")
|
|
36
|
+
.select("orgs.id as org_id")
|
|
37
|
+
.select(({ ref }) => extensionIntent(db, ref("orgs.id"), plugin).as("enabled"))
|
|
38
|
+
.where("deleted_at", "is", null)
|
|
39
|
+
.where(({ ref, not, exists }) => not(exists(extensionSwitch(db, ref("orgs.id"), plugin))))
|
|
40
|
+
.execute();
|
|
41
|
+
return { mode, defaults };
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
/** Keep prior defaults when the new source shape authorizes the same state. */
|
|
45
|
+
export async function restoreSourceIntent(db, plugin, before, actor) {
|
|
46
|
+
if (before.defaults.length === 0)
|
|
47
|
+
return;
|
|
48
|
+
// org-filter: deployment-wide conversion of default extension intent after changing its sources
|
|
49
|
+
await asPlatform("preserve extension intent across source changes", async () => {
|
|
50
|
+
const mode = await sourceMode(db, plugin);
|
|
51
|
+
if (mode === before.mode || mode === "retired" || mode === "locked")
|
|
52
|
+
return;
|
|
53
|
+
const enabled = mode !== "single";
|
|
54
|
+
const affected = before.defaults
|
|
55
|
+
.filter((choice) => choice.enabled === enabled)
|
|
56
|
+
.map((choice) => choice.org_id);
|
|
57
|
+
if (affected.length === 0)
|
|
58
|
+
return;
|
|
59
|
+
await db
|
|
60
|
+
.insertInto("component_org_switches")
|
|
61
|
+
.columns(["kind", "component_id", "org_id", "enabled", "updated_by"])
|
|
62
|
+
.expression(db
|
|
63
|
+
.selectFrom("orgs")
|
|
64
|
+
.select([
|
|
65
|
+
sql `'extension'`.as("kind"),
|
|
66
|
+
sql `${plugin}`.as("component_id"),
|
|
67
|
+
"orgs.id as org_id",
|
|
68
|
+
sql `${enabled}::boolean`.as("enabled"),
|
|
69
|
+
sql `${actor}`.as("updated_by"),
|
|
70
|
+
])
|
|
71
|
+
.where(sql `orgs.id = ANY(${affected}::text[])`)
|
|
72
|
+
.where(({ ref }) => sql `${extensionIntent(db, ref("orgs.id"), plugin)} <> ${enabled}`)
|
|
73
|
+
.where(({ ref }) => sql `${extensionIntent(db, ref("orgs.id"), plugin, enabled)} = ${enabled}`))
|
|
74
|
+
.onConflict((conflict) => conflict.columns(["kind", "component_id", "org_id"]).doNothing())
|
|
75
|
+
.execute();
|
|
76
|
+
});
|
|
77
|
+
}
|
|
@@ -10,7 +10,6 @@ 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 { CatalogService } from "../catalog/catalog.service.js";
|
|
13
|
-
import { LIVE_INSTALL_STATUSES } from "../catalog/install-status.js";
|
|
14
13
|
import { CatalogRequestsService } from "../catalog/requests.service.js";
|
|
15
14
|
import { ApiError } from "../errors.js";
|
|
16
15
|
import { KernelDb } from "../infra/database/kernel-db.js";
|
|
@@ -211,23 +210,12 @@ let PlatformInboxService = class PlatformInboxService {
|
|
|
211
210
|
*/
|
|
212
211
|
failureRows() {
|
|
213
212
|
return this.kdb.db
|
|
214
|
-
.selectFrom("
|
|
213
|
+
.selectFrom("plugin_installs as f")
|
|
215
214
|
.innerJoin("catalog_items as i", "i.id", "f.item_id")
|
|
216
215
|
.innerJoin("orgs as o", "o.id", "f.org_id")
|
|
217
216
|
.where("i.deleted_at", "is", null)
|
|
218
217
|
.where("o.deleted_at", "is", null)
|
|
219
|
-
.where(
|
|
220
|
-
const live = eb.exists(eb
|
|
221
|
-
.selectFrom("plugin_installs as p")
|
|
222
|
-
.select("p.id")
|
|
223
|
-
.whereRef("p.org_id", "=", "f.org_id")
|
|
224
|
-
.whereRef("p.item_id", "=", "f.item_id")
|
|
225
|
-
.where("p.status", "in", [...LIVE_INSTALL_STATUSES]));
|
|
226
|
-
return eb.or([
|
|
227
|
-
eb.and([eb("f.op", "=", "install"), eb.not(live)]),
|
|
228
|
-
eb.and([eb("f.op", "in", ["uninstall", "dependencies"]), live]),
|
|
229
|
-
]);
|
|
230
|
-
});
|
|
218
|
+
.where("f.status", "=", "install_failed");
|
|
231
219
|
}
|
|
232
220
|
async countScopeSyncFailures() {
|
|
233
221
|
const r = await this.failureRows()
|
|
@@ -244,24 +232,25 @@ let PlatformInboxService = class PlatformInboxService {
|
|
|
244
232
|
"i.display_name",
|
|
245
233
|
"f.org_id",
|
|
246
234
|
"o.name as org_name",
|
|
247
|
-
"f.
|
|
248
|
-
"f.code",
|
|
249
|
-
"f.message",
|
|
250
|
-
"f.failed_at",
|
|
235
|
+
"f.error",
|
|
251
236
|
])
|
|
252
|
-
.orderBy(
|
|
237
|
+
.orderBy(sql `(f.error->>'attemptedAt')::timestamptz`, "desc")
|
|
253
238
|
.orderBy("f.item_id")
|
|
254
239
|
.orderBy("f.org_id")
|
|
255
240
|
.limit(SCOPE_SYNC_FAILURES_LIST_MAX)
|
|
256
241
|
.execute();
|
|
257
|
-
return rows.
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
242
|
+
return rows.flatMap((r) => r.error === null
|
|
243
|
+
? []
|
|
244
|
+
: [
|
|
245
|
+
{
|
|
246
|
+
item: { id: r.item_id, name: r.item_name, displayName: r.display_name },
|
|
247
|
+
org: { id: r.org_id, name: r.org_name },
|
|
248
|
+
op: r.error.operation,
|
|
249
|
+
code: r.error.code,
|
|
250
|
+
message: r.error.message,
|
|
251
|
+
failedAt: r.error.attemptedAt,
|
|
252
|
+
},
|
|
253
|
+
]);
|
|
265
254
|
}
|
|
266
255
|
};
|
|
267
256
|
PlatformInboxService = __decorate([
|