@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
@@ -1,138 +1,45 @@
1
1
  import { EffectiveConfigs } from "../extensions/effective-config.js";
2
2
  import { ExtensionRegistry } from "../extensions/registry.js";
3
+ import { KernelConfigService } from "../infra/config/kernel-config.service.js";
3
4
  import { KernelDb } from "../infra/database/kernel-db.js";
4
5
  import { TransactionHost } from "../infra/database/transaction-host.js";
5
6
  import { LockService } from "../infra/lock/lock.service.js";
6
7
  import { OutboxService } from "../infra/outbox/outbox.service.js";
7
8
  import type { KernelLogger } from "../log.js";
9
+ import { OrgLock } from "../orgs/org-lock.js";
10
+ import { type EffectJob } from "./effect-work.js";
8
11
  import { PluginInstaller } from "./plugin-install.js";
9
- import { type ScopeJob } from "./scope-jobs.js";
10
- import { TemplateConnectorEnsurer } from "./template-connector-ensure.js";
11
- /**
12
- * The plugin scope sync (plugin and component management spec §5, phase 1): converges every org
13
- * to each platform plugin's scope. In phase 1 "on in an org" is the org's plugin install, so for
14
- * each (item, org) the sync:
15
- * - wanted on (`wantedOn`, or a live install in the org depends on it: rule 9) and no live install
16
- * -> installs it as the kernel itself (actor null, audits `via: "scope"`). An install asks for
17
- * no input (plugin pages spec §5.2.2): its connector templates become connectors, those lacking
18
- * an org credential or OAuth client `needs_config`, and an extension whose effective config is
19
- * not valid in the org is switched on all the same (it gets no call until it is, and the org
20
- * catalog shows the plugin `needs_config`);
21
- * - wanted off and a live install -> uninstalls it (`via: "scope"`; the person who changed the
22
- * scope or the switch confirmed the preview); the connectors the install created stay as the
23
- * org's own (spec §5 rule 8); a dependency install it took along that its own scope still wants
24
- * on stays as a standalone install (the installer's rule), the others are synced again.
25
- * The decision is made outside the org row lock; the installer re-checks the scope under it for a
26
- * `via: "scope"` install or uninstall, so a person's switch committed meanwhile wins.
27
- * The sync writes no switch row: those record people's choices, and `wantedOn` honours them for
28
- * every scope (an org that switched an `all` item off stays off, also across a scope change away
29
- * and back, layering spec §4). Builtin items are left alone: they are on everywhere without an org
30
- * install, and their extension is enabled in every org by `enabled.ts` (required or not). A
31
- * failed install, uninstall or dependency install is logged, audited `plugin.scope_sync_failed`
32
- * (once while the same failure stays open), kept as the pair's open failure
33
- * (`plugin_scope_sync_failures`, the super admin's inbox, until a later sync of the pair does not
34
- * fail) and not retried until the next sync of the item (syncs follow owing transactions, never a
35
- * timer). An error outside those steps (a read, the failure write itself) ends the attempt
36
- * without touching the pair's row, so an older failure stays open.
37
- *
38
- * Jobs (queue {@link PLUGIN_SCOPE_QUEUE}), all owed through the outbox (transactional outbox spec
39
- * §8.1), so none is lost:
40
- * - `scope-item` (`scope-item-<itemId>-x<xact>`, one per owing transaction): owed by every
41
- * transaction that changes what the item's sync converges to: its scope, disabled flag, list,
42
- * owner or platform version, an import's commit that deploys no extension, and the deploy of its
43
- * extension (`oweDeployedExtensionSync`: enabled, a new version of an enabled one, permissions
44
- * approved). It fans out: one `scope-item-chunk` per chunk of orgs (`<item job id>-c<n>`, at
45
- * most {@link SCOPE_ORG_CHUNK} orgs each), all owed in one transaction;
46
- * - `scope-item-chunk`: converges the item in its orgs;
47
- * - `scope-org` (`scope-org-<orgId>`): every item in one org, owed by the org's creation.
48
- * A migration that changes a scope inserts its outbox rows itself. One BullMQ retry policy
49
- * (registry): a chunk or org job whose extension is enabled on the deployment but not loaded on
50
- * this replica yet fails after converging its other pairs, so BullMQ retries it with its backoff
51
- * (on any replica); its last attempt installs anyway and records what fails. Pairs of one org are
52
- * serialized across replicas by a Redis lock per org; the installer's org row lock and its
53
- * one-live-install rule are the backstop.
54
- */
55
- export { PLUGIN_SCOPE_QUEUE, SCOPE_CHUNK_JOB, SCOPE_ITEM_JOB, SCOPE_ORG_CHUNK, SCOPE_ORG_CHUNK_SIZE, SCOPE_ORG_JOB, type ScopeJob, scopeChunkJobId, scopeItemJobId, scopeOrgJobId, } from "./scope-jobs.js";
56
- /**
57
- * What a sync of one (item, org) did. `deferred`: the plugin's extension is enabled on the
58
- * deployment but not loaded on this replica yet (P3-38); the job fails for a BullMQ retry.
59
- */
12
+ /** What a convergence attempt for one affected pair did. */
60
13
  export type ScopeSyncResult = "installed" | "removed" | "unchanged" | "deferred";
