@capybara-hq/kernel 0.1.0-rc.65 → 0.1.0-rc.67
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 +0 -8
- package/dist/admin/admin.schemas.d.ts +3 -0
- package/dist/agents/admin-agents.d.ts +2 -2
- package/dist/agents/admin-agents.js +2 -1
- package/dist/agents/agent-lookup.js +2 -1
- package/dist/agents/agent-profile.service.d.ts +5 -2
- package/dist/agents/agent-profile.service.js +13 -2
- package/dist/agents/agents.controller.d.ts +4 -3
- package/dist/agents/agents.controller.js +7 -3
- package/dist/agents/agents.module.js +3 -0
- package/dist/agents/agents.schemas.d.ts +6 -6
- package/dist/agents/agents.service.d.ts +23 -2
- package/dist/agents/agents.service.js +61 -6
- package/dist/agents/avatar-view.d.ts +8 -0
- package/dist/agents/avatar-view.js +12 -0
- package/dist/agents/profile.d.ts +38 -13
- package/dist/agents/profile.js +31 -20
- package/dist/attribution/platform-attribution.d.ts +15 -6
- package/dist/attribution/platform-attribution.js +31 -14
- package/dist/background/poll.job.d.ts +1 -1
- package/dist/background/poll.job.js +8 -6
- package/dist/background/tasks.service.js +1 -1
- package/dist/catalog/catalog-content.d.ts +6 -3
- package/dist/catalog/catalog-content.js +7 -8
- package/dist/catalog/claude/translate.js +1 -1
- package/dist/catalog/marketplaces.service.d.ts +1 -1
- package/dist/catalog/marketplaces.service.js +2 -1
- package/dist/catalog/plugin-package.d.ts +3 -2
- package/dist/channels/file-delivery.d.ts +2 -0
- package/dist/channels/file-delivery.js +1 -1
- package/dist/channels/inbound.d.ts +8 -4
- package/dist/channels/inbound.js +14 -7
- package/dist/channels/outbound.js +11 -5
- package/dist/channels/phrases.d.ts +21 -13
- package/dist/channels/phrases.js +21 -14
- package/dist/client/client-files.js +1 -1
- package/dist/config/product-name.d.ts +8 -0
- package/dist/config/product-name.js +9 -0
- package/dist/config/schema.d.ts +1 -0
- package/dist/config/schema.js +17 -4
- package/dist/conversations/conversations.service.d.ts +4 -3
- package/dist/conversations/conversations.service.js +15 -2
- package/dist/ctx/create-ctx.js +5 -2
- package/dist/ctx/device-provider-check.d.ts +7 -0
- package/dist/ctx/device-provider-check.js +21 -0
- package/dist/db/kernel-schema.d.ts +7 -0
- package/dist/devices/access.d.ts +16 -46
- package/dist/devices/access.js +26 -62
- package/dist/devices/access.module.js +2 -2
- package/dist/devices/conversation-devices.d.ts +38 -18
- package/dist/devices/conversation-devices.js +69 -51
- package/dist/devices/default-provider-setting.d.ts +45 -0
- package/dist/devices/default-provider-setting.js +59 -0
- package/dist/devices/device-projects.service.js +7 -2
- package/dist/devices/device-provider-selection.d.ts +37 -0
- package/dist/devices/device-provider-selection.js +86 -0
- package/dist/devices/device-provider-selection.module.d.ts +3 -0
- package/dist/devices/device-provider-selection.module.js +22 -0
- package/dist/devices/devices.controller.d.ts +8 -5
- package/dist/devices/devices.controller.js +7 -4
- package/dist/devices/devices.module.js +3 -1
- package/dist/devices/devices.schemas.js +2 -2
- package/dist/devices/devices.service.d.ts +72 -83
- package/dist/devices/devices.service.js +139 -248
- package/dist/devices/dto.d.ts +9 -0
- package/dist/devices/dto.js +15 -2
- package/dist/devices/label.d.ts +3 -5
- package/dist/devices/label.js +3 -14
- package/dist/devices/legacy-cleanup.job.d.ts +2 -2
- package/dist/devices/legacy-cleanup.job.js +6 -6
- package/dist/errors.d.ts +15 -1
- package/dist/errors.js +15 -1
- package/dist/extensions/guide-places.d.ts +2 -1
- package/dist/extensions/guide-places.js +8 -2
- package/dist/extensions/locks.d.ts +1 -1
- package/dist/extensions/locks.js +1 -1
- package/dist/extensions/org-config.d.ts +20 -4
- package/dist/extensions/org-config.js +23 -6
- package/dist/extensions/permission-view.d.ts +2 -2
- package/dist/extensions/permission-view.js +2 -2
- package/dist/extensions/plugin-guides.d.ts +1 -1
- package/dist/extensions/plugin-guides.js +11 -3
- package/dist/extensions/point-defaults.d.ts +14 -0
- package/dist/extensions/point-defaults.js +70 -47
- package/dist/extensions/resolve.js +7 -2
- package/dist/git/gateway.d.ts +9 -0
- package/dist/git/gateway.js +36 -17
- package/dist/git/gateway.route.d.ts +1 -1
- package/dist/git/gateway.route.js +1 -3
- package/dist/http/app.d.ts +1 -1
- package/dist/identity/app-auth.d.ts +4 -3
- package/dist/identity/app-auth.js +7 -8
- package/dist/identity/settings.d.ts +8 -0
- package/dist/identity/settings.js +30 -3
- package/dist/identity/sso.d.ts +13 -7
- package/dist/identity/sso.js +21 -7
- package/dist/infra/config/kernel-config.service.js +3 -1
- package/dist/lifecycle/kernel-lifecycle.js +7 -6
- package/dist/local-devices/device-routes.d.ts +1 -1
- package/dist/local-devices/device-routes.js +2 -2
- package/dist/local-devices/local-device-provider.d.ts +14 -11
- package/dist/local-devices/local-device-provider.js +14 -0
- package/dist/local-devices/local-devices.module.d.ts +4 -4
- package/dist/local-devices/local-devices.module.js +5 -3
- package/dist/local-devices/owner-report.js +2 -1
- package/dist/local-devices/targets.d.ts +2 -0
- package/dist/local-devices/targets.js +10 -0
- package/dist/orgs/offboarding.js +9 -0
- package/dist/orgs/settings.service.d.ts +26 -1
- package/dist/orgs/settings.service.js +44 -3
- package/dist/platform/ops/admin.ops.js +8 -3
- package/dist/platform/ops/agents.ops.d.ts +6 -1
- package/dist/platform/ops/agents.ops.js +38 -11
- package/dist/platform/ops/devices.ops.js +25 -20
- package/dist/platform/ops/orgs.ops.js +1 -0
- package/dist/platform/ops/platform-icons.ops.js +4 -4
- package/dist/platform/ops/platform.ops.js +2 -1
- package/dist/platform/ops/themes.ops.js +1 -1
- package/dist/runtime/plugin-context.service.js +1 -12
- package/dist/sandbox/cloud-permission-snapshot.d.ts +2 -2
- package/dist/sandbox/cloud-permission-snapshot.js +3 -3
- package/dist/sandbox/device-reports.d.ts +50 -0
- package/dist/sandbox/device-reports.js +157 -0
- package/dist/sandbox/held-operations.d.ts +8 -8
- package/dist/sandbox/leases.d.ts +1 -1
- package/dist/sandbox/leases.js +1 -1
- package/dist/sandbox/operation-authority.d.ts +5 -2
- package/dist/sandbox/operation-authority.js +12 -11
- package/dist/sandbox/operation-reconcile.job.d.ts +2 -2
- package/dist/sandbox/operation-reconcile.job.js +5 -5
- package/dist/sandbox/permission-availability.d.ts +2 -2
- package/dist/sandbox/permission-call-types.d.ts +5 -0
- package/dist/sandbox/permission-facts.d.ts +2 -2
- package/dist/sandbox/permission-facts.js +5 -5
- package/dist/sandbox/providers.d.ts +23 -24
- package/dist/sandbox/providers.js +38 -46
- package/dist/sandbox/providers.module.js +3 -3
- package/dist/sandbox/review/classifier.d.ts +6 -0
- package/dist/sandbox/review/classifier.js +12 -1
- package/dist/sandbox/review/index.d.ts +1 -1
- package/dist/sandbox/review/index.js +1 -1
- package/dist/sandbox/sandbox.module.d.ts +1 -1
- package/dist/sandbox/sandbox.module.js +7 -2
- package/dist/sandbox/sandbox.service.d.ts +95 -68
- package/dist/sandbox/sandbox.service.js +212 -208
- package/dist/setup/setup-guides.service.d.ts +4 -1
- package/dist/setup/setup-guides.service.js +6 -1
- package/dist/themes/avatar-preset-key.d.ts +6 -0
- package/dist/themes/avatar-preset-key.js +9 -0
- package/dist/themes/platform-icon.service.js +1 -1
- package/dist/themes/theme-delivery.service.d.ts +10 -2
- package/dist/themes/theme-delivery.service.js +26 -11
- package/dist/themes/theme-state.d.ts +43 -2
- package/dist/themes/theme-state.js +61 -4
- package/dist/themes/themes-public.controller.d.ts +3 -3
- package/dist/themes/themes-public.controller.js +3 -3
- package/dist/themes/themes.service.d.ts +28 -1
- package/dist/themes/themes.service.js +36 -2
- package/dist/tools/builtins/image/generate.d.ts +3 -0
- package/dist/tools/builtins/image/generate.js +21 -11
- package/dist/tools/builtins/image/index.d.ts +1 -1
- package/dist/tools/builtins/image/index.js +1 -1
- package/dist/tools/builtins/platform.js +25 -17
- package/dist/tools/builtins/sandbox/common.d.ts +37 -13
- package/dist/tools/builtins/sandbox/common.js +63 -19
- package/dist/tools/builtins/sandbox/read.d.ts +5 -2
- package/dist/tools/builtins/sandbox/read.js +9 -6
- package/dist/tools/builtins/sandbox/task-output.d.ts +2 -2
- package/dist/tools/builtins/sandbox/task-output.js +6 -5
- package/dist/tools/builtins/skill-load.js +13 -4
- package/dist/tools/connectors.service.js +2 -1
- package/dist/tools/oauth/discovery.d.ts +2 -0
- package/dist/tools/oauth/discovery.js +3 -1
- package/dist/until-aborted.d.ts +5 -0
- package/dist/until-aborted.js +16 -0
- package/package.json +4 -4
- package/src/migrations/0176_device_report.sql +6 -0
|
@@ -168,64 +168,87 @@ let ExtensionPointDefaults = class ExtensionPointDefaults {
|
|
|
168
168
|
const out = [];
|
|
169
169
|
const failed = new Set();
|
|
170
170
|
for (const [extension, impl] of providers) {
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
171
|
+
const c = await this.evaluate(orgId, point, extension, impl, failed);
|
|
172
|
+
if (c)
|
|
173
|
+
out.push(c);
|
|
174
|
+
}
|
|
175
|
+
out.sort((a, b) => (a.extension < b.extension ? -1 : a.extension > b.extension ? 1 : 0));
|
|
176
|
+
return { candidates: out, failed };
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* Whether the one provider `extension` of `point` evaluates as a candidate in `orgId`. The
|
|
180
|
+
* provider must be loaded on this replica and provide `point`; the org must have it enabled; its
|
|
181
|
+
* org config and effective config must be valid; and its `configured()` must not return false.
|
|
182
|
+
* These are exactly the criteria of {@link providersFor} / {@link resolve}, with only that one
|
|
183
|
+
* provider evaluated. A provider whose status cannot be read counts as not serving (logged).
|
|
184
|
+
*/
|
|
185
|
+
async serves(orgId, point, extension) {
|
|
186
|
+
const entry = this.registry.list(point).find((e) => e.plugin === extension);
|
|
187
|
+
if (!entry || !(await isExtensionEnabled(this.kdb.db, orgId, extension)))
|
|
188
|
+
return false;
|
|
189
|
+
return (await this.evaluate(orgId, point, extension, entry.impl, new Set())) !== undefined;
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* One enabled provider's candidacy: valid org config, valid effective config and `configured()`
|
|
193
|
+
* not false. Undefined when it is off; a provider whose status could not be read is also added
|
|
194
|
+
* to `failed`.
|
|
195
|
+
*/
|
|
196
|
+
async evaluate(orgId, point, extension, impl, failed) {
|
|
197
|
+
let cfg;
|
|
198
|
+
try {
|
|
199
|
+
cfg = await this.orgConfigs.get(orgId, extension);
|
|
200
|
+
}
|
|
201
|
+
catch (err) {
|
|
202
|
+
// a stored org config that no longer validates is a known state: the provider is off
|
|
203
|
+
// (as for an invalid effective config below); only a read that failed is `failed`
|
|
204
|
+
const invalid = err instanceof OrgConfigInvalidError;
|
|
205
|
+
this.log.warn(invalid
|
|
206
|
+
? "extension point provider excluded, its stored org config is invalid"
|
|
207
|
+
: "extension point provider excluded, cannot read its org config", { orgId, point, extension, err });
|
|
208
|
+
if (!invalid)
|
|
209
|
+
failed.add(extension);
|
|
210
|
+
return undefined;
|
|
211
|
+
}
|
|
212
|
+
if (!cfg?.enabled)
|
|
213
|
+
return undefined;
|
|
214
|
+
// spec A §6: an org whose effective config is not valid gets no call from this extension
|
|
215
|
+
let effective;
|
|
216
|
+
try {
|
|
217
|
+
effective = await this.effective.get(orgId, extension);
|
|
218
|
+
}
|
|
219
|
+
catch (err) {
|
|
220
|
+
this.log.warn("extension point provider excluded, cannot read its effective config", {
|
|
221
|
+
orgId,
|
|
222
|
+
point,
|
|
223
|
+
extension,
|
|
224
|
+
err,
|
|
225
|
+
});
|
|
226
|
+
failed.add(extension);
|
|
227
|
+
return undefined;
|
|
228
|
+
}
|
|
229
|
+
if (!effective.ok)
|
|
230
|
+
return undefined;
|
|
231
|
+
const configured = impl
|
|
232
|
+
.configured;
|
|
233
|
+
if (typeof configured === "function") {
|
|
234
|
+
let ok;
|
|
190
235
|
try {
|
|
191
|
-
|
|
236
|
+
ok = configured.call(impl, cfg.config, effective.config) !== false;
|
|
192
237
|
}
|
|
193
238
|
catch (err) {
|
|
194
|
-
this.log.warn("extension point provider excluded,
|
|
239
|
+
this.log.warn("extension point provider excluded, configured() threw", {
|
|
195
240
|
orgId,
|
|
196
241
|
point,
|
|
197
242
|
extension,
|
|
198
243
|
err,
|
|
199
244
|
});
|
|
200
245
|
failed.add(extension);
|
|
201
|
-
|
|
202
|
-
}
|
|
203
|
-
if (!effective.ok)
|
|
204
|
-
continue;
|
|
205
|
-
const configured = impl
|
|
206
|
-
.configured;
|
|
207
|
-
if (typeof configured === "function") {
|
|
208
|
-
let ok;
|
|
209
|
-
try {
|
|
210
|
-
ok = configured.call(impl, cfg.config, effective.config) !== false;
|
|
211
|
-
}
|
|
212
|
-
catch (err) {
|
|
213
|
-
this.log.warn("extension point provider excluded, configured() threw", {
|
|
214
|
-
orgId,
|
|
215
|
-
point,
|
|
216
|
-
extension,
|
|
217
|
-
err,
|
|
218
|
-
});
|
|
219
|
-
failed.add(extension);
|
|
220
|
-
continue;
|
|
221
|
-
}
|
|
222
|
-
if (!ok)
|
|
223
|
-
continue;
|
|
246
|
+
return undefined;
|
|
224
247
|
}
|
|
225
|
-
|
|
248
|
+
if (!ok)
|
|
249
|
+
return undefined;
|
|
226
250
|
}
|
|
227
|
-
|
|
228
|
-
return { candidates: out, failed };
|
|
251
|
+
return { extension, impl, orgConfig: cfg.config, config: effective.config };
|
|
229
252
|
}
|
|
230
253
|
async choose(orgId, point, candidates) {
|
|
231
254
|
if (candidates.length < 2)
|
|
@@ -99,8 +99,13 @@ export function resolveExtensions(manifests, sdkVersion) {
|
|
|
99
99
|
for (const m of manifests) {
|
|
100
100
|
for (const ref of m.provides) {
|
|
101
101
|
const { name, major } = parseExtensionPoint(ref);
|
|
102
|
-
const majors = EXTENSION_POINTS
|
|
103
|
-
|
|
102
|
+
const majors = Object.hasOwn(EXTENSION_POINTS, name)
|
|
103
|
+
? EXTENSION_POINTS[name]?.majors
|
|
104
|
+
: undefined;
|
|
105
|
+
if (!majors) {
|
|
106
|
+
throw new ExtensionResolveError(`Plugin ${m.name} provides ${ref}, which this kernel does not know.`, "extension.unsupported_extension_point");
|
|
107
|
+
}
|
|
108
|
+
if (!majors.includes(major)) {
|
|
104
109
|
throw new ExtensionResolveError(`Plugin ${m.name} provides ${ref}, which this kernel no longer supports; upgrade it to a version that provides ${name}@${Math.max(...majors)}.`, "extension.unsupported_extension_point");
|
|
105
110
|
}
|
|
106
111
|
}
|
package/dist/git/gateway.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { FastifyReply, FastifyRequest } from "fastify";
|
|
2
2
|
import type { Redis } from "ioredis";
|
|
3
|
+
import type { KernelConfig } from "../config/schema.js";
|
|
3
4
|
import { KernelConfigService } from "../infra/config/kernel-config.service.js";
|
|
4
5
|
import { KernelDb } from "../infra/database/kernel-db.js";
|
|
5
6
|
import type { KernelLogger } from "../log.js";
|
|
@@ -69,6 +70,8 @@ export declare class GitGateway {
|
|
|
69
70
|
constructor(tickets: Pick<GitTickets, "resolve">, sources: Pick<GitSources, "sourcesFor">, credentials: Pick<Credentials, "gitAuthorization" | "gitUnauthorized">, db: KernelDb, redis: Redis,
|
|
70
71
|
/** Read per request: `tools.git.*` is read live. */
|
|
71
72
|
config: Pick<KernelConfigService, "get">, log: Pick<KernelLogger, "info" | "warn" | "debug">, upstreamOrigin?: GitUpstreamOrigin | undefined);
|
|
73
|
+
/** `message` as git prints it from this gateway: with the platform name before it. */
|
|
74
|
+
says(message: string): string;
|
|
72
75
|
/** Handles one gateway request (the raw route's handler). */
|
|
73
76
|
handle(req: FastifyRequest, reply: FastifyReply): Promise<void>;
|
|
74
77
|
/** The `git.push` audit row of a receive-pack and the run's fetch counters (best effort). */
|
|
@@ -91,3 +94,9 @@ export declare class GitGateway {
|
|
|
91
94
|
/** The connector's auth (it may have changed since the source was chosen); null when gone. */
|
|
92
95
|
private connectorAuth;
|
|
93
96
|
}
|
|
97
|
+
/** The note a refused push carries (the model reads it in the command's output). */
|
|
98
|
+
/**
|
|
99
|
+
* How the gateway prefixes what git prints (`remote: <platform.name>: …`), so a person reading the
|
|
100
|
+
* output of git knows which side refused.
|
|
101
|
+
*/
|
|
102
|
+
export declare function gitSays(config: Pick<KernelConfig, "platform">): (message: string) => string;
|
package/dist/git/gateway.js
CHANGED
|
@@ -10,6 +10,7 @@ var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
|
10
10
|
import { Readable, Transform } from "node:stream";
|
|
11
11
|
import { pipeline } from "node:stream/promises";
|
|
12
12
|
import { Inject, Injectable, Optional } from "@nestjs/common";
|
|
13
|
+
import { productName } from "../config/product-name.js";
|
|
13
14
|
import { audit } from "../identity/audit.js";
|
|
14
15
|
import { KernelConfigService } from "../infra/config/kernel-config.service.js";
|
|
15
16
|
import { KernelDb } from "../infra/database/kernel-db.js";
|
|
@@ -143,15 +144,19 @@ const BYTES_TTL_SECONDS = 24 * 60 * 60;
|
|
|
143
144
|
const CONCURRENCY_TTL_SECONDS = 15 * 60;
|
|
144
145
|
/** Bytes counted locally before they are added to the Redis counter. */
|
|
145
146
|
const BYTES_FLUSH = 256 * 1024;
|
|
146
|
-
/**
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
const
|
|
151
|
-
const
|
|
152
|
-
const
|
|
153
|
-
const
|
|
154
|
-
const
|
|
147
|
+
/**
|
|
148
|
+
* Texts git prints (`remote: …`); every answer prefixes them with the platform name
|
|
149
|
+
* (`<platform.name>: …`, read per request: the field is hot).
|
|
150
|
+
*/
|
|
151
|
+
const TICKET_REFUSED = "the git ticket is not valid (expired, revoked, or the task has ended). Run the command again from the agent's task.";
|
|
152
|
+
const TOO_MANY = "too many git transfers are running in this organization; try again shortly.";
|
|
153
|
+
const BYTES_EXCEEDED = "this task reached its git transfer limit (tools.git.maxBytesPerRun).";
|
|
154
|
+
const NOT_AN_ENDPOINT = "not a git smart-HTTP endpoint.";
|
|
155
|
+
const reconnect = (host) => `${host} refused the connection's credential. Reconnect it under Settings → Connectors, then run the command again.`;
|
|
156
|
+
const repoRefused = (repo) => `this task may not use the repository ${repo}.`;
|
|
157
|
+
const upstreamFailed = (host, detail) => `the request to ${host} failed (${detail}).`;
|
|
158
|
+
const BAD_PUSH = (why) => `the push could not be read (${why}).`;
|
|
159
|
+
const notConnected = (host) => `you have no connection that can reach ${host}. Connect one under Settings → Connectors, then run the command again.`;
|
|
155
160
|
/** The bytes of one request, added to the run's Redis counter in batches. */
|
|
156
161
|
class ByteMeter {
|
|
157
162
|
redis;
|
|
@@ -282,6 +287,10 @@ let GitGateway = class GitGateway {
|
|
|
282
287
|
this.log = log;
|
|
283
288
|
this.upstreamOrigin = upstreamOrigin;
|
|
284
289
|
}
|
|
290
|
+
/** `message` as git prints it from this gateway: with the platform name before it. */
|
|
291
|
+
says(message) {
|
|
292
|
+
return gitSays(this.config.get())(message);
|
|
293
|
+
}
|
|
285
294
|
/** Handles one gateway request (the raw route's handler). */
|
|
286
295
|
async handle(req, reply) {
|
|
287
296
|
const started = performance.now();
|
|
@@ -289,6 +298,7 @@ let GitGateway = class GitGateway {
|
|
|
289
298
|
const body = req.body instanceof Readable ? req.body : undefined;
|
|
290
299
|
// a refusal closes the connection and stops reading the body: nothing unauthenticated or
|
|
291
300
|
// refused is read further, and nothing it sends is left unbounded
|
|
301
|
+
const said = gitSays(this.config.get());
|
|
292
302
|
const text = (status, message) => {
|
|
293
303
|
fields.status = status;
|
|
294
304
|
if (body !== undefined)
|
|
@@ -298,14 +308,14 @@ let GitGateway = class GitGateway {
|
|
|
298
308
|
.header("content-type", "text/plain; charset=utf-8")
|
|
299
309
|
.header("cache-control", "no-cache")
|
|
300
310
|
.header("connection", "close")
|
|
301
|
-
.send(`${message}\n`);
|
|
311
|
+
.send(`${said(message)}\n`);
|
|
302
312
|
};
|
|
303
313
|
const target = parseGitGatewayPath(req.method, req.url);
|
|
304
314
|
const wrongBody = req.method === "POST"
|
|
305
315
|
? contentTypeOf(req) !== `application/x-${target?.service}-request`
|
|
306
316
|
: body !== undefined;
|
|
307
317
|
if (target === null || wrongBody) {
|
|
308
|
-
return text(404,
|
|
318
|
+
return text(404, NOT_AN_ENDPOINT);
|
|
309
319
|
}
|
|
310
320
|
fields.host = target.host;
|
|
311
321
|
fields.repo = target.repo;
|
|
@@ -318,7 +328,7 @@ let GitGateway = class GitGateway {
|
|
|
318
328
|
if (binding === null)
|
|
319
329
|
return this.done(text(403, TICKET_REFUSED), fields, started);
|
|
320
330
|
if (!binding.hosts.map((h) => h.toLowerCase()).includes(target.host)) {
|
|
321
|
-
return this.done(text(404,
|
|
331
|
+
return this.done(text(404, NOT_AN_ENDPOINT), fields, started);
|
|
322
332
|
}
|
|
323
333
|
if (!repoAllowed(binding.repos, target.repo)) {
|
|
324
334
|
return this.done(text(403, repoRefused(target.repo)), fields, started);
|
|
@@ -327,7 +337,7 @@ let GitGateway = class GitGateway {
|
|
|
327
337
|
const source = (await this.sources.sourcesFor(binding.orgId, binding.accountId)).find((s) => s.host === target.host);
|
|
328
338
|
if (source === undefined) {
|
|
329
339
|
const message = target.service === "git-receive-pack"
|
|
330
|
-
?
|
|
340
|
+
? gitNotConnectedNote(target.host)
|
|
331
341
|
: notConnected(target.host);
|
|
332
342
|
return this.done(text(403, message), fields, started);
|
|
333
343
|
}
|
|
@@ -367,6 +377,7 @@ let GitGateway = class GitGateway {
|
|
|
367
377
|
body: metered,
|
|
368
378
|
fields,
|
|
369
379
|
text,
|
|
380
|
+
said,
|
|
370
381
|
transfer,
|
|
371
382
|
push,
|
|
372
383
|
});
|
|
@@ -472,7 +483,7 @@ let GitGateway = class GitGateway {
|
|
|
472
483
|
return result;
|
|
473
484
|
}
|
|
474
485
|
async relay(req, reply, c) {
|
|
475
|
-
const { target, binding, source, fields, text, transfer, push } = c;
|
|
486
|
+
const { target, binding, source, fields, text, said, transfer, push } = c;
|
|
476
487
|
/** Sets the audit result of a push that was read (a no-op for any other request). */
|
|
477
488
|
const pushResult = (r) => {
|
|
478
489
|
if (push.result !== undefined)
|
|
@@ -493,7 +504,7 @@ let GitGateway = class GitGateway {
|
|
|
493
504
|
.code(200)
|
|
494
505
|
.header("content-type", "application/x-git-receive-pack-advertisement")
|
|
495
506
|
.header("cache-control", "no-cache")
|
|
496
|
-
.send(advertisementError(
|
|
507
|
+
.send(advertisementError(said(refusalNote(target.repo, [], decision))));
|
|
497
508
|
return;
|
|
498
509
|
}
|
|
499
510
|
}
|
|
@@ -544,7 +555,7 @@ let GitGateway = class GitGateway {
|
|
|
544
555
|
.code(200)
|
|
545
556
|
.header("content-type", "application/x-git-receive-pack-result")
|
|
546
557
|
.header("cache-control", "no-cache")
|
|
547
|
-
.send(receivePackRefusal(parsed.capabilities, refs,
|
|
558
|
+
.send(receivePackRefusal(parsed.capabilities, refs, said(note), decision.decision === "ask" ? "needs approval" : "not allowed"));
|
|
548
559
|
return;
|
|
549
560
|
}
|
|
550
561
|
}
|
|
@@ -648,7 +659,7 @@ let GitGateway = class GitGateway {
|
|
|
648
659
|
if (res.status !== 200) {
|
|
649
660
|
await res.body?.cancel().catch(() => { });
|
|
650
661
|
if (res.status === 404 || res.status === 403) {
|
|
651
|
-
text(res.status,
|
|
662
|
+
text(res.status, `${target.host} answered ${res.status} for ${target.repo}.`);
|
|
652
663
|
}
|
|
653
664
|
else {
|
|
654
665
|
text(502, upstreamFailed(target.host, `status ${res.status}`));
|
|
@@ -741,6 +752,14 @@ const contentTypeOf = (req) => String(req.headers["content-type"] ?? "")
|
|
|
741
752
|
?.trim()
|
|
742
753
|
.toLowerCase() ?? "";
|
|
743
754
|
/** The note a refused push carries (the model reads it in the command's output). */
|
|
755
|
+
/**
|
|
756
|
+
* How the gateway prefixes what git prints (`remote: <platform.name>: …`), so a person reading the
|
|
757
|
+
* output of git knows which side refused.
|
|
758
|
+
*/
|
|
759
|
+
export function gitSays(config) {
|
|
760
|
+
const name = productName(config);
|
|
761
|
+
return (message) => `${name}: ${message}`;
|
|
762
|
+
}
|
|
744
763
|
function refusalNote(repo, refs, d) {
|
|
745
764
|
if (d.decision === "ask")
|
|
746
765
|
return gitAskedNote(repo);
|
|
@@ -13,4 +13,4 @@ export declare const GIT_GATEWAY_ROUTE = "/git/v1/*";
|
|
|
13
13
|
* gateway counts bytes against `tools.git.maxBytesPerRun`); any other type is refused by Fastify.
|
|
14
14
|
* HEAD and every other method answer 404. Registered by the api role; call before `app.init()`.
|
|
15
15
|
*/
|
|
16
|
-
export declare function registerGitGatewayRoute(fastify: FastifyInstance, gateway: Pick<GitGateway, "handle">, log: Pick<Logger, "error">): Promise<void>;
|
|
16
|
+
export declare function registerGitGatewayRoute(fastify: FastifyInstance, gateway: Pick<GitGateway, "handle" | "says">, log: Pick<Logger, "error">): Promise<void>;
|
|
@@ -27,9 +27,7 @@ export async function registerGitGatewayRoute(fastify, gateway, log) {
|
|
|
27
27
|
return reply
|
|
28
28
|
.code(status >= 400 && status < 500 ? 404 : 500)
|
|
29
29
|
.header("content-type", "text/plain; charset=utf-8")
|
|
30
|
-
.send(status >= 400 && status < 500
|
|
31
|
-
? "Capybara: not a git smart-HTTP endpoint.\n"
|
|
32
|
-
: "Capybara: internal error.\n");
|
|
30
|
+
.send(`${gateway.says(status >= 400 && status < 500 ? "not a git smart-HTTP endpoint." : "internal error.")}\n`);
|
|
33
31
|
});
|
|
34
32
|
scope.route({
|
|
35
33
|
method: ["GET", "POST"],
|
package/dist/http/app.d.ts
CHANGED
|
@@ -51,7 +51,7 @@ export interface CreateHttpAppOptions {
|
|
|
51
51
|
* The git gateway (`/git/v1/*`, a raw route outside Nest), registered only when given: the
|
|
52
52
|
* kernel passes it when `roles` includes `api`.
|
|
53
53
|
*/
|
|
54
|
-
git?: Pick<GitGateway, "handle">;
|
|
54
|
+
git?: Pick<GitGateway, "handle" | "says">;
|
|
55
55
|
/** 副本标识(`http.replicaId`):设置时每个响应带 `x-capybara-replica` 头。 */
|
|
56
56
|
replicaId?: string | undefined;
|
|
57
57
|
/**
|
|
@@ -31,10 +31,11 @@ export declare function buildRedirect(uri: string, params: Record<string, string
|
|
|
31
31
|
/** Whether `uri` is one of `allowed`, compared as exact strings (no prefix, no case folding). */
|
|
32
32
|
export declare function isAllowedRedirect(uri: string, allowed: readonly string[]): boolean;
|
|
33
33
|
/**
|
|
34
|
-
* The session user agent of an app session
|
|
35
|
-
* `
|
|
34
|
+
* The session user agent of an app session, named by the platform name `product`
|
|
35
|
+
* (`platform.name`): `<product> Desktop/<appVersion> (<name>)` or
|
|
36
|
+
* `<product> Mobile/<appVersion> (<name>)`.
|
|
36
37
|
*/
|
|
37
|
-
export declare const appUserAgent: (g: Pick<CodeGrant, "client" | "appVersion" | "name"
|
|
38
|
+
export declare const appUserAgent: (g: Pick<CodeGrant, "client" | "appVersion" | "name">, product: string) => string;
|
|
38
39
|
/**
|
|
39
40
|
* Native-app sign-in (desktop client spec §6.5, mobile spec §4.3): the authorization code flow with
|
|
40
41
|
* PKCE for native apps (RFC 8252, RFC 7636). The signed-in person consents on the web
|
|
@@ -10,6 +10,7 @@ var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
|
10
10
|
import { createHash, randomBytes, timingSafeEqual } from "node:crypto";
|
|
11
11
|
import { Inject, Injectable } from "@nestjs/common";
|
|
12
12
|
import { sql } from "kysely";
|
|
13
|
+
import { productName } from "../config/product-name.js";
|
|
13
14
|
import { ApiError } from "../errors.js";
|
|
14
15
|
import { KernelConfigService } from "../infra/config/kernel-config.service.js";
|
|
15
16
|
import { KernelDb } from "../infra/database/kernel-db.js";
|
|
@@ -46,15 +47,13 @@ export function buildRedirect(uri, params) {
|
|
|
46
47
|
export function isAllowedRedirect(uri, allowed) {
|
|
47
48
|
return allowed.includes(uri);
|
|
48
49
|
}
|
|
49
|
-
const
|
|
50
|
-
desktop: "Capybara Desktop",
|
|
51
|
-
mobile: "Capybara Mobile",
|
|
52
|
-
};
|
|
50
|
+
const CLIENT_KIND = { desktop: "Desktop", mobile: "Mobile" };
|
|
53
51
|
/**
|
|
54
|
-
* The session user agent of an app session
|
|
55
|
-
* `
|
|
52
|
+
* The session user agent of an app session, named by the platform name `product`
|
|
53
|
+
* (`platform.name`): `<product> Desktop/<appVersion> (<name>)` or
|
|
54
|
+
* `<product> Mobile/<appVersion> (<name>)`.
|
|
56
55
|
*/
|
|
57
|
-
export const appUserAgent = (g) => `${
|
|
56
|
+
export const appUserAgent = (g, product) => `${product} ${CLIENT_KIND[g.client]}/${g.appVersion} (${g.name})`;
|
|
58
57
|
const codeInvalid = () => new ApiError("app_auth.code_invalid", "The sign-in code is invalid, already used or expired; start the sign-in from the app again");
|
|
59
58
|
/**
|
|
60
59
|
* Native-app sign-in (desktop client spec §6.5, mobile spec §4.3): the authorization code flow with
|
|
@@ -169,7 +168,7 @@ let AppAuthService = class AppAuthService {
|
|
|
169
168
|
if (!account)
|
|
170
169
|
throw codeInvalid();
|
|
171
170
|
const session = await this.sessions.create(grant.accountId, {
|
|
172
|
-
userAgent: appUserAgent(grant),
|
|
171
|
+
userAgent: appUserAgent(grant, productName(this.config.get())),
|
|
173
172
|
ip,
|
|
174
173
|
});
|
|
175
174
|
await audit(this.db.db, {
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
2
|
import { type PlatformAttributionPatch, type PlatformAttributionStored, type PlatformAttributionView } from "../attribution/platform-attribution.js";
|
|
3
3
|
import type { KernelSchemaDb } from "../db/kernel-schema.js";
|
|
4
|
+
import { type DevicesDefaultProviderPatch, type DevicesDefaultProviderView } from "../devices/default-provider-setting.js";
|
|
4
5
|
import { KernelConfigService } from "../infra/config/kernel-config.service.js";
|
|
5
6
|
import { KernelDb } from "../infra/database/kernel-db.js";
|
|
6
7
|
import { TransactionHost } from "../infra/database/transaction-host.js";
|
|
@@ -173,6 +174,8 @@ export type DeploymentSettingsView = DeploymentSettings & {
|
|
|
173
174
|
devicesOutsideSandbox: DevicesOutsideSandboxView;
|
|
174
175
|
/** The sandbox network's default and ceiling (the default never above the ceiling). */
|
|
175
176
|
devicesNetwork: DevicesNetworkView;
|
|
177
|
+
/** The device provider that makes a person's default device (null: none) and its source. */
|
|
178
|
+
devicesDefaultProvider: DevicesDefaultProviderView;
|
|
176
179
|
attribution: PlatformAttributionView;
|
|
177
180
|
/** The platform's external sharing switch in effect and where it comes from. */
|
|
178
181
|
externalSharing: ExternalSharingView;
|
|
@@ -246,6 +249,9 @@ export declare const DEPLOYMENT_SETTINGS_PATCH: z.ZodObject<{
|
|
|
246
249
|
open: "open";
|
|
247
250
|
}>>>;
|
|
248
251
|
}, z.core.$strict>>;
|
|
252
|
+
devicesDefaultProvider: z.ZodOptional<z.ZodObject<{
|
|
253
|
+
provider: z.ZodNullable<z.ZodString>;
|
|
254
|
+
}, z.core.$strict>>;
|
|
249
255
|
attribution: z.ZodOptional<z.ZodObject<{
|
|
250
256
|
commit: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
251
257
|
pr: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
@@ -370,6 +376,8 @@ export declare class SettingsService {
|
|
|
370
376
|
checkSharing(patch: Pick<DeploymentSettingsPatch, "externalSharing" | "shareMaxExpiryDays" | "htmlRenderCdnAllowlist">, opts?: {
|
|
371
377
|
onlyNarrows?: boolean;
|
|
372
378
|
}): Promise<void>;
|
|
379
|
+
/** Refuses a `devicesDefaultProvider` change while the startup config sets it. */
|
|
380
|
+
checkDefaultProvider(_patch: DevicesDefaultProviderPatch): void;
|
|
373
381
|
/**
|
|
374
382
|
* The refusals of an `attribution` change against the stored choice: a field set in the startup
|
|
375
383
|
* config (`deployment.setting_readonly`). Returns the next stored choice.
|
|
@@ -11,6 +11,8 @@ import { EXTENSION_NAME_RE } from "@capybara-hq/plugin-sdk";
|
|
|
11
11
|
import { Inject, Injectable } from "@nestjs/common";
|
|
12
12
|
import { z } from "zod";
|
|
13
13
|
import { applyPlatformAttributionPatch, PLATFORM_ATTRIBUTION_FIELDS, PLATFORM_ATTRIBUTION_PATCH, PLATFORM_ATTRIBUTION_SETTING, readStoredPlatformAttribution, resolvePlatformAttribution, } from "../attribution/platform-attribution.js";
|
|
14
|
+
import { productName } from "../config/product-name.js";
|
|
15
|
+
import { DEVICES_DEFAULT_PROVIDER_PATCH, DEVICES_DEFAULT_PROVIDER_SETTING, readPlatformDefaultProvider, } from "../devices/default-provider-setting.js";
|
|
14
16
|
import { ApiError } from "../errors.js";
|
|
15
17
|
import { KernelConfigService } from "../infra/config/kernel-config.service.js";
|
|
16
18
|
import { KernelDb } from "../infra/database/kernel-db.js";
|
|
@@ -304,6 +306,12 @@ export const DEPLOYMENT_SETTINGS_PATCH = z
|
|
|
304
306
|
* startup config is read-only (409 `deployment.setting_readonly`).
|
|
305
307
|
*/
|
|
306
308
|
devicesNetwork: DEVICES_NETWORK_PATCH.optional(),
|
|
309
|
+
/**
|
|
310
|
+
* The platform's default device provider (the `device-provider@1` extension that makes a
|
|
311
|
+
* person's default device): `provider` replaced, null clears it (back to none). A value set in
|
|
312
|
+
* the startup config is read-only (409 `deployment.setting_readonly`).
|
|
313
|
+
*/
|
|
314
|
+
devicesDefaultProvider: DEVICES_DEFAULT_PROVIDER_PATCH.optional(),
|
|
307
315
|
/**
|
|
308
316
|
* The platform's attribution defaults for agent-created git commits and pull requests (spec
|
|
309
317
|
* 2026-11-14-agent-attribution): each given field replaces the stored one, null clears it
|
|
@@ -515,18 +523,20 @@ let SettingsService = class SettingsService {
|
|
|
515
523
|
}
|
|
516
524
|
/** The settings with the platform's device sandbox settings and attribution defaults in effect. */
|
|
517
525
|
async view() {
|
|
518
|
-
const [settings, deviceSandbox, attribution, externalSharing, shareMaxExpiryDays, promptSuggestions,] = await Promise.all([
|
|
526
|
+
const [settings, deviceSandbox, attribution, externalSharing, shareMaxExpiryDays, promptSuggestions, devicesDefaultProvider,] = await Promise.all([
|
|
519
527
|
this.get(),
|
|
520
528
|
readDeviceSandboxSettingsView(this.db.db, this.config, this.log),
|
|
521
529
|
readStoredPlatformAttribution(this.db.db, this.log),
|
|
522
530
|
readExternalSharing(this.db.db, this.config, this.log),
|
|
523
531
|
readShareMaxExpiry(this.db.db, this.config, this.log),
|
|
524
532
|
readPromptSuggestions(this.db.db, this.log),
|
|
533
|
+
readPlatformDefaultProvider(this.config, this.db.db, this.log),
|
|
525
534
|
]);
|
|
526
535
|
return {
|
|
527
536
|
...settings,
|
|
528
537
|
devicesOutsideSandbox: deviceSandbox.outsideSandbox,
|
|
529
538
|
devicesNetwork: deviceSandbox.network,
|
|
539
|
+
devicesDefaultProvider,
|
|
530
540
|
attribution: this.attributionView(attribution),
|
|
531
541
|
externalSharing,
|
|
532
542
|
shareMaxExpiryDays,
|
|
@@ -534,12 +544,15 @@ let SettingsService = class SettingsService {
|
|
|
534
544
|
};
|
|
535
545
|
}
|
|
536
546
|
attributionView(stored) {
|
|
537
|
-
const
|
|
547
|
+
const current = this.config.get();
|
|
538
548
|
const sources = Object.fromEntries(PLATFORM_ATTRIBUTION_FIELDS.map((f) => [
|
|
539
549
|
f,
|
|
540
550
|
this.config.fieldSource(`attribution.${f}`) ?? (stored[f] !== undefined ? "db" : "default"),
|
|
541
551
|
]));
|
|
542
|
-
return {
|
|
552
|
+
return {
|
|
553
|
+
...resolvePlatformAttribution(current.attribution, stored, productName(current)),
|
|
554
|
+
sources,
|
|
555
|
+
};
|
|
543
556
|
}
|
|
544
557
|
/** The cloud devices following the platform's network default (their org sets none). */
|
|
545
558
|
async devicesFollowingPlatformDefault() {
|
|
@@ -654,6 +667,13 @@ let SettingsService = class SettingsService {
|
|
|
654
667
|
throw sharingWidenRefused("htmlRenderCdnAllowlist", `Adding origins to the HTML CDN allowlist (${added.join(", ")}) needs a super admin in the admin console; an API token or the Platform tool may only remove origins.`);
|
|
655
668
|
}
|
|
656
669
|
}
|
|
670
|
+
/** Refuses a `devicesDefaultProvider` change while the startup config sets it. */
|
|
671
|
+
checkDefaultProvider(_patch) {
|
|
672
|
+
const source = this.config.fieldSource("devices.defaultProvider");
|
|
673
|
+
if (source === undefined)
|
|
674
|
+
return;
|
|
675
|
+
throw new ApiError("deployment.setting_readonly", "The default device provider is set in the startup config (file, Nacos or environment) and is read-only here: devicesDefaultProvider", [{ path: "devicesDefaultProvider.provider", source }]);
|
|
676
|
+
}
|
|
657
677
|
/**
|
|
658
678
|
* The refusals of an `attribution` change against the stored choice: a field set in the startup
|
|
659
679
|
* config (`deployment.setting_readonly`). Returns the next stored choice.
|
|
@@ -914,6 +934,13 @@ let SettingsService = class SettingsService {
|
|
|
914
934
|
writes.push([key, value]);
|
|
915
935
|
}
|
|
916
936
|
}
|
|
937
|
+
if (patch.devicesDefaultProvider !== undefined) {
|
|
938
|
+
this.checkDefaultProvider(patch.devicesDefaultProvider);
|
|
939
|
+
if (patch.devicesDefaultProvider.provider === null)
|
|
940
|
+
deletes.push(DEVICES_DEFAULT_PROVIDER_SETTING);
|
|
941
|
+
else
|
|
942
|
+
writes.push([DEVICES_DEFAULT_PROVIDER_SETTING, patch.devicesDefaultProvider]);
|
|
943
|
+
}
|
|
917
944
|
if (patch.promptSuggestions === null)
|
|
918
945
|
deletes.push(PROMPT_SUGGESTIONS_SETTING);
|
|
919
946
|
else if (patch.promptSuggestions !== undefined) {
|
package/dist/identity/sso.d.ts
CHANGED
|
@@ -17,7 +17,7 @@ export declare const SSO_CALLBACK_TIMEOUT_MS = 15000;
|
|
|
17
17
|
* 登录失败的原因码(放进回跳 URL `/login?error=<code>`,界面按码走 i18n;不回显身份源的任何文本)。
|
|
18
18
|
* `auth.account_disabled` 与 API 错误码同名。
|
|
19
19
|
*/
|
|
20
|
-
export type SsoLoginError = "sso.unavailable" | "sso.state_invalid" | "sso.session_mismatch" | "sso.access_denied" | "sso.provider_error" | "sso.identity_not_verified" | "auth.account_disabled";
|
|
20
|
+
export type SsoLoginError = "sso.unavailable" | "sso.state_invalid" | "sso.session_mismatch" | "sso.access_denied" | "sso.provider_error" | "sso.account_not_allowed" | "sso.identity_not_verified" | "auth.account_disabled";
|
|
21
21
|
/** 一个有效的浏览器绑定值(复用请求里已有的,否则新生成)。 */
|
|
22
22
|
export declare function ssoBrowserBinding(existing: string | undefined): string;
|
|
23
23
|
/** 回跳页面:站内相对路径(以单个 `/` 开头,非 `//`),否则 `/`(防开放重定向)。 */
|
|
@@ -69,12 +69,18 @@ export declare class SsoFlow {
|
|
|
69
69
|
*/
|
|
70
70
|
start(plugin: string, returnTo: string | undefined, binding: string, sessionAccountId?: string): Promise<string>;
|
|
71
71
|
/**
|
|
72
|
-
*
|
|
73
|
-
*
|
|
74
|
-
*
|
|
75
|
-
*
|
|
76
|
-
*
|
|
77
|
-
*
|
|
72
|
+
* Handles the identity source's redirect back. The state is read and deleted in one step (it can
|
|
73
|
+
* never be used again, whatever the outcome); a state that belongs to another plugin →
|
|
74
|
+
* `sso.state_invalid`; a browser binding cookie that does not match → `sso.session_mismatch`.
|
|
75
|
+
* Errors from the identity source map only to reason codes: a deliberate refusal
|
|
76
|
+
* (`IdentitySourceRefused`) → `sso.account_not_allowed`, any other error → `sso.provider_error`.
|
|
77
|
+
* The source key the plugin returns must be the one the kernel derives
|
|
78
|
+
* (`${plugin}:${identity.tenantId}`, Ruling A19), otherwise it is refused as `sso.provider_error`.
|
|
79
|
+
* An identity row created through an IM binding link, when the start and the callback were not
|
|
80
|
+
* made by the same signed-in account → `sso.identity_not_verified` (Ruling A18). On success it
|
|
81
|
+
* resolves to an account (without checking the account's status; the caller handles that).
|
|
82
|
+
* `sessionAccountId`: the account of the web session the callback request already carries
|
|
83
|
+
* (omitted when signed out).
|
|
78
84
|
*/
|
|
79
85
|
callback(plugin: string, query: Record<string, string>, binding: string | undefined, sessionAccountId?: string): Promise<SsoCallbackResult>;
|
|
80
86
|
}
|
package/dist/identity/sso.js
CHANGED
|
@@ -8,7 +8,7 @@ var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
|
8
8
|
return function (target, key) { decorator(target, key, paramIndex); }
|
|
9
9
|
};
|
|
10
10
|
import { createHash, randomBytes, timingSafeEqual } from "node:crypto";
|
|
11
|
-
import { IDENTITY_SOURCE_EXTENSION_POINT, } from "@capybara-hq/plugin-sdk";
|
|
11
|
+
import { IDENTITY_SOURCE_EXTENSION_POINT, isIdentitySourceRefused, } from "@capybara-hq/plugin-sdk";
|
|
12
12
|
import { Inject, Injectable } from "@nestjs/common";
|
|
13
13
|
import { ApiError } from "../errors.js";
|
|
14
14
|
import { ExtensionRegistry } from "../extensions/registry.js";
|
|
@@ -143,12 +143,18 @@ let SsoFlow = class SsoFlow {
|
|
|
143
143
|
return url;
|
|
144
144
|
}
|
|
145
145
|
/**
|
|
146
|
-
*
|
|
147
|
-
*
|
|
148
|
-
*
|
|
149
|
-
*
|
|
150
|
-
*
|
|
151
|
-
*
|
|
146
|
+
* Handles the identity source's redirect back. The state is read and deleted in one step (it can
|
|
147
|
+
* never be used again, whatever the outcome); a state that belongs to another plugin →
|
|
148
|
+
* `sso.state_invalid`; a browser binding cookie that does not match → `sso.session_mismatch`.
|
|
149
|
+
* Errors from the identity source map only to reason codes: a deliberate refusal
|
|
150
|
+
* (`IdentitySourceRefused`) → `sso.account_not_allowed`, any other error → `sso.provider_error`.
|
|
151
|
+
* The source key the plugin returns must be the one the kernel derives
|
|
152
|
+
* (`${plugin}:${identity.tenantId}`, Ruling A19), otherwise it is refused as `sso.provider_error`.
|
|
153
|
+
* An identity row created through an IM binding link, when the start and the callback were not
|
|
154
|
+
* made by the same signed-in account → `sso.identity_not_verified` (Ruling A18). On success it
|
|
155
|
+
* resolves to an account (without checking the account's status; the caller handles that).
|
|
156
|
+
* `sessionAccountId`: the account of the web session the callback request already carries
|
|
157
|
+
* (omitted when signed out).
|
|
152
158
|
*/
|
|
153
159
|
async callback(plugin, query, binding, sessionAccountId) {
|
|
154
160
|
const state = query.state;
|
|
@@ -184,6 +190,14 @@ let SsoFlow = class SsoFlow {
|
|
|
184
190
|
});
|
|
185
191
|
}
|
|
186
192
|
catch (err) {
|
|
193
|
+
// A deliberate refusal gets its own code; its message goes to the log only, never the URL
|
|
194
|
+
if (isIdentitySourceRefused(err)) {
|
|
195
|
+
this.log.warn("identity source refused the account", {
|
|
196
|
+
plugin,
|
|
197
|
+
reason: err.message,
|
|
198
|
+
});
|
|
199
|
+
return { ok: false, error: "sso.account_not_allowed" };
|
|
200
|
+
}
|
|
187
201
|
this.log.warn("identity source callback failed", { plugin, err });
|
|
188
202
|
return { ok: false, error: "sso.provider_error" };
|
|
189
203
|
}
|