@stackframe/stack 2.3.5 → 2.3.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 (261) hide show
  1. package/dist/components/card-frame.d.mts +9 -0
  2. package/dist/components/card-frame.d.ts +8 -5
  3. package/dist/components/card-frame.js +58 -23
  4. package/dist/components/credential-sign-in.d.mts +5 -0
  5. package/dist/components/credential-sign-in.d.ts +5 -1
  6. package/dist/components/credential-sign-in.js +109 -41
  7. package/dist/components/credential-sign-up.d.mts +5 -0
  8. package/dist/components/credential-sign-up.d.ts +5 -1
  9. package/dist/components/credential-sign-up.js +140 -62
  10. package/dist/components/forgot-password.d.mts +7 -0
  11. package/dist/components/forgot-password.d.ts +6 -2
  12. package/dist/components/forgot-password.js +83 -26
  13. package/dist/components/form-warning.d.mts +7 -0
  14. package/dist/components/form-warning.d.ts +6 -2
  15. package/dist/components/form-warning.js +34 -8
  16. package/dist/components/magic-link-sign-in.d.mts +5 -0
  17. package/dist/components/magic-link-sign-in.d.ts +5 -1
  18. package/dist/components/magic-link-sign-in.js +89 -31
  19. package/dist/components/message-card.d.mts +10 -0
  20. package/dist/components/message-card.d.ts +8 -4
  21. package/dist/components/message-card.js +45 -6
  22. package/dist/components/oauth-button.d.mts +8 -0
  23. package/dist/components/oauth-button.d.ts +6 -2
  24. package/dist/components/oauth-button.js +142 -63
  25. package/dist/components/oauth-group.d.mts +7 -0
  26. package/dist/components/oauth-group.d.ts +6 -2
  27. package/dist/components/oauth-group.js +46 -8
  28. package/dist/components/password-field.d.mts +5 -0
  29. package/dist/components/password-field.d.ts +5 -3
  30. package/dist/components/password-field.js +111 -41
  31. package/dist/components/password-reset-inner.d.mts +8 -0
  32. package/dist/components/password-reset-inner.d.ts +6 -2
  33. package/dist/components/password-reset-inner.js +120 -58
  34. package/dist/components/redirect-message-card.d.mts +8 -0
  35. package/dist/components/redirect-message-card.d.ts +6 -2
  36. package/dist/components/redirect-message-card.js +110 -58
  37. package/dist/components/separator-with-text.d.mts +7 -0
  38. package/dist/components/separator-with-text.d.ts +6 -2
  39. package/dist/components/separator-with-text.js +35 -5
  40. package/dist/components/user-avatar.d.mts +13 -0
  41. package/dist/components/user-avatar.d.ts +11 -3
  42. package/dist/components/user-avatar.js +34 -6
  43. package/dist/components/user-button.d.mts +15 -0
  44. package/dist/components/user-button.d.ts +12 -3
  45. package/dist/components/user-button.js +156 -26
  46. package/dist/components-core/avatar.d.mts +8 -0
  47. package/dist/components-core/avatar.d.ts +7 -5
  48. package/dist/components-core/avatar.js +73 -18
  49. package/dist/components-core/button.d.mts +12 -0
  50. package/dist/components-core/button.d.ts +8 -6
  51. package/dist/components-core/button.js +177 -113
  52. package/dist/components-core/card.d.mts +8 -0
  53. package/dist/components-core/card.d.ts +4 -2
  54. package/dist/components-core/card.js +73 -22
  55. package/dist/components-core/collapsible.d.mts +8 -0
  56. package/dist/components-core/collapsible.d.ts +8 -6
  57. package/dist/components-core/collapsible.js +48 -5
  58. package/dist/components-core/container.d.mts +8 -0
  59. package/dist/components-core/container.d.ts +5 -3
  60. package/dist/components-core/container.js +61 -11
  61. package/dist/components-core/dropdown.d.mts +15 -0
  62. package/dist/components-core/dropdown.d.ts +10 -8
  63. package/dist/components-core/dropdown.js +108 -36
  64. package/dist/components-core/index.d.mts +59 -0
  65. package/dist/components-core/index.d.ts +51 -40
  66. package/dist/components-core/index.js +144 -46
  67. package/dist/components-core/input.d.mts +6 -0
  68. package/dist/components-core/input.d.ts +5 -3
  69. package/dist/components-core/input.js +97 -28
  70. package/dist/components-core/label.d.mts +6 -0
  71. package/dist/components-core/label.d.ts +5 -3
  72. package/dist/components-core/label.js +65 -15
  73. package/dist/components-core/link.d.mts +10 -0
  74. package/dist/components-core/link.d.ts +7 -6
  75. package/dist/components-core/link.js +72 -18
  76. package/dist/components-core/loading-indicator.d.mts +13 -0
  77. package/dist/components-core/loading-indicator.d.ts +11 -4
  78. package/dist/components-core/loading-indicator.js +46 -6
  79. package/dist/components-core/popover.d.mts +8 -0
  80. package/dist/components-core/popover.d.ts +8 -6
  81. package/dist/components-core/popover.js +72 -16
  82. package/dist/components-core/separator.d.mts +6 -0
  83. package/dist/components-core/separator.d.ts +5 -3
  84. package/dist/components-core/separator.js +66 -16
  85. package/dist/components-core/skeleton.d.mts +7 -0
  86. package/dist/components-core/skeleton.d.ts +5 -3
  87. package/dist/components-core/skeleton.js +75 -21
  88. package/dist/components-core/tabs.d.mts +9 -0
  89. package/dist/components-core/tabs.d.ts +8 -6
  90. package/dist/components-core/tabs.js +87 -20
  91. package/dist/components-core/text.d.mts +10 -0
  92. package/dist/components-core/text.d.ts +5 -3
  93. package/dist/components-core/text.js +95 -40
  94. package/dist/components-core-joy/button.d.mts +6 -0
  95. package/dist/components-core-joy/button.d.ts +6 -2
  96. package/dist/components-core-joy/button.js +86 -28
  97. package/dist/components-core-joy/input.d.mts +5 -0
  98. package/dist/components-core-joy/input.d.ts +5 -2
  99. package/dist/components-core-joy/input.js +51 -6
  100. package/dist/components-core-joy/separator.d.mts +6 -0
  101. package/dist/components-core-joy/separator.d.ts +6 -2
  102. package/dist/components-core-joy/separator.js +50 -6
  103. package/dist/components-core-joy/tabs.d.mts +9 -0
  104. package/dist/components-core-joy/tabs.d.ts +9 -5
  105. package/dist/components-core-joy/tabs.js +62 -16
  106. package/dist/components-core-joy/text.d.mts +9 -0
  107. package/dist/components-core-joy/text.d.ts +6 -3
  108. package/dist/components-core-joy/text.js +68 -28
  109. package/dist/components-page/account-settings.d.mts +7 -0
  110. package/dist/components-page/account-settings.d.ts +6 -2
  111. package/dist/components-page/account-settings.js +213 -81
  112. package/dist/components-page/auth-page.d.mts +8 -0
  113. package/dist/components-page/auth-page.d.ts +6 -2
  114. package/dist/components-page/auth-page.js +79 -19
  115. package/dist/components-page/email-verification.d.mts +8 -0
  116. package/dist/components-page/email-verification.d.ts +6 -2
  117. package/dist/components-page/email-verification.js +65 -28
  118. package/dist/components-page/forgot-password.d.mts +7 -0
  119. package/dist/components-page/forgot-password.d.ts +6 -2
  120. package/dist/components-page/forgot-password.js +64 -20
  121. package/dist/components-page/magic-link-callback.d.mts +8 -0
  122. package/dist/components-page/magic-link-callback.d.ts +6 -2
  123. package/dist/components-page/magic-link-callback.js +72 -34
  124. package/dist/components-page/oauth-callback.d.mts +5 -0
  125. package/dist/components-page/oauth-callback.d.ts +5 -1
  126. package/dist/components-page/oauth-callback.js +52 -16
  127. package/dist/components-page/password-reset.d.mts +8 -0
  128. package/dist/components-page/password-reset.d.ts +6 -2
  129. package/dist/components-page/password-reset.js +70 -34
  130. package/dist/components-page/sign-in.d.mts +7 -0
  131. package/dist/components-page/sign-in.d.ts +6 -2
  132. package/dist/components-page/sign-in.js +41 -5
  133. package/dist/components-page/sign-out.d.mts +5 -0
  134. package/dist/components-page/sign-out.d.ts +5 -1
  135. package/dist/components-page/sign-out.js +47 -11
  136. package/dist/components-page/sign-up.d.mts +7 -0
  137. package/dist/components-page/sign-up.d.ts +6 -2
  138. package/dist/components-page/sign-up.js +41 -5
  139. package/dist/components-page/stack-handler.d.mts +16 -0
  140. package/dist/components-page/stack-handler.d.ts +11 -3
  141. package/dist/components-page/stack-handler.js +102 -64
  142. package/dist/esm/components/card-frame.js +39 -0
  143. package/dist/esm/components/credential-sign-in.js +82 -0
  144. package/dist/esm/components/credential-sign-up.js +114 -0
  145. package/dist/esm/components/forgot-password.js +55 -0
  146. package/dist/esm/components/form-warning.js +15 -0
  147. package/dist/esm/components/magic-link-sign-in.js +61 -0
  148. package/dist/esm/components/message-card.js +16 -0
  149. package/dist/esm/components/oauth-button.js +124 -0
  150. package/dist/esm/components/oauth-group.js +17 -0
  151. package/dist/esm/components/password-field.js +82 -0
  152. package/dist/esm/components/password-reset-inner.js +93 -0
  153. package/dist/esm/components/redirect-message-card.js +83 -0
  154. package/dist/esm/components/separator-with-text.js +16 -0
  155. package/dist/esm/components/user-avatar.js +14 -0
  156. package/dist/esm/components/user-button.js +133 -0
  157. package/dist/esm/components-core/avatar.js +56 -0
  158. package/dist/esm/components-core/button.js +165 -0
  159. package/dist/esm/components-core/card.js +51 -0
  160. package/dist/esm/components-core/collapsible.js +13 -0
  161. package/dist/esm/components-core/container.js +35 -0
  162. package/dist/esm/components-core/dropdown.js +106 -0
  163. package/dist/esm/components-core/index.js +93 -0
  164. package/dist/esm/components-core/input.js +80 -0
  165. package/dist/esm/components-core/label.js +38 -0
  166. package/dist/esm/components-core/link.js +38 -0
  167. package/dist/esm/components-core/loading-indicator.js +27 -0
  168. package/dist/esm/components-core/popover.js +43 -0
  169. package/dist/esm/components-core/separator.js +36 -0
  170. package/dist/esm/components-core/skeleton.js +52 -0
  171. package/dist/esm/components-core/tabs.js +79 -0
  172. package/dist/esm/components-core/text.js +63 -0
  173. package/dist/esm/components-core-joy/button.js +53 -0
  174. package/dist/esm/components-core-joy/input.js +18 -0
  175. package/dist/esm/components-core-joy/separator.js +17 -0
  176. package/dist/esm/components-core-joy/tabs.js +29 -0
  177. package/dist/esm/components-core-joy/text.js +35 -0
  178. package/dist/esm/components-page/account-settings.js +197 -0
  179. package/dist/esm/components-page/auth-page.js +50 -0
  180. package/dist/esm/components-page/email-verification.js +36 -0
  181. package/dist/esm/components-page/forgot-password.js +35 -0
  182. package/dist/esm/components-page/magic-link-callback.js +43 -0
  183. package/dist/esm/components-page/oauth-callback.js +23 -0
  184. package/dist/esm/components-page/password-reset.js +42 -0
  185. package/dist/esm/components-page/sign-in.js +12 -0
  186. package/dist/esm/components-page/sign-out.js +18 -0
  187. package/dist/esm/components-page/sign-up.js +12 -0
  188. package/dist/esm/components-page/stack-handler.js +75 -0
  189. package/dist/esm/index.js +47 -0
  190. package/dist/esm/joy.js +5 -0
  191. package/dist/esm/lib/auth.js +62 -0
  192. package/dist/esm/lib/cookie.js +185 -0
  193. package/dist/esm/lib/hooks.js +29 -0
  194. package/dist/esm/lib/stack-app.js +940 -0
  195. package/dist/esm/providers/component-provider.js +76 -0
  196. package/dist/esm/providers/design-provider.js +36 -0
  197. package/dist/esm/providers/joy-provider.js +35 -0
  198. package/dist/esm/providers/stack-provider-client.js +31 -0
  199. package/dist/esm/providers/stack-provider.js +21 -0
  200. package/dist/esm/providers/styled-components-registry.js +24 -0
  201. package/dist/esm/providers/theme-provider.js +22 -0
  202. package/dist/esm/utils/browser-script.js +25 -0
  203. package/dist/esm/utils/constants.js +34 -0
  204. package/dist/esm/utils/email.js +10 -0
  205. package/dist/esm/utils/next.js +7 -0
  206. package/dist/esm/utils/url.js +21 -0
  207. package/dist/index.d.mts +37 -0
  208. package/dist/index.d.ts +37 -22
  209. package/dist/index.js +106 -21
  210. package/dist/joy.d.mts +16 -0
  211. package/dist/joy.d.ts +16 -1
  212. package/dist/joy.js +30 -1
  213. package/dist/lib/auth.d.mts +11 -0
  214. package/dist/lib/auth.d.ts +8 -4
  215. package/dist/lib/auth.js +83 -57
  216. package/dist/lib/cookie.d.mts +14 -0
  217. package/dist/lib/cookie.d.ts +8 -6
  218. package/dist/lib/cookie.js +217 -45
  219. package/dist/lib/hooks.d.mts +35 -0
  220. package/dist/lib/hooks.d.ts +14 -8
  221. package/dist/lib/hooks.js +53 -28
  222. package/dist/lib/stack-app.d.mts +227 -0
  223. package/dist/lib/stack-app.d.ts +43 -41
  224. package/dist/lib/stack-app.js +937 -849
  225. package/dist/providers/component-provider.d.mts +113 -0
  226. package/dist/providers/component-provider.d.ts +95 -77
  227. package/dist/providers/component-provider.js +92 -58
  228. package/dist/providers/design-provider.d.mts +34 -0
  229. package/dist/providers/design-provider.d.ts +16 -21
  230. package/dist/providers/design-provider.js +57 -58
  231. package/dist/providers/joy-provider.d.mts +36 -0
  232. package/dist/providers/joy-provider.d.ts +30 -14
  233. package/dist/providers/joy-provider.js +58 -30
  234. package/dist/providers/stack-provider-client.d.mts +20 -0
  235. package/dist/providers/stack-provider-client.d.ts +15 -8
  236. package/dist/providers/stack-provider-client.js +64 -20
  237. package/dist/providers/stack-provider.d.mts +14 -0
  238. package/dist/providers/stack-provider.d.ts +13 -5
  239. package/dist/providers/stack-provider.js +39 -8
  240. package/dist/providers/styled-components-registry.d.mts +8 -0
  241. package/dist/providers/styled-components-registry.d.ts +8 -4
  242. package/dist/providers/styled-components-registry.js +43 -17
  243. package/dist/providers/theme-provider.d.mts +22 -0
  244. package/dist/providers/theme-provider.d.ts +21 -9
  245. package/dist/providers/theme-provider.js +55 -19
  246. package/dist/utils/browser-script.d.mts +5 -0
  247. package/dist/utils/browser-script.d.ts +5 -0
  248. package/dist/utils/browser-script.js +50 -0
  249. package/dist/utils/constants.d.mts +48 -0
  250. package/dist/utils/constants.d.ts +11 -9
  251. package/dist/utils/constants.js +66 -21
  252. package/dist/utils/email.d.mts +3 -0
  253. package/dist/utils/email.d.ts +3 -1
  254. package/dist/utils/email.js +44 -6
  255. package/dist/utils/next.d.mts +3 -0
  256. package/dist/utils/next.d.ts +3 -1
  257. package/dist/utils/next.js +31 -3
  258. package/dist/utils/url.d.mts +4 -0
  259. package/dist/utils/url.d.ts +4 -2
  260. package/dist/utils/url.js +44 -13
  261. package/package.json +20 -10
