chore(trpc): type-safety cleanups across routers

This commit is contained in:
ephraimduncan
2026-08-15 13:49:02 +00:00
parent 688ef2fdf3
commit e7b66fe069
22 changed files with 1537 additions and 21 deletions
@@ -1,7 +1,6 @@
import { AppError, AppErrorCode } from '@documenso/lib/errors/app-error';
import {
decryptEmailTransportConfig,
EMAIL_TRANSPORT_SECRET_KEYS,
encryptEmailTransportConfig,
ZEmailTransportConfigSchema,
} from '@documenso/lib/server-only/email/email-transport-config';
@@ -30,16 +29,16 @@ export const updateEmailTransportRoute = adminProcedure
const existingConfig = decryptEmailTransportConfig(existing.config);
// Start from the incoming config; backfill empty secret fields from the existing
// config (only when the type is unchanged).
const merged: Record<string, unknown> = { ...data.config };
// config (only when the type is unchanged). Secrets are never sent back to the
// client, so a blank incoming value means "keep the existing secret".
const merged = { ...data.config };
if (existingConfig.type === data.config.type) {
for (const key of EMAIL_TRANSPORT_SECRET_KEYS) {
const incoming = (data.config as Record<string, unknown>)[key];
if (incoming === undefined || incoming === '') {
merged[key] = (existingConfig as Record<string, unknown>)[key];
}
}
if (merged.type === 'SMTP_AUTH' && existingConfig.type === 'SMTP_AUTH' && !merged.password) {
merged.password = existingConfig.password;
}
if (merged.type !== 'SMTP_AUTH' && merged.type === existingConfig.type && !merged.apiKey) {
merged.apiKey = existingConfig.apiKey;
}
const config = ZEmailTransportConfigSchema.parse(merged);
@@ -148,7 +148,7 @@ export const updateOrganisationMemberRoleRoute = adminProcedure
return;
}
const targetRole = role as OrganisationMemberRole;
const targetRole = role;
if (currentOrganisationRole === targetRole) {
throw new AppError(AppErrorCode.INVALID_REQUEST, {
@@ -54,10 +54,11 @@ export const updateSubscriptionClaimRoute = adminProcedure
}
});
function getNewTruthyFlags(a: Partial<TClaimFlags>, b: Partial<TClaimFlags>): Record<keyof TClaimFlags, true> {
function getNewTruthyFlags(a: Partial<TClaimFlags>, b: Partial<TClaimFlags>) {
const flags: { [key in keyof TClaimFlags]?: true } = {};
for (const key in b) {
// SAFETY: `b` is a Partial<TClaimFlags>, so its enumerable keys are TClaimFlags keys.
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
const typedKey = key as keyof TClaimFlags;
@@ -66,6 +67,5 @@ function getNewTruthyFlags(a: Partial<TClaimFlags>, b: Partial<TClaimFlags>): Re
}
}
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
return flags as Record<keyof TClaimFlags, true>;
return flags;
}