@stackframe/react 2.7.21 → 2.7.22

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 (144) hide show
  1. package/CHANGELOG.md +10 -0
  2. package/dist/admin-app-impl-BN0oFR_r.d.mts +395 -0
  3. package/dist/admin-app-impl-DUgwqr7u.d.ts +395 -0
  4. package/dist/components/selected-team-switcher.d.mts +18 -6
  5. package/dist/components/selected-team-switcher.d.ts +18 -6
  6. package/dist/components/team-icon.d.mts +18 -6
  7. package/dist/components/team-icon.d.ts +18 -6
  8. package/dist/components-page/stack-handler.d.mts +18 -6
  9. package/dist/components-page/stack-handler.d.ts +18 -6
  10. package/dist/esm/lib/stack-app/api-keys/index.js +14 -0
  11. package/dist/esm/lib/stack-app/api-keys/index.js.map +1 -0
  12. package/dist/esm/lib/stack-app/apps/implementations/admin-app-impl.js +291 -0
  13. package/dist/esm/lib/stack-app/apps/implementations/admin-app-impl.js.map +1 -0
  14. package/dist/esm/lib/{stack-app.js → stack-app/apps/implementations/client-app-impl.js} +35 -1108
  15. package/dist/esm/lib/stack-app/apps/implementations/client-app-impl.js.map +1 -0
  16. package/dist/esm/lib/stack-app/apps/implementations/common.js +143 -0
  17. package/dist/esm/lib/stack-app/apps/implementations/common.js.map +1 -0
  18. package/dist/esm/lib/stack-app/apps/implementations/index.js +24 -0
  19. package/dist/esm/lib/stack-app/apps/implementations/index.js.map +1 -0
  20. package/dist/esm/lib/stack-app/apps/implementations/server-app-impl.js +527 -0
  21. package/dist/esm/lib/stack-app/apps/implementations/server-app-impl.js.map +1 -0
  22. package/dist/esm/lib/stack-app/apps/index.js +16 -0
  23. package/dist/esm/lib/stack-app/apps/index.js.map +1 -0
  24. package/dist/esm/lib/stack-app/apps/interfaces/admin-app.js +7 -0
  25. package/dist/esm/lib/stack-app/apps/interfaces/admin-app.js.map +1 -0
  26. package/dist/esm/lib/stack-app/apps/interfaces/client-app.js +7 -0
  27. package/dist/esm/lib/stack-app/apps/interfaces/client-app.js.map +1 -0
  28. package/dist/esm/lib/stack-app/apps/interfaces/server-app.js +7 -0
  29. package/dist/esm/lib/stack-app/apps/interfaces/server-app.js.map +1 -0
  30. package/dist/esm/lib/stack-app/common.js +6 -0
  31. package/dist/esm/lib/stack-app/common.js.map +1 -0
  32. package/dist/esm/lib/stack-app/connected-accounts/index.js +1 -0
  33. package/dist/esm/lib/stack-app/connected-accounts/index.js.map +1 -0
  34. package/dist/esm/lib/stack-app/contact-channels/index.js +39 -0
  35. package/dist/esm/lib/stack-app/contact-channels/index.js.map +1 -0
  36. package/dist/esm/lib/stack-app/email-templates/index.js +11 -0
  37. package/dist/esm/lib/stack-app/email-templates/index.js.map +1 -0
  38. package/dist/esm/lib/stack-app/index.js +16 -0
  39. package/dist/esm/lib/stack-app/index.js.map +1 -0
  40. package/dist/esm/lib/stack-app/permissions/index.js +20 -0
  41. package/dist/esm/lib/stack-app/permissions/index.js.map +1 -0
  42. package/dist/esm/lib/stack-app/project-configs/index.js +1 -0
  43. package/dist/esm/lib/stack-app/project-configs/index.js.map +1 -0
  44. package/dist/esm/lib/stack-app/projects/index.js +57 -0
  45. package/dist/esm/lib/stack-app/projects/index.js.map +1 -0
  46. package/dist/esm/lib/stack-app/teams/index.js +38 -0
  47. package/dist/esm/lib/stack-app/teams/index.js.map +1 -0
  48. package/dist/esm/lib/stack-app/users/index.js +47 -0
  49. package/dist/esm/lib/stack-app/users/index.js.map +1 -0
  50. package/dist/generated/quetzal-translations.d.mts +2 -2
  51. package/dist/generated/quetzal-translations.d.ts +2 -2
  52. package/dist/{lib/stack-app.d.mts → index-CLnvv7mq.d.ts} +138 -354
  53. package/dist/{lib/stack-app.d.ts → index-aU2I3xr5.d.mts} +138 -354
  54. package/dist/index.d.mts +17 -5
  55. package/dist/index.d.ts +17 -5
  56. package/dist/lib/hooks.d.mts +17 -5
  57. package/dist/lib/hooks.d.ts +17 -5
  58. package/dist/lib/stack-app/api-keys/index.d.mts +40 -0
  59. package/dist/lib/stack-app/api-keys/index.d.ts +40 -0
  60. package/dist/lib/stack-app/api-keys/index.js +39 -0
  61. package/dist/lib/stack-app/api-keys/index.js.map +1 -0
  62. package/dist/lib/stack-app/apps/implementations/admin-app-impl.d.mts +30 -0
  63. package/dist/lib/stack-app/apps/implementations/admin-app-impl.d.ts +30 -0
  64. package/dist/lib/stack-app/apps/implementations/admin-app-impl.js +316 -0
  65. package/dist/lib/stack-app/apps/implementations/admin-app-impl.js.map +1 -0
  66. package/dist/lib/stack-app/apps/implementations/client-app-impl.d.mts +30 -0
  67. package/dist/lib/stack-app/apps/implementations/client-app-impl.d.ts +30 -0
  68. package/dist/lib/{stack-app.js → stack-app/apps/implementations/client-app-impl.js} +73 -1151
  69. package/dist/lib/stack-app/apps/implementations/client-app-impl.js.map +1 -0
  70. package/dist/lib/stack-app/apps/implementations/common.d.mts +45 -0
  71. package/dist/lib/stack-app/apps/implementations/common.d.ts +45 -0
  72. package/dist/lib/stack-app/apps/implementations/common.js +188 -0
  73. package/dist/lib/stack-app/apps/implementations/common.js.map +1 -0
  74. package/dist/lib/stack-app/apps/implementations/index.d.mts +36 -0
  75. package/dist/lib/stack-app/apps/implementations/index.d.ts +36 -0
  76. package/dist/lib/stack-app/apps/implementations/index.js +51 -0
  77. package/dist/lib/stack-app/apps/implementations/index.js.map +1 -0
  78. package/dist/lib/stack-app/apps/implementations/server-app-impl.d.mts +30 -0
  79. package/dist/lib/stack-app/apps/implementations/server-app-impl.d.ts +30 -0
  80. package/dist/lib/stack-app/apps/implementations/server-app-impl.js +552 -0
  81. package/dist/lib/stack-app/apps/implementations/server-app-impl.js.map +1 -0
  82. package/dist/lib/stack-app/apps/index.d.mts +23 -0
  83. package/dist/lib/stack-app/apps/index.d.ts +23 -0
  84. package/dist/lib/stack-app/apps/index.js +37 -0
  85. package/dist/lib/stack-app/apps/index.js.map +1 -0
  86. package/dist/lib/stack-app/apps/interfaces/admin-app.d.mts +23 -0
  87. package/dist/lib/stack-app/apps/interfaces/admin-app.d.ts +23 -0
  88. package/dist/lib/stack-app/apps/interfaces/admin-app.js +32 -0
  89. package/dist/lib/stack-app/apps/interfaces/admin-app.js.map +1 -0
  90. package/dist/lib/stack-app/apps/interfaces/client-app.d.mts +23 -0
  91. package/dist/lib/stack-app/apps/interfaces/client-app.d.ts +23 -0
  92. package/dist/lib/stack-app/apps/interfaces/client-app.js +32 -0
  93. package/dist/lib/stack-app/apps/interfaces/client-app.js.map +1 -0
  94. package/dist/lib/stack-app/apps/interfaces/server-app.d.mts +23 -0
  95. package/dist/lib/stack-app/apps/interfaces/server-app.d.ts +23 -0
  96. package/dist/lib/stack-app/apps/interfaces/server-app.js +32 -0
  97. package/dist/lib/stack-app/apps/interfaces/server-app.js.map +1 -0
  98. package/dist/lib/stack-app/common.d.mts +63 -0
  99. package/dist/lib/stack-app/common.d.ts +63 -0
  100. package/dist/lib/stack-app/common.js +31 -0
  101. package/dist/lib/stack-app/common.js.map +1 -0
  102. package/dist/lib/stack-app/connected-accounts/index.d.mts +13 -0
  103. package/dist/lib/stack-app/connected-accounts/index.d.ts +13 -0
  104. package/dist/lib/stack-app/connected-accounts/index.js +19 -0
  105. package/dist/lib/stack-app/connected-accounts/index.js.map +1 -0
  106. package/dist/lib/stack-app/contact-channels/index.d.mts +38 -0
  107. package/dist/lib/stack-app/contact-channels/index.d.ts +38 -0
  108. package/dist/lib/stack-app/contact-channels/index.js +67 -0
  109. package/dist/lib/stack-app/contact-channels/index.js.map +1 -0
  110. package/dist/lib/stack-app/email-templates/index.d.mts +15 -0
  111. package/dist/lib/stack-app/email-templates/index.d.ts +15 -0
  112. package/dist/lib/stack-app/email-templates/index.js +36 -0
  113. package/dist/lib/stack-app/email-templates/index.js.map +1 -0
  114. package/dist/lib/stack-app/index.d.mts +23 -0
  115. package/dist/lib/stack-app/index.d.ts +23 -0
  116. package/dist/lib/stack-app/index.js +38 -0
  117. package/dist/lib/stack-app/index.js.map +1 -0
  118. package/dist/lib/stack-app/permissions/index.d.mts +21 -0
  119. package/dist/lib/stack-app/permissions/index.d.ts +21 -0
  120. package/dist/lib/stack-app/permissions/index.js +46 -0
  121. package/dist/lib/stack-app/permissions/index.js.map +1 -0
  122. package/dist/lib/stack-app/project-configs/index.d.mts +82 -0
  123. package/dist/lib/stack-app/project-configs/index.d.ts +82 -0
  124. package/dist/lib/stack-app/project-configs/index.js +19 -0
  125. package/dist/lib/stack-app/project-configs/index.js.map +1 -0
  126. package/dist/lib/stack-app/projects/index.d.mts +23 -0
  127. package/dist/lib/stack-app/projects/index.d.ts +23 -0
  128. package/dist/lib/stack-app/projects/index.js +83 -0
  129. package/dist/lib/stack-app/projects/index.js.map +1 -0
  130. package/dist/lib/stack-app/teams/index.d.mts +23 -0
  131. package/dist/lib/stack-app/teams/index.d.ts +23 -0
  132. package/dist/lib/stack-app/teams/index.js +66 -0
  133. package/dist/lib/stack-app/teams/index.js.map +1 -0
  134. package/dist/lib/stack-app/users/index.d.mts +23 -0
  135. package/dist/lib/stack-app/users/index.d.ts +23 -0
  136. package/dist/lib/stack-app/users/index.js +74 -0
  137. package/dist/lib/stack-app/users/index.js.map +1 -0
  138. package/dist/providers/stack-provider-client.d.mts +17 -5
  139. package/dist/providers/stack-provider-client.d.ts +17 -5
  140. package/dist/providers/stack-provider.d.mts +18 -6
  141. package/dist/providers/stack-provider.d.ts +18 -6
  142. package/package.json +3 -3
  143. package/dist/esm/lib/stack-app.js.map +0 -1
  144. 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_env = require("@stackframe/stack-shared/dist/utils/env");
