@capybara-hq/kernel 0.1.0-rc.136 → 0.1.0-rc.137
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/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 +1 -1
- 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 +105 -141
- package/dist/catalog/catalog.module.js +2 -0
- package/dist/catalog/catalog.service.d.ts +3 -3
- package/dist/catalog/catalog.service.js +33 -8
- 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/install-status.d.ts +2 -3
- package/dist/catalog/install-status.js +2 -3
- package/dist/catalog/org-catalog.service.d.ts +3 -1
- package/dist/catalog/org-catalog.service.js +33 -94
- package/dist/catalog/org-intent.d.ts +43 -0
- package/dist/catalog/org-intent.js +184 -0
- package/dist/catalog/owned-items.d.ts +1 -1
- package/dist/catalog/owned-items.js +9 -29
- 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.js +12 -16
- package/dist/catalog/plugin-install.d.ts +3 -4
- package/dist/catalog/plugin-install.js +25 -49
- package/dist/catalog/plugin-upgrade.d.ts +2 -2
- package/dist/catalog/plugin-upgrade.js +18 -34
- 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.d.ts +0 -2
- package/dist/catalog/scope-sync.js +11 -39
- package/dist/catalog/scope-writer.d.ts +78 -0
- package/dist/catalog/scope-writer.js +181 -0
- package/dist/catalog/unshare.js +8 -41
- 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 +29 -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 +11 -1
- 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 +5 -0
- package/dist/extensions/admin-ops.d.ts +9 -5
- package/dist/extensions/admin-ops.js +52 -8
- package/dist/extensions/admin-view.js +1 -4
- package/dist/extensions/bootstrap.js +4 -1
- package/dist/extensions/cli.js +1 -0
- package/dist/extensions/effective-config.js +1 -4
- package/dist/extensions/enabled.d.ts +23 -29
- package/dist/extensions/enabled.js +141 -62
- package/dist/extensions/host.d.ts +64 -45
- package/dist/extensions/host.js +443 -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 +37 -0
- package/dist/extensions/isolated/authorization.js +146 -0
- package/dist/extensions/isolated/broker.d.ts +15 -0
- package/dist/extensions/isolated/broker.js +452 -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/lanes.d.ts +100 -0
- package/dist/extensions/isolated/lanes.js +699 -0
- package/dist/extensions/isolated/postgres-gate.d.ts +14 -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 +358 -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 +35 -0
- package/dist/extensions/isolated/sandbox.js +372 -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 +1 -0
- package/dist/extensions/lifecycle-topics.js +1 -0
- package/dist/extensions/lifecycle.d.ts +3 -1
- package/dist/extensions/lifecycle.js +32 -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/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/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/paging/paged-read.d.ts +56 -0
- package/dist/infra/paging/paged-read.js +78 -0
- 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/platform/ops/admin.ops.js +14 -3
- package/dist/platform/ops/orgs.ops.js +13 -3
- 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 +1 -1
- package/dist/tools/registry.js +1 -1
- 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
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { Command, ConnectionBuilder, ControlledTransactionBuilder, Kysely, TransactionBuilder, } from "kysely";
|
|
2
|
+
import { isExtensionTransaction } from "../infra/database/extension-handoff.js";
|
|
3
|
+
/**
|
|
4
|
+
* Protects the owned pool and records the underlying transactions used for durable effects.
|
|
5
|
+
* Kysely methods use private fields, so they are always called on the underlying object.
|
|
6
|
+
*/
|
|
7
|
+
export function guardDb(db, plugin, transactions) {
|
|
8
|
+
const guarded = new Proxy(db, {
|
|
9
|
+
get(target, prop) {
|
|
10
|
+
// Async disposal must never close an instance-owned pool.
|
|
11
|
+
if (prop === "destroy" || prop === Symbol.asyncDispose) {
|
|
12
|
+
return () => {
|
|
13
|
+
throw new Error(`plugin ${plugin}: ctx.db.destroy() is not allowed; the kernel owns the connection pool`);
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
const value = Reflect.get(target, prop, target);
|
|
17
|
+
if (typeof value !== "function")
|
|
18
|
+
return value;
|
|
19
|
+
return (...args) => guardValue(value.apply(target, args), plugin, transactions);
|
|
20
|
+
},
|
|
21
|
+
});
|
|
22
|
+
if (isExtensionTransaction(db))
|
|
23
|
+
transactions.set(guarded, db);
|
|
24
|
+
return guarded;
|
|
25
|
+
}
|
|
26
|
+
/** Builders can return another database handle or pass one into a callback. */
|
|
27
|
+
const BUILDERS = [ConnectionBuilder, TransactionBuilder, ControlledTransactionBuilder, Command];
|
|
28
|
+
const isBuilder = (v) => BUILDERS.some((B) => v instanceof B);
|
|
29
|
+
/** Wrap only values that can expose another database handle. */
|
|
30
|
+
function guardValue(v, plugin, transactions) {
|
|
31
|
+
if (v instanceof Kysely)
|
|
32
|
+
return guardDb(v, plugin, transactions);
|
|
33
|
+
if (isBuilder(v))
|
|
34
|
+
return guardBuilder(v, plugin, transactions);
|
|
35
|
+
return v;
|
|
36
|
+
}
|
|
37
|
+
/** Protect callback arguments, builder results and handles returned by promises. */
|
|
38
|
+
function guardBuilder(builder, plugin, transactions) {
|
|
39
|
+
return new Proxy(builder, {
|
|
40
|
+
get(target, prop) {
|
|
41
|
+
const value = Reflect.get(target, prop, target);
|
|
42
|
+
if (typeof value !== "function")
|
|
43
|
+
return value;
|
|
44
|
+
return (...args) => {
|
|
45
|
+
const wrapped = args.map((a) => typeof a === "function"
|
|
46
|
+
? (...cbArgs) => a(...cbArgs.map((c) => guardValue(c, plugin, transactions)))
|
|
47
|
+
: a);
|
|
48
|
+
const out = guardValue(value.apply(target, wrapped), plugin, transactions);
|
|
49
|
+
return out instanceof Promise
|
|
50
|
+
? out.then((r) => guardValue(r, plugin, transactions))
|
|
51
|
+
: out;
|
|
52
|
+
};
|
|
53
|
+
},
|
|
54
|
+
});
|
|
55
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type Kysely } from "kysely";
|
|
2
2
|
import pg from "pg";
|
|
3
3
|
/** Creates a handoff owned by the one-shot provisioner. The extension can append only. */
|
|
4
|
-
export declare function provisionExtensionHandoff(owner: pg.ClientBase, schema: string, extensionLogin: string, runtimeLogin: string): Promise<void>;
|
|
4
|
+
export declare function provisionExtensionHandoff(owner: pg.ClientBase, schema: string, extensionLogin: string, runtimeLogin: string, legacyOwner?: string): Promise<void>;
|
|
5
5
|
/** Single-login deployments use the kernel's own connection for this table. */
|
|
6
6
|
export declare function ensureLocalExtensionHandoff(db: Kysely<unknown>, dbUrl: string, schema: string, connectTimeoutMs: number | undefined): Promise<void>;
|
|
@@ -3,9 +3,9 @@ import pg from "pg";
|
|
|
3
3
|
import { EXTENSION_EFFECT_HANDOFF } from "../infra/database/extension-handoff.js";
|
|
4
4
|
import { lockMigrationSchema } from "./migrator.js";
|
|
5
5
|
import { pgConnectOptions } from "./pool.js";
|
|
6
|
-
function createHandoffTable(table) {
|
|
6
|
+
function createHandoffTable(table, ifNotExists = true) {
|
|
7
7
|
return `
|
|
8
|
-
create table if not exists ${table} (
|
|
8
|
+
create table ${ifNotExists ? "if not exists " : ""}${table} (
|
|
9
9
|
id uuid primary key,
|
|
10
10
|
created_at timestamptz not null default pg_catalog.now(),
|
|
11
11
|
attempts integer not null default 0,
|
|
@@ -22,20 +22,58 @@ function createHandoffTable(table) {
|
|
|
22
22
|
`;
|
|
23
23
|
}
|
|
24
24
|
/** Creates a handoff owned by the one-shot provisioner. The extension can append only. */
|
|
25
|
-
export async function provisionExtensionHandoff(owner, schema, extensionLogin, runtimeLogin) {
|
|
25
|
+
export async function provisionExtensionHandoff(owner, schema, extensionLogin, runtimeLogin, legacyOwner) {
|
|
26
26
|
await lockMigrationSchema(owner, schema, "transaction");
|
|
27
27
|
const ns = pg.escapeIdentifier(schema);
|
|
28
28
|
const writer = pg.escapeIdentifier(extensionLogin);
|
|
29
29
|
const reader = pg.escapeIdentifier(runtimeLogin);
|
|
30
30
|
const table = `${ns}.${pg.escapeIdentifier(EXTENSION_EFFECT_HANDOFF)}`;
|
|
31
31
|
await owner.query(`create schema if not exists ${ns} authorization ${writer}`);
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
32
|
+
const lookup = async () => {
|
|
33
|
+
const { rows } = await owner.query(`select c.oid, pg_get_userbyid(c.relowner) as login, current_user as provisioner,
|
|
34
|
+
c.relkind = 'r' and c.relpersistence = 'p' and not c.relrowsecurity and not exists (
|
|
35
|
+
select 1 from pg_inherits where inhrelid = c.oid or inhparent = c.oid
|
|
36
|
+
) as plain
|
|
37
|
+
from pg_class c where c.oid = to_regclass($1)`, [table]);
|
|
38
|
+
return rows[0];
|
|
39
|
+
};
|
|
40
|
+
const invalid = () => new Error(`Invalid handoff owner or type for ${schema}`);
|
|
41
|
+
const valid = (relation) => relation.plain && (relation.login === relation.provisioner || relation.login === legacyOwner);
|
|
42
|
+
const existing = await lookup();
|
|
43
|
+
if (existing) {
|
|
44
|
+
if (!valid(existing))
|
|
45
|
+
throw invalid();
|
|
46
|
+
// The migration advisory lock covers Capybara sessions. The relation lock also excludes SQL
|
|
47
|
+
// DDL from other clients while the provisioner changes ownership and grants.
|
|
48
|
+
await owner.query(`lock table only ${table} in access exclusive mode`);
|
|
49
|
+
const locked = await lookup();
|
|
50
|
+
if (!locked || locked.oid !== existing.oid || !valid(locked))
|
|
51
|
+
throw invalid();
|
|
52
|
+
if (locked.login !== locked.provisioner) {
|
|
53
|
+
await owner.query(`alter table ${table} owner to current_user`);
|
|
54
|
+
// Replace legacy grants, including column ACLs that a table-wide REVOKE would leave behind.
|
|
55
|
+
const { rows: grants } = await owner.query(`with grants as (
|
|
56
|
+
select acl.grantee, null::name as column_name
|
|
57
|
+
from pg_class c cross join lateral aclexplode(c.relacl) acl where c.oid = $1
|
|
58
|
+
union
|
|
59
|
+
select acl.grantee, a.attname as column_name
|
|
60
|
+
from pg_attribute a cross join lateral aclexplode(a.attacl) acl
|
|
61
|
+
where a.attrelid = $1 and not a.attisdropped
|
|
62
|
+
)
|
|
63
|
+
select case when grantee = 0 then 'PUBLIC'
|
|
64
|
+
else quote_ident(pg_get_userbyid(grantee)) end as recipient, column_name
|
|
65
|
+
from grants where grantee <> current_user::regrole
|
|
66
|
+
order by column_name nulls first, recipient`, [locked.oid]);
|
|
67
|
+
for (const grant of grants) {
|
|
68
|
+
const privilege = grant.column_name
|
|
69
|
+
? `all (${pg.escapeIdentifier(grant.column_name)})`
|
|
70
|
+
: "all";
|
|
71
|
+
await owner.query(`revoke ${privilege} on table ${table} from ${grant.recipient} cascade`);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
// An object that appears after an absent lookup must not be implicitly adopted.
|
|
76
|
+
await owner.query(createHandoffTable(table, existing !== undefined));
|
|
39
77
|
await owner.query(`revoke all on table ${table} from public, ${writer}`);
|
|
40
78
|
await owner.query(`grant insert (id, envelope) on table ${table} to ${writer}`);
|
|
41
79
|
await owner.query(`grant usage on schema ${ns} to ${reader}`);
|
|
@@ -133,7 +133,8 @@ export async function transferKnownExtensionSchemas(bootstrapUrl, identity, decl
|
|
|
133
133
|
await owner.query("set local search_path = pg_catalog");
|
|
134
134
|
await owner.query("set local lock_timeout = '30s'");
|
|
135
135
|
const { rows: [legacy], } = await owner.query(`
|
|
136
|
-
select current_user as login, pg_get_userbyid(nspowner) as kernel_owner
|
|
136
|
+
select current_user as login, pg_get_userbyid(nspowner) as kernel_owner,
|
|
137
|
+
coalesce(nullif(current_setting('capybara.bootstrap_legacy_role', true), ''), 'capybara') as single_login
|
|
137
138
|
from pg_catalog.pg_namespace where nspname = 'capybara'
|
|
138
139
|
`);
|
|
139
140
|
if (!legacy)
|
|
@@ -151,6 +152,8 @@ export async function transferKnownExtensionSchemas(bootstrapUrl, identity, decl
|
|
|
151
152
|
return { name, schema: pluginSchemaName(name), target: identity.resolve(name) };
|
|
152
153
|
});
|
|
153
154
|
const legacySources = new Set([legacy.login, legacy.kernel_owner]);
|
|
155
|
+
if (provisioning)
|
|
156
|
+
legacySources.add(legacy.single_login);
|
|
154
157
|
if (identity.sharedLogin !== undefined)
|
|
155
158
|
legacySources.add(identity.sharedLogin);
|
|
156
159
|
const sources = new Set([...legacySources, ...resolved.map(({ target }) => target.login)]);
|
|
@@ -201,7 +204,7 @@ export async function transferKnownExtensionSchemas(bootstrapUrl, identity, decl
|
|
|
201
204
|
await transferExtensionSchema(owner, schema, target.login, target.dedicated ? legacySources : sources, target.dedicated);
|
|
202
205
|
if (provisioning && target.dedicated) {
|
|
203
206
|
const relayLogin = provisioning.extensionEffectRelayLogin ?? "capybara_runtime";
|
|
204
|
-
await provisionExtensionHandoff(owner, schema, target.login, relayLogin);
|
|
207
|
+
await provisionExtensionHandoff(owner, schema, target.login, relayLogin, legacy.single_login);
|
|
205
208
|
revoked.push(...(await revokeForeignSchemaGrants(owner, schema, relayLogin)));
|
|
206
209
|
}
|
|
207
210
|
if (target.dedicated && identity.sharedLogin) {
|
|
@@ -2190,6 +2190,7 @@ export interface KernelDatabase {
|
|
|
2190
2190
|
plugin_import_staging: PluginImportStagingTable;
|
|
2191
2191
|
catalog_requests: CatalogRequestsTable;
|
|
2192
2192
|
catalog_org_grants: CatalogOrgGrantsTable;
|
|
2193
|
+
catalog_dependency_edges: CatalogDependencyEdgesTable;
|
|
2193
2194
|
catalog_item_scope_orgs: CatalogItemScopeOrgsTable;
|
|
2194
2195
|
catalog_item_org_switches: CatalogItemOrgSwitchesTable;
|
|
2195
2196
|
platform_skills: PlatformSkillsTable;
|
|
@@ -2370,6 +2371,15 @@ export interface CatalogItemsTable {
|
|
|
2370
2371
|
/** 0084: the owner shares it with other orgs (the gate is `owner_org_id IS NULL OR shareable`). */
|
|
2371
2372
|
shareable: Dflt<boolean>;
|
|
2372
2373
|
}
|
|
2374
|
+
/** 0229: selected deployment versions and their resolved dependency targets. */
|
|
2375
|
+
export interface CatalogDependencyEdgesTable {
|
|
2376
|
+
item_id: string;
|
|
2377
|
+
item_version: string;
|
|
2378
|
+
dependency_name: string;
|
|
2379
|
+
template_id: string;
|
|
2380
|
+
dependency_item_id: string | null;
|
|
2381
|
+
dependency_version: string | null;
|
|
2382
|
+
}
|
|
2373
2383
|
/** 0075: the orgs a `named` item is offered to. */
|
|
2374
2384
|
export interface CatalogItemScopeOrgsTable {
|
|
2375
2385
|
item_id: string;
|
|
@@ -2517,7 +2527,7 @@ export interface ComponentScopeOrgsTable {
|
|
|
2517
2527
|
}
|
|
2518
2528
|
/** 0081: an org's on / off switch of a component. */
|
|
2519
2529
|
export interface ComponentOrgSwitchesTable {
|
|
2520
|
-
kind: ComponentKind;
|
|
2530
|
+
kind: ComponentKind | "extension";
|
|
2521
2531
|
component_id: string;
|
|
2522
2532
|
org_id: string;
|
|
2523
2533
|
enabled: boolean;
|
|
@@ -158,8 +158,8 @@ export declare class HostServiceAccess {
|
|
|
158
158
|
private clearOwed;
|
|
159
159
|
/**
|
|
160
160
|
* Whether the extension is on in the org and on the deployment now, read in a short transaction
|
|
161
|
-
* of its own that takes `FOR SHARE` on the org
|
|
162
|
-
* `extension_installs` row:
|
|
161
|
+
* of its own that takes `FOR SHARE` on the org row and the
|
|
162
|
+
* `extension_installs` row: an org switch-off locks the org and a deployment switch-off updates the install before it marks placements owed,
|
|
163
163
|
* so a switch-off still open waits this read out and is then seen (never a stale "enabled" while
|
|
164
164
|
* its placement UPDATE missed a row inserted meanwhile). Called with the placement lock held,
|
|
165
165
|
* never the other way round.
|
|
@@ -486,18 +486,17 @@ let HostServiceAccess = class HostServiceAccess {
|
|
|
486
486
|
}
|
|
487
487
|
/**
|
|
488
488
|
* Whether the extension is on in the org and on the deployment now, read in a short transaction
|
|
489
|
-
* of its own that takes `FOR SHARE` on the org
|
|
490
|
-
* `extension_installs` row:
|
|
489
|
+
* of its own that takes `FOR SHARE` on the org row and the
|
|
490
|
+
* `extension_installs` row: an org switch-off locks the org and a deployment switch-off updates the install before it marks placements owed,
|
|
491
491
|
* so a switch-off still open waits this read out and is then seen (never a stale "enabled" while
|
|
492
492
|
* its placement UPDATE missed a row inserted meanwhile). Called with the placement lock held,
|
|
493
493
|
* never the other way round.
|
|
494
494
|
*/
|
|
495
495
|
async enabledNow(orgId, extension) {
|
|
496
496
|
await this.db
|
|
497
|
-
.selectFrom("
|
|
498
|
-
.select("
|
|
499
|
-
.where("
|
|
500
|
-
.where("plugin", "=", extension)
|
|
497
|
+
.selectFrom("orgs")
|
|
498
|
+
.select("id")
|
|
499
|
+
.where("id", "=", orgId)
|
|
501
500
|
.forShare()
|
|
502
501
|
.executeTakeFirst();
|
|
503
502
|
// deployment-wide: the extension's install record (none for a dev-loaded extension)
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { sql } from "kysely";
|
|
2
|
-
// PostgreSQL 17 after
|
|
2
|
+
// PostgreSQL 17 after 0229. Re-review the ownership map before updating this fingerprint.
|
|
3
3
|
// It includes relation/column identities and ordered PK, UNIQUE and inbound/outbound FK
|
|
4
4
|
// columns and actions, including FKs from outside the kernel schema.
|
|
5
5
|
export async function orgCatalogDrift(db) {
|
|
@@ -30,5 +30,5 @@ WITH catalog AS (
|
|
|
30
30
|
)
|
|
31
31
|
SELECT md5(string_agg(entry, chr(10) ORDER BY entry COLLATE "C")) AS fingerprint FROM catalog
|
|
32
32
|
`.execute(db);
|
|
33
|
-
return rows[0]?.fingerprint === "
|
|
33
|
+
return rows[0]?.fingerprint === "d312e85ccc7cc10086f6fa60f6e9e851" ? undefined : "schema-drift";
|
|
34
34
|
}
|
|
@@ -95,6 +95,7 @@ export const rowRules = [
|
|
|
95
95
|
rule("platform_connector_templates", "id", ownedRetired),
|
|
96
96
|
rule("platform_skills", "id", ownedRetired),
|
|
97
97
|
rule("platform_themes", "id", ownedRetired),
|
|
98
|
+
rule("catalog_dependency_edges", "item_id, dependency_name, template_id", ownsCatalogVersion("catalog_items", "item_id")),
|
|
98
99
|
rule("catalog_item_versions", "item_id, version", ownsCatalogVersion("catalog_items", "item_id")),
|
|
99
100
|
rule("catalog_items", "id", ownedRetired),
|
|
100
101
|
];
|
|
@@ -150,6 +151,10 @@ export const childReferences = {
|
|
|
150
151
|
],
|
|
151
152
|
platform_themes: [["platform_theme_versions", "child.theme_id = parent.id"]],
|
|
152
153
|
catalog_items: [
|
|
154
|
+
[
|
|
155
|
+
"catalog_dependency_edges",
|
|
156
|
+
"child.item_id = parent.id OR child.dependency_item_id = parent.id",
|
|
157
|
+
],
|
|
153
158
|
["catalog_item_org_switches", "child.item_id = parent.id"],
|
|
154
159
|
["catalog_item_scope_orgs", "child.item_id = parent.id"],
|
|
155
160
|
["catalog_item_versions", "child.item_id = parent.id"],
|
|
@@ -45,6 +45,13 @@ export interface ExtensionOpsOwner {
|
|
|
45
45
|
export type InstallView = AdminExtensionView & {
|
|
46
46
|
leftDisabled?: SingleProviderNote;
|
|
47
47
|
};
|
|
48
|
+
type InstallOptions = {
|
|
49
|
+
catalogItemId?: string;
|
|
50
|
+
liveItem?: true;
|
|
51
|
+
owner?: ExtensionOpsOwner;
|
|
52
|
+
/** Selects a verified bootstrap installation, including restoration during rollback. */
|
|
53
|
+
bootstrap?: true;
|
|
54
|
+
};
|
|
48
55
|
export declare class ExtensionAdminOps {
|
|
49
56
|
private readonly kdb;
|
|
50
57
|
readonly txHost: TransactionHost;
|
|
@@ -142,11 +149,7 @@ export declare class ExtensionAdminOps {
|
|
|
142
149
|
* the result's `leftDisabled` says why (the shape of `enableUnlessOccupied`'s refusal). Checked
|
|
143
150
|
* under the point's lock after the install lock (the enable's order).
|
|
144
151
|
*/
|
|
145
|
-
install(name: string, sha256: string, actor: string | null, actorTokenId?: string, opts?:
|
|
146
|
-
catalogItemId?: string;
|
|
147
|
-
liveItem?: true;
|
|
148
|
-
owner?: ExtensionOpsOwner;
|
|
149
|
-
}): Promise<InstallView>;
|
|
152
|
+
install(name: string, sha256: string, actor: string | null, actorTokenId?: string, opts?: InstallOptions): Promise<InstallView>;
|
|
150
153
|
private writeInstall;
|
|
151
154
|
/**
|
|
152
155
|
* Enable on the deployment (audit `extension.enabled`); no change when already enabled. Org
|
|
@@ -205,3 +208,4 @@ export declare class ExtensionAdminOps {
|
|
|
205
208
|
/** 提交后通知各副本;发布失败只告警(周期 reconcile 兜底),本副本自己先 reconcile。 */
|
|
206
209
|
private notify;
|
|
207
210
|
}
|
|
211
|
+
export {};
|
|
@@ -37,8 +37,10 @@ import { ExtensionLifecycle, PLUGINS_CHANGED_TOPIC } from "./lifecycle.js";
|
|
|
37
37
|
import { PluginInstallLock } from "./locks.js";
|
|
38
38
|
import { unrunMigrations } from "./migrate-lock.js";
|
|
39
39
|
import { ExtensionPackageError, extensionPackageApiError, readExtensionPackage, } from "./package.js";
|
|
40
|
+
import { extensionSourcesQuery } from "./plugin-items.js";
|
|
40
41
|
import { ExtensionRegistry } from "./registry.js";
|
|
41
42
|
import { isSingleProviderCode, SingleProviderGuard, singleProviderNote, } from "./single-provider.js";
|
|
43
|
+
import { captureSourceIntent, restoreSourceIntent } from "./source-intent.js";
|
|
42
44
|
let ExtensionAdminOps = class ExtensionAdminOps {
|
|
43
45
|
kdb;
|
|
44
46
|
txHost;
|
|
@@ -193,8 +195,35 @@ let ExtensionAdminOps = class ExtensionAdminOps {
|
|
|
193
195
|
}
|
|
194
196
|
}
|
|
195
197
|
const row = await this.lockRow(name);
|
|
198
|
+
// Blob metadata records the first upload of these bytes. Admission follows this install
|
|
199
|
+
// and, for a catalog install, the exact catalog revision selected by its caller.
|
|
200
|
+
const catalogRevision = opts.catalogItemId === undefined
|
|
201
|
+
? undefined
|
|
202
|
+
: await db
|
|
203
|
+
.selectFrom("catalog_item_versions")
|
|
204
|
+
.select("source")
|
|
205
|
+
.where("item_id", "=", opts.catalogItemId)
|
|
206
|
+
.where("version", "=", pkg.version)
|
|
207
|
+
.where("extension_sha256", "=", sha256)
|
|
208
|
+
.executeTakeFirst();
|
|
209
|
+
const source = opts.bootstrap || catalogRevision?.source === "bootstrap"
|
|
210
|
+
? "bootstrap"
|
|
211
|
+
: catalogRevision
|
|
212
|
+
? "catalog"
|
|
213
|
+
: pkg.source === "npm"
|
|
214
|
+
? "npm"
|
|
215
|
+
: "file";
|
|
196
216
|
// 不经目录重装时保留原来的来源条目(不清空,C22)
|
|
197
217
|
const catalogItemId = opts.catalogItemId ?? row?.catalog_item_id ?? null;
|
|
218
|
+
const sourceIntent = row &&
|
|
219
|
+
opts.catalogItemId !== undefined &&
|
|
220
|
+
!(await db
|
|
221
|
+
.selectFrom(extensionSourcesQuery(db, name).as("source"))
|
|
222
|
+
.select("item_id")
|
|
223
|
+
.where("item_id", "=", opts.catalogItemId)
|
|
224
|
+
.executeTakeFirst())
|
|
225
|
+
? await captureSourceIntent(db, name, "add")
|
|
226
|
+
: undefined;
|
|
198
227
|
if (opts.catalogItemId !== undefined) {
|
|
199
228
|
await db
|
|
200
229
|
.insertInto("extension_catalog_sources")
|
|
@@ -229,17 +258,24 @@ let ExtensionAdminOps = class ExtensionAdminOps {
|
|
|
229
258
|
if (owner.package_name !== pkg.package_name) {
|
|
230
259
|
throw new ApiError("extension.name_conflict", `Extension name ${name} was previously used by package ${owner.package_name}; its data, secrets and permission approval are retained for that package, so package ${pkg.package_name} cannot take over the name`);
|
|
231
260
|
}
|
|
232
|
-
//
|
|
261
|
+
// The same bytes can be selected through a different source.
|
|
233
262
|
if (row?.sha256 === sha256) {
|
|
234
|
-
if (row.catalog_item_id !== catalogItemId) {
|
|
235
|
-
// 包没变、只有来源条目变了:照样留审计(来源变化影响 T26 的目录策略约束)
|
|
263
|
+
if (row.catalog_item_id !== catalogItemId || row.source !== source) {
|
|
236
264
|
await db
|
|
237
265
|
.updateTable("extension_installs")
|
|
238
|
-
.set({ catalog_item_id: catalogItemId })
|
|
266
|
+
.set({ catalog_item_id: catalogItemId, source })
|
|
239
267
|
.where("name", "=", name)
|
|
240
268
|
.execute();
|
|
241
|
-
await this.audit(actor, actorTokenId, "extension.install_source_changed", name, pkg.version, sha256, {
|
|
269
|
+
await this.audit(actor, actorTokenId, "extension.install_source_changed", name, pkg.version, sha256, {
|
|
270
|
+
catalogItemId,
|
|
271
|
+
previousCatalogItemId: row.catalog_item_id,
|
|
272
|
+
source,
|
|
273
|
+
previousSource: row.source,
|
|
274
|
+
});
|
|
275
|
+
afterCommit(() => this.notify(name));
|
|
242
276
|
}
|
|
277
|
+
if (sourceIntent)
|
|
278
|
+
await restoreSourceIntent(db, name, sourceIntent, actor);
|
|
243
279
|
return { changed: false, state: row.desired_state };
|
|
244
280
|
}
|
|
245
281
|
if (row && isDowngrade(pkg.version, row.version)) {
|
|
@@ -274,7 +310,7 @@ let ExtensionAdminOps = class ExtensionAdminOps {
|
|
|
274
310
|
name,
|
|
275
311
|
sha256,
|
|
276
312
|
version: pkg.version,
|
|
277
|
-
source
|
|
313
|
+
source,
|
|
278
314
|
desired_state: "disabled",
|
|
279
315
|
installed_by: actor,
|
|
280
316
|
updated_by: actor,
|
|
@@ -283,12 +319,14 @@ let ExtensionAdminOps = class ExtensionAdminOps {
|
|
|
283
319
|
.onConflict((oc) => oc.column("name").doUpdateSet({
|
|
284
320
|
sha256,
|
|
285
321
|
version: pkg.version,
|
|
286
|
-
source
|
|
322
|
+
source,
|
|
287
323
|
updated_by: actor,
|
|
288
324
|
catalog_item_id: catalogItemId,
|
|
289
325
|
updated_at: sql `now()`,
|
|
290
326
|
}))
|
|
291
327
|
.execute();
|
|
328
|
+
if (sourceIntent)
|
|
329
|
+
await restoreSourceIntent(db, name, sourceIntent, actor);
|
|
292
330
|
if (leftDisabled !== undefined ||
|
|
293
331
|
target.section.manifest.permissions?.deviceAccess?.siteAccess !== true) {
|
|
294
332
|
await revokeSiteGrantsOfExtensionEverywhere(db, name);
|
|
@@ -474,6 +512,7 @@ let ExtensionAdminOps = class ExtensionAdminOps {
|
|
|
474
512
|
.select([
|
|
475
513
|
"extension_installs.sha256",
|
|
476
514
|
"extension_installs.version",
|
|
515
|
+
"extension_installs.source",
|
|
477
516
|
"extension_installs.desired_state",
|
|
478
517
|
"extension_installs.catalog_item_id",
|
|
479
518
|
"extension_installs.required",
|
|
@@ -608,7 +647,12 @@ async function hasRetainedData(db, name) {
|
|
|
608
647
|
.select(sql `1`.as("x"))
|
|
609
648
|
.where("plugin", "=", name))
|
|
610
649
|
.union(db
|
|
611
|
-
.selectFrom("
|
|
650
|
+
.selectFrom("component_org_switches")
|
|
651
|
+
.select(sql `1`.as("x"))
|
|
652
|
+
.where("kind", "=", "extension")
|
|
653
|
+
.where("component_id", "=", name))
|
|
654
|
+
.union(db
|
|
655
|
+
.selectFrom("extension_org_overrides")
|
|
612
656
|
.select(sql `1`.as("x"))
|
|
613
657
|
.where("plugin", "=", name))
|
|
614
658
|
.limit(1)
|
|
@@ -387,11 +387,8 @@ let ExtensionAdmin = class ExtensionAdmin {
|
|
|
387
387
|
blocked.set(s.name, block);
|
|
388
388
|
}
|
|
389
389
|
const counts = new Map((await this.db
|
|
390
|
-
.selectFrom(enabledExtensionsByOrg(this.db).as("en"))
|
|
391
|
-
.innerJoin("orgs", "orgs.id", "en.org_id")
|
|
390
|
+
.selectFrom(enabledExtensionsByOrg(this.db, names).as("en"))
|
|
392
391
|
.select(["en.plugin", (eb) => eb.fn.countAll().as("n")])
|
|
393
|
-
.where("orgs.deleted_at", "is", null)
|
|
394
|
-
.where("en.plugin", "in", names)
|
|
395
392
|
.groupBy("en.plugin")
|
|
396
393
|
.execute()).map((r) => [r.plugin, Number(r.n)]));
|
|
397
394
|
const { clients, reports } = await this.clientsOf(subjects, rows);
|
|
@@ -776,7 +776,10 @@ let BootstrapService = class BootstrapService {
|
|
|
776
776
|
.where("owner_org_id", "is", null)
|
|
777
777
|
.where("deleted_at", "is", null)
|
|
778
778
|
.executeTakeFirst();
|
|
779
|
-
const installed = await this.ops.install(e.name, review.sha256, null, undefined,
|
|
779
|
+
const installed = await this.ops.install(e.name, review.sha256, null, undefined, {
|
|
780
|
+
bootstrap: true,
|
|
781
|
+
...(item && { catalogItemId: item.id }),
|
|
782
|
+
});
|
|
780
783
|
// An upgrade newly providing a held single-provider point is left disabled by the install
|
|
781
784
|
if (installed.leftDisabled !== undefined)
|
|
782
785
|
return this.leftDisabled(e, installed.leftDisabled);
|
package/dist/extensions/cli.js
CHANGED
|
@@ -36,6 +36,7 @@ export function parseDeploymentConfig(schema, stored, fileValue) {
|
|
|
36
36
|
*/
|
|
37
37
|
export async function openExtensionCli(config, log, opts = {}) {
|
|
38
38
|
const inspected = await ExtensionHost.inspect(config.extensions, {
|
|
39
|
+
maxPackageBytes: config.packages.maxBytes,
|
|
39
40
|
...(opts.resolveFrom !== undefined && { resolveFrom: opts.resolveFrom }),
|
|
40
41
|
});
|
|
41
42
|
const app = await openKernelCli(config, {
|
|
@@ -302,12 +302,9 @@ let EffectiveConfigs = class EffectiveConfigs {
|
|
|
302
302
|
if (!this.registry.current(plugin))
|
|
303
303
|
return 0;
|
|
304
304
|
const rows = await this.db
|
|
305
|
-
.selectFrom(enabledExtensionsByOrg(this.db).as("en"))
|
|
306
|
-
.innerJoin("orgs", "orgs.id", "en.org_id")
|
|
305
|
+
.selectFrom(enabledExtensionsByOrg(this.db, [plugin]).as("en"))
|
|
307
306
|
.leftJoin("extension_org_overrides as ov", (j) => j.onRef("ov.org_id", "=", "en.org_id").onRef("ov.plugin", "=", "en.plugin"))
|
|
308
307
|
.select(["en.org_id as orgId", "ov.org_id as copyOrg"])
|
|
309
|
-
.where("orgs.deleted_at", "is", null)
|
|
310
|
-
.where("en.plugin", "=", plugin)
|
|
311
308
|
.execute();
|
|
312
309
|
let n = 0;
|
|
313
310
|
let following;
|
|
@@ -1,46 +1,39 @@
|
|
|
1
|
+
import { type Expression } from "kysely";
|
|
1
2
|
import type { KernelSchemaDb } from "../db/kernel-schema.js";
|
|
2
|
-
|
|
3
|
-
* Which extensions an organization has enabled. Two sources, and every reader goes through these
|
|
4
|
-
* helpers so none of them misses one:
|
|
5
|
-
* - `extension_org_configs.enabled` (the org's own switch);
|
|
6
|
-
* - every always-on extension ({@link alwaysOnExtensionsQuery}): enabled in every org, existing and
|
|
7
|
-
* future, without an org config row, whatever such a row says. That is a required bootstrap
|
|
8
|
-
* plugin (`extension_installs.required`, package ecosystem spec §7) and an extension shipped in a
|
|
9
|
-
* builtin platform plugin (a live `catalog_items` row with `builtin`, recorded on its install or in
|
|
10
|
-
* `extension_catalog_sources`; a `builtin: true` bootstrap entry is builtin without being
|
|
11
|
-
* required). A builtin plugin is on in every org and its org switch is locked (`wantedOn`,
|
|
12
|
-
* `itemLocked`), so its extension must be on too: the scope sync leaves builtin items alone.
|
|
13
|
-
* Neither checks that the extension is loaded on this replica or enabled on the deployment; callers
|
|
14
|
-
* that need that check it themselves, as before. Plain SQL read on every call (no cache), so every
|
|
15
|
-
* replica sees a change at once. `db` may be a transaction.
|
|
16
|
-
*/
|
|
3
|
+
type Key = string | Expression<string>;
|
|
17
4
|
/**
|
|
18
5
|
* The names of the always-on extensions (a subquery with one column, `plugin`): required bootstrap
|
|
19
6
|
* plugins and the extensions of live builtin platform plugins (see the file header).
|
|
20
7
|
*/
|
|
21
|
-
export declare function alwaysOnExtensionsQuery(db: KernelSchemaDb): import("kysely").SelectQueryBuilder<import("../db/kernel-schema.js").KernelDatabase & {
|
|
8
|
+
export declare function alwaysOnExtensionsQuery(db: KernelSchemaDb, plugin?: string | Expression<string>): import("kysely").SelectQueryBuilder<import("../db/kernel-schema.js").KernelDatabase & {
|
|
22
9
|
ri: import("../db/kernel-schema.js").ExtensionInstallsTable;
|
|
23
10
|
}, "ri", {
|
|
24
11
|
plugin: string;
|
|
25
12
|
}>;
|
|
26
|
-
/** The
|
|
27
|
-
export declare function
|
|
28
|
-
|
|
29
|
-
}, "
|
|
13
|
+
/** The stored choice for this extension. An absent choice follows its source or default. */
|
|
14
|
+
export declare function extensionSwitch(db: KernelSchemaDb, orgId: Key, plugin: Key): import("kysely").SelectQueryBuilder<import("../db/kernel-schema.js").KernelDatabase & {
|
|
15
|
+
extension_switch: import("../db/kernel-schema.js").ComponentOrgSwitchesTable;
|
|
16
|
+
}, "extension_switch", {
|
|
17
|
+
enabled: boolean;
|
|
18
|
+
}>;
|
|
19
|
+
/** The same intent predicate for point, org-list and membership-correlated reads. */
|
|
20
|
+
export declare function extensionIntent(db: KernelSchemaDb, orgId: Key, plugin: Key, proposedChoice?: boolean): import("kysely").RawBuilder<boolean>;
|
|
21
|
+
/** The names enabled in an org, optionally narrowed to one extension in the outer query. */
|
|
22
|
+
export declare function enabledExtensionsQuery(db: KernelSchemaDb, orgId: Key, plugin?: Key): import("kysely").SelectQueryBuilder<import("../db/kernel-schema.js").KernelDatabase, never, {
|
|
30
23
|
plugin: string;
|
|
31
24
|
}>;
|
|
32
|
-
/**
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
}, "
|
|
25
|
+
/** Test only the requested extension names when a deployment-wide reader needs org pairs. */
|
|
26
|
+
export declare function enabledExtensionsByOrg(db: KernelSchemaDb, plugins: readonly string[]): import("kysely").SelectQueryBuilder<import("../db/kernel-schema.js").KernelDatabase & {
|
|
27
|
+
enabled_org: import("../db/kernel-schema.js").OrgsTable;
|
|
28
|
+
} & {
|
|
29
|
+
requested: {
|
|
30
|
+
plugin: string;
|
|
31
|
+
};
|
|
32
|
+
}, "enabled_org" | "requested", {
|
|
40
33
|
org_id: string;
|
|
41
34
|
plugin: string;
|
|
42
35
|
}>;
|
|
43
|
-
/** Whether
|
|
36
|
+
/** Whether the extension has committed intent in the org. Execution checks remain at the caller. */
|
|
44
37
|
export declare function isExtensionEnabled(db: KernelSchemaDb, orgId: string, plugin: string): Promise<boolean>;
|
|
45
38
|
/**
|
|
46
39
|
* The names of the required bootstrap plugins (installed with `required`): the ones that refuse
|
|
@@ -49,3 +42,4 @@ export declare function isExtensionEnabled(db: KernelSchemaDb, orgId: string, pl
|
|
|
49
42
|
export declare function requiredExtensions(db: KernelSchemaDb): Promise<Set<string>>;
|
|
50
43
|
/** The names of the always-on extensions ({@link alwaysOnExtensionsQuery}). */
|
|
51
44
|
export declare function alwaysOnExtensions(db: KernelSchemaDb): Promise<Set<string>>;
|
|
45
|
+
export {};
|