@stackframe/react 2.8.56 → 2.8.59

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 (250) hide show
  1. package/dist/components/api-key-dialogs.js.map +1 -1
  2. package/dist/components/api-key-table.js.map +1 -1
  3. package/dist/components/credential-sign-in.js.map +1 -1
  4. package/dist/components/credential-sign-up.js.map +1 -1
  5. package/dist/components/elements/form-warning.js.map +1 -1
  6. package/dist/components/elements/maybe-full-page.js.map +1 -1
  7. package/dist/components/elements/separator-with-text.js.map +1 -1
  8. package/dist/components/elements/sidebar-layout.js.map +1 -1
  9. package/dist/components/elements/ssr-layout-effect.js.map +1 -1
  10. package/dist/components/elements/user-avatar.js.map +1 -1
  11. package/dist/components/link.js.map +1 -1
  12. package/dist/components/magic-link-sign-in.js.map +1 -1
  13. package/dist/components/message-cards/known-error-message-card.js.map +1 -1
  14. package/dist/components/message-cards/message-card.js.map +1 -1
  15. package/dist/components/message-cards/predefined-message-card.js.map +1 -1
  16. package/dist/components/oauth-button-group.js.map +1 -1
  17. package/dist/components/oauth-button.js.map +1 -1
  18. package/dist/components/passkey-button.js.map +1 -1
  19. package/dist/components/profile-image-editor.js.map +1 -1
  20. package/dist/components/selected-team-switcher.js.map +1 -1
  21. package/dist/components/team-icon.js.map +1 -1
  22. package/dist/components/team-switcher.js.map +1 -1
  23. package/dist/components/use-in-iframe.js.map +1 -1
  24. package/dist/components/user-button.js.map +1 -1
  25. package/dist/components-page/account-settings/active-sessions/active-sessions-page.js.map +1 -1
  26. package/dist/components-page/account-settings/api-keys/api-keys-page.js.map +1 -1
  27. package/dist/components-page/account-settings/editable-text.js.map +1 -1
  28. package/dist/components-page/account-settings/email-and-auth/email-and-auth-page.js.map +1 -1
  29. package/dist/components-page/account-settings/email-and-auth/emails-section.js +4 -3
  30. package/dist/components-page/account-settings/email-and-auth/emails-section.js.map +1 -1
  31. package/dist/components-page/account-settings/email-and-auth/mfa-section.js.map +1 -1
  32. package/dist/components-page/account-settings/email-and-auth/otp-section.js.map +1 -1
  33. package/dist/components-page/account-settings/email-and-auth/passkey-section.js.map +1 -1
  34. package/dist/components-page/account-settings/email-and-auth/password-section.js.map +1 -1
  35. package/dist/components-page/account-settings/notifications/notifications-page.js.map +1 -1
  36. package/dist/components-page/account-settings/page-layout.js.map +1 -1
  37. package/dist/components-page/account-settings/payments/payments-page.js +79 -0
  38. package/dist/components-page/account-settings/payments/payments-page.js.map +1 -0
  39. package/dist/components-page/account-settings/payments/payments-panel.js +374 -0
  40. package/dist/components-page/account-settings/payments/payments-panel.js.map +1 -0
  41. package/dist/components-page/account-settings/profile-page/profile-page.js.map +1 -1
  42. package/dist/components-page/account-settings/section.js.map +1 -1
  43. package/dist/components-page/account-settings/settings/delete-account-section.js.map +1 -1
  44. package/dist/components-page/account-settings/settings/settings-page.js.map +1 -1
  45. package/dist/components-page/account-settings/settings/sign-out-section.js.map +1 -1
  46. package/dist/components-page/account-settings/teams/leave-team-section.js.map +1 -1
  47. package/dist/components-page/account-settings/teams/team-api-keys-section.js.map +1 -1
  48. package/dist/components-page/account-settings/teams/team-creation-page.js.map +1 -1
  49. package/dist/components-page/account-settings/teams/team-display-name-section.js.map +1 -1
  50. package/dist/components-page/account-settings/teams/team-member-invitation-section.js.map +1 -1
  51. package/dist/components-page/account-settings/teams/team-member-list-section.js.map +1 -1
  52. package/dist/components-page/account-settings/teams/team-page.js.map +1 -1
  53. package/dist/components-page/account-settings/teams/team-profile-image-section.js.map +1 -1
  54. package/dist/components-page/account-settings/teams/team-profile-user-section.js.map +1 -1
  55. package/dist/components-page/account-settings.js +22 -2
  56. package/dist/components-page/account-settings.js.map +1 -1
  57. package/dist/components-page/auth-page.js.map +1 -1
  58. package/dist/components-page/cli-auth-confirm.js.map +1 -1
  59. package/dist/components-page/email-verification.js.map +1 -1
  60. package/dist/components-page/error-page.js.map +1 -1
  61. package/dist/components-page/forgot-password.js.map +1 -1
  62. package/dist/components-page/magic-link-callback.js.map +1 -1
  63. package/dist/components-page/mfa.js.map +1 -1
  64. package/dist/components-page/oauth-callback.js.map +1 -1
  65. package/dist/components-page/onboarding.js +170 -0
  66. package/dist/components-page/onboarding.js.map +1 -0
  67. package/dist/components-page/password-reset.js.map +1 -1
  68. package/dist/components-page/section.js.map +1 -1
  69. package/dist/components-page/sign-in.js.map +1 -1
  70. package/dist/components-page/sign-out.js.map +1 -1
  71. package/dist/components-page/sign-up.js.map +1 -1
  72. package/dist/components-page/stack-handler-client.js +13 -1
  73. package/dist/components-page/stack-handler-client.js.map +1 -1
  74. package/dist/components-page/stack-handler.js.map +1 -1
  75. package/dist/components-page/team-creation.js.map +1 -1
  76. package/dist/components-page/team-invitation.js +15 -1
  77. package/dist/components-page/team-invitation.js.map +1 -1
  78. package/dist/esm/components/api-key-dialogs.js.map +1 -1
  79. package/dist/esm/components/api-key-table.js.map +1 -1
  80. package/dist/esm/components/credential-sign-in.js.map +1 -1
  81. package/dist/esm/components/credential-sign-up.js.map +1 -1
  82. package/dist/esm/components/elements/form-warning.js.map +1 -1
  83. package/dist/esm/components/elements/maybe-full-page.js.map +1 -1
  84. package/dist/esm/components/elements/separator-with-text.js.map +1 -1
  85. package/dist/esm/components/elements/sidebar-layout.js.map +1 -1
  86. package/dist/esm/components/elements/ssr-layout-effect.js.map +1 -1
  87. package/dist/esm/components/elements/user-avatar.js.map +1 -1
  88. package/dist/esm/components/link.js.map +1 -1
  89. package/dist/esm/components/magic-link-sign-in.js.map +1 -1
  90. package/dist/esm/components/message-cards/known-error-message-card.js.map +1 -1
  91. package/dist/esm/components/message-cards/message-card.js.map +1 -1
  92. package/dist/esm/components/message-cards/predefined-message-card.js.map +1 -1
  93. package/dist/esm/components/oauth-button-group.js.map +1 -1
  94. package/dist/esm/components/oauth-button.js.map +1 -1
  95. package/dist/esm/components/passkey-button.js.map +1 -1
  96. package/dist/esm/components/profile-image-editor.js.map +1 -1
  97. package/dist/esm/components/selected-team-switcher.js.map +1 -1
  98. package/dist/esm/components/team-icon.js.map +1 -1
  99. package/dist/esm/components/team-switcher.js.map +1 -1
  100. package/dist/esm/components/use-in-iframe.js.map +1 -1
  101. package/dist/esm/components/user-button.js.map +1 -1
  102. package/dist/esm/components-page/account-settings/active-sessions/active-sessions-page.js.map +1 -1
  103. package/dist/esm/components-page/account-settings/api-keys/api-keys-page.js.map +1 -1
  104. package/dist/esm/components-page/account-settings/editable-text.js.map +1 -1
  105. package/dist/esm/components-page/account-settings/email-and-auth/email-and-auth-page.js.map +1 -1
  106. package/dist/esm/components-page/account-settings/email-and-auth/emails-section.js +4 -3
  107. package/dist/esm/components-page/account-settings/email-and-auth/emails-section.js.map +1 -1
  108. package/dist/esm/components-page/account-settings/email-and-auth/mfa-section.js.map +1 -1
  109. package/dist/esm/components-page/account-settings/email-and-auth/otp-section.js.map +1 -1
  110. package/dist/esm/components-page/account-settings/email-and-auth/passkey-section.js.map +1 -1
  111. package/dist/esm/components-page/account-settings/email-and-auth/password-section.js.map +1 -1
  112. package/dist/esm/components-page/account-settings/notifications/notifications-page.js.map +1 -1
  113. package/dist/esm/components-page/account-settings/page-layout.js.map +1 -1
  114. package/dist/esm/components-page/account-settings/payments/payments-page.js +55 -0
  115. package/dist/esm/components-page/account-settings/payments/payments-page.js.map +1 -0
  116. package/dist/esm/components-page/account-settings/payments/payments-panel.js +350 -0
  117. package/dist/esm/components-page/account-settings/payments/payments-panel.js.map +1 -0
  118. package/dist/esm/components-page/account-settings/profile-page/profile-page.js.map +1 -1
  119. package/dist/esm/components-page/account-settings/section.js.map +1 -1
  120. package/dist/esm/components-page/account-settings/settings/delete-account-section.js.map +1 -1
  121. package/dist/esm/components-page/account-settings/settings/settings-page.js.map +1 -1
  122. package/dist/esm/components-page/account-settings/settings/sign-out-section.js.map +1 -1
  123. package/dist/esm/components-page/account-settings/teams/leave-team-section.js.map +1 -1
  124. package/dist/esm/components-page/account-settings/teams/team-api-keys-section.js.map +1 -1
  125. package/dist/esm/components-page/account-settings/teams/team-creation-page.js.map +1 -1
  126. package/dist/esm/components-page/account-settings/teams/team-display-name-section.js.map +1 -1
  127. package/dist/esm/components-page/account-settings/teams/team-member-invitation-section.js.map +1 -1
  128. package/dist/esm/components-page/account-settings/teams/team-member-list-section.js.map +1 -1
  129. package/dist/esm/components-page/account-settings/teams/team-page.js.map +1 -1
  130. package/dist/esm/components-page/account-settings/teams/team-profile-image-section.js.map +1 -1
  131. package/dist/esm/components-page/account-settings/teams/team-profile-user-section.js.map +1 -1
  132. package/dist/esm/components-page/account-settings.js +23 -3
  133. package/dist/esm/components-page/account-settings.js.map +1 -1
  134. package/dist/esm/components-page/auth-page.js.map +1 -1
  135. package/dist/esm/components-page/cli-auth-confirm.js.map +1 -1
  136. package/dist/esm/components-page/email-verification.js.map +1 -1
  137. package/dist/esm/components-page/error-page.js.map +1 -1
  138. package/dist/esm/components-page/forgot-password.js.map +1 -1
  139. package/dist/esm/components-page/magic-link-callback.js.map +1 -1
  140. package/dist/esm/components-page/mfa.js.map +1 -1
  141. package/dist/esm/components-page/oauth-callback.js.map +1 -1
  142. package/dist/esm/components-page/onboarding.js +146 -0
  143. package/dist/esm/components-page/onboarding.js.map +1 -0
  144. package/dist/esm/components-page/password-reset.js.map +1 -1
  145. package/dist/esm/components-page/section.js.map +1 -1
  146. package/dist/esm/components-page/sign-in.js.map +1 -1
  147. package/dist/esm/components-page/sign-out.js.map +1 -1
  148. package/dist/esm/components-page/sign-up.js.map +1 -1
  149. package/dist/esm/components-page/stack-handler-client.js +13 -1
  150. package/dist/esm/components-page/stack-handler-client.js.map +1 -1
  151. package/dist/esm/components-page/stack-handler.js.map +1 -1
  152. package/dist/esm/components-page/team-creation.js.map +1 -1
  153. package/dist/esm/components-page/team-invitation.js +15 -1
  154. package/dist/esm/components-page/team-invitation.js.map +1 -1
  155. package/dist/esm/generated/global-css.js +1 -1
  156. package/dist/esm/generated/global-css.js.map +1 -1
  157. package/dist/esm/generated/quetzal-translations.js.map +1 -1
  158. package/dist/esm/index.js.map +1 -1
  159. package/dist/esm/integrations/convex/component/convex.config.js.map +1 -1
  160. package/dist/esm/integrations/convex.js.map +1 -1
  161. package/dist/esm/lib/auth.js.map +1 -1
  162. package/dist/esm/lib/cookie.js.map +1 -1
  163. package/dist/esm/lib/hooks.js.map +1 -1
  164. package/dist/esm/lib/stack-app/api-keys/index.js.map +1 -1
  165. package/dist/esm/lib/stack-app/apps/implementations/admin-app-impl.js +235 -0
  166. package/dist/esm/lib/stack-app/apps/implementations/admin-app-impl.js.map +1 -1
  167. package/dist/esm/lib/stack-app/apps/implementations/client-app-impl.js +210 -29
  168. package/dist/esm/lib/stack-app/apps/implementations/client-app-impl.js.map +1 -1
  169. package/dist/esm/lib/stack-app/apps/implementations/common.js +2 -1
  170. package/dist/esm/lib/stack-app/apps/implementations/common.js.map +1 -1
  171. package/dist/esm/lib/stack-app/apps/implementations/index.js.map +1 -1
  172. package/dist/esm/lib/stack-app/apps/implementations/server-app-impl.js +40 -27
  173. package/dist/esm/lib/stack-app/apps/implementations/server-app-impl.js.map +1 -1
  174. package/dist/esm/lib/stack-app/apps/index.js.map +1 -1
  175. package/dist/esm/lib/stack-app/apps/interfaces/admin-app.js.map +1 -1
  176. package/dist/esm/lib/stack-app/apps/interfaces/client-app.js.map +1 -1
  177. package/dist/esm/lib/stack-app/apps/interfaces/server-app.js.map +1 -1
  178. package/dist/esm/lib/stack-app/common.js.map +1 -1
  179. package/dist/esm/lib/stack-app/contact-channels/index.js.map +1 -1
  180. package/dist/esm/lib/stack-app/email-templates/index.js.map +1 -1
  181. package/dist/esm/lib/stack-app/index.js.map +1 -1
  182. package/dist/esm/lib/stack-app/internal-api-keys/index.js.map +1 -1
  183. package/dist/esm/lib/stack-app/permissions/index.js.map +1 -1
  184. package/dist/esm/lib/stack-app/projects/index.js +4 -0
  185. package/dist/esm/lib/stack-app/projects/index.js.map +1 -1
  186. package/dist/esm/lib/stack-app/teams/index.js.map +1 -1
  187. package/dist/esm/lib/stack-app/users/index.js +13 -12
  188. package/dist/esm/lib/stack-app/users/index.js.map +1 -1
  189. package/dist/esm/lib/translations.js.map +1 -1
  190. package/dist/esm/providers/stack-provider-client.js.map +1 -1
  191. package/dist/esm/providers/stack-provider.js.map +1 -1
  192. package/dist/esm/providers/theme-provider.js.map +1 -1
  193. package/dist/esm/providers/translation-provider-client.js.map +1 -1
  194. package/dist/esm/providers/translation-provider.js.map +1 -1
  195. package/dist/esm/utils/browser-script.js.map +1 -1
  196. package/dist/esm/utils/constants.js.map +1 -1
  197. package/dist/esm/utils/url.js.map +1 -1
  198. package/dist/generated/global-css.js +1 -1
  199. package/dist/generated/global-css.js.map +1 -1
  200. package/dist/generated/quetzal-translations.js.map +1 -1
  201. package/dist/index.d.mts +306 -17
  202. package/dist/index.d.ts +306 -17
  203. package/dist/index.js.map +1 -1
  204. package/dist/integrations/convex/component/convex.config.js.map +1 -1
  205. package/dist/integrations/convex.js.map +1 -1
  206. package/dist/lib/auth.js.map +1 -1
  207. package/dist/lib/cookie.js.map +1 -1
  208. package/dist/lib/hooks.js.map +1 -1
  209. package/dist/lib/stack-app/api-keys/index.js.map +1 -1
  210. package/dist/lib/stack-app/apps/implementations/admin-app-impl.js +235 -0
  211. package/dist/lib/stack-app/apps/implementations/admin-app-impl.js.map +1 -1
  212. package/dist/lib/stack-app/apps/implementations/client-app-impl.js +208 -27
  213. package/dist/lib/stack-app/apps/implementations/client-app-impl.js.map +1 -1
  214. package/dist/lib/stack-app/apps/implementations/common.js +2 -1
  215. package/dist/lib/stack-app/apps/implementations/common.js.map +1 -1
  216. package/dist/lib/stack-app/apps/implementations/index.js.map +1 -1
  217. package/dist/lib/stack-app/apps/implementations/server-app-impl.js +38 -25
  218. package/dist/lib/stack-app/apps/implementations/server-app-impl.js.map +1 -1
  219. package/dist/lib/stack-app/apps/index.js.map +1 -1
  220. package/dist/lib/stack-app/apps/interfaces/admin-app.js.map +1 -1
  221. package/dist/lib/stack-app/apps/interfaces/client-app.js.map +1 -1
  222. package/dist/lib/stack-app/apps/interfaces/server-app.js.map +1 -1
  223. package/dist/lib/stack-app/common.js.map +1 -1
  224. package/dist/lib/stack-app/connected-accounts/index.js.map +1 -1
  225. package/dist/lib/stack-app/contact-channels/index.js.map +1 -1
  226. package/dist/lib/stack-app/customers/index.js.map +1 -1
  227. package/dist/lib/stack-app/data-vault/index.js.map +1 -1
  228. package/dist/lib/stack-app/email/index.js.map +1 -1
  229. package/dist/lib/stack-app/email-templates/index.js.map +1 -1
  230. package/dist/lib/stack-app/index.js.map +1 -1
  231. package/dist/lib/stack-app/internal-api-keys/index.js.map +1 -1
  232. package/dist/lib/stack-app/notification-categories/index.js.map +1 -1
  233. package/dist/lib/stack-app/permissions/index.js.map +1 -1
  234. package/dist/lib/stack-app/project-configs/index.js.map +1 -1
  235. package/dist/lib/stack-app/projects/index.js +4 -0
  236. package/dist/lib/stack-app/projects/index.js.map +1 -1
  237. package/dist/lib/stack-app/teams/index.js.map +1 -1
  238. package/dist/lib/stack-app/users/index.js +15 -14
  239. package/dist/lib/stack-app/users/index.js.map +1 -1
  240. package/dist/lib/translations.js.map +1 -1
  241. package/dist/providers/stack-provider-client.js.map +1 -1
  242. package/dist/providers/stack-provider.js.map +1 -1
  243. package/dist/providers/theme-provider.js.map +1 -1
  244. package/dist/providers/translation-provider-client.js.map +1 -1
  245. package/dist/providers/translation-provider.js.map +1 -1
  246. package/dist/utils/browser-script.js.map +1 -1
  247. package/dist/utils/constants.js.map +1 -1
  248. package/dist/utils/url.js.map +1 -1
  249. package/package.json +19 -16
  250. package/CHANGELOG.md +0 -2072
