@stackframe/js 2.7.20 → 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 (162) hide show
  1. package/CHANGELOG.md +20 -0
  2. package/dist/admin-app-impl-Co__PI-r.d.ts +357 -0
  3. package/dist/admin-app-impl-s-tPjfRz.d.mts +357 -0
  4. package/dist/esm/index.js.map +1 -1
  5. package/dist/esm/lib/auth.js.map +1 -1
  6. package/dist/esm/lib/cookie.js +5 -8
  7. package/dist/esm/lib/cookie.js.map +1 -1
  8. package/dist/esm/lib/stack-app/api-keys/index.js +14 -0
  9. package/dist/esm/lib/stack-app/api-keys/index.js.map +1 -0
  10. package/dist/esm/lib/stack-app/apps/implementations/admin-app-impl.js +257 -0
  11. package/dist/esm/lib/stack-app/apps/implementations/admin-app-impl.js.map +1 -0
  12. package/dist/esm/lib/{stack-app.js → stack-app/apps/implementations/client-app-impl.js} +36 -952
  13. package/dist/esm/lib/stack-app/apps/implementations/client-app-impl.js.map +1 -0
  14. package/dist/esm/lib/stack-app/apps/implementations/common.js +107 -0
  15. package/dist/esm/lib/stack-app/apps/implementations/common.js.map +1 -0
  16. package/dist/esm/lib/stack-app/apps/implementations/index.js +24 -0
  17. package/dist/esm/lib/stack-app/apps/implementations/index.js.map +1 -0
  18. package/dist/esm/lib/stack-app/apps/implementations/server-app-impl.js +430 -0
  19. package/dist/esm/lib/stack-app/apps/implementations/server-app-impl.js.map +1 -0
  20. package/dist/esm/lib/stack-app/apps/index.js +16 -0
  21. package/dist/esm/lib/stack-app/apps/index.js.map +1 -0
  22. package/dist/esm/lib/stack-app/apps/interfaces/admin-app.js +7 -0
  23. package/dist/esm/lib/stack-app/apps/interfaces/admin-app.js.map +1 -0
  24. package/dist/esm/lib/stack-app/apps/interfaces/client-app.js +7 -0
  25. package/dist/esm/lib/stack-app/apps/interfaces/client-app.js.map +1 -0
  26. package/dist/esm/lib/stack-app/apps/interfaces/server-app.js +7 -0
  27. package/dist/esm/lib/stack-app/apps/interfaces/server-app.js.map +1 -0
  28. package/dist/esm/lib/stack-app/common.js +6 -0
  29. package/dist/esm/lib/stack-app/common.js.map +1 -0
  30. package/dist/esm/lib/stack-app/connected-accounts/index.js +1 -0
  31. package/dist/esm/lib/stack-app/contact-channels/index.js +39 -0
  32. package/dist/esm/lib/stack-app/contact-channels/index.js.map +1 -0
  33. package/dist/esm/lib/stack-app/email-templates/index.js +11 -0
  34. package/dist/esm/lib/stack-app/email-templates/index.js.map +1 -0
  35. package/dist/esm/lib/stack-app/index.js +16 -0
  36. package/dist/esm/lib/stack-app/index.js.map +1 -0
  37. package/dist/esm/lib/stack-app/permissions/index.js +20 -0
  38. package/dist/esm/lib/stack-app/permissions/index.js.map +1 -0
  39. package/dist/esm/lib/stack-app/project-configs/index.js +1 -0
  40. package/dist/esm/lib/stack-app/projects/index.js +57 -0
  41. package/dist/esm/lib/stack-app/projects/index.js.map +1 -0
  42. package/dist/esm/lib/stack-app/teams/index.js +38 -0
  43. package/dist/esm/lib/stack-app/teams/index.js.map +1 -0
  44. package/dist/esm/lib/stack-app/users/index.js +47 -0
  45. package/dist/esm/lib/stack-app/users/index.js.map +1 -0
  46. package/dist/esm/utils/url.js +4 -13
  47. package/dist/esm/utils/url.js.map +1 -1
  48. package/dist/{lib/stack-app.d.mts → index-COYzPcGI.d.mts} +128 -338
  49. package/dist/{lib/stack-app.d.ts → index-CueS5Qbi.d.ts} +128 -338
  50. package/dist/index.d.mts +17 -5
  51. package/dist/index.d.ts +17 -5
  52. package/dist/index.js.map +1 -1
  53. package/dist/lib/auth.js.map +1 -1
  54. package/dist/lib/cookie.d.mts +2 -2
  55. package/dist/lib/cookie.d.ts +2 -2
  56. package/dist/lib/cookie.js +6 -9
  57. package/dist/lib/cookie.js.map +1 -1
  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 +282 -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} +63 -984
  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 +44 -0
  71. package/dist/lib/stack-app/apps/implementations/common.d.ts +44 -0
  72. package/dist/lib/stack-app/apps/implementations/common.js +141 -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 +455 -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 +61 -0
  99. package/dist/lib/stack-app/common.d.ts +61 -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 +10 -0
  103. package/dist/lib/stack-app/connected-accounts/index.d.ts +10 -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/utils/url.d.mts +1 -2
  139. package/dist/utils/url.d.ts +1 -2
  140. package/dist/utils/url.js +4 -14
  141. package/dist/utils/url.js.map +1 -1
  142. package/package.json +2 -2
  143. package/dist/esm/generated/global-css.js +0 -6
  144. package/dist/esm/generated/global-css.js.map +0 -1
  145. package/dist/esm/generated/quetzal-translations.js +0 -2397
  146. package/dist/esm/generated/quetzal-translations.js.map +0 -1
  147. package/dist/esm/global.d.js +0 -1
  148. package/dist/esm/lib/stack-app.js.map +0 -1
  149. package/dist/generated/global-css.d.mts +0 -3
  150. package/dist/generated/global-css.d.ts +0 -3
  151. package/dist/generated/global-css.js +0 -31
  152. package/dist/generated/global-css.js.map +0 -1
  153. package/dist/generated/quetzal-translations.d.mts +0 -4
  154. package/dist/generated/quetzal-translations.d.ts +0 -4
  155. package/dist/generated/quetzal-translations.js +0 -2423
  156. package/dist/generated/quetzal-translations.js.map +0 -1
  157. package/dist/global.d.d.mts +0 -2
  158. package/dist/global.d.d.ts +0 -2
  159. package/dist/global.d.js +0 -2
  160. package/dist/lib/stack-app.js.map +0 -1
  161. /package/dist/esm/{global.d.js.map → lib/stack-app/connected-accounts/index.js.map} +0 -0
  162. /package/dist/{global.d.js.map → esm/lib/stack-app/project-configs/index.js.map} +0 -0
@@ -1,14 +1,11 @@
1
- // src/lib/stack-app.ts
1
+ // src/lib/stack-app/apps/implementations/client-app-impl.ts
2
2
  import { WebAuthnError, startAuthentication, startRegistration } from "@simplewebauthn/browser";
3
- import { KnownErrors, StackAdminInterface, StackClientInterface, StackServerInterface } from "@stackframe/stack-shared";
4
- import { getProductionModeErrors } from "@stackframe/stack-shared/dist/helpers/production-mode";
3
+ import { KnownErrors, StackClientInterface } from "@stackframe/stack-shared";
5
4
  import { InternalSession } from "@stackframe/stack-shared/dist/sessions";
