@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.
Files changed (203) hide show
  1. package/dist/admin/audit-log.service.d.ts +96 -12
  2. package/dist/admin/audit-log.service.js +508 -44
  3. package/dist/admin/audit-targets.d.ts +17 -0
  4. package/dist/admin/audit-targets.js +84 -0
  5. package/dist/admin/audit.controller.d.ts +12 -9
  6. package/dist/admin/audit.controller.js +29 -8
  7. package/dist/admin/audit.schemas.d.ts +20 -4
  8. package/dist/admin/audit.schemas.js +42 -17
  9. package/dist/admin/extensions.controller.d.ts +5 -2
  10. package/dist/admin/extensions.controller.js +10 -1
  11. package/dist/admin/extensions.schemas.d.ts +4 -0
  12. package/dist/admin/extensions.schemas.js +9 -0
  13. package/dist/admin/health.service.d.ts +1 -1
  14. package/dist/admin/health.service.js +3 -3
  15. package/dist/agents/templates.js +3 -10
  16. package/dist/app.d.ts +3 -1
  17. package/dist/app.js +1 -0
  18. package/dist/automations/automations.service.js +4 -5
  19. package/dist/catalog/catalog-content.d.ts +6 -8
  20. package/dist/catalog/catalog-content.js +17 -22
  21. package/dist/catalog/catalog-items.d.ts +5 -10
  22. package/dist/catalog/catalog-items.js +27 -51
  23. package/dist/catalog/catalog-scope.service.d.ts +4 -2
  24. package/dist/catalog/catalog-scope.service.js +109 -145
  25. package/dist/catalog/catalog.module.js +7 -4
  26. package/dist/catalog/catalog.service.d.ts +10 -4
  27. package/dist/catalog/catalog.service.js +52 -10
  28. package/dist/catalog/cli.js +17 -0
  29. package/dist/catalog/component-promotion.js +8 -4
  30. package/dist/catalog/component-scope.service.d.ts +3 -1
  31. package/dist/catalog/component-scope.service.js +101 -140
  32. package/dist/catalog/component-state.d.ts +10 -8
  33. package/dist/catalog/component-state.js +42 -30
  34. package/dist/catalog/dependency-edges.d.ts +25 -0
  35. package/dist/catalog/dependency-edges.js +125 -0
  36. package/dist/catalog/effect-work.d.ts +27 -0
  37. package/dist/catalog/effect-work.js +151 -0
  38. package/dist/catalog/jobs.d.ts +4 -1
  39. package/dist/catalog/jobs.js +14 -4
  40. package/dist/catalog/org-catalog.service.d.ts +5 -1
  41. package/dist/catalog/org-catalog.service.js +101 -106
  42. package/dist/catalog/org-intent.d.ts +45 -0
  43. package/dist/catalog/org-intent.js +205 -0
  44. package/dist/catalog/owned-items.d.ts +6 -2
  45. package/dist/catalog/owned-items.js +27 -32
  46. package/dist/catalog/ownership.d.ts +2 -3
  47. package/dist/catalog/ownership.js +10 -28
  48. package/dist/catalog/platform-components.d.ts +3 -1
  49. package/dist/catalog/platform-components.js +9 -1
  50. package/dist/catalog/plugin-import.d.ts +4 -2
  51. package/dist/catalog/plugin-import.js +22 -21
  52. package/dist/catalog/plugin-install.d.ts +19 -54
  53. package/dist/catalog/plugin-install.js +221 -271
  54. package/dist/catalog/plugin-upgrade.d.ts +10 -5
  55. package/dist/catalog/plugin-upgrade.js +80 -67
  56. package/dist/catalog/request-rules.js +20 -8
  57. package/dist/catalog/scope-orgs.js +2 -7
  58. package/dist/catalog/scope-state.d.ts +6 -6
  59. package/dist/catalog/scope-state.js +24 -43
  60. package/dist/catalog/scope-sync-workers.d.ts +7 -11
  61. package/dist/catalog/scope-sync-workers.js +10 -26
  62. package/dist/catalog/scope-sync.d.ts +19 -116
  63. package/dist/catalog/scope-sync.js +228 -275
  64. package/dist/catalog/scope-writer.d.ts +87 -0
  65. package/dist/catalog/scope-writer.js +239 -0
  66. package/dist/catalog/template-connector-ensure.js +1 -1
  67. package/dist/catalog/unshare.js +9 -43
  68. package/dist/channels/connections.service.js +6 -6
  69. package/dist/channels/supervisor.js +3 -7
  70. package/dist/client/client-access.service.js +2 -12
  71. package/dist/config/schema.d.ts +6 -0
  72. package/dist/config/schema.js +32 -1
  73. package/dist/ctx/create-ctx.d.ts +2 -2
  74. package/dist/ctx/create-ctx.js +2 -60
  75. package/dist/ctx/guard-db.d.ts +6 -0
  76. package/dist/ctx/guard-db.js +55 -0
  77. package/dist/db/extension-handoff-schema.d.ts +1 -1
  78. package/dist/db/extension-handoff-schema.js +48 -10
  79. package/dist/db/extension-schema-transfer.js +5 -2
  80. package/dist/db/kernel-schema.d.ts +32 -6
  81. package/dist/device-access/host-services.d.ts +2 -2
  82. package/dist/device-access/host-services.js +5 -6
  83. package/dist/erasure/org-catalog.js +2 -2
  84. package/dist/erasure/org-rules.js +7 -0
  85. package/dist/extensions/admin-ops.d.ts +10 -6
  86. package/dist/extensions/admin-ops.js +53 -9
  87. package/dist/extensions/admin-view.d.ts +4 -1
  88. package/dist/extensions/admin-view.js +27 -14
  89. package/dist/extensions/bootstrap.d.ts +1 -1
  90. package/dist/extensions/bootstrap.js +6 -4
  91. package/dist/extensions/cli.js +1 -0
  92. package/dist/extensions/effective-config.js +1 -4
  93. package/dist/extensions/enabled.d.ts +183 -29
  94. package/dist/extensions/enabled.js +148 -62
  95. package/dist/extensions/host.d.ts +65 -45
  96. package/dist/extensions/host.js +446 -128
  97. package/dist/extensions/installs.d.ts +9 -0
  98. package/dist/extensions/installs.js +23 -0
  99. package/dist/extensions/isolated/admission.d.ts +10 -0
  100. package/dist/extensions/isolated/admission.js +206 -0
  101. package/dist/extensions/isolated/authorization.d.ts +45 -0
  102. package/dist/extensions/isolated/authorization.js +191 -0
  103. package/dist/extensions/isolated/broker.d.ts +15 -0
  104. package/dist/extensions/isolated/broker.js +471 -0
  105. package/dist/extensions/isolated/child-protocol.d.ts +84 -0
  106. package/dist/extensions/isolated/child-protocol.js +21 -0
  107. package/dist/extensions/isolated/child-registration.d.ts +22 -0
  108. package/dist/extensions/isolated/child-registration.js +152 -0
  109. package/dist/extensions/isolated/child-session.d.ts +6 -0
  110. package/dist/extensions/isolated/child-session.js +343 -0
  111. package/dist/extensions/isolated/child-streams.d.ts +4 -0
  112. package/dist/extensions/isolated/child-streams.js +142 -0
  113. package/dist/extensions/isolated/child.d.ts +1 -0
  114. package/dist/extensions/isolated/child.js +10 -0
  115. package/dist/extensions/isolated/configured-package.d.ts +15 -0
  116. package/dist/extensions/isolated/configured-package.js +73 -0
  117. package/dist/extensions/isolated/engine-binds.d.ts +9 -0
  118. package/dist/extensions/isolated/engine-binds.js +82 -0
  119. package/dist/extensions/isolated/engine-policy.d.ts +85 -0
  120. package/dist/extensions/isolated/engine-policy.js +75 -0
  121. package/dist/extensions/isolated/engine-proxy-main.d.ts +1 -0
  122. package/dist/extensions/isolated/engine-proxy-main.js +20 -0
  123. package/dist/extensions/isolated/engine-proxy.d.ts +7 -0
  124. package/dist/extensions/isolated/engine-proxy.js +408 -0
  125. package/dist/extensions/isolated/engine-vaults.d.ts +12 -0
  126. package/dist/extensions/isolated/engine-vaults.js +93 -0
  127. package/dist/extensions/isolated/lanes.d.ts +108 -0
  128. package/dist/extensions/isolated/lanes.js +726 -0
  129. package/dist/extensions/isolated/postgres-gate.d.ts +15 -0
  130. package/dist/extensions/isolated/postgres-gate.js +255 -0
  131. package/dist/extensions/isolated/revision.d.ts +32 -0
  132. package/dist/extensions/isolated/revision.js +359 -0
  133. package/dist/extensions/isolated/rpc-frame.d.ts +50 -0
  134. package/dist/extensions/isolated/rpc-frame.js +193 -0
  135. package/dist/extensions/isolated/rpc.d.ts +66 -0
  136. package/dist/extensions/isolated/rpc.js +314 -0
  137. package/dist/extensions/isolated/sandbox.d.ts +39 -0
  138. package/dist/extensions/isolated/sandbox.js +356 -0
  139. package/dist/extensions/isolated/tier.d.ts +6 -0
  140. package/dist/extensions/isolated/tier.js +45 -0
  141. package/dist/extensions/ledger.d.ts +1 -1
  142. package/dist/extensions/lifecycle-topics.d.ts +2 -0
  143. package/dist/extensions/lifecycle-topics.js +2 -0
  144. package/dist/extensions/lifecycle.d.ts +3 -1
  145. package/dist/extensions/lifecycle.js +53 -5
  146. package/dist/extensions/locks.d.ts +2 -0
  147. package/dist/extensions/locks.js +7 -0
  148. package/dist/extensions/org-config.d.ts +17 -27
  149. package/dist/extensions/org-config.js +114 -129
  150. package/dist/extensions/permission-view.d.ts +6 -1
  151. package/dist/extensions/plugin-guides.d.ts +5 -10
  152. package/dist/extensions/plugin-guides.js +18 -37
  153. package/dist/extensions/plugin-icons.d.ts +3 -21
  154. package/dist/extensions/plugin-icons.js +9 -44
  155. package/dist/extensions/plugin-items.d.ts +10 -30
  156. package/dist/extensions/plugin-items.js +32 -73
  157. package/dist/extensions/source-intent.d.ts +14 -0
  158. package/dist/extensions/source-intent.js +77 -0
  159. package/dist/inbox/platform-inbox.service.js +16 -27
  160. package/dist/index.d.ts +2 -1
  161. package/dist/index.js +2 -1
  162. package/dist/infra/database/database.module.js +6 -1
  163. package/dist/infra/database/kernel-db.d.ts +3 -1
  164. package/dist/infra/database/kernel-db.js +4 -0
  165. package/dist/infra/events/kernel-events.d.ts +4 -0
  166. package/dist/infra/outbox/registry.d.ts +3 -36
  167. package/dist/infra/outbox/registry.js +4 -49
  168. package/dist/infra/paging/paged-read.d.ts +56 -0
  169. package/dist/infra/paging/paged-read.js +78 -0
  170. package/dist/infra/queue/queue-names.d.ts +1 -1
  171. package/dist/infra/queue/queue-names.js +1 -1
  172. package/dist/kernel.d.ts +3 -2
  173. package/dist/kernel.js +21 -2
  174. package/dist/lifecycle/kernel-lifecycle.d.ts +3 -1
  175. package/dist/lifecycle/kernel-lifecycle.js +22 -12
  176. package/dist/lifecycle/tokens.d.ts +8 -0
  177. package/dist/lifecycle/tokens.js +2 -0
  178. package/dist/orgs/directory-sync.js +1 -4
  179. package/dist/orgs/org-lock.d.ts +3 -1
  180. package/dist/orgs/org-lock.js +3 -1
  181. package/dist/orgs/orgs.service.d.ts +3 -1
  182. package/dist/orgs/orgs.service.js +15 -8
  183. package/dist/overrides.d.ts +0 -3
  184. package/dist/overrides.js +0 -2
  185. package/dist/platform/ops/admin.ops.js +14 -3
  186. package/dist/platform/ops/extensions-admin.ops.js +20 -3
  187. package/dist/platform/ops/org-plugins.ops.js +5 -2
  188. package/dist/platform/ops/orgs.ops.js +13 -3
  189. package/dist/platform/ops/plugins.ops.js +11 -10
  190. package/dist/setup/setup-checks.service.js +3 -2
  191. package/dist/skills/usable.js +41 -30
  192. package/dist/themes/theme-state.js +3 -3
  193. package/dist/tools/registry.d.ts +2 -2
  194. package/dist/tools/registry.js +7 -3
  195. package/package.json +2 -2
  196. package/src/migrations/0228_extension_org_switches.sql +56 -0
  197. package/src/migrations/0229_catalog_dependency_edges.sql +17 -0
  198. package/src/migrations/0230_audit_filter_idx.sql +18 -0
  199. package/src/migrations/0231_plugin_effect_work.sql +171 -0
  200. package/dist/catalog/install-status.d.ts +0 -6
  201. package/dist/catalog/install-status.js +0 -6
  202. package/dist/catalog/scope-jobs.d.ts +0 -59
  203. package/dist/catalog/scope-jobs.js +0 -78
