@authyon/auth 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/dist/index.js CHANGED
@@ -516,6 +516,15 @@ function subTenantQuery(options = {}) {
516
516
  return query;
517
517
  }
518
518
 
519
+ // ../../internal/core/http/tenantLookup.ts
520
+ var UUID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/iu;
521
+ function tenantLookupPath(idOrSlug) {
522
+ const value = typeof idOrSlug === "string" ? idOrSlug.trim() : "";
523
+ if (!value) throw new RangeError("Authyon: a tenant id or slug is required.");
524
+ if (value.length > 64) throw new RangeError("Authyon: a tenant slug has at most 64 characters.");
525
+ return UUID.test(value) ? `/auth/tenants/${encodeURIComponent(value)}` : `/auth/tenants/by-slug/${encodeURIComponent(value.toLowerCase())}`;
526
+ }
527
+
519
528
  // src/client/authyonClient.ts
520
529
  var FALLBACK_EXPIRES_IN = 1800;
521
530
  function readTokens(raw) {
@@ -624,54 +633,69 @@ var AuthyonClient = class {
624
633
  return { redirectUri: done?.redirectUri ?? null };
625
634
  }
626
635
  };
627
- // ── Organization ─────────────────────────────────────────────────────────
628
- this.organization = {
636
+ // ── Tenant ─────────────────────────────────────────────────────────
637
+ this.tenants = {
629
638
  /**
630
- * GET /auth/tenants — filterable list of organization memberships.
639
+ * GET /auth/tenants — filterable list of tenant memberships.
631
640
  *
632
- * Also lists the organizations below them that the user may switch into
641
+ * Also lists the tenants below them that the user may switch into
633
642
  * without being a member, marked `inherited` — only the ones that actually
634
643
  * carry `subtenants:tree:switch`, so the switcher never offers an
635
- * organization the switch would then refuse. `depth` indents the list into
644
+ * tenant the switch would then refuse. `depth` indents the list into
636
645
  * the tree it describes.
637
646
  */
638
647
  list: (params = {}) => this.request(appendQuery("/auth/tenants", params), { bearer: true }),
639
648
  /**
640
- * POST /auth/tenants — creates an organization owned by the signed-in
641
- * user (only available when self-service organization creation is
649
+ * POST /auth/tenants — creates a tenant owned by the signed-in
650
+ * user (only available when self-service tenant creation is
642
651
  * enabled for the environment).
643
652
  *
644
653
  * `parentTenantId` nests it under one the user already belongs to, which
645
654
  * needs `subtenants:tree:create` there. The creator lands as the effective
646
655
  * owner either way, with `tenants:settings:manage`,
647
656
  * `tenants:members:invite` and `tenants:members:remove` granted directly
648
- * inside the new organization.
657
+ * inside the new tenant.
649
658
  */
650
659
  create: (params = {}) => this.request("/auth/tenants", { method: "POST", bearer: true, body: params }),
651
- /** GET /auth/tenants/{organizationId} — fetch one of the user's organizations by id. */
652
- get: (organizationId) => this.request(`/auth/tenants/${encodeURIComponent(organizationId)}`, { bearer: true }),
653
660
  /**
654
- * PATCH /auth/tenants/{organizationId} — renames the organization.
661
+ * GET /auth/tenants/{tenantId} — one tenant by id: the user's own,
662
+ * or one below it with `subtenants:tree:read` on an ancestor.
663
+ */
664
+ get: (tenantId) => this.request(`/auth/tenants/${encodeURIComponent(tenantId)}`, { bearer: true }),
665
+ /**
666
+ * One tenant by id **or** slug — a UUID goes to `GET /auth/tenants/{id}`,
667
+ * anything else to `GET /auth/tenants/by-slug/{slug}`. Same access rule and
668
+ * same answer as `get`, so a page that only has the slug from its URL
669
+ * doesn't have to page `subTenants.list` to find it.
670
+ *
671
+ * By slug, every refusal answers `tenant.not_found` (a slug is guessable,
672
+ * so "exists, not yours" is never told apart from "doesn't exist"). An
673
+ * empty value raises `RangeError` before any request. The slug route needs
674
+ * the Authyon API of 2026-11-26 or newer.
675
+ */
676
+ find: (idOrSlug) => this.request(tenantLookupPath(idOrSlug), { bearer: true }),
677
+ /**
678
+ * PATCH /auth/tenants/{tenantId} — renames the tenant.
655
679
  *
656
680
  * Requires the `tenants:settings:manage` custom permission on it, or
657
- * `subtenants:tree:manage` on an organization above it. The value was
681
+ * `subtenants:tree:manage` on a tenant above it. The value was
658
682
  * spelled `tenants:manage` before 2026-10-31 — two segments, which the API
659
683
  * could not store, so the endpoint refused everyone who had been granted
660
684
  * it.
661
685
  */
662
- rename: (organizationId, name) => this.request(`/auth/tenants/${encodeURIComponent(organizationId)}`, {
686
+ rename: (tenantId, name) => this.request(`/auth/tenants/${encodeURIComponent(tenantId)}`, {
663
687
  method: "PATCH",
664
688
  bearer: true,
665
689
  body: { name }
666
690
  }),
667
691
  /**
668
692
  * POST /auth/switch-tenant — issues a fresh token scoped to the new
669
- * organization.
693
+ * tenant.
670
694
  *
671
- * Membership is enough for one of the user's own organizations. Descending
672
- * into one below it takes `subtenants:tree:switch` at the organization they
695
+ * Membership is enough for one of the user's own tenants. Descending
696
+ * into one below it takes `subtenants:tree:switch` at the tenant they
673
697
  * belong to — deliberately not the same permission as administering a
674
- * sub-organization from the outside, since operating AS it is the larger of
698
+ * sub-tenant from the outside, since operating AS it is the larger of
675
699
  * the two powers. The grants then travel from the node the user belongs to,
676
700
  * and the token says so in its `tenant.via`.
677
701
  *
@@ -679,61 +703,58 @@ var AuthyonClient = class {
679
703
  * `tenant.ancestor_disabled`, and `tenant.path_stale` when the tree moved
680
704
  * under a session — sign-in again rather than retrying.
681
705
  */
682
- switch: (organizationSlug) => this.request("/auth/switch-tenant", {
706
+ switch: (tenantSlug) => this.request("/auth/switch-tenant", {
683
707
  method: "POST",
684
708
  bearer: true,
685
- body: { tenantSlug: organizationSlug }
709
+ body: { tenantSlug }
686
710
  }).then((data) => this.setSession({ tokens: readTokens(data) }, "refreshed")).then((session) => this.hydrateUser(session)),
687
- /** The organization the current session is scoped to, from the cached session — no network call. */
688
- current: () => this.getSession()?.user?.activeOrganization ?? null,
711
+ /** The tenant the current session is scoped to, from the cached session — no network call. */
712
+ current: () => this.getSession()?.user?.activeTenant ?? null,
689
713
  members: {
690
714
  /**
691
- * GET /auth/tenants/{organizationId}/members — paginated list of an
692
- * organization's members, newest first, in the `Paged<T>` envelope every
715
+ * GET /auth/tenants/{tenantId}/members — paginated list of an
716
+ * tenant's members, newest first, in the `Paged<T>` envelope every
693
717
  * other `skip`/`take` endpoint returns. `search` matches email, username
694
718
  * or name; at most 100 characters, and `take` 1-100, checked before any
695
719
  * request.
696
720
  */
697
- list: (organizationId, params = {}) => this.request(
698
- appendQuery(
699
- `/auth/tenants/${encodeURIComponent(organizationId)}/members`,
700
- memberQuery(params)
701
- ),
721
+ list: (tenantId, params = {}) => this.request(
722
+ appendQuery(`/auth/tenants/${encodeURIComponent(tenantId)}/members`, memberQuery(params)),
702
723
  { bearer: true }
703
724
  ),
704
725
  /**
705
- * POST /auth/tenants/{organizationId}/members — add an existing
726
+ * POST /auth/tenants/{tenantId}/members — add an existing
706
727
  * environment user by e-mail (no e-mail is sent). To invite an address
707
- * that may not have an account yet, use `organization.invites.create`.
728
+ * that may not have an account yet, use `tenants.invites.create`.
708
729
  */
709
- invite: (organizationId, params) => this.request(`/auth/tenants/${encodeURIComponent(organizationId)}/members`, {
730
+ invite: (tenantId, params) => this.request(`/auth/tenants/${encodeURIComponent(tenantId)}/members`, {
710
731
  method: "POST",
711
732
  bearer: true,
712
733
  body: params
713
734
  }),
714
- /** DELETE /auth/tenants/{organizationId}/members/{userId} — remove a member. */
715
- remove: (organizationId, userId) => this.request(
716
- `/auth/tenants/${encodeURIComponent(organizationId)}/members/${encodeURIComponent(userId)}`,
735
+ /** DELETE /auth/tenants/{tenantId}/members/{userId} — remove a member. */
736
+ remove: (tenantId, userId) => this.request(
737
+ `/auth/tenants/${encodeURIComponent(tenantId)}/members/${encodeURIComponent(userId)}`,
717
738
  { method: "DELETE", bearer: true }
718
739
  )
719
740
  },
720
741
  /**
721
742
  * Invites by e-mail or by link. Managing them requires the
722
- * `tenants:members:invite` permission on the organization; `preview` and
743
+ * `tenants:members:invite` permission on the tenant; `preview` and
723
744
  * `accept` are public — the token in the link is the credential.
724
745
  */
725
746
  invites: {
726
- /** GET /auth/tenants/{organizationId}/invites — every invite with its status, newest first. */
727
- list: (organizationId) => this.request(`/auth/tenants/${encodeURIComponent(organizationId)}/invites`, {
747
+ /** GET /auth/tenants/{tenantId}/invites — every invite with its status, newest first. */
748
+ list: (tenantId) => this.request(`/auth/tenants/${encodeURIComponent(tenantId)}/invites`, {
728
749
  bearer: true
729
750
  }),
730
751
  /**
731
- * POST /auth/tenants/{organizationId}/invites — invite an address.
752
+ * POST /auth/tenants/{tenantId}/invites — invite an address.
732
753
  * Always returns `acceptUrl`; with `sendEmail: false` Authyon does not
733
754
  * mail it and you deliver the link yourself. The link is valid for 7
734
755
  * days, once, and can't be read again later.
735
756
  */
736
- create: (organizationId, params) => this.request(`/auth/tenants/${encodeURIComponent(organizationId)}/invites`, {
757
+ create: (tenantId, params) => this.request(`/auth/tenants/${encodeURIComponent(tenantId)}/invites`, {
737
758
  method: "POST",
738
759
  bearer: true,
739
760
  body: {
@@ -744,17 +765,17 @@ var AuthyonClient = class {
744
765
  }
745
766
  }),
746
767
  /**
747
- * POST /auth/tenants/{organizationId}/invites/{inviteId}/resend — issue
768
+ * POST /auth/tenants/{tenantId}/invites/{inviteId}/resend — issue
748
769
  * a new link (the previous one stops working), mailing it unless
749
770
  * `sendEmail` is `false`.
750
771
  */
751
- resend: (organizationId, inviteId, params = {}) => this.request(
752
- `/auth/tenants/${encodeURIComponent(organizationId)}/invites/${encodeURIComponent(inviteId)}/resend`,
772
+ resend: (tenantId, inviteId, params = {}) => this.request(
773
+ `/auth/tenants/${encodeURIComponent(tenantId)}/invites/${encodeURIComponent(inviteId)}/resend`,
753
774
  { method: "POST", bearer: true, body: { sendEmail: params.sendEmail ?? true } }
754
775
  ),
755
- /** DELETE /auth/tenants/{organizationId}/invites/{inviteId} — revoke a pending invite. */
756
- revoke: (organizationId, inviteId) => this.request(
757
- `/auth/tenants/${encodeURIComponent(organizationId)}/invites/${encodeURIComponent(inviteId)}`,
776
+ /** DELETE /auth/tenants/{tenantId}/invites/{inviteId} — revoke a pending invite. */
777
+ revoke: (tenantId, inviteId) => this.request(
778
+ `/auth/tenants/${encodeURIComponent(tenantId)}/invites/${encodeURIComponent(inviteId)}`,
758
779
  { method: "DELETE", bearer: true }
759
780
  ),
760
781
  /**
@@ -764,41 +785,41 @@ var AuthyonClient = class {
764
785
  */
765
786
  preview: (token) => this.request("/auth/tenant-invites/preview", { method: "POST", body: { token } }),
766
787
  /**
767
- * POST /auth/tenant-invites/accept — public. Joins the organization; for
788
+ * POST /auth/tenant-invites/accept — public. Joins the tenant; for
768
789
  * an address with no account, also creates it (password required) with
769
790
  * the e-mail already confirmed. Does not sign the user in.
770
791
  */
771
792
  accept: (params) => this.request("/auth/tenant-invites/accept", { method: "POST", body: params })
772
793
  },
773
794
  /**
774
- * The direct, active sub-organizations of an organization. One level per
795
+ * The direct, active sub-tenants of a tenant. One level per
775
796
  * call: each row's `childCount` says where the next call is worth making,
776
797
  * which is what a lazily expanded tree asks for.
777
798
  *
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
799
+ * Needs `subtenants:tree:read` on the tenant or on one above it —
800
+ * even on the user's own tenant, since listing the children is
780
801
  * reading below it. Paged like every other `skip`/`take` listing, with
781
802
  * `search` (name, slug, description and public metadata), `filter` (public
782
803
  * scope only — build them with `tenantFilter`) and `orderBy`
783
804
  * (`name` | `createdAt` | `updatedAt`, ascending or descending). A bad
784
805
  * option raises `RangeError` before any request.
785
806
  *
786
- * Not the same list as `organization.list()`, which is the switcher's and
807
+ * Not the same list as `tenants.list()`, which is the switcher's and
787
808
  * only brings what `subtenants:tree:switch` lets the user enter. Requires
788
809
  * the Authyon API of 2026-11-26 or newer.
789
810
  */
790
- subOrganizations: {
791
- /** GET /auth/tenants/{organizationId}/subtenants. */
792
- list: (organizationId, params = {}) => this.request(
811
+ subTenants: {
812
+ /** GET /auth/tenants/{tenantId}/subtenants. */
813
+ list: (tenantId, params = {}) => this.request(
793
814
  appendQuery(
794
- `/auth/tenants/${encodeURIComponent(organizationId)}/subtenants`,
815
+ `/auth/tenants/${encodeURIComponent(tenantId)}/subtenants`,
795
816
  subTenantQuery(params)
796
817
  ),
797
818
  { bearer: true }
798
819
  ),
799
820
  /**
800
- * GET /auth/tenants/subtenants — the same, for the organization the
801
- * session is scoped to (`organization.current()`, the token's
821
+ * GET /auth/tenants/subtenants — the same, for the tenant the
822
+ * session is scoped to (`tenants.current()`, the token's
802
823
  * `tenant_id`). Same permission rule; answers `tenant.no_active_tenant`
803
824
  * when the session never switched into one.
804
825
  */
@@ -807,12 +828,19 @@ var AuthyonClient = class {
807
828
  })
808
829
  },
809
830
  roles: {
810
- /** GET /auth/tenants/{organizationId}/roles — roles available in the organization. */
811
- list: (organizationId) => this.request(`/auth/tenants/${encodeURIComponent(organizationId)}/roles`, {
831
+ /** GET /auth/tenants/{tenantId}/roles — roles available in the tenant. */
832
+ list: (tenantId) => this.request(`/auth/tenants/${encodeURIComponent(tenantId)}/roles`, {
812
833
  bearer: true
813
834
  })
814
835
  }
815
836
  };
837
+ /**
838
+ * @deprecated Use `tenants` — the same methods, named after the API's own
839
+ * vocabulary (`tenants.subTenants` instead of `subOrganizations`). Kept so
840
+ * code written against 0.2.0-beta.30 and earlier keeps working; removed in a
841
+ * later release.
842
+ */
843
+ this.organization = { ...this.tenants, subOrganizations: this.tenants.subTenants };
816
844
  // ── Two-factor management (authenticated) ────────────────────────────────
817
845
  this.twoFactor = {
818
846
  /** GET /auth/2fa/status — enrolled methods and recovery code count. */
@@ -1055,8 +1083,9 @@ var AuthyonClient = class {
1055
1083
  * 2FA challenge to complete via `verifyTwoFactor()`.
1056
1084
  */
1057
1085
  async login(params) {
1058
- const { organizationSlug, ...rest } = params;
1059
- const body = organizationSlug ? { ...rest, tenantSlug: organizationSlug } : rest;
1086
+ const { organizationSlug, tenantSlug, ...rest } = params;
1087
+ const slug = tenantSlug ?? organizationSlug;
1088
+ const body = slug ? { ...rest, tenantSlug: slug } : rest;
1060
1089
  const data = await this.request("/auth/login", { method: "POST", body });
1061
1090
  if (data.twoFactor) {
1062
1091
  return { twoFactorRequired: true, ...data.twoFactor };
@@ -1157,11 +1186,15 @@ var AuthyonClient = class {
1157
1186
  }
1158
1187
  };
1159
1188
  function normalizeUser(raw) {
1160
- const { tenant, tenants, activeTenant, ...rest } = raw;
1189
+ const { tenant, tenants, activeTenant, organizations, activeOrganization, ...rest } = raw;
1190
+ const list = tenants ?? organizations;
1191
+ const active = tenant ?? activeTenant ?? activeOrganization ?? null;
1161
1192
  return {
1162
1193
  ...rest,
1163
- organizations: raw.organizations ?? tenants,
1164
- activeOrganization: tenant ?? raw.activeOrganization ?? activeTenant ?? null
1194
+ tenants: list,
1195
+ activeTenant: active,
1196
+ organizations: list,
1197
+ activeOrganization: active
1165
1198
  };
1166
1199
  }
1167
1200
  function createClient(options) {
@@ -1,7 +1,7 @@
1
1
  import * as react from 'react';
2
2
  import { ReactNode } from 'react';
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';
3
+ import { au as User, a4 as SessionControllerOptions, A as AuthyonClient, a6 as SessionSnapshot, a3 as Session, f as AbilitySubject, u as AuthyonAbilityOptions, s as AuthyonAbility } from '../ability-BPJ5VdSC.cjs';
4
+ export { x as AuthyonSessionController, a7 as SessionSnapshotListener, a8 as SessionStatus } from '../ability-BPJ5VdSC.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 { 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';
3
+ import { au as User, a4 as SessionControllerOptions, A as AuthyonClient, a6 as SessionSnapshot, a3 as Session, f as AbilitySubject, u as AuthyonAbilityOptions, s as AuthyonAbility } from '../ability-BPJ5VdSC.js';
4
+ export { x as AuthyonSessionController, a7 as SessionSnapshotListener, a8 as SessionStatus } from '../ability-BPJ5VdSC.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.30",
3
+ "version": "0.2.0-beta.31",
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",