@capybara-hq/kernel 0.1.0-rc.57 → 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/admin/extensions.controller.d.ts +2 -10
- package/dist/admin/extensions.controller.js +2 -24
- package/dist/admin/extensions.schemas.d.ts +21 -0
- package/dist/admin/extensions.schemas.js +37 -0
- 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/org-extension-switch.d.ts +3 -1
- package/dist/catalog/org-extension-switch.js +12 -5
- package/dist/catalog/org-extension.controller.d.ts +2 -21
- package/dist/catalog/org-extension.controller.js +1 -38
- package/dist/catalog/org-extension.schemas.d.ts +31 -0
- package/dist/catalog/org-extension.schemas.js +65 -0
- package/dist/catalog/plugin-install.d.ts +2 -0
- package/dist/catalog/plugin-install.js +3 -3
- package/dist/channels/actions.js +2 -0
- package/dist/channels/cards.d.ts +8 -0
- package/dist/channels/cards.js +18 -0
- 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 +25 -1
- package/dist/channels/phrases.d.ts +10 -0
- package/dist/channels/phrases.js +10 -0
- package/dist/conversations/conversations.module.js +4 -0
- package/dist/conversations/events.d.ts +35 -0
- package/dist/conversations/events.js +29 -0
- package/dist/conversations/leak-check.d.ts +26 -0
- package/dist/conversations/leak-check.js +69 -0
- package/dist/ctx/secrets.d.ts +13 -1
- package/dist/ctx/secrets.js +19 -1
- package/dist/db/kernel-schema.d.ts +34 -0
- package/dist/devices/working-root.d.ts +2 -3
- package/dist/errors.d.ts +19 -0
- package/dist/errors.js +19 -0
- package/dist/extensions/deployment-config.d.ts +6 -2
- package/dist/extensions/deployment-config.js +35 -23
- package/dist/extensions/org-config.d.ts +2 -0
- package/dist/extensions/org-config.js +1 -0
- package/dist/extensions/org-overrides.d.ts +2 -0
- package/dist/extensions/org-overrides.js +3 -2
- package/dist/http/api.module.js +6 -0
- package/dist/identity/initial-passwords.job.d.ts +3 -2
- package/dist/identity/initial-passwords.job.js +11 -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 +6 -141
- package/dist/platform/method.js +1 -0
- package/dist/platform/operation.d.ts +61 -2
- package/dist/platform/operation.js +4 -4
- 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/extensions-admin.ops.d.ts +15 -2
- package/dist/platform/ops/extensions-admin.ops.js +153 -5
- package/dist/platform/ops/extensions.ops.d.ts +19 -5
- package/dist/platform/ops/extensions.ops.js +285 -10
- 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 +65 -0
- package/dist/platform/ops/person-inputs.js +129 -0
- package/dist/platform/ops/plugins.ops.d.ts +3 -1
- package/dist/platform/ops/plugins.ops.js +33 -20
- package/dist/platform/parity.d.ts +7 -2
- package/dist/platform/parity.js +75 -13
- package/dist/platform/person-fields.d.ts +119 -0
- package/dist/platform/person-fields.js +403 -0
- package/dist/platform/platform.module.d.ts +4 -3
- package/dist/platform/platform.module.js +8 -5
- package/dist/platform/route-schemas.js +2 -0
- package/dist/platform/sealed-inputs.d.ts +44 -0
- package/dist/platform/sealed-inputs.js +116 -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/runtime/waits.js +8 -2
- 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.controller.d.ts +1 -0
- package/dist/tools/approvals.controller.js +19 -0
- package/dist/tools/approvals.service.d.ts +50 -1
- package/dist/tools/approvals.service.js +118 -10
- package/dist/tools/builtins/builtin-tools.d.ts +3 -0
- package/dist/tools/builtins/builtin-tools.js +31 -9
- package/dist/tools/builtins/platform.d.ts +20 -0
- package/dist/tools/builtins/platform.js +214 -15
- 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 +31 -2
- package/dist/tools/pipeline.js +89 -17
- package/dist/tools/policy.d.ts +4 -0
- package/dist/tools/policy.js +8 -0
- package/dist/tools/registry.d.ts +29 -0
- package/dist/tools/tools.module.js +3 -0
- package/package.json +3 -3
- package/src/migrations/0169_platform_sealed_inputs.sql +23 -0
- package/src/migrations/0170_platform_sealed_reveals.sql +27 -0
|
@@ -40,7 +40,9 @@ export { OTHER_ORG } from "./other-orgs.js";
|
|
|
40
40
|
const LOCKED = "This plugin is on for every org (or shipped with the platform) and cannot be switched off in one org.";
|
|
41
41
|
/** The confirm value of switching off a plugin with nothing installed in the org. */
|
|
42
42
|
const NOTHING_INSTALLED = "nothing-installed";
|
|
43
|
-
export const NEEDS_INPUT = "This plugin needs
|
|
43
|
+
export const NEEDS_INPUT = "This plugin needs connector input (endpoints, credentials): install it with plugins.install, or for an installed plugin missing connectors create them with plugins.configure-connectors; the person enters the credentials on the confirmation card.";
|
|
44
|
+
/** `plugin.needs_input` when what is missing is its extension's org config (an agent can set it). */
|
|
45
|
+
export const needsOrgConfig = (extension) => `This plugin's extension ${extension} needs its org config first: read what is missing with extensions.org-config, fill it in with extensions.set-org-config (the person enters secrets on the confirmation card; the org's own copy of overridable platform fields is extensions.save-org-config), then call plugins.set-enabled again.`;
|
|
44
46
|
/** The English name of a plugin as next steps and messages name it. */
|
|
45
47
|
const enName = (i) => localized(i.displayName, i.name).en;
|
|
46
48
|
/** The item with the reason its extension stopped loading (state unchanged), when it has one. */
|
|
@@ -84,21 +86,30 @@ const hasConfigFields = (schema) => {
|
|
|
84
86
|
return typeof props === "object" && props !== null && Object.keys(props).length > 0;
|
|
85
87
|
};
|
|
86
88
|
/**
|
|
87
|
-
*
|
|
88
|
-
*
|
|
89
|
-
* org
|
|
89
|
+
* Why switching the plugin on needs input first, as the `plugin.needs_input` message, or null: its
|
|
90
|
+
* extension's org config misses required values (an agent fills it in with
|
|
91
|
+
* `extensions.set-org-config`), or connector templates without their connector, or anything else
|
|
92
|
+
* the item's `needs_config` stands for (connector input: `plugins.install`, `plugins.configure-connectors`). Unlike the web's
|
|
93
|
+
* install wizard, an org config form whose required values are all stored does not stop the switch.
|
|
90
94
|
*/
|
|
91
95
|
function needsInput(item, extensions) {
|
|
92
|
-
|
|
93
|
-
|
|
96
|
+
const own = extensions.find((e) => e.catalogItem?.itemId === item.id);
|
|
97
|
+
// `needs_config` also means connector templates without their connector
|
|
98
|
+
if (item.state === "needs_config") {
|
|
99
|
+
return own?.needsConfig === true ? needsOrgConfig(own.plugin) : NEEDS_INPUT;
|
|
100
|
+
}
|
|
94
101
|
if (item.installed !== null)
|
|
95
|
-
return
|
|
102
|
+
return null;
|
|
96
103
|
if (item.componentCounts.connectorTemplates > 0)
|
|
97
|
-
return
|
|
104
|
+
return NEEDS_INPUT;
|
|
98
105
|
if (item.componentCounts.extension === 0)
|
|
99
|
-
return
|
|
100
|
-
|
|
101
|
-
|
|
106
|
+
return null;
|
|
107
|
+
return own !== undefined &&
|
|
108
|
+
!own.enabled &&
|
|
109
|
+
hasConfigFields(own.orgConfigSchema) &&
|
|
110
|
+
own.needsConfig
|
|
111
|
+
? needsOrgConfig(own.plugin)
|
|
112
|
+
: null;
|
|
102
113
|
}
|
|
103
114
|
/**
|
|
104
115
|
* Plugin operations of the `Platform` tool (spec §7): the org's view (list, get, switch on or off)
|
|
@@ -211,7 +222,7 @@ let PluginsOperations = class PluginsOperations {
|
|
|
211
222
|
}),
|
|
212
223
|
defineOperation({
|
|
213
224
|
id: "plugins.set-enabled",
|
|
214
|
-
description: "Switch a plugin on or off in this org. Switching on installs it; a plugin whose enabling needs
|
|
225
|
+
description: "Switch a plugin on or off in this org. Switching on installs it; a plugin whose enabling needs connector input is refused: install it with plugins.install instead. Switching off removes what the plugin brought and needs confirm: the value plugins.disable-preview returned with the preview the person saw.",
|
|
215
226
|
input: z.discriminatedUnion("enabled", [
|
|
216
227
|
z.object({ itemId: ItemId, enabled: z.literal(true) }).strict(),
|
|
217
228
|
z.object({ itemId: ItemId, enabled: z.literal(false), confirm: Confirm }).strict(),
|
|
@@ -222,8 +233,8 @@ let PluginsOperations = class PluginsOperations {
|
|
|
222
233
|
authz: { orgAction: "org.extensions.manage" },
|
|
223
234
|
authzNote: "service-enforced",
|
|
224
235
|
mirrors: ["PUT /api/v1/orgs/:orgId/catalog/:itemId/switch"],
|
|
225
|
-
// install inputs a person enters on the web (a plugin that needs them is refused)
|
|
226
236
|
omits: ["inputs"],
|
|
237
|
+
withoutSecrets: "a plugin that needs install inputs is refused here; plugins.install takes them, its secrets entered by the person on the card",
|
|
227
238
|
loosens: {
|
|
228
239
|
confirm: "also takes `nothing-installed` (plugins.disable-preview's value when nothing is installed), which the route's hash pattern rejects; the service checks confirm only when something is installed",
|
|
229
240
|
},
|
|
@@ -251,7 +262,7 @@ let PluginsOperations = class PluginsOperations {
|
|
|
251
262
|
},
|
|
252
263
|
{
|
|
253
264
|
code: "plugin.needs_input",
|
|
254
|
-
next: "
|
|
265
|
+
next: "When its extension's org config is missing, fill it in with extensions.set-org-config (secrets in askPerson), then call again; a plugin that needs connector input is installed with plugins.install (or plugins.configure-connectors once installed), the person entering the credentials on the card.",
|
|
255
266
|
},
|
|
256
267
|
{
|
|
257
268
|
code: "catalog.approval_required",
|
|
@@ -292,9 +303,11 @@ let PluginsOperations = class PluginsOperations {
|
|
|
292
303
|
next: unavailableNext(item.reason, name),
|
|
293
304
|
};
|
|
294
305
|
}
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
306
|
+
const missing = i.enabled
|
|
307
|
+
? needsInput(item, await this.extensions.list(ctx.orgId))
|
|
308
|
+
: null;
|
|
309
|
+
if (missing !== null)
|
|
310
|
+
return { ok: false, code: "plugin.needs_input", message: missing };
|
|
298
311
|
return { ok: true };
|
|
299
312
|
},
|
|
300
313
|
summary: async (i, ctx) => {
|
|
@@ -322,9 +335,9 @@ let PluginsOperations = class PluginsOperations {
|
|
|
322
335
|
run: async (input, ctx) => {
|
|
323
336
|
if (input.enabled) {
|
|
324
337
|
const [item] = await this.orgCatalog.list(ctx.orgId, ctx.actorAccountId, input.itemId);
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
338
|
+
const missing = item ? needsInput(item, await this.extensions.list(ctx.orgId)) : null;
|
|
339
|
+
if (missing !== null)
|
|
340
|
+
throw new ToolError(missing);
|
|
328
341
|
}
|
|
329
342
|
const r = await this.orgCatalog.setSwitch(ctx.orgId, ctx.actorAccountId, input.itemId, input.enabled ? { enabled: true } : { enabled: false, confirm: input.confirm }, undefined, viaAgent("plugins.set-enabled", ctx));
|
|
330
343
|
if (r.kind === "done") {
|
|
@@ -6,10 +6,12 @@ export interface ParityFinding {
|
|
|
6
6
|
route: string;
|
|
7
7
|
/** The operation field (or declaration entry) it is about; absent when about the whole route. */
|
|
8
8
|
field?: string;
|
|
9
|
+
/** The named rule of a finding that has one (`platform-op-secret-param`). */
|
|
10
|
+
rule?: "platform-op-secret-param";
|
|
9
11
|
message: string;
|
|
10
12
|
}
|
|
11
13
|
/** What {@link inputParity} reads of an operation. */
|
|
12
|
-
export type ParityOperation = Pick<PlatformOperation, "id" | "input" | "mirrors"> & Partial<Pick<PlatformOperation, "omits" | "extras" | "renames" | "loosens">>;
|
|
14
|
+
export type ParityOperation = Pick<PlatformOperation, "id" | "input" | "mirrors"> & Partial<Pick<PlatformOperation, "omits" | "extras" | "renames" | "loosens" | "personFields" | "withoutSecrets">>;
|
|
13
15
|
/**
|
|
14
16
|
* Compares an operation's input with one mirrored route's body + query + path params (spec
|
|
15
17
|
* §14.5 item 3), on their input JSON Schemas:
|
|
@@ -23,7 +25,10 @@ export type ParityOperation = Pick<PlatformOperation, "id" | "input" | "mirrors"
|
|
|
23
25
|
* - a `loosens` entry names an input field allowed to accept more than the route (with the
|
|
24
26
|
* reason); it is still compared by type, and an entry that loosens nothing is stale;
|
|
25
27
|
* - a top-level route field the input neither has nor renames into is listed in `omits`, an input
|
|
26
|
-
* field with no route counterpart in `extras`; stale entries of either are findings
|
|
28
|
+
* field with no route counterpart in `extras`; stale entries of either are findings;
|
|
29
|
+
* - rule `platform-op-secret-param`: a route field holding the SDK's `secret()` meta anywhere is
|
|
30
|
+
* never an input field (it is in `omits`), and the operation defines `personFields`, or says in
|
|
31
|
+
* `withoutSecrets` why it takes none of them and asks for none (a preview without the credential).
|
|
27
32
|
*/
|
|
28
33
|
export declare function inputParity(op: ParityOperation, route: RouteSchemas): ParityFinding[];
|
|
29
34
|
/**
|
package/dist/platform/parity.js
CHANGED
|
@@ -5,6 +5,22 @@ const IMPLICIT = new Set(["orgId"]);
|
|
|
5
5
|
const UPPER = ["maxLength", "maximum", "exclusiveMaximum", "maxItems", "maxProperties"];
|
|
6
6
|
const LOWER = ["minLength", "minimum", "exclusiveMinimum", "minItems", "minProperties"];
|
|
7
7
|
const toJson = (s) => z.toJSONSchema(s, { io: "input", unrepresentable: "any" });
|
|
8
|
+
/** Keywords whose value is data, never a schema: a `secret` key inside them is no marker. */
|
|
9
|
+
const DATA_KEYWORDS = new Set(["const", "enum", "default", "examples"]);
|
|
10
|
+
/**
|
|
11
|
+
* Whether a JSON Schema holds the SDK's `secret()` meta anywhere (`z.toJSONSchema` copies the meta
|
|
12
|
+
* `{ secret: true }` onto the node), nested objects, items, unions and `$defs` included.
|
|
13
|
+
*/
|
|
14
|
+
function holdsSecret(node) {
|
|
15
|
+
if (Array.isArray(node))
|
|
16
|
+
return node.some(holdsSecret);
|
|
17
|
+
if (typeof node !== "object" || node === null)
|
|
18
|
+
return false;
|
|
19
|
+
const o = node;
|
|
20
|
+
if (o.secret === true)
|
|
21
|
+
return true;
|
|
22
|
+
return Object.entries(o).some(([k, v]) => !DATA_KEYWORDS.has(k) && holdsSecret(v));
|
|
23
|
+
}
|
|
8
24
|
/** A schema's alternatives: the branches of `anyOf` / `oneOf` (flattened), else itself. */
|
|
9
25
|
function alternatives(s) {
|
|
10
26
|
const branches = (s.anyOf ?? s.oneOf);
|
|
@@ -169,7 +185,10 @@ function fieldMismatch(op, route, path, top) {
|
|
|
169
185
|
* - a `loosens` entry names an input field allowed to accept more than the route (with the
|
|
170
186
|
* reason); it is still compared by type, and an entry that loosens nothing is stale;
|
|
171
187
|
* - a top-level route field the input neither has nor renames into is listed in `omits`, an input
|
|
172
|
-
* field with no route counterpart in `extras`; stale entries of either are findings
|
|
188
|
+
* field with no route counterpart in `extras`; stale entries of either are findings;
|
|
189
|
+
* - rule `platform-op-secret-param`: a route field holding the SDK's `secret()` meta anywhere is
|
|
190
|
+
* never an input field (it is in `omits`), and the operation defines `personFields`, or says in
|
|
191
|
+
* `withoutSecrets` why it takes none of them and asks for none (a preview without the credential).
|
|
173
192
|
*/
|
|
174
193
|
export function inputParity(op, route) {
|
|
175
194
|
const out = [];
|
|
@@ -226,6 +245,25 @@ export function inputParity(op, route) {
|
|
|
226
245
|
if (why !== null)
|
|
227
246
|
add(k, `${name}: ${why} (${r})`);
|
|
228
247
|
}
|
|
248
|
+
// rule `platform-op-secret-param` (platform web parity spec §9): a route field carrying a
|
|
249
|
+
// `secret()` value is entered by the person on the card, never passed by the model
|
|
250
|
+
for (const [k, f] of routeFields) {
|
|
251
|
+
if (!holdsSecret(f.schema))
|
|
252
|
+
continue;
|
|
253
|
+
const secretRule = (message) => out.push({
|
|
254
|
+
op: op.id,
|
|
255
|
+
route: route.route,
|
|
256
|
+
field: k,
|
|
257
|
+
rule: "platform-op-secret-param",
|
|
258
|
+
message: `${op.id}: platform-op-secret-param: ${message}`,
|
|
259
|
+
});
|
|
260
|
+
if (covered.has(k)) {
|
|
261
|
+
secretRule(`\`${k}\` of ${r} carries a secret (\`secret()\` meta): leave it out of the input, list it in \`omits\`, and have the person enter it on the card (\`personFields\`)`);
|
|
262
|
+
}
|
|
263
|
+
else if (op.personFields === undefined && !op.withoutSecrets?.trim()) {
|
|
264
|
+
secretRule(`\`${k}\` of ${r} carries a secret (\`secret()\` meta): the operation must define \`personFields\`, so the person enters secrets on the card, or say in \`withoutSecrets\` why it takes none`);
|
|
265
|
+
}
|
|
266
|
+
}
|
|
229
267
|
for (const k of routeFields.keys()) {
|
|
230
268
|
if (!covered.has(k) && !omits.has(k)) {
|
|
231
269
|
add(k, `\`${k}\` of ${r} is missing from the input and not in \`omits\``);
|
|
@@ -257,16 +295,40 @@ export function inputParity(op, route) {
|
|
|
257
295
|
*/
|
|
258
296
|
export function checkInputParity(ops, routes) {
|
|
259
297
|
const byRoute = new Map(routes.map((r) => [r.route, r]));
|
|
260
|
-
return ops.flatMap((op) =>
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
298
|
+
return ops.flatMap((op) => [
|
|
299
|
+
...staleWithoutSecrets(op, byRoute),
|
|
300
|
+
...op.mirrors.flatMap((m) => {
|
|
301
|
+
const r = byRoute.get(m);
|
|
302
|
+
return r !== undefined
|
|
303
|
+
? inputParity(op, r)
|
|
304
|
+
: [
|
|
305
|
+
{
|
|
306
|
+
op: op.id,
|
|
307
|
+
route: m,
|
|
308
|
+
message: `${op.id} mirrors \`${m}\`, whose schemas are not in ROUTE_SCHEMAS: export them from the controller's <domain>.schemas.ts and list them there`,
|
|
309
|
+
},
|
|
310
|
+
];
|
|
311
|
+
}),
|
|
312
|
+
]);
|
|
313
|
+
}
|
|
314
|
+
/**
|
|
315
|
+
* Rule `platform-op-secret-param`: a `withoutSecrets` reason on an operation none of whose
|
|
316
|
+
* registered mirrored routes carries a secret field is stale (it would hide a later secret).
|
|
317
|
+
*/
|
|
318
|
+
function staleWithoutSecrets(op, byRoute) {
|
|
319
|
+
if (op.withoutSecrets === undefined)
|
|
320
|
+
return [];
|
|
321
|
+
const routes = op.mirrors.flatMap((m) => byRoute.get(m) ?? []);
|
|
322
|
+
const secret = routes.some((r) => [r.params, r.query, r.body].some((part) => part !== undefined && holdsSecret(toJson(part))));
|
|
323
|
+
if (secret || routes.length === 0)
|
|
324
|
+
return [];
|
|
325
|
+
return [
|
|
326
|
+
{
|
|
327
|
+
op: op.id,
|
|
328
|
+
route: op.mirrors.join(", "),
|
|
329
|
+
field: "withoutSecrets",
|
|
330
|
+
rule: "platform-op-secret-param",
|
|
331
|
+
message: `${op.id}: platform-op-secret-param: \`withoutSecrets\` is stale: no mirrored route carries a secret field; remove it`,
|
|
332
|
+
},
|
|
333
|
+
];
|
|
272
334
|
}
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
/**
|
|
3
|
+
* Person fields (platform web parity spec §4.1, §4.2): the secret fields of a write's target config
|
|
4
|
+
* schema that the person types on the approval card instead of the model passing them in params.
|
|
5
|
+
* Pure rules shared by the Platform operations: find the secret fields of a JSON Schema produced by
|
|
6
|
+
* the SDK's `configJsonSchema` (`"x-secret": true`), plan which ones one call asks for, and check
|
|
7
|
+
* one typed value. Paths are the dot paths the config routes use in `values` (ruling R1); secret
|
|
8
|
+
* records (`x-ui.secrets`, `secret(z.record(...))`) and secrets inside array items cannot be
|
|
9
|
+
* addressed that way and are reported as `recordOnly` (entered on the web page).
|
|
10
|
+
*/
|
|
11
|
+
/** UTF-8 bytes of one value the person types. */
|
|
12
|
+
export declare const PERSON_FIELD_MAX_BYTES: number;
|
|
13
|
+
/** Person fields one call may ask for (one approval card). */
|
|
14
|
+
export declare const PERSON_FIELDS_MAX = 32;
|
|
15
|
+
/** One secret field the person may enter on the approval card. */
|
|
16
|
+
export interface PersonFieldSpec {
|
|
17
|
+
/** Dot path from the schema root (R1). */
|
|
18
|
+
path: string;
|
|
19
|
+
/**
|
|
20
|
+
* The card label in both languages: from the node's `title` / `x-ui.label` (a localized hint
|
|
21
|
+
* gives its `zh`; a plain string serves both), else the path.
|
|
22
|
+
*/
|
|
23
|
+
label: {
|
|
24
|
+
zh: string;
|
|
25
|
+
en: string;
|
|
26
|
+
};
|
|
27
|
+
/** From the node's `description` / `x-ui.help`, in both languages as {@link label}. */
|
|
28
|
+
description?: {
|
|
29
|
+
zh: string;
|
|
30
|
+
en: string;
|
|
31
|
+
};
|
|
32
|
+
/**
|
|
33
|
+
* The node's `x-ui` widget is a textarea (or JSON) editor. `checkConfigUi` forbids widgets on
|
|
34
|
+
* secret nodes of extension schemas, so their rows are single-line (JSON pastes fine into a
|
|
35
|
+
* masked single-line input).
|
|
36
|
+
*/
|
|
37
|
+
multiline: boolean;
|
|
38
|
+
/** Listed in its parent's `required` along the whole path. */
|
|
39
|
+
required: boolean;
|
|
40
|
+
/** A stored value exists. */
|
|
41
|
+
isSet: boolean;
|
|
42
|
+
/** The JSON Schema node, scrubbed of value keywords (default / examples / const / enum). */
|
|
43
|
+
schema: Record<string, unknown>;
|
|
44
|
+
}
|
|
45
|
+
/** What one operation writes: its name for the card and the person fields of its schema. */
|
|
46
|
+
export interface PersonFieldTarget {
|
|
47
|
+
target: {
|
|
48
|
+
zh: string;
|
|
49
|
+
en: string;
|
|
50
|
+
};
|
|
51
|
+
fields: PersonFieldSpec[];
|
|
52
|
+
/** Secret paths the card cannot ask for (records, array items): entered on the web page. */
|
|
53
|
+
recordOnly?: string[];
|
|
54
|
+
}
|
|
55
|
+
/** The params every operation with person fields adds to its input schema. */
|
|
56
|
+
export declare const personFieldParams: {
|
|
57
|
+
askPerson: z.ZodType<string[]>;
|
|
58
|
+
clearSecrets: z.ZodType<string[]>;
|
|
59
|
+
};
|
|
60
|
+
/**
|
|
61
|
+
* The secret fields of a config JSON Schema (`configJsonSchema` output): every string node marked
|
|
62
|
+
* `"x-secret": true` (or under a secret object) reachable through `properties`, by dot path, in
|
|
63
|
+
* declaration order. `required` holds when every object along the path lists the next name in
|
|
64
|
+
* its `required`; `isSet` when `stored` holds the path. Secrets the card cannot address go to
|
|
65
|
+
* `recordOnly`: the paths `x-ui.secrets` names, secret nodes that are not strings (records), and
|
|
66
|
+
* secrets inside array items (as `list[].key`), and a secret object that takes undeclared keys
|
|
67
|
+
* (`additionalProperties`, `patternProperties`) for those keys. It fails closed on shapes it cannot see through:
|
|
68
|
+
* a `$ref`, an `allOf` or a union of two or more non-null branches whose subtree holds a secret
|
|
69
|
+
* puts the node's own path into `recordOnly`.
|
|
70
|
+
*/
|
|
71
|
+
export declare function secretFieldsOf(jsonSchema: unknown, stored: ReadonlySet<string>): {
|
|
72
|
+
fields: PersonFieldSpec[];
|
|
73
|
+
recordOnly: string[];
|
|
74
|
+
};
|
|
75
|
+
/**
|
|
76
|
+
* A refusal of a call's person fields (model-visible English, never a value): thrown by the plan,
|
|
77
|
+
* or by an operation's `personFields` for an input the plan cannot see (a dynamic record such as
|
|
78
|
+
* the install's `extensionConfig`). The tool denies the call with the message before the card.
|
|
79
|
+
*/
|
|
80
|
+
export declare class PersonFieldsRefused extends Error {
|
|
81
|
+
}
|
|
82
|
+
/** The plan of one call: the fields the card asks for and the secrets to clear, or a refusal. */
|
|
83
|
+
export type PersonFieldPlan = {
|
|
84
|
+
ok: true;
|
|
85
|
+
ask: PersonFieldSpec[];
|
|
86
|
+
clear: string[];
|
|
87
|
+
} | {
|
|
88
|
+
ok: false;
|
|
89
|
+
message: string;
|
|
90
|
+
};
|
|
91
|
+
/**
|
|
92
|
+
* The paths of `paths` that `values` touches (a pair at, below or above one, null included),
|
|
93
|
+
* flattened like the plan's check: e.g. the read-only fields a call tries to write.
|
|
94
|
+
*/
|
|
95
|
+
export declare function pathsTouched(values: Readonly<Record<string, unknown>> | undefined, paths: readonly string[]): string[];
|
|
96
|
+
/**
|
|
97
|
+
* Plans the person fields of one call (spec §4.1). Refusals are English for the model:
|
|
98
|
+
* - a non-null value in `values` at, below or above a secret field or a recordOnly path (an
|
|
99
|
+
* array-item secret: its array root) -> the leaked-secret copy, naming only the path, never the
|
|
100
|
+
* value; `values` is flattened once, so flat, nested and prefix keys all count; a null at a
|
|
101
|
+
* secret field -> pointed to clearSecrets;
|
|
102
|
+
* - an `askPerson` / `clearSecrets` path that is not a secret field of the target;
|
|
103
|
+
* - a path both asked and cleared;
|
|
104
|
+
* - more than {@link PERSON_FIELDS_MAX} fields to ask.
|
|
105
|
+
* A required secret without a stored value joins `ask` even when not named (unless it is cleared).
|
|
106
|
+
*/
|
|
107
|
+
export declare function planPersonFields(t: PersonFieldTarget, p: {
|
|
108
|
+
values?: Record<string, unknown>;
|
|
109
|
+
askPerson: string[];
|
|
110
|
+
clearSecrets: string[];
|
|
111
|
+
}): PersonFieldPlan;
|
|
112
|
+
/**
|
|
113
|
+
* Checks one value the person typed against its field: at most {@link PERSON_FIELD_MAX_BYTES}
|
|
114
|
+
* UTF-8 bytes, not empty, and valid for the field's JSON Schema node (ajv, JSON Schema 2020-12,
|
|
115
|
+
* as the tool pipeline validates inputs). Returns null when valid, else an English problem that
|
|
116
|
+
* names the field and never echoes the value. A node ajv cannot compile accepts the value: the
|
|
117
|
+
* write validates the whole config again.
|
|
118
|
+
*/
|
|
119
|
+
export declare function checkPersonValue(spec: PersonFieldSpec, value: string): string | null;
|