@stackframe/stack 2.7.20 → 2.7.22
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +20 -0
- package/dist/admin-app-impl-CTQhv9tV.d.ts +395 -0
- package/dist/admin-app-impl-DpyRKp1e.d.mts +395 -0
- package/dist/components/credential-sign-in.js.map +1 -1
- package/dist/components/credential-sign-up.js.map +1 -1
- package/dist/components/elements/form-warning.js.map +1 -1
- package/dist/components/elements/maybe-full-page.js.map +1 -1
- package/dist/components/elements/separator-with-text.js.map +1 -1
- package/dist/components/elements/sidebar-layout.js.map +1 -1
- package/dist/components/elements/ssr-layout-effect.js.map +1 -1
- package/dist/components/elements/user-avatar.js.map +1 -1
- package/dist/components/iframe-preventer.js.map +1 -1
- package/dist/components/link.js.map +1 -1
- package/dist/components/magic-link-sign-in.js.map +1 -1
- package/dist/components/message-cards/known-error-message-card.js.map +1 -1
- package/dist/components/message-cards/message-card.js.map +1 -1
- package/dist/components/message-cards/predefined-message-card.js.map +1 -1
- package/dist/components/oauth-button-group.js.map +1 -1
- package/dist/components/oauth-button.js.map +1 -1
- package/dist/components/passkey-button.js.map +1 -1
- package/dist/components/profile-image-editor.js.map +1 -1
- package/dist/components/selected-team-switcher.d.mts +18 -6
- package/dist/components/selected-team-switcher.d.ts +18 -6
- package/dist/components/selected-team-switcher.js.map +1 -1
- package/dist/components/team-icon.d.mts +18 -6
- package/dist/components/team-icon.d.ts +18 -6
- package/dist/components/team-icon.js.map +1 -1
- package/dist/components/user-button.js.map +1 -1
- package/dist/components-page/account-settings.js.map +1 -1
- package/dist/components-page/auth-page.js.map +1 -1
- package/dist/components-page/email-verification.js.map +1 -1
- package/dist/components-page/error-page.js.map +1 -1
- package/dist/components-page/forgot-password.js.map +1 -1
- package/dist/components-page/magic-link-callback.js.map +1 -1
- package/dist/components-page/oauth-callback.js.map +1 -1
- package/dist/components-page/password-reset.js.map +1 -1
- package/dist/components-page/sign-in.js.map +1 -1
- package/dist/components-page/sign-out.js.map +1 -1
- package/dist/components-page/sign-up.js.map +1 -1
- package/dist/components-page/stack-handler.d.mts +18 -6
- package/dist/components-page/stack-handler.d.ts +18 -6
- package/dist/components-page/stack-handler.js.map +1 -1
- package/dist/components-page/team-creation.js.map +1 -1
- package/dist/components-page/team-invitation.js.map +1 -1
- package/dist/esm/components/credential-sign-in.js.map +1 -1
- package/dist/esm/components/credential-sign-up.js.map +1 -1
- package/dist/esm/components/elements/form-warning.js.map +1 -1
- package/dist/esm/components/elements/maybe-full-page.js.map +1 -1
- package/dist/esm/components/elements/separator-with-text.js.map +1 -1
- package/dist/esm/components/elements/sidebar-layout.js.map +1 -1
- package/dist/esm/components/elements/ssr-layout-effect.js.map +1 -1
- package/dist/esm/components/elements/user-avatar.js.map +1 -1
- package/dist/esm/components/iframe-preventer.js.map +1 -1
- package/dist/esm/components/link.js.map +1 -1
- package/dist/esm/components/magic-link-sign-in.js.map +1 -1
- package/dist/esm/components/message-cards/known-error-message-card.js.map +1 -1
- package/dist/esm/components/message-cards/message-card.js.map +1 -1
- package/dist/esm/components/message-cards/predefined-message-card.js.map +1 -1
- package/dist/esm/components/oauth-button-group.js.map +1 -1
- package/dist/esm/components/oauth-button.js.map +1 -1
- package/dist/esm/components/passkey-button.js.map +1 -1
- package/dist/esm/components/profile-image-editor.js.map +1 -1
- package/dist/esm/components/selected-team-switcher.js.map +1 -1
- package/dist/esm/components/team-icon.js.map +1 -1
- package/dist/esm/components/user-button.js.map +1 -1
- package/dist/esm/components-page/account-settings.js.map +1 -1
- package/dist/esm/components-page/auth-page.js.map +1 -1
- package/dist/esm/components-page/email-verification.js.map +1 -1
- package/dist/esm/components-page/error-page.js.map +1 -1
- package/dist/esm/components-page/forgot-password.js.map +1 -1
- package/dist/esm/components-page/magic-link-callback.js.map +1 -1
- package/dist/esm/components-page/oauth-callback.js.map +1 -1
- package/dist/esm/components-page/password-reset.js.map +1 -1
- package/dist/esm/components-page/sign-in.js.map +1 -1
- package/dist/esm/components-page/sign-out.js.map +1 -1
- package/dist/esm/components-page/sign-up.js.map +1 -1
- package/dist/esm/components-page/stack-handler.js.map +1 -1
- package/dist/esm/components-page/team-creation.js.map +1 -1
- package/dist/esm/components-page/team-invitation.js.map +1 -1
- package/dist/esm/generated/quetzal-translations.js.map +1 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/lib/auth.js.map +1 -1
- package/dist/esm/lib/cookie.js +4 -7
- package/dist/esm/lib/cookie.js.map +1 -1
- package/dist/esm/lib/hooks.js.map +1 -1
- package/dist/esm/lib/stack-app/api-keys/index.js +14 -0
- package/dist/esm/lib/stack-app/api-keys/index.js.map +1 -0
- package/dist/esm/lib/stack-app/apps/implementations/admin-app-impl.js +291 -0
- package/dist/esm/lib/stack-app/apps/implementations/admin-app-impl.js.map +1 -0
- package/dist/esm/lib/{stack-app.js → stack-app/apps/implementations/client-app-impl.js} +39 -1111
- package/dist/esm/lib/stack-app/apps/implementations/client-app-impl.js.map +1 -0
- package/dist/esm/lib/stack-app/apps/implementations/common.js +142 -0
- package/dist/esm/lib/stack-app/apps/implementations/common.js.map +1 -0
- package/dist/esm/lib/stack-app/apps/implementations/index.js +24 -0
- package/dist/esm/lib/stack-app/apps/implementations/index.js.map +1 -0
- package/dist/esm/lib/stack-app/apps/implementations/server-app-impl.js +527 -0
- package/dist/esm/lib/stack-app/apps/implementations/server-app-impl.js.map +1 -0
- package/dist/esm/lib/stack-app/apps/index.js +16 -0
- package/dist/esm/lib/stack-app/apps/index.js.map +1 -0
- package/dist/esm/lib/stack-app/apps/interfaces/admin-app.js +7 -0
- package/dist/esm/lib/stack-app/apps/interfaces/admin-app.js.map +1 -0
- package/dist/esm/lib/stack-app/apps/interfaces/client-app.js +7 -0
- package/dist/esm/lib/stack-app/apps/interfaces/client-app.js.map +1 -0
- package/dist/esm/lib/stack-app/apps/interfaces/server-app.js +7 -0
- package/dist/esm/lib/stack-app/apps/interfaces/server-app.js.map +1 -0
- package/dist/esm/lib/stack-app/common.js +6 -0
- package/dist/esm/lib/stack-app/common.js.map +1 -0
- package/dist/esm/lib/stack-app/connected-accounts/index.js +1 -0
- package/dist/esm/lib/stack-app/connected-accounts/index.js.map +1 -0
- package/dist/esm/lib/stack-app/contact-channels/index.js +39 -0
- package/dist/esm/lib/stack-app/contact-channels/index.js.map +1 -0
- package/dist/esm/lib/stack-app/email-templates/index.js +11 -0
- package/dist/esm/lib/stack-app/email-templates/index.js.map +1 -0
- package/dist/esm/lib/stack-app/index.js +16 -0
- package/dist/esm/lib/stack-app/index.js.map +1 -0
- package/dist/esm/lib/stack-app/permissions/index.js +20 -0
- package/dist/esm/lib/stack-app/permissions/index.js.map +1 -0
- package/dist/esm/lib/stack-app/project-configs/index.js +1 -0
- package/dist/esm/lib/stack-app/project-configs/index.js.map +1 -0
- package/dist/esm/lib/stack-app/projects/index.js +57 -0
- package/dist/esm/lib/stack-app/projects/index.js.map +1 -0
- package/dist/esm/lib/stack-app/teams/index.js +38 -0
- package/dist/esm/lib/stack-app/teams/index.js.map +1 -0
- package/dist/esm/lib/stack-app/users/index.js +47 -0
- package/dist/esm/lib/stack-app/users/index.js.map +1 -0
- package/dist/esm/lib/translations.js.map +1 -1
- package/dist/esm/providers/stack-provider-client.js.map +1 -1
- package/dist/esm/providers/stack-provider.js.map +1 -1
- package/dist/esm/providers/theme-provider.js.map +1 -1
- package/dist/esm/providers/translation-provider-client.js.map +1 -1
- package/dist/esm/providers/translation-provider.js.map +1 -1
- package/dist/esm/utils/browser-script.js.map +1 -1
- package/dist/esm/utils/constants.js.map +1 -1
- package/dist/esm/utils/url.js +4 -13
- package/dist/esm/utils/url.js.map +1 -1
- package/dist/generated/quetzal-translations.d.mts +2 -2
- package/dist/generated/quetzal-translations.d.ts +2 -2
- package/dist/generated/quetzal-translations.js.map +1 -1
- package/dist/{lib/stack-app.d.mts → index-C7D6Vt7X.d.mts} +139 -354
- package/dist/{lib/stack-app.d.ts → index-DQk7XJpU.d.ts} +139 -354
- package/dist/index.d.mts +17 -5
- package/dist/index.d.ts +17 -5
- package/dist/index.js.map +1 -1
- package/dist/lib/auth.js.map +1 -1
- package/dist/lib/cookie.d.mts +2 -2
- package/dist/lib/cookie.d.ts +2 -2
- package/dist/lib/cookie.js +5 -8
- package/dist/lib/cookie.js.map +1 -1
- package/dist/lib/hooks.d.mts +17 -5
- package/dist/lib/hooks.d.ts +17 -5
- package/dist/lib/hooks.js.map +1 -1
- package/dist/lib/stack-app/api-keys/index.d.mts +40 -0
- package/dist/lib/stack-app/api-keys/index.d.ts +40 -0
- package/dist/lib/stack-app/api-keys/index.js +39 -0
- package/dist/lib/stack-app/api-keys/index.js.map +1 -0
- package/dist/lib/stack-app/apps/implementations/admin-app-impl.d.mts +30 -0
- package/dist/lib/stack-app/apps/implementations/admin-app-impl.d.ts +30 -0
- package/dist/lib/stack-app/apps/implementations/admin-app-impl.js +316 -0
- package/dist/lib/stack-app/apps/implementations/admin-app-impl.js.map +1 -0
- package/dist/lib/stack-app/apps/implementations/client-app-impl.d.mts +30 -0
- package/dist/lib/stack-app/apps/implementations/client-app-impl.d.ts +30 -0
- package/dist/lib/{stack-app.js → stack-app/apps/implementations/client-app-impl.js} +77 -1154
- package/dist/lib/stack-app/apps/implementations/client-app-impl.js.map +1 -0
- package/dist/lib/stack-app/apps/implementations/common.d.mts +45 -0
- package/dist/lib/stack-app/apps/implementations/common.d.ts +45 -0
- package/dist/lib/stack-app/apps/implementations/common.js +187 -0
- package/dist/lib/stack-app/apps/implementations/common.js.map +1 -0
- package/dist/lib/stack-app/apps/implementations/index.d.mts +36 -0
- package/dist/lib/stack-app/apps/implementations/index.d.ts +36 -0
- package/dist/lib/stack-app/apps/implementations/index.js +51 -0
- package/dist/lib/stack-app/apps/implementations/index.js.map +1 -0
- package/dist/lib/stack-app/apps/implementations/server-app-impl.d.mts +30 -0
- package/dist/lib/stack-app/apps/implementations/server-app-impl.d.ts +30 -0
- package/dist/lib/stack-app/apps/implementations/server-app-impl.js +552 -0
- package/dist/lib/stack-app/apps/implementations/server-app-impl.js.map +1 -0
- package/dist/lib/stack-app/apps/index.d.mts +23 -0
- package/dist/lib/stack-app/apps/index.d.ts +23 -0
- package/dist/lib/stack-app/apps/index.js +37 -0
- package/dist/lib/stack-app/apps/index.js.map +1 -0
- package/dist/lib/stack-app/apps/interfaces/admin-app.d.mts +23 -0
- package/dist/lib/stack-app/apps/interfaces/admin-app.d.ts +23 -0
- package/dist/lib/stack-app/apps/interfaces/admin-app.js +32 -0
- package/dist/lib/stack-app/apps/interfaces/admin-app.js.map +1 -0
- package/dist/lib/stack-app/apps/interfaces/client-app.d.mts +23 -0
- package/dist/lib/stack-app/apps/interfaces/client-app.d.ts +23 -0
- package/dist/lib/stack-app/apps/interfaces/client-app.js +32 -0
- package/dist/lib/stack-app/apps/interfaces/client-app.js.map +1 -0
- package/dist/lib/stack-app/apps/interfaces/server-app.d.mts +23 -0
- package/dist/lib/stack-app/apps/interfaces/server-app.d.ts +23 -0
- package/dist/lib/stack-app/apps/interfaces/server-app.js +32 -0
- package/dist/lib/stack-app/apps/interfaces/server-app.js.map +1 -0
- package/dist/lib/stack-app/common.d.mts +63 -0
- package/dist/lib/stack-app/common.d.ts +63 -0
- package/dist/lib/stack-app/common.js +31 -0
- package/dist/lib/stack-app/common.js.map +1 -0
- package/dist/lib/stack-app/connected-accounts/index.d.mts +13 -0
- package/dist/lib/stack-app/connected-accounts/index.d.ts +13 -0
- package/dist/lib/stack-app/connected-accounts/index.js +19 -0
- package/dist/lib/stack-app/connected-accounts/index.js.map +1 -0
- package/dist/lib/stack-app/contact-channels/index.d.mts +38 -0
- package/dist/lib/stack-app/contact-channels/index.d.ts +38 -0
- package/dist/lib/stack-app/contact-channels/index.js +67 -0
- package/dist/lib/stack-app/contact-channels/index.js.map +1 -0
- package/dist/lib/stack-app/email-templates/index.d.mts +15 -0
- package/dist/lib/stack-app/email-templates/index.d.ts +15 -0
- package/dist/lib/stack-app/email-templates/index.js +36 -0
- package/dist/lib/stack-app/email-templates/index.js.map +1 -0
- package/dist/lib/stack-app/index.d.mts +23 -0
- package/dist/lib/stack-app/index.d.ts +23 -0
- package/dist/lib/stack-app/index.js +38 -0
- package/dist/lib/stack-app/index.js.map +1 -0
- package/dist/lib/stack-app/permissions/index.d.mts +21 -0
- package/dist/lib/stack-app/permissions/index.d.ts +21 -0
- package/dist/lib/stack-app/permissions/index.js +46 -0
- package/dist/lib/stack-app/permissions/index.js.map +1 -0
- package/dist/lib/stack-app/project-configs/index.d.mts +82 -0
- package/dist/lib/stack-app/project-configs/index.d.ts +82 -0
- package/dist/lib/stack-app/project-configs/index.js +19 -0
- package/dist/lib/stack-app/project-configs/index.js.map +1 -0
- package/dist/lib/stack-app/projects/index.d.mts +23 -0
- package/dist/lib/stack-app/projects/index.d.ts +23 -0
- package/dist/lib/stack-app/projects/index.js +83 -0
- package/dist/lib/stack-app/projects/index.js.map +1 -0
- package/dist/lib/stack-app/teams/index.d.mts +23 -0
- package/dist/lib/stack-app/teams/index.d.ts +23 -0
- package/dist/lib/stack-app/teams/index.js +66 -0
- package/dist/lib/stack-app/teams/index.js.map +1 -0
- package/dist/lib/stack-app/users/index.d.mts +23 -0
- package/dist/lib/stack-app/users/index.d.ts +23 -0
- package/dist/lib/stack-app/users/index.js +74 -0
- package/dist/lib/stack-app/users/index.js.map +1 -0
- package/dist/lib/translations.js.map +1 -1
- package/dist/providers/stack-provider-client.d.mts +17 -5
- package/dist/providers/stack-provider-client.d.ts +17 -5
- package/dist/providers/stack-provider-client.js.map +1 -1
- package/dist/providers/stack-provider.d.mts +18 -6
- package/dist/providers/stack-provider.d.ts +18 -6
- package/dist/providers/stack-provider.js.map +1 -1
- package/dist/providers/theme-provider.js.map +1 -1
- package/dist/providers/translation-provider-client.js.map +1 -1
- package/dist/providers/translation-provider.js.map +1 -1
- package/dist/utils/browser-script.js.map +1 -1
- package/dist/utils/constants.js.map +1 -1
- package/dist/utils/url.d.mts +1 -2
- package/dist/utils/url.d.ts +1 -2
- package/dist/utils/url.js +4 -14
- package/dist/utils/url.js.map +1 -1
- package/package.json +4 -4
- package/dist/esm/lib/stack-app.js.map +0 -1
- package/dist/lib/stack-app.js.map +0 -1
|
@@ -1,15 +1,12 @@
|
|
|
1
|
-
// src/lib/stack-app.ts
|
|
1
|
+
// src/lib/stack-app/apps/implementations/client-app-impl.ts
|
|
2
2
|
import { WebAuthnError, startAuthentication, startRegistration } from "@simplewebauthn/browser";
|
|
3
|
-
import { KnownErrors,
|
|
4
|
-
import { getProductionModeErrors } from "@stackframe/stack-shared/dist/helpers/production-mode";
|
|
3
|
+
import { KnownErrors, StackClientInterface } from "@stackframe/stack-shared";
|
|
5
4
|
import { InternalSession } from "@stackframe/stack-shared/dist/sessions";
|
|
6
|
-
import { encodeBase64 } from "@stackframe/stack-shared/dist/utils/bytes";
|
|
7
|
-
import { AsyncCache } from "@stackframe/stack-shared/dist/utils/caches";
|
|
8
5
|
import { scrambleDuringCompileTime } from "@stackframe/stack-shared/dist/utils/compile-time";
|
|
9
6
|
import { isBrowserLike } from "@stackframe/stack-shared/dist/utils/env";
|
|
10
|
-
import { StackAssertionError,
|
|
7
|
+
import { StackAssertionError, captureError, throwErr } from "@stackframe/stack-shared/dist/utils/errors";
|
|
11
8
|
import { DependenciesMap } from "@stackframe/stack-shared/dist/utils/maps";
|
|
12
|
-
import { deepPlainEquals,
|
|
9
|
+
import { deepPlainEquals, omit } from "@stackframe/stack-shared/dist/utils/objects";
|
|
13
10
|
import { neverResolve, runAsynchronously, wait } from "@stackframe/stack-shared/dist/utils/promises";
|
|
14
11
|
import { suspend, suspendIfSsr } from "@stackframe/stack-shared/dist/utils/react";
|
|
15
12
|
import { Result } from "@stackframe/stack-shared/dist/utils/results";
|
|
@@ -20,137 +17,24 @@ import { generateUuid } from "@stackframe/stack-shared/dist/utils/uuids";
|
|
|
20
17
|
import * as cookie from "cookie";
|
|
21
18
|
import * as NextNavigationUnscrambled from "next/navigation";
|
|
22
19
|
import React, { useCallback, useMemo } from "react";
|
|
23
|
-
import { constructRedirectUrl } from "
|
|
24
|
-
import { addNewOAuthProviderOrScope, callOAuthCallback, signInWithOAuth } from "
|
|
25
|
-
import { createBrowserCookieHelper, createCookieHelper,
|
|
20
|
+
import { constructRedirectUrl } from "../../../../utils/url";
|
|
21
|
+
import { addNewOAuthProviderOrScope, callOAuthCallback, signInWithOAuth } from "../../../auth";
|
|
22
|
+
import { createBrowserCookieHelper, createCookieHelper, createPlaceholderCookieHelper, deleteCookieClient, getCookieClient, setOrDeleteCookie, setOrDeleteCookieClient } from "../../../cookie";
|
|
23
|
+
import { stackAppInternalsSymbol } from "../../common";
|
|
24
|
+
import { contactChannelCreateOptionsToCrud, contactChannelUpdateOptionsToCrud } from "../../contact-channels";
|
|
25
|
+
import { adminProjectCreateOptionsToCrud } from "../../projects";
|
|
26
|
+
import { teamCreateOptionsToCrud, teamUpdateOptionsToCrud } from "../../teams";
|
|
27
|
+
import { userUpdateOptionsToCrud } from "../../users";
|
|
28
|
+
import { clientVersion, createCache, createCacheBySession, createEmptyTokenStore, getBaseUrl, getDefaultProjectId, getDefaultPublishableClientKey, getUrls } from "./common";
|
|
29
|
+
import { useAsyncCache } from "./common";
|
|
26
30
|
import * as sc from "@stackframe/stack-sc";
|
|
27
31
|
import { cookies } from "@stackframe/stack-sc";
|
|
28
32
|
var isReactServer2 = false;
|
|
29
33
|
isReactServer2 = sc.isReactServer;
|
|
30
34
|
var NextNavigation = scrambleDuringCompileTime(NextNavigationUnscrambled);
|
|
31
|
-
var clientVersion = "js @stackframe/stack@2.7.20";
|
|
32
|
-
if (clientVersion.startsWith("STACK_COMPILE_TIME")) {
|
|
33
|
-
throw new StackAssertionError("Client version was not replaced. Something went wrong during build!");
|
|
34
|
-
}
|
|
35
|
-
function getUrls(partial) {
|
|
36
|
-
const handler = partial.handler ?? "/handler";
|
|
37
|
-
const home = partial.home ?? "/";
|
|
38
|
-
const afterSignIn = partial.afterSignIn ?? home;
|
|
39
|
-
return {
|
|
40
|
-
handler,
|
|
41
|
-
signIn: `${handler}/sign-in`,
|
|
42
|
-
afterSignIn: home,
|
|
43
|
-
signUp: `${handler}/sign-up`,
|
|
44
|
-
afterSignUp: afterSignIn,
|
|
45
|
-
signOut: `${handler}/sign-out`,
|
|
46
|
-
afterSignOut: home,
|
|
47
|
-
emailVerification: `${handler}/email-verification`,
|
|
48
|
-
passwordReset: `${handler}/password-reset`,
|
|
49
|
-
forgotPassword: `${handler}/forgot-password`,
|
|
50
|
-
oauthCallback: `${handler}/oauth-callback`,
|
|
51
|
-
magicLinkCallback: `${handler}/magic-link-callback`,
|
|
52
|
-
home,
|
|
53
|
-
accountSettings: `${handler}/account-settings`,
|
|
54
|
-
error: `${handler}/error`,
|
|
55
|
-
teamInvitation: `${handler}/team-invitation`,
|
|
56
|
-
...filterUndefined(partial)
|
|
57
|
-
};
|
|
58
|
-
}
|
|
59
|
-
function getDefaultProjectId() {
|
|
60
|
-
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."));
|
|
61
|
-
}
|
|
62
|
-
function getDefaultPublishableClientKey() {
|
|
63
|
-
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."));
|
|
64
|
-
}
|
|
65
|
-
function getDefaultSecretServerKey() {
|
|
66
|
-
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."));
|
|
67
|
-
}
|
|
68
|
-
function getDefaultSuperSecretAdminKey() {
|
|
69
|
-
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."));
|
|
70
|
-
}
|
|
71
|
-
function getBaseUrl(userSpecifiedBaseUrl) {
|
|
72
|
-
let url;
|
|
73
|
-
if (userSpecifiedBaseUrl) {
|
|
74
|
-
if (typeof userSpecifiedBaseUrl === "string") {
|
|
75
|
-
url = userSpecifiedBaseUrl;
|
|
76
|
-
} else {
|
|
77
|
-
if (isBrowserLike()) {
|
|
78
|
-
url = userSpecifiedBaseUrl.browser;
|
|
79
|
-
} else {
|
|
80
|
-
url = userSpecifiedBaseUrl.server;
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
} else {
|
|
84
|
-
if (isBrowserLike()) {
|
|
85
|
-
url = process.env.NEXT_PUBLIC_BROWSER_STACK_API_URL;
|
|
86
|
-
} else {
|
|
87
|
-
url = process.env.NEXT_PUBLIC_SERVER_STACK_API_URL;
|
|
88
|
-
}
|
|
89
|
-
url = url || process.env.NEXT_PUBLIC_STACK_API_URL || process.env.NEXT_PUBLIC_STACK_URL || defaultBaseUrl;
|
|
90
|
-
}
|
|
91
|
-
return url.endsWith("/") ? url.slice(0, -1) : url;
|
|
92
|
-
}
|
|
93
|
-
var defaultBaseUrl = "https://api.stack-auth.com";
|
|
94
|
-
function createEmptyTokenStore() {
|
|
95
|
-
return new Store({
|
|
96
|
-
refreshToken: null,
|
|
97
|
-
accessToken: null
|
|
98
|
-
});
|
|
99
|
-
}
|
|
100
|
-
var cachePromiseByComponentId = /* @__PURE__ */ new Map();
|
|
101
|
-
function useAsyncCache(cache, dependencies, caller) {
|
|
102
|
-
suspendIfSsr(caller);
|
|
103
|
-
const id = React.useId();
|
|
104
|
-
const subscribe = useCallback((cb) => {
|
|
105
|
-
const { unsubscribe } = cache.onStateChange(dependencies, () => {
|
|
106
|
-
cachePromiseByComponentId.delete(id);
|
|
107
|
-
cb();
|
|
108
|
-
});
|
|
109
|
-
return unsubscribe;
|
|
110
|
-
}, [cache, ...dependencies]);
|
|
111
|
-
const getSnapshot = useCallback(() => {
|
|
112
|
-
if (!cachePromiseByComponentId.has(id)) {
|
|
113
|
-
cachePromiseByComponentId.set(id, cache.getOrWait(dependencies, "read-write"));
|
|
114
|
-
}
|
|
115
|
-
return cachePromiseByComponentId.get(id);
|
|
116
|
-
}, [cache, ...dependencies]);
|
|
117
|
-
const promise = React.useSyncExternalStore(
|
|
118
|
-
subscribe,
|
|
119
|
-
getSnapshot,
|
|
120
|
-
() => throwErr(new Error("getServerSnapshot should never be called in useAsyncCache because we restrict to CSR earlier"))
|
|
121
|
-
);
|
|
122
|
-
const result = React.use(promise);
|
|
123
|
-
if (result.status === "error") {
|
|
124
|
-
const error = result.error;
|
|
125
|
-
if (error instanceof Error && !error.__stackHasConcatenatedStacktraces) {
|
|
126
|
-
concatStacktraces(error, new Error());
|
|
127
|
-
error.__stackHasConcatenatedStacktraces = true;
|
|
128
|
-
}
|
|
129
|
-
throw error;
|
|
130
|
-
}
|
|
131
|
-
return result.data;
|
|
132
|
-
}
|
|
133
|
-
var stackAppInternalsSymbol = Symbol.for("StackAuth--DO-NOT-USE-OR-YOU-WILL-BE-FIRED--StackAppInternals");
|
|
134
|
-
var allClientApps = /* @__PURE__ */ new Map();
|
|
135
|
-
var createCache = (fetcher) => {
|
|
136
|
-
return new AsyncCache(
|
|
137
|
-
async (dependencies) => await Result.fromThrowingAsync(async () => await fetcher(dependencies)),
|
|
138
|
-
{}
|
|
139
|
-
);
|
|
140
|
-
};
|
|
141
|
-
var createCacheBySession = (fetcher) => {
|
|
142
|
-
return new AsyncCache(
|
|
143
|
-
async ([session, ...extraDependencies]) => await Result.fromThrowingAsync(async () => await fetcher(session, extraDependencies)),
|
|
144
|
-
{
|
|
145
|
-
onSubscribe: ([session], refresh) => {
|
|
146
|
-
const handler = session.onInvalidate(() => refresh());
|
|
147
|
-
return () => handler.unsubscribe();
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
);
|
|
151
|
-
};
|
|
152
35
|
var numberOfAppsCreated = 0;
|
|
153
|
-
var
|
|
36
|
+
var allClientApps = /* @__PURE__ */ new Map();
|
|
37
|
+
var __StackClientAppImplIncomplete = class __StackClientAppImplIncomplete {
|
|
154
38
|
constructor(_options) {
|
|
155
39
|
this._options = _options;
|
|
156
40
|
this._uniqueIdentifier = void 0;
|
|
@@ -224,6 +108,7 @@ var _StackClientAppImpl = class __StackClientAppImpl {
|
|
|
224
108
|
}
|
|
225
109
|
);
|
|
226
110
|
this._memoryTokenStore = createEmptyTokenStore();
|
|
111
|
+
this._nextServerCookiesTokenStores = /* @__PURE__ */ new WeakMap();
|
|
227
112
|
this._requestTokenStores = /* @__PURE__ */ new WeakMap();
|
|
228
113
|
this._storedBrowserCookieTokenStore = null;
|
|
229
114
|
/**
|
|
@@ -235,6 +120,9 @@ var _StackClientAppImpl = class __StackClientAppImpl {
|
|
|
235
120
|
* - So different token stores are separated and don't leak information between each other, eg. if the same user sends two requests to the same server they should get a different session object
|
|
236
121
|
*/
|
|
237
122
|
this._sessionsByTokenStoreAndSessionKey = /* @__PURE__ */ new WeakMap();
|
|
123
|
+
if (!__StackClientAppImplIncomplete.LazyStackAdminAppImpl.value) {
|
|
124
|
+
throw new StackAssertionError("Admin app implementation not initialized. Did you import the _StackClientApp from stack-app/apps/implementations/index.ts? You can't import it directly from ./apps/implementations/client-app-impl.ts as that causes a circular dependency (see the comment at _LazyStackAdminAppImpl for more details).");
|
|
125
|
+
}
|
|
238
126
|
if ("interface" in _options) {
|
|
239
127
|
this._interface = _options.interface;
|
|
240
128
|
} else {
|
|
@@ -268,7 +156,7 @@ var _StackClientAppImpl = class __StackClientAppImpl {
|
|
|
268
156
|
if (this._tokenStoreInit === "nextjs-cookie" || this._tokenStoreInit === "cookie") {
|
|
269
157
|
return await createCookieHelper();
|
|
270
158
|
} else {
|
|
271
|
-
return await
|
|
159
|
+
return await createPlaceholderCookieHelper();
|
|
272
160
|
}
|
|
273
161
|
}
|
|
274
162
|
async _getUserOAuthConnectionCacheFn(options) {
|
|
@@ -694,12 +582,12 @@ var _StackClientAppImpl = class __StackClientAppImpl {
|
|
|
694
582
|
let attResp;
|
|
695
583
|
try {
|
|
696
584
|
attResp = await startRegistration({ optionsJSON: options_json });
|
|
697
|
-
debugger;
|
|
698
585
|
} catch (error) {
|
|
699
586
|
if (error instanceof WebAuthnError) {
|
|
700
587
|
return Result.error(new KnownErrors.PasskeyWebAuthnError(error.message, error.name));
|
|
701
588
|
} else {
|
|
702
|
-
|
|
589
|
+
captureError("passkey-registration-failed", error);
|
|
590
|
+
return Result.error(new KnownErrors.PasskeyRegistrationFailed("Failed to start passkey registration due to unknown error"));
|
|
703
591
|
}
|
|
704
592
|
}
|
|
705
593
|
const registrationResult = await app._interface.registerPasskey({ credential: attResp, code }, session);
|
|
@@ -896,7 +784,7 @@ var _StackClientAppImpl = class __StackClientAppImpl {
|
|
|
896
784
|
}
|
|
897
785
|
_getOwnedAdminApp(forProjectId, session) {
|
|
898
786
|
if (!this._ownedAdminApps.has([session, forProjectId])) {
|
|
899
|
-
this._ownedAdminApps.set([session, forProjectId], new
|
|
787
|
+
this._ownedAdminApps.set([session, forProjectId], new __StackClientAppImplIncomplete.LazyStackAdminAppImpl.value({
|
|
900
788
|
baseUrl: this._interface.options.getBaseUrl(),
|
|
901
789
|
projectId: forProjectId,
|
|
902
790
|
tokenStore: null,
|
|
@@ -941,9 +829,9 @@ var _StackClientAppImpl = class __StackClientAppImpl {
|
|
|
941
829
|
if (typeof this._redirectMethod === "object") {
|
|
942
830
|
return this._redirectMethod.useNavigate();
|
|
943
831
|
} else if (this._redirectMethod === "window") {
|
|
944
|
-
return () => window.location.assign;
|
|
832
|
+
return (to) => window.location.assign(to);
|
|
945
833
|
} else if (this._redirectMethod === "nextjs") {
|
|
946
|
-
return NextNavigation.useRouter().push;
|
|
834
|
+
return (to) => NextNavigation.useRouter().push(to);
|
|
947
835
|
} else {
|
|
948
836
|
return (to) => {
|
|
949
837
|
};
|
|
@@ -1210,7 +1098,7 @@ var _StackClientAppImpl = class __StackClientAppImpl {
|
|
|
1210
1098
|
async signUpWithCredential(options) {
|
|
1211
1099
|
this._ensurePersistentTokenStore();
|
|
1212
1100
|
const session = await this._getSession();
|
|
1213
|
-
const emailVerificationRedirectUrl = constructRedirectUrl(this.urls.emailVerification);
|
|
1101
|
+
const emailVerificationRedirectUrl = options.verificationCallbackUrl ?? constructRedirectUrl(this.urls.emailVerification);
|
|
1214
1102
|
const result = await this._interface.signUpWithCredential(
|
|
1215
1103
|
options.email,
|
|
1216
1104
|
options.password,
|
|
@@ -1396,7 +1284,7 @@ var _StackClientAppImpl = class __StackClientAppImpl {
|
|
|
1396
1284
|
}
|
|
1397
1285
|
return clientApp;
|
|
1398
1286
|
}
|
|
1399
|
-
return new
|
|
1287
|
+
return new __StackClientAppImplIncomplete({
|
|
1400
1288
|
...json,
|
|
1401
1289
|
checkString: providedCheckString
|
|
1402
1290
|
});
|
|
@@ -1434,976 +1322,16 @@ var _StackClientAppImpl = class __StackClientAppImpl {
|
|
|
1434
1322
|
};
|
|
1435
1323
|
}
|
|
1436
1324
|
};
|
|
1437
|
-
|
|
1438
|
-
|
|
1439
|
-
|
|
1440
|
-
|
|
1441
|
-
|
|
1442
|
-
|
|
1443
|
-
|
|
1444
|
-
|
|
1445
|
-
|
|
1446
|
-
getBaseUrl: () => getBaseUrl(options.baseUrl),
|
|
1447
|
-
projectId: options.projectId ?? getDefaultProjectId(),
|
|
1448
|
-
clientVersion,
|
|
1449
|
-
publishableClientKey: options.publishableClientKey ?? getDefaultPublishableClientKey(),
|
|
1450
|
-
secretServerKey: options.secretServerKey ?? getDefaultSecretServerKey()
|
|
1451
|
-
}),
|
|
1452
|
-
baseUrl: options.baseUrl,
|
|
1453
|
-
projectId: options.projectId,
|
|
1454
|
-
publishableClientKey: options.publishableClientKey,
|
|
1455
|
-
tokenStore: options.tokenStore,
|
|
1456
|
-
urls: options.urls ?? {},
|
|
1457
|
-
oauthScopesOnSignIn: options.oauthScopesOnSignIn ?? {},
|
|
1458
|
-
redirectMethod: options.redirectMethod
|
|
1459
|
-
});
|
|
1460
|
-
// TODO override the client user cache to use the server user cache, so we save some requests
|
|
1461
|
-
this._currentServerUserCache = createCacheBySession(async (session) => {
|
|
1462
|
-
if (session.isKnownToBeInvalid()) {
|
|
1463
|
-
return null;
|
|
1464
|
-
}
|
|
1465
|
-
return await this._interface.getServerUserByToken(session);
|
|
1466
|
-
});
|
|
1467
|
-
this._serverUsersCache = createCache(async ([cursor, limit, orderBy, desc, query]) => {
|
|
1468
|
-
return await this._interface.listServerUsers({ cursor, limit, orderBy, desc, query });
|
|
1469
|
-
});
|
|
1470
|
-
this._serverUserCache = createCache(async ([userId]) => {
|
|
1471
|
-
const user = await this._interface.getServerUserById(userId);
|
|
1472
|
-
return Result.or(user, null);
|
|
1473
|
-
});
|
|
1474
|
-
this._serverTeamsCache = createCache(async ([userId]) => {
|
|
1475
|
-
return await this._interface.listServerTeams({ userId });
|
|
1476
|
-
});
|
|
1477
|
-
this._serverTeamUserPermissionsCache = createCache(async ([teamId, userId, recursive]) => {
|
|
1478
|
-
return await this._interface.listServerTeamPermissions({ teamId, userId, recursive }, null);
|
|
1479
|
-
});
|
|
1480
|
-
this._serverUserOAuthConnectionAccessTokensCache = createCache(
|
|
1481
|
-
async ([userId, providerId, scope]) => {
|
|
1482
|
-
try {
|
|
1483
|
-
const result = await this._interface.createServerProviderAccessToken(userId, providerId, scope || "");
|
|
1484
|
-
return { accessToken: result.access_token };
|
|
1485
|
-
} catch (err) {
|
|
1486
|
-
if (!(err instanceof KnownErrors.OAuthConnectionDoesNotHaveRequiredScope || err instanceof KnownErrors.OAuthConnectionNotConnectedToUser)) {
|
|
1487
|
-
throw err;
|
|
1488
|
-
}
|
|
1489
|
-
}
|
|
1490
|
-
return null;
|
|
1491
|
-
}
|
|
1492
|
-
);
|
|
1493
|
-
this._serverUserOAuthConnectionCache = createCache(
|
|
1494
|
-
async ([userId, providerId, scope, redirect]) => {
|
|
1495
|
-
return await this._getUserOAuthConnectionCacheFn({
|
|
1496
|
-
getUser: async () => Result.orThrow(await this._serverUserCache.getOrWait([userId], "write-only")),
|
|
1497
|
-
getOrWaitOAuthToken: async () => Result.orThrow(await this._serverUserOAuthConnectionAccessTokensCache.getOrWait([userId, providerId, scope || ""], "write-only")),
|
|
1498
|
-
useOAuthToken: () => useAsyncCache(this._serverUserOAuthConnectionAccessTokensCache, [userId, providerId, scope || ""], "user.useConnectedAccount()"),
|
|
1499
|
-
providerId,
|
|
1500
|
-
scope,
|
|
1501
|
-
redirect,
|
|
1502
|
-
session: null
|
|
1503
|
-
});
|
|
1504
|
-
}
|
|
1505
|
-
);
|
|
1506
|
-
this._serverTeamMemberProfilesCache = createCache(
|
|
1507
|
-
async ([teamId]) => {
|
|
1508
|
-
return await this._interface.listServerTeamMemberProfiles({ teamId });
|
|
1509
|
-
}
|
|
1510
|
-
);
|
|
1511
|
-
this._serverTeamInvitationsCache = createCache(
|
|
1512
|
-
async ([teamId]) => {
|
|
1513
|
-
return await this._interface.listServerTeamInvitations({ teamId });
|
|
1514
|
-
}
|
|
1515
|
-
);
|
|
1516
|
-
this._serverUserTeamProfileCache = createCache(
|
|
1517
|
-
async ([teamId, userId]) => {
|
|
1518
|
-
return await this._interface.getServerTeamMemberProfile({ teamId, userId });
|
|
1519
|
-
}
|
|
1520
|
-
);
|
|
1521
|
-
this._serverContactChannelsCache = createCache(
|
|
1522
|
-
async ([userId]) => {
|
|
1523
|
-
return await this._interface.listServerContactChannels(userId);
|
|
1524
|
-
}
|
|
1525
|
-
);
|
|
1526
|
-
}
|
|
1527
|
-
async _updateServerUser(userId, update) {
|
|
1528
|
-
const result = await this._interface.updateServerUser(userId, serverUserUpdateOptionsToCrud(update));
|
|
1529
|
-
await this._refreshUsers();
|
|
1530
|
-
return result;
|
|
1531
|
-
}
|
|
1532
|
-
_serverEditableTeamProfileFromCrud(crud) {
|
|
1533
|
-
const app = this;
|
|
1534
|
-
return {
|
|
1535
|
-
displayName: crud.display_name,
|
|
1536
|
-
profileImageUrl: crud.profile_image_url,
|
|
1537
|
-
async update(update) {
|
|
1538
|
-
await app._interface.updateServerTeamMemberProfile({
|
|
1539
|
-
teamId: crud.team_id,
|
|
1540
|
-
userId: crud.user_id,
|
|
1541
|
-
profile: {
|
|
1542
|
-
display_name: update.displayName,
|
|
1543
|
-
profile_image_url: update.profileImageUrl
|
|
1544
|
-
}
|
|
1545
|
-
});
|
|
1546
|
-
await app._serverUserTeamProfileCache.refresh([crud.team_id, crud.user_id]);
|
|
1547
|
-
}
|
|
1548
|
-
};
|
|
1549
|
-
}
|
|
1550
|
-
_serverContactChannelFromCrud(userId, crud) {
|
|
1551
|
-
const app = this;
|
|
1552
|
-
return {
|
|
1553
|
-
id: crud.id,
|
|
1554
|
-
value: crud.value,
|
|
1555
|
-
type: crud.type,
|
|
1556
|
-
isVerified: crud.is_verified,
|
|
1557
|
-
isPrimary: crud.is_primary,
|
|
1558
|
-
usedForAuth: crud.used_for_auth,
|
|
1559
|
-
async sendVerificationEmail(options) {
|
|
1560
|
-
if (!options?.callbackUrl && !await app._getCurrentUrl()) {
|
|
1561
|
-
throw new Error("Cannot send verification email without a callback URL from the server or without a redirect method. Make sure you pass the `callbackUrl` option: `sendVerificationEmail({ callbackUrl: ... })`");
|
|
1562
|
-
}
|
|
1563
|
-
await app._interface.sendServerContactChannelVerificationEmail(userId, crud.id, options?.callbackUrl ?? constructRedirectUrl(app.urls.emailVerification));
|
|
1564
|
-
},
|
|
1565
|
-
async update(data) {
|
|
1566
|
-
await app._interface.updateServerContactChannel(userId, crud.id, serverContactChannelUpdateOptionsToCrud(data));
|
|
1567
|
-
},
|
|
1568
|
-
async delete() {
|
|
1569
|
-
await app._interface.deleteServerContactChannel(userId, crud.id);
|
|
1570
|
-
}
|
|
1571
|
-
};
|
|
1572
|
-
}
|
|
1573
|
-
_serverUserFromCrud(crud) {
|
|
1574
|
-
const app = this;
|
|
1575
|
-
async function getConnectedAccount(id, options) {
|
|
1576
|
-
const scopeString = options?.scopes?.join(" ");
|
|
1577
|
-
return Result.orThrow(await app._serverUserOAuthConnectionCache.getOrWait([crud.id, id, scopeString || "", options?.or === "redirect"], "write-only"));
|
|
1578
|
-
}
|
|
1579
|
-
function useConnectedAccount(id, options) {
|
|
1580
|
-
const scopeString = options?.scopes?.join(" ");
|
|
1581
|
-
return useAsyncCache(app._serverUserOAuthConnectionCache, [crud.id, id, scopeString || "", options?.or === "redirect"], "user.useConnectedAccount()");
|
|
1582
|
-
}
|
|
1583
|
-
return {
|
|
1584
|
-
...super._createBaseUser(crud),
|
|
1585
|
-
lastActiveAt: new Date(crud.last_active_at_millis),
|
|
1586
|
-
serverMetadata: crud.server_metadata,
|
|
1587
|
-
async setPrimaryEmail(email, options) {
|
|
1588
|
-
await app._updateServerUser(crud.id, { primaryEmail: email, primaryEmailVerified: options?.verified });
|
|
1589
|
-
},
|
|
1590
|
-
async grantPermission(scope, permissionId) {
|
|
1591
|
-
await app._interface.grantServerTeamUserPermission(scope.id, crud.id, permissionId);
|
|
1592
|
-
for (const recursive of [true, false]) {
|
|
1593
|
-
await app._serverTeamUserPermissionsCache.refresh([scope.id, crud.id, recursive]);
|
|
1594
|
-
}
|
|
1595
|
-
},
|
|
1596
|
-
async revokePermission(scope, permissionId) {
|
|
1597
|
-
await app._interface.revokeServerTeamUserPermission(scope.id, crud.id, permissionId);
|
|
1598
|
-
for (const recursive of [true, false]) {
|
|
1599
|
-
await app._serverTeamUserPermissionsCache.refresh([scope.id, crud.id, recursive]);
|
|
1600
|
-
}
|
|
1601
|
-
},
|
|
1602
|
-
async delete() {
|
|
1603
|
-
const res = await app._interface.deleteServerServerUser(crud.id);
|
|
1604
|
-
await app._refreshUsers();
|
|
1605
|
-
return res;
|
|
1606
|
-
},
|
|
1607
|
-
async createSession(options) {
|
|
1608
|
-
const tokens = await app._interface.createServerUserSession(crud.id, options.expiresInMillis ?? 1e3 * 60 * 60 * 24 * 365);
|
|
1609
|
-
return {
|
|
1610
|
-
async getTokens() {
|
|
1611
|
-
return tokens;
|
|
1612
|
-
}
|
|
1613
|
-
};
|
|
1614
|
-
},
|
|
1615
|
-
async setDisplayName(displayName) {
|
|
1616
|
-
return await this.update({ displayName });
|
|
1617
|
-
},
|
|
1618
|
-
async setClientMetadata(metadata) {
|
|
1619
|
-
return await this.update({ clientMetadata: metadata });
|
|
1620
|
-
},
|
|
1621
|
-
async setClientReadOnlyMetadata(metadata) {
|
|
1622
|
-
return await this.update({ clientReadOnlyMetadata: metadata });
|
|
1623
|
-
},
|
|
1624
|
-
async setServerMetadata(metadata) {
|
|
1625
|
-
return await this.update({ serverMetadata: metadata });
|
|
1626
|
-
},
|
|
1627
|
-
async setSelectedTeam(team) {
|
|
1628
|
-
return await this.update({ selectedTeamId: team?.id ?? null });
|
|
1629
|
-
},
|
|
1630
|
-
getConnectedAccount,
|
|
1631
|
-
useConnectedAccount,
|
|
1632
|
-
selectedTeam: crud.selected_team ? app._serverTeamFromCrud(crud.selected_team) : null,
|
|
1633
|
-
async getTeam(teamId) {
|
|
1634
|
-
const teams = await this.listTeams();
|
|
1635
|
-
return teams.find((t) => t.id === teamId) ?? null;
|
|
1636
|
-
},
|
|
1637
|
-
useTeam(teamId) {
|
|
1638
|
-
const teams = this.useTeams();
|
|
1639
|
-
return useMemo(() => {
|
|
1640
|
-
return teams.find((t) => t.id === teamId) ?? null;
|
|
1641
|
-
}, [teams, teamId]);
|
|
1642
|
-
},
|
|
1643
|
-
async listTeams() {
|
|
1644
|
-
const teams = Result.orThrow(await app._serverTeamsCache.getOrWait([crud.id], "write-only"));
|
|
1645
|
-
return teams.map((t) => app._serverTeamFromCrud(t));
|
|
1646
|
-
},
|
|
1647
|
-
useTeams() {
|
|
1648
|
-
const teams = useAsyncCache(app._serverTeamsCache, [crud.id], "user.useTeams()");
|
|
1649
|
-
return useMemo(() => teams.map((t) => app._serverTeamFromCrud(t)), [teams]);
|
|
1650
|
-
},
|
|
1651
|
-
createTeam: async (data) => {
|
|
1652
|
-
const team = await app._interface.createServerTeam(serverTeamCreateOptionsToCrud({
|
|
1653
|
-
creatorUserId: crud.id,
|
|
1654
|
-
...data
|
|
1655
|
-
}));
|
|
1656
|
-
await app._serverTeamsCache.refresh([void 0]);
|
|
1657
|
-
return app._serverTeamFromCrud(team);
|
|
1658
|
-
},
|
|
1659
|
-
leaveTeam: async (team) => {
|
|
1660
|
-
await app._interface.leaveServerTeam({ teamId: team.id, userId: crud.id });
|
|
1661
|
-
},
|
|
1662
|
-
async listPermissions(scope, options) {
|
|
1663
|
-
const recursive = options?.recursive ?? true;
|
|
1664
|
-
const permissions = Result.orThrow(await app._serverTeamUserPermissionsCache.getOrWait([scope.id, crud.id, recursive], "write-only"));
|
|
1665
|
-
return permissions.map((crud2) => app._serverPermissionFromCrud(crud2));
|
|
1666
|
-
},
|
|
1667
|
-
usePermissions(scope, options) {
|
|
1668
|
-
const recursive = options?.recursive ?? true;
|
|
1669
|
-
const permissions = useAsyncCache(app._serverTeamUserPermissionsCache, [scope.id, crud.id, recursive], "user.usePermissions()");
|
|
1670
|
-
return useMemo(() => permissions.map((crud2) => app._serverPermissionFromCrud(crud2)), [permissions]);
|
|
1671
|
-
},
|
|
1672
|
-
async getPermission(scope, permissionId) {
|
|
1673
|
-
const permissions = await this.listPermissions(scope);
|
|
1674
|
-
return permissions.find((p) => p.id === permissionId) ?? null;
|
|
1675
|
-
},
|
|
1676
|
-
usePermission(scope, permissionId) {
|
|
1677
|
-
const permissions = this.usePermissions(scope);
|
|
1678
|
-
return useMemo(() => permissions.find((p) => p.id === permissionId) ?? null, [permissions, permissionId]);
|
|
1679
|
-
},
|
|
1680
|
-
async hasPermission(scope, permissionId) {
|
|
1681
|
-
return await this.getPermission(scope, permissionId) !== null;
|
|
1682
|
-
},
|
|
1683
|
-
async update(update) {
|
|
1684
|
-
await app._updateServerUser(crud.id, update);
|
|
1685
|
-
},
|
|
1686
|
-
async sendVerificationEmail() {
|
|
1687
|
-
return await app._checkFeatureSupport("sendVerificationEmail() on ServerUser", {});
|
|
1688
|
-
},
|
|
1689
|
-
async updatePassword(options) {
|
|
1690
|
-
const result = await this.update({ password: options.newPassword });
|
|
1691
|
-
await app._serverUserCache.refresh([crud.id]);
|
|
1692
|
-
return result;
|
|
1693
|
-
},
|
|
1694
|
-
async setPassword(options) {
|
|
1695
|
-
const result = await this.update(options);
|
|
1696
|
-
await app._serverUserCache.refresh([crud.id]);
|
|
1697
|
-
return result;
|
|
1698
|
-
},
|
|
1699
|
-
async getTeamProfile(team) {
|
|
1700
|
-
const result = Result.orThrow(await app._serverUserTeamProfileCache.getOrWait([team.id, crud.id], "write-only"));
|
|
1701
|
-
return app._serverEditableTeamProfileFromCrud(result);
|
|
1702
|
-
},
|
|
1703
|
-
useTeamProfile(team) {
|
|
1704
|
-
const result = useAsyncCache(app._serverUserTeamProfileCache, [team.id, crud.id], "user.useTeamProfile()");
|
|
1705
|
-
return useMemo(() => app._serverEditableTeamProfileFromCrud(result), [result]);
|
|
1706
|
-
},
|
|
1707
|
-
async listContactChannels() {
|
|
1708
|
-
const result = Result.orThrow(await app._serverContactChannelsCache.getOrWait([crud.id], "write-only"));
|
|
1709
|
-
return result.map((data) => app._serverContactChannelFromCrud(crud.id, data));
|
|
1710
|
-
},
|
|
1711
|
-
useContactChannels() {
|
|
1712
|
-
const result = useAsyncCache(app._serverContactChannelsCache, [crud.id], "user.useContactChannels()");
|
|
1713
|
-
return useMemo(() => result.map((data) => app._serverContactChannelFromCrud(crud.id, data)), [result]);
|
|
1714
|
-
},
|
|
1715
|
-
createContactChannel: async (data) => {
|
|
1716
|
-
const contactChannel = await app._interface.createServerContactChannel(serverContactChannelCreateOptionsToCrud(crud.id, data));
|
|
1717
|
-
await app._serverContactChannelsCache.refresh([crud.id]);
|
|
1718
|
-
return app._serverContactChannelFromCrud(crud.id, contactChannel);
|
|
1719
|
-
}
|
|
1720
|
-
};
|
|
1721
|
-
}
|
|
1722
|
-
_serverTeamUserFromCrud(crud) {
|
|
1723
|
-
return {
|
|
1724
|
-
...this._serverUserFromCrud(crud.user),
|
|
1725
|
-
teamProfile: {
|
|
1726
|
-
displayName: crud.display_name,
|
|
1727
|
-
profileImageUrl: crud.profile_image_url
|
|
1728
|
-
}
|
|
1729
|
-
};
|
|
1730
|
-
}
|
|
1731
|
-
_serverTeamInvitationFromCrud(crud) {
|
|
1732
|
-
return {
|
|
1733
|
-
id: crud.id,
|
|
1734
|
-
recipientEmail: crud.recipient_email,
|
|
1735
|
-
expiresAt: new Date(crud.expires_at_millis),
|
|
1736
|
-
revoke: async () => {
|
|
1737
|
-
await this._interface.revokeServerTeamInvitation(crud.id, crud.team_id);
|
|
1738
|
-
}
|
|
1739
|
-
};
|
|
1740
|
-
}
|
|
1741
|
-
_currentUserFromCrud(crud, session) {
|
|
1742
|
-
const app = this;
|
|
1743
|
-
const currentUser = {
|
|
1744
|
-
...this._serverUserFromCrud(crud),
|
|
1745
|
-
...this._createAuth(session),
|
|
1746
|
-
...this._isInternalProject() ? this._createInternalUserExtra(session) : {}
|
|
1747
|
-
};
|
|
1748
|
-
Object.freeze(currentUser);
|
|
1749
|
-
return currentUser;
|
|
1750
|
-
}
|
|
1751
|
-
_serverTeamFromCrud(crud) {
|
|
1752
|
-
const app = this;
|
|
1753
|
-
return {
|
|
1754
|
-
id: crud.id,
|
|
1755
|
-
displayName: crud.display_name,
|
|
1756
|
-
profileImageUrl: crud.profile_image_url,
|
|
1757
|
-
createdAt: new Date(crud.created_at_millis),
|
|
1758
|
-
clientMetadata: crud.client_metadata,
|
|
1759
|
-
clientReadOnlyMetadata: crud.client_read_only_metadata,
|
|
1760
|
-
serverMetadata: crud.server_metadata,
|
|
1761
|
-
async update(update) {
|
|
1762
|
-
await app._interface.updateServerTeam(crud.id, serverTeamUpdateOptionsToCrud(update));
|
|
1763
|
-
await app._serverTeamsCache.refresh([void 0]);
|
|
1764
|
-
},
|
|
1765
|
-
async delete() {
|
|
1766
|
-
await app._interface.deleteServerTeam(crud.id);
|
|
1767
|
-
await app._serverTeamsCache.refresh([void 0]);
|
|
1768
|
-
},
|
|
1769
|
-
async listUsers() {
|
|
1770
|
-
const result = Result.orThrow(await app._serverTeamMemberProfilesCache.getOrWait([crud.id], "write-only"));
|
|
1771
|
-
return result.map((u) => app._serverTeamUserFromCrud(u));
|
|
1772
|
-
},
|
|
1773
|
-
useUsers() {
|
|
1774
|
-
const result = useAsyncCache(app._serverTeamMemberProfilesCache, [crud.id], "team.useUsers()");
|
|
1775
|
-
return useMemo(() => result.map((u) => app._serverTeamUserFromCrud(u)), [result]);
|
|
1776
|
-
},
|
|
1777
|
-
async addUser(userId) {
|
|
1778
|
-
await app._interface.addServerUserToTeam({
|
|
1779
|
-
teamId: crud.id,
|
|
1780
|
-
userId
|
|
1781
|
-
});
|
|
1782
|
-
await app._serverTeamMemberProfilesCache.refresh([crud.id]);
|
|
1783
|
-
},
|
|
1784
|
-
async removeUser(userId) {
|
|
1785
|
-
await app._interface.removeServerUserFromTeam({
|
|
1786
|
-
teamId: crud.id,
|
|
1787
|
-
userId
|
|
1788
|
-
});
|
|
1789
|
-
await app._serverTeamMemberProfilesCache.refresh([crud.id]);
|
|
1790
|
-
},
|
|
1791
|
-
async inviteUser(options) {
|
|
1792
|
-
if (!options.callbackUrl && !await app._getCurrentUrl()) {
|
|
1793
|
-
throw new Error("Cannot invite user without a callback URL from the server or without a redirect method. Make sure you pass the `callbackUrl` option: `inviteUser({ email, callbackUrl: ... })`");
|
|
1794
|
-
}
|
|
1795
|
-
await app._interface.sendServerTeamInvitation({
|
|
1796
|
-
teamId: crud.id,
|
|
1797
|
-
email: options.email,
|
|
1798
|
-
callbackUrl: options.callbackUrl ?? constructRedirectUrl(app.urls.teamInvitation)
|
|
1799
|
-
});
|
|
1800
|
-
await app._serverTeamInvitationsCache.refresh([crud.id]);
|
|
1801
|
-
},
|
|
1802
|
-
async listInvitations() {
|
|
1803
|
-
const result = Result.orThrow(await app._serverTeamInvitationsCache.getOrWait([crud.id], "write-only"));
|
|
1804
|
-
return result.map((crud2) => app._serverTeamInvitationFromCrud(crud2));
|
|
1805
|
-
},
|
|
1806
|
-
useInvitations() {
|
|
1807
|
-
const result = useAsyncCache(app._serverTeamInvitationsCache, [crud.id], "team.useInvitations()");
|
|
1808
|
-
return useMemo(() => result.map((crud2) => app._serverTeamInvitationFromCrud(crud2)), [result]);
|
|
1809
|
-
}
|
|
1810
|
-
};
|
|
1811
|
-
}
|
|
1812
|
-
async createUser(options) {
|
|
1813
|
-
const crud = await this._interface.createServerUser(serverUserCreateOptionsToCrud(options));
|
|
1814
|
-
await this._refreshUsers();
|
|
1815
|
-
return this._serverUserFromCrud(crud);
|
|
1816
|
-
}
|
|
1817
|
-
async getUser(options) {
|
|
1818
|
-
if (typeof options === "string") {
|
|
1819
|
-
return await this.getServerUserById(options);
|
|
1820
|
-
} else {
|
|
1821
|
-
this._ensurePersistentTokenStore(options?.tokenStore);
|
|
1822
|
-
const session = await this._getSession(options?.tokenStore);
|
|
1823
|
-
const crud = Result.orThrow(await this._currentServerUserCache.getOrWait([session], "write-only"));
|
|
1824
|
-
if (crud === null) {
|
|
1825
|
-
switch (options?.or) {
|
|
1826
|
-
case "redirect": {
|
|
1827
|
-
await this.redirectToSignIn({ replace: true });
|
|
1828
|
-
break;
|
|
1829
|
-
}
|
|
1830
|
-
case "throw": {
|
|
1831
|
-
throw new Error("User is not signed in but getUser was called with { or: 'throw' }");
|
|
1832
|
-
}
|
|
1833
|
-
default: {
|
|
1834
|
-
return null;
|
|
1835
|
-
}
|
|
1836
|
-
}
|
|
1837
|
-
}
|
|
1838
|
-
return crud && this._currentUserFromCrud(crud, session);
|
|
1839
|
-
}
|
|
1840
|
-
}
|
|
1841
|
-
async getServerUser() {
|
|
1842
|
-
console.warn("stackServerApp.getServerUser is deprecated; use stackServerApp.getUser instead");
|
|
1843
|
-
return await this.getUser();
|
|
1844
|
-
}
|
|
1845
|
-
async getServerUserById(userId) {
|
|
1846
|
-
const crud = Result.orThrow(await this._serverUserCache.getOrWait([userId], "write-only"));
|
|
1847
|
-
return crud && this._serverUserFromCrud(crud);
|
|
1848
|
-
}
|
|
1849
|
-
useUser(options) {
|
|
1850
|
-
if (typeof options === "string") {
|
|
1851
|
-
return this.useUserById(options);
|
|
1852
|
-
} else {
|
|
1853
|
-
this._ensurePersistentTokenStore(options?.tokenStore);
|
|
1854
|
-
const session = this._useSession(options?.tokenStore);
|
|
1855
|
-
const crud = useAsyncCache(this._currentServerUserCache, [session], "useUser()");
|
|
1856
|
-
if (crud === null) {
|
|
1857
|
-
switch (options?.or) {
|
|
1858
|
-
case "redirect": {
|
|
1859
|
-
runAsynchronously(this.redirectToSignIn({ replace: true }));
|
|
1860
|
-
suspend();
|
|
1861
|
-
throw new StackAssertionError("suspend should never return");
|
|
1862
|
-
}
|
|
1863
|
-
case "throw": {
|
|
1864
|
-
throw new Error("User is not signed in but useUser was called with { or: 'throw' }");
|
|
1865
|
-
}
|
|
1866
|
-
case void 0:
|
|
1867
|
-
case "return-null": {
|
|
1868
|
-
}
|
|
1869
|
-
}
|
|
1870
|
-
}
|
|
1871
|
-
return useMemo(() => {
|
|
1872
|
-
return crud && this._currentUserFromCrud(crud, session);
|
|
1873
|
-
}, [crud, session, options?.or]);
|
|
1874
|
-
}
|
|
1875
|
-
}
|
|
1876
|
-
useUserById(userId) {
|
|
1877
|
-
const crud = useAsyncCache(this._serverUserCache, [userId], "useUserById()");
|
|
1878
|
-
return useMemo(() => {
|
|
1879
|
-
return crud && this._serverUserFromCrud(crud);
|
|
1880
|
-
}, [crud]);
|
|
1881
|
-
}
|
|
1882
|
-
async listUsers(options) {
|
|
1883
|
-
const crud = Result.orThrow(await this._serverUsersCache.getOrWait([options?.cursor, options?.limit, options?.orderBy, options?.desc, options?.query], "write-only"));
|
|
1884
|
-
const result = crud.items.map((j) => this._serverUserFromCrud(j));
|
|
1885
|
-
result.nextCursor = crud.pagination?.next_cursor ?? null;
|
|
1886
|
-
return result;
|
|
1887
|
-
}
|
|
1888
|
-
useUsers(options) {
|
|
1889
|
-
const crud = useAsyncCache(this._serverUsersCache, [options?.cursor, options?.limit, options?.orderBy, options?.desc, options?.query], "useServerUsers()");
|
|
1890
|
-
const result = crud.items.map((j) => this._serverUserFromCrud(j));
|
|
1891
|
-
result.nextCursor = crud.pagination?.next_cursor ?? null;
|
|
1892
|
-
return result;
|
|
1893
|
-
}
|
|
1894
|
-
_serverPermissionFromCrud(crud) {
|
|
1895
|
-
return {
|
|
1896
|
-
id: crud.id
|
|
1897
|
-
};
|
|
1898
|
-
}
|
|
1899
|
-
_serverTeamPermissionDefinitionFromCrud(crud) {
|
|
1900
|
-
return {
|
|
1901
|
-
id: crud.id,
|
|
1902
|
-
description: crud.description,
|
|
1903
|
-
containedPermissionIds: crud.contained_permission_ids
|
|
1904
|
-
};
|
|
1905
|
-
}
|
|
1906
|
-
async listTeams() {
|
|
1907
|
-
const teams = Result.orThrow(await this._serverTeamsCache.getOrWait([void 0], "write-only"));
|
|
1908
|
-
return teams.map((t) => this._serverTeamFromCrud(t));
|
|
1909
|
-
}
|
|
1910
|
-
async createTeam(data) {
|
|
1911
|
-
const team = await this._interface.createServerTeam(serverTeamCreateOptionsToCrud(data));
|
|
1912
|
-
await this._serverTeamsCache.refresh([void 0]);
|
|
1913
|
-
return this._serverTeamFromCrud(team);
|
|
1914
|
-
}
|
|
1915
|
-
useTeams() {
|
|
1916
|
-
const teams = useAsyncCache(this._serverTeamsCache, [void 0], "useServerTeams()");
|
|
1917
|
-
return useMemo(() => {
|
|
1918
|
-
return teams.map((t) => this._serverTeamFromCrud(t));
|
|
1919
|
-
}, [teams]);
|
|
1920
|
-
}
|
|
1921
|
-
async getTeam(teamId) {
|
|
1922
|
-
const teams = await this.listTeams();
|
|
1923
|
-
return teams.find((t) => t.id === teamId) ?? null;
|
|
1924
|
-
}
|
|
1925
|
-
useTeam(teamId) {
|
|
1926
|
-
const teams = this.useTeams();
|
|
1927
|
-
return useMemo(() => {
|
|
1928
|
-
return teams.find((t) => t.id === teamId) ?? null;
|
|
1929
|
-
}, [teams, teamId]);
|
|
1930
|
-
}
|
|
1931
|
-
async _refreshSession(session) {
|
|
1932
|
-
await Promise.all([
|
|
1933
|
-
super._refreshUser(session),
|
|
1934
|
-
this._currentServerUserCache.refresh([session])
|
|
1935
|
-
]);
|
|
1936
|
-
}
|
|
1937
|
-
async _refreshUsers() {
|
|
1938
|
-
await Promise.all([
|
|
1939
|
-
super._refreshUsers(),
|
|
1940
|
-
this._serverUserCache.refreshWhere(() => true),
|
|
1941
|
-
this._serverUsersCache.refreshWhere(() => true),
|
|
1942
|
-
this._serverContactChannelsCache.refreshWhere(() => true)
|
|
1943
|
-
]);
|
|
1944
|
-
}
|
|
1945
|
-
};
|
|
1946
|
-
var _StackAdminAppImpl = class extends _StackServerAppImpl {
|
|
1947
|
-
constructor(options) {
|
|
1948
|
-
super({
|
|
1949
|
-
interface: new StackAdminInterface({
|
|
1950
|
-
getBaseUrl: () => getBaseUrl(options.baseUrl),
|
|
1951
|
-
projectId: options.projectId ?? getDefaultProjectId(),
|
|
1952
|
-
clientVersion,
|
|
1953
|
-
..."projectOwnerSession" in options ? {
|
|
1954
|
-
projectOwnerSession: options.projectOwnerSession
|
|
1955
|
-
} : {
|
|
1956
|
-
publishableClientKey: options.publishableClientKey ?? getDefaultPublishableClientKey(),
|
|
1957
|
-
secretServerKey: options.secretServerKey ?? getDefaultSecretServerKey(),
|
|
1958
|
-
superSecretAdminKey: options.superSecretAdminKey ?? getDefaultSuperSecretAdminKey()
|
|
1959
|
-
}
|
|
1960
|
-
}),
|
|
1961
|
-
baseUrl: options.baseUrl,
|
|
1962
|
-
projectId: options.projectId,
|
|
1963
|
-
tokenStore: options.tokenStore,
|
|
1964
|
-
urls: options.urls,
|
|
1965
|
-
oauthScopesOnSignIn: options.oauthScopesOnSignIn,
|
|
1966
|
-
redirectMethod: options.redirectMethod
|
|
1967
|
-
});
|
|
1968
|
-
this._adminProjectCache = createCache(async () => {
|
|
1969
|
-
return await this._interface.getProject();
|
|
1970
|
-
});
|
|
1971
|
-
this._apiKeysCache = createCache(async () => {
|
|
1972
|
-
return await this._interface.listApiKeys();
|
|
1973
|
-
});
|
|
1974
|
-
this._adminEmailTemplatesCache = createCache(async () => {
|
|
1975
|
-
return await this._interface.listEmailTemplates();
|
|
1976
|
-
});
|
|
1977
|
-
this._adminTeamPermissionDefinitionsCache = createCache(async () => {
|
|
1978
|
-
return await this._interface.listPermissionDefinitions();
|
|
1979
|
-
});
|
|
1980
|
-
this._svixTokenCache = createCache(async () => {
|
|
1981
|
-
return await this._interface.getSvixToken();
|
|
1982
|
-
});
|
|
1983
|
-
this._metricsCache = createCache(async () => {
|
|
1984
|
-
return await this._interface.getMetrics();
|
|
1985
|
-
});
|
|
1986
|
-
}
|
|
1987
|
-
_adminOwnedProjectFromCrud(data, onRefresh) {
|
|
1988
|
-
if (this._tokenStoreInit !== null) {
|
|
1989
|
-
throw new StackAssertionError("Owned apps must always have tokenStore === null \u2014 did you not create this project with app._createOwnedApp()?");
|
|
1990
|
-
;
|
|
1991
|
-
}
|
|
1992
|
-
return {
|
|
1993
|
-
...this._adminProjectFromCrud(data, onRefresh),
|
|
1994
|
-
app: this
|
|
1995
|
-
};
|
|
1996
|
-
}
|
|
1997
|
-
_adminProjectFromCrud(data, onRefresh) {
|
|
1998
|
-
if (data.id !== this.projectId) {
|
|
1999
|
-
throw new StackAssertionError(`The project ID of the provided project JSON (${data.id}) does not match the project ID of the app (${this.projectId})!`);
|
|
2000
|
-
}
|
|
2001
|
-
const app = this;
|
|
2002
|
-
return {
|
|
2003
|
-
id: data.id,
|
|
2004
|
-
displayName: data.display_name,
|
|
2005
|
-
description: data.description,
|
|
2006
|
-
createdAt: new Date(data.created_at_millis),
|
|
2007
|
-
userCount: data.user_count,
|
|
2008
|
-
isProductionMode: data.is_production_mode,
|
|
2009
|
-
config: {
|
|
2010
|
-
id: data.config.id,
|
|
2011
|
-
signUpEnabled: data.config.sign_up_enabled,
|
|
2012
|
-
credentialEnabled: data.config.credential_enabled,
|
|
2013
|
-
magicLinkEnabled: data.config.magic_link_enabled,
|
|
2014
|
-
passkeyEnabled: data.config.passkey_enabled,
|
|
2015
|
-
clientTeamCreationEnabled: data.config.client_team_creation_enabled,
|
|
2016
|
-
clientUserDeletionEnabled: data.config.client_user_deletion_enabled,
|
|
2017
|
-
allowLocalhost: data.config.allow_localhost,
|
|
2018
|
-
oauthProviders: data.config.oauth_providers.map((p) => p.type === "shared" ? {
|
|
2019
|
-
id: p.id,
|
|
2020
|
-
enabled: p.enabled,
|
|
2021
|
-
type: "shared"
|
|
2022
|
-
} : {
|
|
2023
|
-
id: p.id,
|
|
2024
|
-
enabled: p.enabled,
|
|
2025
|
-
type: "standard",
|
|
2026
|
-
clientId: p.client_id ?? throwErr("Client ID is missing"),
|
|
2027
|
-
clientSecret: p.client_secret ?? throwErr("Client secret is missing"),
|
|
2028
|
-
facebookConfigId: p.facebook_config_id,
|
|
2029
|
-
microsoftTenantId: p.microsoft_tenant_id
|
|
2030
|
-
}),
|
|
2031
|
-
emailConfig: data.config.email_config.type === "shared" ? {
|
|
2032
|
-
type: "shared"
|
|
2033
|
-
} : {
|
|
2034
|
-
type: "standard",
|
|
2035
|
-
host: data.config.email_config.host ?? throwErr("Email host is missing"),
|
|
2036
|
-
port: data.config.email_config.port ?? throwErr("Email port is missing"),
|
|
2037
|
-
username: data.config.email_config.username ?? throwErr("Email username is missing"),
|
|
2038
|
-
password: data.config.email_config.password ?? throwErr("Email password is missing"),
|
|
2039
|
-
senderName: data.config.email_config.sender_name ?? throwErr("Email sender name is missing"),
|
|
2040
|
-
senderEmail: data.config.email_config.sender_email ?? throwErr("Email sender email is missing")
|
|
2041
|
-
},
|
|
2042
|
-
domains: data.config.domains.map((d) => ({
|
|
2043
|
-
domain: d.domain,
|
|
2044
|
-
handlerPath: d.handler_path
|
|
2045
|
-
})),
|
|
2046
|
-
createTeamOnSignUp: data.config.create_team_on_sign_up,
|
|
2047
|
-
teamCreatorDefaultPermissions: data.config.team_creator_default_permissions,
|
|
2048
|
-
teamMemberDefaultPermissions: data.config.team_member_default_permissions
|
|
2049
|
-
},
|
|
2050
|
-
async update(update) {
|
|
2051
|
-
await app._interface.updateProject(adminProjectUpdateOptionsToCrud(update));
|
|
2052
|
-
await onRefresh();
|
|
2053
|
-
},
|
|
2054
|
-
async delete() {
|
|
2055
|
-
await app._interface.deleteProject();
|
|
2056
|
-
},
|
|
2057
|
-
async getProductionModeErrors() {
|
|
2058
|
-
return getProductionModeErrors(data);
|
|
2059
|
-
},
|
|
2060
|
-
useProductionModeErrors() {
|
|
2061
|
-
return getProductionModeErrors(data);
|
|
2062
|
-
}
|
|
2063
|
-
};
|
|
2064
|
-
}
|
|
2065
|
-
_adminEmailTemplateFromCrud(data) {
|
|
2066
|
-
return {
|
|
2067
|
-
type: data.type,
|
|
2068
|
-
subject: data.subject,
|
|
2069
|
-
content: data.content,
|
|
2070
|
-
isDefault: data.is_default
|
|
2071
|
-
};
|
|
2072
|
-
}
|
|
2073
|
-
async getProject() {
|
|
2074
|
-
return this._adminProjectFromCrud(
|
|
2075
|
-
Result.orThrow(await this._adminProjectCache.getOrWait([], "write-only")),
|
|
2076
|
-
() => this._refreshProject()
|
|
2077
|
-
);
|
|
2078
|
-
}
|
|
2079
|
-
useProject() {
|
|
2080
|
-
const crud = useAsyncCache(this._adminProjectCache, [], "useProjectAdmin()");
|
|
2081
|
-
return useMemo(() => this._adminProjectFromCrud(
|
|
2082
|
-
crud,
|
|
2083
|
-
() => this._refreshProject()
|
|
2084
|
-
), [crud]);
|
|
2085
|
-
}
|
|
2086
|
-
_createApiKeyBaseFromCrud(data) {
|
|
2087
|
-
const app = this;
|
|
2088
|
-
return {
|
|
2089
|
-
id: data.id,
|
|
2090
|
-
description: data.description,
|
|
2091
|
-
expiresAt: new Date(data.expires_at_millis),
|
|
2092
|
-
manuallyRevokedAt: data.manually_revoked_at_millis ? new Date(data.manually_revoked_at_millis) : null,
|
|
2093
|
-
createdAt: new Date(data.created_at_millis),
|
|
2094
|
-
isValid() {
|
|
2095
|
-
return this.whyInvalid() === null;
|
|
2096
|
-
},
|
|
2097
|
-
whyInvalid() {
|
|
2098
|
-
if (this.expiresAt.getTime() < Date.now()) return "expired";
|
|
2099
|
-
if (this.manuallyRevokedAt) return "manually-revoked";
|
|
2100
|
-
return null;
|
|
2101
|
-
},
|
|
2102
|
-
async revoke() {
|
|
2103
|
-
const res = await app._interface.revokeApiKeyById(data.id);
|
|
2104
|
-
await app._refreshApiKeys();
|
|
2105
|
-
return res;
|
|
2106
|
-
}
|
|
2107
|
-
};
|
|
2108
|
-
}
|
|
2109
|
-
_createApiKeyFromCrud(data) {
|
|
2110
|
-
return {
|
|
2111
|
-
...this._createApiKeyBaseFromCrud(data),
|
|
2112
|
-
publishableClientKey: data.publishable_client_key ? { lastFour: data.publishable_client_key.last_four } : null,
|
|
2113
|
-
secretServerKey: data.secret_server_key ? { lastFour: data.secret_server_key.last_four } : null,
|
|
2114
|
-
superSecretAdminKey: data.super_secret_admin_key ? { lastFour: data.super_secret_admin_key.last_four } : null
|
|
2115
|
-
};
|
|
2116
|
-
}
|
|
2117
|
-
_createApiKeyFirstViewFromCrud(data) {
|
|
2118
|
-
return {
|
|
2119
|
-
...this._createApiKeyBaseFromCrud(data),
|
|
2120
|
-
publishableClientKey: data.publishable_client_key,
|
|
2121
|
-
secretServerKey: data.secret_server_key,
|
|
2122
|
-
superSecretAdminKey: data.super_secret_admin_key
|
|
2123
|
-
};
|
|
2124
|
-
}
|
|
2125
|
-
async listApiKeys() {
|
|
2126
|
-
const crud = Result.orThrow(await this._apiKeysCache.getOrWait([], "write-only"));
|
|
2127
|
-
return crud.map((j) => this._createApiKeyFromCrud(j));
|
|
2128
|
-
}
|
|
2129
|
-
useApiKeys() {
|
|
2130
|
-
const crud = useAsyncCache(this._apiKeysCache, [], "useApiKeys()");
|
|
2131
|
-
return useMemo(() => {
|
|
2132
|
-
return crud.map((j) => this._createApiKeyFromCrud(j));
|
|
2133
|
-
}, [crud]);
|
|
2134
|
-
}
|
|
2135
|
-
async createApiKey(options) {
|
|
2136
|
-
const crud = await this._interface.createApiKey(apiKeyCreateOptionsToCrud(options));
|
|
2137
|
-
await this._refreshApiKeys();
|
|
2138
|
-
return this._createApiKeyFirstViewFromCrud(crud);
|
|
2139
|
-
}
|
|
2140
|
-
useEmailTemplates() {
|
|
2141
|
-
const crud = useAsyncCache(this._adminEmailTemplatesCache, [], "useEmailTemplates()");
|
|
2142
|
-
return useMemo(() => {
|
|
2143
|
-
return crud.map((j) => this._adminEmailTemplateFromCrud(j));
|
|
2144
|
-
}, [crud]);
|
|
2145
|
-
}
|
|
2146
|
-
async listEmailTemplates() {
|
|
2147
|
-
const crud = Result.orThrow(await this._adminEmailTemplatesCache.getOrWait([], "write-only"));
|
|
2148
|
-
return crud.map((j) => this._adminEmailTemplateFromCrud(j));
|
|
2149
|
-
}
|
|
2150
|
-
async updateEmailTemplate(type, data) {
|
|
2151
|
-
await this._interface.updateEmailTemplate(type, adminEmailTemplateUpdateOptionsToCrud(data));
|
|
2152
|
-
await this._adminEmailTemplatesCache.refresh([]);
|
|
2153
|
-
}
|
|
2154
|
-
async resetEmailTemplate(type) {
|
|
2155
|
-
await this._interface.resetEmailTemplate(type);
|
|
2156
|
-
await this._adminEmailTemplatesCache.refresh([]);
|
|
2157
|
-
}
|
|
2158
|
-
async createTeamPermissionDefinition(data) {
|
|
2159
|
-
const crud = await this._interface.createPermissionDefinition(serverTeamPermissionDefinitionCreateOptionsToCrud(data));
|
|
2160
|
-
await this._adminTeamPermissionDefinitionsCache.refresh([]);
|
|
2161
|
-
return this._serverTeamPermissionDefinitionFromCrud(crud);
|
|
2162
|
-
}
|
|
2163
|
-
async updateTeamPermissionDefinition(permissionId, data) {
|
|
2164
|
-
await this._interface.updatePermissionDefinition(permissionId, serverTeamPermissionDefinitionUpdateOptionsToCrud(data));
|
|
2165
|
-
await this._adminTeamPermissionDefinitionsCache.refresh([]);
|
|
2166
|
-
}
|
|
2167
|
-
async deleteTeamPermissionDefinition(permissionId) {
|
|
2168
|
-
await this._interface.deletePermissionDefinition(permissionId);
|
|
2169
|
-
await this._adminTeamPermissionDefinitionsCache.refresh([]);
|
|
2170
|
-
}
|
|
2171
|
-
async listTeamPermissionDefinitions() {
|
|
2172
|
-
const crud = Result.orThrow(await this._adminTeamPermissionDefinitionsCache.getOrWait([], "write-only"));
|
|
2173
|
-
return crud.map((p) => this._serverTeamPermissionDefinitionFromCrud(p));
|
|
2174
|
-
}
|
|
2175
|
-
useTeamPermissionDefinitions() {
|
|
2176
|
-
const crud = useAsyncCache(this._adminTeamPermissionDefinitionsCache, [], "usePermissions()");
|
|
2177
|
-
return useMemo(() => {
|
|
2178
|
-
return crud.map((p) => this._serverTeamPermissionDefinitionFromCrud(p));
|
|
2179
|
-
}, [crud]);
|
|
2180
|
-
}
|
|
2181
|
-
useSvixToken() {
|
|
2182
|
-
const crud = useAsyncCache(this._svixTokenCache, [], "useSvixToken()");
|
|
2183
|
-
return crud.token;
|
|
2184
|
-
}
|
|
2185
|
-
async _refreshProject() {
|
|
2186
|
-
await Promise.all([
|
|
2187
|
-
super._refreshProject(),
|
|
2188
|
-
this._adminProjectCache.refresh([])
|
|
2189
|
-
]);
|
|
2190
|
-
}
|
|
2191
|
-
async _refreshApiKeys() {
|
|
2192
|
-
await this._apiKeysCache.refresh([]);
|
|
2193
|
-
}
|
|
2194
|
-
get [stackAppInternalsSymbol]() {
|
|
2195
|
-
return {
|
|
2196
|
-
...super[stackAppInternalsSymbol],
|
|
2197
|
-
useMetrics: () => {
|
|
2198
|
-
return useAsyncCache(this._metricsCache, [], "useMetrics()");
|
|
2199
|
-
}
|
|
2200
|
-
};
|
|
2201
|
-
}
|
|
2202
|
-
async sendTestEmail(options) {
|
|
2203
|
-
const response = await this._interface.sendTestEmail({
|
|
2204
|
-
recipient_email: options.recipientEmail,
|
|
2205
|
-
email_config: {
|
|
2206
|
-
...pick(options.emailConfig, ["host", "port", "username", "password"]),
|
|
2207
|
-
sender_email: options.emailConfig.senderEmail,
|
|
2208
|
-
sender_name: options.emailConfig.senderName
|
|
2209
|
-
}
|
|
2210
|
-
});
|
|
2211
|
-
if (response.success) {
|
|
2212
|
-
return Result.ok(void 0);
|
|
2213
|
-
} else {
|
|
2214
|
-
return Result.error({ errorMessage: response.error_message ?? throwErr("Email test error not specified") });
|
|
2215
|
-
}
|
|
2216
|
-
}
|
|
2217
|
-
};
|
|
2218
|
-
function contactChannelCreateOptionsToCrud(userId, options) {
|
|
2219
|
-
return {
|
|
2220
|
-
value: options.value,
|
|
2221
|
-
type: options.type,
|
|
2222
|
-
used_for_auth: options.usedForAuth,
|
|
2223
|
-
user_id: userId
|
|
2224
|
-
};
|
|
2225
|
-
}
|
|
2226
|
-
function contactChannelUpdateOptionsToCrud(options) {
|
|
2227
|
-
return {
|
|
2228
|
-
value: options.value,
|
|
2229
|
-
used_for_auth: options.usedForAuth,
|
|
2230
|
-
is_primary: options.isPrimary
|
|
2231
|
-
};
|
|
2232
|
-
}
|
|
2233
|
-
function serverContactChannelUpdateOptionsToCrud(options) {
|
|
2234
|
-
return {
|
|
2235
|
-
value: options.value,
|
|
2236
|
-
is_verified: options.isVerified,
|
|
2237
|
-
used_for_auth: options.usedForAuth
|
|
2238
|
-
};
|
|
2239
|
-
}
|
|
2240
|
-
function serverContactChannelCreateOptionsToCrud(userId, options) {
|
|
2241
|
-
return {
|
|
2242
|
-
type: options.type,
|
|
2243
|
-
value: options.value,
|
|
2244
|
-
is_verified: options.isVerified,
|
|
2245
|
-
user_id: userId,
|
|
2246
|
-
used_for_auth: options.usedForAuth
|
|
2247
|
-
};
|
|
2248
|
-
}
|
|
2249
|
-
function userUpdateOptionsToCrud(options) {
|
|
2250
|
-
return {
|
|
2251
|
-
display_name: options.displayName,
|
|
2252
|
-
client_metadata: options.clientMetadata,
|
|
2253
|
-
selected_team_id: options.selectedTeamId,
|
|
2254
|
-
totp_secret_base64: options.totpMultiFactorSecret != null ? encodeBase64(options.totpMultiFactorSecret) : options.totpMultiFactorSecret,
|
|
2255
|
-
profile_image_url: options.profileImageUrl,
|
|
2256
|
-
otp_auth_enabled: options.otpAuthEnabled,
|
|
2257
|
-
passkey_auth_enabled: options.passkeyAuthEnabled
|
|
2258
|
-
};
|
|
2259
|
-
}
|
|
2260
|
-
function serverUserUpdateOptionsToCrud(options) {
|
|
2261
|
-
return {
|
|
2262
|
-
display_name: options.displayName,
|
|
2263
|
-
primary_email: options.primaryEmail,
|
|
2264
|
-
client_metadata: options.clientMetadata,
|
|
2265
|
-
client_read_only_metadata: options.clientReadOnlyMetadata,
|
|
2266
|
-
server_metadata: options.serverMetadata,
|
|
2267
|
-
selected_team_id: options.selectedTeamId,
|
|
2268
|
-
primary_email_auth_enabled: options.primaryEmailAuthEnabled,
|
|
2269
|
-
primary_email_verified: options.primaryEmailVerified,
|
|
2270
|
-
password: options.password,
|
|
2271
|
-
profile_image_url: options.profileImageUrl,
|
|
2272
|
-
totp_secret_base64: options.totpMultiFactorSecret != null ? encodeBase64(options.totpMultiFactorSecret) : options.totpMultiFactorSecret
|
|
2273
|
-
};
|
|
2274
|
-
}
|
|
2275
|
-
function serverUserCreateOptionsToCrud(options) {
|
|
2276
|
-
return {
|
|
2277
|
-
primary_email: options.primaryEmail,
|
|
2278
|
-
password: options.password,
|
|
2279
|
-
otp_auth_enabled: options.otpAuthEnabled,
|
|
2280
|
-
primary_email_auth_enabled: options.primaryEmailAuthEnabled,
|
|
2281
|
-
display_name: options.displayName,
|
|
2282
|
-
primary_email_verified: options.primaryEmailVerified,
|
|
2283
|
-
client_metadata: options.clientMetadata,
|
|
2284
|
-
client_read_only_metadata: options.clientReadOnlyMetadata,
|
|
2285
|
-
server_metadata: options.serverMetadata
|
|
2286
|
-
};
|
|
2287
|
-
}
|
|
2288
|
-
function adminProjectUpdateOptionsToCrud(options) {
|
|
2289
|
-
return {
|
|
2290
|
-
display_name: options.displayName,
|
|
2291
|
-
description: options.description,
|
|
2292
|
-
is_production_mode: options.isProductionMode,
|
|
2293
|
-
config: {
|
|
2294
|
-
domains: options.config?.domains?.map((d) => ({
|
|
2295
|
-
domain: d.domain,
|
|
2296
|
-
handler_path: d.handlerPath
|
|
2297
|
-
})),
|
|
2298
|
-
oauth_providers: options.config?.oauthProviders?.map((p) => ({
|
|
2299
|
-
id: p.id,
|
|
2300
|
-
enabled: p.enabled,
|
|
2301
|
-
type: p.type,
|
|
2302
|
-
...p.type === "standard" && {
|
|
2303
|
-
client_id: p.clientId,
|
|
2304
|
-
client_secret: p.clientSecret,
|
|
2305
|
-
facebook_config_id: p.facebookConfigId,
|
|
2306
|
-
microsoft_tenant_id: p.microsoftTenantId
|
|
2307
|
-
}
|
|
2308
|
-
})),
|
|
2309
|
-
email_config: options.config?.emailConfig && (options.config.emailConfig.type === "shared" ? {
|
|
2310
|
-
type: "shared"
|
|
2311
|
-
} : {
|
|
2312
|
-
type: "standard",
|
|
2313
|
-
host: options.config.emailConfig.host,
|
|
2314
|
-
port: options.config.emailConfig.port,
|
|
2315
|
-
username: options.config.emailConfig.username,
|
|
2316
|
-
password: options.config.emailConfig.password,
|
|
2317
|
-
sender_name: options.config.emailConfig.senderName,
|
|
2318
|
-
sender_email: options.config.emailConfig.senderEmail
|
|
2319
|
-
}),
|
|
2320
|
-
sign_up_enabled: options.config?.signUpEnabled,
|
|
2321
|
-
credential_enabled: options.config?.credentialEnabled,
|
|
2322
|
-
magic_link_enabled: options.config?.magicLinkEnabled,
|
|
2323
|
-
passkey_enabled: options.config?.passkeyEnabled,
|
|
2324
|
-
allow_localhost: options.config?.allowLocalhost,
|
|
2325
|
-
create_team_on_sign_up: options.config?.createTeamOnSignUp,
|
|
2326
|
-
client_team_creation_enabled: options.config?.clientTeamCreationEnabled,
|
|
2327
|
-
client_user_deletion_enabled: options.config?.clientUserDeletionEnabled,
|
|
2328
|
-
team_creator_default_permissions: options.config?.teamCreatorDefaultPermissions,
|
|
2329
|
-
team_member_default_permissions: options.config?.teamMemberDefaultPermissions
|
|
2330
|
-
}
|
|
2331
|
-
};
|
|
2332
|
-
}
|
|
2333
|
-
function adminProjectCreateOptionsToCrud(options) {
|
|
2334
|
-
return {
|
|
2335
|
-
...adminProjectUpdateOptionsToCrud(options),
|
|
2336
|
-
display_name: options.displayName
|
|
2337
|
-
};
|
|
2338
|
-
}
|
|
2339
|
-
function apiKeyCreateOptionsToCrud(options) {
|
|
2340
|
-
return {
|
|
2341
|
-
description: options.description,
|
|
2342
|
-
expires_at_millis: options.expiresAt.getTime(),
|
|
2343
|
-
has_publishable_client_key: options.hasPublishableClientKey,
|
|
2344
|
-
has_secret_server_key: options.hasSecretServerKey,
|
|
2345
|
-
has_super_secret_admin_key: options.hasSuperSecretAdminKey
|
|
2346
|
-
};
|
|
2347
|
-
}
|
|
2348
|
-
function teamUpdateOptionsToCrud(options) {
|
|
2349
|
-
return {
|
|
2350
|
-
display_name: options.displayName,
|
|
2351
|
-
profile_image_url: options.profileImageUrl,
|
|
2352
|
-
client_metadata: options.clientMetadata
|
|
2353
|
-
};
|
|
2354
|
-
}
|
|
2355
|
-
function teamCreateOptionsToCrud(options, creatorUserId) {
|
|
2356
|
-
return {
|
|
2357
|
-
display_name: options.displayName,
|
|
2358
|
-
profile_image_url: options.profileImageUrl,
|
|
2359
|
-
creator_user_id: creatorUserId
|
|
2360
|
-
};
|
|
2361
|
-
}
|
|
2362
|
-
function serverTeamCreateOptionsToCrud(options) {
|
|
2363
|
-
return {
|
|
2364
|
-
display_name: options.displayName,
|
|
2365
|
-
profile_image_url: options.profileImageUrl,
|
|
2366
|
-
creator_user_id: options.creatorUserId
|
|
2367
|
-
};
|
|
2368
|
-
}
|
|
2369
|
-
function serverTeamUpdateOptionsToCrud(options) {
|
|
2370
|
-
return {
|
|
2371
|
-
display_name: options.displayName,
|
|
2372
|
-
profile_image_url: options.profileImageUrl,
|
|
2373
|
-
client_metadata: options.clientMetadata,
|
|
2374
|
-
client_read_only_metadata: options.clientReadOnlyMetadata,
|
|
2375
|
-
server_metadata: options.serverMetadata
|
|
2376
|
-
};
|
|
2377
|
-
}
|
|
2378
|
-
function serverTeamPermissionDefinitionCreateOptionsToCrud(options) {
|
|
2379
|
-
return {
|
|
2380
|
-
id: options.id,
|
|
2381
|
-
description: options.description,
|
|
2382
|
-
contained_permission_ids: options.containedPermissionIds
|
|
2383
|
-
};
|
|
2384
|
-
}
|
|
2385
|
-
function serverTeamPermissionDefinitionUpdateOptionsToCrud(options) {
|
|
2386
|
-
return {
|
|
2387
|
-
id: options.id,
|
|
2388
|
-
description: options.description,
|
|
2389
|
-
contained_permission_ids: options.containedPermissionIds
|
|
2390
|
-
};
|
|
2391
|
-
}
|
|
2392
|
-
var StackClientApp = _StackClientAppImpl;
|
|
2393
|
-
var StackServerApp = _StackServerAppImpl;
|
|
2394
|
-
var StackAdminApp = _StackAdminAppImpl;
|
|
2395
|
-
function adminEmailTemplateUpdateOptionsToCrud(options) {
|
|
2396
|
-
return {
|
|
2397
|
-
subject: options.subject,
|
|
2398
|
-
content: options.content
|
|
2399
|
-
};
|
|
2400
|
-
}
|
|
1325
|
+
/**
|
|
1326
|
+
* There is a circular dependency between the admin app and the client app, as the former inherits from the latter and
|
|
1327
|
+
* the latter needs to use the former when creating a new instance of an internal project.
|
|
1328
|
+
*
|
|
1329
|
+
* To break it, we set the admin app here lazily instead of importing it directly. This variable is set by ./index.ts,
|
|
1330
|
+
* which imports both this file and ./admin-app-impl.ts.
|
|
1331
|
+
*/
|
|
1332
|
+
__StackClientAppImplIncomplete.LazyStackAdminAppImpl = { value: void 0 };
|
|
1333
|
+
var _StackClientAppImplIncomplete = __StackClientAppImplIncomplete;
|
|
2401
1334
|
export {
|
|
2402
|
-
|
|
2403
|
-
StackClientApp,
|
|
2404
|
-
StackServerApp,
|
|
2405
|
-
serverTeamPermissionDefinitionCreateOptionsToCrud,
|
|
2406
|
-
serverTeamPermissionDefinitionUpdateOptionsToCrud,
|
|
2407
|
-
stackAppInternalsSymbol
|
|
1335
|
+
_StackClientAppImplIncomplete
|
|
2408
1336
|
};
|
|
2409
|
-
//# sourceMappingURL=
|
|
1337
|
+
//# sourceMappingURL=client-app-impl.js.map
|