/
githubmirror
/
novu
Обзор
Документация
Войти
/
githubmirror
/
novu
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
next
apps/api/src/app/environment-variables/usecases/validate-environment-variable-values.ts
46 строк
2 KB
Dima Grossman
fix(api-service): scope env variable writes and environment deletes to API key environment fixes NV-8182 (#11781)
05 июл 2026, 15:40
Не верифицирован
05 июл 2026, 15:40
48084bd
Код
Авторство
О чём код?
import { ForbiddenException, NotFoundException } from '@nestjs/common'; import { EnvironmentRepository } from '@novu/dal'; type EnvironmentVariableValueInput = { _environmentId: string; }; type ValidateEnvironmentVariableValuesOptions = { restrictToUserEnvironment?: boolean; userEnvironmentId?: string; }; export async function validateEnvironmentVariableValues( environmentRepository: EnvironmentRepository, organizationId: string, values: EnvironmentVariableValueInput[] | undefined, options?: ValidateEnvironmentVariableValuesOptions ): Promise<void> { if (!values?.length) { return; } if (options?.restrictToUserEnvironment && options.userEnvironmentId) { const crossEnvironmentValue = values.find((value) => value._environmentId !== options.userEnvironmentId); if (crossEnvironmentValue) { throw new ForbiddenException( 'This authentication scheme is scoped to a single environment and cannot target a different `_environmentId`. ' + 'Use credentials from the target environment, or authenticate with a session token.' ); } } const uniqueEnvironmentIds = [...new Set(values.map((value) => value._environmentId))]; const environments = await Promise.all( uniqueEnvironmentIds.map((environmentId) => environmentRepository.findByIdAndOrganization(environmentId, organizationId) ) ); const invalidEnvironmentIndex = environments.findIndex((environment) => !environment); if (invalidEnvironmentIndex !== -1) { throw new NotFoundException(`Environment with id ${uniqueEnvironmentIds[invalidEnvironmentIndex]} not found`); } }