@better-auth/core 1.7.0-beta.7 → 1.7.0-beta.8

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 (140) hide show
  1. package/dist/api/index.d.mts +3 -3
  2. package/dist/context/global.mjs +1 -1
  3. package/dist/db/adapter/factory.mjs +1 -1
  4. package/dist/db/get-tables.mjs +3 -3
  5. package/dist/db/schema/account.d.mts +1 -1
  6. package/dist/db/schema/account.mjs +1 -1
  7. package/dist/error/codes.d.mts +0 -5
  8. package/dist/error/codes.mjs +0 -5
  9. package/dist/instrumentation/tracer.mjs +1 -1
  10. package/dist/oauth2/create-authorization-url.d.mts +1 -4
  11. package/dist/oauth2/create-authorization-url.mjs +1 -4
  12. package/dist/oauth2/index.d.mts +3 -4
  13. package/dist/oauth2/index.mjs +2 -3
  14. package/dist/oauth2/oauth-provider.d.mts +12 -50
  15. package/dist/oauth2/refresh-access-token.mjs +2 -1
  16. package/dist/oauth2/utils.d.mts +6 -1
  17. package/dist/oauth2/utils.mjs +24 -2
  18. package/dist/oauth2/verify-id-token.d.mts +6 -5
  19. package/dist/oauth2/verify-id-token.mjs +2 -2
  20. package/dist/social-providers/apple.d.mts +1 -5
  21. package/dist/social-providers/apple.mjs +5 -5
  22. package/dist/social-providers/atlassian.d.mts +1 -5
  23. package/dist/social-providers/atlassian.mjs +4 -4
  24. package/dist/social-providers/cognito.d.mts +1 -5
  25. package/dist/social-providers/cognito.mjs +11 -18
  26. package/dist/social-providers/discord.d.mts +1 -5
  27. package/dist/social-providers/discord.mjs +6 -7
  28. package/dist/social-providers/dropbox.d.mts +1 -5
  29. package/dist/social-providers/dropbox.mjs +5 -5
  30. package/dist/social-providers/facebook.d.mts +1 -5
  31. package/dist/social-providers/facebook.mjs +5 -5
  32. package/dist/social-providers/figma.d.mts +1 -5
  33. package/dist/social-providers/figma.mjs +5 -5
  34. package/dist/social-providers/github.d.mts +1 -5
  35. package/dist/social-providers/github.mjs +4 -4
  36. package/dist/social-providers/gitlab.d.mts +1 -5
  37. package/dist/social-providers/gitlab.mjs +6 -6
  38. package/dist/social-providers/google.d.mts +8 -10
  39. package/dist/social-providers/google.mjs +12 -13
  40. package/dist/social-providers/huggingface.d.mts +1 -5
  41. package/dist/social-providers/huggingface.mjs +8 -8
  42. package/dist/social-providers/index.d.mts +35 -177
  43. package/dist/social-providers/kakao.d.mts +1 -5
  44. package/dist/social-providers/kakao.mjs +8 -8
  45. package/dist/social-providers/kick.d.mts +1 -5
  46. package/dist/social-providers/kick.mjs +4 -4
  47. package/dist/social-providers/line.d.mts +1 -5
  48. package/dist/social-providers/line.mjs +10 -10
  49. package/dist/social-providers/linear.d.mts +1 -5
  50. package/dist/social-providers/linear.mjs +4 -4
  51. package/dist/social-providers/linkedin.d.mts +1 -5
  52. package/dist/social-providers/linkedin.mjs +10 -10
  53. package/dist/social-providers/microsoft-entra-id.d.mts +1 -5
  54. package/dist/social-providers/microsoft-entra-id.mjs +10 -11
  55. package/dist/social-providers/naver.d.mts +1 -5
  56. package/dist/social-providers/naver.mjs +4 -4
  57. package/dist/social-providers/notion.d.mts +1 -5
  58. package/dist/social-providers/notion.mjs +4 -4
  59. package/dist/social-providers/paybin.d.mts +1 -5
  60. package/dist/social-providers/paybin.mjs +10 -10
  61. package/dist/social-providers/paypal.d.mts +1 -5
  62. package/dist/social-providers/paypal.mjs +2 -8
  63. package/dist/social-providers/polar.d.mts +1 -5
  64. package/dist/social-providers/polar.mjs +8 -8
  65. package/dist/social-providers/railway.d.mts +1 -5
  66. package/dist/social-providers/railway.mjs +9 -9
  67. package/dist/social-providers/reddit.d.mts +1 -5
  68. package/dist/social-providers/reddit.mjs +5 -5
  69. package/dist/social-providers/roblox.d.mts +1 -5
  70. package/dist/social-providers/roblox.mjs +5 -5
  71. package/dist/social-providers/salesforce.d.mts +1 -5
  72. package/dist/social-providers/salesforce.mjs +8 -8
  73. package/dist/social-providers/slack.d.mts +1 -5
  74. package/dist/social-providers/slack.mjs +9 -9
  75. package/dist/social-providers/spotify.d.mts +1 -5
  76. package/dist/social-providers/spotify.mjs +5 -5
  77. package/dist/social-providers/tiktok.d.mts +1 -5
  78. package/dist/social-providers/tiktok.mjs +5 -9
  79. package/dist/social-providers/twitch.d.mts +1 -5
  80. package/dist/social-providers/twitch.mjs +4 -4
  81. package/dist/social-providers/twitter.d.mts +1 -5
  82. package/dist/social-providers/twitter.mjs +9 -9
  83. package/dist/social-providers/vercel.d.mts +1 -5
  84. package/dist/social-providers/vercel.mjs +7 -4
  85. package/dist/social-providers/vk.d.mts +1 -5
  86. package/dist/social-providers/vk.mjs +5 -5
  87. package/dist/social-providers/wechat.d.mts +1 -5
  88. package/dist/social-providers/wechat.mjs +5 -9
  89. package/dist/social-providers/zoom.d.mts +1 -6
  90. package/dist/social-providers/zoom.mjs +9 -15
  91. package/dist/types/context.d.mts +6 -2
  92. package/package.json +1 -1
  93. package/src/db/get-tables.ts +3 -8
  94. package/src/db/schema/account.ts +5 -14
  95. package/src/error/codes.ts +0 -5
  96. package/src/oauth2/create-authorization-url.ts +1 -1
  97. package/src/oauth2/index.ts +2 -12
  98. package/src/oauth2/oauth-provider.ts +11 -56
  99. package/src/oauth2/refresh-access-token.ts +3 -2
  100. package/src/oauth2/utils.ts +39 -1
  101. package/src/oauth2/verify-id-token.ts +7 -5
  102. package/src/social-providers/apple.ts +8 -13
  103. package/src/social-providers/atlassian.ts +8 -12
  104. package/src/social-providers/cognito.ts +11 -18
  105. package/src/social-providers/discord.ts +8 -19
  106. package/src/social-providers/dropbox.ts +7 -13
  107. package/src/social-providers/facebook.ts +9 -13
  108. package/src/social-providers/figma.ts +9 -13
  109. package/src/social-providers/github.ts +8 -12
  110. package/src/social-providers/gitlab.ts +8 -14
  111. package/src/social-providers/google.ts +23 -29
  112. package/src/social-providers/huggingface.ts +8 -12
  113. package/src/social-providers/kakao.ts +8 -16
  114. package/src/social-providers/kick.ts +7 -12
  115. package/src/social-providers/line.ts +10 -14
  116. package/src/social-providers/linear.ts +6 -12
  117. package/src/social-providers/linkedin.ts +10 -14
  118. package/src/social-providers/microsoft-entra-id.ts +8 -18
  119. package/src/social-providers/naver.ts +6 -12
  120. package/src/social-providers/notion.ts +6 -12
  121. package/src/social-providers/paybin.ts +11 -14
  122. package/src/social-providers/paypal.ts +8 -6
  123. package/src/social-providers/polar.ts +8 -12
  124. package/src/social-providers/railway.ts +9 -13
  125. package/src/social-providers/reddit.ts +7 -18
  126. package/src/social-providers/roblox.ts +7 -18
  127. package/src/social-providers/salesforce.ts +8 -12
  128. package/src/social-providers/slack.ts +9 -18
  129. package/src/social-providers/spotify.ts +7 -13
  130. package/src/social-providers/tiktok.ts +7 -13
  131. package/src/social-providers/twitch.ts +8 -12
  132. package/src/social-providers/twitter.ts +8 -17
  133. package/src/social-providers/vercel.ts +10 -16
  134. package/src/social-providers/vk.ts +7 -13
  135. package/src/social-providers/wechat.ts +8 -20
  136. package/src/social-providers/zoom.ts +6 -19
  137. package/src/types/context.ts +8 -2
  138. package/dist/oauth2/scopes.d.mts +0 -76
  139. package/dist/oauth2/scopes.mjs +0 -96
  140. package/src/oauth2/scopes.ts +0 -118
