@authyon/auth 0.2.0-beta.29 → 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 +60 -32
- package/dist/{ability-D47fzavh.d.cts → ability-BPJ5VdSC.d.cts} +426 -74
- package/dist/{ability-D47fzavh.d.ts → ability-BPJ5VdSC.d.ts} +426 -74
- package/dist/index.cjs +251 -55
- package/dist/index.d.cts +40 -3
- package/dist/index.d.ts +40 -3
- package/dist/index.js +246 -54
- package/dist/react/index.d.cts +2 -2
- package/dist/react/index.d.ts +2 -2
- package/package.json +1 -1
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,54 @@ 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
|
+
|
|
557
|
+
// ../../internal/core/http/tenantLookup.ts
|
|
558
|
+
var UUID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/iu;
|
|
559
|
+
function tenantLookupPath(idOrSlug) {
|
|
560
|
+
const value = typeof idOrSlug === "string" ? idOrSlug.trim() : "";
|
|
561
|
+
if (!value) throw new RangeError("Authyon: a tenant id or slug is required.");
|
|
562
|
+
if (value.length > 64) throw new RangeError("Authyon: a tenant slug has at most 64 characters.");
|
|
563
|
+
return UUID.test(value) ? `/auth/tenants/${encodeURIComponent(value)}` : `/auth/tenants/by-slug/${encodeURIComponent(value.toLowerCase())}`;
|
|
564
|
+
}
|
|
565
|
+
|
|
514
566
|
// src/client/authyonClient.ts
|
|
515
567
|
var FALLBACK_EXPIRES_IN = 1800;
|
|
516
568
|
function readTokens(raw) {
|
|
@@ -619,54 +671,69 @@ var AuthyonClient = class {
|
|
|
619
671
|
return { redirectUri: done?.redirectUri ?? null };
|
|
620
672
|
}
|
|
621
673
|
};
|
|
622
|
-
// ──
|
|
623
|
-
this.
|
|
674
|
+
// ── Tenant ─────────────────────────────────────────────────────────
|
|
675
|
+
this.tenants = {
|
|
624
676
|
/**
|
|
625
|
-
* GET /auth/tenants — filterable list of
|
|
677
|
+
* GET /auth/tenants — filterable list of tenant memberships.
|
|
626
678
|
*
|
|
627
|
-
* Also lists the
|
|
679
|
+
* Also lists the tenants below them that the user may switch into
|
|
628
680
|
* without being a member, marked `inherited` — only the ones that actually
|
|
629
681
|
* carry `subtenants:tree:switch`, so the switcher never offers an
|
|
630
|
-
*
|
|
682
|
+
* tenant the switch would then refuse. `depth` indents the list into
|
|
631
683
|
* the tree it describes.
|
|
632
684
|
*/
|
|
633
685
|
list: (params = {}) => this.request(appendQuery("/auth/tenants", params), { bearer: true }),
|
|
634
686
|
/**
|
|
635
|
-
* POST /auth/tenants — creates
|
|
636
|
-
* user (only available when self-service
|
|
687
|
+
* POST /auth/tenants — creates a tenant owned by the signed-in
|
|
688
|
+
* user (only available when self-service tenant creation is
|
|
637
689
|
* enabled for the environment).
|
|
638
690
|
*
|
|
639
691
|
* `parentTenantId` nests it under one the user already belongs to, which
|
|
640
692
|
* needs `subtenants:tree:create` there. The creator lands as the effective
|
|
641
693
|
* owner either way, with `tenants:settings:manage`,
|
|
642
694
|
* `tenants:members:invite` and `tenants:members:remove` granted directly
|
|
643
|
-
* inside the new
|
|
695
|
+
* inside the new tenant.
|
|
644
696
|
*/
|
|
645
697
|
create: (params = {}) => this.request("/auth/tenants", { method: "POST", bearer: true, body: params }),
|
|
646
|
-
/** GET /auth/tenants/{organizationId} — fetch one of the user's organizations by id. */
|
|
647
|
-
get: (organizationId) => this.request(`/auth/tenants/${encodeURIComponent(organizationId)}`, { bearer: true }),
|
|
648
698
|
/**
|
|
649
|
-
*
|
|
699
|
+
* GET /auth/tenants/{tenantId} — one tenant by id: the user's own,
|
|
700
|
+
* or one below it with `subtenants:tree:read` on an ancestor.
|
|
701
|
+
*/
|
|
702
|
+
get: (tenantId) => this.request(`/auth/tenants/${encodeURIComponent(tenantId)}`, { bearer: true }),
|
|
703
|
+
/**
|
|
704
|
+
* One tenant by id **or** slug — a UUID goes to `GET /auth/tenants/{id}`,
|
|
705
|
+
* anything else to `GET /auth/tenants/by-slug/{slug}`. Same access rule and
|
|
706
|
+
* same answer as `get`, so a page that only has the slug from its URL
|
|
707
|
+
* doesn't have to page `subTenants.list` to find it.
|
|
708
|
+
*
|
|
709
|
+
* By slug, every refusal answers `tenant.not_found` (a slug is guessable,
|
|
710
|
+
* so "exists, not yours" is never told apart from "doesn't exist"). An
|
|
711
|
+
* empty value raises `RangeError` before any request. The slug route needs
|
|
712
|
+
* the Authyon API of 2026-11-26 or newer.
|
|
713
|
+
*/
|
|
714
|
+
find: (idOrSlug) => this.request(tenantLookupPath(idOrSlug), { bearer: true }),
|
|
715
|
+
/**
|
|
716
|
+
* PATCH /auth/tenants/{tenantId} — renames the tenant.
|
|
650
717
|
*
|
|
651
718
|
* Requires the `tenants:settings:manage` custom permission on it, or
|
|
652
|
-
* `subtenants:tree:manage` on
|
|
719
|
+
* `subtenants:tree:manage` on a tenant above it. The value was
|
|
653
720
|
* spelled `tenants:manage` before 2026-10-31 — two segments, which the API
|
|
654
721
|
* could not store, so the endpoint refused everyone who had been granted
|
|
655
722
|
* it.
|
|
656
723
|
*/
|
|
657
|
-
rename: (
|
|
724
|
+
rename: (tenantId, name) => this.request(`/auth/tenants/${encodeURIComponent(tenantId)}`, {
|
|
658
725
|
method: "PATCH",
|
|
659
726
|
bearer: true,
|
|
660
727
|
body: { name }
|
|
661
728
|
}),
|
|
662
729
|
/**
|
|
663
730
|
* POST /auth/switch-tenant — issues a fresh token scoped to the new
|
|
664
|
-
*
|
|
731
|
+
* tenant.
|
|
665
732
|
*
|
|
666
|
-
* Membership is enough for one of the user's own
|
|
667
|
-
* into one below it takes `subtenants:tree:switch` at the
|
|
733
|
+
* Membership is enough for one of the user's own tenants. Descending
|
|
734
|
+
* into one below it takes `subtenants:tree:switch` at the tenant they
|
|
668
735
|
* belong to — deliberately not the same permission as administering a
|
|
669
|
-
* sub-
|
|
736
|
+
* sub-tenant from the outside, since operating AS it is the larger of
|
|
670
737
|
* the two powers. The grants then travel from the node the user belongs to,
|
|
671
738
|
* and the token says so in its `tenant.via`.
|
|
672
739
|
*
|
|
@@ -674,61 +741,58 @@ var AuthyonClient = class {
|
|
|
674
741
|
* `tenant.ancestor_disabled`, and `tenant.path_stale` when the tree moved
|
|
675
742
|
* under a session — sign-in again rather than retrying.
|
|
676
743
|
*/
|
|
677
|
-
switch: (
|
|
744
|
+
switch: (tenantSlug) => this.request("/auth/switch-tenant", {
|
|
678
745
|
method: "POST",
|
|
679
746
|
bearer: true,
|
|
680
|
-
body: { tenantSlug
|
|
747
|
+
body: { tenantSlug }
|
|
681
748
|
}).then((data) => this.setSession({ tokens: readTokens(data) }, "refreshed")).then((session) => this.hydrateUser(session)),
|
|
682
|
-
/** The
|
|
683
|
-
current: () => this.getSession()?.user?.
|
|
749
|
+
/** The tenant the current session is scoped to, from the cached session — no network call. */
|
|
750
|
+
current: () => this.getSession()?.user?.activeTenant ?? null,
|
|
684
751
|
members: {
|
|
685
752
|
/**
|
|
686
|
-
* GET /auth/tenants/{
|
|
687
|
-
*
|
|
753
|
+
* GET /auth/tenants/{tenantId}/members — paginated list of an
|
|
754
|
+
* tenant's members, newest first, in the `Paged<T>` envelope every
|
|
688
755
|
* other `skip`/`take` endpoint returns. `search` matches email, username
|
|
689
756
|
* or name; at most 100 characters, and `take` 1-100, checked before any
|
|
690
757
|
* request.
|
|
691
758
|
*/
|
|
692
|
-
list: (
|
|
693
|
-
appendQuery(
|
|
694
|
-
`/auth/tenants/${encodeURIComponent(organizationId)}/members`,
|
|
695
|
-
memberQuery(params)
|
|
696
|
-
),
|
|
759
|
+
list: (tenantId, params = {}) => this.request(
|
|
760
|
+
appendQuery(`/auth/tenants/${encodeURIComponent(tenantId)}/members`, memberQuery(params)),
|
|
697
761
|
{ bearer: true }
|
|
698
762
|
),
|
|
699
763
|
/**
|
|
700
|
-
* POST /auth/tenants/{
|
|
764
|
+
* POST /auth/tenants/{tenantId}/members — add an existing
|
|
701
765
|
* environment user by e-mail (no e-mail is sent). To invite an address
|
|
702
|
-
* that may not have an account yet, use `
|
|
766
|
+
* that may not have an account yet, use `tenants.invites.create`.
|
|
703
767
|
*/
|
|
704
|
-
invite: (
|
|
768
|
+
invite: (tenantId, params) => this.request(`/auth/tenants/${encodeURIComponent(tenantId)}/members`, {
|
|
705
769
|
method: "POST",
|
|
706
770
|
bearer: true,
|
|
707
771
|
body: params
|
|
708
772
|
}),
|
|
709
|
-
/** DELETE /auth/tenants/{
|
|
710
|
-
remove: (
|
|
711
|
-
`/auth/tenants/${encodeURIComponent(
|
|
773
|
+
/** DELETE /auth/tenants/{tenantId}/members/{userId} — remove a member. */
|
|
774
|
+
remove: (tenantId, userId) => this.request(
|
|
775
|
+
`/auth/tenants/${encodeURIComponent(tenantId)}/members/${encodeURIComponent(userId)}`,
|
|
712
776
|
{ method: "DELETE", bearer: true }
|
|
713
777
|
)
|
|
714
778
|
},
|
|
715
779
|
/**
|
|
716
780
|
* Invites by e-mail or by link. Managing them requires the
|
|
717
|
-
* `tenants:members:invite` permission on the
|
|
781
|
+
* `tenants:members:invite` permission on the tenant; `preview` and
|
|
718
782
|
* `accept` are public — the token in the link is the credential.
|
|
719
783
|
*/
|
|
720
784
|
invites: {
|
|
721
|
-
/** GET /auth/tenants/{
|
|
722
|
-
list: (
|
|
785
|
+
/** GET /auth/tenants/{tenantId}/invites — every invite with its status, newest first. */
|
|
786
|
+
list: (tenantId) => this.request(`/auth/tenants/${encodeURIComponent(tenantId)}/invites`, {
|
|
723
787
|
bearer: true
|
|
724
788
|
}),
|
|
725
789
|
/**
|
|
726
|
-
* POST /auth/tenants/{
|
|
790
|
+
* POST /auth/tenants/{tenantId}/invites — invite an address.
|
|
727
791
|
* Always returns `acceptUrl`; with `sendEmail: false` Authyon does not
|
|
728
792
|
* mail it and you deliver the link yourself. The link is valid for 7
|
|
729
793
|
* days, once, and can't be read again later.
|
|
730
794
|
*/
|
|
731
|
-
create: (
|
|
795
|
+
create: (tenantId, params) => this.request(`/auth/tenants/${encodeURIComponent(tenantId)}/invites`, {
|
|
732
796
|
method: "POST",
|
|
733
797
|
bearer: true,
|
|
734
798
|
body: {
|
|
@@ -739,17 +803,17 @@ var AuthyonClient = class {
|
|
|
739
803
|
}
|
|
740
804
|
}),
|
|
741
805
|
/**
|
|
742
|
-
* POST /auth/tenants/{
|
|
806
|
+
* POST /auth/tenants/{tenantId}/invites/{inviteId}/resend — issue
|
|
743
807
|
* a new link (the previous one stops working), mailing it unless
|
|
744
808
|
* `sendEmail` is `false`.
|
|
745
809
|
*/
|
|
746
|
-
resend: (
|
|
747
|
-
`/auth/tenants/${encodeURIComponent(
|
|
810
|
+
resend: (tenantId, inviteId, params = {}) => this.request(
|
|
811
|
+
`/auth/tenants/${encodeURIComponent(tenantId)}/invites/${encodeURIComponent(inviteId)}/resend`,
|
|
748
812
|
{ method: "POST", bearer: true, body: { sendEmail: params.sendEmail ?? true } }
|
|
749
813
|
),
|
|
750
|
-
/** DELETE /auth/tenants/{
|
|
751
|
-
revoke: (
|
|
752
|
-
`/auth/tenants/${encodeURIComponent(
|
|
814
|
+
/** DELETE /auth/tenants/{tenantId}/invites/{inviteId} — revoke a pending invite. */
|
|
815
|
+
revoke: (tenantId, inviteId) => this.request(
|
|
816
|
+
`/auth/tenants/${encodeURIComponent(tenantId)}/invites/${encodeURIComponent(inviteId)}`,
|
|
753
817
|
{ method: "DELETE", bearer: true }
|
|
754
818
|
),
|
|
755
819
|
/**
|
|
@@ -759,19 +823,62 @@ var AuthyonClient = class {
|
|
|
759
823
|
*/
|
|
760
824
|
preview: (token) => this.request("/auth/tenant-invites/preview", { method: "POST", body: { token } }),
|
|
761
825
|
/**
|
|
762
|
-
* POST /auth/tenant-invites/accept — public. Joins the
|
|
826
|
+
* POST /auth/tenant-invites/accept — public. Joins the tenant; for
|
|
763
827
|
* an address with no account, also creates it (password required) with
|
|
764
828
|
* the e-mail already confirmed. Does not sign the user in.
|
|
765
829
|
*/
|
|
766
830
|
accept: (params) => this.request("/auth/tenant-invites/accept", { method: "POST", body: params })
|
|
767
831
|
},
|
|
832
|
+
/**
|
|
833
|
+
* The direct, active sub-tenants of a tenant. One level per
|
|
834
|
+
* call: each row's `childCount` says where the next call is worth making,
|
|
835
|
+
* which is what a lazily expanded tree asks for.
|
|
836
|
+
*
|
|
837
|
+
* Needs `subtenants:tree:read` on the tenant or on one above it —
|
|
838
|
+
* even on the user's own tenant, since listing the children is
|
|
839
|
+
* reading below it. Paged like every other `skip`/`take` listing, with
|
|
840
|
+
* `search` (name, slug, description and public metadata), `filter` (public
|
|
841
|
+
* scope only — build them with `tenantFilter`) and `orderBy`
|
|
842
|
+
* (`name` | `createdAt` | `updatedAt`, ascending or descending). A bad
|
|
843
|
+
* option raises `RangeError` before any request.
|
|
844
|
+
*
|
|
845
|
+
* Not the same list as `tenants.list()`, which is the switcher's and
|
|
846
|
+
* only brings what `subtenants:tree:switch` lets the user enter. Requires
|
|
847
|
+
* the Authyon API of 2026-11-26 or newer.
|
|
848
|
+
*/
|
|
849
|
+
subTenants: {
|
|
850
|
+
/** GET /auth/tenants/{tenantId}/subtenants. */
|
|
851
|
+
list: (tenantId, params = {}) => this.request(
|
|
852
|
+
appendQuery(
|
|
853
|
+
`/auth/tenants/${encodeURIComponent(tenantId)}/subtenants`,
|
|
854
|
+
subTenantQuery(params)
|
|
855
|
+
),
|
|
856
|
+
{ bearer: true }
|
|
857
|
+
),
|
|
858
|
+
/**
|
|
859
|
+
* GET /auth/tenants/subtenants — the same, for the tenant the
|
|
860
|
+
* session is scoped to (`tenants.current()`, the token's
|
|
861
|
+
* `tenant_id`). Same permission rule; answers `tenant.no_active_tenant`
|
|
862
|
+
* when the session never switched into one.
|
|
863
|
+
*/
|
|
864
|
+
listCurrent: (params = {}) => this.request(appendQuery("/auth/tenants/subtenants", subTenantQuery(params)), {
|
|
865
|
+
bearer: true
|
|
866
|
+
})
|
|
867
|
+
},
|
|
768
868
|
roles: {
|
|
769
|
-
/** GET /auth/tenants/{
|
|
770
|
-
list: (
|
|
869
|
+
/** GET /auth/tenants/{tenantId}/roles — roles available in the tenant. */
|
|
870
|
+
list: (tenantId) => this.request(`/auth/tenants/${encodeURIComponent(tenantId)}/roles`, {
|
|
771
871
|
bearer: true
|
|
772
872
|
})
|
|
773
873
|
}
|
|
774
874
|
};
|
|
875
|
+
/**
|
|
876
|
+
* @deprecated Use `tenants` — the same methods, named after the API's own
|
|
877
|
+
* vocabulary (`tenants.subTenants` instead of `subOrganizations`). Kept so
|
|
878
|
+
* code written against 0.2.0-beta.30 and earlier keeps working; removed in a
|
|
879
|
+
* later release.
|
|
880
|
+
*/
|
|
881
|
+
this.organization = { ...this.tenants, subOrganizations: this.tenants.subTenants };
|
|
775
882
|
// ── Two-factor management (authenticated) ────────────────────────────────
|
|
776
883
|
this.twoFactor = {
|
|
777
884
|
/** GET /auth/2fa/status — enrolled methods and recovery code count. */
|
|
@@ -1014,8 +1121,9 @@ var AuthyonClient = class {
|
|
|
1014
1121
|
* 2FA challenge to complete via `verifyTwoFactor()`.
|
|
1015
1122
|
*/
|
|
1016
1123
|
async login(params) {
|
|
1017
|
-
const { organizationSlug, ...rest } = params;
|
|
1018
|
-
const
|
|
1124
|
+
const { organizationSlug, tenantSlug, ...rest } = params;
|
|
1125
|
+
const slug = tenantSlug ?? organizationSlug;
|
|
1126
|
+
const body = slug ? { ...rest, tenantSlug: slug } : rest;
|
|
1019
1127
|
const data = await this.request("/auth/login", { method: "POST", body });
|
|
1020
1128
|
if (data.twoFactor) {
|
|
1021
1129
|
return { twoFactorRequired: true, ...data.twoFactor };
|
|
@@ -1116,11 +1224,15 @@ var AuthyonClient = class {
|
|
|
1116
1224
|
}
|
|
1117
1225
|
};
|
|
1118
1226
|
function normalizeUser(raw) {
|
|
1119
|
-
const { tenant, tenants, activeTenant, ...rest } = raw;
|
|
1227
|
+
const { tenant, tenants, activeTenant, organizations, activeOrganization, ...rest } = raw;
|
|
1228
|
+
const list = tenants ?? organizations;
|
|
1229
|
+
const active = tenant ?? activeTenant ?? activeOrganization ?? null;
|
|
1120
1230
|
return {
|
|
1121
1231
|
...rest,
|
|
1122
|
-
|
|
1123
|
-
|
|
1232
|
+
tenants: list,
|
|
1233
|
+
activeTenant: active,
|
|
1234
|
+
organizations: list,
|
|
1235
|
+
activeOrganization: active
|
|
1124
1236
|
};
|
|
1125
1237
|
}
|
|
1126
1238
|
function createClient(options) {
|
|
@@ -1166,6 +1278,86 @@ var AuthyonClientBuilder = class {
|
|
|
1166
1278
|
}
|
|
1167
1279
|
};
|
|
1168
1280
|
|
|
1281
|
+
// ../../internal/core/http/tenantFilters.ts
|
|
1282
|
+
var TENANT_FILTER_MAX_VALUES = 25;
|
|
1283
|
+
var TENANT_FILTER_MAX_VALUE_LENGTH = 200;
|
|
1284
|
+
var TENANT_FILTER_MAX_DEPTH = 3;
|
|
1285
|
+
var SCOPES = ["public", "private", "custom"];
|
|
1286
|
+
var KEY_SEGMENT = /^[A-Za-z0-9_-]{1,64}$/;
|
|
1287
|
+
function assertPath(path2) {
|
|
1288
|
+
if (typeof path2 !== "string" || path2.length === 0) {
|
|
1289
|
+
throw new RangeError("Authyon: a filter path is required, e.g. public.kind.");
|
|
1290
|
+
}
|
|
1291
|
+
const [scope, ...keys] = path2.split(".");
|
|
1292
|
+
if (!SCOPES.includes(scope)) {
|
|
1293
|
+
throw new RangeError(
|
|
1294
|
+
`Authyon: unknown filter scope "${scope}" \u2014 use ${SCOPES.join(", ")} (e.g. public.kind).`
|
|
1295
|
+
);
|
|
1296
|
+
}
|
|
1297
|
+
if (keys.length === 0) {
|
|
1298
|
+
throw new RangeError(`Authyon: filter path "${path2}" needs a key after the scope.`);
|
|
1299
|
+
}
|
|
1300
|
+
if (keys.length > TENANT_FILTER_MAX_DEPTH) {
|
|
1301
|
+
throw new RangeError(
|
|
1302
|
+
`Authyon: filter path "${path2}" goes deeper than ${TENANT_FILTER_MAX_DEPTH} levels.`
|
|
1303
|
+
);
|
|
1304
|
+
}
|
|
1305
|
+
for (const key of keys) {
|
|
1306
|
+
if (!KEY_SEGMENT.test(key)) {
|
|
1307
|
+
throw new RangeError(
|
|
1308
|
+
`Authyon: invalid filter key "${key}" \u2014 letters, digits, "_" and "-", up to 64 characters.`
|
|
1309
|
+
);
|
|
1310
|
+
}
|
|
1311
|
+
}
|
|
1312
|
+
return path2;
|
|
1313
|
+
}
|
|
1314
|
+
function assertValue(value, forIn) {
|
|
1315
|
+
if (value === void 0 || value === null) {
|
|
1316
|
+
throw new RangeError("Authyon: a filter value is required.");
|
|
1317
|
+
}
|
|
1318
|
+
const text = String(value);
|
|
1319
|
+
if (text.length === 0) {
|
|
1320
|
+
throw new RangeError("Authyon: a filter value may not be empty.");
|
|
1321
|
+
}
|
|
1322
|
+
if (text.length > TENANT_FILTER_MAX_VALUE_LENGTH) {
|
|
1323
|
+
throw new RangeError(
|
|
1324
|
+
`Authyon: a filter value may hold at most ${TENANT_FILTER_MAX_VALUE_LENGTH} characters.`
|
|
1325
|
+
);
|
|
1326
|
+
}
|
|
1327
|
+
if (text.includes(",")) {
|
|
1328
|
+
throw new RangeError(
|
|
1329
|
+
forIn ? "Authyon: an `in` value may not contain a comma \u2014 pass separate values instead." : "Authyon: a filter value may not contain a comma."
|
|
1330
|
+
);
|
|
1331
|
+
}
|
|
1332
|
+
return text;
|
|
1333
|
+
}
|
|
1334
|
+
var tenantFilter = {
|
|
1335
|
+
/** `public.kind:eq:reseller` — the key equals this value. */
|
|
1336
|
+
eq(path2, value) {
|
|
1337
|
+
return `${assertPath(path2)}:eq:${assertValue(value, false)}`;
|
|
1338
|
+
},
|
|
1339
|
+
/** `public.kind:in:reseller,partner` — the key equals any of these (SQL IN). */
|
|
1340
|
+
in(path2, values) {
|
|
1341
|
+
if (!Array.isArray(values) || values.length === 0) {
|
|
1342
|
+
throw new RangeError("Authyon: `in` needs at least one value.");
|
|
1343
|
+
}
|
|
1344
|
+
if (values.length > TENANT_FILTER_MAX_VALUES) {
|
|
1345
|
+
throw new RangeError(`Authyon: \`in\` takes at most ${TENANT_FILTER_MAX_VALUES} values.`);
|
|
1346
|
+
}
|
|
1347
|
+
const unique = [...new Set(values.map((value) => assertValue(value, true)))];
|
|
1348
|
+
return `${assertPath(path2)}:in:${unique.join(",")}`;
|
|
1349
|
+
},
|
|
1350
|
+
/** `public.notes:like:nacional` — the key contains this text, case-insensitive.
|
|
1351
|
+
* The server escapes the LIKE metacharacters, so `100%` means `100%`. */
|
|
1352
|
+
like(path2, text) {
|
|
1353
|
+
return `${assertPath(path2)}:like:${assertValue(text, false)}`;
|
|
1354
|
+
},
|
|
1355
|
+
/** `custom.cnpj:exists` — the key is present, whatever its value. */
|
|
1356
|
+
exists(path2) {
|
|
1357
|
+
return `${assertPath(path2)}:exists`;
|
|
1358
|
+
}
|
|
1359
|
+
};
|
|
1360
|
+
|
|
1169
1361
|
// src/session/sessionController.ts
|
|
1170
1362
|
var SERVER_SNAPSHOT = {
|
|
1171
1363
|
// The server cannot inspect browser storage. Reporting unauthenticated here
|
|
@@ -1569,6 +1761,9 @@ var SubtenantPermissions = {
|
|
|
1569
1761
|
FetchHttpAdapter,
|
|
1570
1762
|
LoggingHttpAdapter,
|
|
1571
1763
|
SubtenantPermissions,
|
|
1764
|
+
TENANT_FILTER_MAX_DEPTH,
|
|
1765
|
+
TENANT_FILTER_MAX_VALUES,
|
|
1766
|
+
TENANT_FILTER_MAX_VALUE_LENGTH,
|
|
1572
1767
|
TenantPermissions,
|
|
1573
1768
|
createAuthyonAbility,
|
|
1574
1769
|
createAuthyonRules,
|
|
@@ -1577,5 +1772,6 @@ var SubtenantPermissions = {
|
|
|
1577
1772
|
createLocalStorage,
|
|
1578
1773
|
createMemoryStorage,
|
|
1579
1774
|
hasPermission,
|
|
1580
|
-
hasPermissionGroup
|
|
1775
|
+
hasPermissionGroup,
|
|
1776
|
+
tenantFilter
|
|
1581
1777
|
});
|
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-
|
|
2
|
-
export { b as AbilityConditions, c as AbilityEvent, d as AbilityListener, e as AbilityRule, f as AbilitySubject, g as AcceptOrganizationInviteInput, h as
|
|
1
|
+
import { T as TokenStorage, H as HttpAdapter, a as HttpLoggerOptions, A as AuthyonClient } from './ability-BPJ5VdSC.cjs';
|
|
2
|
+
export { b as AbilityConditions, c as AbilityEvent, d as AbilityListener, e as AbilityRule, f as AbilitySubject, g as AcceptOrganizationInviteInput, h as AcceptTenantInviteInput, i as Activity, j as Approval, k as ApprovalAssurance, l as ApprovalPayload, m as ApprovalStatus, n as ApprovalWebAuthnOptions, o as AuthEvent, p as AuthState, q as AuthStateListener, r as AuthenticatorSetup, s as AuthyonAbility, t as AuthyonAbilityBuilder, u as AuthyonAbilityOptions, v as AuthyonClientOptions, w as AuthyonPermissionSource, x as AuthyonSessionController, C as ConfirmApprovalInput, y as CreateOrganizationInput, z as CreateTenantInput, F as FetchHttpAdapter, B as HttpAdapterRequest, D as HttpLogEvent, E as HttpLogger, I as IntrospectResult, G as InviteMemberInput, L as LoggingHttpAdapter, J as LoginInput, K as LoginResult, M as MemberListOptions, O as Organization, N as OrganizationInvite, P as OrganizationInviteAccepted, Q as OrganizationInviteInput, R as OrganizationInviteIssued, S as OrganizationInvitePreview, U as OrganizationInviteStatus, V as OrganizationMember, W as Paged, X as PaginationOptions, Y as PasswordResetCompleted, Z as PasswordResetPreview, _ as PasswordResetRequestOptions, $ as PermissionGroup, a0 as RegisterInput, a1 as Role, a2 as SecurityMethods, a3 as Session, a4 as SessionControllerOptions, a5 as SessionInfo, a6 as SessionSnapshot, a7 as SessionSnapshotListener, a8 as SessionStatus, a9 as SsoProvider, aa as SubOrganization, ab as SubOrganizationListOptions, ac as SubTenant, ad as SubTenantListOptions, ae as SubjectApprovals, af as SubjectSecurity, ag as Tenant, ah as TenantInvite, ai as TenantInviteAccepted, aj as TenantInviteInput, ak as TenantInviteIssued, al as TenantInvitePreview, am as TenantInviteStatus, an as TenantMember, ao as TenantOrder, ap as TenantOrderField, aq as TenantParent, ar as TwoFactorChallenge, as as TwoFactorMethod, at as TwoFactorStatus, au as User, av as ValidateResult, aw as VerifyTwoFactorInput, ax as WebAuthnAssertion, ay as WebAuthnCeremonyStart, az as WebAuthnCredential, aA as createAuthyonAbility, aB as createAuthyonRules, aC as createClient, aD as hasPermission, aE as hasPermissionGroup } from './ability-BPJ5VdSC.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-
|
|
2
|
-
export { b as AbilityConditions, c as AbilityEvent, d as AbilityListener, e as AbilityRule, f as AbilitySubject, g as AcceptOrganizationInviteInput, h as
|
|
1
|
+
import { T as TokenStorage, H as HttpAdapter, a as HttpLoggerOptions, A as AuthyonClient } from './ability-BPJ5VdSC.js';
|
|
2
|
+
export { b as AbilityConditions, c as AbilityEvent, d as AbilityListener, e as AbilityRule, f as AbilitySubject, g as AcceptOrganizationInviteInput, h as AcceptTenantInviteInput, i as Activity, j as Approval, k as ApprovalAssurance, l as ApprovalPayload, m as ApprovalStatus, n as ApprovalWebAuthnOptions, o as AuthEvent, p as AuthState, q as AuthStateListener, r as AuthenticatorSetup, s as AuthyonAbility, t as AuthyonAbilityBuilder, u as AuthyonAbilityOptions, v as AuthyonClientOptions, w as AuthyonPermissionSource, x as AuthyonSessionController, C as ConfirmApprovalInput, y as CreateOrganizationInput, z as CreateTenantInput, F as FetchHttpAdapter, B as HttpAdapterRequest, D as HttpLogEvent, E as HttpLogger, I as IntrospectResult, G as InviteMemberInput, L as LoggingHttpAdapter, J as LoginInput, K as LoginResult, M as MemberListOptions, O as Organization, N as OrganizationInvite, P as OrganizationInviteAccepted, Q as OrganizationInviteInput, R as OrganizationInviteIssued, S as OrganizationInvitePreview, U as OrganizationInviteStatus, V as OrganizationMember, W as Paged, X as PaginationOptions, Y as PasswordResetCompleted, Z as PasswordResetPreview, _ as PasswordResetRequestOptions, $ as PermissionGroup, a0 as RegisterInput, a1 as Role, a2 as SecurityMethods, a3 as Session, a4 as SessionControllerOptions, a5 as SessionInfo, a6 as SessionSnapshot, a7 as SessionSnapshotListener, a8 as SessionStatus, a9 as SsoProvider, aa as SubOrganization, ab as SubOrganizationListOptions, ac as SubTenant, ad as SubTenantListOptions, ae as SubjectApprovals, af as SubjectSecurity, ag as Tenant, ah as TenantInvite, ai as TenantInviteAccepted, aj as TenantInviteInput, ak as TenantInviteIssued, al as TenantInvitePreview, am as TenantInviteStatus, an as TenantMember, ao as TenantOrder, ap as TenantOrderField, aq as TenantParent, ar as TwoFactorChallenge, as as TwoFactorMethod, at as TwoFactorStatus, au as User, av as ValidateResult, aw as VerifyTwoFactorInput, ax as WebAuthnAssertion, ay as WebAuthnCeremonyStart, az as WebAuthnCredential, aA as createAuthyonAbility, aB as createAuthyonRules, aC as createClient, aD as hasPermission, aE as hasPermissionGroup } from './ability-BPJ5VdSC.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 };
|