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.mjs CHANGED
@@ -229,6 +229,7 @@ function createAuthClient(options = {}) {
229
229
  return null;
230
230
  }
231
231
  }
232
+ const upgradeUrl = (provider, o = {}) => `${base}/me/upgrade/social/${encodeURIComponent(provider)}${o.returnTo ? `?return_to=${encodeURIComponent(o.returnTo)}` : ""}`;
232
233
  const linkUrl = (provider, o = {}) => `${base}/me/identities/link/${encodeURIComponent(provider)}${o.returnTo ? `?return_to=${encodeURIComponent(o.returnTo)}` : ""}`;
233
234
  const socialUrl = (provider, o = {}) => `${base}/sign-in/social/${encodeURIComponent(provider)}${o.returnTo ? `?return_to=${encodeURIComponent(o.returnTo)}` : ""}`;
234
235
  const ssoUrl = (target, o = {}) => {
@@ -266,6 +267,7 @@ function createAuthClient(options = {}) {
266
267
  }
267
268
  return {
268
269
  signIn: {
270
+ anonymously: (f = {}) => post("/sign-in/anonymous", {}, null, f.captchaToken),
269
271
  email: (f) => post("/sign-in/email", { email: f.email, password: f.password }, firstProblem(checkEmail(f.email), checkPassword(f.password)), f.captchaToken),
270
272
  mfa: (f) => post("/sign-in/mfa", { code: f.code }, checkCode(f.code)),
271
273
  mfaMethods: () => post("/sign-in/mfa/methods", {}, null),
@@ -363,6 +365,24 @@ function createAuthClient(options = {}) {
363
365
  resetPassword: (f) => post("/reset-password", { token: f.token, password: f.password }, checkNewPassword(f.password)),
364
366
  verifyEmail: (f) => post("/verify-email", { token: f.token }, null),
365
367
  signOut: () => post("/sign-out", {}, null),
368
+ organizations: {
369
+ async list(system) {
370
+ const body = await read(`/me/organizations${system ? `?system=${encodeURIComponent(system)}` : ""}`);
371
+ return body && Array.isArray(body.organizations) ? body.organizations : [];
372
+ },
373
+ async members(id) {
374
+ const body = await read(`/me/organizations/members?id=${encodeURIComponent(id)}`);
375
+ return body && Array.isArray(body.members) ? body.members : null;
376
+ },
377
+ async roles(id) {
378
+ const body = await read(`/me/organizations/roles?id=${encodeURIComponent(id)}`);
379
+ return body && Array.isArray(body.roles) ? body.roles : null;
380
+ },
381
+ 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)),
382
+ setRole: (id, userId, role) => post("/me/organizations/members/role", { organizationId: id, userId, role }, null),
383
+ remove: (id, userId) => post("/me/organizations/members/remove", { organizationId: id, userId }, null),
384
+ inviteAgain: (id, userId, f = {}) => post("/me/organizations/members/invite", { organizationId: id, userId, locale: f.locale ?? "" }, null)
385
+ },
366
386
  account: {
367
387
  async get() {
368
388
  const body = await read("/me");
@@ -401,6 +421,11 @@ function createAuthClient(options = {}) {
401
421
  return body && Array.isArray(body.sessions) ? body.sessions : [];
402
422
  },
403
423
  signOutEverywhere: () => post("/me/sessions/end", {}, null),
424
+ upgrade: (f) => post("/me/upgrade", { email: f.email, password: f.password, name: f.name ?? "" }, firstProblem(checkName(f.name), checkEmail(f.email), checkNewPassword(f.password))),
425
+ upgradeUrl,
426
+ upgradeWith(provider, o) {
427
+ window.location.assign(upgradeUrl(provider, o));
428
+ },
404
429
  async agents() {
405
430
  const body = await read("/me/agents");
406
431
  return body && Array.isArray(body.agents) ? body.agents : [];
@@ -575,7 +600,29 @@ var TEXTS = {
575
600
  unlink: "Unlink",
576
601
  linked: "The account was linked.",
577
602
  ssoOnly: "Your company signs you in to this account.",
603
+ members: "Members",
604
+ membersHidden: "Your role here does not let you see the members.",
605
+ organizationMissing: "You do not belong to this organization.",
606
+ memberYou: "you",
607
+ memberInvited: "invited",
608
+ memberManager: "manages members",
609
+ memberRole: "Role",
610
+ memberAdd: "Add member",
611
+ memberAdded: "{email} is a member now.",
612
+ memberRemove: "Remove",
613
+ memberRemoveConfirm: "Remove {who}?",
614
+ memberLeave: "Leave",
615
+ memberLeaveConfirm: "Leave {org}? You will need an invitation to come back.",
616
+ memberInviteAgain: "Send the invitation again",
617
+ memberInvitationSent: "The invitation is on its way.",
618
+ yes: "Yes",
619
+ cancel: "Cancel",
578
620
  errors: {
621
+ not_allowed: "Your role in this organization does not allow that.",
622
+ last_manager: "Somebody else must manage the members first: give that role to another member.",
623
+ already_member: "That person already belongs to the organization. Change their role instead.",
624
+ unknown_role: "Choose one of the roles offered.",
625
+ user_not_active: "That account is disabled.",
579
626
  required: "This is required.",
580
627
  invalid_email: "That does not look like an email address.",
581
628
  too_short: "Use at least 8 characters.",
@@ -699,7 +746,29 @@ var TEXTS = {
699
746
  unlink: "Desvincular",
700
747
  linked: "La cuenta qued\xF3 vinculada.",
701
748
  ssoOnly: "A esta cuenta entras con el inicio de sesi\xF3n de tu empresa.",
749
+ members: "Miembros",
750
+ membersHidden: "Tu rol aqu\xED no te deja ver los miembros.",
751
+ organizationMissing: "No perteneces a esta organizaci\xF3n.",
752
+ memberYou: "t\xFA",
753
+ memberInvited: "invitado",
754
+ memberManager: "administra los miembros",
755
+ memberRole: "Rol",
756
+ memberAdd: "Agregar miembro",
757
+ memberAdded: "{email} ya es miembro.",
758
+ memberRemove: "Quitar",
759
+ memberRemoveConfirm: "\xBFQuitar a {who}?",
760
+ memberLeave: "Salir",
761
+ memberLeaveConfirm: "\xBFSalir de {org}? Necesitar\xE1s una invitaci\xF3n para volver.",
762
+ memberInviteAgain: "Enviar la invitaci\xF3n de nuevo",
763
+ memberInvitationSent: "La invitaci\xF3n va en camino.",
764
+ yes: "S\xED",
765
+ cancel: "Cancelar",
702
766
  errors: {
767
+ not_allowed: "Tu rol en esta organizaci\xF3n no permite eso.",
768
+ last_manager: "Primero alguien m\xE1s debe administrar los miembros: dale ese rol a otro miembro.",
769
+ already_member: "Esa persona ya pertenece a la organizaci\xF3n. Cambia su rol.",
770
+ unknown_role: "Escoge uno de los roles ofrecidos.",
771
+ user_not_active: "Esa cuenta est\xE1 desactivada.",
703
772
  required: "Este dato es obligatorio.",
704
773
  invalid_email: "Eso no parece un correo.",
705
774
  too_short: "Usa al menos 8 caracteres.",
@@ -1103,7 +1172,7 @@ function SignUp(props) {
1103
1172
  e.preventDefault();
1104
1173
  f.setBusy(true);
1105
1174
  f.setError(null);
1106
- const r = await auth.signUp.email({ name, email, password, captchaToken: challenge.token });
1175
+ const r = auth.session?.user.isAnonymous === true ? await auth.account.upgrade({ name, email, password }) : await auth.signUp.email({ name, email, password, captchaToken: challenge.token });
1107
1176
  f.setBusy(false);
1108
1177
  challenge.renew();
1109
1178
  if (!r.ok) return f.setError(r.error);
@@ -1273,6 +1342,130 @@ function Account(props) {
1273
1342
  ] })
1274
1343
  ] });
1275
1344
  }
1345
+ function OrganizationMembers(props) {
1346
+ const auth = useAuth();
1347
+ const { root } = useForm(props);
1348
+ const { f, done, setDone, run } = useSection(props);
1349
+ const problem = f.error && f.error.field !== "email" ? f.error : null;
1350
+ const [seat, setSeat] = useState(void 0);
1351
+ const [members, setMembers] = useState(null);
1352
+ const [roles, setRoles] = useState([]);
1353
+ const [email, setEmail] = useState("");
1354
+ const [role, setRole] = useState("");
1355
+ const [asking, setAsking] = useState(null);
1356
+ const id = props.organizationId;
1357
+ const when = props.formatDate ?? ((iso) => new Date(iso).toLocaleDateString());
1358
+ const load = async () => {
1359
+ const [list, people, choices] = await Promise.all([auth.organizations.list(), auth.organizations.members(id), auth.organizations.roles(id)]);
1360
+ setSeat(list.find((o) => o.id === id) ?? null);
1361
+ setMembers(people);
1362
+ setRoles(choices ?? []);
1363
+ if (choices && choices.length > 0 && !choices.some((c) => c.role === role)) setRole(choices[0].role);
1364
+ };
1365
+ useEffect(() => {
1366
+ void load();
1367
+ }, [id]);
1368
+ if (seat === void 0) return /* @__PURE__ */ jsx("div", { className: f.cx("account"), ...root, "aria-busy": "true" });
1369
+ if (seat === null) return /* @__PURE__ */ jsx("div", { className: f.cx("account"), ...root, children: /* @__PURE__ */ jsx("p", { className: f.cx("notice"), children: f.t.organizationMissing }) });
1370
+ const manage = seat.can.manageMembers;
1371
+ const label = (r) => roles.find((c) => c.role === r)?.name || r;
1372
+ const add = async (e) => {
1373
+ e.preventDefault();
1374
+ const r = await run(() => auth.organizations.add(id, { email, role, locale: props.locale }));
1375
+ if (!r.ok) return;
1376
+ setEmail("");
1377
+ setDone(f.t.memberAdded.replace("{email}", r.member.email));
1378
+ await load();
1379
+ };
1380
+ const change = async (m, next) => {
1381
+ const r = await run(() => auth.organizations.setRole(id, m.userId, next));
1382
+ if (r.ok) await load();
1383
+ };
1384
+ const remove = async (m) => {
1385
+ setAsking(null);
1386
+ const r = await run(() => auth.organizations.remove(id, m.userId));
1387
+ if (!r.ok) return;
1388
+ if (m.you) setSeat(null);
1389
+ else await load();
1390
+ };
1391
+ const inviteAgain = async (m) => {
1392
+ const r = await run(() => auth.organizations.inviteAgain(id, m.userId, { locale: props.locale }));
1393
+ if (r.ok) setDone(f.t.memberInvitationSent);
1394
+ };
1395
+ return /* @__PURE__ */ jsxs("div", { className: f.cx("account"), ...root, children: [
1396
+ /* @__PURE__ */ jsxs("section", { className: f.cx("section"), children: [
1397
+ /* @__PURE__ */ jsxs("h2", { className: f.cx("heading"), children: [
1398
+ f.t.members,
1399
+ " \xB7 ",
1400
+ seat.name
1401
+ ] }),
1402
+ problem && /* @__PURE__ */ jsx("p", { role: "alert", className: f.cx("error"), children: f.say(problem) }),
1403
+ members === null ? /* @__PURE__ */ jsxs(Fragment, { children: [
1404
+ /* @__PURE__ */ jsx("p", { className: f.cx("notice"), children: f.t.membersHidden }),
1405
+ auth.session && (asking === auth.session.user.id ? /* @__PURE__ */ jsxs("span", { role: "group", "aria-label": f.t.memberLeave, children: [
1406
+ /* @__PURE__ */ jsx("span", { children: f.t.memberLeaveConfirm.replace("{org}", seat.name) }),
1407
+ " ",
1408
+ /* @__PURE__ */ jsx(
1409
+ f.Button,
1410
+ {
1411
+ type: "button",
1412
+ disabled: f.busy,
1413
+ className: f.cx("providerButton"),
1414
+ onClick: () => void remove({ userId: auth.session.user.id, you: true }),
1415
+ children: f.t.yes
1416
+ }
1417
+ ),
1418
+ /* @__PURE__ */ jsx(f.Button, { type: "button", disabled: f.busy, className: f.cx("providerButton"), onClick: () => setAsking(null), children: f.t.cancel })
1419
+ ] }) : /* @__PURE__ */ jsx(f.Button, { type: "button", disabled: f.busy, className: f.cx("providerButton"), onClick: () => setAsking(auth.session.user.id), children: f.t.memberLeave }))
1420
+ ] }) : /* @__PURE__ */ jsx("ul", { className: f.cx("sessions"), children: members.map((m) => {
1421
+ const who = m.name || m.email;
1422
+ return /* @__PURE__ */ jsxs("li", { className: f.cx("session"), children: [
1423
+ /* @__PURE__ */ jsxs("span", { children: [
1424
+ who,
1425
+ m.name ? ` \xB7 ${m.email}` : "",
1426
+ m.you ? ` (${f.t.memberYou})` : "",
1427
+ m.invited ? ` \xB7 ${f.t.memberInvited}` : "",
1428
+ m.manager ? ` \xB7 ${f.t.memberManager}` : "",
1429
+ " \xB7 ",
1430
+ when(m.since)
1431
+ ] }),
1432
+ " ",
1433
+ manage && roles.length > 0 ? /* @__PURE__ */ jsx(
1434
+ "select",
1435
+ {
1436
+ "aria-label": `${f.t.memberRole}: ${who}`,
1437
+ className: f.cx("input"),
1438
+ value: m.role,
1439
+ disabled: f.busy,
1440
+ onChange: (e) => void change(m, e.target.value),
1441
+ children: roles.map((c) => /* @__PURE__ */ jsx("option", { value: c.role, children: c.name || c.role }, c.role))
1442
+ }
1443
+ ) : /* @__PURE__ */ jsx("span", { children: label(m.role) }),
1444
+ " ",
1445
+ asking === m.userId ? /* @__PURE__ */ jsxs("span", { role: "group", "aria-label": m.you ? f.t.memberLeave : f.t.memberRemove, children: [
1446
+ /* @__PURE__ */ jsx("span", { children: m.you ? f.t.memberLeaveConfirm.replace("{org}", seat.name) : f.t.memberRemoveConfirm.replace("{who}", who) }),
1447
+ " ",
1448
+ /* @__PURE__ */ jsx(f.Button, { type: "button", disabled: f.busy, className: f.cx("providerButton"), onClick: () => void remove(m), children: f.t.yes }),
1449
+ /* @__PURE__ */ jsx(f.Button, { type: "button", disabled: f.busy, className: f.cx("providerButton"), onClick: () => setAsking(null), children: f.t.cancel })
1450
+ ] }) : /* @__PURE__ */ jsxs(Fragment, { children: [
1451
+ manage && m.invited && /* @__PURE__ */ jsx(f.Button, { type: "button", disabled: f.busy, className: f.cx("providerButton"), onClick: () => void inviteAgain(m), children: f.t.memberInviteAgain }),
1452
+ (manage || m.you) && /* @__PURE__ */ 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 })
1453
+ ] })
1454
+ ] }, m.userId);
1455
+ }) }),
1456
+ done && /* @__PURE__ */ jsx("p", { role: "status", className: f.cx("notice"), children: done })
1457
+ ] }),
1458
+ manage && roles.length > 0 && /* @__PURE__ */ jsxs("form", { className: f.cx("section"), onSubmit: add, noValidate: true, children: [
1459
+ /* @__PURE__ */ jsx("h2", { className: f.cx("heading"), children: f.t.memberAdd }),
1460
+ /* @__PURE__ */ jsx(Field, { f, name: "email", type: "email", label: f.t.email, value: email, autoComplete: "off", required: true, onChange: setEmail }),
1461
+ /* @__PURE__ */ jsxs("label", { className: f.cx("field"), children: [
1462
+ /* @__PURE__ */ jsx("span", { className: f.cx("label"), children: f.t.memberRole }),
1463
+ /* @__PURE__ */ jsx("select", { name: "role", className: f.cx("input"), value: role, onChange: (e) => setRole(e.target.value), children: roles.map((c) => /* @__PURE__ */ jsx("option", { value: c.role, children: c.name || c.role }, c.role)) })
1464
+ ] }),
1465
+ /* @__PURE__ */ jsx(f.Button, { type: "submit", disabled: f.busy, className: f.cx("button"), children: f.t.memberAdd })
1466
+ ] })
1467
+ ] });
1468
+ }
1276
1469
  function PasskeysPart({ props, account, accountUrl, when }) {
1277
1470
  const auth = useAuth();
1278
1471
  const { f, done, setDone, run, general } = useSection(props);
@@ -1694,6 +1887,7 @@ function useAuth() {
1694
1887
  ...client,
1695
1888
  signIn: {
1696
1889
  ...client.signIn,
1890
+ anonymously: (f) => then(client.signIn.anonymously(f)),
1697
1891
  email: (f) => then(client.signIn.email(f)),
1698
1892
  mfa: (f) => then(client.signIn.mfa(f)),
1699
1893
  magicLinkVerify: (f) => then(client.signIn.magicLinkVerify(f)),
@@ -1709,7 +1903,9 @@ function useAuth() {
1709
1903
  // What is on screen says the new name, and knows when the session ended.
1710
1904
  update: (f) => then(client.account.update(f)),
1711
1905
  changePassword: (f) => then(client.account.changePassword(f)),
1712
- signOutEverywhere: () => then(client.account.signOutEverywhere())
1906
+ signOutEverywhere: () => then(client.account.signOutEverywhere()),
1907
+ // The guest is now the account: what is on screen says so.
1908
+ upgrade: (f) => then(client.account.upgrade(f))
1713
1909
  },
1714
1910
  session,
1715
1911
  status,
@@ -1722,6 +1918,7 @@ export {
1722
1918
  CauthyProvider,
1723
1919
  ForgotPassword,
1724
1920
  GoogleOneTap,
1921
+ OrganizationMembers,
1725
1922
  ResetPassword,
1726
1923
  SignIn,
1727
1924
  SignUp,