@@ -1,96 +0,0 @@
1
- //#region src/oauth2/scopes.ts
2
- /**
3
- * Parse a provider's `scope` token-response field into a string array.
4
- *
5
- * RFC 6749 §3.3 defines `scope` as a space-delimited string, but providers
6
- * vary: some (e.g. Twitch) return an already-split array. Accept both, plus the
7
- * omitted/empty case, without ever calling `.split` on a non-string. Returns
8
- * `[]` when no scope is present.
9
- *
10
- * @see https://github.com/better-auth/better-auth/issues/9076
11
- */
12
- function parseScopeField(scope) {
13
- if (Array.isArray(scope)) return scope.filter((s) => typeof s === "string" && s !== "");
14
- if (typeof scope === "string") return scope.split(" ").filter(Boolean);
15
- return [];
16
- }
17
- /**
18
- * Normalize a scope set into a single deduped, sorted array.
19
- *
20
- * Scope order is insignificant per RFC 6749 §3.3, so normalize for idempotent
21
- * writes and trivial comparisons: trim each token, drop empties, dedupe, and
22
- * sort ascending. Returns `[]` when the union is empty.
23
- *
24
- * @see https://www.rfc-editor.org/rfc/rfc6749#section-3.3
25
- */
26
- function normalizeScopes(stored, incoming) {
27
- const normalized = /* @__PURE__ */ new Set();
28
- for (const scope of [...stored ?? [], ...incoming ?? []]) {
29
- const trimmed = scope.trim();
30
- if (trimmed) normalized.add(trimmed);
31
- }
32
- return [...normalized].sort();
33
- }
34
- /**
35
- * Union the stored granted-scope set with the scopes observed on an
36
- * authorization or token exchange.
37
- *
38
- * The provider's echoed `scope` is authoritative when present. RFC 6749 §3.3
39
- * and §5.1 say an omitted or empty echo means the grant equals what was
40
- * requested, so fall back to `requested` in that case. The result unions onto
41
- * the stored grant (never narrows on a normal write) and is normalized per
42
- * {@link normalizeScopes}.
43
- *
44
- * @see https://www.rfc-editor.org/rfc/rfc6749#section-3.3
45
- * @see https://www.rfc-editor.org/rfc/rfc6749#section-5.1
46
- */
47
- function unionGrantedScopes(stored, echoed, requested) {
48
- return normalizeScopes(stored, echoed?.length ? echoed : requested);
49
- }
50
- /**
51
- * Coerce a stored granted-scope value into a usable array.
52
- *
53
- * `account.grantedScopes` is nullable (legacy rows and non-OAuth accounts read
54
- * as unset), and on dialects that store the array as a JSON string a malformed
55
- * operator backfill could deserialize to a non-array. Both collapse to `[]`
56
- * here so every reader works against a real `string[]` without re-deriving the
57
- * guard.
58
- */
59
- function readGrantedScopes(stored) {
60
- return Array.isArray(stored) ? stored : [];
61
- }
62
- /**
63
- * Test whether a normalized granted-scope set contains a specific scope.
64
- *
65
- * Matching is exact and case-sensitive per RFC 6749 §3.3. The argument is the
66
- * normalized `account.grantedScopes` array; a raw provider `scope` string must
67
- * be run through {@link parseScopeField} first.
68
- *
69
- * @see https://www.rfc-editor.org/rfc/rfc6749#section-3.3
70
- */
71
- function includesGrantedScope(granted, scope) {
72
- return granted?.includes(scope) ?? false;
73
- }
74
- /**
75
- * Compose the effective scope set to encode in a single authorization URL.
76
- *
77
- * Precedence: the provider's built-in defaults (unless `disableDefaultScope`),
78
- * then the integrator's configured `options.scope`, then the per-request
79
- * `scopes`. The result is the value persisted into OAuth state as the RFC 6749
80
- * §5.1 fallback, so it is preserved verbatim (not normalized) to match what is
81
- * sent to the provider.
82
- *
83
- * `defaultScopes` is a parameter rather than a provider-contract field so the
84
- * runtime-synthesized generic OAuth provider, which has no static default set,
85
- * can pass its configured scopes here.
86
- *
87
- * @see https://www.rfc-editor.org/rfc/rfc6749#section-5.1
88
- */
89
- function resolveRequestedScopes(options, defaultScopes, perRequestScopes) {
90
- const scopes = options?.disableDefaultScope ? [] : [...defaultScopes];
91
- if (options?.scope) scopes.push(...options.scope);
92
- if (perRequestScopes) scopes.push(...perRequestScopes);
93
- return scopes;
94
- }
95
- //#endregion
96
- export { includesGrantedScope, normalizeScopes, parseScopeField, readGrantedScopes, resolveRequestedScopes, unionGrantedScopes };
@@ -1,118 +0,0 @@
1
- import type { ProviderOptions } from "./oauth-provider";
2
-
3
- /**
4
- * Parse a provider's `scope` token-response field into a string array.
5
- *
6
- * RFC 6749 §3.3 defines `scope` as a space-delimited string, but providers
7
- * vary: some (e.g. Twitch) return an already-split array. Accept both, plus the
8
- * omitted/empty case, without ever calling `.split` on a non-string. Returns
9
- * `[]` when no scope is present.
10
- *
11
- * @see https://github.com/better-auth/better-auth/issues/9076
12
- */
13
- export function parseScopeField(scope: unknown): string[] {
14
- if (Array.isArray(scope))
15
- return scope.filter((s): s is string => typeof s === "string" && s !== "");
16
- if (typeof scope === "string") return scope.split(" ").filter(Boolean);
17
- return [];
18
- }
19
-
20
- /**
21
- * Normalize a scope set into a single deduped, sorted array.
22
- *
23
- * Scope order is insignificant per RFC 6749 §3.3, so normalize for idempotent
24
- * writes and trivial comparisons: trim each token, drop empties, dedupe, and
25
- * sort ascending. Returns `[]` when the union is empty.
26
- *
27
- * @see https://www.rfc-editor.org/rfc/rfc6749#section-3.3
28
- */
29
- export function normalizeScopes(
30
- stored: string[] | null | undefined,
31
- incoming?: string[] | undefined,
32
- ): string[] {
33
- const normalized = new Set<string>();
34
- for (const scope of [...(stored ?? []), ...(incoming ?? [])]) {
35
- const trimmed = scope.trim();
36
- if (trimmed) normalized.add(trimmed);
37
- }
38
- return [...normalized].sort();
39
- }
40
-
41
- /**
42
- * Union the stored granted-scope set with the scopes observed on an
43
- * authorization or token exchange.
44
- *
45
- * The provider's echoed `scope` is authoritative when present. RFC 6749 §3.3
46
- * and §5.1 say an omitted or empty echo means the grant equals what was
47
- * requested, so fall back to `requested` in that case. The result unions onto
48
- * the stored grant (never narrows on a normal write) and is normalized per
49
- * {@link normalizeScopes}.
50
- *
51
- * @see https://www.rfc-editor.org/rfc/rfc6749#section-3.3
52
- * @see https://www.rfc-editor.org/rfc/rfc6749#section-5.1
53
- */
54
- export function unionGrantedScopes(
55
- stored: string[] | null | undefined,
56
- echoed: string[] | undefined,
57
- requested: string[] | undefined,
58
- ): string[] {
59
- const granted = echoed?.length ? echoed : requested;
60
- return normalizeScopes(stored, granted);
61
- }
62
-
63
- /**
64
- * Coerce a stored granted-scope value into a usable array.
65
- *
66
- * `account.grantedScopes` is nullable (legacy rows and non-OAuth accounts read
67
- * as unset), and on dialects that store the array as a JSON string a malformed
68
- * operator backfill could deserialize to a non-array. Both collapse to `[]`
69
- * here so every reader works against a real `string[]` without re-deriving the
70
- * guard.
71
- */
72
- export function readGrantedScopes(
73
- stored: string[] | null | undefined,
74
- ): string[] {
75
- return Array.isArray(stored) ? stored : [];
76
- }
77
-
78
- /**
79
- * Test whether a normalized granted-scope set contains a specific scope.
80
- *
81
- * Matching is exact and case-sensitive per RFC 6749 §3.3. The argument is the
82
- * normalized `account.grantedScopes` array; a raw provider `scope` string must
83
- * be run through {@link parseScopeField} first.
84
- *
85
- * @see https://www.rfc-editor.org/rfc/rfc6749#section-3.3
86
- */
87
- export function includesGrantedScope(
88
- granted: string[] | null | undefined,
89
- scope: string,
90
- ): boolean {
91
- return granted?.includes(scope) ?? false;
92
- }
93
-
94
- /**
95
- * Compose the effective scope set to encode in a single authorization URL.
96
- *
97
- * Precedence: the provider's built-in defaults (unless `disableDefaultScope`),
98
- * then the integrator's configured `options.scope`, then the per-request
99
- * `scopes`. The result is the value persisted into OAuth state as the RFC 6749
100
- * §5.1 fallback, so it is preserved verbatim (not normalized) to match what is
101
- * sent to the provider.
102
- *
103
- * `defaultScopes` is a parameter rather than a provider-contract field so the
104
- * runtime-synthesized generic OAuth provider, which has no static default set,
105
- * can pass its configured scopes here.
106
- *
107
- * @see https://www.rfc-editor.org/rfc/rfc6749#section-5.1
108
- */
109
- export function resolveRequestedScopes(
110
- options: Pick<ProviderOptions, "scope" | "disableDefaultScope"> | undefined,
111
- defaultScopes: string[],
112
- perRequestScopes: string[] | undefined,
113
- ): string[] {
114
- const scopes = options?.disableDefaultScope ? [] : [...defaultScopes];
115
- if (options?.scope) scopes.push(...options.scope);
116
- if (perRequestScopes) scopes.push(...perRequestScopes);
117
- return scopes;
118
- }