@capybara-hq/kernel 0.1.0-rc.58 → 0.1.0-rc.59
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/catalog/marketplaces.service.d.ts +1 -1
- package/dist/catalog/org-catalog.controller.d.ts +0 -5
- package/dist/catalog/org-catalog.controller.js +3 -17
- package/dist/catalog/org-catalog.schemas.d.ts +43 -0
- package/dist/catalog/org-catalog.schemas.js +43 -2
- package/dist/catalog/plugin-install.d.ts +2 -0
- package/dist/catalog/plugin-install.js +3 -3
- package/dist/channels/channels.schemas.d.ts +3 -0
- package/dist/channels/channels.schemas.js +8 -0
- package/dist/channels/connections.service.d.ts +17 -2
- package/dist/channels/connections.service.js +30 -5
- package/dist/channels/outbound.js +17 -0
- package/dist/conversations/events.d.ts +34 -0
- package/dist/conversations/events.js +24 -0
- package/dist/ctx/secrets.d.ts +8 -1
- package/dist/ctx/secrets.js +14 -1
- package/dist/db/kernel-schema.d.ts +19 -0
- package/dist/devices/working-root.d.ts +2 -3
- package/dist/errors.d.ts +10 -0
- package/dist/errors.js +10 -0
- package/dist/http/api.module.js +6 -0
- package/dist/identity/initial-passwords.job.d.ts +3 -3
- package/dist/identity/initial-passwords.job.js +7 -5
- package/dist/orgs/invitations.controller.d.ts +3 -11
- package/dist/orgs/invitations.controller.js +9 -10
- package/dist/orgs/invitations.service.d.ts +12 -2
- package/dist/orgs/invitations.service.js +14 -7
- package/dist/orgs/members.service.d.ts +12 -2
- package/dist/orgs/members.service.js +10 -8
- package/dist/orgs/orgs.controller.d.ts +4 -12
- package/dist/orgs/orgs.controller.js +10 -10
- package/dist/orgs/orgs.schemas.d.ts +26 -0
- package/dist/orgs/orgs.schemas.js +22 -0
- package/dist/platform/connector-person-fields.d.ts +67 -0
- package/dist/platform/connector-person-fields.js +129 -0
- package/dist/platform/exclusions.js +5 -100
- package/dist/platform/operation.d.ts +31 -0
- package/dist/platform/operation.js +3 -3
- package/dist/platform/ops/accounts.ops.js +1 -0
- package/dist/platform/ops/channels.ops.d.ts +10 -3
- package/dist/platform/ops/channels.ops.js +223 -5
- package/dist/platform/ops/connectors.ops.d.ts +22 -4
- package/dist/platform/ops/connectors.ops.js +664 -13
- package/dist/platform/ops/org-plugins.ops.d.ts +15 -2
- package/dist/platform/ops/org-plugins.ops.js +323 -4
- package/dist/platform/ops/orgs.ops.d.ts +40 -3
- package/dist/platform/ops/orgs.ops.js +293 -12
- package/dist/platform/ops/person-inputs.d.ts +30 -0
- package/dist/platform/ops/person-inputs.js +50 -0
- package/dist/platform/ops/plugins.ops.d.ts +1 -1
- package/dist/platform/ops/plugins.ops.js +6 -6
- package/dist/platform/parity.d.ts +3 -2
- package/dist/platform/parity.js +40 -15
- package/dist/platform/person-fields.d.ts +20 -4
- package/dist/platform/person-fields.js +27 -5
- package/dist/platform/platform.module.d.ts +2 -1
- package/dist/platform/platform.module.js +5 -3
- package/dist/platform/route-schemas.js +2 -0
- package/dist/platform/sealed-reveals.controller.d.ts +20 -0
- package/dist/platform/sealed-reveals.controller.js +48 -0
- package/dist/platform/sealed-reveals.d.ts +52 -0
- package/dist/platform/sealed-reveals.js +153 -0
- package/dist/runtime/project/knowledge.js +24 -19
- package/dist/sandbox/permission-facts.d.ts +5 -1
- package/dist/sandbox/permission-facts.js +8 -2
- package/dist/setup/setup-guides.service.d.ts +5 -0
- package/dist/setup/setup-guides.service.js +2 -1
- package/dist/tools/approvals.service.js +1 -1
- package/dist/tools/builtins/platform.js +48 -8
- package/dist/tools/connectors.controller.d.ts +6 -7
- package/dist/tools/connectors.controller.js +4 -44
- package/dist/tools/connectors.schemas.d.ts +170 -1
- package/dist/tools/connectors.schemas.js +82 -3
- package/dist/tools/connectors.service.d.ts +16 -6
- package/dist/tools/connectors.service.js +39 -24
- package/dist/tools/oauth/oauth.controller.d.ts +3 -6
- package/dist/tools/oauth/oauth.controller.js +3 -12
- package/dist/tools/oauth/oauth.schemas.d.ts +14 -0
- package/dist/tools/oauth/oauth.schemas.js +27 -0
- package/dist/tools/pipeline.d.ts +7 -0
- package/dist/tools/pipeline.js +13 -4
- package/dist/tools/policy.d.ts +3 -2
- package/dist/tools/policy.js +4 -2
- package/dist/tools/registry.d.ts +7 -0
- package/package.json +4 -4
- package/src/migrations/0170_platform_sealed_reveals.sql +27 -0
|
@@ -5,12 +5,14 @@ import { OrgCatalogService } from "../../catalog/org-catalog.service.js";
|
|
|
5
5
|
import { OrgPluginUploads } from "../../catalog/org-plugin-uploads.js";
|
|
6
6
|
import { OwnedItems } from "../../catalog/owned-items.js";
|
|
7
7
|
import { PluginInstaller } from "../../catalog/plugin-install.js";
|
|
8
|
+
import { OrgExtensionConfigs } from "../../extensions/org-config.js";
|
|
8
9
|
import { KernelDb } from "../../infra/database/kernel-db.js";
|
|
9
10
|
import { ThemesService } from "../../themes/themes.service.js";
|
|
10
11
|
import { PlatformOperations } from "../registry.js";
|
|
11
12
|
/**
|
|
12
13
|
* The org's own plugin operations of the `Platform` tool (spec §14.2): the org's plugin installs
|
|
13
|
-
* (list, uninstall
|
|
14
|
+
* (list, uninstall; installing with inputs and creating missing connectors, their secrets entered
|
|
15
|
+
* by the person on the card, platform web parity spec §7.2), its staged uploads (read; uploading is a byte transport and confirming is done
|
|
14
16
|
* by a person on the web), and the plugins it owns (share, delete after a preview, withdraw a
|
|
15
17
|
* pending upload). Org admins; the services re-check the role under the org lock.
|
|
16
18
|
*/
|
|
@@ -24,7 +26,18 @@ export declare class OrgPluginsOperations implements OnModuleInit {
|
|
|
24
26
|
private readonly kdb;
|
|
25
27
|
private readonly appearance;
|
|
26
28
|
private readonly themes;
|
|
27
|
-
|
|
29
|
+
private readonly extensions;
|
|
30
|
+
constructor(registry: PlatformOperations, installer: PluginInstaller, orgCatalog: OrgCatalogService, uploads: OrgPluginUploads, owned: OwnedItems, scope: CatalogScopeService, kdb: KernelDb, appearance: AppearanceService, themes: ThemesService, extensions: OrgExtensionConfigs);
|
|
31
|
+
/**
|
|
32
|
+
* What installing a plugin asks the person for (platform web parity spec §7.2): the connector
|
|
33
|
+
* templates whose connector the install creates (on in the org, none kept from an earlier
|
|
34
|
+
* switch-off, as the install wizard asks), and the secret fields of its extension's org config
|
|
35
|
+
* under `extensionConfig.` (stored ones count as set; one the schema walk cannot address is web
|
|
36
|
+
* only). An extension whose org view cannot be read refuses the call: its secrets are unknown.
|
|
37
|
+
*/
|
|
38
|
+
private installTargets;
|
|
39
|
+
/** The missing connectors of an installed plugin that a configure call names. */
|
|
40
|
+
private configureTargets;
|
|
28
41
|
/** The display name of the live plugin of `extension`, or the name when it cannot be read. */
|
|
29
42
|
private pluginNames;
|
|
30
43
|
/** The org's own live plugin `id`, or null (another org's, a platform one, deleted, unknown). */
|
|
@@ -11,25 +11,112 @@ import { Inject, Injectable } from "@nestjs/common";
|
|
|
11
11
|
import { z } from "zod";
|
|
12
12
|
import { AppearanceService } from "../../catalog/appearance.service.js";
|
|
13
13
|
import { CatalogScopeService } from "../../catalog/catalog-scope.service.js";
|
|
14
|
-
import { PluginInstallPathParams } from "../../catalog/org-catalog.schemas.js";
|
|
14
|
+
import { CatalogConnectorInput, CatalogItemPathParams, OrgPluginInstallBody, PluginInstallPathParams, } from "../../catalog/org-catalog.schemas.js";
|
|
15
15
|
import { OrgCatalogService } from "../../catalog/org-catalog.service.js";
|
|
16
16
|
import { OrgExtensionParams } from "../../catalog/org-extension.schemas.js";
|
|
17
17
|
import { OrgPluginUploads } from "../../catalog/org-plugin-uploads.js";
|
|
18
18
|
import { OrgOwnedDeleteBody, OrgOwnedPluginParams, OrgOwnedShareableBody, OrgUploadStagingParams, } from "../../catalog/org-plugin-uploads.schemas.js";
|
|
19
19
|
import { OwnedItems } from "../../catalog/owned-items.js";
|
|
20
20
|
import { PluginInstaller } from "../../catalog/plugin-install.js";
|
|
21
|
+
import { ApiError } from "../../errors.js";
|
|
22
|
+
import { OrgExtensionConfigs } from "../../extensions/org-config.js";
|
|
21
23
|
import { KernelDb } from "../../infra/database/kernel-db.js";
|
|
22
24
|
import { ThemesService } from "../../themes/themes.service.js";
|
|
25
|
+
import { clientProblem, headersWebOnly, templateConnectorInput, templatePersonFields, } from "../connector-person-fields.js";
|
|
23
26
|
import { defineOperation } from "../operation.js";
|
|
27
|
+
import { PersonFieldsRefused, personFieldParams, planPersonFields, secretFieldsOf, } from "../person-fields.js";
|
|
24
28
|
import { PlatformOperations } from "../registry.js";
|
|
25
29
|
import { appearanceSummary, reviewBrief } from "./catalog-admin.ops.js";
|
|
26
30
|
import { precheckBy, viaAgent } from "./errors.js";
|
|
27
31
|
import { Cursor, pageOf, startOf } from "./paging.js";
|
|
32
|
+
import { afterTaken, enteredUnder, nestedConfig, takePersonInputs } from "./person-inputs.js";
|
|
28
33
|
import { localized, named, orElse } from "./summary.js";
|
|
29
34
|
const InstallId = PluginInstallPathParams.shape.installId.max(100);
|
|
30
35
|
/** An org-owned plugin's catalog item id (`:id` of the owned-plugins routes). */
|
|
31
36
|
const OwnedId = OrgOwnedPluginParams.shape.id;
|
|
32
37
|
const EXAMPLE_ID = "3f1c2a9e-5b7d-4e21-9c0a-1d2e3f4a5b6c";
|
|
38
|
+
const ItemId = CatalogItemPathParams.shape.itemId.max(100);
|
|
39
|
+
/**
|
|
40
|
+
* The model's input for one connector template (the install's and configure's `connectors` entry
|
|
41
|
+
* without its secrets): name, slug, the endpoint fields the template lets the org edit, and an
|
|
42
|
+
* OAuth client's id. The credential and the client secret are person fields.
|
|
43
|
+
*/
|
|
44
|
+
const TemplateInput = CatalogConnectorInput.pick({ name: true, slug: true, endpoint: true })
|
|
45
|
+
.extend({
|
|
46
|
+
client: z
|
|
47
|
+
.object({ clientId: z.string().min(1).max(500) })
|
|
48
|
+
.strict()
|
|
49
|
+
.optional(),
|
|
50
|
+
})
|
|
51
|
+
.strict();
|
|
52
|
+
const Templates = z
|
|
53
|
+
.record(z.string().min(1).max(100), TemplateInput)
|
|
54
|
+
.refine((v) => Object.keys(v).length <= 50, { message: "Too many connector templates" });
|
|
55
|
+
const InstallInput = z
|
|
56
|
+
.object({
|
|
57
|
+
itemId: ItemId,
|
|
58
|
+
templates: Templates.optional().describe("Per connector template id (plugins.get lists them), the connector's name, slug, endpoint fields and OAuth client id; never a credential."),
|
|
59
|
+
extensionConfig: OrgPluginInstallBody.shape.extensionConfig.describe("The plugin's extension org config without its secret fields (extensions.org-config shows the schema)."),
|
|
60
|
+
askPerson: personFieldParams.askPerson,
|
|
61
|
+
})
|
|
62
|
+
.strict();
|
|
63
|
+
const ConfigureInput = z
|
|
64
|
+
.object({
|
|
65
|
+
itemId: ItemId,
|
|
66
|
+
templates: Templates.describe("Per missing connector template id (plugins.get shows the plugin needs_config), the connector's name, slug, endpoint fields and OAuth client id; never a credential. Name every template to create, even with {}."),
|
|
67
|
+
askPerson: personFieldParams.askPerson,
|
|
68
|
+
})
|
|
69
|
+
.strict();
|
|
70
|
+
/** The card's person-field paths, from the plan (`personAsk`). */
|
|
71
|
+
const entersText = (ctx) => {
|
|
72
|
+
const ask = ctx.personAsk ?? [];
|
|
73
|
+
return ask.length === 0
|
|
74
|
+
? { zh: "", en: "" }
|
|
75
|
+
: { zh: `;由本人填写 ${ask.join("、")}`, en: `; the person enters ${ask.join(", ")}` };
|
|
76
|
+
};
|
|
77
|
+
/** A template as the person-field helpers take it. */
|
|
78
|
+
const targetOf = (t) => ({
|
|
79
|
+
id: t.id,
|
|
80
|
+
name: {
|
|
81
|
+
zh: named(t.displayName?.zh ?? t.displayName?.en ?? t.id),
|
|
82
|
+
en: named(t.displayName?.en ?? t.id),
|
|
83
|
+
},
|
|
84
|
+
auth: t.auth,
|
|
85
|
+
});
|
|
86
|
+
/**
|
|
87
|
+
* The refusal of a template input the card cannot complete, or ok: a credential the card cannot
|
|
88
|
+
* ask for (custom headers), an OAuth client without its id, or a client for a template that takes
|
|
89
|
+
* none.
|
|
90
|
+
*/
|
|
91
|
+
function templatesRefusal(templates, params) {
|
|
92
|
+
for (const t of templates) {
|
|
93
|
+
const where = `Connector template ${t.name.en} (${t.id})`;
|
|
94
|
+
const why = headersWebOnly(t.auth, where);
|
|
95
|
+
if (why !== null)
|
|
96
|
+
return { ok: false, code: "platform.secret_record_web_only", message: why };
|
|
97
|
+
const client = clientProblem(t.auth, params?.[t.id]?.client, where);
|
|
98
|
+
if (client !== null)
|
|
99
|
+
return { ok: false, code: "validation_failed", message: client };
|
|
100
|
+
}
|
|
101
|
+
return { ok: true };
|
|
102
|
+
}
|
|
103
|
+
/** The `connectors` body of the install and configure routes: params plus entered values. */
|
|
104
|
+
function connectorInputs(templates, params, entered) {
|
|
105
|
+
const out = {};
|
|
106
|
+
for (const t of templates) {
|
|
107
|
+
const given = params?.[t.id];
|
|
108
|
+
const hasEntered = Object.keys(entered).some((p) => p.startsWith(`connectors.${t.id}.`));
|
|
109
|
+
if (given === undefined && !hasEntered)
|
|
110
|
+
continue;
|
|
111
|
+
out[t.id] = templateConnectorInput(t, given, entered);
|
|
112
|
+
}
|
|
113
|
+
// a template the plan does not know (not on here) goes to the service as given: it refuses it
|
|
114
|
+
for (const [id, given] of Object.entries(params ?? {})) {
|
|
115
|
+
if (!(id in out) && !templates.some((t) => t.id === id))
|
|
116
|
+
out[id] = { ...given };
|
|
117
|
+
}
|
|
118
|
+
return Object.keys(out).length === 0 ? undefined : out;
|
|
119
|
+
}
|
|
33
120
|
/** One of the org's plugin installs as `plugins.installs` shows it: a compact row. */
|
|
34
121
|
const installRow = (i) => ({
|
|
35
122
|
id: i.id,
|
|
@@ -42,7 +129,8 @@ const installRow = (i) => ({
|
|
|
42
129
|
});
|
|
43
130
|
/**
|
|
44
131
|
* The org's own plugin operations of the `Platform` tool (spec §14.2): the org's plugin installs
|
|
45
|
-
* (list, uninstall
|
|
132
|
+
* (list, uninstall; installing with inputs and creating missing connectors, their secrets entered
|
|
133
|
+
* by the person on the card, platform web parity spec §7.2), its staged uploads (read; uploading is a byte transport and confirming is done
|
|
46
134
|
* by a person on the web), and the plugins it owns (share, delete after a preview, withdraw a
|
|
47
135
|
* pending upload). Org admins; the services re-check the role under the org lock.
|
|
48
136
|
*/
|
|
@@ -56,7 +144,8 @@ let OrgPluginsOperations = class OrgPluginsOperations {
|
|
|
56
144
|
kdb;
|
|
57
145
|
appearance;
|
|
58
146
|
themes;
|
|
59
|
-
|
|
147
|
+
extensions;
|
|
148
|
+
constructor(registry, installer, orgCatalog, uploads, owned, scope, kdb, appearance, themes, extensions) {
|
|
60
149
|
this.registry = registry;
|
|
61
150
|
this.installer = installer;
|
|
62
151
|
this.orgCatalog = orgCatalog;
|
|
@@ -66,6 +155,67 @@ let OrgPluginsOperations = class OrgPluginsOperations {
|
|
|
66
155
|
this.kdb = kdb;
|
|
67
156
|
this.appearance = appearance;
|
|
68
157
|
this.themes = themes;
|
|
158
|
+
this.extensions = extensions;
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* What installing a plugin asks the person for (platform web parity spec §7.2): the connector
|
|
162
|
+
* templates whose connector the install creates (on in the org, none kept from an earlier
|
|
163
|
+
* switch-off, as the install wizard asks), and the secret fields of its extension's org config
|
|
164
|
+
* under `extensionConfig.` (stored ones count as set; one the schema walk cannot address is web
|
|
165
|
+
* only). An extension whose org view cannot be read refuses the call: its secrets are unknown.
|
|
166
|
+
*/
|
|
167
|
+
async installTargets(ctx, itemId) {
|
|
168
|
+
const d = await this.orgCatalog.detail(ctx.orgId, ctx.actorAccountId, itemId);
|
|
169
|
+
const templates = d.templates.filter((t) => t.on && !t.connected).map(targetOf);
|
|
170
|
+
let fields = [];
|
|
171
|
+
let recordOnly = [];
|
|
172
|
+
if (d.extension !== null) {
|
|
173
|
+
const views = await this.extensions.list(ctx.orgId);
|
|
174
|
+
// the view of this catalog item; by plugin name only when that name is unambiguous
|
|
175
|
+
const byName = views.filter((e) => e.plugin === d.extension);
|
|
176
|
+
const v = views.find((e) => e.catalogItem?.itemId === itemId) ??
|
|
177
|
+
(byName.length === 1 ? byName[0] : undefined);
|
|
178
|
+
if (v === undefined && byName.length > 1) {
|
|
179
|
+
throw new PersonFieldsRefused(`Several extensions named ${d.extension} are in this org, so the secret fields of this plugin's extension are not known; install the plugin on the web (Plugins page).`);
|
|
180
|
+
}
|
|
181
|
+
if (v === undefined) {
|
|
182
|
+
throw new PersonFieldsRefused(`Cannot read the config schema of the plugin's extension ${d.extension} now, so its secret fields are unknown; try again, or install the plugin on the web (Plugins page).`);
|
|
183
|
+
}
|
|
184
|
+
else {
|
|
185
|
+
const stored = new Set(v.secrets.filter((x) => x.set).map((x) => x.path));
|
|
186
|
+
const found = secretFieldsOf(v.orgConfigSchema, stored);
|
|
187
|
+
const asked = new Set(found.fields.map((f) => f.path));
|
|
188
|
+
fields = found.fields.map((f) => ({ ...f, path: `extensionConfig.${f.path}` }));
|
|
189
|
+
recordOnly = [
|
|
190
|
+
...new Set([
|
|
191
|
+
...found.recordOnly,
|
|
192
|
+
...v.secrets.map((x) => x.path).filter((p) => !asked.has(p)),
|
|
193
|
+
]),
|
|
194
|
+
].map((p) => `extensionConfig.${p}`);
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
return {
|
|
198
|
+
item: d.item,
|
|
199
|
+
templates,
|
|
200
|
+
target: {
|
|
201
|
+
target: {
|
|
202
|
+
zh: `插件「${localized(d.item.displayName, d.item.name).zh}」的安装`,
|
|
203
|
+
en: `${localized(d.item.displayName, d.item.name).en}: install`,
|
|
204
|
+
},
|
|
205
|
+
fields: [...templatePersonFields(templates), ...fields],
|
|
206
|
+
recordOnly,
|
|
207
|
+
},
|
|
208
|
+
};
|
|
209
|
+
}
|
|
210
|
+
/** The missing connectors of an installed plugin that a configure call names. */
|
|
211
|
+
async configureTargets(ctx, itemId, named) {
|
|
212
|
+
const missing = await this.installer.missingConnectors(ctx.orgId, itemId);
|
|
213
|
+
if (missing === undefined) {
|
|
214
|
+
throw new ApiError("plugin.install_not_found", "The plugin is not installed in this org");
|
|
215
|
+
}
|
|
216
|
+
return missing.templates
|
|
217
|
+
.filter((t) => named.includes(t.id))
|
|
218
|
+
.map((t) => targetOf({ id: t.id, displayName: t.file.displayName, auth: t.file.template.auth }));
|
|
69
219
|
}
|
|
70
220
|
/** The display name of the live plugin of `extension`, or the name when it cannot be read. */
|
|
71
221
|
pluginNames(extension) {
|
|
@@ -370,6 +520,174 @@ let OrgPluginsOperations = class OrgPluginsOperations {
|
|
|
370
520
|
auditDetail: viaAgent("plugins.apply-appearance", ctx),
|
|
371
521
|
}, false),
|
|
372
522
|
}),
|
|
523
|
+
defineOperation({
|
|
524
|
+
id: "plugins.install",
|
|
525
|
+
description: "Install a plugin in this org with its inputs (org admins; the web's install wizard): per connector template the connector's name, slug, endpoint fields and OAuth client id (templates), and the extension's org config without secrets (extensionConfig). Secrets are never params: the person enters them on the confirmation card, at connectors.<templateId>.credential.token (or .credential.username / .credential.password, .client.clientSecret) and extensionConfig.<field>. Required ones are asked even when not listed in askPerson. A plugin that needs no input is switched on with plugins.set-enabled instead.",
|
|
526
|
+
input: InstallInput,
|
|
527
|
+
example: {
|
|
528
|
+
itemId: EXAMPLE_ID,
|
|
529
|
+
templates: { github: { endpoint: { url: "https://api.githubcopilot.com/mcp/" } } },
|
|
530
|
+
askPerson: ["connectors.github.credential.token"],
|
|
531
|
+
},
|
|
532
|
+
// the route needs catalog.read; the service re-checks the plugin's component actions
|
|
533
|
+
authz: { orgAction: "org.extensions.manage" },
|
|
534
|
+
authzNote: "service-enforced",
|
|
535
|
+
mirrors: ["POST /api/v1/orgs/:orgId/catalog/:itemId/install"],
|
|
536
|
+
// the route's connectors carry credentials: templates holds the rest, secrets are person fields
|
|
537
|
+
omits: ["connectors"],
|
|
538
|
+
extras: ["templates", "askPerson"],
|
|
539
|
+
confirm: "org",
|
|
540
|
+
errors: [
|
|
541
|
+
{ code: "catalog.item_not_found", next: "Check the plugin id with plugins.list." },
|
|
542
|
+
{
|
|
543
|
+
code: "plugin.already_installed",
|
|
544
|
+
next: "The plugin is installed in this org already; plugins.get shows its state.",
|
|
545
|
+
},
|
|
546
|
+
{
|
|
547
|
+
code: "plugin.install_failed",
|
|
548
|
+
next: "The install failed at the step its details name and was rolled back; fix that (often the connector's endpoint or credential) and call again: the person enters the credentials again on a new card.",
|
|
549
|
+
},
|
|
550
|
+
{
|
|
551
|
+
code: "catalog.not_deployed",
|
|
552
|
+
next: "The plugin's extension does not run on the platform; plugins.get shows why. Tell the person; the super admin fixes it.",
|
|
553
|
+
},
|
|
554
|
+
{
|
|
555
|
+
code: "validation_failed",
|
|
556
|
+
next: "The error's details name the fields (connectors.<templateId>.… or extensionConfig.…); correct the params and call again.",
|
|
557
|
+
},
|
|
558
|
+
{
|
|
559
|
+
code: "platform.secret_record_web_only",
|
|
560
|
+
next: "Tell the person to finish this on the Plugins page on the web.",
|
|
561
|
+
},
|
|
562
|
+
],
|
|
563
|
+
precheck: async (i, ctx) => {
|
|
564
|
+
let r;
|
|
565
|
+
const read = await precheckBy(async () => {
|
|
566
|
+
r = await this.installTargets(ctx, i.itemId);
|
|
567
|
+
});
|
|
568
|
+
if (!read.ok || r === undefined)
|
|
569
|
+
return read;
|
|
570
|
+
if (r.item.installed !== null) {
|
|
571
|
+
return {
|
|
572
|
+
ok: false,
|
|
573
|
+
code: "plugin.already_installed",
|
|
574
|
+
message: `Plugin ${r.item.name} is installed in this org already`,
|
|
575
|
+
};
|
|
576
|
+
}
|
|
577
|
+
return templatesRefusal(r.templates, i.templates);
|
|
578
|
+
},
|
|
579
|
+
personFields: async (i, ctx) => {
|
|
580
|
+
const { target } = await this.installTargets(ctx, i.itemId);
|
|
581
|
+
// the extension config is a dynamic record: its secrets are checked like values
|
|
582
|
+
const plan = planPersonFields(target, {
|
|
583
|
+
values: { extensionConfig: i.extensionConfig ?? {} },
|
|
584
|
+
askPerson: [],
|
|
585
|
+
clearSecrets: [],
|
|
586
|
+
});
|
|
587
|
+
if (!plan.ok)
|
|
588
|
+
throw new PersonFieldsRefused(plan.message);
|
|
589
|
+
return target;
|
|
590
|
+
},
|
|
591
|
+
summary: async (i, ctx) => {
|
|
592
|
+
const { item, templates } = await this.installTargets(ctx, i.itemId);
|
|
593
|
+
const n = localized(item.displayName, item.name);
|
|
594
|
+
const e = entersText(ctx);
|
|
595
|
+
return {
|
|
596
|
+
zh: `在本组织安装插件「${n.zh}」${item.latestVersion}(${templates.length} 个连接器)${e.zh}`,
|
|
597
|
+
en: `Install plugin "${n.en}" ${item.latestVersion} in the org (${templates.length} connectors)${e.en}`,
|
|
598
|
+
};
|
|
599
|
+
},
|
|
600
|
+
run: async (input, ctx) => {
|
|
601
|
+
const { templates } = await this.installTargets(ctx, input.itemId);
|
|
602
|
+
// the install runs steps in transactions of their own under the org row lock, so the
|
|
603
|
+
// values are taken first (takePersonInputs)
|
|
604
|
+
const { entered, auditDetail } = await takePersonInputs("plugins.install", ctx);
|
|
605
|
+
const connectors = connectorInputs(templates, input.templates, entered);
|
|
606
|
+
const ext = enteredUnder(entered, "extensionConfig.");
|
|
607
|
+
const extensionConfig = input.extensionConfig !== undefined || Object.keys(ext).length > 0
|
|
608
|
+
? nestedConfig(input.extensionConfig ?? {}, ext, [])
|
|
609
|
+
: undefined;
|
|
610
|
+
const r = await this.orgCatalog
|
|
611
|
+
.install(ctx.orgId, ctx.actorAccountId, input.itemId, {
|
|
612
|
+
...(connectors !== undefined && { connectors }),
|
|
613
|
+
...(extensionConfig !== undefined && { extensionConfig }),
|
|
614
|
+
}, undefined, auditDetail)
|
|
615
|
+
.catch((e) => {
|
|
616
|
+
throw afterTaken(e, entered);
|
|
617
|
+
});
|
|
618
|
+
return { installed: r.installed, install: installRow(r.install) };
|
|
619
|
+
},
|
|
620
|
+
}),
|
|
621
|
+
defineOperation({
|
|
622
|
+
id: "plugins.configure-connectors",
|
|
623
|
+
description: "Create the connectors an installed plugin is missing (org admins; the plugin shows needs_config, e.g. after a platform update added a connector template): per missing template its name, slug, endpoint fields and OAuth client id (templates). Credentials are never params: the person enters them on the confirmation card at connectors.<templateId>.credential.token (or .credential.username / .credential.password, .client.clientSecret). Required ones are asked even when not listed in askPerson.",
|
|
624
|
+
input: ConfigureInput,
|
|
625
|
+
example: {
|
|
626
|
+
itemId: EXAMPLE_ID,
|
|
627
|
+
templates: { github: {} },
|
|
628
|
+
askPerson: ["connectors.github.credential.token"],
|
|
629
|
+
},
|
|
630
|
+
authz: { orgAction: "connectors.manage" },
|
|
631
|
+
mirrors: ["POST /api/v1/orgs/:orgId/catalog/:itemId/connectors"],
|
|
632
|
+
// the route's inputs.connectors carry credentials: templates holds the rest
|
|
633
|
+
omits: ["inputs"],
|
|
634
|
+
extras: ["templates", "askPerson"],
|
|
635
|
+
confirm: "org",
|
|
636
|
+
errors: [
|
|
637
|
+
{
|
|
638
|
+
code: "plugin.install_not_found",
|
|
639
|
+
next: "The plugin is not installed in this org; install it with plugins.install.",
|
|
640
|
+
},
|
|
641
|
+
{
|
|
642
|
+
code: "validation_failed",
|
|
643
|
+
next: "The error's details name the fields (connectors.<templateId>.… or extensionConfig.…); correct the params and call again.",
|
|
644
|
+
},
|
|
645
|
+
{
|
|
646
|
+
code: "platform.secret_record_web_only",
|
|
647
|
+
next: "Tell the person to finish this on the Plugins page on the web.",
|
|
648
|
+
},
|
|
649
|
+
],
|
|
650
|
+
precheck: async (i, ctx) => {
|
|
651
|
+
let templates = [];
|
|
652
|
+
const read = await precheckBy(async () => {
|
|
653
|
+
templates = await this.configureTargets(ctx, i.itemId, Object.keys(i.templates));
|
|
654
|
+
});
|
|
655
|
+
return read.ok ? templatesRefusal(templates, i.templates) : read;
|
|
656
|
+
},
|
|
657
|
+
personFields: async (i, ctx) => {
|
|
658
|
+
const templates = await this.configureTargets(ctx, i.itemId, Object.keys(i.templates));
|
|
659
|
+
return {
|
|
660
|
+
target: { zh: "插件缺少的连接器", en: "Plugin: missing connectors" },
|
|
661
|
+
fields: templatePersonFields(templates),
|
|
662
|
+
};
|
|
663
|
+
},
|
|
664
|
+
summary: async (i, ctx) => {
|
|
665
|
+
const n = await orElse(async () => {
|
|
666
|
+
const d = await this.orgCatalog.detail(ctx.orgId, ctx.actorAccountId, i.itemId);
|
|
667
|
+
return localized(d.item.displayName, d.item.name);
|
|
668
|
+
}, { zh: named(i.itemId), en: named(i.itemId) });
|
|
669
|
+
const ids = Object.keys(i.templates).map(named).join(", ");
|
|
670
|
+
const e = entersText(ctx);
|
|
671
|
+
return {
|
|
672
|
+
zh: `为插件「${n.zh}」创建缺少的连接器 ${ids}${e.zh}`,
|
|
673
|
+
en: `Create the missing connectors ${ids} of plugin "${n.en}"${e.en}`,
|
|
674
|
+
};
|
|
675
|
+
},
|
|
676
|
+
run: async (input, ctx) => {
|
|
677
|
+
const templates = await this.configureTargets(ctx, input.itemId, Object.keys(input.templates));
|
|
678
|
+
// each connector is created and recorded in transactions of its own (as the route)
|
|
679
|
+
const { entered, auditDetail } = await takePersonInputs("plugins.configure-connectors", ctx);
|
|
680
|
+
return {
|
|
681
|
+
connectors: await this.installer
|
|
682
|
+
.configureConnectors(ctx.orgId, ctx.actorAccountId, input.itemId, {
|
|
683
|
+
connectors: connectorInputs(templates, input.templates, entered) ?? {},
|
|
684
|
+
}, { auditDetail })
|
|
685
|
+
.catch((e) => {
|
|
686
|
+
throw afterTaken(e, entered);
|
|
687
|
+
}),
|
|
688
|
+
};
|
|
689
|
+
},
|
|
690
|
+
}),
|
|
373
691
|
]);
|
|
374
692
|
}
|
|
375
693
|
};
|
|
@@ -383,6 +701,7 @@ OrgPluginsOperations = __decorate([
|
|
|
383
701
|
__param(5, Inject(CatalogScopeService)),
|
|
384
702
|
__param(6, Inject(KernelDb)),
|
|
385
703
|
__param(7, Inject(AppearanceService)),
|
|
386
|
-
__param(8, Inject(ThemesService))
|
|
704
|
+
__param(8, Inject(ThemesService)),
|
|
705
|
+
__param(9, Inject(OrgExtensionConfigs))
|
|
387
706
|
], OrgPluginsOperations);
|
|
388
707
|
export { OrgPluginsOperations };
|
|
@@ -1,24 +1,55 @@
|
|
|
1
1
|
import { type OnModuleInit } from "@nestjs/common";
|
|
2
2
|
import { AuditLogService } from "../../admin/audit-log.service.js";
|
|
3
3
|
import { OrgNetworkAdmin } from "../../admin/org-network.service.js";
|
|
4
|
+
import { type ErrorCode } from "../../errors.js";
|
|
4
5
|
import { AccountsService } from "../../identity/accounts.js";
|
|
5
6
|
import { SettingsService } from "../../identity/settings.js";
|
|
6
7
|
import { KernelConfigService } from "../../infra/config/kernel-config.service.js";
|
|
7
8
|
import { KernelDb } from "../../infra/database/kernel-db.js";
|
|
9
|
+
import { InvitationsService } from "../../orgs/invitations.service.js";
|
|
8
10
|
import { MembersService } from "../../orgs/members.service.js";
|
|
9
11
|
import { OrgNetworkAllowances } from "../../orgs/network-allowances.service.js";
|
|
10
12
|
import { OrgsService } from "../../orgs/orgs.service.js";
|
|
13
|
+
import { type OrgRole } from "../../orgs/roles.js";
|
|
11
14
|
import { PlatformOperations } from "../registry.js";
|
|
15
|
+
import { SealedReveals } from "../sealed-reveals.js";
|
|
16
|
+
/** What `orgs.invite` returns in place of the token (model-visible English). */
|
|
17
|
+
export declare const INVITATION_LINK_NOTE = "The invitation link is shown once, on the web, to the person who approved this call (on the approval card); they share it with the invitee. It is not shown to you. If it is not read within 24 hours it is lost: revoke the invitation (orgs.revoke-invitation) and invite again.";
|
|
18
|
+
/**
|
|
19
|
+
* Why a member operation through the tool is never offered (spec §7.2, maintainer decision Q2):
|
|
20
|
+
* the actor's own membership (`member.self`), an owner or granting owner
|
|
21
|
+
* (`member.owner_untouchable`), or a role above the actor's own (`member.role_above_actor`). Null:
|
|
22
|
+
* allowed here; the service's own checks still run. A target that is no member is left to the
|
|
23
|
+
* service (`member.not_found`).
|
|
24
|
+
*/
|
|
25
|
+
export declare function memberChangeRefusal(actor: {
|
|
26
|
+
id: string;
|
|
27
|
+
role: OrgRole | null;
|
|
28
|
+
}, target: {
|
|
29
|
+
id: string;
|
|
30
|
+
role: OrgRole | null;
|
|
31
|
+
}, role?: OrgRole): {
|
|
32
|
+
code: ErrorCode;
|
|
33
|
+
message: string;
|
|
34
|
+
} | null;
|
|
35
|
+
/** `member.role_above_actor` when `role` is above the actor's own (or the actor has none). */
|
|
36
|
+
export declare function roleAboveActor(actorRole: OrgRole | null, role: OrgRole): {
|
|
37
|
+
code: ErrorCode;
|
|
38
|
+
message: string;
|
|
39
|
+
} | null;
|
|
12
40
|
/**
|
|
13
41
|
* Org operations of the `Platform` tool (spec §14.2): the super admin's view of every org (list,
|
|
14
42
|
* get, the per-org limits) through their own private agent, and the conversation's org for its
|
|
15
|
-
* members (read, rename, member list, the org audit log for its admins)
|
|
16
|
-
*
|
|
43
|
+
* members (read, rename, member list, the org audit log for its admins), and member management for
|
|
44
|
+
* its admins (invite, revoke, role change, remove; platform web parity spec §7.2: never self, never
|
|
45
|
+
* an owner, never above the actor). Creating, deleting and transferring an org stay on the web.
|
|
17
46
|
*/
|
|
18
47
|
export declare class OrgsOperations implements OnModuleInit {
|
|
19
48
|
private readonly registry;
|
|
20
49
|
private readonly orgs;
|
|
21
50
|
private readonly members;
|
|
51
|
+
private readonly invitations;
|
|
52
|
+
private readonly reveals;
|
|
22
53
|
private readonly settings;
|
|
23
54
|
private readonly accounts;
|
|
24
55
|
private readonly config;
|
|
@@ -26,10 +57,16 @@ export declare class OrgsOperations implements OnModuleInit {
|
|
|
26
57
|
private readonly audit;
|
|
27
58
|
private readonly networkAdmin;
|
|
28
59
|
private readonly allowances;
|
|
29
|
-
constructor(registry: PlatformOperations, orgs: OrgsService, members: MembersService, settings: SettingsService, accounts: AccountsService, config: KernelConfigService, kdb: KernelDb, audit: AuditLogService, networkAdmin: OrgNetworkAdmin, allowances: OrgNetworkAllowances);
|
|
60
|
+
constructor(registry: PlatformOperations, orgs: OrgsService, members: MembersService, invitations: InvitationsService, reveals: SealedReveals, settings: SettingsService, accounts: AccountsService, config: KernelConfigService, kdb: KernelDb, audit: AuditLogService, networkAdmin: OrgNetworkAdmin, allowances: OrgNetworkAllowances);
|
|
30
61
|
private org;
|
|
31
62
|
/** The actor as `OrgsService.update` takes it (it re-checks the role under the org lock). */
|
|
32
63
|
private actor;
|
|
64
|
+
/** The precheck of a member operation: {@link memberChangeRefusal} on the roles read now. */
|
|
65
|
+
private memberCheck;
|
|
66
|
+
/** The precheck of `orgs.invite`, and its run's check: never a role above the actor's. */
|
|
67
|
+
private inviteRefusal;
|
|
68
|
+
/** The member's display name for a card; the id when unknown. */
|
|
69
|
+
private memberName;
|
|
33
70
|
/** The org's allowance `id` (for a card and the remove precheck); none → the remove's 404. */
|
|
34
71
|
private allowance;
|
|
35
72
|
onModuleInit(): void;
|