@@ -14,6 +14,7 @@ import { templateGuideOf } from "../extensions/plugin-guides.js";
14
14
  import { PluginIcons } from "../extensions/plugin-icons.js";
15
15
  import { ExtensionRegistry } from "../extensions/registry.js";
16
16
  import { ExtensionAvailability } from "../extensions/unavailable.js";
17
+ import { audit } from "../identity/audit.js";
17
18
  import { KernelDb } from "../infra/database/kernel-db.js";
18
19
  import { TransactionHost } from "../infra/database/transaction-host.js";
19
20
  import { Transactional } from "../infra/database/transactional.decorator.js";
@@ -22,14 +23,16 @@ import { OrgLock } from "../orgs/org-lock.js";
22
23
  import { can, roleAtLeast } from "../orgs/roles.js";
23
24
  import { packagePath } from "../packages/tgz.js";
24
25
  import { StorageService } from "../storage/storage.service.js";
26
+ import { assertNotPlatformDefault } from "../themes/theme-usage.js";
25
27
  import { catalogHasIcon, findConnectorIn, orgTemplateView, readCatalogAgentTemplates, readCatalogIcon, readCatalogTemplates, templatePluginProblem, } from "./catalog-content.js";
26
28
  import { itemView, ownerOnlyFacts, versionUsable } from "./catalog-items.js";
