@comet/brevo-api 2.1.1 → 2.1.2-canary-20241010125453
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/brevo-api/brevo-api-campaigns.service.d.ts.map +1 -1
- package/lib/brevo-api/brevo-api-campaigns.service.js +152 -96
- package/lib/brevo-api/brevo-api-campaigns.service.js.map +1 -1
- package/lib/brevo-api/brevo-api-contact.service.d.ts.map +1 -1
- package/lib/brevo-api/brevo-api-contact.service.js +149 -74
- package/lib/brevo-api/brevo-api-contact.service.js.map +1 -1
- package/lib/brevo-api/brevo-api-transactional-mails.service.d.ts.map +1 -1
- package/lib/brevo-api/brevo-api-transactional-mails.service.js +21 -10
- package/lib/brevo-api/brevo-api-transactional-mails.service.js.map +1 -1
- package/lib/brevo-api/brevo-api.utils.d.ts +3 -0
- package/lib/brevo-api/brevo-api.utils.d.ts.map +1 -1
- package/lib/brevo-api/brevo-api.utils.js +21 -2
- package/lib/brevo-api/brevo-api.utils.js.map +1 -1
- package/lib/brevo-contact/brevo-contact-import.console.d.ts.map +1 -1
- package/lib/brevo-contact/brevo-contact-import.console.js +10 -6
- package/lib/brevo-contact/brevo-contact-import.console.js.map +1 -1
- package/lib/brevo-contact/brevo-contact-import.controller.d.ts.map +1 -1
- package/lib/brevo-contact/brevo-contact-import.controller.js +13 -16
- package/lib/brevo-contact/brevo-contact-import.controller.js.map +1 -1
- package/lib/brevo-contact/brevo-contact-import.service.d.ts +26 -11
- package/lib/brevo-contact/brevo-contact-import.service.d.ts.map +1 -1
- package/lib/brevo-contact/brevo-contact-import.service.js +168 -75
- package/lib/brevo-contact/brevo-contact-import.service.js.map +1 -1
- package/lib/target-group/target-groups.service.d.ts.map +1 -1
- package/lib/target-group/target-groups.service.js +71 -48
- package/lib/target-group/target-groups.service.js.map +1 -1
- package/lib/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +3 -1
|
@@ -1,22 +1,37 @@
|
|
|
1
|
-
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { EntityRepository } from "@mikro-orm/core";
|
|
3
|
+
import { TargetGroupInterface } from "src/target-group/entity/target-group-entity.factory";
|
|
4
|
+
import { Readable } from "stream";
|
|
5
|
+
import { BrevoApiContactsService } from "../brevo-api/brevo-api-contact.service";
|
|
2
6
|
import { BrevoContactsService } from "../brevo-contact/brevo-contacts.service";
|
|
3
7
|
import { BrevoModuleConfig } from "../config/brevo-module.config";
|
|
4
|
-
import { TargetGroupInterface } from "../target-group/entity/target-group-entity.factory";
|
|
5
8
|
import { TargetGroupsService } from "../target-group/target-groups.service";
|
|
6
9
|
import { EmailCampaignScopeInterface } from "../types";
|
|
10
|
+
export interface CsvImportInformation {
|
|
11
|
+
created: number;
|
|
12
|
+
updated: number;
|
|
13
|
+
failed: number;
|
|
14
|
+
failedColumns: unknown[];
|
|
15
|
+
errorMessage?: string;
|
|
16
|
+
}
|
|
17
|
+
interface ImportContactsFromCsvParams {
|
|
18
|
+
fileStream: Readable;
|
|
19
|
+
scope: EmailCampaignScopeInterface;
|
|
20
|
+
redirectUrl: string;
|
|
21
|
+
targetGroupIds?: string[];
|
|
22
|
+
isAdminImport?: boolean;
|
|
23
|
+
}
|
|
7
24
|
export declare class BrevoContactImportService {
|
|
8
25
|
private readonly config;
|
|
9
26
|
private readonly brevoApiContactsService;
|
|
10
27
|
private readonly brevoContactsService;
|
|
11
28
|
private readonly targetGroupsService;
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
parseCsvToBrevoContacts(csvContent: string, redirectUrl: string): Promise<CreateDoubleOptInContactData[]>;
|
|
19
|
-
private processRow;
|
|
20
|
-
private createAndValidateRow;
|
|
29
|
+
private readonly targetGroupRepository;
|
|
30
|
+
constructor(config: BrevoModuleConfig, brevoApiContactsService: BrevoApiContactsService, brevoContactsService: BrevoContactsService, targetGroupsService: TargetGroupsService, targetGroupRepository: EntityRepository<TargetGroupInterface>);
|
|
31
|
+
importContactsFromCsv({ fileStream, scope, redirectUrl, targetGroupIds, isAdminImport, }: ImportContactsFromCsvParams): Promise<CsvImportInformation>;
|
|
32
|
+
private createOrUpdateBrevoContact;
|
|
33
|
+
private processCsvRow;
|
|
34
|
+
private createValidateableCsvRowClass;
|
|
21
35
|
}
|
|
36
|
+
export {};
|
|
22
37
|
//# sourceMappingURL=brevo-contact-import.service.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"brevo-contact-import.service.d.ts","sourceRoot":"","sources":["../../src/brevo-contact/brevo-contact-import.service.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"brevo-contact-import.service.d.ts","sourceRoot":"","sources":["../../src/brevo-contact/brevo-contact-import.service.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AAKnD,OAAO,EAAE,oBAAoB,EAAE,MAAM,qDAAqD,CAAC;AAC3F,OAAO,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAC;AAGlC,OAAO,EAAE,uBAAuB,EAAgC,MAAM,wCAAwC,CAAC;AAC/G,OAAO,EAAE,oBAAoB,EAAE,MAAM,yCAAyC,CAAC;AAC/E,OAAO,EAAE,iBAAiB,EAAE,MAAM,+BAA+B,CAAC;AAElE,OAAO,EAAE,mBAAmB,EAAE,MAAM,uCAAuC,CAAC;AAC5E,OAAO,EAAE,2BAA2B,EAAE,MAAM,UAAU,CAAC;AAWvD,MAAM,WAAW,oBAAoB;IACjC,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,MAAM,CAAC;IACf,aAAa,EAAE,OAAO,EAAE,CAAC;IACzB,YAAY,CAAC,EAAE,MAAM,CAAC;CACzB;AAED,UAAU,2BAA2B;IACjC,UAAU,EAAE,QAAQ,CAAC;IACrB,KAAK,EAAE,2BAA2B,CAAC;IACnC,WAAW,EAAE,MAAM,CAAC;IACpB,cAAc,CAAC,EAAE,MAAM,EAAE,CAAC;IAC1B,aAAa,CAAC,EAAE,OAAO,CAAC;CAC3B;AAED,qBACa,yBAAyB;IAED,OAAO,CAAC,QAAQ,CAAC,MAAM;IACpD,OAAO,CAAC,QAAQ,CAAC,uBAAuB;IACxC,OAAO,CAAC,QAAQ,CAAC,oBAAoB;IACrC,OAAO,CAAC,QAAQ,CAAC,mBAAmB;IACH,OAAO,CAAC,QAAQ,CAAC,qBAAqB;gBAJzB,MAAM,EAAE,iBAAiB,EACtD,uBAAuB,EAAE,uBAAuB,EAChD,oBAAoB,EAAE,oBAAoB,EAC1C,mBAAmB,EAAE,mBAAmB,EACP,qBAAqB,EAAE,gBAAgB,CAAC,oBAAoB,CAAC;IAG7G,qBAAqB,CAAC,EACxB,UAAU,EACV,KAAK,EACL,WAAW,EACX,cAAmB,EACnB,aAAqB,GACxB,EAAE,2BAA2B,GAAG,OAAO,CAAC,oBAAoB,CAAC;YAoEhD,0BAA0B;YAyC1B,aAAa;IA4B3B,OAAO,CAAC,6BAA6B;CAexC"}
|
|
@@ -1,10 +1,33 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
2
18
|
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
19
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
20
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
21
|
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
22
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
23
|
};
|
|
24
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
25
|
+
if (mod && mod.__esModule) return mod;
|
|
26
|
+
var result = {};
|
|
27
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
28
|
+
__setModuleDefault(result, mod);
|
|
29
|
+
return result;
|
|
30
|
+
};
|
|
8
31
|
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
32
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
33
|
};
|
|
@@ -20,6 +43,13 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
20
43
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
21
44
|
});
|
|
22
45
|
};
|
|
46
|
+
var __asyncValues = (this && this.__asyncValues) || function (o) {
|
|
47
|
+
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
|
|
48
|
+
var m = o[Symbol.asyncIterator], i;
|
|
49
|
+
return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
|
|
50
|
+
function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
|
|
51
|
+
function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
|
|
52
|
+
};
|
|
23
53
|
var __rest = (this && this.__rest) || function (s, e) {
|
|
24
54
|
var t = {};
|
|
25
55
|
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
@@ -31,135 +61,198 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
31
61
|
}
|
|
32
62
|
return t;
|
|
33
63
|
};
|
|
64
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
65
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
66
|
+
};
|
|
34
67
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
35
68
|
exports.BrevoContactImportService = void 0;
|
|
36
|
-
const
|
|
69
|
+
const csv = __importStar(require("@fast-csv/parse"));
|
|
70
|
+
const core_1 = require("@mikro-orm/core");
|
|
71
|
+
const nestjs_1 = require("@mikro-orm/nestjs");
|
|
37
72
|
const common_1 = require("@nestjs/common");
|
|
38
73
|
const class_validator_1 = require("class-validator");
|
|
74
|
+
const lodash_isequal_1 = __importDefault(require("lodash.isequal"));
|
|
39
75
|
const brevo_api_utils_1 = require("../brevo-api/brevo-api.utils");
|
|
40
76
|
const brevo_api_contact_service_1 = require("../brevo-api/brevo-api-contact.service");
|
|
41
77
|
const brevo_contacts_service_1 = require("../brevo-contact/brevo-contacts.service");
|
|
42
78
|
const brevo_module_constants_1 = require("../config/brevo-module.constants");
|
|
43
79
|
const target_groups_service_1 = require("../target-group/target-groups.service");
|
|
44
|
-
class
|
|
80
|
+
class BasicValidateableRow {
|
|
45
81
|
}
|
|
46
82
|
__decorate([
|
|
47
83
|
(0, class_validator_1.IsEmail)(),
|
|
48
84
|
(0, class_validator_1.IsNotEmpty)(),
|
|
49
85
|
__metadata("design:type", String)
|
|
50
|
-
],
|
|
86
|
+
], BasicValidateableRow.prototype, "email", void 0);
|
|
51
87
|
let BrevoContactImportService = class BrevoContactImportService {
|
|
52
|
-
constructor(config, brevoApiContactsService, brevoContactsService, targetGroupsService) {
|
|
88
|
+
constructor(config, brevoApiContactsService, brevoContactsService, targetGroupsService, targetGroupRepository) {
|
|
53
89
|
this.config = config;
|
|
54
90
|
this.brevoApiContactsService = brevoApiContactsService;
|
|
55
91
|
this.brevoContactsService = brevoContactsService;
|
|
56
92
|
this.targetGroupsService = targetGroupsService;
|
|
93
|
+
this.targetGroupRepository = targetGroupRepository;
|
|
57
94
|
}
|
|
58
|
-
importContactsFromCsv(
|
|
95
|
+
importContactsFromCsv({ fileStream, scope, redirectUrl, targetGroupIds = [], isAdminImport = false, }) {
|
|
96
|
+
var _a, e_1, _b, _c;
|
|
59
97
|
return __awaiter(this, void 0, void 0, function* () {
|
|
98
|
+
const failedColumns = [];
|
|
99
|
+
const targetGroups = yield this.targetGroupRepository.find({ id: { $in: targetGroupIds } });
|
|
100
|
+
for (const targetGroup of targetGroups) {
|
|
101
|
+
if (targetGroup.isMainList) {
|
|
102
|
+
throw new Error("Main lists are not allowed as target groups for import");
|
|
103
|
+
}
|
|
104
|
+
if (!(0, lodash_isequal_1.default)(Object.assign({}, targetGroup.scope), scope)) {
|
|
105
|
+
throw new Error("Target group scope does not match the scope of the import file");
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
const manuallyAssignedBrevoContacts = yield Promise.all(targetGroups.map((targetGroup) => {
|
|
109
|
+
return this.targetGroupsService.createIfNotExistsManuallyAssignedContactsTargetGroup(targetGroup);
|
|
110
|
+
}));
|
|
111
|
+
const targetGroupBrevoIds = [...targetGroups.map((targetGroup) => targetGroup.brevoId), ...manuallyAssignedBrevoContacts];
|
|
112
|
+
const rows = fileStream.pipe(csv.parse({ headers: true, delimiter: ";", ignoreEmpty: true })).on("error", (error) => {
|
|
113
|
+
throw error;
|
|
114
|
+
});
|
|
60
115
|
let created = 0;
|
|
61
116
|
let updated = 0;
|
|
62
117
|
let failed = 0;
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
for (const contact of contacts) {
|
|
68
|
-
try {
|
|
69
|
-
let brevoContact;
|
|
118
|
+
try {
|
|
119
|
+
for (var _d = true, rows_1 = __asyncValues(rows), rows_1_1; rows_1_1 = yield rows_1.next(), _a = rows_1_1.done, !_a;) {
|
|
120
|
+
_c = rows_1_1.value;
|
|
121
|
+
_d = false;
|
|
70
122
|
try {
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
123
|
+
const row = _c;
|
|
124
|
+
if (isAdminImport && created + updated + failed > 100) {
|
|
125
|
+
return {
|
|
126
|
+
created,
|
|
127
|
+
updated,
|
|
128
|
+
failed,
|
|
129
|
+
failedColumns,
|
|
130
|
+
errorMessage: "Too many contacts. Currently we only support 100 contacts at once, the first 100 contacts were handled. Please split the file and try again with the remaining contacts.",
|
|
131
|
+
};
|
|
76
132
|
}
|
|
77
|
-
|
|
78
|
-
|
|
133
|
+
try {
|
|
134
|
+
const contactData = yield this.processCsvRow(row, redirectUrl);
|
|
135
|
+
const result = yield this.createOrUpdateBrevoContact(contactData, scope, targetGroupBrevoIds);
|
|
136
|
+
switch (result) {
|
|
137
|
+
case "created":
|
|
138
|
+
created++;
|
|
139
|
+
break;
|
|
140
|
+
case "updated":
|
|
141
|
+
updated++;
|
|
142
|
+
break;
|
|
143
|
+
case "error":
|
|
144
|
+
failedColumns.push(row);
|
|
145
|
+
failed++;
|
|
146
|
+
break;
|
|
147
|
+
}
|
|
79
148
|
}
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
const updatedBrevoContact = yield this.brevoApiContactsService.updateContact(brevoContact.id, Object.assign(Object.assign({}, contact), { listIds: [mainTargetGroupForScope.brevoId, ...targetGroupBrevoIds, ...brevoContact.listIds] }), scope);
|
|
84
|
-
if (updatedBrevoContact)
|
|
85
|
-
updated++;
|
|
86
|
-
else
|
|
149
|
+
catch (validationError) {
|
|
150
|
+
console.error(validationError);
|
|
151
|
+
failedColumns.push(row);
|
|
87
152
|
failed++;
|
|
153
|
+
}
|
|
88
154
|
}
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
if (success)
|
|
92
|
-
created++;
|
|
93
|
-
else
|
|
94
|
-
failed++;
|
|
155
|
+
finally {
|
|
156
|
+
_d = true;
|
|
95
157
|
}
|
|
96
158
|
}
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
159
|
+
}
|
|
160
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
161
|
+
finally {
|
|
162
|
+
try {
|
|
163
|
+
if (!_d && !_a && (_b = rows_1.return)) yield _b.call(rows_1);
|
|
100
164
|
}
|
|
165
|
+
finally { if (e_1) throw e_1.error; }
|
|
166
|
+
}
|
|
167
|
+
if (created + updated + failed === 0) {
|
|
168
|
+
return { created, updated, failed, failedColumns, errorMessage: "No contacts found." };
|
|
101
169
|
}
|
|
102
|
-
return { created, updated, failed };
|
|
170
|
+
return { created, updated, failed, failedColumns };
|
|
103
171
|
});
|
|
104
172
|
}
|
|
105
|
-
|
|
173
|
+
createOrUpdateBrevoContact(contact, scope, targetGroupBrevoIds) {
|
|
106
174
|
return __awaiter(this, void 0, void 0, function* () {
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
.
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
try {
|
|
116
|
-
const contactData = yield this.processRow(row, redirectUrl);
|
|
117
|
-
brevoContacts.push(contactData);
|
|
175
|
+
try {
|
|
176
|
+
let brevoContact;
|
|
177
|
+
try {
|
|
178
|
+
brevoContact = yield this.brevoApiContactsService.findContact(contact.email, scope);
|
|
179
|
+
}
|
|
180
|
+
catch (error) {
|
|
181
|
+
if (!(0, brevo_api_utils_1.isErrorFromBrevo)(error)) {
|
|
182
|
+
throw error;
|
|
118
183
|
}
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
reject(validationError);
|
|
184
|
+
if (error.response.statusCode !== 404) {
|
|
185
|
+
throw error;
|
|
122
186
|
}
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
}
|
|
187
|
+
}
|
|
188
|
+
const mainTargetGroupForScope = yield this.targetGroupsService.createIfNotExistMainTargetGroupForScope(scope);
|
|
189
|
+
if (brevoContact && !brevoContact.emailBlacklisted) {
|
|
190
|
+
const updatedBrevoContact = yield this.brevoApiContactsService.updateContact(brevoContact.id, Object.assign(Object.assign({}, contact), { listIds: [mainTargetGroupForScope.brevoId, ...targetGroupBrevoIds, ...brevoContact.listIds] }), scope);
|
|
191
|
+
if (updatedBrevoContact)
|
|
192
|
+
return "updated";
|
|
193
|
+
}
|
|
194
|
+
else if (!brevoContact) {
|
|
195
|
+
const success = yield this.brevoContactsService.createDoubleOptInContact(Object.assign(Object.assign({}, contact), { scope, templateId: this.config.brevo.resolveConfig(scope).doubleOptInTemplateId, listIds: [mainTargetGroupForScope.brevoId, ...targetGroupBrevoIds] }));
|
|
196
|
+
if (success)
|
|
197
|
+
return "created";
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
catch (err) {
|
|
201
|
+
console.error(err);
|
|
202
|
+
}
|
|
203
|
+
return "error";
|
|
139
204
|
});
|
|
140
205
|
}
|
|
141
|
-
|
|
206
|
+
processCsvRow(row, redirectUrlForImport) {
|
|
142
207
|
return __awaiter(this, void 0, void 0, function* () {
|
|
143
|
-
const mappedRow =
|
|
144
|
-
|
|
208
|
+
const mappedRow = this.createValidateableCsvRowClass();
|
|
209
|
+
for (const key in row) {
|
|
145
210
|
if (key.toLowerCase() === "email") {
|
|
146
211
|
mappedRow.email = row[key];
|
|
147
212
|
}
|
|
148
213
|
else {
|
|
149
|
-
mappedRow[key] = row[key];
|
|
214
|
+
mappedRow[key.toUpperCase()] = row[key];
|
|
150
215
|
}
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
|
|
216
|
+
}
|
|
217
|
+
const errors = (0, class_validator_1.validateSync)(mappedRow);
|
|
218
|
+
if (errors.length > 0) {
|
|
219
|
+
throw errors;
|
|
220
|
+
}
|
|
221
|
+
const { email } = mappedRow, data = __rest(mappedRow, ["email"]);
|
|
222
|
+
return {
|
|
223
|
+
email: mappedRow.email,
|
|
224
|
+
redirectionUrl: redirectUrlForImport,
|
|
225
|
+
attributes: Object.assign({}, data),
|
|
226
|
+
};
|
|
154
227
|
});
|
|
155
228
|
}
|
|
229
|
+
createValidateableCsvRowClass() {
|
|
230
|
+
if (this.config.brevo.BrevoContactAttributes) {
|
|
231
|
+
const BrevoContactAttributesClass = this.config.brevo.BrevoContactAttributes;
|
|
232
|
+
class ValidateableRow extends BrevoContactAttributesClass {
|
|
233
|
+
}
|
|
234
|
+
__decorate([
|
|
235
|
+
(0, class_validator_1.IsEmail)(),
|
|
236
|
+
(0, class_validator_1.IsNotEmpty)(),
|
|
237
|
+
__metadata("design:type", String)
|
|
238
|
+
], ValidateableRow.prototype, "email", void 0);
|
|
239
|
+
return new ValidateableRow();
|
|
240
|
+
}
|
|
241
|
+
else {
|
|
242
|
+
class ValidateableRow extends BasicValidateableRow {
|
|
243
|
+
}
|
|
244
|
+
return new ValidateableRow();
|
|
245
|
+
}
|
|
246
|
+
}
|
|
156
247
|
};
|
|
157
248
|
BrevoContactImportService = __decorate([
|
|
158
249
|
(0, common_1.Injectable)(),
|
|
159
250
|
__param(0, (0, common_1.Inject)(brevo_module_constants_1.BREVO_MODULE_CONFIG)),
|
|
251
|
+
__param(4, (0, nestjs_1.InjectRepository)("TargetGroup")),
|
|
160
252
|
__metadata("design:paramtypes", [Object, brevo_api_contact_service_1.BrevoApiContactsService,
|
|
161
253
|
brevo_contacts_service_1.BrevoContactsService,
|
|
162
|
-
target_groups_service_1.TargetGroupsService
|
|
254
|
+
target_groups_service_1.TargetGroupsService,
|
|
255
|
+
core_1.EntityRepository])
|
|
163
256
|
], BrevoContactImportService);
|
|
164
257
|
exports.BrevoContactImportService = BrevoContactImportService;
|
|
165
258
|
//# sourceMappingURL=brevo-contact-import.service.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"brevo-contact-import.service.js","sourceRoot":"","sources":["../../src/brevo-contact/brevo-contact-import.service.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"brevo-contact-import.service.js","sourceRoot":"","sources":["../../src/brevo-contact/brevo-contact-import.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,qDAAuC;AACvC,0CAAmD;AACnD,8CAAqD;AACrD,2CAAoD;AACpD,qDAAoE;AACpE,oEAAqC;AAIrC,kEAAgE;AAChE,sFAA+G;AAC/G,oFAA+E;AAE/E,6EAAuE;AACvE,iFAA4E;AAG5E,MAAM,oBAAoB;CAOzB;AANG;IAAC,IAAA,yBAAO,GAAE;IACT,IAAA,4BAAU,GAAE;;mDACC;AAuBX,IAAM,yBAAyB,GAA/B,MAAM,yBAAyB;IAClC,YACkD,MAAyB,EACtD,uBAAgD,EAChD,oBAA0C,EAC1C,mBAAwC,EACP,qBAA6D;QAJjE,WAAM,GAAN,MAAM,CAAmB;QACtD,4BAAuB,GAAvB,uBAAuB,CAAyB;QAChD,yBAAoB,GAApB,oBAAoB,CAAsB;QAC1C,wBAAmB,GAAnB,mBAAmB,CAAqB;QACP,0BAAqB,GAArB,qBAAqB,CAAwC;IAChH,CAAC;IAEE,qBAAqB,CAAC,EACxB,UAAU,EACV,KAAK,EACL,WAAW,EACX,cAAc,GAAG,EAAE,EACnB,aAAa,GAAG,KAAK,GACK;;;YAC1B,MAAM,aAAa,GAA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B,WAAA,IAAA,yBAAgB,EAAC,aAAa,CAAC,CAAA;6CAHU,mDAAuB;QAC1B,6CAAoB;QACrB,2CAAmB;QACgB,uBAAgB;GANpF,yBAAyB,CAuKrC;AAvKY,8DAAyB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"target-groups.service.d.ts","sourceRoot":"","sources":["../../src/target-group/target-groups.service.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,gBAAgB,EAAE,WAAW,EAAE,WAAW,EAAQ,MAAM,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"target-groups.service.d.ts","sourceRoot":"","sources":["../../src/target-group/target-groups.service.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,gBAAgB,EAAE,WAAW,EAAE,WAAW,EAAQ,MAAM,iBAAiB,CAAC;AAKlG,OAAO,EAAE,uBAAuB,EAAE,MAAM,wCAAwC,CAAC;AAEjF,OAAO,EAAE,+BAA+B,EAAE,qCAAqC,EAAE,2BAA2B,EAAE,MAAM,UAAU,CAAC;AAC/H,OAAO,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAC;AAC9D,OAAO,EAAE,oBAAoB,EAAE,MAAM,sCAAsC,CAAC;AAE5E,qBACa,mBAAmB;IAES,OAAO,CAAC,QAAQ,CAAC,UAAU;IAC5D,OAAO,CAAC,QAAQ,CAAC,uBAAuB;IACxC,OAAO,CAAC,QAAQ,CAAC,aAAa;gBAFoB,UAAU,EAAE,gBAAgB,CAAC,oBAAoB,CAAC,EACnF,uBAAuB,EAAE,uBAAuB,EAChD,aAAa,EAAE,aAAa;IAGjD,gBAAgB,CAAC,OAAO,EAAE;QAAE,MAAM,CAAC,EAAE,MAAM,CAAC;QAAC,MAAM,CAAC,EAAE,iBAAiB,CAAA;KAAE,GAAG,WAAW,CAAC,oBAAoB,CAAC;IActG,6BAA6B,CAChC,iBAAiB,CAAC,EAAE,+BAA+B,EACnD,OAAO,CAAC,EAAE,qCAAqC,GAChD,OAAO;IA2BG,2BAA2B,CACpC,WAAW,EAAE,oBAAoB,EACjC,KAAK,EAAE,2BAA2B,EAClC,OAAO,CAAC,EAAE,qCAAqC,GAChD,OAAO,CAAC,IAAI,CAAC;IA0DV,gBAAgB,CAAC,EACnB,MAAM,EACN,KAAK,EACL,KAAK,GACR,EAAE;QACC,MAAM,EAAE,MAAM,CAAC;QACf,KAAK,EAAE,MAAM,CAAC;QACd,KAAK,EAAE,WAAW,CAAC,oBAAoB,CAAC,CAAC;KAC5C,GAAG,OAAO,CAAC,CAAC,oBAAoB,EAAE,EAAE,MAAM,CAAC,CAAC;IAMhC,uCAAuC,CAAC,KAAK,EAAE,2BAA2B,GAAG,OAAO,CAAC,oBAAoB,CAAC;IA0B1G,oDAAoD,CAAC,WAAW,EAAE,oBAAoB;CA2BtG"}
|
|
@@ -26,6 +26,7 @@ const cms_api_1 = require("@comet/cms-api");
|
|
|
26
26
|
const core_1 = require("@mikro-orm/core");
|
|
27
27
|
const nestjs_1 = require("@mikro-orm/nestjs");
|
|
28
28
|
const common_1 = require("@nestjs/common");
|
|
29
|
+
const brevo_api_utils_1 = require("../brevo-api/brevo-api.utils");
|
|
29
30
|
const brevo_api_contact_service_1 = require("../brevo-api/brevo-api-contact.service");
|
|
30
31
|
let TargetGroupsService = class TargetGroupsService {
|
|
31
32
|
constructor(repository, brevoApiContactsService, entityManager) {
|
|
@@ -71,36 +72,46 @@ let TargetGroupsService = class TargetGroupsService {
|
|
|
71
72
|
}
|
|
72
73
|
assignContactsToContactList(targetGroup, scope, filters) {
|
|
73
74
|
return __awaiter(this, void 0, void 0, function* () {
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
75
|
+
try {
|
|
76
|
+
const mainScopeTargetGroupList = yield this.repository.findOneOrFail({ scope, isMainList: true });
|
|
77
|
+
let offset = 0;
|
|
78
|
+
let totalCount = 0;
|
|
79
|
+
do {
|
|
80
|
+
try {
|
|
81
|
+
const [contacts, totalContacts] = yield this.brevoApiContactsService.findContactsByListId(mainScopeTargetGroupList.brevoId, 50, offset, scope);
|
|
82
|
+
totalCount = totalContacts;
|
|
83
|
+
offset += contacts.length;
|
|
84
|
+
const contactsInContactList = [];
|
|
85
|
+
const contactsNotInContactList = [];
|
|
86
|
+
for (const contact of contacts) {
|
|
87
|
+
const contactIsInTargetGroupByFilters = this.checkIfContactIsInTargetGroup(contact.attributes, filters);
|
|
88
|
+
const manuallyAssignedTargetGroup = targetGroup.assignedContactsTargetGroupBrevoId;
|
|
89
|
+
const contactIsManuallyAssignedToTargetGroup = manuallyAssignedTargetGroup
|
|
90
|
+
? contact.listIds.includes(manuallyAssignedTargetGroup)
|
|
91
|
+
: false;
|
|
92
|
+
if (contactIsInTargetGroupByFilters || contactIsManuallyAssignedToTargetGroup) {
|
|
93
|
+
contactsInContactList.push(contact);
|
|
94
|
+
}
|
|
95
|
+
else {
|
|
96
|
+
contactsNotInContactList.push(contact);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
if (contactsInContactList.length > 0) {
|
|
100
|
+
yield this.brevoApiContactsService.updateMultipleContacts(contactsInContactList.map((contact) => ({ id: contact.id, listIds: [targetGroup.brevoId] })), scope);
|
|
101
|
+
}
|
|
102
|
+
if (contactsNotInContactList.length > 0) {
|
|
103
|
+
yield this.brevoApiContactsService.updateMultipleContacts(contactsNotInContactList.map((contact) => ({ id: contact.id, unlinkListIds: [targetGroup.brevoId] })), scope);
|
|
104
|
+
}
|
|
91
105
|
}
|
|
92
|
-
|
|
93
|
-
|
|
106
|
+
catch (error) {
|
|
107
|
+
(0, brevo_api_utils_1.handleBrevoError)(error);
|
|
94
108
|
}
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
}
|
|
102
|
-
} while (offset < totalCount);
|
|
103
|
-
return true;
|
|
109
|
+
} while (offset < totalCount);
|
|
110
|
+
return true;
|
|
111
|
+
}
|
|
112
|
+
catch (error) {
|
|
113
|
+
(0, brevo_api_utils_1.handleBrevoError)(error);
|
|
114
|
+
}
|
|
104
115
|
});
|
|
105
116
|
}
|
|
106
117
|
findTargetGroups({ offset, limit, where, }) {
|
|
@@ -111,34 +122,46 @@ let TargetGroupsService = class TargetGroupsService {
|
|
|
111
122
|
}
|
|
112
123
|
createIfNotExistMainTargetGroupForScope(scope) {
|
|
113
124
|
return __awaiter(this, void 0, void 0, function* () {
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
125
|
+
try {
|
|
126
|
+
const mainList = yield this.repository.findOne({ scope, isMainList: true });
|
|
127
|
+
if (mainList) {
|
|
128
|
+
return mainList;
|
|
129
|
+
}
|
|
130
|
+
const title = "Main list for current scope";
|
|
131
|
+
const brevoId = yield this.brevoApiContactsService.createBrevoContactList(title, scope);
|
|
132
|
+
if (brevoId) {
|
|
133
|
+
const mainTargetGroupForScope = this.repository.create({ title, brevoId, scope, isMainList: true });
|
|
134
|
+
yield this.entityManager.flush();
|
|
135
|
+
return mainTargetGroupForScope;
|
|
136
|
+
}
|
|
137
|
+
throw new Error("Brevo Error: Could not create contact list");
|
|
117
138
|
}
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
const mainTargetGroupForScope = this.repository.create({ title, brevoId, scope, isMainList: true });
|
|
122
|
-
yield this.entityManager.flush();
|
|
123
|
-
return mainTargetGroupForScope;
|
|
139
|
+
catch (error) {
|
|
140
|
+
(0, brevo_api_utils_1.handleBrevoError)(error);
|
|
141
|
+
throw error;
|
|
124
142
|
}
|
|
125
|
-
throw new Error("Brevo Error: Could not create contact list");
|
|
126
143
|
});
|
|
127
144
|
}
|
|
128
145
|
createIfNotExistsManuallyAssignedContactsTargetGroup(targetGroup) {
|
|
129
146
|
return __awaiter(this, void 0, void 0, function* () {
|
|
130
|
-
|
|
131
|
-
|
|
147
|
+
try {
|
|
148
|
+
if (targetGroup.assignedContactsTargetGroupBrevoId) {
|
|
149
|
+
return targetGroup.assignedContactsTargetGroupBrevoId;
|
|
150
|
+
}
|
|
151
|
+
const brevoId = yield this.brevoApiContactsService.createBrevoContactList(`Manually assigned contacts for target group ${targetGroup.brevoId}`, targetGroup.scope);
|
|
152
|
+
if (!brevoId) {
|
|
153
|
+
throw new Error("Brevo Error: Could not create target group in brevo");
|
|
154
|
+
}
|
|
155
|
+
(0, core_1.wrap)(targetGroup).assign({
|
|
156
|
+
assignedContactsTargetGroupBrevoId: brevoId,
|
|
157
|
+
});
|
|
158
|
+
yield this.entityManager.flush();
|
|
159
|
+
return brevoId;
|
|
132
160
|
}
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
throw
|
|
161
|
+
catch (error) {
|
|
162
|
+
(0, brevo_api_utils_1.handleBrevoError)(error);
|
|
163
|
+
throw error;
|
|
136
164
|
}
|
|
137
|
-
(0, core_1.wrap)(targetGroup).assign({
|
|
138
|
-
assignedContactsTargetGroupBrevoId: brevoId,
|
|
139
|
-
});
|
|
140
|
-
yield this.entityManager.flush();
|
|
141
|
-
return brevoId;
|
|
142
165
|
});
|
|
143
166
|
}
|
|
144
167
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"target-groups.service.js","sourceRoot":"","sources":["../../src/target-group/target-groups.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAAA,4CAA+E;AAC/E,0CAAkG;AAClG,8CAAqD;AACrD,2CAA4C;AAE5C,sFAAiF;AAO1E,IAAM,mBAAmB,GAAzB,MAAM,mBAAmB;IAC5B,YACsD,UAAkD,EACnF,uBAAgD,EAChD,aAA4B;QAFK,eAAU,GAAV,UAAU,CAAwC;QACnF,4BAAuB,GAAvB,uBAAuB,CAAyB;QAChD,kB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CAAC;aAChB;YACD,OAAO,IAAI,CAAC;SACf;QACD,OAAO,KAAK,CAAC;IACjB,CAAC;IAEY,2BAA2B,CACpC,WAAiC,EACjC,KAAkC,EAClC,OAA+C;;YAE/C,MAAM,wBAAwB,GAAG,MAAM,IAAI,CAAC,UAAU,CAAC,aAAa,CAAC,EAAE,KAAK,EAAE,UAAU,EAAE,IAAI,EAAE,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"target-groups.service.js","sourceRoot":"","sources":["../../src/target-group/target-groups.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAAA,4CAA+E;AAC/E,0CAAkG;AAClG,8CAAqD;AACrD,2CAA4C;AAE5C,kEAAgE;AAChE,sFAAiF;AAO1E,IAAM,mBAAmB,GAAzB,MAAM,mBAAmB;IAC5B,YACsD,UAAkD,EACnF,uBAAgD,EAChD,aAA4B;QAFK,eAAU,GAAV,UAAU,CAAwC;QACnF,4BAAuB,GAAvB,uBAAuB,CAAyB;QAChD,kBAAa,GAAb,aAAa,CAAe;IAC9C,CAAC;IAEJ,gBAAgB,CAAC,OAAwD;QACrE,MAAM,UAAU,GAAG,EAAE,CAAC;QAEtB,IAAI,OAAO,CAAC,MAAM,EAAE;YAChB,UAAU,CAAC,IAAI,CAAC,IAAA,+BAAqB,EAAC,OAAO,CAAC,MAAM,EAAE,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;SACrE;QAED,IAAI,OAAO,CAAC,MAAM,EAAE;YAChB,UAAU,CAAC,IAAI,CAAC,IAAA,gCAAsB,EAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC;SAC3D;QAED,OAAO,UAAU,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,UAAU,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;IAC7D,CAAC;IAEM,6BAA6B,CAChC,iBAAmD,EACnD,OAA+C;QAE/C,IAAI,OAAO,IAAI,iBAAiB,EAAE;YAC9B,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