@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/README.md +40 -39
- package/dist/{ability-CmJEviJj.d.cts → ability-BPJ5VdSC.d.cts} +314 -98
- package/dist/{ability-CmJEviJj.d.ts → ability-BPJ5VdSC.d.ts} +314 -98
- package/dist/index.cjs +96 -63
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +96 -63
- package/dist/react/index.d.cts +2 -2
- package/dist/react/index.d.ts +2 -2
- package/package.json +1 -1
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
|
-
// ──
|
|
628
|
-
this.
|
|
636
|
+
// ── Tenant ─────────────────────────────────────────────────────────
|
|
637
|
+
this.tenants = {
|
|
629
638
|
/**
|
|
630
|
-
* GET /auth/tenants — filterable list of
|
|
639
|
+
* GET /auth/tenants — filterable list of tenant memberships.
|
|
631
640
|
*
|
|
632
|
-
* Also lists the
|
|
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
|
-
*
|
|
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
|
|
641
|
-
* user (only available when self-service
|
|
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
|
|
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
|
-
*
|
|
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
|
|
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: (
|
|
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
|
-
*
|
|
693
|
+
* tenant.
|
|
670
694
|
*
|
|
671
|
-
* Membership is enough for one of the user's own
|
|
672
|
-
* into one below it takes `subtenants:tree:switch` at the
|
|
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-
|
|
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: (
|
|
706
|
+
switch: (tenantSlug) => this.request("/auth/switch-tenant", {
|
|
683
707
|
method: "POST",
|
|
684
708
|
bearer: true,
|
|
685
|
-
body: { tenantSlug
|
|
709
|
+
body: { tenantSlug }
|
|
686
710
|
}).then((data) => this.setSession({ tokens: readTokens(data) }, "refreshed")).then((session) => this.hydrateUser(session)),
|
|
687
|
-
/** The
|
|
688
|
-
current: () => this.getSession()?.user?.
|
|
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/{
|
|
692
|
-
*
|
|
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: (
|
|
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/{
|
|
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 `
|
|
728
|
+
* that may not have an account yet, use `tenants.invites.create`.
|
|
708
729
|
*/
|
|
709
|
-
invite: (
|
|
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/{
|
|
715
|
-
remove: (
|
|
716
|
-
`/auth/tenants/${encodeURIComponent(
|
|
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
|
|
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/{
|
|
727
|
-
list: (
|
|
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/{
|
|
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: (
|
|
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/{
|
|
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: (
|
|
752
|
-
`/auth/tenants/${encodeURIComponent(
|
|
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/{
|
|
756
|
-
revoke: (
|
|
757
|
-
`/auth/tenants/${encodeURIComponent(
|
|
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
|
|
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-
|
|
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
|
|
779
|
-
* even on the user's own
|
|
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 `
|
|
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
|
-
|
|
791
|
-
/** GET /auth/tenants/{
|
|
792
|
-
list: (
|
|
811
|
+
subTenants: {
|
|
812
|
+
/** GET /auth/tenants/{tenantId}/subtenants. */
|
|
813
|
+
list: (tenantId, params = {}) => this.request(
|
|
793
814
|
appendQuery(
|
|
794
|
-
`/auth/tenants/${encodeURIComponent(
|
|
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
|
|
801
|
-
* session is scoped to (`
|
|
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/{
|
|
811
|
-
list: (
|
|
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
|
|
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
|
-
|
|
1164
|
-
|
|
1194
|
+
tenants: list,
|
|
1195
|
+
activeTenant: active,
|
|
1196
|
+
organizations: list,
|
|
1197
|
+
activeOrganization: active
|
|
1165
1198
|
};
|
|
1166
1199
|
}
|
|
1167
1200
|
function createClient(options) {
|
package/dist/react/index.d.cts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as react from 'react';
|
|
2
2
|
import { ReactNode } from 'react';
|
|
3
|
-
import {
|
|
4
|
-
export {
|
|
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;
|
package/dist/react/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as react from 'react';
|
|
2
2
|
import { ReactNode } from 'react';
|
|
3
|
-
import {
|
|
4
|
-
export {
|
|
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;
|