@better-auth/core 1.7.0-beta.5 → 1.7.0-beta.6

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 (44) hide show
  1. package/dist/api/index.d.mts +44 -1
  2. package/dist/api/index.mjs +40 -1
  3. package/dist/context/global.mjs +1 -1
  4. package/dist/context/transaction.d.mts +7 -4
  5. package/dist/context/transaction.mjs +6 -3
  6. package/dist/db/adapter/factory.mjs +56 -30
  7. package/dist/db/adapter/index.d.mts +54 -10
  8. package/dist/db/adapter/types.d.mts +1 -1
  9. package/dist/db/type.d.mts +12 -7
  10. package/dist/instrumentation/tracer.mjs +1 -1
  11. package/dist/oauth2/dpop.d.mts +142 -0
  12. package/dist/oauth2/dpop.mjs +246 -0
  13. package/dist/oauth2/index.d.mts +3 -2
  14. package/dist/oauth2/index.mjs +3 -2
  15. package/dist/oauth2/verify.d.mts +74 -15
  16. package/dist/oauth2/verify.mjs +172 -20
  17. package/dist/social-providers/index.d.mts +1 -0
  18. package/dist/social-providers/microsoft-entra-id.d.mts +10 -0
  19. package/dist/social-providers/microsoft-entra-id.mjs +17 -2
  20. package/dist/social-providers/reddit.mjs +1 -1
  21. package/dist/social-providers/wechat.mjs +1 -1
  22. package/dist/types/context.d.mts +17 -0
  23. package/dist/types/init-options.d.mts +45 -5
  24. package/dist/types/plugin-client.d.mts +12 -2
  25. package/dist/utils/host.mjs +4 -0
  26. package/dist/utils/url.mjs +4 -3
  27. package/package.json +5 -5
  28. package/src/api/index.ts +82 -0
  29. package/src/context/transaction.ts +45 -12
  30. package/src/db/adapter/factory.ts +127 -72
  31. package/src/db/adapter/index.ts +54 -9
  32. package/src/db/adapter/types.ts +1 -0
  33. package/src/db/type.ts +12 -7
  34. package/src/oauth2/dpop.ts +568 -0
  35. package/src/oauth2/index.ts +44 -1
  36. package/src/oauth2/verify.ts +329 -66
  37. package/src/social-providers/microsoft-entra-id.ts +44 -1
  38. package/src/social-providers/reddit.ts +5 -1
  39. package/src/social-providers/wechat.ts +8 -1
  40. package/src/types/context.ts +18 -0
  41. package/src/types/init-options.ts +40 -8
  42. package/src/types/plugin-client.ts +16 -2
  43. package/src/utils/host.ts +15 -0
  44. package/src/utils/url.ts +10 -4
@@ -6,7 +6,21 @@ import type {
6
6
  import type { Atom, WritableAtom } from "nanostores";
7
7
  import type { LiteralString } from "./helper";
8
8
  import type { BetterAuthOptions } from "./init-options";
9
- import type { BetterAuthPlugin } from "./plugin";
9
+
10
+ type InferableServerPlugin = {
11
+ id?: LiteralString | undefined;
12
+ endpoints?: Record<string, unknown> | undefined;
13
+ schema?: Record<string, { fields: Record<string, unknown> }> | undefined;
14
+ $ERROR_CODES?:
15
+ | Record<
16
+ string,
17
+ {
18
+ readonly code: string;
19
+ message: string;
20
+ }
21
+ >
22
+ | undefined;
23
+ };
10
24
 
11
25
  export interface ClientStore {
12
26
  notify: (signal: string) => void;
@@ -84,7 +98,7 @@ export interface BetterAuthClientPlugin {
84
98
  * only used for type inference. don't pass the
85
99
  * actual plugin
86
100
  */
87
- $InferServerPlugin?: BetterAuthPlugin | undefined;
101
+ $InferServerPlugin?: InferableServerPlugin | undefined;
88
102
  /**
89
103
  * Custom actions
90
104
  */
package/src/utils/host.ts CHANGED
@@ -235,6 +235,10 @@ function classifyIPv6(expanded: string): HostKind {
235
235
 
236
236
  if (expanded.startsWith("2001:0db8:")) return "documentation";
237
237
 
238
+ // 2001:2::/48 — Benchmarking (RFC 5180). A specific non-globally-reachable
239
+ // block inside the otherwise-mixed 2001::/23 protocol-assignments space.
240
+ if (expanded.startsWith("2001:0002:0000:")) return "benchmarking";
241
+
238
242
  if (expanded.startsWith("2002:")) {
239
243
  const embedded = extractEmbeddedIPv4(expanded, 1);
240
244
  if (embedded && classifyIPv4(embedded) !== "public") return "reserved";
@@ -247,6 +251,10 @@ function classifyIPv6(expanded: string): HostKind {
247
251
  return "reserved";
248
252
  }
249
253
 
254
+ // 64:ff9b:1::/48 — Local-Use IPv4/IPv6 Translation (RFC 8215). Distinct from
255
+ // the well-known NAT64 /96 prefix above and not globally reachable.
256
+ if (expanded.startsWith("0064:ff9b:0001:")) return "reserved";
257
+
250
258
  if (expanded.startsWith("2001:0000:")) {
251
259
  const embedded = extractEmbeddedIPv4(expanded, 6, { xor: true });
252
260
  if (embedded && classifyIPv4(embedded) !== "public") return "reserved";
@@ -255,6 +263,13 @@ function classifyIPv6(expanded: string): HostKind {
255
263
 
256
264
  if (expanded.startsWith("0100:0000:0000:0000:")) return "reserved";
257
265
 
266
+ // 3fff::/20 — Documentation (RFC 9637). The /20 fixes the first 16 bits to
267
+ // `3fff` and the next nibble to 0, so only `3fff:0xxx` is in range.
268
+ if (expanded.startsWith("3fff:0")) return "documentation";
269
+
270
+ // 5f00::/16 — SRv6 SIDs (RFC 9602), not globally reachable.
271
+ if (expanded.startsWith("5f00:")) return "reserved";
272
+
258
273
  return "public";
259
274
  }
260
275
 
package/src/utils/url.ts CHANGED
@@ -25,18 +25,24 @@ export function normalizePathname(
25
25
  return "/";
26
26
  }
27
27
 
28
- if (basePath === "/" || basePath === "") {
28
+ // Canonicalize the basePath the same way as the request pathname. A baseURL
29
+ // with a trailing slash yields a basePath like "/api/auth/"; without this it
30
+ // would never match the slash-stripped pathname and the prefix would leak
31
+ // through to disabledPaths and rate-limit special-rule matching.
32
+ const normalizedBasePath = basePath.replace(/\/+$/, "");
33
+
34
+ if (normalizedBasePath === "") {
29
35
  return pathname;
30
36
  }
31
37
 
32
38
  // Check for exact match or proper path boundary (basePath followed by "/" or end)
33
39
  // This prevents "/api/auth" from matching "/api/authevil/..."
34
- if (pathname === basePath) {
40
+ if (pathname === normalizedBasePath) {
35
41
  return "/";
36
42
  }
37
43
 
38
- if (pathname.startsWith(basePath + "/")) {
39
- return pathname.slice(basePath.length).replace(/\/+$/, "") || "/";
44
+ if (pathname.startsWith(normalizedBasePath + "/")) {
45
+ return pathname.slice(normalizedBasePath.length).replace(/\/+$/, "") || "/";
40
46
  }
41
47
 
42
48
  return pathname;