@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.js
CHANGED
|
@@ -477,6 +477,54 @@ 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
|
+
|
|
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
|
+
|
|
480
528
|
// src/client/authyonClient.ts
|
|
481
529
|
var FALLBACK_EXPIRES_IN = 1800;
|
|
482
530
|
function readTokens(raw) {
|
|
@@ -585,54 +633,69 @@ var AuthyonClient = class {
|
|
|
585
633
|
return { redirectUri: done?.redirectUri ?? null };
|
|
586
634
|
}
|
|
587
635
|
};
|
|
588
|
-
// ──
|
|
589
|
-
this.
|
|
636
|
+
// ── Tenant ─────────────────────────────────────────────────────────
|
|
637
|
+
this.tenants = {
|
|
590
638
|
/**
|
|
591
|
-
* GET /auth/tenants — filterable list of
|
|
639
|
+
* GET /auth/tenants — filterable list of tenant memberships.
|
|
592
640
|
*
|
|
593
|
-
* Also lists the
|
|
641
|
+
* Also lists the tenants below them that the user may switch into
|
|
594
642
|
* without being a member, marked `inherited` — only the ones that actually
|
|
595
643
|
* carry `subtenants:tree:switch`, so the switcher never offers an
|
|
596
|
-
*
|
|
644
|
+
* tenant the switch would then refuse. `depth` indents the list into
|
|
597
645
|
* the tree it describes.
|
|
598
646
|
*/
|
|
599
647
|
list: (params = {}) => this.request(appendQuery("/auth/tenants", params), { bearer: true }),
|
|
600
648
|
/**
|
|
601
|
-
* POST /auth/tenants — creates
|
|
602
|
-
* 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
|
|
603
651
|
* enabled for the environment).
|
|
604
652
|
*
|
|
605
653
|
* `parentTenantId` nests it under one the user already belongs to, which
|
|
606
654
|
* needs `subtenants:tree:create` there. The creator lands as the effective
|
|
607
655
|
* owner either way, with `tenants:settings:manage`,
|
|
608
656
|
* `tenants:members:invite` and `tenants:members:remove` granted directly
|
|
609
|
-
* inside the new
|
|
657
|
+
* inside the new tenant.
|
|
610
658
|
*/
|
|
611
659
|
create: (params = {}) => this.request("/auth/tenants", { method: "POST", bearer: true, body: params }),
|
|
612
|
-
/** GET /auth/tenants/{organizationId} — fetch one of the user's organizations by id. */
|
|
613
|
-
get: (organizationId) => this.request(`/auth/tenants/${encodeURIComponent(organizationId)}`, { bearer: true }),
|
|
614
660
|
/**
|
|
615
|
-
*
|
|
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.
|
|
616
679
|
*
|
|
617
680
|
* Requires the `tenants:settings:manage` custom permission on it, or
|
|
618
|
-
* `subtenants:tree:manage` on
|
|
681
|
+
* `subtenants:tree:manage` on a tenant above it. The value was
|
|
619
682
|
* spelled `tenants:manage` before 2026-10-31 — two segments, which the API
|
|
620
683
|
* could not store, so the endpoint refused everyone who had been granted
|
|
621
684
|
* it.
|
|
622
685
|
*/
|
|
623
|
-
rename: (
|
|
686
|
+
rename: (tenantId, name) => this.request(`/auth/tenants/${encodeURIComponent(tenantId)}`, {
|
|
624
687
|
method: "PATCH",
|
|
625
688
|
bearer: true,
|
|
626
689
|
body: { name }
|
|
627
690
|
}),
|
|
628
691
|
/**
|
|
629
692
|
* POST /auth/switch-tenant — issues a fresh token scoped to the new
|
|
630
|
-
*
|
|
693
|
+
* tenant.
|
|
631
694
|
*
|
|
632
|
-
* Membership is enough for one of the user's own
|
|
633
|
-
* 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
|
|
634
697
|
* belong to — deliberately not the same permission as administering a
|
|
635
|
-
* sub-
|
|
698
|
+
* sub-tenant from the outside, since operating AS it is the larger of
|
|
636
699
|
* the two powers. The grants then travel from the node the user belongs to,
|
|
637
700
|
* and the token says so in its `tenant.via`.
|
|
638
701
|
*
|
|
@@ -640,61 +703,58 @@ var AuthyonClient = class {
|
|
|
640
703
|
* `tenant.ancestor_disabled`, and `tenant.path_stale` when the tree moved
|
|
641
704
|
* under a session — sign-in again rather than retrying.
|
|
642
705
|
*/
|
|
643
|
-
switch: (
|
|
706
|
+
switch: (tenantSlug) => this.request("/auth/switch-tenant", {
|
|
644
707
|
method: "POST",
|
|
645
708
|
bearer: true,
|
|
646
|
-
body: { tenantSlug
|
|
709
|
+
body: { tenantSlug }
|
|
647
710
|
}).then((data) => this.setSession({ tokens: readTokens(data) }, "refreshed")).then((session) => this.hydrateUser(session)),
|
|
648
|
-
/** The
|
|
649
|
-
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,
|
|
650
713
|
members: {
|
|
651
714
|
/**
|
|
652
|
-
* GET /auth/tenants/{
|
|
653
|
-
*
|
|
715
|
+
* GET /auth/tenants/{tenantId}/members — paginated list of an
|
|
716
|
+
* tenant's members, newest first, in the `Paged<T>` envelope every
|
|
654
717
|
* other `skip`/`take` endpoint returns. `search` matches email, username
|
|
655
718
|
* or name; at most 100 characters, and `take` 1-100, checked before any
|
|
656
719
|
* request.
|
|
657
720
|
*/
|
|
658
|
-
list: (
|
|
659
|
-
appendQuery(
|
|
660
|
-
`/auth/tenants/${encodeURIComponent(organizationId)}/members`,
|
|
661
|
-
memberQuery(params)
|
|
662
|
-
),
|
|
721
|
+
list: (tenantId, params = {}) => this.request(
|
|
722
|
+
appendQuery(`/auth/tenants/${encodeURIComponent(tenantId)}/members`, memberQuery(params)),
|
|
663
723
|
{ bearer: true }
|
|
664
724
|
),
|
|
665
725
|
/**
|
|
666
|
-
* POST /auth/tenants/{
|
|
726
|
+
* POST /auth/tenants/{tenantId}/members — add an existing
|
|
667
727
|
* environment user by e-mail (no e-mail is sent). To invite an address
|
|
668
|
-
* that may not have an account yet, use `
|
|
728
|
+
* that may not have an account yet, use `tenants.invites.create`.
|
|
669
729
|
*/
|
|
670
|
-
invite: (
|
|
730
|
+
invite: (tenantId, params) => this.request(`/auth/tenants/${encodeURIComponent(tenantId)}/members`, {
|
|
671
731
|
method: "POST",
|
|
672
732
|
bearer: true,
|
|
673
733
|
body: params
|
|
674
734
|
}),
|
|
675
|
-
/** DELETE /auth/tenants/{
|
|
676
|
-
remove: (
|
|
677
|
-
`/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)}`,
|
|
678
738
|
{ method: "DELETE", bearer: true }
|
|
679
739
|
)
|
|
680
740
|
},
|
|
681
741
|
/**
|
|
682
742
|
* Invites by e-mail or by link. Managing them requires the
|
|
683
|
-
* `tenants:members:invite` permission on the
|
|
743
|
+
* `tenants:members:invite` permission on the tenant; `preview` and
|
|
684
744
|
* `accept` are public — the token in the link is the credential.
|
|
685
745
|
*/
|
|
686
746
|
invites: {
|
|
687
|
-
/** GET /auth/tenants/{
|
|
688
|
-
list: (
|
|
747
|
+
/** GET /auth/tenants/{tenantId}/invites — every invite with its status, newest first. */
|
|
748
|
+
list: (tenantId) => this.request(`/auth/tenants/${encodeURIComponent(tenantId)}/invites`, {
|
|
689
749
|
bearer: true
|
|
690
750
|
}),
|
|
691
751
|
/**
|
|
692
|
-
* POST /auth/tenants/{
|
|
752
|
+
* POST /auth/tenants/{tenantId}/invites — invite an address.
|
|
693
753
|
* Always returns `acceptUrl`; with `sendEmail: false` Authyon does not
|
|
694
754
|
* mail it and you deliver the link yourself. The link is valid for 7
|
|
695
755
|
* days, once, and can't be read again later.
|
|
696
756
|
*/
|
|
697
|
-
create: (
|
|
757
|
+
create: (tenantId, params) => this.request(`/auth/tenants/${encodeURIComponent(tenantId)}/invites`, {
|
|
698
758
|
method: "POST",
|
|
699
759
|
bearer: true,
|
|
700
760
|
body: {
|
|
@@ -705,17 +765,17 @@ var AuthyonClient = class {
|
|
|
705
765
|
}
|
|
706
766
|
}),
|
|
707
767
|
/**
|
|
708
|
-
* POST /auth/tenants/{
|
|
768
|
+
* POST /auth/tenants/{tenantId}/invites/{inviteId}/resend — issue
|
|
709
769
|
* a new link (the previous one stops working), mailing it unless
|
|
710
770
|
* `sendEmail` is `false`.
|
|
711
771
|
*/
|
|
712
|
-
resend: (
|
|
713
|
-
`/auth/tenants/${encodeURIComponent(
|
|
772
|
+
resend: (tenantId, inviteId, params = {}) => this.request(
|
|
773
|
+
`/auth/tenants/${encodeURIComponent(tenantId)}/invites/${encodeURIComponent(inviteId)}/resend`,
|
|
714
774
|
{ method: "POST", bearer: true, body: { sendEmail: params.sendEmail ?? true } }
|
|
715
775
|
),
|
|
716
|
-
/** DELETE /auth/tenants/{
|
|
717
|
-
revoke: (
|
|
718
|
-
`/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)}`,
|
|
719
779
|
{ method: "DELETE", bearer: true }
|
|
720
780
|
),
|
|
721
781
|
/**
|
|
@@ -725,19 +785,62 @@ var AuthyonClient = class {
|
|
|
725
785
|
*/
|
|
726
786
|
preview: (token) => this.request("/auth/tenant-invites/preview", { method: "POST", body: { token } }),
|
|
727
787
|
/**
|
|
728
|
-
* POST /auth/tenant-invites/accept — public. Joins the
|
|
788
|
+
* POST /auth/tenant-invites/accept — public. Joins the tenant; for
|
|
729
789
|
* an address with no account, also creates it (password required) with
|
|
730
790
|
* the e-mail already confirmed. Does not sign the user in.
|
|
731
791
|
*/
|
|
732
792
|
accept: (params) => this.request("/auth/tenant-invites/accept", { method: "POST", body: params })
|
|
733
793
|
},
|
|
794
|
+
/**
|
|
795
|
+
* The direct, active sub-tenants of a tenant. One level per
|
|
796
|
+
* call: each row's `childCount` says where the next call is worth making,
|
|
797
|
+
* which is what a lazily expanded tree asks for.
|
|
798
|
+
*
|
|
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
|
|
801
|
+
* reading below it. Paged like every other `skip`/`take` listing, with
|
|
802
|
+
* `search` (name, slug, description and public metadata), `filter` (public
|
|
803
|
+
* scope only — build them with `tenantFilter`) and `orderBy`
|
|
804
|
+
* (`name` | `createdAt` | `updatedAt`, ascending or descending). A bad
|
|
805
|
+
* option raises `RangeError` before any request.
|
|
806
|
+
*
|
|
807
|
+
* Not the same list as `tenants.list()`, which is the switcher's and
|
|
808
|
+
* only brings what `subtenants:tree:switch` lets the user enter. Requires
|
|
809
|
+
* the Authyon API of 2026-11-26 or newer.
|
|
810
|
+
*/
|
|
811
|
+
subTenants: {
|
|
812
|
+
/** GET /auth/tenants/{tenantId}/subtenants. */
|
|
813
|
+
list: (tenantId, params = {}) => this.request(
|
|
814
|
+
appendQuery(
|
|
815
|
+
`/auth/tenants/${encodeURIComponent(tenantId)}/subtenants`,
|
|
816
|
+
subTenantQuery(params)
|
|
817
|
+
),
|
|
818
|
+
{ bearer: true }
|
|
819
|
+
),
|
|
820
|
+
/**
|
|
821
|
+
* GET /auth/tenants/subtenants — the same, for the tenant the
|
|
822
|
+
* session is scoped to (`tenants.current()`, the token's
|
|
823
|
+
* `tenant_id`). Same permission rule; answers `tenant.no_active_tenant`
|
|
824
|
+
* when the session never switched into one.
|
|
825
|
+
*/
|
|
826
|
+
listCurrent: (params = {}) => this.request(appendQuery("/auth/tenants/subtenants", subTenantQuery(params)), {
|
|
827
|
+
bearer: true
|
|
828
|
+
})
|
|
829
|
+
},
|
|
734
830
|
roles: {
|
|
735
|
-
/** GET /auth/tenants/{
|
|
736
|
-
list: (
|
|
831
|
+
/** GET /auth/tenants/{tenantId}/roles — roles available in the tenant. */
|
|
832
|
+
list: (tenantId) => this.request(`/auth/tenants/${encodeURIComponent(tenantId)}/roles`, {
|
|
737
833
|
bearer: true
|
|
738
834
|
})
|
|
739
835
|
}
|
|
740
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 };
|
|
741
844
|
// ── Two-factor management (authenticated) ────────────────────────────────
|
|
742
845
|
this.twoFactor = {
|
|
743
846
|
/** GET /auth/2fa/status — enrolled methods and recovery code count. */
|
|
@@ -980,8 +1083,9 @@ var AuthyonClient = class {
|
|
|
980
1083
|
* 2FA challenge to complete via `verifyTwoFactor()`.
|
|
981
1084
|
*/
|
|
982
1085
|
async login(params) {
|
|
983
|
-
const { organizationSlug, ...rest } = params;
|
|
984
|
-
const
|
|
1086
|
+
const { organizationSlug, tenantSlug, ...rest } = params;
|
|
1087
|
+
const slug = tenantSlug ?? organizationSlug;
|
|
1088
|
+
const body = slug ? { ...rest, tenantSlug: slug } : rest;
|
|
985
1089
|
const data = await this.request("/auth/login", { method: "POST", body });
|
|
986
1090
|
if (data.twoFactor) {
|
|
987
1091
|
return { twoFactorRequired: true, ...data.twoFactor };
|
|
@@ -1082,11 +1186,15 @@ var AuthyonClient = class {
|
|
|
1082
1186
|
}
|
|
1083
1187
|
};
|
|
1084
1188
|
function normalizeUser(raw) {
|
|
1085
|
-
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;
|
|
1086
1192
|
return {
|
|
1087
1193
|
...rest,
|
|
1088
|
-
|
|
1089
|
-
|
|
1194
|
+
tenants: list,
|
|
1195
|
+
activeTenant: active,
|
|
1196
|
+
organizations: list,
|
|
1197
|
+
activeOrganization: active
|
|
1090
1198
|
};
|
|
1091
1199
|
}
|
|
1092
1200
|
function createClient(options) {
|
|
@@ -1132,6 +1240,86 @@ var AuthyonClientBuilder = class {
|
|
|
1132
1240
|
}
|
|
1133
1241
|
};
|
|
1134
1242
|
|
|
1243
|
+
// ../../internal/core/http/tenantFilters.ts
|
|
1244
|
+
var TENANT_FILTER_MAX_VALUES = 25;
|
|
1245
|
+
var TENANT_FILTER_MAX_VALUE_LENGTH = 200;
|
|
1246
|
+
var TENANT_FILTER_MAX_DEPTH = 3;
|
|
1247
|
+
var SCOPES = ["public", "private", "custom"];
|
|
1248
|
+
var KEY_SEGMENT = /^[A-Za-z0-9_-]{1,64}$/;
|
|
1249
|
+
function assertPath(path2) {
|
|
1250
|
+
if (typeof path2 !== "string" || path2.length === 0) {
|
|
1251
|
+
throw new RangeError("Authyon: a filter path is required, e.g. public.kind.");
|
|
1252
|
+
}
|
|
1253
|
+
const [scope, ...keys] = path2.split(".");
|
|
1254
|
+
if (!SCOPES.includes(scope)) {
|
|
1255
|
+
throw new RangeError(
|
|
1256
|
+
`Authyon: unknown filter scope "${scope}" \u2014 use ${SCOPES.join(", ")} (e.g. public.kind).`
|
|
1257
|
+
);
|
|
1258
|
+
}
|
|
1259
|
+
if (keys.length === 0) {
|
|
1260
|
+
throw new RangeError(`Authyon: filter path "${path2}" needs a key after the scope.`);
|
|
1261
|
+
}
|
|
1262
|
+
if (keys.length > TENANT_FILTER_MAX_DEPTH) {
|
|
1263
|
+
throw new RangeError(
|
|
1264
|
+
`Authyon: filter path "${path2}" goes deeper than ${TENANT_FILTER_MAX_DEPTH} levels.`
|
|
1265
|
+
);
|
|
1266
|
+
}
|
|
1267
|
+
for (const key of keys) {
|
|
1268
|
+
if (!KEY_SEGMENT.test(key)) {
|
|
1269
|
+
throw new RangeError(
|
|
1270
|
+
`Authyon: invalid filter key "${key}" \u2014 letters, digits, "_" and "-", up to 64 characters.`
|
|
1271
|
+
);
|
|
1272
|
+
}
|
|
1273
|
+
}
|
|
1274
|
+
return path2;
|
|
1275
|
+
}
|
|
1276
|
+
function assertValue(value, forIn) {
|
|
1277
|
+
if (value === void 0 || value === null) {
|
|
1278
|
+
throw new RangeError("Authyon: a filter value is required.");
|
|
1279
|
+
}
|
|
1280
|
+
const text = String(value);
|
|
1281
|
+
if (text.length === 0) {
|
|
1282
|
+
throw new RangeError("Authyon: a filter value may not be empty.");
|
|
1283
|
+
}
|
|
1284
|
+
if (text.length > TENANT_FILTER_MAX_VALUE_LENGTH) {
|
|
1285
|
+
throw new RangeError(
|
|
1286
|
+
`Authyon: a filter value may hold at most ${TENANT_FILTER_MAX_VALUE_LENGTH} characters.`
|
|
1287
|
+
);
|
|
1288
|
+
}
|
|
1289
|
+
if (text.includes(",")) {
|
|
1290
|
+
throw new RangeError(
|
|
1291
|
+
forIn ? "Authyon: an `in` value may not contain a comma \u2014 pass separate values instead." : "Authyon: a filter value may not contain a comma."
|
|
1292
|
+
);
|
|
1293
|
+
}
|
|
1294
|
+
return text;
|
|
1295
|
+
}
|
|
1296
|
+
var tenantFilter = {
|
|
1297
|
+
/** `public.kind:eq:reseller` — the key equals this value. */
|
|
1298
|
+
eq(path2, value) {
|
|
1299
|
+
return `${assertPath(path2)}:eq:${assertValue(value, false)}`;
|
|
1300
|
+
},
|
|
1301
|
+
/** `public.kind:in:reseller,partner` — the key equals any of these (SQL IN). */
|
|
1302
|
+
in(path2, values) {
|
|
1303
|
+
if (!Array.isArray(values) || values.length === 0) {
|
|
1304
|
+
throw new RangeError("Authyon: `in` needs at least one value.");
|
|
1305
|
+
}
|
|
1306
|
+
if (values.length > TENANT_FILTER_MAX_VALUES) {
|
|
1307
|
+
throw new RangeError(`Authyon: \`in\` takes at most ${TENANT_FILTER_MAX_VALUES} values.`);
|
|
1308
|
+
}
|
|
1309
|
+
const unique = [...new Set(values.map((value) => assertValue(value, true)))];
|
|
1310
|
+
return `${assertPath(path2)}:in:${unique.join(",")}`;
|
|
1311
|
+
},
|
|
1312
|
+
/** `public.notes:like:nacional` — the key contains this text, case-insensitive.
|
|
1313
|
+
* The server escapes the LIKE metacharacters, so `100%` means `100%`. */
|
|
1314
|
+
like(path2, text) {
|
|
1315
|
+
return `${assertPath(path2)}:like:${assertValue(text, false)}`;
|
|
1316
|
+
},
|
|
1317
|
+
/** `custom.cnpj:exists` — the key is present, whatever its value. */
|
|
1318
|
+
exists(path2) {
|
|
1319
|
+
return `${assertPath(path2)}:exists`;
|
|
1320
|
+
}
|
|
1321
|
+
};
|
|
1322
|
+
|
|
1135
1323
|
// ../../internal/core/authorization/tenantPermissions.ts
|
|
1136
1324
|
var TenantPermissions = {
|
|
1137
1325
|
/** Rename the tenant and change its settings. */
|
|
@@ -1168,6 +1356,9 @@ export {
|
|
|
1168
1356
|
FetchHttpAdapter,
|
|
1169
1357
|
LoggingHttpAdapter,
|
|
1170
1358
|
SubtenantPermissions,
|
|
1359
|
+
TENANT_FILTER_MAX_DEPTH,
|
|
1360
|
+
TENANT_FILTER_MAX_VALUES,
|
|
1361
|
+
TENANT_FILTER_MAX_VALUE_LENGTH,
|
|
1171
1362
|
TenantPermissions,
|
|
1172
1363
|
createAuthyonAbility,
|
|
1173
1364
|
createAuthyonRules,
|
|
@@ -1176,5 +1367,6 @@ export {
|
|
|
1176
1367
|
createLocalStorage,
|
|
1177
1368
|
createMemoryStorage,
|
|
1178
1369
|
hasPermission,
|
|
1179
|
-
hasPermissionGroup
|
|
1370
|
+
hasPermissionGroup,
|
|
1371
|
+
tenantFilter
|
|
1180
1372
|
};
|
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;
|