cauthy-auth 0.26.0 → 0.27.1

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/dist/index.mjs CHANGED
@@ -495,7 +495,9 @@ function createSystem(given = {}) {
495
495
  async function fail(res, what) {
496
496
  const body = await res.json().catch(() => null);
497
497
  const first = body?.errors?.[0];
498
- throw new CauthyApiError(res.status, first?.code ?? "error", `Cauthy refused ${what} (${res.status}): ${first?.message ?? res.statusText}`);
498
+ const code = typeof body?.error === "string" ? body.error : first?.code;
499
+ const message = typeof body?.error === "string" ? body.error_description : first?.message;
500
+ throw new CauthyApiError(res.status, code ?? "error", `Cauthy refused ${what} (${res.status}): ${message ?? res.statusText}`);
499
501
  }
500
502
  let held;
501
503
  let asking;
@@ -605,8 +607,8 @@ function createSystem(given = {}) {
605
607
  }
606
608
 
607
609
  // src/validate.ts
608
- var MIN_PASSWORD = 8;
609
- var MAX_PASSWORD = 256;
610
+ var MIN_PASSWORD = 12;
611
+ var MAX_PASSWORD = 128;
610
612
  var MAX_NAME = 120;
611
613
  var EMAIL = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
612
614
  function checkEmail(value) {
@@ -1201,6 +1203,8 @@ function createCauthy(given = {}) {
1201
1203
  "/sign-in/mfa/push/finish",
1202
1204
  "/me/sessions",
1203
1205
  "/me/sessions/end",
1206
+ "/me/legal",
1207
+ "/me/legal/accept",
1204
1208
  "/me/email",
1205
1209
  "/me/identities",
1206
1210
  "/me/identities/unlink",
@@ -1259,6 +1263,8 @@ function createCauthy(given = {}) {
1259
1263
  passkeyOnCauthy: place.error ? true : place.data?.on_cauthy === true,
1260
1264
  // A company's sign-in, found by the person's work address.
1261
1265
  sso: Array.isArray(sso.data) && sso.data.some((c) => c?.discoverable === true),
1266
+ // The terms a sign-up accepts and the consents it answers, when the workspace asks any.
1267
+ ...settings.data?.legal ? { legal: legalOf(settings.data.legal) } : {},
1262
1268
  ...settings.data?.captcha_enabled === true && settings.data?.captcha_site_key ? { captchaSiteKey: String(settings.data.captcha_site_key) } : {}
1263
1269
  });
1264
1270
  }
@@ -1419,11 +1425,15 @@ function createCauthy(given = {}) {
1419
1425
  if (res.error) return problem(res.status, res.error.code, res.error.message, void 0, mine.headers);
1420
1426
  return json(factorsOf(res.data), 200, mine.headers);
1421
1427
  }
1422
- if ((route === "/me" || route === "/me/sessions") && !post) {
1428
+ if ((route === "/me" || route === "/me/sessions" || route === "/me/legal") && !post) {
1423
1429
  const mine = await signedInAs(request);
1424
1430
  if ("response" in mine) return mine.response;
1425
- const res = await ask(request, "GET", route === "/me" ? "/v1/auth/me" : "/v1/auth/me/sessions", void 0, void 0, mine.token);
1431
+ const res = await ask(request, "GET", route === "/me" ? "/v1/auth/me" : route === "/me/legal" ? "/v1/auth/me/legal" : "/v1/auth/me/sessions", void 0, void 0, mine.token);
1426
1432
  if (res.error) return problem(res.status, res.error.code, res.error.message, void 0, mine.headers);
1433
+ if (route === "/me/legal") {
1434
+ const list = Array.isArray(res.data?.pending) ? res.data.pending : [];
1435
+ return json({ pending: list.map((d) => ({ kind: String(d.kind ?? ""), version: String(d.version ?? ""), url: String(d.url ?? "") })) }, 200, mine.headers);
1436
+ }
1427
1437
  if (route === "/me/sessions") {
1428
1438
  const list = Array.isArray(res.data) ? res.data : [];
1429
1439
  return json({ sessions: list.map((x) => ({ device: String(x.device ?? ""), ip: String(x.ip ?? ""), createdAt: String(x.created_at ?? ""), expiresAt: String(x.expires_at ?? "") })) }, 200, mine.headers);
@@ -1549,7 +1559,8 @@ function createCauthy(given = {}) {
1549
1559
  if (bad) return invalid(bad);
1550
1560
  const email = String(b.email).trim();
1551
1561
  const organization = typeof b.organization === "string" && b.organization.trim() !== "" ? { organization: { name: b.organization.trim() } } : {};
1552
- const made = await ask(request, "POST", "/v1/auth/register", { email, password: b.password, display_name: typeof b.name === "string" ? b.name.trim() : "", ...organization }, pages.verifyEmail);
1562
+ const legal = { ...b.acceptLegal === true ? { accept_legal: true } : {}, ...b.consents && typeof b.consents === "object" ? { consents: b.consents } : {} };
1563
+ const made = await ask(request, "POST", "/v1/auth/register", { email, password: b.password, display_name: typeof b.name === "string" ? b.name.trim() : "", ...organization, ...legal }, pages.verifyEmail);
1553
1564
  if (made.error) return problem(made.status, made.error.code, made.error.message);
1554
1565
  if (made.data?.verification_required === true) return json({ status: "verification_required", email });
1555
1566
  const res = await ask(request, "POST", "/v1/auth/login", { email, password: b.password });
@@ -1580,6 +1591,12 @@ function createCauthy(given = {}) {
1580
1591
  }
1581
1592
  return json({ status: "saved", account: accountOf(res.data) }, 200, h);
1582
1593
  }
1594
+ if (route === "/me/legal/accept") {
1595
+ const kinds = Array.isArray(b.kinds) ? b.kinds.filter((k) => typeof k === "string") : [];
1596
+ const res = await as("/v1/auth/me/legal/accept", { kinds });
1597
+ if (res.error) return refused(res);
1598
+ return json({ status: "accepted" }, 200, mine.headers);
1599
+ }
1583
1600
  if (route === "/me/password") {
1584
1601
  const bad = checkNewPassword(b.newPassword);
1585
1602
  if (bad) return problem(400, bad.code, bad.message, "newPassword");
@@ -1879,6 +1896,14 @@ function createCauthy(given = {}) {
1879
1896
  options: { issuer, clientId, basePath, afterSignIn, afterSignOut, cookieName }
1880
1897
  };
1881
1898
  }
1899
+ function legalOf(raw) {
1900
+ const documents = Array.isArray(raw?.documents) ? raw.documents : [];
1901
+ const purposes = Array.isArray(raw?.consent_purposes) ? raw.consent_purposes : [];
1902
+ return {
1903
+ documents: documents.map((d) => ({ kind: String(d.kind ?? ""), version: String(d.version ?? ""), url: String(d.url ?? "") })),
1904
+ consentPurposes: purposes.map((p) => ({ key: String(p.key ?? ""), label: String(p.label ?? ""), required: p.required === true }))
1905
+ };
1906
+ }
1882
1907
 
1883
1908
  // src/permissions.ts
1884
1909
  function matches(entry, resource, action) {