@stackframe/js 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 (131) hide show
  1. package/CHANGELOG.md +20 -0
  2. package/README.md +2 -2
  3. package/dist/admin-app-impl-Co__PI-r.d.ts +357 -0
  4. package/dist/admin-app-impl-s-tPjfRz.d.mts +357 -0
  5. package/dist/esm/lib/stack-app/api-keys/index.js +14 -0
  6. package/dist/esm/lib/stack-app/api-keys/index.js.map +1 -0
  7. package/dist/esm/lib/stack-app/apps/implementations/admin-app-impl.js +257 -0
  8. package/dist/esm/lib/stack-app/apps/implementations/admin-app-impl.js.map +1 -0
  9. package/dist/esm/lib/{stack-app.js → stack-app/apps/implementations/client-app-impl.js} +33 -950
  10. package/dist/esm/lib/stack-app/apps/implementations/client-app-impl.js.map +1 -0
  11. package/dist/esm/lib/stack-app/apps/implementations/common.js +107 -0
  12. package/dist/esm/lib/stack-app/apps/implementations/common.js.map +1 -0
  13. package/dist/esm/lib/stack-app/apps/implementations/index.js +24 -0
  14. package/dist/esm/lib/stack-app/apps/implementations/index.js.map +1 -0
  15. package/dist/esm/lib/stack-app/apps/implementations/server-app-impl.js +430 -0
  16. package/dist/esm/lib/stack-app/apps/implementations/server-app-impl.js.map +1 -0
  17. package/dist/esm/lib/stack-app/apps/index.js +16 -0
  18. package/dist/esm/lib/stack-app/apps/index.js.map +1 -0
  19. package/dist/esm/lib/stack-app/apps/interfaces/admin-app.js +7 -0
  20. package/dist/esm/lib/stack-app/apps/interfaces/admin-app.js.map +1 -0
  21. package/dist/esm/lib/stack-app/apps/interfaces/client-app.js +7 -0
  22. package/dist/esm/lib/stack-app/apps/interfaces/client-app.js.map +1 -0
  23. package/dist/esm/lib/stack-app/apps/interfaces/server-app.js +7 -0
  24. package/dist/esm/lib/stack-app/apps/interfaces/server-app.js.map +1 -0
  25. package/dist/esm/lib/stack-app/common.js +6 -0
  26. package/dist/esm/lib/stack-app/common.js.map +1 -0
  27. package/dist/esm/lib/stack-app/connected-accounts/index.js +1 -0
  28. package/dist/esm/lib/stack-app/connected-accounts/index.js.map +1 -0
  29. package/dist/esm/lib/stack-app/contact-channels/index.js +39 -0
  30. package/dist/esm/lib/stack-app/contact-channels/index.js.map +1 -0
  31. package/dist/esm/lib/stack-app/email-templates/index.js +11 -0
  32. package/dist/esm/lib/stack-app/email-templates/index.js.map +1 -0
  33. package/dist/esm/lib/stack-app/index.js +16 -0
  34. package/dist/esm/lib/stack-app/index.js.map +1 -0
  35. package/dist/esm/lib/stack-app/permissions/index.js +20 -0
  36. package/dist/esm/lib/stack-app/permissions/index.js.map +1 -0
  37. package/dist/esm/lib/stack-app/project-configs/index.js +1 -0
  38. package/dist/esm/lib/stack-app/project-configs/index.js.map +1 -0
  39. package/dist/esm/lib/stack-app/projects/index.js +57 -0
  40. package/dist/esm/lib/stack-app/projects/index.js.map +1 -0
  41. package/dist/esm/lib/stack-app/teams/index.js +38 -0
  42. package/dist/esm/lib/stack-app/teams/index.js.map +1 -0
  43. package/dist/esm/lib/stack-app/users/index.js +47 -0
  44. package/dist/esm/lib/stack-app/users/index.js.map +1 -0
  45. package/dist/{lib/stack-app.d.mts → index-COYzPcGI.d.mts} +127 -338
  46. package/dist/{lib/stack-app.d.ts → index-CueS5Qbi.d.ts} +127 -338
  47. package/dist/index.d.mts +17 -5
  48. package/dist/index.d.ts +17 -5
  49. package/dist/lib/stack-app/api-keys/index.d.mts +40 -0
  50. package/dist/lib/stack-app/api-keys/index.d.ts +40 -0
  51. package/dist/lib/stack-app/api-keys/index.js +39 -0
  52. package/dist/lib/stack-app/api-keys/index.js.map +1 -0
  53. package/dist/lib/stack-app/apps/implementations/admin-app-impl.d.mts +30 -0
  54. package/dist/lib/stack-app/apps/implementations/admin-app-impl.d.ts +30 -0
  55. package/dist/lib/stack-app/apps/implementations/admin-app-impl.js +282 -0
  56. package/dist/lib/stack-app/apps/implementations/admin-app-impl.js.map +1 -0
  57. package/dist/lib/stack-app/apps/implementations/client-app-impl.d.mts +30 -0
  58. package/dist/lib/stack-app/apps/implementations/client-app-impl.d.ts +30 -0
  59. package/dist/lib/{stack-app.js → stack-app/apps/implementations/client-app-impl.js} +60 -982
  60. package/dist/lib/stack-app/apps/implementations/client-app-impl.js.map +1 -0
  61. package/dist/lib/stack-app/apps/implementations/common.d.mts +44 -0
  62. package/dist/lib/stack-app/apps/implementations/common.d.ts +44 -0
  63. package/dist/lib/stack-app/apps/implementations/common.js +141 -0
  64. package/dist/lib/stack-app/apps/implementations/common.js.map +1 -0
  65. package/dist/lib/stack-app/apps/implementations/index.d.mts +36 -0
  66. package/dist/lib/stack-app/apps/implementations/index.d.ts +36 -0
  67. package/dist/lib/stack-app/apps/implementations/index.js +51 -0
  68. package/dist/lib/stack-app/apps/implementations/index.js.map +1 -0
  69. package/dist/lib/stack-app/apps/implementations/server-app-impl.d.mts +30 -0
  70. package/dist/lib/stack-app/apps/implementations/server-app-impl.d.ts +30 -0
  71. package/dist/lib/stack-app/apps/implementations/server-app-impl.js +455 -0
  72. package/dist/lib/stack-app/apps/implementations/server-app-impl.js.map +1 -0
  73. package/dist/lib/stack-app/apps/index.d.mts +23 -0
  74. package/dist/lib/stack-app/apps/index.d.ts +23 -0
  75. package/dist/lib/stack-app/apps/index.js +37 -0
  76. package/dist/lib/stack-app/apps/index.js.map +1 -0
  77. package/dist/lib/stack-app/apps/interfaces/admin-app.d.mts +23 -0
  78. package/dist/lib/stack-app/apps/interfaces/admin-app.d.ts +23 -0
  79. package/dist/lib/stack-app/apps/interfaces/admin-app.js +32 -0
  80. package/dist/lib/stack-app/apps/interfaces/admin-app.js.map +1 -0
  81. package/dist/lib/stack-app/apps/interfaces/client-app.d.mts +23 -0
  82. package/dist/lib/stack-app/apps/interfaces/client-app.d.ts +23 -0
  83. package/dist/lib/stack-app/apps/interfaces/client-app.js +32 -0
  84. package/dist/lib/stack-app/apps/interfaces/client-app.js.map +1 -0
  85. package/dist/lib/stack-app/apps/interfaces/server-app.d.mts +23 -0
  86. package/dist/lib/stack-app/apps/interfaces/server-app.d.ts +23 -0
  87. package/dist/lib/stack-app/apps/interfaces/server-app.js +32 -0
  88. package/dist/lib/stack-app/apps/interfaces/server-app.js.map +1 -0
  89. package/dist/lib/stack-app/common.d.mts +61 -0
  90. package/dist/lib/stack-app/common.d.ts +61 -0
  91. package/dist/lib/stack-app/common.js +31 -0
  92. package/dist/lib/stack-app/common.js.map +1 -0
  93. package/dist/lib/stack-app/connected-accounts/index.d.mts +10 -0
  94. package/dist/lib/stack-app/connected-accounts/index.d.ts +10 -0
  95. package/dist/lib/stack-app/connected-accounts/index.js +19 -0
  96. package/dist/lib/stack-app/connected-accounts/index.js.map +1 -0
  97. package/dist/lib/stack-app/contact-channels/index.d.mts +38 -0
  98. package/dist/lib/stack-app/contact-channels/index.d.ts +38 -0
  99. package/dist/lib/stack-app/contact-channels/index.js +67 -0
  100. package/dist/lib/stack-app/contact-channels/index.js.map +1 -0
  101. package/dist/lib/stack-app/email-templates/index.d.mts +15 -0
  102. package/dist/lib/stack-app/email-templates/index.d.ts +15 -0
  103. package/dist/lib/stack-app/email-templates/index.js +36 -0
  104. package/dist/lib/stack-app/email-templates/index.js.map +1 -0
  105. package/dist/lib/stack-app/index.d.mts +23 -0
  106. package/dist/lib/stack-app/index.d.ts +23 -0
  107. package/dist/lib/stack-app/index.js +38 -0
  108. package/dist/lib/stack-app/index.js.map +1 -0
  109. package/dist/lib/stack-app/permissions/index.d.mts +21 -0
  110. package/dist/lib/stack-app/permissions/index.d.ts +21 -0
  111. package/dist/lib/stack-app/permissions/index.js +46 -0
  112. package/dist/lib/stack-app/permissions/index.js.map +1 -0
  113. package/dist/lib/stack-app/project-configs/index.d.mts +82 -0
  114. package/dist/lib/stack-app/project-configs/index.d.ts +82 -0
  115. package/dist/lib/stack-app/project-configs/index.js +19 -0
  116. package/dist/lib/stack-app/project-configs/index.js.map +1 -0
  117. package/dist/lib/stack-app/projects/index.d.mts +23 -0
  118. package/dist/lib/stack-app/projects/index.d.ts +23 -0
  119. package/dist/lib/stack-app/projects/index.js +83 -0
  120. package/dist/lib/stack-app/projects/index.js.map +1 -0
  121. package/dist/lib/stack-app/teams/index.d.mts +23 -0
  122. package/dist/lib/stack-app/teams/index.d.ts +23 -0
  123. package/dist/lib/stack-app/teams/index.js +66 -0
  124. package/dist/lib/stack-app/teams/index.js.map +1 -0
  125. package/dist/lib/stack-app/users/index.d.mts +23 -0
  126. package/dist/lib/stack-app/users/index.d.ts +23 -0
  127. package/dist/lib/stack-app/users/index.js +74 -0
  128. package/dist/lib/stack-app/users/index.js.map +1 -0
  129. package/package.json +2 -2
  130. package/dist/esm/lib/stack-app.js.map +0 -1
  131. 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");
