Skip to content

Commit

Permalink
add folderId to environment variables (#233)
Browse files Browse the repository at this point in the history
  • Loading branch information
juliawegmayr authored Jan 15, 2025
1 parent 09e42d9 commit dd93185
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/ten-months-run.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@comet/brevo-api": minor
---

Add `BREVO_FOLDER_ID` to environment variables to allow overwriting default value `1`
1 change: 1 addition & 0 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 2 additions & 0 deletions demo/api/src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
};
}
},
Expand Down
1 change: 1 addition & 0 deletions demo/api/src/config/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
7 changes: 6 additions & 1 deletion demo/api/src/config/environment-variables.ts
Original file line number Diff line number Diff line change
@@ -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";

Expand Down Expand Up @@ -142,4 +142,9 @@ export class EnvironmentVariables {

@IsString()
CAMPAIGN_BASIC_AUTH_PASSWORD: string;

@IsNumber()
@IsUndefinable()
@Type(() => Number)
BREVO_FOLDER_ID?: number;
}
4 changes: 3 additions & 1 deletion packages/api/src/brevo-api/brevo-api-contact.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,10 +201,12 @@ export class BrevoApiContactsService {
}

public async createBrevoContactList(title: string, scope: EmailCampaignScopeInterface): Promise<number | undefined> {
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);
Expand Down
1 change: 1 addition & 0 deletions packages/api/src/config/brevo-module.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export interface BrevoModuleConfig {
};
allowedRedirectUrl: string;
redirectUrlForImport: string;
folderId?: number;
};
BrevoContactAttributes?: Type<BrevoContactAttributesInterface>;
BrevoContactFilterAttributes?: Type<BrevoContactFilterAttributesInterface>;
Expand Down

0 comments on commit dd93185

Please sign in to comment.