6
- import { encodeBase64 } from "@stackframe/stack-shared/dist/utils/bytes";
7
- import { AsyncCache } from "@stackframe/stack-shared/dist/utils/caches";
8
5
  import { isBrowserLike } from "@stackframe/stack-shared/dist/utils/env";
9
- import { StackAssertionError, throwErr } from "@stackframe/stack-shared/dist/utils/errors";
6
+ import { StackAssertionError, captureError, throwErr } from "@stackframe/stack-shared/dist/utils/errors";
10
7
  import { DependenciesMap } from "@stackframe/stack-shared/dist/utils/maps";
11
- import { deepPlainEquals, filterUndefined, omit, pick } from "@stackframe/stack-shared/dist/utils/objects";
8
+ import { deepPlainEquals, omit } from "@stackframe/stack-shared/dist/utils/objects";
12
9
  import { neverResolve, runAsynchronously, wait } from "@stackframe/stack-shared/dist/utils/promises";
13
10
  import { Result } from "@stackframe/stack-shared/dist/utils/results";
14
11
  import { Store, storeLock } from "@stackframe/stack-shared/dist/utils/stores";
@@ -16,101 +13,20 @@ import { mergeScopeStrings } from "@stackframe/stack-shared/dist/utils/strings";
16
13
  import { getRelativePart, isRelative } from "@stackframe/stack-shared/dist/utils/urls";
17
14
  import { generateUuid } from "@stackframe/stack-shared/dist/utils/uuids";
18
15
  import * as cookie from "cookie";
19
- import { constructRedirectUrl } from "../utils/url";
20
- import { addNewOAuthProviderOrScope, callOAuthCallback, signInWithOAuth } from "./auth";
21
- import { createCookieHelper, createEmptyCookieHelper, deleteCookieClient, getCookieClient, setOrDeleteCookie, setOrDeleteCookieClient } from "./cookie";
16
+ import { constructRedirectUrl } from "../../../../utils/url";
17
+ import { addNewOAuthProviderOrScope, callOAuthCallback, signInWithOAuth } from "../../../auth";
18
+ import { createCookieHelper, createPlaceholderCookieHelper, deleteCookieClient, getCookieClient, setOrDeleteCookie, setOrDeleteCookieClient } from "../../../cookie";
19
+ import { stackAppInternalsSymbol } from "../../common";
20
+ import { contactChannelCreateOptionsToCrud, contactChannelUpdateOptionsToCrud } from "../../contact-channels";
21
+ import { adminProjectCreateOptionsToCrud } from "../../projects";
22
+ import { teamCreateOptionsToCrud, teamUpdateOptionsToCrud } from "../../teams";
23
+ import { userUpdateOptionsToCrud } from "../../users";
24
+ import { clientVersion, createCache, createCacheBySession, createEmptyTokenStore, getBaseUrl, getDefaultProjectId, getDefaultPublishableClientKey, getUrls } from "./common";
22
25
  var isReactServer = false;
23
- var clientVersion = "js @stackframe/js@2.7.20";
24
- if (clientVersion.startsWith("STACK_COMPILE_TIME")) {
25
- throw new StackAssertionError("Client version was not replaced. Something went wrong during build!");
26
- }
27
26
  var process = globalThis.process ?? { env: {} };
28
- function getUrls(partial) {
29
- const handler = partial.handler ?? "/handler";
30
- const home = partial.home ?? "/";
31
- const afterSignIn = partial.afterSignIn ?? home;
32
- return {
33
- handler,
34
- signIn: `${handler}/sign-in`,
35
- afterSignIn: home,
36
- signUp: `${handler}/sign-up`,
37
- afterSignUp: afterSignIn,
38
- signOut: `${handler}/sign-out`,
39
- afterSignOut: home,
40
- emailVerification: `${handler}/email-verification`,
41
- passwordReset: `${handler}/password-reset`,
42
- forgotPassword: `${handler}/forgot-password`,
43
- oauthCallback: `${handler}/oauth-callback`,
44
- magicLinkCallback: `${handler}/magic-link-callback`,
45
- home,
46
- accountSettings: `${handler}/account-settings`,
47
- error: `${handler}/error`,
48
- teamInvitation: `${handler}/team-invitation`,
49
- ...filterUndefined(partial)
50
- };
51
- }
52
- function getDefaultProjectId() {
53
- return process.env.NEXT_PUBLIC_STACK_PROJECT_ID || 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."));
54
- }
55
- function getDefaultPublishableClientKey() {
56
- return process.env.NEXT_PUBLIC_STACK_PUBLISHABLE_CLIENT_KEY || 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."));
57
- }
58
- function getDefaultSecretServerKey() {
59
- return process.env.STACK_SECRET_SERVER_KEY || 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."));
60
- }
61
- function getDefaultSuperSecretAdminKey() {
62
- return process.env.STACK_SUPER_SECRET_ADMIN_KEY || 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."));
63
- }
64
- function getBaseUrl(userSpecifiedBaseUrl) {
65
- let url;
66
- if (userSpecifiedBaseUrl) {
67
- if (typeof userSpecifiedBaseUrl === "string") {
68
- url = userSpecifiedBaseUrl;
69
- } else {
70
- if (isBrowserLike()) {
71
- url = userSpecifiedBaseUrl.browser;
72
- } else {
73
- url = userSpecifiedBaseUrl.server;
74
- }
75
- }
76
- } else {
77
- if (isBrowserLike()) {
78
- url = process.env.NEXT_PUBLIC_BROWSER_STACK_API_URL;
79
- } else {
80
- url = process.env.NEXT_PUBLIC_SERVER_STACK_API_URL;
81
- }
82
- url = url || process.env.NEXT_PUBLIC_STACK_API_URL || process.env.NEXT_PUBLIC_STACK_URL || defaultBaseUrl;
83
- }
84
- return url.endsWith("/") ? url.slice(0, -1) : url;
85
- }
86
- var defaultBaseUrl = "https://api.stack-auth.com";
87
- function createEmptyTokenStore() {
88
- return new Store({
89
- refreshToken: null,
90
- accessToken: null
91
- });
92
- }
93
- var stackAppInternalsSymbol = Symbol.for("StackAuth--DO-NOT-USE-OR-YOU-WILL-BE-FIRED--StackAppInternals");
94
- var allClientApps = /* @__PURE__ */ new Map();
95
- var createCache = (fetcher) => {
96
- return new AsyncCache(
97
- async (dependencies) => await Result.fromThrowingAsync(async () => await fetcher(dependencies)),
98
- {}
99
- );
100
- };
101
- var createCacheBySession = (fetcher) => {
102
- return new AsyncCache(
103
- async ([session, ...extraDependencies]) => await Result.fromThrowingAsync(async () => await fetcher(session, extraDependencies)),
104
- {
105
- onSubscribe: ([session], refresh) => {
106
- const handler = session.onInvalidate(() => refresh());
107
- return () => handler.unsubscribe();
108
- }
109
- }
110
- );
111
- };
112
27
  var numberOfAppsCreated = 0;
