@stackframe/js 2.7.16 → 2.7.17

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.
@@ -1,13 +1,12 @@
1
1
  // src/lib/stack-app.ts
2
2
  import { WebAuthnError, startAuthentication, startRegistration } from "@simplewebauthn/browser";
3
- import { isReactServer } from "@stackframe/stack-sc";
4
3
  import { KnownErrors, StackAdminInterface, StackClientInterface, StackServerInterface } from "@stackframe/stack-shared";
5
4
  import { getProductionModeErrors } from "@stackframe/stack-shared/dist/helpers/production-mode";
6
5
  import { InternalSession } from "@stackframe/stack-shared/dist/sessions";
7
6
  import { encodeBase64 } from "@stackframe/stack-shared/dist/utils/bytes";
8
7
  import { AsyncCache } from "@stackframe/stack-shared/dist/utils/caches";
9
8
  import { scrambleDuringCompileTime } from "@stackframe/stack-shared/dist/utils/compile-time";
10
- import { getPublicEnvVar, isBrowserLike } from "@stackframe/stack-shared/dist/utils/env";
9
+ import { isBrowserLike } from "@stackframe/stack-shared/dist/utils/env";
11
10
  import { StackAssertionError, throwErr } from "@stackframe/stack-shared/dist/utils/errors";
12
11
  import { DependenciesMap } from "@stackframe/stack-shared/dist/utils/maps";
13
12
  import { deepPlainEquals, filterUndefined, omit, pick } from "@stackframe/stack-shared/dist/utils/objects";
@@ -22,8 +21,13 @@ import * as NextNavigationUnscrambled from "next/navigation";
22
21
  import { constructRedirectUrl } from "../utils/url";
23
22
  import { addNewOAuthProviderOrScope, callOAuthCallback, signInWithOAuth } from "./auth";
24
23
  import { createCookieHelper, createEmptyCookieHelper, deleteCookieClient, getCookieClient, setOrDeleteCookie, setOrDeleteCookieClient } from "./cookie";
24
+ var isReactServer = false;
25
25
  var NextNavigation = scrambleDuringCompileTime(NextNavigationUnscrambled);
26
- var clientVersion = "js @stackframe/js@2.7.16";
26
+ var clientVersion = "js @stackframe/js@2.7.17";
27
+ if (clientVersion.startsWith("STACK_COMPILE_TIME")) {
28
+ throw new StackAssertionError("Client version was not replaced. Something went wrong during build!");
29
+ }
30
+ var process = globalThis.process ?? { env: {} };
27
31
  function getUrls(partial) {
28
32
  const handler = partial.handler ?? "/handler";
29
33
  const home = partial.home ?? "/";
@@ -49,10 +53,10 @@ function getUrls(partial) {
49
53
  };
50
54
  }
51
55
  function getDefaultProjectId() {
52
- return getPublicEnvVar("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."));
56
+ 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."));
53
57
  }
54
58
  function getDefaultPublishableClientKey() {
55
- return getPublicEnvVar("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."));
59
+ 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."));
56
60
  }
57
61
  function getDefaultSecretServerKey() {
58
62
  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,8 +64,26 @@ function getDefaultSecretServerKey() {
60
64
  function getDefaultSuperSecretAdminKey() {
61
65
  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."));
62
66
  }
63
- function getDefaultBaseUrl() {
64
- const url = getPublicEnvVar("NEXT_PUBLIC_STACK_API_URL") || getPublicEnvVar("NEXT_PUBLIC_STACK_URL") || defaultBaseUrl;
67
+ function getBaseUrl(userSpecifiedBaseUrl) {
68
+ let url;
69
+ if (userSpecifiedBaseUrl) {
70
+ if (typeof userSpecifiedBaseUrl === "string") {
71
+ url = userSpecifiedBaseUrl;
72
+ } else {
73
+ if (isBrowserLike()) {
74
+ url = userSpecifiedBaseUrl.browser;
75
+ } else {
76
+ url = userSpecifiedBaseUrl.server;
77
+ }
78
+ }
79
+ } else {
80
+ if (isBrowserLike()) {
81
+ url = process.env.NEXT_PUBLIC_BROWSER_STACK_API_URL;
82
+ } else {
83
+ url = process.env.NEXT_PUBLIC_SERVER_STACK_API_URL;
84
+ }
85
+ url = url || process.env.NEXT_PUBLIC_STACK_API_URL || process.env.NEXT_PUBLIC_STACK_URL || defaultBaseUrl;
86
+ }
65
87
  return url.endsWith("/") ? url.slice(0, -1) : url;
66
88
  }
67
89
  var defaultBaseUrl = "https://api.stack-auth.com";
@@ -179,7 +201,7 @@ var _StackClientAppImpl = class __StackClientAppImpl {
179
201
  this._interface = _options.interface;
180
202
  } else {
181
203
  this._interface = new StackClientInterface({
182
- getBaseUrl: () => _options.baseUrl ?? getDefaultBaseUrl(),
204
+ getBaseUrl: () => getBaseUrl(_options.baseUrl),
183
205
  projectId: _options.projectId ?? getDefaultProjectId(),
184
206
  clientVersion,
185
207
  publishableClientKey: _options.publishableClientKey ?? getDefaultPublishableClientKey()
@@ -1260,12 +1282,15 @@ var _StackServerAppImpl = class extends _StackClientAppImpl {
1260
1282
  oauthScopesOnSignIn: options.oauthScopesOnSignIn
1261
1283
  } : {
1262
1284
  interface: new StackServerInterface({
1263
- getBaseUrl: () => options.baseUrl ?? getDefaultBaseUrl(),
1285
+ getBaseUrl: () => getBaseUrl(options.baseUrl),
1264
1286
  projectId: options.projectId ?? getDefaultProjectId(),
1265
1287
  clientVersion,
1266
1288
  publishableClientKey: options.publishableClientKey ?? getDefaultPublishableClientKey(),
1267
1289
  secretServerKey: options.secretServerKey ?? getDefaultSecretServerKey()
1268
1290
  }),
1291
+ baseUrl: options.baseUrl,
1292
+ projectId: options.projectId,
1293
+ publishableClientKey: options.publishableClientKey,
1269
1294
  tokenStore: options.tokenStore,
1270
1295
  urls: options.urls ?? {},
1271
1296
  oauthScopesOnSignIn: options.oauthScopesOnSignIn ?? {}
@@ -1668,7 +1693,7 @@ var _StackAdminAppImpl = class extends _StackServerAppImpl {
1668
1693
  constructor(options) {
1669
1694
  super({
1670
1695
  interface: new StackAdminInterface({
1671
- getBaseUrl: () => options.baseUrl ?? getDefaultBaseUrl(),
1696
+ getBaseUrl: () => getBaseUrl(options.baseUrl),
1672
1697
  projectId: options.projectId ?? getDefaultProjectId(),
1673
1698
  clientVersion,
1674
1699
  ..."projectOwnerSession" in options ? {
@@ -1679,6 +1704,8 @@ var _StackAdminAppImpl = class extends _StackServerAppImpl {
1679
1704
  superSecretAdminKey: options.superSecretAdminKey ?? getDefaultSuperSecretAdminKey()
1680
1705
  }
1681
1706
  }),
1707
+ baseUrl: options.baseUrl,
1708
+ projectId: options.projectId,
1682
1709
  tokenStore: options.tokenStore,
1683
1710
  urls: options.urls,
1684
1711
  oauthScopesOnSignIn: options.oauthScopesOnSignIn