cauthy-auth 0.20.0 → 0.22.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 (43) hide show
  1. package/dist/{cauthy-Bn3iv50y.d.ts → cauthy-DGAy45G2.d.ts} +1 -1
  2. package/dist/{cauthy-C29HCvag.d.mts → cauthy-XkIbG5gE.d.mts} +1 -1
  3. package/dist/client.d.mts +111 -2
  4. package/dist/client.d.ts +111 -2
  5. package/dist/client.js +25 -0
  6. package/dist/client.js.map +1 -1
  7. package/dist/client.mjs +25 -0
  8. package/dist/client.mjs.map +1 -1
  9. package/dist/express.d.mts +2 -2
  10. package/dist/express.d.ts +2 -2
  11. package/dist/fastify.d.mts +2 -2
  12. package/dist/fastify.d.ts +2 -2
  13. package/dist/hono.d.mts +2 -2
  14. package/dist/hono.d.ts +2 -2
  15. package/dist/index.d.mts +2 -2
  16. package/dist/index.d.ts +2 -2
  17. package/dist/index.js +133 -4
  18. package/dist/index.js.map +1 -1
  19. package/dist/index.mjs +133 -4
  20. package/dist/index.mjs.map +1 -1
  21. package/dist/next.d.mts +2 -2
  22. package/dist/next.d.ts +2 -2
  23. package/dist/react.d.mts +145 -1
  24. package/dist/react.d.ts +145 -1
  25. package/dist/react.js +200 -2
  26. package/dist/react.js.map +1 -1
  27. package/dist/react.mjs +199 -2
  28. package/dist/react.mjs.map +1 -1
  29. package/dist/svelte.d.mts +2 -2
  30. package/dist/svelte.d.ts +2 -2
  31. package/dist/svelte.js +25 -0
  32. package/dist/svelte.js.map +1 -1
  33. package/dist/svelte.mjs +25 -0
  34. package/dist/svelte.mjs.map +1 -1
  35. package/dist/{system-ZD_Wa8Bm.d.mts → system-BxMsSIu1.d.mts} +2 -0
  36. package/dist/{system-DhRr_WxR.d.ts → system-DTIeDXDP.d.ts} +2 -0
  37. package/dist/vue.d.mts +2 -2
  38. package/dist/vue.d.ts +2 -2
  39. package/dist/vue.js +25 -0
  40. package/dist/vue.js.map +1 -1
  41. package/dist/vue.mjs +25 -0
  42. package/dist/vue.mjs.map +1 -1
  43. package/package.json +1 -1
