@stackframe/stack 2.5.3 → 2.5.4
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 +10 -0
- package/dist/components/credential-sign-in-form.js +4 -14
- package/dist/components/credential-sign-in-form.js.map +1 -1
- package/dist/components/credential-sign-up-form.js +18 -20
- package/dist/components/credential-sign-up-form.js.map +1 -1
- package/dist/components/elements/maybe-full-page.js.map +1 -1
- package/dist/components/elements/ssr-layout-effect.d.mts +1 -0
- package/dist/components/elements/ssr-layout-effect.d.ts +1 -0
- package/dist/components/elements/ssr-layout-effect.js +8 -1
- package/dist/components/elements/ssr-layout-effect.js.map +1 -1
- package/dist/components/elements/user-avatar.d.mts +5 -3
- package/dist/components/elements/user-avatar.d.ts +5 -3
- package/dist/components/elements/user-avatar.js.map +1 -1
- package/dist/components/forgot-password-form.js +3 -13
- package/dist/components/forgot-password-form.js.map +1 -1
- package/dist/components/magic-link-sign-in-form.js +3 -13
- package/dist/components/magic-link-sign-in-form.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.d.mts +7 -2
- package/dist/components/oauth-button-group.d.ts +7 -2
- package/dist/components/oauth-button-group.js +1 -1
- package/dist/components/oauth-button-group.js.map +1 -1
- package/dist/components/oauth-button.js +28 -26
- package/dist/components/oauth-button.js.map +1 -1
- package/dist/components/password-reset-form.js +4 -3
- package/dist/components/password-reset-form.js.map +1 -1
- package/dist/components/selected-team-switcher.d.mts +5 -3
- package/dist/components/selected-team-switcher.d.ts +5 -3
- package/dist/components/selected-team-switcher.js +12 -1
- package/dist/components/selected-team-switcher.js.map +1 -1
- package/dist/components/user-button.js.map +1 -1
- package/dist/components-page/account-settings.js +42 -7
- package/dist/components-page/account-settings.js.map +1 -1
- package/dist/components-page/auth-page.d.mts +9 -2
- package/dist/components-page/auth-page.d.ts +9 -2
- package/dist/components-page/auth-page.js +3 -3
- package/dist/components-page/auth-page.js.map +1 -1
- package/dist/components-page/email-verification.js +12 -2
- package/dist/components-page/email-verification.js.map +1 -1
- package/dist/components-page/error-page.js.map +1 -1
- package/dist/components-page/magic-link-callback.js +13 -3
- package/dist/components-page/magic-link-callback.js.map +1 -1
- package/dist/components-page/password-reset.js +2 -2
- package/dist/components-page/password-reset.js.map +1 -1
- package/dist/components-page/sign-out.js +12 -2
- package/dist/components-page/sign-out.js.map +1 -1
- package/dist/components-page/stack-handler.d.mts +5 -3
- package/dist/components-page/stack-handler.d.ts +5 -3
- package/dist/components-page/stack-handler.js +27 -10
- package/dist/components-page/stack-handler.js.map +1 -1
- package/dist/esm/components/credential-sign-in-form.js +4 -4
- package/dist/esm/components/credential-sign-in-form.js.map +1 -1
- package/dist/esm/components/credential-sign-up-form.js +18 -20
- package/dist/esm/components/credential-sign-up-form.js.map +1 -1
- package/dist/esm/components/elements/maybe-full-page.js.map +1 -1
- package/dist/esm/components/elements/ssr-layout-effect.js +8 -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/forgot-password-form.js +3 -3
- package/dist/esm/components/forgot-password-form.js.map +1 -1
- package/dist/esm/components/magic-link-sign-in-form.js +3 -3
- package/dist/esm/components/magic-link-sign-in-form.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 +1 -1
- package/dist/esm/components/oauth-button-group.js.map +1 -1
- package/dist/esm/components/oauth-button.js +29 -27
- package/dist/esm/components/oauth-button.js.map +1 -1
- package/dist/esm/components/password-reset-form.js +4 -3
- package/dist/esm/components/password-reset-form.js.map +1 -1
- package/dist/esm/components/selected-team-switcher.js +2 -1
- package/dist/esm/components/selected-team-switcher.js.map +1 -1
- package/dist/esm/components/user-button.js.map +1 -1
- package/dist/esm/components-page/account-settings.js +42 -7
- package/dist/esm/components-page/account-settings.js.map +1 -1
- package/dist/esm/components-page/auth-page.js +3 -3
- package/dist/esm/components-page/auth-page.js.map +1 -1
- package/dist/esm/components-page/email-verification.js +2 -2
- 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/magic-link-callback.js +3 -3
- package/dist/esm/components-page/magic-link-callback.js.map +1 -1
- package/dist/esm/components-page/password-reset.js +2 -2
- package/dist/esm/components-page/password-reset.js.map +1 -1
- package/dist/esm/components-page/sign-out.js +2 -2
- package/dist/esm/components-page/sign-out.js.map +1 -1
- package/dist/esm/components-page/stack-handler.js +27 -10
- package/dist/esm/components-page/stack-handler.js.map +1 -1
- package/dist/esm/index.js +1 -4
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/lib/auth.js.map +1 -1
- package/dist/esm/lib/cookie.js +6 -1
- package/dist/esm/lib/cookie.js.map +1 -1
- package/dist/esm/lib/hooks.js.map +1 -1
- package/dist/esm/lib/stack-app.js +478 -349
- package/dist/esm/lib/stack-app.js.map +1 -1
- package/dist/esm/providers/stack-provider-client.js +3 -4
- package/dist/esm/providers/stack-provider-client.js.map +1 -1
- package/dist/esm/providers/theme-provider.js +16 -7
- package/dist/esm/providers/theme-provider.js.map +1 -1
- package/dist/esm/utils/browser-script.js +2 -2
- package/dist/esm/utils/browser-script.js.map +1 -1
- package/dist/esm/utils/email.js +2 -2
- package/dist/esm/utils/email.js.map +1 -1
- package/dist/index.d.mts +6 -4
- package/dist/index.d.ts +6 -4
- package/dist/index.js +4 -8
- package/dist/index.js.map +1 -1
- package/dist/lib/auth.js.map +1 -1
- package/dist/lib/cookie.js +6 -1
- package/dist/lib/cookie.js.map +1 -1
- package/dist/lib/hooks.d.mts +5 -3
- package/dist/lib/hooks.d.ts +5 -3
- package/dist/lib/hooks.js.map +1 -1
- package/dist/lib/stack-app.d.mts +219 -114
- package/dist/lib/stack-app.d.ts +219 -114
- package/dist/lib/stack-app.js +500 -369
- package/dist/lib/stack-app.js.map +1 -1
- package/dist/providers/stack-provider-client.d.mts +8 -6
- package/dist/providers/stack-provider-client.d.ts +8 -6
- package/dist/providers/stack-provider-client.js +4 -5
- package/dist/providers/stack-provider-client.js.map +1 -1
- package/dist/providers/stack-provider.d.mts +5 -3
- package/dist/providers/stack-provider.d.ts +5 -3
- package/dist/providers/theme-provider.d.mts +2 -1
- package/dist/providers/theme-provider.d.ts +2 -1
- package/dist/providers/theme-provider.js +15 -6
- package/dist/providers/theme-provider.js.map +1 -1
- package/dist/utils/browser-script.d.mts +3 -1
- package/dist/utils/browser-script.d.ts +3 -1
- package/dist/utils/browser-script.js +2 -2
- package/dist/utils/browser-script.js.map +1 -1
- package/dist/utils/email.js +2 -12
- package/dist/utils/email.js.map +1 -1
- package/package.json +4 -5
- package/dist/esm/providers/styled-components-registry.js +0 -25
- package/dist/esm/providers/styled-components-registry.js.map +0 -1
- package/dist/providers/styled-components-registry.d.mts +0 -8
- package/dist/providers/styled-components-registry.d.ts +0 -8
- package/dist/providers/styled-components-registry.js +0 -45
- package/dist/providers/styled-components-registry.js.map +0 -1
package/dist/lib/stack-app.js
CHANGED
|
@@ -33,36 +33,35 @@ __export(stack_app_exports, {
|
|
|
33
33
|
StackAdminApp: () => StackAdminApp,
|
|
34
34
|
StackClientApp: () => StackClientApp,
|
|
35
35
|
StackServerApp: () => StackServerApp,
|
|
36
|
+
serverTeamPermissionDefinitionCreateOptionsToCrud: () => serverTeamPermissionDefinitionCreateOptionsToCrud,
|
|
37
|
+
serverTeamPermissionDefinitionUpdateOptionsToCrud: () => serverTeamPermissionDefinitionUpdateOptionsToCrud,
|
|
36
38
|
stackAppInternalsSymbol: () => stackAppInternalsSymbol
|
|
37
39
|
});
|
|
38
40
|
module.exports = __toCommonJS(stack_app_exports);
|
|
39
|
-
var
|
|
41
|
+
var import_stack_sc = require("@stackframe/stack-sc");
|
|
40
42
|
var import_stack_shared = require("@stackframe/stack-shared");
|
|
41
|
-
var
|
|
43
|
+
var import_production_mode = require("@stackframe/stack-shared/dist/helpers/production-mode");
|
|
44
|
+
var import_sessions = require("@stackframe/stack-shared/dist/sessions");
|
|
45
|
+
var import_caches = require("@stackframe/stack-shared/dist/utils/caches");
|
|
46
|
+
var import_compile_time = require("@stackframe/stack-shared/dist/utils/compile-time");
|
|
47
|
+
var import_env = require("@stackframe/stack-shared/dist/utils/env");
|
|
42
48
|
var import_errors = require("@stackframe/stack-shared/dist/utils/errors");
|
|
43
|
-
var
|
|
49
|
+
var import_maps = require("@stackframe/stack-shared/dist/utils/maps");
|
|
50
|
+
var import_objects = require("@stackframe/stack-shared/dist/utils/objects");
|
|
51
|
+
var import_promises = require("@stackframe/stack-shared/dist/utils/promises");
|
|
52
|
+
var import_react = require("@stackframe/stack-shared/dist/utils/react");
|
|
44
53
|
var import_results = require("@stackframe/stack-shared/dist/utils/results");
|
|
45
|
-
var import_react2 = require("@stackframe/stack-shared/dist/utils/react");
|
|
46
54
|
var import_stores = require("@stackframe/stack-shared/dist/utils/stores");
|
|
47
|
-
var
|
|
48
|
-
var
|
|
49
|
-
var
|
|
55
|
+
var import_strings = require("@stackframe/stack-shared/dist/utils/strings");
|
|
56
|
+
var import_uuids = require("@stackframe/stack-shared/dist/utils/uuids");
|
|
57
|
+
var cookie = __toESM(require("cookie"));
|
|
50
58
|
var NextNavigationUnscrambled = __toESM(require("next/navigation"));
|
|
59
|
+
var import_react2 = __toESM(require("react"));
|
|
51
60
|
var import_url = require("../utils/url");
|
|
52
|
-
var
|
|
53
|
-
var
|
|
54
|
-
var import_caches = require("@stackframe/stack-shared/dist/utils/caches");
|
|
55
|
-
var import_react3 = require("@stackframe/stack-shared/dist/utils/react");
|
|
56
|
-
var import_compile_time = require("@stackframe/stack-shared/dist/utils/compile-time");
|
|
57
|
-
var import_stack_sc = require("@stackframe/stack-sc");
|
|
58
|
-
var cookie = __toESM(require("cookie"));
|
|
59
|
-
var import_sessions = require("@stackframe/stack-shared/dist/sessions");
|
|
60
|
-
var import_strings = require("@stackframe/stack-shared/dist/utils/strings");
|
|
61
|
+
var import_auth = require("./auth");
|
|
62
|
+
var import_cookie = require("./cookie");
|
|
61
63
|
var NextNavigation = (0, import_compile_time.scrambleDuringCompileTime)(NextNavigationUnscrambled);
|
|
62
|
-
var clientVersion = "js @stackframe/stack@2.5.
|
|
63
|
-
function permissionDefinitionScopeToType(scope) {
|
|
64
|
-
return { "any-team": "team", "specific-team": "team", "global": "global" }[scope.type];
|
|
65
|
-
}
|
|
64
|
+
var clientVersion = "js @stackframe/stack@2.5.4";
|
|
66
65
|
function getUrls(partial) {
|
|
67
66
|
const handler = partial.handler ?? "/handler";
|
|
68
67
|
return {
|
|
@@ -111,7 +110,7 @@ function getDefaultSuperSecretAdminKey() {
|
|
|
111
110
|
function getDefaultBaseUrl() {
|
|
112
111
|
return process.env.NEXT_PUBLIC_STACK_URL || defaultBaseUrl;
|
|
113
112
|
}
|
|
114
|
-
var defaultBaseUrl = "https://
|
|
113
|
+
var defaultBaseUrl = "https://api.stack-auth.com";
|
|
115
114
|
function createEmptyTokenStore() {
|
|
116
115
|
return new import_stores.Store({
|
|
117
116
|
refreshToken: null,
|
|
@@ -120,27 +119,27 @@ function createEmptyTokenStore() {
|
|
|
120
119
|
}
|
|
121
120
|
var cachePromiseByComponentId = /* @__PURE__ */ new Map();
|
|
122
121
|
function useAsyncCache(cache, dependencies, caller) {
|
|
123
|
-
(0,
|
|
124
|
-
const id =
|
|
125
|
-
const subscribe = (0,
|
|
122
|
+
(0, import_react.suspendIfSsr)(caller);
|
|
123
|
+
const id = import_react2.default.useId();
|
|
124
|
+
const subscribe = (0, import_react2.useCallback)((cb) => {
|
|
126
125
|
const { unsubscribe } = cache.onStateChange(dependencies, () => {
|
|
127
126
|
cachePromiseByComponentId.delete(id);
|
|
128
127
|
cb();
|
|
129
128
|
});
|
|
130
129
|
return unsubscribe;
|
|
131
130
|
}, [cache, ...dependencies]);
|
|
132
|
-
const getSnapshot = (0,
|
|
131
|
+
const getSnapshot = (0, import_react2.useCallback)(() => {
|
|
133
132
|
if (!cachePromiseByComponentId.has(id)) {
|
|
134
133
|
cachePromiseByComponentId.set(id, cache.getOrWait(dependencies, "read-write"));
|
|
135
134
|
}
|
|
136
135
|
return cachePromiseByComponentId.get(id);
|
|
137
136
|
}, [cache, ...dependencies]);
|
|
138
|
-
const promise =
|
|
137
|
+
const promise = import_react2.default.useSyncExternalStore(
|
|
139
138
|
subscribe,
|
|
140
139
|
getSnapshot,
|
|
141
140
|
() => (0, import_errors.throwErr)(new Error("getServerSnapshot should never be called in useAsyncCache because we restrict to CSR earlier"))
|
|
142
141
|
);
|
|
143
|
-
return
|
|
142
|
+
return import_react2.default.use(promise);
|
|
144
143
|
}
|
|
145
144
|
var stackAppInternalsSymbol = Symbol.for("StackAppInternals");
|
|
146
145
|
var allClientApps = /* @__PURE__ */ new Map();
|
|
@@ -167,12 +166,12 @@ var _StackClientAppImpl = class __StackClientAppImpl {
|
|
|
167
166
|
this._options = _options;
|
|
168
167
|
this._uniqueIdentifier = void 0;
|
|
169
168
|
this.__DEMO_ENABLE_SLIGHT_FETCH_DELAY = false;
|
|
169
|
+
this._ownedAdminApps = new import_maps.DependenciesMap();
|
|
170
170
|
this._currentUserCache = createCacheBySession(async (session) => {
|
|
171
171
|
if (this.__DEMO_ENABLE_SLIGHT_FETCH_DELAY) {
|
|
172
172
|
await (0, import_promises.wait)(2e3);
|
|
173
173
|
}
|
|
174
|
-
|
|
175
|
-
return import_results.Result.or(user, null);
|
|
174
|
+
return await this._interface.getClientUserByToken(session);
|
|
176
175
|
});
|
|
177
176
|
this._currentProjectCache = createCache(async () => {
|
|
178
177
|
return import_results.Result.orThrow(await this._interface.getClientProject());
|
|
@@ -180,11 +179,11 @@ var _StackClientAppImpl = class __StackClientAppImpl {
|
|
|
180
179
|
this._ownedProjectsCache = createCacheBySession(async (session) => {
|
|
181
180
|
return await this._interface.listProjects(session);
|
|
182
181
|
});
|
|
183
|
-
this._currentUserPermissionsCache = createCacheBySession(async (session, [teamId,
|
|
184
|
-
return await this._interface.
|
|
182
|
+
this._currentUserPermissionsCache = createCacheBySession(async (session, [teamId, recursive]) => {
|
|
183
|
+
return await this._interface.listCurrentUserTeamPermissions({ teamId, recursive }, session);
|
|
185
184
|
});
|
|
186
185
|
this._currentUserTeamsCache = createCacheBySession(async (session) => {
|
|
187
|
-
return await this._interface.
|
|
186
|
+
return await this._interface.listCurrentUserTeams(session);
|
|
188
187
|
});
|
|
189
188
|
this._currentUserOAuthConnectionAccessTokensCache = createCacheBySession(
|
|
190
189
|
async (session, [accountId, scope]) => {
|
|
@@ -202,7 +201,7 @@ var _StackClientAppImpl = class __StackClientAppImpl {
|
|
|
202
201
|
async (session, [connectionId, scope, redirect]) => {
|
|
203
202
|
const user = await this._currentUserCache.getOrWait([session], "write-only");
|
|
204
203
|
let hasConnection = true;
|
|
205
|
-
if (!user || !user.
|
|
204
|
+
if (!user || !user.oauth_providers.find((p) => p.id === connectionId)) {
|
|
206
205
|
hasConnection = false;
|
|
207
206
|
}
|
|
208
207
|
const token = await this._currentUserOAuthConnectionAccessTokensCache.getOrWait([session, connectionId, scope || ""], "write-only");
|
|
@@ -249,9 +248,9 @@ var _StackClientAppImpl = class __StackClientAppImpl {
|
|
|
249
248
|
this._storedCookieTokenStore = null;
|
|
250
249
|
/**
|
|
251
250
|
* A map from token stores and session keys to sessions.
|
|
252
|
-
*
|
|
251
|
+
*
|
|
253
252
|
* This isn't just a map from session keys to sessions for two reasons:
|
|
254
|
-
*
|
|
253
|
+
*
|
|
255
254
|
* - So we can garbage-collect Session objects when the token store is garbage-collected
|
|
256
255
|
* - 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
|
|
257
256
|
*/
|
|
@@ -273,9 +272,11 @@ var _StackClientAppImpl = class __StackClientAppImpl {
|
|
|
273
272
|
this._uniqueIdentifier = _options.uniqueIdentifier;
|
|
274
273
|
this._initUniqueIdentifier();
|
|
275
274
|
}
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
275
|
+
if (!_options.noAutomaticPrefetch) {
|
|
276
|
+
numberOfAppsCreated++;
|
|
277
|
+
if (numberOfAppsCreated > 10) {
|
|
278
|
+
(process.env.NODE_ENV === "development" ? console.log : console.warn)(`You have created more than 10 Stack apps with automatic pre-fetch enabled (${numberOfAppsCreated}). This is usually a sign of a memory leak, but can sometimes be caused by hot reload of your tech stack. If you are getting this error and it is not caused by hot reload, make sure to minimize the number of Stack apps per page (usually, one per project). (If it is caused by hot reload and does not occur in production, you can safely ignore it.)`);
|
|
279
|
+
}
|
|
279
280
|
}
|
|
280
281
|
}
|
|
281
282
|
_initUniqueIdentifier() {
|
|
@@ -289,7 +290,8 @@ var _StackClientAppImpl = class __StackClientAppImpl {
|
|
|
289
290
|
}
|
|
290
291
|
/**
|
|
291
292
|
* Cloudflare workers does not allow use of randomness on the global scope (on which the Stack app is probably
|
|
292
|
-
* initialized). For that reason, we generate the unique identifier lazily when it is first needed
|
|
293
|
+
* initialized). For that reason, we generate the unique identifier lazily when it is first needed instead of in the
|
|
294
|
+
* constructor.
|
|
293
295
|
*/
|
|
294
296
|
_getUniqueIdentifier() {
|
|
295
297
|
if (!this._uniqueIdentifier) {
|
|
@@ -465,14 +467,14 @@ var _StackClientAppImpl = class __StackClientAppImpl {
|
|
|
465
467
|
}
|
|
466
468
|
_useSession(overrideTokenStoreInit) {
|
|
467
469
|
const tokenStore = this._getOrCreateTokenStore(overrideTokenStoreInit);
|
|
468
|
-
const subscribe = (0,
|
|
470
|
+
const subscribe = (0, import_react2.useCallback)((cb) => {
|
|
469
471
|
const { unsubscribe } = tokenStore.onChange(() => {
|
|
470
472
|
cb();
|
|
471
473
|
});
|
|
472
474
|
return unsubscribe;
|
|
473
475
|
}, [tokenStore]);
|
|
474
|
-
const getSnapshot = (0,
|
|
475
|
-
return
|
|
476
|
+
const getSnapshot = (0, import_react2.useCallback)(() => this._getSessionFromTokenStore(tokenStore), [tokenStore]);
|
|
477
|
+
return import_react2.default.useSyncExternalStore(subscribe, getSnapshot, getSnapshot);
|
|
476
478
|
}
|
|
477
479
|
async _signInToAccountWithTokens(tokens) {
|
|
478
480
|
const tokenStore = this._getOrCreateTokenStore();
|
|
@@ -494,38 +496,28 @@ var _StackClientAppImpl = class __StackClientAppImpl {
|
|
|
494
496
|
throw new Error("Cannot call this function on a Stack app with a project ID other than 'internal'.");
|
|
495
497
|
}
|
|
496
498
|
}
|
|
497
|
-
|
|
498
|
-
const type = permissionDefinitionScopeToType(json.scope);
|
|
499
|
-
if (type === "team") {
|
|
500
|
-
return {
|
|
501
|
-
id: json.id,
|
|
502
|
-
type,
|
|
503
|
-
teamId: json.scope.teamId
|
|
504
|
-
};
|
|
505
|
-
} else {
|
|
506
|
-
return {
|
|
507
|
-
id: json.id,
|
|
508
|
-
type
|
|
509
|
-
};
|
|
510
|
-
}
|
|
511
|
-
}
|
|
512
|
-
_teamFromJson(json) {
|
|
499
|
+
_clientProjectFromCrud(crud) {
|
|
513
500
|
return {
|
|
514
|
-
id:
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
501
|
+
id: crud.id,
|
|
502
|
+
config: {
|
|
503
|
+
credentialEnabled: crud.config.credential_enabled,
|
|
504
|
+
magicLinkEnabled: crud.config.magic_link_enabled,
|
|
505
|
+
oauthProviders: crud.config.oauth_providers.map((p) => ({
|
|
506
|
+
id: p.id
|
|
507
|
+
}))
|
|
520
508
|
}
|
|
521
509
|
};
|
|
522
510
|
}
|
|
523
|
-
|
|
524
|
-
|
|
511
|
+
_clientTeamPermissionFromCrud(crud) {
|
|
512
|
+
return {
|
|
513
|
+
id: crud.id
|
|
514
|
+
};
|
|
515
|
+
}
|
|
516
|
+
_clientTeamFromCrud(crud) {
|
|
525
517
|
return {
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
518
|
+
id: crud.id,
|
|
519
|
+
displayName: crud.display_name,
|
|
520
|
+
profileImageUrl: crud.profile_image_url
|
|
529
521
|
};
|
|
530
522
|
}
|
|
531
523
|
_createAuth(session) {
|
|
@@ -555,41 +547,29 @@ var _StackClientAppImpl = class __StackClientAppImpl {
|
|
|
555
547
|
}
|
|
556
548
|
};
|
|
557
549
|
}
|
|
558
|
-
_createBaseUser(
|
|
550
|
+
_createBaseUser(crud) {
|
|
551
|
+
if (!crud) {
|
|
552
|
+
throw new import_errors.StackAssertionError("User not found");
|
|
553
|
+
}
|
|
559
554
|
return {
|
|
560
|
-
projectId:
|
|
561
|
-
id:
|
|
562
|
-
displayName:
|
|
563
|
-
primaryEmail:
|
|
564
|
-
primaryEmailVerified:
|
|
565
|
-
profileImageUrl:
|
|
566
|
-
signedUpAt: new Date(
|
|
567
|
-
clientMetadata:
|
|
568
|
-
hasPassword:
|
|
569
|
-
|
|
570
|
-
oauthProviders:
|
|
571
|
-
selectedTeam:
|
|
555
|
+
projectId: crud.project_id,
|
|
556
|
+
id: crud.id,
|
|
557
|
+
displayName: crud.display_name,
|
|
558
|
+
primaryEmail: crud.primary_email,
|
|
559
|
+
primaryEmailVerified: crud.primary_email_verified,
|
|
560
|
+
profileImageUrl: crud.profile_image_url,
|
|
561
|
+
signedUpAt: new Date(crud.signed_up_at_millis),
|
|
562
|
+
clientMetadata: crud.client_metadata,
|
|
563
|
+
hasPassword: crud.has_password,
|
|
564
|
+
emailAuthEnabled: crud.auth_with_email,
|
|
565
|
+
oauthProviders: crud.oauth_providers,
|
|
566
|
+
selectedTeam: crud.selected_team && this._clientTeamFromCrud(crud.selected_team),
|
|
572
567
|
toClientJson() {
|
|
573
|
-
return
|
|
574
|
-
"projectId",
|
|
575
|
-
"id",
|
|
576
|
-
"displayName",
|
|
577
|
-
"primaryEmail",
|
|
578
|
-
"primaryEmailVerified",
|
|
579
|
-
"profileImageUrl",
|
|
580
|
-
"signedUpAtMillis",
|
|
581
|
-
"clientMetadata",
|
|
582
|
-
"hasPassword",
|
|
583
|
-
"authMethod",
|
|
584
|
-
"authWithEmail",
|
|
585
|
-
"selectedTeamId",
|
|
586
|
-
"selectedTeam",
|
|
587
|
-
"oauthProviders"
|
|
588
|
-
]);
|
|
568
|
+
return crud;
|
|
589
569
|
}
|
|
590
570
|
};
|
|
591
571
|
}
|
|
592
|
-
|
|
572
|
+
_createCurrentUserExtra(crud, session) {
|
|
593
573
|
const app = this;
|
|
594
574
|
async function getConnectedAccount(id, options) {
|
|
595
575
|
const scopeString = options?.scopes?.join(" ");
|
|
@@ -617,34 +597,36 @@ var _StackClientAppImpl = class __StackClientAppImpl {
|
|
|
617
597
|
},
|
|
618
598
|
useTeam(teamId) {
|
|
619
599
|
const teams = this.useTeams();
|
|
620
|
-
return (0,
|
|
600
|
+
return (0, import_react2.useMemo)(() => {
|
|
621
601
|
return teams.find((t) => t.id === teamId) ?? null;
|
|
622
602
|
}, [teams, teamId]);
|
|
623
603
|
},
|
|
624
604
|
async listTeams() {
|
|
625
605
|
const teams = await app._currentUserTeamsCache.getOrWait([session], "write-only");
|
|
626
|
-
return teams.map((
|
|
606
|
+
return teams.map((crud2) => app._clientTeamFromCrud(crud2));
|
|
627
607
|
},
|
|
628
608
|
useTeams() {
|
|
629
609
|
const teams = useAsyncCache(app._currentUserTeamsCache, [session], "user.useTeams()");
|
|
630
|
-
return (0,
|
|
610
|
+
return (0, import_react2.useMemo)(() => teams.map((crud2) => app._clientTeamFromCrud(crud2)), [teams]);
|
|
631
611
|
},
|
|
632
612
|
async createTeam(data) {
|
|
633
|
-
const
|
|
613
|
+
const crud2 = await app._interface.createTeamForCurrentUser(teamCreateOptionsToCrud(data), session);
|
|
634
614
|
await app._currentUserTeamsCache.refresh([session]);
|
|
635
|
-
return app.
|
|
615
|
+
return app._clientTeamFromCrud(crud2);
|
|
636
616
|
},
|
|
637
617
|
async listPermissions(scope, options) {
|
|
638
|
-
const
|
|
639
|
-
|
|
618
|
+
const recursive = options?.recursive ?? true;
|
|
619
|
+
const permissions = await app._currentUserPermissionsCache.getOrWait([session, scope.id, recursive], "write-only");
|
|
620
|
+
return permissions.map((crud2) => app._clientTeamPermissionFromCrud(crud2));
|
|
640
621
|
},
|
|
641
622
|
usePermissions(scope, options) {
|
|
642
|
-
const
|
|
643
|
-
|
|
623
|
+
const recursive = options?.recursive ?? true;
|
|
624
|
+
const permissions = useAsyncCache(app._currentUserPermissionsCache, [session, scope.id, recursive], "user.usePermissions()");
|
|
625
|
+
return (0, import_react2.useMemo)(() => permissions.map((crud2) => app._clientTeamPermissionFromCrud(crud2)), [permissions]);
|
|
644
626
|
},
|
|
645
627
|
usePermission(scope, permissionId) {
|
|
646
628
|
const permissions = this.usePermissions(scope);
|
|
647
|
-
return (0,
|
|
629
|
+
return (0, import_react2.useMemo)(() => permissions.find((p) => p.id === permissionId) ?? null, [permissions, permissionId]);
|
|
648
630
|
},
|
|
649
631
|
async getPermission(scope, permissionId) {
|
|
650
632
|
const permissions = await this.listPermissions(scope);
|
|
@@ -654,7 +636,7 @@ var _StackClientAppImpl = class __StackClientAppImpl {
|
|
|
654
636
|
return await this.getPermission(scope, permissionId) !== null;
|
|
655
637
|
},
|
|
656
638
|
update(update) {
|
|
657
|
-
return app.
|
|
639
|
+
return app._updateClientUser(update, session);
|
|
658
640
|
},
|
|
659
641
|
sendVerificationEmail() {
|
|
660
642
|
return app._sendVerificationEmail(session);
|
|
@@ -679,58 +661,27 @@ var _StackClientAppImpl = class __StackClientAppImpl {
|
|
|
679
661
|
}
|
|
680
662
|
};
|
|
681
663
|
}
|
|
682
|
-
|
|
664
|
+
_currentUserFromCrud(crud, session) {
|
|
683
665
|
const currentUser = {
|
|
684
|
-
...this._createBaseUser(
|
|
666
|
+
...this._createBaseUser(crud),
|
|
685
667
|
...this._createAuth(session),
|
|
686
|
-
...this.
|
|
668
|
+
...this._createCurrentUserExtra(crud, session),
|
|
687
669
|
...this._isInternalProject() ? this._createInternalUserExtra(session) : {}
|
|
688
670
|
};
|
|
689
671
|
Object.freeze(currentUser);
|
|
690
672
|
return currentUser;
|
|
691
673
|
}
|
|
692
|
-
|
|
693
|
-
if (
|
|
694
|
-
|
|
674
|
+
_getOwnedAdminApp(forProjectId, session) {
|
|
675
|
+
if (!this._ownedAdminApps.has([session, forProjectId])) {
|
|
676
|
+
this._ownedAdminApps.set([session, forProjectId], new _StackAdminAppImpl({
|
|
677
|
+
baseUrl: this._interface.options.baseUrl,
|
|
678
|
+
projectId: forProjectId,
|
|
679
|
+
tokenStore: null,
|
|
680
|
+
projectOwnerSession: session,
|
|
681
|
+
noAutomaticPrefetch: true
|
|
682
|
+
}));
|
|
695
683
|
}
|
|
696
|
-
return
|
|
697
|
-
id: data.id,
|
|
698
|
-
displayName: data.displayName,
|
|
699
|
-
description: data.description,
|
|
700
|
-
createdAt: new Date(data.createdAtMillis),
|
|
701
|
-
userCount: data.userCount,
|
|
702
|
-
isProductionMode: data.isProductionMode,
|
|
703
|
-
evaluatedConfig: {
|
|
704
|
-
id: data.evaluatedConfig.id,
|
|
705
|
-
credentialEnabled: data.evaluatedConfig.credentialEnabled,
|
|
706
|
-
magicLinkEnabled: data.evaluatedConfig.magicLinkEnabled,
|
|
707
|
-
allowLocalhost: data.evaluatedConfig.allowLocalhost,
|
|
708
|
-
oauthProviders: data.evaluatedConfig.oauthProviders,
|
|
709
|
-
emailConfig: data.evaluatedConfig.emailConfig,
|
|
710
|
-
domains: data.evaluatedConfig.domains,
|
|
711
|
-
createTeamOnSignUp: data.evaluatedConfig.createTeamOnSignUp,
|
|
712
|
-
teamCreatorDefaultPermissions: data.evaluatedConfig.teamCreatorDefaultPermissions,
|
|
713
|
-
teamMemberDefaultPermissions: data.evaluatedConfig.teamMemberDefaultPermissions
|
|
714
|
-
},
|
|
715
|
-
async update(update) {
|
|
716
|
-
await adminInterface.updateProject(update);
|
|
717
|
-
await onRefresh();
|
|
718
|
-
},
|
|
719
|
-
toJson() {
|
|
720
|
-
return data;
|
|
721
|
-
},
|
|
722
|
-
getProductionModeErrors() {
|
|
723
|
-
return (0, import_clientInterface.getProductionModeErrors)(this.toJson());
|
|
724
|
-
}
|
|
725
|
-
};
|
|
726
|
-
}
|
|
727
|
-
_createAdminInterface(forProjectId, session) {
|
|
728
|
-
return new import_stack_shared.StackAdminInterface({
|
|
729
|
-
baseUrl: this._interface.options.baseUrl,
|
|
730
|
-
projectId: forProjectId,
|
|
731
|
-
clientVersion,
|
|
732
|
-
projectOwnerSession: session
|
|
733
|
-
});
|
|
684
|
+
return this._ownedAdminApps.get([session, forProjectId]);
|
|
734
685
|
}
|
|
735
686
|
get projectId() {
|
|
736
687
|
return this._interface.projectId;
|
|
@@ -810,8 +761,8 @@ var _StackClientAppImpl = class __StackClientAppImpl {
|
|
|
810
761
|
async getUser(options) {
|
|
811
762
|
this._ensurePersistentTokenStore(options?.tokenStore);
|
|
812
763
|
const session = this._getSession(options?.tokenStore);
|
|
813
|
-
const
|
|
814
|
-
if (
|
|
764
|
+
const crud = await this._currentUserCache.getOrWait([session], "write-only");
|
|
765
|
+
if (crud === null) {
|
|
815
766
|
switch (options?.or) {
|
|
816
767
|
case "redirect": {
|
|
817
768
|
await this.redirectToSignIn();
|
|
@@ -825,18 +776,18 @@ var _StackClientAppImpl = class __StackClientAppImpl {
|
|
|
825
776
|
}
|
|
826
777
|
}
|
|
827
778
|
}
|
|
828
|
-
return
|
|
779
|
+
return crud && this._currentUserFromCrud(crud, session);
|
|
829
780
|
}
|
|
830
781
|
useUser(options) {
|
|
831
782
|
this._ensurePersistentTokenStore(options?.tokenStore);
|
|
832
783
|
const router = NextNavigation.useRouter();
|
|
833
784
|
const session = this._useSession(options?.tokenStore);
|
|
834
|
-
const
|
|
835
|
-
if (
|
|
785
|
+
const crud = useAsyncCache(this._currentUserCache, [session], "useUser()");
|
|
786
|
+
if (crud === null) {
|
|
836
787
|
switch (options?.or) {
|
|
837
788
|
case "redirect": {
|
|
838
789
|
setTimeout(() => router.replace(this.urls.signIn), 0);
|
|
839
|
-
(0,
|
|
790
|
+
(0, import_react.suspend)();
|
|
840
791
|
throw new import_errors.StackAssertionError("suspend should never return");
|
|
841
792
|
}
|
|
842
793
|
case "throw": {
|
|
@@ -847,12 +798,12 @@ var _StackClientAppImpl = class __StackClientAppImpl {
|
|
|
847
798
|
}
|
|
848
799
|
}
|
|
849
800
|
}
|
|
850
|
-
return (0,
|
|
851
|
-
return
|
|
852
|
-
}, [
|
|
801
|
+
return (0, import_react2.useMemo)(() => {
|
|
802
|
+
return crud && this._currentUserFromCrud(crud, session);
|
|
803
|
+
}, [crud, session, options?.or]);
|
|
853
804
|
}
|
|
854
|
-
async
|
|
855
|
-
const res = await this._interface.
|
|
805
|
+
async _updateClientUser(update, session) {
|
|
806
|
+
const res = await this._interface.updateClientUser(userUpdateOptionsToCrud(update), session);
|
|
856
807
|
await this._refreshUser(session);
|
|
857
808
|
return res;
|
|
858
809
|
}
|
|
@@ -896,8 +847,7 @@ var _StackClientAppImpl = class __StackClientAppImpl {
|
|
|
896
847
|
}
|
|
897
848
|
async signInWithMagicLink(code) {
|
|
898
849
|
this._ensurePersistentTokenStore();
|
|
899
|
-
const
|
|
900
|
-
const result = await this._interface.signInWithMagicLink(code, session);
|
|
850
|
+
const result = await this._interface.signInWithMagicLink(code);
|
|
901
851
|
if (result instanceof import_stack_shared.KnownError) {
|
|
902
852
|
return result;
|
|
903
853
|
}
|
|
@@ -944,35 +894,34 @@ var _StackClientAppImpl = class __StackClientAppImpl {
|
|
|
944
894
|
}
|
|
945
895
|
}
|
|
946
896
|
async getProject() {
|
|
947
|
-
|
|
897
|
+
const crud = await this._currentProjectCache.getOrWait([], "write-only");
|
|
898
|
+
return this._clientProjectFromCrud(crud);
|
|
948
899
|
}
|
|
949
900
|
useProject() {
|
|
950
|
-
|
|
901
|
+
const crud = useAsyncCache(this._currentProjectCache, [], "useProject()");
|
|
902
|
+
return (0, import_react2.useMemo)(() => this._clientProjectFromCrud(crud), [crud]);
|
|
951
903
|
}
|
|
952
904
|
async _listOwnedProjects(session) {
|
|
953
905
|
this._ensureInternalProject();
|
|
954
|
-
const
|
|
955
|
-
return
|
|
906
|
+
const crud = await this._ownedProjectsCache.getOrWait([session], "write-only");
|
|
907
|
+
return crud.map((j) => this._getOwnedAdminApp(j.id, session)._adminOwnedProjectFromCrud(
|
|
956
908
|
j,
|
|
957
|
-
this._createAdminInterface(j.id, session),
|
|
958
909
|
() => this._refreshOwnedProjects(session)
|
|
959
910
|
));
|
|
960
911
|
}
|
|
961
912
|
_useOwnedProjects(session) {
|
|
962
913
|
this._ensureInternalProject();
|
|
963
|
-
const
|
|
964
|
-
return (0,
|
|
914
|
+
const projects = useAsyncCache(this._ownedProjectsCache, [session], "useOwnedProjects()");
|
|
915
|
+
return (0, import_react2.useMemo)(() => projects.map((j) => this._getOwnedAdminApp(j.id, session)._adminOwnedProjectFromCrud(
|
|
965
916
|
j,
|
|
966
|
-
this._createAdminInterface(j.id, session),
|
|
967
917
|
() => this._refreshOwnedProjects(session)
|
|
968
|
-
)), [
|
|
918
|
+
)), [projects]);
|
|
969
919
|
}
|
|
970
920
|
async _createProject(session, newProject) {
|
|
971
921
|
this._ensureInternalProject();
|
|
972
|
-
const
|
|
973
|
-
const res = this.
|
|
974
|
-
|
|
975
|
-
this._createAdminInterface(json.id, session),
|
|
922
|
+
const crud = await this._interface.createProject(adminProjectCreateOptionsToCrud(newProject), session);
|
|
923
|
+
const res = this._getOwnedAdminApp(crud.id, session)._adminOwnedProjectFromCrud(
|
|
924
|
+
crud,
|
|
976
925
|
() => this._refreshOwnedProjects(session)
|
|
977
926
|
);
|
|
978
927
|
await this._refreshOwnedProjects(session);
|
|
@@ -1056,8 +1005,7 @@ var _StackServerAppImpl = class extends _StackClientAppImpl {
|
|
|
1056
1005
|
});
|
|
1057
1006
|
// TODO override the client user cache to use the server user cache, so we save some requests
|
|
1058
1007
|
this._currentServerUserCache = createCacheBySession(async (session) => {
|
|
1059
|
-
|
|
1060
|
-
return import_results.Result.or(user, null);
|
|
1008
|
+
return await this._interface.getServerUserByToken(session);
|
|
1061
1009
|
});
|
|
1062
1010
|
this._serverUsersCache = createCache(async () => {
|
|
1063
1011
|
return await this._interface.listServerUsers();
|
|
@@ -1069,36 +1017,32 @@ var _StackServerAppImpl = class extends _StackClientAppImpl {
|
|
|
1069
1017
|
this._serverTeamsCache = createCache(async () => {
|
|
1070
1018
|
return await this._interface.listServerTeams();
|
|
1071
1019
|
});
|
|
1072
|
-
this.
|
|
1073
|
-
return await this._interface.
|
|
1020
|
+
this._serverCurrentUserTeamsCache = createCacheBySession(async (session) => {
|
|
1021
|
+
return await this._interface.listServerCurrentUserTeams(session);
|
|
1074
1022
|
});
|
|
1075
|
-
this.
|
|
1076
|
-
return await this._interface.
|
|
1023
|
+
this._serverTeamUsersCache = createCache(async ([teamId]) => {
|
|
1024
|
+
return await this._interface.listServerTeamUsers(teamId);
|
|
1077
1025
|
});
|
|
1078
|
-
this._serverTeamUserPermissionsCache = createCache(async ([teamId, userId,
|
|
1079
|
-
return await this._interface.listServerTeamMemberPermissions({ teamId, userId,
|
|
1080
|
-
});
|
|
1081
|
-
this._serverEmailTemplatesCache = createCache(async () => {
|
|
1082
|
-
return await this._interface.listEmailTemplates();
|
|
1026
|
+
this._serverTeamUserPermissionsCache = createCache(async ([teamId, userId, recursive]) => {
|
|
1027
|
+
return await this._interface.listServerTeamMemberPermissions({ teamId, userId, recursive });
|
|
1083
1028
|
});
|
|
1084
1029
|
}
|
|
1085
|
-
_createBaseUser(
|
|
1030
|
+
_createBaseUser(crud) {
|
|
1031
|
+
if (!crud) {
|
|
1032
|
+
throw new import_errors.StackAssertionError("User not found");
|
|
1033
|
+
}
|
|
1086
1034
|
return {
|
|
1087
|
-
...super._createBaseUser(
|
|
1088
|
-
..."
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
return {
|
|
1092
|
-
...this.toClientJson(),
|
|
1093
|
-
...(0, import_objects.pick)(json, [
|
|
1094
|
-
"serverMetadata"
|
|
1095
|
-
])
|
|
1096
|
-
};
|
|
1097
|
-
}
|
|
1035
|
+
...super._createBaseUser(crud),
|
|
1036
|
+
..."server_metadata" in crud ? {
|
|
1037
|
+
// server user
|
|
1038
|
+
serverMetadata: crud.server_metadata
|
|
1098
1039
|
} : {}
|
|
1099
1040
|
};
|
|
1100
1041
|
}
|
|
1101
|
-
|
|
1042
|
+
_createCurrentUserExtra(crud) {
|
|
1043
|
+
if (!crud) {
|
|
1044
|
+
throw new import_errors.StackAssertionError("User not found");
|
|
1045
|
+
}
|
|
1102
1046
|
const app = this;
|
|
1103
1047
|
return {
|
|
1104
1048
|
async setDisplayName(displayName) {
|
|
@@ -1114,7 +1058,7 @@ var _StackServerAppImpl = class extends _StackClientAppImpl {
|
|
|
1114
1058
|
return await this.update({ selectedTeamId: team?.id ?? null });
|
|
1115
1059
|
},
|
|
1116
1060
|
async setPrimaryEmail(email, options) {
|
|
1117
|
-
return await this.update({ primaryEmail: email });
|
|
1061
|
+
return await this.update({ primaryEmail: email, primaryEmailVerified: options?.verified });
|
|
1118
1062
|
},
|
|
1119
1063
|
getConnectedAccount: async () => {
|
|
1120
1064
|
return await app._checkFeatureSupport("getConnectedAccount() on ServerUser", {});
|
|
@@ -1127,31 +1071,29 @@ var _StackServerAppImpl = class extends _StackClientAppImpl {
|
|
|
1127
1071
|
return teams.find((t) => t.id === teamId) ?? null;
|
|
1128
1072
|
},
|
|
1129
1073
|
useTeam(teamId) {
|
|
1130
|
-
|
|
1131
|
-
return (0, import_react.useMemo)(() => {
|
|
1132
|
-
return teams.find((t) => t.id === teamId) ?? null;
|
|
1133
|
-
}, [teams, teamId]);
|
|
1074
|
+
return app._useCheckFeatureSupport("useTeam() on ServerUser", {});
|
|
1134
1075
|
},
|
|
1135
1076
|
async listTeams() {
|
|
1136
|
-
const
|
|
1137
|
-
|
|
1138
|
-
return withMembers.filter(([_, members]) => members.find((m) => m.userId === json.id)).map(([t]) => t);
|
|
1077
|
+
const crud2 = await app._serverCurrentUserTeamsCache.getOrWait([app._getSession()], "write-only");
|
|
1078
|
+
return crud2.map((t) => app._serverTeamFromCrud(t));
|
|
1139
1079
|
},
|
|
1140
1080
|
useTeams() {
|
|
1141
1081
|
return app._useCheckFeatureSupport("useTeams() on ServerUser", {});
|
|
1142
1082
|
},
|
|
1143
1083
|
createTeam: async (data) => {
|
|
1144
|
-
const team = await app._interface.
|
|
1084
|
+
const team = await app._interface.createServerTeam(serverTeamCreateOptionsToCrud(data), app._getSession());
|
|
1145
1085
|
await app._serverTeamsCache.refresh([]);
|
|
1146
|
-
return app.
|
|
1086
|
+
return app._serverTeamFromCrud(team);
|
|
1147
1087
|
},
|
|
1148
1088
|
async listPermissions(scope, options) {
|
|
1149
|
-
const
|
|
1150
|
-
|
|
1089
|
+
const recursive = options?.recursive ?? true;
|
|
1090
|
+
const permissions = await app._serverTeamUserPermissionsCache.getOrWait([scope.id, crud.id, recursive], "write-only");
|
|
1091
|
+
return permissions.map((crud2) => app._serverPermissionFromCrud(crud2));
|
|
1151
1092
|
},
|
|
1152
1093
|
usePermissions(scope, options) {
|
|
1153
|
-
const
|
|
1154
|
-
|
|
1094
|
+
const recursive = options?.recursive ?? true;
|
|
1095
|
+
const permissions = useAsyncCache(app._serverTeamUserPermissionsCache, [scope.id, crud.id, recursive], "user.usePermissions()");
|
|
1096
|
+
return (0, import_react2.useMemo)(() => permissions.map((crud2) => app._serverPermissionFromCrud(crud2)), [permissions]);
|
|
1155
1097
|
},
|
|
1156
1098
|
async getPermission(scope, permissionId) {
|
|
1157
1099
|
const permissions = await this.listPermissions(scope);
|
|
@@ -1159,32 +1101,31 @@ var _StackServerAppImpl = class extends _StackClientAppImpl {
|
|
|
1159
1101
|
},
|
|
1160
1102
|
usePermission(scope, permissionId) {
|
|
1161
1103
|
const permissions = this.usePermissions(scope);
|
|
1162
|
-
return (0,
|
|
1104
|
+
return (0, import_react2.useMemo)(() => permissions.find((p) => p.id === permissionId) ?? null, [permissions, permissionId]);
|
|
1163
1105
|
},
|
|
1164
1106
|
async hasPermission(scope, permissionId) {
|
|
1165
1107
|
return await this.getPermission(scope, permissionId) !== null;
|
|
1166
1108
|
},
|
|
1167
1109
|
async grantPermission(scope, permissionId) {
|
|
1168
|
-
await app._interface.grantServerTeamUserPermission(scope.id,
|
|
1169
|
-
for (const
|
|
1170
|
-
await app._serverTeamUserPermissionsCache.refresh([scope.id,
|
|
1110
|
+
await app._interface.grantServerTeamUserPermission(scope.id, crud.id, permissionId);
|
|
1111
|
+
for (const recursive of [true, false]) {
|
|
1112
|
+
await app._serverTeamUserPermissionsCache.refresh([scope.id, crud.id, recursive]);
|
|
1171
1113
|
}
|
|
1172
1114
|
},
|
|
1173
1115
|
async revokePermission(scope, permissionId) {
|
|
1174
|
-
await app._interface.revokeServerTeamUserPermission(scope.id,
|
|
1175
|
-
for (const
|
|
1176
|
-
await app._serverTeamUserPermissionsCache.refresh([scope.id,
|
|
1116
|
+
await app._interface.revokeServerTeamUserPermission(scope.id, crud.id, permissionId);
|
|
1117
|
+
for (const recursive of [true, false]) {
|
|
1118
|
+
await app._serverTeamUserPermissionsCache.refresh([scope.id, crud.id, recursive]);
|
|
1177
1119
|
}
|
|
1178
1120
|
},
|
|
1179
1121
|
async delete() {
|
|
1180
|
-
const res = await app._interface.deleteServerServerUser(
|
|
1122
|
+
const res = await app._interface.deleteServerServerUser(crud.id);
|
|
1181
1123
|
await app._refreshUsers();
|
|
1182
1124
|
return res;
|
|
1183
1125
|
},
|
|
1184
1126
|
async update(update) {
|
|
1185
|
-
const res = await app._interface.
|
|
1127
|
+
const res = await app._interface.updateServerUser(crud.id, serverUserUpdateOptionsToCrud(update));
|
|
1186
1128
|
await app._refreshUsers();
|
|
1187
|
-
return res;
|
|
1188
1129
|
},
|
|
1189
1130
|
async sendVerificationEmail() {
|
|
1190
1131
|
return await app._checkFeatureSupport("sendVerificationEmail() on ServerUser", {});
|
|
@@ -1194,76 +1135,65 @@ var _StackServerAppImpl = class extends _StackClientAppImpl {
|
|
|
1194
1135
|
}
|
|
1195
1136
|
};
|
|
1196
1137
|
}
|
|
1197
|
-
|
|
1138
|
+
_serverUserFromCrud(crud) {
|
|
1198
1139
|
return {
|
|
1199
|
-
...this._createBaseUser(
|
|
1200
|
-
...this.
|
|
1140
|
+
...this._createBaseUser(crud),
|
|
1141
|
+
...this._createCurrentUserExtra(crud)
|
|
1201
1142
|
};
|
|
1202
1143
|
}
|
|
1203
|
-
|
|
1144
|
+
_currentUserFromCrud(crud, session) {
|
|
1204
1145
|
const app = this;
|
|
1205
1146
|
const currentUser = {
|
|
1206
|
-
...this.
|
|
1147
|
+
...this._serverUserFromCrud(crud),
|
|
1207
1148
|
...this._createAuth(session),
|
|
1208
1149
|
...this._isInternalProject() ? this._createInternalUserExtra(session) : {}
|
|
1209
1150
|
};
|
|
1210
1151
|
Object.freeze(currentUser);
|
|
1211
1152
|
return currentUser;
|
|
1212
1153
|
}
|
|
1213
|
-
|
|
1214
|
-
if (json === null) return null;
|
|
1154
|
+
_serverTeamFromCrud(crud) {
|
|
1215
1155
|
const app = this;
|
|
1216
1156
|
return {
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
return {
|
|
1224
|
-
id: json.id,
|
|
1225
|
-
displayName: json.displayName,
|
|
1226
|
-
profileImageUrl: json.profileImageUrl,
|
|
1227
|
-
createdAt: new Date(json.createdAtMillis),
|
|
1228
|
-
async listMembers() {
|
|
1229
|
-
return (await app._interface.listServerTeamMembers(json.id)).map((u) => app._serverTeamMemberFromJson(u));
|
|
1157
|
+
id: crud.id,
|
|
1158
|
+
displayName: crud.display_name,
|
|
1159
|
+
profileImageUrl: crud.profile_image_url,
|
|
1160
|
+
createdAt: new Date(crud.created_at_millis),
|
|
1161
|
+
async listUsers() {
|
|
1162
|
+
return (await app._interface.listServerTeamUsers(crud.id)).map((u) => app._serverUserFromCrud(u));
|
|
1230
1163
|
},
|
|
1231
1164
|
async update(update) {
|
|
1232
|
-
await app._interface.updateServerTeam(
|
|
1165
|
+
await app._interface.updateServerTeam(crud.id, serverTeamUpdateOptionsToCrud(update));
|
|
1233
1166
|
await app._serverTeamsCache.refresh([]);
|
|
1234
1167
|
},
|
|
1235
1168
|
async delete() {
|
|
1236
|
-
await app._interface.deleteServerTeam(
|
|
1169
|
+
await app._interface.deleteServerTeam(crud.id);
|
|
1237
1170
|
await app._serverTeamsCache.refresh([]);
|
|
1238
1171
|
},
|
|
1239
|
-
|
|
1240
|
-
const result = useAsyncCache(app.
|
|
1241
|
-
return (0,
|
|
1172
|
+
useUsers() {
|
|
1173
|
+
const result = useAsyncCache(app._serverTeamUsersCache, [crud.id], "team.useUsers()");
|
|
1174
|
+
return (0, import_react2.useMemo)(() => result.map((u) => app._serverUserFromCrud(u)), [result]);
|
|
1242
1175
|
},
|
|
1243
1176
|
async addUser(userId) {
|
|
1244
1177
|
await app._interface.addServerUserToTeam({
|
|
1245
|
-
teamId:
|
|
1178
|
+
teamId: crud.id,
|
|
1246
1179
|
userId
|
|
1247
1180
|
});
|
|
1248
|
-
await app.
|
|
1181
|
+
await app._serverTeamUsersCache.refresh([crud.id]);
|
|
1249
1182
|
},
|
|
1250
1183
|
async removeUser(userId) {
|
|
1251
1184
|
await app._interface.removeServerUserFromTeam({
|
|
1252
|
-
teamId:
|
|
1185
|
+
teamId: crud.id,
|
|
1253
1186
|
userId
|
|
1254
1187
|
});
|
|
1255
|
-
await app.
|
|
1256
|
-
},
|
|
1257
|
-
toJson() {
|
|
1258
|
-
return json;
|
|
1188
|
+
await app._serverTeamUsersCache.refresh([crud.id]);
|
|
1259
1189
|
}
|
|
1260
1190
|
};
|
|
1261
1191
|
}
|
|
1262
1192
|
async getUser(options) {
|
|
1263
1193
|
this._ensurePersistentTokenStore(options?.tokenStore);
|
|
1264
1194
|
const session = this._getSession(options?.tokenStore);
|
|
1265
|
-
const
|
|
1266
|
-
if (
|
|
1195
|
+
const crud = await this._currentServerUserCache.getOrWait([session], "write-only");
|
|
1196
|
+
if (crud === null) {
|
|
1267
1197
|
switch (options?.or) {
|
|
1268
1198
|
case "redirect": {
|
|
1269
1199
|
await this.redirectToSignIn();
|
|
@@ -1277,26 +1207,26 @@ var _StackServerAppImpl = class extends _StackClientAppImpl {
|
|
|
1277
1207
|
}
|
|
1278
1208
|
}
|
|
1279
1209
|
}
|
|
1280
|
-
return
|
|
1210
|
+
return crud && this._currentUserFromCrud(crud, session);
|
|
1281
1211
|
}
|
|
1282
1212
|
async getServerUser() {
|
|
1283
1213
|
console.warn("stackServerApp.getServerUser is deprecated; use stackServerApp.getUser instead");
|
|
1284
1214
|
return await this.getUser();
|
|
1285
1215
|
}
|
|
1286
1216
|
async getServerUserById(userId) {
|
|
1287
|
-
const
|
|
1288
|
-
return
|
|
1217
|
+
const crud = await this._serverUserCache.getOrWait([userId], "write-only");
|
|
1218
|
+
return crud && this._serverUserFromCrud(crud);
|
|
1289
1219
|
}
|
|
1290
1220
|
useUser(options) {
|
|
1291
1221
|
this._ensurePersistentTokenStore(options?.tokenStore);
|
|
1292
1222
|
const router = NextNavigation.useRouter();
|
|
1293
1223
|
const session = this._getSession(options?.tokenStore);
|
|
1294
|
-
const
|
|
1295
|
-
if (
|
|
1224
|
+
const crud = useAsyncCache(this._currentServerUserCache, [session], "useUser()");
|
|
1225
|
+
if (crud === null) {
|
|
1296
1226
|
switch (options?.or) {
|
|
1297
1227
|
case "redirect": {
|
|
1298
1228
|
setTimeout(() => router.replace(this.urls.signIn), 0);
|
|
1299
|
-
(0,
|
|
1229
|
+
(0, import_react.suspend)();
|
|
1300
1230
|
throw new import_errors.StackAssertionError("suspend should never return");
|
|
1301
1231
|
}
|
|
1302
1232
|
case "throw": {
|
|
@@ -1307,66 +1237,51 @@ var _StackServerAppImpl = class extends _StackClientAppImpl {
|
|
|
1307
1237
|
}
|
|
1308
1238
|
}
|
|
1309
1239
|
}
|
|
1310
|
-
return (0,
|
|
1311
|
-
return
|
|
1312
|
-
}, [
|
|
1240
|
+
return (0, import_react2.useMemo)(() => {
|
|
1241
|
+
return crud && this._currentUserFromCrud(crud, session);
|
|
1242
|
+
}, [crud, session, options?.or]);
|
|
1313
1243
|
}
|
|
1314
1244
|
useUserById(userId) {
|
|
1315
|
-
const
|
|
1316
|
-
return (0,
|
|
1317
|
-
return
|
|
1318
|
-
}, [
|
|
1245
|
+
const crud = useAsyncCache(this._serverUserCache, [userId], "useUserById()");
|
|
1246
|
+
return (0, import_react2.useMemo)(() => {
|
|
1247
|
+
return crud && this._serverUserFromCrud(crud);
|
|
1248
|
+
}, [crud]);
|
|
1319
1249
|
}
|
|
1320
1250
|
async listUsers() {
|
|
1321
|
-
const
|
|
1322
|
-
return
|
|
1251
|
+
const crud = await this._serverUsersCache.getOrWait([], "write-only");
|
|
1252
|
+
return crud.map((j) => this._serverUserFromCrud(j));
|
|
1323
1253
|
}
|
|
1324
1254
|
useUsers() {
|
|
1325
|
-
const
|
|
1326
|
-
return (0,
|
|
1327
|
-
return
|
|
1328
|
-
}, [
|
|
1329
|
-
}
|
|
1330
|
-
async listPermissionDefinitions() {
|
|
1331
|
-
return await this._serverTeamPermissionDefinitionsCache.getOrWait([], "write-only");
|
|
1255
|
+
const crud = useAsyncCache(this._serverUsersCache, [], "useServerUsers()");
|
|
1256
|
+
return (0, import_react2.useMemo)(() => {
|
|
1257
|
+
return crud.map((j) => this._serverUserFromCrud(j));
|
|
1258
|
+
}, [crud]);
|
|
1332
1259
|
}
|
|
1333
|
-
|
|
1334
|
-
return useAsyncCache(this._serverTeamPermissionDefinitionsCache, [], "usePermissions()");
|
|
1335
|
-
}
|
|
1336
|
-
_serverPermissionFromJson(json) {
|
|
1260
|
+
_serverPermissionFromCrud(crud) {
|
|
1337
1261
|
return {
|
|
1338
|
-
|
|
1339
|
-
__databaseUniqueId: json.__databaseUniqueId,
|
|
1340
|
-
description: json.description,
|
|
1341
|
-
containPermissionIds: json.containPermissionIds
|
|
1262
|
+
id: crud.id
|
|
1342
1263
|
};
|
|
1343
1264
|
}
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
await this._interface.updatePermissionDefinition(permissionId, data);
|
|
1351
|
-
await this._serverTeamPermissionDefinitionsCache.refresh([]);
|
|
1352
|
-
}
|
|
1353
|
-
async deletePermissionDefinition(permissionId) {
|
|
1354
|
-
await this._interface.deletePermissionDefinition(permissionId);
|
|
1355
|
-
await this._serverTeamPermissionDefinitionsCache.refresh([]);
|
|
1265
|
+
_serverTeamPermissionDefinitionFromCrud(crud) {
|
|
1266
|
+
return {
|
|
1267
|
+
id: crud.id,
|
|
1268
|
+
description: crud.description,
|
|
1269
|
+
containedPermissionIds: crud.contained_permission_ids
|
|
1270
|
+
};
|
|
1356
1271
|
}
|
|
1357
1272
|
async listTeams() {
|
|
1358
1273
|
const teams = await this._serverTeamsCache.getOrWait([], "write-only");
|
|
1359
|
-
return teams.map((t) => this.
|
|
1274
|
+
return teams.map((t) => this._serverTeamFromCrud(t));
|
|
1360
1275
|
}
|
|
1361
1276
|
async createTeam(data) {
|
|
1362
|
-
const team = await this._interface.createServerTeam(data);
|
|
1277
|
+
const team = await this._interface.createServerTeam(serverTeamCreateOptionsToCrud(data));
|
|
1363
1278
|
await this._serverTeamsCache.refresh([]);
|
|
1364
|
-
return this.
|
|
1279
|
+
return this._serverTeamFromCrud(team);
|
|
1365
1280
|
}
|
|
1366
1281
|
useTeams() {
|
|
1367
1282
|
const teams = useAsyncCache(this._serverTeamsCache, [], "useServerTeams()");
|
|
1368
|
-
return (0,
|
|
1369
|
-
return teams.map((t) => this.
|
|
1283
|
+
return (0, import_react2.useMemo)(() => {
|
|
1284
|
+
return teams.map((t) => this._serverTeamFromCrud(t));
|
|
1370
1285
|
}, [teams]);
|
|
1371
1286
|
}
|
|
1372
1287
|
async getTeam(teamId) {
|
|
@@ -1375,7 +1290,7 @@ var _StackServerAppImpl = class extends _StackClientAppImpl {
|
|
|
1375
1290
|
}
|
|
1376
1291
|
useTeam(teamId) {
|
|
1377
1292
|
const teams = this.useTeams();
|
|
1378
|
-
return (0,
|
|
1293
|
+
return (0, import_react2.useMemo)(() => {
|
|
1379
1294
|
return teams.find((t) => t.id === teamId) ?? null;
|
|
1380
1295
|
}, [teams, teamId]);
|
|
1381
1296
|
}
|
|
@@ -1391,20 +1306,6 @@ var _StackServerAppImpl = class extends _StackClientAppImpl {
|
|
|
1391
1306
|
this._serverUsersCache.refresh([])
|
|
1392
1307
|
]);
|
|
1393
1308
|
}
|
|
1394
|
-
useEmailTemplates() {
|
|
1395
|
-
return useAsyncCache(this._serverEmailTemplatesCache, [], "useEmailTemplates()");
|
|
1396
|
-
}
|
|
1397
|
-
async listEmailTemplates() {
|
|
1398
|
-
return await this._serverEmailTemplatesCache.getOrWait([], "write-only");
|
|
1399
|
-
}
|
|
1400
|
-
async updateEmailTemplate(type, data) {
|
|
1401
|
-
await this._interface.updateEmailTemplate(type, data);
|
|
1402
|
-
await this._serverEmailTemplatesCache.refresh([]);
|
|
1403
|
-
}
|
|
1404
|
-
async resetEmailTemplate(type) {
|
|
1405
|
-
await this._interface.resetEmailTemplate(type);
|
|
1406
|
-
await this._serverEmailTemplatesCache.refresh([]);
|
|
1407
|
-
}
|
|
1408
1309
|
};
|
|
1409
1310
|
var _StackAdminAppImpl = class extends _StackServerAppImpl {
|
|
1410
1311
|
constructor(options) {
|
|
@@ -1428,18 +1329,114 @@ var _StackAdminAppImpl = class extends _StackServerAppImpl {
|
|
|
1428
1329
|
this._adminProjectCache = createCache(async () => {
|
|
1429
1330
|
return await this._interface.getProject();
|
|
1430
1331
|
});
|
|
1431
|
-
this.
|
|
1432
|
-
return await this._interface.
|
|
1332
|
+
this._apiKeysCache = createCache(async () => {
|
|
1333
|
+
return await this._interface.listApiKeys();
|
|
1334
|
+
});
|
|
1335
|
+
this._adminEmailTemplatesCache = createCache(async () => {
|
|
1336
|
+
return await this._interface.listEmailTemplates();
|
|
1433
1337
|
});
|
|
1338
|
+
this._adminTeamPermissionDefinitionsCache = createCache(async () => {
|
|
1339
|
+
return await this._interface.listPermissionDefinitions();
|
|
1340
|
+
});
|
|
1341
|
+
}
|
|
1342
|
+
_adminOwnedProjectFromCrud(data, onRefresh) {
|
|
1343
|
+
if (this._tokenStoreInit !== null) {
|
|
1344
|
+
throw new import_errors.StackAssertionError("Owned apps must always have tokenStore === null \u2014 did you not create this project with app._createOwnedApp()?");
|
|
1345
|
+
;
|
|
1346
|
+
}
|
|
1347
|
+
return {
|
|
1348
|
+
...this._adminProjectFromCrud(data, onRefresh),
|
|
1349
|
+
app: this
|
|
1350
|
+
};
|
|
1434
1351
|
}
|
|
1435
|
-
|
|
1352
|
+
_adminProjectFromCrud(data, onRefresh) {
|
|
1353
|
+
if (data.id !== this.projectId) {
|
|
1354
|
+
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})!`);
|
|
1355
|
+
}
|
|
1436
1356
|
const app = this;
|
|
1437
1357
|
return {
|
|
1438
1358
|
id: data.id,
|
|
1359
|
+
displayName: data.display_name,
|
|
1439
1360
|
description: data.description,
|
|
1440
|
-
|
|
1441
|
-
|
|
1442
|
-
|
|
1361
|
+
createdAt: new Date(data.created_at_millis),
|
|
1362
|
+
userCount: data.user_count,
|
|
1363
|
+
isProductionMode: data.is_production_mode,
|
|
1364
|
+
config: {
|
|
1365
|
+
id: data.config.id,
|
|
1366
|
+
credentialEnabled: data.config.credential_enabled,
|
|
1367
|
+
magicLinkEnabled: data.config.magic_link_enabled,
|
|
1368
|
+
allowLocalhost: data.config.allow_localhost,
|
|
1369
|
+
oauthProviders: data.config.oauth_providers.map((p) => p.type === "shared" ? {
|
|
1370
|
+
id: p.id,
|
|
1371
|
+
enabled: p.enabled,
|
|
1372
|
+
type: "shared"
|
|
1373
|
+
} : {
|
|
1374
|
+
id: p.id,
|
|
1375
|
+
enabled: p.enabled,
|
|
1376
|
+
type: "standard",
|
|
1377
|
+
clientId: p.client_id ?? (0, import_errors.throwErr)("Client ID is missing"),
|
|
1378
|
+
clientSecret: p.client_secret ?? (0, import_errors.throwErr)("Client secret is missing")
|
|
1379
|
+
}),
|
|
1380
|
+
emailConfig: data.config.email_config.type === "shared" ? {
|
|
1381
|
+
type: "shared"
|
|
1382
|
+
} : {
|
|
1383
|
+
type: "standard",
|
|
1384
|
+
host: data.config.email_config.host ?? (0, import_errors.throwErr)("Email host is missing"),
|
|
1385
|
+
port: data.config.email_config.port ?? (0, import_errors.throwErr)("Email port is missing"),
|
|
1386
|
+
username: data.config.email_config.username ?? (0, import_errors.throwErr)("Email username is missing"),
|
|
1387
|
+
password: data.config.email_config.password ?? (0, import_errors.throwErr)("Email password is missing"),
|
|
1388
|
+
senderName: data.config.email_config.sender_name ?? (0, import_errors.throwErr)("Email sender name is missing"),
|
|
1389
|
+
senderEmail: data.config.email_config.sender_email ?? (0, import_errors.throwErr)("Email sender email is missing")
|
|
1390
|
+
},
|
|
1391
|
+
domains: data.config.domains.map((d) => ({
|
|
1392
|
+
domain: d.domain,
|
|
1393
|
+
handlerPath: d.handler_path
|
|
1394
|
+
})),
|
|
1395
|
+
createTeamOnSignUp: data.config.create_team_on_sign_up,
|
|
1396
|
+
teamCreatorDefaultPermissions: data.config.team_creator_default_permissions,
|
|
1397
|
+
teamMemberDefaultPermissions: data.config.team_member_default_permissions
|
|
1398
|
+
},
|
|
1399
|
+
async update(update) {
|
|
1400
|
+
await app._interface.updateProject(adminProjectUpdateOptionsToCrud(update));
|
|
1401
|
+
await onRefresh();
|
|
1402
|
+
},
|
|
1403
|
+
async getProductionModeErrors() {
|
|
1404
|
+
return (0, import_production_mode.getProductionModeErrors)(data);
|
|
1405
|
+
},
|
|
1406
|
+
useProductionModeErrors() {
|
|
1407
|
+
return (0, import_production_mode.getProductionModeErrors)(data);
|
|
1408
|
+
}
|
|
1409
|
+
};
|
|
1410
|
+
}
|
|
1411
|
+
_adminEmailTemplateFromCrud(data) {
|
|
1412
|
+
return {
|
|
1413
|
+
type: data.type,
|
|
1414
|
+
subject: data.subject,
|
|
1415
|
+
content: data.content,
|
|
1416
|
+
isDefault: data.is_default
|
|
1417
|
+
};
|
|
1418
|
+
}
|
|
1419
|
+
async getProject() {
|
|
1420
|
+
return this._adminProjectFromCrud(
|
|
1421
|
+
await this._adminProjectCache.getOrWait([], "write-only"),
|
|
1422
|
+
() => this._refreshProject()
|
|
1423
|
+
);
|
|
1424
|
+
}
|
|
1425
|
+
useProject() {
|
|
1426
|
+
const crud = useAsyncCache(this._adminProjectCache, [], "useProjectAdmin()");
|
|
1427
|
+
return (0, import_react2.useMemo)(() => this._adminProjectFromCrud(
|
|
1428
|
+
crud,
|
|
1429
|
+
() => this._refreshProject()
|
|
1430
|
+
), [crud]);
|
|
1431
|
+
}
|
|
1432
|
+
_createApiKeyBaseFromCrud(data) {
|
|
1433
|
+
const app = this;
|
|
1434
|
+
return {
|
|
1435
|
+
id: data.id,
|
|
1436
|
+
description: data.description,
|
|
1437
|
+
expiresAt: new Date(data.expires_at_millis),
|
|
1438
|
+
manuallyRevokedAt: data.manually_revoked_at_millis ? new Date(data.manually_revoked_at_millis) : null,
|
|
1439
|
+
createdAt: new Date(data.created_at_millis),
|
|
1443
1440
|
isValid() {
|
|
1444
1441
|
return this.whyInvalid() === null;
|
|
1445
1442
|
},
|
|
@@ -1449,57 +1446,83 @@ var _StackAdminAppImpl = class extends _StackServerAppImpl {
|
|
|
1449
1446
|
return null;
|
|
1450
1447
|
},
|
|
1451
1448
|
async revoke() {
|
|
1452
|
-
const res = await app._interface.
|
|
1453
|
-
await app.
|
|
1449
|
+
const res = await app._interface.revokeApiKeyById(data.id);
|
|
1450
|
+
await app._refreshApiKeys();
|
|
1454
1451
|
return res;
|
|
1455
1452
|
}
|
|
1456
1453
|
};
|
|
1457
1454
|
}
|
|
1458
|
-
|
|
1455
|
+
_createApiKeyFromCrud(data) {
|
|
1459
1456
|
return {
|
|
1460
|
-
...this.
|
|
1461
|
-
publishableClientKey: data.
|
|
1462
|
-
secretServerKey: data.
|
|
1463
|
-
superSecretAdminKey: data.
|
|
1457
|
+
...this._createApiKeyBaseFromCrud(data),
|
|
1458
|
+
publishableClientKey: data.publishable_client_key ? { lastFour: data.publishable_client_key.last_four } : null,
|
|
1459
|
+
secretServerKey: data.secret_server_key ? { lastFour: data.secret_server_key.last_four } : null,
|
|
1460
|
+
superSecretAdminKey: data.super_secret_admin_key ? { lastFour: data.super_secret_admin_key.last_four } : null
|
|
1464
1461
|
};
|
|
1465
1462
|
}
|
|
1466
|
-
|
|
1463
|
+
_createApiKeyFirstViewFromCrud(data) {
|
|
1467
1464
|
return {
|
|
1468
|
-
...this.
|
|
1469
|
-
publishableClientKey: data.
|
|
1470
|
-
secretServerKey: data.
|
|
1471
|
-
superSecretAdminKey: data.
|
|
1465
|
+
...this._createApiKeyBaseFromCrud(data),
|
|
1466
|
+
publishableClientKey: data.publishable_client_key,
|
|
1467
|
+
secretServerKey: data.secret_server_key,
|
|
1468
|
+
superSecretAdminKey: data.super_secret_admin_key
|
|
1472
1469
|
};
|
|
1473
1470
|
}
|
|
1474
|
-
async
|
|
1475
|
-
|
|
1476
|
-
|
|
1477
|
-
this._interface,
|
|
1478
|
-
() => this._refreshProject()
|
|
1479
|
-
);
|
|
1471
|
+
async listApiKeys() {
|
|
1472
|
+
const crud = await this._apiKeysCache.getOrWait([], "write-only");
|
|
1473
|
+
return crud.map((j) => this._createApiKeyFromCrud(j));
|
|
1480
1474
|
}
|
|
1481
|
-
|
|
1482
|
-
const
|
|
1483
|
-
return (0,
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
|
|
1475
|
+
useApiKeys() {
|
|
1476
|
+
const crud = useAsyncCache(this._apiKeysCache, [], "useApiKeys()");
|
|
1477
|
+
return (0, import_react2.useMemo)(() => {
|
|
1478
|
+
return crud.map((j) => this._createApiKeyFromCrud(j));
|
|
1479
|
+
}, [crud]);
|
|
1480
|
+
}
|
|
1481
|
+
async createApiKey(options) {
|
|
1482
|
+
const crud = await this._interface.createApiKey(apiKeyCreateOptionsToCrud(options));
|
|
1483
|
+
await this._refreshApiKeys();
|
|
1484
|
+
return this._createApiKeyFirstViewFromCrud(crud);
|
|
1485
|
+
}
|
|
1486
|
+
useEmailTemplates() {
|
|
1487
|
+
const crud = useAsyncCache(this._adminEmailTemplatesCache, [], "useEmailTemplates()");
|
|
1488
|
+
return (0, import_react2.useMemo)(() => {
|
|
1489
|
+
return crud.map((j) => this._adminEmailTemplateFromCrud(j));
|
|
1490
|
+
}, [crud]);
|
|
1491
|
+
}
|
|
1492
|
+
async listEmailTemplates() {
|
|
1493
|
+
const crud = await this._adminEmailTemplatesCache.getOrWait([], "write-only");
|
|
1494
|
+
return crud.map((j) => this._adminEmailTemplateFromCrud(j));
|
|
1488
1495
|
}
|
|
1489
|
-
async
|
|
1490
|
-
|
|
1491
|
-
|
|
1496
|
+
async updateEmailTemplate(type, data) {
|
|
1497
|
+
await this._interface.updateEmailTemplate(type, adminEmailTemplateUpdateOptionsToCrud(data));
|
|
1498
|
+
await this._adminEmailTemplatesCache.refresh([]);
|
|
1499
|
+
}
|
|
1500
|
+
async resetEmailTemplate(type) {
|
|
1501
|
+
await this._interface.resetEmailTemplate(type);
|
|
1502
|
+
await this._adminEmailTemplatesCache.refresh([]);
|
|
1492
1503
|
}
|
|
1493
|
-
|
|
1494
|
-
const
|
|
1495
|
-
|
|
1496
|
-
|
|
1497
|
-
}, [json]);
|
|
1504
|
+
async createTeamPermissionDefinition(data) {
|
|
1505
|
+
const crud = await this._interface.createPermissionDefinition(serverTeamPermissionDefinitionCreateOptionsToCrud(data));
|
|
1506
|
+
await this._adminTeamPermissionDefinitionsCache.refresh([]);
|
|
1507
|
+
return this._serverTeamPermissionDefinitionFromCrud(crud);
|
|
1498
1508
|
}
|
|
1499
|
-
async
|
|
1500
|
-
|
|
1501
|
-
await this.
|
|
1502
|
-
|
|
1509
|
+
async updateTeamPermissionDefinition(permissionId, data) {
|
|
1510
|
+
await this._interface.updatePermissionDefinition(permissionId, data);
|
|
1511
|
+
await this._adminTeamPermissionDefinitionsCache.refresh([]);
|
|
1512
|
+
}
|
|
1513
|
+
async deleteTeamPermissionDefinition(permissionId) {
|
|
1514
|
+
await this._interface.deletePermissionDefinition(permissionId);
|
|
1515
|
+
await this._adminTeamPermissionDefinitionsCache.refresh([]);
|
|
1516
|
+
}
|
|
1517
|
+
async listTeamPermissionDefinitions() {
|
|
1518
|
+
const crud = await this._adminTeamPermissionDefinitionsCache.getOrWait([], "write-only");
|
|
1519
|
+
return crud.map((p) => this._serverTeamPermissionDefinitionFromCrud(p));
|
|
1520
|
+
}
|
|
1521
|
+
useTeamPermissionDefinitions() {
|
|
1522
|
+
const crud = useAsyncCache(this._adminTeamPermissionDefinitionsCache, [], "usePermissions()");
|
|
1523
|
+
return (0, import_react2.useMemo)(() => {
|
|
1524
|
+
return crud.map((p) => this._serverTeamPermissionDefinitionFromCrud(p));
|
|
1525
|
+
}, [crud]);
|
|
1503
1526
|
}
|
|
1504
1527
|
async _refreshProject() {
|
|
1505
1528
|
await Promise.all([
|
|
@@ -1507,18 +1530,126 @@ var _StackAdminAppImpl = class extends _StackServerAppImpl {
|
|
|
1507
1530
|
this._adminProjectCache.refresh([])
|
|
1508
1531
|
]);
|
|
1509
1532
|
}
|
|
1510
|
-
async
|
|
1511
|
-
await this.
|
|
1533
|
+
async _refreshApiKeys() {
|
|
1534
|
+
await this._apiKeysCache.refresh([]);
|
|
1512
1535
|
}
|
|
1513
1536
|
};
|
|
1537
|
+
function userUpdateOptionsToCrud(options) {
|
|
1538
|
+
return {
|
|
1539
|
+
display_name: options.displayName,
|
|
1540
|
+
client_metadata: options.clientMetadata,
|
|
1541
|
+
selected_team_id: options.selectedTeamId
|
|
1542
|
+
};
|
|
1543
|
+
}
|
|
1544
|
+
function serverUserUpdateOptionsToCrud(options) {
|
|
1545
|
+
return {
|
|
1546
|
+
display_name: options.displayName,
|
|
1547
|
+
client_metadata: options.clientMetadata,
|
|
1548
|
+
selected_team_id: options.selectedTeamId,
|
|
1549
|
+
primary_email: options.primaryEmail,
|
|
1550
|
+
primary_email_verified: options.primaryEmailVerified,
|
|
1551
|
+
server_metadata: options.serverMetadata
|
|
1552
|
+
};
|
|
1553
|
+
}
|
|
1554
|
+
function adminProjectUpdateOptionsToCrud(options) {
|
|
1555
|
+
return {
|
|
1556
|
+
display_name: options.displayName,
|
|
1557
|
+
description: options.description,
|
|
1558
|
+
is_production_mode: options.isProductionMode,
|
|
1559
|
+
config: {
|
|
1560
|
+
domains: options.config?.domains?.map((d) => ({
|
|
1561
|
+
domain: d.domain,
|
|
1562
|
+
handler_path: d.handlerPath
|
|
1563
|
+
})),
|
|
1564
|
+
oauth_providers: options.config?.oauthProviders?.map((p) => ({
|
|
1565
|
+
id: p.id,
|
|
1566
|
+
enabled: p.enabled,
|
|
1567
|
+
type: p.type,
|
|
1568
|
+
...p.type === "standard" && {
|
|
1569
|
+
client_id: p.clientId,
|
|
1570
|
+
client_secret: p.clientSecret
|
|
1571
|
+
}
|
|
1572
|
+
})),
|
|
1573
|
+
email_config: options.config?.emailConfig && (options.config.emailConfig.type === "shared" ? {
|
|
1574
|
+
type: "shared"
|
|
1575
|
+
} : {
|
|
1576
|
+
type: "standard",
|
|
1577
|
+
host: options.config.emailConfig.host,
|
|
1578
|
+
port: options.config.emailConfig.port,
|
|
1579
|
+
username: options.config.emailConfig.username,
|
|
1580
|
+
password: options.config.emailConfig.password,
|
|
1581
|
+
sender_name: options.config.emailConfig.senderName,
|
|
1582
|
+
sender_email: options.config.emailConfig.senderEmail
|
|
1583
|
+
}),
|
|
1584
|
+
credential_enabled: options.config?.credentialEnabled,
|
|
1585
|
+
magic_link_enabled: options.config?.magicLinkEnabled,
|
|
1586
|
+
allow_localhost: options.config?.allowLocalhost,
|
|
1587
|
+
create_team_on_sign_up: options.config?.createTeamOnSignUp,
|
|
1588
|
+
team_creator_default_permissions: options.config?.teamCreatorDefaultPermissions,
|
|
1589
|
+
team_member_default_permissions: options.config?.teamMemberDefaultPermissions
|
|
1590
|
+
}
|
|
1591
|
+
};
|
|
1592
|
+
}
|
|
1593
|
+
function adminProjectCreateOptionsToCrud(options) {
|
|
1594
|
+
return {
|
|
1595
|
+
...adminProjectUpdateOptionsToCrud(options),
|
|
1596
|
+
display_name: options.displayName
|
|
1597
|
+
};
|
|
1598
|
+
}
|
|
1599
|
+
function apiKeyCreateOptionsToCrud(options) {
|
|
1600
|
+
return {
|
|
1601
|
+
description: options.description,
|
|
1602
|
+
expires_at_millis: options.expiresAt.getTime(),
|
|
1603
|
+
has_publishable_client_key: options.hasPublishableClientKey,
|
|
1604
|
+
has_secret_server_key: options.hasSecretServerKey,
|
|
1605
|
+
has_super_secret_admin_key: options.hasSuperSecretAdminKey
|
|
1606
|
+
};
|
|
1607
|
+
}
|
|
1608
|
+
function teamCreateOptionsToCrud(options) {
|
|
1609
|
+
return {
|
|
1610
|
+
display_name: options.displayName,
|
|
1611
|
+
profile_image_url: options.profileImageUrl
|
|
1612
|
+
};
|
|
1613
|
+
}
|
|
1614
|
+
function serverTeamCreateOptionsToCrud(options) {
|
|
1615
|
+
return teamCreateOptionsToCrud(options);
|
|
1616
|
+
}
|
|
1617
|
+
function serverTeamUpdateOptionsToCrud(options) {
|
|
1618
|
+
return {
|
|
1619
|
+
display_name: options.displayName,
|
|
1620
|
+
profile_image_url: options.profileImageUrl
|
|
1621
|
+
};
|
|
1622
|
+
}
|
|
1623
|
+
function serverTeamPermissionDefinitionCreateOptionsToCrud(options) {
|
|
1624
|
+
return {
|
|
1625
|
+
id: options.id,
|
|
1626
|
+
description: options.description,
|
|
1627
|
+
contained_permission_ids: options.containedPermissionIds
|
|
1628
|
+
};
|
|
1629
|
+
}
|
|
1630
|
+
function serverTeamPermissionDefinitionUpdateOptionsToCrud(options) {
|
|
1631
|
+
return {
|
|
1632
|
+
id: options.id,
|
|
1633
|
+
description: options.description,
|
|
1634
|
+
contained_permission_ids: options.containedPermissionIds
|
|
1635
|
+
};
|
|
1636
|
+
}
|
|
1514
1637
|
var StackClientApp = _StackClientAppImpl;
|
|
1515
1638
|
var StackServerApp = _StackServerAppImpl;
|
|
1516
1639
|
var StackAdminApp = _StackAdminAppImpl;
|
|
1640
|
+
function adminEmailTemplateUpdateOptionsToCrud(options) {
|
|
1641
|
+
return {
|
|
1642
|
+
subject: options.subject,
|
|
1643
|
+
content: options.content
|
|
1644
|
+
};
|
|
1645
|
+
}
|
|
1517
1646
|
// Annotate the CommonJS export names for ESM import in node:
|
|
1518
1647
|
0 && (module.exports = {
|
|
1519
1648
|
StackAdminApp,
|
|
1520
1649
|
StackClientApp,
|
|
1521
1650
|
StackServerApp,
|
|
1651
|
+
serverTeamPermissionDefinitionCreateOptionsToCrud,
|
|
1652
|
+
serverTeamPermissionDefinitionUpdateOptionsToCrud,
|
|
1522
1653
|
stackAppInternalsSymbol
|
|
1523
1654
|
});
|
|
1524
1655
|
//# sourceMappingURL=stack-app.js.map
|