@axiom-lattice/protocols 7.1.0 → 7.3.0
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/.turbo/turbo-build.log +10 -10
- package/CHANGELOG.md +179 -0
- package/dist/index.d.mts +740 -8
- package/dist/index.d.ts +740 -8
- package/dist/index.js +184 -0
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +161 -0
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/AuthProviderProtocol.ts +80 -0
- package/src/InviteLinkStoreProtocol.ts +59 -0
- package/src/McpLatticeProtocol.ts +2 -2
- package/src/McpServerConfigStoreProtocol.ts +118 -0
- package/src/ModelProviderProtocol.ts +20 -4
- package/src/OidcIdentityClaimStoreProtocol.ts +117 -0
- package/src/OidcProviderConfigStoreProtocol.ts +84 -0
- package/src/PlatformAuditProtocol.ts +80 -0
- package/src/PlatformInvitationStoreProtocol.ts +60 -0
- package/src/PlatformMemberStoreProtocol.ts +23 -0
- package/src/PlatformOpsProtocol.ts +73 -0
- package/src/PlatformSettingsProtocol.ts +161 -0
- package/src/SandboxPluginProtocol.ts +1 -1
- package/src/UserExternalIdentityStoreProtocol.ts +53 -0
- package/src/__tests__/AuthProviderProtocol.test.ts +20 -0
- package/src/index.ts +10 -0
package/package.json
CHANGED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
/** Interactive login surface. Machine credentials are not part of this extension point. */
|
|
2
|
+
export type LoginSurface = "console";
|
|
3
|
+
|
|
4
|
+
/** One selectable sign-in method for a UI. */
|
|
5
|
+
export interface AuthProviderDescriptor {
|
|
6
|
+
id: string;
|
|
7
|
+
displayName: string;
|
|
8
|
+
interaction: "form" | "redirect" | "none";
|
|
9
|
+
surfaces: LoginSurface[];
|
|
10
|
+
/**
|
|
11
|
+
* True when the form provider is only an emergency local account and normal
|
|
12
|
+
* password sign-in is disabled. UIs should label it instead of treating it as
|
|
13
|
+
* the default sign-in method.
|
|
14
|
+
*/
|
|
15
|
+
breakGlassOnly?: boolean;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/** Authenticated external identity. Contains no tenant or authorization data. */
|
|
19
|
+
export interface Principal {
|
|
20
|
+
subject: string;
|
|
21
|
+
method: string;
|
|
22
|
+
email?: string;
|
|
23
|
+
emailVerified?: boolean;
|
|
24
|
+
name?: string;
|
|
25
|
+
/** IdP-provided avatar URL (OIDC `picture`); validated only at render time. */
|
|
26
|
+
picture?: string;
|
|
27
|
+
tenantHint?: string;
|
|
28
|
+
claims?: Record<string, unknown>;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/** A cookie a provider asks the route layer to set. */
|
|
32
|
+
export interface AuthCookie {
|
|
33
|
+
name: string;
|
|
34
|
+
value: string;
|
|
35
|
+
options: {
|
|
36
|
+
httpOnly?: boolean;
|
|
37
|
+
secure?: boolean;
|
|
38
|
+
sameSite?: "lax" | "strict" | "none";
|
|
39
|
+
path?: string;
|
|
40
|
+
maxAge?: number;
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export type AuthChallenge =
|
|
45
|
+
| { kind: "redirect"; url: string; cookies?: AuthCookie[] }
|
|
46
|
+
| { kind: "form"; fields: Array<{ name: string; label: string; secret?: boolean }> }
|
|
47
|
+
| { kind: "none" };
|
|
48
|
+
|
|
49
|
+
export interface AuthRequestContext {
|
|
50
|
+
surface: LoginSurface;
|
|
51
|
+
tenantId?: string;
|
|
52
|
+
params?: Record<string, string>;
|
|
53
|
+
cookies?: Record<string, string>;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export interface AuthProvider {
|
|
57
|
+
readonly descriptor: AuthProviderDescriptor;
|
|
58
|
+
begin?(ctx: AuthRequestContext): Promise<AuthChallenge>;
|
|
59
|
+
callback?(ctx: AuthRequestContext): Promise<Principal>;
|
|
60
|
+
verify?(ctx: AuthRequestContext & { credential: unknown }): Promise<Principal>;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export type AuthErrorCode =
|
|
64
|
+
| "INVALID_CREDENTIALS"
|
|
65
|
+
| "PROVIDER_ERROR"
|
|
66
|
+
| "TENANT_UNAVAILABLE"
|
|
67
|
+
| "INVALID_STATE"
|
|
68
|
+
| "EMAIL_REQUIRED"
|
|
69
|
+
| "NOT_PROVISIONED";
|
|
70
|
+
|
|
71
|
+
export class AuthError extends Error {
|
|
72
|
+
constructor(
|
|
73
|
+
readonly code: AuthErrorCode,
|
|
74
|
+
readonly status: 400 | 401 | 502,
|
|
75
|
+
message: string,
|
|
76
|
+
) {
|
|
77
|
+
super(message);
|
|
78
|
+
this.name = "AuthError";
|
|
79
|
+
}
|
|
80
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import type { PlatformRole } from "./PlatformMemberStoreProtocol";
|
|
2
|
+
import type { UserTenantRole } from "./UserTenantLinkProtocol";
|
|
3
|
+
|
|
4
|
+
export type InviteLinkScope = "platform" | "tenant";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* A bearer invitation link. The token is stored encrypted at rest and also
|
|
8
|
+
* hashed for lookup; the plaintext token is only returned to platform admins
|
|
9
|
+
* who are allowed to manage the link.
|
|
10
|
+
*/
|
|
11
|
+
export interface InviteLink {
|
|
12
|
+
id: string;
|
|
13
|
+
scope: InviteLinkScope;
|
|
14
|
+
token: string;
|
|
15
|
+
tokenHash: string;
|
|
16
|
+
email?: string;
|
|
17
|
+
platformRole?: PlatformRole;
|
|
18
|
+
tenantId?: string;
|
|
19
|
+
tenantRole?: UserTenantRole;
|
|
20
|
+
createdBy?: string;
|
|
21
|
+
createdAt: Date;
|
|
22
|
+
updatedAt: Date;
|
|
23
|
+
expiresAt: Date;
|
|
24
|
+
maxUses: number;
|
|
25
|
+
usedCount: number;
|
|
26
|
+
revokedAt?: Date;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export interface CreateInviteLinkInput {
|
|
30
|
+
id: string;
|
|
31
|
+
scope: InviteLinkScope;
|
|
32
|
+
token: string;
|
|
33
|
+
tokenHash: string;
|
|
34
|
+
email?: string;
|
|
35
|
+
platformRole?: PlatformRole;
|
|
36
|
+
tenantId?: string;
|
|
37
|
+
tenantRole?: UserTenantRole;
|
|
38
|
+
createdBy?: string;
|
|
39
|
+
expiresAt: Date;
|
|
40
|
+
maxUses: number;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export interface InviteLinkStore {
|
|
44
|
+
list(): Promise<InviteLink[]>;
|
|
45
|
+
get(id: string): Promise<InviteLink | null>;
|
|
46
|
+
getByTokenHash(tokenHash: string): Promise<InviteLink | null>;
|
|
47
|
+
create(input: CreateInviteLinkInput): Promise<InviteLink>;
|
|
48
|
+
/**
|
|
49
|
+
* Atomically consumes one use of a live link.
|
|
50
|
+
*
|
|
51
|
+
* Returns null when the link is missing, revoked, expired, or exhausted.
|
|
52
|
+
*/
|
|
53
|
+
consume(tokenHash: string, now: Date): Promise<InviteLink | null>;
|
|
54
|
+
revoke(id: string, now: Date): Promise<InviteLink | null>;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export function normalizeInviteLinkEmail(email: string): string {
|
|
58
|
+
return email.trim().toLowerCase();
|
|
59
|
+
}
|
|
@@ -11,7 +11,7 @@ import { BaseLatticeProtocol, LatticeMessage } from "./BaseLatticeProtocol";
|
|
|
11
11
|
/**
|
|
12
12
|
* MCP transport type
|
|
13
13
|
*/
|
|
14
|
-
export type McpTransportType = "stdio" | "streamable_http"
|
|
14
|
+
export type McpTransportType = "stdio" | "streamable_http";
|
|
15
15
|
|
|
16
16
|
/**
|
|
17
17
|
* MCP protocol era selection for client connections.
|
|
@@ -41,7 +41,7 @@ export interface McpServerConfig {
|
|
|
41
41
|
/** Environment variables (stdio transport; credentials passed to the server process) */
|
|
42
42
|
env?: Record<string, string>;
|
|
43
43
|
/**
|
|
44
|
-
* Custom HTTP headers sent with every request (streamable_http
|
|
44
|
+
* Custom HTTP headers sent with every request (streamable_http only).
|
|
45
45
|
* Commonly used for authentication, e.g. `{ Authorization: "Bearer <token>" }`.
|
|
46
46
|
* Ignored for stdio transport. Values are encrypted at rest by config stores.
|
|
47
47
|
*/
|
|
@@ -21,6 +21,12 @@ export interface McpServerConfigEntry {
|
|
|
21
21
|
*/
|
|
22
22
|
tenantId: string;
|
|
23
23
|
|
|
24
|
+
/**
|
|
25
|
+
* Personal assistant that owns this configuration, when it belongs to the
|
|
26
|
+
* personal data domain. Tenant-scoped entries leave this undefined.
|
|
27
|
+
*/
|
|
28
|
+
ownerAssistantId?: string;
|
|
29
|
+
|
|
24
30
|
/**
|
|
25
31
|
* Business key for the configuration (unique within tenant)
|
|
26
32
|
*/
|
|
@@ -227,3 +233,115 @@ export interface McpServerConfigStore {
|
|
|
227
233
|
*/
|
|
228
234
|
hasConfig(tenantId: string, id: string): Promise<boolean>;
|
|
229
235
|
}
|
|
236
|
+
|
|
237
|
+
/**
|
|
238
|
+
* MCP server configuration owned by one personal assistant.
|
|
239
|
+
*
|
|
240
|
+
* Personal configs live in a separate store surface so tenant-only code paths
|
|
241
|
+
* can never read them by accident; the owning assistant id is part of every
|
|
242
|
+
* lookup key.
|
|
243
|
+
*/
|
|
244
|
+
export interface PersonalMcpServerConfigEntry extends McpServerConfigEntry {
|
|
245
|
+
/** Personal assistant that owns this configuration. */
|
|
246
|
+
ownerAssistantId: string;
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
/**
|
|
250
|
+
* Store operations for the personal MCP data domain.
|
|
251
|
+
*
|
|
252
|
+
* Every method scopes by `(tenantId, ownerAssistantId)`. Implementations must
|
|
253
|
+
* never merge personal rows into the tenant-only methods of
|
|
254
|
+
* {@link McpServerConfigStore}.
|
|
255
|
+
*/
|
|
256
|
+
export interface PersonalMcpServerConfigStore {
|
|
257
|
+
/** List all personal MCP configs belonging to one assistant. */
|
|
258
|
+
getAllConfigsForAssistant(
|
|
259
|
+
tenantId: string,
|
|
260
|
+
ownerAssistantId: string,
|
|
261
|
+
): Promise<PersonalMcpServerConfigEntry[]>;
|
|
262
|
+
|
|
263
|
+
/**
|
|
264
|
+
* List every personal MCP config across tenants.
|
|
265
|
+
*
|
|
266
|
+
* Intended for operations and tests only; startup restoration must not call
|
|
267
|
+
* it (personal connections are established lazily).
|
|
268
|
+
*/
|
|
269
|
+
getAllPersonalConfigsWithoutTenant(): Promise<PersonalMcpServerConfigEntry[]>;
|
|
270
|
+
|
|
271
|
+
/** Get one personal config by id, scoped to its assistant. */
|
|
272
|
+
getConfigByIdForAssistant(
|
|
273
|
+
tenantId: string,
|
|
274
|
+
ownerAssistantId: string,
|
|
275
|
+
id: string,
|
|
276
|
+
): Promise<PersonalMcpServerConfigEntry | null>;
|
|
277
|
+
|
|
278
|
+
/** Get one personal config by business key, scoped to its assistant. */
|
|
279
|
+
getConfigByKeyForAssistant(
|
|
280
|
+
tenantId: string,
|
|
281
|
+
ownerAssistantId: string,
|
|
282
|
+
key: string,
|
|
283
|
+
): Promise<PersonalMcpServerConfigEntry | null>;
|
|
284
|
+
|
|
285
|
+
/** Create a personal config for one assistant. */
|
|
286
|
+
createConfigForAssistant(
|
|
287
|
+
tenantId: string,
|
|
288
|
+
ownerAssistantId: string,
|
|
289
|
+
id: string,
|
|
290
|
+
data: CreateMcpServerConfigRequest,
|
|
291
|
+
): Promise<PersonalMcpServerConfigEntry>;
|
|
292
|
+
|
|
293
|
+
/** Update a personal config by id, scoped to its assistant. */
|
|
294
|
+
updateConfigForAssistant(
|
|
295
|
+
tenantId: string,
|
|
296
|
+
ownerAssistantId: string,
|
|
297
|
+
id: string,
|
|
298
|
+
updates: Partial<UpdateMcpServerConfigRequest>,
|
|
299
|
+
): Promise<PersonalMcpServerConfigEntry | null>;
|
|
300
|
+
|
|
301
|
+
/** Delete one personal config by id; returns whether a row was removed. */
|
|
302
|
+
deleteConfigForAssistant(
|
|
303
|
+
tenantId: string,
|
|
304
|
+
ownerAssistantId: string,
|
|
305
|
+
id: string,
|
|
306
|
+
): Promise<boolean>;
|
|
307
|
+
|
|
308
|
+
/** Delete every personal config owned by one assistant; returns the count. */
|
|
309
|
+
deleteConfigsForAssistant(
|
|
310
|
+
tenantId: string,
|
|
311
|
+
ownerAssistantId: string,
|
|
312
|
+
): Promise<number>;
|
|
313
|
+
|
|
314
|
+
/** Check whether a personal config id exists for one assistant. */
|
|
315
|
+
hasConfigForAssistant(
|
|
316
|
+
tenantId: string,
|
|
317
|
+
ownerAssistantId: string,
|
|
318
|
+
id: string,
|
|
319
|
+
): Promise<boolean>;
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
/** A store that serves both the tenant and personal MCP data domains. */
|
|
323
|
+
export type McpConfigStoreWithPersonal =
|
|
324
|
+
McpServerConfigStore & PersonalMcpServerConfigStore;
|
|
325
|
+
|
|
326
|
+
/**
|
|
327
|
+
* Narrow a store to the personal MCP surface at runtime.
|
|
328
|
+
*
|
|
329
|
+
* Custom hosts may register a tenant-only MCP store; callers use this guard to
|
|
330
|
+
* degrade gracefully instead of assuming the personal methods exist.
|
|
331
|
+
*/
|
|
332
|
+
export function isPersonalMcpServerConfigStore(
|
|
333
|
+
store: McpServerConfigStore,
|
|
334
|
+
): store is McpConfigStoreWithPersonal {
|
|
335
|
+
const candidate = store as Partial<PersonalMcpServerConfigStore>;
|
|
336
|
+
return (
|
|
337
|
+
typeof candidate.getAllConfigsForAssistant === "function" &&
|
|
338
|
+
typeof candidate.getAllPersonalConfigsWithoutTenant === "function" &&
|
|
339
|
+
typeof candidate.getConfigByIdForAssistant === "function" &&
|
|
340
|
+
typeof candidate.getConfigByKeyForAssistant === "function" &&
|
|
341
|
+
typeof candidate.createConfigForAssistant === "function" &&
|
|
342
|
+
typeof candidate.updateConfigForAssistant === "function" &&
|
|
343
|
+
typeof candidate.deleteConfigForAssistant === "function" &&
|
|
344
|
+
typeof candidate.deleteConfigsForAssistant === "function" &&
|
|
345
|
+
typeof candidate.hasConfigForAssistant === "function"
|
|
346
|
+
);
|
|
347
|
+
}
|
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
10
|
import type { LLMConfig } from "./ModelLatticeProtocol";
|
|
11
|
+
import { PLATFORM_TENANT_ID } from "./PlatformOpsProtocol";
|
|
11
12
|
|
|
12
13
|
/**
|
|
13
14
|
* Wire protocol used to talk to the upstream provider.
|
|
@@ -65,6 +66,20 @@ export const DEFAULT_MODEL_KEY = "default";
|
|
|
65
66
|
export const EMBEDDING_DEFAULT_KEY = "default:embedding";
|
|
66
67
|
export const ASR_DEFAULT_KEY = "default:asr";
|
|
67
68
|
|
|
69
|
+
/**
|
|
70
|
+
* Reserved tenant id for the platform-owned model provider catalog.
|
|
71
|
+
*
|
|
72
|
+
* The platform catalog lives in the same encrypted `modelProvider` store as a
|
|
73
|
+
* tenant's own providers, under this reserved id. It is deliberately distinct
|
|
74
|
+
* from the deployment `"default"` namespace, which holds the models registered
|
|
75
|
+
* from environment configuration at boot.
|
|
76
|
+
*
|
|
77
|
+
* Resolution uses it as the second step: a tenant with providers of its own
|
|
78
|
+
* never reaches it, a tenant with none falls back to it while it has providers,
|
|
79
|
+
* and only an empty platform catalog falls through to the deployment namespace.
|
|
80
|
+
*/
|
|
81
|
+
export const PLATFORM_MODEL_TENANT_ID = PLATFORM_TENANT_ID;
|
|
82
|
+
|
|
68
83
|
/**
|
|
69
84
|
* Build the tenant-scoped model key.
|
|
70
85
|
*
|
|
@@ -445,11 +460,12 @@ export interface ModelSelection {
|
|
|
445
460
|
*/
|
|
446
461
|
kind?: ModelKind;
|
|
447
462
|
/**
|
|
448
|
-
* Whether this is the tenant's default model.
|
|
463
|
+
* Whether this is the tenant's default model of its kind.
|
|
449
464
|
*
|
|
450
|
-
*
|
|
451
|
-
*
|
|
452
|
-
*
|
|
465
|
+
* The flag is scoped per *(tenant, kind)*: at most one chat model, one
|
|
466
|
+
* embedding model, and one ASR model may carry it. Omitted means "leave the
|
|
467
|
+
* stored flag alone"; a default can only be replaced, never dropped by
|
|
468
|
+
* omission — see `ModelProviderStore.getDefaultModel`.
|
|
453
469
|
*/
|
|
454
470
|
isDefault?: boolean;
|
|
455
471
|
}
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import type { PlatformRole } from "./PlatformMemberStoreProtocol";
|
|
2
|
+
import type { UserTenantRole } from "./UserTenantLinkProtocol";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Pending SSO identity claims.
|
|
6
|
+
*
|
|
7
|
+
* A claim is created when an enterprise IdP authenticates a user without an
|
|
8
|
+
* email. It deliberately does not create a user or link an external identity
|
|
9
|
+
* until a platform administrator reviews it. This keeps unverified,
|
|
10
|
+
* user-entered email separate from local accounts and lets an admin either
|
|
11
|
+
* create a new user or explicitly link the SSO identity to an existing one.
|
|
12
|
+
*/
|
|
13
|
+
export type OidcIdentityClaimStatus =
|
|
14
|
+
| "pending"
|
|
15
|
+
| "approved"
|
|
16
|
+
| "rejected"
|
|
17
|
+
| "expired";
|
|
18
|
+
|
|
19
|
+
export interface OidcIdentityClaim {
|
|
20
|
+
id: string;
|
|
21
|
+
providerId: string;
|
|
22
|
+
issuer: string;
|
|
23
|
+
subject: string;
|
|
24
|
+
email: string;
|
|
25
|
+
name?: string;
|
|
26
|
+
picture?: string;
|
|
27
|
+
status: OidcIdentityClaimStatus;
|
|
28
|
+
createdAt: Date;
|
|
29
|
+
updatedAt: Date;
|
|
30
|
+
expiresAt: Date;
|
|
31
|
+
reviewedBy?: string;
|
|
32
|
+
reviewedAt?: Date;
|
|
33
|
+
linkedUserId?: string;
|
|
34
|
+
/** Where the request came from; omitted for legacy email-completion claims. */
|
|
35
|
+
source?: "email_completion" | "invite_link";
|
|
36
|
+
inviteLinkId?: string;
|
|
37
|
+
/** Existing user the request is about, for invite links. */
|
|
38
|
+
requestedUserId?: string;
|
|
39
|
+
requestedPlatformRole?: PlatformRole;
|
|
40
|
+
requestedTenantId?: string;
|
|
41
|
+
requestedTenantRole?: UserTenantRole;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export interface CreateOidcIdentityClaimInput {
|
|
45
|
+
id: string;
|
|
46
|
+
providerId: string;
|
|
47
|
+
issuer: string;
|
|
48
|
+
subject: string;
|
|
49
|
+
email: string;
|
|
50
|
+
name?: string;
|
|
51
|
+
picture?: string;
|
|
52
|
+
expiresAt: Date;
|
|
53
|
+
source?: "email_completion" | "invite_link";
|
|
54
|
+
inviteLinkId?: string;
|
|
55
|
+
requestedUserId?: string;
|
|
56
|
+
requestedPlatformRole?: PlatformRole;
|
|
57
|
+
requestedTenantId?: string;
|
|
58
|
+
requestedTenantRole?: UserTenantRole;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export interface UpdateOidcIdentityClaimInput {
|
|
62
|
+
email?: string;
|
|
63
|
+
name?: string;
|
|
64
|
+
picture?: string;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export interface OidcIdentityClaimApproval {
|
|
68
|
+
reviewedBy: string;
|
|
69
|
+
linkedUserId: string;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export interface OidcIdentityClaimStore {
|
|
73
|
+
/** Lists claims in a stable order, optionally filtered by status. */
|
|
74
|
+
list(status?: OidcIdentityClaimStatus): Promise<OidcIdentityClaim[]>;
|
|
75
|
+
get(id: string): Promise<OidcIdentityClaim | null>;
|
|
76
|
+
/** Returns the live pending claim for a subject, or null. */
|
|
77
|
+
getPendingBySubject(
|
|
78
|
+
providerId: string,
|
|
79
|
+
issuer: string,
|
|
80
|
+
subject: string,
|
|
81
|
+
now: Date,
|
|
82
|
+
): Promise<OidcIdentityClaim | null>;
|
|
83
|
+
/**
|
|
84
|
+
* Creates a pending claim.
|
|
85
|
+
*
|
|
86
|
+
* Expired pending claims for the same subject are marked `expired` rather
|
|
87
|
+
* than blocking a retry. A live pending claim raises
|
|
88
|
+
* {@link OidcIdentityClaimConflictError}.
|
|
89
|
+
*/
|
|
90
|
+
create(input: CreateOidcIdentityClaimInput): Promise<OidcIdentityClaim>;
|
|
91
|
+
/** Updates the requested profile of a live pending claim. */
|
|
92
|
+
updatePending(
|
|
93
|
+
id: string,
|
|
94
|
+
updates: UpdateOidcIdentityClaimInput,
|
|
95
|
+
now: Date,
|
|
96
|
+
): Promise<OidcIdentityClaim | null>;
|
|
97
|
+
/** Approves a live pending claim with CAS semantics. */
|
|
98
|
+
approve(
|
|
99
|
+
id: string,
|
|
100
|
+
approval: OidcIdentityClaimApproval,
|
|
101
|
+
now: Date,
|
|
102
|
+
): Promise<OidcIdentityClaim | null>;
|
|
103
|
+
/** Rejects a live pending claim with CAS semantics. */
|
|
104
|
+
reject(id: string, reviewedBy: string, now: Date): Promise<OidcIdentityClaim | null>;
|
|
105
|
+
delete(id: string): Promise<boolean>;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
export class OidcIdentityClaimConflictError extends Error {
|
|
109
|
+
constructor(readonly providerId: string, readonly issuer: string, readonly subject: string) {
|
|
110
|
+
super("A pending SSO identity claim already exists for this subject");
|
|
111
|
+
this.name = "OidcIdentityClaimConflictError";
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
export function normalizeOidcIdentityEmail(email: string): string {
|
|
116
|
+
return email.trim().toLowerCase();
|
|
117
|
+
}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
export interface OidcProviderConfig {
|
|
2
|
+
id: string;
|
|
3
|
+
displayName: string;
|
|
4
|
+
issuer: string;
|
|
5
|
+
clientId: string;
|
|
6
|
+
clientSecret: string;
|
|
7
|
+
scopes: string;
|
|
8
|
+
enabled: boolean;
|
|
9
|
+
jitProvisioning: boolean;
|
|
10
|
+
autoLinkEmail: boolean;
|
|
11
|
+
defaultTenantId?: string;
|
|
12
|
+
/**
|
|
13
|
+
* Exact hostnames allowed to resolve to a private address for this provider.
|
|
14
|
+
*
|
|
15
|
+
* `undefined` falls back to the deployment allowlist; an explicit empty array
|
|
16
|
+
* denies all private-network issuers for this provider.
|
|
17
|
+
*/
|
|
18
|
+
allowedPrivateHosts?: string[];
|
|
19
|
+
createdAt: Date;
|
|
20
|
+
updatedAt: Date;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export interface CreateOidcProviderConfigInput {
|
|
24
|
+
displayName: string;
|
|
25
|
+
issuer: string;
|
|
26
|
+
clientId: string;
|
|
27
|
+
clientSecret: string;
|
|
28
|
+
scopes: string;
|
|
29
|
+
enabled: boolean;
|
|
30
|
+
jitProvisioning: boolean;
|
|
31
|
+
autoLinkEmail: boolean;
|
|
32
|
+
defaultTenantId?: string;
|
|
33
|
+
allowedPrivateHosts?: string[];
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export interface UpdateOidcProviderConfigInput {
|
|
37
|
+
displayName?: string;
|
|
38
|
+
issuer?: string;
|
|
39
|
+
clientId?: string;
|
|
40
|
+
clientSecret?: string;
|
|
41
|
+
scopes?: string;
|
|
42
|
+
enabled?: boolean;
|
|
43
|
+
jitProvisioning?: boolean;
|
|
44
|
+
autoLinkEmail?: boolean;
|
|
45
|
+
defaultTenantId?: string | null;
|
|
46
|
+
allowedPrivateHosts?: string[];
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Normalizes an allowed-private-hosts list by trimming and lowercasing each
|
|
51
|
+
* entry and removing duplicates. Empty entries are preserved; callers that
|
|
52
|
+
* accept user input must reject them before calling this helper.
|
|
53
|
+
*
|
|
54
|
+
* @param values - Raw hostname entries.
|
|
55
|
+
* @returns Deduplicated, normalized hostname entries.
|
|
56
|
+
*/
|
|
57
|
+
export function normalizeAllowedPrivateHosts(
|
|
58
|
+
values: readonly string[],
|
|
59
|
+
): string[] {
|
|
60
|
+
return [...new Set(values.map((value) => value.trim().toLowerCase()))];
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export class OidcProviderConfigConflictError extends Error {
|
|
64
|
+
readonly code = "OIDC_PROVIDER_CONFIG_CONFLICT";
|
|
65
|
+
|
|
66
|
+
constructor(readonly id: string) {
|
|
67
|
+
super(`OIDC provider config "${id}" already exists`);
|
|
68
|
+
this.name = "OidcProviderConfigConflictError";
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export interface OidcProviderConfigStore {
|
|
73
|
+
list(): Promise<OidcProviderConfig[]>;
|
|
74
|
+
get(id: string): Promise<OidcProviderConfig | null>;
|
|
75
|
+
create(
|
|
76
|
+
id: string,
|
|
77
|
+
input: CreateOidcProviderConfigInput,
|
|
78
|
+
): Promise<OidcProviderConfig>;
|
|
79
|
+
update(
|
|
80
|
+
id: string,
|
|
81
|
+
updates: UpdateOidcProviderConfigInput,
|
|
82
|
+
): Promise<OidcProviderConfig | null>;
|
|
83
|
+
delete(id: string): Promise<boolean>;
|
|
84
|
+
}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
/** Actor on whose behalf a platform-level audit record was produced. */
|
|
2
|
+
export type PlatformAuditInitiator =
|
|
3
|
+
| { type: "human"; userId: string; role: "owner" | "admin" | "auditor" }
|
|
4
|
+
| { type: "bootstrap" }
|
|
5
|
+
| { type: "system"; component: string };
|
|
6
|
+
|
|
7
|
+
/** Execution surface that performed the audited platform operation. */
|
|
8
|
+
export type PlatformAuditExecutor =
|
|
9
|
+
| { type: "admin_center"; route: string }
|
|
10
|
+
| {
|
|
11
|
+
type: "ops_agent";
|
|
12
|
+
agentId: "platform-ops";
|
|
13
|
+
threadId: string;
|
|
14
|
+
runId: string;
|
|
15
|
+
toolName: string;
|
|
16
|
+
}
|
|
17
|
+
| { type: "bootstrap" }
|
|
18
|
+
| { type: "system"; component: string };
|
|
19
|
+
|
|
20
|
+
/** Entry point that originated a platform-level audit record. */
|
|
21
|
+
export type PlatformAuditSource =
|
|
22
|
+
| "admin_center"
|
|
23
|
+
| "ops_agent"
|
|
24
|
+
| "bootstrap"
|
|
25
|
+
| "system";
|
|
26
|
+
|
|
27
|
+
/** Kind of platform operation captured by an audit record. */
|
|
28
|
+
export type PlatformAuditAction = "write" | "playbook";
|
|
29
|
+
|
|
30
|
+
/** Terminal outcome of the audited operation. */
|
|
31
|
+
export type PlatformAuditStatus = "ok" | "error" | "cancelled";
|
|
32
|
+
|
|
33
|
+
/** Input accepted when appending a platform audit record. */
|
|
34
|
+
export interface PlatformAuditAppendInput {
|
|
35
|
+
initiator: PlatformAuditInitiator;
|
|
36
|
+
source: PlatformAuditSource;
|
|
37
|
+
executor: PlatformAuditExecutor;
|
|
38
|
+
tenantId?: string;
|
|
39
|
+
action: PlatformAuditAction;
|
|
40
|
+
status: PlatformAuditStatus;
|
|
41
|
+
summary: Record<string, unknown>;
|
|
42
|
+
before?: Record<string, unknown>;
|
|
43
|
+
after?: Record<string, unknown>;
|
|
44
|
+
errorCode?: string;
|
|
45
|
+
durationMs: number;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/** Persisted platform audit record. */
|
|
49
|
+
export interface PlatformAuditRecord extends PlatformAuditAppendInput {
|
|
50
|
+
id: string;
|
|
51
|
+
createdAt: Date;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Filter and pagination options for querying platform audit records.
|
|
56
|
+
*
|
|
57
|
+
* Results are ordered newest-first by `createdAt` descending, then by `id`
|
|
58
|
+
* descending as a total-order tie-break. `from` is inclusive and `to` is
|
|
59
|
+
* exclusive on `createdAt`. `limit` defaults to 100; negative `offset` and
|
|
60
|
+
* `limit` values are clamped to 0. `initiatorUserId` matches human initiators
|
|
61
|
+
* only.
|
|
62
|
+
*/
|
|
63
|
+
export interface PlatformAuditQuery {
|
|
64
|
+
initiatorUserId?: string;
|
|
65
|
+
source?: PlatformAuditSource;
|
|
66
|
+
tenantId?: string;
|
|
67
|
+
action?: PlatformAuditAction;
|
|
68
|
+
status?: PlatformAuditStatus;
|
|
69
|
+
from?: string;
|
|
70
|
+
to?: string;
|
|
71
|
+
limit?: number;
|
|
72
|
+
offset?: number;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/** Persistence operations for platform audit records. */
|
|
76
|
+
export interface PlatformAuditStore {
|
|
77
|
+
append(record: PlatformAuditAppendInput): Promise<PlatformAuditRecord>;
|
|
78
|
+
get(id: string): Promise<PlatformAuditRecord | null>;
|
|
79
|
+
query(params: PlatformAuditQuery): Promise<PlatformAuditRecord[]>;
|
|
80
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import type { PlatformRole } from "./PlatformMemberStoreProtocol";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Normalizes a platform invitation email for storage and lookup.
|
|
5
|
+
*
|
|
6
|
+
* Emails are trimmed and lower-cased so the same address maps to a single
|
|
7
|
+
* invitation regardless of caller formatting.
|
|
8
|
+
*
|
|
9
|
+
* @param email Raw email address supplied by a caller.
|
|
10
|
+
* @returns The normalized email address.
|
|
11
|
+
*/
|
|
12
|
+
export function normalizePlatformInvitationEmail(email: string): string {
|
|
13
|
+
return email.trim().toLowerCase();
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/** Durable invitation for a platform-level role, keyed by normalized email. */
|
|
17
|
+
export interface PlatformInvitation {
|
|
18
|
+
/** Normalized (trimmed, lower-cased) invitee email. */
|
|
19
|
+
email: string;
|
|
20
|
+
/** Platform role granted when the invitation is consumed. */
|
|
21
|
+
role: PlatformRole;
|
|
22
|
+
/** User id of the platform owner/admin who created the invitation. */
|
|
23
|
+
invitedBy?: string;
|
|
24
|
+
/** When the invitation was created. */
|
|
25
|
+
createdAt: Date;
|
|
26
|
+
/** Optional expiry; invitations at or after this instant cannot be consumed. */
|
|
27
|
+
expiresAt?: Date;
|
|
28
|
+
/** When the invitation was consumed, or omitted while pending. */
|
|
29
|
+
consumedAt?: Date;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Persistence operations for platform invitations.
|
|
34
|
+
*
|
|
35
|
+
* Implementations normalize emails on every write and lookup. All operations
|
|
36
|
+
* are idempotent with respect to normalization.
|
|
37
|
+
*/
|
|
38
|
+
export interface PlatformInvitationStore {
|
|
39
|
+
/** Lists every invitation, ordered by normalized email. */
|
|
40
|
+
list(): Promise<PlatformInvitation[]>;
|
|
41
|
+
/** Returns the invitation for an email, or null. */
|
|
42
|
+
get(email: string): Promise<PlatformInvitation | null>;
|
|
43
|
+
/**
|
|
44
|
+
* Inserts or replaces an invitation keyed by normalized email.
|
|
45
|
+
*
|
|
46
|
+
* The supplied invitation replaces any existing row in full (last write wins),
|
|
47
|
+
* including `expiresAt` and `consumedAt`.
|
|
48
|
+
*/
|
|
49
|
+
upsert(invitation: PlatformInvitation): Promise<PlatformInvitation>;
|
|
50
|
+
/** Deletes an invitation. Returns whether a row was removed. */
|
|
51
|
+
delete(email: string): Promise<boolean>;
|
|
52
|
+
/**
|
|
53
|
+
* Atomically consumes a pending, unexpired invitation.
|
|
54
|
+
*
|
|
55
|
+
* A row is consumable only when `consumedAt` is unset and `expiresAt` is
|
|
56
|
+
* unset or strictly after `at`. Returns the consumed invitation, or null
|
|
57
|
+
* when the row is missing, already consumed, or expired.
|
|
58
|
+
*/
|
|
59
|
+
consume(email: string, at: Date): Promise<PlatformInvitation | null>;
|
|
60
|
+
}
|