@authyon/auth 0.2.0-beta.29 → 0.2.0-beta.30

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 CHANGED
@@ -240,6 +240,8 @@ Métodos de sessão/auth ficam soltos no client; os que giram em torno de um rec
240
240
  | `organization.members.invite(organizationId, params)` | `POST /auth/tenants/{id}/members` |
241
241
  | `organization.members.remove(organizationId, userId)` | `DELETE /auth/tenants/{id}/members/{userId}` |
242
242
  | `organization.roles.list(organizationId)` | `GET /auth/tenants/{id}/roles` |
243
+ | `organization.subOrganizations.list(organizationId, params?)` | `GET /auth/tenants/{id}/subtenants` |
244
+ | `organization.subOrganizations.listCurrent(params?)` | `GET /auth/tenants/subtenants` (tenant ativo) |
243
245
  | `organization.invites.list(organizationId)` | `GET /auth/tenants/{id}/invites` |
244
246
  | `organization.invites.create(organizationId, params)` | `POST /auth/tenants/{id}/invites` |
245
247
  | `organization.invites.resend(organizationId, inviteId, params?)` | `POST /auth/tenants/{id}/invites/{inviteId}/resend` |
@@ -266,6 +268,31 @@ usuário já pertence (precisa de `subtenants:tree:create` lá). `organization.r
266
268
  `tenants:settings:manage` — o valor antes escrito `tenants:manage`, que a API não
267
269
  armazenava. Ver o [guia de hierarquia](../../docs/tenantHierarchy.md).
268
270
 
271
+ Para navegar pelos sub-tenants (e não só pelos que aceitam troca), use
272
+ `organization.subOrganizations.list(id, params)` ou `.listCurrent(params)`, que usa o
273
+ tenant ativo da sessão. Um nível por chamada, paginado (`skip`, `take` de 1 a 100), com
274
+ `search` (nome, slug, descrição e metadados públicos), `filter` só no escopo `public` —
275
+ monte com `tenantFilter`, exportado também por este pacote — e `orderBy` (`name`,
276
+ `createdAt` ou `updatedAt`, `asc` ou `desc`). Cada linha traz `childCount`, então dá
277
+ para expandir a árvore só onde há filhos. Exige `subtenants:tree:read`, inclusive no
278
+ próprio tenant.
279
+
280
+ ```ts
281
+ import { tenantFilter } from "@authyon/auth";
282
+
283
+ const { data, total, hasNext } = await authyon.organization.subOrganizations.listCurrent({
284
+ filter: [tenantFilter.eq("public.region", "sul")],
285
+ orderBy: { field: "name", direction: "asc" },
286
+ take: 50,
287
+ });
288
+ ```
289
+
290
+ `organization.get()` passa a trazer `myPermissions` — as permissões das rotas de
291
+ organização que o usuário pode usar ali. Use esse campo, e não `myRoles`, para decidir que
292
+ ações mostrar: quem cria o tenant recebe permissões diretas e nenhum papel. Cada membro de
293
+ `organization.members.list()` traz `status` (`active`, `suspended` ou `disabled`) e
294
+ `emailConfirmed`.
295
+
269
296
  ### `authyon.twoFactor`
270
297
 
271
298
  | Método | Endpoint |
@@ -206,6 +206,66 @@ interface IntrospectResult {
206
206
  jti?: string;
207
207
  token_type?: string;
208
208
  }
209
+ /** Fields a tenant listing can order by. */
210
+ type TenantOrderField = "name" | "createdAt" | "updatedAt";
211
+ /**
212
+ * A server-side order: a field as a bare name (ascending) or with a direction.
213
+ * Ties always break on the id, so a row cannot move across a page boundary
214
+ * between two calls.
215
+ */
216
+ type TenantOrder = TenantOrderField | {
217
+ field: TenantOrderField;
218
+ direction?: "asc" | "desc";
219
+ };
220
+ /**
221
+ * Options for a sub-tenant listing on the end-user routes
222
+ * (`/auth/tenants/{id}/subtenants` and `/auth/tenants/subtenants`).
223
+ *
224
+ * The same knobs as the environment's tenant list, cut down to what a member
225
+ * is shown:
226
+ *
227
+ * - `search`: one substring, case-insensitive, over the name, the slug, the
228
+ * description and the public metadata. Never the private metadata. At most
229
+ * 100 characters; blank lists everything.
230
+ * - `filter`: structured conditions, ANDed, at most 10 — build them with
231
+ * `tenantFilter`. Only the `public` scope: a `private.*` or `custom.*`
232
+ * filter would let a member test values they cannot read, so it raises
233
+ * `RangeError` here (and is a 400 `tenant.filter.invalid` on the API).
234
+ * - `orderBy`: `name` (the default, ascending), `createdAt` or `updatedAt`.
235
+ *
236
+ * There is no `status`: only active sub-tenants are listed, since everything
237
+ * below a disabled one is closed to reads from above.
238
+ */
239
+ interface SubTenantListOptions extends PaginationOptions {
240
+ search?: string;
241
+ filter?: string[];
242
+ orderBy?: TenantOrder;
243
+ }
244
+ /** The tenant another one hangs from: enough to name it in a breadcrumb. */
245
+ interface TenantParent {
246
+ id: string;
247
+ slug: string;
248
+ name: string;
249
+ }
250
+ /** One direct sub-tenant, as the end-user sub-tenant listings return it. */
251
+ interface SubTenant {
252
+ id: string;
253
+ slug: string;
254
+ name: string;
255
+ description: string | null;
256
+ /** Distance from the root: `1` for a child of a root. */
257
+ depth: number;
258
+ /** Its own direct sub-tenants. Ask for the next level only where this is above zero. */
259
+ childCount: number;
260
+ /** Whether the user also belongs to it directly. */
261
+ isMember: boolean;
262
+ createdAt: string;
263
+ updatedAt: string;
264
+ /** JSON-encoded metadata visible to members. */
265
+ publicMetadata: string;
266
+ /** The tenant it hangs from — the same on every row of a page, carried so a row stands on its own. */
267
+ parent: TenantParent;
268
+ }
209
269
 
210
270
  /**
211
271
  * Organization membership (the Authyon API calls this a "tenant" on the
@@ -232,7 +292,46 @@ interface Organization {
232
292
  inherited?: boolean;
233
293
  /** Distance from the root: `0` at a root organization. Indent the switcher by it. */
234
294
  depth?: number;
295
+ /**
296
+ * The parent's id, `null` for a root. Only `organization.list()` fills it —
297
+ * with `depth`, it nests the switcher's flat list into a tree. `get`,
298
+ * `create` and `rename` send `parent` instead. Absent from an API older than
299
+ * 2026-11-26.
300
+ */
301
+ parentTenantId?: string | null;
302
+ /**
303
+ * The organization it hangs from, `null` for a root — the same shape the
304
+ * sub-organization listing uses. Filled by `get`, `create` and `rename`;
305
+ * absent from an API older than 2026-11-26.
306
+ */
307
+ parent?: TenantParent | null;
308
+ /**
309
+ * A disabled organization still reads, but every change to it is refused
310
+ * with `tenant.disabled`. Filled by `get`, `create` and `rename`; absent from
311
+ * an API older than 2026-11-26.
312
+ */
313
+ isDisabled?: boolean;
314
+ /** Roles the user holds in it; empty when they reach it from an ancestor. Filled by `get`, `create` and `rename`. */
315
+ myRoles?: string[];
316
+ /**
317
+ * The organization-route permissions the user can use on it, as concrete
318
+ * values: `tenants:*` on their own organization, `subtenants:tree:*` from
319
+ * above. This, not `myRoles`, is what decides which actions to offer — the
320
+ * creator holds direct grants and no role. Filled by `get`, `create` and
321
+ * `rename`; absent from an API older than 2026-11-26.
322
+ */
323
+ myPermissions?: string[];
324
+ /** How many members it has. Filled by `get`, `create` and `rename`. */
325
+ memberCount?: number;
235
326
  }
327
+ /** One direct sub-organization, as `organization.subOrganizations` lists it. */
328
+ type SubOrganization = SubTenant;
329
+ /**
330
+ * What `organization.subOrganizations` accepts — see `SubTenantListOptions`:
331
+ * `skip`/`take`, `search`, `filter` (public scope only, built with
332
+ * `tenantFilter`) and `orderBy`.
333
+ */
334
+ type SubOrganizationListOptions = SubTenantListOptions;
236
335
  /** POST /auth/tenants — creates an organization owned by the signed-in user. */
237
336
  interface CreateOrganizationInput {
238
337
  name?: string;
@@ -261,6 +360,13 @@ interface OrganizationMember {
261
360
  roles?: string[];
262
361
  createdAt?: string;
263
362
  lastLoginAt?: string | null;
363
+ /**
364
+ * Account status: `"active"`, `"suspended"` (a temporary hold is in force) or
365
+ * `"disabled"`. Absent from an API older than 2026-11-26.
366
+ */
367
+ status?: "active" | "suspended" | "disabled";
368
+ /** Whether the member confirmed their e-mail. Absent from an API older than 2026-11-26. */
369
+ emailConfirmed?: boolean;
264
370
  }
265
371
  /** POST /auth/tenants/{tenantId}/members — invites a member by e-mail. */
266
372
  interface InviteMemberInput {
@@ -499,6 +605,8 @@ interface Activity {
499
605
  interface Role {
500
606
  id: string;
501
607
  name: string;
608
+ /** Label to show instead of `name`, when the operator set one. Absent from an API older than 2026-11-26. */
609
+ displayName?: string | null;
502
610
  description?: string;
503
611
  permissions?: string[];
504
612
  }
@@ -835,6 +943,34 @@ declare class AuthyonClient {
835
943
  */
836
944
  accept: (params: AcceptOrganizationInviteInput) => Promise<OrganizationInviteAccepted>;
837
945
  };
946
+ /**
947
+ * The direct, active sub-organizations of an organization. One level per
948
+ * call: each row's `childCount` says where the next call is worth making,
949
+ * which is what a lazily expanded tree asks for.
950
+ *
951
+ * Needs `subtenants:tree:read` on the organization or on one above it —
952
+ * even on the user's own organization, since listing the children is
953
+ * reading below it. Paged like every other `skip`/`take` listing, with
954
+ * `search` (name, slug, description and public metadata), `filter` (public
955
+ * scope only — build them with `tenantFilter`) and `orderBy`
956
+ * (`name` | `createdAt` | `updatedAt`, ascending or descending). A bad
957
+ * option raises `RangeError` before any request.
958
+ *
959
+ * Not the same list as `organization.list()`, which is the switcher's and
960
+ * only brings what `subtenants:tree:switch` lets the user enter. Requires
961
+ * the Authyon API of 2026-11-26 or newer.
962
+ */
963
+ subOrganizations: {
964
+ /** GET /auth/tenants/{organizationId}/subtenants. */
965
+ list: (organizationId: string, params?: SubOrganizationListOptions) => Promise<Paged<SubOrganization>>;
966
+ /**
967
+ * GET /auth/tenants/subtenants — the same, for the organization the
968
+ * session is scoped to (`organization.current()`, the token's
969
+ * `tenant_id`). Same permission rule; answers `tenant.no_active_tenant`
970
+ * when the session never switched into one.
971
+ */
972
+ listCurrent: (params?: SubOrganizationListOptions) => Promise<Paged<SubOrganization>>;
973
+ };
838
974
  roles: {
839
975
  /** GET /auth/tenants/{organizationId}/roles — roles available in the organization. */
840
976
  list: (organizationId: string) => Promise<Role[]>;
@@ -1031,4 +1167,4 @@ declare function hasPermissionGroup(source: AuthyonPermissionSource | readonly s
1031
1167
  /** Converts Authyon's `subject:action` permission strings to authorization rules. */
1032
1168
  declare function createAuthyonRules(source?: AuthyonPermissionSource, options?: AuthyonAbilityOptions): AbilityRule[];
1033
1169
 
1034
- export { type Role as $, AuthyonClient as A, type HttpLogger as B, type ConfirmApprovalInput as C, type InviteMemberInput as D, type LoginInput as E, FetchHttpAdapter as F, type LoginResult as G, type HttpAdapter as H, type IntrospectResult as I, type OrganizationInvite as J, type OrganizationInviteAccepted as K, LoggingHttpAdapter as L, type MemberListOptions as M, type OrganizationInviteInput as N, type Organization as O, type OrganizationInviteIssued as P, type OrganizationInvitePreview as Q, type OrganizationInviteStatus as R, type OrganizationMember as S, type TokenStorage as T, type Paged as U, type PaginationOptions as V, type PasswordResetCompleted as W, type PasswordResetPreview as X, type PasswordResetRequestOptions as Y, type PermissionGroup as Z, type RegisterInput as _, type HttpLoggerOptions as a, type SecurityMethods as a0, type Session as a1, type SessionControllerOptions as a2, type SessionInfo as a3, type SessionSnapshot as a4, type SessionSnapshotListener as a5, type SessionStatus as a6, type SsoProvider as a7, type SubjectApprovals as a8, type SubjectSecurity as a9, type TwoFactorChallenge as aa, type TwoFactorMethod as ab, type TwoFactorStatus as ac, type User as ad, type ValidateResult as ae, type VerifyTwoFactorInput as af, type WebAuthnAssertion as ag, type WebAuthnCeremonyStart as ah, type WebAuthnCredential as ai, createAuthyonAbility as aj, createAuthyonRules as ak, createClient as al, hasPermission as am, hasPermissionGroup as an, type AbilityConditions as b, type AbilityEvent as c, type AbilityListener as d, type AbilityRule as e, type AbilitySubject as f, type AcceptOrganizationInviteInput as g, type Activity as h, type Approval as i, type ApprovalAssurance as j, type ApprovalPayload as k, type ApprovalStatus as l, type ApprovalWebAuthnOptions as m, type AuthEvent as n, type AuthState as o, type AuthStateListener as p, type AuthenticatorSetup as q, AuthyonAbility as r, AuthyonAbilityBuilder as s, type AuthyonAbilityOptions as t, type AuthyonClientOptions as u, type AuthyonPermissionSource as v, AuthyonSessionController as w, type CreateOrganizationInput as x, type HttpAdapterRequest as y, type HttpLogEvent as z };
1170
+ export { type Role as $, AuthyonClient as A, type HttpLogger as B, type ConfirmApprovalInput as C, type InviteMemberInput as D, type LoginInput as E, FetchHttpAdapter as F, type LoginResult as G, type HttpAdapter as H, type IntrospectResult as I, type OrganizationInvite as J, type OrganizationInviteAccepted as K, LoggingHttpAdapter as L, type MemberListOptions as M, type OrganizationInviteInput as N, type Organization as O, type OrganizationInviteIssued as P, type OrganizationInvitePreview as Q, type OrganizationInviteStatus as R, type OrganizationMember as S, type TokenStorage as T, type Paged as U, type PaginationOptions as V, type PasswordResetCompleted as W, type PasswordResetPreview as X, type PasswordResetRequestOptions as Y, type PermissionGroup as Z, type RegisterInput as _, type HttpLoggerOptions as a, type SecurityMethods as a0, type Session as a1, type SessionControllerOptions as a2, type SessionInfo as a3, type SessionSnapshot as a4, type SessionSnapshotListener as a5, type SessionStatus as a6, type SsoProvider as a7, type SubOrganization as a8, type SubOrganizationListOptions as a9, type SubTenant as aa, type SubTenantListOptions as ab, type SubjectApprovals as ac, type SubjectSecurity as ad, type TenantOrder as ae, type TenantOrderField as af, type TenantParent as ag, type TwoFactorChallenge as ah, type TwoFactorMethod as ai, type TwoFactorStatus as aj, type User as ak, type ValidateResult as al, type VerifyTwoFactorInput as am, type WebAuthnAssertion as an, type WebAuthnCeremonyStart as ao, type WebAuthnCredential as ap, createAuthyonAbility as aq, createAuthyonRules as ar, createClient as as, hasPermission as at, hasPermissionGroup as au, type AbilityConditions as b, type AbilityEvent as c, type AbilityListener as d, type AbilityRule as e, type AbilitySubject as f, type AcceptOrganizationInviteInput as g, type Activity as h, type Approval as i, type ApprovalAssurance as j, type ApprovalPayload as k, type ApprovalStatus as l, type ApprovalWebAuthnOptions as m, type AuthEvent as n, type AuthState as o, type AuthStateListener as p, type AuthenticatorSetup as q, AuthyonAbility as r, AuthyonAbilityBuilder as s, type AuthyonAbilityOptions as t, type AuthyonClientOptions as u, type AuthyonPermissionSource as v, AuthyonSessionController as w, type CreateOrganizationInput as x, type HttpAdapterRequest as y, type HttpLogEvent as z };
@@ -206,6 +206,66 @@ interface IntrospectResult {
206
206
  jti?: string;
207
207
  token_type?: string;
208
208
  }
209
+ /** Fields a tenant listing can order by. */
210
+ type TenantOrderField = "name" | "createdAt" | "updatedAt";
211
+ /**
212
+ * A server-side order: a field as a bare name (ascending) or with a direction.
213
+ * Ties always break on the id, so a row cannot move across a page boundary
214
+ * between two calls.
215
+ */
216
+ type TenantOrder = TenantOrderField | {
217
+ field: TenantOrderField;
218
+ direction?: "asc" | "desc";
219
+ };
220
+ /**
221
+ * Options for a sub-tenant listing on the end-user routes
222
+ * (`/auth/tenants/{id}/subtenants` and `/auth/tenants/subtenants`).
223
+ *
224
+ * The same knobs as the environment's tenant list, cut down to what a member
225
+ * is shown:
226
+ *
227
+ * - `search`: one substring, case-insensitive, over the name, the slug, the
228
+ * description and the public metadata. Never the private metadata. At most
229
+ * 100 characters; blank lists everything.
230
+ * - `filter`: structured conditions, ANDed, at most 10 — build them with
231
+ * `tenantFilter`. Only the `public` scope: a `private.*` or `custom.*`
232
+ * filter would let a member test values they cannot read, so it raises
233
+ * `RangeError` here (and is a 400 `tenant.filter.invalid` on the API).
234
+ * - `orderBy`: `name` (the default, ascending), `createdAt` or `updatedAt`.
235
+ *
236
+ * There is no `status`: only active sub-tenants are listed, since everything
237
+ * below a disabled one is closed to reads from above.
238
+ */
239
+ interface SubTenantListOptions extends PaginationOptions {
240
+ search?: string;
241
+ filter?: string[];
242
+ orderBy?: TenantOrder;
243
+ }
244
+ /** The tenant another one hangs from: enough to name it in a breadcrumb. */
245
+ interface TenantParent {
246
+ id: string;
247
+ slug: string;
248
+ name: string;
249
+ }
250
+ /** One direct sub-tenant, as the end-user sub-tenant listings return it. */
251
+ interface SubTenant {
252
+ id: string;
253
+ slug: string;
254
+ name: string;
255
+ description: string | null;
256
+ /** Distance from the root: `1` for a child of a root. */
257
+ depth: number;
258
+ /** Its own direct sub-tenants. Ask for the next level only where this is above zero. */
259
+ childCount: number;
260
+ /** Whether the user also belongs to it directly. */
261
+ isMember: boolean;
262
+ createdAt: string;
263
+ updatedAt: string;
264
+ /** JSON-encoded metadata visible to members. */
265
+ publicMetadata: string;
266
+ /** The tenant it hangs from — the same on every row of a page, carried so a row stands on its own. */
267
+ parent: TenantParent;
268
+ }
209
269
 
210
270
  /**
211
271
  * Organization membership (the Authyon API calls this a "tenant" on the
@@ -232,7 +292,46 @@ interface Organization {
232
292
  inherited?: boolean;
233
293
  /** Distance from the root: `0` at a root organization. Indent the switcher by it. */
234
294
  depth?: number;
295
+ /**
296
+ * The parent's id, `null` for a root. Only `organization.list()` fills it —
297
+ * with `depth`, it nests the switcher's flat list into a tree. `get`,
298
+ * `create` and `rename` send `parent` instead. Absent from an API older than
299
+ * 2026-11-26.
300
+ */
301
+ parentTenantId?: string | null;
302
+ /**
303
+ * The organization it hangs from, `null` for a root — the same shape the
304
+ * sub-organization listing uses. Filled by `get`, `create` and `rename`;
305
+ * absent from an API older than 2026-11-26.
306
+ */
307
+ parent?: TenantParent | null;
308
+ /**
309
+ * A disabled organization still reads, but every change to it is refused
310
+ * with `tenant.disabled`. Filled by `get`, `create` and `rename`; absent from
311
+ * an API older than 2026-11-26.
312
+ */
313
+ isDisabled?: boolean;
314
+ /** Roles the user holds in it; empty when they reach it from an ancestor. Filled by `get`, `create` and `rename`. */
315
+ myRoles?: string[];
316
+ /**
317
+ * The organization-route permissions the user can use on it, as concrete
318
+ * values: `tenants:*` on their own organization, `subtenants:tree:*` from
319
+ * above. This, not `myRoles`, is what decides which actions to offer — the
320
+ * creator holds direct grants and no role. Filled by `get`, `create` and
321
+ * `rename`; absent from an API older than 2026-11-26.
322
+ */
323
+ myPermissions?: string[];
324
+ /** How many members it has. Filled by `get`, `create` and `rename`. */
325
+ memberCount?: number;
235
326
  }
327
+ /** One direct sub-organization, as `organization.subOrganizations` lists it. */
328
+ type SubOrganization = SubTenant;
329
+ /**
330
+ * What `organization.subOrganizations` accepts — see `SubTenantListOptions`:
331
+ * `skip`/`take`, `search`, `filter` (public scope only, built with
332
+ * `tenantFilter`) and `orderBy`.
333
+ */
334
+ type SubOrganizationListOptions = SubTenantListOptions;
236
335
  /** POST /auth/tenants — creates an organization owned by the signed-in user. */
237
336
  interface CreateOrganizationInput {
238
337
  name?: string;
@@ -261,6 +360,13 @@ interface OrganizationMember {
261
360
  roles?: string[];
262
361
  createdAt?: string;
263
362
  lastLoginAt?: string | null;
363
+ /**
364
+ * Account status: `"active"`, `"suspended"` (a temporary hold is in force) or
365
+ * `"disabled"`. Absent from an API older than 2026-11-26.
366
+ */
367
+ status?: "active" | "suspended" | "disabled";
368
+ /** Whether the member confirmed their e-mail. Absent from an API older than 2026-11-26. */
369
+ emailConfirmed?: boolean;
264
370
  }
265
371
  /** POST /auth/tenants/{tenantId}/members — invites a member by e-mail. */
266
372
  interface InviteMemberInput {
@@ -499,6 +605,8 @@ interface Activity {
499
605
  interface Role {
500
606
  id: string;
501
607
  name: string;
608
+ /** Label to show instead of `name`, when the operator set one. Absent from an API older than 2026-11-26. */
609
+ displayName?: string | null;
502
610
  description?: string;
503
611
  permissions?: string[];
504
612
  }
@@ -835,6 +943,34 @@ declare class AuthyonClient {
835
943
  */
836
944
  accept: (params: AcceptOrganizationInviteInput) => Promise<OrganizationInviteAccepted>;
837
945
  };
946
+ /**
947
+ * The direct, active sub-organizations of an organization. One level per
948
+ * call: each row's `childCount` says where the next call is worth making,
949
+ * which is what a lazily expanded tree asks for.
950
+ *
951
+ * Needs `subtenants:tree:read` on the organization or on one above it —
952
+ * even on the user's own organization, since listing the children is
953
+ * reading below it. Paged like every other `skip`/`take` listing, with
954
+ * `search` (name, slug, description and public metadata), `filter` (public
955
+ * scope only — build them with `tenantFilter`) and `orderBy`
956
+ * (`name` | `createdAt` | `updatedAt`, ascending or descending). A bad
957
+ * option raises `RangeError` before any request.
958
+ *
959
+ * Not the same list as `organization.list()`, which is the switcher's and
960
+ * only brings what `subtenants:tree:switch` lets the user enter. Requires
961
+ * the Authyon API of 2026-11-26 or newer.
962
+ */
963
+ subOrganizations: {
964
+ /** GET /auth/tenants/{organizationId}/subtenants. */
965
+ list: (organizationId: string, params?: SubOrganizationListOptions) => Promise<Paged<SubOrganization>>;
966
+ /**
967
+ * GET /auth/tenants/subtenants — the same, for the organization the
968
+ * session is scoped to (`organization.current()`, the token's
969
+ * `tenant_id`). Same permission rule; answers `tenant.no_active_tenant`
970
+ * when the session never switched into one.
971
+ */
972
+ listCurrent: (params?: SubOrganizationListOptions) => Promise<Paged<SubOrganization>>;
973
+ };
838
974
  roles: {
839
975
  /** GET /auth/tenants/{organizationId}/roles — roles available in the organization. */
840
976
  list: (organizationId: string) => Promise<Role[]>;
@@ -1031,4 +1167,4 @@ declare function hasPermissionGroup(source: AuthyonPermissionSource | readonly s
1031
1167
  /** Converts Authyon's `subject:action` permission strings to authorization rules. */
1032
1168
  declare function createAuthyonRules(source?: AuthyonPermissionSource, options?: AuthyonAbilityOptions): AbilityRule[];
1033
1169
 
1034
- export { type Role as $, AuthyonClient as A, type HttpLogger as B, type ConfirmApprovalInput as C, type InviteMemberInput as D, type LoginInput as E, FetchHttpAdapter as F, type LoginResult as G, type HttpAdapter as H, type IntrospectResult as I, type OrganizationInvite as J, type OrganizationInviteAccepted as K, LoggingHttpAdapter as L, type MemberListOptions as M, type OrganizationInviteInput as N, type Organization as O, type OrganizationInviteIssued as P, type OrganizationInvitePreview as Q, type OrganizationInviteStatus as R, type OrganizationMember as S, type TokenStorage as T, type Paged as U, type PaginationOptions as V, type PasswordResetCompleted as W, type PasswordResetPreview as X, type PasswordResetRequestOptions as Y, type PermissionGroup as Z, type RegisterInput as _, type HttpLoggerOptions as a, type SecurityMethods as a0, type Session as a1, type SessionControllerOptions as a2, type SessionInfo as a3, type SessionSnapshot as a4, type SessionSnapshotListener as a5, type SessionStatus as a6, type SsoProvider as a7, type SubjectApprovals as a8, type SubjectSecurity as a9, type TwoFactorChallenge as aa, type TwoFactorMethod as ab, type TwoFactorStatus as ac, type User as ad, type ValidateResult as ae, type VerifyTwoFactorInput as af, type WebAuthnAssertion as ag, type WebAuthnCeremonyStart as ah, type WebAuthnCredential as ai, createAuthyonAbility as aj, createAuthyonRules as ak, createClient as al, hasPermission as am, hasPermissionGroup as an, type AbilityConditions as b, type AbilityEvent as c, type AbilityListener as d, type AbilityRule as e, type AbilitySubject as f, type AcceptOrganizationInviteInput as g, type Activity as h, type Approval as i, type ApprovalAssurance as j, type ApprovalPayload as k, type ApprovalStatus as l, type ApprovalWebAuthnOptions as m, type AuthEvent as n, type AuthState as o, type AuthStateListener as p, type AuthenticatorSetup as q, AuthyonAbility as r, AuthyonAbilityBuilder as s, type AuthyonAbilityOptions as t, type AuthyonClientOptions as u, type AuthyonPermissionSource as v, AuthyonSessionController as w, type CreateOrganizationInput as x, type HttpAdapterRequest as y, type HttpLogEvent as z };
1170
+ export { type Role as $, AuthyonClient as A, type HttpLogger as B, type ConfirmApprovalInput as C, type InviteMemberInput as D, type LoginInput as E, FetchHttpAdapter as F, type LoginResult as G, type HttpAdapter as H, type IntrospectResult as I, type OrganizationInvite as J, type OrganizationInviteAccepted as K, LoggingHttpAdapter as L, type MemberListOptions as M, type OrganizationInviteInput as N, type Organization as O, type OrganizationInviteIssued as P, type OrganizationInvitePreview as Q, type OrganizationInviteStatus as R, type OrganizationMember as S, type TokenStorage as T, type Paged as U, type PaginationOptions as V, type PasswordResetCompleted as W, type PasswordResetPreview as X, type PasswordResetRequestOptions as Y, type PermissionGroup as Z, type RegisterInput as _, type HttpLoggerOptions as a, type SecurityMethods as a0, type Session as a1, type SessionControllerOptions as a2, type SessionInfo as a3, type SessionSnapshot as a4, type SessionSnapshotListener as a5, type SessionStatus as a6, type SsoProvider as a7, type SubOrganization as a8, type SubOrganizationListOptions as a9, type SubTenant as aa, type SubTenantListOptions as ab, type SubjectApprovals as ac, type SubjectSecurity as ad, type TenantOrder as ae, type TenantOrderField as af, type TenantParent as ag, type TwoFactorChallenge as ah, type TwoFactorMethod as ai, type TwoFactorStatus as aj, type User as ak, type ValidateResult as al, type VerifyTwoFactorInput as am, type WebAuthnAssertion as an, type WebAuthnCeremonyStart as ao, type WebAuthnCredential as ap, createAuthyonAbility as aq, createAuthyonRules as ar, createClient as as, hasPermission as at, hasPermissionGroup as au, type AbilityConditions as b, type AbilityEvent as c, type AbilityListener as d, type AbilityRule as e, type AbilitySubject as f, type AcceptOrganizationInviteInput as g, type Activity as h, type Approval as i, type ApprovalAssurance as j, type ApprovalPayload as k, type ApprovalStatus as l, type ApprovalWebAuthnOptions as m, type AuthEvent as n, type AuthState as o, type AuthStateListener as p, type AuthenticatorSetup as q, AuthyonAbility as r, AuthyonAbilityBuilder as s, type AuthyonAbilityOptions as t, type AuthyonClientOptions as u, type AuthyonPermissionSource as v, AuthyonSessionController as w, type CreateOrganizationInput as x, type HttpAdapterRequest as y, type HttpLogEvent as z };
package/dist/index.cjs CHANGED
@@ -30,6 +30,9 @@ __export(index_exports, {
30
30
  FetchHttpAdapter: () => FetchHttpAdapter,
31
31
  LoggingHttpAdapter: () => LoggingHttpAdapter,
32
32
  SubtenantPermissions: () => SubtenantPermissions,
33
+ TENANT_FILTER_MAX_DEPTH: () => TENANT_FILTER_MAX_DEPTH,
34
+ TENANT_FILTER_MAX_VALUES: () => TENANT_FILTER_MAX_VALUES,
35
+ TENANT_FILTER_MAX_VALUE_LENGTH: () => TENANT_FILTER_MAX_VALUE_LENGTH,
33
36
  TenantPermissions: () => TenantPermissions,
34
37
  createAuthyonAbility: () => createAuthyonAbility,
35
38
  createAuthyonRules: () => createAuthyonRules,
@@ -38,7 +41,8 @@ __export(index_exports, {
38
41
  createLocalStorage: () => createLocalStorage,
39
42
  createMemoryStorage: () => createMemoryStorage,
40
43
  hasPermission: () => hasPermission,
41
- hasPermissionGroup: () => hasPermissionGroup
44
+ hasPermissionGroup: () => hasPermissionGroup,
45
+ tenantFilter: () => tenantFilter
42
46
  });
43
47
  module.exports = __toCommonJS(index_exports);
44
48
 
@@ -511,6 +515,45 @@ function memberQuery(options = {}) {
511
515
  return { search: search?.trim() || void 0, skip, take };
512
516
  }
513
517
 
518
+ // ../../internal/core/http/subTenantQuery.ts
519
+ var ORDER_FIELDS = ["name", "createdAt", "updatedAt"];
520
+ var MAX_FILTERS = 10;
521
+ var MAX_FILTER_LENGTH = 512;
522
+ function orderByParam(order) {
523
+ if (order === void 0) return void 0;
524
+ const field = typeof order === "string" ? order : order?.field;
525
+ const direction = typeof order === "string" ? "asc" : order.direction ?? "asc";
526
+ if (!ORDER_FIELDS.includes(field))
527
+ throw new RangeError(`Authyon: orderBy must be one of ${ORDER_FIELDS.join(", ")}.`);
528
+ if (direction !== "asc" && direction !== "desc")
529
+ throw new RangeError('Authyon: orderBy direction must be "asc" or "desc".');
530
+ return `${field}:${direction}`;
531
+ }
532
+ function subTenantQuery(options = {}) {
533
+ const { filter, orderBy, ...page } = options;
534
+ const query = { ...memberQuery(page) };
535
+ if (filter !== void 0) {
536
+ if (!Array.isArray(filter)) throw new RangeError("Authyon: filter must be an array.");
537
+ const present = filter.filter((f) => typeof f === "string" && f.trim().length > 0);
538
+ if (present.length !== filter.length)
539
+ throw new RangeError("Authyon: a filter may not be empty \u2014 build it with tenantFilter.");
540
+ if (present.length > MAX_FILTERS)
541
+ throw new RangeError(`Authyon: at most ${MAX_FILTERS} filters per request.`);
542
+ for (const f of present) {
543
+ if (f.length > MAX_FILTER_LENGTH)
544
+ throw new RangeError(`Authyon: a filter may hold at most ${MAX_FILTER_LENGTH} characters.`);
545
+ if (!f.startsWith("public."))
546
+ throw new RangeError(
547
+ `Authyon: sub-tenant listings only filter on the public scope (got "${f.split(":")[0]}").`
548
+ );
549
+ }
550
+ if (present.length > 0) query.filter = present;
551
+ }
552
+ const order = orderByParam(orderBy);
553
+ if (order !== void 0) query.orderBy = order;
554
+ return query;
555
+ }
556
+
514
557
  // src/client/authyonClient.ts
515
558
  var FALLBACK_EXPIRES_IN = 1800;
516
559
  function readTokens(raw) {
@@ -765,6 +808,42 @@ var AuthyonClient = class {
765
808
  */
766
809
  accept: (params) => this.request("/auth/tenant-invites/accept", { method: "POST", body: params })
767
810
  },
811
+ /**
812
+ * The direct, active sub-organizations of an organization. One level per
813
+ * call: each row's `childCount` says where the next call is worth making,
814
+ * which is what a lazily expanded tree asks for.
815
+ *
816
+ * Needs `subtenants:tree:read` on the organization or on one above it —
817
+ * even on the user's own organization, since listing the children is
818
+ * reading below it. Paged like every other `skip`/`take` listing, with
819
+ * `search` (name, slug, description and public metadata), `filter` (public
820
+ * scope only — build them with `tenantFilter`) and `orderBy`
821
+ * (`name` | `createdAt` | `updatedAt`, ascending or descending). A bad
822
+ * option raises `RangeError` before any request.
823
+ *
824
+ * Not the same list as `organization.list()`, which is the switcher's and
825
+ * only brings what `subtenants:tree:switch` lets the user enter. Requires
826
+ * the Authyon API of 2026-11-26 or newer.
827
+ */
828
+ subOrganizations: {
829
+ /** GET /auth/tenants/{organizationId}/subtenants. */
830
+ list: (organizationId, params = {}) => this.request(
831
+ appendQuery(
832
+ `/auth/tenants/${encodeURIComponent(organizationId)}/subtenants`,
833
+ subTenantQuery(params)
834
+ ),
835
+ { bearer: true }
836
+ ),
837
+ /**
838
+ * GET /auth/tenants/subtenants — the same, for the organization the
839
+ * session is scoped to (`organization.current()`, the token's
840
+ * `tenant_id`). Same permission rule; answers `tenant.no_active_tenant`
841
+ * when the session never switched into one.
842
+ */
843
+ listCurrent: (params = {}) => this.request(appendQuery("/auth/tenants/subtenants", subTenantQuery(params)), {
844
+ bearer: true
845
+ })
846
+ },
768
847
  roles: {
769
848
  /** GET /auth/tenants/{organizationId}/roles — roles available in the organization. */
770
849
  list: (organizationId) => this.request(`/auth/tenants/${encodeURIComponent(organizationId)}/roles`, {
@@ -1166,6 +1245,86 @@ var AuthyonClientBuilder = class {
1166
1245
  }
1167
1246
  };
1168
1247
 
1248
+ // ../../internal/core/http/tenantFilters.ts
1249
+ var TENANT_FILTER_MAX_VALUES = 25;
1250
+ var TENANT_FILTER_MAX_VALUE_LENGTH = 200;
1251
+ var TENANT_FILTER_MAX_DEPTH = 3;
1252
+ var SCOPES = ["public", "private", "custom"];
1253
+ var KEY_SEGMENT = /^[A-Za-z0-9_-]{1,64}$/;
1254
+ function assertPath(path2) {
1255
+ if (typeof path2 !== "string" || path2.length === 0) {
1256
+ throw new RangeError("Authyon: a filter path is required, e.g. public.kind.");
1257
+ }
1258
+ const [scope, ...keys] = path2.split(".");
1259
+ if (!SCOPES.includes(scope)) {
1260
+ throw new RangeError(
1261
+ `Authyon: unknown filter scope "${scope}" \u2014 use ${SCOPES.join(", ")} (e.g. public.kind).`
1262
+ );
1263
+ }
1264
+ if (keys.length === 0) {
1265
+ throw new RangeError(`Authyon: filter path "${path2}" needs a key after the scope.`);
1266
+ }
1267
+ if (keys.length > TENANT_FILTER_MAX_DEPTH) {
1268
+ throw new RangeError(
1269
+ `Authyon: filter path "${path2}" goes deeper than ${TENANT_FILTER_MAX_DEPTH} levels.`
1270
+ );
1271
+ }
1272
+ for (const key of keys) {
1273
+ if (!KEY_SEGMENT.test(key)) {
1274
+ throw new RangeError(
1275
+ `Authyon: invalid filter key "${key}" \u2014 letters, digits, "_" and "-", up to 64 characters.`
1276
+ );
1277
+ }
1278
+ }
1279
+ return path2;
1280
+ }
1281
+ function assertValue(value, forIn) {
1282
+ if (value === void 0 || value === null) {
1283
+ throw new RangeError("Authyon: a filter value is required.");
1284
+ }
1285
+ const text = String(value);
1286
+ if (text.length === 0) {
1287
+ throw new RangeError("Authyon: a filter value may not be empty.");
1288
+ }
1289
+ if (text.length > TENANT_FILTER_MAX_VALUE_LENGTH) {
1290
+ throw new RangeError(
1291
+ `Authyon: a filter value may hold at most ${TENANT_FILTER_MAX_VALUE_LENGTH} characters.`
1292
+ );
1293
+ }
1294
+ if (text.includes(",")) {
1295
+ throw new RangeError(
1296
+ forIn ? "Authyon: an `in` value may not contain a comma \u2014 pass separate values instead." : "Authyon: a filter value may not contain a comma."
1297
+ );
1298
+ }
1299
+ return text;
1300
+ }
1301
+ var tenantFilter = {
1302
+ /** `public.kind:eq:reseller` — the key equals this value. */
1303
+ eq(path2, value) {
1304
+ return `${assertPath(path2)}:eq:${assertValue(value, false)}`;
1305
+ },
1306
+ /** `public.kind:in:reseller,partner` — the key equals any of these (SQL IN). */
1307
+ in(path2, values) {
1308
+ if (!Array.isArray(values) || values.length === 0) {
1309
+ throw new RangeError("Authyon: `in` needs at least one value.");
1310
+ }
1311
+ if (values.length > TENANT_FILTER_MAX_VALUES) {
1312
+ throw new RangeError(`Authyon: \`in\` takes at most ${TENANT_FILTER_MAX_VALUES} values.`);
1313
+ }
1314
+ const unique = [...new Set(values.map((value) => assertValue(value, true)))];
1315
+ return `${assertPath(path2)}:in:${unique.join(",")}`;
1316
+ },
1317
+ /** `public.notes:like:nacional` — the key contains this text, case-insensitive.
1318
+ * The server escapes the LIKE metacharacters, so `100%` means `100%`. */
1319
+ like(path2, text) {
1320
+ return `${assertPath(path2)}:like:${assertValue(text, false)}`;
1321
+ },
1322
+ /** `custom.cnpj:exists` — the key is present, whatever its value. */
1323
+ exists(path2) {
1324
+ return `${assertPath(path2)}:exists`;
1325
+ }
1326
+ };
1327
+
1169
1328
  // src/session/sessionController.ts
