cauthy-auth 0.12.0 → 0.14.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/dist/svelte.mjs CHANGED
@@ -174,13 +174,13 @@ function createAuthClient(options = {}) {
174
174
  const said = typeof options.locale === "function" ? options.locale() : options.locale;
175
175
  return (said ?? (typeof document === "undefined" ? "" : document.documentElement?.lang) ?? "").trim();
176
176
  };
177
- async function post(path, form, bad) {
177
+ async function post(path, form, bad, captchaToken) {
178
178
  if (bad) return { ok: false, error: { code: bad.code, message: bad.message, field: bad.field } };
179
179
  try {
180
180
  const res = await doFetch(`${base}${path}`, {
181
181
  method: "POST",
182
182
  credentials: "same-origin",
183
- headers: { "content-type": "application/json", accept: "application/json", ...locale() ? { "x-cauthy-locale": locale() } : {} },
183
+ headers: { "content-type": "application/json", accept: "application/json", ...locale() ? { "x-cauthy-locale": locale() } : {}, ...captchaToken ? { "x-cauthy-captcha": captchaToken } : {} },
184
184
  body: JSON.stringify(form)
185
185
  });
186
186
  const body = await res.json().catch(() => null);
@@ -232,9 +232,11 @@ function createAuthClient(options = {}) {
232
232
  }
233
233
  return {
234
234
  signIn: {
235
- email: (f) => post("/sign-in/email", { email: f.email, password: f.password }, firstProblem(checkEmail(f.email), checkPassword(f.password))),
235
+ email: (f) => post("/sign-in/email", { email: f.email, password: f.password }, firstProblem(checkEmail(f.email), checkPassword(f.password)), f.captchaToken),
236
236
  mfa: (f) => post("/sign-in/mfa", { code: f.code }, checkCode(f.code)),
237
- magicLink: (f) => post("/sign-in/magic-link", { email: f.email }, checkEmail(f.email)),
237
+ mfaMethods: () => post("/sign-in/mfa/methods", {}, null),
238
+ mfaSendCode: () => post("/sign-in/mfa/send", {}, null),
239
+ magicLink: (f) => post("/sign-in/magic-link", { email: f.email }, checkEmail(f.email), f.captchaToken),
238
240
  magicLinkVerify: (f) => post("/sign-in/magic-link/verify", { token: f.token }, null),
239
241
  emailCode: (f) => post("/sign-in/email-code", { code: f.code }, checkCode(f.code)),
240
242
  passkeyUrl,
@@ -315,9 +317,9 @@ function createAuthClient(options = {}) {
315
317
  }
316
318
  },
317
319
  signUp: {
318
- email: (f) => post("/sign-up/email", { email: f.email, password: f.password, name: f.name }, firstProblem(checkName(f.name), checkEmail(f.email), checkNewPassword(f.password)))
320
+ email: (f) => post("/sign-up/email", { email: f.email, password: f.password, name: f.name }, firstProblem(checkName(f.name), checkEmail(f.email), checkNewPassword(f.password)), f.captchaToken)
319
321
  },
320
- forgotPassword: (f) => post("/forgot-password", { email: f.email }, checkEmail(f.email)),
322
+ forgotPassword: (f) => post("/forgot-password", { email: f.email }, checkEmail(f.email), f.captchaToken),
321
323
  resetPassword: (f) => post("/reset-password", { token: f.token, password: f.password }, checkNewPassword(f.password)),
322
324
  verifyEmail: (f) => post("/verify-email", { token: f.token }, null),
323
325
  signOut: () => post("/sign-out", {}, null),
@@ -335,7 +337,14 @@ function createAuthClient(options = {}) {
335
337
  setup: (f) => post("/me/mfa/setup", { password: f.password }, null),
336
338
  verify: (f) => post("/me/mfa/verify", { code: f.code }, checkCode(f.code)),
337
339
  disable: (f) => post("/me/mfa/disable", { password: f.password }, null),
338
- recoveryCodes: (f) => post("/me/mfa/recovery-codes", { password: f.password }, null)
340
+ recoveryCodes: (f) => post("/me/mfa/recovery-codes", { password: f.password }, null),
341
+ async factors() {
342
+ const body = await read("/me/mfa/factors");
343
+ return body && typeof body.totp === "boolean" ? body : null;
344
+ },
345
+ addPhone: (f) => post("/me/mfa/phone", { phone: f.phone, channel: f.channel, password: f.password }, null),
346
+ verifyPhone: (f) => post("/me/mfa/phone/verify", { code: f.code }, checkCode(f.code)),
347
+ removePhone: (f) => post("/me/mfa/phone/remove", { password: f.password }, null)
339
348
  },
340
349
  changeEmail: (f) => post("/me/email", { email: f.email, password: f.password }, checkEmail(f.email)),
341
350
  async identities() {
@@ -352,6 +361,11 @@ function createAuthClient(options = {}) {
352
361
  return body && Array.isArray(body.sessions) ? body.sessions : [];
353
362
  },
354
363
  signOutEverywhere: () => post("/me/sessions/end", {}, null),
364
+ async agents() {
365
+ const body = await read("/me/agents");
366
+ return body && Array.isArray(body.agents) ? body.agents : [];
367
+ },
368
+ disconnectAgent: (id) => post("/me/agents/disconnect", { id }, null),
355
369
  async passkeys() {
356
370
  const body = await read("/me/passkeys");
357
371
  return body && Array.isArray(body.passkeys) ? body.passkeys : [];