cauthy-auth 0.28.1 → 0.30.0
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 +51 -0
- package/dist/{cauthy-CTVg4kvo.d.mts → cauthy-BXgsZ-Um.d.mts} +19 -1
- package/dist/{cauthy-BAwAJChs.d.ts → cauthy-CHENs452.d.ts} +19 -1
- package/dist/cli.js +155 -54
- package/dist/client.d.mts +47 -7
- package/dist/client.d.ts +47 -7
- package/dist/client.js +23 -1
- package/dist/client.js.map +1 -1
- package/dist/client.mjs +23 -1
- package/dist/client.mjs.map +1 -1
- package/dist/express.d.mts +2 -2
- package/dist/express.d.ts +2 -2
- package/dist/fastify.d.mts +2 -2
- package/dist/fastify.d.ts +2 -2
- package/dist/hono.d.mts +2 -2
- package/dist/hono.d.ts +2 -2
- package/dist/index.d.mts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +325 -129
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +323 -129
- package/dist/index.mjs.map +1 -1
- package/dist/next.d.mts +2 -2
- package/dist/next.d.ts +2 -2
- package/dist/react.d.mts +214 -18
- package/dist/react.d.ts +214 -18
- package/dist/react.js +129 -32
- package/dist/react.js.map +1 -1
- package/dist/react.mjs +129 -32
- package/dist/react.mjs.map +1 -1
- package/dist/svelte.d.mts +2 -2
- package/dist/svelte.d.ts +2 -2
- package/dist/svelte.js +37 -2
- package/dist/svelte.js.map +1 -1
- package/dist/svelte.mjs +37 -2
- package/dist/svelte.mjs.map +1 -1
- package/dist/{system-CVBW_AV8.d.mts → system-0mHrdAgO.d.mts} +307 -109
- package/dist/{system-Bn8uckvQ.d.ts → system-BIYbS7h2.d.ts} +307 -109
- package/dist/vue.d.mts +2 -2
- package/dist/vue.d.ts +2 -2
- package/dist/vue.js +37 -2
- package/dist/vue.js.map +1 -1
- package/dist/vue.mjs +37 -2
- package/dist/vue.mjs.map +1 -1
- package/package.json +1 -1
package/dist/svelte.mjs
CHANGED
|
@@ -254,6 +254,12 @@ function checkOrganization(value, required = false) {
|
|
|
254
254
|
if (v.length > MAX_ORGANIZATION) return { field: "organization", code: "too_long", message: `Use at most ${MAX_ORGANIZATION} characters.` };
|
|
255
255
|
return null;
|
|
256
256
|
}
|
|
257
|
+
function checkOrganizationName(value) {
|
|
258
|
+
const v = typeof value === "string" ? value.trim() : "";
|
|
259
|
+
if (v === "") return { field: "name", code: "required", message: "Enter the organization's name." };
|
|
260
|
+
if (v.length > MAX_ORGANIZATION) return { field: "name", code: "too_long", message: `Use at most ${MAX_ORGANIZATION} characters.` };
|
|
261
|
+
return null;
|
|
262
|
+
}
|
|
257
263
|
function checkCode(value) {
|
|
258
264
|
const v = typeof value === "string" ? value.trim() : "";
|
|
259
265
|
if (v === "") return { field: "code", code: "required", message: "Enter the code." };
|
|
@@ -506,7 +512,23 @@ function createAuthClient(options = {}) {
|
|
|
506
512
|
add: (id, f) => post("/me/organizations/members/add", { organizationId: id, email: f.email, role: f.role, name: f.name ?? "", locale: f.locale ?? "" }, checkEmail(f.email)),
|
|
507
513
|
setRole: (id, userId, role) => post("/me/organizations/members/role", { organizationId: id, userId, role }, null),
|
|
508
514
|
remove: (id, userId) => post("/me/organizations/members/remove", { organizationId: id, userId }, null),
|
|
509
|
-
inviteAgain: (id, userId, f = {}) => post("/me/organizations/members/invite", { organizationId: id, userId, locale: f.locale ?? "" }, null)
|
|
515
|
+
inviteAgain: (id, userId, f = {}) => post("/me/organizations/members/invite", { organizationId: id, userId, locale: f.locale ?? "" }, null),
|
|
516
|
+
rename: (id, name) => post("/me/organizations/rename", { organizationId: id, name }, checkOrganizationName(name)),
|
|
517
|
+
archive: (id) => post("/me/organizations/archive", { organizationId: id }, null),
|
|
518
|
+
delete: (id) => post("/me/organizations/delete", { organizationId: id }, null),
|
|
519
|
+
async check(q) {
|
|
520
|
+
const organizationId = typeof q.organization === "string" ? q.organization : q.organization?.id ?? "";
|
|
521
|
+
const r = await post("/me/organizations/check", {
|
|
522
|
+
organizationId,
|
|
523
|
+
resource: q.resource,
|
|
524
|
+
action: q.action,
|
|
525
|
+
...q.attributes !== void 0 ? { attributes: q.attributes } : {},
|
|
526
|
+
...q.resourceId !== void 0 ? { resourceId: q.resourceId } : {},
|
|
527
|
+
...q.ownerId !== void 0 ? { ownerId: q.ownerId } : {}
|
|
528
|
+
}, null);
|
|
529
|
+
if (!r.ok) return { allowed: false, reason: r.error.message, error: r.error };
|
|
530
|
+
return { allowed: r.allowed === true, reason: String(r.reason ?? ""), ...r.rule ? { rule: r.rule } : {} };
|
|
531
|
+
}
|
|
510
532
|
},
|
|
511
533
|
account: {
|
|
512
534
|
async get() {
|
|
@@ -710,7 +732,9 @@ function can(organization, resource, action) {
|
|
|
710
732
|
if ((organization.denied ?? []).some((d) => matches(d, resource, action))) return false;
|
|
711
733
|
return organization.permissions.some((p) => matches(p, resource, action));
|
|
712
734
|
}
|
|
713
|
-
function definePolicy(
|
|
735
|
+
function definePolicy(given) {
|
|
736
|
+
const roles = Array.isArray(given) ? given : given.roles;
|
|
737
|
+
const resources = Array.isArray(given) ? [] : given.catalog ?? [];
|
|
714
738
|
const entry = (p) => `${p.resource}:${p.action}`;
|
|
715
739
|
const byName = new Map(roles.map((r) => [r.role, r]));
|
|
716
740
|
const split = (permission) => {
|
|
@@ -725,6 +749,12 @@ function definePolicy(roles) {
|
|
|
725
749
|
...r.inherits ? { inherits: [...r.inherits] } : {},
|
|
726
750
|
...r.permissions ? { permissions: r.permissions.map((p) => ({ ...p })) } : {}
|
|
727
751
|
})),
|
|
752
|
+
catalog: resources.map((c) => ({
|
|
753
|
+
resource: c.resource,
|
|
754
|
+
...c.description !== void 0 ? { description: c.description } : {},
|
|
755
|
+
actions: [...c.actions],
|
|
756
|
+
...c.attributes ? { attributes: { ...c.attributes } } : {}
|
|
757
|
+
})),
|
|
728
758
|
roleNames: roles.map((r) => r.role),
|
|
729
759
|
permissions: [...new Set(roles.flatMap((r) => (r.permissions ?? []).map(entry)))],
|
|
730
760
|
can(organization, permission) {
|
|
@@ -746,6 +776,11 @@ function definePolicy(roles) {
|
|
|
746
776
|
};
|
|
747
777
|
walk(role);
|
|
748
778
|
return [...out];
|
|
779
|
+
},
|
|
780
|
+
// The types did the work; this only hands the question on, as a method of
|
|
781
|
+
// the asker so it keeps its `this`.
|
|
782
|
+
check(asker, ...args) {
|
|
783
|
+
return asker.check(...args);
|
|
749
784
|
}
|
|
750
785
|
};
|
|
751
786
|
}
|