113
- var _StackClientAppImpl = class __StackClientAppImpl {
28
+ var allClientApps = /* @__PURE__ */ new Map();
29
+ var __StackClientAppImplIncomplete = class __StackClientAppImplIncomplete {
114
30
  constructor(_options) {
115
31
  this._options = _options;
116
32
  this._uniqueIdentifier = void 0;
@@ -183,6 +99,7 @@ var _StackClientAppImpl = class __StackClientAppImpl {
183
99
  }
184
100
  );
185
101
  this._memoryTokenStore = createEmptyTokenStore();
102
+ this._nextServerCookiesTokenStores = /* @__PURE__ */ new WeakMap();
186
103
  this._requestTokenStores = /* @__PURE__ */ new WeakMap();
187
104
  this._storedBrowserCookieTokenStore = null;
188
105
  /**
@@ -194,6 +111,9 @@ var _StackClientAppImpl = class __StackClientAppImpl {
194
111
  * - 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
195
112
  */
196
113
  this._sessionsByTokenStoreAndSessionKey = /* @__PURE__ */ new WeakMap();
114
+ if (!__StackClientAppImplIncomplete.LazyStackAdminAppImpl.value) {
115
+ throw new 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).");
116
+ }
197
117
  if ("interface" in _options) {
198
118
  this._interface = _options.interface;
199
119
  } else {
@@ -225,7 +145,7 @@ var _StackClientAppImpl = class __StackClientAppImpl {
225
145
  if (this._tokenStoreInit === "nextjs-cookie" || this._tokenStoreInit === "cookie") {
226
146
  return await createCookieHelper();
227
147
  } else {
228
- return await createEmptyCookieHelper();
148
+ return await createPlaceholderCookieHelper();
229
149
  }
230
150
  }
231
151
  async _getUserOAuthConnectionCacheFn(options) {
@@ -619,12 +539,12 @@ var _StackClientAppImpl = class __StackClientAppImpl {
619
539
  let attResp;
620
540
  try {
621
541
  attResp = await startRegistration({ optionsJSON: options_json });
622
- debugger;
623
542
  } catch (error) {
624
543
  if (error instanceof WebAuthnError) {
625
544
  return Result.error(new KnownErrors.PasskeyWebAuthnError(error.message, error.name));
626
545
  } else {
627
- return Result.error(new KnownErrors.PasskeyRegistrationFailed("Failed to start passkey registration"));
546
+ captureError("passkey-registration-failed", error);
547
+ return Result.error(new KnownErrors.PasskeyRegistrationFailed("Failed to start passkey registration due to unknown error"));
628
548
  }
629
549
  }
630
550
  const registrationResult = await app._interface.registerPasskey({ credential: attResp, code }, session);
@@ -786,7 +706,7 @@ var _StackClientAppImpl = class __StackClientAppImpl {
786
706
  }
787
707
  _getOwnedAdminApp(forProjectId, session) {
788
708
  if (!this._ownedAdminApps.has([session, forProjectId])) {
789
- this._ownedAdminApps.set([session, forProjectId], new _StackAdminAppImpl({
709
+ this._ownedAdminApps.set([session, forProjectId], new __StackClientAppImplIncomplete.LazyStackAdminAppImpl.value({
790
710
  baseUrl: this._interface.options.getBaseUrl(),
791
711
  projectId: forProjectId,
792
712
  tokenStore: null,
@@ -1063,7 +983,7 @@ var _StackClientAppImpl = class __StackClientAppImpl {
1063
983
  async signUpWithCredential(options) {
1064
984
  this._ensurePersistentTokenStore();
1065
985
  const session = await this._getSession();
1066
- const emailVerificationRedirectUrl = constructRedirectUrl(this.urls.emailVerification);
986
+ const emailVerificationRedirectUrl = options.verificationCallbackUrl ?? constructRedirectUrl(this.urls.emailVerification);
1067
987
  const result = await this._interface.signUpWithCredential(
1068
988
  options.email,
1069
989
  options.password,
@@ -1237,7 +1157,7 @@ var _StackClientAppImpl = class __StackClientAppImpl {
1237
1157
  }
1238
1158
  return clientApp;
1239
1159
  }
1240
- return new __StackClientAppImpl({
1160
+ return new __StackClientAppImplIncomplete({
1241
1161
  ...json,
1242
1162
  checkString: providedCheckString
1243
1163
  });
@@ -1275,852 +1195,16 @@ var _StackClientAppImpl = class __StackClientAppImpl {
1275
1195
  };
1276
1196
  }
1277
1197
  };
1278
- var _StackServerAppImpl = class extends _StackClientAppImpl {
1279
- constructor(options) {
1280
- super("interface" in options ? {
1281
- interface: options.interface,
1282
- tokenStore: options.tokenStore,
1283
- urls: options.urls,
1284
- oauthScopesOnSignIn: options.oauthScopesOnSignIn
1285
- } : {
1286
- interface: new StackServerInterface({
1287
- getBaseUrl: () => getBaseUrl(options.baseUrl),
1288
- projectId: options.projectId ?? getDefaultProjectId(),
1289
- clientVersion,
1290
- publishableClientKey: options.publishableClientKey ?? getDefaultPublishableClientKey(),
1291
- secretServerKey: options.secretServerKey ?? getDefaultSecretServerKey()
1292
- }),
1293
- baseUrl: options.baseUrl,
1294
- projectId: options.projectId,
1295
- publishableClientKey: options.publishableClientKey,
1296
- tokenStore: options.tokenStore,
1297
- urls: options.urls ?? {},
1298
- oauthScopesOnSignIn: options.oauthScopesOnSignIn ?? {},
1299
- redirectMethod: options.redirectMethod
1300
- });
1301
- // TODO override the client user cache to use the server user cache, so we save some requests
1302
- this._currentServerUserCache = createCacheBySession(async (session) => {
1303
- if (session.isKnownToBeInvalid()) {
1304
- return null;
1305
- }
1306
- return await this._interface.getServerUserByToken(session);
1307
- });
1308
- this._serverUsersCache = createCache(async ([cursor, limit, orderBy, desc, query]) => {
1309
- return await this._interface.listServerUsers({ cursor, limit, orderBy, desc, query });
1310
- });
1311
- this._serverUserCache = createCache(async ([userId]) => {
1312
- const user = await this._interface.getServerUserById(userId);
1313
- return Result.or(user, null);
1314
- });
1315
- this._serverTeamsCache = createCache(async ([userId]) => {
1316
- return await this._interface.listServerTeams({ userId });
1317
- });
1318
- this._serverTeamUserPermissionsCache = createCache(async ([teamId, userId, recursive]) => {
1319
- return await this._interface.listServerTeamPermissions({ teamId, userId, recursive }, null);
1320
- });
1321
- this._serverUserOAuthConnectionAccessTokensCache = createCache(
1322
- async ([userId, providerId, scope]) => {
1323
- try {
1324
- const result = await this._interface.createServerProviderAccessToken(userId, providerId, scope || "");
1325
- return { accessToken: result.access_token };
1326
- } catch (err) {
1327
- if (!(err instanceof KnownErrors.OAuthConnectionDoesNotHaveRequiredScope || err instanceof KnownErrors.OAuthConnectionNotConnectedToUser)) {
1328
- throw err;
1329
- }
1330
- }
1331
- return null;
1332
- }
1333
- );
1334
- this._serverUserOAuthConnectionCache = createCache(
1335
- async ([userId, providerId, scope, redirect]) => {
1336
- return await this._getUserOAuthConnectionCacheFn({
1337
- getUser: async () => Result.orThrow(await this._serverUserCache.getOrWait([userId], "write-only")),
1338
- getOrWaitOAuthToken: async () => Result.orThrow(await this._serverUserOAuthConnectionAccessTokensCache.getOrWait([userId, providerId, scope || ""], "write-only")),
1339
- providerId,
1340
- scope,
1341
- redirect,
1342
- session: null
1343
- });
1344
- }
1345
- );
1346
- this._serverTeamMemberProfilesCache = createCache(
1347
- async ([teamId]) => {
1348
- return await this._interface.listServerTeamMemberProfiles({ teamId });
1349
- }
1350
- );
1351
- this._serverTeamInvitationsCache = createCache(
1352
- async ([teamId]) => {
1353
- return await this._interface.listServerTeamInvitations({ teamId });
1354
- }
1355
- );
1356
- this._serverUserTeamProfileCache = createCache(
1357
- async ([teamId, userId]) => {
1358
- return await this._interface.getServerTeamMemberProfile({ teamId, userId });
1359
- }
1360
- );
1361
- this._serverContactChannelsCache = createCache(
1362
- async ([userId]) => {
1363
- return await this._interface.listServerContactChannels(userId);
1364
- }
1365
- );
1366
- }
1367
- async _updateServerUser(userId, update) {
1368
- const result = await this._interface.updateServerUser(userId, serverUserUpdateOptionsToCrud(update));
1369
- await this._refreshUsers();
1370
- return result;
1371
- }
1372
- _serverEditableTeamProfileFromCrud(crud) {
1373
- const app = this;
1374
- return {
1375
- displayName: crud.display_name,
1376
- profileImageUrl: crud.profile_image_url,
1377
- async update(update) {
1378
- await app._interface.updateServerTeamMemberProfile({
1379
- teamId: crud.team_id,
1380
- userId: crud.user_id,
1381
- profile: {
1382
- display_name: update.displayName,
1383
- profile_image_url: update.profileImageUrl
1384
- }
1385
- });
1386
- await app._serverUserTeamProfileCache.refresh([crud.team_id, crud.user_id]);
1387
- }
1388
- };
1389
- }
1390
- _serverContactChannelFromCrud(userId, crud) {
1391
- const app = this;
1392
- return {
1393
- id: crud.id,
1394
- value: crud.value,
1395
- type: crud.type,
1396
- isVerified: crud.is_verified,
1397
- isPrimary: crud.is_primary,
1398
- usedForAuth: crud.used_for_auth,
1399
- async sendVerificationEmail(options) {
1400
- if (!options?.callbackUrl && !await app._getCurrentUrl()) {
1401
- 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: ... })`");
1402
- }
1403
- await app._interface.sendServerContactChannelVerificationEmail(userId, crud.id, options?.callbackUrl ?? constructRedirectUrl(app.urls.emailVerification));
1404
- },
1405
- async update(data) {
1406
- await app._interface.updateServerContactChannel(userId, crud.id, serverContactChannelUpdateOptionsToCrud(data));
1407
- },
1408
- async delete() {
1409
- await app._interface.deleteServerContactChannel(userId, crud.id);
1410
- }
1411
- };
1412
- }
1413
- _serverUserFromCrud(crud) {
1414
- const app = this;
1415
- async function getConnectedAccount(id, options) {
1416
- const scopeString = options?.scopes?.join(" ");
1417
- return Result.orThrow(await app._serverUserOAuthConnectionCache.getOrWait([crud.id, id, scopeString || "", options?.or === "redirect"], "write-only"));
1418
- }
1419
- return {
1420
- ...super._createBaseUser(crud),
1421
- lastActiveAt: new Date(crud.last_active_at_millis),
1422
- serverMetadata: crud.server_metadata,
1423
- async setPrimaryEmail(email, options) {
1424
- await app._updateServerUser(crud.id, { primaryEmail: email, primaryEmailVerified: options?.verified });
1425
- },
1426
- async grantPermission(scope, permissionId) {
1427
- await app._interface.grantServerTeamUserPermission(scope.id, crud.id, permissionId);
1428
- for (const recursive of [true, false]) {
1429
- await app._serverTeamUserPermissionsCache.refresh([scope.id, crud.id, recursive]);
1430
- }
1431
- },
1432
- async revokePermission(scope, permissionId) {
1433
- await app._interface.revokeServerTeamUserPermission(scope.id, crud.id, permissionId);
1434
- for (const recursive of [true, false]) {
1435
- await app._serverTeamUserPermissionsCache.refresh([scope.id, crud.id, recursive]);
1436
- }
1437
- },
1438
- async delete() {
1439
- const res = await app._interface.deleteServerServerUser(crud.id);
1440
- await app._refreshUsers();
1441
- return res;
1442
- },
1443
- async createSession(options) {
1444
- const tokens = await app._interface.createServerUserSession(crud.id, options.expiresInMillis ?? 1e3 * 60 * 60 * 24 * 365);
1445
- return {
1446
- async getTokens() {
1447
- return tokens;
1448
- }
1449
- };
1450
- },
1451
- async setDisplayName(displayName) {
1452
- return await this.update({ displayName });
1453
- },
1454
- async setClientMetadata(metadata) {
1455
- return await this.update({ clientMetadata: metadata });
1456
- },
1457
- async setClientReadOnlyMetadata(metadata) {
1458
- return await this.update({ clientReadOnlyMetadata: metadata });
1459
- },
1460
- async setServerMetadata(metadata) {
1461
- return await this.update({ serverMetadata: metadata });
1462
- },
1463
- async setSelectedTeam(team) {
1464
- return await this.update({ selectedTeamId: team?.id ?? null });
1465
- },
1466
- getConnectedAccount,
1467
- selectedTeam: crud.selected_team ? app._serverTeamFromCrud(crud.selected_team) : null,
1468
- async getTeam(teamId) {
1469
- const teams = await this.listTeams();
1470
- return teams.find((t) => t.id === teamId) ?? null;
1471
- },
1472
- async listTeams() {
1473
- const teams = Result.orThrow(await app._serverTeamsCache.getOrWait([crud.id], "write-only"));
1474
- return teams.map((t) => app._serverTeamFromCrud(t));
1475
- },
1476
- createTeam: async (data) => {
1477
- const team = await app._interface.createServerTeam(serverTeamCreateOptionsToCrud({
1478
- creatorUserId: crud.id,
1479
- ...data
1480
- }));
1481
- await app._serverTeamsCache.refresh([void 0]);
1482
- return app._serverTeamFromCrud(team);
1483
- },
1484
- leaveTeam: async (team) => {
1485
- await app._interface.leaveServerTeam({ teamId: team.id, userId: crud.id });
1486
- },
1487
- async listPermissions(scope, options) {
1488
- const recursive = options?.recursive ?? true;
1489
- const permissions = Result.orThrow(await app._serverTeamUserPermissionsCache.getOrWait([scope.id, crud.id, recursive], "write-only"));
1490
- return permissions.map((crud2) => app._serverPermissionFromCrud(crud2));
1491
- },
1492
- async getPermission(scope, permissionId) {
1493
- const permissions = await this.listPermissions(scope);
1494
- return permissions.find((p) => p.id === permissionId) ?? null;
1495
- },
1496
- async hasPermission(scope, permissionId) {
1497
- return await this.getPermission(scope, permissionId) !== null;
1498
- },
1499
- async update(update) {
1500
- await app._updateServerUser(crud.id, update);
1501
- },
1502
- async sendVerificationEmail() {
1503
- return await app._checkFeatureSupport("sendVerificationEmail() on ServerUser", {});
1504
- },
1505
- async updatePassword(options) {
1506
- const result = await this.update({ password: options.newPassword });
1507
- await app._serverUserCache.refresh([crud.id]);
1508
- return result;
1509
- },
1510
- async setPassword(options) {
1511
- const result = await this.update(options);
1512
- await app._serverUserCache.refresh([crud.id]);
1513
- return result;
1514
- },
1515
- async getTeamProfile(team) {
1516
- const result = Result.orThrow(await app._serverUserTeamProfileCache.getOrWait([team.id, crud.id], "write-only"));
1517
- return app._serverEditableTeamProfileFromCrud(result);
1518
- },
1519
- async listContactChannels() {
1520
- const result = Result.orThrow(await app._serverContactChannelsCache.getOrWait([crud.id], "write-only"));
1521
- return result.map((data) => app._serverContactChannelFromCrud(crud.id, data));
1522
- },
1523
- createContactChannel: async (data) => {
1524
- const contactChannel = await app._interface.createServerContactChannel(serverContactChannelCreateOptionsToCrud(crud.id, data));
1525
- await app._serverContactChannelsCache.refresh([crud.id]);
1526
- return app._serverContactChannelFromCrud(crud.id, contactChannel);
1527
- }
1528
- };
1529
- }
1530
- _serverTeamUserFromCrud(crud) {
1531
- return {
1532
- ...this._serverUserFromCrud(crud.user),
1533
- teamProfile: {
1534
- displayName: crud.display_name,
1535
- profileImageUrl: crud.profile_image_url
1536
- }
1537
- };
1538
- }
1539
- _serverTeamInvitationFromCrud(crud) {
1540
- return {
1541
- id: crud.id,
1542
- recipientEmail: crud.recipient_email,
1543
- expiresAt: new Date(crud.expires_at_millis),
1544
- revoke: async () => {
1545
- await this._interface.revokeServerTeamInvitation(crud.id, crud.team_id);
1546
- }
1547
- };
1548
- }
1549
- _currentUserFromCrud(crud, session) {
1550
- const app = this;
1551
- const currentUser = {
1552
- ...this._serverUserFromCrud(crud),
1553
- ...this._createAuth(session),
1554
- ...this._isInternalProject() ? this._createInternalUserExtra(session) : {}
1555
- };
1556
- Object.freeze(currentUser);
1557
- return currentUser;
1558
- }
1559
- _serverTeamFromCrud(crud) {
1560
- const app = this;
1561
- return {
1562
- id: crud.id,
1563
- displayName: crud.display_name,
1564
- profileImageUrl: crud.profile_image_url,
1565
- createdAt: new Date(crud.created_at_millis),
1566
- clientMetadata: crud.client_metadata,
1567
- clientReadOnlyMetadata: crud.client_read_only_metadata,
1568
- serverMetadata: crud.server_metadata,
1569
- async update(update) {
1570
- await app._interface.updateServerTeam(crud.id, serverTeamUpdateOptionsToCrud(update));
1571
- await app._serverTeamsCache.refresh([void 0]);
1572
- },
1573
- async delete() {
1574
- await app._interface.deleteServerTeam(crud.id);
1575
- await app._serverTeamsCache.refresh([void 0]);
1576
- },
1577
- async listUsers() {
1578
- const result = Result.orThrow(await app._serverTeamMemberProfilesCache.getOrWait([crud.id], "write-only"));
1579
- return result.map((u) => app._serverTeamUserFromCrud(u));
1580
- },
1581
- async addUser(userId) {
1582
- await app._interface.addServerUserToTeam({
1583
- teamId: crud.id,
1584
- userId
1585
- });
1586
- await app._serverTeamMemberProfilesCache.refresh([crud.id]);
1587
- },
1588
- async removeUser(userId) {
1589
- await app._interface.removeServerUserFromTeam({
1590
- teamId: crud.id,
1591
- userId
1592
- });
1593
- await app._serverTeamMemberProfilesCache.refresh([crud.id]);
1594
- },
1595
- async inviteUser(options) {
1596
- if (!options.callbackUrl && !await app._getCurrentUrl()) {
1597
- 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: ... })`");
1598
- }
1599
- await app._interface.sendServerTeamInvitation({
1600
- teamId: crud.id,
1601
- email: options.email,
1602
- callbackUrl: options.callbackUrl ?? constructRedirectUrl(app.urls.teamInvitation)
1603
- });
1604
- await app._serverTeamInvitationsCache.refresh([crud.id]);
1605
- },
1606
- async listInvitations() {
1607
- const result = Result.orThrow(await app._serverTeamInvitationsCache.getOrWait([crud.id], "write-only"));
1608
- return result.map((crud2) => app._serverTeamInvitationFromCrud(crud2));
1609
- }
1610
- };
1611
- }
1612
- async createUser(options) {
1613
- const crud = await this._interface.createServerUser(serverUserCreateOptionsToCrud(options));
1614
- await this._refreshUsers();
1615
- return this._serverUserFromCrud(crud);
1616
- }
1617
- async getUser(options) {
1618
- if (typeof options === "string") {
1619
- return await this.getServerUserById(options);
1620
- } else {
1621
- this._ensurePersistentTokenStore(options?.tokenStore);
1622
- const session = await this._getSession(options?.tokenStore);
1623
- const crud = Result.orThrow(await this._currentServerUserCache.getOrWait([session], "write-only"));
1624
- if (crud === null) {
1625
- switch (options?.or) {
1626
- case "redirect": {
1627
- await this.redirectToSignIn({ replace: true });
1628
- break;
1629
- }
1630
- case "throw": {
1631
- throw new Error("User is not signed in but getUser was called with { or: 'throw' }");
1632
- }
1633
- default: {
1634
- return null;
1635
- }
1636
- }
1637
- }
1638
- return crud && this._currentUserFromCrud(crud, session);
1639
- }
1640
- }
1641
- async getServerUser() {
1642
- console.warn("stackServerApp.getServerUser is deprecated; use stackServerApp.getUser instead");
1643
- return await this.getUser();
1644
- }
1645
- async getServerUserById(userId) {
1646
- const crud = Result.orThrow(await this._serverUserCache.getOrWait([userId], "write-only"));
1647
- return crud && this._serverUserFromCrud(crud);
1648
- }
1649
- async listUsers(options) {
1650
- const crud = Result.orThrow(await this._serverUsersCache.getOrWait([options?.cursor, options?.limit, options?.orderBy, options?.desc, options?.query], "write-only"));
1651
- const result = crud.items.map((j) => this._serverUserFromCrud(j));
1652
- result.nextCursor = crud.pagination?.next_cursor ?? null;
1653
- return result;
1654
- }
1655
- _serverPermissionFromCrud(crud) {
1656
- return {
1657
- id: crud.id
1658
- };
1659
- }
1660
- _serverTeamPermissionDefinitionFromCrud(crud) {
1661
- return {
1662
- id: crud.id,
1663
- description: crud.description,
1664
- containedPermissionIds: crud.contained_permission_ids
1665
- };
1666
- }
1667
- async listTeams() {
1668
- const teams = Result.orThrow(await this._serverTeamsCache.getOrWait([void 0], "write-only"));
1669
- return teams.map((t) => this._serverTeamFromCrud(t));
1670
- }
1671
- async createTeam(data) {
1672
- const team = await this._interface.createServerTeam(serverTeamCreateOptionsToCrud(data));
1673
- await this._serverTeamsCache.refresh([void 0]);
1674
- return this._serverTeamFromCrud(team);
1675
- }
1676
- async getTeam(teamId) {
1677
- const teams = await this.listTeams();
1678
- return teams.find((t) => t.id === teamId) ?? null;
1679
- }
1680
- async _refreshSession(session) {
1681
- await Promise.all([
1682
- super._refreshUser(session),
1683
- this._currentServerUserCache.refresh([session])
1684
- ]);
1685
- }
1686
- async _refreshUsers() {
1687
- await Promise.all([
1688
- super._refreshUsers(),
1689
- this._serverUserCache.refreshWhere(() => true),
1690
- this._serverUsersCache.refreshWhere(() => true),
1691
- this._serverContactChannelsCache.refreshWhere(() => true)
1692
- ]);
1693
- }
1694
- };
1695
- var _StackAdminAppImpl = class extends _StackServerAppImpl {
1696
- constructor(options) {
1697
- super({
1698
- interface: new StackAdminInterface({
1699
- getBaseUrl: () => getBaseUrl(options.baseUrl),
1700
- projectId: options.projectId ?? getDefaultProjectId(),
1701
- clientVersion,
1702
- ..."projectOwnerSession" in options ? {
1703
- projectOwnerSession: options.projectOwnerSession
1704
- } : {
1705
- publishableClientKey: options.publishableClientKey ?? getDefaultPublishableClientKey(),
1706
- secretServerKey: options.secretServerKey ?? getDefaultSecretServerKey(),
1707
- superSecretAdminKey: options.superSecretAdminKey ?? getDefaultSuperSecretAdminKey()
1708
- }
1709
- }),
1710
- baseUrl: options.baseUrl,
1711
- projectId: options.projectId,
1712
- tokenStore: options.tokenStore,
1713
- urls: options.urls,
1714
- oauthScopesOnSignIn: options.oauthScopesOnSignIn,
1715
- redirectMethod: options.redirectMethod
1716
- });
1717
- this._adminProjectCache = createCache(async () => {
1718
- return await this._interface.getProject();
1719
- });
1720
- this._apiKeysCache = createCache(async () => {
1721
- return await this._interface.listApiKeys();
1722
- });
1723
- this._adminEmailTemplatesCache = createCache(async () => {
1724
- return await this._interface.listEmailTemplates();
1725
- });
1726
- this._adminTeamPermissionDefinitionsCache = createCache(async () => {
1727
- return await this._interface.listPermissionDefinitions();
1728
- });
1729
- this._svixTokenCache = createCache(async () => {
1730
- return await this._interface.getSvixToken();
1731
- });
1732
- this._metricsCache = createCache(async () => {
1733
- return await this._interface.getMetrics();
1734
- });
1735
- }
1736
- _adminOwnedProjectFromCrud(data, onRefresh) {
1737
- if (this._tokenStoreInit !== null) {
1738
- throw new StackAssertionError("Owned apps must always have tokenStore === null \u2014 did you not create this project with app._createOwnedApp()?");
1739
- ;
1740
- }
1741
- return {
1742
- ...this._adminProjectFromCrud(data, onRefresh),
1743
- app: this
1744
- };
1745
- }
1746
- _adminProjectFromCrud(data, onRefresh) {
1747
- if (data.id !== this.projectId) {
1748
- throw new StackAssertionError(`The project ID of the provided project JSON (${data.id}) does not match the project ID of the app (${this.projectId})!`);
1749
- }
1750
- const app = this;
1751
- return {
1752
- id: data.id,
1753
- displayName: data.display_name,
1754
- description: data.description,
1755
- createdAt: new Date(data.created_at_millis),
1756
- userCount: data.user_count,
1757
- isProductionMode: data.is_production_mode,
1758
- config: {
1759
- id: data.config.id,
1760
- signUpEnabled: data.config.sign_up_enabled,
1761
- credentialEnabled: data.config.credential_enabled,
1762
- magicLinkEnabled: data.config.magic_link_enabled,
1763
- passkeyEnabled: data.config.passkey_enabled,
1764
- clientTeamCreationEnabled: data.config.client_team_creation_enabled,
1765
- clientUserDeletionEnabled: data.config.client_user_deletion_enabled,
1766
- allowLocalhost: data.config.allow_localhost,
1767
- oauthProviders: data.config.oauth_providers.map((p) => p.type === "shared" ? {
1768
- id: p.id,
1769
- enabled: p.enabled,
1770
- type: "shared"
1771
- } : {
1772
- id: p.id,
1773
- enabled: p.enabled,
1774
- type: "standard",
1775
- clientId: p.client_id ?? throwErr("Client ID is missing"),
1776
- clientSecret: p.client_secret ?? throwErr("Client secret is missing"),
1777
- facebookConfigId: p.facebook_config_id,
1778
- microsoftTenantId: p.microsoft_tenant_id
1779
- }),
1780
- emailConfig: data.config.email_config.type === "shared" ? {
1781
- type: "shared"
1782
- } : {
1783
- type: "standard",
1784
- host: data.config.email_config.host ?? throwErr("Email host is missing"),
1785
- port: data.config.email_config.port ?? throwErr("Email port is missing"),
1786
- username: data.config.email_config.username ?? throwErr("Email username is missing"),
1787
- password: data.config.email_config.password ?? throwErr("Email password is missing"),
1788
- senderName: data.config.email_config.sender_name ?? throwErr("Email sender name is missing"),
1789
- senderEmail: data.config.email_config.sender_email ?? throwErr("Email sender email is missing")
1790
- },
1791
- domains: data.config.domains.map((d) => ({
1792
- domain: d.domain,
1793
- handlerPath: d.handler_path
1794
- })),
1795
- createTeamOnSignUp: data.config.create_team_on_sign_up,
1796
- teamCreatorDefaultPermissions: data.config.team_creator_default_permissions,
1797
- teamMemberDefaultPermissions: data.config.team_member_default_permissions
1798
- },
1799
- async update(update) {
1800
- await app._interface.updateProject(adminProjectUpdateOptionsToCrud(update));
1801
- await onRefresh();
1802
- },
1803
- async delete() {
1804
- await app._interface.deleteProject();
1805
- },
1806
- async getProductionModeErrors() {
1807
- return getProductionModeErrors(data);
1808
- },
1809
- useProductionModeErrors() {
1810
- return getProductionModeErrors(data);
1811
- }
1812
- };
1813
- }
1814
- _adminEmailTemplateFromCrud(data) {
1815
- return {
1816
- type: data.type,
1817
- subject: data.subject,
1818
- content: data.content,
1819
- isDefault: data.is_default
1820
- };
1821
- }
1822
- async getProject() {
1823
- return this._adminProjectFromCrud(
1824
- Result.orThrow(await this._adminProjectCache.getOrWait([], "write-only")),
1825
- () => this._refreshProject()
1826
- );
1827
- }
1828
- _createApiKeyBaseFromCrud(data) {
1829
- const app = this;
1830
- return {
1831
- id: data.id,
1832
- description: data.description,
1833
- expiresAt: new Date(data.expires_at_millis),
1834
- manuallyRevokedAt: data.manually_revoked_at_millis ? new Date(data.manually_revoked_at_millis) : null,
1835
- createdAt: new Date(data.created_at_millis),
1836
- isValid() {
1837
- return this.whyInvalid() === null;
1838
- },
1839
- whyInvalid() {
1840
- if (this.expiresAt.getTime() < Date.now()) return "expired";
1841
- if (this.manuallyRevokedAt) return "manually-revoked";
1842
- return null;
1843
- },
1844
- async revoke() {
1845
- const res = await app._interface.revokeApiKeyById(data.id);
1846
- await app._refreshApiKeys();
1847
- return res;
1848
- }
1849
- };
1850
- }
1851
- _createApiKeyFromCrud(data) {
1852
- return {
1853
- ...this._createApiKeyBaseFromCrud(data),
1854
- publishableClientKey: data.publishable_client_key ? { lastFour: data.publishable_client_key.last_four } : null,
1855
- secretServerKey: data.secret_server_key ? { lastFour: data.secret_server_key.last_four } : null,
1856
- superSecretAdminKey: data.super_secret_admin_key ? { lastFour: data.super_secret_admin_key.last_four } : null
1857
- };
1858
- }
1859
- _createApiKeyFirstViewFromCrud(data) {
1860
- return {
1861
- ...this._createApiKeyBaseFromCrud(data),
1862
- publishableClientKey: data.publishable_client_key,
1863
- secretServerKey: data.secret_server_key,
1864
- superSecretAdminKey: data.super_secret_admin_key
1865
- };
1866
- }
1867
- async listApiKeys() {
1868
- const crud = Result.orThrow(await this._apiKeysCache.getOrWait([], "write-only"));
1869
- return crud.map((j) => this._createApiKeyFromCrud(j));
1870
- }
1871
- async createApiKey(options) {
1872
- const crud = await this._interface.createApiKey(apiKeyCreateOptionsToCrud(options));
1873
- await this._refreshApiKeys();
1874
- return this._createApiKeyFirstViewFromCrud(crud);
1875
- }
1876
- async listEmailTemplates() {
1877
- const crud = Result.orThrow(await this._adminEmailTemplatesCache.getOrWait([], "write-only"));
1878
- return crud.map((j) => this._adminEmailTemplateFromCrud(j));
1879
- }
1880
- async updateEmailTemplate(type, data) {
1881
- await this._interface.updateEmailTemplate(type, adminEmailTemplateUpdateOptionsToCrud(data));
1882
- await this._adminEmailTemplatesCache.refresh([]);
1883
- }
1884
- async resetEmailTemplate(type) {
1885
- await this._interface.resetEmailTemplate(type);
1886
- await this._adminEmailTemplatesCache.refresh([]);
1887
- }
1888
- async createTeamPermissionDefinition(data) {
1889
- const crud = await this._interface.createPermissionDefinition(serverTeamPermissionDefinitionCreateOptionsToCrud(data));
1890
- await this._adminTeamPermissionDefinitionsCache.refresh([]);
1891
- return this._serverTeamPermissionDefinitionFromCrud(crud);
1892
- }
1893
- async updateTeamPermissionDefinition(permissionId, data) {
1894
- await this._interface.updatePermissionDefinition(permissionId, serverTeamPermissionDefinitionUpdateOptionsToCrud(data));
1895
- await this._adminTeamPermissionDefinitionsCache.refresh([]);
1896
- }
1897
- async deleteTeamPermissionDefinition(permissionId) {
1898
- await this._interface.deletePermissionDefinition(permissionId);
1899
- await this._adminTeamPermissionDefinitionsCache.refresh([]);
1900
- }
1901
- async listTeamPermissionDefinitions() {
1902
- const crud = Result.orThrow(await this._adminTeamPermissionDefinitionsCache.getOrWait([], "write-only"));
1903
- return crud.map((p) => this._serverTeamPermissionDefinitionFromCrud(p));
1904
- }
1905
- async _refreshProject() {
1906
- await Promise.all([
1907
- super._refreshProject(),
1908
- this._adminProjectCache.refresh([])
1909
- ]);
1910
- }
1911
- async _refreshApiKeys() {
1912
- await this._apiKeysCache.refresh([]);
1913
- }
1914
- get [stackAppInternalsSymbol]() {
1915
- return {
1916
- ...super[stackAppInternalsSymbol]
1917
- };
1918
- }
1919
- async sendTestEmail(options) {
1920
- const response = await this._interface.sendTestEmail({
1921
- recipient_email: options.recipientEmail,
1922
- email_config: {
1923
- ...pick(options.emailConfig, ["host", "port", "username", "password"]),
1924
- sender_email: options.emailConfig.senderEmail,
1925
- sender_name: options.emailConfig.senderName
1926
- }
1927
- });
1928
- if (response.success) {
1929
- return Result.ok(void 0);
1930
- } else {
1931
- return Result.error({ errorMessage: response.error_message ?? throwErr("Email test error not specified") });
1932
- }
1933
- }
1934
- };
1935
- function contactChannelCreateOptionsToCrud(userId, options) {
1936
- return {
1937
- value: options.value,
1938
- type: options.type,
1939
- used_for_auth: options.usedForAuth,
1940
- user_id: userId
1941
- };
1942
- }
1943
- function contactChannelUpdateOptionsToCrud(options) {
1944
- return {
1945
- value: options.value,
1946
- used_for_auth: options.usedForAuth,
1947
- is_primary: options.isPrimary
1948
- };
1949
- }
1950
- function serverContactChannelUpdateOptionsToCrud(options) {
1951
- return {
1952
- value: options.value,
1953
- is_verified: options.isVerified,
1954
- used_for_auth: options.usedForAuth
1955
- };
1956
- }
1957
- function serverContactChannelCreateOptionsToCrud(userId, options) {
1958
- return {
1959
- type: options.type,
1960
- value: options.value,
1961
- is_verified: options.isVerified,
1962
- user_id: userId,
1963
- used_for_auth: options.usedForAuth
1964
- };
1965
- }
1966
- function userUpdateOptionsToCrud(options) {
1967
- return {
1968
- display_name: options.displayName,
1969
- client_metadata: options.clientMetadata,
1970
- selected_team_id: options.selectedTeamId,
1971
- totp_secret_base64: options.totpMultiFactorSecret != null ? encodeBase64(options.totpMultiFactorSecret) : options.totpMultiFactorSecret,
1972
- profile_image_url: options.profileImageUrl,
1973
- otp_auth_enabled: options.otpAuthEnabled,
1974
- passkey_auth_enabled: options.passkeyAuthEnabled
1975
- };
1976
- }
1977
- function serverUserUpdateOptionsToCrud(options) {
1978
- return {
1979
- display_name: options.displayName,
1980
- primary_email: options.primaryEmail,
1981
- client_metadata: options.clientMetadata,
1982
- client_read_only_metadata: options.clientReadOnlyMetadata,
1983
- server_metadata: options.serverMetadata,
1984
- selected_team_id: options.selectedTeamId,
1985
- primary_email_auth_enabled: options.primaryEmailAuthEnabled,
1986
- primary_email_verified: options.primaryEmailVerified,
1987
- password: options.password,
1988
- profile_image_url: options.profileImageUrl,
1989
- totp_secret_base64: options.totpMultiFactorSecret != null ? encodeBase64(options.totpMultiFactorSecret) : options.totpMultiFactorSecret
1990
- };
1991
- }
1992
- function serverUserCreateOptionsToCrud(options) {
1993
- return {
1994
- primary_email: options.primaryEmail,
1995
- password: options.password,
1996
- otp_auth_enabled: options.otpAuthEnabled,
1997
- primary_email_auth_enabled: options.primaryEmailAuthEnabled,
1998
- display_name: options.displayName,
1999
- primary_email_verified: options.primaryEmailVerified,
2000
- client_metadata: options.clientMetadata,
2001
- client_read_only_metadata: options.clientReadOnlyMetadata,
2002
- server_metadata: options.serverMetadata
2003
- };
2004
- }
2005
- function adminProjectUpdateOptionsToCrud(options) {
2006
- return {
2007
- display_name: options.displayName,
2008
- description: options.description,
2009
- is_production_mode: options.isProductionMode,
2010
- config: {
2011
- domains: options.config?.domains?.map((d) => ({
2012
- domain: d.domain,
2013
- handler_path: d.handlerPath
2014
- })),
2015
- oauth_providers: options.config?.oauthProviders?.map((p) => ({
2016
- id: p.id,
2017
- enabled: p.enabled,
2018
- type: p.type,
2019
- ...p.type === "standard" && {
2020
- client_id: p.clientId,
2021
- client_secret: p.clientSecret,
2022
- facebook_config_id: p.facebookConfigId,
2023
- microsoft_tenant_id: p.microsoftTenantId
2024
- }
2025
- })),
2026
- email_config: options.config?.emailConfig && (options.config.emailConfig.type === "shared" ? {
2027
- type: "shared"
2028
- } : {
2029
- type: "standard",
2030
- host: options.config.emailConfig.host,
2031
- port: options.config.emailConfig.port,
2032
- username: options.config.emailConfig.username,
2033
- password: options.config.emailConfig.password,
2034
- sender_name: options.config.emailConfig.senderName,
2035
- sender_email: options.config.emailConfig.senderEmail
2036
- }),
2037
- sign_up_enabled: options.config?.signUpEnabled,
2038
- credential_enabled: options.config?.credentialEnabled,
2039
- magic_link_enabled: options.config?.magicLinkEnabled,
2040
- passkey_enabled: options.config?.passkeyEnabled,
2041
- allow_localhost: options.config?.allowLocalhost,
2042
- create_team_on_sign_up: options.config?.createTeamOnSignUp,
2043
- client_team_creation_enabled: options.config?.clientTeamCreationEnabled,
2044
- client_user_deletion_enabled: options.config?.clientUserDeletionEnabled,
2045
- team_creator_default_permissions: options.config?.teamCreatorDefaultPermissions,
2046
- team_member_default_permissions: options.config?.teamMemberDefaultPermissions
2047
- }
2048
- };
2049
- }
2050
- function adminProjectCreateOptionsToCrud(options) {
2051
- return {
2052
- ...adminProjectUpdateOptionsToCrud(options),
2053
- display_name: options.displayName
2054
- };
2055
- }
2056
- function apiKeyCreateOptionsToCrud(options) {
2057
- return {
2058
- description: options.description,
2059
- expires_at_millis: options.expiresAt.getTime(),
2060
- has_publishable_client_key: options.hasPublishableClientKey,
2061
- has_secret_server_key: options.hasSecretServerKey,
2062
- has_super_secret_admin_key: options.hasSuperSecretAdminKey
2063
- };
2064
- }
2065
- function teamUpdateOptionsToCrud(options) {
2066
- return {
2067
- display_name: options.displayName,
2068
- profile_image_url: options.profileImageUrl,
2069
- client_metadata: options.clientMetadata
2070
- };
2071
- }
2072
- function teamCreateOptionsToCrud(options, creatorUserId) {
2073
- return {
2074
- display_name: options.displayName,
2075
- profile_image_url: options.profileImageUrl,
2076
- creator_user_id: creatorUserId
2077
- };
2078
- }
2079
- function serverTeamCreateOptionsToCrud(options) {
2080
- return {
2081
- display_name: options.displayName,
2082
- profile_image_url: options.profileImageUrl,
2083
- creator_user_id: options.creatorUserId
2084
- };
2085
- }
2086
- function serverTeamUpdateOptionsToCrud(options) {
2087
- return {
2088
- display_name: options.displayName,
2089
- profile_image_url: options.profileImageUrl,
2090
- client_metadata: options.clientMetadata,
2091
- client_read_only_metadata: options.clientReadOnlyMetadata,
2092
- server_metadata: options.serverMetadata
2093
- };
2094
- }
2095
- function serverTeamPermissionDefinitionCreateOptionsToCrud(options) {
2096
- return {
2097
- id: options.id,
2098
- description: options.description,
2099
- contained_permission_ids: options.containedPermissionIds
2100
- };
2101
- }
2102
- function serverTeamPermissionDefinitionUpdateOptionsToCrud(options) {
2103
- return {
2104
- id: options.id,
2105
- description: options.description,
2106
- contained_permission_ids: options.containedPermissionIds
2107
- };
2108
- }
2109
- var StackClientApp = _StackClientAppImpl;
2110
- var StackServerApp = _StackServerAppImpl;
2111
- var StackAdminApp = _StackAdminAppImpl;
2112
- function adminEmailTemplateUpdateOptionsToCrud(options) {
2113
- return {
2114
- subject: options.subject,
2115
- content: options.content
2116
- };
2117
- }
1198
+ /**
1199
+ * There is a circular dependency between the admin app and the client app, as the former inherits from the latter and
1200
+ * the latter needs to use the former when creating a new instance of an internal project.
1201
+ *
1202
+ * To break it, we set the admin app here lazily instead of importing it directly. This variable is set by ./index.ts,
1203
+ * which imports both this file and ./admin-app-impl.ts.
1204
+ */
1205
+ __StackClientAppImplIncomplete.LazyStackAdminAppImpl = { value: void 0 };
1206
+ var _StackClientAppImplIncomplete = __StackClientAppImplIncomplete;
2118
1207
  export {
2119
- StackAdminApp,
2120
- StackClientApp,
2121
- StackServerApp,
2122
- serverTeamPermissionDefinitionCreateOptionsToCrud,
2123
- serverTeamPermissionDefinitionUpdateOptionsToCrud,
2124
- stackAppInternalsSymbol
1208
+ _StackClientAppImplIncomplete
2125
1209
  };
2126
- //# sourceMappingURL=stack-app.js.map
1210
+ //# sourceMappingURL=client-app-impl.js.map