Skip to content

Commit

Permalink
Merge pull request #45 from vivid-planet/add-brevo-configuration
Browse files Browse the repository at this point in the history
Add brevo configuration
  • Loading branch information
RainbowBunchie authored Jun 11, 2024
2 parents cc83a1f + 85be9da commit ef828fc
Show file tree
Hide file tree
Showing 30 changed files with 775 additions and 40 deletions.
20 changes: 20 additions & 0 deletions .changeset/yellow-toes-tickle.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
"@comet/brevo-admin": major
"@comet/brevo-api": minor
---

A required brevo config page must now be generated with `createBrevoConfigPage`.
All necessary brevo configuration (for each scope) must be configured within this page for emails campaigns to be sent.

```diff
+ const BrevoConfigPage = createBrevoConfigPage({
+ scopeParts: ["domain", "language"],
+ });
```

Env vars containing the brevo sender information can be removed.

```diff
- BREVO_SENDER_NAME=senderName
- BREVO_SENDER_EMAIL=senderEmail
```
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,15 @@ The following variables must be set manually

- `BREVO_API_KEY`
- `BREVO_DOUBLE_OPT_IN_TEMPLATE_ID`
- `BREVO_SENDER_NAME`
- `BREVO_SENDER_EMAIL`
- `ECG_RTR_LIST_API_KEY`
- `CAMPAIGN_BASIC_AUTH_USERNAME`
- `CAMPAIGN_BASIC_AUTH_PASSWORD`

### Configure brevo sender in the demo admin brevo config page

- Brevo sender name
- Brevo sender mail

### Start development processes

[dev-process-manager](https://github.com/vivid-planet/dev-process-manager) is used for local development.
Expand Down
7 changes: 6 additions & 1 deletion demo/admin/src/Routes.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { MasterLayout, RouteWithErrorBoundary } from "@comet/admin";
import { Domain } from "@comet/admin-icons";
import { createBrevoContactsPage, createEmailCampaignsPage, createTargetGroupsPage } from "@comet/brevo-admin";
import { createBrevoConfigPage, createBrevoContactsPage, createEmailCampaignsPage, createTargetGroupsPage } from "@comet/brevo-admin";
import { ContentScopeIndicator, createRedirectsPage, DamPage, PagesPage, PublisherPage, SitePreview } from "@comet/cms-admin";
import { getBrevoContactConfig } from "@src/common/brevoModuleConfig/brevoContactsPageAttributesConfig";
import { config } from "@src/config";
Expand Down Expand Up @@ -50,6 +50,10 @@ export const Routes: React.FC = () => {
previewUrl: `${config.campaignUrl}/preview`,
});

const BrevoConfigPage = createBrevoConfigPage({
scopeParts: ["domain", "language"],
});