@@ -9,7 +9,7 @@ import { parseJson } from "@stackframe/stack-shared/dist/utils/json";
9
9
  import { DependenciesMap } from "@stackframe/stack-shared/dist/utils/maps";
10
10
  import { deepPlainEquals, omit } from "@stackframe/stack-shared/dist/utils/objects";
11
11
  import { neverResolve, runAsynchronously, wait } from "@stackframe/stack-shared/dist/utils/promises";
12
- import { suspend, suspendIfSsr } from "@stackframe/stack-shared/dist/utils/react";
12
+ import { suspend, suspendIfSsr, use } from "@stackframe/stack-shared/dist/utils/react";
13
13
  import { Result } from "@stackframe/stack-shared/dist/utils/results";
14
14
  import { Store, storeLock } from "@stackframe/stack-shared/dist/utils/stores";
15
15
  import { deindent, mergeScopeStrings } from "@stackframe/stack-shared/dist/utils/strings";
@@ -25,7 +25,7 @@ import { stackAppInternalsSymbol } from "../../common.js";
25
25
  import { contactChannelCreateOptionsToCrud, contactChannelUpdateOptionsToCrud } from "../../contact-channels/index.js";
26
26
  import { adminProjectCreateOptionsToCrud } from "../../projects/index.js";
27
27
  import { teamCreateOptionsToCrud, teamUpdateOptionsToCrud } from "../../teams/index.js";
