cauthy-auth 0.28.0 → 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.
Files changed (45) hide show
  1. package/README.md +52 -1
  2. package/dist/{cauthy-XkIbG5gE.d.mts → cauthy-BXgsZ-Um.d.mts} +19 -1
  3. package/dist/{cauthy-DGAy45G2.d.ts → cauthy-CHENs452.d.ts} +19 -1
  4. package/dist/cli.js +155 -54
  5. package/dist/client.d.mts +47 -7
  6. package/dist/client.d.ts +47 -7
  7. package/dist/client.js +23 -1
  8. package/dist/client.js.map +1 -1
  9. package/dist/client.mjs +23 -1
  10. package/dist/client.mjs.map +1 -1
  11. package/dist/express.d.mts +2 -2
  12. package/dist/express.d.ts +2 -2
  13. package/dist/fastify.d.mts +2 -2
  14. package/dist/fastify.d.ts +2 -2
  15. package/dist/hono.d.mts +2 -2
  16. package/dist/hono.d.ts +2 -2
  17. package/dist/index.d.mts +2 -2
  18. package/dist/index.d.ts +2 -2
  19. package/dist/index.js +352 -131
  20. package/dist/index.js.map +1 -1
  21. package/dist/index.mjs +350 -131
  22. package/dist/index.mjs.map +1 -1
  23. package/dist/next.d.mts +2 -2
  24. package/dist/next.d.ts +2 -2
  25. package/dist/react.d.mts +214 -18
  26. package/dist/react.d.ts +214 -18
  27. package/dist/react.js +129 -32
  28. package/dist/react.js.map +1 -1
  29. package/dist/react.mjs +129 -32
  30. package/dist/react.mjs.map +1 -1
  31. package/dist/svelte.d.mts +2 -2
  32. package/dist/svelte.d.ts +2 -2
  33. package/dist/svelte.js +37 -2
  34. package/dist/svelte.js.map +1 -1
  35. package/dist/svelte.mjs +37 -2
  36. package/dist/svelte.mjs.map +1 -1
  37. package/dist/{system-BxMsSIu1.d.mts → system-0mHrdAgO.d.mts} +312 -112
  38. package/dist/{system-DTIeDXDP.d.ts → system-BIYbS7h2.d.ts} +312 -112
  39. package/dist/vue.d.mts +2 -2
  40. package/dist/vue.d.ts +2 -2
  41. package/dist/vue.js +37 -2
  42. package/dist/vue.js.map +1 -1
  43. package/dist/vue.mjs +37 -2
  44. package/dist/vue.mjs.map +1 -1
  45. package/package.json +1 -1
package/dist/svelte.d.mts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { SessionStore, SessionState, SessionStoreOptions } from './client.mjs';
2
2
  export { Account, AccountSession, AuthClient, AuthError, AuthMethods, AuthResult, Passkey, PasskeyKind, SSOConnection } from './client.mjs';
3
- import { i as PublicSession } from './system-BxMsSIu1.mjs';
4
- export { P as PermissionOf, f as Policy, R as RoleOf, k as SessionOrganization, m as SessionUser, p as can, r as definePolicy } from './system-BxMsSIu1.mjs';
3
+ import { q as PublicSession } from './system-0mHrdAgO.mjs';
4
+ export { P as PermissionOf, m as Policy, R as RoleOf, s as SessionOrganization, u as SessionUser, y as can, B as definePolicy } from './system-0mHrdAgO.mjs';
5
5
  import './theme.mjs';
6
6
  import './validate-sEXG82po.mjs';
7
7
  import 'jose';
package/dist/svelte.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { SessionStore, SessionState, SessionStoreOptions } from './client.js';
2
2
  export { Account, AccountSession, AuthClient, AuthError, AuthMethods, AuthResult, Passkey, PasskeyKind, SSOConnection } from './client.js';
3
- import { i as PublicSession } from './system-DTIeDXDP.js';
4
- export { P as PermissionOf, f as Policy, R as RoleOf, k as SessionOrganization, m as SessionUser, p as can, r as definePolicy } from './system-DTIeDXDP.js';
3
+ import { q as PublicSession } from './system-BIYbS7h2.js';
4
+ export { P as PermissionOf, m as Policy, R as RoleOf, s as SessionOrganization, u as SessionUser, y as can, B as definePolicy } from './system-BIYbS7h2.js';
5
5
  import './theme.js';
6
6
  import './validate-sEXG82po.js';
7
7
  import 'jose';
