Refactor updateConfigOverrides to handle legacy config structure and improve config management in StackAdminInterface

This commit is contained in:
Zai Shi 2025-07-25 10:02:01 -07:00
parent 1afbf069c4
commit c18cae3199
2 changed files with 64 additions and 4 deletions

View File

@ -1,4 +1,5 @@
import { InternalSession } from "../sessions";
import { filterUndefined, typedFromEntries } from "../utils/objects";
import { ConfigOverridesCrud } from "./crud/config-overrides";
import { EmailTemplateCrud, EmailTemplateType } from "./crud/email-templates";
import { InternalEmailsCrud } from "./crud/emails";
@ -482,10 +483,64 @@ export class StackAdminInterface extends StackServerInterface {
return await response.json();
}
async updateConfigOverrides(data: ConfigOverridesCrud["Admin"]["Update"]): Promise<ConfigOverridesCrud["Admin"]["Read"]> {
async updateConfigOverrides(data: { config: any }): Promise<ConfigOverridesCrud["Admin"]["Read"]> {
const legacyConfig = data.config;
const configOverrideOverride = filterUndefined({
// ======================= auth =======================
'auth.allowSignUp': legacyConfig.sign_up_enabled,
'auth.password.allowSignIn': legacyConfig.credential_enabled,
'auth.otp.allowSignIn': legacyConfig.magic_link_enabled,
'auth.passkey.allowSignIn': legacyConfig.passkey_enabled,
'auth.oauth.accountMergeStrategy': legacyConfig.oauth_account_merge_strategy,
'auth.oauth.providers': legacyConfig.oauth_providers ? typedFromEntries(legacyConfig.oauth_providers
.map((provider: any) => {
return [
provider.id,
{
type: provider.id,
isShared: provider.type === "shared",
clientId: provider.client_id,
clientSecret: provider.client_secret,
facebookConfigId: provider.facebook_config_id,
microsoftTenantId: provider.microsoft_tenant_id,
allowSignIn: true,
allowConnectedAccounts: true,
}
];
})) : undefined,
// ======================= users =======================
'users.allowClientUserDeletion': legacyConfig.client_user_deletion_enabled,
// ======================= teams =======================
'teams.allowClientTeamCreation': legacyConfig.client_team_creation_enabled,
'teams.createPersonalTeamOnSignUp': legacyConfig.create_team_on_sign_up,
// ======================= domains =======================
'domains.allowLocalhost': legacyConfig.allow_localhost ?? true,
'domains.trustedDomains': legacyConfig.domains ? legacyConfig.domains.map((domain: any) => {
return {
baseUrl: domain.domain,
handlerPath: domain.handler_path,
};
}) : undefined,
// ======================= api keys =======================
'apiKeys.enabled.user': legacyConfig.allow_user_api_keys,
'apiKeys.enabled.team': legacyConfig.allow_team_api_keys,
// ======================= emails =======================
'emails.server': legacyConfig.email_config ? {
isShared: legacyConfig.email_config.type === 'shared',
host: legacyConfig.email_config.host,
port: legacyConfig.email_config.port,
username: legacyConfig.email_config.username,
password: legacyConfig.email_config.password,
senderName: legacyConfig.email_config.sender_name,
senderEmail: legacyConfig.email_config.sender_email,
} : undefined,
'emails.theme': legacyConfig.email_theme,
});
const response = await this.sendAdminRequest(
`/internal/config-overrides`,
{ method: "PATCH", body: JSON.stringify(data) },
{ method: "PATCH", body: JSON.stringify({ config: JSON.stringify(configOverrideOverride) }) },
null,
);
return await response.json();

View File

@ -5,7 +5,7 @@ import { EmailTemplateCrud, EmailTemplateType } from "@stackframe/stack-shared/d
import { InternalApiKeysCrud } from "@stackframe/stack-shared/dist/interface/crud/internal-api-keys";
import { ProjectsCrud } from "@stackframe/stack-shared/dist/interface/crud/projects";
import { StackAssertionError, throwErr } from "@stackframe/stack-shared/dist/utils/errors";
import { pick } from "@stackframe/stack-shared/dist/utils/objects";
import { filterUndefined, pick } from "@stackframe/stack-shared/dist/utils/objects";
import { Result } from "@stackframe/stack-shared/dist/utils/results";
import { useMemo } from "react"; // THIS_LINE_PLATFORM react-like
import { AdminSentEmail } from "../..";
@ -152,7 +152,12 @@ export class _StackAdminAppImplIncomplete<HasTokenStore extends boolean, Project
},
async update(update: AdminProjectUpdateOptions) {
await app._interface.updateProject(adminProjectUpdateOptionsToCrud(update));
const updateOptions = adminProjectUpdateOptionsToCrud(update);
await app._interface.updateProject(filterUndefined({
...updateOptions,
config: undefined,
}));
await app._interface.updateConfigOverrides({ config: updateOptions.config });
await onRefresh();
},
async delete() {