@@ -55,107 +47,26 @@ var import_strings = require("@stackframe/stack-shared/dist/utils/strings");
55
47
  var import_urls = require("@stackframe/stack-shared/dist/utils/urls");
56
48
  var import_uuids = require("@stackframe/stack-shared/dist/utils/uuids");
57
49
  var cookie = __toESM(require("cookie"));
58
- var import_url = require("../utils/url");
59
- var import_auth = require("./auth");
60
- var import_cookie = require("./cookie");
50
+ var import_url = require("../../../../utils/url");
51
+ var import_auth = require("../../../auth");
52
+ var import_cookie = require("../../../cookie");
53
+ var import_common = require("../../common");
54
+ var import_contact_channels = require("../../contact-channels");
55
+ var import_projects = require("../../projects");
56
+ var import_teams = require("../../teams");
57
+ var import_users = require("../../users");
58
+ var import_common2 = require("./common");
61
59
  var isReactServer = false;
62
- var clientVersion = "js @stackframe/js@2.7.21";
63
- if (clientVersion.startsWith("STACK_COMPILE_TIME")) {
64
- throw new import_errors.StackAssertionError("Client version was not replaced. Something went wrong during build!");
65
- }
66
60
  var process = globalThis.process ?? { env: {} };
67
- function getUrls(partial) {
68
- const handler = partial.handler ?? "/handler";
69
- const home = partial.home ?? "/";
70
- const afterSignIn = partial.afterSignIn ?? home;
71
- return {
72
- handler,
73
- signIn: `${handler}/sign-in`,
74
- afterSignIn: home,
75
- signUp: `${handler}/sign-up`,
76
- afterSignUp: afterSignIn,
77
- signOut: `${handler}/sign-out`,
78
- afterSignOut: home,
79
- emailVerification: `${handler}/email-verification`,
80
- passwordReset: `${handler}/password-reset`,
81
- forgotPassword: `${handler}/forgot-password`,
82
- oauthCallback: `${handler}/oauth-callback`,
83
- magicLinkCallback: `${handler}/magic-link-callback`,
84
- home,
85
- accountSettings: `${handler}/account-settings`,
86
- error: `${handler}/error`,
87
- teamInvitation: `${handler}/team-invitation`,
88
- ...(0, import_objects.filterUndefined)(partial)
89
- };
90
- }
91
- function getDefaultProjectId() {
92
- 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."));
93
- }
94
- function getDefaultPublishableClientKey() {
95
- 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."));
96
- }
97
- function getDefaultSecretServerKey() {
98
- 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."));
99
- }
100
- function getDefaultSuperSecretAdminKey() {
101
- 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."));
102
- }
103
- function getBaseUrl(userSpecifiedBaseUrl) {
104
- let url;
105
- if (userSpecifiedBaseUrl) {
106
- if (typeof userSpecifiedBaseUrl === "string") {
107
- url = userSpecifiedBaseUrl;
108
- } else {
109
- if ((0, import_env.isBrowserLike)()) {
110
- url = userSpecifiedBaseUrl.browser;
111
- } else {
112
- url = userSpecifiedBaseUrl.server;
113
- }
114
- }
115
- } else {
116
- if ((0, import_env.isBrowserLike)()) {
117
- url = process.env.NEXT_PUBLIC_BROWSER_STACK_API_URL;
118
- } else {
119
- url = process.env.NEXT_PUBLIC_SERVER_STACK_API_URL;
120
- }
121
- url = url || process.env.NEXT_PUBLIC_STACK_API_URL || process.env.NEXT_PUBLIC_STACK_URL || defaultBaseUrl;
122
- }
123
- return url.endsWith("/") ? url.slice(0, -1) : url;
124
- }
125
- var defaultBaseUrl = "https://api.stack-auth.com";
126
- function createEmptyTokenStore() {
127
- return new import_stores.Store({
128
- refreshToken: null,
129
- accessToken: null
130
- });
131
- }
132
- var stackAppInternalsSymbol = Symbol.for("StackAuth--DO-NOT-USE-OR-YOU-WILL-BE-FIRED--StackAppInternals");
133
- var allClientApps = /* @__PURE__ */ new Map();
134
- var createCache = (fetcher) => {
135
- return new import_caches.AsyncCache(
136
- async (dependencies) => await import_results.Result.fromThrowingAsync(async () => await fetcher(dependencies)),
137
- {}
138
- );
139
- };
140
- var createCacheBySession = (fetcher) => {
141
- return new import_caches.AsyncCache(
142
- async ([session, ...extraDependencies]) => await import_results.Result.fromThrowingAsync(async () => await fetcher(session, extraDependencies)),
143
- {
144
- onSubscribe: ([session], refresh) => {
145
- const handler = session.onInvalidate(() => refresh());
146
- return () => handler.unsubscribe();
147
- }
148
- }
149
- );
150
- };
151
61
  var numberOfAppsCreated = 0;
