Skip to content

Commit

Permalink
Merge pull request #89 from vivid-planet/merge-main-into-next
Browse files Browse the repository at this point in the history
Merge main into next
  • Loading branch information
thomasdax98 authored Sep 20, 2024
2 parents be7f9fb + ad64063 commit b92152a
Show file tree
Hide file tree
Showing 9 changed files with 51 additions and 25 deletions.
4 changes: 2 additions & 2 deletions demo/campaign/src/lang.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { IntlConfig } from "react-intl";

export function getMessages(language: string): Promise<IntlConfig["messages"]> {
if (language === "en") {
return require("../lang/comet-brevo-module-demo-lang/campaign/en.json");
return require("../lang/comet-brevo-module-demo-lang/en.json");
}
return require("../lang/comet-brevo-module-demo-lang/campaign/de.json");
return require("../lang/comet-brevo-module-demo-lang/de.json");
}
4 changes: 4 additions & 0 deletions packages/admin/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# @comet/brevo-admin

## 2.1.0

## 2.0.2

## 2.0.1

## 2.0.0
Expand Down
2 changes: 1 addition & 1 deletion packages/admin/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@comet/brevo-admin",
"version": "2.0.1",
"version": "2.1.0",
"repository": {
"type": "git",
"url": "https://github.com/vivid-planet/comet-brevo-module/",
Expand Down
18 changes: 18 additions & 0 deletions packages/api/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,23 @@
# @comet/brevo-api

## 2.1.0

### Minor Changes

- 3606421: Brevo returns a 404 error when an email address is not found and a 400 error if an invalid email is provided. Instead of handling only one of these errors, both status codes must be ignored to prevent the contact search from throwing an error.

## 2.0.2

### Patch Changes

- 06c18b7: Fix campaign statistics

Addressed an issue where the globalStats property was being used to retrieve campaign stats, but it wasn’t working as expected. We now use the campaignStats property instead, which returns a list. The first value from this list is now used to show accurate campaign statistics.

- b1cff9b: Fix searching contacts

Previously, Brevo returned a 400 error when an email address was not found. The implementation has been updated to correctly handle the 404 status code instead of 400. As a result, the contact search functionality now works as expected without throwing an error when no matching email address is found.

## 2.0.1

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/api/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@comet/brevo-api",
"version": "2.0.1",
"version": "2.1.0",
"repository": {
"type": "git",
"url": "https://github.com/vivid-planet/comet-brevo-module/",
Expand Down
5 changes: 4 additions & 1 deletion packages/api/src/brevo-api/brevo-api-campaigns.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,10 @@ export class BrevoApiCampaignsService {

const brevoCampaign = await this.loadBrevoCampaignById(campaign);

return brevoCampaign.statistics.globalStats;
// The property globalStats seems to be right here according to the docs: https://developers.brevo.com/reference/getemailcampaign
// Unforunately, the API returns only 0 values for the globalStats property.
// That's why we return the first element of the campaignStats array, which contains the correct values.
return brevoCampaign.statistics.campaignStats[0];
}

private async *getCampaignsResponse(
Expand Down
4 changes: 2 additions & 2 deletions packages/api/src/brevo-api/brevo-api-contact.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,8 @@ export class BrevoApiContactsService {
if (!contact) return undefined;
return contact;
} catch (error) {
// Brevo throws 400 error if no contact was found
if (isErrorFromBrevo(error) && error.response.statusCode === 400) {
// Brevo returns a 404 error if no contact is found and a 400 error if an invalid email is provided.
if (isErrorFromBrevo(error) && (error.response.statusCode === 404 || error.response.statusCode === 400)) {
return undefined;
}
throw error;
Expand Down
31 changes: 17 additions & 14 deletions packages/api/src/brevo-api/dto/brevo-api-campaign.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,29 @@
import { GetEmailCampaignsCampaignsInner } from "@getbrevo/brevo";

interface BrevoStatistics {
uniqueClicks: number;
clickers: number;
complaints: number;
delivered: number;
sent: number;
softBounces: number;
hardBounces: number;
uniqueViews: number;
trackableViews: number;
estimatedViews?: number;
unsubscriptions: number;
viewed: number;
}

export interface BrevoApiCampaign {
id: number;
name: string;
subject?: string;
type: GetEmailCampaignsCampaignsInner.TypeEnum;
status: GetEmailCampaignsCampaignsInner.StatusEnum;
statistics: {
globalStats: {
uniqueClicks: number;
clickers: number;
complaints: number;
delivered: number;
sent: number;
softBounces: number;
hardBounces: number;
uniqueViews: number;
trackableViews: number;
estimatedViews?: number;
unsubscriptions: number;
viewed: number;
};
globalStats: BrevoStatistics; // Overall statistics of the campaign
campaignStats: BrevoStatistics[]; // List-wise statistics of the campaign.
};
sentDate?: string;
scheduledAt?: string;
Expand Down
6 changes: 2 additions & 4 deletions packages/api/src/target-group/target-groups.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,7 @@ export class TargetGroupsService {
contactAttributes?: BrevoContactAttributesInterface,
filters?: BrevoContactFilterAttributesInterface,
): boolean {
if (!contactAttributes) return false;

if (filters) {
if (filters && contactAttributes) {
for (const [key, value] of Object.entries(filters)) {
if (!value) continue;
if (value.includes(contactAttributes[key])) {
Expand All @@ -49,7 +47,7 @@ export class TargetGroupsService {
return true;
}

return true;
return false;
}

public async assignContactsToContactList(
Expand Down

0 comments on commit b92152a

Please sign in to comment.