1170
1329
  var SERVER_SNAPSHOT = {
1171
1330
  // The server cannot inspect browser storage. Reporting unauthenticated here
@@ -1569,6 +1728,9 @@ var SubtenantPermissions = {
1569
1728
  FetchHttpAdapter,
1570
1729
  LoggingHttpAdapter,
1571
1730
  SubtenantPermissions,
1731
+ TENANT_FILTER_MAX_DEPTH,
1732
+ TENANT_FILTER_MAX_VALUES,
1733
+ TENANT_FILTER_MAX_VALUE_LENGTH,
1572
1734
  TenantPermissions,
1573
1735
  createAuthyonAbility,
1574
1736
  createAuthyonRules,
@@ -1577,5 +1739,6 @@ var SubtenantPermissions = {
1577
1739
  createLocalStorage,
1578
1740
  createMemoryStorage,
1579
1741
  hasPermission,
1580
- hasPermissionGroup
1742
+ hasPermissionGroup,
1743
+ tenantFilter
1581
1744
  });
package/dist/index.d.cts CHANGED
@@ -1,5 +1,5 @@
1
- import { T as TokenStorage, H as HttpAdapter, a as HttpLoggerOptions, A as AuthyonClient } from './ability-D47fzavh.cjs';
2
- export { b as AbilityConditions, c as AbilityEvent, d as AbilityListener, e as AbilityRule, f as AbilitySubject, g as AcceptOrganizationInviteInput, h as Activity, i as Approval, j as ApprovalAssurance, k as ApprovalPayload, l as ApprovalStatus, m as ApprovalWebAuthnOptions, n as AuthEvent, o as AuthState, p as AuthStateListener, q as AuthenticatorSetup, r as AuthyonAbility, s as AuthyonAbilityBuilder, t as AuthyonAbilityOptions, u as AuthyonClientOptions, v as AuthyonPermissionSource, w as AuthyonSessionController, C as ConfirmApprovalInput, x as CreateOrganizationInput, F as FetchHttpAdapter, y as HttpAdapterRequest, z as HttpLogEvent, B as HttpLogger, I as IntrospectResult, D as InviteMemberInput, L as LoggingHttpAdapter, E as LoginInput, G as LoginResult, M as MemberListOptions, O as Organization, J as OrganizationInvite, K as OrganizationInviteAccepted, N as OrganizationInviteInput, P as OrganizationInviteIssued, Q as OrganizationInvitePreview, R as OrganizationInviteStatus, S as OrganizationMember, U as Paged, V as PaginationOptions, W as PasswordResetCompleted, X as PasswordResetPreview, Y as PasswordResetRequestOptions, Z as PermissionGroup, _ as RegisterInput, $ as Role, a0 as SecurityMethods, a1 as Session, a2 as SessionControllerOptions, a3 as SessionInfo, a4 as SessionSnapshot, a5 as SessionSnapshotListener, a6 as SessionStatus, a7 as SsoProvider, a8 as SubjectApprovals, a9 as SubjectSecurity, aa as TwoFactorChallenge, ab as TwoFactorMethod, ac as TwoFactorStatus, ad as User, ae as ValidateResult, af as VerifyTwoFactorInput, ag as WebAuthnAssertion, ah as WebAuthnCeremonyStart, ai as WebAuthnCredential, aj as createAuthyonAbility, ak as createAuthyonRules, al as createClient, am as hasPermission, an as hasPermissionGroup } from './ability-D47fzavh.cjs';
1
+ import { T as TokenStorage, H as HttpAdapter, a as HttpLoggerOptions, A as AuthyonClient } from './ability-CmJEviJj.cjs';
2
+ export { b as AbilityConditions, c as AbilityEvent, d as AbilityListener, e as AbilityRule, f as AbilitySubject, g as AcceptOrganizationInviteInput, h as Activity, i as Approval, j as ApprovalAssurance, k as ApprovalPayload, l as ApprovalStatus, m as ApprovalWebAuthnOptions, n as AuthEvent, o as AuthState, p as AuthStateListener, q as AuthenticatorSetup, r as AuthyonAbility, s as AuthyonAbilityBuilder, t as AuthyonAbilityOptions, u as AuthyonClientOptions, v as AuthyonPermissionSource, w as AuthyonSessionController, C as ConfirmApprovalInput, x as CreateOrganizationInput, F as FetchHttpAdapter, y as HttpAdapterRequest, z as HttpLogEvent, B as HttpLogger, I as IntrospectResult, D as InviteMemberInput, L as LoggingHttpAdapter, E as LoginInput, G as LoginResult, M as MemberListOptions, O as Organization, J as OrganizationInvite, K as OrganizationInviteAccepted, N as OrganizationInviteInput, P as OrganizationInviteIssued, Q as OrganizationInvitePreview, R as OrganizationInviteStatus, S as OrganizationMember, U as Paged, V as PaginationOptions, W as PasswordResetCompleted, X as PasswordResetPreview, Y as PasswordResetRequestOptions, Z as PermissionGroup, _ as RegisterInput, $ as Role, a0 as SecurityMethods, a1 as Session, a2 as SessionControllerOptions, a3 as SessionInfo, a4 as SessionSnapshot, a5 as SessionSnapshotListener, a6 as SessionStatus, a7 as SsoProvider, a8 as SubOrganization, a9 as SubOrganizationListOptions, aa as SubTenant, ab as SubTenantListOptions, ac as SubjectApprovals, ad as SubjectSecurity, ae as TenantOrder, af as TenantOrderField, ag as TenantParent, ah as TwoFactorChallenge, ai as TwoFactorMethod, aj as TwoFactorStatus, ak as User, al as ValidateResult, am as VerifyTwoFactorInput, an as WebAuthnAssertion, ao as WebAuthnCeremonyStart, ap as WebAuthnCredential, aq as createAuthyonAbility, ar as createAuthyonRules, as as createClient, at as hasPermission, au as hasPermissionGroup } from './ability-CmJEviJj.cjs';
3
3
 
4
4
  declare const ErrorCodes: {
5
5
  readonly Unknown: "unknown";
@@ -93,6 +93,43 @@ declare class AuthyonClientBuilder {
93
93
  build(): AuthyonClient;
94
94
  }
95
95
 
96
+ /**
97
+ * Builders for the tenant list's structured filters.
98
+ *
99
+ * The wire form of one filter is `<scope>.<key>:<op>[:<value>]`, repeated once
100
+ * per condition: `?filter=public.kind:in:reseller,partner&filter=custom.cnpj:eq:000`.
101
+ * Repeating the parameter ANDs the conditions and the comma inside `in` is the
102
+ * OR, which is the whole reason to filter server-side — the conditions are part
103
+ * of the SQL statement, so `total`, `pages` and `hasNext` describe the filtered
104
+ * set. A filter applied to a page after it arrives cannot do that.
105
+ *
106
+ * Scopes map to the three JSON documents a tenant carries: `public` →
107
+ * `publicMetadata`, `private` → `privateMetadata`, `custom` → `customFields`
108
+ * (the one the free-text `search` never covered).
109
+ *
110
+ * The rules below mirror the server's parser, so a typo raises `RangeError`
111
+ * here instead of coming back as a 400 `tenant.filter.invalid`.
112
+ */
113
+ /** One `filter` parameter, ready to send. */
114
+ type TenantFilterExpression = string;
115
+ /** Values the filters accept; numbers and booleans are compared as text, the
116
+ * way `jsonb ->> key` returns them. */
117
+ type TenantFilterValue = string | number | boolean;
118
+ declare const TENANT_FILTER_MAX_VALUES = 25;
119
+ declare const TENANT_FILTER_MAX_VALUE_LENGTH = 200;
120
+ declare const TENANT_FILTER_MAX_DEPTH = 3;
121
+ declare const tenantFilter: {
122
+ /** `public.kind:eq:reseller` — the key equals this value. */
123
+ eq(path: string, value: TenantFilterValue): TenantFilterExpression;
124
+ /** `public.kind:in:reseller,partner` — the key equals any of these (SQL IN). */
125
+ in(path: string, values: readonly TenantFilterValue[]): TenantFilterExpression;
126
+ /** `public.notes:like:nacional` — the key contains this text, case-insensitive.
127
+ * The server escapes the LIKE metacharacters, so `100%` means `100%`. */
128
+ like(path: string, text: string): TenantFilterExpression;
129
+ /** `custom.cnpj:exists` — the key is present, whatever its value. */
130
+ exists(path: string): TenantFilterExpression;
131
+ };
132
+
96
133
  /** Keeps the session in memory only (lost on page reload). */
97
134
  declare function createMemoryStorage(): TokenStorage;
98
135
  /** Persists the session in `localStorage` under a namespaced key. */
@@ -149,4 +186,4 @@ declare const SubtenantPermissions: {
149
186
  type TenantPermission = (typeof TenantPermissions)[keyof typeof TenantPermissions];
150
187
  type SubtenantPermission = (typeof SubtenantPermissions)[keyof typeof SubtenantPermissions];
151
188
 
152
- export { AuthyonClient, AuthyonClientBuilder, AuthyonError, type AuthyonErrorAction, type AuthyonErrorBody, type AuthyonErrorCategory, type AuthyonErrorInterpretation, ErrorCodes, HttpAdapter, HttpLoggerOptions, type KnownErrorCode, type SubtenantPermission, SubtenantPermissions, type TenantPermission, TenantPermissions, TokenStorage, createDefaultStorage, createLocalStorage, createMemoryStorage };
189
+ export { AuthyonClient, AuthyonClientBuilder, AuthyonError, type AuthyonErrorAction, type AuthyonErrorBody, type AuthyonErrorCategory, type AuthyonErrorInterpretation, ErrorCodes, HttpAdapter, HttpLoggerOptions, type KnownErrorCode, type SubtenantPermission, SubtenantPermissions, TENANT_FILTER_MAX_DEPTH, TENANT_FILTER_MAX_VALUES, TENANT_FILTER_MAX_VALUE_LENGTH, type TenantFilterExpression, type TenantFilterValue, type TenantPermission, TenantPermissions, TokenStorage, createDefaultStorage, createLocalStorage, createMemoryStorage, tenantFilter };
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { T as TokenStorage, H as HttpAdapter, a as HttpLoggerOptions, A as AuthyonClient } from './ability-D47fzavh.js';
2
- export { b as AbilityConditions, c as AbilityEvent, d as AbilityListener, e as AbilityRule, f as AbilitySubject, g as AcceptOrganizationInviteInput, h as Activity, i as Approval, j as ApprovalAssurance, k as ApprovalPayload, l as ApprovalStatus, m as ApprovalWebAuthnOptions, n as AuthEvent, o as AuthState, p as AuthStateListener, q as AuthenticatorSetup, r as AuthyonAbility, s as AuthyonAbilityBuilder, t as AuthyonAbilityOptions, u as AuthyonClientOptions, v as AuthyonPermissionSource, w as AuthyonSessionController, C as ConfirmApprovalInput, x as CreateOrganizationInput, F as FetchHttpAdapter, y as HttpAdapterRequest, z as HttpLogEvent, B as HttpLogger, I as IntrospectResult, D as InviteMemberInput, L as LoggingHttpAdapter, E as LoginInput, G as LoginResult, M as MemberListOptions, O as Organization, J as OrganizationInvite, K as OrganizationInviteAccepted, N as OrganizationInviteInput, P as OrganizationInviteIssued, Q as OrganizationInvitePreview, R as OrganizationInviteStatus, S as OrganizationMember, U as Paged, V as PaginationOptions, W as PasswordResetCompleted, X as PasswordResetPreview, Y as PasswordResetRequestOptions, Z as PermissionGroup, _ as RegisterInput, $ as Role, a0 as SecurityMethods, a1 as Session, a2 as SessionControllerOptions, a3 as SessionInfo, a4 as SessionSnapshot, a5 as SessionSnapshotListener, a6 as SessionStatus, a7 as SsoProvider, a8 as SubjectApprovals, a9 as SubjectSecurity, aa as TwoFactorChallenge, ab as TwoFactorMethod, ac as TwoFactorStatus, ad as User, ae as ValidateResult, af as VerifyTwoFactorInput, ag as WebAuthnAssertion, ah as WebAuthnCeremonyStart, ai as WebAuthnCredential, aj as createAuthyonAbility, ak as createAuthyonRules, al as createClient, am as hasPermission, an as hasPermissionGroup } from './ability-D47fzavh.js';
1
+ import { T as TokenStorage, H as HttpAdapter, a as HttpLoggerOptions, A as AuthyonClient } from './ability-CmJEviJj.js';
2
+ export { b as AbilityConditions, c as AbilityEvent, d as AbilityListener, e as AbilityRule, f as AbilitySubject, g as AcceptOrganizationInviteInput, h as Activity, i as Approval, j as ApprovalAssurance, k as ApprovalPayload, l as ApprovalStatus, m as ApprovalWebAuthnOptions, n as AuthEvent, o as AuthState, p as AuthStateListener, q as AuthenticatorSetup, r as AuthyonAbility, s as AuthyonAbilityBuilder, t as AuthyonAbilityOptions, u as AuthyonClientOptions, v as AuthyonPermissionSource, w as AuthyonSessionController, C as ConfirmApprovalInput, x as CreateOrganizationInput, F as FetchHttpAdapter, y as HttpAdapterRequest, z as HttpLogEvent, B as HttpLogger, I as IntrospectResult, D as InviteMemberInput, L as LoggingHttpAdapter, E as LoginInput, G as LoginResult, M as MemberListOptions, O as Organization, J as OrganizationInvite, K as OrganizationInviteAccepted, N as OrganizationInviteInput, P as OrganizationInviteIssued, Q as OrganizationInvitePreview, R as OrganizationInviteStatus, S as OrganizationMember, U as Paged, V as PaginationOptions, W as PasswordResetCompleted, X as PasswordResetPreview, Y as PasswordResetRequestOptions, Z as PermissionGroup, _ as RegisterInput, $ as Role, a0 as SecurityMethods, a1 as Session, a2 as SessionControllerOptions, a3 as SessionInfo, a4 as SessionSnapshot, a5 as SessionSnapshotListener, a6 as SessionStatus, a7 as SsoProvider, a8 as SubOrganization, a9 as SubOrganizationListOptions, aa as SubTenant, ab as SubTenantListOptions, ac as SubjectApprovals, ad as SubjectSecurity, ae as TenantOrder, af as TenantOrderField, ag as TenantParent, ah as TwoFactorChallenge, ai as TwoFactorMethod, aj as TwoFactorStatus, ak as User, al as ValidateResult, am as VerifyTwoFactorInput, an as WebAuthnAssertion, ao as WebAuthnCeremonyStart, ap as WebAuthnCredential, aq as createAuthyonAbility, ar as createAuthyonRules, as as createClient, at as hasPermission, au as hasPermissionGroup } from './ability-CmJEviJj.js';
3
3
 
4
4
  declare const ErrorCodes: {
5
5
  readonly Unknown: "unknown";
@@ -93,6 +93,43 @@ declare class AuthyonClientBuilder {
93
93
  build(): AuthyonClient;
94
94
  }
95
95
 
96
+ /**
97
+ * Builders for the tenant list's structured filters.
98
+ *
99
+ * The wire form of one filter is `<scope>.<key>:<op>[:<value>]`, repeated once
100
+ * per condition: `?filter=public.kind:in:reseller,partner&filter=custom.cnpj:eq:000`.
101
+ * Repeating the parameter ANDs the conditions and the comma inside `in` is the
102
+ * OR, which is the whole reason to filter server-side — the conditions are part
103
+ * of the SQL statement, so `total`, `pages` and `hasNext` describe the filtered
104
+ * set. A filter applied to a page after it arrives cannot do that.
105
+ *
106
+ * Scopes map to the three JSON documents a tenant carries: `public` →
107
+ * `publicMetadata`, `private` → `privateMetadata`, `custom` → `customFields`
108
+ * (the one the free-text `search` never covered).
109
+ *
110
+ * The rules below mirror the server's parser, so a typo raises `RangeError`
111
+ * here instead of coming back as a 400 `tenant.filter.invalid`.
112
+ */
113
+ /** One `filter` parameter, ready to send. */
114
+ type TenantFilterExpression = string;
115
+ /** Values the filters accept; numbers and booleans are compared as text, the
116
+ * way `jsonb ->> key` returns them. */
117
+ type TenantFilterValue = string | number | boolean;
118
+ declare const TENANT_FILTER_MAX_VALUES = 25;
119
+ declare const TENANT_FILTER_MAX_VALUE_LENGTH = 200;
120
+ declare const TENANT_FILTER_MAX_DEPTH = 3;
121
+ declare const tenantFilter: {
122
+ /** `public.kind:eq:reseller` — the key equals this value. */
123
+ eq(path: string, value: TenantFilterValue): TenantFilterExpression;
124
+ /** `public.kind:in:reseller,partner` — the key equals any of these (SQL IN). */
125
+ in(path: string, values: readonly TenantFilterValue[]): TenantFilterExpression;
126
+ /** `public.notes:like:nacional` — the key contains this text, case-insensitive.
127
+ * The server escapes the LIKE metacharacters, so `100%` means `100%`. */
128
+ like(path: string, text: string): TenantFilterExpression;
129
+ /** `custom.cnpj:exists` — the key is present, whatever its value. */
130
+ exists(path: string): TenantFilterExpression;
131
+ };
132
+
96
133
  /** Keeps the session in memory only (lost on page reload). */
97
134
  declare function createMemoryStorage(): TokenStorage;
98
135
  /** Persists the session in `localStorage` under a namespaced key. */
@@ -149,4 +186,4 @@ declare const SubtenantPermissions: {
149
186
  type TenantPermission = (typeof TenantPermissions)[keyof typeof TenantPermissions];
150
187
  type SubtenantPermission = (typeof SubtenantPermissions)[keyof typeof SubtenantPermissions];
151
188
 
152
- export { AuthyonClient, AuthyonClientBuilder, AuthyonError, type AuthyonErrorAction, type AuthyonErrorBody, type AuthyonErrorCategory, type AuthyonErrorInterpretation, ErrorCodes, HttpAdapter, HttpLoggerOptions, type KnownErrorCode, type SubtenantPermission, SubtenantPermissions, type TenantPermission, TenantPermissions, TokenStorage, createDefaultStorage, createLocalStorage, createMemoryStorage };
189
+ export { AuthyonClient, AuthyonClientBuilder, AuthyonError, type AuthyonErrorAction, type AuthyonErrorBody, type AuthyonErrorCategory, type AuthyonErrorInterpretation, ErrorCodes, HttpAdapter, HttpLoggerOptions, type KnownErrorCode, type SubtenantPermission, SubtenantPermissions, TENANT_FILTER_MAX_DEPTH, TENANT_FILTER_MAX_VALUES, TENANT_FILTER_MAX_VALUE_LENGTH, type TenantFilterExpression, type TenantFilterValue, type TenantPermission, TenantPermissions, TokenStorage, createDefaultStorage, createLocalStorage, createMemoryStorage, tenantFilter };
package/dist/index.js CHANGED
@@ -477,6 +477,45 @@ function memberQuery(options = {}) {
477
477
  return { search: search?.trim() || void 0, skip, take };
478
478
  }
479
479
 
480
+ // ../../internal/core/http/subTenantQuery.ts
481
+ var ORDER_FIELDS = ["name", "createdAt", "updatedAt"];
482
+ var MAX_FILTERS = 10;
483
+ var MAX_FILTER_LENGTH = 512;
484
+ function orderByParam(order) {
485
+ if (order === void 0) return void 0;
486
+ const field = typeof order === "string" ? order : order?.field;
487
+ const direction = typeof order === "string" ? "asc" : order.direction ?? "asc";
488
+ if (!ORDER_FIELDS.includes(field))
489
+ throw new RangeError(`Authyon: orderBy must be one of ${ORDER_FIELDS.join(", ")}.`);
490
+ if (direction !== "asc" && direction !== "desc")
491
+ throw new RangeError('Authyon: orderBy direction must be "asc" or "desc".');
492
+ return `${field}:${direction}`;
493
+ }
494
+ function subTenantQuery(options = {}) {
495
+ const { filter, orderBy, ...page } = options;
496
+ const query = { ...memberQuery(page) };
497
+ if (filter !== void 0) {
498
+ if (!Array.isArray(filter)) throw new RangeError("Authyon: filter must be an array.");
499
+ const present = filter.filter((f) => typeof f === "string" && f.trim().length > 0);
500
+ if (present.length !== filter.length)
501
+ throw new RangeError("Authyon: a filter may not be empty \u2014 build it with tenantFilter.");
502
+ if (present.length > MAX_FILTERS)
503
+ throw new RangeError(`Authyon: at most ${MAX_FILTERS} filters per request.`);
504
+ for (const f of present) {
505
+ if (f.length > MAX_FILTER_LENGTH)
506
+ throw new RangeError(`Authyon: a filter may hold at most ${MAX_FILTER_LENGTH} characters.`);
507
+ if (!f.startsWith("public."))
508
+ throw new RangeError(
509
+ `Authyon: sub-tenant listings only filter on the public scope (got "${f.split(":")[0]}").`
510
+ );
511
+ }
512
+ if (present.length > 0) query.filter = present;
513
+ }
514
+ const order = orderByParam(orderBy);
515
+ if (order !== void 0) query.orderBy = order;
516
+ return query;
517
+ }
518
+
480
519
  // src/client/authyonClient.ts
481
520
  var FALLBACK_EXPIRES_IN = 1800;
482
521
  function readTokens(raw) {
@@ -731,6 +770,42 @@ var AuthyonClient = class {
731
770
  */
732
771
  accept: (params) => this.request("/auth/tenant-invites/accept", { method: "POST", body: params })
733
772
  },
773
+ /**
774
+ * The direct, active sub-organizations of an organization. One level per
775
+ * call: each row's `childCount` says where the next call is worth making,
776
+ * which is what a lazily expanded tree asks for.
777
+ *
778
+ * Needs `subtenants:tree:read` on the organization or on one above it —
779
+ * even on the user's own organization, since listing the children is
780
+ * reading below it. Paged like every other `skip`/`take` listing, with
781
+ * `search` (name, slug, description and public metadata), `filter` (public
782
+ * scope only — build them with `tenantFilter`) and `orderBy`
783
+ * (`name` | `createdAt` | `updatedAt`, ascending or descending). A bad
784
+ * option raises `RangeError` before any request.
785
+ *
786
+ * Not the same list as `organization.list()`, which is the switcher's and
787
+ * only brings what `subtenants:tree:switch` lets the user enter. Requires
788
+ * the Authyon API of 2026-11-26 or newer.
789
+ */
790
+ subOrganizations: {
791
+ /** GET /auth/tenants/{organizationId}/subtenants. */
792
+ list: (organizationId, params = {}) => this.request(
793
+ appendQuery(
794
+ `/auth/tenants/${encodeURIComponent(organizationId)}/subtenants`,
795
+ subTenantQuery(params)
796
+ ),
797
+ { bearer: true }
798
+ ),
799
+ /**
800
+ * GET /auth/tenants/subtenants — the same, for the organization the
801
+ * session is scoped to (`organization.current()`, the token's
802
+ * `tenant_id`). Same permission rule; answers `tenant.no_active_tenant`
803
+ * when the session never switched into one.
804
+ */
805
+ listCurrent: (params = {}) => this.request(appendQuery("/auth/tenants/subtenants", subTenantQuery(params)), {
806
+ bearer: true
807
+ })
808
+ },
734
809
  roles: {
735
810
  /** GET /auth/tenants/{organizationId}/roles — roles available in the organization. */
736
811
  list: (organizationId) => this.request(`/auth/tenants/${encodeURIComponent(organizationId)}/roles`, {
@@ -1132,6 +1207,86 @@ var AuthyonClientBuilder = class {
1132
1207
  }
1133
1208
  };
1134
1209
 
1210
+ // ../../internal/core/http/tenantFilters.ts
1211
+ var TENANT_FILTER_MAX_VALUES = 25;
1212
+ var TENANT_FILTER_MAX_VALUE_LENGTH = 200;
1213
+ var TENANT_FILTER_MAX_DEPTH = 3;
1214
+ var SCOPES = ["public", "private", "custom"];
1215
+ var KEY_SEGMENT = /^[A-Za-z0-9_-]{1,64}$/;
1216
+ function assertPath(path2) {
1217
+ if (typeof path2 !== "string" || path2.length === 0) {
1218
+ throw new RangeError("Authyon: a filter path is required, e.g. public.kind.");
1219
+ }
1220
+ const [scope, ...keys] = path2.split(".");
1221
+ if (!SCOPES.includes(scope)) {
1222
+ throw new RangeError(
1223
+ `Authyon: unknown filter scope "${scope}" \u2014 use ${SCOPES.join(", ")} (e.g. public.kind).`
1224
+ );
1225
+ }
1226
+ if (keys.length === 0) {
1227
+ throw new RangeError(`Authyon: filter path "${path2}" needs a key after the scope.`);
1228
+ }
1229
+ if (keys.length > TENANT_FILTER_MAX_DEPTH) {
1230
+ throw new RangeError(
1231
+ `Authyon: filter path "${path2}" goes deeper than ${TENANT_FILTER_MAX_DEPTH} levels.`
1232
+ );
1233
+ }
1234
+ for (const key of keys) {
1235
+ if (!KEY_SEGMENT.test(key)) {
1236
+ throw new RangeError(
1237
+ `Authyon: invalid filter key "${key}" \u2014 letters, digits, "_" and "-", up to 64 characters.`
1238
+ );
1239
+ }
1240
+ }
1241
+ return path2;
1242
+ }
1243
+ function assertValue(value, forIn) {
1244
+ if (value === void 0 || value === null) {
1245
+ throw new RangeError("Authyon: a filter value is required.");
1246
+ }
1247
+ const text = String(value);
1248
+ if (text.length === 0) {
1249
+ throw new RangeError("Authyon: a filter value may not be empty.");
1250
+ }
1251
+ if (text.length > TENANT_FILTER_MAX_VALUE_LENGTH) {
1252
+ throw new RangeError(
1253
+ `Authyon: a filter value may hold at most ${TENANT_FILTER_MAX_VALUE_LENGTH} characters.`
1254
+ );
1255
+ }
1256
+ if (text.includes(",")) {
1257
+ throw new RangeError(
1258
+ forIn ? "Authyon: an `in` value may not contain a comma \u2014 pass separate values instead." : "Authyon: a filter value may not contain a comma."
1259
+ );
1260
+ }
1261
+ return text;
1262
+ }
1263
+ var tenantFilter = {
1264
+ /** `public.kind:eq:reseller` — the key equals this value. */
1265
+ eq(path2, value) {
1266
+ return `${assertPath(path2)}:eq:${assertValue(value, false)}`;
1267
+ },
1268
+ /** `public.kind:in:reseller,partner` — the key equals any of these (SQL IN). */
1269
+ in(path2, values) {
1270
+ if (!Array.isArray(values) || values.length === 0) {
1271
+ throw new RangeError("Authyon: `in` needs at least one value.");
1272
+ }
1273
+ if (values.length > TENANT_FILTER_MAX_VALUES) {
1274
+ throw new RangeError(`Authyon: \`in\` takes at most ${TENANT_FILTER_MAX_VALUES} values.`);
1275
+ }
1276
+ const unique = [...new Set(values.map((value) => assertValue(value, true)))];
1277
+ return `${assertPath(path2)}:in:${unique.join(",")}`;
1278
+ },
1279
+ /** `public.notes:like:nacional` — the key contains this text, case-insensitive.
1280
+ * The server escapes the LIKE metacharacters, so `100%` means `100%`. */
1281
+ like(path2, text) {
1282
+ return `${assertPath(path2)}:like:${assertValue(text, false)}`;
1283
+ },
1284
+ /** `custom.cnpj:exists` — the key is present, whatever its value. */
1285
+ exists(path2) {
1286
+ return `${assertPath(path2)}:exists`;
1287
+ }
1288
+ };
1289
+
1135
1290
  // ../../internal/core/authorization/tenantPermissions.ts
1136
1291
  var TenantPermissions = {
1137
1292
  /** Rename the tenant and change its settings. */
@@ -1168,6 +1323,9 @@ export {
1168
1323
  FetchHttpAdapter,
1169
1324
  LoggingHttpAdapter,
1170
1325
  SubtenantPermissions,
1326
+ TENANT_FILTER_MAX_DEPTH,
1327
+ TENANT_FILTER_MAX_VALUES,
1328
+ TENANT_FILTER_MAX_VALUE_LENGTH,
1171
1329
  TenantPermissions,
1172
1330
  createAuthyonAbility,
1173
1331
  createAuthyonRules,
@@ -1176,5 +1334,6 @@ export {
1176
1334
  createLocalStorage,
1177
1335
  createMemoryStorage,
1178
1336
  hasPermission,
1179
- hasPermissionGroup
1337
+ hasPermissionGroup,
1338
+ tenantFilter
1180
1339
  };
@@ -1,7 +1,7 @@
1
1
  import * as react from 'react';
2
2
  import { ReactNode } from 'react';
3
- import { ad as User, a2 as SessionControllerOptions, A as AuthyonClient, a4 as SessionSnapshot, a1 as Session, f as AbilitySubject, t as AuthyonAbilityOptions, r as AuthyonAbility } from '../ability-D47fzavh.cjs';
4
- export { w as AuthyonSessionController, a5 as SessionSnapshotListener, a6 as SessionStatus } from '../ability-D47fzavh.cjs';
3
+ import { ak as User, a2 as SessionControllerOptions, A as AuthyonClient, a4 as SessionSnapshot, a1 as Session, f as AbilitySubject, t as AuthyonAbilityOptions, r as AuthyonAbility } from '../ability-CmJEviJj.cjs';
4
+ export { w as AuthyonSessionController, a5 as SessionSnapshotListener, a6 as SessionStatus } from '../ability-CmJEviJj.cjs';
5
5
 
6
6
  interface AuthyonProviderProps<TUser extends User = User> extends SessionControllerOptions {
7
7
  client: AuthyonClient;
@@ -1,7 +1,7 @@
1
1
  import * as react from 'react';
2
2
  import { ReactNode } from 'react';
3
- import { ad as User, a2 as SessionControllerOptions, A as AuthyonClient, a4 as SessionSnapshot, a1 as Session, f as AbilitySubject, t as AuthyonAbilityOptions, r as AuthyonAbility } from '../ability-D47fzavh.js';
4
- export { w as AuthyonSessionController, a5 as SessionSnapshotListener, a6 as SessionStatus } from '../ability-D47fzavh.js';
3
+ import { ak as User, a2 as SessionControllerOptions, A as AuthyonClient, a4 as SessionSnapshot, a1 as Session, f as AbilitySubject, t as AuthyonAbilityOptions, r as AuthyonAbility } from '../ability-CmJEviJj.js';
4
+ export { w as AuthyonSessionController, a5 as SessionSnapshotListener, a6 as SessionStatus } from '../ability-CmJEviJj.js';
5
5
 
6
6
  interface AuthyonProviderProps<TUser extends User = User> extends SessionControllerOptions {
7
7
  client: AuthyonClient;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@authyon/auth",
3
- "version": "0.2.0-beta.29",
3
+ "version": "0.2.0-beta.30",
4
4
  "description": "Authyon SDK for browsers — auth, sessions, multi-tenant and 2FA for vanilla JS/TS.",
5
5
  "license": "MIT",
6
6
  "type": "module",