@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
package/dist/ctx/create-ctx.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { CONVERSATION_TARGET_EXTENSION_POINT, CtxReadError, DEVICE_PROVIDER_EXTENSION_POINT, DeviceAccessError, EXTENSION_POINTS, ExtensionPermissionError, ExtensionPointUnavailableError, FILE_PREVIEW_EXTENSION_POINT, InboxError, OBJECT_STORE_EXTENSION_POINT, parseExtensionPoint, resolveUiSlots, SETUP_CHECK_ID_RE, SETUP_GUIDE_PLACES, TriggerError, validateFilePreviewProvider, validateToolSpec, } from "@capybara-hq/plugin-sdk";
|
|
2
|
-
import { Command, ConnectionBuilder, ControlledTransactionBuilder, Kysely, TransactionBuilder, } from "kysely";
|
|
3
2
|
import { conversationTopic } from "../conversations/event-log.js";
|
|
4
3
|
import { checkExternalText } from "../conversations/external/external-calls.js";
|
|
5
4
|
import { pluginSchemaName } from "../db/extension-db.js";
|
|
@@ -9,7 +8,7 @@ import { enabledExtensionsQuery } from "../extensions/enabled.js";
|
|
|
9
8
|
import { checkHookRegistration } from "../extensions/hooks.js";
|
|
10
9
|
import { RegistrationLedger } from "../extensions/ledger.js";
|
|
11
10
|
import { audit } from "../identity/audit.js";
|
|
12
|
-
import { appendEffect
|
|
11
|
+
import { appendEffect } from "../infra/database/extension-handoff.js";
|
|
13
12
|
import { currentScope, withOrgScope } from "../infra/database/org-scope.js";
|
|
14
13
|
import { can } from "../orgs/roles.js";
|
|
15
14
|
import { PrefixedStorage } from "../storage/storage.service.js";
|
|
@@ -17,6 +16,7 @@ import { canUseSlot, orgUiTopic, PLATFORM_UI_TOPIC, PluginUiRegistration, } from
|
|
|
17
16
|
import { createBus } from "./bus.js";
|
|
18
17
|
import { checkDeviceProvider } from "./device-provider-check.js";
|
|
19
18
|
import { assertEffectKey, } from "./durable-effects.service.js";
|
|
19
|
+
import { guardDb } from "./guard-db.js";
|
|
20
20
|
import { createKv } from "./kv.js";
|
|
21
21
|
import { createLock } from "./lock.js";
|
|
22
22
|
import { createExtensionNet } from "./net.js";
|
|
@@ -150,64 +150,6 @@ async function recordDenial(deps, plugin, item) {
|
|
|
150
150
|
deps.log.warn("plugin permission denial audit failed", { plugin, item, err: e });
|
|
151
151
|
}
|
|
152
152
|
}
|
|
153
|
-
/**
|
|
154
|
-
* 包装插件拿到的 Kysely:`destroy`(及 `Symbol.asyncDispose`)换成抛错的函数(连接池归内核所有,插件销毁会拖垮整个进程的 DB 访问),
|
|
155
|
-
* 其余属性透传。方法绑定到原对象(Kysely 用私有字段,以 Proxy 作 this 调用会失败)。
|
|
156
|
-
* 递归包裹一切能再拿到 Kysely 的路径,使 `destroy` 在任何路径都被拦截:
|
|
157
|
-
* - 方法返回的新 Kysely(`withSchema` / `withPlugin` 等);
|
|
158
|
-
* - 方法返回的构建器(`transaction()` / `connection()` / `startTransaction()` 及其链式方法、
|
|
159
|
-
* 受控事务的 `Command`):其方法收到的回调拿到的 Kysely(`transaction().execute(cb)`、
|
|
160
|
-
* `connection().execute(cb)`)与返回的 Promise 结果(`startTransaction().execute()` 得到的受控事务)。
|
|
161
|
-
*/
|
|
162
|
-
function guardDb(db, plugin, transactions) {
|
|
163
|
-
const guarded = new Proxy(db, {
|
|
164
|
-
get(target, prop) {
|
|
165
|
-
// `await using` 经 Symbol.asyncDispose 调用 destroy,同样拦截
|
|
166
|
-
if (prop === "destroy" || prop === Symbol.asyncDispose) {
|
|
167
|
-
return () => {
|
|
168
|
-
throw new Error(`plugin ${plugin}: ctx.db.destroy() is not allowed; the kernel owns the connection pool`);
|
|
169
|
-
};
|
|
170
|
-
}
|
|
171
|
-
const value = Reflect.get(target, prop, target);
|
|
172
|
-
if (typeof value !== "function")
|
|
173
|
-
return value;
|
|
174
|
-
return (...args) => guardValue(value.apply(target, args), plugin, transactions);
|
|
175
|
-
},
|
|
176
|
-
});
|
|
177
|
-
if (isExtensionTransaction(db))
|
|
178
|
-
transactions.set(guarded, db);
|
|
179
|
-
return guarded;
|
|
180
|
-
}
|
|
181
|
-
/** 能(经回调或返回值)再拿到 Kysely 的构建器类。 */
|
|
182
|
-
const BUILDERS = [ConnectionBuilder, TransactionBuilder, ControlledTransactionBuilder, Command];
|
|
183
|
-
const isBuilder = (v) => BUILDERS.some((B) => v instanceof B);
|
|
184
|
-
/** Kysely → guardDb;构建器 → guardBuilder;其余原样返回。 */
|
|
185
|
-
function guardValue(v, plugin, transactions) {
|
|
186
|
-
if (v instanceof Kysely)
|
|
187
|
-
return guardDb(v, plugin, transactions);
|
|
188
|
-
if (isBuilder(v))
|
|
189
|
-
return guardBuilder(v, plugin, transactions);
|
|
190
|
-
return v;
|
|
191
|
-
}
|
|
192
|
-
/** 包装构建器:回调参数里的 Kysely、返回值与 Promise 结果都经 guardValue。 */
|
|
193
|
-
function guardBuilder(builder, plugin, transactions) {
|
|
194
|
-
return new Proxy(builder, {
|
|
195
|
-
get(target, prop) {
|
|
196
|
-
const value = Reflect.get(target, prop, target);
|
|
197
|
-
if (typeof value !== "function")
|
|
198
|
-
return value;
|
|
199
|
-
return (...args) => {
|
|
200
|
-
const wrapped = args.map((a) => typeof a === "function"
|
|
201
|
-
? (...cbArgs) => a(...cbArgs.map((c) => guardValue(c, plugin, transactions)))
|
|
202
|
-
: a);
|
|
203
|
-
const out = guardValue(value.apply(target, wrapped), plugin, transactions);
|
|
204
|
-
return out instanceof Promise
|
|
205
|
-
? out.then((r) => guardValue(r, plugin, transactions))
|
|
206
|
-
: out;
|
|
207
|
-
};
|
|
208
|
-
},
|
|
209
|
-
});
|
|
210
|
-
}
|
|
211
153
|
/** 未注入能力访问时(单独构造 ctx 的测试等):没有任何提供方,组织启用照常查库。 */
|
|
212
154
|
const noProviders = (deps) => ({
|
|
213
155
|
providers: () => [],
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { Kysely } from "kysely";
|
|
2
|
+
/**
|
|
3
|
+
* Protects the owned pool and records the underlying transactions used for durable effects.
|
|
4
|
+
* Kysely methods use private fields, so they are always called on the underlying object.
|
|
5
|
+
*/
|
|
6
|
+
export declare function guardDb(db: Kysely<unknown>, plugin: string, transactions: WeakMap<object, Kysely<unknown>>): Kysely<unknown>;
|
|
@@ -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;
|
|
@@ -2209,6 +2210,7 @@ export interface KernelDatabase {
|
|
|
2209
2210
|
org_notices: OrgNoticesTable;
|
|
2210
2211
|
platform_notices: PlatformNoticesTable;
|
|
2211
2212
|
plugin_scope_sync_failures: PluginScopeSyncFailuresTable;
|
|
2213
|
+
plugin_effect_work: PluginEffectWorkTable;
|
|
2212
2214
|
extension_client_builds: ExtensionClientBuildsTable;
|
|
2213
2215
|
extension_client_reports: ExtensionClientReportsTable;
|
|
2214
2216
|
outbox: OutboxTable;
|
|
@@ -2298,7 +2300,7 @@ export interface PlatformNoticesTable {
|
|
|
2298
2300
|
* 0083: what a failed scope sync attempt was doing: turning the plugin on, off, or installing the
|
|
2299
2301
|
* dependencies a platform update added to a live install.
|
|
2300
2302
|
*/
|
|
2301
|
-
export type ScopeSyncOp = "install" | "uninstall" | "dependencies";
|
|
2303
|
+
export type ScopeSyncOp = "install" | "update" | "uninstall" | "dependencies";
|
|
2302
2304
|
/**
|
|
2303
2305
|
* 0083: an open failure of the plugin scope sync for one (item, org): its last attempt failed; the
|
|
2304
2306
|
* next sync of the pair that does not fail deletes the row.
|
|
@@ -2312,6 +2314,15 @@ export interface PluginScopeSyncFailuresTable {
|
|
|
2312
2314
|
message: string;
|
|
2313
2315
|
failed_at: Ts;
|
|
2314
2316
|
}
|
|
2317
|
+
/** The latest owed or settled generation of a plugin's effects in one org. */
|
|
2318
|
+
export interface PluginEffectWorkTable {
|
|
2319
|
+
item_id: string;
|
|
2320
|
+
org_id: string;
|
|
2321
|
+
generation: string;
|
|
2322
|
+
state: "pending" | "settled";
|
|
2323
|
+
generation_started_at: Ts;
|
|
2324
|
+
updated_at: Ts;
|
|
2325
|
+
}
|
|
2315
2326
|
/** 0050: one row per bootstrap manifest the bootstrap step completed. */
|
|
2316
2327
|
export interface BootstrapRunsTable {
|
|
2317
2328
|
/** sha256 (hex) of the bootstrap manifest. */
|
|
@@ -2370,6 +2381,15 @@ export interface CatalogItemsTable {
|
|
|
2370
2381
|
/** 0084: the owner shares it with other orgs (the gate is `owner_org_id IS NULL OR shareable`). */
|
|
2371
2382
|
shareable: Dflt<boolean>;
|
|
2372
2383
|
}
|
|
2384
|
+
/** 0229: selected deployment versions and their resolved dependency targets. */
|
|
2385
|
+
export interface CatalogDependencyEdgesTable {
|
|
2386
|
+
item_id: string;
|
|
2387
|
+
item_version: string;
|
|
2388
|
+
dependency_name: string;
|
|
2389
|
+
template_id: string;
|
|
2390
|
+
dependency_item_id: string | null;
|
|
2391
|
+
dependency_version: string | null;
|
|
2392
|
+
}
|
|
2373
2393
|
/** 0075: the orgs a `named` item is offered to. */
|
|
2374
2394
|
export interface CatalogItemScopeOrgsTable {
|
|
2375
2395
|
item_id: string;
|
|
@@ -2517,7 +2537,7 @@ export interface ComponentScopeOrgsTable {
|
|
|
2517
2537
|
}
|
|
2518
2538
|
/** 0081: an org's on / off switch of a component. */
|
|
2519
2539
|
export interface ComponentOrgSwitchesTable {
|
|
2520
|
-
kind: ComponentKind;
|
|
2540
|
+
kind: ComponentKind | "extension";
|
|
2521
2541
|
component_id: string;
|
|
2522
2542
|
org_id: string;
|
|
2523
2543
|
enabled: boolean;
|
|
@@ -2721,18 +2741,24 @@ export interface CatalogOrgGrantsTable {
|
|
|
2721
2741
|
granted_at: Generated<Date>;
|
|
2722
2742
|
}
|
|
2723
2743
|
/** 0049 / 0138: the states of a plugin install (`LIVE_INSTALL_STATUSES` are the live ones). */
|
|
2724
|
-
export type PluginInstallStatus = "
|
|
2744
|
+
export type PluginInstallStatus = "on" | "install_failed";
|
|
2745
|
+
export interface PluginEffectError {
|
|
2746
|
+
generation: string;
|
|
2747
|
+
operation: ScopeSyncOp;
|
|
2748
|
+
code: string;
|
|
2749
|
+
message: string;
|
|
2750
|
+
attemptedAt: string;
|
|
2751
|
+
}
|
|
2725
2752
|
/** 0037: a plugin's install in an org. */
|
|
2726
2753
|
export interface PluginInstallsTable {
|
|
2727
2754
|
id: string;
|
|
2728
2755
|
org_id: string;
|
|
2729
2756
|
item_id: string;
|
|
2730
|
-
version: string;
|
|
2731
|
-
/** 0138 dropped 0049's `upgrading` (no per-org upgrade since ruling F2). */
|
|
2757
|
+
version: string | null;
|
|
2732
2758
|
status: PluginInstallStatus;
|
|
2733
2759
|
installed_by: string | null;
|
|
2734
2760
|
installed_at: Generated<Date>;
|
|
2735
|
-
error: ColumnType<
|
|
2761
|
+
error: ColumnType<PluginEffectError | null, string | null | undefined, string | null>;
|
|
2736
2762
|
/**
|
|
2737
2763
|
* 0049: the journal of a per-org upgrade. Unused since 0138 (no code reads or writes it, every
|
|
2738
2764
|
* row null); kept for the replicas of the previous release, dropped by a later migration.
|
|
@@ -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 0231. 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 === "b1f087cb2ef17b0d3f1a53f4f3099ef6" ? undefined : "schema-drift";
|
|
34
34
|
}
|
|
@@ -48,6 +48,7 @@ export const rowRules = [
|
|
|
48
48
|
rule("platform_sealed_reveals", "id"),
|
|
49
49
|
rule("plugin_install_components", "install_id, kind, ref", "install_id IN (SELECT id FROM capybara.plugin_installs WHERE org_id = (SELECT id FROM subject))"),
|
|
50
50
|
rule("plugin_scope_sync_failures", "item_id, org_id"),
|
|
51
|
+
rule("plugin_effect_work", "item_id, org_id"),
|
|
51
52
|
rule("questions", "id"),
|
|
52
53
|
rule("retention_work", "id"),
|
|
53
54
|
rule("secrets", "namespace, org_id, key"),
|
|
@@ -95,6 +96,7 @@ export const rowRules = [
|
|
|
95
96
|
rule("platform_connector_templates", "id", ownedRetired),
|
|
96
97
|
rule("platform_skills", "id", ownedRetired),
|
|
97
98
|
rule("platform_themes", "id", ownedRetired),
|
|
99
|
+
rule("catalog_dependency_edges", "item_id, dependency_name, template_id", ownsCatalogVersion("catalog_items", "item_id")),
|
|
98
100
|
rule("catalog_item_versions", "item_id, version", ownsCatalogVersion("catalog_items", "item_id")),
|
|
99
101
|
rule("catalog_items", "id", ownedRetired),
|
|
100
102
|
];
|
|
@@ -150,6 +152,10 @@ export const childReferences = {
|
|
|
150
152
|
],
|
|
151
153
|
platform_themes: [["platform_theme_versions", "child.theme_id = parent.id"]],
|
|
152
154
|
catalog_items: [
|
|
155
|
+
[
|
|
156
|
+
"catalog_dependency_edges",
|
|
157
|
+
"child.item_id = parent.id OR child.dependency_item_id = parent.id",
|
|
158
|
+
],
|
|
153
159
|
["catalog_item_org_switches", "child.item_id = parent.id"],
|
|
154
160
|
["catalog_item_scope_orgs", "child.item_id = parent.id"],
|
|
155
161
|
["catalog_item_versions", "child.item_id = parent.id"],
|
|
@@ -164,6 +170,7 @@ export const childReferences = {
|
|
|
164
170
|
["platform_themes", "child.catalog_item_id = parent.id"],
|
|
165
171
|
["plugin_installs", "child.item_id = parent.id"],
|
|
166
172
|
["plugin_scope_sync_failures", "child.item_id = parent.id"],
|
|
173
|
+
["plugin_effect_work", "child.item_id = parent.id"],
|
|
167
174
|
["skill_versions", "child.catalog_item_id = parent.id"],
|
|
168
175
|
["skills", "child.catalog_item_id = parent.id"],
|
|
169
176
|
],
|
|
@@ -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;
|
|
@@ -104,7 +111,7 @@ export declare class ExtensionAdminOps {
|
|
|
104
111
|
/** One enabled provider per single-provider extension point (checked in the enable). */
|
|
105
112
|
singleProvider: SingleProviderGuard,
|
|
106
113
|
/** The plugin scope sync a deploy owes (`oweDeployedExtensionSync`). */
|
|
107
|
-
outbox: Pick<OutboxService, "add">);
|
|
114
|
+
outbox: Pick<OutboxService, "add" | "addMany">);
|
|
108
115
|
private get db();
|
|
109
116
|
/**
|
|
110
117
|
* New install or version change (upgrade / downgrade): the install record points at package
|
|
@@ -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 {};
|
|
@@ -11,8 +11,8 @@ import { SDK_VERSION } from "@capybara-hq/plugin-sdk";
|
|
|
11
11
|
import { Inject, Injectable } from "@nestjs/common";
|
|
12
12
|
import { sql } from "kysely";
|
|
13
13
|
import semver from "semver";
|
|
14
|
+
import { oweDeployedExtensionSync } from "../catalog/effect-work.js";
|
|
14
15
|
import { itemRemovedError } from "../catalog/ownership.js";
|
|
15
|
-
import { oweDeployedExtensionSync } from "../catalog/scope-jobs.js";
|
|
16
16
|
import { pluginSchemaName } from "../ctx/create-ctx.js";
|
|
17
17
|
import { ConfiguredExtensionDbIdentity } from "../db/extension-db.js";
|
|
18
18
|
import { EMPTY_EXTENSION_SCHEMA_COMMENT } from "../db/extension-role-provision.js";
|
|
@@ -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)
|
|
@@ -13,6 +13,7 @@ import { ExtensionHost } from "./host.js";
|
|
|
13
13
|
import { ExtensionInstalls } from "./installs.js";
|
|
14
14
|
import { ExtensionLifecycle, PLUGINS_CHANGED_TOPIC } from "./lifecycle.js";
|
|
15
15
|
import { PluginApproveLock } from "./locks.js";
|
|
16
|
+
import type { ExtensionOrgCounts } from "./permission-view.js";
|
|
16
17
|
import { type AdminExtensionView } from "./permission-view.js";
|
|
17
18
|
import { PluginIcons } from "./plugin-icons.js";
|
|
18
19
|
import { SingleProviderGuard } from "./single-provider.js";
|
|
@@ -75,7 +76,7 @@ export declare class ExtensionAdmin {
|
|
|
75
76
|
/** The plugins' icons (admin catalog routes). */
|
|
76
77
|
icons: PluginIcons,
|
|
77
78
|
/** The plugin scope sync an approval of an enabled extension owes. */
|
|
78
|
-
outbox: Pick<OutboxService, "add">);
|
|
79
|
+
outbox: Pick<OutboxService, "add" | "addMany">);
|
|
79
80
|
private get db();
|
|
80
81
|
/**
|
|
81
82
|
* Every extension (config-declared, then install records, each by name). With `names`, only
|
|
@@ -120,6 +121,8 @@ export declare class ExtensionAdmin {
|
|
|
120
121
|
* 包的权限集合(静态清单 + 迁移 SQL,与上传时的审阅相同)、迁移审阅警告与是否有部署级配置字段;按 sha256 缓存。
|
|
121
122
|
*/
|
|
122
123
|
private packageInfo;
|
|
124
|
+
orgCounts(names: readonly string[]): Promise<ExtensionOrgCounts[]>;
|
|
125
|
+
private orgCountsForSubjects;
|
|
123
126
|
/**
|
|
124
127
|
* For each configurable, readable extension whose platform config leaves required overridable
|
|
125
128
|
* fields empty (spec A §5.4a): the number of orgs still needing their own config. Extensions
|