authhero 0.131.0 → 0.133.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.
@@ -23,7 +23,7 @@ export interface Totals {
23
23
  length: number;
24
24
  }
25
25
  export declare const baseUserSchema: z.ZodObject<{
26
- email: z.ZodOptional<z.ZodString>;
26
+ email: z.ZodEffects<z.ZodOptional<z.ZodString>, string | undefined, string | undefined>;
27
27
  username: z.ZodOptional<z.ZodString>;
28
28
  phone_number: z.ZodOptional<z.ZodString>;
29
29
  given_name: z.ZodOptional<z.ZodString>;
@@ -70,7 +70,7 @@ export declare const baseUserSchema: z.ZodObject<{
70
70
  }>;
71
71
  export type BaseUser = z.infer<typeof baseUserSchema>;
72
72
  export declare const userInsertSchema: z.ZodObject<{
73
- email: z.ZodOptional<z.ZodString>;
73
+ email: z.ZodEffects<z.ZodOptional<z.ZodString>, string | undefined, string | undefined>;
74
74
  username: z.ZodOptional<z.ZodString>;
75
75
  phone_number: z.ZodOptional<z.ZodString>;
76
76
  given_name: z.ZodOptional<z.ZodString>;
@@ -142,7 +142,7 @@ export declare const userSchema: z.ZodObject<{
142
142
  user_id: z.ZodString;
143
143
  is_social: z.ZodBoolean;
144
144
  email: z.ZodOptional<z.ZodString>;
145
- login_count: z.ZodNumber;
145
+ login_count: z.ZodDefault<z.ZodNumber>;
146
146
  identities: z.ZodOptional<z.ZodArray<z.ZodObject<{
147
147
  connection: z.ZodString;
148
148
  user_id: z.ZodString;
@@ -285,7 +285,6 @@ export declare const userSchema: z.ZodObject<{
285
285
  updated_at: string;
286
286
  user_id: string;
287
287
  is_social: boolean;
288
- login_count: number;
289
288
  email?: string | undefined;
290
289
  email_verified?: boolean | undefined;
291
290
  name?: string | undefined;
@@ -305,6 +304,7 @@ export declare const userSchema: z.ZodObject<{
305
304
  verify_email?: boolean | undefined;
306
305
  last_ip?: string | undefined;
307
306
  last_login?: string | undefined;
307
+ login_count?: number | undefined;
308
308
  identities?: {
309
309
  connection: string;
310
310
  user_id: string;
@@ -330,7 +330,7 @@ export declare const auth0UserResponseSchema: z.ZodObject<{
330
330
  user_id: z.ZodString;
331
331
  is_social: z.ZodBoolean;
332
332
  email: z.ZodOptional<z.ZodString>;
333
- login_count: z.ZodNumber;
333
+ login_count: z.ZodDefault<z.ZodNumber>;
334
334
  identities: z.ZodOptional<z.ZodArray<z.ZodObject<{
335
335
  connection: z.ZodString;
336
336
  user_id: z.ZodString;
@@ -473,7 +473,6 @@ export declare const auth0UserResponseSchema: z.ZodObject<{
473
473
  updated_at: string;
474
474
  user_id: string;
475
475
  is_social: boolean;
476
- login_count: number;
477
476
  email?: string | undefined;
478
477
  email_verified?: boolean | undefined;
479
478
  name?: string | undefined;
@@ -493,6 +492,7 @@ export declare const auth0UserResponseSchema: z.ZodObject<{
493
492
  verify_email?: boolean | undefined;
494
493
  last_ip?: string | undefined;
495
494
  last_login?: string | undefined;
495
+ login_count?: number | undefined;
496
496
  identities?: {
497
497
  connection: string;
498
498
  user_id: string;
@@ -521,6 +521,7 @@ export interface PostUsersBody extends BaseUser {
521
521
  email_verified?: boolean;
522
522
  }
523
523
  export declare const userResponseSchema: z.ZodObject<{
524
+ email: z.ZodEffects<z.ZodOptional<z.ZodString>, string | undefined, string | undefined>;
524
525
  username: z.ZodOptional<z.ZodString>;
525
526
  phone_number: z.ZodOptional<z.ZodString>;
526
527
  given_name: z.ZodOptional<z.ZodString>;
@@ -534,13 +535,13 @@ export declare const userResponseSchema: z.ZodObject<{
534
535
  app_metadata: z.ZodOptional<z.ZodDefault<z.ZodAny>>;
535
536
  user_metadata: z.ZodOptional<z.ZodDefault<z.ZodAny>>;
536
537
  } & {
537
- email: z.ZodString;
538
538
  login_count: z.ZodNumber;
539
539
  multifactor: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
540
540
  last_ip: z.ZodOptional<z.ZodString>;
541
541
  last_login: z.ZodOptional<z.ZodString>;
542
542
  user_id: z.ZodString;
543
543
  }, "strip", z.ZodAny, z.objectOutputType<{
544
+ email: z.ZodEffects<z.ZodOptional<z.ZodString>, string | undefined, string | undefined>;
544
545
  username: z.ZodOptional<z.ZodString>;
545
546
  phone_number: z.ZodOptional<z.ZodString>;
546
547
  given_name: z.ZodOptional<z.ZodString>;
@@ -554,13 +555,13 @@ export declare const userResponseSchema: z.ZodObject<{
554
555
  app_metadata: z.ZodOptional<z.ZodDefault<z.ZodAny>>;
555
556
  user_metadata: z.ZodOptional<z.ZodDefault<z.ZodAny>>;
556
557
  } & {
557
- email: z.ZodString;
558
558
  login_count: z.ZodNumber;
559
559
  multifactor: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
560
560
  last_ip: z.ZodOptional<z.ZodString>;
561
561
  last_login: z.ZodOptional<z.ZodString>;
562
562
  user_id: z.ZodString;
563
563
  }, z.ZodAny, "strip">, z.objectInputType<{
564
+ email: z.ZodEffects<z.ZodOptional<z.ZodString>, string | undefined, string | undefined>;
564
565
  username: z.ZodOptional<z.ZodString>;
565
566
  phone_number: z.ZodOptional<z.ZodString>;
566
567
  given_name: z.ZodOptional<z.ZodString>;
@@ -574,7 +575,6 @@ export declare const userResponseSchema: z.ZodObject<{
574
575
  app_metadata: z.ZodOptional<z.ZodDefault<z.ZodAny>>;
575
576
  user_metadata: z.ZodOptional<z.ZodDefault<z.ZodAny>>;
576
577
  } & {
577
- email: z.ZodString;
578
578
  login_count: z.ZodNumber;
579
579
  multifactor: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
580
580
  last_ip: z.ZodOptional<z.ZodString>;
package/dist/authhero.mjs CHANGED
@@ -1447,7 +1447,7 @@ const Fn = c.object({
1447
1447
  refresh_token: c.string().optional(),
1448
1448
  profileData: Km.optional()
1449
1449
  }), bd = c.object({
1450
- email: c.string().optional(),
1450
+ email: c.string().optional().transform((t) => t && t.toLowerCase()),
1451
1451
  username: c.string().optional(),
1452
1452
  phone_number: c.string().optional(),
1453
1453
  given_name: c.string().optional(),
@@ -1475,12 +1475,10 @@ const Fn = c.object({
1475
1475
  ...o0.shape,
1476
1476
  user_id: c.string(),
1477
1477
  is_social: c.boolean(),
1478
- // TODO: this not might be correct if you use the username
1479
1478
  email: c.string().optional(),
1480
- login_count: c.number(),
1479
+ login_count: c.number().default(0),
1481
1480
  identities: c.array(Gm).optional()
1482
1481
  }), Rt = a0, mT = bd.extend({
1483
- email: c.string(),
1484
1482
  login_count: c.number(),
1485
1483
  multifactor: c.array(c.string()).optional(),
1486
1484
  last_ip: c.string().optional(),
@@ -5642,18 +5640,24 @@ async function oo(t, e) {
5642
5640
  };
5643
5641
  }
5644
5642
  async function N0(t, e) {
5645
- return e.loginSession || (e.loginSession = await t.env.data.loginSessions.create(
5646
- e.client.tenant.id,
5647
- {
5648
- expires_at: new Date(
5649
- Date.now() + nr * 1e3
5650
- ).toISOString(),
5651
- authParams: e.authParams,
5652
- authorization_url: t.req.url,
5653
- csrf_token: Se(),
5654
- ...jt(t.req)
5655
- }
5656
- )), {
5643
+ if (!e.loginSession) {
5644
+ const { ip: r, useragent: i, auth0Client: s } = jt(t.req);
5645
+ e.loginSession = await t.env.data.loginSessions.create(
5646
+ e.client.tenant.id,
5647
+ {
5648
+ expires_at: new Date(
5649
+ Date.now() + nr * 1e3
5650
+ ).toISOString(),
5651
+ authParams: e.authParams,
5652
+ authorization_url: t.req.url,
5653
+ csrf_token: Se(),
5654
+ ip: r,
5655
+ useragent: i,
5656
+ auth0Client: s
5657
+ }
5658
+ );
5659
+ }
5660
+ return {
5657
5661
  code: (await t.env.data.codes.create(e.client.tenant.id, {
5658
5662
  code_id: Se(),
5659
5663
  user_id: e.user.user_id,
@@ -6299,48 +6303,53 @@ const ku = Fn.extend({
6299
6303
  async (t) => {
6300
6304
  const { "tenant-id": e } = t.req.valid("header"), n = t.req.valid("json");
6301
6305
  t.set("body", n);
6302
- const { email: r } = n;
6303
- if (!r)
6304
- throw new C(400, { message: "Email is required" });
6305
- const i = r.toLowerCase(), s = `${n.provider}|${n.user_id || ro()}`;
6306
+ const {
6307
+ email: r,
6308
+ phone_number: i,
6309
+ name: s,
6310
+ linked_to: o,
6311
+ email_verified: a,
6312
+ provider: d,
6313
+ connection: l
6314
+ } = n, u = `${n.provider}|${n.user_id || ro()}`;
6306
6315
  try {
6307
- const o = await t.env.data.users.create(e, {
6308
- email: i,
6309
- user_id: s,
6310
- name: n.name || i,
6311
- provider: n.provider,
6312
- connection: n.connection,
6313
- // we need to be careful with this as the profile service was setting this true in places where I don't think it's correct
6314
- // AND when does the account linking happen then? here? first login?
6315
- email_verified: n.email_verified || !1,
6316
+ const f = await t.env.data.users.create(e, {
6317
+ email: r,
6318
+ user_id: u,
6319
+ name: s || r || i,
6320
+ phone_number: i,
6321
+ provider: d,
6322
+ connection: l,
6323
+ linked_to: o ?? void 0,
6324
+ email_verified: a || !1,
6316
6325
  last_ip: "",
6317
6326
  is_social: !1,
6318
6327
  last_login: (/* @__PURE__ */ new Date()).toISOString()
6319
6328
  });
6320
- t.set("user_id", o.user_id);
6321
- const a = be(t, {
6329
+ t.set("user_id", f.user_id);
6330
+ const m = be(t, {
6322
6331
  type: ye.SUCCESS_API_OPERATION,
6323
6332
  description: "User created"
6324
6333
  });
6325
- Nt(t, t.env.data.logs.create(e, a));
6326
- const d = {
6327
- ...o,
6334
+ Nt(t, t.env.data.logs.create(e, m));
6335
+ const w = {
6336
+ ...f,
6328
6337
  identities: [
6329
6338
  {
6330
- connection: o.connection,
6331
- provider: o.provider,
6332
- user_id: gu(o.user_id),
6333
- isSocial: o.is_social
6339
+ connection: f.connection,
6340
+ provider: f.provider,
6341
+ user_id: gu(f.user_id),
6342
+ isSocial: f.is_social
6334
6343
  }
6335
6344
  ]
6336
6345
  };
6337
- return t.json(Rt.parse(d), {
6346
+ return t.json(Rt.parse(w), {
6338
6347
  status: 201
6339
6348
  });
6340
- } catch (o) {
6341
- throw o.message === "User already exists" ? new C(409, {
6349
+ } catch (f) {
6350
+ throw f.message === "User already exists" ? new C(409, {
6342
6351
  message: "User already exists"
6343
- }) : o;
6352
+ }) : f;
6344
6353
  }
6345
6354
  }
6346
6355
  ).openapi(
@@ -18507,14 +18516,19 @@ async function Sv(t, e, n, r) {
18507
18516
  e.tenant.id,
18508
18517
  r.state
18509
18518
  );
18510
- s || (s = await t.env.data.loginSessions.create(e.tenant.id, {
18511
- expires_at: new Date(
18512
- Date.now() + nr * 1e3
18513
- ).toISOString(),
18514
- authParams: r,
18515
- csrf_token: Se(),
18516
- ...jt(t.req)
18517
- }));
18519
+ if (!s) {
18520
+ const { ip: d, useragent: l, auth0Client: u } = jt(t.req);
18521
+ s = await t.env.data.loginSessions.create(e.tenant.id, {
18522
+ expires_at: new Date(
18523
+ Date.now() + nr * 1e3
18524
+ ).toISOString(),
18525
+ authParams: r,
18526
+ csrf_token: Se(),
18527
+ ip: d,
18528
+ useragent: l,
18529
+ auth0Client: u
18530
+ });
18531
+ }
18518
18532
  const a = await Og(t, i.strategy).getRedirect(t, i);
18519
18533
  return await t.env.data.codes.create(e.tenant.id, {
18520
18534
  login_id: s.id,
@@ -21494,30 +21508,32 @@ const Gb = new ae().openapi(
21494
21508
  message: "Client not found"
21495
21509
  });
21496
21510
  t.set("client_id", a.id), t.set("tenant_id", a.tenant.id);
21497
- const d = o === "email" ? e.email : e.phone_number, l = await n.data.loginSessions.create(
21511
+ const d = o === "email" ? e.email : e.phone_number, { ip: l, useragent: u, auth0Client: f } = jt(t.req), m = await n.data.loginSessions.create(
21498
21512
  a.tenant.id,
21499
21513
  {
21500
21514
  authParams: { ...s, client_id: r, username: d },
21501
21515
  expires_at: new Date(Date.now() + Da).toISOString(),
21502
21516
  csrf_token: Se(),
21503
- ...jt(t.req)
21517
+ ip: l,
21518
+ useragent: u,
21519
+ auth0Client: f
21504
21520
  }
21505
- ), u = await n.data.codes.create(a.tenant.id, {
21521
+ ), w = await n.data.codes.create(a.tenant.id, {
21506
21522
  code_id: Mn(),
21507
21523
  code_type: "otp",
21508
- login_id: l.id,
21524
+ login_id: m.id,
21509
21525
  expires_at: new Date(Date.now() + Da).toISOString()
21510
21526
  });
21511
21527
  return i === "link" ? await Tl(t, {
21512
21528
  to: d,
21513
- code: u.code_id,
21529
+ code: w.code_id,
21514
21530
  authParams: {
21515
21531
  ...s,
21516
21532
  client_id: r
21517
21533
  }
21518
21534
  }) : await Kg(t, {
21519
21535
  to: d,
21520
- code: u.code_id
21536
+ code: w.code_id
21521
21537
  }), t.html("OK");
21522
21538
  }
21523
21539
  ).openapi(
@@ -21687,7 +21703,7 @@ async function Wb(t, e, n, r) {
21687
21703
  i,
21688
21704
  "password_reset"
21689
21705
  );
21690
- const o = await t.env.data.loginSessions.create(
21706
+ const { ip: o, useragent: a, auth0Client: d } = jt(t.req), l = await t.env.data.loginSessions.create(
21691
21707
  e.tenant.id,
21692
21708
  {
21693
21709
  expires_at: new Date(
@@ -21698,17 +21714,19 @@ async function Wb(t, e, n, r) {
21698
21714
  username: n
21699
21715
  },
21700
21716
  csrf_token: Se(),
21701
- ...jt(t.req)
21717
+ ip: o,
21718
+ useragent: a,
21719
+ auth0Client: d
21702
21720
  }
21703
- ), a = await t.env.data.codes.create(e.tenant.id, {
21721
+ ), u = await t.env.data.codes.create(e.tenant.id, {
21704
21722
  code_id: i,
21705
21723
  code_type: "password_reset",
21706
- login_id: o.id,
21724
+ login_id: l.id,
21707
21725
  expires_at: new Date(
21708
21726
  Date.now() + V1
21709
21727
  ).toISOString()
21710
21728
  });
21711
- await Hg(t, n, a.code_id, r);
21729
+ await Hg(t, n, u.code_id, r);
21712
21730
  }
21713
21731
  const Jb = new ae().openapi(
21714
21732
  M({
@@ -21760,7 +21778,7 @@ const Jb = new ae().openapi(
21760
21778
  message: "Client not found"
21761
21779
  });
21762
21780
  t.set("client_id", n), t.set("tenant_id", i.tenant.id);
21763
- const s = r.toLocaleLowerCase();
21781
+ const s = r.toLocaleLowerCase(), o = jt(t.req);
21764
21782
  if ("otp" in e)
21765
21783
  return Il(
21766
21784
  t,
@@ -21771,7 +21789,7 @@ const Jb = new ae().openapi(
21771
21789
  !0
21772
21790
  );
21773
21791
  if ("password" in e) {
21774
- const o = await t.env.data.loginSessions.create(
21792
+ const a = await t.env.data.loginSessions.create(
21775
21793
  i.tenant.id,
21776
21794
  {
21777
21795
  expires_at: new Date(
@@ -21782,7 +21800,9 @@ const Jb = new ae().openapi(
21782
21800
  username: s
21783
21801
  },
21784
21802
  csrf_token: Se(),
21785
- ...jt(t.req)
21803
+ ip: o.ip,
21804
+ useragent: o.useragent,
21805
+ auth0Client: o.auth0Client
21786
21806
  }
21787
21807
  );
21788
21808
  return Rl(
@@ -21793,7 +21813,7 @@ const Jb = new ae().openapi(
21793
21813
  password: e.password,
21794
21814
  client_id: n
21795
21815
  },
21796
- o,
21816
+ a,
21797
21817
  !0
21798
21818
  );
21799
21819
  } else
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "authhero",
3
- "version": "0.131.0",
3
+ "version": "0.133.0",
4
4
  "files": [
5
5
  "dist"
6
6
  ],
@@ -36,7 +36,7 @@
36
36
  "vite": "^5.4.11",
37
37
  "vite-plugin-dts": "^4.3.0",
38
38
  "vitest": "^2.1.5",
39
- "@authhero/kysely-adapter": "^10.9.0"
39
+ "@authhero/kysely-adapter": "^10.10.0"
40
40
  },
41
41
  "dependencies": {
42
42
  "@peculiar/x509": "^1.12.3",
@@ -49,7 +49,7 @@
49
49
  "libphonenumber-js": "^1.12.8",
50
50
  "nanoid": "^5.0.8",
51
51
  "oslo": "^1.2.1",
52
- "@authhero/adapter-interfaces": "^0.59.0"
52
+ "@authhero/adapter-interfaces": "^0.60.0"
53
53
  },
54
54
  "peerDependencies": {
55
55
  "@hono/zod-openapi": "^0.19.2",