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