@capybara-hq/kernel 0.1.0-rc.141 → 0.1.0-rc.143

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 (129) hide show
  1. package/dist/agents/agents.module.js +3 -0
  2. package/dist/agents/agents.service.js +1 -1
  3. package/dist/agents/org-templates.d.ts +3 -1
  4. package/dist/agents/org-templates.js +7 -3
  5. package/dist/agents/pending-connector-requests.d.ts +10 -4
  6. package/dist/agents/pending-connector-requests.js +29 -7
  7. package/dist/automations/events/acceptance.d.ts +6 -1
  8. package/dist/automations/events/acceptance.js +30 -11
  9. package/dist/catalog/catalog-import.module.js +3 -0
  10. package/dist/catalog/catalog-scope.service.d.ts +3 -1
  11. package/dist/catalog/catalog-scope.service.js +11 -7
  12. package/dist/catalog/catalog.module.js +3 -0
  13. package/dist/catalog/catalog.service.d.ts +3 -1
  14. package/dist/catalog/catalog.service.js +8 -4
  15. package/dist/catalog/component-promotion.d.ts +3 -1
  16. package/dist/catalog/component-promotion.js +7 -3
  17. package/dist/catalog/component-scope.service.d.ts +3 -1
  18. package/dist/catalog/component-scope.service.js +7 -3
  19. package/dist/catalog/enable-requests.d.ts +10 -8
  20. package/dist/catalog/enable-requests.js +40 -21
  21. package/dist/catalog/owned-items.d.ts +3 -1
  22. package/dist/catalog/owned-items.js +13 -9
  23. package/dist/catalog/platform-components.d.ts +6 -1
  24. package/dist/catalog/platform-components.js +9 -3
  25. package/dist/catalog/plugin-connectors.d.ts +8 -4
  26. package/dist/catalog/plugin-connectors.js +12 -6
  27. package/dist/catalog/plugin-import.d.ts +3 -1
  28. package/dist/catalog/plugin-import.js +14 -5
  29. package/dist/catalog/plugin-install.d.ts +3 -1
  30. package/dist/catalog/plugin-install.js +8 -4
  31. package/dist/catalog/plugin-upgrade.d.ts +3 -1
  32. package/dist/catalog/plugin-upgrade.js +8 -4
  33. package/dist/catalog/request-hints.d.ts +19 -0
  34. package/dist/catalog/request-hints.js +34 -0
  35. package/dist/catalog/request-rules.d.ts +9 -5
  36. package/dist/catalog/request-rules.js +16 -9
  37. package/dist/catalog/requests.service.d.ts +3 -1
  38. package/dist/catalog/requests.service.js +28 -9
  39. package/dist/catalog/scope-orgs.d.ts +2 -1
  40. package/dist/catalog/scope-orgs.js +2 -2
  41. package/dist/catalog/scope-sync.d.ts +3 -1
  42. package/dist/catalog/scope-sync.js +12 -2
  43. package/dist/catalog/scope-writer.d.ts +6 -3
  44. package/dist/catalog/scope-writer.js +28 -10
  45. package/dist/catalog/unshare.d.ts +3 -2
  46. package/dist/catalog/unshare.js +4 -4
  47. package/dist/config/schema.d.ts +4 -0
  48. package/dist/config/schema.js +40 -0
  49. package/dist/db/migrator.js +36 -0
  50. package/dist/extensions/admin-ops.d.ts +6 -1
  51. package/dist/extensions/admin-ops.js +17 -4
  52. package/dist/extensions/deployment-config.d.ts +6 -1
  53. package/dist/extensions/deployment-config.js +13 -2
  54. package/dist/extensions/extensions.module.js +3 -0
  55. package/dist/extensions/org-config.d.ts +3 -1
  56. package/dist/extensions/org-config.js +13 -4
  57. package/dist/extensions/org-overrides.d.ts +6 -1
  58. package/dist/extensions/org-overrides.js +13 -2
  59. package/dist/http/api.module.js +6 -0
  60. package/dist/inbox/inbox-items.service.d.ts +6 -1
  61. package/dist/inbox/inbox-items.service.js +29 -10
  62. package/dist/inbox/inbox.module.js +3 -0
  63. package/dist/inbox/inbox.service.d.ts +3 -1
  64. package/dist/inbox/inbox.service.js +9 -2
  65. package/dist/inbox/org-notices.d.ts +4 -3
  66. package/dist/inbox/org-notices.js +9 -6
  67. package/dist/inbox/platform-inbox.service.d.ts +3 -1
  68. package/dist/inbox/platform-inbox.service.js +11 -3
  69. package/dist/inbox/platform-notices.d.ts +3 -2
  70. package/dist/inbox/platform-notices.js +10 -4
  71. package/dist/infra/config/kernel-config.service.js +5 -0
  72. package/dist/invalidation/audiences.d.ts +32 -0
  73. package/dist/invalidation/audiences.js +43 -0
  74. package/dist/invalidation/hints.d.ts +62 -0
  75. package/dist/invalidation/hints.js +73 -0
  76. package/dist/invalidation/invalidation-hints.d.ts +35 -0
  77. package/dist/invalidation/invalidation-hints.js +100 -0
  78. package/dist/invalidation/invalidation-hints.module.d.ts +10 -0
  79. package/dist/invalidation/invalidation-hints.module.js +26 -0
  80. package/dist/invalidation/me-stream.controller.d.ts +30 -0
  81. package/dist/invalidation/me-stream.controller.js +100 -0
  82. package/dist/invalidation/me-stream.d.ts +57 -0
  83. package/dist/invalidation/me-stream.js +322 -0
  84. package/dist/invalidation/me-stream.module.d.ts +7 -0
  85. package/dist/invalidation/me-stream.module.js +22 -0
  86. package/dist/invalidation/org-intent-bridge.d.ts +18 -0
  87. package/dist/invalidation/org-intent-bridge.js +46 -0
  88. package/dist/kernel.module.js +4 -0
  89. package/dist/models/enablement.d.ts +3 -1
  90. package/dist/models/enablement.js +25 -5
  91. package/dist/orgs/offboarding.d.ts +3 -1
  92. package/dist/orgs/offboarding.js +7 -3
  93. package/dist/orgs/orgs.module.js +3 -0
  94. package/dist/orgs/orgs.service.d.ts +3 -1
  95. package/dist/orgs/orgs.service.js +7 -3
  96. package/dist/platform/exclusions.js +5 -0
  97. package/dist/push/delivery.d.ts +3 -1
  98. package/dist/push/delivery.js +7 -3
  99. package/dist/push/push-processor.js +8 -1
  100. package/dist/runtime/stream-limit.d.ts +13 -0
  101. package/dist/runtime/stream-limit.js +40 -0
  102. package/dist/runtime/stream.controller.d.ts +2 -0
  103. package/dist/runtime/stream.controller.js +2 -0
  104. package/dist/runtime/stream.d.ts +1 -0
  105. package/dist/runtime/stream.js +15 -6
  106. package/dist/sandbox/permission-authority.module.js +6 -1
  107. package/dist/sandbox/permission-transitions.d.ts +3 -1
  108. package/dist/sandbox/permission-transitions.js +17 -2
  109. package/dist/skills/agent-skills.service.d.ts +6 -1
  110. package/dist/skills/agent-skills.service.js +12 -3
  111. package/dist/skills/changes.service.d.ts +6 -1
  112. package/dist/skills/changes.service.js +11 -3
  113. package/dist/skills/conversation-catalog.d.ts +3 -0
  114. package/dist/skills/conversation-catalog.js +2 -0
  115. package/dist/skills/skills.module.js +3 -0
  116. package/dist/skills/skills.service.d.ts +3 -1
  117. package/dist/skills/skills.service.js +8 -4
  118. package/dist/tools/approvals.service.d.ts +12 -1
  119. package/dist/tools/approvals.service.js +36 -9
  120. package/dist/tools/connectors.service.d.ts +3 -1
  121. package/dist/tools/connectors.service.js +29 -7
  122. package/dist/tools/tools.module.js +3 -0
  123. package/dist/ui/admin-ui.controller.d.ts +3 -1
  124. package/dist/ui/admin-ui.controller.js +3 -1
  125. package/dist/ui/ui-stream.d.ts +2 -0
  126. package/dist/ui/ui-stream.js +20 -6
  127. package/dist/ui/views.controller.d.ts +4 -2
  128. package/dist/ui/views.controller.js +4 -2
  129. package/package.json +1 -1