package/dist/svelte.js CHANGED
@@ -282,6 +282,12 @@ function checkOrganization(value, required = false) {
282
282
  if (v.length > MAX_ORGANIZATION) return { field: "organization", code: "too_long", message: `Use at most ${MAX_ORGANIZATION} characters.` };
283
283
  return null;
284
284
  }
285
+ function checkOrganizationName(value) {
286
+ const v = typeof value === "string" ? value.trim() : "";
287
+ if (v === "") return { field: "name", code: "required", message: "Enter the organization's name." };
288
+ if (v.length > MAX_ORGANIZATION) return { field: "name", code: "too_long", message: `Use at most ${MAX_ORGANIZATION} characters.` };
289
+ return null;
290
+ }
285
291
  function checkCode(value) {
286
292
  const v = typeof value === "string" ? value.trim() : "";
287
293
  if (v === "") return { field: "code", code: "required", message: "Enter the code." };
@@ -534,7 +540,23 @@ function createAuthClient(options = {}) {
534
540
  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)),
535
541
  setRole: (id, userId, role) => post("/me/organizations/members/role", { organizationId: id, userId, role }, null),
536
542
  remove: (id, userId) => post("/me/organizations/members/remove", { organizationId: id, userId }, null),
537
- inviteAgain: (id, userId, f = {}) => post("/me/organizations/members/invite", { organizationId: id, userId, locale: f.locale ?? "" }, null)
543
+ inviteAgain: (id, userId, f = {}) => post("/me/organizations/members/invite", { organizationId: id, userId, locale: f.locale ?? "" }, null),
544
+ rename: (id, name) => post("/me/organizations/rename", { organizationId: id, name }, checkOrganizationName(name)),
545
+ archive: (id) => post("/me/organizations/archive", { organizationId: id }, null),
546
+ delete: (id) => post("/me/organizations/delete", { organizationId: id }, null),
547
+ async check(q) {
548
+ const organizationId = typeof q.organization === "string" ? q.organization : q.organization?.id ?? "";
549
+ const r = await post("/me/organizations/check", {
550
+ organizationId,
551
+ resource: q.resource,
552
+ action: q.action,
553
+ ...q.attributes !== void 0 ? { attributes: q.attributes } : {},
554
+ ...q.resourceId !== void 0 ? { resourceId: q.resourceId } : {},
555
+ ...q.ownerId !== void 0 ? { ownerId: q.ownerId } : {}
556
+ }, null);
557
+ if (!r.ok) return { allowed: false, reason: r.error.message, error: r.error };
558
+ return { allowed: r.allowed === true, reason: String(r.reason ?? ""), ...r.rule ? { rule: r.rule } : {} };
559
+ }
538
560
  },
539
561
  account: {
540
562
  async get() {
@@ -738,7 +760,9 @@ function can(organization, resource, action) {
738
760
  if ((organization.denied ?? []).some((d) => matches(d, resource, action))) return false;
739
761
  return organization.permissions.some((p) => matches(p, resource, action));
740
762
  }
741
- function definePolicy(roles) {
763
+ function definePolicy(given) {
764
+ const roles = Array.isArray(given) ? given : given.roles;
765
+ const resources = Array.isArray(given) ? [] : given.catalog ?? [];
742
766
  const entry = (p) => `${p.resource}:${p.action}`;
743
767
  const byName = new Map(roles.map((r) => [r.role, r]));
744
768
  const split = (permission) => {
@@ -753,6 +777,12 @@ function definePolicy(roles) {
753
777
  ...r.inherits ? { inherits: [...r.inherits] } : {},
754
778
  ...r.permissions ? { permissions: r.permissions.map((p) => ({ ...p })) } : {}
755
779
  })),
780
+ catalog: resources.map((c) => ({
781
+ resource: c.resource,
782
+ ...c.description !== void 0 ? { description: c.description } : {},
783
+ actions: [...c.actions],
784
+ ...c.attributes ? { attributes: { ...c.attributes } } : {}
785
+ })),
756
786
  roleNames: roles.map((r) => r.role),
757
787
  permissions: [...new Set(roles.flatMap((r) => (r.permissions ?? []).map(entry)))],
758
788
  can(organization, permission) {
@@ -774,6 +804,11 @@ function definePolicy(roles) {
774
804
  };
775
805
  walk(role);
776
806
  return [...out];
807
+ },
808
+ // The types did the work; this only hands the question on, as a method of
809
+ // the asker so it keeps its `this`.
810
+ check(asker, ...args) {
811
+ return asker.check(...args);
777
812
  }
778
813
  };
779
814
  }