@authyon/server 0.2.0-beta.3 → 0.2.0-beta.5
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/README.md +7 -1
- package/dist/authorization-NQe6R3am.d.cts +989 -0
- package/dist/authorization-NQe6R3am.d.ts +989 -0
- package/dist/chunk-24IFDJ73.js +490 -0
- package/dist/index.cjs +4 -0
- package/dist/index.d.cts +4 -975
- package/dist/index.d.ts +4 -975
- package/dist/index.js +23 -470
- package/dist/next.cjs +328 -0
- package/dist/next.d.cts +26 -0
- package/dist/next.d.ts +26 -0
- package/dist/next.js +47 -0
- package/package.json +20 -5
|
@@ -0,0 +1,989 @@
|
|
|
1
|
+
import { JSONWebKeySet, JWTPayload, JWSHeaderParameters } from 'jose';
|
|
2
|
+
|
|
3
|
+
interface HttpAdapterRequest {
|
|
4
|
+
url: string;
|
|
5
|
+
method: string;
|
|
6
|
+
headers: Record<string, string>;
|
|
7
|
+
body?: BodyInit | null;
|
|
8
|
+
signal: AbortSignal;
|
|
9
|
+
}
|
|
10
|
+
/** Transport contract accepted by both Authyon clients. */
|
|
11
|
+
interface HttpAdapter {
|
|
12
|
+
request(request: HttpAdapterRequest): Promise<Response>;
|
|
13
|
+
}
|
|
14
|
+
type HttpLogEvent = {
|
|
15
|
+
type: "request";
|
|
16
|
+
method: string;
|
|
17
|
+
url: string;
|
|
18
|
+
timestamp: number;
|
|
19
|
+
} | {
|
|
20
|
+
type: "response";
|
|
21
|
+
method: string;
|
|
22
|
+
url: string;
|
|
23
|
+
status: number;
|
|
24
|
+
durationMs: number;
|
|
25
|
+
requestId?: string;
|
|
26
|
+
timestamp: number;
|
|
27
|
+
} | {
|
|
28
|
+
type: "error";
|
|
29
|
+
method: string;
|
|
30
|
+
url: string;
|
|
31
|
+
errorName: string;
|
|
32
|
+
durationMs: number;
|
|
33
|
+
timestamp: number;
|
|
34
|
+
};
|
|
35
|
+
/** Receives sanitized HTTP lifecycle events. Headers, bodies and query values are never exposed. */
|
|
36
|
+
type HttpLogger = (event: HttpLogEvent) => void;
|
|
37
|
+
/**
|
|
38
|
+
* Mutable logging configuration. Change `enabled` at runtime to enable or disable logging
|
|
39
|
+
* without recreating the Authyon client.
|
|
40
|
+
*/
|
|
41
|
+
interface HttpLoggerOptions {
|
|
42
|
+
enabled: boolean;
|
|
43
|
+
logger?: HttpLogger;
|
|
44
|
+
}
|
|
45
|
+
/** Default adapter backed by the platform's Fetch API. */
|
|
46
|
+
declare class FetchHttpAdapter implements HttpAdapter {
|
|
47
|
+
private readonly fetchImpl;
|
|
48
|
+
constructor(fetchImpl?: typeof fetch);
|
|
49
|
+
request(request: HttpAdapterRequest): Promise<Response>;
|
|
50
|
+
}
|
|
51
|
+
/** Adds safe, configurable lifecycle logging to any HTTP adapter. */
|
|
52
|
+
declare class LoggingHttpAdapter implements HttpAdapter {
|
|
53
|
+
private readonly adapter;
|
|
54
|
+
private readonly options;
|
|
55
|
+
constructor(adapter: HttpAdapter, options: HttpLoggerOptions);
|
|
56
|
+
request(request: HttpAdapterRequest): Promise<Response>;
|
|
57
|
+
private log;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
interface PaginationOptions {
|
|
61
|
+
skip?: number;
|
|
62
|
+
take?: number;
|
|
63
|
+
}
|
|
64
|
+
interface Paged<T> {
|
|
65
|
+
data: T[];
|
|
66
|
+
perPage?: number;
|
|
67
|
+
pageSize: number;
|
|
68
|
+
total: number;
|
|
69
|
+
pages: number;
|
|
70
|
+
hasNext: boolean;
|
|
71
|
+
hasPrev: boolean;
|
|
72
|
+
}
|
|
73
|
+
interface IntrospectResult {
|
|
74
|
+
active: boolean;
|
|
75
|
+
sub?: string;
|
|
76
|
+
username?: string | null;
|
|
77
|
+
email?: string | null;
|
|
78
|
+
roles?: string[] | null;
|
|
79
|
+
permissions?: string[];
|
|
80
|
+
client_id?: string;
|
|
81
|
+
scope?: string;
|
|
82
|
+
exp?: number;
|
|
83
|
+
iat?: number;
|
|
84
|
+
jti?: string;
|
|
85
|
+
token_type?: string;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/** GET/POST /env/tenants — confirmed against the live API. */
|
|
89
|
+
interface Organization {
|
|
90
|
+
id: string;
|
|
91
|
+
slug: string;
|
|
92
|
+
name?: string;
|
|
93
|
+
description?: string | null;
|
|
94
|
+
environmentId?: string;
|
|
95
|
+
workspaceId?: string;
|
|
96
|
+
isDisabled?: boolean;
|
|
97
|
+
memberCount?: number;
|
|
98
|
+
createdAt?: string;
|
|
99
|
+
updatedAt?: string;
|
|
100
|
+
}
|
|
101
|
+
/** One of a user's tenant memberships, as embedded in `EnvironmentUser.tenantMemberships`. */
|
|
102
|
+
interface TenantMembership {
|
|
103
|
+
tenantId: string;
|
|
104
|
+
tenantSlug: string;
|
|
105
|
+
tenantName: string;
|
|
106
|
+
tenantDisabled: boolean;
|
|
107
|
+
roles: string[];
|
|
108
|
+
}
|
|
109
|
+
/** Lightweight user shape returned by `introspect()`/`validate()`. */
|
|
110
|
+
interface User {
|
|
111
|
+
id: string;
|
|
112
|
+
email: string;
|
|
113
|
+
username?: string;
|
|
114
|
+
/** Environment-level roles from the database-validated user profile. */
|
|
115
|
+
roles?: string[];
|
|
116
|
+
permissions?: string[];
|
|
117
|
+
}
|
|
118
|
+
interface RoleGrant {
|
|
119
|
+
role: string;
|
|
120
|
+
expiresAt?: string | null;
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Full user record from the EnvironmentManagement plane
|
|
124
|
+
* (`environment.users.get()` / `.list()`), confirmed against the live API.
|
|
125
|
+
* `get()` returns every field below; `list()` returns a subset (no
|
|
126
|
+
* `failedLoginAttempts`, `lockedOutUntil`, `roleGrants`,
|
|
127
|
+
* `directPermissions`, `effectivePermissions`, `refreshTokens`,
|
|
128
|
+
* `tenantMemberships`, `totpConfirmedAt`, `emailOtpEnabledAt`,
|
|
129
|
+
* `remainingRecoveryCodes`, `disableReason`, `suspension`, `deleteReason`,
|
|
130
|
+
* `customFields` — and `suspendedUntil` instead of `suspension`).
|
|
131
|
+
*/
|
|
132
|
+
interface EnvironmentUser {
|
|
133
|
+
id: string;
|
|
134
|
+
email: string;
|
|
135
|
+
username?: string;
|
|
136
|
+
firstName?: string | null;
|
|
137
|
+
lastName?: string | null;
|
|
138
|
+
emailConfirmed: boolean;
|
|
139
|
+
isDisabled: boolean;
|
|
140
|
+
createdAt: string;
|
|
141
|
+
lastLoginAt?: string | null;
|
|
142
|
+
failedLoginAttempts?: number;
|
|
143
|
+
lockedOutUntil?: string | null;
|
|
144
|
+
roles: string[];
|
|
145
|
+
roleGrants?: RoleGrant[];
|
|
146
|
+
directPermissions?: string[];
|
|
147
|
+
effectivePermissions?: string[];
|
|
148
|
+
/** Confirmed shape unknown — empty in every response seen so far. */
|
|
149
|
+
refreshTokens?: unknown[];
|
|
150
|
+
tenantIds: string[];
|
|
151
|
+
tenantMemberships?: TenantMembership[];
|
|
152
|
+
/** Flattened role names across all tenant memberships (list() only). */
|
|
153
|
+
tenantRoles?: string[];
|
|
154
|
+
twoFactorMethods: string[];
|
|
155
|
+
totpConfirmedAt?: string | null;
|
|
156
|
+
emailOtpEnabledAt?: string | null;
|
|
157
|
+
remainingRecoveryCodes?: number;
|
|
158
|
+
disableReason?: string | null;
|
|
159
|
+
suspension?: unknown | null;
|
|
160
|
+
suspendedUntil?: string | null;
|
|
161
|
+
deletedAt?: string | null;
|
|
162
|
+
deleteReason?: string | null;
|
|
163
|
+
/** JSON-encoded string. */
|
|
164
|
+
customFields?: string;
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* POST /auth/validate — confirmed against the live API. The wire shape is
|
|
168
|
+
* `{ valid, reason, profile }`, not `{ user, organization }` as the
|
|
169
|
+
* OpenAPI schema (which didn't document response bodies) suggested.
|
|
170
|
+
* `profile` is `null` for machine tokens (there's no user behind them) and
|
|
171
|
+
* for tokens that fail validation.
|
|
172
|
+
*/
|
|
173
|
+
interface ValidateResult {
|
|
174
|
+
valid: boolean;
|
|
175
|
+
reason?: string | null;
|
|
176
|
+
user: User | null;
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* A role available within an environment or one of its tenants. Confirmed
|
|
180
|
+
* live: system roles carry no `id`/`description` (only `name` +
|
|
181
|
+
* `permissions`) — both are only populated for custom roles you create.
|
|
182
|
+
*/
|
|
183
|
+
interface Role {
|
|
184
|
+
id?: string | null;
|
|
185
|
+
name: string;
|
|
186
|
+
description?: string | null;
|
|
187
|
+
permissions: string[];
|
|
188
|
+
}
|
|
189
|
+
interface RoleInput {
|
|
190
|
+
name: string;
|
|
191
|
+
description?: string;
|
|
192
|
+
permissions?: string[];
|
|
193
|
+
}
|
|
194
|
+
/**
|
|
195
|
+
* GET /env/roles and GET /tenant/roles group results by origin instead of
|
|
196
|
+
* returning a flat array — confirmed live for the environment endpoint.
|
|
197
|
+
*/
|
|
198
|
+
interface RoleList {
|
|
199
|
+
custom: Role[];
|
|
200
|
+
system: Role[];
|
|
201
|
+
}
|
|
202
|
+
/** A permission entry as it appears nested under a role in `PermissionsByRole`. */
|
|
203
|
+
interface Permission {
|
|
204
|
+
value: string;
|
|
205
|
+
description?: string | null;
|
|
206
|
+
/** Confirmed live: `null` for the built-in catalog: no separate id per entry. */
|
|
207
|
+
catalogId?: string | null;
|
|
208
|
+
}
|
|
209
|
+
/** A role entry as returned by GET /env/permissions, with its permissions nested. */
|
|
210
|
+
interface RolePermissions {
|
|
211
|
+
roleId: string | null;
|
|
212
|
+
name: string;
|
|
213
|
+
description?: string | null;
|
|
214
|
+
isSystem: boolean;
|
|
215
|
+
permissions: Permission[];
|
|
216
|
+
}
|
|
217
|
+
/** GET /env/permissions — confirmed live: grouped by role, plus any orphaned entries. */
|
|
218
|
+
interface PermissionsByRole {
|
|
219
|
+
roles: RolePermissions[];
|
|
220
|
+
orphans: Permission[];
|
|
221
|
+
}
|
|
222
|
+
/** GET /permissions/reserved — confirmed live: wrapped, not a bare string array. */
|
|
223
|
+
interface ReservedPermissions {
|
|
224
|
+
namespace: string;
|
|
225
|
+
items: string[];
|
|
226
|
+
}
|
|
227
|
+
interface CreatePermissionInput {
|
|
228
|
+
value: string;
|
|
229
|
+
description?: string;
|
|
230
|
+
/** Attach the new permission to this role immediately. */
|
|
231
|
+
attachToRoleId?: string;
|
|
232
|
+
}
|
|
233
|
+
interface CreateOrganizationInput {
|
|
234
|
+
name: string;
|
|
235
|
+
slug: string;
|
|
236
|
+
description?: string;
|
|
237
|
+
}
|
|
238
|
+
interface UpdateOrganizationInput {
|
|
239
|
+
name: string;
|
|
240
|
+
description?: string;
|
|
241
|
+
}
|
|
242
|
+
interface CreateUserInput {
|
|
243
|
+
email: string;
|
|
244
|
+
username: string;
|
|
245
|
+
password: string;
|
|
246
|
+
emailConfirmed?: boolean;
|
|
247
|
+
roles?: string[];
|
|
248
|
+
/** Tenants (organizations) to add the user to on creation. */
|
|
249
|
+
tenantIds?: string[];
|
|
250
|
+
}
|
|
251
|
+
/** GET /env/audit — one audit-trail entry, confirmed against the live API. */
|
|
252
|
+
interface AuditEvent {
|
|
253
|
+
id: string;
|
|
254
|
+
occurredAt: string;
|
|
255
|
+
eventType: string;
|
|
256
|
+
/** JSON-encoded string — `JSON.parse` it for the event-specific payload. */
|
|
257
|
+
payloadJson?: string;
|
|
258
|
+
workspaceId?: string;
|
|
259
|
+
environmentId?: string;
|
|
260
|
+
actorUserId?: string | null;
|
|
261
|
+
actorType?: string;
|
|
262
|
+
actorIp?: string;
|
|
263
|
+
userAgent?: string;
|
|
264
|
+
tenantId?: string | null;
|
|
265
|
+
}
|
|
266
|
+
/**
|
|
267
|
+
* GET /env/audit/login-activity. Not confirmed with a populated example
|
|
268
|
+
* live (the test environment had none) — assumed to share `AuditEvent`'s
|
|
269
|
+
* shape, since login activity is the same underlying audit-event stream
|
|
270
|
+
* filtered to sign-in events.
|
|
271
|
+
*/
|
|
272
|
+
type LoginActivity = AuditEvent;
|
|
273
|
+
/**
|
|
274
|
+
* Envelope every `skip`/`take`-paginated list endpoint returns, confirmed
|
|
275
|
+
* live for `/env/users`, `/env/audit` and `/env/audit/login-activity`.
|
|
276
|
+
* Endpoints without `skip`/`take` params return a bare array instead.
|
|
277
|
+
*/
|
|
278
|
+
/** Tenant credential metadata. Listing never returns the secret. */
|
|
279
|
+
interface TenantCredentialSummary {
|
|
280
|
+
id: string;
|
|
281
|
+
clientId: string;
|
|
282
|
+
description: string | null;
|
|
283
|
+
createdAt: string;
|
|
284
|
+
lastUsedAt: string | null;
|
|
285
|
+
revokedAt: string | null;
|
|
286
|
+
expiresAt: string | null;
|
|
287
|
+
isActive: boolean;
|
|
288
|
+
permissions: string[];
|
|
289
|
+
}
|
|
290
|
+
/** Input for a tenant machine credential. Requires at least one explicit permission. */
|
|
291
|
+
interface CreateTenantCredentialInput {
|
|
292
|
+
description: string;
|
|
293
|
+
/** Number of days until the tenant credential expires. Omit for no automatic expiration. */
|
|
294
|
+
lifetimeDays?: number | null;
|
|
295
|
+
permissions: string[];
|
|
296
|
+
}
|
|
297
|
+
/** The plaintext secret is returned only when the credential is issued. */
|
|
298
|
+
interface TenantCredentialIssued {
|
|
299
|
+
credentialId: string;
|
|
300
|
+
clientId: string;
|
|
301
|
+
clientSecret: string;
|
|
302
|
+
createdAt: string;
|
|
303
|
+
expiresAt: string | null;
|
|
304
|
+
permissions: string[];
|
|
305
|
+
}
|
|
306
|
+
/** OAuth 2.0 client-credentials pair minted in the Authyon console. */
|
|
307
|
+
interface ClientCredentials {
|
|
308
|
+
clientId: string;
|
|
309
|
+
clientSecret: string;
|
|
310
|
+
}
|
|
311
|
+
/** Standard OAuth 2.0 client-credentials token response. */
|
|
312
|
+
interface TokenResult {
|
|
313
|
+
access_token: string;
|
|
314
|
+
token_type: string;
|
|
315
|
+
expires_in: number;
|
|
316
|
+
scope?: string;
|
|
317
|
+
}
|
|
318
|
+
/** POST /tenant/auth/validate — validates the current tenant-client bearer. */
|
|
319
|
+
interface TenantClientValidationResult {
|
|
320
|
+
valid: boolean;
|
|
321
|
+
reason?: string | null;
|
|
322
|
+
tenantId: string;
|
|
323
|
+
workspaceId: string;
|
|
324
|
+
environmentId: string;
|
|
325
|
+
credentialId: string;
|
|
326
|
+
clientId: string;
|
|
327
|
+
permissions: string[];
|
|
328
|
+
}
|
|
329
|
+
interface JsonWebKeySet {
|
|
330
|
+
keys: Record<string, unknown>[];
|
|
331
|
+
}
|
|
332
|
+
interface OpenIdConfiguration {
|
|
333
|
+
issuer: string;
|
|
334
|
+
jwks_uri: string;
|
|
335
|
+
authorization_endpoint?: string;
|
|
336
|
+
token_endpoint?: string;
|
|
337
|
+
[key: string]: unknown;
|
|
338
|
+
}
|
|
339
|
+
interface AuthyonServerClientOptions {
|
|
340
|
+
/**
|
|
341
|
+
* Publishable environment key (`pk_live_...` / `pk_test_...`), sent as
|
|
342
|
+
* `X-Authyon-Environment`. Required on **every** call — it selects the
|
|
343
|
+
* environment (Test / Live) that a request applies to, independently of
|
|
344
|
+
* whichever bearer token authenticates it.
|
|
345
|
+
*/
|
|
346
|
+
envKey?: string;
|
|
347
|
+
/**
|
|
348
|
+
* Environment-level OAuth client credentials (`ec_...` / secret), minted
|
|
349
|
+
* in the console. Required for everything under `environment.*` and
|
|
350
|
+
* `permissions.*` — the SDK exchanges them for a short-lived access token
|
|
351
|
+
* via `POST /env/oauth/token` and refreshes it transparently.
|
|
352
|
+
*/
|
|
353
|
+
clientId?: string;
|
|
354
|
+
clientSecret?: string;
|
|
355
|
+
/** API origin. Defaults to `https://api.authyon.com`. */
|
|
356
|
+
baseUrl?: string;
|
|
357
|
+
/** Allow an HTTP `baseUrl`. Intended only for explicitly trusted local development. */
|
|
358
|
+
allowInsecureHttp?: boolean;
|
|
359
|
+
/** Maximum duration of each HTTP request. Defaults to 15 seconds; set to `0` to disable. */
|
|
360
|
+
timeoutMs?: number;
|
|
361
|
+
/** Custom HTTP adapter for tracing, mocks or an alternative HTTP stack. */
|
|
362
|
+
httpAdapter?: HttpAdapter;
|
|
363
|
+
/** Safe HTTP lifecycle logging. Disabled unless this option is provided with `enabled: true`. */
|
|
364
|
+
httpLogger?: HttpLoggerOptions;
|
|
365
|
+
/** @deprecated Prefer `httpAdapter: new FetchHttpAdapter(customFetch)`. */
|
|
366
|
+
fetch?: typeof fetch;
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
/** A token of the requested authentication plane, or a provider called for each request. */
|
|
370
|
+
type AccessTokenSource = string | (() => string | Promise<string>);
|
|
371
|
+
interface CredentialListOptions extends PaginationOptions {
|
|
372
|
+
search?: string;
|
|
373
|
+
}
|
|
374
|
+
/** scopes is an alias for permissions. Always supply an explicit, nonempty set. */
|
|
375
|
+
type CredentialPermissionsInput = {
|
|
376
|
+
permissions: readonly string[];
|
|
377
|
+
scopes?: never;
|
|
378
|
+
} | {
|
|
379
|
+
scopes: readonly string[];
|
|
380
|
+
permissions?: never;
|
|
381
|
+
};
|
|
382
|
+
type CreateCredentialInput = CredentialPermissionsInput & {
|
|
383
|
+
description?: string;
|
|
384
|
+
lifetimeDays?: number | null;
|
|
385
|
+
};
|
|
386
|
+
interface CredentialScope {
|
|
387
|
+
workspaceId: string;
|
|
388
|
+
environmentId: string;
|
|
389
|
+
tenantId?: string;
|
|
390
|
+
}
|
|
391
|
+
interface TenantManagementScope extends CredentialScope {
|
|
392
|
+
tenantId: string;
|
|
393
|
+
}
|
|
394
|
+
interface CredentialCreator {
|
|
395
|
+
id: string | null;
|
|
396
|
+
type: string;
|
|
397
|
+
displayName: string | null;
|
|
398
|
+
}
|
|
399
|
+
interface CredentialDetail extends TenantCredentialSummary {
|
|
400
|
+
createdBy: CredentialCreator | null;
|
|
401
|
+
updatedAt: string | null;
|
|
402
|
+
secretRotatedAt: string | null;
|
|
403
|
+
expiresAt: string | null;
|
|
404
|
+
ageSeconds: number;
|
|
405
|
+
/** Null while active; elapsed lifetime at revocation otherwise. */
|
|
406
|
+
lifetimeSeconds: number | null;
|
|
407
|
+
accessTokenLifetimeSeconds: number;
|
|
408
|
+
}
|
|
409
|
+
type WorkspaceRole = "admin" | "auditor";
|
|
410
|
+
interface WorkspaceMember {
|
|
411
|
+
memberId: string | null;
|
|
412
|
+
userId: string;
|
|
413
|
+
email: string;
|
|
414
|
+
name: string;
|
|
415
|
+
role: string;
|
|
416
|
+
isOwner: boolean;
|
|
417
|
+
isSelf: boolean;
|
|
418
|
+
invitedByName: string | null;
|
|
419
|
+
joinedAt: string;
|
|
420
|
+
lastLoginAt: string | null;
|
|
421
|
+
}
|
|
422
|
+
interface WorkspaceInvite {
|
|
423
|
+
id: string;
|
|
424
|
+
email: string;
|
|
425
|
+
role: string;
|
|
426
|
+
invitedByName: string | null;
|
|
427
|
+
createdAt: string;
|
|
428
|
+
expiresAt: string;
|
|
429
|
+
}
|
|
430
|
+
interface WorkspaceTeam {
|
|
431
|
+
workspaceId: string;
|
|
432
|
+
workspaceName: string;
|
|
433
|
+
callerRole: string;
|
|
434
|
+
canManage: boolean;
|
|
435
|
+
members: WorkspaceMember[];
|
|
436
|
+
pendingInvites: WorkspaceInvite[];
|
|
437
|
+
}
|
|
438
|
+
interface InviteWorkspaceMemberInput {
|
|
439
|
+
email: string;
|
|
440
|
+
role: WorkspaceRole;
|
|
441
|
+
}
|
|
442
|
+
interface WorkspaceInviteIssued {
|
|
443
|
+
inviteId: string;
|
|
444
|
+
email: string;
|
|
445
|
+
role: string;
|
|
446
|
+
/** Sensitive bearer link returned at issuance. Do not log or persist in public storage. */
|
|
447
|
+
acceptUrl: string;
|
|
448
|
+
expiresAt: string;
|
|
449
|
+
}
|
|
450
|
+
interface WorkspaceInvitePreview {
|
|
451
|
+
workspaceName: string;
|
|
452
|
+
email: string;
|
|
453
|
+
role: string;
|
|
454
|
+
expiresAt: string;
|
|
455
|
+
requiresRegistration: boolean;
|
|
456
|
+
}
|
|
457
|
+
interface WorkspaceInviteAccepted {
|
|
458
|
+
workspaceId: string;
|
|
459
|
+
workspaceName: string;
|
|
460
|
+
role: string;
|
|
461
|
+
accountCreated: boolean;
|
|
462
|
+
}
|
|
463
|
+
interface AcceptWorkspaceInviteInput {
|
|
464
|
+
name?: string;
|
|
465
|
+
password?: string;
|
|
466
|
+
}
|
|
467
|
+
interface InviteTenantMemberInput {
|
|
468
|
+
email: string;
|
|
469
|
+
roles?: string[];
|
|
470
|
+
}
|
|
471
|
+
interface TenantMember {
|
|
472
|
+
userId: string;
|
|
473
|
+
email: string;
|
|
474
|
+
username: string;
|
|
475
|
+
roles: string[];
|
|
476
|
+
createdAt: string;
|
|
477
|
+
lastLoginAt: string | null;
|
|
478
|
+
}
|
|
479
|
+
type TenantMemberPage = Paged<TenantMember>;
|
|
480
|
+
|
|
481
|
+
type QueryParams = object;
|
|
482
|
+
|
|
483
|
+
type HttpMethod = "GET" | "POST" | "PUT" | "PATCH" | "DELETE";
|
|
484
|
+
interface JsonRequestOptions {
|
|
485
|
+
method?: HttpMethod;
|
|
486
|
+
body?: unknown;
|
|
487
|
+
query?: QueryParams;
|
|
488
|
+
headers?: Record<string, string>;
|
|
489
|
+
}
|
|
490
|
+
|
|
491
|
+
type ManagementRequest = <T>(path: string, options?: JsonRequestOptions) => Promise<T>;
|
|
492
|
+
|
|
493
|
+
/** Platform user administration. Never falls back to an environment machine token. */
|
|
494
|
+
declare class PlatformScopedClient {
|
|
495
|
+
#private;
|
|
496
|
+
/** @hidden */
|
|
497
|
+
constructor(request: ManagementRequest, token: AccessTokenSource);
|
|
498
|
+
readonly credentials: {
|
|
499
|
+
list: (scope: CredentialScope, options?: CredentialListOptions) => Promise<Paged<TenantCredentialSummary>>;
|
|
500
|
+
get: (scope: CredentialScope, credentialId: string) => Promise<CredentialDetail>;
|
|
501
|
+
create: (scope: CredentialScope, input: CreateCredentialInput) => Promise<TenantCredentialIssued>;
|
|
502
|
+
updatePermissions: (scope: CredentialScope, credentialId: string, input: CredentialPermissionsInput) => Promise<void>;
|
|
503
|
+
updateScopes: (scope: CredentialScope, credentialId: string, scopes: readonly string[]) => Promise<void>;
|
|
504
|
+
/** Returns a new secret once. API may require an explicit step-up first. */
|
|
505
|
+
rotate: (scope: CredentialScope, credentialId: string) => Promise<TenantCredentialIssued>;
|
|
506
|
+
revoke: (scope: CredentialScope, credentialId: string) => Promise<void>;
|
|
507
|
+
};
|
|
508
|
+
readonly workspaces: {
|
|
509
|
+
team: (workspaceId: string) => Promise<WorkspaceTeam>;
|
|
510
|
+
members: {
|
|
511
|
+
invite: (workspaceId: string, input: InviteWorkspaceMemberInput) => Promise<WorkspaceInviteIssued>;
|
|
512
|
+
/** memberId comes from team.members; it is not the platform userId. */
|
|
513
|
+
remove: (workspaceId: string, memberId: string) => Promise<void>;
|
|
514
|
+
changeRole: (workspaceId: string, memberId: string, role: WorkspaceRole) => Promise<void>;
|
|
515
|
+
};
|
|
516
|
+
invites: {
|
|
517
|
+
create: (workspaceId: string, input: InviteWorkspaceMemberInput) => Promise<WorkspaceInviteIssued>;
|
|
518
|
+
revoke: (workspaceId: string, inviteId: string) => Promise<void>;
|
|
519
|
+
};
|
|
520
|
+
};
|
|
521
|
+
readonly tenants: {
|
|
522
|
+
members: {
|
|
523
|
+
list: (scope: TenantManagementScope, options?: PaginationOptions) => Promise<EnvironmentUser[]>;
|
|
524
|
+
add: (scope: TenantManagementScope, userId: string, roles?: string[]) => Promise<void>;
|
|
525
|
+
remove: (scope: TenantManagementScope, userId: string) => Promise<void>;
|
|
526
|
+
};
|
|
527
|
+
};
|
|
528
|
+
readonly auth: {
|
|
529
|
+
/** Explicitly confirms the current platform session; passwords are not retained. */
|
|
530
|
+
stepUp: (currentPassword: string) => Promise<void>;
|
|
531
|
+
};
|
|
532
|
+
}
|
|
533
|
+
/** End-user operations require a user token and the environment publishable key. */
|
|
534
|
+
declare class UserScopedClient {
|
|
535
|
+
#private;
|
|
536
|
+
/** @hidden */
|
|
537
|
+
constructor(request: ManagementRequest, token: AccessTokenSource);
|
|
538
|
+
readonly tenants: {
|
|
539
|
+
members: {
|
|
540
|
+
list: (tenantId: string, options?: PaginationOptions) => Promise<TenantMemberPage>;
|
|
541
|
+
/** Adds an existing environment user by email; does not send an invitation email. */
|
|
542
|
+
invite: (tenantId: string, input: InviteTenantMemberInput) => Promise<TenantMember>;
|
|
543
|
+
remove: (tenantId: string, userId: string) => Promise<void>;
|
|
544
|
+
};
|
|
545
|
+
};
|
|
546
|
+
}
|
|
547
|
+
/** Anonymous invite endpoints: the invitation token itself authorizes these requests. */
|
|
548
|
+
declare class WorkspaceInvitesClient {
|
|
549
|
+
#private;
|
|
550
|
+
/** @hidden */
|
|
551
|
+
constructor(request: ManagementRequest);
|
|
552
|
+
preview(token: string): Promise<WorkspaceInvitePreview>;
|
|
553
|
+
accept(token: string, input?: AcceptWorkspaceInviteInput): Promise<WorkspaceInviteAccepted>;
|
|
554
|
+
}
|
|
555
|
+
|
|
556
|
+
interface ClientRequestContext {
|
|
557
|
+
/** Real end-user IP, resolved only from infrastructure trusted by the application. */
|
|
558
|
+
clientIp?: string;
|
|
559
|
+
}
|
|
560
|
+
/** Rejects header injection and values that are not a single IPv4 or IPv6 address. */
|
|
561
|
+
declare function normalizeClientIp(value: string): string;
|
|
562
|
+
|
|
563
|
+
type SafeJwtAlgorithm = "RS256" | "PS256" | "ES256" | "EdDSA";
|
|
564
|
+
interface AuthyonJwtClaims extends JWTPayload {
|
|
565
|
+
sub: string;
|
|
566
|
+
iss: string;
|
|
567
|
+
aud: string | string[];
|
|
568
|
+
exp: number;
|
|
569
|
+
iat: number;
|
|
570
|
+
email?: string;
|
|
571
|
+
username?: string;
|
|
572
|
+
roles?: string[];
|
|
573
|
+
permissions?: string[];
|
|
574
|
+
scope?: string;
|
|
575
|
+
}
|
|
576
|
+
interface VerifiedAccessToken {
|
|
577
|
+
claims: AuthyonJwtClaims;
|
|
578
|
+
protectedHeader: JWSHeaderParameters;
|
|
579
|
+
}
|
|
580
|
+
interface JwksTokenVerifierOptions {
|
|
581
|
+
/** Exact trusted issuer from Authyon OpenID discovery. */
|
|
582
|
+
issuer: string;
|
|
583
|
+
/** Audience assigned to the API consuming this token. */
|
|
584
|
+
audience: string | string[];
|
|
585
|
+
/** Trusted HTTPS JWKS endpoint. Never derive this value from the token header. */
|
|
586
|
+
jwksUri?: string;
|
|
587
|
+
/** Static trusted keys for pinned or offline verification. */
|
|
588
|
+
jwks?: JSONWebKeySet;
|
|
589
|
+
algorithms?: readonly SafeJwtAlgorithm[];
|
|
590
|
+
acceptedTokenTypes?: readonly string[];
|
|
591
|
+
clockToleranceSeconds?: number;
|
|
592
|
+
maxTokenAgeSeconds?: number;
|
|
593
|
+
jwksTimeoutMs?: number;
|
|
594
|
+
jwksCacheMs?: number;
|
|
595
|
+
jwksCooldownMs?: number;
|
|
596
|
+
}
|
|
597
|
+
interface AuthyonJwksDiscoveryOptions extends Omit<JwksTokenVerifierOptions, "issuer" | "jwksUri" | "jwks"> {
|
|
598
|
+
/** Optional pin; discovery fails if Authyon advertises a different issuer. */
|
|
599
|
+
issuer?: string;
|
|
600
|
+
/** Override the client environment key used by the discovery endpoint. */
|
|
601
|
+
publishableKey?: string;
|
|
602
|
+
}
|
|
603
|
+
type TokenVerificationErrorCode = "token.invalid" | "token.expired" | "token.not_active" | "token.invalid_claims" | "token.invalid_signature" | "token.key_unavailable";
|
|
604
|
+
declare class TokenVerificationError extends Error {
|
|
605
|
+
readonly code: TokenVerificationErrorCode;
|
|
606
|
+
constructor(code: TokenVerificationErrorCode, options?: {
|
|
607
|
+
cause?: unknown;
|
|
608
|
+
});
|
|
609
|
+
}
|
|
610
|
+
/** Secure, cached JWT signature and claims verifier backed by a trusted remote JWKS. */
|
|
611
|
+
declare class JwksTokenVerifier {
|
|
612
|
+
private readonly options;
|
|
613
|
+
private readonly verifyKey;
|
|
614
|
+
private readonly algorithms;
|
|
615
|
+
private readonly acceptedTokenTypes;
|
|
616
|
+
constructor(options: JwksTokenVerifierOptions);
|
|
617
|
+
verifyAccessToken(token: string): Promise<VerifiedAccessToken>;
|
|
618
|
+
}
|
|
619
|
+
|
|
620
|
+
/**
|
|
621
|
+
* Server-side Authyon client: environment/tenant administration (OAuth
|
|
622
|
+
* client-credentials) plus access-token verification (publishable key).
|
|
623
|
+
* Never import this in browser code — client secrets must stay on your
|
|
624
|
+
* server.
|
|
625
|
+
*/
|
|
626
|
+
declare class AuthyonServerClient {
|
|
627
|
+
#private;
|
|
628
|
+
private readonly envKey?;
|
|
629
|
+
private readonly clientId?;
|
|
630
|
+
private readonly transport;
|
|
631
|
+
private readonly http;
|
|
632
|
+
private readonly environmentTokenProvider;
|
|
633
|
+
constructor(options?: AuthyonServerClientOptions);
|
|
634
|
+
private request;
|
|
635
|
+
/** Mints (and caches) an environment access token from `clientId`/`clientSecret`. */
|
|
636
|
+
private getEnvironmentAccessToken;
|
|
637
|
+
readonly discovery: {
|
|
638
|
+
/** GET /.well-known/jwks.json — the environment's public signing keys. */
|
|
639
|
+
jwks: (publishableKey?: string) => Promise<JsonWebKeySet>;
|
|
640
|
+
/** GET /.well-known/openid-configuration — OIDC discovery document. */
|
|
641
|
+
openidConfiguration: (publishableKey?: string) => Promise<OpenIdConfiguration>;
|
|
642
|
+
};
|
|
643
|
+
/** Discovers Authyon's trusted issuer/JWKS and creates a cached local access-token verifier. */
|
|
644
|
+
createJwksTokenVerifier(options: AuthyonJwksDiscoveryOptions): Promise<JwksTokenVerifier>;
|
|
645
|
+
/** POST /auth/introspect — lightweight token introspection (RFC 7662). */
|
|
646
|
+
introspect(token: string, context?: ClientRequestContext): Promise<IntrospectResult>;
|
|
647
|
+
/** POST /auth/validate — recommended: cross-checks DB state, catches revocation immediately. */
|
|
648
|
+
validate(token: string, context?: ClientRequestContext): Promise<ValidateResult>;
|
|
649
|
+
readonly environmentAuth: {
|
|
650
|
+
/** POST /env/oauth/token — exchanges environment client credentials for an access token. */
|
|
651
|
+
token: (credentials: ClientCredentials) => Promise<TokenResult>;
|
|
652
|
+
};
|
|
653
|
+
readonly tenantAuth: {
|
|
654
|
+
/** POST /tenant/oauth/token — exchanges a tenant's client credentials for a scoped access token. */
|
|
655
|
+
token: (credentials: ClientCredentials) => Promise<TokenResult>;
|
|
656
|
+
};
|
|
657
|
+
/**
|
|
658
|
+
* Scopes a client to a single tenant's OAuth credentials — mints and
|
|
659
|
+
* caches its access token independently of the environment plane. Use
|
|
660
|
+
* this for the `TenantManagement` endpoints (`/tenant/...`), which act on
|
|
661
|
+
* "the token's tenant" rather than one you pass by id.
|
|
662
|
+
*/
|
|
663
|
+
tenant(credentials: ClientCredentials): TenantScopedClient;
|
|
664
|
+
/** Uses only the supplied platform-user access token. */
|
|
665
|
+
platform(token: AccessTokenSource): PlatformScopedClient;
|
|
666
|
+
/** Uses an end-user token; the configured environment key selects the environment. */
|
|
667
|
+
user(token: AccessTokenSource): UserScopedClient;
|
|
668
|
+
readonly workspaceInvites: WorkspaceInvitesClient;
|
|
669
|
+
readonly environment: {
|
|
670
|
+
users: {
|
|
671
|
+
/** GET /env/users — paginated list of users in the environment. */
|
|
672
|
+
list: (params?: {
|
|
673
|
+
search?: string;
|
|
674
|
+
} & PaginationOptions) => Promise<Paged<EnvironmentUser>>;
|
|
675
|
+
/** POST /env/users — create a user in the environment; returns only the new id. */
|
|
676
|
+
create: (input: CreateUserInput) => Promise<{
|
|
677
|
+
id: string;
|
|
678
|
+
}>;
|
|
679
|
+
/** GET /env/users/{userId} — fetch an environment user by id. */
|
|
680
|
+
get: (userId: string) => Promise<EnvironmentUser>;
|
|
681
|
+
/** POST /env/users/{userId}/roles — grant a role to an environment user. */
|
|
682
|
+
assignRole: (userId: string, role: string) => Promise<void>;
|
|
683
|
+
/** DELETE /env/users/{userId}/roles/{role} — revoke a role from an environment user. */
|
|
684
|
+
removeRole: (userId: string, role: string) => Promise<void>;
|
|
685
|
+
/** POST /env/users/{userId}/permissions — grant a direct permission to an environment user. */
|
|
686
|
+
grantPermission: (userId: string, permission: string) => Promise<void>;
|
|
687
|
+
/** DELETE /env/users/{userId}/permissions/{permission} — revoke a direct permission. */
|
|
688
|
+
revokePermission: (userId: string, permission: string) => Promise<void>;
|
|
689
|
+
/** POST /env/users/{userId}/unlock — clears an environment user's lockout. */
|
|
690
|
+
unlock: (userId: string, reason?: string) => Promise<void>;
|
|
691
|
+
/** POST /env/users/{userId}/password — sets a new password for the user. */
|
|
692
|
+
setPassword: (userId: string, newPassword: string, reason?: string) => Promise<void>;
|
|
693
|
+
/** POST /env/users/{userId}/sessions/revoke-all — revokes every session the user has. */
|
|
694
|
+
revokeSessions: (userId: string, reason?: string) => Promise<void>;
|
|
695
|
+
/** DELETE /env/users/{userId}/sessions/{sessionId} — revokes a single session. */
|
|
696
|
+
revokeSession: (userId: string, sessionId: string, reason?: string) => Promise<void>;
|
|
697
|
+
/** POST /env/users/{userId}/disable — bans the user indefinitely; revokes live sessions. */
|
|
698
|
+
disable: (userId: string, reason?: string) => Promise<void>;
|
|
699
|
+
/** POST /env/users/{userId}/enable — lifts a ban. */
|
|
700
|
+
enable: (userId: string, reason?: string) => Promise<void>;
|
|
701
|
+
/** POST /env/users/{userId}/suspend — blocks the user temporarily; clears itself after `durationMinutes`. */
|
|
702
|
+
suspend: (userId: string, durationMinutes: number, reason?: string) => Promise<void>;
|
|
703
|
+
/** POST /env/users/{userId}/unsuspend — lifts a suspension early. */
|
|
704
|
+
unsuspend: (userId: string, reason?: string) => Promise<void>;
|
|
705
|
+
/** POST /env/users/{userId}/tenants — adds an environment user to a tenant. */
|
|
706
|
+
assignTenant: (userId: string, tenantId: string, roles?: string[]) => Promise<void>;
|
|
707
|
+
/** DELETE /env/users/{userId}/tenants/{tenantId} — removes an environment user from a tenant. */
|
|
708
|
+
removeTenant: (userId: string, tenantId: string) => Promise<void>;
|
|
709
|
+
};
|
|
710
|
+
tenants: {
|
|
711
|
+
credentials: {
|
|
712
|
+
/** GET /env/tenants/{tenantId}/credentials. Returns metadata only, including revoked credentials. */
|
|
713
|
+
list: (tenantId: string) => Promise<TenantCredentialSummary[]>;
|
|
714
|
+
/** Paginated searchable listing. Prefer this over loading every credential. */
|
|
715
|
+
listPage: (tenantId: string, options?: CredentialListOptions) => Promise<Paged<TenantCredentialSummary>>;
|
|
716
|
+
get: (tenantId: string, credentialId: string) => Promise<CredentialDetail>;
|
|
717
|
+
/** Explicit scopes/permissions; only issuance returns the client secret. */
|
|
718
|
+
create: (tenantId: string, input: CreateTenantCredentialInput | CreateCredentialInput) => Promise<TenantCredentialIssued>;
|
|
719
|
+
/** Returns a new secret once while keeping the same client id. */
|
|
720
|
+
rotate: (tenantId: string, credentialId: string) => Promise<TenantCredentialIssued>;
|
|
721
|
+
updatePermissions: (tenantId: string, credentialId: string, input: CredentialPermissionsInput) => Promise<void>;
|
|
722
|
+
updateScopes: (tenantId: string, credentialId: string, scopes: readonly string[]) => Promise<void>;
|
|
723
|
+
revoke: (tenantId: string, credentialId: string) => Promise<void>;
|
|
724
|
+
};
|
|
725
|
+
/** GET /env/tenants — paginated, searchable list of tenants in the environment. */
|
|
726
|
+
list: (params?: {
|
|
727
|
+
search?: string;
|
|
728
|
+
} & PaginationOptions) => Promise<Paged<Organization>>;
|
|
729
|
+
/** POST /env/tenants — create a tenant in the environment. */
|
|
730
|
+
create: (input: CreateOrganizationInput) => Promise<Organization>;
|
|
731
|
+
/** GET /env/tenants/{tenantId} — fetch a tenant by id. */
|
|
732
|
+
get: (tenantId: string) => Promise<Organization>;
|
|
733
|
+
/** PUT /env/tenants/{tenantId} — update a tenant. */
|
|
734
|
+
update: (tenantId: string, input: UpdateOrganizationInput) => Promise<Organization>;
|
|
735
|
+
/** DELETE /env/tenants/{tenantId} — delete a tenant. */
|
|
736
|
+
delete: (tenantId: string) => Promise<void>;
|
|
737
|
+
members: {
|
|
738
|
+
/**
|
|
739
|
+
* GET /env/tenants/{tenantId}/members — a tenant's members as full
|
|
740
|
+
* user records. Confirmed live: a bare array (unlike
|
|
741
|
+
* `environment.users.list()`, this one does NOT paginate despite
|
|
742
|
+
* accepting `skip`/`take`), with the same shape
|
|
743
|
+
* `environment.users.list()` items have.
|
|
744
|
+
*/
|
|
745
|
+
list: (tenantId: string, params?: PaginationOptions) => Promise<EnvironmentUser[]>;
|
|
746
|
+
/** POST /env/tenants/{tenantId}/members — add a member to a tenant. */
|
|
747
|
+
add: (tenantId: string, userId: string, roles?: string[]) => Promise<void>;
|
|
748
|
+
/** DELETE /env/tenants/{tenantId}/members/{userId} — remove a member from a tenant. */
|
|
749
|
+
remove: (tenantId: string, userId: string) => Promise<void>;
|
|
750
|
+
/** POST /env/tenants/{tenantId}/members/{userId}/roles — grant a tenant role to a member. */
|
|
751
|
+
assignRole: (tenantId: string, userId: string, role: string) => Promise<void>;
|
|
752
|
+
/** DELETE .../members/{userId}/roles/{role} — revoke a tenant role from a member. */
|
|
753
|
+
removeRole: (tenantId: string, userId: string, role: string) => Promise<void>;
|
|
754
|
+
/** POST .../members/{userId}/permissions — grant a permission to a tenant member. */
|
|
755
|
+
grantPermission: (tenantId: string, userId: string, permission: string) => Promise<void>;
|
|
756
|
+
/** DELETE .../members/{userId}/permissions/{permission} — revoke a permission from a tenant member. */
|
|
757
|
+
revokePermission: (tenantId: string, userId: string, permission: string) => Promise<void>;
|
|
758
|
+
};
|
|
759
|
+
roles: {
|
|
760
|
+
/** GET /env/tenants/{tenantId}/roles — list a tenant's roles. */
|
|
761
|
+
list: (tenantId: string) => Promise<Role[]>;
|
|
762
|
+
/** POST /env/tenants/{tenantId}/roles — create a tenant role. */
|
|
763
|
+
create: (tenantId: string, input: RoleInput) => Promise<Role>;
|
|
764
|
+
/** GET /env/tenants/{tenantId}/roles/{roleId} — fetch a tenant role by id. */
|
|
765
|
+
get: (tenantId: string, roleId: string) => Promise<Role>;
|
|
766
|
+
/** PUT /env/tenants/{tenantId}/roles/{roleId} — update a tenant role. */
|
|
767
|
+
update: (tenantId: string, roleId: string, input: RoleInput) => Promise<Role>;
|
|
768
|
+
/** DELETE /env/tenants/{tenantId}/roles/{roleId} — delete a tenant role. */
|
|
769
|
+
delete: (tenantId: string, roleId: string) => Promise<void>;
|
|
770
|
+
};
|
|
771
|
+
};
|
|
772
|
+
roles: {
|
|
773
|
+
/** GET /env/roles — environment-level roles, grouped into custom and system-defined. */
|
|
774
|
+
list: () => Promise<RoleList>;
|
|
775
|
+
/** POST /env/roles — create an environment-level role. */
|
|
776
|
+
create: (input: RoleInput) => Promise<Role>;
|
|
777
|
+
/** PUT /env/roles/{roleId} — update an environment-level role. */
|
|
778
|
+
update: (roleId: string, input: RoleInput) => Promise<Role>;
|
|
779
|
+
/** DELETE /env/roles/{roleId} — delete an environment-level role. */
|
|
780
|
+
delete: (roleId: string) => Promise<void>;
|
|
781
|
+
};
|
|
782
|
+
permissions: {
|
|
783
|
+
/** GET /env/permissions — environment-level permissions, grouped by the role they're attached to. */
|
|
784
|
+
list: () => Promise<PermissionsByRole>;
|
|
785
|
+
/** POST /env/permissions — create an environment-level permission. */
|
|
786
|
+
create: (input: CreatePermissionInput) => Promise<Permission>;
|
|
787
|
+
/** PUT /env/permissions/{permissionId} — update an environment-level permission. */
|
|
788
|
+
update: (permissionId: string, description?: string) => Promise<Permission>;
|
|
789
|
+
/** DELETE /env/permissions/{permissionId} — delete an environment-level permission. */
|
|
790
|
+
delete: (permissionId: string) => Promise<void>;
|
|
791
|
+
/** GET /permissions/reserved — reserved permission names you can't redefine. */
|
|
792
|
+
reserved: () => Promise<ReservedPermissions>;
|
|
793
|
+
};
|
|
794
|
+
audit: {
|
|
795
|
+
/** GET /env/audit — paginated list of the environment's audit events. */
|
|
796
|
+
list: (params?: PaginationOptions) => Promise<Paged<AuditEvent>>;
|
|
797
|
+
/** GET /env/audit/login-activity — paginated login activity in the environment. */
|
|
798
|
+
loginActivity: (params?: PaginationOptions) => Promise<Paged<LoginActivity>>;
|
|
799
|
+
};
|
|
800
|
+
};
|
|
801
|
+
readonly permissions: {
|
|
802
|
+
/** POST /users/{userId}/permissions — grant a permission directly to a user. */
|
|
803
|
+
grant: (userId: string, permission: string) => Promise<void>;
|
|
804
|
+
/** DELETE /users/{userId}/permissions/{permission} — revoke a permission from a user. */
|
|
805
|
+
revoke: (userId: string, permission: string) => Promise<void>;
|
|
806
|
+
};
|
|
807
|
+
/** @internal used by {@link TenantScopedClient} to share the base URL/fetch/error handling. */
|
|
808
|
+
_requestAsTenant<T>(accessToken: string, path: string, options?: {
|
|
809
|
+
method?: "GET" | "POST" | "PUT" | "PATCH" | "DELETE";
|
|
810
|
+
body?: unknown;
|
|
811
|
+
query?: object;
|
|
812
|
+
headers?: Record<string, string>;
|
|
813
|
+
}): Promise<T>;
|
|
814
|
+
}
|
|
815
|
+
/**
|
|
816
|
+
* Client scoped to a single tenant's OAuth credentials — every call acts on
|
|
817
|
+
* "the token's tenant" (`TenantManagement` endpoints), so there's no
|
|
818
|
+
* `tenantId` parameter to pass.
|
|
819
|
+
*/
|
|
820
|
+
declare class TenantScopedClient {
|
|
821
|
+
private readonly server;
|
|
822
|
+
private readonly tokenProvider;
|
|
823
|
+
constructor(server: AuthyonServerClient, credentials: ClientCredentials);
|
|
824
|
+
private getAccessToken;
|
|
825
|
+
private request;
|
|
826
|
+
/** POST /tenant/auth/validate — validates this tenant client's current bearer token. */
|
|
827
|
+
validate(): Promise<TenantClientValidationResult>;
|
|
828
|
+
readonly members: {
|
|
829
|
+
/**
|
|
830
|
+
* GET /tenant/members — members of the token's tenant.
|
|
831
|
+
*
|
|
832
|
+
* ⚠️ Inferred, not confirmed live (no tenant client credentials
|
|
833
|
+
* available to exchange for a scoped token) — assumed to share
|
|
834
|
+
* `/env/tenants/{id}/members`'s confirmed shape (bare array of full
|
|
835
|
+
* user records), since both are the "admin" member listing as opposed
|
|
836
|
+
* to `/auth/tenants/{id}/members`'s paginated, lightweight one.
|
|
837
|
+
*/
|
|
838
|
+
list: (params?: PaginationOptions) => Promise<EnvironmentUser[]>;
|
|
839
|
+
/** POST /tenant/members — add a member to the token's tenant. */
|
|
840
|
+
add: (userId: string, roles?: string[]) => Promise<void>;
|
|
841
|
+
/** DELETE /tenant/members/{userId} — remove a member from the token's tenant. */
|
|
842
|
+
remove: (userId: string) => Promise<void>;
|
|
843
|
+
/** POST /tenant/members/{userId}/roles — grant a role to a member of the tenant. */
|
|
844
|
+
assignRole: (userId: string, role: string) => Promise<void>;
|
|
845
|
+
/** DELETE /tenant/members/{userId}/roles/{role} — revoke a role from a member of the tenant. */
|
|
846
|
+
removeRole: (userId: string, role: string) => Promise<void>;
|
|
847
|
+
/** POST /tenant/members/{userId}/permissions — grant a permission to a member of the tenant. */
|
|
848
|
+
grantPermission: (userId: string, permission: string) => Promise<void>;
|
|
849
|
+
/** DELETE .../permissions/{permission} — revoke a permission from a member of the tenant. */
|
|
850
|
+
revokePermission: (userId: string, permission: string) => Promise<void>;
|
|
851
|
+
};
|
|
852
|
+
readonly roles: {
|
|
853
|
+
/**
|
|
854
|
+
* GET /tenant/roles — roles in the token's tenant, grouped into custom
|
|
855
|
+
* and system-defined.
|
|
856
|
+
*
|
|
857
|
+
* ⚠️ Inferred, not confirmed live (the test environment had no tenants
|
|
858
|
+
* to exchange a scoped token for) — assumed to share `/env/roles`'
|
|
859
|
+
* grouped shape, since both operate on the same underlying role model.
|
|
860
|
+
*/
|
|
861
|
+
list: () => Promise<RoleList>;
|
|
862
|
+
/** POST /tenant/roles — create a role in the tenant. */
|
|
863
|
+
create: (input: RoleInput) => Promise<Role>;
|
|
864
|
+
/** GET /tenant/roles/{roleId} — fetch a tenant role by id. */
|
|
865
|
+
get: (roleId: string) => Promise<Role>;
|
|
866
|
+
/** PUT /tenant/roles/{roleId} — update a role in the tenant. */
|
|
867
|
+
update: (roleId: string, input: RoleInput) => Promise<Role>;
|
|
868
|
+
/** DELETE /tenant/roles/{roleId} — delete a role in the tenant. */
|
|
869
|
+
delete: (roleId: string) => Promise<void>;
|
|
870
|
+
};
|
|
871
|
+
}
|
|
872
|
+
/** Convenience factory: `const authyon = createClient({ clientId, clientSecret })`. */
|
|
873
|
+
declare function createClient(options?: AuthyonServerClientOptions): AuthyonServerClient;
|
|
874
|
+
|
|
875
|
+
type AbilitySubject = string | Record<string, unknown>;
|
|
876
|
+
type AbilityConditions = Record<string, unknown>;
|
|
877
|
+
interface AbilityRule {
|
|
878
|
+
action: string | string[];
|
|
879
|
+
subject: string | string[];
|
|
880
|
+
inverted?: boolean;
|
|
881
|
+
conditions?: AbilityConditions;
|
|
882
|
+
fields?: string[];
|
|
883
|
+
reason?: string;
|
|
884
|
+
}
|
|
885
|
+
interface AuthyonPermissionSource {
|
|
886
|
+
permissions?: readonly string[] | null;
|
|
887
|
+
roles?: readonly string[] | null;
|
|
888
|
+
/** OAuth scopes are also accepted and interpreted as Authyon permissions. */
|
|
889
|
+
scope?: string | null;
|
|
890
|
+
}
|
|
891
|
+
interface AuthyonAbilityOptions {
|
|
892
|
+
rules?: readonly AbilityRule[];
|
|
893
|
+
/** Rules added when the source contains a matching Authyon role. */
|
|
894
|
+
roleRules?: Readonly<Record<string, readonly AbilityRule[]>>;
|
|
895
|
+
roles?: readonly string[] | null;
|
|
896
|
+
detectSubjectType?: (subject: Record<string, unknown>) => string;
|
|
897
|
+
}
|
|
898
|
+
type AbilityEvent = "updated";
|
|
899
|
+
type AbilityListener = (rules: readonly AbilityRule[]) => void;
|
|
900
|
+
/** Isomorphic, deny-by-default authorization engine backed by Authyon permissions. */
|
|
901
|
+
declare class AuthyonAbility {
|
|
902
|
+
private readonly detectSubjectType;
|
|
903
|
+
private currentRules;
|
|
904
|
+
private readonly listeners;
|
|
905
|
+
constructor(rules?: readonly AbilityRule[], detectSubjectType?: (subject: Record<string, unknown>) => string);
|
|
906
|
+
get rules(): readonly AbilityRule[];
|
|
907
|
+
can(action: string, subject: AbilitySubject, field?: string): boolean;
|
|
908
|
+
cannot(action: string, subject: AbilitySubject, field?: string): boolean;
|
|
909
|
+
rulesFor(action: string, subject: string): readonly AbilityRule[];
|
|
910
|
+
update(rules: readonly AbilityRule[]): void;
|
|
911
|
+
on(event: AbilityEvent, listener: AbilityListener): () => void;
|
|
912
|
+
}
|
|
913
|
+
/** Fluent rule builder with CASL-like `can` and `cannot` methods. */
|
|
914
|
+
declare class AuthyonAbilityBuilder {
|
|
915
|
+
readonly rules: AbilityRule[];
|
|
916
|
+
can(action: string | string[], subject: string | string[], conditions?: AbilityConditions, fields?: string[]): this;
|
|
917
|
+
cannot(action: string | string[], subject: string | string[], conditions?: AbilityConditions, fields?: string[], reason?: string): this;
|
|
918
|
+
build(options?: Pick<AuthyonAbilityOptions, "detectSubjectType">): AuthyonAbility;
|
|
919
|
+
}
|
|
920
|
+
/** Creates an ability from Authyon permissions, OAuth scope and optional role rules. */
|
|
921
|
+
declare function createAuthyonAbility(source?: AuthyonPermissionSource, options?: AuthyonAbilityOptions): AuthyonAbility;
|
|
922
|
+
/** Checks an Authyon permission string using the same wildcard rules as an ability. */
|
|
923
|
+
declare function hasPermission(source: AuthyonPermissionSource | readonly string[], requiredPermission: string): boolean;
|
|
924
|
+
/** Converts Authyon's `subject:action` permission strings to authorization rules. */
|
|
925
|
+
declare function createAuthyonRules(source?: AuthyonPermissionSource, options?: AuthyonAbilityOptions): AbilityRule[];
|
|
926
|
+
|
|
927
|
+
interface AbilityRequirement {
|
|
928
|
+
action: string;
|
|
929
|
+
subject: AbilitySubject;
|
|
930
|
+
field?: string;
|
|
931
|
+
}
|
|
932
|
+
interface AuthorizationContext {
|
|
933
|
+
token: string;
|
|
934
|
+
userId?: string;
|
|
935
|
+
ability: AuthyonAbility;
|
|
936
|
+
permissions: readonly string[];
|
|
937
|
+
roles: readonly string[];
|
|
938
|
+
}
|
|
939
|
+
interface AuthorizationOptions extends AuthyonAbilityOptions {
|
|
940
|
+
requirement?: AbilityRequirement;
|
|
941
|
+
/** Uses database-backed validation by default; introspection can be selected when desired. */
|
|
942
|
+
verification?: "validate" | "introspect" | "jwks";
|
|
943
|
+
/** Required for local JWKS verification. Create once and reuse its key cache. */
|
|
944
|
+
jwksVerifier?: JwksTokenVerifier;
|
|
945
|
+
/** Real end-user IP, obtained from trusted application infrastructure. */
|
|
946
|
+
clientIp?: string;
|
|
947
|
+
}
|
|
948
|
+
declare class AuthorizationError extends Error {
|
|
949
|
+
readonly status: 401 | 403 | 503;
|
|
950
|
+
readonly code: "authorization.unauthenticated" | "authorization.forbidden" | "authorization.unavailable";
|
|
951
|
+
constructor(status: 401 | 403 | 503, code: "authorization.unauthenticated" | "authorization.forbidden" | "authorization.unavailable", message: string);
|
|
952
|
+
}
|
|
953
|
+
/** Validates a bearer token and creates an Authyon-backed ability for server runtimes. */
|
|
954
|
+
declare function authorizeToken(client: AuthyonServerClient, token: string, options?: AuthorizationOptions): Promise<AuthorizationContext>;
|
|
955
|
+
/** Works with Web Request objects used by Next.js Route Handlers and other Fetch runtimes. */
|
|
956
|
+
declare function authorizeRequest(client: AuthyonServerClient, request: Pick<Request, "headers">, options?: RequestAuthorizationOptions): Promise<AuthorizationContext>;
|
|
957
|
+
interface RequestAuthorizationOptions extends AuthorizationOptions {
|
|
958
|
+
/** Platform-aware resolver. Only read headers that your trusted proxy overwrites. */
|
|
959
|
+
resolveClientIp?: (request: Pick<Request, "headers">) => string | undefined;
|
|
960
|
+
}
|
|
961
|
+
interface ExpressRequestLike {
|
|
962
|
+
headers: Record<string, string | string[] | undefined>;
|
|
963
|
+
ip?: string;
|
|
964
|
+
socket?: {
|
|
965
|
+
remoteAddress?: string;
|
|
966
|
+
};
|
|
967
|
+
authyon?: AuthorizationContext;
|
|
968
|
+
}
|
|
969
|
+
interface ExpressResponseLike {
|
|
970
|
+
status(code: number): ExpressResponseLike;
|
|
971
|
+
json(body: unknown): unknown;
|
|
972
|
+
}
|
|
973
|
+
type ExpressNext = (error?: unknown) => void;
|
|
974
|
+
interface ExpressAuthorizationMiddlewareOptions extends AuthorizationOptions {
|
|
975
|
+
/** Property assigned to the request. Defaults to `authyon`. */
|
|
976
|
+
requestProperty?: string;
|
|
977
|
+
/** Pass authorization errors to Express error middleware instead of writing a JSON response. */
|
|
978
|
+
passErrorsToNext?: boolean;
|
|
979
|
+
/** Trust Express's proxy-aware `request.ip`. Disabled by default. */
|
|
980
|
+
trustProxy?: boolean;
|
|
981
|
+
/** Overrides all built-in IP resolution; return only a trusted, single client IP. */
|
|
982
|
+
resolveClientIp?: (request: ExpressRequestLike) => string | undefined;
|
|
983
|
+
}
|
|
984
|
+
/** Dependency-free middleware compatible with Express and similar Connect frameworks. */
|
|
985
|
+
declare function createExpressAuthorizationMiddleware(client: AuthyonServerClient, options?: ExpressAuthorizationMiddlewareOptions): (request: ExpressRequestLike & Record<string, unknown>, response: ExpressResponseLike, next: ExpressNext) => Promise<void>;
|
|
986
|
+
/** Converts an authorization error into a Fetch Response suitable for Next.js. */
|
|
987
|
+
declare function createAuthorizationErrorResponse(error: unknown): Response;
|
|
988
|
+
|
|
989
|
+
export { type Organization as $, AuthyonServerClient as A, type CredentialCreator as B, type ClientCredentials as C, type CredentialDetail as D, type CredentialListOptions as E, type CredentialPermissionsInput as F, type CredentialScope as G, type HttpAdapter as H, type EnvironmentUser as I, type ExpressAuthorizationMiddlewareOptions as J, type ExpressNext as K, type ExpressRequestLike as L, type ExpressResponseLike as M, FetchHttpAdapter as N, type HttpAdapterRequest as O, type HttpLogEvent as P, type HttpLogger as Q, type RequestAuthorizationOptions as R, type IntrospectResult as S, type InviteTenantMemberInput as T, type InviteWorkspaceMemberInput as U, type JsonWebKeySet as V, JwksTokenVerifier as W, type JwksTokenVerifierOptions as X, LoggingHttpAdapter as Y, type LoginActivity as Z, type OpenIdConfiguration as _, type AbilitySubject as a, type Paged as a0, type PaginationOptions as a1, type Permission as a2, type PermissionsByRole as a3, PlatformScopedClient as a4, type ReservedPermissions as a5, type Role as a6, type RoleGrant as a7, type RoleInput as a8, type RoleList as a9, authorizeRequest as aA, authorizeToken as aB, createAuthorizationErrorResponse as aC, createAuthyonAbility as aD, createAuthyonRules as aE, createClient as aF, createExpressAuthorizationMiddleware as aG, hasPermission as aH, normalizeClientIp as aI, type RolePermissions as aa, type SafeJwtAlgorithm as ab, type TenantClientValidationResult as ac, type TenantCredentialIssued as ad, type TenantCredentialSummary as ae, type TenantManagementScope as af, type TenantMember as ag, type TenantMemberPage as ah, type TenantMembership as ai, TenantScopedClient as aj, type TokenResult as ak, TokenVerificationError as al, type TokenVerificationErrorCode as am, type UpdateOrganizationInput as an, type User as ao, UserScopedClient as ap, type ValidateResult as aq, type VerifiedAccessToken as ar, type WorkspaceInvite as as, type WorkspaceInviteAccepted as at, type WorkspaceInviteIssued as au, type WorkspaceInvitePreview as av, WorkspaceInvitesClient as aw, type WorkspaceMember as ax, type WorkspaceRole as ay, type WorkspaceTeam as az, AuthorizationError as b, type HttpLoggerOptions as c, type AbilityConditions as d, type AbilityEvent as e, type AbilityListener as f, type AbilityRequirement as g, type AbilityRule as h, type AcceptWorkspaceInviteInput as i, type AccessTokenSource as j, type AuditEvent as k, type AuthorizationContext as l, type AuthorizationOptions as m, AuthyonAbility as n, AuthyonAbilityBuilder as o, type AuthyonAbilityOptions as p, type AuthyonJwksDiscoveryOptions as q, type AuthyonJwtClaims as r, type AuthyonPermissionSource as s, type AuthyonServerClientOptions as t, type ClientRequestContext as u, type CreateCredentialInput as v, type CreateOrganizationInput as w, type CreatePermissionInput as x, type CreateTenantCredentialInput as y, type CreateUserInput as z };
|