@@ -37,6 +37,7 @@ import { Transactional } from "../infra/database/transactional.decorator.js";
37
37
  import { XactLock } from "../infra/database/xact-lock.js";
38
38
  import { OutboxService } from "../infra/outbox/outbox.service.js";
39
39
  import { KERNEL_LOGGER } from "../infra/tokens.js";
40
+ import { InvalidationHints } from "../invalidation/invalidation-hints.js";
40
41
  import { OrgLock } from "../orgs/org-lock.js";
41
42
  import { sha512Hex } from "../packages/provenance.js";
42
43
  import { packagePath, packPackageTgz } from "../packages/tgz.js";
@@ -168,6 +169,7 @@ let PluginImport = class PluginImport {
168
169
  xactLock;
169
170
  platform;
170
171
  outbox;
172
+ hints;
171
173
  /** Where plugin files go (the kernel's object storage; the CLI's own, see {@link useCliStorage}). */
172
174
  files;
173
175
  /**
@@ -188,7 +190,7 @@ let PluginImport = class PluginImport {
188
190
  /** The platform rows of a new item's components, written in the confirm's transaction. */
189
191
  platform,
190
192
  /** The item's scope sync, owed by the confirm's commit when it deploys no extension. */
191
- outbox) {
193
+ outbox, hints) {
192
194
  this.kdb = kdb;
193
195
  this.adminLock = adminLock;
194
196
  this.orgLock = orgLock;
@@ -207,6 +209,7 @@ let PluginImport = class PluginImport {
207
209
  this.xactLock = xactLock;
208
210
  this.platform = platform;
209
211
  this.outbox = outbox;
212
+ this.hints = hints;
210
213
  this.files = storage;
211
214
  }
212
215
  /** The kernel-schema handle of the current context (the transaction, else the pool). */
@@ -1004,7 +1007,12 @@ let PluginImport = class PluginImport {
1004
1007
  .where("id", "=", itemId)
1005
1008
  .execute();
1006
1009
  }
1007
- await writeScope(t, { kind: "plugin", id: itemId, scope: scope.scope, orgs: scope.orgs });
1010
+ await writeScope(t, this.hints, {
1011
+ kind: "plugin",
1012
+ id: itemId,
1013
+ scope: scope.scope,
1014
+ orgs: scope.orgs,
1015
+ });
1008
1016
  }
1009
1017
  // The org requests this staging answers resolve with the confirm; on an item that existed
1010
1018
  // already (imported meanwhile) a `named` scope gains their orgs. An org-owned item held back by