152
- var _StackClientAppImpl = class __StackClientAppImpl {
62
+ var allClientApps = /* @__PURE__ */ new Map();
63
+ var __StackClientAppImplIncomplete = class __StackClientAppImplIncomplete {
153
64
  constructor(_options) {
154
65
  this._options = _options;
155
66
  this._uniqueIdentifier = void 0;
156
67
  this.__DEMO_ENABLE_SLIGHT_FETCH_DELAY = false;
157
68
  this._ownedAdminApps = new import_maps.DependenciesMap();
158
- this._currentUserCache = createCacheBySession(async (session) => {
69
+ this._currentUserCache = (0, import_common2.createCacheBySession)(async (session) => {
159
70
  if (this.__DEMO_ENABLE_SLIGHT_FETCH_DELAY) {
160
71
  await (0, import_promises.wait)(2e3);
161
72
  }
@@ -164,19 +75,19 @@ var _StackClientAppImpl = class __StackClientAppImpl {
164
75
  }
165
76
  return await this._interface.getClientUserByToken(session);
166
77
  });
167
- this._currentProjectCache = createCache(async () => {
78
+ this._currentProjectCache = (0, import_common2.createCache)(async () => {
168
79
  return import_results.Result.orThrow(await this._interface.getClientProject());
169
80
  });
170
- this._ownedProjectsCache = createCacheBySession(async (session) => {
81
+ this._ownedProjectsCache = (0, import_common2.createCacheBySession)(async (session) => {
171
82
  return await this._interface.listProjects(session);
172
83
  });
173
- this._currentUserPermissionsCache = createCacheBySession(async (session, [teamId, recursive]) => {
84
+ this._currentUserPermissionsCache = (0, import_common2.createCacheBySession)(async (session, [teamId, recursive]) => {
174
85
  return await this._interface.listCurrentUserTeamPermissions({ teamId, recursive }, session);
175
86
  });
176
- this._currentUserTeamsCache = createCacheBySession(async (session) => {
87
+ this._currentUserTeamsCache = (0, import_common2.createCacheBySession)(async (session) => {
177
88
  return await this._interface.listCurrentUserTeams(session);
178
89
  });
179
- this._currentUserOAuthConnectionAccessTokensCache = createCacheBySession(
90
+ this._currentUserOAuthConnectionAccessTokensCache = (0, import_common2.createCacheBySession)(
180
91
  async (session, [providerId, scope]) => {
181
92
  try {
182
93
  const result = await this._interface.createProviderAccessToken(providerId, scope || "", session);
@@ -189,7 +100,7 @@ var _StackClientAppImpl = class __StackClientAppImpl {
189
100
  return null;
190
101
  }
191
102
  );
192
- this._currentUserOAuthConnectionCache = createCacheBySession(
103
+ this._currentUserOAuthConnectionCache = (0, import_common2.createCacheBySession)(
193
104
  async (session, [providerId, scope, redirect]) => {
194
105
  return await this._getUserOAuthConnectionCacheFn({
195
106
  getUser: async () => import_results.Result.orThrow(await this._currentUserCache.getOrWait([session], "write-only")),
@@ -201,27 +112,27 @@ var _StackClientAppImpl = class __StackClientAppImpl {
201
112
  });
202
113
  }
203
114
  );
204
- this._teamMemberProfilesCache = createCacheBySession(
115
+ this._teamMemberProfilesCache = (0, import_common2.createCacheBySession)(
205
116
  async (session, [teamId]) => {
206
117
  return await this._interface.listTeamMemberProfiles({ teamId }, session);
207
118
  }
208
119
  );
209
- this._teamInvitationsCache = createCacheBySession(
120
+ this._teamInvitationsCache = (0, import_common2.createCacheBySession)(
210
121
  async (session, [teamId]) => {
211
122
  return await this._interface.listTeamInvitations({ teamId }, session);
212
123
  }
213
124
  );
214
- this._currentUserTeamProfileCache = createCacheBySession(
125
+ this._currentUserTeamProfileCache = (0, import_common2.createCacheBySession)(
215
126
  async (session, [teamId]) => {
216
127
  return await this._interface.getTeamMemberProfile({ teamId, userId: "me" }, session);
217
128
  }
218
129
  );
219
- this._clientContactChannelsCache = createCacheBySession(
130
+ this._clientContactChannelsCache = (0, import_common2.createCacheBySession)(
220
131
  async (session) => {
221
132
  return await this._interface.listClientContactChannels(session);
222
133
  }
223
134
  );
224
- this._memoryTokenStore = createEmptyTokenStore();
135
+ this._memoryTokenStore = (0, import_common2.createEmptyTokenStore)();
225
136
  this._nextServerCookiesTokenStores = /* @__PURE__ */ new WeakMap();
226
137
  this._requestTokenStores = /* @__PURE__ */ new WeakMap();
227
138
  this._storedBrowserCookieTokenStore = null;
@@ -234,14 +145,17 @@ var _StackClientAppImpl = class __StackClientAppImpl {
234
145
  * - 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
235
146
  */
236
147
  this._sessionsByTokenStoreAndSessionKey = /* @__PURE__ */ new WeakMap();
148
+ if (!__StackClientAppImplIncomplete.LazyStackAdminAppImpl.value) {
149
+ 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).");
150
+ }
237
151
  if ("interface" in _options) {
238
152
  this._interface = _options.interface;
239
153
  } else {
240
154
  this._interface = new import_stack_shared.StackClientInterface({
241
- getBaseUrl: () => getBaseUrl(_options.baseUrl),
242
- projectId: _options.projectId ?? getDefaultProjectId(),
243
- clientVersion,
244
- publishableClientKey: _options.publishableClientKey ?? getDefaultPublishableClientKey(),
155
+ getBaseUrl: () => (0, import_common2.getBaseUrl)(_options.baseUrl),
156
+ projectId: _options.projectId ?? (0, import_common2.getDefaultProjectId)(),
157
+ clientVersion: import_common2.clientVersion,
158
+ publishableClientKey: _options.publishableClientKey ?? (0, import_common2.getDefaultPublishableClientKey)(),
245
159
  prepareRequest: async () => {
246
160
  }
247
161
  });
@@ -427,7 +341,7 @@ var _StackClientAppImpl = class __StackClientAppImpl {
427
341
  }
428
342
  default: {
429
343
  if (tokenStoreInit === null) {
430
- return createEmptyTokenStore();
344
+ return (0, import_common2.createEmptyTokenStore)();
431
345
  } else if (typeof tokenStoreInit === "object" && "headers" in tokenStoreInit) {
432
346
  if (this._requestTokenStores.has(tokenStoreInit)) return this._requestTokenStores.get(tokenStoreInit);
433
347
  const stackAuthHeader = tokenStoreInit.headers.get("x-stack-auth");
@@ -589,7 +503,7 @@ var _StackClientAppImpl = class __StackClientAppImpl {
589
503
  return result.map((crud2) => app._clientTeamInvitationFromCrud(session, crud2));
590
504
  },
591
505
  async update(data) {
592
- await app._interface.updateTeam({ data: teamUpdateOptionsToCrud(data), teamId: crud.id }, session);
506
+ await app._interface.updateTeam({ data: (0, import_teams.teamUpdateOptionsToCrud)(data), teamId: crud.id }, session);
593
507
  await app._currentUserTeamsCache.refresh([session]);
594
508
  },
595
509
  async delete() {
@@ -611,7 +525,7 @@ var _StackClientAppImpl = class __StackClientAppImpl {
611
525
  await app._interface.sendCurrentUserContactChannelVerificationEmail(crud.id, (0, import_url.constructRedirectUrl)(app.urls.emailVerification), session);
612
526
  },
613
527
  async update(data) {
614
- await app._interface.updateClientContactChannel(crud.id, contactChannelUpdateOptionsToCrud(data), session);
528
+ await app._interface.updateClientContactChannel(crud.id, (0, import_contact_channels.contactChannelUpdateOptionsToCrud)(data), session);
615
529
  await app._clientContactChannelsCache.refresh([session]);
616
530
  },
617
531
  async delete() {
@@ -659,12 +573,12 @@ var _StackClientAppImpl = class __StackClientAppImpl {
659
573
  let attResp;
660
574
  try {
661
575
  attResp = await (0, import_browser.startRegistration)({ optionsJSON: options_json });
662
- debugger;
663
576
  } catch (error) {
664
577
  if (error instanceof import_browser.WebAuthnError) {
665
578
  return import_results.Result.error(new import_stack_shared.KnownErrors.PasskeyWebAuthnError(error.message, error.name));
666
579
  } else {
667
- return import_results.Result.error(new import_stack_shared.KnownErrors.PasskeyRegistrationFailed("Failed to start passkey registration"));
580
+ (0, import_errors.captureError)("passkey-registration-failed", error);
581
+ return import_results.Result.error(new import_stack_shared.KnownErrors.PasskeyRegistrationFailed("Failed to start passkey registration due to unknown error"));
668
582
  }
669
583
  }
670
584
  const registrationResult = await app._interface.registerPasskey({ credential: attResp, code }, session);
@@ -741,7 +655,7 @@ var _StackClientAppImpl = class __StackClientAppImpl {
741
655
  return teams.map((crud2) => app._clientTeamFromCrud(crud2, session));
742
656
  },
743
657
  async createTeam(data) {
744
- const crud2 = await app._interface.createClientTeam(teamCreateOptionsToCrud(data, "me"), session);
658
+ const crud2 = await app._interface.createClientTeam((0, import_teams.teamCreateOptionsToCrud)(data, "me"), session);
745
659
  await app._currentUserTeamsCache.refresh([session]);
746
660
  return app._clientTeamFromCrud(crud2, session);
747
661
  },
@@ -796,7 +710,7 @@ var _StackClientAppImpl = class __StackClientAppImpl {
796
710
  return result.map((crud2) => app._clientContactChannelFromCrud(crud2, session));
797
711
  },
798
712
  async createContactChannel(data) {
799
- const crud2 = await app._interface.createClientContactChannel(contactChannelCreateOptionsToCrud("me", data), session);
713
+ const crud2 = await app._interface.createClientContactChannel((0, import_contact_channels.contactChannelCreateOptionsToCrud)("me", data), session);
800
714
  await app._clientContactChannelsCache.refresh([session]);
801
715
  return app._clientContactChannelFromCrud(crud2, session);
802
716
  }
@@ -826,7 +740,7 @@ var _StackClientAppImpl = class __StackClientAppImpl {
826
740
  }
827
741
  _getOwnedAdminApp(forProjectId, session) {
828
742
  if (!this._ownedAdminApps.has([session, forProjectId])) {
829
- this._ownedAdminApps.set([session, forProjectId], new _StackAdminAppImpl({
743
+ this._ownedAdminApps.set([session, forProjectId], new __StackClientAppImplIncomplete.LazyStackAdminAppImpl.value({
830
744
  baseUrl: this._interface.options.getBaseUrl(),
831
745
  projectId: forProjectId,
832
746
  tokenStore: null,
@@ -843,7 +757,7 @@ var _StackClientAppImpl = class __StackClientAppImpl {
843
757
  return (0, import_urls.isRelative)(url);
844
758
  }
845
759
  get urls() {
846
- return getUrls(this._urlOptions);
760
+ return (0, import_common2.getUrls)(this._urlOptions);
847
761
  }
848
762
  async _getCurrentUrl() {
849
763
  if (this._redirectMethod === "none") {
@@ -1028,7 +942,7 @@ var _StackClientAppImpl = class __StackClientAppImpl {
1028
942
  return crud && this._currentUserFromCrud(crud, session);
1029
943
  }
1030
944
  async _updateClientUser(update, session) {
1031
- const res = await this._interface.updateClientUser(userUpdateOptionsToCrud(update), session);
945
+ const res = await this._interface.updateClientUser((0, import_users.userUpdateOptionsToCrud)(update), session);
1032
946
  await this._refreshUser(session);
1033
947
  return res;
1034
948
  }
@@ -1241,7 +1155,7 @@ var _StackClientAppImpl = class __StackClientAppImpl {
1241
1155
  }
1242
1156
  async _createProject(session, newProject) {
1243
1157
  this._ensureInternalProject();
1244
- const crud = await this._interface.createProject(adminProjectCreateOptionsToCrud(newProject), session);
1158
+ const crud = await this._interface.createProject((0, import_projects.adminProjectCreateOptionsToCrud)(newProject), session);
1245
1159
  const res = this._getOwnedAdminApp(crud.id, session)._adminOwnedProjectFromCrud(
1246
1160
  crud,
1247
1161
  () => this._refreshOwnedProjects(session)
@@ -1263,7 +1177,7 @@ var _StackClientAppImpl = class __StackClientAppImpl {
1263
1177
  async _refreshOwnedProjects(session) {
1264
1178
  await this._ownedProjectsCache.refresh([session]);
1265
1179
  }
1266
- static get [stackAppInternalsSymbol]() {
1180
+ static get [import_common.stackAppInternalsSymbol]() {
1267
1181
  return {
1268
1182
  fromClientJson: (json) => {
1269
1183
  const providedCheckString = JSON.stringify((0, import_objects.omit)(json, [
@@ -1277,14 +1191,14 @@ var _StackClientAppImpl = class __StackClientAppImpl {
1277
1191
  }
1278
1192
  return clientApp;
1279
1193
  }
1280
- return new __StackClientAppImpl({
1194
+ return new __StackClientAppImplIncomplete({
1281
1195
  ...json,
1282
1196
  checkString: providedCheckString
1283
1197
  });
1284
1198
  }
1285
1199
  };
1286
1200
  }
1287
- get [stackAppInternalsSymbol]() {
1201
+ get [import_common.stackAppInternalsSymbol]() {
1288
1202
  return {
1289
1203
  toClientJson: () => {
1290
1204
  if (!("publishableClientKey" in this._interface.options)) {
@@ -1315,853 +1229,17 @@ var _StackClientAppImpl = class __StackClientAppImpl {
1315
1229
  };
1316
1230
  }
1317
1231
  };
1318
- var _StackServerAppImpl = class extends _StackClientAppImpl {
1319
- constructor(options) {
1320
- super("interface" in options ? {
1321
- interface: options.interface,
1322
- tokenStore: options.tokenStore,
1323
- urls: options.urls,
1324
- oauthScopesOnSignIn: options.oauthScopesOnSignIn
1325
- } : {
1326
- interface: new import_stack_shared.StackServerInterface({
1327
- getBaseUrl: () => getBaseUrl(options.baseUrl),
1328
- projectId: options.projectId ?? getDefaultProjectId(),
1329
- clientVersion,
1330
- publishableClientKey: options.publishableClientKey ?? getDefaultPublishableClientKey(),
1331
- secretServerKey: options.secretServerKey ?? getDefaultSecretServerKey()
1332
- }),
1333
- baseUrl: options.baseUrl,
1334
- projectId: options.projectId,
1335
- publishableClientKey: options.publishableClientKey,
1336
- tokenStore: options.tokenStore,
1337
- urls: options.urls ?? {},
1338
- oauthScopesOnSignIn: options.oauthScopesOnSignIn ?? {},
1339
- redirectMethod: options.redirectMethod
1340
- });
1341
- // TODO override the client user cache to use the server user cache, so we save some requests
1342
- this._currentServerUserCache = createCacheBySession(async (session) => {
1343
- if (session.isKnownToBeInvalid()) {
1344
- return null;
1345
- }
1346
- return await this._interface.getServerUserByToken(session);
1347
- });
1348
- this._serverUsersCache = createCache(async ([cursor, limit, orderBy, desc, query]) => {
1349
- return await this._interface.listServerUsers({ cursor, limit, orderBy, desc, query });
1350
- });
1351
- this._serverUserCache = createCache(async ([userId]) => {
1352
- const user = await this._interface.getServerUserById(userId);
1353
- return import_results.Result.or(user, null);
1354
- });
1355
- this._serverTeamsCache = createCache(async ([userId]) => {
1356
- return await this._interface.listServerTeams({ userId });
1357
- });
1358
- this._serverTeamUserPermissionsCache = createCache(async ([teamId, userId, recursive]) => {
1359
- return await this._interface.listServerTeamPermissions({ teamId, userId, recursive }, null);
1360
- });
1361
- this._serverUserOAuthConnectionAccessTokensCache = createCache(
1362
- async ([userId, providerId, scope]) => {
1363
- try {
1364
- const result = await this._interface.createServerProviderAccessToken(userId, providerId, scope || "");
1365
- return { accessToken: result.access_token };
1366
- } catch (err) {
1367
- if (!(err instanceof import_stack_shared.KnownErrors.OAuthConnectionDoesNotHaveRequiredScope || err instanceof import_stack_shared.KnownErrors.OAuthConnectionNotConnectedToUser)) {
1368
- throw err;
1369
- }
1370
- }
1371
- return null;
1372
- }
1373
- );
1374
- this._serverUserOAuthConnectionCache = createCache(
1375
- async ([userId, providerId, scope, redirect]) => {
1376
- return await this._getUserOAuthConnectionCacheFn({
1377
- getUser: async () => import_results.Result.orThrow(await this._serverUserCache.getOrWait([userId], "write-only")),
1378
- getOrWaitOAuthToken: async () => import_results.Result.orThrow(await this._serverUserOAuthConnectionAccessTokensCache.getOrWait([userId, providerId, scope || ""], "write-only")),
1379
- providerId,
1380
- scope,
1381
- redirect,
1382
- session: null
1383
- });
1384
- }
1385
- );
1386
- this._serverTeamMemberProfilesCache = createCache(
1387
- async ([teamId]) => {
1388
- return await this._interface.listServerTeamMemberProfiles({ teamId });
1389
- }
1390
- );
1391
- this._serverTeamInvitationsCache = createCache(
1392
- async ([teamId]) => {
1393
- return await this._interface.listServerTeamInvitations({ teamId });
1394
- }
1395
- );
1396
- this._serverUserTeamProfileCache = createCache(
1397
- async ([teamId, userId]) => {
1398
- return await this._interface.getServerTeamMemberProfile({ teamId, userId });
1399
- }
1400
- );
1401
- this._serverContactChannelsCache = createCache(
1402
- async ([userId]) => {
1403
- return await this._interface.listServerContactChannels(userId);
1404
- }
1405
- );
1406
- }
1407
- async _updateServerUser(userId, update) {
1408
- const result = await this._interface.updateServerUser(userId, serverUserUpdateOptionsToCrud(update));
1409
- await this._refreshUsers();
1410
- return result;
1411
- }
1412
- _serverEditableTeamProfileFromCrud(crud) {
1413
- const app = this;
1414
- return {
1415
- displayName: crud.display_name,
1416
- profileImageUrl: crud.profile_image_url,
1417
- async update(update) {
1418
- await app._interface.updateServerTeamMemberProfile({
1419
- teamId: crud.team_id,
1420
- userId: crud.user_id,
1421
- profile: {
1422
- display_name: update.displayName,
1423
- profile_image_url: update.profileImageUrl
1424
- }
1425
- });
1426
- await app._serverUserTeamProfileCache.refresh([crud.team_id, crud.user_id]);
1427
- }
1428
- };
1429
- }
1430
- _serverContactChannelFromCrud(userId, crud) {
1431
- const app = this;
1432
- return {
1433
- id: crud.id,
1434
- value: crud.value,
1435
- type: crud.type,
1436
- isVerified: crud.is_verified,
1437
- isPrimary: crud.is_primary,
1438
- usedForAuth: crud.used_for_auth,
1439
- async sendVerificationEmail(options) {
1440
- if (!options?.callbackUrl && !await app._getCurrentUrl()) {
1441
- 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: ... })`");
1442
- }
1443
- await app._interface.sendServerContactChannelVerificationEmail(userId, crud.id, options?.callbackUrl ?? (0, import_url.constructRedirectUrl)(app.urls.emailVerification));
1444
- },
1445
- async update(data) {
1446
- await app._interface.updateServerContactChannel(userId, crud.id, serverContactChannelUpdateOptionsToCrud(data));
1447
- },
1448
- async delete() {
1449
- await app._interface.deleteServerContactChannel(userId, crud.id);
1450
- }
1451
- };
1452
- }
1453
- _serverUserFromCrud(crud) {
1454
- const app = this;
1455
- async function getConnectedAccount(id, options) {
1456
- const scopeString = options?.scopes?.join(" ");
1457
- return import_results.Result.orThrow(await app._serverUserOAuthConnectionCache.getOrWait([crud.id, id, scopeString || "", options?.or === "redirect"], "write-only"));
1458
- }
1459
- return {
1460
- ...super._createBaseUser(crud),
1461
- lastActiveAt: new Date(crud.last_active_at_millis),
1462
- serverMetadata: crud.server_metadata,
1463
- async setPrimaryEmail(email, options) {
1464
- await app._updateServerUser(crud.id, { primaryEmail: email, primaryEmailVerified: options?.verified });
1465
- },
1466
- async grantPermission(scope, permissionId) {
1467
- await app._interface.grantServerTeamUserPermission(scope.id, crud.id, permissionId);
1468
- for (const recursive of [true, false]) {
1469
- await app._serverTeamUserPermissionsCache.refresh([scope.id, crud.id, recursive]);
1470
- }
1471
- },
1472
- async revokePermission(scope, permissionId) {
1473
- await app._interface.revokeServerTeamUserPermission(scope.id, crud.id, permissionId);
1474
- for (const recursive of [true, false]) {
1475
- await app._serverTeamUserPermissionsCache.refresh([scope.id, crud.id, recursive]);
1476
- }
1477
- },
1478
- async delete() {
1479
- const res = await app._interface.deleteServerServerUser(crud.id);
1480
- await app._refreshUsers();
1481
- return res;
1482
- },
1483
- async createSession(options) {
1484
- const tokens = await app._interface.createServerUserSession(crud.id, options.expiresInMillis ?? 1e3 * 60 * 60 * 24 * 365);
1485
- return {
1486
- async getTokens() {
1487
- return tokens;
1488
- }
1489
- };
1490
- },
1491
- async setDisplayName(displayName) {
1492
- return await this.update({ displayName });
1493
- },
1494
- async setClientMetadata(metadata) {
1495
- return await this.update({ clientMetadata: metadata });
1496
- },
1497
- async setClientReadOnlyMetadata(metadata) {
1498
- return await this.update({ clientReadOnlyMetadata: metadata });
1499
- },
1500
- async setServerMetadata(metadata) {
1501
- return await this.update({ serverMetadata: metadata });
1502
- },
1503
- async setSelectedTeam(team) {
1504
- return await this.update({ selectedTeamId: team?.id ?? null });
1505
- },
1506
- getConnectedAccount,
1507
- selectedTeam: crud.selected_team ? app._serverTeamFromCrud(crud.selected_team) : null,
1508
- async getTeam(teamId) {
1509
- const teams = await this.listTeams();
1510
- return teams.find((t) => t.id === teamId) ?? null;
1511
- },
1512
- async listTeams() {
1513
- const teams = import_results.Result.orThrow(await app._serverTeamsCache.getOrWait([crud.id], "write-only"));
1514
- return teams.map((t) => app._serverTeamFromCrud(t));
1515
- },
1516
- createTeam: async (data) => {
1517
- const team = await app._interface.createServerTeam(serverTeamCreateOptionsToCrud({
1518
- creatorUserId: crud.id,
1519
- ...data
1520
- }));
1521
- await app._serverTeamsCache.refresh([void 0]);
1522
- return app._serverTeamFromCrud(team);
1523
- },
1524
- leaveTeam: async (team) => {
1525
- await app._interface.leaveServerTeam({ teamId: team.id, userId: crud.id });
1526
- },
1527
- async listPermissions(scope, options) {
1528
- const recursive = options?.recursive ?? true;
1529
- const permissions = import_results.Result.orThrow(await app._serverTeamUserPermissionsCache.getOrWait([scope.id, crud.id, recursive], "write-only"));
1530
- return permissions.map((crud2) => app._serverPermissionFromCrud(crud2));
1531
- },
1532
- async getPermission(scope, permissionId) {
1533
- const permissions = await this.listPermissions(scope);
1534
- return permissions.find((p) => p.id === permissionId) ?? null;
1535
- },
1536
- async hasPermission(scope, permissionId) {
1537
- return await this.getPermission(scope, permissionId) !== null;
1538
- },
1539
- async update(update) {
1540
- await app._updateServerUser(crud.id, update);
1541
- },
1542
- async sendVerificationEmail() {
1543
- return await app._checkFeatureSupport("sendVerificationEmail() on ServerUser", {});
1544
- },
1545
- async updatePassword(options) {
1546
- const result = await this.update({ password: options.newPassword });
1547
- await app._serverUserCache.refresh([crud.id]);
1548
- return result;
1549
- },
1550
- async setPassword(options) {
1551
- const result = await this.update(options);
1552
- await app._serverUserCache.refresh([crud.id]);
1553
- return result;
1554
- },
1555
- async getTeamProfile(team) {
1556
- const result = import_results.Result.orThrow(await app._serverUserTeamProfileCache.getOrWait([team.id, crud.id], "write-only"));
1557
- return app._serverEditableTeamProfileFromCrud(result);
1558
- },
1559
- async listContactChannels() {
1560
- const result = import_results.Result.orThrow(await app._serverContactChannelsCache.getOrWait([crud.id], "write-only"));
1561
- return result.map((data) => app._serverContactChannelFromCrud(crud.id, data));
1562
- },
1563
- createContactChannel: async (data) => {
1564
- const contactChannel = await app._interface.createServerContactChannel(serverContactChannelCreateOptionsToCrud(crud.id, data));
1565
- await app._serverContactChannelsCache.refresh([crud.id]);
1566
- return app._serverContactChannelFromCrud(crud.id, contactChannel);
1567
- }
1568
- };
1569
- }
1570
- _serverTeamUserFromCrud(crud) {
1571
- return {
1572
- ...this._serverUserFromCrud(crud.user),
1573
- teamProfile: {
1574
- displayName: crud.display_name,
1575
- profileImageUrl: crud.profile_image_url
1576
- }
1577
- };
1578
- }
1579
- _serverTeamInvitationFromCrud(crud) {
1580
- return {
1581
- id: crud.id,
1582
- recipientEmail: crud.recipient_email,
1583
- expiresAt: new Date(crud.expires_at_millis),
1584
- revoke: async () => {
1585
- await this._interface.revokeServerTeamInvitation(crud.id, crud.team_id);
1586
- }
1587
- };
1588
- }
1589
- _currentUserFromCrud(crud, session) {
1590
- const app = this;
1591
- const currentUser = {
1592
- ...this._serverUserFromCrud(crud),
1593
- ...this._createAuth(session),
1594
- ...this._isInternalProject() ? this._createInternalUserExtra(session) : {}
1595
- };
1596
- Object.freeze(currentUser);
1597
- return currentUser;
1598
- }
1599
- _serverTeamFromCrud(crud) {
1600
- const app = this;
1601
- return {
1602
- id: crud.id,
1603
- displayName: crud.display_name,
1604
- profileImageUrl: crud.profile_image_url,
1605
- createdAt: new Date(crud.created_at_millis),
1606
- clientMetadata: crud.client_metadata,
1607
- clientReadOnlyMetadata: crud.client_read_only_metadata,
1608
- serverMetadata: crud.server_metadata,
1609
- async update(update) {
1610
- await app._interface.updateServerTeam(crud.id, serverTeamUpdateOptionsToCrud(update));
1611
- await app._serverTeamsCache.refresh([void 0]);
1612
- },
1613
- async delete() {
1614
- await app._interface.deleteServerTeam(crud.id);
1615
- await app._serverTeamsCache.refresh([void 0]);
1616
- },
1617
- async listUsers() {
1618
- const result = import_results.Result.orThrow(await app._serverTeamMemberProfilesCache.getOrWait([crud.id], "write-only"));
1619
- return result.map((u) => app._serverTeamUserFromCrud(u));
1620
- },
1621
- async addUser(userId) {
1622
- await app._interface.addServerUserToTeam({
1623
- teamId: crud.id,
1624
- userId
1625
- });
1626
- await app._serverTeamMemberProfilesCache.refresh([crud.id]);
1627
- },
1628
- async removeUser(userId) {
1629
- await app._interface.removeServerUserFromTeam({
1630
- teamId: crud.id,
1631
- userId
1632
- });
1633
- await app._serverTeamMemberProfilesCache.refresh([crud.id]);
1634
- },
1635
- async inviteUser(options) {
1636
- if (!options.callbackUrl && !await app._getCurrentUrl()) {
1637
- 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: ... })`");
1638
- }
1639
- await app._interface.sendServerTeamInvitation({
1640
- teamId: crud.id,
1641
- email: options.email,
1642
- callbackUrl: options.callbackUrl ?? (0, import_url.constructRedirectUrl)(app.urls.teamInvitation)
1643
- });
1644
- await app._serverTeamInvitationsCache.refresh([crud.id]);
1645
- },
1646
- async listInvitations() {
1647
- const result = import_results.Result.orThrow(await app._serverTeamInvitationsCache.getOrWait([crud.id], "write-only"));
1648
- return result.map((crud2) => app._serverTeamInvitationFromCrud(crud2));
1649
- }
1650
- };
1651
- }
1652
- async createUser(options) {
1653
- const crud = await this._interface.createServerUser(serverUserCreateOptionsToCrud(options));
1654
- await this._refreshUsers();
1655
- return this._serverUserFromCrud(crud);
1656
- }
1657
- async getUser(options) {
1658
- if (typeof options === "string") {
1659
- return await this.getServerUserById(options);
1660
- } else {
1661
- this._ensurePersistentTokenStore(options?.tokenStore);
1662
- const session = await this._getSession(options?.tokenStore);
1663
- const crud = import_results.Result.orThrow(await this._currentServerUserCache.getOrWait([session], "write-only"));
1664
- if (crud === null) {
1665
- switch (options?.or) {
1666
- case "redirect": {
1667
- await this.redirectToSignIn({ replace: true });
1668
- break;
1669
- }
1670
- case "throw": {
1671
- throw new Error("User is not signed in but getUser was called with { or: 'throw' }");
1672
- }
1673
- default: {
1674
- return null;
1675
- }
1676
- }
1677
- }
1678
- return crud && this._currentUserFromCrud(crud, session);
1679
- }
1680
- }
1681
- async getServerUser() {
1682
- console.warn("stackServerApp.getServerUser is deprecated; use stackServerApp.getUser instead");
1683
- return await this.getUser();
1684
- }
1685
- async getServerUserById(userId) {
1686
- const crud = import_results.Result.orThrow(await this._serverUserCache.getOrWait([userId], "write-only"));
1687
- return crud && this._serverUserFromCrud(crud);
1688
- }
1689
- async listUsers(options) {
1690
- const crud = import_results.Result.orThrow(await this._serverUsersCache.getOrWait([options?.cursor, options?.limit, options?.orderBy, options?.desc, options?.query], "write-only"));
1691
- const result = crud.items.map((j) => this._serverUserFromCrud(j));
1692
- result.nextCursor = crud.pagination?.next_cursor ?? null;
1693
- return result;
1694
- }
1695
- _serverPermissionFromCrud(crud) {
1696
- return {
1697
- id: crud.id
1698
- };
1699
- }
1700
- _serverTeamPermissionDefinitionFromCrud(crud) {
1701
- return {
1702
- id: crud.id,
1703
- description: crud.description,
1704
- containedPermissionIds: crud.contained_permission_ids
1705
- };
1706
- }
1707
- async listTeams() {
1708
- const teams = import_results.Result.orThrow(await this._serverTeamsCache.getOrWait([void 0], "write-only"));
1709
- return teams.map((t) => this._serverTeamFromCrud(t));
1710
- }
1711
- async createTeam(data) {
1712
- const team = await this._interface.createServerTeam(serverTeamCreateOptionsToCrud(data));
1713
- await this._serverTeamsCache.refresh([void 0]);
1714
- return this._serverTeamFromCrud(team);
1715
- }
1716
- async getTeam(teamId) {
1717
- const teams = await this.listTeams();
1718
- return teams.find((t) => t.id === teamId) ?? null;
1719
- }
1720
- async _refreshSession(session) {
1721
- await Promise.all([
1722
- super._refreshUser(session),
1723
- this._currentServerUserCache.refresh([session])
1724
- ]);
1725
- }
1726
- async _refreshUsers() {
1727
- await Promise.all([
1728
- super._refreshUsers(),
1729
- this._serverUserCache.refreshWhere(() => true),
1730
- this._serverUsersCache.refreshWhere(() => true),
1731
- this._serverContactChannelsCache.refreshWhere(() => true)
1732
- ]);
1733
- }
1734
- };
1735
- var _StackAdminAppImpl = class extends _StackServerAppImpl {
1736
- constructor(options) {
1737
- super({
1738
- interface: new import_stack_shared.StackAdminInterface({
1739
- getBaseUrl: () => getBaseUrl(options.baseUrl),
1740
- projectId: options.projectId ?? getDefaultProjectId(),
1741
- clientVersion,
1742
- ..."projectOwnerSession" in options ? {
1743
- projectOwnerSession: options.projectOwnerSession
1744
- } : {
1745
- publishableClientKey: options.publishableClientKey ?? getDefaultPublishableClientKey(),
1746
- secretServerKey: options.secretServerKey ?? getDefaultSecretServerKey(),
1747
- superSecretAdminKey: options.superSecretAdminKey ?? getDefaultSuperSecretAdminKey()
1748
- }
1749
- }),
1750
- baseUrl: options.baseUrl,
1751
- projectId: options.projectId,
1752
- tokenStore: options.tokenStore,
1753
- urls: options.urls,
1754
- oauthScopesOnSignIn: options.oauthScopesOnSignIn,
1755
- redirectMethod: options.redirectMethod
1756
- });
1757
- this._adminProjectCache = createCache(async () => {
1758
- return await this._interface.getProject();
1759
- });
1760
- this._apiKeysCache = createCache(async () => {
1761
- return await this._interface.listApiKeys();
1762
- });
1763
- this._adminEmailTemplatesCache = createCache(async () => {
1764
- return await this._interface.listEmailTemplates();
1765
- });
1766
- this._adminTeamPermissionDefinitionsCache = createCache(async () => {
1767
- return await this._interface.listPermissionDefinitions();
1768
- });
1769
- this._svixTokenCache = createCache(async () => {
1770
- return await this._interface.getSvixToken();
1771
- });
1772
- this._metricsCache = createCache(async () => {
1773
- return await this._interface.getMetrics();
1774
- });
1775
- }
1776
- _adminOwnedProjectFromCrud(data, onRefresh) {
1777
- if (this._tokenStoreInit !== null) {
1778
- throw new import_errors.StackAssertionError("Owned apps must always have tokenStore === null \u2014 did you not create this project with app._createOwnedApp()?");
1779
- ;
1780
- }
1781
- return {
1782
- ...this._adminProjectFromCrud(data, onRefresh),
1783
- app: this
1784
- };
1785
- }
1786
- _adminProjectFromCrud(data, onRefresh) {
1787
- if (data.id !== this.projectId) {
1788
- 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})!`);
1789
- }
1790
- const app = this;
1791
- return {
1792
- id: data.id,
1793
- displayName: data.display_name,
1794
- description: data.description,
1795
- createdAt: new Date(data.created_at_millis),
1796
- userCount: data.user_count,
1797
- isProductionMode: data.is_production_mode,
1798
- config: {
1799
- id: data.config.id,
1800
- signUpEnabled: data.config.sign_up_enabled,
1801
- credentialEnabled: data.config.credential_enabled,
1802
- magicLinkEnabled: data.config.magic_link_enabled,
1803
- passkeyEnabled: data.config.passkey_enabled,
1804
- clientTeamCreationEnabled: data.config.client_team_creation_enabled,
1805
- clientUserDeletionEnabled: data.config.client_user_deletion_enabled,
1806
- allowLocalhost: data.config.allow_localhost,
1807
- oauthProviders: data.config.oauth_providers.map((p) => p.type === "shared" ? {
1808
- id: p.id,
1809
- enabled: p.enabled,
1810
- type: "shared"
1811
- } : {
1812
- id: p.id,
1813
- enabled: p.enabled,
1814
- type: "standard",
1815
- clientId: p.client_id ?? (0, import_errors.throwErr)("Client ID is missing"),
1816
- clientSecret: p.client_secret ?? (0, import_errors.throwErr)("Client secret is missing"),
1817
- facebookConfigId: p.facebook_config_id,
1818
- microsoftTenantId: p.microsoft_tenant_id
1819
- }),
1820
- emailConfig: data.config.email_config.type === "shared" ? {
1821
- type: "shared"
1822
- } : {
1823
- type: "standard",
1824
- host: data.config.email_config.host ?? (0, import_errors.throwErr)("Email host is missing"),
1825
- port: data.config.email_config.port ?? (0, import_errors.throwErr)("Email port is missing"),
1826
- username: data.config.email_config.username ?? (0, import_errors.throwErr)("Email username is missing"),
1827
- password: data.config.email_config.password ?? (0, import_errors.throwErr)("Email password is missing"),
1828
- senderName: data.config.email_config.sender_name ?? (0, import_errors.throwErr)("Email sender name is missing"),
1829
- senderEmail: data.config.email_config.sender_email ?? (0, import_errors.throwErr)("Email sender email is missing")
1830
- },
1831
- domains: data.config.domains.map((d) => ({
1832
- domain: d.domain,
1833
- handlerPath: d.handler_path
1834
- })),
1835
- createTeamOnSignUp: data.config.create_team_on_sign_up,
1836
- teamCreatorDefaultPermissions: data.config.team_creator_default_permissions,
1837
- teamMemberDefaultPermissions: data.config.team_member_default_permissions
1838
- },
1839
- async update(update) {
1840
- await app._interface.updateProject(adminProjectUpdateOptionsToCrud(update));
1841
- await onRefresh();
1842
- },
1843
- async delete() {
1844
- await app._interface.deleteProject();
1845
- },
1846
- async getProductionModeErrors() {
1847
- return (0, import_production_mode.getProductionModeErrors)(data);
1848
- },
1849
- useProductionModeErrors() {
1850
- return (0, import_production_mode.getProductionModeErrors)(data);
1851
- }
1852
- };
1853
- }
1854
- _adminEmailTemplateFromCrud(data) {
1855
- return {
1856
- type: data.type,
1857
- subject: data.subject,
1858
- content: data.content,
1859
- isDefault: data.is_default
1860
- };
1861
- }
1862
- async getProject() {
1863
- return this._adminProjectFromCrud(
1864
- import_results.Result.orThrow(await this._adminProjectCache.getOrWait([], "write-only")),
1865
- () => this._refreshProject()
1866
- );
1867
- }
1868
- _createApiKeyBaseFromCrud(data) {
1869
- const app = this;
1870
- return {
1871
- id: data.id,
1872
- description: data.description,
1873
- expiresAt: new Date(data.expires_at_millis),
1874
- manuallyRevokedAt: data.manually_revoked_at_millis ? new Date(data.manually_revoked_at_millis) : null,
1875
- createdAt: new Date(data.created_at_millis),
1876
- isValid() {
1877
- return this.whyInvalid() === null;
1878
- },
1879
- whyInvalid() {
1880
- if (this.expiresAt.getTime() < Date.now()) return "expired";
1881
- if (this.manuallyRevokedAt) return "manually-revoked";
1882
- return null;
1883
- },
1884
- async revoke() {
1885
- const res = await app._interface.revokeApiKeyById(data.id);
1886
- await app._refreshApiKeys();
1887
- return res;
1888
- }
1889
- };
1890
- }
1891
- _createApiKeyFromCrud(data) {
1892
- return {
1893
- ...this._createApiKeyBaseFromCrud(data),
1894
- publishableClientKey: data.publishable_client_key ? { lastFour: data.publishable_client_key.last_four } : null,
1895
- secretServerKey: data.secret_server_key ? { lastFour: data.secret_server_key.last_four } : null,
1896
- superSecretAdminKey: data.super_secret_admin_key ? { lastFour: data.super_secret_admin_key.last_four } : null
1897
- };
1898
- }
1899
- _createApiKeyFirstViewFromCrud(data) {
1900
- return {
1901
- ...this._createApiKeyBaseFromCrud(data),
1902
- publishableClientKey: data.publishable_client_key,
1903
- secretServerKey: data.secret_server_key,
1904
- superSecretAdminKey: data.super_secret_admin_key
1905
- };
1906
- }
1907
- async listApiKeys() {
1908
- const crud = import_results.Result.orThrow(await this._apiKeysCache.getOrWait([], "write-only"));
1909
- return crud.map((j) => this._createApiKeyFromCrud(j));
1910
- }
1911
- async createApiKey(options) {
1912
- const crud = await this._interface.createApiKey(apiKeyCreateOptionsToCrud(options));
1913
- await this._refreshApiKeys();
1914
- return this._createApiKeyFirstViewFromCrud(crud);
1915
- }
1916
- async listEmailTemplates() {
1917
- const crud = import_results.Result.orThrow(await this._adminEmailTemplatesCache.getOrWait([], "write-only"));
1918
- return crud.map((j) => this._adminEmailTemplateFromCrud(j));
1919
- }
1920
- async updateEmailTemplate(type, data) {
1921
- await this._interface.updateEmailTemplate(type, adminEmailTemplateUpdateOptionsToCrud(data));
1922
- await this._adminEmailTemplatesCache.refresh([]);
1923
- }
1924
- async resetEmailTemplate(type) {
1925
- await this._interface.resetEmailTemplate(type);
1926
- await this._adminEmailTemplatesCache.refresh([]);
1927
- }
1928
- async createTeamPermissionDefinition(data) {
1929
- const crud = await this._interface.createPermissionDefinition(serverTeamPermissionDefinitionCreateOptionsToCrud(data));
1930
- await this._adminTeamPermissionDefinitionsCache.refresh([]);
1931
- return this._serverTeamPermissionDefinitionFromCrud(crud);
1932
- }
1933
- async updateTeamPermissionDefinition(permissionId, data) {
1934
- await this._interface.updatePermissionDefinition(permissionId, serverTeamPermissionDefinitionUpdateOptionsToCrud(data));
1935
- await this._adminTeamPermissionDefinitionsCache.refresh([]);
1936
- }
1937
- async deleteTeamPermissionDefinition(permissionId) {
1938
- await this._interface.deletePermissionDefinition(permissionId);
1939
- await this._adminTeamPermissionDefinitionsCache.refresh([]);
1940
- }
1941
- async listTeamPermissionDefinitions() {
1942
- const crud = import_results.Result.orThrow(await this._adminTeamPermissionDefinitionsCache.getOrWait([], "write-only"));
1943
- return crud.map((p) => this._serverTeamPermissionDefinitionFromCrud(p));
1944
- }
1945
- async _refreshProject() {
1946
- await Promise.all([
1947
- super._refreshProject(),
1948
- this._adminProjectCache.refresh([])
1949
- ]);
1950
- }
1951
- async _refreshApiKeys() {
1952
- await this._apiKeysCache.refresh([]);
1953
- }
1954
- get [stackAppInternalsSymbol]() {
1955
- return {
1956
- ...super[stackAppInternalsSymbol]
1957
- };
1958
- }
1959
- async sendTestEmail(options) {
1960
- const response = await this._interface.sendTestEmail({
1961
- recipient_email: options.recipientEmail,
1962
- email_config: {
1963
- ...(0, import_objects.pick)(options.emailConfig, ["host", "port", "username", "password"]),
1964
- sender_email: options.emailConfig.senderEmail,
1965
- sender_name: options.emailConfig.senderName
1966
- }
1967
- });
1968
- if (response.success) {
1969
- return import_results.Result.ok(void 0);
1970
- } else {
1971
- return import_results.Result.error({ errorMessage: response.error_message ?? (0, import_errors.throwErr)("Email test error not specified") });
1972
- }
1973
- }
1974
- };
1975
- function contactChannelCreateOptionsToCrud(userId, options) {
1976
- return {
1977
- value: options.value,
1978
- type: options.type,
1979
- used_for_auth: options.usedForAuth,
1980
- user_id: userId
1981
- };
1982
- }
1983
- function contactChannelUpdateOptionsToCrud(options) {
1984
- return {
1985
- value: options.value,
1986
- used_for_auth: options.usedForAuth,
1987
- is_primary: options.isPrimary
1988
- };
1989
- }
1990
- function serverContactChannelUpdateOptionsToCrud(options) {
1991
- return {
1992
- value: options.value,
1993
- is_verified: options.isVerified,
1994
- used_for_auth: options.usedForAuth
1995
- };
1996
- }
1997
- function serverContactChannelCreateOptionsToCrud(userId, options) {
1998
- return {
1999
- type: options.type,
2000
- value: options.value,
2001
- is_verified: options.isVerified,
2002
- user_id: userId,
2003
- used_for_auth: options.usedForAuth
2004
- };
2005
- }
2006
- function userUpdateOptionsToCrud(options) {
2007
- return {
2008
- display_name: options.displayName,
2009
- client_metadata: options.clientMetadata,
2010
- selected_team_id: options.selectedTeamId,
2011
- totp_secret_base64: options.totpMultiFactorSecret != null ? (0, import_bytes.encodeBase64)(options.totpMultiFactorSecret) : options.totpMultiFactorSecret,
2012
- profile_image_url: options.profileImageUrl,
2013
- otp_auth_enabled: options.otpAuthEnabled,
2014
- passkey_auth_enabled: options.passkeyAuthEnabled
2015
- };
2016
- }
2017
- function serverUserUpdateOptionsToCrud(options) {
2018
- return {
2019
- display_name: options.displayName,
2020
- primary_email: options.primaryEmail,
2021
- client_metadata: options.clientMetadata,
2022
- client_read_only_metadata: options.clientReadOnlyMetadata,
2023
- server_metadata: options.serverMetadata,
2024
- selected_team_id: options.selectedTeamId,
2025
- primary_email_auth_enabled: options.primaryEmailAuthEnabled,
2026
- primary_email_verified: options.primaryEmailVerified,
2027
- password: options.password,
2028
- profile_image_url: options.profileImageUrl,
2029
- totp_secret_base64: options.totpMultiFactorSecret != null ? (0, import_bytes.encodeBase64)(options.totpMultiFactorSecret) : options.totpMultiFactorSecret
2030
- };
2031
- }
2032
- function serverUserCreateOptionsToCrud(options) {
2033
- return {
2034
- primary_email: options.primaryEmail,
2035
- password: options.password,
2036
- otp_auth_enabled: options.otpAuthEnabled,
2037
- primary_email_auth_enabled: options.primaryEmailAuthEnabled,
2038
- display_name: options.displayName,
2039
- primary_email_verified: options.primaryEmailVerified,
2040
- client_metadata: options.clientMetadata,
2041
- client_read_only_metadata: options.clientReadOnlyMetadata,
2042
- server_metadata: options.serverMetadata
2043
- };
2044
- }
2045
- function adminProjectUpdateOptionsToCrud(options) {
2046
- return {
2047
- display_name: options.displayName,
2048
- description: options.description,
2049
- is_production_mode: options.isProductionMode,
2050
- config: {
2051
- domains: options.config?.domains?.map((d) => ({
2052
- domain: d.domain,
2053
- handler_path: d.handlerPath
2054
- })),
2055
- oauth_providers: options.config?.oauthProviders?.map((p) => ({
2056
- id: p.id,
2057
- enabled: p.enabled,
2058
- type: p.type,
2059
- ...p.type === "standard" && {
2060
- client_id: p.clientId,
2061
- client_secret: p.clientSecret,
2062
- facebook_config_id: p.facebookConfigId,
2063
- microsoft_tenant_id: p.microsoftTenantId
2064
- }
2065
- })),
2066
- email_config: options.config?.emailConfig && (options.config.emailConfig.type === "shared" ? {
2067
- type: "shared"
2068
- } : {
2069
- type: "standard",
2070
- host: options.config.emailConfig.host,
2071
- port: options.config.emailConfig.port,
2072
- username: options.config.emailConfig.username,
2073
- password: options.config.emailConfig.password,
2074
- sender_name: options.config.emailConfig.senderName,
2075
- sender_email: options.config.emailConfig.senderEmail
2076
- }),
2077
- sign_up_enabled: options.config?.signUpEnabled,
2078
- credential_enabled: options.config?.credentialEnabled,
2079
- magic_link_enabled: options.config?.magicLinkEnabled,
2080
- passkey_enabled: options.config?.passkeyEnabled,
2081
- allow_localhost: options.config?.allowLocalhost,
2082
- create_team_on_sign_up: options.config?.createTeamOnSignUp,
2083
- client_team_creation_enabled: options.config?.clientTeamCreationEnabled,
2084
- client_user_deletion_enabled: options.config?.clientUserDeletionEnabled,
2085
- team_creator_default_permissions: options.config?.teamCreatorDefaultPermissions,
2086
- team_member_default_permissions: options.config?.teamMemberDefaultPermissions
2087
- }
2088
- };
2089
- }
2090
- function adminProjectCreateOptionsToCrud(options) {
2091
- return {
2092
- ...adminProjectUpdateOptionsToCrud(options),
2093
- display_name: options.displayName
2094
- };
2095
- }
2096
- function apiKeyCreateOptionsToCrud(options) {
2097
- return {
2098
- description: options.description,
2099
- expires_at_millis: options.expiresAt.getTime(),
2100
- has_publishable_client_key: options.hasPublishableClientKey,
2101
- has_secret_server_key: options.hasSecretServerKey,
2102
- has_super_secret_admin_key: options.hasSuperSecretAdminKey
2103
- };
2104
- }
2105
- function teamUpdateOptionsToCrud(options) {
2106
- return {
2107
- display_name: options.displayName,
2108
- profile_image_url: options.profileImageUrl,
2109
- client_metadata: options.clientMetadata
2110
- };
2111
- }
2112
- function teamCreateOptionsToCrud(options, creatorUserId) {
2113
- return {
2114
- display_name: options.displayName,
2115
- profile_image_url: options.profileImageUrl,
2116
- creator_user_id: creatorUserId
2117
- };
2118
- }
2119
- function serverTeamCreateOptionsToCrud(options) {
2120
- return {
2121
- display_name: options.displayName,
2122
- profile_image_url: options.profileImageUrl,
2123
- creator_user_id: options.creatorUserId
2124
- };
2125
- }
2126
- function serverTeamUpdateOptionsToCrud(options) {
2127
- return {
2128
- display_name: options.displayName,
2129
- profile_image_url: options.profileImageUrl,
2130
- client_metadata: options.clientMetadata,
2131
- client_read_only_metadata: options.clientReadOnlyMetadata,
2132
- server_metadata: options.serverMetadata
2133
- };
2134
- }
2135
- function serverTeamPermissionDefinitionCreateOptionsToCrud(options) {
2136
- return {
2137
- id: options.id,
2138
- description: options.description,
2139
- contained_permission_ids: options.containedPermissionIds
2140
- };
2141
- }
2142
- function serverTeamPermissionDefinitionUpdateOptionsToCrud(options) {
2143
- return {
2144
- id: options.id,
2145
- description: options.description,
2146
- contained_permission_ids: options.containedPermissionIds
2147
- };
2148
- }
2149
- var StackClientApp = _StackClientAppImpl;
2150
- var StackServerApp = _StackServerAppImpl;
2151
- var StackAdminApp = _StackAdminAppImpl;
2152
- function adminEmailTemplateUpdateOptionsToCrud(options) {
2153
- return {
2154
- subject: options.subject,
2155
- content: options.content
2156
- };
2157
- }
1232
+ /**
1233
+ * There is a circular dependency between the admin app and the client app, as the former inherits from the latter and
1234
+ * the latter needs to use the former when creating a new instance of an internal project.
1235
+ *
1236
+ * To break it, we set the admin app here lazily instead of importing it directly. This variable is set by ./index.ts,
1237
+ * which imports both this file and ./admin-app-impl.ts.
1238
+ */
1239
+ __StackClientAppImplIncomplete.LazyStackAdminAppImpl = { value: void 0 };
1240
+ var _StackClientAppImplIncomplete = __StackClientAppImplIncomplete;
2158
1241
  // Annotate the CommonJS export names for ESM import in node:
2159
1242
  0 && (module.exports = {
2160
- StackAdminApp,
2161
- StackClientApp,
2162
- StackServerApp,
2163
- serverTeamPermissionDefinitionCreateOptionsToCrud,
2164
- serverTeamPermissionDefinitionUpdateOptionsToCrud,
2165
- stackAppInternalsSymbol
1243
+ _StackClientAppImplIncomplete
2166
1244
  });
2167
- //# sourceMappingURL=stack-app.js.map
1245
+ //# sourceMappingURL=client-app-impl.js.map