@better-auth/core 1.5.0 → 1.5.1-beta.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.
@@ -2,7 +2,7 @@
2
2
  const symbol = Symbol.for("better-auth:global");
3
3
  let bind = null;
4
4
  const __context = {};
5
- const __betterAuthVersion = "1.5.0";
5
+ const __betterAuthVersion = "1.5.1-beta.1";
6
6
  /**
7
7
  * We store context instance in the globalThis.
8
8
  *
@@ -109,9 +109,8 @@ interface InternalAdapter<_Options extends BetterAuthOptions = BetterAuthOptions
109
109
  updateAccount(id: string, data: Partial<Account>): Promise<Account>;
110
110
  createVerificationValue(data: Omit<Verification, "createdAt" | "id" | "updatedAt"> & Partial<Verification>): Promise<Verification>;
111
111
  findVerificationValue(identifier: string): Promise<Verification | null>;
112
- deleteVerificationValue(id: string): Promise<void>;
113
112
  deleteVerificationByIdentifier(identifier: string): Promise<void>;
114
- updateVerificationValue(id: string, data: Partial<Verification>): Promise<Verification>;
113
+ updateVerificationByIdentifier(identifier: string, data: Partial<Verification>): Promise<Verification>;
115
114
  }
116
115
  type CreateCookieGetterFn = (cookieName: string, overrideAttributes?: Partial<CookieOptions> | undefined) => BetterAuthCookie;
117
116
  type CheckPasswordFn<Options extends BetterAuthOptions = BetterAuthOptions> = (userId: string, ctx: GenericEndpointContext<Options>) => Promise<boolean>;
@@ -2,19 +2,38 @@ import { logger } from "../env/logger.mjs";
2
2
  import "../env/index.mjs";
3
3
 
4
4
  //#region src/utils/json.ts
5
- function safeJSONParse(data) {
6
- function reviver(_, value) {
7
- if (typeof value === "string") {
8
- if (/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d+)?Z$/.test(value)) {
9
- const date = new Date(value);
10
- if (!isNaN(date.getTime())) return date;
11
- }
12
- }
13
- return value;
5
+ const iso8601Regex = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d+)?Z$/;
6
+ function reviveDate(value) {
7
+ if (typeof value === "string" && iso8601Regex.test(value)) {
8
+ const date = new Date(value);
9
+ if (!isNaN(date.getTime())) return date;
10
+ }
11
+ return value;
12
+ }
13
+ /**
14
+ * Recursively walk a pre-parsed object and convert ISO 8601 date strings
15
+ * to Date instances. This handles the case where a Redis client (or similar)
16
+ * returns already-parsed JSON objects whose date fields are still strings.
17
+ */
18
+ function reviveDates(value) {
19
+ if (value === null || value === void 0) return value;
20
+ if (typeof value === "string") return reviveDate(value);
21
+ if (value instanceof Date) return value;
22
+ if (Array.isArray(value)) return value.map(reviveDates);
23
+ if (typeof value === "object") {
24
+ const result = {};
25
+ for (const key of Object.keys(value)) result[key] = reviveDates(value[key]);
26
+ return result;
14
27
  }
28
+ return value;
29
+ }
30
+ function safeJSONParse(data) {
15
31
  try {
16
- if (typeof data !== "string") return data;
17
- return JSON.parse(data, reviver);
32
+ if (typeof data !== "string") {
33
+ if (data === null || data === void 0) return null;
34
+ return reviveDates(data);
35
+ }
36
+ return JSON.parse(data, (_, value) => reviveDate(value));
18
37
  } catch (e) {
19
38
  logger.error("Error parsing JSON", { error: e });
20
39
  return null;
@@ -1 +1 @@
1
- {"version":3,"file":"json.mjs","names":[],"sources":["../../src/utils/json.ts"],"sourcesContent":["import { logger } from \"../env\";\n\nexport function safeJSONParse<T>(data: unknown): T | null {\n\tfunction reviver(_: string, value: any): any {\n\t\tif (typeof value === \"string\") {\n\t\t\tconst iso8601Regex = /^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}(?:\\.\\d+)?Z$/;\n\t\t\tif (iso8601Regex.test(value)) {\n\t\t\t\tconst date = new Date(value);\n\t\t\t\tif (!isNaN(date.getTime())) {\n\t\t\t\t\treturn date;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn value;\n\t}\n\ttry {\n\t\tif (typeof data !== \"string\") {\n\t\t\treturn data as T;\n\t\t}\n\t\treturn JSON.parse(data, reviver);\n\t} catch (e) {\n\t\tlogger.error(\"Error parsing JSON\", { error: e });\n\t\treturn null;\n\t}\n}\n"],"mappings":";;;;AAEA,SAAgB,cAAiB,MAAyB;CACzD,SAAS,QAAQ,GAAW,OAAiB;AAC5C,MAAI,OAAO,UAAU,UAEpB;OADqB,mDACJ,KAAK,MAAM,EAAE;IAC7B,MAAM,OAAO,IAAI,KAAK,MAAM;AAC5B,QAAI,CAAC,MAAM,KAAK,SAAS,CAAC,CACzB,QAAO;;;AAIV,SAAO;;AAER,KAAI;AACH,MAAI,OAAO,SAAS,SACnB,QAAO;AAER,SAAO,KAAK,MAAM,MAAM,QAAQ;UACxB,GAAG;AACX,SAAO,MAAM,sBAAsB,EAAE,OAAO,GAAG,CAAC;AAChD,SAAO"}
1
+ {"version":3,"file":"json.mjs","names":[],"sources":["../../src/utils/json.ts"],"sourcesContent":["import { logger } from \"../env\";\n\nconst iso8601Regex = /^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}(?:\\.\\d+)?Z$/;\n\nfunction reviveDate(value: unknown): any {\n\tif (typeof value === \"string\" && iso8601Regex.test(value)) {\n\t\tconst date = new Date(value);\n\t\tif (!isNaN(date.getTime())) {\n\t\t\treturn date;\n\t\t}\n\t}\n\treturn value;\n}\n\n/**\n * Recursively walk a pre-parsed object and convert ISO 8601 date strings\n * to Date instances. This handles the case where a Redis client (or similar)\n * returns already-parsed JSON objects whose date fields are still strings.\n */\nfunction reviveDates(value: unknown): any {\n\tif (value === null || value === undefined) {\n\t\treturn value;\n\t}\n\tif (typeof value === \"string\") {\n\t\treturn reviveDate(value);\n\t}\n\tif (value instanceof Date) {\n\t\treturn value;\n\t}\n\tif (Array.isArray(value)) {\n\t\treturn value.map(reviveDates);\n\t}\n\tif (typeof value === \"object\") {\n\t\tconst result: Record<string, any> = {};\n\t\tfor (const key of Object.keys(value)) {\n\t\t\tresult[key] = reviveDates((value as Record<string, any>)[key]);\n\t\t}\n\t\treturn result;\n\t}\n\treturn value;\n}\n\nexport function safeJSONParse<T>(data: unknown): T | null {\n\ttry {\n\t\tif (typeof data !== \"string\") {\n\t\t\tif (data === null || data === undefined) {\n\t\t\t\treturn null;\n\t\t\t}\n\t\t\treturn reviveDates(data) as T;\n\t\t}\n\t\treturn JSON.parse(data, (_, value) => reviveDate(value));\n\t} catch (e) {\n\t\tlogger.error(\"Error parsing JSON\", { error: e });\n\t\treturn null;\n\t}\n}\n"],"mappings":";;;;AAEA,MAAM,eAAe;AAErB,SAAS,WAAW,OAAqB;AACxC,KAAI,OAAO,UAAU,YAAY,aAAa,KAAK,MAAM,EAAE;EAC1D,MAAM,OAAO,IAAI,KAAK,MAAM;AAC5B,MAAI,CAAC,MAAM,KAAK,SAAS,CAAC,CACzB,QAAO;;AAGT,QAAO;;;;;;;AAQR,SAAS,YAAY,OAAqB;AACzC,KAAI,UAAU,QAAQ,UAAU,OAC/B,QAAO;AAER,KAAI,OAAO,UAAU,SACpB,QAAO,WAAW,MAAM;AAEzB,KAAI,iBAAiB,KACpB,QAAO;AAER,KAAI,MAAM,QAAQ,MAAM,CACvB,QAAO,MAAM,IAAI,YAAY;AAE9B,KAAI,OAAO,UAAU,UAAU;EAC9B,MAAM,SAA8B,EAAE;AACtC,OAAK,MAAM,OAAO,OAAO,KAAK,MAAM,CACnC,QAAO,OAAO,YAAa,MAA8B,KAAK;AAE/D,SAAO;;AAER,QAAO;;AAGR,SAAgB,cAAiB,MAAyB;AACzD,KAAI;AACH,MAAI,OAAO,SAAS,UAAU;AAC7B,OAAI,SAAS,QAAQ,SAAS,OAC7B,QAAO;AAER,UAAO,YAAY,KAAK;;AAEzB,SAAO,KAAK,MAAM,OAAO,GAAG,UAAU,WAAW,MAAM,CAAC;UAChD,GAAG;AACX,SAAO,MAAM,sBAAsB,EAAE,OAAO,GAAG,CAAC;AAChD,SAAO"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@better-auth/core",
3
- "version": "1.5.0",
3
+ "version": "1.5.1-beta.1",
4
4
  "description": "The most comprehensive authentication framework for TypeScript.",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -141,7 +141,7 @@
141
141
  "jose": "^6.1.3",
142
142
  "kysely": "^0.28.11",
143
143
  "nanostores": "^1.1.1",
144
- "tsdown": "^0.20.3"
144
+ "tsdown": "0.21.0-beta.2"
145
145
  },
146
146
  "peerDependencies": {
147
147
  "@better-auth/utils": "0.3.1",
@@ -208,12 +208,10 @@ export interface InternalAdapter<
208
208
 
209
209
  findVerificationValue(identifier: string): Promise<Verification | null>;
210
210
 
211
- deleteVerificationValue(id: string): Promise<void>;
212
-
213
211
  deleteVerificationByIdentifier(identifier: string): Promise<void>;
214
212
 
215
- updateVerificationValue(
216
- id: string,
213
+ updateVerificationByIdentifier(
214
+ identifier: string,
217
215
  data: Partial<Verification>,
218
216
  ): Promise<Verification>;
219
217
  }
package/src/utils/json.ts CHANGED
@@ -1,23 +1,54 @@
1
1
  import { logger } from "../env";
2
2
 
3
- export function safeJSONParse<T>(data: unknown): T | null {
4
- function reviver(_: string, value: any): any {
5
- if (typeof value === "string") {
6
- const iso8601Regex = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d+)?Z$/;
7
- if (iso8601Regex.test(value)) {
8
- const date = new Date(value);
9
- if (!isNaN(date.getTime())) {
10
- return date;
11
- }
12
- }
3
+ const iso8601Regex = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d+)?Z$/;
4
+
5
+ function reviveDate(value: unknown): any {
6
+ if (typeof value === "string" && iso8601Regex.test(value)) {
7
+ const date = new Date(value);
8
+ if (!isNaN(date.getTime())) {
9
+ return date;
13
10
  }
11
+ }
12
+ return value;
13
+ }
14
+
15
+ /**
16
+ * Recursively walk a pre-parsed object and convert ISO 8601 date strings
17
+ * to Date instances. This handles the case where a Redis client (or similar)
18
+ * returns already-parsed JSON objects whose date fields are still strings.
19
+ */
20
+ function reviveDates(value: unknown): any {
21
+ if (value === null || value === undefined) {
22
+ return value;
23
+ }
24
+ if (typeof value === "string") {
25
+ return reviveDate(value);
26
+ }
27
+ if (value instanceof Date) {
14
28
  return value;
15
29
  }
30
+ if (Array.isArray(value)) {
31
+ return value.map(reviveDates);
32
+ }
33
+ if (typeof value === "object") {
34
+ const result: Record<string, any> = {};
35
+ for (const key of Object.keys(value)) {
36
+ result[key] = reviveDates((value as Record<string, any>)[key]);
37
+ }
38
+ return result;
39
+ }
40
+ return value;
41
+ }
42
+
43
+ export function safeJSONParse<T>(data: unknown): T | null {
16
44
  try {
17
45
  if (typeof data !== "string") {
18
- return data as T;
46
+ if (data === null || data === undefined) {
47
+ return null;
48
+ }
49
+ return reviveDates(data) as T;
19
50
  }
20
- return JSON.parse(data, reviver);
51
+ return JSON.parse(data, (_, value) => reviveDate(value));
21
52
  } catch (e) {
22
53
  logger.error("Error parsing JSON", { error: e });
23
54
  return null;