diff --git a/.changeset/ten-months-run.md b/.changeset/ten-months-run.md new file mode 100644 index 00000000..7af93bdd --- /dev/null +++ b/.changeset/ten-months-run.md @@ -0,0 +1,5 @@ +--- +"@comet/brevo-api": minor +--- + +Add `BREVO_FOLDER_ID` to environment variables to allow overwriting default value `1` diff --git a/.env b/.env index 5857a47d..6325b516 100644 --- a/.env +++ b/.env @@ -85,3 +85,4 @@ NEXT_PUBLIC_CAMPAIGN_IS_PREVIEW=false REDIRECT_URL_FOR_IMPORT=$SITE_URL BREVO_ALLOWED_REDIRECT_URL=http://${DEV_DOMAIN:-localhost}${WORKAROUND_DOTENV_ISSUE}:${SITE_PORT} CAMPAIGNS_FRONTEND_URL=http://${DEV_DOMAIN:-localhost}${WORKAROUND_DOTENV_ISSUE}:${SITE_PORT} # doesn't work, TODO: add actual mailing frontend +BREVO_FOLDER_ID=1 diff --git a/demo/api/src/app.module.ts b/demo/api/src/app.module.ts index 38b0765d..5c9b9981 100644 --- a/demo/api/src/app.module.ts +++ b/demo/api/src/app.module.ts @@ -148,6 +148,7 @@ export class AppModule { sender: { name: config.brevo.sender.name, email: config.brevo.sender.email }, allowedRedirectUrl: config.brevo.allowedRedirectUrl, redirectUrlForImport: config.brevo.redirectUrlForImport, + folderId: config.brevo.folderId ?? 1, // folderId is required, folder #1 is created by default }; } else { return { @@ -156,6 +157,7 @@ export class AppModule { sender: { name: config.brevo.sender.name, email: config.brevo.sender.email }, allowedRedirectUrl: config.brevo.allowedRedirectUrl, redirectUrlForImport: config.brevo.redirectUrlForImport, + folderId: config.brevo.folderId ?? 1, // folderId is required, folder #1 is created by default }; } }, diff --git a/demo/api/src/config/config.ts b/demo/api/src/config/config.ts index 3eb8c825..72e1ac40 100644 --- a/demo/api/src/config/config.ts +++ b/demo/api/src/config/config.ts @@ -64,6 +64,7 @@ export function createConfig(processEnv: NodeJS.ProcessEnv) { email: envVars.BREVO_SENDER_EMAIL, }, redirectUrlForImport: envVars.REDIRECT_URL_FOR_IMPORT, + folderId: envVars.BREVO_FOLDER_ID, }, campaign: { url: envVars.CAMPAIGN_URL, diff --git a/demo/api/src/config/environment-variables.ts b/demo/api/src/config/environment-variables.ts index b094b38f..23f92d70 100644 --- a/demo/api/src/config/environment-variables.ts +++ b/demo/api/src/config/environment-variables.ts @@ -1,5 +1,5 @@ /* eslint-disable @typescript-eslint/naming-convention */ -import { BlobStorageConfig } from "@comet/cms-api"; +import { BlobStorageConfig, IsUndefinable } from "@comet/cms-api"; import { Transform, Type } from "class-transformer"; import { IsBase64, IsBoolean, IsEmail, IsInt, IsNumber, IsOptional, IsString, MinLength, ValidateIf } from "class-validator"; @@ -142,4 +142,9 @@ export class EnvironmentVariables { @IsString() CAMPAIGN_BASIC_AUTH_PASSWORD: string; + + @IsNumber() + @IsUndefinable() + @Type(() => Number) + BREVO_FOLDER_ID?: number; } diff --git a/packages/api/src/brevo-api/brevo-api-contact.service.ts b/packages/api/src/brevo-api/brevo-api-contact.service.ts index 3627751d..4f68e857 100644 --- a/packages/api/src/brevo-api/brevo-api-contact.service.ts +++ b/packages/api/src/brevo-api/brevo-api-contact.service.ts @@ -186,10 +186,12 @@ export class BrevoApiContactsService { } public async createBrevoContactList(title: string, scope: EmailCampaignScopeInterface): Promise { + const folderId = this.config.brevo.resolveConfig(scope).folderId; + try { const contactList = { name: title, - folderId: 1, // folderId is required, folder #1 is created by default + folderId: folderId ?? 1, }; const data = await this.getContactsApi(scope).createList(contactList); diff --git a/packages/api/src/config/brevo-module.config.ts b/packages/api/src/config/brevo-module.config.ts index e1de61f7..7307b29d 100644 --- a/packages/api/src/config/brevo-module.config.ts +++ b/packages/api/src/config/brevo-module.config.ts @@ -15,6 +15,7 @@ export interface BrevoModuleConfig { }; allowedRedirectUrl: string; redirectUrlForImport: string; + folderId?: number; }; BrevoContactAttributes?: Type; BrevoContactFilterAttributes?: Type;