28
- import { attachUserDestructureGuard, userUpdateOptionsToCrud } from "../../users/index.js";
28
+ import { userUpdateOptionsToCrud, withUserDestructureGuard } from "../../users/index.js";
29
29
  import { clientVersion, createCache, createCacheBySession, createEmptyTokenStore, getBaseUrl, getDefaultExtraRequestHeaders, getDefaultProjectId, getDefaultPublishableClientKey, getUrls, resolveConstructorOptions } from "./common.js";
30
30
  import { useAsyncCache } from "./common.js";
31
31
  var isReactServer = false;
@@ -174,6 +174,11 @@ var __StackClientAppImplIncomplete = class __StackClientAppImplIncomplete {
174
174
  }, session);
175
175
  }
176
176
  );
177
+ this._customerBillingCache = createCacheBySession(
178
+ async (session, [customerType, customerId]) => {
179
+ return await this._interface.getCustomerBilling(customerType, customerId, session);
180
+ }
181
+ );
177
182
  this._convexPartialUserCache = createCache(
178
183
  async ([ctx]) => await this._getPartialUserFromConvex(ctx)
179
184
  );
@@ -408,7 +413,7 @@ var __StackClientAppImplIncomplete = class __StackClientAppImplIncomplete {
408
413
  if (!isBrowserLike()) {
409
414
  throw new StackAssertionError("Cannot get browser cookies on the server!");
410
415
  }
411
- return cookie.parse(document.cookie || "");
416
+ return cookie.parseCookie(document.cookie || "");
412
417
  }
