Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add folderId to environment variables #233

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -186,10 +186,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
Loading