return (
<ContentScopeProvider>
{({ match }) => (
Expand Down Expand Up @@ -97,6 +101,7 @@ export const Routes: React.FC = () => {
<RouteWithErrorBoundary path={`${match.path}/newsletter/contacts`} component={BrevoContactsPage} />
<RouteWithErrorBoundary path={`${match.path}/newsletter/target-groups`} component={TargetGroupsPage} />
<RouteWithErrorBoundary path={`${match.path}/newsletter/email-campaigns`} component={EmailCampaignsPage} />
<RouteWithErrorBoundary path={`${match.path}/newsletter/brevo-config`} component={BrevoConfigPage} />

<RouteWithErrorBoundary path={`${match.path}/structured-content/products`} component={ProductsPage} />
<RouteWithErrorBoundary path={`${match.path}/assets`} component={DamPage} />
Expand Down
4 changes: 4 additions & 0 deletions demo/admin/src/common/MasterMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ export const MasterMenu: React.FC = () => {
primary={intl.formatMessage({ id: "menu.newsletter.emailCampaigns", defaultMessage: "Email campaigns" })}
to={`${match.url}/newsletter/email-campaigns`}
/>
<MenuItemRouterLink
primary={intl.formatMessage({ id: "menu.newsletter.brevoConfig", defaultMessage: "Brevo config" })}
to={`${match.url}/newsletter/brevo-config`}
/>
</MenuCollapsibleItem>
<MenuCollapsibleItem primary={intl.formatMessage({ id: "menu.structuredContent", defaultMessage: "Structured content" })} icon={<Data />}>
<MenuItemRouterLink
Expand Down
37 changes: 37 additions & 0 deletions demo/api/schema.gql
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,20 @@ type PaginatedUserList {
totalCount: Int!
}

type BrevoApiSender {
id: ID!
name: String!
email: String!
active: Boolean!
ips: [BrevoIp!]
}

type BrevoIp {
ip: String!
domain: String!
weight: Int!
}

type BrevoApiCampaignStatistics {
"""Number of unique clicks for the campaign"""
uniqueClicks: Int!
Expand Down Expand Up @@ -425,6 +439,15 @@ type TargetGroup implements DocumentInterface {
filters: BrevoContactFilterAttributes
}

type BrevoConfig implements DocumentInterface {
id: ID!
updatedAt: DateTime!
senderMail: String!
senderName: String!
createdAt: DateTime!
scope: EmailCampaignContentScope!
}

type BrevoContact {
id: Int!
createdAt: String!
Expand Down Expand Up @@ -539,6 +562,8 @@ type Query {
emailCampaignStatistics(id: ID!): BrevoApiCampaignStatistics
targetGroup(id: ID!): TargetGroup!
targetGroups(scope: EmailCampaignContentScopeInput!, search: String, filter: TargetGroupFilter, sort: [TargetGroupSort!], offset: Int! = 0, limit: Int! = 25): PaginatedTargetGroups!
senders: [BrevoApiSender!]
brevoConfig(scope: EmailCampaignContentScopeInput!): BrevoConfig
}

input UserFilter {
Expand Down Expand Up @@ -777,6 +802,8 @@ type Mutation {
createTargetGroup(scope: EmailCampaignContentScopeInput!, input: TargetGroupInput!): TargetGroup!
updateTargetGroup(id: ID!, input: TargetGroupUpdateInput!, lastUpdatedAt: DateTime): TargetGroup!
deleteTargetGroup(id: ID!): Boolean!
createBrevoConfig(scope: EmailCampaignContentScopeInput!, input: BrevoConfigInput!): BrevoConfig!
updateBrevoConfig(id: ID!, input: BrevoConfigUpdateInput!, lastUpdatedAt: DateTime): BrevoConfig!
}

input UserPermissionInput {
Expand Down Expand Up @@ -957,3 +984,13 @@ input TargetGroupUpdateInput {
title: String
filters: BrevoContactFilterAttributesInput
}

input BrevoConfigInput {
senderMail: String!
senderName: String!
}

input BrevoConfigUpdateInput {
senderMail: String!
senderName: String!
}
4 changes: 0 additions & 4 deletions demo/api/src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,10 +143,6 @@ export class AppModule {
BrevoContactFilterAttributes,
doubleOptInTemplateId: config.brevo.doubleOptInTemplateId,
allowedRedirectUrl: config.brevo.allowedRedirectUrl,
sender: {
name: config.brevo.sender.name,
email: config.brevo.sender.email,
},
},
ecgRtrList: {
apiKey: config.ecgRtrList.apiKey,
Expand Down
4 changes: 0 additions & 4 deletions demo/api/src/config/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,6 @@ export function createConfig(processEnv: NodeJS.ProcessEnv) {
apiKey: envVars.BREVO_API_KEY,
doubleOptInTemplateId: envVars.BREVO_DOUBLE_OPT_IN_TEMPLATE_ID,
allowedRedirectUrl: envVars.BREVO_ALLOWED_REDIRECT_URL,
sender: {
name: envVars.BREVO_SENDER_NAME,
email: envVars.BREVO_SENDER_EMAIL,
},
},
campaign: {
url: envVars.CAMPAIGN_URL,
Expand Down
8 changes: 1 addition & 7 deletions demo/api/src/config/environment-variables.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-disable @typescript-eslint/naming-convention */
import { BlobStorageConfig } from "@comet/cms-api";
import { Transform, Type } from "class-transformer";
import { IsBase64, IsBoolean, IsEmail, IsInt, IsNumber, IsOptional, IsString, MinLength, ValidateIf } from "class-validator";
import { IsBase64, IsBoolean, IsInt, IsNumber, IsOptional, IsString, MinLength, ValidateIf } from "class-validator";

export class EnvironmentVariables {
@IsString()
Expand Down Expand Up @@ -122,12 +122,6 @@ export class EnvironmentVariables {
@IsString()
BREVO_ALLOWED_REDIRECT_URL: string;

@IsString()
BREVO_SENDER_NAME: string;

@IsEmail()
BREVO_SENDER_EMAIL: string;

@IsString()
ECG_RTR_LIST_API_KEY: string;

Expand Down
9 changes: 9 additions & 0 deletions demo/api/src/db/migrations/Migration20240527112204.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { Migration } from "@mikro-orm/migrations";

export class Migration20240527112204 extends Migration {
async up(): Promise<void> {
this.addSql(
'create table "BrevoConfig" ("id" uuid not null, "createdAt" timestamp with time zone not null, "updatedAt" timestamp with time zone not null, "scope_domain" text not null, "scope_language" text not null, "senderMail" text not null, "senderName" text not null, constraint "BrevoConfig_pkey" primary key ("id"));',
);
}
}
59 changes: 59 additions & 0 deletions packages/admin/src/brevoConfiguration/BrevoConfigForm.gql.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import { gql } from "@apollo/client";

export const brevoConfigFormFragment = gql`
fragment BrevoConfigForm on BrevoConfig {
senderMail
senderName
}
`;

export const brevoConfigFormQuery = gql`
query BrevoConfigForm($scope: EmailCampaignContentScopeInput!) {
brevoConfig(scope: $scope) {
id
updatedAt
...BrevoConfigForm
}
}
${brevoConfigFormFragment}
`;

export const brevoConfigFormCheckForChangesQuery = gql`
query BrevoConfigFormCheckForChanges($scope: EmailCampaignContentScopeInput!) {
brevoConfig(scope: $scope) {
updatedAt
}
}
`;

export const createBrevoConfigMutation = gql`
mutation CreateBrevoConfig($scope: EmailCampaignContentScopeInput!, $input: BrevoConfigInput!) {
createBrevoConfig(scope: $scope, input: $input) {
id
updatedAt
...BrevoConfigForm
}
}
${brevoConfigFormFragment}
`;

export const updateBrevoConfigMutation = gql`
mutation UpdateBrevoConfig($id: ID!, $input: BrevoConfigUpdateInput!, $lastUpdatedAt: DateTime) {
updateBrevoConfig(id: $id, input: $input, lastUpdatedAt: $lastUpdatedAt) {
id
updatedAt
...BrevoConfigForm
}
}
${brevoConfigFormFragment}
`;

export const sendersSelectQuery = gql`
query SendersSelect {
senders {
id
name
email
}
}
`;
Loading

0 comments on commit ef828fc

Please sign in to comment.