package/dist/joy.js CHANGED
@@ -1 +1,30 @@
1
- export { StackJoyTheme } from './providers/joy-provider';
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/joy.tsx
21
+ var joy_exports = {};
22
+ __export(joy_exports, {
23
+ StackJoyTheme: () => import_joy_provider.StackJoyTheme
24
+ });
25
+ module.exports = __toCommonJS(joy_exports);
26
+ var import_joy_provider = require("./providers/joy-provider");
27
+ // Annotate the CommonJS export names for ESM import in node:
28
+ 0 && (module.exports = {
29
+ StackJoyTheme
30
+ });
@@ -0,0 +1,11 @@
1
+ import * as oauth4webapi from 'oauth4webapi';
2
+ import { StackClientInterface } from '@stackframe/stack-shared';
3
+ import { TokenStore } from '@stackframe/stack-shared/dist/interface/clientInterface';
4
+
5
+ declare function signInWithOAuth(iface: StackClientInterface, { provider, redirectUrl, }: {
6
+ provider: string;
7
+ redirectUrl?: string;
8
+ }): Promise<void>;
9
+ declare function callOAuthCallback(iface: StackClientInterface, tokenStore: TokenStore, redirectUrl: string): Promise<oauth4webapi.OAuth2TokenEndpointResponse | null>;
10
+
11
+ export { callOAuthCallback, signInWithOAuth };
@@ -1,7 +1,11 @@
1
- import { StackClientInterface } from "@stackframe/stack-shared";
2
- import { TokenStore } from "@stackframe/stack-shared/dist/interface/clientInterface";
3
- export declare function signInWithOAuth(iface: StackClientInterface, { provider, redirectUrl, }: {
1
+ import * as oauth4webapi from 'oauth4webapi';
2
+ import { StackClientInterface } from '@stackframe/stack-shared';
3
+ import { TokenStore } from '@stackframe/stack-shared/dist/interface/clientInterface';
4
+
5
+ declare function signInWithOAuth(iface: StackClientInterface, { provider, redirectUrl, }: {
4
6
  provider: string;
5
7
  redirectUrl?: string;
6
8
  }): Promise<void>;
7
- export declare function callOAuthCallback(iface: StackClientInterface, tokenStore: TokenStore, redirectUrl: string): Promise<import("oauth4webapi").OAuth2TokenEndpointResponse | null>;
9
+ declare function callOAuthCallback(iface: StackClientInterface, tokenStore: TokenStore, redirectUrl: string): Promise<oauth4webapi.OAuth2TokenEndpointResponse | null>;
10
+
11
+ export { callOAuthCallback, signInWithOAuth };
package/dist/lib/auth.js CHANGED
@@ -1,62 +1,88 @@
1
- import { saveVerifierAndState, getVerifierAndState } from "./cookie";
2
- import { constructRedirectUrl } from "../utils/url";
3
- import { neverResolve } from "@stackframe/stack-shared/dist/utils/promises";
4
- import { StackAssertionError } from "@stackframe/stack-shared/dist/utils/errors";
5
- export async function signInWithOAuth(iface, { provider, redirectUrl, }) {
6
- redirectUrl = constructRedirectUrl(redirectUrl);
7
- const { codeChallenge, state } = await saveVerifierAndState();
8
- const location = await iface.getOAuthUrl(provider, redirectUrl, codeChallenge, state);
9
- window.location.assign(location);
10
- await neverResolve();
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/lib/auth.ts
21
+ var auth_exports = {};
22
+ __export(auth_exports, {
23
+ callOAuthCallback: () => callOAuthCallback,
24
+ signInWithOAuth: () => signInWithOAuth
25
+ });
26
+ module.exports = __toCommonJS(auth_exports);
27
+ var import_cookie = require("./cookie");
28
+ var import_url = require("../utils/url");
29
+ var import_promises = require("@stackframe/stack-shared/dist/utils/promises");
30
+ var import_errors = require("@stackframe/stack-shared/dist/utils/errors");
31
+ async function signInWithOAuth(iface, {
32
+ provider,
33
+ redirectUrl
34
+ }) {
35
+ redirectUrl = (0, import_url.constructRedirectUrl)(redirectUrl);
36
+ const { codeChallenge, state } = await (0, import_cookie.saveVerifierAndState)();
37
+ const location = await iface.getOAuthUrl(
38
+ provider,
39
+ redirectUrl,
40
+ codeChallenge,
41
+ state
42
+ );
43
+ window.location.assign(location);
44
+ await (0, import_promises.neverResolve)();
11
45
  }
12
- /**
13
- * Checks if the current URL has the query parameters for an OAuth callback, and if so, removes them.
14
- *
15
- * Must be synchronous for the logic in callOAuthCallback to work without race conditions.
16
- */
17
46
  function consumeOAuthCallbackQueryParams(expectedState) {
18
- const requiredParams = ["code", "state"];
19
- const originalUrl = new URL(window.location.href);
20
- for (const param of requiredParams) {
21
- if (!originalUrl.searchParams.has(param)) {
22
- return null;
23
- }
47
+ const requiredParams = ["code", "state"];
48
+ const originalUrl = new URL(window.location.href);
49
+ for (const param of requiredParams) {
50
+ if (!originalUrl.searchParams.has(param)) {
51
+ return null;
24
52
  }
25
- if (expectedState !== originalUrl.searchParams.get("state")) {
26
- // If the state doesn't match, then the callback wasn't meant for us.
27
- // Maybe the website uses another OAuth library?
28
- return null;
29
- }
30
- const newUrl = new URL(originalUrl);
31
- for (const param of requiredParams) {
32
- newUrl.searchParams.delete(param);
33
- }
34
- // let's get rid of the authorization code in the history as we
35
- // don't redirect to `redirectUrl` if there's a validation error
36
- // (as the redirectUrl might be malicious!).
37
- //
38
- // We use history.replaceState instead of location.assign(...) to
39
- // prevent an unnecessary reload
40
- window.history.replaceState({}, "", newUrl.toString());
41
- return originalUrl;
53
+ }
54
+ if (expectedState !== originalUrl.searchParams.get("state")) {
55
+ return null;
56
+ }
57
+ const newUrl = new URL(originalUrl);
58
+ for (const param of requiredParams) {
59
+ newUrl.searchParams.delete(param);
60
+ }
61
+ window.history.replaceState({}, "", newUrl.toString());
62
+ return originalUrl;
42
63
  }
43
- export async function callOAuthCallback(iface, tokenStore, redirectUrl) {
44
- // note: this part of the function (until the return) needs
45
- // to be synchronous, to prevent race conditions when
46
- // callOAuthCallback is called multiple times in parallel
47
- const { codeVerifier, state } = getVerifierAndState();
48
- if (!codeVerifier || !state) {
49
- throw new Error("Invalid OAuth callback URL parameters. It seems like the OAuth flow was interrupted, so please try again.");
50
- }
51
- const originalUrl = consumeOAuthCallbackQueryParams(state);
52
- if (!originalUrl)
53
- return null;
54
- // the rest can be asynchronous (we now know that we are the
55
- // intended recipient of the callback)
56
- try {
57
- return await iface.callOAuthCallback(originalUrl.searchParams, constructRedirectUrl(redirectUrl), codeVerifier, state, tokenStore);
58
- }
59
- catch (e) {
60
- throw new StackAssertionError("Error signing in during OAuth callback. Please try again.", { cause: e });
61
- }
64
+ async function callOAuthCallback(iface, tokenStore, redirectUrl) {
65
+ const { codeVerifier, state } = (0, import_cookie.getVerifierAndState)();
66
+ if (!codeVerifier || !state) {
67
+ throw new Error("Invalid OAuth callback URL parameters. It seems like the OAuth flow was interrupted, so please try again.");
68
+ }
69
+ const originalUrl = consumeOAuthCallbackQueryParams(state);
70
+ if (!originalUrl)
71
+ return null;
72
+ try {
73
+ return await iface.callOAuthCallback(
74
+ originalUrl.searchParams,
75
+ (0, import_url.constructRedirectUrl)(redirectUrl),
76
+ codeVerifier,
77
+ state,
78
+ tokenStore
79
+ );
80
+ } catch (e) {
81
+ throw new import_errors.StackAssertionError("Error signing in during OAuth callback. Please try again.", { cause: e });
82
+ }
62
83
  }
84
+ // Annotate the CommonJS export names for ESM import in node:
85
+ 0 && (module.exports = {
86
+ callOAuthCallback,
87
+ signInWithOAuth
88
+ });
@@ -0,0 +1,14 @@
1
+ declare function getCookie(name: string): string | null;
2
+ declare function setOrDeleteCookie(name: string, value: string | null): void;
3
+ declare function deleteCookie(name: string): void;
4
+ declare function setCookie(name: string, value: string): void;
5
+ declare function saveVerifierAndState(): Promise<{
6
+ codeChallenge: string;
7
+ state: string;
8
+ }>;
9
+ declare function getVerifierAndState(): {
10
+ codeVerifier: string | null;
11
+ state: string | null;
12
+ };
13
+
14
+ export { deleteCookie, getCookie, getVerifierAndState, saveVerifierAndState, setCookie, setOrDeleteCookie };
@@ -1,12 +1,14 @@
1
- export declare function getCookie(name: string): string | null;
2
- export declare function setOrDeleteCookie(name: string, value: string | null): void;
3
- export declare function deleteCookie(name: string): void;
4
- export declare function setCookie(name: string, value: string): void;
5
- export declare function saveVerifierAndState(): Promise<{
1
+ declare function getCookie(name: string): string | null;
2
+ declare function setOrDeleteCookie(name: string, value: string | null): void;
3
+ declare function deleteCookie(name: string): void;
4
+ declare function setCookie(name: string, value: string): void;
5
+ declare function saveVerifierAndState(): Promise<{
6
6
  codeChallenge: string;
7
7
  state: string;
8
8
  }>;
9
- export declare function getVerifierAndState(): {
9
+ declare function getVerifierAndState(): {
10
10
  codeVerifier: string | null;
11
11
  state: string | null;
12
12
  };
13
+
14
+ export { deleteCookie, getCookie, getVerifierAndState, saveVerifierAndState, setCookie, setOrDeleteCookie };
@@ -1,55 +1,227 @@
1
- import { generateRandomCodeVerifier, generateRandomState, calculatePKCECodeChallenge } from "oauth4webapi";
2
- import Cookies from "js-cookie";
3
- import { cookies as rscCookies } from '@stackframe/stack-sc';
4
- export function getCookie(name) {
5
- // TODO the differentiating factor should be RCC vs. RSC, not whether it's a client
6
- if (rscCookies) {
7
- return rscCookies().get(name)?.value ?? null;
8
- }
9
- else {
10
- return Cookies.get(name) ?? null;
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+
30
+ // src/lib/cookie.ts
31
+ var cookie_exports = {};
32
+ __export(cookie_exports, {
33
+ deleteCookie: () => deleteCookie,
34
+ getCookie: () => getCookie,
35
+ getVerifierAndState: () => getVerifierAndState,
36
+ saveVerifierAndState: () => saveVerifierAndState,
37
+ setCookie: () => setCookie,
38
+ setOrDeleteCookie: () => setOrDeleteCookie
39
+ });
40
+ module.exports = __toCommonJS(cookie_exports);
41
+
42
+ // ../../node_modules/.pnpm/oauth4webapi@2.10.3/node_modules/oauth4webapi/build/index.js
43
+ var USER_AGENT;
44
+ if (typeof navigator === "undefined" || !navigator.userAgent?.startsWith?.("Mozilla/5.0 ")) {
45
+ const NAME = "oauth4webapi";
46
+ const VERSION = "v2.10.3";
47
+ USER_AGENT = `${NAME}/${VERSION}`;
48
+ }
49
+ var clockSkew = Symbol();
50
+ var clockTolerance = Symbol();
51
+ var customFetch = Symbol();
52
+ var useMtlsAlias = Symbol();
53
+ var encoder = new TextEncoder();
54
+ var decoder = new TextDecoder();
55
+ function buf(input) {
56
+ if (typeof input === "string") {
57
+ return encoder.encode(input);
58
+ }
59
+ return decoder.decode(input);
60
+ }
61
+ var CHUNK_SIZE = 32768;
62
+ function encodeBase64Url(input) {
63
+ if (input instanceof ArrayBuffer) {
64
+ input = new Uint8Array(input);
65
+ }
66
+ const arr = [];
67
+ for (let i = 0; i < input.byteLength; i += CHUNK_SIZE) {
68
+ arr.push(String.fromCharCode.apply(null, input.subarray(i, i + CHUNK_SIZE)));
69
+ }
70
+ return btoa(arr.join("")).replace(/=/g, "").replace(/\+/g, "-").replace(/\//g, "_");
71
+ }
72
+ function decodeBase64Url(input) {
73
+ try {
74
+ const binary = atob(input.replace(/-/g, "+").replace(/_/g, "/").replace(/\s/g, ""));
75
+ const bytes = new Uint8Array(binary.length);
76
+ for (let i = 0; i < binary.length; i++) {
77
+ bytes[i] = binary.charCodeAt(i);
11
78
  }
79
+ return bytes;
80
+ } catch (cause) {
81
+ throw new OPE("The input to be decoded is not correctly encoded.", { cause });
82
+ }
12
83
  }
13
- export function setOrDeleteCookie(name, value) {
14
- if (value === null) {
15
- deleteCookie(name);
84
+ function b64u(input) {
85
+ if (typeof input === "string") {
86
+ return decodeBase64Url(input);
87
+ }
88
+ return encodeBase64Url(input);
89
+ }
90
+ var LRU = class {
91
+ constructor(maxSize) {
92
+ this.cache = /* @__PURE__ */ new Map();
93
+ this._cache = /* @__PURE__ */ new Map();
94
+ this.maxSize = maxSize;
95
+ }
96
+ get(key) {
97
+ let v = this.cache.get(key);
98
+ if (v) {
99
+ return v;
16
100
  }
17
- else {
18
- setCookie(name, value);
101
+ if (v = this._cache.get(key)) {
102
+ this.update(key, v);
103
+ return v;
19
104
  }
20
- }
21
- export function deleteCookie(name) {
22
- if (rscCookies) {
23
- rscCookies().delete(name);
105
+ return void 0;
106
+ }
107
+ has(key) {
108
+ return this.cache.has(key) || this._cache.has(key);
109
+ }
110
+ set(key, value) {
111
+ if (this.cache.has(key)) {
112
+ this.cache.set(key, value);
113
+ } else {
114
+ this.update(key, value);
24
115
  }
25
- else {
26
- Cookies.remove(name);
116
+ return this;
117
+ }
118
+ delete(key) {
119
+ if (this.cache.has(key)) {
120
+ return this.cache.delete(key);
27
121
  }
28
- }
29
- export function setCookie(name, value) {
30
- if (rscCookies) {
31
- rscCookies().set(name, value);
122
+ if (this._cache.has(key)) {
123
+ return this._cache.delete(key);
32
124
  }
33
- else {
34
- Cookies.set(name, value, { secure: window.location.protocol === "https:" });
125
+ return false;
126
+ }
127
+ update(key, value) {
128
+ this.cache.set(key, value);
129
+ if (this.cache.size >= this.maxSize) {
130
+ this._cache = this.cache;
131
+ this.cache = /* @__PURE__ */ new Map();
35
132
  }
133
+ }
134
+ };
135
+ var OperationProcessingError = class extends Error {
136
+ constructor(message, options) {
137
+ super(message, options);
138
+ this.name = this.constructor.name;
139
+ Error.captureStackTrace?.(this, this.constructor);
140
+ }
141
+ };
142
+ var OPE = OperationProcessingError;
143
+ var dpopNonces = new LRU(100);
144
+ function validateString(input) {
145
+ return typeof input === "string" && input.length !== 0;
146
+ }
147
+ function randomBytes() {
148
+ return b64u(crypto.getRandomValues(new Uint8Array(32)));
149
+ }
150
+ function generateRandomCodeVerifier() {
151
+ return randomBytes();
152
+ }
153
+ function generateRandomState() {
154
+ return randomBytes();
155
+ }
156
+ async function calculatePKCECodeChallenge(codeVerifier) {
157
+ if (!validateString(codeVerifier)) {
158
+ throw new TypeError('"codeVerifier" must be a non-empty string');
159
+ }
160
+ return b64u(await crypto.subtle.digest("SHA-256", buf(codeVerifier)));
161
+ }
162
+ var skipSubjectCheck = Symbol();
163
+ var expectNoNonce = Symbol();
164
+ var skipAuthTimeCheck = Symbol();
165
+ var noSignatureCheck = Symbol();
166
+ var skipStateCheck = Symbol();
167
+ var expectNoState = Symbol();
168
+
169
+ // src/lib/cookie.ts
170
+ var import_js_cookie = __toESM(require("js-cookie"));
171
+ var import_stack_sc = require("@stackframe/stack-sc");
172
+ function getCookie(name) {
173
+ if (import_stack_sc.cookies) {
174
+ return (0, import_stack_sc.cookies)().get(name)?.value ?? null;
175
+ } else {
176
+ return import_js_cookie.default.get(name) ?? null;
177
+ }
178
+ }
179
+ function setOrDeleteCookie(name, value) {
180
+ if (value === null) {
181
+ deleteCookie(name);
182
+ } else {
183
+ setCookie(name, value);
184
+ }
185
+ }
186
+ function deleteCookie(name) {
187
+ if (import_stack_sc.cookies) {
188
+ (0, import_stack_sc.cookies)().delete(name);
189
+ } else {
190
+ import_js_cookie.default.remove(name);
191
+ }
192
+ }
193
+ function setCookie(name, value) {
194
+ if (import_stack_sc.cookies) {
195
+ (0, import_stack_sc.cookies)().set(name, value);
196
+ } else {
197
+ import_js_cookie.default.set(name, value, { secure: window.location.protocol === "https:" });
198
+ }
199
+ }
200
+ async function saveVerifierAndState() {
201
+ const codeVerifier = generateRandomCodeVerifier();
202
+ const codeChallenge = await calculatePKCECodeChallenge(codeVerifier);
203
+ const state = generateRandomState();
204
+ setCookie("stack-code-verifier", codeVerifier);
205
+ setCookie("stack-state", state);
206
+ return {
207
+ codeChallenge,
208
+ state
209
+ };
36
210
  }
37
- export async function saveVerifierAndState() {
38
- const codeVerifier = generateRandomCodeVerifier();
39
- const codeChallenge = await calculatePKCECodeChallenge(codeVerifier);
40
- const state = generateRandomState();
41
- setCookie("stack-code-verifier", codeVerifier);
42
- setCookie("stack-state", state);
43
- return {
44
- codeChallenge,
45
- state,
46
- };
47
- }
48
- export function getVerifierAndState() {
49
- const codeVerifier = getCookie("stack-code-verifier");
50
- const state = getCookie("stack-state");
51
- return {
52
- codeVerifier,
53
- state,
54
- };
211
+ function getVerifierAndState() {
212
+ const codeVerifier = getCookie("stack-code-verifier");
213
+ const state = getCookie("stack-state");
214
+ return {
215
+ codeVerifier,
216
+ state
217
+ };
55
218
  }
219
+ // Annotate the CommonJS export names for ESM import in node:
220
+ 0 && (module.exports = {
221
+ deleteCookie,
222
+ getCookie,
223
+ getVerifierAndState,
224
+ saveVerifierAndState,
225
+ setCookie,
226
+ setOrDeleteCookie
227
+ });
@@ -0,0 +1,35 @@
1
+ import { CurrentInternalUser, CurrentUser, StackClientApp, GetUserOptions as GetUserOptions$1 } from './stack-app.mjs';
2
+ import '@stackframe/stack-shared';
3
+ import '@stackframe/stack-shared/dist/interface/clientInterface';
4
+ import '@stackframe/stack-shared/dist/utils/json';
5
+ import '@stackframe/stack-shared/dist/interface/adminInterface';
6
+
7
+ /**
8
+ * Returns the current user object. Equivalent to `useStackApp().useUser()`.
9
+ *
10
+ * @returns the current user
11
+ */
12
+ type GetUserOptions = GetUserOptions$1 & {
13
+ projectIdMustMatch?: string;
14
+ };
15
+ declare function useUser(options: GetUserOptions & {
16
+ or: 'redirect' | 'throw';
17
+ projectIdMustMatch: "internal";
18
+ }): CurrentInternalUser;
19
+ declare function useUser(options: GetUserOptions & {
20
+ or: 'redirect' | 'throw';
21
+ }): CurrentUser;
22
+ declare function useUser(options: GetUserOptions & {
23
+ projectIdMustMatch: "internal";
24
+ }): CurrentInternalUser | null;
25
+ declare function useUser(options?: GetUserOptions): CurrentUser | CurrentInternalUser | null;
26
+ /**
27
+ * Returns the current Stack app associated with the StackProvider.
28
+ *
29
+ * @returns the current Stack app
30
+ */
31
+ declare function useStackApp<ProjectId extends string>(options?: {
32
+ projectIdMustMatch?: ProjectId;
33
+ }): StackClientApp<true, ProjectId>;
34
+
35
+ export { useStackApp, useUser };
@@ -1,29 +1,35 @@
1
- import { CurrentUser, GetUserOptions as AppGetUserOptions, StackClientApp, CurrentInternalUser } from "./stack-app";
1
+ import { CurrentInternalUser, CurrentUser, StackClientApp, GetUserOptions as GetUserOptions$1 } from './stack-app.js';
2
+ import '@stackframe/stack-shared';
3
+ import '@stackframe/stack-shared/dist/interface/clientInterface';
4
+ import '@stackframe/stack-shared/dist/utils/json';
5
+ import '@stackframe/stack-shared/dist/interface/adminInterface';
6
+
2
7
  /**
3
8
  * Returns the current user object. Equivalent to `useStackApp().useUser()`.
4
9
  *
5
10
  * @returns the current user
6
11
  */
7
- type GetUserOptions = AppGetUserOptions & {
12
+ type GetUserOptions = GetUserOptions$1 & {
8
13
  projectIdMustMatch?: string;
9
14
  };
10
- export declare function useUser(options: GetUserOptions & {
15
+ declare function useUser(options: GetUserOptions & {
11
16
  or: 'redirect' | 'throw';
12
17
  projectIdMustMatch: "internal";
13
18
  }): CurrentInternalUser;
14
- export declare function useUser(options: GetUserOptions & {
19
+ declare function useUser(options: GetUserOptions & {
15
20
  or: 'redirect' | 'throw';
16
21
  }): CurrentUser;
17
- export declare function useUser(options: GetUserOptions & {
22
+ declare function useUser(options: GetUserOptions & {
18
23
  projectIdMustMatch: "internal";
19
24
  }): CurrentInternalUser | null;
20
- export declare function useUser(options?: GetUserOptions): CurrentUser | CurrentInternalUser | null;
25
+ declare function useUser(options?: GetUserOptions): CurrentUser | CurrentInternalUser | null;
21
26
  /**
22
27
  * Returns the current Stack app associated with the StackProvider.
23
28
  *
24
29
  * @returns the current Stack app
25
30
  */
26
- export declare function useStackApp<ProjectId extends string>(options?: {
31
+ declare function useStackApp<ProjectId extends string>(options?: {
27
32
  projectIdMustMatch?: ProjectId;
28
33
  }): StackClientApp<true, ProjectId>;
29
- export {};
34
+
35
+ export { useStackApp, useUser };