48
40
  var import_errors = require("@stackframe/stack-shared/dist/utils/errors");
49
41
  var import_maps = require("@stackframe/stack-shared/dist/utils/maps");
@@ -57,140 +49,27 @@ var import_urls = require("@stackframe/stack-shared/dist/utils/urls");
57
49
  var import_uuids = require("@stackframe/stack-shared/dist/utils/uuids");
58
50
  var cookie = __toESM(require("cookie"));
59
51
  var import_react2 = __toESM(require("react"));
60
- var import_url = require("../utils/url");
61
- var import_auth = require("./auth");
62
- var import_cookie = require("./cookie");
52
+ var import_url = require("../../../../utils/url");
53
+ var import_auth = require("../../../auth");
54
+ var import_cookie = require("../../../cookie");
55
+ var import_common = require("../../common");
56
+ var import_contact_channels = require("../../contact-channels");
57
+ var import_projects = require("../../projects");
58
+ var import_teams = require("../../teams");
59
+ var import_users = require("../../users");
60
+ var import_common2 = require("./common");
61
+ var import_common3 = require("./common");
63
62
  var isReactServer = false;
64
- var clientVersion = "js @stackframe/react@2.7.21";
65
- if (clientVersion.startsWith("STACK_COMPILE_TIME")) {
66
- throw new import_errors.StackAssertionError("Client version was not replaced. Something went wrong during build!");
67
- }
68
63
  var process = globalThis.process ?? { env: {} };
69
- function getUrls(partial) {
70
- const handler = partial.handler ?? "/handler";
71
- const home = partial.home ?? "/";
72
- const afterSignIn = partial.afterSignIn ?? home;
73
- return {
74
- handler,
75
- signIn: `${handler}/sign-in`,
76
- afterSignIn: home,
77
- signUp: `${handler}/sign-up`,
78
- afterSignUp: afterSignIn,
79
- signOut: `${handler}/sign-out`,
80
- afterSignOut: home,
81
- emailVerification: `${handler}/email-verification`,
82
- passwordReset: `${handler}/password-reset`,
83
- forgotPassword: `${handler}/forgot-password`,
84
- oauthCallback: `${handler}/oauth-callback`,
85
- magicLinkCallback: `${handler}/magic-link-callback`,
86
- home,
87
- accountSettings: `${handler}/account-settings`,
88
- error: `${handler}/error`,
89
- teamInvitation: `${handler}/team-invitation`,
90
- ...(0, import_objects.filterUndefined)(partial)
91
- };
92
- }
93
- function getDefaultProjectId() {
94
- 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."));
95
- }
96
- function getDefaultPublishableClientKey() {
97
- 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."));
98
- }
99
- function getDefaultSecretServerKey() {
100
- 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."));
101
- }
102
- function getDefaultSuperSecretAdminKey() {
103
- 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."));
104
- }
105
- function getBaseUrl(userSpecifiedBaseUrl) {
106
- let url;
107
- if (userSpecifiedBaseUrl) {
108
- if (typeof userSpecifiedBaseUrl === "string") {
109
- url = userSpecifiedBaseUrl;
110
- } else {
111
- if ((0, import_env.isBrowserLike)()) {
112
- url = userSpecifiedBaseUrl.browser;
113
- } else {
114
- url = userSpecifiedBaseUrl.server;
115
- }
116
- }
117
- } else {
118
- if ((0, import_env.isBrowserLike)()) {
119
- url = process.env.NEXT_PUBLIC_BROWSER_STACK_API_URL;
120
- } else {
121
- url = process.env.NEXT_PUBLIC_SERVER_STACK_API_URL;
122
- }
123
- url = url || process.env.NEXT_PUBLIC_STACK_API_URL || process.env.NEXT_PUBLIC_STACK_URL || defaultBaseUrl;
124
- }
125
- return url.endsWith("/") ? url.slice(0, -1) : url;
126
- }
127
- var defaultBaseUrl = "https://api.stack-auth.com";
128
- function createEmptyTokenStore() {
129
- return new import_stores.Store({
130
- refreshToken: null,
131
- accessToken: null
132
- });
133
- }
134
- var cachePromiseByComponentId = /* @__PURE__ */ new Map();
135
- function useAsyncCache(cache, dependencies, caller) {
136
- (0, import_react.suspendIfSsr)(caller);
137
- const id = import_react2.default.useId();
138
- const subscribe = (0, import_react2.useCallback)((cb) => {
139
- const { unsubscribe } = cache.onStateChange(dependencies, () => {
140
- cachePromiseByComponentId.delete(id);
141
- cb();
142
- });
143
- return unsubscribe;
144
- }, [cache, ...dependencies]);
145
- const getSnapshot = (0, import_react2.useCallback)(() => {
146
- if (!cachePromiseByComponentId.has(id)) {
147
- cachePromiseByComponentId.set(id, cache.getOrWait(dependencies, "read-write"));
148
- }
149
- return cachePromiseByComponentId.get(id);
150
- }, [cache, ...dependencies]);
151
- const promise = import_react2.default.useSyncExternalStore(
152
- subscribe,
153
- getSnapshot,
154
- () => (0, import_errors.throwErr)(new Error("getServerSnapshot should never be called in useAsyncCache because we restrict to CSR earlier"))
155
- );
156
- const result = import_react2.default.use(promise);
157
- if (result.status === "error") {
158
- const error = result.error;
159
- if (error instanceof Error && !error.__stackHasConcatenatedStacktraces) {
160
- (0, import_errors.concatStacktraces)(error, new Error());
161
- error.__stackHasConcatenatedStacktraces = true;
162
- }
163
- throw error;
164
- }
165
- return result.data;
166
- }
167
- var stackAppInternalsSymbol = Symbol.for("StackAuth--DO-NOT-USE-OR-YOU-WILL-BE-FIRED--StackAppInternals");
168
- var allClientApps = /* @__PURE__ */ new Map();
169
- var createCache = (fetcher) => {
170
- return new import_caches.AsyncCache(
171
- async (dependencies) => await import_results.Result.fromThrowingAsync(async () => await fetcher(dependencies)),
172
- {}
173
- );
174
- };
175
- var createCacheBySession = (fetcher) => {
176
- return new import_caches.AsyncCache(
177
- async ([session, ...extraDependencies]) => await import_results.Result.fromThrowingAsync(async () => await fetcher(session, extraDependencies)),
178
- {
179
- onSubscribe: ([session], refresh) => {
180
- const handler = session.onInvalidate(() => refresh());
181
- return () => handler.unsubscribe();
182
- }
183
- }
184
- );
185
- };
186
64
  var numberOfAppsCreated = 0;