@@ -1021,10 +1029,10 @@ let PluginImport = class PluginImport {
1021
1029
  if (item !== undefined && !shareGate(item) && (await hasImportRequests(t, stagingId))) {
1022
1030
  assertShareable(item);
1023
1031
  }
1024
- const requestOrgs = await resolveImportRequests(t, stagingId, itemId, actor, opts);
1032
+ const requestOrgs = await resolveImportRequests(t, this.hints, stagingId, itemId, actor, opts);
1025
1033
  if (item !== undefined) {
1026
1034
  for (const org of requestOrgs)
1027
- await addScopeOrg(t, actor, item, org, opts);
1035
+ await addScopeOrg(t, this.hints, actor, item, org, opts);
1028
1036
  }
1029
1037
  if (owner !== undefined && created)
1030
1038
  await markVersionApplied(t, itemId, staged.version);
@@ -1647,7 +1655,8 @@ PluginImport = __decorate([
1647
1655
  __param(15, Inject(TransactionHost)),
1648
1656
  __param(16, Inject(XactLock)),
1649
1657
  __param(17, Inject(PlatformComponents)),
1650
- __param(18, Inject(OutboxService))
1658
+ __param(18, Inject(OutboxService)),
1659
+ __param(19, Inject(InvalidationHints))
1651
1660
  ], PluginImport);
1652
1661
  export { PluginImport };
1653
1662
  /**
@@ -5,6 +5,7 @@ import { ExtensionRegistry } from "../extensions/registry.js";
5
5
  import { KernelDb } from "../infra/database/kernel-db.js";
6
6
  import { TransactionHost } from "../infra/database/transaction-host.js";
7
7
  import { OutboxService } from "../infra/outbox/outbox.service.js";
8
+ import type { HintPublisher } from "../invalidation/audiences.js";
8
9
  import { OrgLock } from "../orgs/org-lock.js";
9
10
  import type { OrgAction } from "../orgs/roles.js";
10
11
  import { type SkillConflict, SkillsService } from "../skills/skills.service.js";
@@ -267,6 +268,7 @@ export declare class PluginInstaller {
267
268
  /** Owes the template connector ensure of an install's commit (`markInstalled`). */
268
269
  private readonly outbox;
269
270
  readonly txHost: TransactionHost;
271
+ private readonly hints;
270
272
  constructor(kdb: KernelDb,
271
273
  /** The org row lock (orgs/org-lock.ts): joins the caller's transaction. */
272
274
  orgLock: OrgLock, storage: StorageService,
@@ -275,7 +277,7 @@ export declare class PluginInstaller {
275
277
  /** Org connectors: installs create, upgrade and remove them. */
276
278
  connectors: ConnectorsService,
277
279
  /** Owes the template connector ensure of an install's commit (`markInstalled`). */
278
- outbox: Pick<OutboxService, "add">, txHost: TransactionHost);
280
+ outbox: Pick<OutboxService, "add">, txHost: TransactionHost, hints: HintPublisher);
279
281
  /** The kernel-schema handle of the current context (the transaction, else the pool). */
280
282
  private get db();
281
283
  /**
@@ -22,6 +22,7 @@ import { KernelDb } from "../infra/database/kernel-db.js";
22
22
  import { TransactionHost } from "../infra/database/transaction-host.js";
23
23
  import { Transactional } from "../infra/database/transactional.decorator.js";
24
24
  import { OutboxService } from "../infra/outbox/outbox.service.js";
25
+ import { InvalidationHints } from "../invalidation/invalidation-hints.js";
25
26
  import { OrgLock } from "../orgs/org-lock.js";
26
27
  import { packagePath } from "../packages/tgz.js";
27
28
  import { SkillsService, skillConflictError, skillConflicts, } from "../skills/skills.service.js";
@@ -270,6 +271,7 @@ let PluginInstaller = class PluginInstaller {
270
271
  connectors;
271
272
  outbox;
272
273
  txHost;
274
+ hints;
273
275
  constructor(kdb,
274
276
  /** The org row lock (orgs/org-lock.ts): joins the caller's transaction. */
275
277
  orgLock, storage,
@@ -278,7 +280,7 @@ let PluginInstaller = class PluginInstaller {
278
280
  /** Org connectors: installs create, upgrade and remove them. */
279
281
  connectors,
280
282
  /** Owes the template connector ensure of an install's commit (`markInstalled`). */
281
- outbox, txHost) {
283
+ outbox, txHost, hints) {
282
284
  this.kdb = kdb;
283
285
  this.orgLock = orgLock;
284
286
  this.storage = storage;
@@ -289,6 +291,7 @@ let PluginInstaller = class PluginInstaller {
289
291
  this.connectors = connectors;
290
292
  this.outbox = outbox;
291
293
  this.txHost = txHost;
294
+ this.hints = hints;
292
295
  }
293
296
  /** The kernel-schema handle of the current context (the transaction, else the pool). */
294
297
  get db() {
@@ -872,7 +875,7 @@ let PluginInstaller = class PluginInstaller {
872
875
  }
873
876
  if (!appliesOrgEffects(plan)) {
874
877
  if (ctx.parent === undefined) {
875
- await resolveRequestsByInstall(t, orgId, itemId, actor, opts);
878
+ await resolveRequestsByInstall(t, this.hints, orgId, itemId, actor, opts);
876
879
  if (ctx.switchOn === true) {
877
880
  await audit(t, {
878
881
  actorAccountId: actor,
@@ -938,7 +941,7 @@ let PluginInstaller = class PluginInstaller {
938
941
  if (updated.numUpdatedRows === 0n) {
939
942
  throw new ApiError("plugin.install_not_found", "The install record was cleaned up as stale while the install was running");
940
943
  }
941
- await resolveRequestsByInstall(t, orgId, itemId, actor, opts);
944
+ await resolveRequestsByInstall(t, this.hints, orgId, itemId, actor, opts);
942
945
  // The org's choice of connector templates is written with the install too: the chosen ones on,
943
946
  // the ones left out off (they stay available on the connectors page)
944
947
  for (const sw of ctx.via === "scope" ? [] : plan.templateSwitches) {
@@ -1980,7 +1983,8 @@ PluginInstaller = __decorate([
1980
1983
  __param(6, Inject(ScopeWriter)),
1981
1984
  __param(7, Inject(ConnectorsService)),
1982
1985
  __param(8, Inject(OutboxService)),
1983
- __param(9, Inject(TransactionHost))
1986
+ __param(9, Inject(TransactionHost)),
1987
+ __param(10, Inject(InvalidationHints))
1984
1988
  ], PluginInstaller);
1985
1989
  export { PluginInstaller };
1986
1990
  /**
@@ -12,6 +12,7 @@ import { XactLock } from "../infra/database/xact-lock.js";
12
12
  import { KernelEvents } from "../infra/events/kernel-events.js";
13
13
  import { LockService } from "../infra/lock/lock.service.js";
14
14
  import { OutboxService } from "../infra/outbox/outbox.service.js";
15
+ import type { HintPublisher } from "../invalidation/audiences.js";
15
16
  import type { KernelLogger } from "../log.js";
16
17
  import { OrgLock } from "../orgs/org-lock.js";
17
18
  import { StorageService } from "../storage/storage.service.js";
@@ -271,6 +272,7 @@ export declare class PlatformPluginUpdater {
271
272
  private readonly guides;
272
273
  /** Owes the template connector ensure of the orgs with a deferred connector (ruling R27). */
273
274
  private readonly outbox;
275
+ private readonly hints;
274
276
  constructor(kdb: KernelDb, txHost: TransactionHost, xactLock: XactLock, events: KernelEvents, adminLock: SuperAdminLock, itemLock: CatalogItemLock, orgLock: OrgLock, locks: LockService, storage: StorageService, registry: ExtensionRegistry, ops: ExtensionAdminOps,
275
277
  /** Reads the target's extension package (its permissions, for `needsApproval`). */
276
278
  blobs: ExtensionBlobs, config: KernelConfigService, platform: PlatformComponents,
@@ -279,7 +281,7 @@ export declare class PlatformPluginUpdater {
279
281
  /** The connector template guides an update changes (the preview's `guideChanges`). */
280
282
  guides: Pick<PluginGuides, "templateGuideChanges">,
281
283
  /** Owes the template connector ensure of the orgs with a deferred connector (ruling R27). */
282
- outbox: Pick<OutboxService, "add">);
284
+ outbox: Pick<OutboxService, "add">, hints: HintPublisher);
283
285
  private get db();
284
286
  /** The update preview (see the class comment); writes nothing. */
285
287
  preview(itemId: string, version: string): Promise<PlatformUpdatePreview>;
@@ -36,6 +36,7 @@ import { KernelEvents } from "../infra/events/kernel-events.js";
36
36
  import { LockService } from "../infra/lock/lock.service.js";
37
37
  import { OutboxService } from "../infra/outbox/outbox.service.js";
38
38
  import { KERNEL_LOGGER } from "../infra/tokens.js";
39
+ import { InvalidationHints } from "../invalidation/invalidation-hints.js";
39
40
  import { OrgLock } from "../orgs/org-lock.js";
40
41
  import { sha512Hex } from "../packages/provenance.js";
41
42
  import { packagePath } from "../packages/tgz.js";
@@ -150,6 +151,7 @@ let PlatformPluginUpdater = class PlatformPluginUpdater {
150
151
  log;
151
152
  guides;
152
153
  outbox;
154
+ hints;
153
155
  constructor(kdb, txHost, xactLock, events, adminLock, itemLock, orgLock, locks, storage, registry, ops,
154
156
  /** Reads the target's extension package (its permissions, for `needsApproval`). */
155
157
  blobs, config, platform,
@@ -158,7 +160,7 @@ let PlatformPluginUpdater = class PlatformPluginUpdater {
158
160
  /** The connector template guides an update changes (the preview's `guideChanges`). */
159
161
  guides,
160
162
  /** Owes the template connector ensure of the orgs with a deferred connector (ruling R27). */
161
- outbox) {
163
+ outbox, hints) {
162
164
  this.kdb = kdb;
163
165
  this.txHost = txHost;
164
166
  this.xactLock = xactLock;
@@ -179,6 +181,7 @@ let PlatformPluginUpdater = class PlatformPluginUpdater {
179
181
  this.log = log;
180
182
  this.guides = guides;
181
183
  this.outbox = outbox;
184
+ this.hints = hints;
182
185
  }
183
186
  get db() {
184
187
  return this.kdb.db;
@@ -612,7 +615,7 @@ let PlatformPluginUpdater = class PlatformPluginUpdater {
612
615
  .where("id", "=", c.id)
613
616
  .execute();
614
617
  // every org's pending enable requests that name it (target, subject or a follower's)
615
- await reconcileEnableRequestsOf(t, { kind: c.kind, id: c.id }, null);
618
+ await reconcileEnableRequestsOf(t, this.hints, { kind: c.kind, id: c.id }, null);
616
619
  }
617
620
  // Pins of linked copies: moved to the plugin's version (spec §7.1)
618
621
  for (const c of diff.components) {
@@ -698,7 +701,7 @@ let PlatformPluginUpdater = class PlatformPluginUpdater {
698
701
  // The orgs using a shared org-owned plugin are told, one notice per plugin (a platform-owned
699
702
  // plugin tells nobody); a plugin never synced before has no version to come from
700
703
  if (diff.from !== null) {
701
- await notifySharedUpdate(t, { kind: "plugin", id: itemId }, { name: diff.name, from: diff.from, to: diff.to.version });
704
+ await notifySharedUpdate(t, this.hints, { kind: "plugin", id: itemId }, { name: diff.name, from: diff.from, to: diff.to.version });
702
705
  }
703
706
  await audit(t, {
704
707
  actorAccountId: actor,
@@ -1696,7 +1699,8 @@ PlatformPluginUpdater = __decorate([
1696
1699
  __param(16, Inject(PluginScopeSync)),
1697
1700
  __param(17, Inject(KERNEL_LOGGER)),
1698
1701
  __param(18, Inject(PluginGuides)),
1699
- __param(19, Inject(OutboxService))
1702
+ __param(19, Inject(OutboxService)),
1703
+ __param(20, Inject(InvalidationHints))
1700
1704
  ], PlatformPluginUpdater);
1701
1705
  export { PlatformPluginUpdater };
1702
1706
  /** The preview of a diff (without `guideChanges`, which reads PG). */
@@ -0,0 +1,19 @@
1
+ import type { HintPublisher } from "../invalidation/audiences.js";
2
+ /** The catalog request kinds the super admin decides (their rows are the platform inbox's too). */
3
+ export declare const DEPLOYMENT_KINDS: readonly ["access", "import"];
4
+ /** The columns of a catalog request row its hint audience comes from (no extra query). */
5
+ export interface RequestHintRow {
6
+ org_id: string;
7
+ requested_by: string | null;
8
+ kind: string;
9
+ /** An enable request's detail names its followers (other kinds: ignored). */
10
+ detail?: unknown;
11
+ }
12
+ /**
13
+ * Publishes `requests` after the commit for written catalog request rows (account invalidation
14
+ * stream spec §4): to each row's requester and followers and to the admins and owners of each
15
+ * row's org, in one publish; a row the super admin decides (`access`, `import`) also publishes
16
+ * `platform-inbox` to the super admins. `extraAccounts`: accounts the write concerns that the
17
+ * rows do not name (a follower dropped from a row). Nothing for no rows.
18
+ */
19
+ export declare function publishRequestHints(hints: HintPublisher, rows: readonly RequestHintRow[], extraAccounts?: readonly string[]): void;
@@ -0,0 +1,34 @@
1
+ import { acctTopic, orgRoleTopic, PLATFORM_ADMINS_TOPIC, } from "../invalidation/hints.js";
2
+ import { readEnableDetail } from "./enable-targets.js";
3
+ /** The catalog request kinds the super admin decides (their rows are the platform inbox's too). */
4
+ export const DEPLOYMENT_KINDS = ["access", "import"];
5
+ /**
6
+ * Publishes `requests` after the commit for written catalog request rows (account invalidation
7
+ * stream spec §4): to each row's requester and followers and to the admins and owners of each
8
+ * row's org, in one publish; a row the super admin decides (`access`, `import`) also publishes
9
+ * `platform-inbox` to the super admins. `extraAccounts`: accounts the write concerns that the
10
+ * rows do not name (a follower dropped from a row). Nothing for no rows.
11
+ */
12
+ export function publishRequestHints(hints, rows, extraAccounts = []) {
13
+ if (rows.length === 0 && extraAccounts.length === 0)
14
+ return;
15
+ const topics = new Set();
16
+ let platform = false;
17
+ for (const r of rows) {
18
+ topics.add(orgRoleTopic(r.org_id, "admin"));
19
+ if (r.requested_by !== null)
20
+ topics.add(acctTopic(r.requested_by));
21
+ if (r.kind === "enable") {
22
+ for (const f of readEnableDetail(r.detail)?.followers ?? []) {
23
+ topics.add(acctTopic(f.accountId));
24
+ }
25
+ }
26
+ if (DEPLOYMENT_KINDS.includes(r.kind))
27
+ platform = true;
28
+ }
29
+ for (const a of extraAccounts)
30
+ topics.add(acctTopic(a));
31
+ hints.publishAfterCommit([...topics], { kind: "requests" });
32
+ if (platform)
33
+ hints.publishAfterCommit([PLATFORM_ADMINS_TOPIC], { kind: "platform-inbox" });
34
+ }
@@ -1,5 +1,6 @@
1
1
  import type { KernelSchemaDb } from "../db/kernel-schema.js";
2
2
  import { ApiError } from "../errors.js";
3
+ import type { HintPublisher } from "../invalidation/audiences.js";
3
4
  /**
4
5
  * Before an org creates a component from the catalog (enabling an extension, creating a connector
5
6
  * from a template, importing a skill), re-checks in the caller's transaction that the item is live
@@ -38,9 +39,10 @@ export interface RequestActorOpts {
38
39
  * item or the org is deleted), status `cancelled` (the decider is the actor). For an item, that is
39
40
  * its own requests and the enable requests that target it or need it on (`detail.bundle`: an
40
41
  * extension, component, connector or model of it). Each one audits `catalog.request_cancelled`
41
- * (with the reason). Returns how many were cancelled.
42
+ * (with the reason) and the cancelled rows publish `requests` after the commit. Returns how many
43
+ * were cancelled.
42
44
  */
43
- export declare function cancelPendingRequests(db: KernelSchemaDb, where: {
45
+ export declare function cancelPendingRequests(db: KernelSchemaDb, hints: HintPublisher, where: {
44
46
  itemId: string;
45
47
  } | {
46
48
  orgId: string;
@@ -50,8 +52,9 @@ export declare function cancelPendingRequests(db: KernelSchemaDb, where: {
50
52
  * pending `access` request the scope has since granted is approved with the installer as the
51
53
  * decider (null for the scope sync), audited `catalog.request_decided` with `installed: true`;
52
54
  * the pending enable requests that target the plugin are settled ({@link settleEnableRequests}).
55
+ * The rows written publish `requests` after the commit.
53
56
  */
54
- export declare function resolveRequestsByInstall(db: KernelSchemaDb, orgId: string, itemId: string, actor: string | null, opts?: RequestActorOpts): Promise<void>;
57
+ export declare function resolveRequestsByInstall(db: KernelSchemaDb, hints: HintPublisher, orgId: string, itemId: string, actor: string | null, opts?: RequestActorOpts): Promise<void>;
55
58
  /** The pending `import` request linked to a staged import (its approval prepared it), if any. */
56
59
  export declare function importRequestOf(db: KernelSchemaDb, stagingId: string): Promise<{
57
60
  id: string;
@@ -62,6 +65,7 @@ export declare function hasImportRequests(db: KernelSchemaDb, stagingId: string)
62
65
  /**
63
66
  * The confirm of a staged import, in its transaction: the pending `import` requests linked to the
64
67
  * staging are approved (decider: the confirming admin) and point at the item. Audits
65
- * `catalog.request_decided`. Returns the requests' orgs.
68
+ * `catalog.request_decided`; the rows publish `requests` (and `platform-inbox`) after the commit.
69
+ * Returns the requests' orgs.
66
70
  */
67
- export declare function resolveImportRequests(db: KernelSchemaDb, stagingId: string, itemId: string, actor: string | null, opts?: RequestActorOpts): Promise<string[]>;
71
+ export declare function resolveImportRequests(db: KernelSchemaDb, hints: HintPublisher, stagingId: string, itemId: string, actor: string | null, opts?: RequestActorOpts): Promise<string[]>;
@@ -5,6 +5,7 @@ import { audit } from "../identity/audit.js";
5
5
  import { asPlatform, withOrgScope } from "../infra/database/org-scope.js";
6
6
  import { settleEnableRequests } from "./enable-requests.js";
7
7
  import { isUsable } from "./ownership.js";
8
+ import { publishRequestHints } from "./request-hints.js";
8
9
  import { visibleTo } from "./scope.js";
9
10
  /**
10
11
  * The catalog's database-level rules shared by the installers, the import confirm and the request
@@ -128,9 +129,10 @@ export async function assertPluginSourcesInstallable(t, orgId, plugin) {
128
129
  * item or the org is deleted), status `cancelled` (the decider is the actor). For an item, that is
129
130
  * its own requests and the enable requests that target it or need it on (`detail.bundle`: an
130
131
  * extension, component, connector or model of it). Each one audits `catalog.request_cancelled`
131
- * (with the reason). Returns how many were cancelled.
132
+ * (with the reason) and the cancelled rows publish `requests` after the commit. Returns how many
133
+ * were cancelled.
132
134
  */
133
- export async function cancelPendingRequests(db, where, actor, reason, opts = {}) {
135
+ export async function cancelPendingRequests(db, hints, where, actor, reason, opts = {}) {
134
136
  // Rows are locked in id order first, as settlement and reconciliation lock them (no deadlock),
135
137
  // then cancelled by id
136
138
  const cancel = async (ids) => {
@@ -141,7 +143,7 @@ export async function cancelPendingRequests(db, where, actor, reason, opts = {})
141
143
  .updateTable("catalog_requests")
142
144
  .set({ status: "cancelled", decided_by: actor, decided_at: sql `now()` })
143
145
  .where("id", "in", [...ids])
144
- .returning(["id", "org_id", "item_id", "kind"])
146
+ .returning(["id", "org_id", "item_id", "kind", "requested_by", "detail"])
145
147
  .execute();
146
148
  return done;
147
149
  };
@@ -171,6 +173,7 @@ export async function cancelPendingRequests(db, where, actor, reason, opts = {})
171
173
  .orderBy("id")
172
174
  .forUpdate()
173
175
  .execute()).map((r) => r.id));
176
+ publishRequestHints(hints, rows);
174
177
  for (const r of rows) {
175
178
  await withOrgScope(r.org_id, () => audit(db, {
176
179
  actorAccountId: actor,
@@ -188,8 +191,9 @@ export async function cancelPendingRequests(db, where, actor, reason, opts = {})
188
191
  * pending `access` request the scope has since granted is approved with the installer as the
189
192
  * decider (null for the scope sync), audited `catalog.request_decided` with `installed: true`;
190
193
  * the pending enable requests that target the plugin are settled ({@link settleEnableRequests}).
194
+ * The rows written publish `requests` after the commit.
191
195
  */
192
- export async function resolveRequestsByInstall(db, orgId, itemId, actor, opts = {}) {
196
+ export async function resolveRequestsByInstall(db, hints, orgId, itemId, actor, opts = {}) {
193
197
  const rows = await db
194
198
  .updateTable("catalog_requests")
195
199
  .set({ status: "approved", decided_by: actor, decided_at: sql `now()` })
@@ -197,8 +201,9 @@ export async function resolveRequestsByInstall(db, orgId, itemId, actor, opts =
197
201
  .where("item_id", "=", itemId)
198
202
  .where("kind", "<>", "enable")
199
203
  .where("status", "=", "pending")
200
- .returning(["id", "kind"])
204
+ .returning(["id", "org_id", "kind", "requested_by"])
201
205
  .execute();
206
+ publishRequestHints(hints, rows);
202
207
  for (const r of rows) {
203
208
  await audit(db, {
204
209
  actorAccountId: actor,
@@ -209,7 +214,7 @@ export async function resolveRequestsByInstall(db, orgId, itemId, actor, opts =
209
214
  detail: { itemId, kind: r.kind, decision: "approve", installed: true },
210
215
  });
211
216
  }
212
- await settleEnableRequests(db, orgId, { kind: "plugin", id: itemId }, actor, opts);
217
+ await settleEnableRequests(db, hints, orgId, { kind: "plugin", id: itemId }, actor, opts);
213
218
  }
214
219
  /** The pending `import` request linked to a staged import (its approval prepared it), if any. */
215
220
  // org-filter: by the staging id of the confirm's own staging row (ownStaging checked it); a platform
@@ -240,11 +245,12 @@ export async function hasImportRequests(db, stagingId) {
240
245
  /**
241
246
  * The confirm of a staged import, in its transaction: the pending `import` requests linked to the
242
247
  * staging are approved (decider: the confirming admin) and point at the item. Audits
243
- * `catalog.request_decided`. Returns the requests' orgs.
248
+ * `catalog.request_decided`; the rows publish `requests` (and `platform-inbox`) after the commit.
249
+ * Returns the requests' orgs.
244
250
  */
245
251
  // org-filter: by the staging id of the confirm's own staging row (ownStaging checked it); a platform
246
252
  // staging prepared by approving import requests links requests of several orgs, read on purpose
247
- export async function resolveImportRequests(db, stagingId, itemId, actor, opts = {}) {
253
+ export async function resolveImportRequests(db, hints, stagingId, itemId, actor, opts = {}) {
248
254
  const rows = await db
249
255
  .updateTable("catalog_requests")
250
256
  .set({
@@ -256,8 +262,9 @@ export async function resolveImportRequests(db, stagingId, itemId, actor, opts =
256
262
  .where("staging_id", "=", stagingId)
257
263
  .where("kind", "=", "import")
258
264
  .where("status", "=", "pending")
259
- .returning(["id", "org_id"])
265
+ .returning(["id", "org_id", "kind", "requested_by"])
260
266
  .execute();
267
+ publishRequestHints(hints, rows);
261
268
  for (const r of rows) {
262
269
  await audit(db, {
263
270
  actorAccountId: actor,
@@ -6,6 +6,7 @@ import { KernelConfigService } from "../infra/config/kernel-config.service.js";
6
6
  import { KernelDb } from "../infra/database/kernel-db.js";
7
7
  import { TransactionHost } from "../infra/database/transaction-host.js";
8
8
  import { LockService } from "../infra/lock/lock.service.js";
9
+ import type { HintPublisher } from "../invalidation/audiences.js";
9
10
  import { ModelEnablement } from "../models/enablement.js";
10
11
  import { OrgLock } from "../orgs/org-lock.js";
11
12
  import { OrgSettingsService } from "../orgs/settings.service.js";
@@ -207,6 +208,7 @@ export declare class CatalogRequestsService {
207
208
  private readonly connectors;
208
209
  private readonly extensions;
209
210
  private readonly providers;
211
+ private readonly hints;
210
212
  constructor(kdb: KernelDb,
211
213
  /** The org row and super admin locks: both join the caller's transaction. */
212
214
  orgLock: OrgLock, adminLock: SuperAdminLock, orgCatalog: OrgCatalogService, scope: CatalogScopeService, catalog: CatalogService, config: KernelConfigService, pluginImport: PluginImport,
@@ -219,7 +221,7 @@ export declare class CatalogRequestsService {
219
221
  * (extension, component, model, connector; a plugin goes through `orgCatalog.setSwitch`), and
220
222
  * the deployment's live state a request is checked against (loaded extensions, listed models).
221
223
  */
222
- orgExtensions: OrgExtensionConfigs, components: ComponentScopeService, models: ModelEnablement, connectors: ConnectorsService, extensions: ExtensionRegistry, providers: ProviderRegistry);
224
+ orgExtensions: OrgExtensionConfigs, components: ComponentScopeService, models: ModelEnablement, connectors: ConnectorsService, extensions: ExtensionRegistry, providers: ProviderRegistry, hints: HintPublisher);
223
225
  /** The kernel-schema handle of the current context (the transaction, else the pool). */
224
226
  private get db();
225
227
  /**
@@ -24,6 +24,8 @@ import { TransactionHost } from "../infra/database/transaction-host.js";
24
24
  import { Transactional } from "../infra/database/transactional.decorator.js";
25
25
  import { LockService } from "../infra/lock/lock.service.js";
26
26
  import { WithLock } from "../infra/lock/with-lock.decorator.js";
27
+ import { acctTopic } from "../invalidation/hints.js";
28
+ import { InvalidationHints } from "../invalidation/invalidation-hints.js";
27
29
  import { ModelEnablement } from "../models/enablement.js";
28
30
  import { OrgLock } from "../orgs/org-lock.js";
29
31
  import { roleAtLeast } from "../orgs/roles.js";
@@ -42,6 +44,7 @@ import { decodeModelId, readEnableDetail, sameTarget, targetKey, } from "./enabl
42
44
  import { assertEntryNotDeprecated, loadMarketplaceEntry } from "./marketplaces.service.js";
43
45
  import { OrgCatalogService } from "./org-catalog.service.js";
44
46
  import { PluginImport } from "./plugin-import.js";
47
+ import { DEPLOYMENT_KINDS, publishRequestHints } from "./request-hints.js";
45
48
  import { itemsSeenBy } from "./scope-state.js";
46
49
  /** The most pending `network_allowlist` requests one member may have in an org. */
47
50
  export const NETWORK_REQUESTS_PENDING_MAX = 10;
@@ -70,8 +73,6 @@ function sandboxAllowlist(limits, org) {
70
73
  const outsideCeiling = (hosts) => new ApiError("catalog.request_invalid", `The platform limits sandbox hosts to its allowlist; only a super admin can add ${hosts.join(", ")} (sandbox.limits.allowHosts)`);
71
74
  /** A unique violation (the partial index of pending requests). */
72
75
  const isUniqueViolation = (e) => typeof e === "object" && e !== null && e.code === "23505";
73
- /** The deployment-level kinds (decided by the super admin). */
74
- const DEPLOYMENT_KINDS = ["access", "import"];
75
76
  /** The org-level kinds (decided by the org admins). */
76
77
  const ORG_KINDS = ["enable", "connector_setup", "network_allowlist"];
77
78
  /**
@@ -112,6 +113,7 @@ let CatalogRequestsService = class CatalogRequestsService {
112
113
  connectors;
113
114
  extensions;
114
115
  providers;
116
+ hints;
115
117
  constructor(kdb,
116
118
  /** The org row and super admin locks: both join the caller's transaction. */
117
119
  orgLock, adminLock, orgCatalog, scope, catalog, config, pluginImport,
@@ -124,7 +126,7 @@ let CatalogRequestsService = class CatalogRequestsService {
124
126
  * (extension, component, model, connector; a plugin goes through `orgCatalog.setSwitch`), and
125
127
  * the deployment's live state a request is checked against (loaded extensions, listed models).
126
128
  */
127
- orgExtensions, components, models, connectors, extensions, providers) {
129
+ orgExtensions, components, models, connectors, extensions, providers, hints) {
128
130
  this.kdb = kdb;
129
131
  this.orgLock = orgLock;
130
132
  this.adminLock = adminLock;
@@ -142,6 +144,7 @@ let CatalogRequestsService = class CatalogRequestsService {
142
144
  this.connectors = connectors;
143
145
  this.extensions = extensions;
144
146
  this.providers = providers;
147
+ this.hints = hints;
145
148
  }
146
149
  /** The kernel-schema handle of the current context (the transaction, else the pool). */
147
150
  get db() {
@@ -224,6 +227,7 @@ let CatalogRequestsService = class CatalogRequestsService {
224
227
  throw pendingExists();
225
228
  throw e;
226
229
  }
230
+ publishRequestHints(this.hints, [{ org_id: orgId, requested_by: actor, kind: input.kind }]);
227
231
  await audit(t, {
228
232
  actorAccountId: actor,
229
233
  ...(opts.actorTokenId !== undefined && { actorTokenId: opts.actorTokenId }),
@@ -330,6 +334,9 @@ let CatalogRequestsService = class CatalogRequestsService {
330
334
  note: input.note ?? "",
331
335
  })
332
336
  .execute();
337
+ publishRequestHints(this.hints, [
338
+ { org_id: orgId, requested_by: actor, kind: "network_allowlist" },
339
+ ]);
333
340
  await audit(t, {
334
341
  actorAccountId: actor,
335
342
  ...(opts.actorTokenId !== undefined && { actorTokenId: opts.actorTokenId }),
@@ -432,7 +439,7 @@ let CatalogRequestsService = class CatalogRequestsService {
432
439
  // a pending request whose own subject went stale (removed, hidden, another switch first) is
433
440
  // settled first (row locked above), so it never absorbs new askers; a fresh request follows
434
441
  const stale = existing !== undefined &&
435
- (await settleRequestRows(t, orgId, [existing], { kind: "reconcile" }, () => ({
442
+ (await settleRequestRows(t, this.hints, orgId, [existing], { kind: "reconcile" }, () => ({
436
443
  actor: null,
437
444
  }))).has(existing.id);
438
445
  if (existing && !stale) {
@@ -462,6 +469,9 @@ let CatalogRequestsService = class CatalogRequestsService {
462
469
  .where("id", "=", existing.id)
463
470
  .where("org_id", "=", orgId)
464
471
  .execute();
472
+ publishRequestHints(this.hints, [
473
+ { org_id: orgId, requested_by: existing.requested_by, kind: "enable", detail: next },
474
+ ]);
465
475
  }
466
476
  return { id: existing.id, created: false };
467
477
  }
@@ -488,6 +498,7 @@ let CatalogRequestsService = class CatalogRequestsService {
488
498
  throw pendingExists();
489
499
  throw e;
490
500
  }
501
+ publishRequestHints(this.hints, [{ org_id: orgId, requested_by: actor, kind: "enable" }]);
491
502
  await audit(t, {
492
503
  actorAccountId: actor,
493
504
  ...(opts.actorTokenId !== undefined && { actorTokenId: opts.actorTokenId }),
@@ -575,6 +586,7 @@ let CatalogRequestsService = class CatalogRequestsService {
575
586
  throw pendingExists();
576
587
  throw e;
577
588
  }
589
+ publishRequestHints(this.hints, [{ org_id: orgId, requested_by: actor, kind: "import" }]);
578
590
  await audit(t, {
579
591
  actorAccountId: actor,
580
592
  ...(opts.actorTokenId !== undefined && { actorTokenId: opts.actorTokenId }),
@@ -723,7 +735,7 @@ let CatalogRequestsService = class CatalogRequestsService {
723
735
  const detail = readEnableDetail(row.detail);
724
736
  if (detail === null)
725
737
  throw requestNotFound();
726
- const outcomes = await settleRequestRows(this.db, orgId, [row], { kind: "final" }, () => ({
738
+ const outcomes = await settleRequestRows(this.db, this.hints, orgId, [row], { kind: "final" }, () => ({
727
739
  actor,
728
740
  actorTokenId: opts.actorTokenId,
729
741
  auditDetail: { requestId, ...opts.auditDetail },
@@ -851,7 +863,7 @@ let CatalogRequestsService = class CatalogRequestsService {
851
863
  // org-filter: super admin links any org's import request (adminLock just above)
852
864
  const row = await this.db
853
865
  .selectFrom("catalog_requests")
854
- .select(["org_id", "status", "entry_name"])
866
+ .select(["org_id", "status", "entry_name", "requested_by", "kind"])
855
867
  .where("id", "=", requestId)
856
868
  .forUpdate()
857
869
  .executeTakeFirstOrThrow();
@@ -863,6 +875,8 @@ let CatalogRequestsService = class CatalogRequestsService {
863
875
  .where("id", "=", requestId)
864
876
  .where("org_id", "=", row.org_id)
865
877
  .execute();
878
+ // the request views carry the pending staging (the platform inbox's and the requester's)
879
+ publishRequestHints(this.hints, [row]);
866
880
  await audit(this.db, {
867
881
  actorAccountId: actor,
868
882
  ...(opts.actorTokenId !== undefined && { actorTokenId: opts.actorTokenId }),
@@ -885,7 +899,7 @@ let CatalogRequestsService = class CatalogRequestsService {
885
899
  await this.adminLock.lockAndAuthorize(actor);
886
900
  let q = t
887
901
  .selectFrom("catalog_requests")
888
- .select(["id", "org_id", "item_id", "kind", "status", "decided_by", "detail"])
902
+ .select(["id", "org_id", "item_id", "kind", "status", "decided_by", "detail", "requested_by"])
889
903
  .where("id", "=", requestId);
890
904
  q =
891
905
  "orgId" in side
@@ -937,6 +951,7 @@ let CatalogRequestsService = class CatalogRequestsService {
937
951
  .where("id", "=", requestId)
938
952
  .where("org_id", "=", row.org_id)
939
953
  .execute();
954
+ publishRequestHints(this.hints, [row]);
940
955
  await audit(t, {
941
956
  actorAccountId: actor,
942
957
  ...(opts.actorTokenId !== undefined && { actorTokenId: opts.actorTokenId }),
@@ -1025,8 +1040,10 @@ let CatalogRequestsService = class CatalogRequestsService {
1025
1040
  .where(decidedForRequester("status", "detail"))
1026
1041
  .where("dismissed_at", "is", null)
1027
1042
  .executeTakeFirst();
1043
+ // a dismissal changes only the dismissing person's inbox (no admin list shows it)
1044
+ const dismissed = () => this.hints.publishAfterCommit([acctTopic(accountId)], { kind: "requests" });
1028
1045
  if (r.numUpdatedRows > 0n)
1029
- return;
1046
+ return dismissed();
1030
1047
  // a follower of an enable request dismisses their own copy of the notice
1031
1048
  const f = await this.db
1032
1049
  .updateTable("catalog_requests")
@@ -1043,6 +1060,7 @@ let CatalogRequestsService = class CatalogRequestsService {
1043
1060
  .executeTakeFirst();
1044
1061
  if (f.numUpdatedRows === 0n)
1045
1062
  throw requestNotFound();
1063
+ dismissed();
1046
1064
  }
1047
1065
  /** 超级管理员的申请列表(`access` / `import`;`status` 缺省 pending),新的在前。 */
1048
1066
  async listDeployment(q = {}) {
@@ -1365,7 +1383,8 @@ CatalogRequestsService = __decorate([
1365
1383
  __param(13, Inject(ModelEnablement)),
1366
1384
  __param(14, Inject(ConnectorsService)),
1367
1385
  __param(15, Inject(ExtensionRegistry)),
1368
- __param(16, Inject(ProviderRegistry))
1386
+ __param(16, Inject(ProviderRegistry)),
1387
+ __param(17, Inject(InvalidationHints))
1369
1388
  ], CatalogRequestsService);
1370
1389
  export { CatalogRequestsService };
1371
1390
  /** The view fields of a `connector_setup` request (ruling P4-T6-5); null for other kinds. */
@@ -1,4 +1,5 @@
1
1
  import type { KernelSchemaDb } from "../db/kernel-schema.js";
2
+ import type { HintPublisher } from "../invalidation/audiences.js";
2
3
  /**
3
4
  * Adds one org to a `named` item's list in the caller's transaction (the caller holds the item row
4
5
  * `FOR UPDATE`): audits `catalog.scope_changed` the way a scope change
@@ -8,7 +9,7 @@ import type { KernelSchemaDb } from "../db/kernel-schema.js";
8
9
  * than its owner to an org-owned item that is not shareable -> 409 `catalog.not_shareable` (the
9
10
  * share gate, ruling P3-16, read on the caller's locked row).
10
11
  */
11
- export declare function addScopeOrg(db: KernelSchemaDb, actor: string | null, item: {
12
+ export declare function addScopeOrg(db: KernelSchemaDb, hints: HintPublisher, actor: string | null, item: {
12
13
  id: string;
13
14
  name: string;
14
15
  scope: "all" | "optional" | "named";