@capybara-hq/kernel 0.1.0-rc.84 → 0.1.0-rc.85
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/admin.module.js +5 -0
- package/dist/admin/health.service.d.ts +2 -2
- package/dist/admin/health.service.js +10 -2
- package/dist/catalog/admin-catalog.controller.d.ts +2 -1
- package/dist/catalog/admin-catalog.controller.js +2 -1
- package/dist/catalog/catalog-content.d.ts +5 -15
- package/dist/catalog/catalog-content.js +5 -56
- package/dist/catalog/catalog-scope.service.d.ts +3 -3
- package/dist/catalog/catalog-scope.service.js +4 -3
- package/dist/catalog/catalog.module.d.ts +3 -1
- package/dist/catalog/catalog.module.js +14 -1
- package/dist/catalog/component-scope.service.d.ts +6 -1
- package/dist/catalog/component-scope.service.js +16 -2
- package/dist/catalog/job-ids.d.ts +29 -0
- package/dist/catalog/job-ids.js +29 -0
- package/dist/catalog/jobs.d.ts +12 -3
- package/dist/catalog/jobs.js +28 -7
- package/dist/catalog/org-catalog.controller.d.ts +2 -30
- package/dist/catalog/org-catalog.controller.js +3 -29
- package/dist/catalog/org-catalog.schemas.d.ts +9 -46
- package/dist/catalog/org-catalog.schemas.js +9 -23
- package/dist/catalog/org-catalog.service.js +14 -23
- package/dist/catalog/plugin-import.d.ts +21 -0
- package/dist/catalog/plugin-import.js +33 -3
- package/dist/catalog/plugin-install.d.ts +69 -76
- package/dist/catalog/plugin-install.js +156 -234
- package/dist/catalog/plugin-upgrade.d.ts +71 -11
- package/dist/catalog/plugin-upgrade.js +222 -43
- package/dist/catalog/scope-sync.d.ts +22 -20
- package/dist/catalog/scope-sync.js +57 -42
- package/dist/catalog/template-connector-ensure.d.ts +100 -0
- package/dist/catalog/template-connector-ensure.js +285 -0
- package/dist/catalog/template-connector-jobs.d.ts +28 -0
- package/dist/catalog/template-connector-jobs.js +54 -0
- package/dist/catalog/template-connector-reconcile.d.ts +44 -0
- package/dist/catalog/template-connector-reconcile.js +114 -0
- package/dist/catalog/template-connectors.processor.d.ts +32 -0
- package/dist/catalog/template-connectors.processor.js +101 -0
- package/dist/db/kernel-schema.d.ts +2 -1
- package/dist/extensions/org-config.d.ts +6 -1
- package/dist/extensions/org-config.js +15 -2
- package/dist/git/gateway.js +3 -1
- package/dist/infra/outbox/registry.d.ts +28 -0
- package/dist/infra/outbox/registry.js +33 -0
- package/dist/infra/queue/queue-names.d.ts +1 -1
- package/dist/infra/queue/queue-names.js +2 -0
- package/dist/lifecycle/kernel-lifecycle.d.ts +8 -1
- package/dist/lifecycle/kernel-lifecycle.js +37 -11
- package/dist/orgs/org-owner.d.ts +7 -0
- package/dist/orgs/org-owner.js +16 -0
- package/dist/platform/operation.d.ts +3 -4
- package/dist/platform/ops/connectors.ops.js +8 -1
- package/dist/platform/ops/org-plugins.ops.d.ts +0 -9
- package/dist/platform/ops/org-plugins.ops.js +18 -235
- package/dist/platform/ops/plugins.ops.d.ts +0 -1
- package/dist/platform/ops/plugins.ops.js +3 -31
- package/dist/roles/worker-role.d.ts +9 -4
- package/dist/roles/worker-role.js +18 -5
- package/dist/roles/worker.module.d.ts +1 -1
- package/dist/roles/worker.module.js +8 -1
- package/dist/setup/setup-guides.service.d.ts +9 -1
- package/dist/setup/setup-guides.service.js +38 -8
- package/dist/tools/admin-connectors.d.ts +3 -2
- package/dist/tools/admin-connectors.js +5 -4
- package/dist/tools/connector-setup.d.ts +28 -0
- package/dist/tools/connector-setup.js +33 -0
- package/dist/tools/connector-tools-jobs.d.ts +35 -0
- package/dist/tools/connector-tools-jobs.js +40 -0
- package/dist/tools/connector-tools.processor.d.ts +32 -0
- package/dist/tools/connector-tools.processor.js +97 -0
- package/dist/tools/connectors.controller.d.ts +1 -0
- package/dist/tools/connectors.schemas.d.ts +1 -0
- package/dist/tools/connectors.schemas.js +5 -0
- package/dist/tools/connectors.service.d.ts +138 -14
- package/dist/tools/connectors.service.js +410 -50
- package/dist/tools/credentials.d.ts +35 -0
- package/dist/tools/credentials.js +89 -1
- package/dist/tools/drift.d.ts +5 -0
- package/dist/tools/drift.js +21 -2
- package/dist/tools/editable-endpoint.d.ts +23 -0
- package/dist/tools/editable-endpoint.js +92 -0
- package/dist/tools/oauth/flow.d.ts +1 -1
- package/dist/tools/oauth/flow.js +3 -2
- package/dist/tools/pipeline.js +14 -5
- package/dist/tools/registry.d.ts +14 -2
- package/dist/tools/registry.js +27 -6
- package/dist/tools/tools.module.js +4 -0
- package/package.json +2 -2
- package/src/migrations/0183_connectors_created_by_nullable.sql +5 -0
|
@@ -7,14 +7,17 @@ import { OutboxService } from "../infra/outbox/outbox.service.js";
|
|
|
7
7
|
import type { KernelLogger } from "../log.js";
|
|
8
8
|
import { PluginInstaller } from "./plugin-install.js";
|
|
9
9
|
import { type ScopeJob } from "./scope-jobs.js";
|
|
10
|
+
import { TemplateConnectorEnsurer } from "./template-connector-ensure.js";
|
|
10
11
|
/**
|
|
11
12
|
* The plugin scope sync (plugin and component management spec §5, phase 1): converges every org
|
|
12
13
|
* to each platform plugin's scope. In phase 1 "on in an org" is the org's plugin install, so for
|
|
13
14
|
* each (item, org) the sync:
|
|
14
15
|
* - wanted on (`wantedOn`, or a live install in the org depends on it: rule 9) and no live install
|
|
15
|
-
* -> installs it as the kernel itself (actor null, audits `via: "scope"`)
|
|
16
|
-
*
|
|
17
|
-
*
|
|
16
|
+
* -> installs it as the kernel itself (actor null, audits `via: "scope"`). An install asks for
|
|
17
|
+
* no input (plugin pages spec §5.2.2): its connector templates become connectors, those lacking
|
|
18
|
+
* an org credential or OAuth client `needs_config`, and an extension whose effective config is
|
|
19
|
+
* not valid in the org is switched on all the same (it gets no call until it is, and the org
|
|
20
|
+
* catalog shows the plugin `needs_config`);
|
|
18
21
|
* - wanted off and a live install -> uninstalls it (`via: "scope"`; the person who changed the
|
|
19
22
|
* scope or the switch confirmed the preview); the connectors the install created stay as the
|
|
20
23
|
* org's own (spec §5 rule 8); a dependency install it took along that its own scope still wants
|
|
@@ -25,10 +28,11 @@ import { type ScopeJob } from "./scope-jobs.js";
|
|
|
25
28
|
* every scope (an org that switched an `all` item off stays off, also across a scope change away
|
|
26
29
|
* and back, layering spec §4). Builtin items are left alone: they are on everywhere without an org
|
|
27
30
|
* install, and their extension is enabled in every org by `enabled.ts` (required or not). A
|
|
28
|
-
* failed install, uninstall or dependency install is logged, audited
|
|
29
|
-
*
|
|
30
|
-
* super admin's inbox, until a later sync of the pair does not
|
|
31
|
-
*
|
|
31
|
+
* failed install, uninstall or dependency install is logged, audited `plugin.scope_sync_failed`
|
|
32
|
+
* (once while the same failure stays open), kept as the pair's open failure
|
|
33
|
+
* (`plugin_scope_sync_failures`, the super admin's inbox, until a later sync of the pair does not
|
|
34
|
+
* fail) and not retried until the next sync of the item (syncs follow owing transactions, never a
|
|
35
|
+
* timer). An error outside those steps (a read, the failure write itself) ends the attempt
|
|
32
36
|
* without touching the pair's row, so an older failure stays open.
|
|
33
37
|
*
|
|
34
38
|
* Jobs (queue {@link PLUGIN_SCOPE_QUEUE}), all owed through the outbox (transactional outbox spec
|
|
@@ -53,7 +57,7 @@ export { PLUGIN_SCOPE_QUEUE, SCOPE_CHUNK_JOB, SCOPE_ITEM_JOB, SCOPE_ORG_CHUNK, S
|
|
|
53
57
|
* What a sync of one (item, org) did. `deferred`: the plugin's extension is enabled on the
|
|
54
58
|
* deployment but not loaded on this replica yet (P3-38); the job fails for a BullMQ retry.
|
|
55
59
|
*/
|
|
56
|
-
export type ScopeSyncResult = "installed" | "removed" | "
|
|
60
|
+
export type ScopeSyncResult = "installed" | "removed" | "unchanged" | "deferred";
|
|
57
61
|
/**
|
|
58
62
|
* A chunk or org job with a pair whose extension this replica has not loaded yet (P3-38): thrown
|
|
59
63
|
* after its other pairs converged, so BullMQ retries the job with its backoff.
|
|
@@ -79,6 +83,7 @@ export declare class PluginScopeSync {
|
|
|
79
83
|
private readonly kdb;
|
|
80
84
|
private readonly outbox;
|
|
81
85
|
private readonly installer;
|
|
86
|
+
private readonly templateConnectors;
|
|
82
87
|
private readonly registry;
|
|
83
88
|
private readonly effective;
|
|
84
89
|
private readonly locks;
|
|
@@ -86,7 +91,7 @@ export declare class PluginScopeSync {
|
|
|
86
91
|
readonly txHost: TransactionHost;
|
|
87
92
|
/** Orgs per chunk job (a test seam; default {@link SCOPE_ORG_CHUNK}). */
|
|
88
93
|
private readonly chunkSize;
|
|
89
|
-
constructor(kdb: KernelDb, outbox: Pick<OutboxService, "add" | "addMany">, installer: PluginInstaller, registry: ExtensionRegistry, effective: Pick<EffectiveConfigs, "get">, locks: LockService, log: KernelLogger, txHost: TransactionHost,
|
|
94
|
+
constructor(kdb: KernelDb, outbox: Pick<OutboxService, "add" | "addMany">, installer: PluginInstaller, templateConnectors: Pick<TemplateConnectorEnsurer, "ensureTemplateConnectorsIn">, registry: ExtensionRegistry, effective: Pick<EffectiveConfigs, "get">, locks: LockService, log: KernelLogger, txHost: TransactionHost,
|
|
90
95
|
/** Orgs per chunk job (a test seam; default {@link SCOPE_ORG_CHUNK}). */
|
|
91
96
|
chunkSize?: number);
|
|
92
97
|
private get db();
|
|
@@ -131,18 +136,15 @@ export declare class PluginScopeSync {
|
|
|
131
136
|
/** The items of the dependency installs this install (of `orgId`) created. */
|
|
132
137
|
private createdDependencies;
|
|
133
138
|
/**
|
|
134
|
-
* Whether installing the item (with the dependencies the org lacks)
|
|
135
|
-
*
|
|
136
|
-
*
|
|
139
|
+
* Whether installing the item (with the dependencies the org lacks) leaves an extension whose
|
|
140
|
+
* effective config for the org is not valid (a required overridable field the platform leaves
|
|
141
|
+
* empty and the org has no copy of): the plugin then comes on `needs_config` (the scope preview
|
|
142
|
+
* lists such orgs). Connector templates never count: they become connectors (plugin pages spec
|
|
143
|
+
* §5.2.2).
|
|
137
144
|
*/
|
|
138
|
-
|
|
139
|
-
/**
|
|
140
|
-
|
|
141
|
-
* on in the org (ruling P2-6: templates switched off there, outside their own scope or disabled
|
|
142
|
-
* make no connector), or its extension's effective config for the org is not valid (a required
|
|
143
|
-
* overridable field the platform leaves empty and the org has no copy of).
|
|
144
|
-
*/
|
|
145
|
-
private manifestNeedsInput;
|
|
145
|
+
needsConfig(orgId: string, itemId: string, version: string): Promise<boolean>;
|
|
146
|
+
/** Whether the plugin's extension (manifest `m`), loaded here, has no valid config for the org. */
|
|
147
|
+
private extensionConfigInvalid;
|
|
146
148
|
/**
|
|
147
149
|
* Logs and audits a failed install or uninstall (`plugin.scope_sync_failed`, actor null) and
|
|
148
150
|
* records it as the pair's open failure (the super admin's inbox).
|
|
@@ -18,21 +18,23 @@ import { Transactional } from "../infra/database/transactional.decorator.js";
|
|
|
18
18
|
import { LockService } from "../infra/lock/lock.service.js";
|
|
19
19
|
import { OutboxService } from "../infra/outbox/outbox.service.js";
|
|
20
20
|
import { KERNEL_LOGGER } from "../infra/tokens.js";
|
|
21
|
-
import { connectorTemplatesOn, templateIdOfPath } from "./component-state.js";
|
|
22
21
|
import { LIVE_INSTALL_STATUSES } from "./install-status.js";
|
|
23
22
|
import { isUsable } from "./ownership.js";
|
|
24
23
|
import { PluginInstaller } from "./plugin-install.js";
|
|
25
24
|
import { wantedOn } from "./scope.js";
|
|
26
25
|
import { oweScopeItem, PLUGIN_SCOPE_QUEUE, SCOPE_CHUNK_JOB, SCOPE_ORG_CHUNK, SCOPE_ORG_CHUNK_SIZE, SCOPE_ORG_JOB, scopeChunkJobId, scopeOrgJobId, } from "./scope-jobs.js";
|
|
27
26
|
import { ScopeNoLongerWanted, ScopeStillWanted } from "./scope-state.js";
|
|
27
|
+
import { TemplateConnectorEnsurer } from "./template-connector-ensure.js";
|
|
28
28
|
/**
|
|
29
29
|
* The plugin scope sync (plugin and component management spec §5, phase 1): converges every org
|
|
30
30
|
* to each platform plugin's scope. In phase 1 "on in an org" is the org's plugin install, so for
|
|
31
31
|
* each (item, org) the sync:
|
|
32
32
|
* - wanted on (`wantedOn`, or a live install in the org depends on it: rule 9) and no live install
|
|
33
|
-
* -> installs it as the kernel itself (actor null, audits `via: "scope"`)
|
|
34
|
-
*
|
|
35
|
-
*
|
|
33
|
+
* -> installs it as the kernel itself (actor null, audits `via: "scope"`). An install asks for
|
|
34
|
+
* no input (plugin pages spec §5.2.2): its connector templates become connectors, those lacking
|
|
35
|
+
* an org credential or OAuth client `needs_config`, and an extension whose effective config is
|
|
36
|
+
* not valid in the org is switched on all the same (it gets no call until it is, and the org
|
|
37
|
+
* catalog shows the plugin `needs_config`);
|
|
36
38
|
* - wanted off and a live install -> uninstalls it (`via: "scope"`; the person who changed the
|
|
37
39
|
* scope or the switch confirmed the preview); the connectors the install created stay as the
|
|
38
40
|
* org's own (spec §5 rule 8); a dependency install it took along that its own scope still wants
|
|
@@ -43,10 +45,11 @@ import { ScopeNoLongerWanted, ScopeStillWanted } from "./scope-state.js";
|
|
|
43
45
|
* every scope (an org that switched an `all` item off stays off, also across a scope change away
|
|
44
46
|
* and back, layering spec §4). Builtin items are left alone: they are on everywhere without an org
|
|
45
47
|
* install, and their extension is enabled in every org by `enabled.ts` (required or not). A
|
|
46
|
-
* failed install, uninstall or dependency install is logged, audited
|
|
47
|
-
*
|
|
48
|
-
* super admin's inbox, until a later sync of the pair does not
|
|
49
|
-
*
|
|
48
|
+
* failed install, uninstall or dependency install is logged, audited `plugin.scope_sync_failed`
|
|
49
|
+
* (once while the same failure stays open), kept as the pair's open failure
|
|
50
|
+
* (`plugin_scope_sync_failures`, the super admin's inbox, until a later sync of the pair does not
|
|
51
|
+
* fail) and not retried until the next sync of the item (syncs follow owing transactions, never a
|
|
52
|
+
* timer). An error outside those steps (a read, the failure write itself) ends the attempt
|
|
50
53
|
* without touching the pair's row, so an older failure stays open.
|
|
51
54
|
*
|
|
52
55
|
* Jobs (queue {@link PLUGIN_SCOPE_QUEUE}), all owed through the outbox (transactional outbox spec
|
|
@@ -97,18 +100,20 @@ let PluginScopeSync = class PluginScopeSync {
|
|
|
97
100
|
kdb;
|
|
98
101
|
outbox;
|
|
99
102
|
installer;
|
|
103
|
+
templateConnectors;
|
|
100
104
|
registry;
|
|
101
105
|
effective;
|
|
102
106
|
locks;
|
|
103
107
|
log;
|
|
104
108
|
txHost;
|
|
105
109
|
chunkSize;
|
|
106
|
-
constructor(kdb, outbox, installer, registry, effective, locks, log, txHost,
|
|
110
|
+
constructor(kdb, outbox, installer, templateConnectors, registry, effective, locks, log, txHost,
|
|
107
111
|
/** Orgs per chunk job (a test seam; default {@link SCOPE_ORG_CHUNK}). */
|
|
108
112
|
chunkSize = SCOPE_ORG_CHUNK) {
|
|
109
113
|
this.kdb = kdb;
|
|
110
114
|
this.outbox = outbox;
|
|
111
115
|
this.installer = installer;
|
|
116
|
+
this.templateConnectors = templateConnectors;
|
|
112
117
|
this.registry = registry;
|
|
113
118
|
this.effective = effective;
|
|
114
119
|
this.locks = locks;
|
|
@@ -304,7 +309,13 @@ let PluginScopeSync = class PluginScopeSync {
|
|
|
304
309
|
// A platform update may have added dependencies: installed here (rule 9, Task 7)
|
|
305
310
|
if (live.status === "installed") {
|
|
306
311
|
try {
|
|
307
|
-
|
|
312
|
+
// a dependency just installed may provide the connector kind of a template the org
|
|
313
|
+
// never got a connector from (ruling R27); nothing installed, nothing new to provide
|
|
314
|
+
if ((await this.installer.addMissingDependencies(orgId, live.id)) > 0) {
|
|
315
|
+
await this.templateConnectors.ensureTemplateConnectorsIn(orgId, undefined, {
|
|
316
|
+
via: "scope",
|
|
317
|
+
});
|
|
318
|
+
}
|
|
308
319
|
}
|
|
309
320
|
catch (e) {
|
|
310
321
|
await this.failed(orgId, itemId, "dependencies", e, attempt);
|
|
@@ -321,8 +332,6 @@ let PluginScopeSync = class PluginScopeSync {
|
|
|
321
332
|
try {
|
|
322
333
|
if (!(await this.extensionReady(itemId, version, attempt.finalTry)))
|
|
323
334
|
return "deferred";
|
|
324
|
-
if (await this.needsInput(orgId, itemId, version))
|
|
325
|
-
return "needs_config";
|
|
326
335
|
await this.installer.install(orgId, null, itemId, version, {}, { via: "scope" });
|
|
327
336
|
return "installed";
|
|
328
337
|
}
|
|
@@ -397,11 +406,13 @@ let PluginScopeSync = class PluginScopeSync {
|
|
|
397
406
|
return rows.map((r) => r.item_id);
|
|
398
407
|
}
|
|
399
408
|
/**
|
|
400
|
-
* Whether installing the item (with the dependencies the org lacks)
|
|
401
|
-
*
|
|
402
|
-
*
|
|
409
|
+
* Whether installing the item (with the dependencies the org lacks) leaves an extension whose
|
|
410
|
+
* effective config for the org is not valid (a required overridable field the platform leaves
|
|
411
|
+
* empty and the org has no copy of): the plugin then comes on `needs_config` (the scope preview
|
|
412
|
+
* lists such orgs). Connector templates never count: they become connectors (plugin pages spec
|
|
413
|
+
* §5.2.2).
|
|
403
414
|
*/
|
|
404
|
-
async
|
|
415
|
+
async needsConfig(orgId, itemId, version) {
|
|
405
416
|
const v = await this.db
|
|
406
417
|
.selectFrom("catalog_item_versions")
|
|
407
418
|
.select("manifest")
|
|
@@ -411,12 +422,12 @@ let PluginScopeSync = class PluginScopeSync {
|
|
|
411
422
|
const root = v?.manifest;
|
|
412
423
|
if (root === undefined)
|
|
413
424
|
return false;
|
|
414
|
-
if (await this.
|
|
425
|
+
if (await this.extensionConfigInvalid(orgId, root))
|
|
415
426
|
return true;
|
|
416
427
|
// the dependencies the install would bring (planning reads no input of the org)
|
|
417
428
|
const plan = await this.installer.plan(orgId, null, itemId, version, null, "", undefined);
|
|
418
429
|
const visit = async (p) => {
|
|
419
|
-
if (await this.
|
|
430
|
+
if (await this.extensionConfigInvalid(orgId, p.manifest))
|
|
420
431
|
return true;
|
|
421
432
|
for (const d of p.dependencies)
|
|
422
433
|
if (d.plan && (await visit(d.plan)))
|
|
@@ -425,16 +436,8 @@ let PluginScopeSync = class PluginScopeSync {
|
|
|
425
436
|
};
|
|
426
437
|
return visit(plan);
|
|
427
438
|
}
|
|
428
|
-
/**
|
|
429
|
-
|
|
430
|
-
* on in the org (ruling P2-6: templates switched off there, outside their own scope or disabled
|
|
431
|
-
* make no connector), or its extension's effective config for the org is not valid (a required
|
|
432
|
-
* overridable field the platform leaves empty and the org has no copy of).
|
|
433
|
-
*/
|
|
434
|
-
async manifestNeedsInput(orgId, m, itemId) {
|
|
435
|
-
const ids = (m.connectorTemplates ?? []).map((t) => templateIdOfPath(t.path));
|
|
436
|
-
if ((await connectorTemplatesOn(this.db, orgId, itemId, ids)).size > 0)
|
|
437
|
-
return true;
|
|
439
|
+
/** Whether the plugin's extension (manifest `m`), loaded here, has no valid config for the org. */
|
|
440
|
+
async extensionConfigInvalid(orgId, m) {
|
|
438
441
|
if (!m.extension)
|
|
439
442
|
return false;
|
|
440
443
|
// not loaded here: `extensionReady` decides; an extension without overridable fields is ok
|
|
@@ -454,13 +457,24 @@ let PluginScopeSync = class PluginScopeSync {
|
|
|
454
457
|
await this.recordFailure(orgId, itemId, op, code, message);
|
|
455
458
|
}
|
|
456
459
|
async recordFailure(orgId, itemId, op, code, message) {
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
460
|
+
// The same failure again (the pair's open one: an org whose connector kind stays unavailable,
|
|
461
|
+
// synced by every later owing of the item) refreshes its time without another audit row
|
|
462
|
+
const open = await this.db
|
|
463
|
+
.selectFrom("plugin_scope_sync_failures")
|
|
464
|
+
.select(["op", "code", "message"])
|
|
465
|
+
.where("item_id", "=", itemId)
|
|
466
|
+
.where("org_id", "=", orgId)
|
|
467
|
+
.forUpdate()
|
|
468
|
+
.executeTakeFirst();
|
|
469
|
+
if (open?.op !== op || open.code !== code || open.message !== message) {
|
|
470
|
+
await audit(this.db, {
|
|
471
|
+
actorAccountId: null,
|
|
472
|
+
orgId,
|
|
473
|
+
action: "plugin.scope_sync_failed",
|
|
474
|
+
target: itemId,
|
|
475
|
+
detail: { via: "scope", op, code, message },
|
|
476
|
+
});
|
|
477
|
+
}
|
|
464
478
|
const failure = { op, code, message, failed_at: new Date() };
|
|
465
479
|
await this.db
|
|
466
480
|
.insertInto("plugin_scope_sync_failures")
|
|
@@ -486,12 +500,13 @@ PluginScopeSync = __decorate([
|
|
|
486
500
|
__param(0, Inject(KernelDb)),
|
|
487
501
|
__param(1, Inject(OutboxService)),
|
|
488
502
|
__param(2, Inject(PluginInstaller)),
|
|
489
|
-
__param(3, Inject(
|
|
490
|
-
__param(4, Inject(
|
|
491
|
-
__param(5, Inject(
|
|
492
|
-
__param(6, Inject(
|
|
493
|
-
__param(7, Inject(
|
|
494
|
-
__param(8,
|
|
495
|
-
__param(
|
|
503
|
+
__param(3, Inject(TemplateConnectorEnsurer)),
|
|
504
|
+
__param(4, Inject(ExtensionRegistry)),
|
|
505
|
+
__param(5, Inject(EffectiveConfigs)),
|
|
506
|
+
__param(6, Inject(LockService)),
|
|
507
|
+
__param(7, Inject(KERNEL_LOGGER)),
|
|
508
|
+
__param(8, Inject(TransactionHost)),
|
|
509
|
+
__param(9, Optional()),
|
|
510
|
+
__param(9, Inject(SCOPE_ORG_CHUNK_SIZE))
|
|
496
511
|
], PluginScopeSync);
|
|
497
512
|
export { PluginScopeSync };
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { KernelDb } from "../infra/database/kernel-db.js";
|
|
2
|
+
import { TransactionHost } from "../infra/database/transaction-host.js";
|
|
3
|
+
import { LockService } from "../infra/lock/lock.service.js";
|
|
4
|
+
import type { KernelLogger } from "../log.js";
|
|
5
|
+
import { OrgLock } from "../orgs/org-lock.js";
|
|
6
|
+
import { ConnectorsService } from "../tools/connectors.service.js";
|
|
7
|
+
import { PluginInstaller } from "./plugin-install.js";
|
|
8
|
+
/** What one ensure did. */
|
|
9
|
+
export interface EnsureResult {
|
|
10
|
+
/** Connectors created. */
|
|
11
|
+
created: number;
|
|
12
|
+
/** Templates refused by the create's checks (kind off in the org, planning failed): logged. */
|
|
13
|
+
skipped: number;
|
|
14
|
+
/** Templates whose connector extension is not loaded on this replica (yet): not attempted. */
|
|
15
|
+
notLoaded: number;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Creates the template connectors an org never had (ruling R27): for every plugin installed in the
|
|
19
|
+
* org (or only `itemId`), each connector template that is on there and that the org never had a
|
|
20
|
+
* connector from. "Never had" means no connector of the org (live or deleted) was made from the
|
|
21
|
+
* platform template, and no install of the plugin in the org recorded a connector for its
|
|
22
|
+
* template id. So a connector an admin deleted is never made again. The platform templates
|
|
23
|
+
* (`platform_connector_templates`, one version per deployment) are the authority, as for the
|
|
24
|
+
* switch-on (ruling R24).
|
|
25
|
+
*
|
|
26
|
+
* Each connector is created in its own transaction under the org row lock. That transaction
|
|
27
|
+
* re-checks the "never had" rule and that the template is on, then creates it as an install
|
|
28
|
+
* would (`PluginInstaller.createSwitchedOnTemplateConnectorIn`: `planConnector` +
|
|
29
|
+
* `createDeferredIn`, no outbound call, `needs_config` when it needs an org credential or OAuth
|
|
30
|
+
* client, recorded on the install). The create re-checks that the connector kind is available
|
|
31
|
+
* in the org. A refusal (an `ApiError` from those checks) is logged and skipped. Any other error
|
|
32
|
+
* is thrown: the caller's job retries, or the startup pass stops without its mark. A template
|
|
33
|
+
* whose connector extension is not loaded on this replica is counted in `notLoaded` and not
|
|
34
|
+
* attempted: the queued ensure retries until it loads.
|
|
35
|
+
*
|
|
36
|
+
* Callers: the `template-connectors-ensure` job (owed by an install's commit and by an org
|
|
37
|
+
* switching an extension on), the plugin scope sync after it added a plugin's dependencies, and
|
|
38
|
+
* the one-off startup reconciliation (`TemplateConnectorReconciler`).
|
|
39
|
+
*/
|
|
40
|
+
export declare class TemplateConnectorEnsurer {
|
|
41
|
+
private readonly kdb;
|
|
42
|
+
private readonly orgLock;
|
|
43
|
+
private readonly installer;
|
|
44
|
+
/** The connector kinds each org can create connectors of (the sweep's availability check). */
|
|
45
|
+
private readonly connectors;
|
|
46
|
+
private readonly log;
|
|
47
|
+
/** The refusals already warned about (a lease per org and template). */
|
|
48
|
+
private readonly locks;
|
|
49
|
+
readonly txHost: TransactionHost;
|
|
50
|
+
constructor(kdb: KernelDb, orgLock: OrgLock, installer: PluginInstaller,
|
|
51
|
+
/** The connector kinds each org can create connectors of (the sweep's availability check). */
|
|
52
|
+
connectors: Pick<ConnectorsService, "kinds">, log: KernelLogger,
|
|
53
|
+
/** The refusals already warned about (a lease per org and template). */
|
|
54
|
+
locks: Pick<LockService, "lease">, txHost: TransactionHost);
|
|
55
|
+
private get db();
|
|
56
|
+
/** The live orgs with at least one template connector they never had (the startup pass). */
|
|
57
|
+
orgsMissing(): Promise<string[]>;
|
|
58
|
+
/**
|
|
59
|
+
* The backstop sweep (ruling R30, `CatalogJobs.sweepTemplateConnectors`): runs
|
|
60
|
+
* {@link ensureTemplateConnectorsIn} for at most `limit` orgs that have a template connector
|
|
61
|
+
* they never had whose connector kind is available there now (loaded on this replica and its
|
|
62
|
+
* extension enabled in the org). It catches what no event re-triggers: a kind that loaded only
|
|
63
|
+
* after the queued ensure gave up, or an always-on connector extension (it writes no org switch,
|
|
64
|
+
* so it owes no ensure). One query lists the candidates; it already leaves out templates of
|
|
65
|
+
* connector extensions not loaded here and templates plainly off in the org (switched off, or
|
|
66
|
+
* shipped default-off and not switched on). Then one kinds read per candidate org, in org id
|
|
67
|
+
* order starting just after the last org the previous tick ensured (a cursor in
|
|
68
|
+
* `deployment_settings`, wrapping to
|
|
69
|
+
* the first), until `limit` orgs are found. Templates off by their scope, and refusals, are left
|
|
70
|
+
* to the ensure's exact check. The rotation keeps orgs where it keeps creating nothing from
|
|
71
|
+
* starving the later ones, and a repeated refusal is warned about once a day.
|
|
72
|
+
*/
|
|
73
|
+
sweep(opts: {
|
|
74
|
+
limit: number;
|
|
75
|
+
signal?: AbortSignal;
|
|
76
|
+
}): Promise<{
|
|
77
|
+
orgs: number;
|
|
78
|
+
created: number;
|
|
79
|
+
}>;
|
|
80
|
+
/** The last org the previous sweep tick ensured, if any. */
|
|
81
|
+
private sweepCursor;
|
|
82
|
+
/**
|
|
83
|
+
* Creates the org's template connectors it never had (see the class comment); `itemId` limits
|
|
84
|
+
* it to one plugin. `signal` stops it between connectors.
|
|
85
|
+
*/
|
|
86
|
+
ensureTemplateConnectorsIn(orgId: string, itemId?: string, opts?: {
|
|
87
|
+
signal?: AbortSignal;
|
|
88
|
+
via?: string;
|
|
89
|
+
}): Promise<EnsureResult>;
|
|
90
|
+
/**
|
|
91
|
+
* The connector templates of the org's installed plugins (in live orgs) the org never had a
|
|
92
|
+
* connector from; `orgId` / `itemId` undefined: every org / plugin.
|
|
93
|
+
*/
|
|
94
|
+
private missingQuery;
|
|
95
|
+
/**
|
|
96
|
+
* Creates one connector in its own transaction under the org row lock: none for an org deleted
|
|
97
|
+
* meanwhile, a template the org has had a connector from since, or one now off there.
|
|
98
|
+
*/
|
|
99
|
+
private createOne;
|
|
100
|
+
}
|