@capybara-hq/kernel 0.1.0-rc.136 → 0.1.0-rc.138
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/admin/audit-log.service.d.ts +96 -12
- package/dist/admin/audit-log.service.js +508 -44
- package/dist/admin/audit-targets.d.ts +17 -0
- package/dist/admin/audit-targets.js +84 -0
- package/dist/admin/audit.controller.d.ts +12 -9
- package/dist/admin/audit.controller.js +29 -8
- package/dist/admin/audit.schemas.d.ts +20 -4
- package/dist/admin/audit.schemas.js +42 -17
- package/dist/admin/extensions.controller.d.ts +5 -2
- package/dist/admin/extensions.controller.js +10 -1
- package/dist/admin/extensions.schemas.d.ts +4 -0
- package/dist/admin/extensions.schemas.js +9 -0
- package/dist/admin/health.service.d.ts +1 -1
- package/dist/admin/health.service.js +3 -3
- package/dist/agents/templates.js +3 -10
- package/dist/app.d.ts +3 -1
- package/dist/app.js +1 -0
- package/dist/automations/automations.service.js +4 -5
- package/dist/catalog/catalog-content.d.ts +6 -8
- package/dist/catalog/catalog-content.js +17 -22
- package/dist/catalog/catalog-items.d.ts +5 -10
- package/dist/catalog/catalog-items.js +27 -51
- package/dist/catalog/catalog-scope.service.d.ts +4 -2
- package/dist/catalog/catalog-scope.service.js +109 -145
- package/dist/catalog/catalog.module.js +7 -4
- package/dist/catalog/catalog.service.d.ts +10 -4
- package/dist/catalog/catalog.service.js +52 -10
- package/dist/catalog/cli.js +17 -0
- package/dist/catalog/component-promotion.js +8 -4
- package/dist/catalog/component-scope.service.d.ts +3 -1
- package/dist/catalog/component-scope.service.js +101 -140
- package/dist/catalog/component-state.d.ts +10 -8
- package/dist/catalog/component-state.js +42 -30
- package/dist/catalog/dependency-edges.d.ts +25 -0
- package/dist/catalog/dependency-edges.js +125 -0
- package/dist/catalog/effect-work.d.ts +27 -0
- package/dist/catalog/effect-work.js +151 -0
- package/dist/catalog/jobs.d.ts +4 -1
- package/dist/catalog/jobs.js +14 -4
- package/dist/catalog/org-catalog.service.d.ts +5 -1
- package/dist/catalog/org-catalog.service.js +101 -106
- package/dist/catalog/org-intent.d.ts +45 -0
- package/dist/catalog/org-intent.js +205 -0
- package/dist/catalog/owned-items.d.ts +6 -2
- package/dist/catalog/owned-items.js +27 -32
- package/dist/catalog/ownership.d.ts +2 -3
- package/dist/catalog/ownership.js +10 -28
- package/dist/catalog/platform-components.d.ts +3 -1
- package/dist/catalog/platform-components.js +9 -1
- package/dist/catalog/plugin-import.d.ts +4 -2
- package/dist/catalog/plugin-import.js +22 -21
- package/dist/catalog/plugin-install.d.ts +19 -54
- package/dist/catalog/plugin-install.js +221 -271
- package/dist/catalog/plugin-upgrade.d.ts +10 -5
- package/dist/catalog/plugin-upgrade.js +80 -67
- package/dist/catalog/request-rules.js +20 -8
- package/dist/catalog/scope-orgs.js +2 -7
- package/dist/catalog/scope-state.d.ts +6 -6
- package/dist/catalog/scope-state.js +24 -43
- package/dist/catalog/scope-sync-workers.d.ts +7 -11
- package/dist/catalog/scope-sync-workers.js +10 -26
- package/dist/catalog/scope-sync.d.ts +19 -116
- package/dist/catalog/scope-sync.js +228 -275
- package/dist/catalog/scope-writer.d.ts +87 -0
- package/dist/catalog/scope-writer.js +239 -0
- package/dist/catalog/template-connector-ensure.js +1 -1
- package/dist/catalog/unshare.js +9 -43
- package/dist/channels/connections.service.js +6 -6
- package/dist/channels/supervisor.js +3 -7
- package/dist/client/client-access.service.js +2 -12
- package/dist/config/schema.d.ts +6 -0
- package/dist/config/schema.js +32 -1
- package/dist/ctx/create-ctx.d.ts +2 -2
- package/dist/ctx/create-ctx.js +2 -60
- package/dist/ctx/guard-db.d.ts +6 -0
- package/dist/ctx/guard-db.js +55 -0
- package/dist/db/extension-handoff-schema.d.ts +1 -1
- package/dist/db/extension-handoff-schema.js +48 -10
- package/dist/db/extension-schema-transfer.js +5 -2
- package/dist/db/kernel-schema.d.ts +32 -6
- package/dist/device-access/host-services.d.ts +2 -2
- package/dist/device-access/host-services.js +5 -6
- package/dist/erasure/org-catalog.js +2 -2
- package/dist/erasure/org-rules.js +7 -0
- package/dist/extensions/admin-ops.d.ts +10 -6
- package/dist/extensions/admin-ops.js +53 -9
- package/dist/extensions/admin-view.d.ts +4 -1
- package/dist/extensions/admin-view.js +27 -14
- package/dist/extensions/bootstrap.d.ts +1 -1
- package/dist/extensions/bootstrap.js +6 -4
- package/dist/extensions/cli.js +1 -0
- package/dist/extensions/effective-config.js +1 -4
- package/dist/extensions/enabled.d.ts +183 -29
- package/dist/extensions/enabled.js +148 -62
- package/dist/extensions/host.d.ts +65 -45
- package/dist/extensions/host.js +446 -128
- package/dist/extensions/installs.d.ts +9 -0
- package/dist/extensions/installs.js +23 -0
- package/dist/extensions/isolated/admission.d.ts +10 -0
- package/dist/extensions/isolated/admission.js +206 -0
- package/dist/extensions/isolated/authorization.d.ts +45 -0
- package/dist/extensions/isolated/authorization.js +191 -0
- package/dist/extensions/isolated/broker.d.ts +15 -0
- package/dist/extensions/isolated/broker.js +471 -0
- package/dist/extensions/isolated/child-protocol.d.ts +84 -0
- package/dist/extensions/isolated/child-protocol.js +21 -0
- package/dist/extensions/isolated/child-registration.d.ts +22 -0
- package/dist/extensions/isolated/child-registration.js +152 -0
- package/dist/extensions/isolated/child-session.d.ts +6 -0
- package/dist/extensions/isolated/child-session.js +343 -0
- package/dist/extensions/isolated/child-streams.d.ts +4 -0
- package/dist/extensions/isolated/child-streams.js +142 -0
- package/dist/extensions/isolated/child.d.ts +1 -0
- package/dist/extensions/isolated/child.js +10 -0
- package/dist/extensions/isolated/configured-package.d.ts +15 -0
- package/dist/extensions/isolated/configured-package.js +73 -0
- package/dist/extensions/isolated/engine-binds.d.ts +9 -0
- package/dist/extensions/isolated/engine-binds.js +82 -0
- package/dist/extensions/isolated/engine-policy.d.ts +85 -0
- package/dist/extensions/isolated/engine-policy.js +75 -0
- package/dist/extensions/isolated/engine-proxy-main.d.ts +1 -0
- package/dist/extensions/isolated/engine-proxy-main.js +20 -0
- package/dist/extensions/isolated/engine-proxy.d.ts +7 -0
- package/dist/extensions/isolated/engine-proxy.js +408 -0
- package/dist/extensions/isolated/engine-vaults.d.ts +12 -0
- package/dist/extensions/isolated/engine-vaults.js +93 -0
- package/dist/extensions/isolated/lanes.d.ts +108 -0
- package/dist/extensions/isolated/lanes.js +726 -0
- package/dist/extensions/isolated/postgres-gate.d.ts +15 -0
- package/dist/extensions/isolated/postgres-gate.js +255 -0
- package/dist/extensions/isolated/revision.d.ts +32 -0
- package/dist/extensions/isolated/revision.js +359 -0
- package/dist/extensions/isolated/rpc-frame.d.ts +50 -0
- package/dist/extensions/isolated/rpc-frame.js +193 -0
- package/dist/extensions/isolated/rpc.d.ts +66 -0
- package/dist/extensions/isolated/rpc.js +314 -0
- package/dist/extensions/isolated/sandbox.d.ts +39 -0
- package/dist/extensions/isolated/sandbox.js +356 -0
- package/dist/extensions/isolated/tier.d.ts +6 -0
- package/dist/extensions/isolated/tier.js +45 -0
- package/dist/extensions/ledger.d.ts +1 -1
- package/dist/extensions/lifecycle-topics.d.ts +2 -0
- package/dist/extensions/lifecycle-topics.js +2 -0
- package/dist/extensions/lifecycle.d.ts +3 -1
- package/dist/extensions/lifecycle.js +53 -5
- package/dist/extensions/locks.d.ts +2 -0
- package/dist/extensions/locks.js +7 -0
- package/dist/extensions/org-config.d.ts +17 -27
- package/dist/extensions/org-config.js +114 -129
- package/dist/extensions/permission-view.d.ts +6 -1
- package/dist/extensions/plugin-guides.d.ts +5 -10
- package/dist/extensions/plugin-guides.js +18 -37
- package/dist/extensions/plugin-icons.d.ts +3 -21
- package/dist/extensions/plugin-icons.js +9 -44
- package/dist/extensions/plugin-items.d.ts +10 -30
- package/dist/extensions/plugin-items.js +32 -73
- package/dist/extensions/source-intent.d.ts +14 -0
- package/dist/extensions/source-intent.js +77 -0
- package/dist/inbox/platform-inbox.service.js +16 -27
- package/dist/index.d.ts +2 -1
- package/dist/index.js +2 -1
- package/dist/infra/database/database.module.js +6 -1
- package/dist/infra/database/kernel-db.d.ts +3 -1
- package/dist/infra/database/kernel-db.js +4 -0
- package/dist/infra/events/kernel-events.d.ts +4 -0
- package/dist/infra/outbox/registry.d.ts +3 -36
- package/dist/infra/outbox/registry.js +4 -49
- package/dist/infra/paging/paged-read.d.ts +56 -0
- package/dist/infra/paging/paged-read.js +78 -0
- package/dist/infra/queue/queue-names.d.ts +1 -1
- package/dist/infra/queue/queue-names.js +1 -1
- package/dist/kernel.d.ts +3 -2
- package/dist/kernel.js +21 -2
- package/dist/lifecycle/kernel-lifecycle.d.ts +3 -1
- package/dist/lifecycle/kernel-lifecycle.js +22 -12
- package/dist/lifecycle/tokens.d.ts +8 -0
- package/dist/lifecycle/tokens.js +2 -0
- package/dist/orgs/directory-sync.js +1 -4
- package/dist/orgs/org-lock.d.ts +3 -1
- package/dist/orgs/org-lock.js +3 -1
- package/dist/orgs/orgs.service.d.ts +3 -1
- package/dist/orgs/orgs.service.js +15 -8
- package/dist/overrides.d.ts +0 -3
- package/dist/overrides.js +0 -2
- package/dist/platform/ops/admin.ops.js +14 -3
- package/dist/platform/ops/extensions-admin.ops.js +20 -3
- package/dist/platform/ops/org-plugins.ops.js +5 -2
- package/dist/platform/ops/orgs.ops.js +13 -3
- package/dist/platform/ops/plugins.ops.js +11 -10
- package/dist/setup/setup-checks.service.js +3 -2
- package/dist/skills/usable.js +41 -30
- package/dist/themes/theme-state.js +3 -3
- package/dist/tools/registry.d.ts +2 -2
- package/dist/tools/registry.js +7 -3
- package/package.json +2 -2
- package/src/migrations/0228_extension_org_switches.sql +56 -0
- package/src/migrations/0229_catalog_dependency_edges.sql +17 -0
- package/src/migrations/0230_audit_filter_idx.sql +18 -0
- package/src/migrations/0231_plugin_effect_work.sql +171 -0
- package/dist/catalog/install-status.d.ts +0 -6
- package/dist/catalog/install-status.js +0 -6
- package/dist/catalog/scope-jobs.d.ts +0 -59
- package/dist/catalog/scope-jobs.js +0 -78
|
@@ -8,6 +8,8 @@ import { SuperAdminLock } from "../identity/super-admin.js";
|
|
|
8
8
|
import { KernelConfigService } from "../infra/config/kernel-config.service.js";
|
|
9
9
|
import { KernelDb } from "../infra/database/kernel-db.js";
|
|
10
10
|
import { TransactionHost } from "../infra/database/transaction-host.js";
|
|
11
|
+
import { XactLock } from "../infra/database/xact-lock.js";
|
|
12
|
+
import { KernelEvents } from "../infra/events/kernel-events.js";
|
|
11
13
|
import { LockService } from "../infra/lock/lock.service.js";
|
|
12
14
|
import { OutboxService } from "../infra/outbox/outbox.service.js";
|
|
13
15
|
import type { KernelLogger } from "../log.js";
|
|
@@ -133,7 +135,7 @@ export interface PlatformUpdatePreview {
|
|
|
133
135
|
* The orgs where the scope sync owed with the update will install the plugin (plugin pages spec
|
|
134
136
|
* §5.2.3): its scope wants it on there and the org has no live install (one that waited for
|
|
135
137
|
* connector input before installs took none). `failing`: the scope sync's last attempt there
|
|
136
|
-
* failed (an
|
|
138
|
+
* failed (an `install_failed` effects row), `lastFailure` its message. Sorted by org
|
|
137
139
|
* id. Hashed by org id and `failing` only. An owner's preview ({@link
|
|
138
140
|
* PlatformPluginUpdater.previewForOwner}) drops both for orgs other than the owner.
|
|
139
141
|
*/
|
|
@@ -247,6 +249,8 @@ export type UpdateTarget = VersionRow;
|
|
|
247
249
|
export declare class PlatformPluginUpdater {
|
|
248
250
|
private readonly kdb;
|
|
249
251
|
readonly txHost: TransactionHost;
|
|
252
|
+
private readonly xactLock;
|
|
253
|
+
private readonly events;
|
|
250
254
|
private readonly adminLock;
|
|
251
255
|
private readonly itemLock;
|
|
252
256
|
private readonly orgLock;
|
|
@@ -267,7 +271,7 @@ export declare class PlatformPluginUpdater {
|
|
|
267
271
|
private readonly guides;
|
|
268
272
|
/** Owes the template connector ensure of the orgs with a deferred connector (ruling R27). */
|
|
269
273
|
private readonly outbox;
|
|
270
|
-
constructor(kdb: KernelDb, txHost: TransactionHost, adminLock: SuperAdminLock, itemLock: CatalogItemLock, orgLock: OrgLock, locks: LockService, storage: StorageService, registry: ExtensionRegistry, ops: ExtensionAdminOps,
|
|
274
|
+
constructor(kdb: KernelDb, txHost: TransactionHost, xactLock: XactLock, events: KernelEvents, adminLock: SuperAdminLock, itemLock: CatalogItemLock, orgLock: OrgLock, locks: LockService, storage: StorageService, registry: ExtensionRegistry, ops: ExtensionAdminOps,
|
|
271
275
|
/** Reads the target's extension package (its permissions, for `needsApproval`). */
|
|
272
276
|
blobs: ExtensionBlobs, config: KernelConfigService, platform: PlatformComponents,
|
|
273
277
|
/** Template dependencies (the deployed connector kinds). */
|
|
@@ -413,12 +417,13 @@ export declare class PlatformPluginUpdater {
|
|
|
413
417
|
private themesLost;
|
|
414
418
|
/**
|
|
415
419
|
* {@link PlatformUpdatePreview.scopeInstalls}: the live orgs without a live install (`onOrgs`
|
|
416
|
-
* are those with one)
|
|
417
|
-
*
|
|
420
|
+
* are those with one) that owe setup under the scope worker's intent predicate.
|
|
421
|
+
* Builtin or unavailable plugins have no org setup plan.
|
|
418
422
|
*/
|
|
419
423
|
private scopeInstallsOf;
|
|
420
|
-
/** The orgs where the plugin is on: a live install (builtin: every live org). */
|
|
421
424
|
private pluginOrgs;
|
|
425
|
+
/** Applied org resources that the platform update must move with the catalog version. */
|
|
426
|
+
private appliedPluginOrgs;
|
|
422
427
|
private liveOrgs;
|
|
423
428
|
}
|
|
424
429
|
export {};
|
|
@@ -26,10 +26,13 @@ import { audit } from "../identity/audit.js";
|
|
|
26
26
|
import { SuperAdminLock } from "../identity/super-admin.js";
|
|
27
27
|
import { notifySharedUpdate } from "../inbox/org-notices.js";
|
|
28
28
|
import { KernelConfigService } from "../infra/config/kernel-config.service.js";
|
|
29
|
+
import { afterCommit } from "../infra/database/after-commit.js";
|
|
29
30
|
import { KernelDb } from "../infra/database/kernel-db.js";
|
|
30
31
|
import { asPlatform, withOrgScope } from "../infra/database/org-scope.js";
|
|
31
32
|
import { TransactionHost } from "../infra/database/transaction-host.js";
|
|
32
33
|
import { Transactional } from "../infra/database/transactional.decorator.js";
|
|
34
|
+
import { XactLock } from "../infra/database/xact-lock.js";
|
|
35
|
+
import { KernelEvents } from "../infra/events/kernel-events.js";
|
|
33
36
|
import { LockService } from "../infra/lock/lock.service.js";
|
|
34
37
|
import { OutboxService } from "../infra/outbox/outbox.service.js";
|
|
35
38
|
import { KERNEL_LOGGER } from "../infra/tokens.js";
|
|
@@ -45,15 +48,16 @@ import { dirDigest, getPath, readCatalogAgentTemplates, readCatalogTemplates, re
|
|
|
45
48
|
import { markVersionApplied, versionUsable } from "./catalog-items.js";
|
|
46
49
|
import { agentsUsing, clashingOrgSkills, clashingPlatformSkills, componentOn, connectorsMadeFrom, connectorTemplatesOn, listedIn, loadComponents, loadScopeState, pluginFactsOf, switchOf, themeIdClashes, } from "./component-state.js";
|
|
47
50
|
import { credentialKey } from "./credential-key.js";
|
|
48
|
-
import {
|
|
51
|
+
import { refreshCatalogDependencyEdges } from "./dependency-edges.js";
|
|
52
|
+
import { EFFECT_CANDIDATES_LOCK } from "./effect-work.js";
|
|
49
53
|
import { CatalogItemLock } from "./locks.js";
|
|
50
54
|
import { requireMarketplacePublisher } from "./marketplace-fetch.js";
|
|
55
|
+
import { orgPluginEffectIntent, orgUsable } from "./org-intent.js";
|
|
51
56
|
import { isUsable } from "./ownership.js";
|
|
52
57
|
import { PlanStale, PlatformComponents } from "./platform-components.js";
|
|
53
58
|
import { catalogSkillNames, PluginInstaller } from "./plugin-install.js";
|
|
54
59
|
import { assertDeclarativeUpload } from "./plugin-package.js";
|
|
55
60
|
import { OFFICIAL_MARKETPLACE_ID, officialPublisherProofMode } from "./publisher-policy.js";
|
|
56
|
-
import { wantedOn } from "./scope.js";
|
|
57
61
|
import { PluginScopeSync } from "./scope-sync.js";
|
|
58
62
|
import { oweTemplateConnectors } from "./template-connector-jobs.js";
|
|
59
63
|
import { compareVersions, satisfiesRange } from "./versions.js";
|
|
@@ -127,6 +131,8 @@ const filesDigest = (row) => skillFilesDigest(row.files.map((f) => ({ path: f.pa
|
|
|
127
131
|
let PlatformPluginUpdater = class PlatformPluginUpdater {
|
|
128
132
|
kdb;
|
|
129
133
|
txHost;
|
|
134
|
+
xactLock;
|
|
135
|
+
events;
|
|
130
136
|
adminLock;
|
|
131
137
|
itemLock;
|
|
132
138
|
orgLock;
|
|
@@ -143,7 +149,7 @@ let PlatformPluginUpdater = class PlatformPluginUpdater {
|
|
|
143
149
|
log;
|
|
144
150
|
guides;
|
|
145
151
|
outbox;
|
|
146
|
-
constructor(kdb, txHost, adminLock, itemLock, orgLock, locks, storage, registry, ops,
|
|
152
|
+
constructor(kdb, txHost, xactLock, events, adminLock, itemLock, orgLock, locks, storage, registry, ops,
|
|
147
153
|
/** Reads the target's extension package (its permissions, for `needsApproval`). */
|
|
148
154
|
blobs, config, platform,
|
|
149
155
|
/** Template dependencies (the deployed connector kinds). */
|
|
@@ -154,6 +160,8 @@ let PlatformPluginUpdater = class PlatformPluginUpdater {
|
|
|
154
160
|
outbox) {
|
|
155
161
|
this.kdb = kdb;
|
|
156
162
|
this.txHost = txHost;
|
|
163
|
+
this.xactLock = xactLock;
|
|
164
|
+
this.events = events;
|
|
157
165
|
this.adminLock = adminLock;
|
|
158
166
|
this.itemLock = itemLock;
|
|
159
167
|
this.orgLock = orgLock;
|
|
@@ -438,22 +446,15 @@ let PlatformPluginUpdater = class PlatformPluginUpdater {
|
|
|
438
446
|
// An owner update was authorized at its start: the put-back is not checked again
|
|
439
447
|
const back = opsOwner && { ...opsOwner, rollback: true };
|
|
440
448
|
try {
|
|
441
|
-
if (ext.
|
|
442
|
-
|
|
443
|
-
await this.ops.install(checked.name,
|
|
444
|
-
catalogItemId:
|
|
449
|
+
if (ext.previous !== null) {
|
|
450
|
+
const { source, sha256, catalog_item_id } = ext.previous;
|
|
451
|
+
await this.ops.install(checked.name, sha256, actor, opts.actorTokenId, {
|
|
452
|
+
...(source === "catalog" && catalog_item_id && { catalogItemId: catalog_item_id }),
|
|
453
|
+
...(source === "bootstrap" && { bootstrap: true }),
|
|
445
454
|
...(back && { owner: back }),
|
|
446
455
|
});
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
}
|
|
450
|
-
else if (ext.previous !== null) {
|
|
451
|
-
await this.ops.install(checked.name, ext.previous, actor, opts.actorTokenId, {
|
|
452
|
-
...(back && { owner: back }),
|
|
453
|
-
});
|
|
454
|
-
// The install left the enabled extension disabled (a held single-provider point): the
|
|
455
|
-
// previous version, which did not provide it, runs again
|
|
456
|
-
if (leftDisabled !== undefined) {
|
|
456
|
+
// Restore the serving state after a removal or a single-provider conflict.
|
|
457
|
+
if (removedEnabled || leftDisabled !== undefined) {
|
|
457
458
|
await this.ops.enable(checked.name, actor, opts.actorTokenId, back);
|
|
458
459
|
}
|
|
459
460
|
}
|
|
@@ -539,6 +540,7 @@ let PlatformPluginUpdater = class PlatformPluginUpdater {
|
|
|
539
540
|
if (owner !== undefined && actor === null) {
|
|
540
541
|
throw new Error("an owner update needs the acting account");
|
|
541
542
|
}
|
|
543
|
+
await this.xactLock.lock(EFFECT_CANDIDATES_LOCK);
|
|
542
544
|
// null: the kernel itself (the bootstrap step), no super admin to re-check
|
|
543
545
|
if (owner === undefined && actor !== null)
|
|
544
546
|
await this.adminLock.lockAndAuthorize(actor);
|
|
@@ -590,9 +592,12 @@ let PlatformPluginUpdater = class PlatformPluginUpdater {
|
|
|
590
592
|
}
|
|
591
593
|
// Removals (spec §7.3): kept while agents use it; otherwise soft-deleted
|
|
592
594
|
const now = sql `now()`;
|
|
595
|
+
let removedConnectorTemplate = false;
|
|
593
596
|
for (const c of diff.components) {
|
|
594
597
|
if (c.change !== "removed" || c.id === null || c.kept !== undefined)
|
|
595
598
|
continue;
|
|
599
|
+
if (c.kind === "connector_template")
|
|
600
|
+
removedConnectorTemplate = true;
|
|
596
601
|
const table = c.kind === "skill"
|
|
597
602
|
? "platform_skills"
|
|
598
603
|
: c.kind === "agent_template"
|
|
@@ -670,9 +675,9 @@ let PlatformPluginUpdater = class PlatformPluginUpdater {
|
|
|
670
675
|
// current at its commit, PluginInstaller.markInstalled)
|
|
671
676
|
await t
|
|
672
677
|
.updateTable("plugin_installs")
|
|
673
|
-
.set({ version: diff.to.version
|
|
678
|
+
.set({ version: diff.to.version })
|
|
674
679
|
.where("item_id", "=", itemId)
|
|
675
|
-
.where("
|
|
680
|
+
.where("version", "is not", null)
|
|
676
681
|
.execute();
|
|
677
682
|
if (owner !== undefined) {
|
|
678
683
|
// An org's version becomes its latest once applied
|
|
@@ -683,6 +688,10 @@ let PlatformPluginUpdater = class PlatformPluginUpdater {
|
|
|
683
688
|
.execute();
|
|
684
689
|
await markVersionApplied(t, itemId, diff.to.version);
|
|
685
690
|
}
|
|
691
|
+
await refreshCatalogDependencyEdges(t);
|
|
692
|
+
if (removedConnectorTemplate) {
|
|
693
|
+
afterCommit(() => this.events.emit("catalog.org-intent-changed", {}));
|
|
694
|
+
}
|
|
686
695
|
// The orgs using a shared org-owned plugin are told, one notice per plugin (a platform-owned
|
|
687
696
|
// plugin tells nobody); a plugin never synced before has no version to come from
|
|
688
697
|
if (diff.from !== null) {
|
|
@@ -767,7 +776,7 @@ let PlatformPluginUpdater = class PlatformPluginUpdater {
|
|
|
767
776
|
const connectorId = await this.connectors.createDeferredIn(c.orgId, null, ci, {
|
|
768
777
|
auditDetail: { via: "platform_update" },
|
|
769
778
|
});
|
|
770
|
-
await this.installer.recordTemplateConnectorIn(c.orgId, itemId, connectorId, c.templateId
|
|
779
|
+
await this.installer.recordTemplateConnectorIn(c.orgId, itemId, connectorId, c.templateId);
|
|
771
780
|
}
|
|
772
781
|
/**
|
|
773
782
|
* Computes an update (see the class comment). `target`: the target read from an org's staging
|
|
@@ -1094,8 +1103,8 @@ let PlatformPluginUpdater = class PlatformPluginUpdater {
|
|
|
1094
1103
|
pinnedOrgs: [],
|
|
1095
1104
|
});
|
|
1096
1105
|
}
|
|
1097
|
-
|
|
1098
|
-
const
|
|
1106
|
+
const onOrgs = await this.pluginOrgs(itemId);
|
|
1107
|
+
const appliedOrgs = item.builtin ? onOrgs : await this.appliedPluginOrgs(itemId);
|
|
1099
1108
|
if (extension)
|
|
1100
1109
|
extension = { ...extension, orgs: onOrgs };
|
|
1101
1110
|
// Rule 10: an added skill must not take a name already used where the plugin is on
|
|
@@ -1233,7 +1242,7 @@ let PlatformPluginUpdater = class PlatformPluginUpdater {
|
|
|
1233
1242
|
.execute()).map((r) => r.org_id))
|
|
1234
1243
|
: undefined;
|
|
1235
1244
|
const ids = [...flipped.keys()].sort();
|
|
1236
|
-
for (const orgId of
|
|
1245
|
+
for (const orgId of appliedOrgs) {
|
|
1237
1246
|
if (listedOrgs !== undefined && !listedOrgs.has(orgId))
|
|
1238
1247
|
continue;
|
|
1239
1248
|
// a template the org already has a live connector from (one a switch-off kept) needs none
|
|
@@ -1318,7 +1327,11 @@ let PlatformPluginUpdater = class PlatformPluginUpdater {
|
|
|
1318
1327
|
}
|
|
1319
1328
|
}
|
|
1320
1329
|
}
|
|
1321
|
-
const
|
|
1330
|
+
const toManifest = to.manifest;
|
|
1331
|
+
const expectsSetup = toManifest.extension !== undefined ||
|
|
1332
|
+
(toManifest.connectorTemplates?.length ?? 0) > 0 ||
|
|
1333
|
+
(toManifest.dependencies?.length ?? 0) > 0;
|
|
1334
|
+
const scopeInstalls = expectsSetup ? await this.scopeInstallsOf(item, appliedOrgs) : [];
|
|
1322
1335
|
const connectorOrgs = [...byOrg.values()]
|
|
1323
1336
|
.map((e) => ({
|
|
1324
1337
|
...e,
|
|
@@ -1414,7 +1427,7 @@ let PlatformPluginUpdater = class PlatformPluginUpdater {
|
|
|
1414
1427
|
const want = to.manifest.extension;
|
|
1415
1428
|
const row = await this.db
|
|
1416
1429
|
.selectFrom("extension_installs")
|
|
1417
|
-
.select(["sha256", "version"])
|
|
1430
|
+
.select(["sha256", "version", "source", "catalog_item_id"])
|
|
1418
1431
|
.where("name", "=", name)
|
|
1419
1432
|
.executeTakeFirst();
|
|
1420
1433
|
// Only an extension declared in the startup config runs without an install record; one this
|
|
@@ -1423,7 +1436,7 @@ let PlatformPluginUpdater = class PlatformPluginUpdater {
|
|
|
1423
1436
|
const loaded = declared ? this.registry.manifests().find((m) => m.name === name) : undefined;
|
|
1424
1437
|
if (!want) {
|
|
1425
1438
|
if (allowRemove && from?.manifest.extension && row && !declared) {
|
|
1426
|
-
return { from: row.version, to: null, sha256: null, previous: row
|
|
1439
|
+
return { from: row.version, to: null, sha256: null, previous: row };
|
|
1427
1440
|
}
|
|
1428
1441
|
if (from?.manifest.extension && (row || declared)) {
|
|
1429
1442
|
throw targetInvalid(`Version ${to.version} of plugin ${name} has no extension, but the deployment runs it; uninstall the extension first`, [{ reason: "extension_removed", version: to.version }]);
|
|
@@ -1448,7 +1461,7 @@ let PlatformPluginUpdater = class PlatformPluginUpdater {
|
|
|
1448
1461
|
from: row?.version ?? null,
|
|
1449
1462
|
to: want.manifest.version,
|
|
1450
1463
|
sha256: to.extension_sha256,
|
|
1451
|
-
previous: row
|
|
1464
|
+
previous: row ?? null,
|
|
1452
1465
|
};
|
|
1453
1466
|
}
|
|
1454
1467
|
/**
|
|
@@ -1579,41 +1592,31 @@ let PlatformPluginUpdater = class PlatformPluginUpdater {
|
|
|
1579
1592
|
}
|
|
1580
1593
|
/**
|
|
1581
1594
|
* {@link PlatformUpdatePreview.scopeInstalls}: the live orgs without a live install (`onOrgs`
|
|
1582
|
-
* are those with one)
|
|
1583
|
-
*
|
|
1595
|
+
* are those with one) that owe setup under the scope worker's intent predicate.
|
|
1596
|
+
* Builtin or unavailable plugins have no org setup plan.
|
|
1584
1597
|
*/
|
|
1585
1598
|
async scopeInstallsOf(item, onOrgs) {
|
|
1586
1599
|
if (item.builtin || !isUsable(item))
|
|
1587
1600
|
return [];
|
|
1588
|
-
const [orgs,
|
|
1601
|
+
const [orgs, failures] = await Promise.all([
|
|
1589
1602
|
this.db
|
|
1590
1603
|
.selectFrom("orgs")
|
|
1591
1604
|
.select(["id", "name"])
|
|
1592
1605
|
.where("deleted_at", "is", null)
|
|
1606
|
+
.where(({ ref }) => orgPluginEffectIntent(this.db, ref("orgs.id"), item.id))
|
|
1593
1607
|
.orderBy("id")
|
|
1594
1608
|
.execute(),
|
|
1595
1609
|
this.db
|
|
1596
|
-
.selectFrom("
|
|
1597
|
-
.select("org_id")
|
|
1598
|
-
.where("
|
|
1599
|
-
.execute(),
|
|
1600
|
-
this.db
|
|
1601
|
-
.selectFrom("catalog_item_org_switches")
|
|
1602
|
-
.select(["org_id", "enabled"])
|
|
1603
|
-
.where("item_id", "=", item.id)
|
|
1604
|
-
.execute(),
|
|
1605
|
-
this.db
|
|
1606
|
-
.selectFrom("plugin_scope_sync_failures")
|
|
1607
|
-
.select(["org_id", "message"])
|
|
1610
|
+
.selectFrom("plugin_installs")
|
|
1611
|
+
.select(["org_id", "error"])
|
|
1612
|
+
.where("status", "=", "install_failed")
|
|
1608
1613
|
.where("item_id", "=", item.id)
|
|
1609
1614
|
.execute(),
|
|
1610
1615
|
]);
|
|
1611
|
-
const failed = new Map(failures.map((r) => [r.org_id, r.message]));
|
|
1616
|
+
const failed = new Map(failures.map((r) => [r.org_id, r.error?.message]));
|
|
1612
1617
|
const on = new Set(onOrgs);
|
|
1613
|
-
const inList = new Set(listed.map((r) => r.org_id));
|
|
1614
|
-
const sw = new Map(switches.map((r) => [r.org_id, r.enabled]));
|
|
1615
1618
|
return orgs
|
|
1616
|
-
.filter((o) => !on.has(o.id)
|
|
1619
|
+
.filter((o) => !on.has(o.id))
|
|
1617
1620
|
.map((o) => {
|
|
1618
1621
|
const lastFailure = failed.get(o.id);
|
|
1619
1622
|
return {
|
|
@@ -1623,17 +1626,25 @@ let PlatformPluginUpdater = class PlatformPluginUpdater {
|
|
|
1623
1626
|
};
|
|
1624
1627
|
});
|
|
1625
1628
|
}
|
|
1626
|
-
|
|
1627
|
-
|
|
1628
|
-
|
|
1629
|
-
|
|
1629
|
+
async pluginOrgs(itemId) {
|
|
1630
|
+
const rows = await this.db
|
|
1631
|
+
.selectFrom("orgs")
|
|
1632
|
+
.select("id")
|
|
1633
|
+
.where("deleted_at", "is", null)
|
|
1634
|
+
.where(({ ref }) => orgUsable(this.db, ref("orgs.id"), itemId))
|
|
1635
|
+
.orderBy("id")
|
|
1636
|
+
.execute();
|
|
1637
|
+
return rows.map((row) => row.id);
|
|
1638
|
+
}
|
|
1639
|
+
/** Applied org resources that the platform update must move with the catalog version. */
|
|
1640
|
+
async appliedPluginOrgs(itemId) {
|
|
1630
1641
|
const rows = await this.db
|
|
1631
1642
|
.selectFrom("plugin_installs as a")
|
|
1632
1643
|
.innerJoin("orgs as o", "o.id", "a.org_id")
|
|
1633
1644
|
.select("a.org_id")
|
|
1634
1645
|
.distinct()
|
|
1635
1646
|
.where("a.item_id", "=", itemId)
|
|
1636
|
-
.where("a.
|
|
1647
|
+
.where("a.version", "is not", null)
|
|
1637
1648
|
.where("o.deleted_at", "is", null)
|
|
1638
1649
|
.orderBy("a.org_id")
|
|
1639
1650
|
.execute();
|
|
@@ -1665,22 +1676,24 @@ PlatformPluginUpdater = __decorate([
|
|
|
1665
1676
|
,
|
|
1666
1677
|
__param(0, Inject(KernelDb)),
|
|
1667
1678
|
__param(1, Inject(TransactionHost)),
|
|
1668
|
-
__param(2, Inject(
|
|
1669
|
-
__param(3, Inject(
|
|
1670
|
-
__param(4, Inject(
|
|
1671
|
-
__param(5, Inject(
|
|
1672
|
-
__param(6, Inject(
|
|
1673
|
-
__param(7, Inject(
|
|
1674
|
-
__param(8, Inject(
|
|
1675
|
-
__param(9, Inject(
|
|
1676
|
-
__param(10, Inject(
|
|
1677
|
-
__param(11, Inject(
|
|
1678
|
-
__param(12, Inject(
|
|
1679
|
-
__param(13, Inject(
|
|
1680
|
-
__param(14, Inject(
|
|
1681
|
-
__param(15, Inject(
|
|
1682
|
-
__param(16, Inject(
|
|
1683
|
-
__param(17, Inject(
|
|
1679
|
+
__param(2, Inject(XactLock)),
|
|
1680
|
+
__param(3, Inject(KernelEvents)),
|
|
1681
|
+
__param(4, Inject(SuperAdminLock)),
|
|
1682
|
+
__param(5, Inject(CatalogItemLock)),
|
|
1683
|
+
__param(6, Inject(OrgLock)),
|
|
1684
|
+
__param(7, Inject(LockService)),
|
|
1685
|
+
__param(8, Inject(StorageService)),
|
|
1686
|
+
__param(9, Inject(ExtensionRegistry)),
|
|
1687
|
+
__param(10, Inject(ExtensionAdminOps)),
|
|
1688
|
+
__param(11, Inject(ExtensionBlobs)),
|
|
1689
|
+
__param(12, Inject(KernelConfigService)),
|
|
1690
|
+
__param(13, Inject(PlatformComponents)),
|
|
1691
|
+
__param(14, Inject(PluginInstaller)),
|
|
1692
|
+
__param(15, Inject(ConnectorsService)),
|
|
1693
|
+
__param(16, Inject(PluginScopeSync)),
|
|
1694
|
+
__param(17, Inject(KERNEL_LOGGER)),
|
|
1695
|
+
__param(18, Inject(PluginGuides)),
|
|
1696
|
+
__param(19, Inject(OutboxService))
|
|
1684
1697
|
], PlatformPluginUpdater);
|
|
1685
1698
|
export { PlatformPluginUpdater };
|
|
1686
1699
|
/** The preview of a diff (without `guideChanges`, which reads PG). */
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { sql } from "kysely";
|
|
2
2
|
import { ApiError } from "../errors.js";
|
|
3
|
+
import { extensionSourcesQuery } from "../extensions/plugin-items.js";
|
|
3
4
|
import { audit } from "../identity/audit.js";
|
|
4
5
|
import { isUsable } from "./ownership.js";
|
|
5
6
|
import { visibleTo } from "./scope.js";
|
|
@@ -95,19 +96,30 @@ export function pluginItemDisabled(names) {
|
|
|
95
96
|
*/
|
|
96
97
|
export async function assertPluginSourcesInstallable(t, orgId, plugin) {
|
|
97
98
|
const rows = await t
|
|
98
|
-
.selectFrom(
|
|
99
|
-
.innerJoin("catalog_items as i", "i.id", "
|
|
100
|
-
.select([
|
|
101
|
-
|
|
102
|
-
|
|
99
|
+
.selectFrom(extensionSourcesQuery(t, plugin).as("source"))
|
|
100
|
+
.innerJoin("catalog_items as i", "i.id", "source.item_id")
|
|
101
|
+
.select([
|
|
102
|
+
"i.id",
|
|
103
|
+
"i.disabled",
|
|
104
|
+
"i.scope",
|
|
105
|
+
"i.builtin",
|
|
106
|
+
"i.deleted_at",
|
|
107
|
+
"i.owner_org_id",
|
|
108
|
+
"i.shareable",
|
|
109
|
+
])
|
|
103
110
|
.orderBy("i.id")
|
|
104
111
|
.forShare("i")
|
|
105
112
|
.execute();
|
|
106
|
-
|
|
113
|
+
const live = rows.filter((row) => row.deleted_at === null);
|
|
114
|
+
if (live.some((row) => row.disabled))
|
|
107
115
|
throw itemDisabled();
|
|
108
|
-
|
|
109
|
-
|
|
116
|
+
if (rows.length > 0 && live.length === 0)
|
|
117
|
+
throw notOffered();
|
|
118
|
+
for (const row of live) {
|
|
119
|
+
if ((row.owner_org_id !== null && row.owner_org_id !== orgId && !row.shareable) ||
|
|
120
|
+
!(await offeredTo(t, orgId, row)))
|
|
110
121
|
throw notOffered();
|
|
122
|
+
}
|
|
111
123
|
}
|
|
112
124
|
/**
|
|
113
125
|
* Cancels catalog requests still pending in the caller's transaction (`db` is its handle; when the
|
|
@@ -2,6 +2,7 @@ import { sql } from "kysely";
|
|
|
2
2
|
import { audit } from "../identity/audit.js";
|
|
3
3
|
import { notifyItemShared } from "../inbox/org-notices.js";
|
|
4
4
|
import { assertShareable, shareGate } from "./ownership.js";
|
|
5
|
+
import { addNamedPluginOrg } from "./scope-writer.js";
|
|
5
6
|
/**
|
|
6
7
|
* Adds one org to a `named` item's list in the caller's transaction (the caller holds the item row
|
|
7
8
|
* `FOR UPDATE`): audits `catalog.scope_changed` the way a scope change
|
|
@@ -25,13 +26,7 @@ export async function addScopeOrg(db, actor, item, orgId, opts = {}) {
|
|
|
25
26
|
return false;
|
|
26
27
|
assertShareable(item);
|
|
27
28
|
}
|
|
28
|
-
|
|
29
|
-
.insertInto("catalog_item_scope_orgs")
|
|
30
|
-
.values({ item_id: item.id, org_id: orgId })
|
|
31
|
-
.onConflict((oc) => oc.doNothing())
|
|
32
|
-
.returning("org_id")
|
|
33
|
-
.executeTakeFirst();
|
|
34
|
-
if (added === undefined)
|
|
29
|
+
if (!(await addNamedPluginOrg(db, item.id, orgId)))
|
|
35
30
|
return false;
|
|
36
31
|
await db
|
|
37
32
|
.updateTable("catalog_items")
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import type { KernelSchemaDb } from "../db/kernel-schema.js";
|
|
2
|
-
/**
|
|
3
|
-
* Whether the item's own scope wants it on in the org (`wantedOn` over the item's scope, builtin
|
|
4
|
-
* and disabled flags, the org's list membership and its switch), read through `db` (the caller's
|
|
5
|
-
* transaction under the org row lock, or the pool). A deleted or missing item is not wanted.
|
|
6
|
-
*/
|
|
2
|
+
/** Whether the item's own scope wants it on in the org, independent of dependencies. */
|
|
7
3
|
export declare function wantedByScope(db: KernelSchemaDb, orgId: string, itemId: string): Promise<boolean>;
|
|
4
|
+
/** The committed plugin intent, including any authorized dependency root. */
|
|
5
|
+
export declare function pluginUsable(db: KernelSchemaDb, orgId: string, itemId: string): Promise<boolean>;
|
|
6
|
+
/** Direct intent still owes an effect attempt when a blocked dependency denies execution. */
|
|
7
|
+
export declare function pluginEffectsWanted(db: KernelSchemaDb, orgId: string, itemId: string): Promise<boolean>;
|
|
8
8
|
/**
|
|
9
9
|
* A scope sync install (`via: "scope"`) found, under the org row lock, that the item is no longer
|
|
10
10
|
* wanted in the org (a person switched it off, or the scope changed, after the sync's decision):
|
|
@@ -32,4 +32,4 @@ export declare class ScopeStillWanted extends Error {
|
|
|
32
32
|
* orgs, through the share gate). A hidden `named` item outside its list is left out, so nothing
|
|
33
33
|
* reveals it to the org.
|
|
34
34
|
*/
|
|
35
|
-
export declare function itemsSeenBy(db: KernelSchemaDb, orgId: string, itemIds: readonly string[]): Promise<Set<string>>;
|
|
35
|
+
export declare function itemsSeenBy(db: KernelSchemaDb, orgId: string, itemIds: readonly string[], view?: "catalog" | "offered"): Promise<Set<string>>;
|
|
@@ -1,32 +1,24 @@
|
|
|
1
|
-
import {
|
|
2
|
-
/**
|
|
3
|
-
* Whether the item's own scope wants it on in the org (`wantedOn` over the item's scope, builtin
|
|
4
|
-
* and disabled flags, the org's list membership and its switch), read through `db` (the caller's
|
|
5
|
-
* transaction under the org row lock, or the pool). A deleted or missing item is not wanted.
|
|
6
|
-
*/
|
|
1
|
+
import { orgPluginDirectIntent, orgPluginEffectIntent, orgSees, orgUsable } from "./org-intent.js";
|
|
2
|
+
/** Whether the item's own scope wants it on in the org, independent of dependencies. */
|
|
7
3
|
export async function wantedByScope(db, orgId, itemId) {
|
|
8
|
-
const item = await db
|
|
9
|
-
.
|
|
10
|
-
.select(["scope", "builtin", "disabled"])
|
|
11
|
-
.where("id", "=", itemId)
|
|
12
|
-
.where("deleted_at", "is", null)
|
|
13
|
-
.executeTakeFirst();
|
|
14
|
-
if (!item)
|
|
15
|
-
return false;
|
|
16
|
-
// one after the other: `db` may be a transaction's single connection
|
|
17
|
-
const listed = await db
|
|
18
|
-
.selectFrom("catalog_item_scope_orgs")
|
|
19
|
-
.select("item_id")
|
|
20
|
-
.where("item_id", "=", itemId)
|
|
21
|
-
.where("org_id", "=", orgId)
|
|
4
|
+
const item = await orgPluginDirectIntent(db, orgId)
|
|
5
|
+
.where("item.id", "=", itemId)
|
|
22
6
|
.executeTakeFirst();
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
.
|
|
29
|
-
|
|
7
|
+
return item?.directIntent === true;
|
|
8
|
+
}
|
|
9
|
+
/** The committed plugin intent, including any authorized dependency root. */
|
|
10
|
+
export async function pluginUsable(db, orgId, itemId) {
|
|
11
|
+
const row = await db
|
|
12
|
+
.selectNoFrom(orgUsable(db, orgId, itemId).as("usable"))
|
|
13
|
+
.executeTakeFirstOrThrow();
|
|
14
|
+
return row.usable;
|
|
15
|
+
}
|
|
16
|
+
/** Direct intent still owes an effect attempt when a blocked dependency denies execution. */
|
|
17
|
+
export async function pluginEffectsWanted(db, orgId, itemId) {
|
|
18
|
+
const row = await db
|
|
19
|
+
.selectNoFrom(orgPluginEffectIntent(db, orgId, itemId).as("wanted"))
|
|
20
|
+
.executeTakeFirstOrThrow();
|
|
21
|
+
return row.wanted;
|
|
30
22
|
}
|
|
31
23
|
/**
|
|
32
24
|
* A scope sync install (`via: "scope"`) found, under the org row lock, that the item is no longer
|
|
@@ -65,23 +57,12 @@ export class ScopeStillWanted extends Error {
|
|
|
65
57
|
* orgs, through the share gate). A hidden `named` item outside its list is left out, so nothing
|
|
66
58
|
* reveals it to the org.
|
|
67
59
|
*/
|
|
68
|
-
export async function itemsSeenBy(db, orgId, itemIds) {
|
|
60
|
+
export async function itemsSeenBy(db, orgId, itemIds, view = "catalog") {
|
|
69
61
|
if (itemIds.length === 0)
|
|
70
62
|
return new Set();
|
|
71
|
-
const items = await db
|
|
72
|
-
.
|
|
73
|
-
.
|
|
74
|
-
.where("id", "in", [...itemIds])
|
|
75
|
-
.where("deleted_at", "is", null)
|
|
63
|
+
const items = await orgSees(db, orgId, true, view)
|
|
64
|
+
.select("item.id")
|
|
65
|
+
.where("item.id", "in", [...itemIds])
|
|
76
66
|
.execute();
|
|
77
|
-
|
|
78
|
-
.selectFrom("catalog_item_scope_orgs")
|
|
79
|
-
.select("item_id")
|
|
80
|
-
.where("org_id", "=", orgId)
|
|
81
|
-
.where("item_id", "in", [...itemIds])
|
|
82
|
-
.execute()).map((r) => r.item_id));
|
|
83
|
-
return new Set(items
|
|
84
|
-
.filter((i) => visibleTo({ scope: i.builtin ? "all" : i.scope }, listed.has(i.id)) ||
|
|
85
|
-
requestable(i, listed.has(i.id)))
|
|
86
|
-
.map((i) => i.id));
|
|
67
|
+
return new Set(items.map((item) => item.id));
|
|
87
68
|
}
|
|
@@ -1,24 +1,20 @@
|
|
|
1
1
|
import { WorkerHost } from "@nestjs/bullmq";
|
|
2
2
|
import type { Job, Worker } from "bullmq";
|
|
3
3
|
import type { KernelLogger } from "../log.js";
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
* chunk or org job with a pair whose extension this replica has not loaded yet throws, so BullMQ
|
|
9
|
-
* retries it with the registry's backoff; its last attempt installs anyway.
|
|
10
|
-
*/
|
|
11
|
-
export declare class PluginScopeSyncProcessor extends WorkerHost<Worker<ScopeJob>> {
|
|
4
|
+
import { type EffectJob } from "./effect-work.js";
|
|
5
|
+
import { PluginScopeSync } from "./scope-sync.js";
|
|
6
|
+
/** Runs one generation of effects for one org and item. */
|
|
7
|
+
export declare class PluginScopeSyncProcessor extends WorkerHost<Worker<EffectJob>> {
|
|
12
8
|
private readonly sync;
|
|
13
9
|
private readonly log;
|
|
14
10
|
private readonly stopping;
|
|
15
|
-
constructor(sync: PluginScopeSync, log: Pick<KernelLogger, "error"
|
|
16
|
-
process(job: Job<
|
|
11
|
+
constructor(sync: PluginScopeSync, log: Pick<KernelLogger, "error">);
|
|
12
|
+
process(job: Job<EffectJob>): Promise<void>;
|
|
17
13
|
/** Starts consuming (worker role, after the extensions loaded; built with `autorun: false`). */
|
|
18
14
|
start(): void;
|
|
19
15
|
/** Stops between pairs and closes the worker. */
|
|
20
16
|
close(): Promise<void>;
|
|
21
|
-
failed(job: Job<
|
|
17
|
+
failed(job: Job<EffectJob> | undefined, err: Error): void;
|
|
22
18
|
error(err: Error): void;
|
|
23
19
|
}
|
|
24
20
|
/**
|
|
@@ -13,13 +13,9 @@ import { configuredProcessor } from "../infra/queue/configured-processor.js";
|
|
|
13
13
|
import { runJob } from "../infra/queue/run-job.js";
|
|
14
14
|
import { KERNEL_LOGGER } from "../infra/tokens.js";
|
|
15
15
|
import { CatalogModule } from "./catalog.module.js";
|
|
16
|
-
import {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
* `scope-item-chunk` and `scope-org` jobs the outbox delivers (any other name fails the job). A
|
|
20
|
-
* chunk or org job with a pair whose extension this replica has not loaded yet throws, so BullMQ
|
|
21
|
-
* retries it with the registry's backoff; its last attempt installs anyway.
|
|
22
|
-
*/
|
|
16
|
+
import { PLUGIN_EFFECT_JOB, PLUGIN_EFFECT_QUEUE } from "./effect-work.js";
|
|
17
|
+
import { PLUGIN_SCOPE_CONCURRENCY, PluginScopeSync } from "./scope-sync.js";
|
|
18
|
+
/** Runs one generation of effects for one org and item. */
|
|
23
19
|
let PluginScopeSyncProcessor = class PluginScopeSyncProcessor extends WorkerHost {
|
|
24
20
|
sync;
|
|
25
21
|
log;
|
|
@@ -30,20 +26,12 @@ let PluginScopeSyncProcessor = class PluginScopeSyncProcessor extends WorkerHost
|
|
|
30
26
|
this.log = log;
|
|
31
27
|
}
|
|
32
28
|
process(job) {
|
|
33
|
-
return runJob(
|
|
34
|
-
if (
|
|
35
|
-
throw new Error(`unknown plugin
|
|
36
|
-
}
|
|
29
|
+
return runJob(PLUGIN_EFFECT_QUEUE, job, () => {
|
|
30
|
+
if (job.name !== PLUGIN_EFFECT_JOB)
|
|
31
|
+
throw new Error(`unknown plugin effect job ${job.name}`);
|
|
37
32
|
if (job.id === undefined)
|
|
38
|
-
throw new Error("a plugin
|
|
39
|
-
return this.sync.process(job.data,
|
|
40
|
-
jobId: job.id,
|
|
41
|
-
finalAttempt: job.attemptsMade + 1 >= (job.opts.attempts ?? 1),
|
|
42
|
-
signal: this.stopping.signal,
|
|
43
|
-
});
|
|
44
|
-
}, {
|
|
45
|
-
// an item or chunk job spans the orgs of a platform item; an org job carries its orgId
|
|
46
|
-
platform: "plugin scope sync of a platform item",
|
|
33
|
+
throw new Error("a plugin effect job has no id");
|
|
34
|
+
return this.sync.process(job.data, job.id, this.stopping.signal);
|
|
47
35
|
});
|
|
48
36
|
}
|
|
49
37
|
/** Starts consuming (worker role, after the extensions loaded; built with `autorun: false`). */
|
|
@@ -57,11 +45,7 @@ let PluginScopeSyncProcessor = class PluginScopeSyncProcessor extends WorkerHost
|
|
|
57
45
|
}
|
|
58
46
|
failed(job, err) {
|
|
59
47
|
const meta = { name: job?.name, jobId: job?.id, attempt: job?.attemptsMade, err };
|
|
60
|
-
|
|
61
|
-
if (err instanceof ScopeSyncDeferred)
|
|
62
|
-
this.log.warn("plugin scope job deferred", meta);
|
|
63
|
-
else
|
|
64
|
-
this.log.error("plugin scope job failed", meta);
|
|
48
|
+
this.log.error("plugin effect job failed", meta);
|
|
65
49
|
}
|
|
66
50
|
error(err) {
|
|
67
51
|
this.log.error("plugin scope worker error", { err });
|
|
@@ -90,7 +74,7 @@ PluginScopeWorkersModule = __decorate([
|
|
|
90
74
|
Module({
|
|
91
75
|
imports: [CatalogModule],
|
|
92
76
|
providers: [
|
|
93
|
-
configuredProcessor(PluginScopeSyncProcessor,
|
|
77
|
+
configuredProcessor(PluginScopeSyncProcessor, PLUGIN_EFFECT_QUEUE, {
|
|
94
78
|
concurrency: PLUGIN_SCOPE_CONCURRENCY,
|
|
95
79
|
}),
|
|
96
80
|
],
|