@authyon/server 0.2.0-beta.30 → 0.2.0-beta.31
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 +4 -4
- package/dist/{authorization-DR079xKg.d.cts → authorization-CALNd7HI.d.cts} +1 -1
- package/dist/{authorization-Dkawj1IN.d.ts → authorization-Cc-xr0ay.d.ts} +1 -1
- package/dist/{authyonServerClient-C_iWckru.d.cts → authyonServerClient-mwY55kc9.d.cts} +65 -15
- package/dist/{authyonServerClient-C_iWckru.d.ts → authyonServerClient-mwY55kc9.d.ts} +65 -15
- package/dist/bff.cjs +59 -31
- package/dist/bff.d.cts +37 -4
- package/dist/bff.d.ts +37 -4
- package/dist/bff.js +59 -31
- package/dist/index.cjs +22 -0
- package/dist/index.d.cts +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/index.js +22 -0
- package/dist/next.d.cts +2 -2
- package/dist/next.d.ts +2 -2
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -40,7 +40,7 @@ O client também aceita `httpLogger: { enabled, logger? }`. A configuração é
|
|
|
40
40
|
## Sessão web no BFF (código ainda não publicado)
|
|
41
41
|
|
|
42
42
|
O novo entrypoint `@authyon/server/bff` oferece login, 2FA, sessão HttpOnly,
|
|
43
|
-
renovação sob demanda, logout e troca de
|
|
43
|
+
renovação sob demanda, logout e troca de tenant. Os tokens ficam no servidor,
|
|
44
44
|
com adaptador Redis cifrado e compare-and-swap para concorrência entre instâncias.
|
|
45
45
|
Reutiliza os endpoints existentes e o cliente de validação server-side.
|
|
46
46
|
|
|
@@ -93,7 +93,7 @@ const authyon = createClient({
|
|
|
93
93
|
|
|
94
94
|
```ts
|
|
95
95
|
const { active, sub } = await authyon.introspect(token); // leve
|
|
96
|
-
const {
|
|
96
|
+
const { valid, user } = await authyon.validate(token); // recomendado — cross-checa revogação
|
|
97
97
|
```
|
|
98
98
|
|
|
99
99
|
Veja [`examples/tokenVerification.ts`](./examples/tokenVerification.ts) para um middleware completo.
|
|
@@ -118,7 +118,7 @@ await authyon.environment.roles.create({ name: "support", permissions: ["tickets
|
|
|
118
118
|
await authyon.environment.audit.list({ take: 50 });
|
|
119
119
|
```
|
|
120
120
|
|
|
121
|
-
Veja [`examples/
|
|
121
|
+
Veja [`examples/tenantMembership.ts`](./examples/tenantMembership.ts) para o fluxo completo, incluindo as rotas de backend que o `@authyon/auth` chamaria.
|
|
122
122
|
|
|
123
123
|
Namespaces disponíveis: `environment.users`, `environment.tenants` (com `.members` e `.roles` aninhados), `environment.roles`, `environment.permissions`, `environment.audit`. OTP e aprovações ficam em `security` (veja abaixo).
|
|
124
124
|
|
|
@@ -493,7 +493,7 @@ Configure `envKey` para `user()`. `members.invite` associa um usuário já
|
|
|
493
493
|
cadastrado no ambiente pelo e-mail; não cria conta e não envia link por e-mail.
|
|
494
494
|
Para isso, use os convites abaixo.
|
|
495
495
|
A API exige associação/permissões do usuário chamador. No browser, os métodos
|
|
496
|
-
existentes `@authyon/auth` → `
|
|
496
|
+
existentes `@authyon/auth` → `tenants.members.invite/remove` continuam
|
|
497
497
|
atendendo esse fluxo. Nunca importe `@authyon/server` no browser.
|
|
498
498
|
|
|
499
499
|
## Convites de tenant (e-mail ou link)
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { J as JwksTokenVerifier, A as AuthyonServerClient } from './authyonServerClient-
|
|
1
|
+
import { J as JwksTokenVerifier, A as AuthyonServerClient } from './authyonServerClient-mwY55kc9.cjs';
|
|
2
2
|
|
|
3
3
|
type AbilitySubject = string | Record<string, unknown>;
|
|
4
4
|
type AbilityConditions = Record<string, unknown>;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { J as JwksTokenVerifier, A as AuthyonServerClient } from './authyonServerClient-
|
|
1
|
+
import { J as JwksTokenVerifier, A as AuthyonServerClient } from './authyonServerClient-mwY55kc9.js';
|
|
2
2
|
|
|
3
3
|
type AbilitySubject = string | Record<string, unknown>;
|
|
4
4
|
type AbilityConditions = Record<string, unknown>;
|
|
@@ -239,6 +239,36 @@ interface SubTenant {
|
|
|
239
239
|
/** The tenant it hangs from — the same on every row of a page, carried so a row stands on its own. */
|
|
240
240
|
parent: TenantParent;
|
|
241
241
|
}
|
|
242
|
+
/**
|
|
243
|
+
* One tenant as the end-user routes return it (`GET /auth/tenants/{id}` and
|
|
244
|
+
* `/auth/tenants/by-slug/{slug}`): the user's own, or one below it read with
|
|
245
|
+
* `subtenants:tree:read` from an ancestor.
|
|
246
|
+
*/
|
|
247
|
+
interface MyTenant {
|
|
248
|
+
id: string;
|
|
249
|
+
slug: string;
|
|
250
|
+
name: string;
|
|
251
|
+
description?: string | null;
|
|
252
|
+
createdAt: string;
|
|
253
|
+
updatedAt?: string | null;
|
|
254
|
+
memberCount: number;
|
|
255
|
+
/** Roles the user holds in it; empty when they reach it from an ancestor. */
|
|
256
|
+
myRoles: string[];
|
|
257
|
+
/**
|
|
258
|
+
* The end-user-route permissions the user can use on it, as concrete values.
|
|
259
|
+
* This, not `myRoles`, is what decides which actions to offer.
|
|
260
|
+
*/
|
|
261
|
+
myPermissions?: string[];
|
|
262
|
+
/** JSON-encoded metadata visible to members. */
|
|
263
|
+
publicMetadata: string;
|
|
264
|
+
isDisabled: boolean;
|
|
265
|
+
/** Distance from the root: `0` at a root tenant. */
|
|
266
|
+
depth: number;
|
|
267
|
+
/** `true` when the user reaches it from an ancestor rather than as a member. */
|
|
268
|
+
inherited: boolean;
|
|
269
|
+
/** The tenant it hangs from, `null` for a root. */
|
|
270
|
+
parent: TenantParent | null;
|
|
271
|
+
}
|
|
242
272
|
|
|
243
273
|
/**
|
|
244
274
|
* Builders for the tenant list's structured filters.
|
|
@@ -278,7 +308,7 @@ declare const tenantFilter: {
|
|
|
278
308
|
};
|
|
279
309
|
|
|
280
310
|
/** GET/POST /env/tenants — confirmed against the live API. */
|
|
281
|
-
interface
|
|
311
|
+
interface Tenant {
|
|
282
312
|
id: string;
|
|
283
313
|
slug: string;
|
|
284
314
|
name?: string;
|
|
@@ -318,7 +348,7 @@ interface Organization {
|
|
|
318
348
|
*/
|
|
319
349
|
ancestors?: TenantAncestor[];
|
|
320
350
|
}
|
|
321
|
-
/** One step of the chain above a tenant, as `
|
|
351
|
+
/** One step of the chain above a tenant, as `Tenant.ancestors` carries it. */
|
|
322
352
|
interface TenantAncestor {
|
|
323
353
|
id: string;
|
|
324
354
|
name: string;
|
|
@@ -496,7 +526,7 @@ interface PermissionsByRole {
|
|
|
496
526
|
roles: RolePermissions[];
|
|
497
527
|
orphans: Permission[];
|
|
498
528
|
/**
|
|
499
|
-
* The permissions Authyon itself checks on the end-user
|
|
529
|
+
* The permissions Authyon itself checks on the end-user tenant routes
|
|
500
530
|
* (`tenants:settings:manage`, `tenants:members:invite`,
|
|
501
531
|
* `tenants:members:remove` and `subtenants:tree:*`), listed whether or not
|
|
502
532
|
* a role names them. Absent from an API older than 2026-11-25.
|
|
@@ -522,7 +552,7 @@ interface CreatePermissionInput {
|
|
|
522
552
|
/** Attach the new permission to this role immediately. */
|
|
523
553
|
attachToRoleId?: string;
|
|
524
554
|
}
|
|
525
|
-
interface
|
|
555
|
+
interface CreateTenantInput {
|
|
526
556
|
name: string;
|
|
527
557
|
slug: string;
|
|
528
558
|
description?: string;
|
|
@@ -541,7 +571,7 @@ interface CreateOrganizationInput {
|
|
|
541
571
|
*/
|
|
542
572
|
parentTenantId?: string;
|
|
543
573
|
}
|
|
544
|
-
interface
|
|
574
|
+
interface UpdateTenantInput {
|
|
545
575
|
name: string;
|
|
546
576
|
description?: string;
|
|
547
577
|
customFields?: Record<string, unknown>;
|
|
@@ -561,7 +591,7 @@ interface CreateUserInput {
|
|
|
561
591
|
customFields?: Record<string, unknown>;
|
|
562
592
|
emailConfirmed?: boolean;
|
|
563
593
|
roles?: string[];
|
|
564
|
-
/** Tenants
|
|
594
|
+
/** Tenants to add the user to on creation. */
|
|
565
595
|
tenantIds?: string[];
|
|
566
596
|
}
|
|
567
597
|
/** GET /env/audit — one audit-trail entry, confirmed against the live API. */
|
|
@@ -703,6 +733,13 @@ interface AuthyonServerClientOptions {
|
|
|
703
733
|
fetch?: typeof fetch;
|
|
704
734
|
}
|
|
705
735
|
|
|
736
|
+
/** @deprecated Use `Tenant`. */
|
|
737
|
+
type Organization = Tenant;
|
|
738
|
+
/** @deprecated Use `CreateTenantInput`. */
|
|
739
|
+
type CreateOrganizationInput = CreateTenantInput;
|
|
740
|
+
/** @deprecated Use `UpdateTenantInput`. */
|
|
741
|
+
type UpdateOrganizationInput = UpdateTenantInput;
|
|
742
|
+
|
|
706
743
|
/** A token of the requested authentication plane, or a provider called for each request. */
|
|
707
744
|
type AccessTokenSource = string | (() => string | Promise<string>);
|
|
708
745
|
interface CredentialListOptions extends PaginationOptions {
|
|
@@ -956,6 +993,19 @@ declare class UserScopedClient {
|
|
|
956
993
|
*/
|
|
957
994
|
readonly security: SubjectSecurity;
|
|
958
995
|
readonly tenants: {
|
|
996
|
+
/**
|
|
997
|
+
* GET /auth/tenants/{tenantId} — one tenant, acting as the user: their own,
|
|
998
|
+
* or one below it with `subtenants:tree:read` on an ancestor.
|
|
999
|
+
*/
|
|
1000
|
+
get: (tenantId: string) => Promise<MyTenant>;
|
|
1001
|
+
/**
|
|
1002
|
+
* One tenant by id **or** slug: a UUID goes to `GET /auth/tenants/{id}`,
|
|
1003
|
+
* anything else to `GET /auth/tenants/by-slug/{slug}`. Same rule and answer
|
|
1004
|
+
* as `get`; by slug every refusal is `tenant.not_found`. An empty value
|
|
1005
|
+
* raises `RangeError` before any request. The slug route needs the Authyon
|
|
1006
|
+
* API of 2026-11-26 or newer.
|
|
1007
|
+
*/
|
|
1008
|
+
find: (idOrSlug: string) => Promise<MyTenant>;
|
|
959
1009
|
/**
|
|
960
1010
|
* The direct, active sub-tenants of a tenant, acting as the user. One level
|
|
961
1011
|
* per call: each row's `childCount` says where the next call is worth
|
|
@@ -1327,7 +1377,7 @@ declare class AuthyonServerClient {
|
|
|
1327
1377
|
* 2026-10-22 ignores `filter` and one older than 2026-10-31 ignores
|
|
1328
1378
|
* `parentId`, which read as a page that is too wide rather than an error.
|
|
1329
1379
|
*/
|
|
1330
|
-
list: (params?: TenantListOptions) => Promise<Paged<
|
|
1380
|
+
list: (params?: TenantListOptions) => Promise<Paged<Tenant>>;
|
|
1331
1381
|
/**
|
|
1332
1382
|
* One page of a tenant's direct sub-tenants — `list()` with `parentId`.
|
|
1333
1383
|
*
|
|
@@ -1335,7 +1385,7 @@ declare class AuthyonServerClient {
|
|
|
1335
1385
|
* view asks again where that is above zero instead of reading the whole
|
|
1336
1386
|
* subtree to draw the first level of it.
|
|
1337
1387
|
*/
|
|
1338
|
-
children: (parentTenantId: string, params?: Omit<TenantListOptions, "parentId">) => Promise<Paged<
|
|
1388
|
+
children: (parentTenantId: string, params?: Omit<TenantListOptions, "parentId">) => Promise<Paged<Tenant>>;
|
|
1339
1389
|
/**
|
|
1340
1390
|
* One page of the environment's root tenants — `list()` with no parent.
|
|
1341
1391
|
*
|
|
@@ -1344,7 +1394,7 @@ declare class AuthyonServerClient {
|
|
|
1344
1394
|
* depth, which is what a flat picker wants and what a tree view must not
|
|
1345
1395
|
* start from.
|
|
1346
1396
|
*/
|
|
1347
|
-
roots: (params?: Omit<TenantListOptions, "parentId">) => Promise<Paged<
|
|
1397
|
+
roots: (params?: Omit<TenantListOptions, "parentId">) => Promise<Paged<Tenant>>;
|
|
1348
1398
|
/**
|
|
1349
1399
|
* Every sub-tenant in the environment, at any depth and under any
|
|
1350
1400
|
* parent — `list()` with `minDepth: 1`. This is the one page
|
|
@@ -1356,7 +1406,7 @@ declare class AuthyonServerClient {
|
|
|
1356
1406
|
* Against an Authyon API older than 2026-10-31 the floor is ignored and
|
|
1357
1407
|
* the roots come back too.
|
|
1358
1408
|
*/
|
|
1359
|
-
subTenants: (params?: Omit<TenantListOptions, "parentId" | "minDepth">) => Promise<Paged<
|
|
1409
|
+
subTenants: (params?: Omit<TenantListOptions, "parentId" | "minDepth">) => Promise<Paged<Tenant>>;
|
|
1360
1410
|
/**
|
|
1361
1411
|
* POST /env/tenants — create a tenant in the environment.
|
|
1362
1412
|
*
|
|
@@ -1365,18 +1415,18 @@ declare class AuthyonServerClient {
|
|
|
1365
1415
|
* so this answers `tenant.depth.not_allowed` until an operator raises it
|
|
1366
1416
|
* in the console.
|
|
1367
1417
|
*/
|
|
1368
|
-
create: (input:
|
|
1418
|
+
create: (input: CreateTenantInput) => Promise<Tenant>;
|
|
1369
1419
|
/**
|
|
1370
1420
|
* GET /env/tenants/{tenantId} — fetch a tenant by id.
|
|
1371
1421
|
*
|
|
1372
1422
|
* Returns `ancestors` as well, the chain above it root first, so a
|
|
1373
1423
|
* breadcrumb costs this one call rather than one per level.
|
|
1374
1424
|
*/
|
|
1375
|
-
get: (tenantId: string) => Promise<
|
|
1425
|
+
get: (tenantId: string) => Promise<Tenant>;
|
|
1376
1426
|
/** PUT /env/tenants/{tenantId} — update a tenant. */
|
|
1377
|
-
update: (tenantId: string, input:
|
|
1427
|
+
update: (tenantId: string, input: UpdateTenantInput) => Promise<Tenant>;
|
|
1378
1428
|
/** PUT /env/tenants/{tenantId}/metadata - replace public and private metadata. */
|
|
1379
|
-
updateMetadata: (tenantId: string, input: Pick<
|
|
1429
|
+
updateMetadata: (tenantId: string, input: Pick<CreateTenantInput, "publicMetadata" | "privateMetadata">) => Promise<void>;
|
|
1380
1430
|
/**
|
|
1381
1431
|
* POST /env/tenants/{tenantId}/disable — disable without removing tenant
|
|
1382
1432
|
* data.
|
|
@@ -1656,4 +1706,4 @@ declare class TenantScopedClient {
|
|
|
1656
1706
|
/** Convenience factory: `const authyon = createClient({ clientId, clientSecret })`. */
|
|
1657
1707
|
declare function createClient(options?: AuthyonServerClientOptions): AuthyonServerClient;
|
|
1658
1708
|
|
|
1659
|
-
export { type
|
|
1709
|
+
export { type PasswordResetIssued as $, AuthyonServerClient as A, type BuiltInPermission as B, CLIENT_IP_HEADER as C, type CredentialListOptions as D, type CredentialPermissionsInput as E, type EnvironmentUser as F, FetchHttpAdapter as G, type HttpAdapter as H, type HttpAdapterRequest as I, JwksTokenVerifier as J, type HttpLogEvent as K, type HttpLogger as L, type IntrospectResult as M, type InviteTenantMemberInput as N, type IssuePasswordResetInput as O, type JsonWebKeySet as P, type JwksTokenVerifierOptions as Q, LoggingHttpAdapter as R, type LoginActivity as S, type MemberListOptions as T, type MyTenant as U, type OpenIdConfiguration as V, type Organization as W, type OtpCheckResult as X, type Paged as Y, type PaginationOptions as Z, type PasswordResetCompleted as _, type HttpLoggerOptions as a, type PasswordResetPreview as a0, type Permission as a1, type PermissionsByRole as a2, type ReservedPermissions as a3, type Role as a4, type RoleGrant as a5, type RoleInput as a6, type RoleList as a7, type RolePermissions as a8, type SafeJwtAlgorithm as a9, type TenantOrder as aA, type TenantOrderField as aB, type TenantParent as aC, TenantScopedClient as aD, type TokenResult as aE, TokenVerificationError as aF, type TokenVerificationErrorCode as aG, type UpdateOrganizationInput as aH, type UpdateTenantInput as aI, type User as aJ, UserScopedClient as aK, type ValidateResult as aL, type VerifiedAccessToken as aM, createClient as aN, normalizeClientIp as aO, tenantFilter as aP, type SecurityMethods as aa, type SubTenant as ab, type SubTenantListOptions as ac, type SubjectApprovals as ad, type SubjectSecurity as ae, TENANT_FILTER_MAX_DEPTH as af, TENANT_FILTER_MAX_VALUES as ag, TENANT_FILTER_MAX_VALUE_LENGTH as ah, type Tenant as ai, type TenantAncestor as aj, type TenantClientValidationResult as ak, type TenantCredentialIssued as al, type TenantCredentialSummary as am, type TenantFilterExpression as an, type TenantFilterValue as ao, type TenantInvite as ap, type TenantInviteAccepted as aq, type TenantInviteInput as ar, type TenantInviteIssued as as, type TenantInviteListOptions as at, type TenantInvitePreview as au, type TenantInviteStatus as av, type TenantListOptions as aw, type TenantMember as ax, type TenantMemberPage as ay, type TenantMembership as az, type AcceptTenantInviteInput as b, type AccessTokenSource as c, type Approval as d, type ApprovalAssurance as e, type ApprovalPayload as f, type ApprovalStatus as g, type ApprovalWebAuthnOptions as h, type AuditEvent as i, type AuthyonJwksDiscoveryOptions as j, type AuthyonJwtClaims as k, type AuthyonServerClientOptions as l, type AuthyonTenantClaim as m, type ClientCredentials as n, type ClientRequestContext as o, type ConfirmApprovalInput as p, type ConsumedApproval as q, type CreateApprovalInput as r, type CreateCredentialInput as s, type CreateOrganizationInput as t, type CreatePermissionInput as u, type CreateTenantCredentialInput as v, type CreateTenantInput as w, type CreateUserInput as x, type CredentialCreator as y, type CredentialDetail as z };
|
|
@@ -239,6 +239,36 @@ interface SubTenant {
|
|
|
239
239
|
/** The tenant it hangs from — the same on every row of a page, carried so a row stands on its own. */
|
|
240
240
|
parent: TenantParent;
|
|
241
241
|
}
|
|
242
|
+
/**
|
|
243
|
+
* One tenant as the end-user routes return it (`GET /auth/tenants/{id}` and
|
|
244
|
+
* `/auth/tenants/by-slug/{slug}`): the user's own, or one below it read with
|
|
245
|
+
* `subtenants:tree:read` from an ancestor.
|
|
246
|
+
*/
|
|
247
|
+
interface MyTenant {
|
|
248
|
+
id: string;
|
|
249
|
+
slug: string;
|
|
250
|
+
name: string;
|
|
251
|
+
description?: string | null;
|
|
252
|
+
createdAt: string;
|
|
253
|
+
updatedAt?: string | null;
|
|
254
|
+
memberCount: number;
|
|
255
|
+
/** Roles the user holds in it; empty when they reach it from an ancestor. */
|
|
256
|
+
myRoles: string[];
|
|
257
|
+
/**
|
|
258
|
+
* The end-user-route permissions the user can use on it, as concrete values.
|
|
259
|
+
* This, not `myRoles`, is what decides which actions to offer.
|
|
260
|
+
*/
|
|
261
|
+
myPermissions?: string[];
|
|
262
|
+
/** JSON-encoded metadata visible to members. */
|
|
263
|
+
publicMetadata: string;
|
|
264
|
+
isDisabled: boolean;
|
|
265
|
+
/** Distance from the root: `0` at a root tenant. */
|
|
266
|
+
depth: number;
|
|
267
|
+
/** `true` when the user reaches it from an ancestor rather than as a member. */
|
|
268
|
+
inherited: boolean;
|
|
269
|
+
/** The tenant it hangs from, `null` for a root. */
|
|
270
|
+
parent: TenantParent | null;
|
|
271
|
+
}
|
|
242
272
|
|
|
243
273
|
/**
|
|
244
274
|
* Builders for the tenant list's structured filters.
|
|
@@ -278,7 +308,7 @@ declare const tenantFilter: {
|
|
|
278
308
|
};
|
|
279
309
|
|
|
280
310
|
/** GET/POST /env/tenants — confirmed against the live API. */
|
|
281
|
-
interface
|
|
311
|
+
interface Tenant {
|
|
282
312
|
id: string;
|
|
283
313
|
slug: string;
|
|
284
314
|
name?: string;
|
|
@@ -318,7 +348,7 @@ interface Organization {
|
|
|
318
348
|
*/
|
|
319
349
|
ancestors?: TenantAncestor[];
|
|
320
350
|
}
|
|
321
|
-
/** One step of the chain above a tenant, as `
|
|
351
|
+
/** One step of the chain above a tenant, as `Tenant.ancestors` carries it. */
|
|
322
352
|
interface TenantAncestor {
|
|
323
353
|
id: string;
|
|
324
354
|
name: string;
|
|
@@ -496,7 +526,7 @@ interface PermissionsByRole {
|
|
|
496
526
|
roles: RolePermissions[];
|
|
497
527
|
orphans: Permission[];
|
|
498
528
|
/**
|
|
499
|
-
* The permissions Authyon itself checks on the end-user
|
|
529
|
+
* The permissions Authyon itself checks on the end-user tenant routes
|
|
500
530
|
* (`tenants:settings:manage`, `tenants:members:invite`,
|
|
501
531
|
* `tenants:members:remove` and `subtenants:tree:*`), listed whether or not
|
|
502
532
|
* a role names them. Absent from an API older than 2026-11-25.
|
|
@@ -522,7 +552,7 @@ interface CreatePermissionInput {
|
|
|
522
552
|
/** Attach the new permission to this role immediately. */
|
|
523
553
|
attachToRoleId?: string;
|
|
524
554
|
}
|
|
525
|
-
interface
|
|
555
|
+
interface CreateTenantInput {
|
|
526
556
|
name: string;
|
|
527
557
|
slug: string;
|
|
528
558
|
description?: string;
|
|
@@ -541,7 +571,7 @@ interface CreateOrganizationInput {
|
|
|
541
571
|
*/
|
|
542
572
|
parentTenantId?: string;
|
|
543
573
|
}
|
|
544
|
-
interface
|
|
574
|
+
interface UpdateTenantInput {
|
|
545
575
|
name: string;
|
|
546
576
|
description?: string;
|
|
547
577
|
customFields?: Record<string, unknown>;
|
|
@@ -561,7 +591,7 @@ interface CreateUserInput {
|
|
|
561
591
|
customFields?: Record<string, unknown>;
|
|
562
592
|
emailConfirmed?: boolean;
|
|
563
593
|
roles?: string[];
|
|
564
|
-
/** Tenants
|
|
594
|
+
/** Tenants to add the user to on creation. */
|
|
565
595
|
tenantIds?: string[];
|
|
566
596
|
}
|
|
567
597
|
/** GET /env/audit — one audit-trail entry, confirmed against the live API. */
|
|
@@ -703,6 +733,13 @@ interface AuthyonServerClientOptions {
|
|
|
703
733
|
fetch?: typeof fetch;
|
|
704
734
|
}
|
|
705
735
|
|
|
736
|
+
/** @deprecated Use `Tenant`. */
|
|
737
|
+
type Organization = Tenant;
|
|
738
|
+
/** @deprecated Use `CreateTenantInput`. */
|
|
739
|
+
type CreateOrganizationInput = CreateTenantInput;
|
|
740
|
+
/** @deprecated Use `UpdateTenantInput`. */
|
|
741
|
+
type UpdateOrganizationInput = UpdateTenantInput;
|
|
742
|
+
|
|
706
743
|
/** A token of the requested authentication plane, or a provider called for each request. */
|
|
707
744
|
type AccessTokenSource = string | (() => string | Promise<string>);
|
|
708
745
|
interface CredentialListOptions extends PaginationOptions {
|
|
@@ -956,6 +993,19 @@ declare class UserScopedClient {
|
|
|
956
993
|
*/
|
|
957
994
|
readonly security: SubjectSecurity;
|
|
958
995
|
readonly tenants: {
|
|
996
|
+
/**
|
|
997
|
+
* GET /auth/tenants/{tenantId} — one tenant, acting as the user: their own,
|
|
998
|
+
* or one below it with `subtenants:tree:read` on an ancestor.
|
|
999
|
+
*/
|
|
1000
|
+
get: (tenantId: string) => Promise<MyTenant>;
|
|
1001
|
+
/**
|
|
1002
|
+
* One tenant by id **or** slug: a UUID goes to `GET /auth/tenants/{id}`,
|
|
1003
|
+
* anything else to `GET /auth/tenants/by-slug/{slug}`. Same rule and answer
|
|
1004
|
+
* as `get`; by slug every refusal is `tenant.not_found`. An empty value
|
|
1005
|
+
* raises `RangeError` before any request. The slug route needs the Authyon
|
|
1006
|
+
* API of 2026-11-26 or newer.
|
|
1007
|
+
*/
|
|
1008
|
+
find: (idOrSlug: string) => Promise<MyTenant>;
|
|
959
1009
|
/**
|
|
960
1010
|
* The direct, active sub-tenants of a tenant, acting as the user. One level
|
|
961
1011
|
* per call: each row's `childCount` says where the next call is worth
|
|
@@ -1327,7 +1377,7 @@ declare class AuthyonServerClient {
|
|
|
1327
1377
|
* 2026-10-22 ignores `filter` and one older than 2026-10-31 ignores
|
|
1328
1378
|
* `parentId`, which read as a page that is too wide rather than an error.
|
|
1329
1379
|
*/
|
|
1330
|
-
list: (params?: TenantListOptions) => Promise<Paged<
|
|
1380
|
+
list: (params?: TenantListOptions) => Promise<Paged<Tenant>>;
|
|
1331
1381
|
/**
|
|
1332
1382
|
* One page of a tenant's direct sub-tenants — `list()` with `parentId`.
|
|
1333
1383
|
*
|
|
@@ -1335,7 +1385,7 @@ declare class AuthyonServerClient {
|
|
|
1335
1385
|
* view asks again where that is above zero instead of reading the whole
|
|
1336
1386
|
* subtree to draw the first level of it.
|
|
1337
1387
|
*/
|
|
1338
|
-
children: (parentTenantId: string, params?: Omit<TenantListOptions, "parentId">) => Promise<Paged<
|
|
1388
|
+
children: (parentTenantId: string, params?: Omit<TenantListOptions, "parentId">) => Promise<Paged<Tenant>>;
|
|
1339
1389
|
/**
|
|
1340
1390
|
* One page of the environment's root tenants — `list()` with no parent.
|
|
1341
1391
|
*
|
|
@@ -1344,7 +1394,7 @@ declare class AuthyonServerClient {
|
|
|
1344
1394
|
* depth, which is what a flat picker wants and what a tree view must not
|
|
1345
1395
|
* start from.
|
|
1346
1396
|
*/
|
|
1347
|
-
roots: (params?: Omit<TenantListOptions, "parentId">) => Promise<Paged<
|
|
1397
|
+
roots: (params?: Omit<TenantListOptions, "parentId">) => Promise<Paged<Tenant>>;
|
|
1348
1398
|
/**
|
|
1349
1399
|
* Every sub-tenant in the environment, at any depth and under any
|
|
1350
1400
|
* parent — `list()` with `minDepth: 1`. This is the one page
|
|
@@ -1356,7 +1406,7 @@ declare class AuthyonServerClient {
|
|
|
1356
1406
|
* Against an Authyon API older than 2026-10-31 the floor is ignored and
|
|
1357
1407
|
* the roots come back too.
|
|
1358
1408
|
*/
|
|
1359
|
-
subTenants: (params?: Omit<TenantListOptions, "parentId" | "minDepth">) => Promise<Paged<
|
|
1409
|
+
subTenants: (params?: Omit<TenantListOptions, "parentId" | "minDepth">) => Promise<Paged<Tenant>>;
|
|
1360
1410
|
/**
|
|
1361
1411
|
* POST /env/tenants — create a tenant in the environment.
|
|
1362
1412
|
*
|
|
@@ -1365,18 +1415,18 @@ declare class AuthyonServerClient {
|
|
|
1365
1415
|
* so this answers `tenant.depth.not_allowed` until an operator raises it
|
|
1366
1416
|
* in the console.
|
|
1367
1417
|
*/
|
|
1368
|
-
create: (input:
|
|
1418
|
+
create: (input: CreateTenantInput) => Promise<Tenant>;
|
|
1369
1419
|
/**
|
|
1370
1420
|
* GET /env/tenants/{tenantId} — fetch a tenant by id.
|
|
1371
1421
|
*
|
|
1372
1422
|
* Returns `ancestors` as well, the chain above it root first, so a
|
|
1373
1423
|
* breadcrumb costs this one call rather than one per level.
|
|
1374
1424
|
*/
|
|
1375
|
-
get: (tenantId: string) => Promise<
|
|
1425
|
+
get: (tenantId: string) => Promise<Tenant>;
|
|
1376
1426
|
/** PUT /env/tenants/{tenantId} — update a tenant. */
|
|
1377
|
-
update: (tenantId: string, input:
|
|
1427
|
+
update: (tenantId: string, input: UpdateTenantInput) => Promise<Tenant>;
|
|
1378
1428
|
/** PUT /env/tenants/{tenantId}/metadata - replace public and private metadata. */
|
|
1379
|
-
updateMetadata: (tenantId: string, input: Pick<
|
|
1429
|
+
updateMetadata: (tenantId: string, input: Pick<CreateTenantInput, "publicMetadata" | "privateMetadata">) => Promise<void>;
|
|
1380
1430
|
/**
|
|
1381
1431
|
* POST /env/tenants/{tenantId}/disable — disable without removing tenant
|
|
1382
1432
|
* data.
|
|
@@ -1656,4 +1706,4 @@ declare class TenantScopedClient {
|
|
|
1656
1706
|
/** Convenience factory: `const authyon = createClient({ clientId, clientSecret })`. */
|
|
1657
1707
|
declare function createClient(options?: AuthyonServerClientOptions): AuthyonServerClient;
|
|
1658
1708
|
|
|
1659
|
-
export { type
|
|
1709
|
+
export { type PasswordResetIssued as $, AuthyonServerClient as A, type BuiltInPermission as B, CLIENT_IP_HEADER as C, type CredentialListOptions as D, type CredentialPermissionsInput as E, type EnvironmentUser as F, FetchHttpAdapter as G, type HttpAdapter as H, type HttpAdapterRequest as I, JwksTokenVerifier as J, type HttpLogEvent as K, type HttpLogger as L, type IntrospectResult as M, type InviteTenantMemberInput as N, type IssuePasswordResetInput as O, type JsonWebKeySet as P, type JwksTokenVerifierOptions as Q, LoggingHttpAdapter as R, type LoginActivity as S, type MemberListOptions as T, type MyTenant as U, type OpenIdConfiguration as V, type Organization as W, type OtpCheckResult as X, type Paged as Y, type PaginationOptions as Z, type PasswordResetCompleted as _, type HttpLoggerOptions as a, type PasswordResetPreview as a0, type Permission as a1, type PermissionsByRole as a2, type ReservedPermissions as a3, type Role as a4, type RoleGrant as a5, type RoleInput as a6, type RoleList as a7, type RolePermissions as a8, type SafeJwtAlgorithm as a9, type TenantOrder as aA, type TenantOrderField as aB, type TenantParent as aC, TenantScopedClient as aD, type TokenResult as aE, TokenVerificationError as aF, type TokenVerificationErrorCode as aG, type UpdateOrganizationInput as aH, type UpdateTenantInput as aI, type User as aJ, UserScopedClient as aK, type ValidateResult as aL, type VerifiedAccessToken as aM, createClient as aN, normalizeClientIp as aO, tenantFilter as aP, type SecurityMethods as aa, type SubTenant as ab, type SubTenantListOptions as ac, type SubjectApprovals as ad, type SubjectSecurity as ae, TENANT_FILTER_MAX_DEPTH as af, TENANT_FILTER_MAX_VALUES as ag, TENANT_FILTER_MAX_VALUE_LENGTH as ah, type Tenant as ai, type TenantAncestor as aj, type TenantClientValidationResult as ak, type TenantCredentialIssued as al, type TenantCredentialSummary as am, type TenantFilterExpression as an, type TenantFilterValue as ao, type TenantInvite as ap, type TenantInviteAccepted as aq, type TenantInviteInput as ar, type TenantInviteIssued as as, type TenantInviteListOptions as at, type TenantInvitePreview as au, type TenantInviteStatus as av, type TenantListOptions as aw, type TenantMember as ax, type TenantMemberPage as ay, type TenantMembership as az, type AcceptTenantInviteInput as b, type AccessTokenSource as c, type Approval as d, type ApprovalAssurance as e, type ApprovalPayload as f, type ApprovalStatus as g, type ApprovalWebAuthnOptions as h, type AuditEvent as i, type AuthyonJwksDiscoveryOptions as j, type AuthyonJwtClaims as k, type AuthyonServerClientOptions as l, type AuthyonTenantClaim as m, type ClientCredentials as n, type ClientRequestContext as o, type ConfirmApprovalInput as p, type ConsumedApproval as q, type CreateApprovalInput as r, type CreateCredentialInput as s, type CreateOrganizationInput as t, type CreatePermissionInput as u, type CreateTenantCredentialInput as v, type CreateTenantInput as w, type CreateUserInput as x, type CredentialCreator as y, type CredentialDetail as z };
|
package/dist/bff.cjs
CHANGED
|
@@ -307,7 +307,7 @@ function loginInput(body) {
|
|
|
307
307
|
return {
|
|
308
308
|
password: inputString(body, "password"),
|
|
309
309
|
...body.email !== void 0 ? { email: inputString(body, "email") } : { username: inputString(body, "username") },
|
|
310
|
-
...body.organizationSlug !== void 0 ? {
|
|
310
|
+
...body.tenantSlug !== void 0 ? { tenantSlug: inputString(body, "tenantSlug") } : body.organizationSlug !== void 0 ? { tenantSlug: inputString(body, "organizationSlug") } : {},
|
|
311
311
|
sessionPersistence: sessionPersistence(body)
|
|
312
312
|
};
|
|
313
313
|
}
|
|
@@ -455,11 +455,11 @@ var BffSessionManager = class {
|
|
|
455
455
|
});
|
|
456
456
|
this.refreshAhead = positiveDuration(options.refreshAheadMs ?? DEFAULT_REFRESH_AHEAD_MS);
|
|
457
457
|
}
|
|
458
|
-
async create(tokens,
|
|
458
|
+
async create(tokens, tenantSlug, sessionPersistence2 = "standard") {
|
|
459
459
|
try {
|
|
460
460
|
const user = await this.verifiedProfile(tokens);
|
|
461
|
-
if (
|
|
462
|
-
throw new BffSessionError("session.
|
|
461
|
+
if (tenantSlug !== void 0 && user.tenant?.slug !== tenantSlug) {
|
|
462
|
+
throw new BffSessionError("session.tenant_mismatch", 502);
|
|
463
463
|
}
|
|
464
464
|
const lifetime = this.sessionLifetime(sessionPersistence2);
|
|
465
465
|
const record = {
|
|
@@ -480,15 +480,19 @@ var BffSessionManager = class {
|
|
|
480
480
|
async read(id) {
|
|
481
481
|
return this.readCurrent(id, 0);
|
|
482
482
|
}
|
|
483
|
+
/** @deprecated Use `switchTenant`. */
|
|
483
484
|
async switchOrganization(id, slug) {
|
|
485
|
+
return this.switchTenant(id, slug);
|
|
486
|
+
}
|
|
487
|
+
async switchTenant(id, slug) {
|
|
484
488
|
return this.update(id, async (lease) => {
|
|
485
489
|
const refreshed = await this.refreshIfNeeded(lease);
|
|
486
490
|
if (!refreshed && !await this.options.provider.validate(lease.record.tokens.accessToken)) {
|
|
487
491
|
throw new BffSessionError("session.revoked", 401, true);
|
|
488
492
|
}
|
|
489
493
|
await this.rotate(lease, {
|
|
490
|
-
issue: () => this.
|
|
491
|
-
accepts: (user) => user.id === lease.record.user.id && user.
|
|
494
|
+
issue: () => this.issueTenantTokens(lease.record.tokens.accessToken, slug),
|
|
495
|
+
accepts: (user) => user.id === lease.record.user.id && user.tenant?.slug === slug
|
|
492
496
|
});
|
|
493
497
|
});
|
|
494
498
|
}
|
|
@@ -571,7 +575,7 @@ var BffSessionManager = class {
|
|
|
571
575
|
if (!this.needsRefresh(lease.record)) return false;
|
|
572
576
|
await this.rotate(lease, {
|
|
573
577
|
issue: () => this.options.provider.refresh(lease.record.tokens.refreshToken),
|
|
574
|
-
accepts: (user) => user.id === lease.record.user.id && user.
|
|
578
|
+
accepts: (user) => user.id === lease.record.user.id && user.tenant?.id === lease.record.user.tenant?.id
|
|
575
579
|
});
|
|
576
580
|
return true;
|
|
577
581
|
}
|
|
@@ -581,7 +585,7 @@ var BffSessionManager = class {
|
|
|
581
585
|
tokens = await operation.issue();
|
|
582
586
|
} catch (error) {
|
|
583
587
|
if (error instanceof AuthyonError && error.status === 429) throw error;
|
|
584
|
-
if (error instanceof BffSessionError && error.code === "
|
|
588
|
+
if (error instanceof BffSessionError && error.code === "tenant.forbidden") throw error;
|
|
585
589
|
if (rejectedCredential(error)) throw error;
|
|
586
590
|
if (error instanceof BffSessionError && error.clearCookie) throw error;
|
|
587
591
|
throw new BffSessionError("session.rotation_interrupted", 503, true);
|
|
@@ -597,12 +601,15 @@ var BffSessionManager = class {
|
|
|
597
601
|
throw new BffSessionError("session.rotation_interrupted", 503, true);
|
|
598
602
|
}
|
|
599
603
|
}
|
|
600
|
-
async
|
|
604
|
+
async issueTenantTokens(accessToken, slug) {
|
|
605
|
+
const provider = this.options.provider;
|
|
606
|
+
const issue = provider.switchTenant ?? provider.switchOrganization;
|
|
607
|
+
if (!issue) throw new BffSessionError("provider.unsupported_operation", 501);
|
|
601
608
|
try {
|
|
602
|
-
return await
|
|
609
|
+
return await issue.call(provider, accessToken, slug);
|
|
603
610
|
} catch (error) {
|
|
604
611
|
if (error instanceof AuthyonError && error.status === 403)
|
|
605
|
-
throw new BffSessionError("
|
|
612
|
+
throw new BffSessionError("tenant.forbidden", 403);
|
|
606
613
|
throw error;
|
|
607
614
|
}
|
|
608
615
|
}
|
|
@@ -613,10 +620,11 @@ var BffSessionManager = class {
|
|
|
613
620
|
if (!await this.options.provider.validate(tokens.accessToken))
|
|
614
621
|
throw new BffSessionError("session.revoked", 401, true);
|
|
615
622
|
const user = await this.options.provider.profile(tokens.accessToken);
|
|
623
|
+
const tenant = user.tenant ?? user.organization ?? null;
|
|
616
624
|
return {
|
|
617
625
|
id: user.id,
|
|
618
626
|
email: user.email,
|
|
619
|
-
|
|
627
|
+
tenant: tenant ? { id: tenant.id, slug: tenant.slug } : null
|
|
620
628
|
};
|
|
621
629
|
}
|
|
622
630
|
async revokeUnstoredTokens(tokens) {
|
|
@@ -629,8 +637,12 @@ var BffSessionManager = class {
|
|
|
629
637
|
};
|
|
630
638
|
|
|
631
639
|
// src/bff/handlers.ts
|
|
640
|
+
function publicUser(user) {
|
|
641
|
+
const { id, email, tenant } = user;
|
|
642
|
+
return { id, email, tenant, organization: tenant };
|
|
643
|
+
}
|
|
632
644
|
function publicSession(record) {
|
|
633
|
-
return { authenticated: true, user: record.user, expiresAt: record.expiresAt };
|
|
645
|
+
return { authenticated: true, user: publicUser(record.user), expiresAt: record.expiresAt };
|
|
634
646
|
}
|
|
635
647
|
function createBffSession(options) {
|
|
636
648
|
const http = createBffHttp(options);
|
|
@@ -658,8 +670,8 @@ function createBffSession(options) {
|
|
|
658
670
|
}
|
|
659
671
|
};
|
|
660
672
|
}
|
|
661
|
-
async function finishLogin(tokens,
|
|
662
|
-
const { id, record } = await manager.create(tokens,
|
|
673
|
+
async function finishLogin(tokens, tenantSlug, sessionPersistence2) {
|
|
674
|
+
const { id, record } = await manager.create(tokens, tenantSlug, sessionPersistence2);
|
|
663
675
|
return http.response(publicSession(record), { cookie: http.cookie(id, record.expiresAt) });
|
|
664
676
|
}
|
|
665
677
|
async function assertSignedOut(request) {
|
|
@@ -673,6 +685,16 @@ function createBffSession(options) {
|
|
|
673
685
|
}
|
|
674
686
|
throw new BffSessionError("session.already_authenticated", 409);
|
|
675
687
|
}
|
|
688
|
+
const switchTenant = handler("POST", async (request) => {
|
|
689
|
+
const body = await readBffBody(request);
|
|
690
|
+
const slug = inputString(
|
|
691
|
+
body,
|
|
692
|
+
body.tenantSlug === void 0 && body.organizationSlug !== void 0 ? "organizationSlug" : "tenantSlug"
|
|
693
|
+
);
|
|
694
|
+
return http.response(
|
|
695
|
+
publicSession(await manager.switchTenant(requiredSessionId(request), slug))
|
|
696
|
+
);
|
|
697
|
+
});
|
|
676
698
|
return {
|
|
677
699
|
login: handler("POST", async (request) => {
|
|
678
700
|
await assertSignedOut(request);
|
|
@@ -685,7 +707,7 @@ function createBffSession(options) {
|
|
|
685
707
|
methods: result.methods
|
|
686
708
|
});
|
|
687
709
|
}
|
|
688
|
-
return finishLogin(result, input.
|
|
710
|
+
return finishLogin(result, input.tenantSlug, input.sessionPersistence);
|
|
689
711
|
}),
|
|
690
712
|
verifyTwoFactor: handler("POST", async (request) => {
|
|
691
713
|
await assertSignedOut(request);
|
|
@@ -707,12 +729,10 @@ function createBffSession(options) {
|
|
|
707
729
|
"GET",
|
|
708
730
|
async (request) => http.response(publicSession(await manager.read(requiredSessionId(request))))
|
|
709
731
|
),
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
);
|
|
715
|
-
}),
|
|
732
|
+
/** Body `{ tenantSlug }` (the deprecated `{ organizationSlug }` is still read). */
|
|
733
|
+
switchTenant,
|
|
734
|
+
/** @deprecated Mount `switchTenant`; this is the same handler. */
|
|
735
|
+
switchOrganization: switchTenant,
|
|
716
736
|
logout: handler("POST", async (request) => {
|
|
717
737
|
const id = http.sessionId(request);
|
|
718
738
|
if (id) {
|
|
@@ -730,7 +750,7 @@ function createBffSession(options) {
|
|
|
730
750
|
const record = await manager.read(requiredSessionId(request));
|
|
731
751
|
return {
|
|
732
752
|
accessToken: record.tokens.accessToken,
|
|
733
|
-
user: record.user,
|
|
753
|
+
user: publicUser(record.user),
|
|
734
754
|
expiresAt: record.expiresAt
|
|
735
755
|
};
|
|
736
756
|
},
|
|
@@ -988,12 +1008,12 @@ function readChallenge(value) {
|
|
|
988
1008
|
}
|
|
989
1009
|
function readProfile(value) {
|
|
990
1010
|
const user = object(value);
|
|
991
|
-
const
|
|
992
|
-
const
|
|
1011
|
+
const active = user.tenant ?? user.activeTenant ?? user.activeOrganization;
|
|
1012
|
+
const tenant = active == null ? null : object(active);
|
|
993
1013
|
return {
|
|
994
1014
|
id: requiredString(user.id),
|
|
995
1015
|
email: requiredString(user.email),
|
|
996
|
-
|
|
1016
|
+
tenant: tenant ? { id: requiredString(tenant.id), slug: requiredString(tenant.slug) } : null
|
|
997
1017
|
};
|
|
998
1018
|
}
|
|
999
1019
|
function createAuthyonBffProvider(options) {
|
|
@@ -1009,6 +1029,8 @@ function createAuthyonBffProvider(options) {
|
|
|
1009
1029
|
return {
|
|
1010
1030
|
async login(input) {
|
|
1011
1031
|
const credentials = { ...input };
|
|
1032
|
+
const tenantSlug = input.tenantSlug ?? input.organizationSlug;
|
|
1033
|
+
delete credentials.tenantSlug;
|
|
1012
1034
|
delete credentials.organizationSlug;
|
|
1013
1035
|
delete credentials.sessionPersistence;
|
|
1014
1036
|
const response = object(
|
|
@@ -1017,7 +1039,7 @@ function createAuthyonBffProvider(options) {
|
|
|
1017
1039
|
headers,
|
|
1018
1040
|
body: {
|
|
1019
1041
|
...credentials,
|
|
1020
|
-
...
|
|
1042
|
+
...tenantSlug ? { tenantSlug } : {}
|
|
1021
1043
|
}
|
|
1022
1044
|
})
|
|
1023
1045
|
);
|
|
@@ -1045,7 +1067,7 @@ function createAuthyonBffProvider(options) {
|
|
|
1045
1067
|
async logout(refreshToken) {
|
|
1046
1068
|
await http.request("/auth/logout", { method: "POST", headers, body: { refreshToken } });
|
|
1047
1069
|
},
|
|
1048
|
-
async
|
|
1070
|
+
async switchTenant(accessToken, slug) {
|
|
1049
1071
|
return readTokens(
|
|
1050
1072
|
await http.request("/auth/switch-tenant", {
|
|
1051
1073
|
method: "POST",
|
|
@@ -1121,12 +1143,18 @@ function isObject(value) {
|
|
|
1121
1143
|
function isFiniteNumber(value) {
|
|
1122
1144
|
return typeof value === "number" && Number.isFinite(value);
|
|
1123
1145
|
}
|
|
1124
|
-
function
|
|
1146
|
+
function isTenant(value) {
|
|
1125
1147
|
return value === null || isObject(value) && typeof value.id === "string" && typeof value.slug === "string";
|
|
1126
1148
|
}
|
|
1149
|
+
function upgradeLegacyRecord(value) {
|
|
1150
|
+
if (!isObject(value) || !isObject(value.user)) return value;
|
|
1151
|
+
if (value.user.tenant !== void 0 || value.user.organization === void 0) return value;
|
|
1152
|
+
const { organization, ...user } = value.user;
|
|
1153
|
+
return { ...value, user: { ...user, tenant: organization } };
|
|
1154
|
+
}
|
|
1127
1155
|
function isSessionRecord(value) {
|
|
1128
1156
|
if (!isObject(value) || !isObject(value.tokens) || !isObject(value.user)) return false;
|
|
1129
|
-
return typeof value.revision === "string" && typeof value.tokens.accessToken === "string" && typeof value.tokens.refreshToken === "string" && isFiniteNumber(value.tokens.expiresAt) && typeof value.user.id === "string" && typeof value.user.email === "string" &&
|
|
1157
|
+
return typeof value.revision === "string" && typeof value.tokens.accessToken === "string" && typeof value.tokens.refreshToken === "string" && isFiniteNumber(value.tokens.expiresAt) && typeof value.user.id === "string" && typeof value.user.email === "string" && isTenant(value.user.tenant) && (value.sessionPersistence === void 0 || value.sessionPersistence === "standard" || value.sessionPersistence === "remembered") && isFiniteNumber(value.expiresAt) && isFiniteNumber(value.idleExpiresAt) && (value.busyUntil === null || isFiniteNumber(value.busyUntil));
|
|
1130
1158
|
}
|
|
1131
1159
|
function createRedisBffSessionStore(options) {
|
|
1132
1160
|
if (options.encryptionKey.byteLength !== 32) {
|
|
@@ -1145,7 +1173,7 @@ function createRedisBffSessionStore(options) {
|
|
|
1145
1173
|
contentEncryptionAlgorithms: ["A256GCM"],
|
|
1146
1174
|
audience: prefix + key
|
|
1147
1175
|
});
|
|
1148
|
-
const record = payload.session;
|
|
1176
|
+
const record = upgradeLegacyRecord(payload.session);
|
|
1149
1177
|
if (!isSessionRecord(record) || record.revision !== envelope.revision) {
|
|
1150
1178
|
throw new Error("invalid session record");
|
|
1151
1179
|
}
|
package/dist/bff.d.cts
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
|
-
import { H as HttpAdapter, a as HttpLoggerOptions, A as AuthyonServerClient } from './authyonServerClient-
|
|
1
|
+
import { H as HttpAdapter, a as HttpLoggerOptions, A as AuthyonServerClient } from './authyonServerClient-mwY55kc9.cjs';
|
|
2
2
|
import 'jose';
|
|
3
3
|
|
|
4
4
|
interface BffLoginInput {
|
|
5
5
|
email?: string;
|
|
6
6
|
username?: string;
|
|
7
7
|
password: string;
|
|
8
|
+
/** Tenant to scope the new session to. */
|
|
9
|
+
tenantSlug?: string;
|
|
10
|
+
/** @deprecated Use `tenantSlug`. */
|
|
8
11
|
organizationSlug?: string;
|
|
9
12
|
sessionPersistence?: BffSessionPersistence;
|
|
10
13
|
}
|
|
@@ -32,7 +35,16 @@ interface BffTokens {
|
|
|
32
35
|
interface BffUser {
|
|
33
36
|
id: string;
|
|
34
37
|
email: string;
|
|
35
|
-
|
|
38
|
+
/** The tenant the session is scoped to, or `null`. */
|
|
39
|
+
tenant: {
|
|
40
|
+
id: string;
|
|
41
|
+
slug: string;
|
|
42
|
+
} | null;
|
|
43
|
+
/**
|
|
44
|
+
* @deprecated Use `tenant`. Still read from custom providers and still sent
|
|
45
|
+
* to the browser as a mirror of `tenant`; removed in a later release.
|
|
46
|
+
*/
|
|
47
|
+
organization?: {
|
|
36
48
|
id: string;
|
|
37
49
|
slug: string;
|
|
38
50
|
} | null;
|
|
@@ -52,7 +64,14 @@ interface BffAuthProvider {
|
|
|
52
64
|
resendTwoFactorEmail?(challengeToken: string): Promise<void>;
|
|
53
65
|
refresh(refreshToken: string): Promise<BffTokens>;
|
|
54
66
|
logout(refreshToken: string): Promise<void>;
|
|
55
|
-
|
|
67
|
+
/**
|
|
68
|
+
* Issues tokens scoped to another tenant. Optional only so providers written
|
|
69
|
+
* against the old name keep working: one of `switchTenant` or the deprecated
|
|
70
|
+
* `switchOrganization` must exist, or switching answers 501.
|
|
71
|
+
*/
|
|
72
|
+
switchTenant?(accessToken: string, slug: string): Promise<BffTokens>;
|
|
73
|
+
/** @deprecated Implement `switchTenant`. */
|
|
74
|
+
switchOrganization?(accessToken: string, slug: string): Promise<BffTokens>;
|
|
56
75
|
validate(accessToken: string): Promise<boolean>;
|
|
57
76
|
profile(accessToken: string): Promise<BffUser>;
|
|
58
77
|
}
|
|
@@ -98,12 +117,26 @@ declare function createBffSession(options: BffSessionOptions): {
|
|
|
98
117
|
/** Same guards as `verifyTwoFactor`; never creates a session or sets a cookie. */
|
|
99
118
|
resendTwoFactorEmail: (request: Request) => Promise<Response>;
|
|
100
119
|
session: (request: Request) => Promise<Response>;
|
|
120
|
+
/** Body `{ tenantSlug }` (the deprecated `{ organizationSlug }` is still read). */
|
|
121
|
+
switchTenant: (request: Request) => Promise<Response>;
|
|
122
|
+
/** @deprecated Mount `switchTenant`; this is the same handler. */
|
|
101
123
|
switchOrganization: (request: Request) => Promise<Response>;
|
|
102
124
|
logout: (request: Request) => Promise<Response>;
|
|
103
125
|
/** Server-only credential for downstream calls. Never serialize this result to the browser. */
|
|
104
126
|
requireSession(request: Request): Promise<{
|
|
105
127
|
accessToken: string;
|
|
106
|
-
user:
|
|
128
|
+
user: {
|
|
129
|
+
id: string;
|
|
130
|
+
email: string;
|
|
131
|
+
tenant: {
|
|
132
|
+
id: string;
|
|
133
|
+
slug: string;
|
|
134
|
+
} | null;
|
|
135
|
+
organization: {
|
|
136
|
+
id: string;
|
|
137
|
+
slug: string;
|
|
138
|
+
} | null;
|
|
139
|
+
};
|
|
107
140
|
expiresAt: number;
|
|
108
141
|
}>;
|
|
109
142
|
errorResponse: (error: unknown) => Response;
|
package/dist/bff.d.ts
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
|
-
import { H as HttpAdapter, a as HttpLoggerOptions, A as AuthyonServerClient } from './authyonServerClient-
|
|
1
|
+
import { H as HttpAdapter, a as HttpLoggerOptions, A as AuthyonServerClient } from './authyonServerClient-mwY55kc9.js';
|
|
2
2
|
import 'jose';
|
|
3
3
|
|
|
4
4
|
interface BffLoginInput {
|
|
5
5
|
email?: string;
|
|
6
6
|
username?: string;
|
|
7
7
|
password: string;
|
|
8
|
+
/** Tenant to scope the new session to. */
|
|
9
|
+
tenantSlug?: string;
|
|
10
|
+
/** @deprecated Use `tenantSlug`. */
|
|
8
11
|
organizationSlug?: string;
|
|
9
12
|
sessionPersistence?: BffSessionPersistence;
|
|
10
13
|
}
|
|
@@ -32,7 +35,16 @@ interface BffTokens {
|
|
|
32
35
|
interface BffUser {
|
|
33
36
|
id: string;
|
|
34
37
|
email: string;
|
|
35
|
-
|
|
38
|
+
/** The tenant the session is scoped to, or `null`. */
|
|
39
|
+
tenant: {
|
|
40
|
+
id: string;
|
|
41
|
+
slug: string;
|
|
42
|
+
} | null;
|
|
43
|
+
/**
|
|
44
|
+
* @deprecated Use `tenant`. Still read from custom providers and still sent
|
|
45
|
+
* to the browser as a mirror of `tenant`; removed in a later release.
|
|
46
|
+
*/
|
|
47
|
+
organization?: {
|
|
36
48
|
id: string;
|
|
37
49
|
slug: string;
|
|
38
50
|
} | null;
|
|
@@ -52,7 +64,14 @@ interface BffAuthProvider {
|
|
|
52
64
|
resendTwoFactorEmail?(challengeToken: string): Promise<void>;
|
|
53
65
|
refresh(refreshToken: string): Promise<BffTokens>;
|
|
54
66
|
logout(refreshToken: string): Promise<void>;
|
|
55
|
-
|
|
67
|
+
/**
|
|
68
|
+
* Issues tokens scoped to another tenant. Optional only so providers written
|
|
69
|
+
* against the old name keep working: one of `switchTenant` or the deprecated
|
|
70
|
+
* `switchOrganization` must exist, or switching answers 501.
|
|
71
|
+
*/
|
|
72
|
+
switchTenant?(accessToken: string, slug: string): Promise<BffTokens>;
|
|
73
|
+
/** @deprecated Implement `switchTenant`. */
|
|
74
|
+
switchOrganization?(accessToken: string, slug: string): Promise<BffTokens>;
|
|
56
75
|
validate(accessToken: string): Promise<boolean>;
|
|
57
76
|
profile(accessToken: string): Promise<BffUser>;
|
|
58
77
|
}
|
|
@@ -98,12 +117,26 @@ declare function createBffSession(options: BffSessionOptions): {
|
|
|
98
117
|
/** Same guards as `verifyTwoFactor`; never creates a session or sets a cookie. */
|
|
99
118
|
resendTwoFactorEmail: (request: Request) => Promise<Response>;
|
|
100
119
|
session: (request: Request) => Promise<Response>;
|
|
120
|
+
/** Body `{ tenantSlug }` (the deprecated `{ organizationSlug }` is still read). */
|
|
121
|
+
switchTenant: (request: Request) => Promise<Response>;
|
|
122
|
+
/** @deprecated Mount `switchTenant`; this is the same handler. */
|
|
101
123
|
switchOrganization: (request: Request) => Promise<Response>;
|
|
102
124
|
logout: (request: Request) => Promise<Response>;
|
|
103
125
|
/** Server-only credential for downstream calls. Never serialize this result to the browser. */
|
|
104
126
|
requireSession(request: Request): Promise<{
|
|
105
127
|
accessToken: string;
|
|
106
|
-
user:
|
|
128
|
+
user: {
|
|
129
|
+
id: string;
|
|
130
|
+
email: string;
|
|
131
|
+
tenant: {
|
|
132
|
+
id: string;
|
|
133
|
+
slug: string;
|
|
134
|
+
} | null;
|
|
135
|
+
organization: {
|
|
136
|
+
id: string;
|
|
137
|
+
slug: string;
|
|
138
|
+
} | null;
|
|
139
|
+
};
|
|
107
140
|
expiresAt: number;
|
|
108
141
|
}>;
|
|
109
142
|
errorResponse: (error: unknown) => Response;
|
package/dist/bff.js
CHANGED
|
@@ -147,7 +147,7 @@ function loginInput(body) {
|
|
|
147
147
|
return {
|
|
148
148
|
password: inputString(body, "password"),
|
|
149
149
|
...body.email !== void 0 ? { email: inputString(body, "email") } : { username: inputString(body, "username") },
|
|
150
|
-
...body.organizationSlug !== void 0 ? {
|
|
150
|
+
...body.tenantSlug !== void 0 ? { tenantSlug: inputString(body, "tenantSlug") } : body.organizationSlug !== void 0 ? { tenantSlug: inputString(body, "organizationSlug") } : {},
|
|
151
151
|
sessionPersistence: sessionPersistence(body)
|
|
152
152
|
};
|
|
153
153
|
}
|
|
@@ -295,11 +295,11 @@ var BffSessionManager = class {
|
|
|
295
295
|
});
|
|
296
296
|
this.refreshAhead = positiveDuration(options.refreshAheadMs ?? DEFAULT_REFRESH_AHEAD_MS);
|
|
297
297
|
}
|
|
298
|
-
async create(tokens,
|
|
298
|
+
async create(tokens, tenantSlug, sessionPersistence2 = "standard") {
|
|
299
299
|
try {
|
|
300
300
|
const user = await this.verifiedProfile(tokens);
|
|
301
|
-
if (
|
|
302
|
-
throw new BffSessionError("session.
|
|
301
|
+
if (tenantSlug !== void 0 && user.tenant?.slug !== tenantSlug) {
|
|
302
|
+
throw new BffSessionError("session.tenant_mismatch", 502);
|
|
303
303
|
}
|
|
304
304
|
const lifetime = this.sessionLifetime(sessionPersistence2);
|
|
305
305
|
const record = {
|
|
@@ -320,15 +320,19 @@ var BffSessionManager = class {
|
|
|
320
320
|
async read(id) {
|
|
321
321
|
return this.readCurrent(id, 0);
|
|
322
322
|
}
|
|
323
|
+
/** @deprecated Use `switchTenant`. */
|
|
323
324
|
async switchOrganization(id, slug) {
|
|
325
|
+
return this.switchTenant(id, slug);
|
|
326
|
+
}
|
|
327
|
+
async switchTenant(id, slug) {
|
|
324
328
|
return this.update(id, async (lease) => {
|
|
325
329
|
const refreshed = await this.refreshIfNeeded(lease);
|
|
326
330
|
if (!refreshed && !await this.options.provider.validate(lease.record.tokens.accessToken)) {
|
|
327
331
|
throw new BffSessionError("session.revoked", 401, true);
|
|
328
332
|
}
|
|
329
333
|
await this.rotate(lease, {
|
|
330
|
-
issue: () => this.
|
|
331
|
-
accepts: (user) => user.id === lease.record.user.id && user.
|
|
334
|
+
issue: () => this.issueTenantTokens(lease.record.tokens.accessToken, slug),
|
|
335
|
+
accepts: (user) => user.id === lease.record.user.id && user.tenant?.slug === slug
|
|
332
336
|
});
|
|
333
337
|
});
|
|
334
338
|
}
|
|
@@ -411,7 +415,7 @@ var BffSessionManager = class {
|
|
|
411
415
|
if (!this.needsRefresh(lease.record)) return false;
|
|
412
416
|
await this.rotate(lease, {
|
|
413
417
|
issue: () => this.options.provider.refresh(lease.record.tokens.refreshToken),
|
|
414
|
-
accepts: (user) => user.id === lease.record.user.id && user.
|
|
418
|
+
accepts: (user) => user.id === lease.record.user.id && user.tenant?.id === lease.record.user.tenant?.id
|
|
415
419
|
});
|
|
416
420
|
return true;
|
|
417
421
|
}
|
|
@@ -421,7 +425,7 @@ var BffSessionManager = class {
|
|
|
421
425
|
tokens = await operation.issue();
|
|
422
426
|
} catch (error) {
|
|
423
427
|
if (error instanceof AuthyonError && error.status === 429) throw error;
|
|
424
|
-
if (error instanceof BffSessionError && error.code === "
|
|
428
|
+
if (error instanceof BffSessionError && error.code === "tenant.forbidden") throw error;
|
|
425
429
|
if (rejectedCredential(error)) throw error;
|
|
426
430
|
if (error instanceof BffSessionError && error.clearCookie) throw error;
|
|
427
431
|
throw new BffSessionError("session.rotation_interrupted", 503, true);
|
|
@@ -437,12 +441,15 @@ var BffSessionManager = class {
|
|
|
437
441
|
throw new BffSessionError("session.rotation_interrupted", 503, true);
|
|
438
442
|
}
|
|
439
443
|
}
|
|
440
|
-
async
|
|
444
|
+
async issueTenantTokens(accessToken, slug) {
|
|
445
|
+
const provider = this.options.provider;
|
|
446
|
+
const issue = provider.switchTenant ?? provider.switchOrganization;
|
|
447
|
+
if (!issue) throw new BffSessionError("provider.unsupported_operation", 501);
|
|
441
448
|
try {
|
|
442
|
-
return await
|
|
449
|
+
return await issue.call(provider, accessToken, slug);
|
|
443
450
|
} catch (error) {
|
|
444
451
|
if (error instanceof AuthyonError && error.status === 403)
|
|
445
|
-
throw new BffSessionError("
|
|
452
|
+
throw new BffSessionError("tenant.forbidden", 403);
|
|
446
453
|
throw error;
|
|
447
454
|
}
|
|
448
455
|
}
|
|
@@ -453,10 +460,11 @@ var BffSessionManager = class {
|
|
|
453
460
|
if (!await this.options.provider.validate(tokens.accessToken))
|
|
454
461
|
throw new BffSessionError("session.revoked", 401, true);
|
|
455
462
|
const user = await this.options.provider.profile(tokens.accessToken);
|
|
463
|
+
const tenant = user.tenant ?? user.organization ?? null;
|
|
456
464
|
return {
|
|
457
465
|
id: user.id,
|
|
458
466
|
email: user.email,
|
|
459
|
-
|
|
467
|
+
tenant: tenant ? { id: tenant.id, slug: tenant.slug } : null
|
|
460
468
|
};
|
|
461
469
|
}
|
|
462
470
|
async revokeUnstoredTokens(tokens) {
|
|
@@ -469,8 +477,12 @@ var BffSessionManager = class {
|
|
|
469
477
|
};
|
|
470
478
|
|
|
471
479
|
// src/bff/handlers.ts
|
|
480
|
+
function publicUser(user) {
|
|
481
|
+
const { id, email, tenant } = user;
|
|
482
|
+
return { id, email, tenant, organization: tenant };
|
|
483
|
+
}
|
|
472
484
|
function publicSession(record) {
|
|
473
|
-
return { authenticated: true, user: record.user, expiresAt: record.expiresAt };
|
|
485
|
+
return { authenticated: true, user: publicUser(record.user), expiresAt: record.expiresAt };
|
|
474
486
|
}
|
|
475
487
|
function createBffSession(options) {
|
|
476
488
|
const http = createBffHttp(options);
|
|
@@ -498,8 +510,8 @@ function createBffSession(options) {
|
|
|
498
510
|
}
|
|
499
511
|
};
|
|
500
512
|
}
|
|
501
|
-
async function finishLogin(tokens,
|
|
502
|
-
const { id, record } = await manager.create(tokens,
|
|
513
|
+
async function finishLogin(tokens, tenantSlug, sessionPersistence2) {
|
|
514
|
+
const { id, record } = await manager.create(tokens, tenantSlug, sessionPersistence2);
|
|
503
515
|
return http.response(publicSession(record), { cookie: http.cookie(id, record.expiresAt) });
|
|
504
516
|
}
|
|
505
517
|
async function assertSignedOut(request) {
|
|
@@ -513,6 +525,16 @@ function createBffSession(options) {
|
|
|
513
525
|
}
|
|
514
526
|
throw new BffSessionError("session.already_authenticated", 409);
|
|
515
527
|
}
|
|
528
|
+
const switchTenant = handler("POST", async (request) => {
|
|
529
|
+
const body = await readBffBody(request);
|
|
530
|
+
const slug = inputString(
|
|
531
|
+
body,
|
|
532
|
+
body.tenantSlug === void 0 && body.organizationSlug !== void 0 ? "organizationSlug" : "tenantSlug"
|
|
533
|
+
);
|
|
534
|
+
return http.response(
|
|
535
|
+
publicSession(await manager.switchTenant(requiredSessionId(request), slug))
|
|
536
|
+
);
|
|
537
|
+
});
|
|
516
538
|
return {
|
|
517
539
|
login: handler("POST", async (request) => {
|
|
518
540
|
await assertSignedOut(request);
|
|
@@ -525,7 +547,7 @@ function createBffSession(options) {
|
|
|
525
547
|
methods: result.methods
|
|
526
548
|
});
|
|
527
549
|
}
|
|
528
|
-
return finishLogin(result, input.
|
|
550
|
+
return finishLogin(result, input.tenantSlug, input.sessionPersistence);
|
|
529
551
|
}),
|
|
530
552
|
verifyTwoFactor: handler("POST", async (request) => {
|
|
531
553
|
await assertSignedOut(request);
|
|
@@ -547,12 +569,10 @@ function createBffSession(options) {
|
|
|
547
569
|
"GET",
|
|
548
570
|
async (request) => http.response(publicSession(await manager.read(requiredSessionId(request))))
|
|
549
571
|
),
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
);
|
|
555
|
-
}),
|
|
572
|
+
/** Body `{ tenantSlug }` (the deprecated `{ organizationSlug }` is still read). */
|
|
573
|
+
switchTenant,
|
|
574
|
+
/** @deprecated Mount `switchTenant`; this is the same handler. */
|
|
575
|
+
switchOrganization: switchTenant,
|
|
556
576
|
logout: handler("POST", async (request) => {
|
|
557
577
|
const id = http.sessionId(request);
|
|
558
578
|
if (id) {
|
|
@@ -570,7 +590,7 @@ function createBffSession(options) {
|
|
|
570
590
|
const record = await manager.read(requiredSessionId(request));
|
|
571
591
|
return {
|
|
572
592
|
accessToken: record.tokens.accessToken,
|
|
573
|
-
user: record.user,
|
|
593
|
+
user: publicUser(record.user),
|
|
574
594
|
expiresAt: record.expiresAt
|
|
575
595
|
};
|
|
576
596
|
},
|
|
@@ -616,12 +636,12 @@ function readChallenge(value) {
|
|
|
616
636
|
}
|
|
617
637
|
function readProfile(value) {
|
|
618
638
|
const user = object(value);
|
|
619
|
-
const
|
|
620
|
-
const
|
|
639
|
+
const active = user.tenant ?? user.activeTenant ?? user.activeOrganization;
|
|
640
|
+
const tenant = active == null ? null : object(active);
|
|
621
641
|
return {
|
|
622
642
|
id: requiredString(user.id),
|
|
623
643
|
email: requiredString(user.email),
|
|
624
|
-
|
|
644
|
+
tenant: tenant ? { id: requiredString(tenant.id), slug: requiredString(tenant.slug) } : null
|
|
625
645
|
};
|
|
626
646
|
}
|
|
627
647
|
function createAuthyonBffProvider(options) {
|
|
@@ -637,6 +657,8 @@ function createAuthyonBffProvider(options) {
|
|
|
637
657
|
return {
|
|
638
658
|
async login(input) {
|
|
639
659
|
const credentials = { ...input };
|
|
660
|
+
const tenantSlug = input.tenantSlug ?? input.organizationSlug;
|
|
661
|
+
delete credentials.tenantSlug;
|
|
640
662
|
delete credentials.organizationSlug;
|
|
641
663
|
delete credentials.sessionPersistence;
|
|
642
664
|
const response = object(
|
|
@@ -645,7 +667,7 @@ function createAuthyonBffProvider(options) {
|
|
|
645
667
|
headers,
|
|
646
668
|
body: {
|
|
647
669
|
...credentials,
|
|
648
|
-
...
|
|
670
|
+
...tenantSlug ? { tenantSlug } : {}
|
|
649
671
|
}
|
|
650
672
|
})
|
|
651
673
|
);
|
|
@@ -673,7 +695,7 @@ function createAuthyonBffProvider(options) {
|
|
|
673
695
|
async logout(refreshToken) {
|
|
674
696
|
await http.request("/auth/logout", { method: "POST", headers, body: { refreshToken } });
|
|
675
697
|
},
|
|
676
|
-
async
|
|
698
|
+
async switchTenant(accessToken, slug) {
|
|
677
699
|
return readTokens(
|
|
678
700
|
await http.request("/auth/switch-tenant", {
|
|
679
701
|
method: "POST",
|
|
@@ -749,12 +771,18 @@ function isObject(value) {
|
|
|
749
771
|
function isFiniteNumber(value) {
|
|
750
772
|
return typeof value === "number" && Number.isFinite(value);
|
|
751
773
|
}
|
|
752
|
-
function
|
|
774
|
+
function isTenant(value) {
|
|
753
775
|
return value === null || isObject(value) && typeof value.id === "string" && typeof value.slug === "string";
|
|
754
776
|
}
|
|
777
|
+
function upgradeLegacyRecord(value) {
|
|
778
|
+
if (!isObject(value) || !isObject(value.user)) return value;
|
|
779
|
+
if (value.user.tenant !== void 0 || value.user.organization === void 0) return value;
|
|
780
|
+
const { organization, ...user } = value.user;
|
|
781
|
+
return { ...value, user: { ...user, tenant: organization } };
|
|
782
|
+
}
|
|
755
783
|
function isSessionRecord(value) {
|
|
756
784
|
if (!isObject(value) || !isObject(value.tokens) || !isObject(value.user)) return false;
|
|
757
|
-
return typeof value.revision === "string" && typeof value.tokens.accessToken === "string" && typeof value.tokens.refreshToken === "string" && isFiniteNumber(value.tokens.expiresAt) && typeof value.user.id === "string" && typeof value.user.email === "string" &&
|
|
785
|
+
return typeof value.revision === "string" && typeof value.tokens.accessToken === "string" && typeof value.tokens.refreshToken === "string" && isFiniteNumber(value.tokens.expiresAt) && typeof value.user.id === "string" && typeof value.user.email === "string" && isTenant(value.user.tenant) && (value.sessionPersistence === void 0 || value.sessionPersistence === "standard" || value.sessionPersistence === "remembered") && isFiniteNumber(value.expiresAt) && isFiniteNumber(value.idleExpiresAt) && (value.busyUntil === null || isFiniteNumber(value.busyUntil));
|
|
758
786
|
}
|
|
759
787
|
function createRedisBffSessionStore(options) {
|
|
760
788
|
if (options.encryptionKey.byteLength !== 32) {
|
|
@@ -773,7 +801,7 @@ function createRedisBffSessionStore(options) {
|
|
|
773
801
|
contentEncryptionAlgorithms: ["A256GCM"],
|
|
774
802
|
audience: prefix + key
|
|
775
803
|
});
|
|
776
|
-
const record = payload.session;
|
|
804
|
+
const record = upgradeLegacyRecord(payload.session);
|
|
777
805
|
if (!isSessionRecord(record) || record.revision !== envelope.revision) {
|
|
778
806
|
throw new Error("invalid session record");
|
|
779
807
|
}
|
package/dist/index.cjs
CHANGED
|
@@ -246,6 +246,15 @@ function subTenantQuery(options = {}) {
|
|
|
246
246
|
return query;
|
|
247
247
|
}
|
|
248
248
|
|
|
249
|
+
// ../../internal/core/http/tenantLookup.ts
|
|
250
|
+
var UUID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/iu;
|
|
251
|
+
function tenantLookupPath(idOrSlug) {
|
|
252
|
+
const value = typeof idOrSlug === "string" ? idOrSlug.trim() : "";
|
|
253
|
+
if (!value) throw new RangeError("Authyon: a tenant id or slug is required.");
|
|
254
|
+
if (value.length > 64) throw new RangeError("Authyon: a tenant slug has at most 64 characters.");
|
|
255
|
+
return UUID.test(value) ? `/auth/tenants/${encodeURIComponent(value)}` : `/auth/tenants/by-slug/${encodeURIComponent(value.toLowerCase())}`;
|
|
256
|
+
}
|
|
257
|
+
|
|
249
258
|
// ../../internal/core/security/approvals.ts
|
|
250
259
|
function path(id, suffix = "") {
|
|
251
260
|
if (typeof id !== "string" || !id.trim())
|
|
@@ -295,6 +304,19 @@ var UserScopedClient = class {
|
|
|
295
304
|
constructor(request, token) {
|
|
296
305
|
__privateAdd(this, _request);
|
|
297
306
|
this.tenants = {
|
|
307
|
+
/**
|
|
308
|
+
* GET /auth/tenants/{tenantId} — one tenant, acting as the user: their own,
|
|
309
|
+
* or one below it with `subtenants:tree:read` on an ancestor.
|
|
310
|
+
*/
|
|
311
|
+
get: (tenantId) => __privateGet(this, _request).call(this, `/auth/tenants/${segment(tenantId)}`),
|
|
312
|
+
/**
|
|
313
|
+
* One tenant by id **or** slug: a UUID goes to `GET /auth/tenants/{id}`,
|
|
314
|
+
* anything else to `GET /auth/tenants/by-slug/{slug}`. Same rule and answer
|
|
315
|
+
* as `get`; by slug every refusal is `tenant.not_found`. An empty value
|
|
316
|
+
* raises `RangeError` before any request. The slug route needs the Authyon
|
|
317
|
+
* API of 2026-11-26 or newer.
|
|
318
|
+
*/
|
|
319
|
+
find: (idOrSlug) => __privateGet(this, _request).call(this, tenantLookupPath(idOrSlug)),
|
|
298
320
|
/**
|
|
299
321
|
* The direct, active sub-tenants of a tenant, acting as the user. One level
|
|
300
322
|
* per call: each row's `childCount` says where the next call is worth
|
package/dist/index.d.cts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { H as HttpAdapter, a as HttpLoggerOptions, A as AuthyonServerClient } from './authyonServerClient-
|
|
2
|
-
export { b as AcceptTenantInviteInput, c as AccessTokenSource, d as Approval, e as ApprovalAssurance, f as ApprovalPayload, g as ApprovalStatus, h as ApprovalWebAuthnOptions, i as AuditEvent, j as AuthyonJwksDiscoveryOptions, k as AuthyonJwtClaims, l as AuthyonServerClientOptions, m as AuthyonTenantClaim, B as BuiltInPermission, C as CLIENT_IP_HEADER, n as ClientCredentials, o as ClientRequestContext, p as ConfirmApprovalInput, q as ConsumedApproval, r as CreateApprovalInput, s as CreateCredentialInput, t as CreateOrganizationInput, u as CreatePermissionInput, v as CreateTenantCredentialInput, w as
|
|
3
|
-
export { b as AbilityConditions, c as AbilityEvent, d as AbilityListener, e as AbilityRequirement, f as AbilityRule, A as AbilitySubject, g as AuthorizationContext, a as AuthorizationError, h as AuthorizationOptions, i as AuthyonAbility, j as AuthyonAbilityBuilder, k as AuthyonAbilityOptions, l as AuthyonPermissionSource, E as ExpressAuthorizationMiddlewareOptions, m as ExpressNext, n as ExpressRequestLike, o as ExpressResponseLike, P as PermissionGroup, R as RequestAuthorizationOptions, p as authorizeRequest, q as authorizeToken, r as createAuthorizationErrorResponse, s as createAuthyonAbility, t as createAuthyonRules, u as createExpressAuthorizationMiddleware, v as hasPermission, w as hasPermissionGroup } from './authorization-
|
|
1
|
+
import { H as HttpAdapter, a as HttpLoggerOptions, A as AuthyonServerClient } from './authyonServerClient-mwY55kc9.cjs';
|
|
2
|
+
export { b as AcceptTenantInviteInput, c as AccessTokenSource, d as Approval, e as ApprovalAssurance, f as ApprovalPayload, g as ApprovalStatus, h as ApprovalWebAuthnOptions, i as AuditEvent, j as AuthyonJwksDiscoveryOptions, k as AuthyonJwtClaims, l as AuthyonServerClientOptions, m as AuthyonTenantClaim, B as BuiltInPermission, C as CLIENT_IP_HEADER, n as ClientCredentials, o as ClientRequestContext, p as ConfirmApprovalInput, q as ConsumedApproval, r as CreateApprovalInput, s as CreateCredentialInput, t as CreateOrganizationInput, u as CreatePermissionInput, v as CreateTenantCredentialInput, w as CreateTenantInput, x as CreateUserInput, y as CredentialCreator, z as CredentialDetail, D as CredentialListOptions, E as CredentialPermissionsInput, F as EnvironmentUser, G as FetchHttpAdapter, I as HttpAdapterRequest, K as HttpLogEvent, L as HttpLogger, M as IntrospectResult, N as InviteTenantMemberInput, O as IssuePasswordResetInput, P as JsonWebKeySet, J as JwksTokenVerifier, Q as JwksTokenVerifierOptions, R as LoggingHttpAdapter, S as LoginActivity, T as MemberListOptions, U as MyTenant, V as OpenIdConfiguration, W as Organization, X as OtpCheckResult, Y as Paged, Z as PaginationOptions, _ as PasswordResetCompleted, $ as PasswordResetIssued, a0 as PasswordResetPreview, a1 as Permission, a2 as PermissionsByRole, a3 as ReservedPermissions, a4 as Role, a5 as RoleGrant, a6 as RoleInput, a7 as RoleList, a8 as RolePermissions, a9 as SafeJwtAlgorithm, aa as SecurityMethods, ab as SubTenant, ac as SubTenantListOptions, ad as SubjectApprovals, ae as SubjectSecurity, af as TENANT_FILTER_MAX_DEPTH, ag as TENANT_FILTER_MAX_VALUES, ah as TENANT_FILTER_MAX_VALUE_LENGTH, ai as Tenant, aj as TenantAncestor, ak as TenantClientValidationResult, al as TenantCredentialIssued, am as TenantCredentialSummary, an as TenantFilterExpression, ao as TenantFilterValue, ap as TenantInvite, aq as TenantInviteAccepted, ar as TenantInviteInput, as as TenantInviteIssued, at as TenantInviteListOptions, au as TenantInvitePreview, av as TenantInviteStatus, aw as TenantListOptions, ax as TenantMember, ay as TenantMemberPage, az as TenantMembership, aA as TenantOrder, aB as TenantOrderField, aC as TenantParent, aD as TenantScopedClient, aE as TokenResult, aF as TokenVerificationError, aG as TokenVerificationErrorCode, aH as UpdateOrganizationInput, aI as UpdateTenantInput, aJ as User, aK as UserScopedClient, aL as ValidateResult, aM as VerifiedAccessToken, aN as createClient, aO as normalizeClientIp, aP as tenantFilter } from './authyonServerClient-mwY55kc9.cjs';
|
|
3
|
+
export { b as AbilityConditions, c as AbilityEvent, d as AbilityListener, e as AbilityRequirement, f as AbilityRule, A as AbilitySubject, g as AuthorizationContext, a as AuthorizationError, h as AuthorizationOptions, i as AuthyonAbility, j as AuthyonAbilityBuilder, k as AuthyonAbilityOptions, l as AuthyonPermissionSource, E as ExpressAuthorizationMiddlewareOptions, m as ExpressNext, n as ExpressRequestLike, o as ExpressResponseLike, P as PermissionGroup, R as RequestAuthorizationOptions, p as authorizeRequest, q as authorizeToken, r as createAuthorizationErrorResponse, s as createAuthyonAbility, t as createAuthyonRules, u as createExpressAuthorizationMiddleware, v as hasPermission, w as hasPermissionGroup } from './authorization-CALNd7HI.cjs';
|
|
4
4
|
import 'jose';
|
|
5
5
|
|
|
6
6
|
declare const ErrorCodes: {
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { H as HttpAdapter, a as HttpLoggerOptions, A as AuthyonServerClient } from './authyonServerClient-
|
|
2
|
-
export { b as AcceptTenantInviteInput, c as AccessTokenSource, d as Approval, e as ApprovalAssurance, f as ApprovalPayload, g as ApprovalStatus, h as ApprovalWebAuthnOptions, i as AuditEvent, j as AuthyonJwksDiscoveryOptions, k as AuthyonJwtClaims, l as AuthyonServerClientOptions, m as AuthyonTenantClaim, B as BuiltInPermission, C as CLIENT_IP_HEADER, n as ClientCredentials, o as ClientRequestContext, p as ConfirmApprovalInput, q as ConsumedApproval, r as CreateApprovalInput, s as CreateCredentialInput, t as CreateOrganizationInput, u as CreatePermissionInput, v as CreateTenantCredentialInput, w as
|
|
3
|
-
export { b as AbilityConditions, c as AbilityEvent, d as AbilityListener, e as AbilityRequirement, f as AbilityRule, A as AbilitySubject, g as AuthorizationContext, a as AuthorizationError, h as AuthorizationOptions, i as AuthyonAbility, j as AuthyonAbilityBuilder, k as AuthyonAbilityOptions, l as AuthyonPermissionSource, E as ExpressAuthorizationMiddlewareOptions, m as ExpressNext, n as ExpressRequestLike, o as ExpressResponseLike, P as PermissionGroup, R as RequestAuthorizationOptions, p as authorizeRequest, q as authorizeToken, r as createAuthorizationErrorResponse, s as createAuthyonAbility, t as createAuthyonRules, u as createExpressAuthorizationMiddleware, v as hasPermission, w as hasPermissionGroup } from './authorization-
|
|
1
|
+
import { H as HttpAdapter, a as HttpLoggerOptions, A as AuthyonServerClient } from './authyonServerClient-mwY55kc9.js';
|
|
2
|
+
export { b as AcceptTenantInviteInput, c as AccessTokenSource, d as Approval, e as ApprovalAssurance, f as ApprovalPayload, g as ApprovalStatus, h as ApprovalWebAuthnOptions, i as AuditEvent, j as AuthyonJwksDiscoveryOptions, k as AuthyonJwtClaims, l as AuthyonServerClientOptions, m as AuthyonTenantClaim, B as BuiltInPermission, C as CLIENT_IP_HEADER, n as ClientCredentials, o as ClientRequestContext, p as ConfirmApprovalInput, q as ConsumedApproval, r as CreateApprovalInput, s as CreateCredentialInput, t as CreateOrganizationInput, u as CreatePermissionInput, v as CreateTenantCredentialInput, w as CreateTenantInput, x as CreateUserInput, y as CredentialCreator, z as CredentialDetail, D as CredentialListOptions, E as CredentialPermissionsInput, F as EnvironmentUser, G as FetchHttpAdapter, I as HttpAdapterRequest, K as HttpLogEvent, L as HttpLogger, M as IntrospectResult, N as InviteTenantMemberInput, O as IssuePasswordResetInput, P as JsonWebKeySet, J as JwksTokenVerifier, Q as JwksTokenVerifierOptions, R as LoggingHttpAdapter, S as LoginActivity, T as MemberListOptions, U as MyTenant, V as OpenIdConfiguration, W as Organization, X as OtpCheckResult, Y as Paged, Z as PaginationOptions, _ as PasswordResetCompleted, $ as PasswordResetIssued, a0 as PasswordResetPreview, a1 as Permission, a2 as PermissionsByRole, a3 as ReservedPermissions, a4 as Role, a5 as RoleGrant, a6 as RoleInput, a7 as RoleList, a8 as RolePermissions, a9 as SafeJwtAlgorithm, aa as SecurityMethods, ab as SubTenant, ac as SubTenantListOptions, ad as SubjectApprovals, ae as SubjectSecurity, af as TENANT_FILTER_MAX_DEPTH, ag as TENANT_FILTER_MAX_VALUES, ah as TENANT_FILTER_MAX_VALUE_LENGTH, ai as Tenant, aj as TenantAncestor, ak as TenantClientValidationResult, al as TenantCredentialIssued, am as TenantCredentialSummary, an as TenantFilterExpression, ao as TenantFilterValue, ap as TenantInvite, aq as TenantInviteAccepted, ar as TenantInviteInput, as as TenantInviteIssued, at as TenantInviteListOptions, au as TenantInvitePreview, av as TenantInviteStatus, aw as TenantListOptions, ax as TenantMember, ay as TenantMemberPage, az as TenantMembership, aA as TenantOrder, aB as TenantOrderField, aC as TenantParent, aD as TenantScopedClient, aE as TokenResult, aF as TokenVerificationError, aG as TokenVerificationErrorCode, aH as UpdateOrganizationInput, aI as UpdateTenantInput, aJ as User, aK as UserScopedClient, aL as ValidateResult, aM as VerifiedAccessToken, aN as createClient, aO as normalizeClientIp, aP as tenantFilter } from './authyonServerClient-mwY55kc9.js';
|
|
3
|
+
export { b as AbilityConditions, c as AbilityEvent, d as AbilityListener, e as AbilityRequirement, f as AbilityRule, A as AbilitySubject, g as AuthorizationContext, a as AuthorizationError, h as AuthorizationOptions, i as AuthyonAbility, j as AuthyonAbilityBuilder, k as AuthyonAbilityOptions, l as AuthyonPermissionSource, E as ExpressAuthorizationMiddlewareOptions, m as ExpressNext, n as ExpressRequestLike, o as ExpressResponseLike, P as PermissionGroup, R as RequestAuthorizationOptions, p as authorizeRequest, q as authorizeToken, r as createAuthorizationErrorResponse, s as createAuthyonAbility, t as createAuthyonRules, u as createExpressAuthorizationMiddleware, v as hasPermission, w as hasPermissionGroup } from './authorization-Cc-xr0ay.js';
|
|
4
4
|
import 'jose';
|
|
5
5
|
|
|
6
6
|
declare const ErrorCodes: {
|
package/dist/index.js
CHANGED
|
@@ -218,6 +218,15 @@ function subTenantQuery(options = {}) {
|
|
|
218
218
|
return query;
|
|
219
219
|
}
|
|
220
220
|
|
|
221
|
+
// ../../internal/core/http/tenantLookup.ts
|
|
222
|
+
var UUID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/iu;
|
|
223
|
+
function tenantLookupPath(idOrSlug) {
|
|
224
|
+
const value = typeof idOrSlug === "string" ? idOrSlug.trim() : "";
|
|
225
|
+
if (!value) throw new RangeError("Authyon: a tenant id or slug is required.");
|
|
226
|
+
if (value.length > 64) throw new RangeError("Authyon: a tenant slug has at most 64 characters.");
|
|
227
|
+
return UUID.test(value) ? `/auth/tenants/${encodeURIComponent(value)}` : `/auth/tenants/by-slug/${encodeURIComponent(value.toLowerCase())}`;
|
|
228
|
+
}
|
|
229
|
+
|
|
221
230
|
// ../../internal/core/security/approvals.ts
|
|
222
231
|
function path(id, suffix = "") {
|
|
223
232
|
if (typeof id !== "string" || !id.trim())
|
|
@@ -267,6 +276,19 @@ var UserScopedClient = class {
|
|
|
267
276
|
constructor(request, token) {
|
|
268
277
|
__privateAdd(this, _request);
|
|
269
278
|
this.tenants = {
|
|
279
|
+
/**
|
|
280
|
+
* GET /auth/tenants/{tenantId} — one tenant, acting as the user: their own,
|
|
281
|
+
* or one below it with `subtenants:tree:read` on an ancestor.
|
|
282
|
+
*/
|
|
283
|
+
get: (tenantId) => __privateGet(this, _request).call(this, `/auth/tenants/${segment(tenantId)}`),
|
|
284
|
+
/**
|
|
285
|
+
* One tenant by id **or** slug: a UUID goes to `GET /auth/tenants/{id}`,
|
|
286
|
+
* anything else to `GET /auth/tenants/by-slug/{slug}`. Same rule and answer
|
|
287
|
+
* as `get`; by slug every refusal is `tenant.not_found`. An empty value
|
|
288
|
+
* raises `RangeError` before any request. The slug route needs the Authyon
|
|
289
|
+
* API of 2026-11-26 or newer.
|
|
290
|
+
*/
|
|
291
|
+
find: (idOrSlug) => __privateGet(this, _request).call(this, tenantLookupPath(idOrSlug)),
|
|
270
292
|
/**
|
|
271
293
|
* The direct, active sub-tenants of a tenant, acting as the user. One level
|
|
272
294
|
* per call: each row's `childCount` says where the next call is worth
|
package/dist/next.d.cts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ReactNode } from 'react';
|
|
2
|
-
import { R as RequestAuthorizationOptions, A as AbilitySubject, a as AuthorizationError } from './authorization-
|
|
3
|
-
import { A as AuthyonServerClient } from './authyonServerClient-
|
|
2
|
+
import { R as RequestAuthorizationOptions, A as AbilitySubject, a as AuthorizationError } from './authorization-CALNd7HI.cjs';
|
|
3
|
+
import { A as AuthyonServerClient } from './authyonServerClient-mwY55kc9.cjs';
|
|
4
4
|
import 'jose';
|
|
5
5
|
|
|
6
6
|
interface ServerPermissionGuardFallbackContext {
|
package/dist/next.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ReactNode } from 'react';
|
|
2
|
-
import { R as RequestAuthorizationOptions, A as AbilitySubject, a as AuthorizationError } from './authorization-
|
|
3
|
-
import { A as AuthyonServerClient } from './authyonServerClient-
|
|
2
|
+
import { R as RequestAuthorizationOptions, A as AbilitySubject, a as AuthorizationError } from './authorization-Cc-xr0ay.js';
|
|
3
|
+
import { A as AuthyonServerClient } from './authyonServerClient-mwY55kc9.js';
|
|
4
4
|
import 'jose';
|
|
5
5
|
|
|
6
6
|
interface ServerPermissionGuardFallbackContext {
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@authyon/server",
|
|
3
|
-
"version": "0.2.0-beta.
|
|
4
|
-
"description": "Authyon SDK for backends — server-to-server
|
|
3
|
+
"version": "0.2.0-beta.31",
|
|
4
|
+
"description": "Authyon SDK for backends — server-to-server tenant/member management and access-token verification.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"engines": {
|