@hexclave/js 1.0.0 → 1.0.1
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.
- package/README.md +7 -23
- package/dist/dev-tool/dev-tool-core.d.ts.map +1 -1
- package/dist/dev-tool/dev-tool-core.js +23 -23
- package/dist/dev-tool/dev-tool-core.js.map +1 -1
- package/dist/dev-tool/index.js +6 -6
- package/dist/dev-tool/index.js.map +1 -1
- package/dist/esm/dev-tool/dev-tool-core.d.ts.map +1 -1
- package/dist/esm/dev-tool/dev-tool-core.js +2 -2
- package/dist/esm/dev-tool/dev-tool-core.js.map +1 -1
- package/dist/esm/dev-tool/index.js.map +1 -1
- package/dist/esm/index.d.ts +1 -1
- package/dist/esm/index.js +1 -2
- package/dist/esm/integrations/convex.js.map +1 -1
- package/dist/esm/lib/auth.js.map +1 -1
- package/dist/esm/lib/auth.test.js.map +1 -1
- package/dist/esm/lib/cookie.js.map +1 -1
- package/dist/esm/lib/stack-app/api-keys/index.js.map +1 -1
- package/dist/esm/lib/stack-app/apps/implementations/admin-app-impl.d.ts +11 -11
- package/dist/esm/lib/stack-app/apps/implementations/admin-app-impl.d.ts.map +1 -1
- package/dist/esm/lib/stack-app/apps/implementations/admin-app-impl.js +3 -1
- package/dist/esm/lib/stack-app/apps/implementations/admin-app-impl.js.map +1 -1
- package/dist/esm/lib/stack-app/apps/implementations/client-app-impl.d.ts +3 -3
- package/dist/esm/lib/stack-app/apps/implementations/client-app-impl.d.ts.map +1 -1
- package/dist/esm/lib/stack-app/apps/implementations/client-app-impl.js.map +1 -1
- package/dist/esm/lib/stack-app/apps/implementations/common.d.ts.map +1 -1
- package/dist/esm/lib/stack-app/apps/implementations/common.js +1 -1
- package/dist/esm/lib/stack-app/apps/implementations/common.js.map +1 -1
- package/dist/esm/lib/stack-app/apps/implementations/event-tracker.js.map +1 -1
- package/dist/esm/lib/stack-app/apps/implementations/event-tracker.test.js.map +1 -1
- package/dist/esm/lib/stack-app/apps/implementations/index.js.map +1 -1
- package/dist/esm/lib/stack-app/apps/implementations/redirect-page-urls.js.map +1 -1
- package/dist/esm/lib/stack-app/apps/implementations/server-app-impl.js.map +1 -1
- package/dist/esm/lib/stack-app/apps/implementations/session-replay.d.ts.map +1 -1
- package/dist/esm/lib/stack-app/apps/implementations/session-replay.js +3 -2
- package/dist/esm/lib/stack-app/apps/implementations/session-replay.js.map +1 -1
- package/dist/esm/lib/stack-app/apps/interfaces/admin-app.d.ts +4 -0
- package/dist/esm/lib/stack-app/apps/interfaces/admin-app.d.ts.map +1 -1
- package/dist/esm/lib/stack-app/apps/interfaces/admin-app.js +1 -0
- package/dist/esm/lib/stack-app/apps/interfaces/admin-app.js.map +1 -1
- package/dist/esm/lib/stack-app/apps/interfaces/client-app.d.ts +5 -0
- package/dist/esm/lib/stack-app/apps/interfaces/client-app.d.ts.map +1 -1
- package/dist/esm/lib/stack-app/apps/interfaces/client-app.js +1 -0
- package/dist/esm/lib/stack-app/apps/interfaces/client-app.js.map +1 -1
- package/dist/esm/lib/stack-app/apps/interfaces/server-app.d.ts +4 -0
- package/dist/esm/lib/stack-app/apps/interfaces/server-app.d.ts.map +1 -1
- package/dist/esm/lib/stack-app/apps/interfaces/server-app.js +1 -0
- package/dist/esm/lib/stack-app/apps/interfaces/server-app.js.map +1 -1
- package/dist/esm/lib/stack-app/common.js.map +1 -1
- package/dist/esm/lib/stack-app/contact-channels/index.js.map +1 -1
- package/dist/esm/lib/stack-app/email-templates/index.js.map +1 -1
- package/dist/esm/lib/stack-app/internal-api-keys/index.js.map +1 -1
- package/dist/esm/lib/stack-app/permissions/index.js.map +1 -1
- package/dist/esm/lib/stack-app/projects/index.js.map +1 -1
- package/dist/esm/lib/stack-app/teams/index.js.map +1 -1
- package/dist/esm/lib/stack-app/url-targets.js.map +1 -1
- package/dist/esm/lib/stack-app/url-targets.test.js +1 -1
- package/dist/esm/lib/stack-app/url-targets.test.js.map +1 -1
- package/dist/esm/lib/stack-app/users/index.js.map +1 -1
- package/dist/esm/utils/url.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +3 -4
- package/dist/integrations/convex.js +5 -5
- package/dist/integrations/convex.js.map +1 -1
- package/dist/lib/auth.js +12 -12
- package/dist/lib/auth.js.map +1 -1
- package/dist/lib/auth.test.js +2 -2
- package/dist/lib/auth.test.js.map +1 -1
- package/dist/lib/cookie.js +9 -9
- package/dist/lib/cookie.js.map +1 -1
- package/dist/lib/stack-app/api-keys/index.js +2 -2
- package/dist/lib/stack-app/api-keys/index.js.map +1 -1
- package/dist/lib/stack-app/apps/implementations/admin-app-impl.d.ts +11 -11
- package/dist/lib/stack-app/apps/implementations/admin-app-impl.d.ts.map +1 -1
- package/dist/lib/stack-app/apps/implementations/admin-app-impl.js +38 -36
- package/dist/lib/stack-app/apps/implementations/admin-app-impl.js.map +1 -1
- package/dist/lib/stack-app/apps/implementations/client-app-impl.d.ts +3 -3
- package/dist/lib/stack-app/apps/implementations/client-app-impl.d.ts.map +1 -1
- package/dist/lib/stack-app/apps/implementations/client-app-impl.js +192 -192
- package/dist/lib/stack-app/apps/implementations/client-app-impl.js.map +1 -1
- package/dist/lib/stack-app/apps/implementations/common.d.ts.map +1 -1
- package/dist/lib/stack-app/apps/implementations/common.js +25 -25
- package/dist/lib/stack-app/apps/implementations/common.js.map +1 -1
- package/dist/lib/stack-app/apps/implementations/event-tracker.js +7 -7
- package/dist/lib/stack-app/apps/implementations/event-tracker.js.map +1 -1
- package/dist/lib/stack-app/apps/implementations/event-tracker.test.js +3 -3
- package/dist/lib/stack-app/apps/implementations/event-tracker.test.js.map +1 -1
- package/dist/lib/stack-app/apps/implementations/index.js +4 -4
- package/dist/lib/stack-app/apps/implementations/index.js.map +1 -1
- package/dist/lib/stack-app/apps/implementations/redirect-page-urls.js +8 -8
- package/dist/lib/stack-app/apps/implementations/redirect-page-urls.js.map +1 -1
- package/dist/lib/stack-app/apps/implementations/server-app-impl.js +59 -59
- package/dist/lib/stack-app/apps/implementations/server-app-impl.js.map +1 -1
- package/dist/lib/stack-app/apps/implementations/session-replay.d.ts.map +1 -1
- package/dist/lib/stack-app/apps/implementations/session-replay.js +13 -12
- package/dist/lib/stack-app/apps/implementations/session-replay.js.map +1 -1
- package/dist/lib/stack-app/apps/interfaces/admin-app.d.ts +4 -0
- package/dist/lib/stack-app/apps/interfaces/admin-app.d.ts.map +1 -1
- package/dist/lib/stack-app/apps/interfaces/admin-app.js +1 -0
- package/dist/lib/stack-app/apps/interfaces/admin-app.js.map +1 -1
- package/dist/lib/stack-app/apps/interfaces/client-app.d.ts +5 -0
- package/dist/lib/stack-app/apps/interfaces/client-app.d.ts.map +1 -1
- package/dist/lib/stack-app/apps/interfaces/client-app.js +1 -0
- package/dist/lib/stack-app/apps/interfaces/client-app.js.map +1 -1
- package/dist/lib/stack-app/apps/interfaces/server-app.d.ts +4 -0
- package/dist/lib/stack-app/apps/interfaces/server-app.d.ts.map +1 -1
- package/dist/lib/stack-app/apps/interfaces/server-app.js +1 -0
- package/dist/lib/stack-app/apps/interfaces/server-app.js.map +1 -1
- package/dist/lib/stack-app/common.js.map +1 -1
- package/dist/lib/stack-app/contact-channels/index.js.map +1 -1
- package/dist/lib/stack-app/email-templates/index.js.map +1 -1
- package/dist/lib/stack-app/internal-api-keys/index.js.map +1 -1
- package/dist/lib/stack-app/permissions/index.js.map +1 -1
- package/dist/lib/stack-app/projects/index.js.map +1 -1
- package/dist/lib/stack-app/teams/index.js.map +1 -1
- package/dist/lib/stack-app/url-targets.js +6 -6
- package/dist/lib/stack-app/url-targets.js.map +1 -1
- package/dist/lib/stack-app/url-targets.test.js +1 -1
- package/dist/lib/stack-app/url-targets.test.js.map +1 -1
- package/dist/lib/stack-app/users/index.js +3 -3
- package/dist/lib/stack-app/users/index.js.map +1 -1
- package/dist/utils/url.js +2 -2
- package/dist/utils/url.js.map +1 -1
- package/package.json +3 -3
- package/dist/esm/internal/deprecation-warning.d.ts +0 -1
- package/dist/esm/internal/deprecation-warning.js +0 -24
- package/dist/esm/internal/deprecation-warning.js.map +0 -1
- package/dist/internal/deprecation-warning.d.ts +0 -1
- package/dist/internal/deprecation-warning.js +0 -24
- package/dist/internal/deprecation-warning.js.map +0 -1
|
@@ -1,25 +1,25 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
2
|
const require_chunk = require('../../../../chunk-BE-pF4vm.js');
|
|
3
|
-
let
|
|
4
|
-
let
|
|
5
|
-
let
|
|
6
|
-
let
|
|
7
|
-
let
|
|
8
|
-
let
|
|
9
|
-
let
|
|
3
|
+
let _hexclave_shared_dist_utils_promises = require("@hexclave/shared/dist/utils/promises");
|
|
4
|
+
let _hexclave_shared_dist_utils_urls = require("@hexclave/shared/dist/utils/urls");
|
|
5
|
+
let _hexclave_shared_dist_utils_errors = require("@hexclave/shared/dist/utils/errors");
|
|
6
|
+
let _hexclave_shared = require("@hexclave/shared");
|
|
7
|
+
let _hexclave_shared_dist_utils_results = require("@hexclave/shared/dist/utils/results");
|
|
8
|
+
let _hexclave_shared_dist_utils_strings = require("@hexclave/shared/dist/utils/strings");
|
|
9
|
+
let _hexclave_shared_dist_utils_env = require("@hexclave/shared/dist/utils/env");
|
|
10
10
|
let __common_js = require("./common.js");
|
|
11
|
-
let
|
|
12
|
-
let
|
|
13
|
-
let
|
|
11
|
+
let _hexclave_shared_dist_utils_redirect_urls = require("@hexclave/shared/dist/utils/redirect-urls");
|
|
12
|
+
let _hexclave_shared_dist_utils_objects = require("@hexclave/shared/dist/utils/objects");
|
|
13
|
+
let _hexclave_shared_dist_utils_bytes = require("@hexclave/shared/dist/utils/bytes");
|
|
14
14
|
let ______common_js = require("../../common.js");
|
|
15
15
|
let ______projects_index_js = require("../../projects/index.js");
|
|
16
16
|
let _simplewebauthn_browser = require("@simplewebauthn/browser");
|
|
17
|
-
let
|
|
18
|
-
let
|
|
19
|
-
let
|
|
20
|
-
let
|
|
21
|
-
let
|
|
22
|
-
let
|
|
17
|
+
let _hexclave_shared_dist_sessions = require("@hexclave/shared/dist/sessions");
|
|
18
|
+
let _hexclave_shared_dist_utils_json = require("@hexclave/shared/dist/utils/json");
|
|
19
|
+
let _hexclave_shared_dist_utils_maps = require("@hexclave/shared/dist/utils/maps");
|
|
20
|
+
let _hexclave_shared_dist_utils_stores = require("@hexclave/shared/dist/utils/stores");
|
|
21
|
+
let _hexclave_shared_dist_utils_turnstile_flow = require("@hexclave/shared/dist/utils/turnstile-flow");
|
|
22
|
+
let _hexclave_shared_dist_utils_uuids = require("@hexclave/shared/dist/utils/uuids");
|
|
23
23
|
let cookie = require("cookie");
|
|
24
24
|
cookie = require_chunk.__toESM(cookie);
|
|
25
25
|
let ____________utils_url_js = require("../../../../utils/url.js");
|
|
@@ -61,7 +61,7 @@ const STACK_AUTHORIZATION_VALUE_PREFIX = "stackauth_";
|
|
|
61
61
|
const HEXCLAVE_AUTHORIZATION_VALUE_PREFIX = "hexclave_";
|
|
62
62
|
function getAuthorizationHeaderValueFromAuthJson(authJson) {
|
|
63
63
|
if (authJson.accessToken == null && authJson.refreshToken == null) return null;
|
|
64
|
-
return `Bearer ${STACK_AUTHORIZATION_VALUE_PREFIX}${(0,
|
|
64
|
+
return `Bearer ${STACK_AUTHORIZATION_VALUE_PREFIX}${(0, _hexclave_shared_dist_utils_bytes.encodeBase64)(new TextEncoder().encode(JSON.stringify(authJson)))}`;
|
|
65
65
|
}
|
|
66
66
|
function getAuthJsonFromAuthorizationHeaderValue(authorizationHeaderValue) {
|
|
67
67
|
const match = authorizationHeaderValue.match(/^Bearer\s+(.+)$/i);
|
|
@@ -73,7 +73,7 @@ function getAuthJsonFromAuthorizationHeaderValue(authorizationHeaderValue) {
|
|
|
73
73
|
if (encodedAuthJson.length === 0) throw new Error("Invalid Authorization header format. Expected `Bearer stackauth_<base64(getAuthJson())>`.");
|
|
74
74
|
let parsed;
|
|
75
75
|
try {
|
|
76
|
-
const decodedAuthJson = new TextDecoder().decode((0,
|
|
76
|
+
const decodedAuthJson = new TextDecoder().decode((0, _hexclave_shared_dist_utils_bytes.decodeBase64)(encodedAuthJson));
|
|
77
77
|
parsed = JSON.parse(decodedAuthJson);
|
|
78
78
|
} catch (e) {
|
|
79
79
|
throw new Error("Invalid stackauth authorization header.", { cause: e });
|
|
@@ -113,7 +113,7 @@ var _StackClientAppImplIncomplete = class _StackClientAppImplIncomplete {
|
|
|
113
113
|
if (!user || !user.oauth_providers.find((p) => p.id === options.providerId)) hasConnection = false;
|
|
114
114
|
if (!await options.getOrWaitOAuthToken()) hasConnection = false;
|
|
115
115
|
if (!hasConnection && options.redirect) {
|
|
116
|
-
if (!options.session) throw new Error(
|
|
116
|
+
if (!options.session) throw new Error(_hexclave_shared_dist_utils_strings.deindent`
|
|
117
117
|
Cannot add new scopes to a user that is not a CurrentUser. Please ensure that you are calling this function on a CurrentUser object, or remove the 'or: redirect' option.
|
|
118
118
|
|
|
119
119
|
Often, you can solve this by calling this function in the browser instead, or by removing the 'or: redirect' option and dealing with the case where the user doesn't have enough permissions.
|
|
@@ -122,10 +122,10 @@ var _StackClientAppImplIncomplete = class _StackClientAppImplIncomplete {
|
|
|
122
122
|
provider: options.providerId,
|
|
123
123
|
redirectUrl: this._getOAuthCallbackRedirectUri(),
|
|
124
124
|
errorRedirectUrl: this.urls.error,
|
|
125
|
-
providerScope: (0,
|
|
125
|
+
providerScope: (0, _hexclave_shared_dist_utils_strings.mergeScopeStrings)(options.scope || "", (this._oauthScopesOnSignIn[options.providerId] ?? []).join(" "))
|
|
126
126
|
}, options.session);
|
|
127
127
|
await this._redirectTo({ url: location });
|
|
128
|
-
return await (0,
|
|
128
|
+
return await (0, _hexclave_shared_dist_utils_promises.neverResolve)();
|
|
129
129
|
} else if (!hasConnection) return null;
|
|
130
130
|
const providerAccountId = user.oauth_providers.find((p) => p.id === options.providerId)?.account_id ?? "";
|
|
131
131
|
return {
|
|
@@ -134,7 +134,7 @@ var _StackClientAppImplIncomplete = class _StackClientAppImplIncomplete {
|
|
|
134
134
|
providerAccountId,
|
|
135
135
|
async getAccessToken() {
|
|
136
136
|
const result = await options.getOrWaitOAuthToken();
|
|
137
|
-
if (!result) throw new
|
|
137
|
+
if (!result) throw new _hexclave_shared_dist_utils_errors.HexclaveAssertionError(`Failed to retrieve an access token for this connected account (provider: ${options.providerId}). This usually means the OAuth refresh token has been revoked or expired. The user needs to re-authorize by calling \`linkConnectedAccount\` or using \`getOrLinkConnectedAccount\`.`);
|
|
138
138
|
return result;
|
|
139
139
|
}
|
|
140
140
|
};
|
|
@@ -149,7 +149,7 @@ var _StackClientAppImplIncomplete = class _StackClientAppImplIncomplete {
|
|
|
149
149
|
providerAccountId,
|
|
150
150
|
async getAccessToken(options) {
|
|
151
151
|
const scopeString = options?.scopes?.join(" ") ?? "";
|
|
152
|
-
const result =
|
|
152
|
+
const result = _hexclave_shared_dist_utils_results.Result.orThrow(await app._currentUserOAuthConnectionAccessTokensByAccountCache.getOrWait([
|
|
153
153
|
session,
|
|
154
154
|
providerId,
|
|
155
155
|
providerAccountId,
|
|
@@ -157,9 +157,9 @@ var _StackClientAppImplIncomplete = class _StackClientAppImplIncomplete {
|
|
|
157
157
|
], "write-only"));
|
|
158
158
|
if (!result) {
|
|
159
159
|
const scopeDetail = scopeString ? `The requested scopes [${scopeString}] are not available on the existing token.` : "The OAuth refresh token has likely been revoked or expired.";
|
|
160
|
-
return
|
|
160
|
+
return _hexclave_shared_dist_utils_results.Result.error(new _hexclave_shared.KnownErrors.OAuthAccessTokenNotAvailable(providerId, `${scopeDetail} The user needs to re-authorize by calling \`linkConnectedAccount\` or using \`getOrLinkConnectedAccount\`.`));
|
|
161
161
|
}
|
|
162
|
-
return
|
|
162
|
+
return _hexclave_shared_dist_utils_results.Result.ok(result);
|
|
163
163
|
}
|
|
164
164
|
};
|
|
165
165
|
}
|
|
@@ -168,14 +168,14 @@ var _StackClientAppImplIncomplete = class _StackClientAppImplIncomplete {
|
|
|
168
168
|
this._sessionRecorder = null;
|
|
169
169
|
this._eventTracker = null;
|
|
170
170
|
this.__DEMO_ENABLE_SLIGHT_FETCH_DELAY = false;
|
|
171
|
-
this._ownedAdminApps = new
|
|
171
|
+
this._ownedAdminApps = new _hexclave_shared_dist_utils_maps.DependenciesMap();
|
|
172
172
|
this._currentUserCache = (0, __common_js.createCacheBySession)(async (session) => {
|
|
173
|
-
if (this.__DEMO_ENABLE_SLIGHT_FETCH_DELAY) await (0,
|
|
173
|
+
if (this.__DEMO_ENABLE_SLIGHT_FETCH_DELAY) await (0, _hexclave_shared_dist_utils_promises.wait)(2e3);
|
|
174
174
|
if (session.isKnownToBeInvalid()) return null;
|
|
175
175
|
return await this._interface.getClientUserByToken(session);
|
|
176
176
|
});
|
|
177
177
|
this._currentProjectCache = (0, __common_js.createCache)(async () => {
|
|
178
|
-
return
|
|
178
|
+
return _hexclave_shared_dist_utils_results.Result.orThrow(await this._interface.getClientProject());
|
|
179
179
|
});
|
|
180
180
|
this._ownedProjectsCache = (0, __common_js.createCacheBySession)(async (session) => {
|
|
181
181
|
return await this._interface.listProjects(session);
|
|
@@ -196,14 +196,14 @@ var _StackClientAppImplIncomplete = class _StackClientAppImplIncomplete {
|
|
|
196
196
|
try {
|
|
197
197
|
return { accessToken: (await this._interface.createProviderAccessToken(providerId, scope || "", session)).access_token };
|
|
198
198
|
} catch (err) {
|
|
199
|
-
if (!(
|
|
199
|
+
if (!(_hexclave_shared.KnownErrors.OAuthAccessTokenNotAvailable.isInstance(err) || _hexclave_shared.KnownErrors.OAuthConnectionDoesNotHaveRequiredScope.isInstance(err) || _hexclave_shared.KnownErrors.OAuthConnectionNotConnectedToUser.isInstance(err))) throw err;
|
|
200
200
|
}
|
|
201
201
|
return null;
|
|
202
202
|
});
|
|
203
203
|
this._currentUserOAuthConnectionCache = (0, __common_js.createCacheBySession)(async (session, [providerId, scope, redirect]) => {
|
|
204
204
|
return await this._getUserOAuthConnectionCacheFn({
|
|
205
|
-
getUser: async () =>
|
|
206
|
-
getOrWaitOAuthToken: async () =>
|
|
205
|
+
getUser: async () => _hexclave_shared_dist_utils_results.Result.orThrow(await this._currentUserCache.getOrWait([session], "write-only")),
|
|
206
|
+
getOrWaitOAuthToken: async () => _hexclave_shared_dist_utils_results.Result.orThrow(await this._currentUserOAuthConnectionAccessTokensCache.getOrWait([
|
|
207
207
|
session,
|
|
208
208
|
providerId,
|
|
209
209
|
scope || ""
|
|
@@ -221,22 +221,22 @@ var _StackClientAppImplIncomplete = class _StackClientAppImplIncomplete {
|
|
|
221
221
|
try {
|
|
222
222
|
return { accessToken: (await this._interface.createProviderAccessTokenByAccount(providerId, providerAccountId, scope, session)).access_token };
|
|
223
223
|
} catch (err) {
|
|
224
|
-
if (
|
|
224
|
+
if (_hexclave_shared.KnownErrors.OAuthAccessTokenNotAvailable.isInstance(err) || _hexclave_shared.KnownErrors.OAuthConnectionDoesNotHaveRequiredScope.isInstance(err) || _hexclave_shared.KnownErrors.OAuthConnectionNotConnectedToUser.isInstance(err)) return null;
|
|
225
225
|
throw err;
|
|
226
226
|
}
|
|
227
227
|
});
|
|
228
228
|
this._currentUserValidConnectedAccountForProviderCache = (0, __common_js.createCacheBySession)(async (session, [provider, scopeString]) => {
|
|
229
|
-
const matchingAccounts =
|
|
229
|
+
const matchingAccounts = _hexclave_shared_dist_utils_results.Result.orThrow(await this._currentUserConnectedAccountsCache.getOrWait([session], "write-only")).filter((a) => a.provider === provider);
|
|
230
230
|
const scopes = scopeString ? scopeString.split(" ") : void 0;
|
|
231
231
|
for (const account of matchingAccounts) if ((await account.getAccessToken({ scopes })).status === "ok") return account;
|
|
232
232
|
const location = await (0, _________auth_js.getNewOAuthProviderOrScopeUrl)(this._interface, {
|
|
233
233
|
provider,
|
|
234
234
|
redirectUrl: this._getOAuthCallbackRedirectUri(),
|
|
235
235
|
errorRedirectUrl: this.urls.error,
|
|
236
|
-
providerScope: (0,
|
|
236
|
+
providerScope: (0, _hexclave_shared_dist_utils_strings.mergeScopeStrings)(scopeString, (this._oauthScopesOnSignIn[provider] ?? []).join(" "))
|
|
237
237
|
}, session);
|
|
238
238
|
await this._redirectTo({ url: location });
|
|
239
|
-
return await (0,
|
|
239
|
+
return await (0, _hexclave_shared_dist_utils_promises.neverResolve)();
|
|
240
240
|
});
|
|
241
241
|
this._teamMemberProfilesCache = (0, __common_js.createCacheBySession)(async (session, [teamId]) => {
|
|
242
242
|
return await this._interface.listTeamMemberProfiles({ teamId }, session);
|
|
@@ -344,7 +344,7 @@ var _StackClientAppImplIncomplete = class _StackClientAppImplIncomplete {
|
|
|
344
344
|
this._sessionsByTokenStoreAndSessionKey = /* @__PURE__ */ new WeakMap();
|
|
345
345
|
this._botChallengeSiteKeysWarned = false;
|
|
346
346
|
const resolvedOptions = (0, __common_js.resolveConstructorOptions)(options);
|
|
347
|
-
if (!_StackClientAppImplIncomplete.LazyStackAdminAppImpl.value) throw new
|
|
347
|
+
if (!_StackClientAppImplIncomplete.LazyStackAdminAppImpl.value) throw new _hexclave_shared_dist_utils_errors.HexclaveAssertionError("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).");
|
|
348
348
|
this._options = resolvedOptions;
|
|
349
349
|
this._extraOptions = extraOptions;
|
|
350
350
|
const projectId = resolvedOptions.projectId ?? (0, __common_js.getDefaultProjectId)();
|
|
@@ -353,7 +353,7 @@ var _StackClientAppImplIncomplete = class _StackClientAppImplIncomplete {
|
|
|
353
353
|
if (extraOptions && extraOptions.interface) this._interface = extraOptions.interface;
|
|
354
354
|
else {
|
|
355
355
|
const apiUrls = (0, __common_js.resolveApiUrls)(resolvedOptions.baseUrl);
|
|
356
|
-
this._interface = new
|
|
356
|
+
this._interface = new _hexclave_shared.HexclaveClientInterface({
|
|
357
357
|
getBaseUrl: () => apiUrls()[0],
|
|
358
358
|
getAnalyticsBaseUrl: () => (0, __common_js.getAnalyticsBaseUrl)(apiUrls()[0]),
|
|
359
359
|
getApiUrls: apiUrls,
|
|
@@ -365,11 +365,11 @@ var _StackClientAppImplIncomplete = class _StackClientAppImplIncomplete {
|
|
|
365
365
|
});
|
|
366
366
|
}
|
|
367
367
|
this._tokenStoreInit = resolvedOptions.tokenStore;
|
|
368
|
-
this._redirectMethod = resolvedOptions.redirectMethod || ((0,
|
|
368
|
+
this._redirectMethod = resolvedOptions.redirectMethod || ((0, _hexclave_shared_dist_utils_env.isBrowserLike)() ? "window" : "none");
|
|
369
369
|
this._urlOptions = resolvedOptions.urls ?? {};
|
|
370
370
|
this._oauthScopesOnSignIn = resolvedOptions.oauthScopesOnSignIn ?? {};
|
|
371
|
-
if ((0,
|
|
372
|
-
(0,
|
|
371
|
+
if ((0, _hexclave_shared_dist_utils_env.isBrowserLike)() && (resolvedOptions.tokenStore === "cookie" || resolvedOptions.tokenStore === "nextjs-cookie")) {
|
|
372
|
+
(0, _hexclave_shared_dist_utils_promises.runAsynchronously)(this._trustedParentDomainCache.getOrWait([window.location.hostname], "write-only"));
|
|
373
373
|
this._ensureCrossSubdomainCookieExists();
|
|
374
374
|
}
|
|
375
375
|
if (extraOptions && extraOptions.uniqueIdentifier) {
|
|
@@ -386,7 +386,7 @@ var _StackClientAppImplIncomplete = class _StackClientAppImplIncomplete {
|
|
|
386
386
|
return (await this.getUser({ or: "anonymous" }))._internalSession;
|
|
387
387
|
};
|
|
388
388
|
const analyticsEnabled = this._analyticsOptions?.enabled !== false;
|
|
389
|
-
if (analyticsEnabled && (0,
|
|
389
|
+
if (analyticsEnabled && (0, _hexclave_shared_dist_utils_env.isBrowserLike)() && this._hasPersistentTokenStore() && this._analyticsOptions?.replays?.enabled === true) {
|
|
390
390
|
this._sessionRecorder = new __session_replay_js.SessionRecorder({
|
|
391
391
|
projectId: this.projectId,
|
|
392
392
|
sendBatch: async (body, opts) => {
|
|
@@ -395,7 +395,7 @@ var _StackClientAppImplIncomplete = class _StackClientAppImplIncomplete {
|
|
|
395
395
|
}, this._analyticsOptions.replays);
|
|
396
396
|
this._sessionRecorder.start();
|
|
397
397
|
}
|
|
398
|
-
if (analyticsEnabled && (0,
|
|
398
|
+
if (analyticsEnabled && (0, _hexclave_shared_dist_utils_env.isBrowserLike)() && this._hasPersistentTokenStore()) {
|
|
399
399
|
this._eventTracker = new __event_tracker_js.EventTracker({
|
|
400
400
|
projectId: this.projectId,
|
|
401
401
|
sendBatch: async (body, opts) => {
|
|
@@ -404,17 +404,17 @@ var _StackClientAppImplIncomplete = class _StackClientAppImplIncomplete {
|
|
|
404
404
|
});
|
|
405
405
|
this._eventTracker.start();
|
|
406
406
|
}
|
|
407
|
-
if ((0,
|
|
408
|
-
if ((0,
|
|
407
|
+
if ((0, _hexclave_shared_dist_utils_env.isBrowserLike)() && this._isOAuthCallbackUrlHosted() && this._currentUrlLooksLikeStackOAuthCallback()) this._trackPendingAuthResolution(async () => {
|
|
408
|
+
if ((0, _hexclave_shared_dist_utils_env.isBrowserLike)()) await this.callOAuthCallback({ dontWarnAboutMissingQueryParams: true });
|
|
409
409
|
});
|
|
410
|
-
if ((0,
|
|
410
|
+
if ((0, _hexclave_shared_dist_utils_env.isBrowserLike)()) this._trackPendingAuthResolution(async () => {
|
|
411
411
|
await this._maybeHandleNestedCrossDomainAuth();
|
|
412
412
|
});
|
|
413
|
-
if ((0,
|
|
413
|
+
if ((0, _hexclave_shared_dist_utils_env.isBrowserLike)() && resolvedOptions.devTool !== false) (0, ____________dev_tool_index_js.mountDevTool)(this);
|
|
414
414
|
}
|
|
415
415
|
_initUniqueIdentifier() {
|
|
416
|
-
if (!this._uniqueIdentifier) throw new
|
|
417
|
-
if (allClientApps.has(this._uniqueIdentifier)) throw new
|
|
416
|
+
if (!this._uniqueIdentifier) throw new _hexclave_shared_dist_utils_errors.HexclaveAssertionError("Unique identifier not initialized");
|
|
417
|
+
if (allClientApps.has(this._uniqueIdentifier)) throw new _hexclave_shared_dist_utils_errors.HexclaveAssertionError("A Stack client app with the same unique identifier already exists");
|
|
418
418
|
allClientApps.set(this._uniqueIdentifier, [this._extraOptions?.checkString ?? void 0, this]);
|
|
419
419
|
}
|
|
420
420
|
_trackPendingAuthResolution(callback) {
|
|
@@ -423,11 +423,11 @@ var _StackClientAppImplIncomplete = class _StackClientAppImplIncomplete {
|
|
|
423
423
|
try {
|
|
424
424
|
await callback();
|
|
425
425
|
} catch (error) {
|
|
426
|
-
(0,
|
|
426
|
+
(0, _hexclave_shared_dist_utils_errors.captureError)("pending-auth-resolution-failed", error);
|
|
427
427
|
}
|
|
428
428
|
})();
|
|
429
429
|
this._pendingAuthResolutionPromises.push(promise);
|
|
430
|
-
(0,
|
|
430
|
+
(0, _hexclave_shared_dist_utils_promises.runAsynchronously)(async () => {
|
|
431
431
|
try {
|
|
432
432
|
await promise;
|
|
433
433
|
} finally {
|
|
@@ -457,7 +457,7 @@ var _StackClientAppImplIncomplete = class _StackClientAppImplIncomplete {
|
|
|
457
457
|
}
|
|
458
458
|
_getOAuthCallbackRedirectUri() {
|
|
459
459
|
if (!this._isOAuthCallbackUrlHosted()) return this.urls.oauthCallback;
|
|
460
|
-
if (typeof window === "undefined") throw new
|
|
460
|
+
if (typeof window === "undefined") throw new _hexclave_shared_dist_utils_errors.HexclaveAssertionError("Hosted OAuth callback URLs require a browser environment to use the current URL as the redirect URI");
|
|
461
461
|
const currentUrl = new URL(window.location.href);
|
|
462
462
|
for (const param of oauthCallbackResponseQueryParams) currentUrl.searchParams.delete(param);
|
|
463
463
|
return currentUrl.toString();
|
|
@@ -489,13 +489,13 @@ var _StackClientAppImplIncomplete = class _StackClientAppImplIncomplete {
|
|
|
489
489
|
const state = currentUrl.searchParams.get(nestedCrossDomainAuthQueryParams.state);
|
|
490
490
|
const codeChallenge = currentUrl.searchParams.get(nestedCrossDomainAuthQueryParams.codeChallenge);
|
|
491
491
|
if (redirectUri != null || state != null || codeChallenge != null) {
|
|
492
|
-
if (redirectUri == null || state == null || codeChallenge == null) throw new
|
|
492
|
+
if (redirectUri == null || state == null || codeChallenge == null) throw new _hexclave_shared_dist_utils_errors.HexclaveAssertionError("Nested cross-domain auth callback URL is missing OAuth request parameters", {
|
|
493
493
|
redirectUri,
|
|
494
494
|
state,
|
|
495
495
|
codeChallenge
|
|
496
496
|
});
|
|
497
|
-
if ((currentUrl.searchParams.get(nestedCrossDomainAuthQueryParams.codeChallengeMethod) ?? "S256") !== "S256") throw new
|
|
498
|
-
if ((0,
|
|
497
|
+
if ((currentUrl.searchParams.get(nestedCrossDomainAuthQueryParams.codeChallengeMethod) ?? "S256") !== "S256") throw new _hexclave_shared_dist_utils_errors.HexclaveAssertionError("Nested cross-domain auth only supports S256 PKCE");
|
|
498
|
+
if ((0, _hexclave_shared_dist_utils_urls.isRelative)(redirectUri)) throw new Error("Nested cross-domain auth redirect URI must be absolute.");
|
|
499
499
|
const redirectUriUrl = new URL(redirectUri);
|
|
500
500
|
if (!await this._isTrusted(redirectUriUrl.toString())) throw new Error(`Nested cross-domain auth redirect URI ${redirectUri} is not trusted.`);
|
|
501
501
|
const afterCallbackRedirectUrlString = currentUrl.searchParams.get(nestedCrossDomainAuthQueryParams.afterCallbackRedirectUrl);
|
|
@@ -516,8 +516,8 @@ var _StackClientAppImplIncomplete = class _StackClientAppImplIncomplete {
|
|
|
516
516
|
}
|
|
517
517
|
if (await this._getCurrentRefreshTokenIdIfSignedIn({ awaitPendingAuthResolutions: false }) === refreshTokenId) return false;
|
|
518
518
|
const callbackUrlString = currentUrl.searchParams.get(nestedCrossDomainAuthQueryParams.callbackUrl);
|
|
519
|
-
if (callbackUrlString == null) throw new
|
|
520
|
-
if ((0,
|
|
519
|
+
if (callbackUrlString == null) throw new _hexclave_shared_dist_utils_errors.HexclaveAssertionError("Nested cross-domain auth URL is missing callback URL");
|
|
520
|
+
if ((0, _hexclave_shared_dist_utils_urls.isRelative)(callbackUrlString)) throw new Error("Nested cross-domain auth callback URL must be absolute.");
|
|
521
521
|
const callbackUrl = new URL(callbackUrlString);
|
|
522
522
|
if (!await this._isTrusted(callbackUrl.toString())) throw new Error(`Nested cross-domain auth callback URL ${callbackUrlString} is not trusted.`);
|
|
523
523
|
const afterCallbackRedirectUrl = new URL(currentUrl);
|
|
@@ -543,7 +543,7 @@ var _StackClientAppImplIncomplete = class _StackClientAppImplIncomplete {
|
|
|
543
543
|
*/
|
|
544
544
|
_getUniqueIdentifier() {
|
|
545
545
|
if (!this._uniqueIdentifier) {
|
|
546
|
-
this._uniqueIdentifier = (0,
|
|
546
|
+
this._uniqueIdentifier = (0, _hexclave_shared_dist_utils_uuids.generateUuid)();
|
|
547
547
|
this._initUniqueIdentifier();
|
|
548
548
|
}
|
|
549
549
|
return this._uniqueIdentifier;
|
|
@@ -555,8 +555,8 @@ var _StackClientAppImplIncomplete = class _StackClientAppImplIncomplete {
|
|
|
555
555
|
});
|
|
556
556
|
}
|
|
557
557
|
_useCheckFeatureSupport(name, options) {
|
|
558
|
-
(0,
|
|
559
|
-
throw new
|
|
558
|
+
(0, _hexclave_shared_dist_utils_promises.runAsynchronously)(this._checkFeatureSupport(name, options));
|
|
559
|
+
throw new _hexclave_shared_dist_utils_errors.HexclaveAssertionError(`${name} is not currently supported. Please reach out to Stack support for more information.`);
|
|
560
560
|
}
|
|
561
561
|
get _legacyRefreshTokenCookieName() {
|
|
562
562
|
return `stack-refresh-${this.projectId}`;
|
|
@@ -568,7 +568,7 @@ var _StackClientAppImplIncomplete = class _StackClientAppImplIncomplete {
|
|
|
568
568
|
return `${secure ? "__Host-" : ""}${this._refreshTokenCookieName}--default`;
|
|
569
569
|
}
|
|
570
570
|
_getCustomRefreshCookieName(domain) {
|
|
571
|
-
const encoded = (0,
|
|
571
|
+
const encoded = (0, _hexclave_shared_dist_utils_bytes.encodeBase32)(new TextEncoder().encode(domain.toLowerCase()));
|
|
572
572
|
return `${this._refreshTokenCookieName}--custom-${encoded}`;
|
|
573
573
|
}
|
|
574
574
|
_getDomainFromCustomRefreshCookieName(name) {
|
|
@@ -576,7 +576,7 @@ var _StackClientAppImplIncomplete = class _StackClientAppImplIncomplete {
|
|
|
576
576
|
const prefix = `${base}--custom-`;
|
|
577
577
|
if (!name.startsWith(prefix)) continue;
|
|
578
578
|
try {
|
|
579
|
-
return new TextDecoder().decode((0,
|
|
579
|
+
return new TextDecoder().decode((0, _hexclave_shared_dist_utils_bytes.decodeBase32)(name.slice(prefix.length)));
|
|
580
580
|
} catch {
|
|
581
581
|
return null;
|
|
582
582
|
}
|
|
@@ -594,7 +594,7 @@ var _StackClientAppImplIncomplete = class _StackClientAppImplIncomplete {
|
|
|
594
594
|
}
|
|
595
595
|
_parseStructuredRefreshCookie(value) {
|
|
596
596
|
if (!value) return null;
|
|
597
|
-
const parsed = (0,
|
|
597
|
+
const parsed = (0, _hexclave_shared_dist_utils_json.parseJson)(value);
|
|
598
598
|
if (parsed.status !== "ok" || typeof parsed.data !== "object" || parsed.data === null) {
|
|
599
599
|
console.warn("Failed to parse structured refresh cookie");
|
|
600
600
|
return null;
|
|
@@ -653,7 +653,7 @@ var _StackClientAppImplIncomplete = class _StackClientAppImplIncomplete {
|
|
|
653
653
|
const accessTokenCookie = cookies[this._accessTokenCookieName] ?? cookies[this._legacyAccessTokenCookieName] ?? null;
|
|
654
654
|
let accessToken = null;
|
|
655
655
|
if (accessTokenCookie && accessTokenCookie.startsWith("[\"")) {
|
|
656
|
-
const parsed = (0,
|
|
656
|
+
const parsed = (0, _hexclave_shared_dist_utils_json.parseJson)(accessTokenCookie);
|
|
657
657
|
if (parsed.status === "ok" && typeof parsed.data === "object" && parsed.data !== null && Array.isArray(parsed.data) && parsed.data.length === 2 && typeof parsed.data[0] === "string" && typeof parsed.data[1] === "string") {
|
|
658
658
|
if (parsed.data[0] === refreshToken) accessToken = parsed.data[1];
|
|
659
659
|
} else console.warn("Access token cookie has invalid format");
|
|
@@ -670,7 +670,7 @@ var _StackClientAppImplIncomplete = class _StackClientAppImplIncomplete {
|
|
|
670
670
|
return `stack-access`;
|
|
671
671
|
}
|
|
672
672
|
_getAllBrowserCookies() {
|
|
673
|
-
if (!(0,
|
|
673
|
+
if (!(0, _hexclave_shared_dist_utils_env.isBrowserLike)()) throw new _hexclave_shared_dist_utils_errors.HexclaveAssertionError("Cannot get browser cookies on the server!");
|
|
674
674
|
return cookie.parseCookie(document.cookie || "");
|
|
675
675
|
}
|
|
676
676
|
_getRefreshTokenCookieNamePatterns() {
|
|
@@ -703,7 +703,7 @@ var _StackClientAppImplIncomplete = class _StackClientAppImplIncomplete {
|
|
|
703
703
|
};
|
|
704
704
|
}
|
|
705
705
|
_ensureCrossSubdomainCookieExists() {
|
|
706
|
-
(0,
|
|
706
|
+
(0, _hexclave_shared_dist_utils_promises.runAsynchronously)(async () => {
|
|
707
707
|
const hostname = window.location.hostname;
|
|
708
708
|
const domain = await this._trustedParentDomainCache.getOrWait([hostname], "read-write");
|
|
709
709
|
if (domain.status === "error" || !domain.data) return;
|
|
@@ -718,11 +718,11 @@ var _StackClientAppImplIncomplete = class _StackClientAppImplIncomplete {
|
|
|
718
718
|
});
|
|
719
719
|
}
|
|
720
720
|
_queueCustomRefreshCookieUpdate(refreshToken, updatedAt, context) {
|
|
721
|
-
(0,
|
|
721
|
+
(0, _hexclave_shared_dist_utils_promises.runAsynchronously)(async () => {
|
|
722
722
|
this._mostRecentQueuedCookieRefreshIndex++;
|
|
723
723
|
const updateIndex = this._mostRecentQueuedCookieRefreshIndex;
|
|
724
724
|
let hostname;
|
|
725
|
-
if ((0,
|
|
725
|
+
if ((0, _hexclave_shared_dist_utils_env.isBrowserLike)()) hostname = window.location.hostname;
|
|
726
726
|
else hostname = await getServerRequestHost();
|
|
727
727
|
if (!hostname) {
|
|
728
728
|
console.warn("No hostname found when queueing custom refresh cookie update");
|
|
@@ -752,7 +752,7 @@ var _StackClientAppImplIncomplete = class _StackClientAppImplIncomplete {
|
|
|
752
752
|
});
|
|
753
753
|
}
|
|
754
754
|
async _getTrustedRedirectConfig() {
|
|
755
|
-
const project =
|
|
755
|
+
const project = _hexclave_shared_dist_utils_results.Result.orThrow(await this._currentProjectCache.getOrWait([], "write-only"));
|
|
756
756
|
return {
|
|
757
757
|
allowLocalhost: project.config.allow_localhost,
|
|
758
758
|
trustedDomains: [...project.config.domains.map((d) => d.domain), new URL((0, ______url_targets_js.getHostedHandlerUrl)({
|
|
@@ -762,10 +762,10 @@ var _StackClientAppImplIncomplete = class _StackClientAppImplIncomplete {
|
|
|
762
762
|
};
|
|
763
763
|
}
|
|
764
764
|
async _getTrustedParentDomain(currentDomain) {
|
|
765
|
-
return (0,
|
|
765
|
+
return (0, _hexclave_shared_dist_utils_redirect_urls.getTrustedParentDomain)(currentDomain, (await this._getTrustedRedirectConfig()).trustedDomains);
|
|
766
766
|
}
|
|
767
767
|
_getBrowserCookieTokenStore() {
|
|
768
|
-
if (!(0,
|
|
768
|
+
if (!(0, _hexclave_shared_dist_utils_env.isBrowserLike)()) throw new Error("Cannot use cookie token store on the server!");
|
|
769
769
|
if (this._storedBrowserCookieTokenStore === null) {
|
|
770
770
|
const getCurrentValue = (old) => {
|
|
771
771
|
const tokens = this._getTokensFromCookies(this._getAllBrowserCookies());
|
|
@@ -774,13 +774,13 @@ var _StackClientAppImplIncomplete = class _StackClientAppImplIncomplete {
|
|
|
774
774
|
accessToken: tokens.accessToken ?? (old?.refreshToken === tokens.refreshToken ? old.accessToken : null)
|
|
775
775
|
};
|
|
776
776
|
};
|
|
777
|
-
this._storedBrowserCookieTokenStore = new
|
|
777
|
+
this._storedBrowserCookieTokenStore = new _hexclave_shared_dist_utils_stores.Store(getCurrentValue(null));
|
|
778
778
|
let hasSucceededInWriting = true;
|
|
779
779
|
setInterval(() => {
|
|
780
780
|
if (hasSucceededInWriting) {
|
|
781
781
|
const oldValue = this._storedBrowserCookieTokenStore.get();
|
|
782
782
|
const currentValue = getCurrentValue(oldValue);
|
|
783
|
-
if (!(0,
|
|
783
|
+
if (!(0, _hexclave_shared_dist_utils_objects.deepPlainEquals)(currentValue, oldValue)) this._storedBrowserCookieTokenStore.set(currentValue);
|
|
784
784
|
}
|
|
785
785
|
}, 100);
|
|
786
786
|
this._storedBrowserCookieTokenStore.onChange((value) => {
|
|
@@ -801,7 +801,7 @@ var _StackClientAppImplIncomplete = class _StackClientAppImplIncomplete {
|
|
|
801
801
|
this._queueCustomRefreshCookieUpdate(refreshToken, updatedAt, "browser");
|
|
802
802
|
hasSucceededInWriting = true;
|
|
803
803
|
} catch (e) {
|
|
804
|
-
if (!(0,
|
|
804
|
+
if (!(0, _hexclave_shared_dist_utils_env.isBrowserLike)()) hasSucceededInWriting = false;
|
|
805
805
|
else throw e;
|
|
806
806
|
}
|
|
807
807
|
});
|
|
@@ -812,11 +812,11 @@ var _StackClientAppImplIncomplete = class _StackClientAppImplIncomplete {
|
|
|
812
812
|
const tokenStoreInit = overrideTokenStoreInit === void 0 ? this._tokenStoreInit : overrideTokenStoreInit;
|
|
813
813
|
switch (tokenStoreInit) {
|
|
814
814
|
case "cookie": return this._getBrowserCookieTokenStore();
|
|
815
|
-
case "nextjs-cookie": if ((0,
|
|
815
|
+
case "nextjs-cookie": if ((0, _hexclave_shared_dist_utils_env.isBrowserLike)()) return this._getBrowserCookieTokenStore();
|
|
816
816
|
else {
|
|
817
|
-
const store = new
|
|
817
|
+
const store = new _hexclave_shared_dist_utils_stores.Store(this._getTokensFromCookies(cookieHelper.getAll()));
|
|
818
818
|
store.onChange((value) => {
|
|
819
|
-
(0,
|
|
819
|
+
(0, _hexclave_shared_dist_utils_promises.runAsynchronously)(async () => {
|
|
820
820
|
const refreshToken = value.refreshToken;
|
|
821
821
|
const secure = await (0, _________cookie_js.isSecure)();
|
|
822
822
|
const defaultName = this._getRefreshTokenDefaultCookieNameForSecure(secure);
|
|
@@ -849,7 +849,7 @@ var _StackClientAppImplIncomplete = class _StackClientAppImplIncomplete {
|
|
|
849
849
|
if (authorizationHeader) {
|
|
850
850
|
const authJson = getAuthJsonFromAuthorizationHeaderValue(authorizationHeader);
|
|
851
851
|
if (authJson != null) {
|
|
852
|
-
const tokenStore = new
|
|
852
|
+
const tokenStore = new _hexclave_shared_dist_utils_stores.Store({
|
|
853
853
|
accessToken: authJson.accessToken,
|
|
854
854
|
refreshToken: authJson.refreshToken
|
|
855
855
|
});
|
|
@@ -874,10 +874,10 @@ var _StackClientAppImplIncomplete = class _StackClientAppImplIncomplete {
|
|
|
874
874
|
}
|
|
875
875
|
const cookieHeader = getHeaderValueFromRequestLikeHeaders(tokenStoreInit.headers, "cookie");
|
|
876
876
|
const parsed = cookie.parseCookie(cookieHeader || "");
|
|
877
|
-
const res = new
|
|
877
|
+
const res = new _hexclave_shared_dist_utils_stores.Store(this._getTokensFromCookies(parsed));
|
|
878
878
|
this._requestTokenStores.set(tokenStoreInit, res);
|
|
879
879
|
return res;
|
|
880
|
-
} else if ("accessToken" in tokenStoreInit || "refreshToken" in tokenStoreInit) return new
|
|
880
|
+
} else if ("accessToken" in tokenStoreInit || "refreshToken" in tokenStoreInit) return new _hexclave_shared_dist_utils_stores.Store({
|
|
881
881
|
refreshToken: tokenStoreInit.refreshToken,
|
|
882
882
|
accessToken: tokenStoreInit.accessToken
|
|
883
883
|
});
|
|
@@ -886,7 +886,7 @@ var _StackClientAppImplIncomplete = class _StackClientAppImplIncomplete {
|
|
|
886
886
|
}
|
|
887
887
|
_getSessionFromTokenStore(tokenStore) {
|
|
888
888
|
const tokenObj = tokenStore.get();
|
|
889
|
-
const sessionKey =
|
|
889
|
+
const sessionKey = _hexclave_shared_dist_sessions.InternalSession.calculateSessionKey(tokenObj);
|
|
890
890
|
const existing = sessionKey ? this._sessionsByTokenStoreAndSessionKey.get(tokenStore)?.get(sessionKey) : null;
|
|
891
891
|
if (existing) return existing;
|
|
892
892
|
const session = this._interface.createSession({
|
|
@@ -917,7 +917,7 @@ var _StackClientAppImplIncomplete = class _StackClientAppImplIncomplete {
|
|
|
917
917
|
return this._getSessionFromTokenStore(tokenStore);
|
|
918
918
|
}
|
|
919
919
|
async _signInToAccountWithTokens(tokens) {
|
|
920
|
-
if (!("accessToken" in tokens) || !("refreshToken" in tokens)) throw new
|
|
920
|
+
if (!("accessToken" in tokens) || !("refreshToken" in tokens)) throw new _hexclave_shared_dist_utils_errors.HexclaveAssertionError("Invalid tokens object; can't sign in with this", { tokens });
|
|
921
921
|
const tokenStore = this._getOrCreateTokenStore(await this._createCookieHelper());
|
|
922
922
|
tokenStore.set(tokens);
|
|
923
923
|
const newSession = this._getSessionFromTokenStore(tokenStore);
|
|
@@ -1057,10 +1057,10 @@ var _StackClientAppImplIncomplete = class _StackClientAppImplIncomplete {
|
|
|
1057
1057
|
await app._teamInvitationsCache.refresh([session, crud.id]);
|
|
1058
1058
|
},
|
|
1059
1059
|
async listUsers() {
|
|
1060
|
-
return
|
|
1060
|
+
return _hexclave_shared_dist_utils_results.Result.orThrow(await app._teamMemberProfilesCache.getOrWait([session, crud.id], "write-only")).map((crud) => app._clientTeamUserFromCrud(crud));
|
|
1061
1061
|
},
|
|
1062
1062
|
async listInvitations() {
|
|
1063
|
-
return
|
|
1063
|
+
return _hexclave_shared_dist_utils_results.Result.orThrow(await app._teamInvitationsCache.getOrWait([session, crud.id], "write-only")).map((crud) => app._clientSentTeamInvitationFromCrud(session, crud));
|
|
1064
1064
|
},
|
|
1065
1065
|
async update(data) {
|
|
1066
1066
|
await app._interface.updateTeam({
|
|
@@ -1074,7 +1074,7 @@ var _StackClientAppImplIncomplete = class _StackClientAppImplIncomplete {
|
|
|
1074
1074
|
await app._currentUserTeamsCache.refresh([session]);
|
|
1075
1075
|
},
|
|
1076
1076
|
async listApiKeys() {
|
|
1077
|
-
return
|
|
1077
|
+
return _hexclave_shared_dist_utils_results.Result.orThrow(await app._teamApiKeysCache.getOrWait([session, crud.id], "write-only")).map((crud) => app._clientApiKeyFromCrud(session, crud));
|
|
1078
1078
|
},
|
|
1079
1079
|
async createApiKey(options) {
|
|
1080
1080
|
const result = await app._interface.createProjectApiKey(await (0, ______api_keys_index_js.apiKeyCreationOptionsToCrud)("team", crud.id, options), session, "client");
|
|
@@ -1134,9 +1134,9 @@ var _StackClientAppImplIncomplete = class _StackClientAppImplIncomplete {
|
|
|
1134
1134
|
allow_connected_accounts: data.allowConnectedAccounts
|
|
1135
1135
|
}, session);
|
|
1136
1136
|
await Promise.all([app._currentUserOAuthProvidersCache.refresh([session]), app._currentUserConnectedAccountsCache.refresh([session])]);
|
|
1137
|
-
return
|
|
1137
|
+
return _hexclave_shared_dist_utils_results.Result.ok(void 0);
|
|
1138
1138
|
} catch (error) {
|
|
1139
|
-
if (
|
|
1139
|
+
if (_hexclave_shared.KnownErrors.OAuthProviderAccountIdAlreadyUsedForSignIn.isInstance(error)) return _hexclave_shared_dist_utils_results.Result.error(error);
|
|
1140
1140
|
throw error;
|
|
1141
1141
|
}
|
|
1142
1142
|
},
|
|
@@ -1270,11 +1270,11 @@ var _StackClientAppImplIncomplete = class _StackClientAppImplIncomplete {
|
|
|
1270
1270
|
const scopeString = options?.scopes?.join(" ") ?? "";
|
|
1271
1271
|
if (typeof idOrAccount === "object" && "provider" in idOrAccount && "providerAccountId" in idOrAccount) {
|
|
1272
1272
|
const { provider, providerAccountId } = idOrAccount;
|
|
1273
|
-
const found =
|
|
1273
|
+
const found = _hexclave_shared_dist_utils_results.Result.orThrow(await app._currentUserConnectedAccountsCache.getOrWait([session], "write-only")).find((a) => a.provider === provider && a.providerAccountId === providerAccountId);
|
|
1274
1274
|
if (!found) return null;
|
|
1275
1275
|
return found;
|
|
1276
1276
|
}
|
|
1277
|
-
return
|
|
1277
|
+
return _hexclave_shared_dist_utils_results.Result.orThrow(await app._currentUserOAuthConnectionCache.getOrWait([
|
|
1278
1278
|
session,
|
|
1279
1279
|
idOrAccount,
|
|
1280
1280
|
scopeString,
|
|
@@ -1299,7 +1299,7 @@ var _StackClientAppImplIncomplete = class _StackClientAppImplIncomplete {
|
|
|
1299
1299
|
},
|
|
1300
1300
|
getConnectedAccount,
|
|
1301
1301
|
async listConnectedAccounts() {
|
|
1302
|
-
return
|
|
1302
|
+
return _hexclave_shared_dist_utils_results.Result.orThrow(await app._currentUserConnectedAccountsCache.getOrWait([session], "write-only"));
|
|
1303
1303
|
},
|
|
1304
1304
|
async linkConnectedAccount(provider, options) {
|
|
1305
1305
|
const scopeString = options?.scopes?.join(" ") ?? "";
|
|
@@ -1307,22 +1307,22 @@ var _StackClientAppImplIncomplete = class _StackClientAppImplIncomplete {
|
|
|
1307
1307
|
provider,
|
|
1308
1308
|
redirectUrl: app._getOAuthCallbackRedirectUri(),
|
|
1309
1309
|
errorRedirectUrl: app.urls.error,
|
|
1310
|
-
providerScope: (0,
|
|
1310
|
+
providerScope: (0, _hexclave_shared_dist_utils_strings.mergeScopeStrings)(scopeString, (app._oauthScopesOnSignIn[provider] ?? []).join(" "))
|
|
1311
1311
|
}, session);
|
|
1312
1312
|
await app._redirectTo({ url: location });
|
|
1313
|
-
return await (0,
|
|
1313
|
+
return await (0, _hexclave_shared_dist_utils_promises.neverResolve)();
|
|
1314
1314
|
},
|
|
1315
1315
|
async getOrLinkConnectedAccount(provider, options) {
|
|
1316
|
-
const matchingAccounts =
|
|
1316
|
+
const matchingAccounts = _hexclave_shared_dist_utils_results.Result.orThrow(await app._currentUserConnectedAccountsCache.getOrWait([session], "write-only")).filter((a) => a.provider === provider);
|
|
1317
1317
|
for (const account of matchingAccounts) if ((await account.getAccessToken({ scopes: options?.scopes })).status === "ok") return account;
|
|
1318
1318
|
await this.linkConnectedAccount(provider, options);
|
|
1319
|
-
return await (0,
|
|
1319
|
+
return await (0, _hexclave_shared_dist_utils_promises.neverResolve)();
|
|
1320
1320
|
},
|
|
1321
1321
|
async getTeam(teamId) {
|
|
1322
1322
|
return (await this.listTeams()).find((t) => t.id === teamId) ?? null;
|
|
1323
1323
|
},
|
|
1324
1324
|
async listTeams() {
|
|
1325
|
-
return
|
|
1325
|
+
return _hexclave_shared_dist_utils_results.Result.orThrow(await app._currentUserTeamsCache.getOrWait([session], "write-only")).map((crud) => app._clientTeamFromCrud(crud, session));
|
|
1326
1326
|
},
|
|
1327
1327
|
async createTeam(data) {
|
|
1328
1328
|
const crud = await app._interface.createClientTeam((0, ______teams_index_js.teamCreateOptionsToCrud)(data, "me"), session);
|
|
@@ -1334,20 +1334,20 @@ var _StackClientAppImplIncomplete = class _StackClientAppImplIncomplete {
|
|
|
1334
1334
|
await app._interface.leaveTeam(team.id, session);
|
|
1335
1335
|
},
|
|
1336
1336
|
async listTeamInvitations() {
|
|
1337
|
-
return
|
|
1337
|
+
return _hexclave_shared_dist_utils_results.Result.orThrow(await app._currentUserTeamInvitationsCache.getOrWait([session], "write-only")).map((crud) => app._clientReceivedTeamInvitationFromCrud(session, crud));
|
|
1338
1338
|
},
|
|
1339
1339
|
async listPermissions(scopeOrOptions, options) {
|
|
1340
1340
|
if (scopeOrOptions && "id" in scopeOrOptions) {
|
|
1341
1341
|
const scope = scopeOrOptions;
|
|
1342
1342
|
const recursive = options?.recursive ?? true;
|
|
1343
|
-
return
|
|
1343
|
+
return _hexclave_shared_dist_utils_results.Result.orThrow(await app._currentUserPermissionsCache.getOrWait([
|
|
1344
1344
|
session,
|
|
1345
1345
|
scope.id,
|
|
1346
1346
|
recursive
|
|
1347
1347
|
], "write-only")).map((crud) => app._clientPermissionFromCrud(crud));
|
|
1348
1348
|
} else {
|
|
1349
1349
|
const recursive = scopeOrOptions?.recursive ?? true;
|
|
1350
|
-
return
|
|
1350
|
+
return _hexclave_shared_dist_utils_results.Result.orThrow(await app._currentUserProjectPermissionsCache.getOrWait([session, recursive], "write-only")).map((crud) => app._clientPermissionFromCrud(crud));
|
|
1351
1351
|
}
|
|
1352
1352
|
},
|
|
1353
1353
|
async getPermission(scopeOrPermissionId, permissionId) {
|
|
@@ -1372,7 +1372,7 @@ var _StackClientAppImplIncomplete = class _StackClientAppImplIncomplete {
|
|
|
1372
1372
|
return await app._updateClientUser(update, session);
|
|
1373
1373
|
},
|
|
1374
1374
|
async sendVerificationEmail(options) {
|
|
1375
|
-
if (!crud.primary_email) throw new
|
|
1375
|
+
if (!crud.primary_email) throw new _hexclave_shared_dist_utils_errors.HexclaveAssertionError("User does not have a primary email");
|
|
1376
1376
|
return await app._interface.sendVerificationEmail(crud.primary_email, options?.callbackUrl ?? (0, ____________utils_url_js.constructRedirectUrl)(app.urls.emailVerification, "callbackUrl"), session);
|
|
1377
1377
|
},
|
|
1378
1378
|
async updatePassword(options) {
|
|
@@ -1387,7 +1387,7 @@ var _StackClientAppImplIncomplete = class _StackClientAppImplIncomplete {
|
|
|
1387
1387
|
},
|
|
1388
1388
|
selectedTeam: crud.selected_team && this._clientTeamFromCrud(crud.selected_team, session),
|
|
1389
1389
|
async getTeamProfile(team) {
|
|
1390
|
-
const result =
|
|
1390
|
+
const result = _hexclave_shared_dist_utils_results.Result.orThrow(await app._currentUserTeamProfileCache.getOrWait([session, team.id], "write-only"));
|
|
1391
1391
|
return app._editableTeamProfileFromCrud(result, session);
|
|
1392
1392
|
},
|
|
1393
1393
|
async delete() {
|
|
@@ -1395,7 +1395,7 @@ var _StackClientAppImplIncomplete = class _StackClientAppImplIncomplete {
|
|
|
1395
1395
|
session.markInvalid();
|
|
1396
1396
|
},
|
|
1397
1397
|
async listContactChannels() {
|
|
1398
|
-
return
|
|
1398
|
+
return _hexclave_shared_dist_utils_results.Result.orThrow(await app._clientContactChannelsCache.getOrWait([session], "write-only")).map((crud) => app._clientContactChannelFromCrud(crud, session));
|
|
1399
1399
|
},
|
|
1400
1400
|
async createContactChannel(data) {
|
|
1401
1401
|
const crud = await app._interface.createClientContactChannel((0, ______contact_channels_index_js.contactChannelCreateOptionsToCrud)("me", data), session);
|
|
@@ -1403,7 +1403,7 @@ var _StackClientAppImplIncomplete = class _StackClientAppImplIncomplete {
|
|
|
1403
1403
|
return app._clientContactChannelFromCrud(crud, session);
|
|
1404
1404
|
},
|
|
1405
1405
|
async listNotificationCategories() {
|
|
1406
|
-
return
|
|
1406
|
+
return _hexclave_shared_dist_utils_results.Result.orThrow(await app._notificationCategoriesCache.getOrWait([session], "write-only")).map((crud) => app._clientNotificationCategoryFromCrud(crud, session));
|
|
1407
1407
|
},
|
|
1408
1408
|
async listApiKeys() {
|
|
1409
1409
|
return (await app._interface.listProjectApiKeys({ user_id: "me" }, session, "client")).map((crud) => app._clientApiKeyFromCrud(session, crud));
|
|
@@ -1414,27 +1414,27 @@ var _StackClientAppImplIncomplete = class _StackClientAppImplIncomplete {
|
|
|
1414
1414
|
return app._clientApiKeyFromCrud(session, result);
|
|
1415
1415
|
},
|
|
1416
1416
|
async listOAuthProviders() {
|
|
1417
|
-
return
|
|
1417
|
+
return _hexclave_shared_dist_utils_results.Result.orThrow(await app._currentUserOAuthProvidersCache.getOrWait([session], "write-only")).map((crud) => app._clientOAuthProviderFromCrud(crud, session));
|
|
1418
1418
|
},
|
|
1419
1419
|
async getOAuthProvider(id) {
|
|
1420
1420
|
return (await this.listOAuthProviders()).find((p) => p.id === id) ?? null;
|
|
1421
1421
|
},
|
|
1422
1422
|
async registerPasskey(options) {
|
|
1423
1423
|
const hostname = (await app._getCurrentUrl())?.hostname;
|
|
1424
|
-
if (!hostname) throw new
|
|
1424
|
+
if (!hostname) throw new _hexclave_shared_dist_utils_errors.HexclaveAssertionError("hostname must be provided if the Stack App does not have a redirect method");
|
|
1425
1425
|
const initiationResult = await app._interface.initiatePasskeyRegistration({}, session);
|
|
1426
|
-
if (initiationResult.status !== "ok") return
|
|
1426
|
+
if (initiationResult.status !== "ok") return _hexclave_shared_dist_utils_results.Result.error(new _hexclave_shared.KnownErrors.PasskeyRegistrationFailed("Failed to get initiation options for passkey registration"));
|
|
1427
1427
|
const { options_json, code } = initiationResult.data;
|
|
1428
|
-
if (options_json.rp.id !== "THIS_VALUE_WILL_BE_REPLACED.example.com") throw new
|
|
1428
|
+
if (options_json.rp.id !== "THIS_VALUE_WILL_BE_REPLACED.example.com") throw new _hexclave_shared_dist_utils_errors.HexclaveAssertionError(`Expected returned RP ID from server to equal sentinel, but found ${options_json.rp.id}`);
|
|
1429
1429
|
options_json.rp.id = hostname;
|
|
1430
1430
|
let attResp;
|
|
1431
1431
|
try {
|
|
1432
1432
|
attResp = await (0, _simplewebauthn_browser.startRegistration)({ optionsJSON: options_json });
|
|
1433
1433
|
} catch (error) {
|
|
1434
|
-
if (error instanceof _simplewebauthn_browser.WebAuthnError) return
|
|
1434
|
+
if (error instanceof _simplewebauthn_browser.WebAuthnError) return _hexclave_shared_dist_utils_results.Result.error(new _hexclave_shared.KnownErrors.PasskeyWebAuthnError(error.message, error.name));
|
|
1435
1435
|
else {
|
|
1436
|
-
(0,
|
|
1437
|
-
return
|
|
1436
|
+
(0, _hexclave_shared_dist_utils_errors.captureError)("passkey-registration-failed", error);
|
|
1437
|
+
return _hexclave_shared_dist_utils_results.Result.error(new _hexclave_shared.KnownErrors.PasskeyRegistrationFailed("Failed to start passkey registration due to unknown error"));
|
|
1438
1438
|
}
|
|
1439
1439
|
}
|
|
1440
1440
|
const registrationResult = await app._interface.registerPasskey({
|
|
@@ -1468,7 +1468,7 @@ var _StackClientAppImplIncomplete = class _StackClientAppImplIncomplete {
|
|
|
1468
1468
|
const customerOptions = type === "user" ? { userId: userIdOrTeamId } : { teamId: userIdOrTeamId };
|
|
1469
1469
|
return {
|
|
1470
1470
|
async getBilling() {
|
|
1471
|
-
const response =
|
|
1471
|
+
const response = _hexclave_shared_dist_utils_results.Result.orThrow(await app._customerBillingCache.getOrWait([
|
|
1472
1472
|
effectiveSession,
|
|
1473
1473
|
type,
|
|
1474
1474
|
userIdOrTeamId
|
|
@@ -1534,17 +1534,17 @@ var _StackClientAppImplIncomplete = class _StackClientAppImplIncomplete {
|
|
|
1534
1534
|
async getItem(options) {
|
|
1535
1535
|
const session = await this._getSession();
|
|
1536
1536
|
let crud;
|
|
1537
|
-
if ("userId" in options) crud =
|
|
1537
|
+
if ("userId" in options) crud = _hexclave_shared_dist_utils_results.Result.orThrow(await this._userItemCache.getOrWait([
|
|
1538
1538
|
session,
|
|
1539
1539
|
options.userId,
|
|
1540
1540
|
options.itemId
|
|
1541
1541
|
], "write-only"));
|
|
1542
|
-
else if ("teamId" in options) crud =
|
|
1542
|
+
else if ("teamId" in options) crud = _hexclave_shared_dist_utils_results.Result.orThrow(await this._teamItemCache.getOrWait([
|
|
1543
1543
|
session,
|
|
1544
1544
|
options.teamId,
|
|
1545
1545
|
options.itemId
|
|
1546
1546
|
], "write-only"));
|
|
1547
|
-
else crud =
|
|
1547
|
+
else crud = _hexclave_shared_dist_utils_results.Result.orThrow(await this._customItemCache.getOrWait([
|
|
1548
1548
|
session,
|
|
1549
1549
|
options.customCustomerId,
|
|
1550
1550
|
options.itemId
|
|
@@ -1554,7 +1554,7 @@ var _StackClientAppImplIncomplete = class _StackClientAppImplIncomplete {
|
|
|
1554
1554
|
async listProducts(options) {
|
|
1555
1555
|
const session = (await this.getUser())?._internalSession ?? await this._getSession();
|
|
1556
1556
|
if ("userId" in options) {
|
|
1557
|
-
const response =
|
|
1557
|
+
const response = _hexclave_shared_dist_utils_results.Result.orThrow(await this._userProductsCache.getOrWait([
|
|
1558
1558
|
session,
|
|
1559
1559
|
options.userId,
|
|
1560
1560
|
options.cursor ?? null,
|
|
@@ -1562,7 +1562,7 @@ var _StackClientAppImplIncomplete = class _StackClientAppImplIncomplete {
|
|
|
1562
1562
|
], "write-only"));
|
|
1563
1563
|
return this._customerProductsFromResponse(response);
|
|
1564
1564
|
} else if ("teamId" in options) {
|
|
1565
|
-
const response =
|
|
1565
|
+
const response = _hexclave_shared_dist_utils_results.Result.orThrow(await this._teamProductsCache.getOrWait([
|
|
1566
1566
|
session,
|
|
1567
1567
|
options.teamId,
|
|
1568
1568
|
options.cursor ?? null,
|
|
@@ -1570,7 +1570,7 @@ var _StackClientAppImplIncomplete = class _StackClientAppImplIncomplete {
|
|
|
1570
1570
|
], "write-only"));
|
|
1571
1571
|
return this._customerProductsFromResponse(response);
|
|
1572
1572
|
}
|
|
1573
|
-
const response =
|
|
1573
|
+
const response = _hexclave_shared_dist_utils_results.Result.orThrow(await this._customProductsCache.getOrWait([
|
|
1574
1574
|
session,
|
|
1575
1575
|
options.customCustomerId,
|
|
1576
1576
|
options.cursor ?? null,
|
|
@@ -1581,7 +1581,7 @@ var _StackClientAppImplIncomplete = class _StackClientAppImplIncomplete {
|
|
|
1581
1581
|
async listInvoices(options) {
|
|
1582
1582
|
const session = await this._getSession();
|
|
1583
1583
|
if ("userId" in options) {
|
|
1584
|
-
const response =
|
|
1584
|
+
const response = _hexclave_shared_dist_utils_results.Result.orThrow(await this._userInvoicesCache.getOrWait([
|
|
1585
1585
|
session,
|
|
1586
1586
|
options.userId,
|
|
1587
1587
|
options.cursor ?? null,
|
|
@@ -1589,7 +1589,7 @@ var _StackClientAppImplIncomplete = class _StackClientAppImplIncomplete {
|
|
|
1589
1589
|
], "write-only"));
|
|
1590
1590
|
return this._customerInvoicesFromResponse(response);
|
|
1591
1591
|
}
|
|
1592
|
-
const response =
|
|
1592
|
+
const response = _hexclave_shared_dist_utils_results.Result.orThrow(await this._teamInvoicesCache.getOrWait([
|
|
1593
1593
|
session,
|
|
1594
1594
|
options.teamId,
|
|
1595
1595
|
options.cursor ?? null,
|
|
@@ -1600,7 +1600,7 @@ var _StackClientAppImplIncomplete = class _StackClientAppImplIncomplete {
|
|
|
1600
1600
|
async cancelSubscription(options) {
|
|
1601
1601
|
const session = await this._getSession();
|
|
1602
1602
|
const user = await this.getUser();
|
|
1603
|
-
if (!user) throw new
|
|
1603
|
+
if (!user) throw new _hexclave_shared.KnownErrors.UserAuthenticationRequired();
|
|
1604
1604
|
const customerType = "teamId" in options ? "team" : "user";
|
|
1605
1605
|
const customerId = "teamId" in options ? options.teamId : user.id;
|
|
1606
1606
|
await this._interface.cancelSubscription({
|
|
@@ -1649,7 +1649,7 @@ var _StackClientAppImplIncomplete = class _StackClientAppImplIncomplete {
|
|
|
1649
1649
|
return __common_js.clientVersion;
|
|
1650
1650
|
}
|
|
1651
1651
|
_getBotChallengeSiteKeys() {
|
|
1652
|
-
if (!(0,
|
|
1652
|
+
if (!(0, _hexclave_shared_dist_utils_env.isBrowserLike)()) return null;
|
|
1653
1653
|
const visibleSiteKey = _________env_js.envVars.NEXT_PUBLIC_STACK_BOT_CHALLENGE_SITE_KEY;
|
|
1654
1654
|
if (!visibleSiteKey) {
|
|
1655
1655
|
if (!this._botChallengeSiteKeysWarned) {
|
|
@@ -1664,23 +1664,23 @@ var _StackClientAppImplIncomplete = class _StackClientAppImplIncomplete {
|
|
|
1664
1664
|
};
|
|
1665
1665
|
}
|
|
1666
1666
|
_getBotChallengeFlowFailure(error) {
|
|
1667
|
-
if (error instanceof
|
|
1667
|
+
if (error instanceof _hexclave_shared_dist_utils_turnstile_flow.BotChallengeUserCancelledError) return {
|
|
1668
1668
|
type: "cancelled",
|
|
1669
|
-
knownError: new
|
|
1669
|
+
knownError: new _hexclave_shared.KnownErrors.BotChallengeFailed("Bot challenge cancelled by user")
|
|
1670
1670
|
};
|
|
1671
|
-
if (error instanceof
|
|
1671
|
+
if (error instanceof _hexclave_shared_dist_utils_turnstile_flow.BotChallengeExecutionFailedError) return {
|
|
1672
1672
|
type: "failed",
|
|
1673
|
-
knownError: new
|
|
1673
|
+
knownError: new _hexclave_shared.KnownErrors.BotChallengeFailed(error.message)
|
|
1674
1674
|
};
|
|
1675
1675
|
return null;
|
|
1676
1676
|
}
|
|
1677
1677
|
_normalizeBotChallengeResult(result) {
|
|
1678
1678
|
if (result.status === "ok") return result;
|
|
1679
|
-
if (
|
|
1680
|
-
(0,
|
|
1681
|
-
return
|
|
1679
|
+
if (_hexclave_shared.KnownErrors.BotChallengeRequired.isInstance(result.error)) {
|
|
1680
|
+
(0, _hexclave_shared_dist_utils_errors.captureError)("bot-challenge-unexpected-after-flow", result.error);
|
|
1681
|
+
return _hexclave_shared_dist_utils_results.Result.error(new _hexclave_shared.KnownErrors.BotChallengeFailed("Unexpected bot challenge after flow completion"));
|
|
1682
1682
|
}
|
|
1683
|
-
return
|
|
1683
|
+
return _hexclave_shared_dist_utils_results.Result.error(result.error);
|
|
1684
1684
|
}
|
|
1685
1685
|
_toInterfaceBotChallengeInput(challenge) {
|
|
1686
1686
|
if (challenge.unavailable) return { phase: "visible" };
|
|
@@ -1693,25 +1693,25 @@ var _StackClientAppImplIncomplete = class _StackClientAppImplIncomplete {
|
|
|
1693
1693
|
const siteKeys = this._getBotChallengeSiteKeys();
|
|
1694
1694
|
let result;
|
|
1695
1695
|
try {
|
|
1696
|
-
if (siteKeys) result = await (0,
|
|
1696
|
+
if (siteKeys) result = await (0, _hexclave_shared_dist_utils_turnstile_flow.withBotChallengeFlow)({
|
|
1697
1697
|
...siteKeys,
|
|
1698
1698
|
action: options.action,
|
|
1699
1699
|
execute: options.execute,
|
|
1700
1700
|
isChallengeRequired: (flowResult) => {
|
|
1701
|
-
return flowResult.status === "error" &&
|
|
1701
|
+
return flowResult.status === "error" && _hexclave_shared.KnownErrors.BotChallengeRequired.isInstance(flowResult.error);
|
|
1702
1702
|
}
|
|
1703
1703
|
});
|
|
1704
1704
|
else result = await options.execute({});
|
|
1705
1705
|
} catch (e) {
|
|
1706
1706
|
const flowFailure = this._getBotChallengeFlowFailure(e);
|
|
1707
|
-
if (flowFailure) return
|
|
1707
|
+
if (flowFailure) return _hexclave_shared_dist_utils_results.Result.error(flowFailure.knownError);
|
|
1708
1708
|
throw e;
|
|
1709
1709
|
}
|
|
1710
1710
|
return this._normalizeBotChallengeResult(result);
|
|
1711
1711
|
}
|
|
1712
1712
|
async _isTrusted(url) {
|
|
1713
|
-
if ((0,
|
|
1714
|
-
const parsedUrl = (0,
|
|
1713
|
+
if ((0, _hexclave_shared_dist_utils_urls.isRelative)(url)) return true;
|
|
1714
|
+
const parsedUrl = (0, _hexclave_shared_dist_utils_urls.createUrlIfValid)(url);
|
|
1715
1715
|
if (parsedUrl == null) return false;
|
|
1716
1716
|
if (typeof window !== "undefined" && window.location.origin === parsedUrl.origin) return true;
|
|
1717
1717
|
if ((0, ______url_targets_js.isHostedHandlerUrlForProject)({
|
|
@@ -1719,7 +1719,7 @@ var _StackClientAppImplIncomplete = class _StackClientAppImplIncomplete {
|
|
|
1719
1719
|
projectId: this.projectId
|
|
1720
1720
|
})) return true;
|
|
1721
1721
|
const trustedRedirectConfig = await this._getTrustedRedirectConfig();
|
|
1722
|
-
return (0,
|
|
1722
|
+
return (0, _hexclave_shared_dist_utils_redirect_urls.validateRedirectUrl)(parsedUrl, {
|
|
1723
1723
|
allowLocalhost: trustedRedirectConfig.allowLocalhost,
|
|
1724
1724
|
trustedDomains: trustedRedirectConfig.trustedDomains
|
|
1725
1725
|
});
|
|
@@ -1729,11 +1729,11 @@ var _StackClientAppImplIncomplete = class _StackClientAppImplIncomplete {
|
|
|
1729
1729
|
}
|
|
1730
1730
|
_prefetchCrossDomainHandoffParamsIfNeeded() {
|
|
1731
1731
|
const canWriteOauthVerifierCookie = this._tokenStoreInit === "cookie" || this._tokenStoreInit === "nextjs-cookie";
|
|
1732
|
-
if (!(0,
|
|
1732
|
+
if (!(0, _hexclave_shared_dist_utils_env.isBrowserLike)() || !canWriteOauthVerifierCookie || this._isPrefetchingCrossDomainHandoffParams || this._getFreshPrefetchedCrossDomainHandoffParams() != null) return;
|
|
1733
1733
|
this._isPrefetchingCrossDomainHandoffParams = true;
|
|
1734
|
-
(0,
|
|
1734
|
+
(0, _hexclave_shared_dist_utils_promises.runAsynchronously)(async () => {
|
|
1735
1735
|
try {
|
|
1736
|
-
if (!(0,
|
|
1736
|
+
if (!(0, _hexclave_shared_dist_utils_env.isBrowserLike)()) return;
|
|
1737
1737
|
const { state, codeChallenge } = await (0, _________cookie_js.saveVerifierAndState)();
|
|
1738
1738
|
this._prefetchedCrossDomainHandoffParams = {
|
|
1739
1739
|
state,
|
|
@@ -1795,10 +1795,10 @@ var _StackClientAppImplIncomplete = class _StackClientAppImplIncomplete {
|
|
|
1795
1795
|
}, session);
|
|
1796
1796
|
if (!response.ok) {
|
|
1797
1797
|
const responseBody = await response.text();
|
|
1798
|
-
throw new
|
|
1798
|
+
throw new _hexclave_shared_dist_utils_errors.HexclaveAssertionError(`Cross-domain authorization endpoint failed: ${response.status} ${responseBody}`);
|
|
1799
1799
|
}
|
|
1800
1800
|
const result = await response.json();
|
|
1801
|
-
if (!("redirect_url" in result) || typeof result.redirect_url !== "string") throw new
|
|
1801
|
+
if (!("redirect_url" in result) || typeof result.redirect_url !== "string") throw new _hexclave_shared_dist_utils_errors.HexclaveAssertionError("Cross-domain authorization endpoint returned an invalid payload", { result });
|
|
1802
1802
|
return result.redirect_url;
|
|
1803
1803
|
}
|
|
1804
1804
|
_getFreshPrefetchedCrossDomainHandoffParams() {
|
|
@@ -1819,7 +1819,7 @@ var _StackClientAppImplIncomplete = class _StackClientAppImplIncomplete {
|
|
|
1819
1819
|
else if (typeof this._redirectMethod === "object" && this._redirectMethod.navigate) this._redirectMethod.navigate(options.url.toString());
|
|
1820
1820
|
else if (options.replace) window.location.replace(options.url);
|
|
1821
1821
|
else window.location.assign(options.url);
|
|
1822
|
-
await (0,
|
|
1822
|
+
await (0, _hexclave_shared_dist_utils_promises.wait)(2e3);
|
|
1823
1823
|
}
|
|
1824
1824
|
async _redirectIfTrusted(url, options) {
|
|
1825
1825
|
if (!await this._isTrusted(url)) throw new Error(`Redirect URL ${url} is not trusted; should be relative.`);
|
|
@@ -1951,8 +1951,8 @@ var _StackClientAppImplIncomplete = class _StackClientAppImplIncomplete {
|
|
|
1951
1951
|
code,
|
|
1952
1952
|
session: await this._getSession()
|
|
1953
1953
|
});
|
|
1954
|
-
if (result.status === "ok") return
|
|
1955
|
-
else return
|
|
1954
|
+
if (result.status === "ok") return _hexclave_shared_dist_utils_results.Result.ok(void 0);
|
|
1955
|
+
else return _hexclave_shared_dist_utils_results.Result.error(result.error);
|
|
1956
1956
|
}
|
|
1957
1957
|
async getTeamInvitationDetails(code) {
|
|
1958
1958
|
const result = await this._interface.acceptTeamInvitation({
|
|
@@ -1960,8 +1960,8 @@ var _StackClientAppImplIncomplete = class _StackClientAppImplIncomplete {
|
|
|
1960
1960
|
code,
|
|
1961
1961
|
session: await this._getSession()
|
|
1962
1962
|
});
|
|
1963
|
-
if (result.status === "ok") return
|
|
1964
|
-
else return
|
|
1963
|
+
if (result.status === "ok") return _hexclave_shared_dist_utils_results.Result.ok({ teamDisplayName: result.data.team_display_name });
|
|
1964
|
+
else return _hexclave_shared_dist_utils_results.Result.error(result.error);
|
|
1965
1965
|
}
|
|
1966
1966
|
async verifyEmail(code) {
|
|
1967
1967
|
const result = await this._interface.verifyEmail(code);
|
|
@@ -1973,7 +1973,7 @@ var _StackClientAppImplIncomplete = class _StackClientAppImplIncomplete {
|
|
|
1973
1973
|
if (options?.or === "anonymous" && options.includeRestricted === false) throw new Error("Cannot use { or: 'anonymous' } with { includeRestricted: false }. Anonymous users implicitly include restricted users.");
|
|
1974
1974
|
this._ensurePersistentTokenStore(options?.tokenStore);
|
|
1975
1975
|
const session = await this._getSession(options?.tokenStore);
|
|
1976
|
-
let crud =
|
|
1976
|
+
let crud = _hexclave_shared_dist_utils_results.Result.orThrow(await this._currentUserCache.getOrWait([session], "write-only"));
|
|
1977
1977
|
const includeAnonymous = options?.or === "anonymous" || options?.or === "anonymous-if-exists[deprecated]";
|
|
1978
1978
|
const includeRestricted = options?.includeRestricted === true || includeAnonymous;
|
|
1979
1979
|
if (crud === null || crud.is_anonymous && !includeAnonymous || crud.is_restricted && !includeRestricted) switch (options?.or) {
|
|
@@ -1988,7 +1988,7 @@ var _StackClientAppImplIncomplete = class _StackClientAppImplIncomplete {
|
|
|
1988
1988
|
tokenStore: tokens,
|
|
1989
1989
|
or: "anonymous-if-exists[deprecated]",
|
|
1990
1990
|
includeRestricted: true
|
|
1991
|
-
}) ?? (0,
|
|
1991
|
+
}) ?? (0, _hexclave_shared_dist_utils_errors.throwErr)("Something went wrong while signing up anonymously");
|
|
1992
1992
|
}
|
|
1993
1993
|
case void 0:
|
|
1994
1994
|
case "anonymous-if-exists[deprecated]":
|
|
@@ -2076,12 +2076,12 @@ var _StackClientAppImplIncomplete = class _StackClientAppImplIncomplete {
|
|
|
2076
2076
|
};
|
|
2077
2077
|
let authorizeResult;
|
|
2078
2078
|
try {
|
|
2079
|
-
if (siteKeys) authorizeResult = await (0,
|
|
2079
|
+
if (siteKeys) authorizeResult = await (0, _hexclave_shared_dist_utils_turnstile_flow.withBotChallengeFlow)({
|
|
2080
2080
|
...siteKeys,
|
|
2081
2081
|
action: "oauth_authenticate",
|
|
2082
2082
|
execute: executeOAuth,
|
|
2083
2083
|
isChallengeRequired: (result) => {
|
|
2084
|
-
return result.status === "error" &&
|
|
2084
|
+
return result.status === "error" && _hexclave_shared.KnownErrors.BotChallengeRequired.isInstance(result.error);
|
|
2085
2085
|
}
|
|
2086
2086
|
});
|
|
2087
2087
|
else authorizeResult = await executeOAuth({});
|
|
@@ -2091,17 +2091,17 @@ var _StackClientAppImplIncomplete = class _StackClientAppImplIncomplete {
|
|
|
2091
2091
|
if (flowFailure?.type === "failed") throw flowFailure.knownError;
|
|
2092
2092
|
throw e;
|
|
2093
2093
|
}
|
|
2094
|
-
const location =
|
|
2094
|
+
const location = _hexclave_shared_dist_utils_results.Result.orThrow(authorizeResult);
|
|
2095
2095
|
await this._redirectTo({ url: location });
|
|
2096
|
-
await (0,
|
|
2096
|
+
await (0, _hexclave_shared_dist_utils_promises.neverResolve)();
|
|
2097
2097
|
}
|
|
2098
2098
|
/**
|
|
2099
2099
|
* Handles MFA verification by redirecting to the OTP page
|
|
2100
2100
|
*/
|
|
2101
2101
|
async _experimentalMfa(error, session) {
|
|
2102
|
-
if (typeof window !== "undefined") window.sessionStorage.setItem("hexclave_mfa_attempt_code", error.details?.attempt_code ?? (0,
|
|
2102
|
+
if (typeof window !== "undefined") window.sessionStorage.setItem("hexclave_mfa_attempt_code", error.details?.attempt_code ?? (0, _hexclave_shared_dist_utils_errors.throwErr)("attempt code missing"));
|
|
2103
2103
|
await this.redirectToMfa();
|
|
2104
|
-
throw new
|
|
2104
|
+
throw new _hexclave_shared_dist_utils_errors.HexclaveAssertionError("we should have redirected in redirectToMfa()");
|
|
2105
2105
|
}
|
|
2106
2106
|
/**
|
|
2107
2107
|
* @deprecated
|
|
@@ -2111,7 +2111,7 @@ var _StackClientAppImplIncomplete = class _StackClientAppImplIncomplete {
|
|
|
2111
2111
|
try {
|
|
2112
2112
|
return await callback();
|
|
2113
2113
|
} catch (e) {
|
|
2114
|
-
if (
|
|
2114
|
+
if (_hexclave_shared.KnownErrors.MultiFactorAuthenticationRequired.isInstance(e)) return _hexclave_shared_dist_utils_results.Result.ok(await this._experimentalMfa(e, await this._getSession(void 0, { awaitPendingAuthResolutions: false })));
|
|
2115
2115
|
throw e;
|
|
2116
2116
|
}
|
|
2117
2117
|
}
|
|
@@ -2124,25 +2124,25 @@ var _StackClientAppImplIncomplete = class _StackClientAppImplIncomplete {
|
|
|
2124
2124
|
return await this._interface.signInWithCredential(options.email, options.password, session);
|
|
2125
2125
|
});
|
|
2126
2126
|
} catch (e) {
|
|
2127
|
-
if (
|
|
2127
|
+
if (_hexclave_shared.KnownErrors.InvalidTotpCode.isInstance(e)) return _hexclave_shared_dist_utils_results.Result.error(e);
|
|
2128
2128
|
throw e;
|
|
2129
2129
|
}
|
|
2130
2130
|
if (result.status === "ok") {
|
|
2131
2131
|
await this._signInToAccountWithTokens(result.data);
|
|
2132
2132
|
if (!options.noRedirect) await this._redirectToHandler("afterSignIn", { replace: true }, { overrideTokenStoreInit: this._getTokenStoreInitForFreshTokens(result.data) });
|
|
2133
|
-
return
|
|
2134
|
-
} else return
|
|
2133
|
+
return _hexclave_shared_dist_utils_results.Result.ok(void 0);
|
|
2134
|
+
} else return _hexclave_shared_dist_utils_results.Result.error(result.error);
|
|
2135
2135
|
}
|
|
2136
2136
|
async signUpWithCredential(options) {
|
|
2137
|
-
if (options.noVerificationCallback && options.verificationCallbackUrl) throw new
|
|
2137
|
+
if (options.noVerificationCallback && options.verificationCallbackUrl) throw new _hexclave_shared_dist_utils_errors.HexclaveAssertionError("verificationCallbackUrl is not allowed when noVerificationCallback is true");
|
|
2138
2138
|
this._ensurePersistentTokenStore();
|
|
2139
2139
|
const session = await this._getSession();
|
|
2140
2140
|
const emailVerificationRedirectUrl = options.noVerificationCallback ? void 0 : options.verificationCallbackUrl ?? (0, ____________utils_url_js.constructRedirectUrl)(this.urls.emailVerification, "verificationCallbackUrl");
|
|
2141
2141
|
const executeSignUp = async (challenge) => {
|
|
2142
2142
|
let result = await this._interface.signUpWithCredential(options.email, options.password, emailVerificationRedirectUrl, session, this._toInterfaceBotChallengeInput(challenge));
|
|
2143
|
-
if (result.status === "error" && result.error instanceof
|
|
2143
|
+
if (result.status === "error" && result.error instanceof _hexclave_shared.KnownErrors.RedirectUrlNotWhitelisted && emailVerificationRedirectUrl !== void 0) {
|
|
2144
2144
|
if (!options.verificationCallbackUrl) {
|
|
2145
|
-
(0,
|
|
2145
|
+
(0, _hexclave_shared_dist_utils_errors.captureError)("signup-verification-url-not-whitelisted", new _hexclave_shared_dist_utils_errors.HexclaveAssertionError("The auto-constructed verification callback URL is not whitelisted; proceeding without email verification", { emailVerificationRedirectUrl }));
|
|
2146
2146
|
result = await this._interface.signUpWithCredential(options.email, options.password, void 0, session, this._toInterfaceBotChallengeInput(challenge));
|
|
2147
2147
|
}
|
|
2148
2148
|
}
|
|
@@ -2156,8 +2156,8 @@ var _StackClientAppImplIncomplete = class _StackClientAppImplIncomplete {
|
|
|
2156
2156
|
if (result.status === "ok") {
|
|
2157
2157
|
await this._signInToAccountWithTokens(result.data);
|
|
2158
2158
|
if (!options.noRedirect) await this._redirectToHandler("afterSignUp", { replace: true }, { overrideTokenStoreInit: this._getTokenStoreInitForFreshTokens(result.data) });
|
|
2159
|
-
return
|
|
2160
|
-
} else return
|
|
2159
|
+
return _hexclave_shared_dist_utils_results.Result.ok(void 0);
|
|
2160
|
+
} else return _hexclave_shared_dist_utils_results.Result.error(result.error);
|
|
2161
2161
|
}
|
|
2162
2162
|
async _signUpAnonymously() {
|
|
2163
2163
|
this._ensurePersistentTokenStore();
|
|
@@ -2166,7 +2166,7 @@ var _StackClientAppImplIncomplete = class _StackClientAppImplIncomplete {
|
|
|
2166
2166
|
const session = await this._getSession();
|
|
2167
2167
|
const result = await this._interface.signUpAnonymously(session);
|
|
2168
2168
|
if (result.status === "ok") await this._signInToAccountWithTokens(result.data);
|
|
2169
|
-
else throw new
|
|
2169
|
+
else throw new _hexclave_shared_dist_utils_errors.HexclaveAssertionError("signUpAnonymously() should never return an error");
|
|
2170
2170
|
this._anonymousSignUpInProgress = null;
|
|
2171
2171
|
return result.data;
|
|
2172
2172
|
})();
|
|
@@ -2181,7 +2181,7 @@ var _StackClientAppImplIncomplete = class _StackClientAppImplIncomplete {
|
|
|
2181
2181
|
return await this._interface.signInWithMagicLink(code, session);
|
|
2182
2182
|
});
|
|
2183
2183
|
} catch (e) {
|
|
2184
|
-
if (
|
|
2184
|
+
if (_hexclave_shared.KnownErrors.InvalidTotpCode.isInstance(e)) return _hexclave_shared_dist_utils_results.Result.error(e);
|
|
2185
2185
|
throw e;
|
|
2186
2186
|
}
|
|
2187
2187
|
if (result.status === "ok") {
|
|
@@ -2194,8 +2194,8 @@ var _StackClientAppImplIncomplete = class _StackClientAppImplIncomplete {
|
|
|
2194
2194
|
awaitPendingAuthResolutions: false,
|
|
2195
2195
|
overrideTokenStoreInit: this._getTokenStoreInitForFreshTokens(result.data)
|
|
2196
2196
|
});
|
|
2197
|
-
return
|
|
2198
|
-
} else return
|
|
2197
|
+
return _hexclave_shared_dist_utils_results.Result.ok(void 0);
|
|
2198
|
+
} else return _hexclave_shared_dist_utils_results.Result.error(result.error);
|
|
2199
2199
|
}
|
|
2200
2200
|
/**
|
|
2201
2201
|
* Initiates a CLI authentication process that allows a command line application
|
|
@@ -2226,7 +2226,7 @@ var _StackClientAppImplIncomplete = class _StackClientAppImplIncomplete {
|
|
|
2226
2226
|
...options.anonRefreshToken != null ? { anon_refresh_token: options.anonRefreshToken } : {}
|
|
2227
2227
|
})
|
|
2228
2228
|
}, null);
|
|
2229
|
-
if (!response.ok) return
|
|
2229
|
+
if (!response.ok) return _hexclave_shared_dist_utils_results.Result.error(new _hexclave_shared.KnownErrors.CliAuthError(`Failed to initiate CLI auth: ${response.status} ${await response.text()}`));
|
|
2230
2230
|
const initResult = await response.json();
|
|
2231
2231
|
const pollingCode = initResult.polling_code;
|
|
2232
2232
|
const loginCode = initResult.login_code;
|
|
@@ -2248,18 +2248,18 @@ var _StackClientAppImplIncomplete = class _StackClientAppImplIncomplete {
|
|
|
2248
2248
|
headers: { "Content-Type": "application/json" },
|
|
2249
2249
|
body: JSON.stringify({ polling_code: pollingCode })
|
|
2250
2250
|
}, null);
|
|
2251
|
-
if (!pollResponse.ok) return
|
|
2251
|
+
if (!pollResponse.ok) return _hexclave_shared_dist_utils_results.Result.error(new _hexclave_shared.KnownErrors.CliAuthError(`Failed to initiate CLI auth: ${pollResponse.status} ${await pollResponse.text()}`));
|
|
2252
2252
|
const pollResult = await pollResponse.json();
|
|
2253
|
-
if (pollResponse.status === 201 && pollResult.status === "success") return
|
|
2253
|
+
if (pollResponse.status === 201 && pollResult.status === "success") return _hexclave_shared_dist_utils_results.Result.ok(pollResult.refresh_token);
|
|
2254
2254
|
if (pollResult.status === "waiting") {
|
|
2255
|
-
await (0,
|
|
2255
|
+
await (0, _hexclave_shared_dist_utils_promises.wait)(options.waitTimeMillis ?? 2e3);
|
|
2256
2256
|
continue;
|
|
2257
2257
|
}
|
|
2258
|
-
if (pollResult.status === "expired") return
|
|
2259
|
-
if (pollResult.status === "used") return
|
|
2260
|
-
return
|
|
2258
|
+
if (pollResult.status === "expired") return _hexclave_shared_dist_utils_results.Result.error(new _hexclave_shared.KnownErrors.CliAuthExpiredError("CLI authentication request expired. Please try again."));
|
|
2259
|
+
if (pollResult.status === "used") return _hexclave_shared_dist_utils_results.Result.error(new _hexclave_shared.KnownErrors.CliAuthUsedError("This authentication token has already been used."));
|
|
2260
|
+
return _hexclave_shared_dist_utils_results.Result.error(new _hexclave_shared.KnownErrors.CliAuthError(`Unexpected status from CLI auth polling: ${pollResult.status}`));
|
|
2261
2261
|
}
|
|
2262
|
-
return
|
|
2262
|
+
return _hexclave_shared_dist_utils_results.Result.error(new _hexclave_shared.KnownErrors.CliAuthError("Timed out waiting for CLI authentication."));
|
|
2263
2263
|
}
|
|
2264
2264
|
async signInWithMfa(totp, code, options) {
|
|
2265
2265
|
this._ensurePersistentTokenStore();
|
|
@@ -2270,16 +2270,16 @@ var _StackClientAppImplIncomplete = class _StackClientAppImplIncomplete {
|
|
|
2270
2270
|
return await this._interface.signInWithMfa(totp, code, session);
|
|
2271
2271
|
});
|
|
2272
2272
|
} catch (e) {
|
|
2273
|
-
if (e instanceof
|
|
2273
|
+
if (e instanceof _hexclave_shared.KnownErrors.InvalidTotpCode) return _hexclave_shared_dist_utils_results.Result.error(e);
|
|
2274
2274
|
throw e;
|
|
2275
2275
|
}
|
|
2276
2276
|
if (result.status === "ok") {
|
|
2277
2277
|
await this._signInToAccountWithTokens(result.data);
|
|
2278
2278
|
if (!options?.noRedirect) if (result.data.newUser) await this._redirectToHandler("afterSignUp", { replace: true }, { overrideTokenStoreInit: this._getTokenStoreInitForFreshTokens(result.data) });
|
|
2279
2279
|
else await this._redirectToHandler("afterSignIn", { replace: true }, { overrideTokenStoreInit: this._getTokenStoreInitForFreshTokens(result.data) });
|
|
2280
|
-
return
|
|
2280
|
+
return _hexclave_shared_dist_utils_results.Result.ok(void 0);
|
|
2281
2281
|
}
|
|
2282
|
-
return
|
|
2282
|
+
return _hexclave_shared_dist_utils_results.Result.error(result.error);
|
|
2283
2283
|
}
|
|
2284
2284
|
async signInWithPasskey() {
|
|
2285
2285
|
this._ensurePersistentTokenStore();
|
|
@@ -2288,9 +2288,9 @@ var _StackClientAppImplIncomplete = class _StackClientAppImplIncomplete {
|
|
|
2288
2288
|
try {
|
|
2289
2289
|
result = await this._catchMfaRequiredError(async () => {
|
|
2290
2290
|
const initiationResult = await this._interface.initiatePasskeyAuthentication({}, session);
|
|
2291
|
-
if (initiationResult.status !== "ok") return
|
|
2291
|
+
if (initiationResult.status !== "ok") return _hexclave_shared_dist_utils_results.Result.error(new _hexclave_shared.KnownErrors.PasskeyAuthenticationFailed("Failed to get initiation options for passkey authentication"));
|
|
2292
2292
|
const { options_json, code } = initiationResult.data;
|
|
2293
|
-
if (options_json.rpId !== "THIS_VALUE_WILL_BE_REPLACED.example.com") throw new
|
|
2293
|
+
if (options_json.rpId !== "THIS_VALUE_WILL_BE_REPLACED.example.com") throw new _hexclave_shared_dist_utils_errors.HexclaveAssertionError(`Expected returned RP ID from server to equal sentinel, but found ${options_json.rpId}`);
|
|
2294
2294
|
options_json.rpId = window.location.hostname;
|
|
2295
2295
|
const authentication_response = await (0, _simplewebauthn_browser.startAuthentication)({ optionsJSON: options_json });
|
|
2296
2296
|
return await this._interface.signInWithPasskey({
|
|
@@ -2299,14 +2299,14 @@ var _StackClientAppImplIncomplete = class _StackClientAppImplIncomplete {
|
|
|
2299
2299
|
}, session);
|
|
2300
2300
|
});
|
|
2301
2301
|
} catch (error) {
|
|
2302
|
-
if (error instanceof _simplewebauthn_browser.WebAuthnError) return
|
|
2303
|
-
else return
|
|
2302
|
+
if (error instanceof _simplewebauthn_browser.WebAuthnError) return _hexclave_shared_dist_utils_results.Result.error(new _hexclave_shared.KnownErrors.PasskeyWebAuthnError(error.message, error.name));
|
|
2303
|
+
else return _hexclave_shared_dist_utils_results.Result.error(new _hexclave_shared.KnownErrors.PasskeyAuthenticationFailed("Failed to sign in with passkey"));
|
|
2304
2304
|
}
|
|
2305
2305
|
if (result.status === "ok") {
|
|
2306
2306
|
await this._signInToAccountWithTokens(result.data);
|
|
2307
2307
|
await this._redirectToHandler("afterSignIn", { replace: true }, { overrideTokenStoreInit: this._getTokenStoreInitForFreshTokens(result.data) });
|
|
2308
|
-
return
|
|
2309
|
-
} else return
|
|
2308
|
+
return _hexclave_shared_dist_utils_results.Result.ok(void 0);
|
|
2309
|
+
} else return _hexclave_shared_dist_utils_results.Result.error(result.error);
|
|
2310
2310
|
}
|
|
2311
2311
|
async callOAuthCallback(options) {
|
|
2312
2312
|
if (typeof window === "undefined") throw new Error("callOAuthCallback can currently only be called in a browser environment");
|
|
@@ -2324,7 +2324,7 @@ var _StackClientAppImplIncomplete = class _StackClientAppImplIncomplete {
|
|
|
2324
2324
|
return await (0, _________auth_js.callOAuthCallback)(this._interface, oauthCallbackRedirectUri, options);
|
|
2325
2325
|
});
|
|
2326
2326
|
} catch (e) {
|
|
2327
|
-
if (
|
|
2327
|
+
if (_hexclave_shared.KnownErrors.InvalidTotpCode.isInstance(e)) {
|
|
2328
2328
|
alert("Invalid TOTP code. Please try signing in again.");
|
|
2329
2329
|
return false;
|
|
2330
2330
|
} else throw e;
|
|
@@ -2357,7 +2357,7 @@ var _StackClientAppImplIncomplete = class _StackClientAppImplIncomplete {
|
|
|
2357
2357
|
async _signOut(session, options) {
|
|
2358
2358
|
this._eventTracker?.clearBuffer();
|
|
2359
2359
|
this._sessionRecorder?.clearBuffer();
|
|
2360
|
-
await
|
|
2360
|
+
await _hexclave_shared_dist_utils_stores.storeLock.withWriteLock(async () => {
|
|
2361
2361
|
await this._interface.signOut(session);
|
|
2362
2362
|
if (options?.redirectUrl) await this._redirectTo({
|
|
2363
2363
|
url: options.redirectUrl,
|
|
@@ -2395,12 +2395,12 @@ var _StackClientAppImplIncomplete = class _StackClientAppImplIncomplete {
|
|
|
2395
2395
|
};
|
|
2396
2396
|
}
|
|
2397
2397
|
async getProject() {
|
|
2398
|
-
const crud =
|
|
2398
|
+
const crud = _hexclave_shared_dist_utils_results.Result.orThrow(await this._currentProjectCache.getOrWait([], "write-only"));
|
|
2399
2399
|
return this._clientProjectFromCrud(crud);
|
|
2400
2400
|
}
|
|
2401
2401
|
async _listOwnedProjects(session) {
|
|
2402
2402
|
this._ensureInternalProject();
|
|
2403
|
-
return
|
|
2403
|
+
return _hexclave_shared_dist_utils_results.Result.orThrow(await this._ownedProjectsCache.getOrWait([session], "write-only")).map((j) => this._getOwnedAdminApp(j.id, session)._adminOwnedProjectFromCrud(j, () => this._refreshOwnedProjects(session)));
|
|
2404
2404
|
}
|
|
2405
2405
|
async _createProject(session, newProject) {
|
|
2406
2406
|
this._ensureInternalProject();
|
|
@@ -2425,17 +2425,17 @@ var _StackClientAppImplIncomplete = class _StackClientAppImplIncomplete {
|
|
|
2425
2425
|
}
|
|
2426
2426
|
static get [______common_js.stackAppInternalsSymbol]() {
|
|
2427
2427
|
return { fromClientJson: (json) => {
|
|
2428
|
-
const providedCheckString = JSON.stringify((0,
|
|
2428
|
+
const providedCheckString = JSON.stringify((0, _hexclave_shared_dist_utils_objects.omit)(json, []));
|
|
2429
2429
|
const existing = allClientApps.get(json.uniqueIdentifier);
|
|
2430
2430
|
if (existing) {
|
|
2431
2431
|
const [existingCheckString, clientApp] = existing;
|
|
2432
|
-
if (existingCheckString !== void 0 && existingCheckString !== providedCheckString) throw new
|
|
2432
|
+
if (existingCheckString !== void 0 && existingCheckString !== providedCheckString) throw new _hexclave_shared_dist_utils_errors.HexclaveAssertionError("The provided app JSON does not match the configuration of the existing client app with the same unique identifier", {
|
|
2433
2433
|
providedObj: json,
|
|
2434
2434
|
existingString: existingCheckString
|
|
2435
2435
|
});
|
|
2436
2436
|
return clientApp;
|
|
2437
2437
|
}
|
|
2438
|
-
const { analytics, ...restJson } = (0,
|
|
2438
|
+
const { analytics, ...restJson } = (0, _hexclave_shared_dist_utils_objects.omit)(json, ["uniqueIdentifier"]);
|
|
2439
2439
|
return new _StackClientAppImplIncomplete({
|
|
2440
2440
|
...restJson,
|
|
2441
2441
|
analytics: (0, __session_replay_js.analyticsOptionsFromJson)(analytics)
|
|
@@ -2448,7 +2448,7 @@ var _StackClientAppImplIncomplete = class _StackClientAppImplIncomplete {
|
|
|
2448
2448
|
get [______common_js.stackAppInternalsSymbol]() {
|
|
2449
2449
|
return {
|
|
2450
2450
|
toClientJson: () => {
|
|
2451
|
-
if (typeof this._redirectMethod !== "string") throw new
|
|
2451
|
+
if (typeof this._redirectMethod !== "string") throw new _hexclave_shared_dist_utils_errors.HexclaveAssertionError("Cannot serialize to JSON from an application with a non-string redirect method");
|
|
2452
2452
|
const publishableClientKey = "publishableClientKey" in this._interface.options ? this._interface.options.publishableClientKey : void 0;
|
|
2453
2453
|
return {
|
|
2454
2454
|
baseUrl: this._options.baseUrl,
|
|
@@ -2465,8 +2465,8 @@ var _StackClientAppImplIncomplete = class _StackClientAppImplIncomplete {
|
|
|
2465
2465
|
};
|
|
2466
2466
|
},
|
|
2467
2467
|
setCurrentUser: (userJsonPromise) => {
|
|
2468
|
-
(0,
|
|
2469
|
-
await this._currentUserCache.forceSetCachedValueAsync([await this._getSession()],
|
|
2468
|
+
(0, _hexclave_shared_dist_utils_promises.runAsynchronously)(async () => {
|
|
2469
|
+
await this._currentUserCache.forceSetCachedValueAsync([await this._getSession()], _hexclave_shared_dist_utils_results.Result.fromPromise(userJsonPromise));
|
|
2470
2470
|
});
|
|
2471
2471
|
},
|
|
2472
2472
|
getConstructorOptions: () => this._options,
|
|
@@ -2482,7 +2482,7 @@ var _StackClientAppImplIncomplete = class _StackClientAppImplIncomplete {
|
|
|
2482
2482
|
sendRequest: async (path, requestOptions, requestType = "client") => {
|
|
2483
2483
|
return await this._interface.sendClientRequest(path, requestOptions, await this._getSession(), requestType);
|
|
2484
2484
|
},
|
|
2485
|
-
getRedirectMethod: () => this._redirectMethod ?? (0,
|
|
2485
|
+
getRedirectMethod: () => this._redirectMethod ?? (0, _hexclave_shared_dist_utils_errors.throwErr)("Redirect method should have been initialized in the Stack client app constructor"),
|
|
2486
2486
|
redirectToUrl: async (url, options) => {
|
|
2487
2487
|
await this._redirectTo({
|
|
2488
2488
|
url,
|