27
29
  import { connectorTemplatesOn } from "./component-state.js";
28
- import { LIVE_INSTALL_STATUSES } from "./install-status.js";
30
+ import { orgSees, orgUsable } from "./org-intent.js";
29
31
  import { ownerOf, ownersOf } from "./ownership.js";
30
- import { PluginInstaller, uninstallPreviewHash, upsertOrgSwitch, } from "./plugin-install.js";
32
+ import { PluginInstaller, uninstallPreviewHash, } from "./plugin-install.js";
31
33
  import { schemaPathTitle } from "./schema-path.js";
32
- import { requestable, switchable, visibleTo, wantedOn } from "./scope.js";
34
+ import { requestable, switchable, visibleTo } from "./scope.js";
35
+ import { ScopeWriter } from "./scope-writer.js";
33
36
  const UUID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
34
37
  const itemNotFound = () => new ApiError("catalog.item_not_found", "Catalog item not found");
35
38
  const notOffered = () => new ApiError("catalog.approval_required", "This plugin is not offered to this organization; an org admin can request access");
@@ -63,6 +66,7 @@ let OrgCatalogService = class OrgCatalogService {
63
66
  storage;
64
67
  registry;
65
68
  pluginInstaller;
69
+ scopeWriter;
66
70
  log;
67
71
  txHost;
68
72
  availability;
@@ -70,7 +74,7 @@ let OrgCatalogService = class OrgCatalogService {
70
74
  icons;
71
75
  constructor(kdb,
72
76
  /** The org row lock (orgs/org-lock.ts): joins the caller's transaction. */
73
- orgLock, storage, registry, pluginInstaller, log, txHost,
77
+ orgLock, storage, registry, pluginInstaller, scopeWriter, log, txHost,
74
78
  /** Why a plugin's extension cannot run (the `unavailable` state's reason). */
75
79
  availability,
76
80
  /** The effective config of an extension for the org: a wanted plugin whose config is not valid needs input. */
@@ -80,6 +84,7 @@ let OrgCatalogService = class OrgCatalogService {
80
84
  this.storage = storage;
81
85
  this.registry = registry;
82
86
  this.pluginInstaller = pluginInstaller;
87
+ this.scopeWriter = scopeWriter;
83
88
  this.log = log;
84
89
  this.txHost = txHost;
85
90
  this.availability = availability;
@@ -97,39 +102,17 @@ let OrgCatalogService = class OrgCatalogService {
97
102
  */
98
103
  async list(orgId, accountId, itemId) {
99
104
  const isAdmin = await this.isOrgAdmin(orgId, accountId);
100
- let q = this.db
101
- .selectFrom("catalog_items")
102
- .selectAll()
103
- .where("deleted_at", "is", null)
104
- .orderBy("name")
105
- .orderBy("id");
106
- if (itemId !== undefined)
107
- q = q.where("id", "=", itemId);
108
- if (!isAdmin)
109
- q = q.where("disabled", "=", false);
110
- const all = await q.execute();
111
- const [listed, switches] = await Promise.all([
112
- this.db
113
- .selectFrom("catalog_item_scope_orgs")
114
- .select("item_id")
115
- .where("org_id", "=", orgId)
116
- .execute(),
117
- this.db
118
- .selectFrom("catalog_item_org_switches")
119
- .select(["item_id", "enabled"])
120
- .where("org_id", "=", orgId)
121
- .execute(),
122
- ]);
123
- const inList = new Set(listed.map((r) => r.item_id));
124
- // Hidden `named` items (not listed, not shown to other orgs) are absent; shown ones are
125
- // `not_offered`
126
- const items = all.filter((i) => visibleTo({ scope: i.builtin ? "all" : i.scope }, inList.has(i.id)) ||
127
- requestable(i, inList.has(i.id)));
105
+ const q = orgSees(this.db, orgId, isAdmin)
106
+ .selectAll("item")
107
+ .select("named.item_id as namedItemId")
108
+ .select((eb) => orgUsable(this.db, orgId, eb.ref("item.id")).as("usable"))
109
+ .orderBy("item.name")
110
+ .orderBy("item.id");
111
+ const items = await (itemId === undefined ? q : q.where("item.id", "=", itemId)).execute();
128
112
  if (items.length === 0)
129
113
  return [];
130
- const sw = new Map(switches.map((r) => [r.item_id, r.enabled]));
131
114
  const ids = items.map((i) => i.id);
132
- const [versions, pluginInstalls, requests] = await Promise.all([
115
+ const [versions, pluginInstalls, requests, pendingEffectWork] = await Promise.all([
133
116
  this.db
134
117
  .selectFrom("catalog_item_versions")
135
118
  .select([
@@ -146,9 +129,9 @@ let OrgCatalogService = class OrgCatalogService {
146
129
  .execute(),
147
130
  this.db
148
131
  .selectFrom("plugin_installs")
149
- .select(["id", "item_id", "version"])
132
+ .select(["id", "item_id", "version", "status"])
150
133
  .where("org_id", "=", orgId)
151
- .where("status", "in", [...LIVE_INSTALL_STATUSES])
134
+ .where("item_id", "in", ids)
152
135
  .execute(),
153
136
  this.db
154
137
  .selectFrom("catalog_requests")
@@ -159,7 +142,15 @@ let OrgCatalogService = class OrgCatalogService {
159
142
  .where("status", "=", "pending")
160
143
  .orderBy("created_at")
161
144
  .execute(),
145
+ this.db
146
+ .selectFrom("plugin_effect_work")
147
+ .select("item_id")
148
+ .where("org_id", "=", orgId)
149
+ .where("item_id", "in", ids)
150
+ .where("state", "=", "pending")
151
+ .execute(),
162
152
  ]);
153
+ const pendingEffects = new Set(pendingEffectWork.map((work) => work.item_id));
163
154
  const pending = new Map(requests.map((r) => [
164
155
  r.item_id,
165
156
  { id: r.id, kind: r.kind, createdAt: r.created_at.toISOString() },
@@ -192,7 +183,6 @@ let OrgCatalogService = class OrgCatalogService {
192
183
  const latest = vs.find((v) => v.version === i.latest_version);
193
184
  const a = pluginInstalls.find((x) => x.item_id === i.id);
194
185
  const scope = i.builtin ? "all" : i.scope;
195
- const wanted = wantedOn(i, inList.has(i.id), sw.get(i.id) ?? null);
196
186
  let state;
197
187
  let reason;
198
188
  const extName = extensionOf(i);
@@ -206,36 +196,29 @@ let OrgCatalogService = class OrgCatalogService {
206
196
  state = "unavailable";
207
197
  reason = "plugin_disabled";
208
198
  }
209
- else if (requestable(i, inList.has(i.id)))
199
+ else if (!i.usable && requestable(i, i.namedItemId !== null))
210
200
  state = "not_offered";
211
- // not installed here and its extension cannot run: switching it on would fail (spec §14.2
212
- // problem 1); an installed one keeps its state (an org admin can still switch it off)
213
- else if (!a && why !== undefined) {
201
+ else if (why !== undefined) {
214
202
  state = "unavailable";
215
203
  reason = why.reason;
216
204
  }
217
- else if (a) {
205
+ else if (i.usable) {
218
206
  state = (await configInvalid()) ? "needs_config" : "on";
219
207
  }
220
- else if (i.builtin)
221
- state = "on";
222
- else if (!wanted)
208
+ else
223
209
  state = "off";
224
- else {
225
- // Wanted but not installed: the sync has not installed it (yet, or its install failed);
226
- // `off`, so an org admin can switch it on (the worker start retries it), unless its
227
- // extension's effective config is not valid here
228
- state = (await configInvalid()) ? "needs_config" : "off";
229
- }
230
210
  out.push({
231
211
  ...view,
232
212
  scope,
233
213
  builtin: i.builtin,
234
214
  state,
215
+ ...(pendingEffects.has(i.id) && { setup: "pending" }),
216
+ ...(!pendingEffects.has(i.id) &&
217
+ a?.status === "install_failed" && { setup: "install_failed" }),
235
218
  ...(reason !== undefined && { reason }),
236
219
  switchable: state !== "not_offered" && switchable(i),
237
220
  notDeployed: latest !== undefined && undeployed.has(i.id),
238
- installed: a
221
+ installed: a?.version != null
239
222
  ? {
240
223
  pluginInstallId: a.id,
241
224
  version: a.version,
@@ -354,29 +337,7 @@ let OrgCatalogService = class OrgCatalogService {
354
337
  * (the super admin) every item.
355
338
  */
356
339
  async icon(itemId, isAdmin, orgId) {
357
- if (orgId === undefined)
358
- return readCatalogIcon(this.db, itemId, isAdmin);
359
- if (!UUID_RE.test(itemId))
360
- throw itemNotFound();
361
- // A hidden `named` item stays absent here too
362
- const item = await this.db
363
- .selectFrom("catalog_items")
364
- .select(["scope", "builtin", "shown_to_others", "owner_org_id", "shareable"])
365
- .where("id", "=", itemId)
366
- .where("deleted_at", "is", null)
367
- .executeTakeFirst();
368
- // Not requestable from outside its list (hidden, or held back by the share gate): only listed orgs
369
- if (item && !item.builtin && item.scope === "named" && !requestable(item, false)) {
370
- const listed = await this.db
371
- .selectFrom("catalog_item_scope_orgs")
372
- .select("item_id")
373
- .where("item_id", "=", itemId)
374
- .where("org_id", "=", orgId)
375
- .executeTakeFirst();
376
- if (listed === undefined)
377
- throw itemNotFound();
378
- }
379
- return readCatalogIcon(this.db, itemId, isAdmin);
340
+ return readCatalogIcon(this.db, itemId, isAdmin, orgId);
380
341
  }
381
342
  /** For the admin item detail: whether the latest version has an icon. */
382
343
  hasIcon(itemId) {
@@ -451,32 +412,21 @@ let OrgCatalogService = class OrgCatalogService {
451
412
  const view = await this.pluginInstaller.install(orgId, actor, itemId, version, body, opts);
452
413
  return {
453
414
  status: 201,
454
- installed: { itemId, version, pluginInstallId: view.id },
415
+ installed: { itemId, version, pluginInstallId: view?.id ?? null },
455
416
  install: view,
456
417
  };
457
418
  }
458
419
  /** The item when the org may see it (scope), else `catalog.item_not_found`. */
459
420
  async visibleItem(orgId, itemId) {
460
- const item = await this.db
461
- .selectFrom("catalog_items")
462
- .selectAll()
463
- .where("id", "=", itemId)
464
- .where("deleted_at", "is", null)
421
+ const item = await orgSees(this.db, orgId, true)
422
+ .selectAll("item")
423
+ .select("named.item_id as namedItemId")
424
+ .where("item.id", "=", itemId)
465
425
  .executeTakeFirst();
466
- if (!item)
426
+ if (item === undefined)
467
427
  throw itemNotFound();
468
- const listed = await this.db
469
- .selectFrom("catalog_item_scope_orgs")
470
- .select("item_id")
471
- .where("item_id", "=", itemId)
472
- .where("org_id", "=", orgId)
473
- .executeTakeFirst();
474
- if (!visibleTo({ scope: item.builtin ? "all" : item.scope }, listed !== undefined)) {
475
- // Shown to other orgs: the org sees it and may request access, but cannot switch it on
476
- if (requestable(item, false))
477
- throw notOffered();
478
- throw itemNotFound();
479
- }
428
+ if (requestable(item, item.namedItemId !== null))
429
+ throw notOffered();
480
430
  return item;
481
431
  }
482
432
  /** The org's live plugin install of the item, if any. */
@@ -486,7 +436,7 @@ let OrgCatalogService = class OrgCatalogService {
486
436
  .select("id")
487
437
  .where("org_id", "=", orgId)
488
438
  .where("item_id", "=", itemId)
489
- .where("status", "in", [...LIVE_INSTALL_STATUSES])
439
+ .where("version", "is not", null)
490
440
  .executeTakeFirst();
491
441
  }
492
442
  /**
@@ -509,7 +459,7 @@ let OrgCatalogService = class OrgCatalogService {
509
459
  if (item.disabled)
510
460
  throw pluginDisabled();
511
461
  if ((await this.liveInstall(orgId, itemId)) !== undefined) {
512
- await this.recordSwitch(orgId, actor, itemId, true);
462
+ await this.recordSwitch(orgId, actor, itemId, true, opts);
513
463
  }
514
464
  else {
515
465
  await this.install(orgId, actor, itemId, body.inputs ?? {}, actorTokenId, auditDetail);
@@ -521,7 +471,11 @@ let OrgCatalogService = class OrgCatalogService {
521
471
  }
522
472
  const live = await this.liveInstall(orgId, itemId);
523
473
  if (live === undefined) {
524
- await this.recordSwitch(orgId, actor, itemId, false);
474
+ const preview = await this.previewContentOff(orgId, itemId);
475
+ if (preview && body.confirm === undefined) {
476
+ return { kind: "preview", preview, confirm: uninstallPreviewHash(preview) };
477
+ }
478
+ await this.recordSwitch(orgId, actor, itemId, false, opts, body.confirm);
525
479
  return { kind: "done", item: await this.itemOf(orgId, actor, itemId) };
526
480
  }
527
481
  // The platform default theme is locked on (themes spec §7): refused at the preview already;
@@ -550,12 +504,12 @@ let OrgCatalogService = class OrgCatalogService {
550
504
  const row = await this.db
551
505
  .selectFrom("plugin_installs as a")
552
506
  .innerJoin("catalog_items as i", "i.id", "a.item_id")
553
- .select(["i.scope", "i.builtin", "a.status"])
507
+ .select(["i.scope", "i.builtin", "a.version"])
554
508
  .where("a.id", "=", installId)
555
509
  .where("a.org_id", "=", orgId)
556
510
  .executeTakeFirst();
557
511
  // A failed or stuck install is cleaned up whatever the scope (it is not on anyway)
558
- const live = row?.status === "installed";
512
+ const live = row?.version != null;
559
513
  if (row !== undefined && live && !switchable(row)) {
560
514
  throw new ApiError("plugin.scope_locked", "This plugin is built in: it is on for every organization and cannot be uninstalled here");
561
515
  }
@@ -567,6 +521,17 @@ let OrgCatalogService = class OrgCatalogService {
567
521
  // item its scope wants stays wanted and the sync installs it again
568
522
  row !== undefined && live ? {} : undefined);
569
523
  }
524
+ /** The switch-off impact even when there are no applied org resources. */
525
+ async previewContentOff(orgId, itemId) {
526
+ const preview = await this.pluginInstaller.previewContentOff(orgId, itemId);
527
+ if (!preview)
528
+ return null;
529
+ const themes = preview.themes ?? [];
530
+ if (themes.length > 0) {
531
+ await assertNotPlatformDefault(this.db, themes.map((theme) => theme.id), () => "narrower");
532
+ }
533
+ return preview.agents.length > 0 || themes.length > 0 ? preview : null;
534
+ }
570
535
  async itemOf(orgId, accountId, itemId) {
571
536
  const [item] = await this.list(orgId, accountId, itemId);
572
537
  if (!item)
@@ -578,7 +543,7 @@ let OrgCatalogService = class OrgCatalogService {
578
543
  * SHARE first (exclusive with a scope change, an unshare, ruling P3-25, and an owner's delete or
579
544
  * transfer); switching on re-checks that the org may still see it; the install path re-checks the same in `assertItemInstallable`.
580
545
  */
581
- async recordSwitch(orgId, actor, itemId, enabled) {
546
+ async recordSwitch(orgId, actor, itemId, enabled, opts, confirm) {
582
547
  await this.orgLock.lock(orgId);
583
548
  // Both directions lock the item row FOR SHARE: an owner's delete or transfer (FOR UPDATE)
584
549
  // decides on who uses it, so a switch-off racing it must not change that answer meanwhile
@@ -602,7 +567,36 @@ let OrgCatalogService = class OrgCatalogService {
602
567
  throw itemNotFound();
603
568
  }
604
569
  }
605
- await upsertOrgSwitch(this.db, orgId, itemId, enabled, actor);
570
+ else {
571
+ if (item?.builtin)
572
+ throw new ApiError("plugin.scope_locked", "A built-in plugin cannot be switched off");
573
+ const themes = await this.db
574
+ .selectFrom("platform_themes")
575
+ .select("id")
576
+ .where("catalog_item_id", "=", itemId)
577
+ .where("scope_mode", "=", "follow")
578
+ .where("deleted_at", "is", null)
579
+ .where("disabled", "=", false)
580
+ .orderBy("id")
581
+ .forShare()
582
+ .execute();
583
+ await assertNotPlatformDefault(this.db, themes.map((theme) => theme.id), () => "narrower");
584
+ }
585
+ if (!enabled) {
586
+ const preview = await this.previewContentOff(orgId, itemId);
587
+ if (preview && uninstallPreviewHash(preview) !== confirm) {
588
+ throw new ApiError("plugin.switch_stale", "The switch preview changed; review it and confirm again");
589
+ }
590
+ }
591
+ await this.scopeWriter.setOrgSwitch({ kind: "plugin", id: itemId }, orgId, enabled, actor);
592
+ await audit(this.db, {
593
+ actorAccountId: actor,
594
+ ...(opts.actorTokenId !== undefined && { actorTokenId: opts.actorTokenId }),
595
+ orgId,
596
+ action: "catalog.scope_changed",
597
+ target: itemId,
598
+ detail: { enabled, ...opts.auditDetail },
599
+ });
606
600
  }
607
601
  /** The actor can install something in the org (forbidden otherwise), checked before item errors. */
608
602
  async assertCanInstall(orgId, actor) {
@@ -625,10 +619,11 @@ OrgCatalogService = __decorate([
625
619
  __param(2, Inject(StorageService)),
626
620
  __param(3, Inject(ExtensionRegistry)),
627
621
  __param(4, Inject(PluginInstaller)),
628
- __param(5, Inject(KERNEL_LOGGER)),
629
- __param(6, Inject(TransactionHost)),
630
- __param(7, Inject(ExtensionAvailability)),
631
- __param(8, Inject(EffectiveConfigs)),
632
- __param(9, Inject(PluginIcons))
622
+ __param(5, Inject(ScopeWriter)),
623
+ __param(6, Inject(KERNEL_LOGGER)),
624
+ __param(7, Inject(TransactionHost)),
625
+ __param(8, Inject(ExtensionAvailability)),
626
+ __param(9, Inject(EffectiveConfigs)),
627
+ __param(10, Inject(PluginIcons))
633
628
  ], OrgCatalogService);
634
629
  export { OrgCatalogService };
@@ -0,0 +1,45 @@
1
+ import { type Expression } from "kysely";
2
+ import type { KernelSchemaDb } from "../db/kernel-schema.js";
3
+ import type { PluginScope } from "./scope.js";
4
+ type Key = string | Expression<string>;
5
+ export declare const DEPENDENCY_DEPTH_LIMIT = 10;
6
+ export interface ProposedPluginScope {
7
+ itemId: string;
8
+ scope: PluginScope;
9
+ orgs: string[];
10
+ disabled: boolean;
11
+ resetComponents: boolean;
12
+ }
13
+ /** Shared ownership gate used before applying the subject's offer or intent. */
14
+ export declare function orgCatalogAdmits(db: KernelSchemaDb, orgId: Key, itemId: Key): import("kysely").RawBuilder<boolean>;
15
+ /** Catalog visibility for one org. A named association never widens the owner's share gate. */
16
+ export declare function orgSees(db: KernelSchemaDb, orgId: Key, isAdmin: boolean, view?: "catalog" | "offered"): import("kysely").SelectQueryBuilder<import("../db/kernel-schema.js").KernelDatabase & {
17
+ item: import("../db/kernel-schema.js").CatalogItemsTable;
18
+ } & {
19
+ named: import("kysely").Nullable<import("../db/kernel-schema.js").CatalogItemScopeOrgsTable>;
20
+ }, "item" | "named", Partial<Omit<unknown, never>>>;
21
+ /** Project a catalog item's direct intent, before considering dependency roots. */
22
+ export declare function orgPluginDirectIntent(db: KernelSchemaDb, orgId: Key, proposal?: ProposedPluginScope, offItemId?: string): import("kysely").SelectQueryBuilder<import("../db/kernel-schema.js").KernelDatabase & {
23
+ item: import("../db/kernel-schema.js").CatalogItemsTable;
24
+ } & {
25
+ named: import("kysely").Nullable<import("../db/kernel-schema.js").CatalogItemScopeOrgsTable>;
26
+ } & {
27
+ org_switch: import("kysely").Nullable<import("../db/kernel-schema.js").CatalogItemOrgSwitchesTable>;
28
+ }, "item" | "named" | "org_switch", Partial<Omit<unknown, never>> & {
29
+ directIntent: boolean;
30
+ }>;
31
+ /**
32
+ * Find directly enabled roots using the reverse index. Check the selected graph of each root
33
+ * for missing or ineligible dependencies. Deduplication by depth bounds repeated diamond paths
34
+ * and turns cycles and over-deep graphs into denials.
35
+ */
36
+ export declare function orgUsable(db: KernelSchemaDb, orgId: Key, itemId: string | Expression<string | null>, proposal?: ProposedPluginScope, offItemId?: string): import("kysely").RawBuilder<boolean>;
37
+ /** Content lost when the org stops following one root, while other roots remain available. */
38
+ export declare function contentLostWhenOff(db: KernelSchemaDb, orgId: string, itemId: string): Promise<string[]>;
39
+ /** Setup attempts also surface failures for an authorized direct choice with a blocked dependency. */
40
+ export declare function orgPluginEffectIntent(db: KernelSchemaDb, orgId: Key, itemId: string): import("kysely").RawBuilder<boolean>;
41
+ /** Filter existing display rows with the same visibility projection as the catalog query. */
42
+ export declare function visibleCatalogRows<T extends {
43
+ id: string;
44
+ }>(db: KernelSchemaDb, rows: T[], orgId: string, isAdmin: boolean): Promise<T[]>;
45
+ export {};
@@ -0,0 +1,205 @@
1
+ import { sql } from "kysely";
2
+ export const DEPENDENCY_DEPTH_LIMIT = 10;
3
+ function proposed(item, proposal, stored, next) {
4
+ return proposal === undefined
5
+ ? stored
6
+ : sql `CASE WHEN ${sql.ref(`${item}.id`)} = ${proposal.itemId} THEN ${next} ELSE ${stored} END`;
7
+ }
8
+ function orgCatalogItems(db, orgId, isAdmin) {
9
+ return db
10
+ .selectFrom("catalog_items as item")
11
+ .leftJoin("catalog_item_scope_orgs as named", (join) => join.onRef("named.item_id", "=", "item.id").on("named.org_id", "=", orgId))
12
+ .where("item.deleted_at", "is", null)
13
+ .where((eb) => eb.or([
14
+ eb("item.owner_org_id", "is", null),
15
+ eb("item.owner_org_id", "=", orgId),
16
+ eb.and([
17
+ eb("item.shareable", "=", true),
18
+ eb.exists(eb
19
+ .selectFrom("catalog_item_versions as visible_version")
20
+ .select("visible_version.item_id")
21
+ .whereRef("visible_version.item_id", "=", "item.id")
22
+ .whereRef("visible_version.version", "=", "item.latest_version")
23
+ .where("visible_version.applied_at", "is not", null)),
24
+ ]),
25
+ ]))
26
+ .$if(!isAdmin, (q) => q.where("item.disabled", "=", false));
27
+ }
28
+ /** Shared ownership gate used before applying the subject's offer or intent. */
29
+ export function orgCatalogAdmits(db, orgId, itemId) {
30
+ return sql `exists (${orgCatalogItems(db, orgId, true)
31
+ .select("item.id")
32
+ .where("item.id", "=", itemId)})`;
33
+ }
34
+ /** Catalog visibility for one org. A named association never widens the owner's share gate. */
35
+ export function orgSees(db, orgId, isAdmin, view = "catalog") {
36
+ return orgCatalogItems(db, orgId, isAdmin).where((eb) => eb.or([
37
+ eb("item.builtin", "=", true),
38
+ eb("item.scope", "!=", "named"),
39
+ eb("named.item_id", "is not", null),
40
+ ...(view === "catalog" ? [eb("item.shown_to_others", "=", true)] : []),
41
+ orgUsable(db, orgId, eb.ref("item.id")),
42
+ ]));
43
+ }
44
+ /** Project a catalog item's direct intent, before considering dependency roots. */
45
+ export function orgPluginDirectIntent(db, orgId, proposal, offItemId) {
46
+ const scope = proposed("item", proposal, sql `item.scope`, sql `${proposal?.scope}::text`);
47
+ const enabled = proposed("item", proposal, sql `NOT item.disabled`, sql `${!proposal?.disabled}::boolean`);
48
+ const listed = proposed("item", proposal, sql `named.item_id IS NOT NULL`, sql `${orgId} = ANY(${proposal?.orgs}::text[])`);
49
+ return orgCatalogItems(db, orgId, true)
50
+ .leftJoin("catalog_item_org_switches as org_switch", (join) => join.onRef("org_switch.item_id", "=", "item.id").on("org_switch.org_id", "=", orgId))
51
+ .select(sql `(${enabled} AND ${offItemId === undefined ? sql `true` : sql `item.id <> ${offItemId}`} AND (
52
+ (item.builtin AND item.owner_org_id IS NULL) OR
53
+ (${scope} = 'optional' AND org_switch.enabled IS TRUE) OR
54
+ ((${scope} = 'all' OR (${scope} = 'named' AND ${listed})) AND org_switch.enabled IS NOT FALSE)
55
+ ))`.as("directIntent"));
56
+ }
57
+ /** The live catalog and ownership gate for every item in the selected dependency graph. */
58
+ function graphAdmits(alias, orgId, proposal) {
59
+ const item = sql.table(alias);
60
+ const enabled = proposed(alias, proposal, sql `NOT ${item}.disabled`, sql `${!proposal?.disabled}::boolean`);
61
+ return sql `
62
+ ${item}.deleted_at IS NULL AND ${enabled}
63
+ AND (
64
+ ${item}.owner_org_id IS NULL OR ${item}.owner_org_id = ${orgId}
65
+ OR (${item}.shareable AND EXISTS (
66
+ SELECT 1 FROM capybara.catalog_item_versions AS published
67
+ WHERE published.item_id = ${item}.id
68
+ AND published.version = ${item}.latest_version
69
+ AND published.applied_at IS NOT NULL
70
+ ))
71
+ )`;
72
+ }
73
+ /** Declared dependencies always apply. An implied provider follows its template's own intent. */
74
+ function edgeApplies(orgId, proposal) {
75
+ const follows = proposed("parent", proposal, sql `template.scope_mode = 'follow'`, sql `${proposal?.resetComponents ?? false} OR template.scope_mode = 'follow'`);
76
+ return sql `(
77
+ edge.template_id = '' OR EXISTS (
78
+ SELECT 1
79
+ FROM capybara.platform_connector_templates AS template
80
+ LEFT JOIN capybara.component_org_switches AS choice
81
+ ON choice.kind = 'connector_template' AND choice.component_id = template.id
82
+ AND choice.org_id = ${orgId}
83
+ LEFT JOIN capybara.component_scope_orgs AS named
84
+ ON named.kind = 'connector_template' AND named.component_id = template.id
85
+ AND named.org_id = ${orgId}
86
+ WHERE template.id = edge.template_id
87
+ AND template.deleted_at IS NULL AND NOT template.disabled
88
+ AND (template.owner_org_id IS NULL OR template.owner_org_id = ${orgId} OR template.shareable)
89
+ AND CASE WHEN ${follows} THEN
90
+ CASE WHEN (NOT parent.builtin OR parent.owner_org_id IS NOT NULL)
91
+ AND template.file->>'defaultEnabled' = 'false'
92
+ THEN choice.enabled IS TRUE ELSE choice.enabled IS NOT FALSE END
93
+ WHEN template.scope = 'optional' THEN choice.enabled IS TRUE
94
+ ELSE (template.scope = 'all' OR named.component_id IS NOT NULL)
95
+ AND choice.enabled IS NOT FALSE
96
+ END
97
+ )
98
+ )`;
99
+ }
100
+ /** Implied providers must be offered to the org. Only a declared dependency can lift that gate. */
101
+ function edgeAdmitsTarget(orgId, proposal) {
102
+ const scope = proposed("dep", proposal, sql `dep.scope`, sql `${proposal?.scope}::text`);
103
+ const listed = proposed("dep", proposal, sql `EXISTS (
104
+ SELECT 1 FROM capybara.catalog_item_scope_orgs AS offer
105
+ WHERE offer.item_id = dep.id AND offer.org_id = ${orgId}
106
+ )`, sql `${orgId} = ANY(${proposal?.orgs}::text[])`);
107
+ return sql `(
108
+ edge.template_id = '' OR ${scope} <> 'named' OR dep.builtin OR ${listed}
109
+ )`;
110
+ }
111
+ /**
112
+ * Find directly enabled roots using the reverse index. Check the selected graph of each root
113
+ * for missing or ineligible dependencies. Deduplication by depth bounds repeated diamond paths
114
+ * and turns cycles and over-deep graphs into denials.
115
+ */
116
+ export function orgUsable(db, orgId, itemId, proposal, offItemId) {
117
+ const direct = orgPluginDirectIntent(db, orgId, proposal, offItemId)
118
+ .where("item.id", "=", sql `reach.id`)
119
+ .limit(1);
120
+ return sql `exists (
121
+ WITH RECURSIVE reach(id, version) AS (
122
+ SELECT target.id, coalesce(target.platform_synced_version, target.latest_version)
123
+ FROM capybara.catalog_items AS target
124
+ WHERE target.id = ${itemId} AND ${graphAdmits("target", orgId, proposal)}
125
+ AND EXISTS (SELECT 1 FROM capybara.orgs AS live_org WHERE live_org.id = ${orgId} AND live_org.deleted_at IS NULL)
126
+ UNION
127
+ SELECT parent.id, edge.item_version
128
+ FROM reach
129
+ JOIN LATERAL (
130
+ SELECT item_id, item_version, template_id
131
+ FROM capybara.catalog_dependency_edges
132
+ WHERE dependency_item_id = reach.id AND dependency_version = reach.version
133
+ OFFSET 0
134
+ ) AS edge ON true
135
+ JOIN capybara.catalog_items AS parent ON parent.id = edge.item_id
136
+ WHERE ${graphAdmits("parent", orgId, proposal)}
137
+ AND edge.item_version = coalesce(parent.platform_synced_version, parent.latest_version)
138
+ AND ${edgeApplies(orgId, proposal)}
139
+ ), roots AS (
140
+ SELECT reach.id, reach.version FROM reach
141
+ JOIN LATERAL (${direct}) AS root ON root."directIntent"
142
+ ), requirements(root_id, id, version, depth, blocked) AS (
143
+ SELECT roots.id, roots.id, roots.version, 0, false FROM roots
144
+ UNION
145
+ SELECT requirements.root_id, dep.id, edge.dependency_version, requirements.depth + 1,
146
+ dep.id IS NULL OR requirements.depth >= ${DEPENDENCY_DEPTH_LIMIT}
147
+ FROM requirements
148
+ JOIN LATERAL (
149
+ SELECT item_id, template_id, dependency_item_id, dependency_version
150
+ FROM capybara.catalog_dependency_edges
151
+ WHERE item_id = requirements.id AND item_version = requirements.version
152
+ OFFSET 0
153
+ ) AS edge ON true
154
+ JOIN capybara.catalog_items AS parent ON parent.id = edge.item_id
155
+ LEFT JOIN capybara.catalog_items AS dep
156
+ ON dep.id = edge.dependency_item_id
157
+ AND coalesce(dep.platform_synced_version, dep.latest_version) = edge.dependency_version
158
+ AND ${graphAdmits("dep", orgId, proposal)} AND ${edgeAdmitsTarget(orgId, proposal)}
159
+ WHERE NOT requirements.blocked AND ${edgeApplies(orgId, proposal)}
160
+ )
161
+ SELECT 1 FROM roots
162
+ WHERE NOT EXISTS (
163
+ SELECT 1 FROM requirements WHERE requirements.root_id = roots.id AND requirements.blocked
164
+ )
165
+ )`;
166
+ }
167
+ /** Content lost when the org stops following one root, while other roots remain available. */
168
+ export async function contentLostWhenOff(db, orgId, itemId) {
169
+ const candidateId = sql.ref("affected.id");
170
+ const { rows } = await sql `
171
+ WITH RECURSIVE affected(id) AS (
172
+ SELECT id FROM capybara.catalog_items WHERE id = ${itemId}
173
+ UNION
174
+ SELECT edge.dependency_item_id
175
+ FROM affected
176
+ JOIN capybara.catalog_items AS parent ON parent.id = affected.id
177
+ JOIN capybara.catalog_dependency_edges AS edge ON edge.item_id = parent.id
178
+ AND edge.item_version = coalesce(parent.platform_synced_version, parent.latest_version)
179
+ WHERE edge.dependency_item_id IS NOT NULL
180
+ )
181
+ SELECT id FROM affected
182
+ WHERE ${orgUsable(db, orgId, candidateId)}
183
+ AND NOT ${orgUsable(db, orgId, candidateId, undefined, itemId)}
184
+ ORDER BY id
185
+ `.execute(db);
186
+ return rows.map((row) => row.id);
187
+ }
188
+ /** Setup attempts also surface failures for an authorized direct choice with a blocked dependency. */
189
+ export function orgPluginEffectIntent(db, orgId, itemId) {
190
+ const direct = orgPluginDirectIntent(db, orgId).where("item.id", "=", itemId);
191
+ return sql `(
192
+ coalesce((${direct}), false) OR ${orgUsable(db, orgId, itemId)}
193
+ )`;
194
+ }
195
+ /** Filter existing display rows with the same visibility projection as the catalog query. */
196
+ export async function visibleCatalogRows(db, rows, orgId, isAdmin) {
197
+ if (rows.length === 0)
198
+ return [];
199
+ const visible = await orgSees(db, orgId, isAdmin)
200
+ .select("item.id")
201
+ .where("item.id", "in", [...new Set(rows.map((row) => row.id))])
202
+ .execute();
203
+ const ids = new Set(visible.map((row) => row.id));
204
+ return rows.filter((row) => ids.has(row.id));
205
+ }
@@ -1,5 +1,7 @@
1
1
  import { KernelDb } from "../infra/database/kernel-db.js";
2
2
  import { TransactionHost } from "../infra/database/transaction-host.js";
3
+ import { XactLock } from "../infra/database/xact-lock.js";
4
+ import { KernelEvents } from "../infra/events/kernel-events.js";
3
5
  import type { KernelLogger } from "../log.js";
4
6
  import { OrgLock } from "../orgs/org-lock.js";
5
7
  import { SkillsService } from "../skills/skills.service.js";
@@ -46,11 +48,13 @@ export declare class OwnedItems {
46
48
  private readonly skills;
47
49
  private readonly log;
48
50
  readonly txHost: TransactionHost;
51
+ private readonly xactLock;
52
+ private readonly events;
49
53
  constructor(kdb: KernelDb, orgLock: OrgLock, catalog: CatalogService, scope: CatalogScopeService,
50
54
  /** The owner org's own uninstall of a removed plugin (ruling P3-41). */
51
55
  installer: PluginInstaller,
52
56
  /** The owner's org skill row, soft-deleted after its promoted platform row leaves it. */
53
- skills: SkillsService, log: KernelLogger, txHost: TransactionHost);
57
+ skills: SkillsService, log: KernelLogger, txHost: TransactionHost, xactLock: XactLock, events: KernelEvents);
54
58
  private get db();
55
59
  /**
56
60
  * The owner org's 可共享 flag of its item, written on the item and (a plugin) every component
@@ -131,7 +135,7 @@ export declare class OwnedItems {
131
135
  * `named` = the orgs using it, ruling P3-39; an `optional` item stays `optional`, ruling P3-40:
132
136
  * it passed the share gate already, so every org could see it, and the former owner is then an
133
137
  * ordinary org that may switch it on again), written
134
- * directly rather than through the guarded scope writer (ruling P3-27); platform notice
138
+ * using the scope writer under the ownership transaction (ruling P3-27); platform notice
135
139
  * `ownership_transferred`, audit `catalog.ownership_transferred`, the scope sync owed with it
136
140
  * (it uninstalls the former owner's install). Otherwise -> `removed`: the soft delete of
137
141
  * `catalog.remove` ({@link CatalogService.removeIn}); an owner delete