61
- /**
62
- * A chunk or org job with a pair whose extension this replica has not loaded yet (P3-38): thrown
63
- * after its other pairs converged, so BullMQ retries the job with its backoff.
64
- */
65
- export declare class ScopeSyncDeferred extends Error {
66
- readonly itemIds: string[];
67
- constructor(itemIds: string[]);
68
- }
69
- /** How a job runs: its BullMQ id and whether this is its last attempt. */
70
- export interface ScopeJobRun {
71
- /** The job's id (an item job's chunks are named after it). */
72
- jobId: string;
73
- /** The job's last attempt: a pair whose extension is not loaded here is attempted anyway. */
74
- finalAttempt: boolean;
75
- /** Stops between pairs (the worker closing). */
76
- signal?: AbortSignal;
77
- }
78
- /** The worker's concurrency (per replica): how many chunk, item and org jobs run at once. */
14
+ /** The maximum number of effect jobs one worker processes at once. */
79
15
  export declare const PLUGIN_SCOPE_CONCURRENCY = 2;
80
- /** `ids` in chunks of `size` (the last one shorter). */
81
- export declare function chunked<T>(ids: readonly T[], size: number): T[][];
16
+ export { PLUGIN_EFFECT_QUEUE } from "./effect-work.js";
82
17
  export declare class PluginScopeSync {
83
18
  private readonly kdb;
84
19
  private readonly outbox;
85
20
  private readonly installer;
86
- private readonly templateConnectors;
87
21
  private readonly registry;
22
+ private readonly config;
88
23
  private readonly effective;
24
+ private readonly orgLock;
89
25
  private readonly locks;
90
26
  private readonly log;
91
27
  readonly txHost: TransactionHost;
92
- /** Orgs per chunk job (a test seam; default {@link SCOPE_ORG_CHUNK}). */
93
- private readonly chunkSize;
94
- constructor(kdb: KernelDb, outbox: Pick<OutboxService, "add" | "addMany">, installer: PluginInstaller, templateConnectors: Pick<TemplateConnectorEnsurer, "ensureTemplateConnectorsIn">, registry: ExtensionRegistry, effective: Pick<EffectiveConfigs, "get">, locks: LockService, log: KernelLogger, txHost: TransactionHost,
95
- /** Orgs per chunk job (a test seam; default {@link SCOPE_ORG_CHUNK}). */
96
- chunkSize?: number);
28
+ constructor(kdb: KernelDb, outbox: Pick<OutboxService, "add" | "addMany">, installer: PluginInstaller, registry: ExtensionRegistry, config: KernelConfigService, effective: Pick<EffectiveConfigs, "get">, orgLock: OrgLock, locks: LockService, log: KernelLogger, txHost: TransactionHost);
97
29
  private get db();
98
- /**
99
- * Owes the sync of an item in every org in the transaction in context (one job per
100
- * transaction), the transaction that changes what it converges to.
101
- */
102
- enqueueItem(itemId: string): Promise<void>;
103
- /** Owes the sync of every item in an org, in the transaction that creates the org. */
30
+ enqueueItem(itemId: string, previousOrgs?: readonly string[]): Promise<void>;
104
31
  enqueueOrg(orgId: string): Promise<void>;
105
- /**
106
- * One job: an item job fans out to its chunk jobs; a chunk job converges the item in its orgs,
107
- * an org job every item in the org. A pair deferred because its extension is not loaded here
108
- * fails the job after the others ({@link ScopeSyncDeferred}), unless this is its last attempt.
109
- */
110
- process(data: ScopeJob, run: ScopeJobRun): Promise<void>;
111
- /**
112
- * Owes one chunk job per {@link chunkSize} live orgs of the item job `jobId`, in one
113
- * transaction (a redelivered item job owes the same ids again: deduped).
114
- */
115
- private fanOut;
116
- /**
117
- * Whether the install of the item's `version` may go ahead on this replica (P3-38): its
118
- * extension is loaded here, or it is not enabled on the deployment (the install reports
119
- * `catalog.not_deployed` as before). Enabled but not loaded here (its deploy owed this sync, and
120
- * this replica's reconcile has not caught up yet) -> false, unless this is the job's last try.
121
- */
32
+ recover(): Promise<void>;
33
+ process(data: EffectJob, jobId: string, signal?: AbortSignal): Promise<void>;
34
+ /** Allow another worker to apply the effects while a live replica has the revision. */
122
35
  private extensionReady;
123
36
  /** Converges one (item, org), under the org's sync lock; `signal` ends the wait for it. */
124
- syncPair(itemId: string, orgId: string, signal?: AbortSignal, opts?: {
125
- finalTry?: boolean;
126
- }): Promise<ScopeSyncResult>;
127
- /**
128
- * {@link syncLocked} plus the pair's open failure (`plugin_scope_sync_failures`, the super
129
- * admin's inbox): an attempt that failed records it, any other attempt clears it. An attempt
130
- * that throws (outside the recorded steps) leaves the row as it was.
131
- */
132
- private syncRecorded;
37
+ syncPair(itemId: string, orgId: string, signal?: AbortSignal, generation?: string): Promise<ScopeSyncResult>;
38
+ private apply;
39
+ private current;
40
+ private settleGeneration;
133
41
  private syncLocked;
134
- /** Whether a live install of the org depends on this install (spec §5 rule 9). */
135
- dependedOn(orgId: string, installId: string): Promise<boolean>;
42
+ private enqueueDependencyEffects;
136
43
  /** The items of the dependency installs this install (of `orgId`) created. */
137
44
  private createdDependencies;
138
45
  /**
@@ -145,10 +52,6 @@ export declare class PluginScopeSync {
145
52
  needsConfig(orgId: string, itemId: string, version: string): Promise<boolean>;
146
53
  /** Whether the plugin's extension (manifest `m`), loaded here, has no valid config for the org. */
147
54
  private extensionConfigInvalid;
148
- /**
149
- * Logs and audits a failed install or uninstall (`plugin.scope_sync_failed`, actor null) and
150
- * records it as the pair's open failure (the super admin's inbox).
151
- */
152
55
  private failed;
153
- private recordFailure;
56
+ private settleFailure;
154
57
  }