@stackframe/stack 2.7.21 → 2.7.23

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 (145) hide show
  1. package/CHANGELOG.md +20 -0
  2. package/README.md +2 -2
  3. package/dist/admin-app-impl-CTQhv9tV.d.ts +395 -0
  4. package/dist/admin-app-impl-DpyRKp1e.d.mts +395 -0
  5. package/dist/components/selected-team-switcher.d.mts +18 -6
  6. package/dist/components/selected-team-switcher.d.ts +18 -6
  7. package/dist/components/team-icon.d.mts +18 -6
  8. package/dist/components/team-icon.d.ts +18 -6
  9. package/dist/components-page/stack-handler.d.mts +18 -6
  10. package/dist/components-page/stack-handler.d.ts +18 -6
  11. package/dist/esm/lib/stack-app/api-keys/index.js +14 -0
  12. package/dist/esm/lib/stack-app/api-keys/index.js.map +1 -0
  13. package/dist/esm/lib/stack-app/apps/implementations/admin-app-impl.js +291 -0
  14. package/dist/esm/lib/stack-app/apps/implementations/admin-app-impl.js.map +1 -0
  15. package/dist/esm/lib/{stack-app.js → stack-app/apps/implementations/client-app-impl.js} +37 -1109
  16. package/dist/esm/lib/stack-app/apps/implementations/client-app-impl.js.map +1 -0
  17. package/dist/esm/lib/stack-app/apps/implementations/common.js +142 -0
  18. package/dist/esm/lib/stack-app/apps/implementations/common.js.map +1 -0
  19. package/dist/esm/lib/stack-app/apps/implementations/index.js +24 -0
  20. package/dist/esm/lib/stack-app/apps/implementations/index.js.map +1 -0
  21. package/dist/esm/lib/stack-app/apps/implementations/server-app-impl.js +527 -0
  22. package/dist/esm/lib/stack-app/apps/implementations/server-app-impl.js.map +1 -0
  23. package/dist/esm/lib/stack-app/apps/index.js +16 -0
  24. package/dist/esm/lib/stack-app/apps/index.js.map +1 -0
  25. package/dist/esm/lib/stack-app/apps/interfaces/admin-app.js +7 -0
  26. package/dist/esm/lib/stack-app/apps/interfaces/admin-app.js.map +1 -0
  27. package/dist/esm/lib/stack-app/apps/interfaces/client-app.js +7 -0
  28. package/dist/esm/lib/stack-app/apps/interfaces/client-app.js.map +1 -0
  29. package/dist/esm/lib/stack-app/apps/interfaces/server-app.js +7 -0
  30. package/dist/esm/lib/stack-app/apps/interfaces/server-app.js.map +1 -0
  31. package/dist/esm/lib/stack-app/common.js +6 -0
  32. package/dist/esm/lib/stack-app/common.js.map +1 -0
  33. package/dist/esm/lib/stack-app/connected-accounts/index.js +1 -0
  34. package/dist/esm/lib/stack-app/connected-accounts/index.js.map +1 -0
  35. package/dist/esm/lib/stack-app/contact-channels/index.js +39 -0
  36. package/dist/esm/lib/stack-app/contact-channels/index.js.map +1 -0
  37. package/dist/esm/lib/stack-app/email-templates/index.js +11 -0
  38. package/dist/esm/lib/stack-app/email-templates/index.js.map +1 -0
  39. package/dist/esm/lib/stack-app/index.js +16 -0
  40. package/dist/esm/lib/stack-app/index.js.map +1 -0
  41. package/dist/esm/lib/stack-app/permissions/index.js +20 -0
  42. package/dist/esm/lib/stack-app/permissions/index.js.map +1 -0
  43. package/dist/esm/lib/stack-app/project-configs/index.js +1 -0
  44. package/dist/esm/lib/stack-app/project-configs/index.js.map +1 -0
  45. package/dist/esm/lib/stack-app/projects/index.js +57 -0
  46. package/dist/esm/lib/stack-app/projects/index.js.map +1 -0
  47. package/dist/esm/lib/stack-app/teams/index.js +38 -0
  48. package/dist/esm/lib/stack-app/teams/index.js.map +1 -0
  49. package/dist/esm/lib/stack-app/users/index.js +47 -0
  50. package/dist/esm/lib/stack-app/users/index.js.map +1 -0
  51. package/dist/generated/quetzal-translations.d.mts +2 -2
  52. package/dist/generated/quetzal-translations.d.ts +2 -2
  53. package/dist/{lib/stack-app.d.mts → index-C7D6Vt7X.d.mts} +138 -354
  54. package/dist/{lib/stack-app.d.ts → index-DQk7XJpU.d.ts} +138 -354
  55. package/dist/index.d.mts +17 -5
  56. package/dist/index.d.ts +17 -5
  57. package/dist/lib/hooks.d.mts +17 -5
  58. package/dist/lib/hooks.d.ts +17 -5
  59. package/dist/lib/stack-app/api-keys/index.d.mts +40 -0
  60. package/dist/lib/stack-app/api-keys/index.d.ts +40 -0
  61. package/dist/lib/stack-app/api-keys/index.js +39 -0
  62. package/dist/lib/stack-app/api-keys/index.js.map +1 -0
  63. package/dist/lib/stack-app/apps/implementations/admin-app-impl.d.mts +30 -0
  64. package/dist/lib/stack-app/apps/implementations/admin-app-impl.d.ts +30 -0
  65. package/dist/lib/stack-app/apps/implementations/admin-app-impl.js +316 -0
  66. package/dist/lib/stack-app/apps/implementations/admin-app-impl.js.map +1 -0
  67. package/dist/lib/stack-app/apps/implementations/client-app-impl.d.mts +30 -0
  68. package/dist/lib/stack-app/apps/implementations/client-app-impl.d.ts +30 -0
  69. package/dist/lib/{stack-app.js → stack-app/apps/implementations/client-app-impl.js} +75 -1152
  70. package/dist/lib/stack-app/apps/implementations/client-app-impl.js.map +1 -0
  71. package/dist/lib/stack-app/apps/implementations/common.d.mts +45 -0
  72. package/dist/lib/stack-app/apps/implementations/common.d.ts +45 -0
  73. package/dist/lib/stack-app/apps/implementations/common.js +187 -0
  74. package/dist/lib/stack-app/apps/implementations/common.js.map +1 -0
  75. package/dist/lib/stack-app/apps/implementations/index.d.mts +36 -0
  76. package/dist/lib/stack-app/apps/implementations/index.d.ts +36 -0
  77. package/dist/lib/stack-app/apps/implementations/index.js +51 -0
  78. package/dist/lib/stack-app/apps/implementations/index.js.map +1 -0
  79. package/dist/lib/stack-app/apps/implementations/server-app-impl.d.mts +30 -0
  80. package/dist/lib/stack-app/apps/implementations/server-app-impl.d.ts +30 -0
  81. package/dist/lib/stack-app/apps/implementations/server-app-impl.js +552 -0
  82. package/dist/lib/stack-app/apps/implementations/server-app-impl.js.map +1 -0
  83. package/dist/lib/stack-app/apps/index.d.mts +23 -0
  84. package/dist/lib/stack-app/apps/index.d.ts +23 -0
  85. package/dist/lib/stack-app/apps/index.js +37 -0
  86. package/dist/lib/stack-app/apps/index.js.map +1 -0
  87. package/dist/lib/stack-app/apps/interfaces/admin-app.d.mts +23 -0
  88. package/dist/lib/stack-app/apps/interfaces/admin-app.d.ts +23 -0
  89. package/dist/lib/stack-app/apps/interfaces/admin-app.js +32 -0
  90. package/dist/lib/stack-app/apps/interfaces/admin-app.js.map +1 -0
  91. package/dist/lib/stack-app/apps/interfaces/client-app.d.mts +23 -0
  92. package/dist/lib/stack-app/apps/interfaces/client-app.d.ts +23 -0
  93. package/dist/lib/stack-app/apps/interfaces/client-app.js +32 -0
  94. package/dist/lib/stack-app/apps/interfaces/client-app.js.map +1 -0
  95. package/dist/lib/stack-app/apps/interfaces/server-app.d.mts +23 -0
  96. package/dist/lib/stack-app/apps/interfaces/server-app.d.ts +23 -0
  97. package/dist/lib/stack-app/apps/interfaces/server-app.js +32 -0
  98. package/dist/lib/stack-app/apps/interfaces/server-app.js.map +1 -0
  99. package/dist/lib/stack-app/common.d.mts +63 -0
  100. package/dist/lib/stack-app/common.d.ts +63 -0
  101. package/dist/lib/stack-app/common.js +31 -0
  102. package/dist/lib/stack-app/common.js.map +1 -0
  103. package/dist/lib/stack-app/connected-accounts/index.d.mts +13 -0
  104. package/dist/lib/stack-app/connected-accounts/index.d.ts +13 -0
  105. package/dist/lib/stack-app/connected-accounts/index.js +19 -0
  106. package/dist/lib/stack-app/connected-accounts/index.js.map +1 -0
  107. package/dist/lib/stack-app/contact-channels/index.d.mts +38 -0
  108. package/dist/lib/stack-app/contact-channels/index.d.ts +38 -0
  109. package/dist/lib/stack-app/contact-channels/index.js +67 -0
  110. package/dist/lib/stack-app/contact-channels/index.js.map +1 -0
  111. package/dist/lib/stack-app/email-templates/index.d.mts +15 -0
  112. package/dist/lib/stack-app/email-templates/index.d.ts +15 -0
  113. package/dist/lib/stack-app/email-templates/index.js +36 -0
  114. package/dist/lib/stack-app/email-templates/index.js.map +1 -0
  115. package/dist/lib/stack-app/index.d.mts +23 -0
  116. package/dist/lib/stack-app/index.d.ts +23 -0
  117. package/dist/lib/stack-app/index.js +38 -0
  118. package/dist/lib/stack-app/index.js.map +1 -0
  119. package/dist/lib/stack-app/permissions/index.d.mts +21 -0
  120. package/dist/lib/stack-app/permissions/index.d.ts +21 -0
  121. package/dist/lib/stack-app/permissions/index.js +46 -0
  122. package/dist/lib/stack-app/permissions/index.js.map +1 -0
  123. package/dist/lib/stack-app/project-configs/index.d.mts +82 -0
  124. package/dist/lib/stack-app/project-configs/index.d.ts +82 -0
  125. package/dist/lib/stack-app/project-configs/index.js +19 -0
  126. package/dist/lib/stack-app/project-configs/index.js.map +1 -0
  127. package/dist/lib/stack-app/projects/index.d.mts +23 -0
  128. package/dist/lib/stack-app/projects/index.d.ts +23 -0
  129. package/dist/lib/stack-app/projects/index.js +83 -0
  130. package/dist/lib/stack-app/projects/index.js.map +1 -0
  131. package/dist/lib/stack-app/teams/index.d.mts +23 -0
  132. package/dist/lib/stack-app/teams/index.d.ts +23 -0
  133. package/dist/lib/stack-app/teams/index.js +66 -0
  134. package/dist/lib/stack-app/teams/index.js.map +1 -0
  135. package/dist/lib/stack-app/users/index.d.mts +23 -0
  136. package/dist/lib/stack-app/users/index.d.ts +23 -0
  137. package/dist/lib/stack-app/users/index.js +74 -0
  138. package/dist/lib/stack-app/users/index.js.map +1 -0
  139. package/dist/providers/stack-provider-client.d.mts +17 -5
  140. package/dist/providers/stack-provider-client.d.ts +17 -5
  141. package/dist/providers/stack-provider.d.mts +18 -6
  142. package/dist/providers/stack-provider.d.ts +18 -6
  143. package/package.json +4 -4
  144. package/dist/esm/lib/stack-app.js.map +0 -1
  145. package/dist/lib/stack-app.js.map +0 -1