413
418
  _getRefreshTokenCookieNamePatterns() {
414
419
  return {
@@ -606,7 +611,7 @@ var __StackClientAppImplIncomplete = class __StackClientAppImplIncomplete {
606
611
  });
607
612
  }
608
613
  const cookieHeader = tokenStoreInit.headers.get("cookie");
609
- const parsed = cookie.parse(cookieHeader || "");
614
+ const parsed = cookie.parseCookie(cookieHeader || "");
610
615
  const res = new Store(this._getTokensFromCookies(parsed));
611
616
  this._requestTokenStores.set(tokenStoreInit, res);
612
617
  return res;
@@ -927,32 +932,92 @@ var __StackClientAppImplIncomplete = class __StackClientAppImplIncomplete {
927
932
  displayName: item.product.display_name,
928
933
  customerType: item.product.customer_type,
929
934
  isServerOnly: item.product.server_only,
930
- stackable: item.product.stackable
935
+ stackable: item.product.stackable,
936
+ type: item.type,
937
+ subscription: item.subscription ? {
938
+ currentPeriodEnd: item.subscription.current_period_end ? new Date(item.subscription.current_period_end) : null,
939
+ cancelAtPeriodEnd: item.subscription.cancel_at_period_end,
940
+ isCancelable: item.subscription.is_cancelable
941
+ } : null,
942
+ switchOptions: item.switch_options?.map((option) => ({
943
+ productId: option.product_id,
944
+ displayName: option.product.display_name,
945
+ prices: option.product.prices
946
+ }))
931
947
  }));