package/dist/react.js CHANGED
@@ -25,6 +25,7 @@ __export(react_exports, {
25
25
  CauthyProvider: () => CauthyProvider,
26
26
  ForgotPassword: () => ForgotPassword,
27
27
  GoogleOneTap: () => GoogleOneTap,
28
+ OrganizationMembers: () => OrganizationMembers,
28
29
  ResetPassword: () => ResetPassword,
29
30
  SignIn: () => SignIn,
30
31
  SignUp: () => SignUp,
@@ -266,6 +267,7 @@ function createAuthClient(options = {}) {
266
267
  return null;
267
268
  }
268
269
  }
270
+ const upgradeUrl = (provider, o = {}) => `${base}/me/upgrade/social/${encodeURIComponent(provider)}${o.returnTo ? `?return_to=${encodeURIComponent(o.returnTo)}` : ""}`;
269
271
  const linkUrl = (provider, o = {}) => `${base}/me/identities/link/${encodeURIComponent(provider)}${o.returnTo ? `?return_to=${encodeURIComponent(o.returnTo)}` : ""}`;
270
272
  const socialUrl = (provider, o = {}) => `${base}/sign-in/social/${encodeURIComponent(provider)}${o.returnTo ? `?return_to=${encodeURIComponent(o.returnTo)}` : ""}`;
271
273
  const ssoUrl = (target, o = {}) => {
@@ -303,6 +305,7 @@ function createAuthClient(options = {}) {
303
305
  }
304
306
  return {
305
307
  signIn: {
308
+ anonymously: (f = {}) => post("/sign-in/anonymous", {}, null, f.captchaToken),
306
309
  email: (f) => post("/sign-in/email", { email: f.email, password: f.password }, firstProblem(checkEmail(f.email), checkPassword(f.password)), f.captchaToken),
307
310
  mfa: (f) => post("/sign-in/mfa", { code: f.code }, checkCode(f.code)),
308
311
  mfaMethods: () => post("/sign-in/mfa/methods", {}, null),
@@ -400,6 +403,24 @@ function createAuthClient(options = {}) {
400
403
  resetPassword: (f) => post("/reset-password", { token: f.token, password: f.password }, checkNewPassword(f.password)),
401
404
  verifyEmail: (f) => post("/verify-email", { token: f.token }, null),
402
405
  signOut: () => post("/sign-out", {}, null),
406
+ organizations: {
407
+ async list(system) {
408
+ const body = await read(`/me/organizations${system ? `?system=${encodeURIComponent(system)}` : ""}`);
409
+ return body && Array.isArray(body.organizations) ? body.organizations : [];
410
+ },
411
+ async members(id) {
412
+ const body = await read(`/me/organizations/members?id=${encodeURIComponent(id)}`);
413
+ return body && Array.isArray(body.members) ? body.members : null;
414
+ },
415
+ async roles(id) {
416
+ const body = await read(`/me/organizations/roles?id=${encodeURIComponent(id)}`);
417
+ return body && Array.isArray(body.roles) ? body.roles : null;
418
+ },
419
+ 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)),
420
+ setRole: (id, userId, role) => post("/me/organizations/members/role", { organizationId: id, userId, role }, null),
421
+ remove: (id, userId) => post("/me/organizations/members/remove", { organizationId: id, userId }, null),
422
+ inviteAgain: (id, userId, f = {}) => post("/me/organizations/members/invite", { organizationId: id, userId, locale: f.locale ?? "" }, null)
423
+ },
403
424
  account: {
404
425
  async get() {
405
426
  const body = await read("/me");
@@ -438,6 +459,11 @@ function createAuthClient(options = {}) {
438
459
  return body && Array.isArray(body.sessions) ? body.sessions : [];
439
460
  },
440
461
  signOutEverywhere: () => post("/me/sessions/end", {}, null),
462
+ upgrade: (f) => post("/me/upgrade", { email: f.email, password: f.password, name: f.name ?? "" }, firstProblem(checkName(f.name), checkEmail(f.email), checkNewPassword(f.password))),
463
+ upgradeUrl,
464
+ upgradeWith(provider, o) {
465
+ window.location.assign(upgradeUrl(provider, o));
466
+ },
441
467
  async agents() {
442
468
  const body = await read("/me/agents");
443
469
  return body && Array.isArray(body.agents) ? body.agents : [];
@@ -612,7 +638,29 @@ var TEXTS = {
612
638
  unlink: "Unlink",
613
639
  linked: "The account was linked.",
614
640
  ssoOnly: "Your company signs you in to this account.",
641
+ members: "Members",
642
+ membersHidden: "Your role here does not let you see the members.",
643
+ organizationMissing: "You do not belong to this organization.",
644
+ memberYou: "you",
645
+ memberInvited: "invited",
646
+ memberManager: "manages members",
647
+ memberRole: "Role",
648
+ memberAdd: "Add member",
649
+ memberAdded: "{email} is a member now.",
650
+ memberRemove: "Remove",
651
+ memberRemoveConfirm: "Remove {who}?",
652
+ memberLeave: "Leave",
653
+ memberLeaveConfirm: "Leave {org}? You will need an invitation to come back.",
654
+ memberInviteAgain: "Send the invitation again",
655
+ memberInvitationSent: "The invitation is on its way.",
656
+ yes: "Yes",
657
+ cancel: "Cancel",
615
658
  errors: {
659
+ not_allowed: "Your role in this organization does not allow that.",
660
+ last_manager: "Somebody else must manage the members first: give that role to another member.",
661
+ already_member: "That person already belongs to the organization. Change their role instead.",
662
+ unknown_role: "Choose one of the roles offered.",
663
+ user_not_active: "That account is disabled.",
616
664
  required: "This is required.",
617
665
  invalid_email: "That does not look like an email address.",
618
666
  too_short: "Use at least 8 characters.",
@@ -736,7 +784,29 @@ var TEXTS = {
736
784
  unlink: "Desvincular",
737
785
  linked: "La cuenta qued\xF3 vinculada.",
738
786
  ssoOnly: "A esta cuenta entras con el inicio de sesi\xF3n de tu empresa.",
787
+ members: "Miembros",
788
+ membersHidden: "Tu rol aqu\xED no te deja ver los miembros.",
789
+ organizationMissing: "No perteneces a esta organizaci\xF3n.",
790
+ memberYou: "t\xFA",
791
+ memberInvited: "invitado",
792
+ memberManager: "administra los miembros",
793
+ memberRole: "Rol",
794
+ memberAdd: "Agregar miembro",
795
+ memberAdded: "{email} ya es miembro.",
796
+ memberRemove: "Quitar",
797
+ memberRemoveConfirm: "\xBFQuitar a {who}?",
798
+ memberLeave: "Salir",
799
+ memberLeaveConfirm: "\xBFSalir de {org}? Necesitar\xE1s una invitaci\xF3n para volver.",
800
+ memberInviteAgain: "Enviar la invitaci\xF3n de nuevo",
801
+ memberInvitationSent: "La invitaci\xF3n va en camino.",
802
+ yes: "S\xED",
803
+ cancel: "Cancelar",
739
804
  errors: {
805
+ not_allowed: "Tu rol en esta organizaci\xF3n no permite eso.",
806
+ last_manager: "Primero alguien m\xE1s debe administrar los miembros: dale ese rol a otro miembro.",
807
+ already_member: "Esa persona ya pertenece a la organizaci\xF3n. Cambia su rol.",
808
+ unknown_role: "Escoge uno de los roles ofrecidos.",
809
+ user_not_active: "Esa cuenta est\xE1 desactivada.",
740
810
  required: "Este dato es obligatorio.",
741
811
  invalid_email: "Eso no parece un correo.",
742
812
  too_short: "Usa al menos 8 caracteres.",
@@ -1140,7 +1210,7 @@ function SignUp(props) {
1140
1210
  e.preventDefault();
1141
1211
  f.setBusy(true);
1142
1212
  f.setError(null);
1143
- const r = await auth.signUp.email({ name, email, password, captchaToken: challenge.token });
1213
+ const r = auth.session?.user.isAnonymous === true ? await auth.account.upgrade({ name, email, password }) : await auth.signUp.email({ name, email, password, captchaToken: challenge.token });
1144
1214
  f.setBusy(false);
1145
1215
  challenge.renew();
1146
1216
  if (!r.ok) return f.setError(r.error);
@@ -1310,6 +1380,130 @@ function Account(props) {
1310
1380
  ] })
1311
1381
  ] });
1312
1382
  }
1383
+ function OrganizationMembers(props) {
1384
+ const auth = useAuth();
1385
+ const { root } = useForm(props);
1386
+ const { f, done, setDone, run } = useSection(props);
1387
+ const problem = f.error && f.error.field !== "email" ? f.error : null;
1388
+ const [seat, setSeat] = (0, import_react.useState)(void 0);
1389
+ const [members, setMembers] = (0, import_react.useState)(null);
1390
+ const [roles, setRoles] = (0, import_react.useState)([]);
1391
+ const [email, setEmail] = (0, import_react.useState)("");
1392
+ const [role, setRole] = (0, import_react.useState)("");
1393
+ const [asking, setAsking] = (0, import_react.useState)(null);
1394
+ const id = props.organizationId;
1395
+ const when = props.formatDate ?? ((iso) => new Date(iso).toLocaleDateString());
1396
+ const load = async () => {
1397
+ const [list, people, choices] = await Promise.all([auth.organizations.list(), auth.organizations.members(id), auth.organizations.roles(id)]);
1398
+ setSeat(list.find((o) => o.id === id) ?? null);
1399
+ setMembers(people);
1400
+ setRoles(choices ?? []);
1401
+ if (choices && choices.length > 0 && !choices.some((c) => c.role === role)) setRole(choices[0].role);
1402
+ };
1403
+ (0, import_react.useEffect)(() => {
1404
+ void load();
1405
+ }, [id]);
1406
+ if (seat === void 0) return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: f.cx("account"), ...root, "aria-busy": "true" });
1407
+ if (seat === null) return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: f.cx("account"), ...root, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { className: f.cx("notice"), children: f.t.organizationMissing }) });
1408
+ const manage = seat.can.manageMembers;
1409
+ const label = (r) => roles.find((c) => c.role === r)?.name || r;
1410
+ const add = async (e) => {
1411
+ e.preventDefault();
1412
+ const r = await run(() => auth.organizations.add(id, { email, role, locale: props.locale }));
1413
+ if (!r.ok) return;
1414
+ setEmail("");
1415
+ setDone(f.t.memberAdded.replace("{email}", r.member.email));
1416
+ await load();
1417
+ };
1418
+ const change = async (m, next) => {
1419
+ const r = await run(() => auth.organizations.setRole(id, m.userId, next));
1420
+ if (r.ok) await load();
1421
+ };
1422
+ const remove = async (m) => {
1423
+ setAsking(null);
1424
+ const r = await run(() => auth.organizations.remove(id, m.userId));
1425
+ if (!r.ok) return;
1426
+ if (m.you) setSeat(null);
1427
+ else await load();
1428
+ };
1429
+ const inviteAgain = async (m) => {
1430
+ const r = await run(() => auth.organizations.inviteAgain(id, m.userId, { locale: props.locale }));
1431
+ if (r.ok) setDone(f.t.memberInvitationSent);
1432
+ };
1433
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: f.cx("account"), ...root, children: [
1434
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("section", { className: f.cx("section"), children: [
1435
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("h2", { className: f.cx("heading"), children: [
1436
+ f.t.members,
1437
+ " \xB7 ",
1438
+ seat.name
1439
+ ] }),
1440
+ problem && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { role: "alert", className: f.cx("error"), children: f.say(problem) }),
1441
+ members === null ? /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
1442
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { className: f.cx("notice"), children: f.t.membersHidden }),
1443
+ auth.session && (asking === auth.session.user.id ? /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("span", { role: "group", "aria-label": f.t.memberLeave, children: [
1444
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { children: f.t.memberLeaveConfirm.replace("{org}", seat.name) }),
1445
+ " ",
1446
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
1447
+ f.Button,
1448
+ {
1449
+ type: "button",
1450
+ disabled: f.busy,
1451
+ className: f.cx("providerButton"),
1452
+ onClick: () => void remove({ userId: auth.session.user.id, you: true }),
1453
+ children: f.t.yes
1454
+ }
1455
+ ),
1456
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(f.Button, { type: "button", disabled: f.busy, className: f.cx("providerButton"), onClick: () => setAsking(null), children: f.t.cancel })
1457
+ ] }) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)(f.Button, { type: "button", disabled: f.busy, className: f.cx("providerButton"), onClick: () => setAsking(auth.session.user.id), children: f.t.memberLeave }))
1458
+ ] }) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)("ul", { className: f.cx("sessions"), children: members.map((m) => {
1459
+ const who = m.name || m.email;
1460
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("li", { className: f.cx("session"), children: [
1461
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("span", { children: [
1462
+ who,
1463
+ m.name ? ` \xB7 ${m.email}` : "",
1464
+ m.you ? ` (${f.t.memberYou})` : "",
1465
+ m.invited ? ` \xB7 ${f.t.memberInvited}` : "",
1466
+ m.manager ? ` \xB7 ${f.t.memberManager}` : "",
1467
+ " \xB7 ",
1468
+ when(m.since)
1469
+ ] }),
1470
+ " ",
1471
+ manage && roles.length > 0 ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
1472
+ "select",
1473
+ {
1474
+ "aria-label": `${f.t.memberRole}: ${who}`,
1475
+ className: f.cx("input"),
1476
+ value: m.role,
1477
+ disabled: f.busy,
1478
+ onChange: (e) => void change(m, e.target.value),
1479
+ children: roles.map((c) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)("option", { value: c.role, children: c.name || c.role }, c.role))
1480
+ }
1481
+ ) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { children: label(m.role) }),
1482
+ " ",
1483
+ asking === m.userId ? /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("span", { role: "group", "aria-label": m.you ? f.t.memberLeave : f.t.memberRemove, children: [
1484
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { children: m.you ? f.t.memberLeaveConfirm.replace("{org}", seat.name) : f.t.memberRemoveConfirm.replace("{who}", who) }),
1485
+ " ",
1486
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(f.Button, { type: "button", disabled: f.busy, className: f.cx("providerButton"), onClick: () => void remove(m), children: f.t.yes }),
1487
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(f.Button, { type: "button", disabled: f.busy, className: f.cx("providerButton"), onClick: () => setAsking(null), children: f.t.cancel })
1488
+ ] }) : /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
1489
+ manage && m.invited && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(f.Button, { type: "button", disabled: f.busy, className: f.cx("providerButton"), onClick: () => void inviteAgain(m), children: f.t.memberInviteAgain }),
1490
+ (manage || m.you) && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(f.Button, { type: "button", disabled: f.busy, className: f.cx("providerButton"), onClick: () => setAsking(m.userId), children: m.you ? f.t.memberLeave : f.t.memberRemove })
1491
+ ] })
1492
+ ] }, m.userId);
1493
+ }) }),
1494
+ done && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { role: "status", className: f.cx("notice"), children: done })
1495
+ ] }),
1496
+ manage && roles.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("form", { className: f.cx("section"), onSubmit: add, noValidate: true, children: [
1497
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("h2", { className: f.cx("heading"), children: f.t.memberAdd }),
1498
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Field, { f, name: "email", type: "email", label: f.t.email, value: email, autoComplete: "off", required: true, onChange: setEmail }),
1499
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("label", { className: f.cx("field"), children: [
1500
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: f.cx("label"), children: f.t.memberRole }),
1501
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("select", { name: "role", className: f.cx("input"), value: role, onChange: (e) => setRole(e.target.value), children: roles.map((c) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)("option", { value: c.role, children: c.name || c.role }, c.role)) })
1502
+ ] }),
1503
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(f.Button, { type: "submit", disabled: f.busy, className: f.cx("button"), children: f.t.memberAdd })
1504
+ ] })
1505
+ ] });
1506
+ }
1313
1507
  function PasskeysPart({ props, account, accountUrl, when }) {
1314
1508
  const auth = useAuth();
1315
1509
  const { f, done, setDone, run, general } = useSection(props);
@@ -1731,6 +1925,7 @@ function useAuth() {
1731
1925
  ...client,
1732
1926
  signIn: {
1733
1927
  ...client.signIn,
1928
+ anonymously: (f) => then(client.signIn.anonymously(f)),
1734
1929
  email: (f) => then(client.signIn.email(f)),
1735
1930
  mfa: (f) => then(client.signIn.mfa(f)),
1736
1931
  magicLinkVerify: (f) => then(client.signIn.magicLinkVerify(f)),
@@ -1746,7 +1941,9 @@ function useAuth() {
1746
1941
  // What is on screen says the new name, and knows when the session ended.
1747
1942
  update: (f) => then(client.account.update(f)),
1748
1943
  changePassword: (f) => then(client.account.changePassword(f)),
1749
- signOutEverywhere: () => then(client.account.signOutEverywhere())
1944
+ signOutEverywhere: () => then(client.account.signOutEverywhere()),
1945
+ // The guest is now the account: what is on screen says so.
1946
+ upgrade: (f) => then(client.account.upgrade(f))
1750
1947
  },
1751
1948
  session,
1752
1949
  status,
@@ -1760,6 +1957,7 @@ function useAuth() {
1760
1957
  CauthyProvider,
1761
1958
  ForgotPassword,
1762
1959
  GoogleOneTap,
1960
+ OrganizationMembers,
1763
1961
  ResetPassword,
1764
1962
  SignIn,
1765
1963
  SignUp,