cauthy-auth 0.28.1 → 0.31.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 +61 -3
- package/dist/{cauthy-CTVg4kvo.d.mts → cauthy-2jtP2LVQ.d.mts} +19 -1
- package/dist/{cauthy-BAwAJChs.d.ts → cauthy-CKfvvv_i.d.ts} +19 -1
- package/dist/cli.js +163 -59
- package/dist/client.d.mts +91 -10
- package/dist/client.d.ts +91 -10
- package/dist/client.js +39 -3
- package/dist/client.js.map +1 -1
- package/dist/client.mjs +39 -3
- 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 +387 -148
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +385 -148
- 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 +275 -23
- package/dist/react.d.ts +275 -23
- package/dist/react.js +312 -78
- package/dist/react.js.map +1 -1
- package/dist/react.mjs +311 -78
- package/dist/react.mjs.map +1 -1
- package/dist/styles.css +8 -0
- package/dist/svelte.d.mts +2 -2
- package/dist/svelte.d.ts +2 -2
- package/dist/svelte.js +53 -4
- package/dist/svelte.js.map +1 -1
- package/dist/svelte.mjs +53 -4
- package/dist/svelte.mjs.map +1 -1
- package/dist/{system-CVBW_AV8.d.mts → system-BrrJsrFW.d.mts} +321 -109
- package/dist/{system-Bn8uckvQ.d.ts → system-BvvoNs2y.d.ts} +321 -109
- package/dist/vue.d.mts +2 -2
- package/dist/vue.d.ts +2 -2
- package/dist/vue.js +53 -4
- package/dist/vue.js.map +1 -1
- package/dist/vue.mjs +53 -4
- package/dist/vue.mjs.map +1 -1
- package/package.json +1 -1
package/dist/styles.css
CHANGED
|
@@ -158,6 +158,14 @@
|
|
|
158
158
|
border: 1px solid var(--cauthy-input-border);
|
|
159
159
|
}
|
|
160
160
|
|
|
161
|
+
/* A provider's logo, before "Continue with …". */
|
|
162
|
+
:where([data-cauthy] .cauthy-providerIcon) {
|
|
163
|
+
flex: none;
|
|
164
|
+
width: 18px;
|
|
165
|
+
height: 18px;
|
|
166
|
+
object-fit: contain;
|
|
167
|
+
}
|
|
168
|
+
|
|
161
169
|
:where([data-cauthy] .cauthy-button:hover:not(:disabled)),
|
|
162
170
|
:where([data-cauthy] .cauthy-providerButton:hover:not(:disabled)) {
|
|
163
171
|
filter: brightness(0.94);
|
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 {
|
|
4
|
-
export { P as PermissionOf,
|
|
3
|
+
import { q as PublicSession } from './system-BrrJsrFW.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-BrrJsrFW.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 {
|
|
4
|
-
export { P as PermissionOf,
|
|
3
|
+
import { q as PublicSession } from './system-BvvoNs2y.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-BvvoNs2y.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." };
|
|
@@ -366,11 +372,11 @@ function createAuthClient(options = {}) {
|
|
|
366
372
|
if (res.ok) {
|
|
367
373
|
const m = await res.json();
|
|
368
374
|
if (m.password) policy = passwordPolicyOf(m.password);
|
|
369
|
-
return { providers: [], signUp: true, magicLink: false, passkey: false, ...m, ...policy ? { password: policy } : {}, passkeyHere: m.passkeyHere === true, passkeyOnCauthy: m.passkeyOnCauthy ?? m.passkey === true, sso: m.sso === true };
|
|
375
|
+
return { providers: [], signUp: true, magicLink: false, passkey: false, ...m, ...policy ? { password: policy } : {}, passwordSignIn: m.passwordSignIn !== false, passkeyHere: m.passkeyHere === true, passkeyOnCauthy: m.passkeyOnCauthy ?? m.passkey === true, sso: m.sso === true };
|
|
370
376
|
}
|
|
371
377
|
} catch {
|
|
372
378
|
}
|
|
373
|
-
return { providers: [], signUp: true, magicLink: false, passkey: false, passkeyHere: false, passkeyOnCauthy: false, sso: false };
|
|
379
|
+
return { providers: [], signUp: true, passwordSignIn: true, magicLink: false, passkey: false, passkeyHere: false, passkeyOnCauthy: false, sso: false };
|
|
374
380
|
}
|
|
375
381
|
async function ceremony(begin, finish, form, run, more = {}) {
|
|
376
382
|
const begun = await post(begin, form, null);
|
|
@@ -517,6 +523,20 @@ function createAuthClient(options = {}) {
|
|
|
517
523
|
forgotPassword: (f) => post("/forgot-password", { email: f.email }, checkEmail(f.email), f.captchaToken),
|
|
518
524
|
resetPassword: (f) => post("/reset-password", { token: f.token, password: f.password }, checkNewPassword(f.password, policy)),
|
|
519
525
|
verifyEmail: (f) => post("/verify-email", { token: f.token }, null),
|
|
526
|
+
async invitation(token) {
|
|
527
|
+
const bad = { ok: false, error: { code: "invalid_token", message: "This invitation is not valid, or it has expired." } };
|
|
528
|
+
if (typeof token !== "string" || token.trim() === "") return bad;
|
|
529
|
+
try {
|
|
530
|
+
const res = await doFetch(`${base}/invitation?token=${encodeURIComponent(token.trim())}`, { credentials: "same-origin", headers: { accept: "application/json" } });
|
|
531
|
+
const body = await res.json().catch(() => null);
|
|
532
|
+
if (res.ok && body?.invitation) return { ok: true, status: "ok", invitation: body.invitation };
|
|
533
|
+
const e = body?.error;
|
|
534
|
+
return { ok: false, error: e && typeof e.code === "string" ? { code: e.code, message: String(e.message ?? "") } : UNAVAILABLE };
|
|
535
|
+
} catch {
|
|
536
|
+
return { ok: false, error: UNAVAILABLE };
|
|
537
|
+
}
|
|
538
|
+
},
|
|
539
|
+
acceptInvitation: (token, password) => post("/invitation/accept", { token, password }, checkNewPassword(password, policy)),
|
|
520
540
|
signOut: () => post("/sign-out", {}, null),
|
|
521
541
|
organizations: {
|
|
522
542
|
async list(system) {
|
|
@@ -534,7 +554,23 @@ function createAuthClient(options = {}) {
|
|
|
534
554
|
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
555
|
setRole: (id, userId, role) => post("/me/organizations/members/role", { organizationId: id, userId, role }, null),
|
|
536
556
|
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)
|
|
557
|
+
inviteAgain: (id, userId, f = {}) => post("/me/organizations/members/invite", { organizationId: id, userId, locale: f.locale ?? "" }, null),
|
|
558
|
+
rename: (id, name) => post("/me/organizations/rename", { organizationId: id, name }, checkOrganizationName(name)),
|
|
559
|
+
archive: (id) => post("/me/organizations/archive", { organizationId: id }, null),
|
|
560
|
+
delete: (id) => post("/me/organizations/delete", { organizationId: id }, null),
|
|
561
|
+
async check(q) {
|
|
562
|
+
const organizationId = typeof q.organization === "string" ? q.organization : q.organization?.id ?? "";
|
|
563
|
+
const r = await post("/me/organizations/check", {
|
|
564
|
+
organizationId,
|
|
565
|
+
resource: q.resource,
|
|
566
|
+
action: q.action,
|
|
567
|
+
...q.attributes !== void 0 ? { attributes: q.attributes } : {},
|
|
568
|
+
...q.resourceId !== void 0 ? { resourceId: q.resourceId } : {},
|
|
569
|
+
...q.ownerId !== void 0 ? { ownerId: q.ownerId } : {}
|
|
570
|
+
}, null);
|
|
571
|
+
if (!r.ok) return { allowed: false, reason: r.error.message, error: r.error };
|
|
572
|
+
return { allowed: r.allowed === true, reason: String(r.reason ?? ""), ...r.rule ? { rule: r.rule } : {} };
|
|
573
|
+
}
|
|
538
574
|
},
|
|
539
575
|
account: {
|
|
540
576
|
async get() {
|
|
@@ -738,7 +774,9 @@ function can(organization, resource, action) {
|
|
|
738
774
|
if ((organization.denied ?? []).some((d) => matches(d, resource, action))) return false;
|
|
739
775
|
return organization.permissions.some((p) => matches(p, resource, action));
|
|
740
776
|
}
|
|
741
|
-
function definePolicy(
|
|
777
|
+
function definePolicy(given) {
|
|
778
|
+
const roles = Array.isArray(given) ? given : given.roles;
|
|
779
|
+
const resources = Array.isArray(given) ? [] : given.catalog ?? [];
|
|
742
780
|
const entry = (p) => `${p.resource}:${p.action}`;
|
|
743
781
|
const byName = new Map(roles.map((r) => [r.role, r]));
|
|
744
782
|
const split = (permission) => {
|
|
@@ -753,6 +791,12 @@ function definePolicy(roles) {
|
|
|
753
791
|
...r.inherits ? { inherits: [...r.inherits] } : {},
|
|
754
792
|
...r.permissions ? { permissions: r.permissions.map((p) => ({ ...p })) } : {}
|
|
755
793
|
})),
|
|
794
|
+
catalog: resources.map((c) => ({
|
|
795
|
+
resource: c.resource,
|
|
796
|
+
...c.description !== void 0 ? { description: c.description } : {},
|
|
797
|
+
actions: [...c.actions],
|
|
798
|
+
...c.attributes ? { attributes: { ...c.attributes } } : {}
|
|
799
|
+
})),
|
|
756
800
|
roleNames: roles.map((r) => r.role),
|
|
757
801
|
permissions: [...new Set(roles.flatMap((r) => (r.permissions ?? []).map(entry)))],
|
|
758
802
|
can(organization, permission) {
|
|
@@ -774,6 +818,11 @@ function definePolicy(roles) {
|
|
|
774
818
|
};
|
|
775
819
|
walk(role);
|
|
776
820
|
return [...out];
|
|
821
|
+
},
|
|
822
|
+
// The types did the work; this only hands the question on, as a method of
|
|
823
|
+
// the asker so it keeps its `this`.
|
|
824
|
+
check(asker, ...args) {
|
|
825
|
+
return asker.check(...args);
|
|
777
826
|
}
|
|
778
827
|
};
|
|
779
828
|
}
|