932
948
  return Object.assign(products, { nextCursor: response.pagination.next_cursor ?? null });
933
949
  }
950
+ _customerBillingFromResponse(response) {
951
+ return {
952
+ hasCustomer: response.has_customer,
953
+ defaultPaymentMethod: response.default_payment_method
954
+ };
955
+ }
934
956
  _createAuth(session) {
935
957
  const app = this;
936
958
  return {
937
959
  _internalSession: session,
938
960
  currentSession: {
939
961
  async getTokens() {
940
- const tokens = await session.getOrFetchLikelyValidTokens(2e4);
962
+ const tokens = await session.getOrFetchLikelyValidTokens(2e4, 75e3);
941
963
  return {
942
964
  accessToken: tokens?.accessToken.token ?? null,
943
965
  refreshToken: tokens?.refreshToken?.token ?? null
944
966
  };
967
+ },
968
+ useTokens() {
969
+ const [_, setCounter] = React.useState(0);
970
+ React.useEffect(() => {
971
+ const { unsubscribe: unsubscribeRefresh } = session.startRefreshingAccessToken(3e4, 6e4);
972
+ const { unsubscribe: unsubscribeInvalidate } = session.onInvalidate(() => setCounter((c) => c + 1));
973
+ const { unsubscribe: unsubscribeAccessTokenChange } = session.onAccessTokenChange(() => setCounter((c) => c + 1));
974
+ return () => {
975
+ unsubscribeRefresh();
976
+ unsubscribeInvalidate();
977
+ unsubscribeAccessTokenChange();
978
+ };
979
+ }, []);
980
+ let accessToken = session.isKnownToBeInvalid() ? null : session.getAccessTokenIfNotExpiredYet(2e4, 75e3);
981
+ if (accessToken === null) {
982
+ accessToken = use(session.getOrFetchLikelyValidTokens(2e4, 75e3))?.accessToken ?? null;
983
+ }
984
+ return {
985
+ accessToken: accessToken?.token ?? null,
986
+ refreshToken: session.getRefreshToken()?.token ?? null
987
+ };
945
988
  }
946
989
  },
990
+ async getAccessToken() {
991
+ const tokens = await this.currentSession.getTokens();
992
+ return tokens.accessToken;
993
+ },
994
+ useAccessToken() {
995
+ return this.currentSession.useTokens().accessToken;
996
+ },
997
+ async getRefreshToken() {
998
+ const tokens = await this.currentSession.getTokens();
999
+ return tokens.refreshToken;
1000
+ },
1001
+ useRefreshToken() {
1002
+ return this.currentSession.useTokens().refreshToken;
1003
+ },
947
1004
  async getAuthHeaders() {
948
1005
  return {
949
1006
  "x-stack-auth": JSON.stringify(await this.getAuthJson())
950
1007
  };
951
1008
  },
1009
+ useAuthHeaders() {
1010
+ return {
1011
+ "x-stack-auth": JSON.stringify(this.useAuthJson())
1012
+ };
1013
+ },
952
1014
  async getAuthJson() {
953
1015
  const tokens = await this.currentSession.getTokens();
954
1016
  return tokens;
955
1017
  },
1018
+ useAuthJson() {
1019
+ return this.currentSession.useTokens();
1020
+ },
956
1021
  signOut(options) {
957
1022
  return app._signOut(session, options);
958
1023
  }
@@ -993,6 +1058,8 @@ var __StackClientAppImplIncomplete = class __StackClientAppImplIncomplete {
993
1058
  passkeyAuthEnabled: crud.passkey_auth_enabled,
994
1059
  isMultiFactorRequired: crud.requires_totp_mfa,
995
1060
  isAnonymous: crud.is_anonymous,
1061
+ isRestricted: crud.is_restricted,
1062
+ restrictedReason: crud.restricted_reason,
996
1063
  toClientJson() {
997
1064
  return crud;
998
1065
  }
@@ -1023,7 +1090,7 @@ var __StackClientAppImplIncomplete = class __StackClientAppImplIncomplete {
1023
1090
  return this.update({ clientMetadata: metadata });
1024
1091
  },
1025
1092
  async setSelectedTeam(team) {
1026
- await this.update({ selectedTeamId: team?.id ?? null });
1093
+ await this.update({ selectedTeamId: typeof team === "string" ? team : team?.id ?? null });
1027
1094
  },
1028
1095
  getConnectedAccount,
1029
1096
  useConnectedAccount,
@@ -1254,8 +1321,29 @@ var __StackClientAppImplIncomplete = class __StackClientAppImplIncomplete {
1254
1321
  }
1255
1322
  _createCustomer(userIdOrTeamId, type, session) {
1256
1323
  const app = this;
1324
+ const effectiveSession = session ?? app._interface.createSession({ refreshToken: null });
1257
1325
  const customerOptions = type === "user" ? { userId: userIdOrTeamId } : { teamId: userIdOrTeamId };
1258
1326
  return {
1327
+ async getBilling() {
1328
+ const response = Result.orThrow(await app._customerBillingCache.getOrWait([effectiveSession, type, userIdOrTeamId], "write-only"));
1329
+ return app._customerBillingFromResponse(response);
1330
+ },
1331
+ useBilling() {
1332
+ const response = useAsyncCache(app._customerBillingCache, [effectiveSession, type, userIdOrTeamId], "customer.useBilling()");
1333
+ return app._customerBillingFromResponse(response);
1334
+ },
1335
+ async createPaymentMethodSetupIntent() {
1336
+ const body = await app._interface.createCustomerPaymentMethodSetupIntent(type, userIdOrTeamId, effectiveSession);
1337
+ return {
1338
+ clientSecret: body.client_secret,
1339
+ stripeAccountId: body.stripe_account_id
1340
+ };
1341
+ },
1342
+ async setDefaultPaymentMethodFromSetupIntent(setupIntentId) {
1343
+ const body = await app._interface.setDefaultCustomerPaymentMethodFromSetupIntent(type, userIdOrTeamId, setupIntentId, effectiveSession);
1344
+ await app._customerBillingCache.refresh([effectiveSession, type, userIdOrTeamId]);
1345
+ return body.default_payment_method;
1346
+ },
1259
1347
  async getItem(itemId) {
1260
1348
  return await app.getItem({ itemId, ...customerOptions });
1261
1349
  },
@@ -1269,7 +1357,23 @@ var __StackClientAppImplIncomplete = class __StackClientAppImplIncomplete {
1269
1357
  return app.useProducts({ ...options, ...customerOptions });
1270
1358
  },
1271
1359
  async createCheckoutUrl(options) {
1272
- return await app._interface.createCheckoutUrl(type, userIdOrTeamId, options.productId, session, options.returnUrl);
1360
+ return await app._interface.createCheckoutUrl(type, userIdOrTeamId, options.productId, effectiveSession, options.returnUrl);
1361
+ },
1362
+ async switchSubscription(options) {
1363
+ await app._interface.switchSubscription({
1364
+ customer_type: type,
1365
+ customer_id: userIdOrTeamId,
1366
+ from_product_id: options.fromProductId,
1367
+ to_product_id: options.toProductId,
1368
+ price_id: options.priceId,
1369
+ quantity: options.quantity
1370
+ }, effectiveSession);
1371
+ await app._customerBillingCache.refresh([effectiveSession, type, userIdOrTeamId]);
1372
+ if (type === "user") {
1373
+ await app._userProductsCache.invalidateWhere(([cachedSession, userId]) => cachedSession === effectiveSession && userId === userIdOrTeamId);
1374
+ } else {
1375
+ await app._teamProductsCache.invalidateWhere(([cachedSession, teamId]) => cachedSession === effectiveSession && teamId === userIdOrTeamId);
1376
+ }
1273
1377
  }
1274
1378
  };
1275
1379
  }
@@ -1303,6 +1407,25 @@ var __StackClientAppImplIncomplete = class __StackClientAppImplIncomplete {
1303
1407
  const response = Result.orThrow(await this._customProductsCache.getOrWait([session, options.customCustomerId, options.cursor ?? null, options.limit ?? null], "write-only"));
1304
1408
  return this._customerProductsFromResponse(response);
1305
1409
  }
1410
+ async cancelSubscription(options) {
1411
+ const session = await this._getSession();
1412
+ const user = await this.getUser();
1413
+ if (!user) {
1414
+ throw new KnownErrors.UserAuthenticationRequired();
1415
+ }
1416
+ const customerType = "teamId" in options ? "team" : "user";
1417
+ const customerId = "teamId" in options ? options.teamId : user.id;
1418
+ await this._interface.cancelSubscription({
1419
+ customer_type: customerType,
1420
+ customer_id: customerId,
1421
+ product_id: options.productId
1422
+ }, session);
1423
+ if (customerType === "user") {
1424
+ await this._userProductsCache.invalidateWhere(([cachedSession, userId]) => cachedSession === session && userId === customerId);
1425
+ } else {
1426
+ await this._teamProductsCache.invalidateWhere(([cachedSession, teamId]) => cachedSession === session && teamId === customerId);
1427
+ }
1428
+ }
1306
1429
  useProducts(options) {
1307
1430
  const session = this._useSession();
1308
1431
  const cache = "userId" in options ? this._userProductsCache : "teamId" in options ? this._teamProductsCache : this._customProductsCache;
@@ -1312,15 +1435,13 @@ var __StackClientAppImplIncomplete = class __StackClientAppImplIncomplete {
1312
1435
  return this._customerProductsFromResponse(response);
1313
1436
  }
1314
1437
  _currentUserFromCrud(crud, session) {
1315
- const currentUser = {
1438
+ const currentUser = withUserDestructureGuard({
1316
1439
  ...this._createBaseUser(crud),
1317
1440
  ...this._createAuth(session),
1318
1441
  ...this._createUserExtraFromCurrent(crud, session),
1319
1442
  ...this._isInternalProject() ? this._createInternalUserExtra(session) : {},
1320
1443
  ...this._createCustomer(crud.id, "user", session)
1321
- };
1322
- attachUserDestructureGuard(currentUser);
1323
- Object.freeze(currentUser);
1444
+ });
1324
1445
  return currentUser;
1325
1446
  }
1326
1447
  _clientSessionFromCrud(crud) {
@@ -1403,7 +1524,7 @@ var __StackClientAppImplIncomplete = class __StackClientAppImplIncomplete {
1403
1524
  const queryParams = new URLSearchParams(window.location.search);
1404
1525
  url = queryParams.get("after_auth_return_to") || url;
1405
1526
  }
1406
- } else if (handlerName === "signIn" || handlerName === "signUp") {
1527
+ } else if (handlerName === "signIn" || handlerName === "signUp" || handlerName === "onboarding") {
1407
1528
  if (isReactServer || typeof window === "undefined") {
1408
1529
  } else {
1409
1530
  const currentUrl = new URL(window.location.href);
@@ -1452,6 +1573,9 @@ var __StackClientAppImplIncomplete = class __StackClientAppImplIncomplete {
1452
1573
  async redirectToAfterSignUp(options) {
1453
1574
  return await this._redirectToHandler("afterSignUp", options);
1454
1575
  }
1576
+ async redirectToOnboarding(options) {
1577
+ return await this._redirectToHandler("onboarding", options);
1578
+ }
1455
1579
  async redirectToAfterSignOut(options) {
1456
1580
  return await this._redirectToHandler("afterSignOut", options);
1457
1581
  }
@@ -1517,16 +1641,22 @@ var __StackClientAppImplIncomplete = class __StackClientAppImplIncomplete {
1517
1641
  return result;
1518
1642
  }
1519
1643
  async getUser(options) {
1644
+ if (options?.or === "anonymous" && options.includeRestricted === false) {
1645
+ throw new Error("Cannot use { or: 'anonymous' } with { includeRestricted: false }. Anonymous users implicitly include restricted users.");
1646
+ }
1520
1647
  this._ensurePersistentTokenStore(options?.tokenStore);
1521
1648
  const session = await this._getSession(options?.tokenStore);
1522
1649
  let crud = Result.orThrow(await this._currentUserCache.getOrWait([session], "write-only"));
1523
- if (crud?.is_anonymous && options?.or !== "anonymous" && options?.or !== "anonymous-if-exists[deprecated]") {
1524
- crud = null;
1525
- }
1526
- if (crud === null) {
1650
+ const includeAnonymous = options?.or === "anonymous" || options?.or === "anonymous-if-exists[deprecated]";
1651
+ const includeRestricted = options?.includeRestricted === true || includeAnonymous;
1652
+ if (crud === null || crud.is_anonymous && !includeAnonymous || crud.is_restricted && !includeRestricted) {
1527
1653
  switch (options?.or) {
1528
1654
  case "redirect": {
1529
- await this.redirectToSignIn({ replace: true });
1655
+ if (!crud?.is_anonymous && crud?.is_restricted) {
1656
+ await this.redirectToOnboarding({ replace: true });
1657
+ } else {
1658
+ await this.redirectToSignIn({ replace: true });
1659
+ }
1530
1660
  break;
1531
1661
  }
1532
1662
  case "throw": {
@@ -1534,7 +1664,7 @@ var __StackClientAppImplIncomplete = class __StackClientAppImplIncomplete {
1534
1664
  }
1535
1665
  case "anonymous": {
1536
1666
  const tokens = await this._signUpAnonymously();
1537
- return await this.getUser({ tokenStore: tokens, or: "anonymous-if-exists[deprecated]" }) ?? throwErr("Something went wrong while signing up anonymously");
1667
+ return await this.getUser({ tokenStore: tokens, or: "anonymous-if-exists[deprecated]", includeRestricted: true }) ?? throwErr("Something went wrong while signing up anonymously");
1538
1668
  }
1539
1669
  case void 0:
1540
1670
  case "anonymous-if-exists[deprecated]":
@@ -1546,16 +1676,22 @@ var __StackClientAppImplIncomplete = class __StackClientAppImplIncomplete {
1546
1676
  return crud && this._currentUserFromCrud(crud, session);
1547
1677
  }
1548
1678
  useUser(options) {
1679
+ if (options?.or === "anonymous" && options.includeRestricted === false) {
1680
+ throw new Error("Cannot use { or: 'anonymous' } with { includeRestricted: false }. Anonymous users implicitly include restricted users.");
1681
+ }
1549
1682
  this._ensurePersistentTokenStore(options?.tokenStore);
1550
1683
  const session = this._useSession(options?.tokenStore);
1551
1684
  let crud = useAsyncCache(this._currentUserCache, [session], "clientApp.useUser()");
1552
- if (crud?.is_anonymous && options?.or !== "anonymous" && options?.or !== "anonymous-if-exists[deprecated]") {
1553
- crud = null;
1554
- }
1555
- if (crud === null) {
1685
+ const includeAnonymous = options?.or === "anonymous" || options?.or === "anonymous-if-exists[deprecated]";
1686
+ const includeRestricted = options?.includeRestricted === true || includeAnonymous;
1687
+ if (crud === null || crud.is_anonymous && !includeAnonymous || crud.is_restricted && !includeRestricted) {
1556
1688
  switch (options?.or) {
1557
1689
  case "redirect": {
1558
- runAsynchronously(this.redirectToSignIn({ replace: true }));
1690
+ if (!crud?.is_anonymous && crud?.is_restricted) {
1691
+ runAsynchronously(this.redirectToOnboarding({ replace: true }));
1692
+ } else {
1693
+ runAsynchronously(this.redirectToSignIn({ replace: true }));
1694
+ }
1559
1695
  suspend();
1560
1696
  throw new StackAssertionError("suspend should never return");
1561
1697
  }
@@ -1583,7 +1719,7 @@ var __StackClientAppImplIncomplete = class __StackClientAppImplIncomplete {
1583
1719
  }, [crud, session, options?.or]);
1584
1720
  }
1585
1721
  _getTokenPartialUserFromSession(session, options) {
1586
- const accessToken = session.getAccessTokenIfNotExpiredYet(0);
1722
+ const accessToken = session.getAccessTokenIfNotExpiredYet(0, null);
1587
1723
  if (!accessToken) {
1588
1724
  return null;
1589
1725
  }
@@ -1596,7 +1732,9 @@ var __StackClientAppImplIncomplete = class __StackClientAppImplIncomplete {
1596
1732
  primaryEmail: accessToken.payload.email,
1597
1733
  displayName: accessToken.payload.name,
1598
1734
  primaryEmailVerified: accessToken.payload.email_verified,
1599
- isAnonymous
1735
+ isAnonymous,
1736
+ isRestricted: accessToken.payload.is_restricted,
1737
+ restrictedReason: accessToken.payload.restricted_reason
1600
1738
  };
1601
1739
  }
1602
1740
  async _getPartialUserFromConvex(ctx) {
@@ -1609,7 +1747,9 @@ var __StackClientAppImplIncomplete = class __StackClientAppImplIncomplete {
1609
1747
  displayName: auth.name ?? null,
1610
1748
  primaryEmail: auth.email ?? null,
1611
1749
  primaryEmailVerified: auth.email_verified,
1612
- isAnonymous: auth.is_anonymous
1750
+ isAnonymous: auth.is_anonymous,
1751
+ isRestricted: auth.is_restricted,
1752
+ restrictedReason: auth.restricted_reason ?? null
1613
1753
  };
1614
1754
  }
1615
1755
  async getPartialUser(options) {
@@ -1647,7 +1787,7 @@ var __StackClientAppImplIncomplete = class __StackClientAppImplIncomplete {
1647
1787
  return async (args) => {
1648
1788
  const session = await this._getSession(options.tokenStore ?? this._tokenStoreInit);
1649
1789
  if (!args.forceRefreshToken) {
1650
- const tokens2 = await session.getOrFetchLikelyValidTokens(2e4);
1790
+ const tokens2 = await session.getOrFetchLikelyValidTokens(2e4, 75e3);
1651
1791
  return tokens2?.accessToken.token ?? null;
1652
1792
  }
1653
1793
  const tokens = await session.fetchNewTokens();
@@ -1656,7 +1796,7 @@ var __StackClientAppImplIncomplete = class __StackClientAppImplIncomplete {
1656
1796
  }
1657
1797
  async getConvexHttpClientAuth(options) {
1658
1798
  const session = await this._getSession(options.tokenStore);
1659
- const tokens = await session.getOrFetchLikelyValidTokens(2e4);
1799
+ const tokens = await session.getOrFetchLikelyValidTokens(2e4, 75e3);
1660
1800
  return tokens?.accessToken.token ?? "";
1661
1801
  }
1662
1802
  async _updateClientUser(update, session) {
@@ -2003,11 +2143,44 @@ ${url}`);
2003
2143
  await user.signOut({ redirectUrl: options?.redirectUrl });
2004
2144
  }
2005
2145
  }
2146
+ async getAccessToken(options) {
2147
+ const user = await this.getUser({ tokenStore: options?.tokenStore ?? void 0 });
2148
+ if (user) {
2149
+ return await user.getAccessToken();
2150
+ }
2151
+ return null;
2152
+ }
2153
+ useAccessToken(options) {
2154
+ const user = this.useUser({ tokenStore: options?.tokenStore ?? void 0 });
2155
+ if (user) {
2156
+ return user.useAccessToken();
2157
+ }
2158
+ return null;
2159
+ }
2160
+ async getRefreshToken(options) {
2161
+ const user = await this.getUser({ tokenStore: options?.tokenStore ?? void 0 });
2162
+ if (user) {
2163
+ return await user.getRefreshToken();
2164
+ }
2165
+ return null;
2166
+ }
2167
+ useRefreshToken(options) {
2168
+ const user = this.useUser({ tokenStore: options?.tokenStore ?? void 0 });
2169
+ if (user) {
2170
+ return user.useRefreshToken();
2171
+ }
2172
+ return null;
2173
+ }
2006
2174
  async getAuthHeaders(options) {
2007
2175
  return {
2008
2176
  "x-stack-auth": JSON.stringify(await this.getAuthJson(options))
2009
2177
  };
2010
2178
  }
2179
+ useAuthHeaders(options) {
2180
+ return {
2181
+ "x-stack-auth": JSON.stringify(this.useAuthJson(options))
2182
+ };
2183
+ }
2011
2184
  async getAuthJson(options) {
2012
2185
  const user = await this.getUser({ tokenStore: options?.tokenStore ?? void 0 });
2013
2186
  if (user) {
@@ -2015,6 +2188,13 @@ ${url}`);
2015
2188
  }
2016
2189
  return { accessToken: null, refreshToken: null };
2017
2190
  }
2191
+ useAuthJson(options) {
2192
+ const user = this.useUser({ tokenStore: options?.tokenStore ?? void 0 });
2193
+ if (user) {
2194
+ return user.useAuthJson();
2195
+ }
2196
+ return { accessToken: null, refreshToken: null };
2197
+ }
2018
2198
  async getProject() {
2019
2199
  const crud = Result.orThrow(await this._currentProjectCache.getOrWait([], "write-only"));
2020
2200
  return this._clientProjectFromCrud(crud);
@@ -2051,6 +2231,7 @@ ${url}`);
2051
2231
  }
2052
2232
  async _refreshUser(session) {
2053
2233
  await this._refreshSession(session);
2234
+ session.suggestAccessTokenExpired();
2054
2235
  }
2055
2236
  async _refreshSession(session) {
2056
2237
  await this._currentUserCache.refresh([session]);