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/client.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." };
|
|
@@ -446,11 +452,11 @@ function createAuthClient(options = {}) {
|
|
|
446
452
|
if (res.ok) {
|
|
447
453
|
const m = await res.json();
|
|
448
454
|
if (m.password) policy = passwordPolicyOf(m.password);
|
|
449
|
-
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 };
|
|
455
|
+
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 };
|
|
450
456
|
}
|
|
451
457
|
} catch {
|
|
452
458
|
}
|
|
453
|
-
return { providers: [], signUp: true, magicLink: false, passkey: false, passkeyHere: false, passkeyOnCauthy: false, sso: false };
|
|
459
|
+
return { providers: [], signUp: true, passwordSignIn: true, magicLink: false, passkey: false, passkeyHere: false, passkeyOnCauthy: false, sso: false };
|
|
454
460
|
}
|
|
455
461
|
async function ceremony(begin, finish, form, run, more = {}) {
|
|
456
462
|
const begun = await post(begin, form, null);
|
|
@@ -597,6 +603,20 @@ function createAuthClient(options = {}) {
|
|
|
597
603
|
forgotPassword: (f) => post("/forgot-password", { email: f.email }, checkEmail(f.email), f.captchaToken),
|
|
598
604
|
resetPassword: (f) => post("/reset-password", { token: f.token, password: f.password }, checkNewPassword(f.password, policy)),
|
|
599
605
|
verifyEmail: (f) => post("/verify-email", { token: f.token }, null),
|
|
606
|
+
async invitation(token) {
|
|
607
|
+
const bad = { ok: false, error: { code: "invalid_token", message: "This invitation is not valid, or it has expired." } };
|
|
608
|
+
if (typeof token !== "string" || token.trim() === "") return bad;
|
|
609
|
+
try {
|
|
610
|
+
const res = await doFetch(`${base}/invitation?token=${encodeURIComponent(token.trim())}`, { credentials: "same-origin", headers: { accept: "application/json" } });
|
|
611
|
+
const body = await res.json().catch(() => null);
|
|
612
|
+
if (res.ok && body?.invitation) return { ok: true, status: "ok", invitation: body.invitation };
|
|
613
|
+
const e = body?.error;
|
|
614
|
+
return { ok: false, error: e && typeof e.code === "string" ? { code: e.code, message: String(e.message ?? "") } : UNAVAILABLE };
|
|
615
|
+
} catch {
|
|
616
|
+
return { ok: false, error: UNAVAILABLE };
|
|
617
|
+
}
|
|
618
|
+
},
|
|
619
|
+
acceptInvitation: (token, password) => post("/invitation/accept", { token, password }, checkNewPassword(password, policy)),
|
|
600
620
|
signOut: () => post("/sign-out", {}, null),
|
|
601
621
|
organizations: {
|
|
602
622
|
async list(system) {
|
|
@@ -614,7 +634,23 @@ function createAuthClient(options = {}) {
|
|
|
614
634
|
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)),
|
|
615
635
|
setRole: (id, userId, role) => post("/me/organizations/members/role", { organizationId: id, userId, role }, null),
|
|
616
636
|
remove: (id, userId) => post("/me/organizations/members/remove", { organizationId: id, userId }, null),
|
|
617
|
-
inviteAgain: (id, userId, f = {}) => post("/me/organizations/members/invite", { organizationId: id, userId, locale: f.locale ?? "" }, null)
|
|
637
|
+
inviteAgain: (id, userId, f = {}) => post("/me/organizations/members/invite", { organizationId: id, userId, locale: f.locale ?? "" }, null),
|
|
638
|
+
rename: (id, name) => post("/me/organizations/rename", { organizationId: id, name }, checkOrganizationName(name)),
|
|
639
|
+
archive: (id) => post("/me/organizations/archive", { organizationId: id }, null),
|
|
640
|
+
delete: (id) => post("/me/organizations/delete", { organizationId: id }, null),
|
|
641
|
+
async check(q) {
|
|
642
|
+
const organizationId = typeof q.organization === "string" ? q.organization : q.organization?.id ?? "";
|
|
643
|
+
const r = await post("/me/organizations/check", {
|
|
644
|
+
organizationId,
|
|
645
|
+
resource: q.resource,
|
|
646
|
+
action: q.action,
|
|
647
|
+
...q.attributes !== void 0 ? { attributes: q.attributes } : {},
|
|
648
|
+
...q.resourceId !== void 0 ? { resourceId: q.resourceId } : {},
|
|
649
|
+
...q.ownerId !== void 0 ? { ownerId: q.ownerId } : {}
|
|
650
|
+
}, null);
|
|
651
|
+
if (!r.ok) return { allowed: false, reason: r.error.message, error: r.error };
|
|
652
|
+
return { allowed: r.allowed === true, reason: String(r.reason ?? ""), ...r.rule ? { rule: r.rule } : {} };
|
|
653
|
+
}
|
|
618
654
|
},
|
|
619
655
|
account: {
|
|
620
656
|
async get() {
|