@@ -27,23 +27,15 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
27
27
  ));
28
28
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
29
 
30
- // src/lib/stack-app.ts
31
- var stack_app_exports = {};
32
- __export(stack_app_exports, {
33
- StackAdminApp: () => StackAdminApp,
34
- StackClientApp: () => StackClientApp,
35
- StackServerApp: () => StackServerApp,
36
- serverTeamPermissionDefinitionCreateOptionsToCrud: () => serverTeamPermissionDefinitionCreateOptionsToCrud,
37
- serverTeamPermissionDefinitionUpdateOptionsToCrud: () => serverTeamPermissionDefinitionUpdateOptionsToCrud,
38
- stackAppInternalsSymbol: () => stackAppInternalsSymbol
30
+ // src/lib/stack-app/apps/implementations/client-app-impl.ts
31
+ var client_app_impl_exports = {};
32
+ __export(client_app_impl_exports, {
33
+ _StackClientAppImplIncomplete: () => _StackClientAppImplIncomplete
39
34
  });
40
- module.exports = __toCommonJS(stack_app_exports);
35
+ module.exports = __toCommonJS(client_app_impl_exports);
41
36
  var import_browser = require("@simplewebauthn/browser");
42
37
  var import_stack_shared = require("@stackframe/stack-shared");
43
- var import_production_mode = require("@stackframe/stack-shared/dist/helpers/production-mode");
44
38
  var import_sessions = require("@stackframe/stack-shared/dist/sessions");
45
- var import_bytes = require("@stackframe/stack-shared/dist/utils/bytes");
46
- var import_caches = require("@stackframe/stack-shared/dist/utils/caches");
47
39
  var import_compile_time = require("@stackframe/stack-shared/dist/utils/compile-time");
48
40
  var import_env = require("@stackframe/stack-shared/dist/utils/env");
49
41
  var import_errors = require("@stackframe/stack-shared/dist/utils/errors");
@@ -59,143 +51,30 @@ var import_uuids = require("@stackframe/stack-shared/dist/utils/uuids");
59
51
  var cookie = __toESM(require("cookie"));
60
52
  var NextNavigationUnscrambled = __toESM(require("next/navigation"));
61
53
  var import_react2 = __toESM(require("react"));
62
- var import_url = require("../utils/url");
63
- var import_auth = require("./auth");
64
- var import_cookie = require("./cookie");
54
+ var import_url = require("../../../../utils/url");
55
+ var import_auth = require("../../../auth");
56
+ var import_cookie = require("../../../cookie");
57
+ var import_common = require("../../common");
58
+ var import_contact_channels = require("../../contact-channels");
59
+ var import_projects = require("../../projects");
60
+ var import_teams = require("../../teams");
61
+ var import_users = require("../../users");
62
+ var import_common2 = require("./common");
63
+ var import_common3 = require("./common");
65
64
  var sc = __toESM(require("@stackframe/stack-sc"));
66
65
  var import_stack_sc = require("@stackframe/stack-sc");
67
66
  var isReactServer2 = false;
68
67
  isReactServer2 = sc.isReactServer;
69
68
  var NextNavigation = (0, import_compile_time.scrambleDuringCompileTime)(NextNavigationUnscrambled);
70
- var clientVersion = "js @stackframe/stack@2.7.21";
71
- if (clientVersion.startsWith("STACK_COMPILE_TIME")) {
72
- throw new import_errors.StackAssertionError("Client version was not replaced. Something went wrong during build!");
73
- }
74
- function getUrls(partial) {
75
- const handler = partial.handler ?? "/handler";
76
- const home = partial.home ?? "/";
77
- const afterSignIn = partial.afterSignIn ?? home;
78
- return {
79
- handler,
80
- signIn: `${handler}/sign-in`,
81
- afterSignIn: home,
82
- signUp: `${handler}/sign-up`,
83
- afterSignUp: afterSignIn,
84
- signOut: `${handler}/sign-out`,
85
- afterSignOut: home,
86
- emailVerification: `${handler}/email-verification`,
87
- passwordReset: `${handler}/password-reset`,
88
- forgotPassword: `${handler}/forgot-password`,
89
- oauthCallback: `${handler}/oauth-callback`,
90
- magicLinkCallback: `${handler}/magic-link-callback`,
91
- home,
92
- accountSettings: `${handler}/account-settings`,
93
- error: `${handler}/error`,
94
- teamInvitation: `${handler}/team-invitation`,
95
- ...(0, import_objects.filterUndefined)(partial)
96
- };
97
- }
98
- function getDefaultProjectId() {
99
- return process.env.NEXT_PUBLIC_STACK_PROJECT_ID || (0, import_errors.throwErr)(new Error("Welcome to Stack Auth! It seems that you haven't provided a project ID. Please create a project on the Stack dashboard at https://app.stack-auth.com and put it in the NEXT_PUBLIC_STACK_PROJECT_ID environment variable."));
100
- }
101
- function getDefaultPublishableClientKey() {
102
- return process.env.NEXT_PUBLIC_STACK_PUBLISHABLE_CLIENT_KEY || (0, import_errors.throwErr)(new Error("Welcome to Stack Auth! It seems that you haven't provided a publishable client key. Please create an API key for your project on the Stack dashboard at https://app.stack-auth.com and copy your publishable client key into the NEXT_PUBLIC_STACK_PUBLISHABLE_CLIENT_KEY environment variable."));
103
- }
104
- function getDefaultSecretServerKey() {
105
- return process.env.STACK_SECRET_SERVER_KEY || (0, import_errors.throwErr)(new Error("No secret server key provided. Please copy your key from the Stack dashboard and put your it in the STACK_SECRET_SERVER_KEY environment variable."));
106
- }
107
- function getDefaultSuperSecretAdminKey() {
108
- return process.env.STACK_SUPER_SECRET_ADMIN_KEY || (0, import_errors.throwErr)(new Error("No super secret admin key provided. Please copy your key from the Stack dashboard and put it in the STACK_SUPER_SECRET_ADMIN_KEY environment variable."));
109
- }
110
- function getBaseUrl(userSpecifiedBaseUrl) {
111
- let url;
112
- if (userSpecifiedBaseUrl) {
113
- if (typeof userSpecifiedBaseUrl === "string") {
114
- url = userSpecifiedBaseUrl;
115
- } else {
116
- if ((0, import_env.isBrowserLike)()) {
117
- url = userSpecifiedBaseUrl.browser;
118
- } else {
119
- url = userSpecifiedBaseUrl.server;
120
- }
121
- }
122
- } else {
123
- if ((0, import_env.isBrowserLike)()) {
124
- url = process.env.NEXT_PUBLIC_BROWSER_STACK_API_URL;
125
- } else {
126
- url = process.env.NEXT_PUBLIC_SERVER_STACK_API_URL;
127
- }
128
- url = url || process.env.NEXT_PUBLIC_STACK_API_URL || process.env.NEXT_PUBLIC_STACK_URL || defaultBaseUrl;
129
- }
130
- return url.endsWith("/") ? url.slice(0, -1) : url;
131
- }
132
- var defaultBaseUrl = "https://api.stack-auth.com";
133
- function createEmptyTokenStore() {
134
- return new import_stores.Store({
135
- refreshToken: null,
136
- accessToken: null
137
- });
138
- }
139
- var cachePromiseByComponentId = /* @__PURE__ */ new Map();
140
- function useAsyncCache(cache, dependencies, caller) {
141
- (0, import_react.suspendIfSsr)(caller);
142
- const id = import_react2.default.useId();
143
- const subscribe = (0, import_react2.useCallback)((cb) => {
144
- const { unsubscribe } = cache.onStateChange(dependencies, () => {
145
- cachePromiseByComponentId.delete(id);
146
- cb();
147
- });
148
- return unsubscribe;
149
- }, [cache, ...dependencies]);
150
- const getSnapshot = (0, import_react2.useCallback)(() => {
151
- if (!cachePromiseByComponentId.has(id)) {
152
- cachePromiseByComponentId.set(id, cache.getOrWait(dependencies, "read-write"));
153
- }
154
- return cachePromiseByComponentId.get(id);
155
- }, [cache, ...dependencies]);
156
- const promise = import_react2.default.useSyncExternalStore(
157
- subscribe,
158
- getSnapshot,
159
- () => (0, import_errors.throwErr)(new Error("getServerSnapshot should never be called in useAsyncCache because we restrict to CSR earlier"))
160
- );
161
- const result = import_react2.default.use(promise);
162
- if (result.status === "error") {
163
- const error = result.error;
164
- if (error instanceof Error && !error.__stackHasConcatenatedStacktraces) {
165
- (0, import_errors.concatStacktraces)(error, new Error());
166
- error.__stackHasConcatenatedStacktraces = true;
167
- }
168
- throw error;
169
- }
170
- return result.data;
171
- }
172
- var stackAppInternalsSymbol = Symbol.for("StackAuth--DO-NOT-USE-OR-YOU-WILL-BE-FIRED--StackAppInternals");
173
- var allClientApps = /* @__PURE__ */ new Map();
174
- var createCache = (fetcher) => {
175
- return new import_caches.AsyncCache(
176
- async (dependencies) => await import_results.Result.fromThrowingAsync(async () => await fetcher(dependencies)),
177
- {}
178
- );
179
- };
180
- var createCacheBySession = (fetcher) => {
181
- return new import_caches.AsyncCache(
182
- async ([session, ...extraDependencies]) => await import_results.Result.fromThrowingAsync(async () => await fetcher(session, extraDependencies)),
183
- {
184
- onSubscribe: ([session], refresh) => {
185
- const handler = session.onInvalidate(() => refresh());
186
- return () => handler.unsubscribe();
187
- }
188
- }
189
- );
190
- };
191
69
  var numberOfAppsCreated = 0;
192
- var _StackClientAppImpl = class __StackClientAppImpl {
70
+ var allClientApps = /* @__PURE__ */ new Map();
71
+ var __StackClientAppImplIncomplete = class __StackClientAppImplIncomplete {
193
72
  constructor(_options) {
194
73
  this._options = _options;
195
74
  this._uniqueIdentifier = void 0;
196
75
  this.__DEMO_ENABLE_SLIGHT_FETCH_DELAY = false;
197
76
  this._ownedAdminApps = new import_maps.DependenciesMap();
198
- this._currentUserCache = createCacheBySession(async (session) => {
77
+ this._currentUserCache = (0, import_common2.createCacheBySession)(async (session) => {
199
78
  if (this.__DEMO_ENABLE_SLIGHT_FETCH_DELAY) {
200
79
  await (0, import_promises.wait)(2e3);
201
80
  }
@@ -204,19 +83,19 @@ var _StackClientAppImpl = class __StackClientAppImpl {
204
83
  }
205
84
  return await this._interface.getClientUserByToken(session);
206
85
  });
207
- this._currentProjectCache = createCache(async () => {
86
+ this._currentProjectCache = (0, import_common2.createCache)(async () => {
208
87
  return import_results.Result.orThrow(await this._interface.getClientProject());
209
88
  });
210
- this._ownedProjectsCache = createCacheBySession(async (session) => {
89
+ this._ownedProjectsCache = (0, import_common2.createCacheBySession)(async (session) => {
211
90
  return await this._interface.listProjects(session);
212
91
  });
213
- this._currentUserPermissionsCache = createCacheBySession(async (session, [teamId, recursive]) => {
92
+ this._currentUserPermissionsCache = (0, import_common2.createCacheBySession)(async (session, [teamId, recursive]) => {
214
93
  return await this._interface.listCurrentUserTeamPermissions({ teamId, recursive }, session);
215
94
  });
216
- this._currentUserTeamsCache = createCacheBySession(async (session) => {
95
+ this._currentUserTeamsCache = (0, import_common2.createCacheBySession)(async (session) => {
217
96
  return await this._interface.listCurrentUserTeams(session);
218
97
  });
219
- this._currentUserOAuthConnectionAccessTokensCache = createCacheBySession(
98
+ this._currentUserOAuthConnectionAccessTokensCache = (0, import_common2.createCacheBySession)(
220
99
  async (session, [providerId, scope]) => {
221
100
  try {
222
101
  const result = await this._interface.createProviderAccessToken(providerId, scope || "", session);
@@ -229,12 +108,12 @@ var _StackClientAppImpl = class __StackClientAppImpl {
229
108
  return null;
230
109
  }
231
110
  );
232
- this._currentUserOAuthConnectionCache = createCacheBySession(
111
+ this._currentUserOAuthConnectionCache = (0, import_common2.createCacheBySession)(
233
112
  async (session, [providerId, scope, redirect]) => {
234
113
  return await this._getUserOAuthConnectionCacheFn({
235
114
  getUser: async () => import_results.Result.orThrow(await this._currentUserCache.getOrWait([session], "write-only")),
236
115
  getOrWaitOAuthToken: async () => import_results.Result.orThrow(await this._currentUserOAuthConnectionAccessTokensCache.getOrWait([session, providerId, scope || ""], "write-only")),
237
- useOAuthToken: () => useAsyncCache(this._currentUserOAuthConnectionAccessTokensCache, [session, providerId, scope || ""], "useOAuthToken"),
116
+ useOAuthToken: () => (0, import_common3.useAsyncCache)(this._currentUserOAuthConnectionAccessTokensCache, [session, providerId, scope || ""], "useOAuthToken"),
238
117
  providerId,
239
118
  scope,
240
119
  redirect,
@@ -242,27 +121,27 @@ var _StackClientAppImpl = class __StackClientAppImpl {
242
121
  });
243
122
  }
244
123
  );
245
- this._teamMemberProfilesCache = createCacheBySession(
124
+ this._teamMemberProfilesCache = (0, import_common2.createCacheBySession)(
246
125
  async (session, [teamId]) => {
247
126
  return await this._interface.listTeamMemberProfiles({ teamId }, session);
248
127
  }
249
128
  );
250
- this._teamInvitationsCache = createCacheBySession(
129
+ this._teamInvitationsCache = (0, import_common2.createCacheBySession)(
251
130
  async (session, [teamId]) => {
252
131
  return await this._interface.listTeamInvitations({ teamId }, session);
253
132
  }
254
133
  );
255
- this._currentUserTeamProfileCache = createCacheBySession(
134
+ this._currentUserTeamProfileCache = (0, import_common2.createCacheBySession)(
256
135
  async (session, [teamId]) => {
257
136
  return await this._interface.getTeamMemberProfile({ teamId, userId: "me" }, session);
258
137
  }
259
138
  );
260
- this._clientContactChannelsCache = createCacheBySession(
139
+ this._clientContactChannelsCache = (0, import_common2.createCacheBySession)(
261
140
  async (session) => {
262
141
  return await this._interface.listClientContactChannels(session);
263
142
  }
264
143
  );
265
- this._memoryTokenStore = createEmptyTokenStore();
144
+ this._memoryTokenStore = (0, import_common2.createEmptyTokenStore)();
266
145
  this._nextServerCookiesTokenStores = /* @__PURE__ */ new WeakMap();
267
146
  this._requestTokenStores = /* @__PURE__ */ new WeakMap();
268
147
  this._storedBrowserCookieTokenStore = null;
@@ -275,14 +154,17 @@ var _StackClientAppImpl = class __StackClientAppImpl {
275
154
  * - So different token stores are separated and don't leak information between each other, eg. if the same user sends two requests to the same server they should get a different session object
276
155
  */
277
156
  this._sessionsByTokenStoreAndSessionKey = /* @__PURE__ */ new WeakMap();
157
+ if (!__StackClientAppImplIncomplete.LazyStackAdminAppImpl.value) {
158
+ throw new import_errors.StackAssertionError("Admin app implementation not initialized. Did you import the _StackClientApp from stack-app/apps/implementations/index.ts? You can't import it directly from ./apps/implementations/client-app-impl.ts as that causes a circular dependency (see the comment at _LazyStackAdminAppImpl for more details).");
159
+ }
278
160
  if ("interface" in _options) {
279
161
  this._interface = _options.interface;
280
162
  } else {
281
163
  this._interface = new import_stack_shared.StackClientInterface({
282
- getBaseUrl: () => getBaseUrl(_options.baseUrl),
283
- projectId: _options.projectId ?? getDefaultProjectId(),
284
- clientVersion,
285
- publishableClientKey: _options.publishableClientKey ?? getDefaultPublishableClientKey(),
164
+ getBaseUrl: () => (0, import_common2.getBaseUrl)(_options.baseUrl),
165
+ projectId: _options.projectId ?? (0, import_common2.getDefaultProjectId)(),
166
+ clientVersion: import_common2.clientVersion,
167
+ publishableClientKey: _options.publishableClientKey ?? (0, import_common2.getDefaultPublishableClientKey)(),
286
168
  prepareRequest: async () => {
287
169
  await (0, import_stack_sc.cookies)?.();
288
170
  }
@@ -477,7 +359,7 @@ var _StackClientAppImpl = class __StackClientAppImpl {
477
359
  }
478
360
  default: {
479
361
  if (tokenStoreInit === null) {
480
- return createEmptyTokenStore();
362
+ return (0, import_common2.createEmptyTokenStore)();
481
363
  } else if (typeof tokenStoreInit === "object" && "headers" in tokenStoreInit) {
482
364
  if (this._requestTokenStores.has(tokenStoreInit)) return this._requestTokenStores.get(tokenStoreInit);
483
365
  const stackAuthHeader = tokenStoreInit.headers.get("x-stack-auth");
@@ -652,7 +534,7 @@ var _StackClientAppImpl = class __StackClientAppImpl {
652
534
  return result.map((crud2) => app._clientTeamUserFromCrud(crud2));
653
535
  },
654
536
  useUsers() {
655
- const result = useAsyncCache(app._teamMemberProfilesCache, [session, crud.id], "team.useUsers()");
537
+ const result = (0, import_common3.useAsyncCache)(app._teamMemberProfilesCache, [session, crud.id], "team.useUsers()");
656
538
  return result.map((crud2) => app._clientTeamUserFromCrud(crud2));
657
539
  },
658
540
  async listInvitations() {
@@ -660,11 +542,11 @@ var _StackClientAppImpl = class __StackClientAppImpl {
660
542
  return result.map((crud2) => app._clientTeamInvitationFromCrud(session, crud2));
661
543
  },
662
544
  useInvitations() {
663
- const result = useAsyncCache(app._teamInvitationsCache, [session, crud.id], "team.useInvitations()");
545
+ const result = (0, import_common3.useAsyncCache)(app._teamInvitationsCache, [session, crud.id], "team.useInvitations()");
664
546
  return result.map((crud2) => app._clientTeamInvitationFromCrud(session, crud2));
665
547
  },
666
548
  async update(data) {
667
- await app._interface.updateTeam({ data: teamUpdateOptionsToCrud(data), teamId: crud.id }, session);
549
+ await app._interface.updateTeam({ data: (0, import_teams.teamUpdateOptionsToCrud)(data), teamId: crud.id }, session);
668
550
  await app._currentUserTeamsCache.refresh([session]);
669
551
  },
670
552
  async delete() {
@@ -686,7 +568,7 @@ var _StackClientAppImpl = class __StackClientAppImpl {
686
568
  await app._interface.sendCurrentUserContactChannelVerificationEmail(crud.id, (0, import_url.constructRedirectUrl)(app.urls.emailVerification), session);
687
569
  },
688
570
  async update(data) {
689
- await app._interface.updateClientContactChannel(crud.id, contactChannelUpdateOptionsToCrud(data), session);
571
+ await app._interface.updateClientContactChannel(crud.id, (0, import_contact_channels.contactChannelUpdateOptionsToCrud)(data), session);
690
572
  await app._clientContactChannelsCache.refresh([session]);
691
573
  },
692
574
  async delete() {
@@ -734,12 +616,12 @@ var _StackClientAppImpl = class __StackClientAppImpl {
734
616
  let attResp;
735
617
  try {
736
618
  attResp = await (0, import_browser.startRegistration)({ optionsJSON: options_json });
737
- debugger;
738
619
  } catch (error) {
739
620
  if (error instanceof import_browser.WebAuthnError) {
740
621
  return import_results.Result.error(new import_stack_shared.KnownErrors.PasskeyWebAuthnError(error.message, error.name));
741
622
  } else {
742
- return import_results.Result.error(new import_stack_shared.KnownErrors.PasskeyRegistrationFailed("Failed to start passkey registration"));
623
+ (0, import_errors.captureError)("passkey-registration-failed", error);
624
+ return import_results.Result.error(new import_stack_shared.KnownErrors.PasskeyRegistrationFailed("Failed to start passkey registration due to unknown error"));
743
625
  }
744
626
  }
745
627
  const registrationResult = await app._interface.registerPasskey({ credential: attResp, code }, session);
@@ -798,7 +680,7 @@ var _StackClientAppImpl = class __StackClientAppImpl {
798
680
  }
799
681
  function useConnectedAccount(id, options) {
800
682
  const scopeString = options?.scopes?.join(" ");
801
- return useAsyncCache(app._currentUserOAuthConnectionCache, [session, id, scopeString || "", options?.or === "redirect"], "user.useConnectedAccount()");
683
+ return (0, import_common3.useAsyncCache)(app._currentUserOAuthConnectionCache, [session, id, scopeString || "", options?.or === "redirect"], "user.useConnectedAccount()");
802
684
  }
803
685
  return {
804
686
  setDisplayName(displayName) {
@@ -827,11 +709,11 @@ var _StackClientAppImpl = class __StackClientAppImpl {
827
709
  return teams.map((crud2) => app._clientTeamFromCrud(crud2, session));
828
710
  },
829
711
  useTeams() {
830
- const teams = useAsyncCache(app._currentUserTeamsCache, [session], "user.useTeams()");
712
+ const teams = (0, import_common3.useAsyncCache)(app._currentUserTeamsCache, [session], "user.useTeams()");
831
713
  return (0, import_react2.useMemo)(() => teams.map((crud2) => app._clientTeamFromCrud(crud2, session)), [teams]);
832
714
  },
833
715
  async createTeam(data) {
834
- const crud2 = await app._interface.createClientTeam(teamCreateOptionsToCrud(data, "me"), session);
716
+ const crud2 = await app._interface.createClientTeam((0, import_teams.teamCreateOptionsToCrud)(data, "me"), session);
835
717
  await app._currentUserTeamsCache.refresh([session]);
836
718
  return app._clientTeamFromCrud(crud2, session);
837
719
  },
@@ -845,7 +727,7 @@ var _StackClientAppImpl = class __StackClientAppImpl {
845
727
  },
846
728
  usePermissions(scope, options) {
847
729
  const recursive = options?.recursive ?? true;
848
- const permissions = useAsyncCache(app._currentUserPermissionsCache, [session, scope.id, recursive], "user.usePermissions()");
730
+ const permissions = (0, import_common3.useAsyncCache)(app._currentUserPermissionsCache, [session, scope.id, recursive], "user.usePermissions()");
849
731
  return (0, import_react2.useMemo)(() => permissions.map((crud2) => app._clientTeamPermissionFromCrud(crud2)), [permissions]);
850
732
  },
851
733
  usePermission(scope, permissionId) {
@@ -887,7 +769,7 @@ var _StackClientAppImpl = class __StackClientAppImpl {
887
769
  return app._editableTeamProfileFromCrud(result, session);
888
770
  },
889
771
  useTeamProfile(team) {
890
- const result = useAsyncCache(app._currentUserTeamProfileCache, [session, team.id], "user.useTeamProfile()");
772
+ const result = (0, import_common3.useAsyncCache)(app._currentUserTeamProfileCache, [session, team.id], "user.useTeamProfile()");
891
773
  return app._editableTeamProfileFromCrud(result, session);
892
774
  },
893
775
  async delete() {
@@ -899,11 +781,11 @@ var _StackClientAppImpl = class __StackClientAppImpl {
899
781
  return result.map((crud2) => app._clientContactChannelFromCrud(crud2, session));
900
782
  },
901
783
  useContactChannels() {
902
- const result = useAsyncCache(app._clientContactChannelsCache, [session], "user.useContactChannels()");
784
+ const result = (0, import_common3.useAsyncCache)(app._clientContactChannelsCache, [session], "user.useContactChannels()");
903
785
  return result.map((crud2) => app._clientContactChannelFromCrud(crud2, session));
904
786
  },
905
787
  async createContactChannel(data) {
906
- const crud2 = await app._interface.createClientContactChannel(contactChannelCreateOptionsToCrud("me", data), session);
788
+ const crud2 = await app._interface.createClientContactChannel((0, import_contact_channels.contactChannelCreateOptionsToCrud)("me", data), session);
907
789
  await app._clientContactChannelsCache.refresh([session]);
908
790
  return app._clientContactChannelFromCrud(crud2, session);
909
791
  }
@@ -936,7 +818,7 @@ var _StackClientAppImpl = class __StackClientAppImpl {
936
818
  }
937
819
  _getOwnedAdminApp(forProjectId, session) {
938
820
  if (!this._ownedAdminApps.has([session, forProjectId])) {
939
- this._ownedAdminApps.set([session, forProjectId], new _StackAdminAppImpl({
821
+ this._ownedAdminApps.set([session, forProjectId], new __StackClientAppImplIncomplete.LazyStackAdminAppImpl.value({
940
822
  baseUrl: this._interface.options.getBaseUrl(),
941
823
  projectId: forProjectId,
942
824
  tokenStore: null,
@@ -953,7 +835,7 @@ var _StackClientAppImpl = class __StackClientAppImpl {
953
835
  return (0, import_urls.isRelative)(url);
954
836
  }
955
837
  get urls() {
956
- return getUrls(this._urlOptions);
838
+ return (0, import_common2.getUrls)(this._urlOptions);
957
839
  }
958
840
  async _getCurrentUrl() {
959
841
  if (this._redirectMethod === "none") {
@@ -981,9 +863,10 @@ var _StackClientAppImpl = class __StackClientAppImpl {
981
863
  if (typeof this._redirectMethod === "object") {
982
864
  return this._redirectMethod.useNavigate();
983
865
  } else if (this._redirectMethod === "window") {
984
- return () => window.location.assign;
866
+ return (to) => window.location.assign(to);
985
867
  } else if (this._redirectMethod === "nextjs") {
986
- return NextNavigation.useRouter().push;
868
+ const router = NextNavigation.useRouter();
869
+ return (to) => router.push(to);
987
870
  } else {
988
871
  return (to) => {
989
872
  };
@@ -1154,7 +1037,7 @@ var _StackClientAppImpl = class __StackClientAppImpl {
1154
1037
  useUser(options) {
1155
1038
  this._ensurePersistentTokenStore(options?.tokenStore);
1156
1039
  const session = this._useSession(options?.tokenStore);
1157
- const crud = useAsyncCache(this._currentUserCache, [session], "useUser()");
1040
+ const crud = (0, import_common3.useAsyncCache)(this._currentUserCache, [session], "useUser()");
1158
1041
  if (crud === null) {
1159
1042
  switch (options?.or) {
1160
1043
  case "redirect": {
@@ -1175,7 +1058,7 @@ var _StackClientAppImpl = class __StackClientAppImpl {
1175
1058
  }, [crud, session, options?.or]);
1176
1059
  }
1177
1060
  async _updateClientUser(update, session) {
1178
- const res = await this._interface.updateClientUser(userUpdateOptionsToCrud(update), session);
1061
+ const res = await this._interface.updateClientUser((0, import_users.userUpdateOptionsToCrud)(update), session);
1179
1062
  await this._refreshUser(session);
1180
1063
  return res;
1181
1064
  }
@@ -1379,7 +1262,7 @@ var _StackClientAppImpl = class __StackClientAppImpl {
1379
1262
  return this._clientProjectFromCrud(crud);
1380
1263
  }
1381
1264
  useProject() {
1382
- const crud = useAsyncCache(this._currentProjectCache, [], "useProject()");
1265
+ const crud = (0, import_common3.useAsyncCache)(this._currentProjectCache, [], "useProject()");
1383
1266
  return (0, import_react2.useMemo)(() => this._clientProjectFromCrud(crud), [crud]);
1384
1267
  }
1385
1268
  async _listOwnedProjects(session) {
@@ -1392,7 +1275,7 @@ var _StackClientAppImpl = class __StackClientAppImpl {
1392
1275
  }
1393
1276
  _useOwnedProjects(session) {
1394
1277
  this._ensureInternalProject();
1395
- const projects = useAsyncCache(this._ownedProjectsCache, [session], "useOwnedProjects()");
1278
+ const projects = (0, import_common3.useAsyncCache)(this._ownedProjectsCache, [session], "useOwnedProjects()");
1396
1279
  return (0, import_react2.useMemo)(() => projects.map((j) => this._getOwnedAdminApp(j.id, session)._adminOwnedProjectFromCrud(
1397
1280
  j,
1398
1281
  () => this._refreshOwnedProjects(session)
@@ -1400,7 +1283,7 @@ var _StackClientAppImpl = class __StackClientAppImpl {
1400
1283
  }
1401
1284
  async _createProject(session, newProject) {
1402
1285
  this._ensureInternalProject();
1403
- const crud = await this._interface.createProject(adminProjectCreateOptionsToCrud(newProject), session);
1286
+ const crud = await this._interface.createProject((0, import_projects.adminProjectCreateOptionsToCrud)(newProject), session);
1404
1287
  const res = this._getOwnedAdminApp(crud.id, session)._adminOwnedProjectFromCrud(
1405
1288
  crud,
1406
1289
  () => this._refreshOwnedProjects(session)
@@ -1422,7 +1305,7 @@ var _StackClientAppImpl = class __StackClientAppImpl {
1422
1305
  async _refreshOwnedProjects(session) {
1423
1306
  await this._ownedProjectsCache.refresh([session]);
1424
1307
  }
1425
- static get [stackAppInternalsSymbol]() {
1308
+ static get [import_common.stackAppInternalsSymbol]() {
1426
1309
  return {
1427
1310
  fromClientJson: (json) => {
1428
1311
  const providedCheckString = JSON.stringify((0, import_objects.omit)(json, [
@@ -1436,14 +1319,14 @@ var _StackClientAppImpl = class __StackClientAppImpl {
1436
1319
  }
1437
1320
  return clientApp;
1438
1321
  }
1439
- return new __StackClientAppImpl({
1322
+ return new __StackClientAppImplIncomplete({
1440
1323
  ...json,
1441
1324
  checkString: providedCheckString
1442
1325
  });
1443
1326
  }
1444
1327
  };
1445
1328
  }
1446
- get [stackAppInternalsSymbol]() {
1329
+ get [import_common.stackAppInternalsSymbol]() {
1447
1330
  return {
1448
1331
  toClientJson: () => {
1449
1332
  if (!("publishableClientKey" in this._interface.options)) {
@@ -1474,977 +1357,17 @@ var _StackClientAppImpl = class __StackClientAppImpl {
1474
1357
  };
1475
1358
  }
1476
1359
  };
1477
- var _StackServerAppImpl = class extends _StackClientAppImpl {
1478
- constructor(options) {
1479
- super("interface" in options ? {
1480
- interface: options.interface,
1481
- tokenStore: options.tokenStore,
1482
- urls: options.urls,
1483
- oauthScopesOnSignIn: options.oauthScopesOnSignIn
1484
- } : {
1485
- interface: new import_stack_shared.StackServerInterface({
1486
- getBaseUrl: () => getBaseUrl(options.baseUrl),
1487
- projectId: options.projectId ?? getDefaultProjectId(),
1488
- clientVersion,
1489
- publishableClientKey: options.publishableClientKey ?? getDefaultPublishableClientKey(),
1490
- secretServerKey: options.secretServerKey ?? getDefaultSecretServerKey()
1491
- }),
1492
- baseUrl: options.baseUrl,
1493
- projectId: options.projectId,
1494
- publishableClientKey: options.publishableClientKey,
1495
- tokenStore: options.tokenStore,
1496
- urls: options.urls ?? {},
1497
- oauthScopesOnSignIn: options.oauthScopesOnSignIn ?? {},
1498
- redirectMethod: options.redirectMethod
1499
- });
1500
- // TODO override the client user cache to use the server user cache, so we save some requests
1501
- this._currentServerUserCache = createCacheBySession(async (session) => {
1502
- if (session.isKnownToBeInvalid()) {
1503
- return null;
1504
- }
1505
- return await this._interface.getServerUserByToken(session);
1506
- });
1507
- this._serverUsersCache = createCache(async ([cursor, limit, orderBy, desc, query]) => {
1508
- return await this._interface.listServerUsers({ cursor, limit, orderBy, desc, query });
1509
- });
1510
- this._serverUserCache = createCache(async ([userId]) => {
1511
- const user = await this._interface.getServerUserById(userId);
1512
- return import_results.Result.or(user, null);
1513
- });
1514
- this._serverTeamsCache = createCache(async ([userId]) => {
1515
- return await this._interface.listServerTeams({ userId });
1516
- });
1517
- this._serverTeamUserPermissionsCache = createCache(async ([teamId, userId, recursive]) => {
1518
- return await this._interface.listServerTeamPermissions({ teamId, userId, recursive }, null);
1519
- });
1520
- this._serverUserOAuthConnectionAccessTokensCache = createCache(
1521
- async ([userId, providerId, scope]) => {
1522
- try {
1523
- const result = await this._interface.createServerProviderAccessToken(userId, providerId, scope || "");
1524
- return { accessToken: result.access_token };
1525
- } catch (err) {
1526
- if (!(err instanceof import_stack_shared.KnownErrors.OAuthConnectionDoesNotHaveRequiredScope || err instanceof import_stack_shared.KnownErrors.OAuthConnectionNotConnectedToUser)) {
1527
- throw err;
1528
- }
1529
- }
1530
- return null;
1531
- }
1532
- );
1533
- this._serverUserOAuthConnectionCache = createCache(
1534
- async ([userId, providerId, scope, redirect]) => {
1535
- return await this._getUserOAuthConnectionCacheFn({
1536
- getUser: async () => import_results.Result.orThrow(await this._serverUserCache.getOrWait([userId], "write-only")),
1537
- getOrWaitOAuthToken: async () => import_results.Result.orThrow(await this._serverUserOAuthConnectionAccessTokensCache.getOrWait([userId, providerId, scope || ""], "write-only")),
1538
- useOAuthToken: () => useAsyncCache(this._serverUserOAuthConnectionAccessTokensCache, [userId, providerId, scope || ""], "user.useConnectedAccount()"),
1539
- providerId,
1540
- scope,
1541
- redirect,
1542
- session: null
1543
- });
1544
- }
1545
- );
1546
- this._serverTeamMemberProfilesCache = createCache(
1547
- async ([teamId]) => {
1548
- return await this._interface.listServerTeamMemberProfiles({ teamId });
1549
- }
1550
- );
1551
- this._serverTeamInvitationsCache = createCache(
1552
- async ([teamId]) => {
1553
- return await this._interface.listServerTeamInvitations({ teamId });
1554
- }
1555
- );
1556
- this._serverUserTeamProfileCache = createCache(
1557
- async ([teamId, userId]) => {
1558
- return await this._interface.getServerTeamMemberProfile({ teamId, userId });
1559
- }
1560
- );
1561
- this._serverContactChannelsCache = createCache(
1562
- async ([userId]) => {
1563
- return await this._interface.listServerContactChannels(userId);
1564
- }
1565
- );
1566
- }
1567
- async _updateServerUser(userId, update) {
1568
- const result = await this._interface.updateServerUser(userId, serverUserUpdateOptionsToCrud(update));
1569
- await this._refreshUsers();
1570
- return result;
1571
- }
1572
- _serverEditableTeamProfileFromCrud(crud) {
1573
- const app = this;
1574
- return {
1575
- displayName: crud.display_name,
1576
- profileImageUrl: crud.profile_image_url,
1577
- async update(update) {
1578
- await app._interface.updateServerTeamMemberProfile({
1579
- teamId: crud.team_id,
1580
- userId: crud.user_id,
1581
- profile: {
1582
- display_name: update.displayName,
1583
- profile_image_url: update.profileImageUrl
1584
- }
1585
- });
1586
- await app._serverUserTeamProfileCache.refresh([crud.team_id, crud.user_id]);
1587
- }
1588
- };
1589
- }
1590
- _serverContactChannelFromCrud(userId, crud) {
1591
- const app = this;
1592
- return {
1593
- id: crud.id,
1594
- value: crud.value,
1595
- type: crud.type,
1596
- isVerified: crud.is_verified,
1597
- isPrimary: crud.is_primary,
1598
- usedForAuth: crud.used_for_auth,
1599
- async sendVerificationEmail(options) {
1600
- if (!options?.callbackUrl && !await app._getCurrentUrl()) {
1601
- throw new Error("Cannot send verification email without a callback URL from the server or without a redirect method. Make sure you pass the `callbackUrl` option: `sendVerificationEmail({ callbackUrl: ... })`");
1602
- }
1603
- await app._interface.sendServerContactChannelVerificationEmail(userId, crud.id, options?.callbackUrl ?? (0, import_url.constructRedirectUrl)(app.urls.emailVerification));
1604
- },
1605
- async update(data) {
1606
- await app._interface.updateServerContactChannel(userId, crud.id, serverContactChannelUpdateOptionsToCrud(data));
1607
- },
1608
- async delete() {
1609
- await app._interface.deleteServerContactChannel(userId, crud.id);
1610
- }
1611
- };
1612
- }
1613
- _serverUserFromCrud(crud) {
1614
- const app = this;
1615
- async function getConnectedAccount(id, options) {
1616
- const scopeString = options?.scopes?.join(" ");
1617
- return import_results.Result.orThrow(await app._serverUserOAuthConnectionCache.getOrWait([crud.id, id, scopeString || "", options?.or === "redirect"], "write-only"));
1618
- }
1619
- function useConnectedAccount(id, options) {
1620
- const scopeString = options?.scopes?.join(" ");
1621
- return useAsyncCache(app._serverUserOAuthConnectionCache, [crud.id, id, scopeString || "", options?.or === "redirect"], "user.useConnectedAccount()");
1622
- }
1623
- return {
1624
- ...super._createBaseUser(crud),
1625
- lastActiveAt: new Date(crud.last_active_at_millis),
1626
- serverMetadata: crud.server_metadata,
1627
- async setPrimaryEmail(email, options) {
1628
- await app._updateServerUser(crud.id, { primaryEmail: email, primaryEmailVerified: options?.verified });
1629
- },
1630
- async grantPermission(scope, permissionId) {
1631
- await app._interface.grantServerTeamUserPermission(scope.id, crud.id, permissionId);
1632
- for (const recursive of [true, false]) {
1633
- await app._serverTeamUserPermissionsCache.refresh([scope.id, crud.id, recursive]);
1634
- }
1635
- },
1636
- async revokePermission(scope, permissionId) {
1637
- await app._interface.revokeServerTeamUserPermission(scope.id, crud.id, permissionId);
1638
- for (const recursive of [true, false]) {
1639
- await app._serverTeamUserPermissionsCache.refresh([scope.id, crud.id, recursive]);
1640
- }
1641
- },
1642
- async delete() {
1643
- const res = await app._interface.deleteServerServerUser(crud.id);
1644
- await app._refreshUsers();
1645
- return res;
1646
- },
1647
- async createSession(options) {
1648
- const tokens = await app._interface.createServerUserSession(crud.id, options.expiresInMillis ?? 1e3 * 60 * 60 * 24 * 365);
1649
- return {
1650
- async getTokens() {
1651
- return tokens;
1652
- }
1653
- };
1654
- },
1655
- async setDisplayName(displayName) {
1656
- return await this.update({ displayName });
1657
- },
1658
- async setClientMetadata(metadata) {
1659
- return await this.update({ clientMetadata: metadata });
1660
- },
1661
- async setClientReadOnlyMetadata(metadata) {
1662
- return await this.update({ clientReadOnlyMetadata: metadata });
1663
- },
1664
- async setServerMetadata(metadata) {
1665
- return await this.update({ serverMetadata: metadata });
1666
- },
1667
- async setSelectedTeam(team) {
1668
- return await this.update({ selectedTeamId: team?.id ?? null });
1669
- },
1670
- getConnectedAccount,
1671
- useConnectedAccount,
1672
- selectedTeam: crud.selected_team ? app._serverTeamFromCrud(crud.selected_team) : null,
1673
- async getTeam(teamId) {
1674
- const teams = await this.listTeams();
1675
- return teams.find((t) => t.id === teamId) ?? null;
1676
- },
1677
- useTeam(teamId) {
1678
- const teams = this.useTeams();
1679
- return (0, import_react2.useMemo)(() => {
1680
- return teams.find((t) => t.id === teamId) ?? null;
1681
- }, [teams, teamId]);
1682
- },
1683
- async listTeams() {
1684
- const teams = import_results.Result.orThrow(await app._serverTeamsCache.getOrWait([crud.id], "write-only"));
1685
- return teams.map((t) => app._serverTeamFromCrud(t));
1686
- },
1687
- useTeams() {
1688
- const teams = useAsyncCache(app._serverTeamsCache, [crud.id], "user.useTeams()");
1689
- return (0, import_react2.useMemo)(() => teams.map((t) => app._serverTeamFromCrud(t)), [teams]);
1690
- },
1691
- createTeam: async (data) => {
1692
- const team = await app._interface.createServerTeam(serverTeamCreateOptionsToCrud({
1693
- creatorUserId: crud.id,
1694
- ...data
1695
- }));
1696
- await app._serverTeamsCache.refresh([void 0]);
1697
- return app._serverTeamFromCrud(team);
1698
- },
1699
- leaveTeam: async (team) => {
1700
- await app._interface.leaveServerTeam({ teamId: team.id, userId: crud.id });
1701
- },
1702
- async listPermissions(scope, options) {
1703
- const recursive = options?.recursive ?? true;
1704
- const permissions = import_results.Result.orThrow(await app._serverTeamUserPermissionsCache.getOrWait([scope.id, crud.id, recursive], "write-only"));
1705
- return permissions.map((crud2) => app._serverPermissionFromCrud(crud2));
1706
- },
1707
- usePermissions(scope, options) {
1708
- const recursive = options?.recursive ?? true;
1709
- const permissions = useAsyncCache(app._serverTeamUserPermissionsCache, [scope.id, crud.id, recursive], "user.usePermissions()");
1710
- return (0, import_react2.useMemo)(() => permissions.map((crud2) => app._serverPermissionFromCrud(crud2)), [permissions]);
1711
- },
1712
- async getPermission(scope, permissionId) {
1713
- const permissions = await this.listPermissions(scope);
1714
- return permissions.find((p) => p.id === permissionId) ?? null;
1715
- },
1716
- usePermission(scope, permissionId) {
1717
- const permissions = this.usePermissions(scope);
1718
- return (0, import_react2.useMemo)(() => permissions.find((p) => p.id === permissionId) ?? null, [permissions, permissionId]);
1719
- },
1720
- async hasPermission(scope, permissionId) {
1721
- return await this.getPermission(scope, permissionId) !== null;
1722
- },
1723
- async update(update) {
1724
- await app._updateServerUser(crud.id, update);
1725
- },
1726
- async sendVerificationEmail() {
1727
- return await app._checkFeatureSupport("sendVerificationEmail() on ServerUser", {});
1728
- },
1729
- async updatePassword(options) {
1730
- const result = await this.update({ password: options.newPassword });
1731
- await app._serverUserCache.refresh([crud.id]);
1732
- return result;
1733
- },
1734
- async setPassword(options) {
1735
- const result = await this.update(options);
1736
- await app._serverUserCache.refresh([crud.id]);
1737
- return result;
1738
- },
1739
- async getTeamProfile(team) {
1740
- const result = import_results.Result.orThrow(await app._serverUserTeamProfileCache.getOrWait([team.id, crud.id], "write-only"));
1741
- return app._serverEditableTeamProfileFromCrud(result);
1742
- },
1743
- useTeamProfile(team) {
1744
- const result = useAsyncCache(app._serverUserTeamProfileCache, [team.id, crud.id], "user.useTeamProfile()");
1745
- return (0, import_react2.useMemo)(() => app._serverEditableTeamProfileFromCrud(result), [result]);
1746
- },
1747
- async listContactChannels() {
1748
- const result = import_results.Result.orThrow(await app._serverContactChannelsCache.getOrWait([crud.id], "write-only"));
1749
- return result.map((data) => app._serverContactChannelFromCrud(crud.id, data));
1750
- },
1751
- useContactChannels() {
1752
- const result = useAsyncCache(app._serverContactChannelsCache, [crud.id], "user.useContactChannels()");
1753
- return (0, import_react2.useMemo)(() => result.map((data) => app._serverContactChannelFromCrud(crud.id, data)), [result]);
1754
- },
1755
- createContactChannel: async (data) => {
1756
- const contactChannel = await app._interface.createServerContactChannel(serverContactChannelCreateOptionsToCrud(crud.id, data));
1757
- await app._serverContactChannelsCache.refresh([crud.id]);
1758
- return app._serverContactChannelFromCrud(crud.id, contactChannel);
1759
- }
1760
- };
1761
- }
1762
- _serverTeamUserFromCrud(crud) {
1763
- return {
1764
- ...this._serverUserFromCrud(crud.user),
1765
- teamProfile: {
1766
- displayName: crud.display_name,
1767
- profileImageUrl: crud.profile_image_url
1768
- }
1769
- };
1770
- }
1771
- _serverTeamInvitationFromCrud(crud) {
1772
- return {
1773
- id: crud.id,
1774
- recipientEmail: crud.recipient_email,
1775
- expiresAt: new Date(crud.expires_at_millis),
1776
- revoke: async () => {
1777
- await this._interface.revokeServerTeamInvitation(crud.id, crud.team_id);
1778
- }
1779
- };
1780
- }
1781
- _currentUserFromCrud(crud, session) {
1782
- const app = this;
1783
- const currentUser = {
1784
- ...this._serverUserFromCrud(crud),
1785
- ...this._createAuth(session),
1786
- ...this._isInternalProject() ? this._createInternalUserExtra(session) : {}
1787
- };
1788
- Object.freeze(currentUser);
1789
- return currentUser;
1790
- }
1791
- _serverTeamFromCrud(crud) {
1792
- const app = this;
1793
- return {
1794
- id: crud.id,
1795
- displayName: crud.display_name,
1796
- profileImageUrl: crud.profile_image_url,
1797
- createdAt: new Date(crud.created_at_millis),
1798
- clientMetadata: crud.client_metadata,
1799
- clientReadOnlyMetadata: crud.client_read_only_metadata,
1800
- serverMetadata: crud.server_metadata,
1801
- async update(update) {
1802
- await app._interface.updateServerTeam(crud.id, serverTeamUpdateOptionsToCrud(update));
1803
- await app._serverTeamsCache.refresh([void 0]);
1804
- },
1805
- async delete() {
1806
- await app._interface.deleteServerTeam(crud.id);
1807
- await app._serverTeamsCache.refresh([void 0]);
1808
- },
1809
- async listUsers() {
1810
- const result = import_results.Result.orThrow(await app._serverTeamMemberProfilesCache.getOrWait([crud.id], "write-only"));
1811
- return result.map((u) => app._serverTeamUserFromCrud(u));
1812
- },
1813
- useUsers() {
1814
- const result = useAsyncCache(app._serverTeamMemberProfilesCache, [crud.id], "team.useUsers()");
1815
- return (0, import_react2.useMemo)(() => result.map((u) => app._serverTeamUserFromCrud(u)), [result]);
1816
- },
1817
- async addUser(userId) {
1818
- await app._interface.addServerUserToTeam({
1819
- teamId: crud.id,
1820
- userId
1821
- });
1822
- await app._serverTeamMemberProfilesCache.refresh([crud.id]);
1823
- },
1824
- async removeUser(userId) {
1825
- await app._interface.removeServerUserFromTeam({
1826
- teamId: crud.id,
1827
- userId
1828
- });
1829
- await app._serverTeamMemberProfilesCache.refresh([crud.id]);
1830
- },
1831
- async inviteUser(options) {
1832
- if (!options.callbackUrl && !await app._getCurrentUrl()) {
1833
- throw new Error("Cannot invite user without a callback URL from the server or without a redirect method. Make sure you pass the `callbackUrl` option: `inviteUser({ email, callbackUrl: ... })`");
1834
- }
1835
- await app._interface.sendServerTeamInvitation({
1836
- teamId: crud.id,
1837
- email: options.email,
1838
- callbackUrl: options.callbackUrl ?? (0, import_url.constructRedirectUrl)(app.urls.teamInvitation)
1839
- });
1840
- await app._serverTeamInvitationsCache.refresh([crud.id]);
1841
- },
1842
- async listInvitations() {
1843
- const result = import_results.Result.orThrow(await app._serverTeamInvitationsCache.getOrWait([crud.id], "write-only"));
1844
- return result.map((crud2) => app._serverTeamInvitationFromCrud(crud2));
1845
- },
1846
- useInvitations() {
1847
- const result = useAsyncCache(app._serverTeamInvitationsCache, [crud.id], "team.useInvitations()");
1848
- return (0, import_react2.useMemo)(() => result.map((crud2) => app._serverTeamInvitationFromCrud(crud2)), [result]);
1849
- }
1850
- };
1851
- }
1852
- async createUser(options) {
1853
- const crud = await this._interface.createServerUser(serverUserCreateOptionsToCrud(options));
1854
- await this._refreshUsers();
1855
- return this._serverUserFromCrud(crud);
1856
- }
1857
- async getUser(options) {
1858
- if (typeof options === "string") {
1859
- return await this.getServerUserById(options);
1860
- } else {
1861
- this._ensurePersistentTokenStore(options?.tokenStore);
1862
- const session = await this._getSession(options?.tokenStore);
1863
- const crud = import_results.Result.orThrow(await this._currentServerUserCache.getOrWait([session], "write-only"));
1864
- if (crud === null) {
1865
- switch (options?.or) {
1866
- case "redirect": {
1867
- await this.redirectToSignIn({ replace: true });
1868
- break;
1869
- }
1870
- case "throw": {
1871
- throw new Error("User is not signed in but getUser was called with { or: 'throw' }");
1872
- }
1873
- default: {
1874
- return null;
1875
- }
1876
- }
1877
- }
1878
- return crud && this._currentUserFromCrud(crud, session);
1879
- }
1880
- }
1881
- async getServerUser() {
1882
- console.warn("stackServerApp.getServerUser is deprecated; use stackServerApp.getUser instead");
1883
- return await this.getUser();
1884
- }
1885
- async getServerUserById(userId) {
1886
- const crud = import_results.Result.orThrow(await this._serverUserCache.getOrWait([userId], "write-only"));
1887
- return crud && this._serverUserFromCrud(crud);
1888
- }
1889
- useUser(options) {
1890
- if (typeof options === "string") {
1891
- return this.useUserById(options);
1892
- } else {
1893
- this._ensurePersistentTokenStore(options?.tokenStore);
1894
- const session = this._useSession(options?.tokenStore);
1895
- const crud = useAsyncCache(this._currentServerUserCache, [session], "useUser()");
1896
- if (crud === null) {
1897
- switch (options?.or) {
1898
- case "redirect": {
1899
- (0, import_promises.runAsynchronously)(this.redirectToSignIn({ replace: true }));
1900
- (0, import_react.suspend)();
1901
- throw new import_errors.StackAssertionError("suspend should never return");
1902
- }
1903
- case "throw": {
1904
- throw new Error("User is not signed in but useUser was called with { or: 'throw' }");
1905
- }
1906
- case void 0:
1907
- case "return-null": {
1908
- }
1909
- }
1910
- }
1911
- return (0, import_react2.useMemo)(() => {
1912
- return crud && this._currentUserFromCrud(crud, session);
1913
- }, [crud, session, options?.or]);
1914
- }
1915
- }
1916
- useUserById(userId) {
1917
- const crud = useAsyncCache(this._serverUserCache, [userId], "useUserById()");
1918
- return (0, import_react2.useMemo)(() => {
1919
- return crud && this._serverUserFromCrud(crud);
1920
- }, [crud]);
1921
- }
1922
- async listUsers(options) {
1923
- const crud = import_results.Result.orThrow(await this._serverUsersCache.getOrWait([options?.cursor, options?.limit, options?.orderBy, options?.desc, options?.query], "write-only"));
1924
- const result = crud.items.map((j) => this._serverUserFromCrud(j));
1925
- result.nextCursor = crud.pagination?.next_cursor ?? null;
1926
- return result;
1927
- }
1928
- useUsers(options) {
1929
- const crud = useAsyncCache(this._serverUsersCache, [options?.cursor, options?.limit, options?.orderBy, options?.desc, options?.query], "useServerUsers()");
1930
- const result = crud.items.map((j) => this._serverUserFromCrud(j));
1931
- result.nextCursor = crud.pagination?.next_cursor ?? null;
1932
- return result;
1933
- }
1934
- _serverPermissionFromCrud(crud) {
1935
- return {
1936
- id: crud.id
1937
- };
1938
- }
1939
- _serverTeamPermissionDefinitionFromCrud(crud) {
1940
- return {
1941
- id: crud.id,
1942
- description: crud.description,
1943
- containedPermissionIds: crud.contained_permission_ids
1944
- };
1945
- }
1946
- async listTeams() {
1947
- const teams = import_results.Result.orThrow(await this._serverTeamsCache.getOrWait([void 0], "write-only"));
1948
- return teams.map((t) => this._serverTeamFromCrud(t));
1949
- }
1950
- async createTeam(data) {
1951
- const team = await this._interface.createServerTeam(serverTeamCreateOptionsToCrud(data));
1952
- await this._serverTeamsCache.refresh([void 0]);
1953
- return this._serverTeamFromCrud(team);
1954
- }
1955
- useTeams() {
1956
- const teams = useAsyncCache(this._serverTeamsCache, [void 0], "useServerTeams()");
1957
- return (0, import_react2.useMemo)(() => {
1958
- return teams.map((t) => this._serverTeamFromCrud(t));
1959
- }, [teams]);
1960
- }
1961
- async getTeam(teamId) {
1962
- const teams = await this.listTeams();
1963
- return teams.find((t) => t.id === teamId) ?? null;
1964
- }
1965
- useTeam(teamId) {
1966
- const teams = this.useTeams();
1967
- return (0, import_react2.useMemo)(() => {
1968
- return teams.find((t) => t.id === teamId) ?? null;
1969
- }, [teams, teamId]);
1970
- }
1971
- async _refreshSession(session) {
1972
- await Promise.all([
1973
- super._refreshUser(session),
1974
- this._currentServerUserCache.refresh([session])
1975
- ]);
1976
- }
1977
- async _refreshUsers() {
1978
- await Promise.all([
1979
- super._refreshUsers(),
1980
- this._serverUserCache.refreshWhere(() => true),
1981
- this._serverUsersCache.refreshWhere(() => true),
1982
- this._serverContactChannelsCache.refreshWhere(() => true)
1983
- ]);
1984
- }
1985
- };
1986
- var _StackAdminAppImpl = class extends _StackServerAppImpl {
1987
- constructor(options) {
1988
- super({
1989
- interface: new import_stack_shared.StackAdminInterface({
1990
- getBaseUrl: () => getBaseUrl(options.baseUrl),
1991
- projectId: options.projectId ?? getDefaultProjectId(),
1992
- clientVersion,
1993
- ..."projectOwnerSession" in options ? {
1994
- projectOwnerSession: options.projectOwnerSession
1995
- } : {
1996
- publishableClientKey: options.publishableClientKey ?? getDefaultPublishableClientKey(),
1997
- secretServerKey: options.secretServerKey ?? getDefaultSecretServerKey(),
1998
- superSecretAdminKey: options.superSecretAdminKey ?? getDefaultSuperSecretAdminKey()
1999
- }
2000
- }),
2001
- baseUrl: options.baseUrl,
2002
- projectId: options.projectId,
2003
- tokenStore: options.tokenStore,
2004
- urls: options.urls,
2005
- oauthScopesOnSignIn: options.oauthScopesOnSignIn,
2006
- redirectMethod: options.redirectMethod
2007
- });
2008
- this._adminProjectCache = createCache(async () => {
2009
- return await this._interface.getProject();
2010
- });
2011
- this._apiKeysCache = createCache(async () => {
2012
- return await this._interface.listApiKeys();
2013
- });
2014
- this._adminEmailTemplatesCache = createCache(async () => {
2015
- return await this._interface.listEmailTemplates();
2016
- });
2017
- this._adminTeamPermissionDefinitionsCache = createCache(async () => {
2018
- return await this._interface.listPermissionDefinitions();
2019
- });
2020
- this._svixTokenCache = createCache(async () => {
2021
- return await this._interface.getSvixToken();
2022
- });
2023
- this._metricsCache = createCache(async () => {
2024
- return await this._interface.getMetrics();
2025
- });
2026
- }
2027
- _adminOwnedProjectFromCrud(data, onRefresh) {
2028
- if (this._tokenStoreInit !== null) {
2029
- throw new import_errors.StackAssertionError("Owned apps must always have tokenStore === null \u2014 did you not create this project with app._createOwnedApp()?");
2030
- ;
2031
- }
2032
- return {
2033
- ...this._adminProjectFromCrud(data, onRefresh),
2034
- app: this
2035
- };
2036
- }
2037
- _adminProjectFromCrud(data, onRefresh) {
2038
- if (data.id !== this.projectId) {
2039
- throw new import_errors.StackAssertionError(`The project ID of the provided project JSON (${data.id}) does not match the project ID of the app (${this.projectId})!`);
2040
- }
2041
- const app = this;
2042
- return {
2043
- id: data.id,
2044
- displayName: data.display_name,
2045
- description: data.description,
2046
- createdAt: new Date(data.created_at_millis),
2047
- userCount: data.user_count,
2048
- isProductionMode: data.is_production_mode,
2049
- config: {
2050
- id: data.config.id,
2051
- signUpEnabled: data.config.sign_up_enabled,
2052
- credentialEnabled: data.config.credential_enabled,
2053
- magicLinkEnabled: data.config.magic_link_enabled,
2054
- passkeyEnabled: data.config.passkey_enabled,
2055
- clientTeamCreationEnabled: data.config.client_team_creation_enabled,
2056
- clientUserDeletionEnabled: data.config.client_user_deletion_enabled,
2057
- allowLocalhost: data.config.allow_localhost,
2058
- oauthProviders: data.config.oauth_providers.map((p) => p.type === "shared" ? {
2059
- id: p.id,
2060
- enabled: p.enabled,
2061
- type: "shared"
2062
- } : {
2063
- id: p.id,
2064
- enabled: p.enabled,
2065
- type: "standard",
2066
- clientId: p.client_id ?? (0, import_errors.throwErr)("Client ID is missing"),
2067
- clientSecret: p.client_secret ?? (0, import_errors.throwErr)("Client secret is missing"),
2068
- facebookConfigId: p.facebook_config_id,
2069
- microsoftTenantId: p.microsoft_tenant_id
2070
- }),
2071
- emailConfig: data.config.email_config.type === "shared" ? {
2072
- type: "shared"
2073
- } : {
2074
- type: "standard",
2075
- host: data.config.email_config.host ?? (0, import_errors.throwErr)("Email host is missing"),
2076
- port: data.config.email_config.port ?? (0, import_errors.throwErr)("Email port is missing"),
2077
- username: data.config.email_config.username ?? (0, import_errors.throwErr)("Email username is missing"),
2078
- password: data.config.email_config.password ?? (0, import_errors.throwErr)("Email password is missing"),
2079
- senderName: data.config.email_config.sender_name ?? (0, import_errors.throwErr)("Email sender name is missing"),
2080
- senderEmail: data.config.email_config.sender_email ?? (0, import_errors.throwErr)("Email sender email is missing")
2081
- },
2082
- domains: data.config.domains.map((d) => ({
2083
- domain: d.domain,
2084
- handlerPath: d.handler_path
2085
- })),
2086
- createTeamOnSignUp: data.config.create_team_on_sign_up,
2087
- teamCreatorDefaultPermissions: data.config.team_creator_default_permissions,
2088
- teamMemberDefaultPermissions: data.config.team_member_default_permissions
2089
- },
2090
- async update(update) {
2091
- await app._interface.updateProject(adminProjectUpdateOptionsToCrud(update));
2092
- await onRefresh();
2093
- },
2094
- async delete() {
2095
- await app._interface.deleteProject();
2096
- },
2097
- async getProductionModeErrors() {
2098
- return (0, import_production_mode.getProductionModeErrors)(data);
2099
- },
2100
- useProductionModeErrors() {
2101
- return (0, import_production_mode.getProductionModeErrors)(data);
2102
- }
2103
- };
2104
- }
2105
- _adminEmailTemplateFromCrud(data) {
2106
- return {
2107
- type: data.type,
2108
- subject: data.subject,
2109
- content: data.content,
2110
- isDefault: data.is_default
2111
- };
2112
- }
2113
- async getProject() {
2114
- return this._adminProjectFromCrud(
2115
- import_results.Result.orThrow(await this._adminProjectCache.getOrWait([], "write-only")),
2116
- () => this._refreshProject()
2117
- );
2118
- }
2119
- useProject() {
2120
- const crud = useAsyncCache(this._adminProjectCache, [], "useProjectAdmin()");
2121
- return (0, import_react2.useMemo)(() => this._adminProjectFromCrud(
2122
- crud,
2123
- () => this._refreshProject()
2124
- ), [crud]);
2125
- }
2126
- _createApiKeyBaseFromCrud(data) {
2127
- const app = this;
2128
- return {
2129
- id: data.id,
2130
- description: data.description,
2131
- expiresAt: new Date(data.expires_at_millis),
2132
- manuallyRevokedAt: data.manually_revoked_at_millis ? new Date(data.manually_revoked_at_millis) : null,
2133
- createdAt: new Date(data.created_at_millis),
2134
- isValid() {
2135
- return this.whyInvalid() === null;
2136
- },
2137
- whyInvalid() {
2138
- if (this.expiresAt.getTime() < Date.now()) return "expired";
2139
- if (this.manuallyRevokedAt) return "manually-revoked";
2140
- return null;
2141
- },
2142
- async revoke() {
2143
- const res = await app._interface.revokeApiKeyById(data.id);
2144
- await app._refreshApiKeys();
2145
- return res;
2146
- }
2147
- };
2148
- }
2149
- _createApiKeyFromCrud(data) {
2150
- return {
2151
- ...this._createApiKeyBaseFromCrud(data),
2152
- publishableClientKey: data.publishable_client_key ? { lastFour: data.publishable_client_key.last_four } : null,
2153
- secretServerKey: data.secret_server_key ? { lastFour: data.secret_server_key.last_four } : null,
2154
- superSecretAdminKey: data.super_secret_admin_key ? { lastFour: data.super_secret_admin_key.last_four } : null
2155
- };
2156
- }
2157
- _createApiKeyFirstViewFromCrud(data) {
2158
- return {
2159
- ...this._createApiKeyBaseFromCrud(data),
2160
- publishableClientKey: data.publishable_client_key,
2161
- secretServerKey: data.secret_server_key,
2162
- superSecretAdminKey: data.super_secret_admin_key
2163
- };
2164
- }
2165
- async listApiKeys() {
2166
- const crud = import_results.Result.orThrow(await this._apiKeysCache.getOrWait([], "write-only"));
2167
- return crud.map((j) => this._createApiKeyFromCrud(j));
2168
- }
2169
- useApiKeys() {
2170
- const crud = useAsyncCache(this._apiKeysCache, [], "useApiKeys()");
2171
- return (0, import_react2.useMemo)(() => {
2172
- return crud.map((j) => this._createApiKeyFromCrud(j));
2173
- }, [crud]);
2174
- }
2175
- async createApiKey(options) {
2176
- const crud = await this._interface.createApiKey(apiKeyCreateOptionsToCrud(options));
2177
- await this._refreshApiKeys();
2178
- return this._createApiKeyFirstViewFromCrud(crud);
2179
- }
2180
- useEmailTemplates() {
2181
- const crud = useAsyncCache(this._adminEmailTemplatesCache, [], "useEmailTemplates()");
2182
- return (0, import_react2.useMemo)(() => {
2183
- return crud.map((j) => this._adminEmailTemplateFromCrud(j));
2184
- }, [crud]);
2185
- }
2186
- async listEmailTemplates() {
2187
- const crud = import_results.Result.orThrow(await this._adminEmailTemplatesCache.getOrWait([], "write-only"));
2188
- return crud.map((j) => this._adminEmailTemplateFromCrud(j));
2189
- }
2190
- async updateEmailTemplate(type, data) {
2191
- await this._interface.updateEmailTemplate(type, adminEmailTemplateUpdateOptionsToCrud(data));
2192
- await this._adminEmailTemplatesCache.refresh([]);
2193
- }
2194
- async resetEmailTemplate(type) {
2195
- await this._interface.resetEmailTemplate(type);
2196
- await this._adminEmailTemplatesCache.refresh([]);
2197
- }
2198
- async createTeamPermissionDefinition(data) {
2199
- const crud = await this._interface.createPermissionDefinition(serverTeamPermissionDefinitionCreateOptionsToCrud(data));
2200
- await this._adminTeamPermissionDefinitionsCache.refresh([]);
2201
- return this._serverTeamPermissionDefinitionFromCrud(crud);
2202
- }
2203
- async updateTeamPermissionDefinition(permissionId, data) {
2204
- await this._interface.updatePermissionDefinition(permissionId, serverTeamPermissionDefinitionUpdateOptionsToCrud(data));
2205
- await this._adminTeamPermissionDefinitionsCache.refresh([]);
2206
- }
2207
- async deleteTeamPermissionDefinition(permissionId) {
2208
- await this._interface.deletePermissionDefinition(permissionId);
2209
- await this._adminTeamPermissionDefinitionsCache.refresh([]);
2210
- }
2211
- async listTeamPermissionDefinitions() {
2212
- const crud = import_results.Result.orThrow(await this._adminTeamPermissionDefinitionsCache.getOrWait([], "write-only"));
2213
- return crud.map((p) => this._serverTeamPermissionDefinitionFromCrud(p));
2214
- }
2215
- useTeamPermissionDefinitions() {
2216
- const crud = useAsyncCache(this._adminTeamPermissionDefinitionsCache, [], "usePermissions()");
2217
- return (0, import_react2.useMemo)(() => {
2218
- return crud.map((p) => this._serverTeamPermissionDefinitionFromCrud(p));
2219
- }, [crud]);
2220
- }
2221
- useSvixToken() {
2222
- const crud = useAsyncCache(this._svixTokenCache, [], "useSvixToken()");
2223
- return crud.token;
2224
- }
2225
- async _refreshProject() {
2226
- await Promise.all([
2227
- super._refreshProject(),
2228
- this._adminProjectCache.refresh([])
2229
- ]);
2230
- }
2231
- async _refreshApiKeys() {
2232
- await this._apiKeysCache.refresh([]);
2233
- }
2234
- get [stackAppInternalsSymbol]() {
2235
- return {
2236
- ...super[stackAppInternalsSymbol],
2237
- useMetrics: () => {
2238
- return useAsyncCache(this._metricsCache, [], "useMetrics()");
2239
- }
2240
- };
2241
- }
2242
- async sendTestEmail(options) {
2243
- const response = await this._interface.sendTestEmail({
2244
- recipient_email: options.recipientEmail,
2245
- email_config: {
2246
- ...(0, import_objects.pick)(options.emailConfig, ["host", "port", "username", "password"]),
2247
- sender_email: options.emailConfig.senderEmail,
2248
- sender_name: options.emailConfig.senderName
2249
- }
2250
- });
2251
- if (response.success) {
2252
- return import_results.Result.ok(void 0);
2253
- } else {
2254
- return import_results.Result.error({ errorMessage: response.error_message ?? (0, import_errors.throwErr)("Email test error not specified") });
2255
- }
2256
- }
2257
- };
2258
- function contactChannelCreateOptionsToCrud(userId, options) {
2259
- return {
2260
- value: options.value,
2261
- type: options.type,
2262
- used_for_auth: options.usedForAuth,
2263
- user_id: userId
2264
- };
2265
- }
2266
- function contactChannelUpdateOptionsToCrud(options) {
2267
- return {
2268
- value: options.value,
2269
- used_for_auth: options.usedForAuth,
2270
- is_primary: options.isPrimary
2271
- };
2272
- }
2273
- function serverContactChannelUpdateOptionsToCrud(options) {
2274
- return {
2275
- value: options.value,
2276
- is_verified: options.isVerified,
2277
- used_for_auth: options.usedForAuth
2278
- };
2279
- }
2280
- function serverContactChannelCreateOptionsToCrud(userId, options) {
2281
- return {
2282
- type: options.type,
2283
- value: options.value,
2284
- is_verified: options.isVerified,
2285
- user_id: userId,
2286
- used_for_auth: options.usedForAuth
2287
- };
2288
- }
2289
- function userUpdateOptionsToCrud(options) {
2290
- return {
2291
- display_name: options.displayName,
2292
- client_metadata: options.clientMetadata,
2293
- selected_team_id: options.selectedTeamId,
2294
- totp_secret_base64: options.totpMultiFactorSecret != null ? (0, import_bytes.encodeBase64)(options.totpMultiFactorSecret) : options.totpMultiFactorSecret,
2295
- profile_image_url: options.profileImageUrl,
2296
- otp_auth_enabled: options.otpAuthEnabled,
2297
- passkey_auth_enabled: options.passkeyAuthEnabled
2298
- };
2299
- }
2300
- function serverUserUpdateOptionsToCrud(options) {
2301
- return {
2302
- display_name: options.displayName,
2303
- primary_email: options.primaryEmail,
2304
- client_metadata: options.clientMetadata,
2305
- client_read_only_metadata: options.clientReadOnlyMetadata,
2306
- server_metadata: options.serverMetadata,
2307
- selected_team_id: options.selectedTeamId,
2308
- primary_email_auth_enabled: options.primaryEmailAuthEnabled,
2309
- primary_email_verified: options.primaryEmailVerified,
2310
- password: options.password,
2311
- profile_image_url: options.profileImageUrl,
2312
- totp_secret_base64: options.totpMultiFactorSecret != null ? (0, import_bytes.encodeBase64)(options.totpMultiFactorSecret) : options.totpMultiFactorSecret
2313
- };
2314
- }
2315
- function serverUserCreateOptionsToCrud(options) {
2316
- return {
2317
- primary_email: options.primaryEmail,
2318
- password: options.password,
2319
- otp_auth_enabled: options.otpAuthEnabled,
2320
- primary_email_auth_enabled: options.primaryEmailAuthEnabled,
2321
- display_name: options.displayName,
2322
- primary_email_verified: options.primaryEmailVerified,
2323
- client_metadata: options.clientMetadata,
2324
- client_read_only_metadata: options.clientReadOnlyMetadata,
2325
- server_metadata: options.serverMetadata
2326
- };
2327
- }
2328
- function adminProjectUpdateOptionsToCrud(options) {
2329
- return {
2330
- display_name: options.displayName,
2331
- description: options.description,
2332
- is_production_mode: options.isProductionMode,
2333
- config: {
2334
- domains: options.config?.domains?.map((d) => ({
2335
- domain: d.domain,
2336
- handler_path: d.handlerPath
2337
- })),
2338
- oauth_providers: options.config?.oauthProviders?.map((p) => ({
2339
- id: p.id,
2340
- enabled: p.enabled,
2341
- type: p.type,
2342
- ...p.type === "standard" && {
2343
- client_id: p.clientId,
2344
- client_secret: p.clientSecret,
2345
- facebook_config_id: p.facebookConfigId,
2346
- microsoft_tenant_id: p.microsoftTenantId
2347
- }
2348
- })),
2349
- email_config: options.config?.emailConfig && (options.config.emailConfig.type === "shared" ? {
2350
- type: "shared"
2351
- } : {
2352
- type: "standard",
2353
- host: options.config.emailConfig.host,
2354
- port: options.config.emailConfig.port,
2355
- username: options.config.emailConfig.username,
2356
- password: options.config.emailConfig.password,
2357
- sender_name: options.config.emailConfig.senderName,
2358
- sender_email: options.config.emailConfig.senderEmail
2359
- }),
2360
- sign_up_enabled: options.config?.signUpEnabled,
2361
- credential_enabled: options.config?.credentialEnabled,
2362
- magic_link_enabled: options.config?.magicLinkEnabled,
2363
- passkey_enabled: options.config?.passkeyEnabled,
2364
- allow_localhost: options.config?.allowLocalhost,
2365
- create_team_on_sign_up: options.config?.createTeamOnSignUp,
2366
- client_team_creation_enabled: options.config?.clientTeamCreationEnabled,
2367
- client_user_deletion_enabled: options.config?.clientUserDeletionEnabled,
2368
- team_creator_default_permissions: options.config?.teamCreatorDefaultPermissions,
2369
- team_member_default_permissions: options.config?.teamMemberDefaultPermissions
2370
- }
2371
- };
2372
- }
2373
- function adminProjectCreateOptionsToCrud(options) {
2374
- return {
2375
- ...adminProjectUpdateOptionsToCrud(options),
2376
- display_name: options.displayName
2377
- };
2378
- }
2379
- function apiKeyCreateOptionsToCrud(options) {
2380
- return {
2381
- description: options.description,
2382
- expires_at_millis: options.expiresAt.getTime(),
2383
- has_publishable_client_key: options.hasPublishableClientKey,
2384
- has_secret_server_key: options.hasSecretServerKey,
2385
- has_super_secret_admin_key: options.hasSuperSecretAdminKey
2386
- };
2387
- }
2388
- function teamUpdateOptionsToCrud(options) {
2389
- return {
2390
- display_name: options.displayName,
2391
- profile_image_url: options.profileImageUrl,
2392
- client_metadata: options.clientMetadata
2393
- };
2394
- }
2395
- function teamCreateOptionsToCrud(options, creatorUserId) {
2396
- return {
2397
- display_name: options.displayName,
2398
- profile_image_url: options.profileImageUrl,
2399
- creator_user_id: creatorUserId
2400
- };
2401
- }
2402
- function serverTeamCreateOptionsToCrud(options) {
2403
- return {
2404
- display_name: options.displayName,
2405
- profile_image_url: options.profileImageUrl,
2406
- creator_user_id: options.creatorUserId
2407
- };
2408
- }
2409
- function serverTeamUpdateOptionsToCrud(options) {
2410
- return {
2411
- display_name: options.displayName,
2412
- profile_image_url: options.profileImageUrl,
2413
- client_metadata: options.clientMetadata,
2414
- client_read_only_metadata: options.clientReadOnlyMetadata,
2415
- server_metadata: options.serverMetadata
2416
- };
2417
- }
2418
- function serverTeamPermissionDefinitionCreateOptionsToCrud(options) {
2419
- return {
2420
- id: options.id,
2421
- description: options.description,
2422
- contained_permission_ids: options.containedPermissionIds
2423
- };
2424
- }
2425
- function serverTeamPermissionDefinitionUpdateOptionsToCrud(options) {
2426
- return {
2427
- id: options.id,
2428
- description: options.description,
2429
- contained_permission_ids: options.containedPermissionIds
2430
- };
2431
- }
2432
- var StackClientApp = _StackClientAppImpl;
2433
- var StackServerApp = _StackServerAppImpl;
2434
- var StackAdminApp = _StackAdminAppImpl;
2435
- function adminEmailTemplateUpdateOptionsToCrud(options) {
2436
- return {
2437
- subject: options.subject,
2438
- content: options.content
2439
- };
2440
- }
1360
+ /**
1361
+ * There is a circular dependency between the admin app and the client app, as the former inherits from the latter and
1362
+ * the latter needs to use the former when creating a new instance of an internal project.
1363
+ *
1364
+ * To break it, we set the admin app here lazily instead of importing it directly. This variable is set by ./index.ts,
1365
+ * which imports both this file and ./admin-app-impl.ts.
1366
+ */
1367
+ __StackClientAppImplIncomplete.LazyStackAdminAppImpl = { value: void 0 };
1368
+ var _StackClientAppImplIncomplete = __StackClientAppImplIncomplete;
2441
1369
  // Annotate the CommonJS export names for ESM import in node:
2442
1370
  0 && (module.exports = {
2443
- StackAdminApp,
2444
- StackClientApp,
2445
- StackServerApp,
2446
- serverTeamPermissionDefinitionCreateOptionsToCrud,
2447
- serverTeamPermissionDefinitionUpdateOptionsToCrud,
2448
- stackAppInternalsSymbol
1371
+ _StackClientAppImplIncomplete
2449
1372
  });
2450
- //# sourceMappingURL=stack-app.js.map
1373
+ //# sourceMappingURL=client-app-impl.js.map