From fe1494bb5c02d83ec6c3dd2d8e5fd3273dfac2ab Mon Sep 17 00:00:00 2001 From: Julia Wegmayr Date: Thu, 28 Nov 2024 09:01:29 +0100 Subject: [PATCH 1/6] add folderId to environment variables --- .env | 1 + demo/api/src/app.module.ts | 2 ++ demo/api/src/config/config.ts | 1 + demo/api/src/config/environment-variables.ts | 4 ++++ packages/api/src/brevo-api/brevo-api-contact.service.ts | 4 +++- packages/api/src/config/brevo-module.config.ts | 1 + 6 files changed, 12 insertions(+), 1 deletion(-) diff --git a/.env b/.env index 5857a47d..3b39eefd 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=457 diff --git a/demo/api/src/app.module.ts b/demo/api/src/app.module.ts index 38b0765d..1be1b434 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, }; } 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, }; } }, 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..3f218473 100644 --- a/demo/api/src/config/environment-variables.ts +++ b/demo/api/src/config/environment-variables.ts @@ -142,4 +142,8 @@ export class EnvironmentVariables { @IsString() CAMPAIGN_BASIC_AUTH_PASSWORD: string; + + @IsNumber() + @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..a0490eed 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, // folderId is required, folder #1 is created by default }; 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..4ae56b9a 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; From 4ee276047be4e659672bac36ae6499f847df1b96 Mon Sep 17 00:00:00 2001 From: Julia Wegmayr Date: Thu, 28 Nov 2024 09:17:49 +0100 Subject: [PATCH 2/6] add changeset --- .changeset/ten-months-run.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/ten-months-run.md 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` From 65030841040a19cfdb787abdc949c32f8e0eea01 Mon Sep 17 00:00:00 2001 From: Julia Wegmayr Date: Mon, 9 Dec 2024 09:44:24 +0100 Subject: [PATCH 3/6] set folderId to optional in environmental variables and handle undefined folderId --- .env | 2 +- demo/api/src/app.module.ts | 4 ++-- demo/api/src/config/environment-variables.ts | 5 +++-- packages/api/src/brevo-api/brevo-api-contact.service.ts | 2 +- 4 files changed, 7 insertions(+), 6 deletions(-) diff --git a/.env b/.env index 3b39eefd..b7c7dabd 100644 --- a/.env +++ b/.env @@ -85,4 +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=457 +BREVO_FOLDER_ID= diff --git a/demo/api/src/app.module.ts b/demo/api/src/app.module.ts index 1be1b434..5c9b9981 100644 --- a/demo/api/src/app.module.ts +++ b/demo/api/src/app.module.ts @@ -148,7 +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, + folderId: config.brevo.folderId ?? 1, // folderId is required, folder #1 is created by default }; } else { return { @@ -157,7 +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, + folderId: config.brevo.folderId ?? 1, // folderId is required, folder #1 is created by default }; } }, diff --git a/demo/api/src/config/environment-variables.ts b/demo/api/src/config/environment-variables.ts index 3f218473..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"; @@ -144,6 +144,7 @@ export class EnvironmentVariables { CAMPAIGN_BASIC_AUTH_PASSWORD: string; @IsNumber() + @IsUndefinable() @Type(() => Number) - BREVO_FOLDER_ID: 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 a0490eed..d4f3179a 100644 --- a/packages/api/src/brevo-api/brevo-api-contact.service.ts +++ b/packages/api/src/brevo-api/brevo-api-contact.service.ts @@ -191,7 +191,7 @@ export class BrevoApiContactsService { try { const contactList = { name: title, - folderId: folderId ?? 1, // folderId is required, folder #1 is created by default + folderId: folderId, }; const data = await this.getContactsApi(scope).createList(contactList); From ae8df102dbdbce0e39aa40ece8ff10f796cef326 Mon Sep 17 00:00:00 2001 From: Julia Wegmayr Date: Mon, 9 Dec 2024 14:43:45 +0100 Subject: [PATCH 4/6] set BrevoFolderId to 1 in env --- .env | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.env b/.env index b7c7dabd..6325b516 100644 --- a/.env +++ b/.env @@ -85,4 +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= +BREVO_FOLDER_ID=1 From 288630f670ac01e9738d773c180115c2bdf41a48 Mon Sep 17 00:00:00 2001 From: Julia Wegmayr Date: Mon, 9 Dec 2024 14:51:46 +0100 Subject: [PATCH 5/6] set folderId to undefined in brevo-module.config --- packages/api/src/config/brevo-module.config.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/api/src/config/brevo-module.config.ts b/packages/api/src/config/brevo-module.config.ts index 4ae56b9a..7307b29d 100644 --- a/packages/api/src/config/brevo-module.config.ts +++ b/packages/api/src/config/brevo-module.config.ts @@ -15,7 +15,7 @@ export interface BrevoModuleConfig { }; allowedRedirectUrl: string; redirectUrlForImport: string; - folderId: number; + folderId?: number; }; BrevoContactAttributes?: Type; BrevoContactFilterAttributes?: Type; From d0e304fbff0cfe5448d7824589b6744db932ed6f Mon Sep 17 00:00:00 2001 From: Julia Wegmayr Date: Mon, 9 Dec 2024 14:53:34 +0100 Subject: [PATCH 6/6] correct value of folderId in brevo api contact service --- packages/api/src/brevo-api/brevo-api-contact.service.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 d4f3179a..4f68e857 100644 --- a/packages/api/src/brevo-api/brevo-api-contact.service.ts +++ b/packages/api/src/brevo-api/brevo-api-contact.service.ts @@ -191,7 +191,7 @@ export class BrevoApiContactsService { try { const contactList = { name: title, - folderId: folderId, + folderId: folderId ?? 1, }; const data = await this.getContactsApi(scope).createList(contactList);