187
- var _StackClientAppImpl = class __StackClientAppImpl {
65
+ var allClientApps = /* @__PURE__ */ new Map();
66
+ var __StackClientAppImplIncomplete = class __StackClientAppImplIncomplete {
188
67
  constructor(_options) {
189
68
  this._options = _options;
190
69
  this._uniqueIdentifier = void 0;
191
70
  this.__DEMO_ENABLE_SLIGHT_FETCH_DELAY = false;
192
71
  this._ownedAdminApps = new import_maps.DependenciesMap();
193
- this._currentUserCache = createCacheBySession(async (session) => {
72
+ this._currentUserCache = (0, import_common2.createCacheBySession)(async (session) => {
194
73
  if (this.__DEMO_ENABLE_SLIGHT_FETCH_DELAY) {
195
74
  await (0, import_promises.wait)(2e3);
196
75
  }
@@ -199,19 +78,19 @@ var _StackClientAppImpl = class __StackClientAppImpl {
199
78
  }
200
79
  return await this._interface.getClientUserByToken(session);
201
80
  });
202
- this._currentProjectCache = createCache(async () => {
81
+ this._currentProjectCache = (0, import_common2.createCache)(async () => {
203
82
  return import_results.Result.orThrow(await this._interface.getClientProject());
204
83
  });
205
- this._ownedProjectsCache = createCacheBySession(async (session) => {
84
+ this._ownedProjectsCache = (0, import_common2.createCacheBySession)(async (session) => {
206
85
  return await this._interface.listProjects(session);
207
86
  });
208
- this._currentUserPermissionsCache = createCacheBySession(async (session, [teamId, recursive]) => {
87
+ this._currentUserPermissionsCache = (0, import_common2.createCacheBySession)(async (session, [teamId, recursive]) => {
209
88
  return await this._interface.listCurrentUserTeamPermissions({ teamId, recursive }, session);
210
89
  });
211
- this._currentUserTeamsCache = createCacheBySession(async (session) => {
90
+ this._currentUserTeamsCache = (0, import_common2.createCacheBySession)(async (session) => {
212
91
  return await this._interface.listCurrentUserTeams(session);
213
92
  });
214
- this._currentUserOAuthConnectionAccessTokensCache = createCacheBySession(
93
+ this._currentUserOAuthConnectionAccessTokensCache = (0, import_common2.createCacheBySession)(
215
94
  async (session, [providerId, scope]) => {
216
95
  try {
217
96
  const result = await this._interface.createProviderAccessToken(providerId, scope || "", session);
@@ -224,12 +103,12 @@ var _StackClientAppImpl = class __StackClientAppImpl {
224
103
  return null;
225
104
  }
226
105
  );
227
- this._currentUserOAuthConnectionCache = createCacheBySession(
106
+ this._currentUserOAuthConnectionCache = (0, import_common2.createCacheBySession)(
228
107
  async (session, [providerId, scope, redirect]) => {
229
108
  return await this._getUserOAuthConnectionCacheFn({
230
109
  getUser: async () => import_results.Result.orThrow(await this._currentUserCache.getOrWait([session], "write-only")),
231
110
  getOrWaitOAuthToken: async () => import_results.Result.orThrow(await this._currentUserOAuthConnectionAccessTokensCache.getOrWait([session, providerId, scope || ""], "write-only")),
232
- useOAuthToken: () => useAsyncCache(this._currentUserOAuthConnectionAccessTokensCache, [session, providerId, scope || ""], "useOAuthToken"),
111
+ useOAuthToken: () => (0, import_common3.useAsyncCache)(this._currentUserOAuthConnectionAccessTokensCache, [session, providerId, scope || ""], "useOAuthToken"),
233
112
  providerId,
234
113
  scope,
235
114
  redirect,
@@ -237,27 +116,27 @@ var _StackClientAppImpl = class __StackClientAppImpl {
237
116
  });
238
117
  }
239
118
  );
240
- this._teamMemberProfilesCache = createCacheBySession(
119
+ this._teamMemberProfilesCache = (0, import_common2.createCacheBySession)(
241
120
  async (session, [teamId]) => {
242
121
  return await this._interface.listTeamMemberProfiles({ teamId }, session);
243
122
  }
244
123
  );
245
- this._teamInvitationsCache = createCacheBySession(
124
+ this._teamInvitationsCache = (0, import_common2.createCacheBySession)(
246
125
  async (session, [teamId]) => {
247
126
  return await this._interface.listTeamInvitations({ teamId }, session);
248
127
  }
249
128
  );
250
- this._currentUserTeamProfileCache = createCacheBySession(
129
+ this._currentUserTeamProfileCache = (0, import_common2.createCacheBySession)(
251
130
  async (session, [teamId]) => {
252
131
  return await this._interface.getTeamMemberProfile({ teamId, userId: "me" }, session);
253
132
  }
254
133
  );
255
- this._clientContactChannelsCache = createCacheBySession(
134
+ this._clientContactChannelsCache = (0, import_common2.createCacheBySession)(
256
135
  async (session) => {
257
136
  return await this._interface.listClientContactChannels(session);
258
137
  }
259
138
  );
260
- this._memoryTokenStore = createEmptyTokenStore();
139
+ this._memoryTokenStore = (0, import_common2.createEmptyTokenStore)();
261
140
  this._nextServerCookiesTokenStores = /* @__PURE__ */ new WeakMap();
262
141
  this._requestTokenStores = /* @__PURE__ */ new WeakMap();
263
142
  this._storedBrowserCookieTokenStore = null;
@@ -270,14 +149,17 @@ var _StackClientAppImpl = class __StackClientAppImpl {
270
149
  * - 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
271
150
  */
272
151
  this._sessionsByTokenStoreAndSessionKey = /* @__PURE__ */ new WeakMap();
152
+ if (!__StackClientAppImplIncomplete.LazyStackAdminAppImpl.value) {
153
+ 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).");
154
+ }
273
155
  if ("interface" in _options) {
274
156
  this._interface = _options.interface;
275
157
  } else {
276
158
  this._interface = new import_stack_shared.StackClientInterface({
277
- getBaseUrl: () => getBaseUrl(_options.baseUrl),
278
- projectId: _options.projectId ?? getDefaultProjectId(),
279
- clientVersion,
280
- publishableClientKey: _options.publishableClientKey ?? getDefaultPublishableClientKey(),
159
+ getBaseUrl: () => (0, import_common2.getBaseUrl)(_options.baseUrl),
160
+ projectId: _options.projectId ?? (0, import_common2.getDefaultProjectId)(),
161
+ clientVersion: import_common2.clientVersion,
162
+ publishableClientKey: _options.publishableClientKey ?? (0, import_common2.getDefaultPublishableClientKey)(),
281
163
  prepareRequest: async () => {
282
164
  }
283
165
  });
@@ -470,7 +352,7 @@ var _StackClientAppImpl = class __StackClientAppImpl {
470
352
  }
471
353
  default: {
472
354
  if (tokenStoreInit === null) {
473
- return createEmptyTokenStore();
355
+ return (0, import_common2.createEmptyTokenStore)();
474
356
  } else if (typeof tokenStoreInit === "object" && "headers" in tokenStoreInit) {
475
357
  if (this._requestTokenStores.has(tokenStoreInit)) return this._requestTokenStores.get(tokenStoreInit);
476
358
  const stackAuthHeader = tokenStoreInit.headers.get("x-stack-auth");
@@ -645,7 +527,7 @@ var _StackClientAppImpl = class __StackClientAppImpl {
645
527
  return result.map((crud2) => app._clientTeamUserFromCrud(crud2));
646
528
  },
647
529
  useUsers() {
648
- const result = useAsyncCache(app._teamMemberProfilesCache, [session, crud.id], "team.useUsers()");
530
+ const result = (0, import_common3.useAsyncCache)(app._teamMemberProfilesCache, [session, crud.id], "team.useUsers()");
649
531
  return result.map((crud2) => app._clientTeamUserFromCrud(crud2));
650
532
  },
651
533
  async listInvitations() {
@@ -653,11 +535,11 @@ var _StackClientAppImpl = class __StackClientAppImpl {
653
535
  return result.map((crud2) => app._clientTeamInvitationFromCrud(session, crud2));
654
536
  },
655
537
  useInvitations() {
656
- const result = useAsyncCache(app._teamInvitationsCache, [session, crud.id], "team.useInvitations()");
538
+ const result = (0, import_common3.useAsyncCache)(app._teamInvitationsCache, [session, crud.id], "team.useInvitations()");
657
539
  return result.map((crud2) => app._clientTeamInvitationFromCrud(session, crud2));
658
540
  },
659
541
  async update(data) {
660
- await app._interface.updateTeam({ data: teamUpdateOptionsToCrud(data), teamId: crud.id }, session);
542
+ await app._interface.updateTeam({ data: (0, import_teams.teamUpdateOptionsToCrud)(data), teamId: crud.id }, session);
661
543
  await app._currentUserTeamsCache.refresh([session]);
662
544
  },
663
545
  async delete() {
@@ -679,7 +561,7 @@ var _StackClientAppImpl = class __StackClientAppImpl {
679
561
  await app._interface.sendCurrentUserContactChannelVerificationEmail(crud.id, (0, import_url.constructRedirectUrl)(app.urls.emailVerification), session);
680
562
  },
681
563
  async update(data) {
682
- await app._interface.updateClientContactChannel(crud.id, contactChannelUpdateOptionsToCrud(data), session);
564
+ await app._interface.updateClientContactChannel(crud.id, (0, import_contact_channels.contactChannelUpdateOptionsToCrud)(data), session);
683
565
  await app._clientContactChannelsCache.refresh([session]);
684
566
  },
685
567
  async delete() {
@@ -727,12 +609,12 @@ var _StackClientAppImpl = class __StackClientAppImpl {
727
609
  let attResp;
728
610
  try {
729
611
  attResp = await (0, import_browser.startRegistration)({ optionsJSON: options_json });
730
- debugger;
731
612
  } catch (error) {
732
613
  if (error instanceof import_browser.WebAuthnError) {
733
614
  return import_results.Result.error(new import_stack_shared.KnownErrors.PasskeyWebAuthnError(error.message, error.name));
734
615
  } else {
735
- return import_results.Result.error(new import_stack_shared.KnownErrors.PasskeyRegistrationFailed("Failed to start passkey registration"));
616
+ (0, import_errors.captureError)("passkey-registration-failed", error);
617
+ return import_results.Result.error(new import_stack_shared.KnownErrors.PasskeyRegistrationFailed("Failed to start passkey registration due to unknown error"));
736
618
  }
737
619
  }
738
620
  const registrationResult = await app._interface.registerPasskey({ credential: attResp, code }, session);
@@ -791,7 +673,7 @@ var _StackClientAppImpl = class __StackClientAppImpl {
791
673
  }
792
674
  function useConnectedAccount(id, options) {
793
675
  const scopeString = options?.scopes?.join(" ");
794
- return useAsyncCache(app._currentUserOAuthConnectionCache, [session, id, scopeString || "", options?.or === "redirect"], "user.useConnectedAccount()");
676
+ return (0, import_common3.useAsyncCache)(app._currentUserOAuthConnectionCache, [session, id, scopeString || "", options?.or === "redirect"], "user.useConnectedAccount()");
795
677
  }
796
678
  return {
797
679
  setDisplayName(displayName) {
@@ -820,11 +702,11 @@ var _StackClientAppImpl = class __StackClientAppImpl {
820
702
  return teams.map((crud2) => app._clientTeamFromCrud(crud2, session));
821
703
  },
822
704
  useTeams() {
823
- const teams = useAsyncCache(app._currentUserTeamsCache, [session], "user.useTeams()");
705
+ const teams = (0, import_common3.useAsyncCache)(app._currentUserTeamsCache, [session], "user.useTeams()");
824
706
  return (0, import_react2.useMemo)(() => teams.map((crud2) => app._clientTeamFromCrud(crud2, session)), [teams]);
825
707
  },
826
708
  async createTeam(data) {
827
- const crud2 = await app._interface.createClientTeam(teamCreateOptionsToCrud(data, "me"), session);
709
+ const crud2 = await app._interface.createClientTeam((0, import_teams.teamCreateOptionsToCrud)(data, "me"), session);
828
710
  await app._currentUserTeamsCache.refresh([session]);
829
711
  return app._clientTeamFromCrud(crud2, session);
830
712
  },
@@ -838,7 +720,7 @@ var _StackClientAppImpl = class __StackClientAppImpl {
838
720
  },
839
721
  usePermissions(scope, options) {
840
722
  const recursive = options?.recursive ?? true;
841
- const permissions = useAsyncCache(app._currentUserPermissionsCache, [session, scope.id, recursive], "user.usePermissions()");
723
+ const permissions = (0, import_common3.useAsyncCache)(app._currentUserPermissionsCache, [session, scope.id, recursive], "user.usePermissions()");
842
724
  return (0, import_react2.useMemo)(() => permissions.map((crud2) => app._clientTeamPermissionFromCrud(crud2)), [permissions]);
843
725
  },
844
726
  usePermission(scope, permissionId) {
@@ -880,7 +762,7 @@ var _StackClientAppImpl = class __StackClientAppImpl {
880
762
  return app._editableTeamProfileFromCrud(result, session);
881
763
  },
882
764
  useTeamProfile(team) {
883
- const result = useAsyncCache(app._currentUserTeamProfileCache, [session, team.id], "user.useTeamProfile()");
765
+ const result = (0, import_common3.useAsyncCache)(app._currentUserTeamProfileCache, [session, team.id], "user.useTeamProfile()");
884
766
  return app._editableTeamProfileFromCrud(result, session);
885
767
  },
886
768
  async delete() {
@@ -892,11 +774,11 @@ var _StackClientAppImpl = class __StackClientAppImpl {
892
774
  return result.map((crud2) => app._clientContactChannelFromCrud(crud2, session));
893
775
  },
894
776
  useContactChannels() {
895
- const result = useAsyncCache(app._clientContactChannelsCache, [session], "user.useContactChannels()");
777
+ const result = (0, import_common3.useAsyncCache)(app._clientContactChannelsCache, [session], "user.useContactChannels()");
896
778
  return result.map((crud2) => app._clientContactChannelFromCrud(crud2, session));
897
779
  },
898
780
  async createContactChannel(data) {
899
- const crud2 = await app._interface.createClientContactChannel(contactChannelCreateOptionsToCrud("me", data), session);
781
+ const crud2 = await app._interface.createClientContactChannel((0, import_contact_channels.contactChannelCreateOptionsToCrud)("me", data), session);
900
782
  await app._clientContactChannelsCache.refresh([session]);
901
783
  return app._clientContactChannelFromCrud(crud2, session);
902
784
  }
@@ -929,7 +811,7 @@ var _StackClientAppImpl = class __StackClientAppImpl {
929
811
  }
930
812
  _getOwnedAdminApp(forProjectId, session) {
931
813
  if (!this._ownedAdminApps.has([session, forProjectId])) {
932
- this._ownedAdminApps.set([session, forProjectId], new _StackAdminAppImpl({
814
+ this._ownedAdminApps.set([session, forProjectId], new __StackClientAppImplIncomplete.LazyStackAdminAppImpl.value({
933
815
  baseUrl: this._interface.options.getBaseUrl(),
934
816
  projectId: forProjectId,
935
817
  tokenStore: null,
@@ -946,7 +828,7 @@ var _StackClientAppImpl = class __StackClientAppImpl {
946
828
  return (0, import_urls.isRelative)(url);
947
829
  }
948
830
  get urls() {
949
- return getUrls(this._urlOptions);
831
+ return (0, import_common2.getUrls)(this._urlOptions);
950
832
  }
951
833
  async _getCurrentUrl() {
952
834
  if (this._redirectMethod === "none") {
@@ -972,7 +854,7 @@ var _StackClientAppImpl = class __StackClientAppImpl {
972
854
  if (typeof this._redirectMethod === "object") {
973
855
  return this._redirectMethod.useNavigate();
974
856
  } else if (this._redirectMethod === "window") {
975
- return () => window.location.assign;
857
+ return (to) => window.location.assign(to);
976
858
  } else {
977
859
  return (to) => {
978
860
  };
@@ -1143,7 +1025,7 @@ var _StackClientAppImpl = class __StackClientAppImpl {
1143
1025
  useUser(options) {
1144
1026
  this._ensurePersistentTokenStore(options?.tokenStore);
1145
1027
  const session = this._useSession(options?.tokenStore);
1146
- const crud = useAsyncCache(this._currentUserCache, [session], "useUser()");
1028
+ const crud = (0, import_common3.useAsyncCache)(this._currentUserCache, [session], "useUser()");
1147
1029
  if (crud === null) {
1148
1030
  switch (options?.or) {
1149
1031
  case "redirect": {
@@ -1164,7 +1046,7 @@ var _StackClientAppImpl = class __StackClientAppImpl {
1164
1046
  }, [crud, session, options?.or]);
1165
1047
  }
1166
1048
  async _updateClientUser(update, session) {
1167
- const res = await this._interface.updateClientUser(userUpdateOptionsToCrud(update), session);
1049
+ const res = await this._interface.updateClientUser((0, import_users.userUpdateOptionsToCrud)(update), session);
1168
1050
  await this._refreshUser(session);
1169
1051
  return res;
1170
1052
  }
@@ -1368,7 +1250,7 @@ var _StackClientAppImpl = class __StackClientAppImpl {
1368
1250
  return this._clientProjectFromCrud(crud);
1369
1251
  }
1370
1252
  useProject() {
1371
- const crud = useAsyncCache(this._currentProjectCache, [], "useProject()");
1253
+ const crud = (0, import_common3.useAsyncCache)(this._currentProjectCache, [], "useProject()");
1372
1254
  return (0, import_react2.useMemo)(() => this._clientProjectFromCrud(crud), [crud]);
1373
1255
  }
1374
1256
  async _listOwnedProjects(session) {
@@ -1381,7 +1263,7 @@ var _StackClientAppImpl = class __StackClientAppImpl {
1381
1263
  }
1382
1264
  _useOwnedProjects(session) {
1383
1265
  this._ensureInternalProject();
1384
- const projects = useAsyncCache(this._ownedProjectsCache, [session], "useOwnedProjects()");
1266
+ const projects = (0, import_common3.useAsyncCache)(this._ownedProjectsCache, [session], "useOwnedProjects()");
1385
1267
  return (0, import_react2.useMemo)(() => projects.map((j) => this._getOwnedAdminApp(j.id, session)._adminOwnedProjectFromCrud(
1386
1268
  j,
1387
1269
  () => this._refreshOwnedProjects(session)
@@ -1389,7 +1271,7 @@ var _StackClientAppImpl = class __StackClientAppImpl {
1389
1271
  }
1390
1272
  async _createProject(session, newProject) {
1391
1273
  this._ensureInternalProject();
1392
- const crud = await this._interface.createProject(adminProjectCreateOptionsToCrud(newProject), session);
1274
+ const crud = await this._interface.createProject((0, import_projects.adminProjectCreateOptionsToCrud)(newProject), session);
1393
1275
  const res = this._getOwnedAdminApp(crud.id, session)._adminOwnedProjectFromCrud(
1394
1276
  crud,
1395
1277
  () => this._refreshOwnedProjects(session)
@@ -1411,7 +1293,7 @@ var _StackClientAppImpl = class __StackClientAppImpl {
1411
1293
  async _refreshOwnedProjects(session) {
1412
1294
  await this._ownedProjectsCache.refresh([session]);
1413
1295
  }
1414
- static get [stackAppInternalsSymbol]() {
1296
+ static get [import_common.stackAppInternalsSymbol]() {
1415
1297
  return {
1416
1298
  fromClientJson: (json) => {
1417
1299
  const providedCheckString = JSON.stringify((0, import_objects.omit)(json, [
@@ -1425,14 +1307,14 @@ var _StackClientAppImpl = class __StackClientAppImpl {
1425
1307
  }
1426
1308
  return clientApp;
1427
1309
  }
1428
- return new __StackClientAppImpl({
1310
+ return new __StackClientAppImplIncomplete({
1429
1311
  ...json,
1430
1312
  checkString: providedCheckString
1431
1313
  });
1432
1314
  }
1433
1315
  };
1434
1316
  }
1435
- get [stackAppInternalsSymbol]() {
1317
+ get [import_common.stackAppInternalsSymbol]() {
1436
1318
  return {
1437
1319
  toClientJson: () => {
1438
1320
  if (!("publishableClientKey" in this._interface.options)) {
@@ -1463,977 +1345,17 @@ var _StackClientAppImpl = class __StackClientAppImpl {
1463
1345
  };
1464
1346
  }
1465
1347
  };
1466
- var _StackServerAppImpl = class extends _StackClientAppImpl {
1467
- constructor(options) {
1468
- super("interface" in options ? {
1469
- interface: options.interface,
1470
- tokenStore: options.tokenStore,
1471
- urls: options.urls,
1472
- oauthScopesOnSignIn: options.oauthScopesOnSignIn
1473
- } : {
1474
- interface: new import_stack_shared.StackServerInterface({
1475
- getBaseUrl: () => getBaseUrl(options.baseUrl),
1476
- projectId: options.projectId ?? getDefaultProjectId(),
1477
- clientVersion,
1478
- publishableClientKey: options.publishableClientKey ?? getDefaultPublishableClientKey(),
1479
- secretServerKey: options.secretServerKey ?? getDefaultSecretServerKey()
1480
- }),
1481
- baseUrl: options.baseUrl,
1482
- projectId: options.projectId,
1483
- publishableClientKey: options.publishableClientKey,
1484
- tokenStore: options.tokenStore,
1485
- urls: options.urls ?? {},
1486
- oauthScopesOnSignIn: options.oauthScopesOnSignIn ?? {},
1487
- redirectMethod: options.redirectMethod
1488
- });
1489
- // TODO override the client user cache to use the server user cache, so we save some requests
1490
- this._currentServerUserCache = createCacheBySession(async (session) => {
1491
- if (session.isKnownToBeInvalid()) {
1492
- return null;
1493
- }
1494
- return await this._interface.getServerUserByToken(session);
1495
- });
1496
- this._serverUsersCache = createCache(async ([cursor, limit, orderBy, desc, query]) => {
1497
- return await this._interface.listServerUsers({ cursor, limit, orderBy, desc, query });
1498
- });
1499
- this._serverUserCache = createCache(async ([userId]) => {
1500
- const user = await this._interface.getServerUserById(userId);
1501
- return import_results.Result.or(user, null);
1502
- });
1503
- this._serverTeamsCache = createCache(async ([userId]) => {
1504
- return await this._interface.listServerTeams({ userId });
1505
- });
1506
- this._serverTeamUserPermissionsCache = createCache(async ([teamId, userId, recursive]) => {
1507
- return await this._interface.listServerTeamPermissions({ teamId, userId, recursive }, null);
1508
- });
1509
- this._serverUserOAuthConnectionAccessTokensCache = createCache(
1510
- async ([userId, providerId, scope]) => {
1511
- try {
1512
- const result = await this._interface.createServerProviderAccessToken(userId, providerId, scope || "");
1513
- return { accessToken: result.access_token };
1514
- } catch (err) {
1515
- if (!(err instanceof import_stack_shared.KnownErrors.OAuthConnectionDoesNotHaveRequiredScope || err instanceof import_stack_shared.KnownErrors.OAuthConnectionNotConnectedToUser)) {
1516
- throw err;
1517
- }
1518
- }
1519
- return null;
1520
- }
1521
- );
1522
- this._serverUserOAuthConnectionCache = createCache(
1523
- async ([userId, providerId, scope, redirect]) => {
1524
- return await this._getUserOAuthConnectionCacheFn({
1525
- getUser: async () => import_results.Result.orThrow(await this._serverUserCache.getOrWait([userId], "write-only")),
1526
- getOrWaitOAuthToken: async () => import_results.Result.orThrow(await this._serverUserOAuthConnectionAccessTokensCache.getOrWait([userId, providerId, scope || ""], "write-only")),
1527
- useOAuthToken: () => useAsyncCache(this._serverUserOAuthConnectionAccessTokensCache, [userId, providerId, scope || ""], "user.useConnectedAccount()"),
1528
- providerId,
1529
- scope,
1530
- redirect,
1531
- session: null
1532
- });
1533
- }
1534
- );
1535
- this._serverTeamMemberProfilesCache = createCache(
1536
- async ([teamId]) => {
1537
- return await this._interface.listServerTeamMemberProfiles({ teamId });
1538
- }
1539
- );
1540
- this._serverTeamInvitationsCache = createCache(
1541
- async ([teamId]) => {
1542
- return await this._interface.listServerTeamInvitations({ teamId });
1543
- }
1544
- );
1545
- this._serverUserTeamProfileCache = createCache(
1546
- async ([teamId, userId]) => {
1547
- return await this._interface.getServerTeamMemberProfile({ teamId, userId });
1548
- }
1549
- );
1550
- this._serverContactChannelsCache = createCache(
1551
- async ([userId]) => {
1552
- return await this._interface.listServerContactChannels(userId);
1553
- }
1554
- );
1555
- }
1556
- async _updateServerUser(userId, update) {
1557
- const result = await this._interface.updateServerUser(userId, serverUserUpdateOptionsToCrud(update));
1558
- await this._refreshUsers();
1559
- return result;
1560
- }
1561
- _serverEditableTeamProfileFromCrud(crud) {
1562
- const app = this;
1563
- return {
1564
- displayName: crud.display_name,
1565
- profileImageUrl: crud.profile_image_url,
1566
- async update(update) {
1567
- await app._interface.updateServerTeamMemberProfile({
1568
- teamId: crud.team_id,
1569
- userId: crud.user_id,
1570
- profile: {
1571
- display_name: update.displayName,
1572
- profile_image_url: update.profileImageUrl
1573
- }
1574
- });
1575
- await app._serverUserTeamProfileCache.refresh([crud.team_id, crud.user_id]);
1576
- }
1577
- };
1578
- }
1579
- _serverContactChannelFromCrud(userId, crud) {
1580
- const app = this;
1581
- return {
1582
- id: crud.id,
1583
- value: crud.value,
1584
- type: crud.type,
1585
- isVerified: crud.is_verified,
1586
- isPrimary: crud.is_primary,
1587
- usedForAuth: crud.used_for_auth,
1588
- async sendVerificationEmail(options) {
1589
- if (!options?.callbackUrl && !await app._getCurrentUrl()) {
1590
- 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: ... })`");
1591
- }
1592
- await app._interface.sendServerContactChannelVerificationEmail(userId, crud.id, options?.callbackUrl ?? (0, import_url.constructRedirectUrl)(app.urls.emailVerification));
1593
- },
1594
- async update(data) {
1595
- await app._interface.updateServerContactChannel(userId, crud.id, serverContactChannelUpdateOptionsToCrud(data));
1596
- },
1597
- async delete() {
1598
- await app._interface.deleteServerContactChannel(userId, crud.id);
1599
- }
1600
- };
1601
- }
1602
- _serverUserFromCrud(crud) {
1603
- const app = this;
1604
- async function getConnectedAccount(id, options) {
1605
- const scopeString = options?.scopes?.join(" ");
1606
- return import_results.Result.orThrow(await app._serverUserOAuthConnectionCache.getOrWait([crud.id, id, scopeString || "", options?.or === "redirect"], "write-only"));
1607
- }
1608
- function useConnectedAccount(id, options) {
1609
- const scopeString = options?.scopes?.join(" ");
1610
- return useAsyncCache(app._serverUserOAuthConnectionCache, [crud.id, id, scopeString || "", options?.or === "redirect"], "user.useConnectedAccount()");
1611
- }
1612
- return {
1613
- ...super._createBaseUser(crud),
1614
- lastActiveAt: new Date(crud.last_active_at_millis),
1615
- serverMetadata: crud.server_metadata,
1616
- async setPrimaryEmail(email, options) {
1617
- await app._updateServerUser(crud.id, { primaryEmail: email, primaryEmailVerified: options?.verified });
1618
- },
1619
- async grantPermission(scope, permissionId) {
1620
- await app._interface.grantServerTeamUserPermission(scope.id, crud.id, permissionId);
1621
- for (const recursive of [true, false]) {
1622
- await app._serverTeamUserPermissionsCache.refresh([scope.id, crud.id, recursive]);
1623
- }
1624
- },
1625
- async revokePermission(scope, permissionId) {
1626
- await app._interface.revokeServerTeamUserPermission(scope.id, crud.id, permissionId);
1627
- for (const recursive of [true, false]) {
1628
- await app._serverTeamUserPermissionsCache.refresh([scope.id, crud.id, recursive]);
1629
- }
1630
- },
1631
- async delete() {
1632
- const res = await app._interface.deleteServerServerUser(crud.id);
1633
- await app._refreshUsers();
1634
- return res;
1635
- },
1636
- async createSession(options) {
1637
- const tokens = await app._interface.createServerUserSession(crud.id, options.expiresInMillis ?? 1e3 * 60 * 60 * 24 * 365);
1638
- return {
1639
- async getTokens() {
1640
- return tokens;
1641
- }
1642
- };
1643
- },
1644
- async setDisplayName(displayName) {
1645
- return await this.update({ displayName });
1646
- },
1647
- async setClientMetadata(metadata) {
1648
- return await this.update({ clientMetadata: metadata });
1649
- },
1650
- async setClientReadOnlyMetadata(metadata) {
1651
- return await this.update({ clientReadOnlyMetadata: metadata });
1652
- },
1653
- async setServerMetadata(metadata) {
1654
- return await this.update({ serverMetadata: metadata });
1655
- },
1656
- async setSelectedTeam(team) {
1657
- return await this.update({ selectedTeamId: team?.id ?? null });
1658
- },
1659
- getConnectedAccount,
1660
- useConnectedAccount,
1661
- selectedTeam: crud.selected_team ? app._serverTeamFromCrud(crud.selected_team) : null,
1662
- async getTeam(teamId) {
1663
- const teams = await this.listTeams();
1664
- return teams.find((t) => t.id === teamId) ?? null;
1665
- },
1666
- useTeam(teamId) {
1667
- const teams = this.useTeams();
1668
- return (0, import_react2.useMemo)(() => {
1669
- return teams.find((t) => t.id === teamId) ?? null;
1670
- }, [teams, teamId]);
1671
- },
1672
- async listTeams() {
1673
- const teams = import_results.Result.orThrow(await app._serverTeamsCache.getOrWait([crud.id], "write-only"));
1674
- return teams.map((t) => app._serverTeamFromCrud(t));
1675
- },
1676
- useTeams() {
1677
- const teams = useAsyncCache(app._serverTeamsCache, [crud.id], "user.useTeams()");
1678
- return (0, import_react2.useMemo)(() => teams.map((t) => app._serverTeamFromCrud(t)), [teams]);
1679
- },
1680
- createTeam: async (data) => {
1681
- const team = await app._interface.createServerTeam(serverTeamCreateOptionsToCrud({
1682
- creatorUserId: crud.id,
1683
- ...data
1684
- }));
1685
- await app._serverTeamsCache.refresh([void 0]);
1686
- return app._serverTeamFromCrud(team);
1687
- },
1688
- leaveTeam: async (team) => {
1689
- await app._interface.leaveServerTeam({ teamId: team.id, userId: crud.id });
1690
- },
1691
- async listPermissions(scope, options) {
1692
- const recursive = options?.recursive ?? true;
1693
- const permissions = import_results.Result.orThrow(await app._serverTeamUserPermissionsCache.getOrWait([scope.id, crud.id, recursive], "write-only"));
1694
- return permissions.map((crud2) => app._serverPermissionFromCrud(crud2));
1695
- },
1696
- usePermissions(scope, options) {
1697
- const recursive = options?.recursive ?? true;
1698
- const permissions = useAsyncCache(app._serverTeamUserPermissionsCache, [scope.id, crud.id, recursive], "user.usePermissions()");
1699
- return (0, import_react2.useMemo)(() => permissions.map((crud2) => app._serverPermissionFromCrud(crud2)), [permissions]);
1700
- },
1701
- async getPermission(scope, permissionId) {
1702
- const permissions = await this.listPermissions(scope);
1703
- return permissions.find((p) => p.id === permissionId) ?? null;
1704
- },
1705
- usePermission(scope, permissionId) {
1706
- const permissions = this.usePermissions(scope);
1707
- return (0, import_react2.useMemo)(() => permissions.find((p) => p.id === permissionId) ?? null, [permissions, permissionId]);
1708
- },
1709
- async hasPermission(scope, permissionId) {
1710
- return await this.getPermission(scope, permissionId) !== null;
1711
- },
1712
- async update(update) {
1713
- await app._updateServerUser(crud.id, update);
1714
- },
1715
- async sendVerificationEmail() {
1716
- return await app._checkFeatureSupport("sendVerificationEmail() on ServerUser", {});
1717
- },
1718
- async updatePassword(options) {
1719
- const result = await this.update({ password: options.newPassword });
1720
- await app._serverUserCache.refresh([crud.id]);
1721
- return result;
1722
- },
1723
- async setPassword(options) {
1724
- const result = await this.update(options);
1725
- await app._serverUserCache.refresh([crud.id]);
1726
- return result;
1727
- },
1728
- async getTeamProfile(team) {
1729
- const result = import_results.Result.orThrow(await app._serverUserTeamProfileCache.getOrWait([team.id, crud.id], "write-only"));
1730
- return app._serverEditableTeamProfileFromCrud(result);
1731
- },
1732
- useTeamProfile(team) {
1733
- const result = useAsyncCache(app._serverUserTeamProfileCache, [team.id, crud.id], "user.useTeamProfile()");
1734
- return (0, import_react2.useMemo)(() => app._serverEditableTeamProfileFromCrud(result), [result]);
1735
- },
1736
- async listContactChannels() {
1737
- const result = import_results.Result.orThrow(await app._serverContactChannelsCache.getOrWait([crud.id], "write-only"));
1738
- return result.map((data) => app._serverContactChannelFromCrud(crud.id, data));
1739
- },
1740
- useContactChannels() {
1741
- const result = useAsyncCache(app._serverContactChannelsCache, [crud.id], "user.useContactChannels()");
1742
- return (0, import_react2.useMemo)(() => result.map((data) => app._serverContactChannelFromCrud(crud.id, data)), [result]);
1743
- },
1744
- createContactChannel: async (data) => {
1745
- const contactChannel = await app._interface.createServerContactChannel(serverContactChannelCreateOptionsToCrud(crud.id, data));
1746
- await app._serverContactChannelsCache.refresh([crud.id]);
1747
- return app._serverContactChannelFromCrud(crud.id, contactChannel);
1748
- }
1749
- };
1750
- }
1751
- _serverTeamUserFromCrud(crud) {
1752
- return {
1753
- ...this._serverUserFromCrud(crud.user),
1754
- teamProfile: {
1755
- displayName: crud.display_name,
1756
- profileImageUrl: crud.profile_image_url
1757
- }
1758
- };
1759
- }
1760
- _serverTeamInvitationFromCrud(crud) {
1761
- return {
1762
- id: crud.id,
1763
- recipientEmail: crud.recipient_email,
1764
- expiresAt: new Date(crud.expires_at_millis),
1765
- revoke: async () => {
1766
- await this._interface.revokeServerTeamInvitation(crud.id, crud.team_id);
1767
- }
1768
- };
1769
- }
1770
- _currentUserFromCrud(crud, session) {
1771
- const app = this;
1772
- const currentUser = {
1773
- ...this._serverUserFromCrud(crud),
1774
- ...this._createAuth(session),
1775
- ...this._isInternalProject() ? this._createInternalUserExtra(session) : {}
1776
- };
1777
- Object.freeze(currentUser);
1778
- return currentUser;
1779
- }
1780
- _serverTeamFromCrud(crud) {
1781
- const app = this;
1782
- return {
1783
- id: crud.id,
1784
- displayName: crud.display_name,
1785
- profileImageUrl: crud.profile_image_url,
1786
- createdAt: new Date(crud.created_at_millis),
1787
- clientMetadata: crud.client_metadata,
1788
- clientReadOnlyMetadata: crud.client_read_only_metadata,
1789
- serverMetadata: crud.server_metadata,
1790
- async update(update) {
1791
- await app._interface.updateServerTeam(crud.id, serverTeamUpdateOptionsToCrud(update));
1792
- await app._serverTeamsCache.refresh([void 0]);
1793
- },
1794
- async delete() {
1795
- await app._interface.deleteServerTeam(crud.id);
1796
- await app._serverTeamsCache.refresh([void 0]);
1797
- },
1798
- async listUsers() {
1799
- const result = import_results.Result.orThrow(await app._serverTeamMemberProfilesCache.getOrWait([crud.id], "write-only"));
1800
- return result.map((u) => app._serverTeamUserFromCrud(u));
1801
- },
1802
- useUsers() {
1803
- const result = useAsyncCache(app._serverTeamMemberProfilesCache, [crud.id], "team.useUsers()");
1804
- return (0, import_react2.useMemo)(() => result.map((u) => app._serverTeamUserFromCrud(u)), [result]);
1805
- },
1806
- async addUser(userId) {
1807
- await app._interface.addServerUserToTeam({
1808
- teamId: crud.id,
1809
- userId
1810
- });
1811
- await app._serverTeamMemberProfilesCache.refresh([crud.id]);
1812
- },
1813
- async removeUser(userId) {
1814
- await app._interface.removeServerUserFromTeam({
1815
- teamId: crud.id,
1816
- userId
1817
- });
1818
- await app._serverTeamMemberProfilesCache.refresh([crud.id]);
1819
- },
1820
- async inviteUser(options) {
1821
- if (!options.callbackUrl && !await app._getCurrentUrl()) {
1822
- 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: ... })`");
1823
- }
1824
- await app._interface.sendServerTeamInvitation({
1825
- teamId: crud.id,
1826
- email: options.email,
1827
- callbackUrl: options.callbackUrl ?? (0, import_url.constructRedirectUrl)(app.urls.teamInvitation)
1828
- });
1829
- await app._serverTeamInvitationsCache.refresh([crud.id]);
1830
- },
1831
- async listInvitations() {
1832
- const result = import_results.Result.orThrow(await app._serverTeamInvitationsCache.getOrWait([crud.id], "write-only"));
1833
- return result.map((crud2) => app._serverTeamInvitationFromCrud(crud2));
1834
- },
1835
- useInvitations() {
1836
- const result = useAsyncCache(app._serverTeamInvitationsCache, [crud.id], "team.useInvitations()");
1837
- return (0, import_react2.useMemo)(() => result.map((crud2) => app._serverTeamInvitationFromCrud(crud2)), [result]);
1838
- }
1839
- };
1840
- }
1841
- async createUser(options) {
1842
- const crud = await this._interface.createServerUser(serverUserCreateOptionsToCrud(options));
1843
- await this._refreshUsers();
1844
- return this._serverUserFromCrud(crud);
1845
- }
1846
- async getUser(options) {
1847
- if (typeof options === "string") {
1848
- return await this.getServerUserById(options);
1849
- } else {
1850
- this._ensurePersistentTokenStore(options?.tokenStore);
1851
- const session = await this._getSession(options?.tokenStore);
1852
- const crud = import_results.Result.orThrow(await this._currentServerUserCache.getOrWait([session], "write-only"));
1853
- if (crud === null) {
1854
- switch (options?.or) {
1855
- case "redirect": {
1856
- await this.redirectToSignIn({ replace: true });
1857
- break;
1858
- }
1859
- case "throw": {
1860
- throw new Error("User is not signed in but getUser was called with { or: 'throw' }");
1861
- }
1862
- default: {
1863
- return null;
1864
- }
1865
- }
1866
- }
1867
- return crud && this._currentUserFromCrud(crud, session);
1868
- }
1869
- }
1870
- async getServerUser() {
1871
- console.warn("stackServerApp.getServerUser is deprecated; use stackServerApp.getUser instead");
1872
- return await this.getUser();
1873
- }
1874
- async getServerUserById(userId) {
1875
- const crud = import_results.Result.orThrow(await this._serverUserCache.getOrWait([userId], "write-only"));
1876
- return crud && this._serverUserFromCrud(crud);
1877
- }
1878
- useUser(options) {
1879
- if (typeof options === "string") {
1880
- return this.useUserById(options);
1881
- } else {
1882
- this._ensurePersistentTokenStore(options?.tokenStore);
1883
- const session = this._useSession(options?.tokenStore);
1884
- const crud = useAsyncCache(this._currentServerUserCache, [session], "useUser()");
1885
- if (crud === null) {
1886
- switch (options?.or) {
1887
- case "redirect": {
1888
- (0, import_promises.runAsynchronously)(this.redirectToSignIn({ replace: true }));
1889
- (0, import_react.suspend)();
1890
- throw new import_errors.StackAssertionError("suspend should never return");
1891
- }
1892
- case "throw": {
1893
- throw new Error("User is not signed in but useUser was called with { or: 'throw' }");
1894
- }
1895
- case void 0:
1896
- case "return-null": {
1897
- }
1898
- }
1899
- }
1900
- return (0, import_react2.useMemo)(() => {
1901
- return crud && this._currentUserFromCrud(crud, session);
1902
- }, [crud, session, options?.or]);
1903
- }
1904
- }
1905
- useUserById(userId) {
1906
- const crud = useAsyncCache(this._serverUserCache, [userId], "useUserById()");
1907
- return (0, import_react2.useMemo)(() => {
1908
- return crud && this._serverUserFromCrud(crud);
1909
- }, [crud]);
1910
- }
1911
- async listUsers(options) {
1912
- const crud = import_results.Result.orThrow(await this._serverUsersCache.getOrWait([options?.cursor, options?.limit, options?.orderBy, options?.desc, options?.query], "write-only"));
1913
- const result = crud.items.map((j) => this._serverUserFromCrud(j));
1914
- result.nextCursor = crud.pagination?.next_cursor ?? null;
1915
- return result;
1916
- }
1917
- useUsers(options) {
1918
- const crud = useAsyncCache(this._serverUsersCache, [options?.cursor, options?.limit, options?.orderBy, options?.desc, options?.query], "useServerUsers()");
1919
- const result = crud.items.map((j) => this._serverUserFromCrud(j));
1920
- result.nextCursor = crud.pagination?.next_cursor ?? null;
1921
- return result;
1922
- }
1923
- _serverPermissionFromCrud(crud) {
1924
- return {
1925
- id: crud.id
1926
- };
1927
- }
1928
- _serverTeamPermissionDefinitionFromCrud(crud) {
1929
- return {
1930
- id: crud.id,
1931
- description: crud.description,
1932
- containedPermissionIds: crud.contained_permission_ids
1933
- };
1934
- }
1935
- async listTeams() {
1936
- const teams = import_results.Result.orThrow(await this._serverTeamsCache.getOrWait([void 0], "write-only"));
1937
- return teams.map((t) => this._serverTeamFromCrud(t));
1938
- }
1939
- async createTeam(data) {
1940
- const team = await this._interface.createServerTeam(serverTeamCreateOptionsToCrud(data));
1941
- await this._serverTeamsCache.refresh([void 0]);
1942
- return this._serverTeamFromCrud(team);
1943
- }
1944
- useTeams() {
1945
- const teams = useAsyncCache(this._serverTeamsCache, [void 0], "useServerTeams()");
1946
- return (0, import_react2.useMemo)(() => {
1947
- return teams.map((t) => this._serverTeamFromCrud(t));
1948
- }, [teams]);
1949
- }
1950
- async getTeam(teamId) {
1951
- const teams = await this.listTeams();
1952
- return teams.find((t) => t.id === teamId) ?? null;
1953
- }
1954
- useTeam(teamId) {
1955
- const teams = this.useTeams();
1956
- return (0, import_react2.useMemo)(() => {
1957
- return teams.find((t) => t.id === teamId) ?? null;
1958
- }, [teams, teamId]);
1959
- }
1960
- async _refreshSession(session) {
1961
- await Promise.all([
1962
- super._refreshUser(session),
1963
- this._currentServerUserCache.refresh([session])
1964
- ]);
1965
- }
1966
- async _refreshUsers() {
1967
- await Promise.all([
1968
- super._refreshUsers(),
1969
- this._serverUserCache.refreshWhere(() => true),
1970
- this._serverUsersCache.refreshWhere(() => true),
1971
- this._serverContactChannelsCache.refreshWhere(() => true)
1972
- ]);
1973
- }
1974
- };
1975
- var _StackAdminAppImpl = class extends _StackServerAppImpl {
1976
- constructor(options) {
1977
- super({
1978
- interface: new import_stack_shared.StackAdminInterface({
1979
- getBaseUrl: () => getBaseUrl(options.baseUrl),
1980
- projectId: options.projectId ?? getDefaultProjectId(),
1981
- clientVersion,
1982
- ..."projectOwnerSession" in options ? {
1983
- projectOwnerSession: options.projectOwnerSession
1984
- } : {
1985
- publishableClientKey: options.publishableClientKey ?? getDefaultPublishableClientKey(),
1986
- secretServerKey: options.secretServerKey ?? getDefaultSecretServerKey(),
1987
- superSecretAdminKey: options.superSecretAdminKey ?? getDefaultSuperSecretAdminKey()
1988
- }
1989
- }),
1990
- baseUrl: options.baseUrl,
1991
- projectId: options.projectId,
1992
- tokenStore: options.tokenStore,
1993
- urls: options.urls,
1994
- oauthScopesOnSignIn: options.oauthScopesOnSignIn,
1995
- redirectMethod: options.redirectMethod
1996
- });
1997
- this._adminProjectCache = createCache(async () => {
1998
- return await this._interface.getProject();
1999
- });
2000
- this._apiKeysCache = createCache(async () => {
2001
- return await this._interface.listApiKeys();
2002
- });
2003
- this._adminEmailTemplatesCache = createCache(async () => {
2004
- return await this._interface.listEmailTemplates();
2005
- });
2006
- this._adminTeamPermissionDefinitionsCache = createCache(async () => {
2007
- return await this._interface.listPermissionDefinitions();
2008
- });
2009
- this._svixTokenCache = createCache(async () => {
2010
- return await this._interface.getSvixToken();
2011
- });
2012
- this._metricsCache = createCache(async () => {
2013
- return await this._interface.getMetrics();
2014
- });
2015
- }
2016
- _adminOwnedProjectFromCrud(data, onRefresh) {
2017
- if (this._tokenStoreInit !== null) {
2018
- throw new import_errors.StackAssertionError("Owned apps must always have tokenStore === null \u2014 did you not create this project with app._createOwnedApp()?");
2019
- ;
2020
- }
2021
- return {
2022
- ...this._adminProjectFromCrud(data, onRefresh),
2023
- app: this
2024
- };
2025
- }
2026
- _adminProjectFromCrud(data, onRefresh) {
2027
- if (data.id !== this.projectId) {
2028
- 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})!`);
2029
- }
2030
- const app = this;
2031
- return {
2032
- id: data.id,
2033
- displayName: data.display_name,
2034
- description: data.description,
2035
- createdAt: new Date(data.created_at_millis),
2036
- userCount: data.user_count,
2037
- isProductionMode: data.is_production_mode,
2038
- config: {
2039
- id: data.config.id,
2040
- signUpEnabled: data.config.sign_up_enabled,
2041
- credentialEnabled: data.config.credential_enabled,
2042
- magicLinkEnabled: data.config.magic_link_enabled,
2043
- passkeyEnabled: data.config.passkey_enabled,
2044
- clientTeamCreationEnabled: data.config.client_team_creation_enabled,
2045
- clientUserDeletionEnabled: data.config.client_user_deletion_enabled,
2046
- allowLocalhost: data.config.allow_localhost,
2047
- oauthProviders: data.config.oauth_providers.map((p) => p.type === "shared" ? {
2048
- id: p.id,
2049
- enabled: p.enabled,
2050
- type: "shared"
2051
- } : {
2052
- id: p.id,
2053
- enabled: p.enabled,
2054
- type: "standard",
2055
- clientId: p.client_id ?? (0, import_errors.throwErr)("Client ID is missing"),
2056
- clientSecret: p.client_secret ?? (0, import_errors.throwErr)("Client secret is missing"),
2057
- facebookConfigId: p.facebook_config_id,
2058
- microsoftTenantId: p.microsoft_tenant_id
2059
- }),
2060
- emailConfig: data.config.email_config.type === "shared" ? {
2061
- type: "shared"
2062
- } : {
2063
- type: "standard",
2064
- host: data.config.email_config.host ?? (0, import_errors.throwErr)("Email host is missing"),
2065
- port: data.config.email_config.port ?? (0, import_errors.throwErr)("Email port is missing"),
2066
- username: data.config.email_config.username ?? (0, import_errors.throwErr)("Email username is missing"),
2067
- password: data.config.email_config.password ?? (0, import_errors.throwErr)("Email password is missing"),
2068
- senderName: data.config.email_config.sender_name ?? (0, import_errors.throwErr)("Email sender name is missing"),
2069
- senderEmail: data.config.email_config.sender_email ?? (0, import_errors.throwErr)("Email sender email is missing")
2070
- },
2071
- domains: data.config.domains.map((d) => ({
2072
- domain: d.domain,
2073
- handlerPath: d.handler_path
2074
- })),
2075
- createTeamOnSignUp: data.config.create_team_on_sign_up,
2076
- teamCreatorDefaultPermissions: data.config.team_creator_default_permissions,
2077
- teamMemberDefaultPermissions: data.config.team_member_default_permissions
2078
- },
2079
- async update(update) {
2080
- await app._interface.updateProject(adminProjectUpdateOptionsToCrud(update));
2081
- await onRefresh();
2082
- },
2083
- async delete() {
2084
- await app._interface.deleteProject();
2085
- },
2086
- async getProductionModeErrors() {
2087
- return (0, import_production_mode.getProductionModeErrors)(data);
2088
- },
2089
- useProductionModeErrors() {
2090
- return (0, import_production_mode.getProductionModeErrors)(data);
2091
- }
2092
- };
2093
- }
2094
- _adminEmailTemplateFromCrud(data) {
2095
- return {
2096
- type: data.type,
2097
- subject: data.subject,
2098
- content: data.content,
2099
- isDefault: data.is_default
2100
- };
2101
- }
2102
- async getProject() {
2103
- return this._adminProjectFromCrud(
2104
- import_results.Result.orThrow(await this._adminProjectCache.getOrWait([], "write-only")),
2105
- () => this._refreshProject()
2106
- );
2107
- }
2108
- useProject() {
2109
- const crud = useAsyncCache(this._adminProjectCache, [], "useProjectAdmin()");
2110
- return (0, import_react2.useMemo)(() => this._adminProjectFromCrud(
2111
- crud,
2112
- () => this._refreshProject()
2113
- ), [crud]);
2114
- }
2115
- _createApiKeyBaseFromCrud(data) {
2116
- const app = this;
2117
- return {
2118
- id: data.id,
2119
- description: data.description,
2120
- expiresAt: new Date(data.expires_at_millis),
2121
- manuallyRevokedAt: data.manually_revoked_at_millis ? new Date(data.manually_revoked_at_millis) : null,
2122
- createdAt: new Date(data.created_at_millis),
2123
- isValid() {
2124
- return this.whyInvalid() === null;
2125
- },
2126
- whyInvalid() {
2127
- if (this.expiresAt.getTime() < Date.now()) return "expired";
2128
- if (this.manuallyRevokedAt) return "manually-revoked";
2129
- return null;
2130
- },
2131
- async revoke() {
2132
- const res = await app._interface.revokeApiKeyById(data.id);
2133
- await app._refreshApiKeys();
2134
- return res;
2135
- }
2136
- };
2137
- }
2138
- _createApiKeyFromCrud(data) {
2139
- return {
2140
- ...this._createApiKeyBaseFromCrud(data),
2141
- publishableClientKey: data.publishable_client_key ? { lastFour: data.publishable_client_key.last_four } : null,
2142
- secretServerKey: data.secret_server_key ? { lastFour: data.secret_server_key.last_four } : null,
2143
- superSecretAdminKey: data.super_secret_admin_key ? { lastFour: data.super_secret_admin_key.last_four } : null
2144
- };
2145
- }
2146
- _createApiKeyFirstViewFromCrud(data) {
2147
- return {
2148
- ...this._createApiKeyBaseFromCrud(data),
2149
- publishableClientKey: data.publishable_client_key,
2150
- secretServerKey: data.secret_server_key,
2151
- superSecretAdminKey: data.super_secret_admin_key
2152
- };
2153
- }
2154
- async listApiKeys() {
2155
- const crud = import_results.Result.orThrow(await this._apiKeysCache.getOrWait([], "write-only"));
2156
- return crud.map((j) => this._createApiKeyFromCrud(j));
2157
- }
2158
- useApiKeys() {
2159
- const crud = useAsyncCache(this._apiKeysCache, [], "useApiKeys()");
2160
- return (0, import_react2.useMemo)(() => {
2161
- return crud.map((j) => this._createApiKeyFromCrud(j));
2162
- }, [crud]);
2163
- }
2164
- async createApiKey(options) {
2165
- const crud = await this._interface.createApiKey(apiKeyCreateOptionsToCrud(options));
2166
- await this._refreshApiKeys();
2167
- return this._createApiKeyFirstViewFromCrud(crud);
2168
- }
2169
- useEmailTemplates() {
2170
- const crud = useAsyncCache(this._adminEmailTemplatesCache, [], "useEmailTemplates()");
2171
- return (0, import_react2.useMemo)(() => {
2172
- return crud.map((j) => this._adminEmailTemplateFromCrud(j));
2173
- }, [crud]);
2174
- }
2175
- async listEmailTemplates() {
2176
- const crud = import_results.Result.orThrow(await this._adminEmailTemplatesCache.getOrWait([], "write-only"));
2177
- return crud.map((j) => this._adminEmailTemplateFromCrud(j));
2178
- }
2179
- async updateEmailTemplate(type, data) {
2180
- await this._interface.updateEmailTemplate(type, adminEmailTemplateUpdateOptionsToCrud(data));
2181
- await this._adminEmailTemplatesCache.refresh([]);
2182
- }
2183
- async resetEmailTemplate(type) {
2184
- await this._interface.resetEmailTemplate(type);
2185
- await this._adminEmailTemplatesCache.refresh([]);
2186
- }
2187
- async createTeamPermissionDefinition(data) {
2188
- const crud = await this._interface.createPermissionDefinition(serverTeamPermissionDefinitionCreateOptionsToCrud(data));
2189
- await this._adminTeamPermissionDefinitionsCache.refresh([]);
2190
- return this._serverTeamPermissionDefinitionFromCrud(crud);
2191
- }
2192
- async updateTeamPermissionDefinition(permissionId, data) {
2193
- await this._interface.updatePermissionDefinition(permissionId, serverTeamPermissionDefinitionUpdateOptionsToCrud(data));
2194
- await this._adminTeamPermissionDefinitionsCache.refresh([]);
2195
- }
2196
- async deleteTeamPermissionDefinition(permissionId) {
2197
- await this._interface.deletePermissionDefinition(permissionId);
2198
- await this._adminTeamPermissionDefinitionsCache.refresh([]);
2199
- }
2200
- async listTeamPermissionDefinitions() {
2201
- const crud = import_results.Result.orThrow(await this._adminTeamPermissionDefinitionsCache.getOrWait([], "write-only"));
2202
- return crud.map((p) => this._serverTeamPermissionDefinitionFromCrud(p));
2203
- }
2204
- useTeamPermissionDefinitions() {
2205
- const crud = useAsyncCache(this._adminTeamPermissionDefinitionsCache, [], "usePermissions()");
2206
- return (0, import_react2.useMemo)(() => {
2207
- return crud.map((p) => this._serverTeamPermissionDefinitionFromCrud(p));
2208
- }, [crud]);
2209
- }
2210
- useSvixToken() {
2211
- const crud = useAsyncCache(this._svixTokenCache, [], "useSvixToken()");
2212
- return crud.token;
2213
- }
2214
- async _refreshProject() {
2215
- await Promise.all([
2216
- super._refreshProject(),
2217
- this._adminProjectCache.refresh([])
2218
- ]);
2219
- }
2220
- async _refreshApiKeys() {
2221
- await this._apiKeysCache.refresh([]);
2222
- }
2223
- get [stackAppInternalsSymbol]() {
2224
- return {
2225
- ...super[stackAppInternalsSymbol],
2226
- useMetrics: () => {
2227
- return useAsyncCache(this._metricsCache, [], "useMetrics()");
2228
- }
2229
- };
2230
- }
2231
- async sendTestEmail(options) {
2232
- const response = await this._interface.sendTestEmail({
2233
- recipient_email: options.recipientEmail,
2234
- email_config: {
2235
- ...(0, import_objects.pick)(options.emailConfig, ["host", "port", "username", "password"]),
2236
- sender_email: options.emailConfig.senderEmail,
2237
- sender_name: options.emailConfig.senderName
2238
- }
2239
- });
2240
- if (response.success) {
2241
- return import_results.Result.ok(void 0);
2242
- } else {
2243
- return import_results.Result.error({ errorMessage: response.error_message ?? (0, import_errors.throwErr)("Email test error not specified") });
2244
- }
2245
- }
2246
- };
2247
- function contactChannelCreateOptionsToCrud(userId, options) {
2248
- return {
2249
- value: options.value,
2250
- type: options.type,
2251
- used_for_auth: options.usedForAuth,
2252
- user_id: userId
2253
- };
2254
- }
2255
- function contactChannelUpdateOptionsToCrud(options) {
2256
- return {
2257
- value: options.value,
2258
- used_for_auth: options.usedForAuth,
2259
- is_primary: options.isPrimary
2260
- };
2261
- }
2262
- function serverContactChannelUpdateOptionsToCrud(options) {
2263
- return {
2264
- value: options.value,
2265
- is_verified: options.isVerified,
2266
- used_for_auth: options.usedForAuth
2267
- };
2268
- }
2269
- function serverContactChannelCreateOptionsToCrud(userId, options) {
2270
- return {
2271
- type: options.type,
2272
- value: options.value,
2273
- is_verified: options.isVerified,
2274
- user_id: userId,
2275
- used_for_auth: options.usedForAuth
2276
- };
2277
- }
2278
- function userUpdateOptionsToCrud(options) {
2279
- return {
2280
- display_name: options.displayName,
2281
- client_metadata: options.clientMetadata,
2282
- selected_team_id: options.selectedTeamId,
2283
- totp_secret_base64: options.totpMultiFactorSecret != null ? (0, import_bytes.encodeBase64)(options.totpMultiFactorSecret) : options.totpMultiFactorSecret,
2284
- profile_image_url: options.profileImageUrl,
2285
- otp_auth_enabled: options.otpAuthEnabled,
2286
- passkey_auth_enabled: options.passkeyAuthEnabled
2287
- };
2288
- }
2289
- function serverUserUpdateOptionsToCrud(options) {
2290
- return {
2291
- display_name: options.displayName,
2292
- primary_email: options.primaryEmail,
2293
- client_metadata: options.clientMetadata,
2294
- client_read_only_metadata: options.clientReadOnlyMetadata,
2295
- server_metadata: options.serverMetadata,
2296
- selected_team_id: options.selectedTeamId,
2297
- primary_email_auth_enabled: options.primaryEmailAuthEnabled,
2298
- primary_email_verified: options.primaryEmailVerified,
2299
- password: options.password,
2300
- profile_image_url: options.profileImageUrl,
2301
- totp_secret_base64: options.totpMultiFactorSecret != null ? (0, import_bytes.encodeBase64)(options.totpMultiFactorSecret) : options.totpMultiFactorSecret
2302
- };
2303
- }
2304
- function serverUserCreateOptionsToCrud(options) {
2305
- return {
2306
- primary_email: options.primaryEmail,
2307
- password: options.password,
2308
- otp_auth_enabled: options.otpAuthEnabled,
2309
- primary_email_auth_enabled: options.primaryEmailAuthEnabled,
2310
- display_name: options.displayName,
2311
- primary_email_verified: options.primaryEmailVerified,
2312
- client_metadata: options.clientMetadata,
2313
- client_read_only_metadata: options.clientReadOnlyMetadata,
2314
- server_metadata: options.serverMetadata
2315
- };
2316
- }
2317
- function adminProjectUpdateOptionsToCrud(options) {
2318
- return {
2319
- display_name: options.displayName,
2320
- description: options.description,
2321
- is_production_mode: options.isProductionMode,
2322
- config: {
2323
- domains: options.config?.domains?.map((d) => ({
2324
- domain: d.domain,
2325
- handler_path: d.handlerPath
2326
- })),
2327
- oauth_providers: options.config?.oauthProviders?.map((p) => ({
2328
- id: p.id,
2329
- enabled: p.enabled,
2330
- type: p.type,
2331
- ...p.type === "standard" && {
2332
- client_id: p.clientId,
2333
- client_secret: p.clientSecret,
2334
- facebook_config_id: p.facebookConfigId,
2335
- microsoft_tenant_id: p.microsoftTenantId
2336
- }
2337
- })),
2338
- email_config: options.config?.emailConfig && (options.config.emailConfig.type === "shared" ? {
2339
- type: "shared"
2340
- } : {
2341
- type: "standard",
2342
- host: options.config.emailConfig.host,
2343
- port: options.config.emailConfig.port,
2344
- username: options.config.emailConfig.username,
2345
- password: options.config.emailConfig.password,
2346
- sender_name: options.config.emailConfig.senderName,
2347
- sender_email: options.config.emailConfig.senderEmail
2348
- }),
2349
- sign_up_enabled: options.config?.signUpEnabled,
2350
- credential_enabled: options.config?.credentialEnabled,
2351
- magic_link_enabled: options.config?.magicLinkEnabled,
2352
- passkey_enabled: options.config?.passkeyEnabled,
2353
- allow_localhost: options.config?.allowLocalhost,
2354
- create_team_on_sign_up: options.config?.createTeamOnSignUp,
2355
- client_team_creation_enabled: options.config?.clientTeamCreationEnabled,
2356
- client_user_deletion_enabled: options.config?.clientUserDeletionEnabled,
2357
- team_creator_default_permissions: options.config?.teamCreatorDefaultPermissions,
2358
- team_member_default_permissions: options.config?.teamMemberDefaultPermissions
2359
- }
2360
- };
2361
- }
2362
- function adminProjectCreateOptionsToCrud(options) {
2363
- return {
2364
- ...adminProjectUpdateOptionsToCrud(options),
2365
- display_name: options.displayName
2366
- };
2367
- }
2368
- function apiKeyCreateOptionsToCrud(options) {
2369
- return {
2370
- description: options.description,
2371
- expires_at_millis: options.expiresAt.getTime(),
2372
- has_publishable_client_key: options.hasPublishableClientKey,
2373
- has_secret_server_key: options.hasSecretServerKey,
2374
- has_super_secret_admin_key: options.hasSuperSecretAdminKey
2375
- };
2376
- }
2377
- function teamUpdateOptionsToCrud(options) {
2378
- return {
2379
- display_name: options.displayName,
2380
- profile_image_url: options.profileImageUrl,
2381
- client_metadata: options.clientMetadata
2382
- };
2383
- }
2384
- function teamCreateOptionsToCrud(options, creatorUserId) {
2385
- return {
2386
- display_name: options.displayName,
2387
- profile_image_url: options.profileImageUrl,
2388
- creator_user_id: creatorUserId
2389
- };
2390
- }
2391
- function serverTeamCreateOptionsToCrud(options) {
2392
- return {
2393
- display_name: options.displayName,
2394
- profile_image_url: options.profileImageUrl,
2395
- creator_user_id: options.creatorUserId
2396
- };
2397
- }
2398
- function serverTeamUpdateOptionsToCrud(options) {
2399
- return {
2400
- display_name: options.displayName,
2401
- profile_image_url: options.profileImageUrl,
2402
- client_metadata: options.clientMetadata,
2403
- client_read_only_metadata: options.clientReadOnlyMetadata,
2404
- server_metadata: options.serverMetadata
2405
- };
2406
- }
2407
- function serverTeamPermissionDefinitionCreateOptionsToCrud(options) {
2408
- return {
2409
- id: options.id,
2410
- description: options.description,
2411
- contained_permission_ids: options.containedPermissionIds
2412
- };
2413
- }
2414
- function serverTeamPermissionDefinitionUpdateOptionsToCrud(options) {
2415
- return {
2416
- id: options.id,
2417
- description: options.description,
2418
- contained_permission_ids: options.containedPermissionIds
2419
- };
2420
- }
2421
- var StackClientApp = _StackClientAppImpl;
2422
- var StackServerApp = _StackServerAppImpl;
2423
- var StackAdminApp = _StackAdminAppImpl;
2424
- function adminEmailTemplateUpdateOptionsToCrud(options) {
2425
- return {
2426
- subject: options.subject,
2427
- content: options.content
2428
- };
2429
- }
1348
+ /**
1349
+ * There is a circular dependency between the admin app and the client app, as the former inherits from the latter and
1350
+ * the latter needs to use the former when creating a new instance of an internal project.
1351
+ *
1352
+ * To break it, we set the admin app here lazily instead of importing it directly. This variable is set by ./index.ts,
1353
+ * which imports both this file and ./admin-app-impl.ts.
1354
+ */
1355
+ __StackClientAppImplIncomplete.LazyStackAdminAppImpl = { value: void 0 };
1356
+ var _StackClientAppImplIncomplete = __StackClientAppImplIncomplete;
2430
1357
  // Annotate the CommonJS export names for ESM import in node:
2431
1358
  0 && (module.exports = {
2432
- StackAdminApp,
2433
- StackClientApp,
2434
- StackServerApp,
2435
- serverTeamPermissionDefinitionCreateOptionsToCrud,
2436
- serverTeamPermissionDefinitionUpdateOptionsToCrud,
2437
- stackAppInternalsSymbol
1359
+ _StackClientAppImplIncomplete
2438
1360
  });
2439
- //# sourceMappingURL=stack-app.js.map
1361
+ //# sourceMappingURL=client-app-impl.js.map