@capybara-hq/kernel 0.1.0-rc.125 → 0.1.0-rc.127
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 +3 -3
- package/dist/catalog/catalog.module.js +0 -3
- package/dist/catalog/org-catalog.service.d.ts +0 -2
- package/dist/catalog/org-catalog.service.js +0 -4
- package/dist/catalog/org-extension.controller.d.ts +5 -9
- package/dist/catalog/org-extension.controller.js +22 -22
- package/dist/catalog/org-extension.schemas.d.ts +0 -1
- package/dist/catalog/org-extension.schemas.js +0 -2
- package/dist/catalog/plugin-install.d.ts +4 -1
- package/dist/catalog/plugin-install.js +4 -1
- package/dist/conversations/events.d.ts +10 -154
- package/dist/conversations/events.js +8 -83
- package/dist/db/kernel-schema.d.ts +7 -107
- package/dist/devices/conversation-devices.d.ts +1 -2
- package/dist/devices/devices.service.d.ts +8 -1
- package/dist/devices/devices.service.js +1 -1
- package/dist/errors.d.ts +5 -0
- package/dist/errors.js +5 -0
- package/dist/evals/recorded-permission-context.js +1 -3
- package/dist/evals/recorded-tools.d.ts +3 -4
- package/dist/evals/recorded-tools.js +6 -7
- package/dist/extensions/org-config.d.ts +35 -8
- package/dist/extensions/org-config.js +61 -14
- package/dist/extensions/plugin-items.d.ts +16 -0
- package/dist/extensions/plugin-items.js +35 -0
- package/dist/platform/operation.d.ts +0 -2
- package/dist/platform/ops/extensions.ops.d.ts +4 -6
- package/dist/platform/ops/extensions.ops.js +17 -34
- package/dist/runtime/context/build.d.ts +1 -1
- package/dist/runtime/context/build.js +1 -10
- package/dist/runtime/context/device-paths.d.ts +5 -82
- package/dist/runtime/context/device-paths.js +3 -174
- package/dist/runtime/context/permission-profile.d.ts +3 -13
- package/dist/runtime/context/permission-profile.js +9 -26
- package/dist/runtime/permission-context.service.js +3 -4
- package/dist/runtime/run-worker.js +6 -5
- package/package.json +1 -1
- package/src/migrations/0210_normalize_conversation_history.sql +1012 -0
- package/src/migrations/0211_pre_release_cleanup.sql +154 -0
- package/dist/catalog/org-extension-switch.d.ts +0 -41
- package/dist/catalog/org-extension-switch.js +0 -123
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
-- Contract the storage left behind by the pre-release reader and writer removals.
|
|
2
|
+
-- 0208 already converted permission settings and 0210 verified any history export receipt.
|
|
3
|
+
|
|
4
|
+
-- These are the two tables whose metadata is about to be contracted.
|
|
5
|
+
LOCK TABLE attachments, file_shares IN ACCESS EXCLUSIVE MODE;
|
|
6
|
+
|
|
7
|
+
-- capybara:allow-destructive Block the contract if the earlier copy did not carry forward still-live file or share metadata.
|
|
8
|
+
DO $$
|
|
9
|
+
BEGIN
|
|
10
|
+
IF EXISTS (
|
|
11
|
+
SELECT FROM attachments a
|
|
12
|
+
WHERE a.purpose = 'chat' AND a.status IN ('ready', 'pending')
|
|
13
|
+
AND (a.expires_at IS NULL OR a.expires_at > now() OR a.conversation_id IS NOT NULL)
|
|
14
|
+
AND NOT EXISTS (
|
|
15
|
+
SELECT FROM files f
|
|
16
|
+
WHERE f.id = a.id AND f.org_id = a.org_id AND f.account_id = a.account_id
|
|
17
|
+
AND (f.status = 'deleted' OR (a.status = 'pending' AND f.staging_key = a.object_key)
|
|
18
|
+
OR (f.blob_id IS NOT NULL AND (a.conversation_id IS NULL OR EXISTS (
|
|
19
|
+
SELECT FROM conversation_files cf
|
|
20
|
+
WHERE cf.conversation_id = a.conversation_id AND cf.file_id = f.id
|
|
21
|
+
AND cf.org_id = a.org_id
|
|
22
|
+
))))
|
|
23
|
+
)
|
|
24
|
+
) THEN
|
|
25
|
+
RAISE EXCEPTION '0211 has live chat attachments without migrated library metadata. Follow the pre-release cleanup release notes.';
|
|
26
|
+
END IF;
|
|
27
|
+
|
|
28
|
+
IF EXISTS (
|
|
29
|
+
SELECT FROM file_shares
|
|
30
|
+
WHERE object_key IS NOT NULL AND blob_id IS NULL AND revoked_at IS NULL
|
|
31
|
+
AND (expires_at IS NULL OR expires_at > now())
|
|
32
|
+
) THEN
|
|
33
|
+
RAISE EXCEPTION '0211 has live shares without a migrated blob. Follow the pre-release cleanup release notes.';
|
|
34
|
+
END IF;
|
|
35
|
+
END
|
|
36
|
+
$$;
|
|
37
|
+
|
|
38
|
+
-- capybara:allow-destructive Only the retired SID launcher wrote these tasks. Managed reservations keep their exact execution state.
|
|
39
|
+
DELETE FROM background_tasks WHERE launch_state = 'legacy';
|
|
40
|
+
|
|
41
|
+
-- capybara:allow-destructive Remove SID-only fields and checks whose writers were removed before the contract.
|
|
42
|
+
ALTER TABLE background_tasks
|
|
43
|
+
DROP COLUMN IF EXISTS sid,
|
|
44
|
+
DROP COLUMN IF EXISTS kill_pending,
|
|
45
|
+
DROP COLUMN IF EXISTS legacy_dispatch,
|
|
46
|
+
DROP COLUMN IF EXISTS legacy_dispatch_provider,
|
|
47
|
+
DROP COLUMN IF EXISTS legacy_dispatch_generation,
|
|
48
|
+
ALTER COLUMN launch_state DROP DEFAULT,
|
|
49
|
+
DROP CONSTRAINT IF EXISTS background_tasks_launch_state_check,
|
|
50
|
+
DROP CONSTRAINT IF EXISTS background_tasks_managed_reservation_check,
|
|
51
|
+
DROP CONSTRAINT IF EXISTS background_tasks_managed_dispatch_check;
|
|
52
|
+
|
|
53
|
+
ALTER TABLE background_tasks
|
|
54
|
+
ADD CONSTRAINT background_tasks_launch_state_check
|
|
55
|
+
CHECK (launch_state IN ('pending', 'dispatched', 'acknowledged', 'cancel-pending', 'terminal')),
|
|
56
|
+
ADD CONSTRAINT background_tasks_managed_reservation_check
|
|
57
|
+
CHECK (operation_id IS NOT NULL AND working_root IS NOT NULL AND retain_until IS NOT NULL
|
|
58
|
+
AND left(output_path, 1) = '/'),
|
|
59
|
+
ADD CONSTRAINT background_tasks_managed_dispatch_check
|
|
60
|
+
CHECK (launch_state IN ('pending', 'terminal')
|
|
61
|
+
OR (input_digest IS NOT NULL AND run_execution_id IS NOT NULL AND task_tag IS NOT NULL
|
|
62
|
+
AND instance_id IS NOT NULL AND instance_provider IS NOT NULL
|
|
63
|
+
AND instance_provider_version IS NOT NULL AND instance_generation IS NOT NULL
|
|
64
|
+
AND profile_revision IS NOT NULL AND ceiling_revision IS NOT NULL));
|
|
65
|
+
|
|
66
|
+
-- capybara:allow-destructive Replace the managed-call partial index with the same uniqueness over all remaining tasks.
|
|
67
|
+
DROP INDEX IF EXISTS background_tasks_managed_call_idx;
|
|
68
|
+
CREATE UNIQUE INDEX IF NOT EXISTS background_tasks_managed_call_idx ON background_tasks (run_id, call_id);
|
|
69
|
+
|
|
70
|
+
-- capybara:allow-destructive 0208 carried forward the inherited network restrictions. The report-driven runtime has no snapshot readers.
|
|
71
|
+
ALTER TABLE devices
|
|
72
|
+
DROP COLUMN IF EXISTS owner_full_access,
|
|
73
|
+
DROP COLUMN IF EXISTS outer_network,
|
|
74
|
+
DROP COLUMN IF EXISTS permission_migration,
|
|
75
|
+
DROP COLUMN IF EXISTS permission_reconcile_required;
|
|
76
|
+
|
|
77
|
+
-- capybara:allow-destructive Obsolete per-conversation sandbox records. The device instances and their storage remain.
|
|
78
|
+
DROP TABLE IF EXISTS sandboxes;
|
|
79
|
+
-- capybara:allow-destructive The legacy launch freeze has no writers or readers after retirement removal.
|
|
80
|
+
DROP TABLE IF EXISTS legacy_launch_freeze;
|
|
81
|
+
-- capybara:allow-destructive Retire obsolete proof membership and its trigger before dropping the referenced obligations.
|
|
82
|
+
DROP TABLE IF EXISTS device_retirement_members;
|
|
83
|
+
-- capybara:allow-destructive The proof trigger belonged only to the removed retirement members.
|
|
84
|
+
DROP FUNCTION IF EXISTS reopen_local_retirement_proof();
|
|
85
|
+
-- capybara:allow-destructive The old retirement ledger no longer owns cleanup. Keep device_instance_destructions for live reconciliation.
|
|
86
|
+
DROP TABLE IF EXISTS device_retirement_obligations;
|
|
87
|
+
-- capybara:allow-destructive Remove exact identities used only by the retired local proof flow.
|
|
88
|
+
DROP TABLE IF EXISTS device_instance_retirement_identities;
|
|
89
|
+
-- capybara:allow-destructive This generation scan index served the removed retirement enumerator only.
|
|
90
|
+
DROP INDEX IF EXISTS sandbox_operation_intents_owed_background_revoke_idx;
|
|
91
|
+
|
|
92
|
+
-- capybara:allow-destructive Only the retired permission tier syntax used this prefix.
|
|
93
|
+
DELETE FROM automation_grants WHERE tool_key LIKE 'tier:%';
|
|
94
|
+
|
|
95
|
+
-- capybara:allow-destructive Effective extension config now uses scoped secret storage instead of the retired plugin-config credentials.
|
|
96
|
+
DELETE FROM secrets
|
|
97
|
+
WHERE namespace = 'kernel' AND org_id <> '_deployment' AND key LIKE 'plugin-config:%';
|
|
98
|
+
|
|
99
|
+
-- capybara:allow-destructive Delete obsolete markers and retired permission keys whose current restrictions were migrated by 0208.
|
|
100
|
+
DELETE FROM deployment_settings WHERE key IN (
|
|
101
|
+
'fileLibraryCopySettled', 'templateConnectorsReconciled', 'devicesAutoMode', 'devicesFullAccess'
|
|
102
|
+
);
|
|
103
|
+
|
|
104
|
+
-- capybara:allow-destructive Remove retired permission keys already converted by 0208, leaving current and unrelated settings untouched.
|
|
105
|
+
UPDATE orgs SET settings = settings - ARRAY['autoMode', 'fullAccess', 'cloudNetwork']
|
|
106
|
+
WHERE jsonb_typeof(settings) = 'object' AND settings ?| ARRAY['autoMode', 'fullAccess', 'cloudNetwork'];
|
|
107
|
+
|
|
108
|
+
-- capybara:allow-destructive These jobs belonged to the removed backfill and share-object paths.
|
|
109
|
+
DELETE FROM outbox
|
|
110
|
+
WHERE queue = 'cap-kernel-maintenance' AND job_name IN ('file-library-backfill', 'share-object-delete');
|
|
111
|
+
|
|
112
|
+
CREATE TEMP TABLE IF NOT EXISTS retired_trigger_dispatches ON COMMIT DROP AS
|
|
113
|
+
SELECT id, data ->> 'eventId' AS event_id
|
|
114
|
+
FROM outbox
|
|
115
|
+
WHERE queue = 'cap-kernel-maintenance' AND job_name = 'trigger-dispatch'
|
|
116
|
+
AND job_id ~ '^trigger-dispatch-[0-9a-f-]{36}-sweep-[0-9]+$'
|
|
117
|
+
AND starts_with(job_id, 'trigger-dispatch-' || (data ->> 'eventId') || '-sweep-');
|
|
118
|
+
|
|
119
|
+
-- A sweep dispatch could be the only job owed for a still-pending event. Transfer it to the
|
|
120
|
+
-- current dispatcher with a deterministic fresh id, distinct from any old BullMQ job.
|
|
121
|
+
INSERT INTO outbox (queue, job_name, job_id, data, org_id)
|
|
122
|
+
SELECT 'cap-kernel-maintenance', 'trigger-dispatch', 'trigger-dispatch-' || e.id || '-0211',
|
|
123
|
+
jsonb_build_object('eventId', e.id, 'orgId', e.org_id), e.org_id
|
|
124
|
+
FROM trigger_events e
|
|
125
|
+
WHERE e.state = 'pending' AND e.audience IS NOT NULL
|
|
126
|
+
AND EXISTS (SELECT FROM retired_trigger_dispatches d WHERE d.event_id = e.id)
|
|
127
|
+
AND NOT EXISTS (
|
|
128
|
+
SELECT FROM outbox current_dispatch
|
|
129
|
+
WHERE current_dispatch.queue = 'cap-kernel-maintenance'
|
|
130
|
+
AND current_dispatch.job_name = 'trigger-dispatch' AND current_dispatch.dead_at IS NULL
|
|
131
|
+
AND current_dispatch.job_id = 'trigger-dispatch-' || e.id
|
|
132
|
+
)
|
|
133
|
+
ON CONFLICT (queue, job_id) WHERE dead_at IS NULL DO NOTHING;
|
|
134
|
+
|
|
135
|
+
-- capybara:allow-destructive Remove only the retired directed-trigger recovery jobs after preserving pending delivery.
|
|
136
|
+
DELETE FROM outbox WHERE id IN (SELECT id FROM retired_trigger_dispatches);
|
|
137
|
+
|
|
138
|
+
-- capybara:allow-destructive The earlier copy migrated chat attachment metadata to the file library. Leave blob and storage objects alone.
|
|
139
|
+
DELETE FROM attachments WHERE purpose = 'chat';
|
|
140
|
+
|
|
141
|
+
-- capybara:allow-destructive Replace the attachment default and check with the current explicit purposes.
|
|
142
|
+
ALTER TABLE attachments ALTER COLUMN purpose DROP DEFAULT,
|
|
143
|
+
DROP CONSTRAINT IF EXISTS attachments_purpose_check;
|
|
144
|
+
ALTER TABLE attachments ADD CONSTRAINT attachments_purpose_check
|
|
145
|
+
CHECK (purpose IN ('skill-package', 'agent-avatar', 'read'));
|
|
146
|
+
|
|
147
|
+
-- capybara:allow-destructive The one-off file library copy has run and its runtime callers are gone.
|
|
148
|
+
DROP FUNCTION IF EXISTS file_library_copy(timestamptz);
|
|
149
|
+
-- capybara:allow-destructive Shares resolve their snapshot through blob_id after the file library cutover.
|
|
150
|
+
ALTER TABLE file_shares DROP COLUMN IF EXISTS object_key;
|
|
151
|
+
-- capybara:allow-destructive The removed org config reader has been replaced by the current storage paths.
|
|
152
|
+
ALTER TABLE extension_org_configs DROP COLUMN IF EXISTS config;
|
|
153
|
+
-- capybara:allow-destructive 0210 has consumed the one-time export receipt. The verified manifests and transcripts stay outside PostgreSQL.
|
|
154
|
+
DROP TABLE IF EXISTS capybara._history_export_0210;
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import { OrgExtensionConfigs, type OrgExtensionInput, type OrgExtensionView } from "../extensions/org-config.js";
|
|
2
|
-
import { TransactionHost } from "../infra/database/transaction-host.js";
|
|
3
|
-
import { OrgCatalogService } from "./org-catalog.service.js";
|
|
4
|
-
import type { UninstallPreview } from "./plugin-install.js";
|
|
5
|
-
/** The result of {@link OrgExtensionSwitch.put}: the extension, or the plugin uninstall preview. */
|
|
6
|
-
export type OrgExtensionPutResult = {
|
|
7
|
-
kind: "done";
|
|
8
|
-
view: OrgExtensionView;
|
|
9
|
-
} | {
|
|
10
|
-
kind: "preview";
|
|
11
|
-
preview: UninstallPreview;
|
|
12
|
-
confirm: string;
|
|
13
|
-
};
|
|
14
|
-
/**
|
|
15
|
-
* `PUT orgs/:orgId/extensions/:extension`: for an extension that ships in a catalog plugin, `enabled`
|
|
16
|
-
* is the plugin's org switch ({@link OrgCatalogService.setSwitch}); anything else is the direct
|
|
17
|
-
* {@link OrgExtensionConfigs.put}. Lives in the catalog module because the catalog depends on the
|
|
18
|
-
* extensions, not the other way round. No in-process state. Switching never checks a config: an
|
|
19
|
-
* extension whose effective config is not valid in the org is switched on and reported
|
|
20
|
-
* `needsConfig` (spec A §6).
|
|
21
|
-
*/
|
|
22
|
-
export declare class OrgExtensionSwitch {
|
|
23
|
-
readonly txHost: TransactionHost;
|
|
24
|
-
private readonly configs;
|
|
25
|
-
private readonly catalog;
|
|
26
|
-
constructor(txHost: TransactionHost, configs: OrgExtensionConfigs, catalog: OrgCatalogService);
|
|
27
|
-
/**
|
|
28
|
-
* - `enabled` on an extension of one catalog plugin: that plugin's switch; off without `confirm`
|
|
29
|
-
* returns the preview and its hash, with the hash uninstalls; a builtin plugin (any of several
|
|
30
|
-
* source items) -> 409 `plugin.scope_locked` (an `all` one may go off, layering spec §4).
|
|
31
|
-
* - A required bootstrap plugin, a config-declared extension and one sourced from several items
|
|
32
|
-
* keep the direct write.
|
|
33
|
-
*/
|
|
34
|
-
put(orgId: string, actor: string, extension: string, body: OrgExtensionInput & {
|
|
35
|
-
confirm?: string | undefined;
|
|
36
|
-
}, actorTokenId?: string,
|
|
37
|
-
/** Merged into the audit details (a Platform operation's `via: "agent"`). */
|
|
38
|
-
auditDetail?: Record<string, unknown>): Promise<OrgExtensionPutResult>;
|
|
39
|
-
private applyAtomic;
|
|
40
|
-
private apply;
|
|
41
|
-
}
|
|
@@ -1,123 +0,0 @@
|
|
|
1
|
-
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
-
};
|
|
7
|
-
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
8
|
-
return function (target, key) { decorator(target, key, paramIndex); }
|
|
9
|
-
};
|
|
10
|
-
import { Inject, Injectable } from "@nestjs/common";
|
|
11
|
-
import { ApiError } from "../errors.js";
|
|
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";
|
|
15
|
-
import { OrgCatalogService } from "./org-catalog.service.js";
|
|
16
|
-
/**
|
|
17
|
-
* `PUT orgs/:orgId/extensions/:extension`: for an extension that ships in a catalog plugin, `enabled`
|
|
18
|
-
* is the plugin's org switch ({@link OrgCatalogService.setSwitch}); anything else is the direct
|
|
19
|
-
* {@link OrgExtensionConfigs.put}. Lives in the catalog module because the catalog depends on the
|
|
20
|
-
* extensions, not the other way round. No in-process state. Switching never checks a config: an
|
|
21
|
-
* extension whose effective config is not valid in the org is switched on and reported
|
|
22
|
-
* `needsConfig` (spec A §6).
|
|
23
|
-
*/
|
|
24
|
-
let OrgExtensionSwitch = class OrgExtensionSwitch {
|
|
25
|
-
txHost;
|
|
26
|
-
configs;
|
|
27
|
-
catalog;
|
|
28
|
-
constructor(txHost, configs, catalog) {
|
|
29
|
-
this.txHost = txHost;
|
|
30
|
-
this.configs = configs;
|
|
31
|
-
this.catalog = catalog;
|
|
32
|
-
}
|
|
33
|
-
/**
|
|
34
|
-
* - `enabled` on an extension of one catalog plugin: that plugin's switch; off without `confirm`
|
|
35
|
-
* returns the preview and its hash, with the hash uninstalls; a builtin plugin (any of several
|
|
36
|
-
* source items) -> 409 `plugin.scope_locked` (an `all` one may go off, layering spec §4).
|
|
37
|
-
* - A required bootstrap plugin, a config-declared extension and one sourced from several items
|
|
38
|
-
* keep the direct write.
|
|
39
|
-
*/
|
|
40
|
-
async put(orgId, actor, extension, body, actorTokenId,
|
|
41
|
-
/** Merged into the audit details (a Platform operation's `via: "agent"`). */
|
|
42
|
-
auditDetail) {
|
|
43
|
-
const { confirm, ...input } = body;
|
|
44
|
-
const audited = auditDetail !== undefined ? { auditDetail } : {};
|
|
45
|
-
const plan = input.enabled === undefined
|
|
46
|
-
? { kind: "direct" }
|
|
47
|
-
: await this.configs.switchPlan(extension, input.enabled);
|
|
48
|
-
if (plan.kind === "locked") {
|
|
49
|
-
throw new ApiError("plugin.scope_locked", "This plugin is built in: it is on for every organization and cannot be switched off here");
|
|
50
|
-
}
|
|
51
|
-
if (plan.kind === "direct") {
|
|
52
|
-
return {
|
|
53
|
-
kind: "done",
|
|
54
|
-
view: await this.configs.put(orgId, extension, input, actor, actorTokenId, audited),
|
|
55
|
-
};
|
|
56
|
-
}
|
|
57
|
-
const { enabled } = input;
|
|
58
|
-
// A fresh install is a multi-step saga that commits on its own and already enables the
|
|
59
|
-
// extension: no transaction spans it. Everything else (the switch row, an uninstall, reading
|
|
60
|
-
// the result back) is one transaction.
|
|
61
|
-
const installing = enabled === true && !(await this.catalog.hasLiveInstall(orgId, plan.itemId));
|
|
62
|
-
const args = {
|
|
63
|
-
orgId,
|
|
64
|
-
actor,
|
|
65
|
-
extension,
|
|
66
|
-
itemId: plan.itemId,
|
|
67
|
-
enabled,
|
|
68
|
-
confirm,
|
|
69
|
-
actorTokenId,
|
|
70
|
-
auditDetail,
|
|
71
|
-
};
|
|
72
|
-
const r = await (installing ? this.apply(args, true) : this.applyAtomic(args));
|
|
73
|
-
if (r !== "readBack")
|
|
74
|
-
return r;
|
|
75
|
-
// Read after the commit: the list reads its own snapshot, which sees only committed rows
|
|
76
|
-
const view = (await this.configs.list(orgId)).find((v) => v.plugin === extension);
|
|
77
|
-
if (view)
|
|
78
|
-
return { kind: "done", view };
|
|
79
|
-
return {
|
|
80
|
-
kind: "done",
|
|
81
|
-
view: await this.configs.put(orgId, extension, { enabled: true }, actor, actorTokenId, {
|
|
82
|
-
ifDisabled: { skipped: false },
|
|
83
|
-
...audited,
|
|
84
|
-
}),
|
|
85
|
-
};
|
|
86
|
-
}
|
|
87
|
-
applyAtomic(a) {
|
|
88
|
-
return this.apply(a, false);
|
|
89
|
-
}
|
|
90
|
-
async apply(a, installing) {
|
|
91
|
-
const { orgId, actor, extension, itemId, enabled, confirm, actorTokenId, auditDetail } = a;
|
|
92
|
-
const audited = auditDetail !== undefined ? { auditDetail } : {};
|
|
93
|
-
// Switching on inside the transaction relies on the live install seen before it: one removed
|
|
94
|
-
// meanwhile would run the install saga here, which commits on its own. Refuse instead; the
|
|
95
|
-
// retry takes the install path.
|
|
96
|
-
if (!installing && enabled === true && !(await this.catalog.hasLiveInstall(orgId, itemId))) {
|
|
97
|
-
throw new ApiError("conflict", "The plugin's install in this organization changed while it was being switched on; try again");
|
|
98
|
-
}
|
|
99
|
-
const r = await this.catalog.setSwitch(orgId, actor, itemId, enabled ? { enabled: true } : { enabled: false, ...(confirm !== undefined && { confirm }) }, actorTokenId, auditDetail);
|
|
100
|
-
if (r.kind === "preview")
|
|
101
|
-
return r;
|
|
102
|
-
if (!enabled)
|
|
103
|
-
return "readBack";
|
|
104
|
-
// Switching on: the install enabled it already (no second write)
|
|
105
|
-
return {
|
|
106
|
-
kind: "done",
|
|
107
|
-
view: await this.configs.put(orgId, extension, { enabled: true }, actor, actorTokenId, {
|
|
108
|
-
ifDisabled: { skipped: false },
|
|
109
|
-
...audited,
|
|
110
|
-
}),
|
|
111
|
-
};
|
|
112
|
-
}
|
|
113
|
-
};
|
|
114
|
-
__decorate([
|
|
115
|
-
Transactional()
|
|
116
|
-
], OrgExtensionSwitch.prototype, "applyAtomic", null);
|
|
117
|
-
OrgExtensionSwitch = __decorate([
|
|
118
|
-
Injectable(),
|
|
119
|
-
__param(0, Inject(TransactionHost)),
|
|
120
|
-
__param(1, Inject(OrgExtensionConfigs)),
|
|
121
|
-
__param(2, Inject(OrgCatalogService))
|
|
122
|
-
], OrgExtensionSwitch);
|
|
123
|
-
export { OrgExtensionSwitch };
|