@capybara-hq/kernel 0.1.0-rc.36 → 0.1.0-rc.37
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/bootstrap.json +5 -5
- package/dist/admin/admin.module.d.ts +3 -3
- package/dist/admin/admin.module.js +6 -6
- package/dist/admin/audit-log.service.d.ts +51 -0
- package/dist/admin/{platform-audit.service.js → audit-log.service.js} +20 -12
- package/dist/admin/audit.controller.d.ts +18 -6
- package/dist/admin/audit.controller.js +36 -6
- package/dist/admin/audit.schemas.d.ts +9 -1
- package/dist/admin/audit.schemas.js +22 -2
- package/dist/admin/outbox-dead.controller.d.ts +4 -6
- package/dist/admin/outbox-dead.controller.js +9 -6
- package/dist/admin/outbox-dead.schemas.d.ts +16 -0
- package/dist/admin/outbox-dead.schemas.js +25 -1
- package/dist/admin/outbox-dead.service.d.ts +16 -7
- package/dist/admin/outbox-dead.service.js +34 -10
- package/dist/admin/overview.service.d.ts +3 -3
- package/dist/admin/overview.service.js +0 -1
- package/dist/agents/agent-lookup.js +2 -10
- package/dist/agents/agents.service.js +9 -20
- package/dist/agents/definition.d.ts +3 -51
- package/dist/agents/definition.js +4 -254
- package/dist/agents/org-templates.js +2 -6
- package/dist/agents/readiness.controller.d.ts +4 -12
- package/dist/agents/readiness.controller.js +4 -12
- package/dist/agents/readiness.service.d.ts +23 -11
- package/dist/agents/readiness.service.js +31 -14
- package/dist/agents/templates.d.ts +0 -6
- package/dist/agents/templates.js +8 -34
- package/dist/background/store.d.ts +2 -0
- package/dist/background/store.js +3 -1
- package/dist/background/wake-rules.js +2 -1
- package/dist/catalog/admin-catalog.controller.d.ts +1 -2
- package/dist/catalog/admin-catalog.controller.js +1 -2
- package/dist/catalog/appearance.service.js +1 -3
- package/dist/catalog/catalog-content.d.ts +1 -1
- package/dist/catalog/catalog-content.js +1 -4
- package/dist/catalog/catalog-items.js +3 -3
- package/dist/catalog/catalog-scope.service.d.ts +10 -28
- package/dist/catalog/catalog-scope.service.js +22 -73
- package/dist/catalog/cli.d.ts +0 -11
- package/dist/catalog/cli.js +0 -20
- package/dist/catalog/component-scope.service.js +0 -2
- package/dist/catalog/component-state.js +2 -2
- package/dist/catalog/install-status.d.ts +6 -0
- package/dist/catalog/install-status.js +6 -0
- package/dist/catalog/job-ids.d.ts +0 -4
- package/dist/catalog/job-ids.js +0 -4
- package/dist/catalog/marketplaces.service.d.ts +1 -1
- package/dist/catalog/org-catalog.service.d.ts +2 -0
- package/dist/catalog/org-catalog.service.js +8 -3
- package/dist/catalog/org-extension-switch.d.ts +7 -2
- package/dist/catalog/org-extension-switch.js +56 -9
- package/dist/catalog/org-plugin-uploads.d.ts +6 -15
- package/dist/catalog/org-plugin-uploads.js +9 -27
- package/dist/catalog/owned-items.js +1 -3
- package/dist/catalog/platform-import-update.js +1 -1
- package/dist/catalog/plugin-import.d.ts +15 -13
- package/dist/catalog/plugin-import.js +21 -30
- package/dist/catalog/plugin-install.d.ts +3 -43
- package/dist/catalog/plugin-install.js +8 -150
- package/dist/catalog/plugin-package.d.ts +5 -10
- package/dist/catalog/plugin-package.js +12 -33
- package/dist/catalog/plugin-upgrade.js +5 -4
- package/dist/catalog/scope-jobs.d.ts +34 -34
- package/dist/catalog/scope-jobs.js +50 -37
- package/dist/catalog/scope-orgs.d.ts +1 -1
- package/dist/catalog/scope-orgs.js +1 -2
- package/dist/catalog/scope-sync-workers.d.ts +4 -3
- package/dist/catalog/scope-sync-workers.js +18 -6
- package/dist/catalog/scope-sync.d.ts +56 -59
- package/dist/catalog/scope-sync.js +96 -166
- package/dist/catalog/unshare.d.ts +3 -4
- package/dist/catalog/unshare.js +5 -8
- package/dist/channels/job-ids.d.ts +2 -6
- package/dist/channels/job-ids.js +2 -6
- package/dist/channels/outbound.d.ts +1 -1
- package/dist/channels/outbound.js +1 -1
- package/dist/channels/supervisor.d.ts +2 -3
- package/dist/channels/supervisor.js +2 -3
- package/dist/client/client-access.service.js +1 -1
- package/dist/config/env.js +19 -1
- package/dist/config/load.d.ts +0 -6
- package/dist/config/load.js +8 -27
- package/dist/config/schema.d.ts +53 -47
- package/dist/config/schema.js +190 -40
- package/dist/conversations/attachments.service.d.ts +10 -3
- package/dist/conversations/attachments.service.js +49 -16
- package/dist/conversations/conversations.controller.d.ts +0 -39
- package/dist/conversations/conversations.controller.js +0 -39
- package/dist/conversations/events.d.ts +71 -46
- package/dist/conversations/events.js +124 -112
- package/dist/conversations/media-types.d.ts +25 -0
- package/dist/conversations/media-types.js +38 -0
- package/dist/conversations/queue.d.ts +3 -1
- package/dist/conversations/queue.service.js +9 -2
- package/dist/conversations/titles.js +6 -0
- package/dist/ctx/create-ctx.js +1 -2
- package/dist/ctx/secrets.d.ts +24 -7
- package/dist/ctx/secrets.js +97 -30
- package/dist/db/kernel-schema.d.ts +17 -6
- package/dist/errors.d.ts +5 -2
- package/dist/errors.js +5 -2
- package/dist/evals/reconstruct.d.ts +4 -17
- package/dist/evals/reconstruct.js +13 -53
- package/dist/evals/recorded-tools.d.ts +0 -27
- package/dist/evals/recorded-tools.js +2 -92
- package/dist/evals/run-replay.d.ts +1 -6
- package/dist/evals/run-replay.js +10 -17
- package/dist/evals/sets.service.d.ts +17 -5
- package/dist/evals/sets.service.js +33 -12
- package/dist/evals/snapshot.d.ts +1 -2
- package/dist/evals/snapshot.js +4 -17
- package/dist/extensions/admin-ops.d.ts +6 -1
- package/dist/extensions/admin-ops.js +17 -4
- package/dist/extensions/admin-view.d.ts +7 -4
- package/dist/extensions/admin-view.js +27 -21
- package/dist/extensions/bootstrap.js +0 -1
- package/dist/extensions/cli.js +0 -1
- package/dist/extensions/host.d.ts +2 -3
- package/dist/extensions/host.js +1 -5
- package/dist/extensions/installs.d.ts +1 -3
- package/dist/extensions/instance.d.ts +0 -2
- package/dist/extensions/instance.js +0 -3
- package/dist/extensions/org-config.d.ts +4 -4
- package/dist/extensions/org-config.js +13 -22
- package/dist/extensions/package.d.ts +6 -6
- package/dist/extensions/package.js +3 -7
- package/dist/extensions/permission-view.d.ts +2 -4
- package/dist/extensions/plugin-items.d.ts +21 -1
- package/dist/extensions/plugin-items.js +28 -0
- package/dist/extensions/sync.js +5 -10
- package/dist/extensions/unavailable.js +0 -1
- package/dist/http/api.module.js +2 -1
- package/dist/identity/audit.d.ts +0 -12
- package/dist/identity/audit.js +0 -27
- package/dist/identity/auth.controller.js +5 -9
- package/dist/identity/cookies.d.ts +4 -9
- package/dist/identity/cookies.js +8 -32
- package/dist/identity/initial-passwords.d.ts +1 -1
- package/dist/identity/initial-passwords.js +1 -2
- package/dist/identity/sessions.d.ts +0 -6
- package/dist/identity/sessions.js +0 -18
- package/dist/inbox/platform-inbox.service.d.ts +33 -1
- package/dist/inbox/platform-inbox.service.js +56 -6
- package/dist/index.d.ts +4 -2
- package/dist/index.js +4 -2
- package/dist/infra/cli/master-key-rewrap.d.ts +15 -0
- package/dist/infra/cli/master-key-rewrap.js +24 -0
- package/dist/infra/config/kernel-config.service.js +0 -17
- package/dist/infra/health/health.controller.js +8 -0
- package/dist/infra/health/process-fault.d.ts +16 -0
- package/dist/infra/health/process-fault.js +49 -0
- package/dist/infra/lifecycle/process-guards.d.ts +8 -2
- package/dist/infra/lifecycle/process-guards.js +12 -3
- package/dist/infra/lifecycle/shutdown-signals.d.ts +10 -1
- package/dist/infra/lifecycle/shutdown-signals.js +28 -13
- package/dist/infra/outbox/outbox.service.d.ts +12 -9
- package/dist/infra/outbox/outbox.service.js +22 -26
- package/dist/infra/outbox/registry.d.ts +15 -7
- package/dist/infra/outbox/registry.js +39 -23
- package/dist/lifecycle/kernel-lifecycle.js +1 -7
- package/dist/models/enablement.d.ts +5 -6
- package/dist/models/enablement.js +7 -14
- package/dist/orgs/orgs.module.d.ts +2 -2
- package/dist/orgs/orgs.module.js +2 -2
- package/dist/orgs/settings.controller.d.ts +3 -2
- package/dist/orgs/settings.service.d.ts +59 -14
- package/dist/orgs/settings.service.js +102 -20
- package/dist/overrides.d.ts +3 -7
- package/dist/overrides.js +2 -4
- package/dist/packages/tgz.d.ts +0 -2
- package/dist/packages/tgz.js +0 -2
- package/dist/platform/exclusions.js +0 -5
- package/dist/platform/operation.js +1 -1
- package/dist/platform/ops/admin.ops.d.ts +2 -2
- package/dist/platform/ops/admin.ops.js +9 -6
- package/dist/platform/ops/agents.ops.js +1 -1
- package/dist/platform/ops/connectors.ops.js +46 -1
- package/dist/platform/ops/evals.ops.js +1 -64
- package/dist/platform/ops/extensions-admin.ops.js +1 -1
- package/dist/platform/ops/inbox.ops.js +16 -3
- package/dist/platform/ops/org-plugins.ops.js +1 -1
- package/dist/platform/ops/orgs.ops.d.ts +5 -3
- package/dist/platform/ops/orgs.ops.js +19 -4
- package/dist/platform/ops/outbox.ops.js +5 -5
- package/dist/roles/worker-role.d.ts +2 -3
- package/dist/roles/worker-role.js +3 -13
- package/dist/runtime/context/build.d.ts +56 -18
- package/dist/runtime/context/build.js +143 -50
- package/dist/runtime/context/compaction.d.ts +1 -3
- package/dist/runtime/context/compaction.js +42 -8
- package/dist/runtime/context/run-context.js +1 -2
- package/dist/runtime/context/skills.d.ts +27 -56
- package/dist/runtime/context/skills.js +42 -114
- package/dist/runtime/context/tool-changes.d.ts +3 -3
- package/dist/runtime/context/tool-changes.js +6 -16
- package/dist/runtime/hook-calls.d.ts +6 -6
- package/dist/runtime/hook-calls.js +7 -7
- package/dist/runtime/langgraph-loop.js +1 -0
- package/dist/runtime/maintenance.d.ts +3 -11
- package/dist/runtime/maintenance.js +5 -20
- package/dist/runtime/model-call.d.ts +5 -0
- package/dist/runtime/model-call.js +48 -36
- package/dist/runtime/providers.d.ts +33 -35
- package/dist/runtime/providers.js +64 -109
- package/dist/runtime/run-context.service.js +7 -22
- package/dist/runtime/run-deletion.d.ts +6 -0
- package/dist/runtime/run-deletion.js +39 -16
- package/dist/runtime/run-execution.js +4 -3
- package/dist/runtime/run-finish.js +2 -1
- package/dist/runtime/run-liveness.d.ts +11 -0
- package/dist/runtime/run-liveness.js +19 -0
- package/dist/runtime/run-orphan-check.job.js +2 -1
- package/dist/runtime/run-queue.js +8 -16
- package/dist/runtime/run-worker.d.ts +2 -2
- package/dist/runtime/run-worker.js +8 -6
- package/dist/runtime/subagents/definition.d.ts +16 -20
- package/dist/runtime/subagents/definition.js +27 -27
- package/dist/runtime/subagents/dispatch.d.ts +6 -2
- package/dist/runtime/subagents/dispatch.js +17 -3
- package/dist/runtime/subagents/org-agents.js +1 -2
- package/dist/runtime/subagents/preamble.d.ts +3 -2
- package/dist/runtime/subagents/preamble.js +3 -2
- package/dist/runtime/subagents/render.d.ts +1 -2
- package/dist/runtime/subagents/render.js +1 -2
- package/dist/runtime/subagents/skill-fork.d.ts +2 -4
- package/dist/runtime/subagents/template-skills.d.ts +47 -0
- package/dist/runtime/subagents/template-skills.js +76 -0
- package/dist/schedules/effective-settings.d.ts +9 -3
- package/dist/schedules/effective-settings.js +5 -4
- package/dist/schedules/fire.js +11 -0
- package/dist/schedules/scheduled-tasks.service.js +5 -0
- package/dist/schedules/unattended.d.ts +2 -0
- package/dist/schedules/unattended.js +6 -1
- package/dist/skills/agent-skills.service.js +1 -2
- package/dist/skills/catalog.d.ts +1 -3
- package/dist/skills/catalog.js +1 -3
- package/dist/skills/conversation-catalog.d.ts +1 -2
- package/dist/skills/conversation-catalog.js +1 -2
- package/dist/skills/usable.js +2 -3
- package/dist/storage/storage.service.js +9 -1
- package/dist/tools/approvals.service.js +2 -4
- package/dist/tools/builtin-names.d.ts +2 -9
- package/dist/tools/builtin-names.js +4 -13
- package/dist/tools/builtins/sandbox/bash.js +3 -3
- package/dist/tools/builtins/sandbox/common.d.ts +7 -13
- package/dist/tools/builtins/sandbox/common.js +8 -115
- package/dist/tools/builtins/sandbox/fetch-attachment.d.ts +10 -0
- package/dist/tools/builtins/sandbox/fetch-attachment.js +119 -0
- package/dist/tools/builtins/sandbox/glob.js +1 -3
- package/dist/tools/builtins/sandbox/grep.js +3 -5
- package/dist/tools/builtins/sandbox/index.d.ts +8 -5
- package/dist/tools/builtins/sandbox/index.js +10 -5
- package/dist/tools/builtins/sandbox/read.js +3 -2
- package/dist/tools/builtins/tool-search.d.ts +4 -7
- package/dist/tools/builtins/tool-search.js +6 -10
- package/dist/tools/connector-account-policies.d.ts +30 -3
- package/dist/tools/connector-account-policies.js +54 -7
- package/dist/tools/connectors.controller.d.ts +24 -11
- package/dist/tools/connectors.controller.js +35 -6
- package/dist/tools/connectors.schemas.d.ts +14 -1
- package/dist/tools/connectors.schemas.js +14 -2
- package/dist/tools/connectors.service.d.ts +22 -0
- package/dist/tools/connectors.service.js +56 -0
- package/dist/tools/drift.d.ts +1 -1
- package/dist/tools/drift.js +1 -1
- package/dist/tools/git-push-policy.d.ts +4 -1
- package/dist/tools/git-push-policy.js +3 -1
- package/dist/tools/info.d.ts +1 -7
- package/dist/tools/info.js +5 -18
- package/dist/tools/job-ids.d.ts +0 -4
- package/dist/tools/job-ids.js +1 -6
- package/dist/tools/pipeline.d.ts +4 -10
- package/dist/tools/pipeline.js +16 -62
- package/dist/tools/policy.d.ts +6 -2
- package/dist/tools/policy.js +14 -12
- package/dist/tools/registry.js +1 -5
- package/dist/ui/views.d.ts +5 -5
- package/dist/ui/views.js +10 -16
- package/package.json +3 -3
- package/src/migrations/0137_audit_org_idx.sql +5 -0
- package/src/migrations/0138_plugin_install_status_no_upgrading.sql +18 -0
- package/src/migrations/0139_retire_legacy_forms.sql +183 -0
- package/src/migrations/0140_retire_history_forms.sql +148 -0
- package/src/migrations/0141_install_ledger_promoted_rows.sql +36 -0
- package/src/migrations/0142_backfill_event_fields.sql +74 -0
- package/src/migrations/0143_backfill_model_call_fields.sql +105 -0
- package/src/migrations/0144_retire_frozen_definition_keys.sql +163 -0
- package/dist/admin/platform-audit.service.d.ts +0 -41
- package/dist/conversations/job-ids.d.ts +0 -6
- package/dist/conversations/job-ids.js +0 -6
- package/dist/extensions/job-ids.d.ts +0 -6
- package/dist/extensions/job-ids.js +0 -6
- package/dist/infra/queue/retired-schedulers.d.ts +0 -7
- package/dist/infra/queue/retired-schedulers.js +0 -9
- package/dist/orgs/job-ids.d.ts +0 -8
- package/dist/orgs/job-ids.js +0 -8
- package/dist/runtime/context/legacy-text.d.ts +0 -22
- package/dist/runtime/context/legacy-text.js +0 -37
- package/dist/runtime/job-ids.d.ts +0 -10
- package/dist/runtime/job-ids.js +0 -10
- package/dist/runtime/retired-schedulers.d.ts +0 -7
- package/dist/runtime/retired-schedulers.js +0 -31
- package/dist/storage/job-ids.d.ts +0 -6
- package/dist/storage/job-ids.js +0 -6
- package/dist/tools/legacy-data.d.ts +0 -34
- package/dist/tools/legacy-data.js +0 -76
- package/dist/tools/legacy-keys.d.ts +0 -51
- package/dist/tools/legacy-keys.js +0 -114
|
@@ -13,7 +13,6 @@ import { sql } from "kysely";
|
|
|
13
13
|
import { ApiError } from "../errors.js";
|
|
14
14
|
import { ExtensionAdminOps } from "../extensions/admin-ops.js";
|
|
15
15
|
import { ExtensionAdmin } from "../extensions/admin-view.js";
|
|
16
|
-
import { ExtensionLifecycle } from "../extensions/lifecycle.js";
|
|
17
16
|
import { PluginInstallLock } from "../extensions/locks.js";
|
|
18
17
|
import { audit } from "../identity/audit.js";
|
|
19
18
|
import { SuperAdminLock } from "../identity/super-admin.js";
|
|
@@ -29,6 +28,7 @@ import { CatalogService } from "./catalog.service.js";
|
|
|
29
28
|
import { assertOrgsExist, markVersionApplied } from "./catalog-items.js";
|
|
30
29
|
import { nameConflictError } from "./component-scope.service.js";
|
|
31
30
|
import { agentsUsing, COMPONENT_KINDS, componentOffered, componentOn, listedIn, loadComponents, loadScopeState, pluginFactsOf, skillNameClashes, switchOf, themeIdClashes, } from "./component-state.js";
|
|
31
|
+
import { LIVE_INSTALL_STATUSES } from "./install-status.js";
|
|
32
32
|
import { oweOwnedPluginCleanup } from "./job-ids.js";
|
|
33
33
|
import { CatalogItemLock } from "./locks.js";
|
|
34
34
|
import { assertNotAwaiting, assertOwnerListed, assertShareable, assertShareableTarget, itemRemovedError, newlySharedWith, ownerOf, ownersOf, PLATFORM_OWNER, packageOwner, pendingDigest, releaseExtensionClaim, } from "./ownership.js";
|
|
@@ -39,12 +39,9 @@ import { PlatformPluginUpdater } from "./plugin-upgrade.js";
|
|
|
39
39
|
import { cancelPendingRequests } from "./request-rules.js";
|
|
40
40
|
import { wantedOn } from "./scope.js";
|
|
41
41
|
import { addScopeOrg } from "./scope-orgs.js";
|
|
42
|
-
import { PluginScopeSync
|
|
42
|
+
import { PluginScopeSync } from "./scope-sync.js";
|
|
43
43
|
import { narrowComponentOnUnshare, narrowItemOnUnshare } from "./unshare.js";
|
|
44
|
-
/** How long the super admin's confirmation waits for this replica to load the extension. */
|
|
45
|
-
const CONFIRM_RECONCILE_WAIT_MS = 5_000;
|
|
46
44
|
const UUID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
47
|
-
const LIVE = ["installing", "installed", "upgrading"];
|
|
48
45
|
const notFound = () => new ApiError("catalog.item_not_found", "Catalog item not found");
|
|
49
46
|
const notPending = (name) => new ApiError("extension.not_pending", `Plugin ${name} has no upload waiting for confirmation`);
|
|
50
47
|
const pendingStale = (name) => new ApiError("extension.approval_stale", `The pending upload of ${name} changed since it was reviewed; review it again`);
|
|
@@ -92,8 +89,7 @@ export function conflictsError(conflicts) {
|
|
|
92
89
|
* The super admin's plugin scope and deployment-level disable (plugin and component management
|
|
93
90
|
* spec §4.1, §5 rules 2-4 and 8), and the import confirm that owes the scope sync of the item it
|
|
94
91
|
* wrote. A change is previewed, then confirmed with the preview's `scopeHash`, recomputed under the
|
|
95
|
-
* item row lock (a difference -> 409 `plugin.scope_stale`); it
|
|
96
|
-
* `catalog.scope_changed` and owes the item's scope sync in the same transaction, which installs or
|
|
92
|
+
* item row lock (a difference -> 409 `plugin.scope_stale`); it audits `catalog.scope_changed` and owes the item's scope sync in the same transaction, which installs or
|
|
97
93
|
* uninstalls in every org. Disabling keeps the scope, its org list and the org switches, so
|
|
98
94
|
* re-enabling (no hash needed) reinstalls where it was on. Builtin items -> 409 `plugin.builtin`.
|
|
99
95
|
* Stateless, shared by every replica.
|
|
@@ -112,7 +108,6 @@ let CatalogScopeService = class CatalogScopeService {
|
|
|
112
108
|
updater;
|
|
113
109
|
orgLock;
|
|
114
110
|
installLock;
|
|
115
|
-
lifecycle;
|
|
116
111
|
outbox;
|
|
117
112
|
log;
|
|
118
113
|
txHost;
|
|
@@ -125,8 +120,6 @@ let CatalogScopeService = class CatalogScopeService {
|
|
|
125
120
|
orgLock,
|
|
126
121
|
/** The per-name install lock a reject / withdraw releases the name claim under (M1). */
|
|
127
122
|
installLock,
|
|
128
|
-
/** This replica's reconcile once a confirmed extension is enabled (before the scope sync). */
|
|
129
|
-
lifecycle,
|
|
130
123
|
/** Owes the scope syncs and the removed org plugin's cleanup (P3-21, pre-flight F9). */
|
|
131
124
|
outbox, log, txHost) {
|
|
132
125
|
this.kdb = kdb;
|
|
@@ -142,7 +135,6 @@ let CatalogScopeService = class CatalogScopeService {
|
|
|
142
135
|
this.updater = updater;
|
|
143
136
|
this.orgLock = orgLock;
|
|
144
137
|
this.installLock = installLock;
|
|
145
|
-
this.lifecycle = lifecycle;
|
|
146
138
|
this.outbox = outbox;
|
|
147
139
|
this.log = log;
|
|
148
140
|
this.txHost = txHost;
|
|
@@ -152,14 +144,11 @@ let CatalogScopeService = class CatalogScopeService {
|
|
|
152
144
|
}
|
|
153
145
|
/**
|
|
154
146
|
* Confirms a staged import ({@link PluginImport.confirm}: installs and enables the extension,
|
|
155
|
-
* writes the new item's scope)
|
|
156
|
-
*
|
|
147
|
+
* writes the new item's scope). The item's scope sync is owed by the import's commit, or by its
|
|
148
|
+
* extension's deploy when it has one to deploy.
|
|
157
149
|
*/
|
|
158
150
|
async confirmImport(actor, stagingId, input, opts = {}) {
|
|
159
|
-
|
|
160
|
-
if (r.item.scope !== "optional")
|
|
161
|
-
await this.oweSync(r.item.id);
|
|
162
|
-
return r;
|
|
151
|
+
return this.pluginImport.confirm(actor, stagingId, input, opts);
|
|
163
152
|
}
|
|
164
153
|
/**
|
|
165
154
|
* Confirms the permissions of an item's extension (the admin's 待确认): approves the current
|
|
@@ -167,7 +156,8 @@ let CatalogScopeService = class CatalogScopeService {
|
|
|
167
156
|
* review digest; a changed set -> 409 `extension.approval_stale`); an extension that was never
|
|
168
157
|
* deployed (no install record) is installed and enabled first (the package is in the package
|
|
169
158
|
* store from the import). Nothing waiting (a covered snapshot a person approved already, an item
|
|
170
|
-
* without an extension) -> 409 `extension.not_pending`.
|
|
159
|
+
* without an extension) -> 409 `extension.not_pending`. The item's scope sync is owed by the
|
|
160
|
+
* approval of an enabled extension, or by the enable.
|
|
171
161
|
*
|
|
172
162
|
* An org-owned item is confirmed only while an upload of it waits (ruling P3-10, see
|
|
173
163
|
* {@link confirmOrgUpload}); otherwise -> 409 `extension.not_pending`.
|
|
@@ -232,15 +222,9 @@ let CatalogScopeService = class CatalogScopeService {
|
|
|
232
222
|
if (!disabled || !(e instanceof ApiError && e.code === "extension.not_pending"))
|
|
233
223
|
throw e;
|
|
234
224
|
}
|
|
235
|
-
// The permissions are confirmed (a stale hash refused above): the backstop before the enable
|
|
236
|
-
// (ruling R24), so a crash before the post-deploy add below still converges the orgs; only
|
|
237
|
-
// when the item's scope turns it on by itself, as the import's commit
|
|
238
|
-
if (item.scope !== "optional")
|
|
239
|
-
await this.oweBackstop(itemId);
|
|
240
225
|
// An occupied single-provider point leaves it installed disabled (the admin view says why)
|
|
241
226
|
if (disabled)
|
|
242
227
|
await this.ops.enableUnlessOccupied(item.name, actor, opts.actorTokenId);
|
|
243
|
-
await this.oweSync(itemId);
|
|
244
228
|
return (await this.catalog.get(itemId)).item;
|
|
245
229
|
}
|
|
246
230
|
/**
|
|
@@ -253,7 +237,7 @@ let CatalogScopeService = class CatalogScopeService {
|
|
|
253
237
|
* A first version: its platform components planned and their files copied (keyed by content),
|
|
254
238
|
* its extension installed, its permissions approved, enabled, then (one transaction) the item
|
|
255
239
|
* stops waiting, its platform component rows are written and the owner is told
|
|
256
|
-
* (`upload_confirmed`)
|
|
240
|
+
* (`upload_confirmed`) and the scope sync is owed in that commit. Each step re-reads
|
|
257
241
|
* the item under its row lock: removed meanwhile -> 409 `catalog.item_removed`, the pending
|
|
258
242
|
* version replaced -> `extension.approval_stale`; the extension this confirmation installed is
|
|
259
243
|
* then taken out again. A new version: the platform update to it
|
|
@@ -264,19 +248,11 @@ let CatalogScopeService = class CatalogScopeService {
|
|
|
264
248
|
async confirmOrgUpload(actor, item, permissionsHash, opts) {
|
|
265
249
|
// Every step under the item's update lock (ruling P3-35): a second confirmation waits its
|
|
266
250
|
// turn out as 409 plugin.install_in_progress and never undoes the first one's install
|
|
267
|
-
|
|
268
|
-
if (first !== null) {
|
|
269
|
-
// Loaded here before the scope sync plans its install, waited for at most a few seconds
|
|
270
|
-
// (the enable does not wait for the reconcile); a sync on a replica that has not loaded it
|
|
271
|
-
// yet defers and retries (ruling P3-38)
|
|
272
|
-
await reconcileWithin(this.lifecycle, `confirmed:${item.name}`, CONFIRM_RECONCILE_WAIT_MS, this.log);
|
|
273
|
-
await this.oweSync(item.id);
|
|
274
|
-
}
|
|
251
|
+
await this.updater.withItemLock(item.id, () => this.confirmLocked(actor, item.id, item.name, permissionsHash, opts));
|
|
275
252
|
return (await this.catalog.get(item.id)).item;
|
|
276
253
|
}
|
|
277
254
|
/**
|
|
278
|
-
* {@link confirmOrgUpload} under the item lock
|
|
279
|
-
* sync follows after), null for a new version.
|
|
255
|
+
* {@link confirmOrgUpload} under the item lock.
|
|
280
256
|
*/
|
|
281
257
|
async confirmLocked(actor, itemId, name, permissionsHash, opts) {
|
|
282
258
|
// Read again under the lock (the caller's read was outside it)
|
|
@@ -367,7 +343,7 @@ let CatalogScopeService = class CatalogScopeService {
|
|
|
367
343
|
catch (e) {
|
|
368
344
|
throw await this.removalOr(e, itemId, name);
|
|
369
345
|
}
|
|
370
|
-
return
|
|
346
|
+
return;
|
|
371
347
|
}
|
|
372
348
|
await this.stillPending(itemId, name, version);
|
|
373
349
|
let installedHere = false;
|
|
@@ -395,7 +371,6 @@ let CatalogScopeService = class CatalogScopeService {
|
|
|
395
371
|
}
|
|
396
372
|
throw await this.removalOr(e, itemId, name);
|
|
397
373
|
}
|
|
398
|
-
return version;
|
|
399
374
|
}
|
|
400
375
|
/** The item is live and its first version confirmed (no longer awaiting). */
|
|
401
376
|
async confirmed(itemId) {
|
|
@@ -607,9 +582,9 @@ let CatalogScopeService = class CatalogScopeService {
|
|
|
607
582
|
target: itemId,
|
|
608
583
|
detail: { name: named.name, version, ownerOrgId: owner },
|
|
609
584
|
});
|
|
610
|
-
// The
|
|
611
|
-
// the
|
|
612
|
-
await this.sync.
|
|
585
|
+
// The item became usable: its commit owes the scope sync (the extension was enabled before,
|
|
586
|
+
// so a replica that has not loaded it yet retries the chunk job)
|
|
587
|
+
await this.sync.enqueueItem(itemId);
|
|
613
588
|
}
|
|
614
589
|
/**
|
|
615
590
|
* The super admin rejects an org upload's pending version (ruling P3-10, `reason` shown to the
|
|
@@ -801,7 +776,6 @@ let CatalogScopeService = class CatalogScopeService {
|
|
|
801
776
|
.updateTable("catalog_items")
|
|
802
777
|
.set({
|
|
803
778
|
scope: t.scope,
|
|
804
|
-
scope_version: sql `scope_version + 1`,
|
|
805
779
|
updated_at: sql `now()`,
|
|
806
780
|
})
|
|
807
781
|
.where("id", "=", itemId)
|
|
@@ -849,7 +823,6 @@ let CatalogScopeService = class CatalogScopeService {
|
|
|
849
823
|
.updateTable("catalog_items")
|
|
850
824
|
.set({
|
|
851
825
|
disabled,
|
|
852
|
-
scope_version: sql `scope_version + 1`,
|
|
853
826
|
updated_at: sql `now()`,
|
|
854
827
|
})
|
|
855
828
|
.where("id", "=", itemId)
|
|
@@ -918,8 +891,7 @@ let CatalogScopeService = class CatalogScopeService {
|
|
|
918
891
|
/**
|
|
919
892
|
* Adds one org to a `named` item's list in the caller's transaction (an approved `access`
|
|
920
893
|
* request, spec §5.1 rule 2): nobody loses access, so no preview. The item row is locked; it
|
|
921
|
-
* must be live and not builtin (404 / `plugin.builtin`).
|
|
922
|
-
* `catalog.scope_changed` and owes the item's scope sync in that transaction. Returns whether
|
|
894
|
+
* must be live and not builtin (404 / `plugin.builtin`). Audits `catalog.scope_changed` and owes the item's scope sync in that transaction. Returns whether
|
|
923
895
|
* the list changed (false: not `named`, or listed already).
|
|
924
896
|
*/
|
|
925
897
|
async addOrg(actor, itemId, orgId, opts = {}) {
|
|
@@ -941,21 +913,6 @@ let CatalogScopeService = class CatalogScopeService {
|
|
|
941
913
|
async enqueue(itemId) {
|
|
942
914
|
await this.sync.enqueueItem(itemId);
|
|
943
915
|
}
|
|
944
|
-
/**
|
|
945
|
-
* Owes the item's scope sync in a transaction of its own, after a confirmation whose last write
|
|
946
|
-
* (the extension's deploy, or the platform components) committed outside the scope service: the
|
|
947
|
-
* sync must not run before the extension it installs is enabled.
|
|
948
|
-
*/
|
|
949
|
-
async oweSync(itemId) {
|
|
950
|
-
await this.enqueue(itemId);
|
|
951
|
-
}
|
|
952
|
-
/**
|
|
953
|
-
* Owes the delayed backstop of the item's sync in a transaction of its own (ruling R24): a
|
|
954
|
-
* permissions confirm writes nothing of the scope service's before its enable.
|
|
955
|
-
*/
|
|
956
|
-
async oweBackstop(itemId) {
|
|
957
|
-
await this.sync.enqueueBackstop(itemId);
|
|
958
|
-
}
|
|
959
916
|
/**
|
|
960
917
|
* 409 `theme.platform_default` when a live theme of the item is the platform default and `after`
|
|
961
918
|
* says the change leaves it narrower than `all` or gone (themes spec §7). In the caller's
|
|
@@ -1042,7 +999,7 @@ let CatalogScopeService = class CatalogScopeService {
|
|
|
1042
999
|
.selectFrom("plugin_installs")
|
|
1043
1000
|
.select(["id", "org_id"])
|
|
1044
1001
|
.where("item_id", "=", item.id)
|
|
1045
|
-
.where("status", "in", [...
|
|
1002
|
+
.where("status", "in", [...LIVE_INSTALL_STATUSES])
|
|
1046
1003
|
.execute();
|
|
1047
1004
|
const sw = new Map(switches.map((s) => [s.org_id, s.enabled]));
|
|
1048
1005
|
const live = new Map(installs.map((a) => [a.org_id, a.id]));
|
|
@@ -1204,8 +1161,8 @@ let CatalogScopeService = class CatalogScopeService {
|
|
|
1204
1161
|
}
|
|
1205
1162
|
/**
|
|
1206
1163
|
* Sends the components of the item with their own scope back to following it (a plugin scope
|
|
1207
|
-
* change, spec §5 rule 2): `scope_mode = follow`, their own lists dropped,
|
|
1208
|
-
*
|
|
1164
|
+
* change, spec §5 rule 2): `scope_mode = follow`, their own lists dropped, one
|
|
1165
|
+
* `component.scope_changed` audit each. In the caller's transaction.
|
|
1209
1166
|
*/
|
|
1210
1167
|
async followAgain(actor, itemId, replaced, opts) {
|
|
1211
1168
|
for (const r of replaced) {
|
|
@@ -1220,7 +1177,6 @@ let CatalogScopeService = class CatalogScopeService {
|
|
|
1220
1177
|
.updateTable(table)
|
|
1221
1178
|
.set({
|
|
1222
1179
|
scope_mode: "follow",
|
|
1223
|
-
scope_version: sql `scope_version + 1`,
|
|
1224
1180
|
updated_at: sql `now()`,
|
|
1225
1181
|
})
|
|
1226
1182
|
.where("id", "=", r.id)
|
|
@@ -1283,12 +1239,6 @@ __decorate([
|
|
|
1283
1239
|
__decorate([
|
|
1284
1240
|
Transactional({ propagation: "mandatory" })
|
|
1285
1241
|
], CatalogScopeService.prototype, "enqueue", null);
|
|
1286
|
-
__decorate([
|
|
1287
|
-
Transactional()
|
|
1288
|
-
], CatalogScopeService.prototype, "oweSync", null);
|
|
1289
|
-
__decorate([
|
|
1290
|
-
Transactional()
|
|
1291
|
-
], CatalogScopeService.prototype, "oweBackstop", null);
|
|
1292
1242
|
CatalogScopeService = __decorate([
|
|
1293
1243
|
Injectable(),
|
|
1294
1244
|
__param(0, Inject(KernelDb)),
|
|
@@ -1304,9 +1254,8 @@ CatalogScopeService = __decorate([
|
|
|
1304
1254
|
__param(10, Inject(PlatformPluginUpdater)),
|
|
1305
1255
|
__param(11, Inject(OrgLock)),
|
|
1306
1256
|
__param(12, Inject(PluginInstallLock)),
|
|
1307
|
-
__param(13, Inject(
|
|
1308
|
-
__param(14, Inject(
|
|
1309
|
-
__param(15, Inject(
|
|
1310
|
-
__param(16, Inject(TransactionHost))
|
|
1257
|
+
__param(13, Inject(OutboxService)),
|
|
1258
|
+
__param(14, Inject(KERNEL_LOGGER)),
|
|
1259
|
+
__param(15, Inject(TransactionHost))
|
|
1311
1260
|
], CatalogScopeService);
|
|
1312
1261
|
export { CatalogScopeService };
|
package/dist/catalog/cli.d.ts
CHANGED
|
@@ -4,22 +4,11 @@ import { type ExtensionCli } from "../extensions/cli.js";
|
|
|
4
4
|
import type { KernelLogger } from "../log.js";
|
|
5
5
|
import { CatalogService } from "./catalog.service.js";
|
|
6
6
|
import { PluginImport } from "./plugin-import.js";
|
|
7
|
-
import type { PluginScope } from "./scope.js";
|
|
8
7
|
/** {@link openCatalogCli}'s result: the extension CLI context plus the catalog services. */
|
|
9
8
|
export interface CatalogCli extends ExtensionCli {
|
|
10
9
|
catalog: CatalogService;
|
|
11
10
|
/** Plugin import (prepare / confirm). The CLI acts without an account (actor `null`). */
|
|
12
11
|
imports: PluginImport;
|
|
13
|
-
/**
|
|
14
|
-
* After an import's confirm (and its deploy): owes the item's plugin scope sync in the outbox, as
|
|
15
|
-
* the admin console's confirm does, when its scope turns it on by itself (`all` or `named`); a
|
|
16
|
-
* worker's relay delivers it. A failure only warns (the confirm's commit owed a backstop that
|
|
17
|
-
* converges the orgs a few minutes later); returns whether it was owed.
|
|
18
|
-
*/
|
|
19
|
-
enqueueScopeSync(item: {
|
|
20
|
-
id: string;
|
|
21
|
-
scope: PluginScope;
|
|
22
|
-
}): Promise<boolean>;
|
|
23
12
|
}
|
|
24
13
|
/** What the CLI can do with the deployment's object store, and why not when it cannot. */
|
|
25
14
|
export type CliObjectStore = {
|
package/dist/catalog/cli.js
CHANGED
|
@@ -9,15 +9,11 @@ import { openExtensionCli } from "../extensions/cli.js";
|
|
|
9
9
|
import { assertSecretsReachable } from "../extensions/host.js";
|
|
10
10
|
import { importExtensionModule, matchesSection } from "../extensions/instance.js";
|
|
11
11
|
import { packageRootOf, syncPackage } from "../extensions/sync.js";
|
|
12
|
-
import { KernelDb } from "../infra/database/kernel-db.js";
|
|
13
|
-
import { TransactionHost } from "../infra/database/transaction-host.js";
|
|
14
|
-
import { OutboxService } from "../infra/outbox/outbox.service.js";
|
|
15
12
|
import { packagePath } from "../packages/tgz.js";
|
|
16
13
|
import { PrefixedStorage } from "../storage/storage.service.js";
|
|
17
14
|
import { CatalogImportModule } from "./catalog.module.js";
|
|
18
15
|
import { CatalogService } from "./catalog.service.js";
|
|
19
16
|
import { PluginImport } from "./plugin-import.js";
|
|
20
|
-
import { oweScopeItem } from "./scope-jobs.js";
|
|
21
17
|
/**
|
|
22
18
|
* Sets up the deployment's object-store extension inside the CLI process. The CLI hosts no
|
|
23
19
|
* extensions, so this runs only the provider's `setup` with a context that offers `config` and
|
|
@@ -182,26 +178,10 @@ export async function openCatalogCli(config, log, opts = {}) {
|
|
|
182
178
|
// and so do the client files of a package with client code (stored with the package)
|
|
183
179
|
cli.app.get(ClientBuilds).useCliStorage(storage);
|
|
184
180
|
const catalog = cli.app.get(CatalogService);
|
|
185
|
-
const db = cli.app.get(KernelDb);
|
|
186
|
-
const txHost = cli.app.get(TransactionHost);
|
|
187
|
-
const outbox = cli.app.get(OutboxService);
|
|
188
181
|
return {
|
|
189
182
|
...cli,
|
|
190
183
|
catalog,
|
|
191
184
|
imports,
|
|
192
|
-
async enqueueScopeSync(item) {
|
|
193
|
-
if (item.scope === "optional")
|
|
194
|
-
return false;
|
|
195
|
-
try {
|
|
196
|
-
// owed in a transaction of its own after the deploy; a worker's relay delivers it
|
|
197
|
-
await txHost.run(() => oweScopeItem(outbox, db.db, item.id));
|
|
198
|
-
return true;
|
|
199
|
-
}
|
|
200
|
-
catch (err) {
|
|
201
|
-
log.warn("cannot owe the plugin scope sync; the import's backstop converges the orgs in a few minutes", { itemId: item.id, err });
|
|
202
|
-
return false;
|
|
203
|
-
}
|
|
204
|
-
},
|
|
205
185
|
async close() {
|
|
206
186
|
await cli.close();
|
|
207
187
|
await removeSyncDir();
|
|
@@ -672,7 +672,6 @@ let ComponentScopeService = class ComponentScopeService {
|
|
|
672
672
|
.set({
|
|
673
673
|
scope_mode: t.scopeMode,
|
|
674
674
|
scope: t.scope,
|
|
675
|
-
scope_version: sql `scope_version + 1`,
|
|
676
675
|
updated_at: sql `now()`,
|
|
677
676
|
})
|
|
678
677
|
.where("id", "=", id)
|
|
@@ -729,7 +728,6 @@ let ComponentScopeService = class ComponentScopeService {
|
|
|
729
728
|
.updateTable(TABLE[kind])
|
|
730
729
|
.set({
|
|
731
730
|
disabled,
|
|
732
|
-
scope_version: sql `scope_version + 1`,
|
|
733
731
|
updated_at: sql `now()`,
|
|
734
732
|
})
|
|
735
733
|
.where("id", "=", id)
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { LIVE_INSTALL_STATUSES } from "./install-status.js";
|
|
1
2
|
import { visibleTo, wantedOn } from "./scope.js";
|
|
2
3
|
/** The kinds the scope, switch, ownership and preview flows (and the component routes) walk. */
|
|
3
4
|
export const COMPONENT_KINDS = [
|
|
@@ -168,7 +169,6 @@ export async function loadComponents(db, kind, filter = {}) {
|
|
|
168
169
|
originOrgId: r.origin_org_id,
|
|
169
170
|
}));
|
|
170
171
|
}
|
|
171
|
-
const LIVE_INSTALL = ["installing", "installed", "upgrading"];
|
|
172
172
|
const groupBy = (rows, key, value) => {
|
|
173
173
|
const out = new Map();
|
|
174
174
|
for (const r of rows) {
|
|
@@ -214,7 +214,7 @@ export async function loadScopeState(db, kind, comps) {
|
|
|
214
214
|
.selectFrom("plugin_installs")
|
|
215
215
|
.select(["item_id", "org_id"])
|
|
216
216
|
.where("item_id", "in", itemIds)
|
|
217
|
-
.where("status", "in", [...
|
|
217
|
+
.where("status", "in", [...LIVE_INSTALL_STATUSES])
|
|
218
218
|
.execute();
|
|
219
219
|
state.installed = groupBy(installs, (r) => r.item_id, (r) => r.org_id);
|
|
220
220
|
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The `plugin_installs.status` values of a live install: the plugin is on in the org (or about to
|
|
3
|
+
* be). `failed` and `uninstalling` are not live. Every query that asks "is this plugin installed
|
|
4
|
+
* in the org" uses this one set.
|
|
5
|
+
*/
|
|
6
|
+
export declare const LIVE_INSTALL_STATUSES: readonly ["installing", "installed"];
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The `plugin_installs.status` values of a live install: the plugin is on in the org (or about to
|
|
3
|
+
* be). `failed` and `uninstalling` are not live. Every query that asks "is this plugin installed
|
|
4
|
+
* in the org" uses this one set.
|
|
5
|
+
*/
|
|
6
|
+
export const LIVE_INSTALL_STATUSES = ["installing", "installed"];
|
|
@@ -5,15 +5,11 @@ import type { OutboxService } from "../infra/outbox/outbox.service.js";
|
|
|
5
5
|
* `@LockedInterval`, once per tick across replicas): refreshes each enabled marketplace in turn.
|
|
6
6
|
*/
|
|
7
7
|
export declare const MARKETPLACES_REFRESH_JOB = "catalogs-refresh";
|
|
8
|
-
/** The BullMQ repeatable scheduler the refresh had before it became `@LockedInterval` (retired). */
|
|
9
|
-
export declare const MARKETPLACES_REFRESH_SCHEDULER_ID = "catalogs-refresh-every";
|
|
10
8
|
/**
|
|
11
9
|
* Hourly cleanup of plugin import staging (T25, F-AE; a `@LockedCron`): deletes expired (24-hour)
|
|
12
10
|
* staging rows and their object storage prefixes (`PluginImport.cleanupExpired`).
|
|
13
11
|
*/
|
|
14
12
|
export declare const PLUGIN_STAGING_CLEANUP_JOB = "app-staging-cleanup";
|
|
15
|
-
/** The BullMQ repeatable scheduler the cleanup had before it became `@LockedCron` (retired). */
|
|
16
|
-
export declare const PLUGIN_STAGING_CLEANUP_SCHEDULER_ID = "app-staging-cleanup-hourly";
|
|
17
13
|
/**
|
|
18
14
|
* The one-off job that takes out the extension of a removed org-owned plugin (spec §14, P3-20,
|
|
19
15
|
* P3-21; `OwnedPluginCleanup.run`), on `cap-kernel-maintenance`.
|
package/dist/catalog/job-ids.js
CHANGED
|
@@ -4,15 +4,11 @@
|
|
|
4
4
|
* `@LockedInterval`, once per tick across replicas): refreshes each enabled marketplace in turn.
|
|
5
5
|
*/
|
|
6
6
|
export const MARKETPLACES_REFRESH_JOB = "catalogs-refresh";
|
|
7
|
-
/** The BullMQ repeatable scheduler the refresh had before it became `@LockedInterval` (retired). */
|
|
8
|
-
export const MARKETPLACES_REFRESH_SCHEDULER_ID = "catalogs-refresh-every";
|
|
9
7
|
/**
|
|
10
8
|
* Hourly cleanup of plugin import staging (T25, F-AE; a `@LockedCron`): deletes expired (24-hour)
|
|
11
9
|
* staging rows and their object storage prefixes (`PluginImport.cleanupExpired`).
|
|
12
10
|
*/
|
|
13
11
|
export const PLUGIN_STAGING_CLEANUP_JOB = "app-staging-cleanup";
|
|
14
|
-
/** The BullMQ repeatable scheduler the cleanup had before it became `@LockedCron` (retired). */
|
|
15
|
-
export const PLUGIN_STAGING_CLEANUP_SCHEDULER_ID = "app-staging-cleanup-hourly";
|
|
16
12
|
/**
|
|
17
13
|
* The one-off job that takes out the extension of a removed org-owned plugin (spec §14, P3-20,
|
|
18
14
|
* P3-21; `OwnedPluginCleanup.run`), on `cap-kernel-maintenance`.
|
|
@@ -188,7 +188,7 @@ export declare function headsToResolve(entries: readonly MarketplaceEntry[], imp
|
|
|
188
188
|
/** The host versions (an entry's `minKernel` is judged against them). */
|
|
189
189
|
export declare const HOST_VERSIONS: {
|
|
190
190
|
readonly kernel: string;
|
|
191
|
-
readonly sdk: "0.1.0-rc.
|
|
191
|
+
readonly sdk: "0.1.0-rc.27";
|
|
192
192
|
};
|
|
193
193
|
/** Whether this deployment satisfies the entry's `minKernel`. */
|
|
194
194
|
export declare const entryCompatible: (e: Pick<MarketplaceEntry, "minKernel">) => boolean;
|
|
@@ -81,6 +81,8 @@ export declare class OrgCatalogService {
|
|
|
81
81
|
install(orgId: string, actor: string, itemId: string, body: OrgInstallInput, actorTokenId?: string, auditDetail?: Record<string, unknown>): Promise<OrgInstallResult>;
|
|
82
82
|
/** The item when the org may see it (scope), else `catalog.item_not_found`. */
|
|
83
83
|
private visibleItem;
|
|
84
|
+
/** Whether the org has a live install of the item (switching it on then installs nothing). */
|
|
85
|
+
hasLiveInstall(orgId: string, itemId: string): Promise<boolean>;
|
|
84
86
|
/** The org's live plugin install of the item, if any. */
|
|
85
87
|
private liveInstall;
|
|
86
88
|
/**
|
|
@@ -23,6 +23,7 @@ import { StorageService } from "../storage/storage.service.js";
|
|
|
23
23
|
import { catalogHasIcon, findConnectorIn, orgTemplateView, readCatalogIcon, readCatalogTemplates, templatePluginProblem, } from "./catalog-content.js";
|
|
24
24
|
import { itemView, ownerOnlyFacts, versionUsable } from "./catalog-items.js";
|
|
25
25
|
import { connectorTemplatesOn, templateIdOfPath } from "./component-state.js";
|
|
26
|
+
import { LIVE_INSTALL_STATUSES } from "./install-status.js";
|
|
26
27
|
import { itemPendingError, ownerOf, ownersOf } from "./ownership.js";
|
|
27
28
|
import { PluginInstaller, uninstallPreviewHash, upsertOrgSwitch, } from "./plugin-install.js";
|
|
28
29
|
import { requestable, switchable, visibleTo, wantedOn } from "./scope.js";
|
|
@@ -135,7 +136,7 @@ let OrgCatalogService = class OrgCatalogService {
|
|
|
135
136
|
.selectFrom("plugin_installs")
|
|
136
137
|
.select(["id", "item_id", "version"])
|
|
137
138
|
.where("org_id", "=", orgId)
|
|
138
|
-
.where("status", "in", [
|
|
139
|
+
.where("status", "in", [...LIVE_INSTALL_STATUSES])
|
|
139
140
|
.execute(),
|
|
140
141
|
this.db
|
|
141
142
|
.selectFrom("extension_org_configs")
|
|
@@ -450,6 +451,10 @@ let OrgCatalogService = class OrgCatalogService {
|
|
|
450
451
|
}
|
|
451
452
|
return item;
|
|
452
453
|
}
|
|
454
|
+
/** Whether the org has a live install of the item (switching it on then installs nothing). */
|
|
455
|
+
async hasLiveInstall(orgId, itemId) {
|
|
456
|
+
return (await this.liveInstall(orgId, itemId)) !== undefined;
|
|
457
|
+
}
|
|
453
458
|
/** The org's live plugin install of the item, if any. */
|
|
454
459
|
liveInstall(orgId, itemId) {
|
|
455
460
|
return this.db
|
|
@@ -457,7 +462,7 @@ let OrgCatalogService = class OrgCatalogService {
|
|
|
457
462
|
.select("id")
|
|
458
463
|
.where("org_id", "=", orgId)
|
|
459
464
|
.where("item_id", "=", itemId)
|
|
460
|
-
.where("status", "in", [
|
|
465
|
+
.where("status", "in", [...LIVE_INSTALL_STATUSES])
|
|
461
466
|
.executeTakeFirst();
|
|
462
467
|
}
|
|
463
468
|
/**
|
|
@@ -526,7 +531,7 @@ let OrgCatalogService = class OrgCatalogService {
|
|
|
526
531
|
.where("a.org_id", "=", orgId)
|
|
527
532
|
.executeTakeFirst();
|
|
528
533
|
// A failed or stuck install is cleaned up whatever the scope (it is not on anyway)
|
|
529
|
-
const live = row?.status === "installed"
|
|
534
|
+
const live = row?.status === "installed";
|
|
530
535
|
if (row !== undefined && live && !switchable(row)) {
|
|
531
536
|
throw new ApiError("plugin.scope_locked", "This plugin is built in: it is on for every organization and cannot be uninstalled here");
|
|
532
537
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { OrgExtensionConfigs, type OrgExtensionInput, type OrgExtensionView } from "../extensions/org-config.js";
|
|
2
|
+
import { TransactionHost } from "../infra/database/transaction-host.js";
|
|
2
3
|
import { OrgCatalogService } from "./org-catalog.service.js";
|
|
3
4
|
import type { UninstallPreview } from "./plugin-install.js";
|
|
4
5
|
/** The result of {@link OrgExtensionSwitch.put}: the extension, or the plugin uninstall preview. */
|
|
@@ -21,12 +22,14 @@ export type OrgExtensionPutResult = {
|
|
|
21
22
|
* the effective config (the stored one with its secrets, or the given `config` merged with them),
|
|
22
23
|
* and the install receives the given `config` as its `extensionConfig`, so the extension is enabled
|
|
23
24
|
* with it. A config write that fails for another reason after the switch succeeded returns that
|
|
24
|
-
* error
|
|
25
|
+
* error in the same transaction as the switch, so the switch stays as it was (a fresh install is the
|
|
26
|
+
* exception: it commits on its own and carries the config itself).
|
|
25
27
|
*/
|
|
26
28
|
export declare class OrgExtensionSwitch {
|
|
29
|
+
readonly txHost: TransactionHost;
|
|
27
30
|
private readonly configs;
|
|
28
31
|
private readonly catalog;
|
|
29
|
-
constructor(configs: OrgExtensionConfigs, catalog: OrgCatalogService);
|
|
32
|
+
constructor(txHost: TransactionHost, configs: OrgExtensionConfigs, catalog: OrgCatalogService);
|
|
30
33
|
/**
|
|
31
34
|
* - `enabled` on an extension of one catalog plugin: that plugin's switch; off without `confirm`
|
|
32
35
|
* returns the preview and its hash, with the hash uninstalls; a builtin plugin (any of several
|
|
@@ -38,4 +41,6 @@ export declare class OrgExtensionSwitch {
|
|
|
38
41
|
put(orgId: string, actor: string, extension: string, body: OrgExtensionInput & {
|
|
39
42
|
confirm?: string | undefined;
|
|
40
43
|
}, actorTokenId?: string): Promise<OrgExtensionPutResult>;
|
|
44
|
+
private applyAtomic;
|
|
45
|
+
private apply;
|
|
41
46
|
}
|
|
@@ -10,6 +10,8 @@ var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
|
10
10
|
import { Inject, Injectable } from "@nestjs/common";
|
|
11
11
|
import { ApiError } from "../errors.js";
|
|
12
12
|
import { OrgExtensionConfigs, } from "../extensions/org-config.js";
|
|
13
|
+
import { TransactionHost } from "../infra/database/transaction-host.js";
|
|
14
|
+
import { Transactional } from "../infra/database/transactional.decorator.js";
|
|
13
15
|
import { OrgCatalogService } from "./org-catalog.service.js";
|
|
14
16
|
/**
|
|
15
17
|
* `PUT orgs/:orgId/extensions/:extension`: for an extension that ships in a catalog plugin, `enabled`
|
|
@@ -22,12 +24,15 @@ import { OrgCatalogService } from "./org-catalog.service.js";
|
|
|
22
24
|
* the effective config (the stored one with its secrets, or the given `config` merged with them),
|
|
23
25
|
* and the install receives the given `config` as its `extensionConfig`, so the extension is enabled
|
|
24
26
|
* with it. A config write that fails for another reason after the switch succeeded returns that
|
|
25
|
-
* error
|
|
27
|
+
* error in the same transaction as the switch, so the switch stays as it was (a fresh install is the
|
|
28
|
+
* exception: it commits on its own and carries the config itself).
|
|
26
29
|
*/
|
|
27
30
|
let OrgExtensionSwitch = class OrgExtensionSwitch {
|
|
31
|
+
txHost;
|
|
28
32
|
configs;
|
|
29
33
|
catalog;
|
|
30
|
-
constructor(configs, catalog) {
|
|
34
|
+
constructor(txHost, configs, catalog) {
|
|
35
|
+
this.txHost = txHost;
|
|
31
36
|
this.configs = configs;
|
|
32
37
|
this.catalog = catalog;
|
|
33
38
|
}
|
|
@@ -60,8 +65,48 @@ let OrgExtensionSwitch = class OrgExtensionSwitch {
|
|
|
60
65
|
if (enabled || input.config !== undefined) {
|
|
61
66
|
await this.configs.put(orgId, extension, { ...config, ...(enabled && { enabled: true }) }, actor, actorTokenId, { validateOnly: true });
|
|
62
67
|
}
|
|
68
|
+
// A fresh install is a multi-step saga that commits on its own and already enables the
|
|
69
|
+
// extension with the given config (`extensionConfig`): no transaction spans it, and no second
|
|
70
|
+
// config write follows. Everything else (the switch row, an uninstall, the config write) is one
|
|
71
|
+
// transaction: a failing config write leaves the switch as it was.
|
|
72
|
+
const installing = enabled === true && !(await this.catalog.hasLiveInstall(orgId, plan.itemId));
|
|
73
|
+
const args = {
|
|
74
|
+
orgId,
|
|
75
|
+
actor,
|
|
76
|
+
extension,
|
|
77
|
+
itemId: plan.itemId,
|
|
78
|
+
enabled,
|
|
79
|
+
input,
|
|
80
|
+
confirm,
|
|
81
|
+
actorTokenId,
|
|
82
|
+
};
|
|
83
|
+
const r = await (installing ? this.apply(args, true) : this.applyAtomic(args));
|
|
84
|
+
if (r !== "readBack")
|
|
85
|
+
return r;
|
|
86
|
+
// Read after the commit: the list reads its own snapshot, which sees only committed rows
|
|
87
|
+
const view = (await this.configs.list(orgId)).find((v) => v.plugin === extension);
|
|
88
|
+
if (view)
|
|
89
|
+
return { kind: "done", view };
|
|
90
|
+
return {
|
|
91
|
+
kind: "done",
|
|
92
|
+
view: await this.configs.put(orgId, extension, { enabled: true }, actor, actorTokenId, {
|
|
93
|
+
ifDisabled: { skipped: false },
|
|
94
|
+
}),
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
applyAtomic(a) {
|
|
98
|
+
return this.apply(a, false);
|
|
99
|
+
}
|
|
100
|
+
async apply(a, installing) {
|
|
101
|
+
const { orgId, actor, extension, itemId, enabled, input, confirm, actorTokenId } = a;
|
|
102
|
+
// Switching on inside the transaction relies on the live install seen before it: one removed
|
|
103
|
+
// meanwhile would run the install saga here, which commits on its own. Refuse instead; the
|
|
104
|
+
// retry takes the install path.
|
|
105
|
+
if (!installing && enabled === true && !(await this.catalog.hasLiveInstall(orgId, itemId))) {
|
|
106
|
+
throw new ApiError("conflict", "The plugin's install in this organization changed while it was being switched on; try again");
|
|
107
|
+
}
|
|
63
108
|
const r = await this.catalog
|
|
64
|
-
.setSwitch(orgId, actor,
|
|
109
|
+
.setSwitch(orgId, actor, itemId, enabled
|
|
65
110
|
? {
|
|
66
111
|
enabled: true,
|
|
67
112
|
...(input.config !== undefined && { inputs: { extensionConfig: input.config } }),
|
|
@@ -74,9 +119,7 @@ let OrgExtensionSwitch = class OrgExtensionSwitch {
|
|
|
74
119
|
return r;
|
|
75
120
|
if (input.config === undefined) {
|
|
76
121
|
if (!enabled) {
|
|
77
|
-
|
|
78
|
-
if (view)
|
|
79
|
-
return { kind: "done", view };
|
|
122
|
+
return "readBack";
|
|
80
123
|
}
|
|
81
124
|
// Switching on: the install enabled it already (no second write)
|
|
82
125
|
return {
|
|
@@ -88,14 +131,18 @@ let OrgExtensionSwitch = class OrgExtensionSwitch {
|
|
|
88
131
|
}
|
|
89
132
|
return {
|
|
90
133
|
kind: "done",
|
|
91
|
-
view: await this.configs.put(orgId, extension, { config: input.config, ...(enabled && { enabled: true }) }, actor, actorTokenId),
|
|
134
|
+
view: await this.configs.put(orgId, extension, { config: input.config, ...(enabled && { enabled: true }) }, actor, actorTokenId, installing ? { ifDisabled: { skipped: false } } : undefined),
|
|
92
135
|
};
|
|
93
136
|
}
|
|
94
137
|
};
|
|
138
|
+
__decorate([
|
|
139
|
+
Transactional()
|
|
140
|
+
], OrgExtensionSwitch.prototype, "applyAtomic", null);
|
|
95
141
|
OrgExtensionSwitch = __decorate([
|
|
96
142
|
Injectable(),
|
|
97
|
-
__param(0, Inject(
|
|
98
|
-
__param(1, Inject(
|
|
143
|
+
__param(0, Inject(TransactionHost)),
|
|
144
|
+
__param(1, Inject(OrgExtensionConfigs)),
|
|
145
|
+
__param(2, Inject(OrgCatalogService))
|
|
99
146
|
], OrgExtensionSwitch);
|
|
100
147
|
export { OrgExtensionSwitch };
|
|
101
148
|
/**
|