@cemiar/cemiarlink-sdk 1.0.22 → 1.0.24
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/dist/exceptions/EpicException.d.ts +3 -0
- package/dist/exceptions/EpicException.js +10 -0
- package/dist/exceptions/MissingInfo.d.ts +3 -0
- package/dist/exceptions/MissingInfo.js +10 -0
- package/dist/exceptions/NotProcessYet.d.ts +3 -0
- package/dist/exceptions/NotProcessYet.js +10 -0
- package/dist/models/admin/BusMessage.d.ts +4 -0
- package/dist/models/admin/BusMessage.js +2 -0
- package/dist/models/admin/Counter.d.ts +8 -0
- package/dist/models/admin/Counter.js +2 -0
- package/dist/models/admin/Email.d.ts +49 -0
- package/dist/models/admin/Email.js +2 -0
- package/dist/models/admin/ExcelSheet.d.ts +5 -0
- package/dist/models/admin/ExcelSheet.js +2 -0
- package/dist/models/admin/ExtractTable.d.ts +37 -0
- package/dist/models/admin/ExtractTable.js +2 -0
- package/dist/models/admin/IDictionary.d.ts +3 -0
- package/dist/models/admin/IDictionary.js +2 -0
- package/dist/models/admin/KimobyResult.d.ts +17 -0
- package/dist/models/admin/KimobyResult.js +2 -0
- package/dist/models/admin/PdfReader.d.ts +26 -0
- package/dist/models/admin/PdfReader.js +2 -0
- package/dist/models/admin/Primaco.d.ts +14 -0
- package/dist/models/admin/Primaco.js +2 -0
- package/dist/models/epic/Activity.d.ts +83 -0
- package/dist/models/epic/Activity.js +2 -0
- package/dist/models/epic/AdditionalInterest.d.ts +15 -0
- package/dist/models/epic/AdditionalInterest.js +2 -0
- package/dist/models/epic/Address.d.ts +10 -0
- package/dist/models/epic/Address.js +2 -0
- package/dist/models/epic/Attachment.d.ts +51 -0
- package/dist/models/epic/Attachment.js +2 -0
- package/dist/models/epic/Broker.d.ts +38 -0
- package/dist/models/epic/Broker.js +2 -0
- package/dist/models/epic/Claim.d.ts +24 -0
- package/dist/models/epic/Claim.js +2 -0
- package/dist/models/epic/Commission.d.ts +76 -0
- package/dist/models/epic/Commission.js +2 -0
- package/dist/models/epic/Company.d.ts +9 -0
- package/dist/models/epic/Company.js +2 -0
- package/dist/models/epic/Contact.d.ts +49 -0
- package/dist/models/epic/Contact.js +2 -0
- package/dist/models/epic/Customer.d.ts +99 -0
- package/dist/models/epic/Customer.js +2 -0
- package/dist/models/epic/DirectBillCommission.d.ts +18 -0
- package/dist/models/epic/DirectBillCommission.js +2 -0
- package/dist/models/epic/Driver.d.ts +67 -0
- package/dist/models/epic/Driver.js +2 -0
- package/dist/models/epic/Employee.d.ts +145 -0
- package/dist/models/epic/Employee.js +2 -0
- package/dist/models/epic/GeneralLedgerReconcileBank.d.ts +117 -0
- package/dist/models/epic/GeneralLedgerReconcileBank.js +2 -0
- package/dist/models/epic/Habitational.d.ts +156 -0
- package/dist/models/epic/Habitational.js +2 -0
- package/dist/models/epic/JournalEntry.d.ts +69 -0
- package/dist/models/epic/JournalEntry.js +2 -0
- package/dist/models/epic/Line.d.ts +169 -0
- package/dist/models/epic/Line.js +2 -0
- package/dist/models/epic/Lookup.d.ts +5 -0
- package/dist/models/epic/Lookup.js +2 -0
- package/dist/models/epic/MultiCarrierSchedule.d.ts +70 -0
- package/dist/models/epic/MultiCarrierSchedule.js +11 -0
- package/dist/models/epic/Opportunity.d.ts +45 -0
- package/dist/models/epic/Opportunity.js +2 -0
- package/dist/models/epic/OptionType.d.ts +4 -0
- package/dist/models/epic/OptionType.js +2 -0
- package/dist/models/epic/PayableContract.d.ts +19 -0
- package/dist/models/epic/PayableContract.js +2 -0
- package/dist/models/epic/Policy.d.ts +129 -0
- package/dist/models/epic/Policy.js +2 -0
- package/dist/models/epic/PolicyV2.d.ts +157 -0
- package/dist/models/epic/PolicyV2.js +2 -0
- package/dist/models/epic/Receipt.d.ts +142 -0
- package/dist/models/epic/Receipt.js +2 -0
- package/dist/models/epic/RenewalStage.d.ts +5 -0
- package/dist/models/epic/RenewalStage.js +2 -0
- package/dist/models/epic/Response.d.ts +9 -0
- package/dist/models/epic/Response.js +2 -0
- package/dist/models/epic/ServiceSummary.d.ts +16 -0
- package/dist/models/epic/ServiceSummary.js +8 -0
- package/dist/models/epic/ServicingContact.d.ts +6 -0
- package/dist/models/epic/ServicingContact.js +2 -0
- package/dist/models/epic/Transaction.d.ts +261 -0
- package/dist/models/epic/Transaction.js +2 -0
- package/dist/models/epic/Vehicle.d.ts +87 -0
- package/dist/models/epic/Vehicle.js +2 -0
- package/dist/models/mail/EmailAttachment.d.ts +5 -0
- package/dist/models/mail/EmailAttachment.js +2 -0
- package/dist/models/mail/EmailReport.d.ts +10 -0
- package/dist/models/mail/EmailReport.js +2 -0
- package/dist/models/mail/GetEmailReportOptions.d.ts +5 -0
- package/dist/models/mail/GetEmailReportOptions.js +2 -0
- package/dist/models/mail/GmailMail.d.ts +8 -0
- package/dist/models/mail/GmailMail.js +2 -0
- package/dist/models/mail/TransactionWatchList.d.ts +7 -0
- package/dist/models/mail/TransactionWatchList.js +2 -0
- package/dist/models/sharepoint/Sharepoint.d.ts +25 -0
- package/dist/models/sharepoint/Sharepoint.js +2 -0
- package/dist/services/Admin.d.ts +40 -0
- package/dist/services/Admin.js +222 -0
- package/dist/services/BaseEpicService.d.ts +16 -0
- package/dist/services/BaseEpicService.js +107 -0
- package/dist/services/Epic.d.ts +129 -0
- package/dist/services/Epic.js +313 -0
- package/dist/services/JobEpicService.d.ts +11 -0
- package/dist/services/JobEpicService.js +21 -0
- package/dist/services/Mail.d.ts +52 -0
- package/dist/services/Mail.js +318 -0
- package/dist/services/MultiCarrierScheduleEpicService.d.ts +12 -0
- package/dist/services/MultiCarrierScheduleEpicService.js +24 -0
- package/dist/services/SharepointService.d.ts +13 -0
- package/dist/services/SharepointService.js +44 -0
- package/dist/utils/AxiosClient.d.ts +6 -0
- package/dist/utils/AxiosClient.js +35 -0
- package/dist/utils/DeepPartial.d.ts +3 -0
- package/dist/utils/DeepPartial.js +2 -0
- package/dist/utils/Excel.d.ts +8 -0
- package/dist/utils/Excel.js +99 -0
- package/package.json +1 -1
|
@@ -0,0 +1,318 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.MailService = void 0;
|
|
7
|
+
const fs_1 = __importDefault(require("fs"));
|
|
8
|
+
const nodemailer_1 = __importDefault(require("nodemailer"));
|
|
9
|
+
const AxiosClient_1 = require("../utils/AxiosClient");
|
|
10
|
+
/**
|
|
11
|
+
* MailService provides email-related features such as sending emails, managing folders, retrieving messages, and handling attachments.
|
|
12
|
+
* It uses Nodemailer and Axios for communication with Gmail and the Cemiar mail API.
|
|
13
|
+
*/
|
|
14
|
+
class MailService {
|
|
15
|
+
constructor(mailUrl, headers, user, password) {
|
|
16
|
+
this.axiosInstance = new AxiosClient_1.AxiosClient(mailUrl, headers).getInstance();
|
|
17
|
+
this.transporter = nodemailer_1.default.createTransport({
|
|
18
|
+
service: 'gmail',
|
|
19
|
+
auth: {
|
|
20
|
+
user: user,
|
|
21
|
+
pass: password,
|
|
22
|
+
},
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
async getEmailFolders() {
|
|
26
|
+
const folders = await this.axiosInstance.get('gmail/folders');
|
|
27
|
+
return folders.data.labels;
|
|
28
|
+
}
|
|
29
|
+
async getEmailMessageIds(filter) {
|
|
30
|
+
// get messages id from gmail
|
|
31
|
+
const queryString = this.buildQueryString(filter);
|
|
32
|
+
const url = `gmail?${queryString}`;
|
|
33
|
+
const res = await this.axiosInstance.get(url);
|
|
34
|
+
if (res.data.resultSizeEstimate == 0) {
|
|
35
|
+
return [];
|
|
36
|
+
}
|
|
37
|
+
return res.data.messages.map((message) => message.id);
|
|
38
|
+
}
|
|
39
|
+
async updateEmailMetadata(mailId, payload) {
|
|
40
|
+
// set mail as read
|
|
41
|
+
await this.axiosInstance.put('gmail/' + mailId, payload);
|
|
42
|
+
}
|
|
43
|
+
async getEmailContent(mailId) {
|
|
44
|
+
const { data } = await this.axiosInstance.get(`gmail/${mailId}?format=FULL`);
|
|
45
|
+
return data;
|
|
46
|
+
}
|
|
47
|
+
findAttachment(parts, attachmentTypes) {
|
|
48
|
+
if (!parts)
|
|
49
|
+
return null;
|
|
50
|
+
let attachment = null;
|
|
51
|
+
for (const part of parts) {
|
|
52
|
+
if (part.mimeType === 'multipart/mixed') {
|
|
53
|
+
for (const subPart of part.parts) {
|
|
54
|
+
if (attachmentTypes.some((type) => subPart.filename.includes(`.${type}`))) {
|
|
55
|
+
attachment = subPart;
|
|
56
|
+
break;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
if (attachmentTypes.some((type) => part.filename.includes(`.${type}`))) {
|
|
62
|
+
attachment = part;
|
|
63
|
+
break;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
return attachment;
|
|
68
|
+
}
|
|
69
|
+
async findData(parts) {
|
|
70
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
|
|
71
|
+
let data = '';
|
|
72
|
+
if (parts) {
|
|
73
|
+
if ((_b = (_a = parts[0]) === null || _a === void 0 ? void 0 : _a.body) === null || _b === void 0 ? void 0 : _b.data) {
|
|
74
|
+
data = parts[0].body.data;
|
|
75
|
+
}
|
|
76
|
+
if ((_c = parts[0]) === null || _c === void 0 ? void 0 : _c.parts) {
|
|
77
|
+
if ((_f = (_e = (_d = parts[0]) === null || _d === void 0 ? void 0 : _d.parts[0]) === null || _e === void 0 ? void 0 : _e.body) === null || _f === void 0 ? void 0 : _f.data) {
|
|
78
|
+
data = parts[0].parts[0].body.data;
|
|
79
|
+
}
|
|
80
|
+
if ((_h = (_g = parts[0]) === null || _g === void 0 ? void 0 : _g.parts[0]) === null || _h === void 0 ? void 0 : _h.parts) {
|
|
81
|
+
if ((_m = (_l = (_k = (_j = parts[0]) === null || _j === void 0 ? void 0 : _j.parts[0]) === null || _k === void 0 ? void 0 : _k.parts[0]) === null || _l === void 0 ? void 0 : _l.body) === null || _m === void 0 ? void 0 : _m.data) {
|
|
82
|
+
data = parts[0].parts[0].parts[0].body.data;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
return data;
|
|
88
|
+
}
|
|
89
|
+
async fetchAttachment(mailId, attachmentId) {
|
|
90
|
+
const { data } = await this.axiosInstance.get(`gmail/attachment/${mailId}/${attachmentId}`);
|
|
91
|
+
return data;
|
|
92
|
+
}
|
|
93
|
+
extractSubject(headers) {
|
|
94
|
+
return headers.find((header) => header.name === 'Subject')['value'].toLowerCase();
|
|
95
|
+
}
|
|
96
|
+
extractTextContent(parts) {
|
|
97
|
+
const textPart = parts ? parts.find((p) => p.mimeType === 'text/plain') : undefined;
|
|
98
|
+
return textPart ? Buffer.from(textPart.body.data, 'base64').toString('binary') : '';
|
|
99
|
+
}
|
|
100
|
+
extractRecipientEmail(headers) {
|
|
101
|
+
const toHeader = headers.find((header) => header.name === 'To');
|
|
102
|
+
if (!toHeader || typeof toHeader.value !== 'string') {
|
|
103
|
+
return null;
|
|
104
|
+
}
|
|
105
|
+
const from = toHeader.value;
|
|
106
|
+
const emailPattern = /[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}/;
|
|
107
|
+
const match = from.match(emailPattern);
|
|
108
|
+
return match ? match[0] : null;
|
|
109
|
+
}
|
|
110
|
+
extractReturnAddress(headers) {
|
|
111
|
+
const from = headers.find((header) => header.name === 'From')['value'].toLowerCase();
|
|
112
|
+
try {
|
|
113
|
+
return from.match(/<(.*)>/)[1];
|
|
114
|
+
}
|
|
115
|
+
catch (_a) {
|
|
116
|
+
return from;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
async extractTransactionWatchData(data, returnAddress) {
|
|
120
|
+
let transactionWatch = {
|
|
121
|
+
financement: '',
|
|
122
|
+
transfert: false,
|
|
123
|
+
itemNumbers: [],
|
|
124
|
+
clientCode: '',
|
|
125
|
+
from: returnAddress,
|
|
126
|
+
};
|
|
127
|
+
let buffer = Buffer.from(data, 'base64');
|
|
128
|
+
let rows = buffer
|
|
129
|
+
.toString()
|
|
130
|
+
.split('[')[0]
|
|
131
|
+
.replace(/[\r ()*]+/g, '')
|
|
132
|
+
.toLowerCase()
|
|
133
|
+
.split('\n');
|
|
134
|
+
for (let row of rows) {
|
|
135
|
+
if (row.indexOf('codeclient:') !== -1) {
|
|
136
|
+
transactionWatch.clientCode = row.split(':')[1];
|
|
137
|
+
}
|
|
138
|
+
if (row.indexOf('transfertdecrédits') !== -1) {
|
|
139
|
+
transactionWatch.transfert = true;
|
|
140
|
+
}
|
|
141
|
+
if (row.indexOf('financement:') !== -1) {
|
|
142
|
+
transactionWatch.financement = row.split(':')[1];
|
|
143
|
+
}
|
|
144
|
+
if (row.indexOf('numérostransactions:') !== -1) {
|
|
145
|
+
transactionWatch.itemNumbers = row.split(':')[1].split(',');
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
return transactionWatch;
|
|
149
|
+
}
|
|
150
|
+
buildQueryString(queryParams) {
|
|
151
|
+
return Object.entries(queryParams)
|
|
152
|
+
.map(([key, value]) => `${encodeURIComponent(key)}=${encodeURIComponent(value)}`)
|
|
153
|
+
.join('&');
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* Asynchronously retrieves an email report based on the provided mail object and attachment type.
|
|
157
|
+
*
|
|
158
|
+
* @param to - email recipient
|
|
159
|
+
* @param subjectType
|
|
160
|
+
* @param {GetEmailReportOptions | undefined} options - The options for fetching email report.
|
|
161
|
+
* @returns {object | undefined} - The data of the retrieved report or undefined if not found or an error occurs.
|
|
162
|
+
* @throws {Error} - If an error occurs during the process.
|
|
163
|
+
*/
|
|
164
|
+
async getEmailReport(to, subjectType, options) {
|
|
165
|
+
const date = new Date();
|
|
166
|
+
date.setDate(date.getDate());
|
|
167
|
+
const today = date.toISOString().split('T')[0];
|
|
168
|
+
date.setDate(date.getDate() + 1);
|
|
169
|
+
const tomorrow = date.toISOString().split('T')[0];
|
|
170
|
+
const filter = Object.assign({ q: `to: ${to} after:${today} before:${tomorrow}` }, ((options === null || options === void 0 ? void 0 : options.includeRead) ? {} : { labelIds: 'UNREAD' }));
|
|
171
|
+
const mails = await this.getEmailMessageIds(filter);
|
|
172
|
+
for (const mail of mails) {
|
|
173
|
+
const emailContent = await this.getEmailContent(mail);
|
|
174
|
+
const subject = this.extractSubject(emailContent.payload.headers);
|
|
175
|
+
if (subject.indexOf(subjectType) === -1) {
|
|
176
|
+
continue;
|
|
177
|
+
}
|
|
178
|
+
const { payload: { parts }, } = emailContent;
|
|
179
|
+
const attachment = this.findAttachment(parts, ['xlsx']);
|
|
180
|
+
if (!attachment || attachment.body.size === 0) {
|
|
181
|
+
throw new Error(`Could not find the attachment ending in 'xlsx' in the email: ${mail}.`);
|
|
182
|
+
}
|
|
183
|
+
const attachmentData = await this.fetchAttachment(mail, attachment.body.attachmentId);
|
|
184
|
+
let fileType = attachment.filename.split('.')[1];
|
|
185
|
+
fileType = '.' + fileType;
|
|
186
|
+
const buffer = Buffer.from(attachmentData.data, 'base64');
|
|
187
|
+
if (!fs_1.default.existsSync('./temp/')) {
|
|
188
|
+
fs_1.default.mkdirSync('./temp/');
|
|
189
|
+
}
|
|
190
|
+
fs_1.default.writeFileSync(`./temp/Rapport ${subjectType} du ${today}${fileType}`, buffer);
|
|
191
|
+
if (!(options === null || options === void 0 ? void 0 : options.skipRead))
|
|
192
|
+
await this.updateEmailMetadata(mail, {
|
|
193
|
+
removeLabelIds: ['UNREAD'],
|
|
194
|
+
});
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
/**
|
|
198
|
+
* Asynchronously retrieves all emails' reports based on a date.
|
|
199
|
+
*
|
|
200
|
+
* @param {Date} date - The date of email reports to fetch.
|
|
201
|
+
* @param {GetEmailReportOptions | undefined} options - The options for fetching email report.
|
|
202
|
+
* @returns {EmailReport[]} - The list of reports.
|
|
203
|
+
* @throws {Error} - If an error occurs during the process.
|
|
204
|
+
*/
|
|
205
|
+
async getEmailReports(date, options) {
|
|
206
|
+
const today = date.toISOString().split('T')[0];
|
|
207
|
+
date.setDate(date.getDate() + 1);
|
|
208
|
+
const tomorrow = date.toISOString().split('T')[0];
|
|
209
|
+
let q = `after:${today} before:${tomorrow} in:inbox`;
|
|
210
|
+
if (!(options === null || options === void 0 ? void 0 : options.includeRead))
|
|
211
|
+
q += ' ' + 'in:unread';
|
|
212
|
+
let emailIds = await this.getEmailMessageIds({
|
|
213
|
+
q,
|
|
214
|
+
});
|
|
215
|
+
if (options === null || options === void 0 ? void 0 : options.subfolders) {
|
|
216
|
+
const gMailFolders = await this.getEmailFolders();
|
|
217
|
+
const folders = gMailFolders.filter((f) => { var _a; return (_a = options === null || options === void 0 ? void 0 : options.subfolders) === null || _a === void 0 ? void 0 : _a.includes(f.name); }).map((f) => f.id);
|
|
218
|
+
if (folders) {
|
|
219
|
+
let qu = `after:${today} before:${tomorrow}`;
|
|
220
|
+
if (!(options === null || options === void 0 ? void 0 : options.includeRead)) {
|
|
221
|
+
qu += ' ' + 'in:unread';
|
|
222
|
+
}
|
|
223
|
+
const folderEmails = await this.getEmailMessageIds({
|
|
224
|
+
q: qu,
|
|
225
|
+
labelIds: folders.join(','),
|
|
226
|
+
});
|
|
227
|
+
emailIds.push(...folderEmails);
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
const emailReports = [];
|
|
231
|
+
for (const emailId of emailIds) {
|
|
232
|
+
const emailContent = await this.getEmailContent(emailId);
|
|
233
|
+
const subject = this.extractSubject(emailContent.payload.headers);
|
|
234
|
+
const recipient = this.extractRecipientEmail(emailContent.payload.headers);
|
|
235
|
+
const date = new Date(parseInt(emailContent.internalDate)).toISOString().split('T')[0];
|
|
236
|
+
const { payload: { parts }, } = emailContent;
|
|
237
|
+
const textContent = this.extractTextContent(parts);
|
|
238
|
+
const attachment = this.findAttachment(parts, ['xlsx', 'csv', 'pdf']);
|
|
239
|
+
if (!recipient)
|
|
240
|
+
continue;
|
|
241
|
+
if (!attachment || attachment.body.size === 0) {
|
|
242
|
+
emailReports.push({
|
|
243
|
+
emailId,
|
|
244
|
+
recipient: recipient,
|
|
245
|
+
subject: subject,
|
|
246
|
+
date: date,
|
|
247
|
+
textContent: textContent,
|
|
248
|
+
extension: undefined,
|
|
249
|
+
buffer: undefined,
|
|
250
|
+
from: this.extractReturnAddress(emailContent.payload.headers),
|
|
251
|
+
});
|
|
252
|
+
}
|
|
253
|
+
else {
|
|
254
|
+
const attachmentData = await this.fetchAttachment(emailId, attachment.body.attachmentId);
|
|
255
|
+
const buffer = Buffer.from(attachmentData.data, 'base64');
|
|
256
|
+
emailReports.push({
|
|
257
|
+
emailId,
|
|
258
|
+
recipient,
|
|
259
|
+
subject,
|
|
260
|
+
buffer,
|
|
261
|
+
date,
|
|
262
|
+
extension: attachment.filename.split('.').pop(),
|
|
263
|
+
textContent,
|
|
264
|
+
from: this.extractReturnAddress(emailContent.payload.headers),
|
|
265
|
+
});
|
|
266
|
+
}
|
|
267
|
+
if (!(options === null || options === void 0 ? void 0 : options.skipRead))
|
|
268
|
+
await this.updateEmailMetadata(emailId, {
|
|
269
|
+
removeLabelIds: ['UNREAD'],
|
|
270
|
+
});
|
|
271
|
+
}
|
|
272
|
+
return emailReports.filter((item, index, self) => index ===
|
|
273
|
+
self.findIndex((t) => t.recipient === item.recipient && t.subject === item.subject && t.date === item.date));
|
|
274
|
+
}
|
|
275
|
+
async getTransactionWatchList(to, subjectType) {
|
|
276
|
+
const date = new Date();
|
|
277
|
+
date.setDate(date.getDate());
|
|
278
|
+
const today = date.toISOString().split('T')[0];
|
|
279
|
+
date.setDate(date.getDate() + 1);
|
|
280
|
+
const tomorrow = date.toISOString().split('T')[0];
|
|
281
|
+
const mails = await this.getEmailMessageIds({
|
|
282
|
+
labelIds: 'UNREAD',
|
|
283
|
+
q: `to: ${to} OR cc:${to} after:${today} before:${tomorrow}`,
|
|
284
|
+
});
|
|
285
|
+
let transactionWatchList = [];
|
|
286
|
+
for (const mail of mails) {
|
|
287
|
+
const emailContent = await this.getEmailContent(mail);
|
|
288
|
+
const subject = this.extractSubject(emailContent.payload.headers);
|
|
289
|
+
if (subject.indexOf(subjectType) === -1) {
|
|
290
|
+
continue;
|
|
291
|
+
}
|
|
292
|
+
const returnAddress = this.extractReturnAddress(emailContent.payload.headers);
|
|
293
|
+
const { payload: { parts }, } = emailContent;
|
|
294
|
+
const data = await this.findData(parts);
|
|
295
|
+
transactionWatchList.push(await this.extractTransactionWatchData(data, returnAddress));
|
|
296
|
+
await this.updateEmailMetadata(mail, {
|
|
297
|
+
removeLabelIds: ['UNREAD'],
|
|
298
|
+
});
|
|
299
|
+
}
|
|
300
|
+
return transactionWatchList;
|
|
301
|
+
}
|
|
302
|
+
async deleteEmail(id) {
|
|
303
|
+
await this.axiosInstance.delete(`gmail/${id}`);
|
|
304
|
+
}
|
|
305
|
+
async sendMail(subject, text, html, to, attachments, cc) {
|
|
306
|
+
const mailOptions = {
|
|
307
|
+
from: this.user,
|
|
308
|
+
to,
|
|
309
|
+
subject,
|
|
310
|
+
text,
|
|
311
|
+
html,
|
|
312
|
+
cc,
|
|
313
|
+
attachments,
|
|
314
|
+
};
|
|
315
|
+
await this.transporter.sendMail(mailOptions);
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
exports.MailService = MailService;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { BaseEpicService } from "./BaseEpicService";
|
|
2
|
+
import { MultiCarrierScheduleModel } from "../models/epic/MultiCarrierSchedule";
|
|
3
|
+
/**
|
|
4
|
+
* MultiCarrierScheduleEpicService provides methods to manage multi-carrier schedules via the Epic API.
|
|
5
|
+
* It extends BaseEpicService for common API functionality.
|
|
6
|
+
*/
|
|
7
|
+
export declare class MultiCarrierScheduleEpicService extends BaseEpicService {
|
|
8
|
+
readonly baseUrl = "multiCarrierSchedule";
|
|
9
|
+
getMultiCarrierSchedules(req: MultiCarrierScheduleModel.GetRequest): Promise<MultiCarrierScheduleModel.MultiCarrierSchedule[]>;
|
|
10
|
+
createMultiCarrierSchedule(req: MultiCarrierScheduleModel.CreateRequest): Promise<string>;
|
|
11
|
+
updateMultiCarrierSchedule(multiCarrierScheduleID: number, payload: MultiCarrierScheduleModel.UpdateRequest): Promise<string>;
|
|
12
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MultiCarrierScheduleEpicService = void 0;
|
|
4
|
+
const BaseEpicService_1 = require("./BaseEpicService");
|
|
5
|
+
/**
|
|
6
|
+
* MultiCarrierScheduleEpicService provides methods to manage multi-carrier schedules via the Epic API.
|
|
7
|
+
* It extends BaseEpicService for common API functionality.
|
|
8
|
+
*/
|
|
9
|
+
class MultiCarrierScheduleEpicService extends BaseEpicService_1.BaseEpicService {
|
|
10
|
+
constructor() {
|
|
11
|
+
super(...arguments);
|
|
12
|
+
this.baseUrl = 'multiCarrierSchedule';
|
|
13
|
+
}
|
|
14
|
+
async getMultiCarrierSchedules(req) {
|
|
15
|
+
return this.get(this.baseUrl, req);
|
|
16
|
+
}
|
|
17
|
+
async createMultiCarrierSchedule(req) {
|
|
18
|
+
return this.post(this.baseUrl, req);
|
|
19
|
+
}
|
|
20
|
+
async updateMultiCarrierSchedule(multiCarrierScheduleID, payload) {
|
|
21
|
+
return this.put(`${this.baseUrl}/${multiCarrierScheduleID}`, payload);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
exports.MultiCarrierScheduleEpicService = MultiCarrierScheduleEpicService;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { AxiosInstance } from 'axios';
|
|
2
|
+
import { SharepointConnection, SharepointDownloadResult, SharepointFileInfo, SharepointSearchRequest } from '../models/sharepoint/Sharepoint';
|
|
3
|
+
/**
|
|
4
|
+
* SharepointService provides methods to interact with the SharePoint API for file search, download, and retrieval operations.
|
|
5
|
+
* It wraps Axios and offers methods to find files, download files by ID, and perform combined find-and-download requests.
|
|
6
|
+
*/
|
|
7
|
+
export declare class SharepointService {
|
|
8
|
+
axiosInstance: AxiosInstance;
|
|
9
|
+
constructor(sharepointUrl: string | undefined, headers: any);
|
|
10
|
+
findFile(input: SharepointSearchRequest): Promise<SharepointFileInfo | null>;
|
|
11
|
+
downloadFileById(id: string, connection: SharepointConnection): Promise<Buffer>;
|
|
12
|
+
findAndDownload(input: SharepointSearchRequest): Promise<SharepointDownloadResult | null>;
|
|
13
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SharepointService = void 0;
|
|
4
|
+
const AxiosClient_1 = require("../utils/AxiosClient");
|
|
5
|
+
/**
|
|
6
|
+
* SharepointService provides methods to interact with the SharePoint API for file search, download, and retrieval operations.
|
|
7
|
+
* It wraps Axios and offers methods to find files, download files by ID, and perform combined find-and-download requests.
|
|
8
|
+
*/
|
|
9
|
+
class SharepointService {
|
|
10
|
+
constructor(sharepointUrl, headers) {
|
|
11
|
+
this.axiosInstance = new AxiosClient_1.AxiosClient(sharepointUrl, headers).getInstance();
|
|
12
|
+
}
|
|
13
|
+
async findFile(input) {
|
|
14
|
+
var _a;
|
|
15
|
+
const { data } = await this.axiosInstance.post('sharepoint/files/search', input);
|
|
16
|
+
return (_a = data === null || data === void 0 ? void 0 : data.file) !== null && _a !== void 0 ? _a : null;
|
|
17
|
+
}
|
|
18
|
+
async downloadFileById(id, connection) {
|
|
19
|
+
const res = await this.axiosInstance.post(`sharepoint/files/download/${encodeURIComponent(id)}`, connection, { responseType: 'arraybuffer' });
|
|
20
|
+
return Buffer.from(res.data);
|
|
21
|
+
}
|
|
22
|
+
async findAndDownload(input) {
|
|
23
|
+
const res = await this.axiosInstance.post('sharepoint/files/find-and-download', input, {
|
|
24
|
+
responseType: 'arraybuffer',
|
|
25
|
+
validateStatus: (status) => status === 200 || status === 404,
|
|
26
|
+
});
|
|
27
|
+
if (res.status === 404)
|
|
28
|
+
return null;
|
|
29
|
+
const getHeader = (name) => {
|
|
30
|
+
var _a;
|
|
31
|
+
const value = res.headers[name];
|
|
32
|
+
if (Array.isArray(value))
|
|
33
|
+
return (_a = value[0]) !== null && _a !== void 0 ? _a : '';
|
|
34
|
+
return typeof value === 'string' ? value : String(value !== null && value !== void 0 ? value : '');
|
|
35
|
+
};
|
|
36
|
+
return {
|
|
37
|
+
buffer: Buffer.from(res.data),
|
|
38
|
+
fileName: decodeURIComponent(getHeader('x-sharepoint-file-name')),
|
|
39
|
+
fileId: getHeader('x-sharepoint-file-id'),
|
|
40
|
+
webUrl: getHeader('x-sharepoint-file-weburl'),
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
exports.SharepointService = SharepointService;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.AxiosClient = void 0;
|
|
7
|
+
const axios_1 = __importDefault(require("axios"));
|
|
8
|
+
class AxiosClient {
|
|
9
|
+
constructor(baseURL, headers) {
|
|
10
|
+
this.axiosInstance = axios_1.default.create({
|
|
11
|
+
baseURL: baseURL,
|
|
12
|
+
headers: headers,
|
|
13
|
+
});
|
|
14
|
+
this.axiosInstance.interceptors.response.use((res) => {
|
|
15
|
+
return res;
|
|
16
|
+
}, async (err) => {
|
|
17
|
+
var _a, _b;
|
|
18
|
+
const originalConfig = err.config;
|
|
19
|
+
originalConfig._retry = originalConfig._retry || 0;
|
|
20
|
+
if ((((_a = err === null || err === void 0 ? void 0 : err.response) === null || _a === void 0 ? void 0 : _a.status) === 524 || ((_b = err === null || err === void 0 ? void 0 : err.response) === null || _b === void 0 ? void 0 : _b.status) === 504) && originalConfig._retry < 3) {
|
|
21
|
+
await sleep(originalConfig._retry * 10000);
|
|
22
|
+
originalConfig._retry += 1;
|
|
23
|
+
return await this.axiosInstance(originalConfig);
|
|
24
|
+
}
|
|
25
|
+
return Promise.reject(err);
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
getInstance() {
|
|
29
|
+
return this.axiosInstance;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
exports.AxiosClient = AxiosClient;
|
|
33
|
+
async function sleep(ms) {
|
|
34
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
35
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import ExcelSheet from "../models/admin/ExcelSheet";
|
|
2
|
+
export default class readXlsx {
|
|
3
|
+
static getFromXLSX<T>(path: string, sheetNumber: number): Promise<T[]>;
|
|
4
|
+
static getFromCSV<T>(path: string): Promise<T[]>;
|
|
5
|
+
static appendFile(array: Array<string>, fileName: string): Promise<void>;
|
|
6
|
+
static createFile(data: string[][], header: string[], fileName: string): void;
|
|
7
|
+
static createFileFromSheets(sheets: ExcelSheet[], fileName: string): void;
|
|
8
|
+
}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const fs_1 = __importDefault(require("fs"));
|
|
7
|
+
const xlsx_1 = __importDefault(require("xlsx"));
|
|
8
|
+
class readXlsx {
|
|
9
|
+
static async getFromXLSX(path, sheetNumber) {
|
|
10
|
+
var _a, _b;
|
|
11
|
+
const file = xlsx_1.default.readFile(path);
|
|
12
|
+
const worksheet = file.Sheets[file.SheetNames[sheetNumber]];
|
|
13
|
+
if (!worksheet) {
|
|
14
|
+
return [];
|
|
15
|
+
}
|
|
16
|
+
(_a = worksheet['!rows']) === null || _a === void 0 ? void 0 : _a.shift();
|
|
17
|
+
const range = xlsx_1.default.utils.decode_range((_b = worksheet['!ref']) !== null && _b !== void 0 ? _b : '');
|
|
18
|
+
range.s.r = 1;
|
|
19
|
+
worksheet['!ref'] = xlsx_1.default.utils.encode_range(range);
|
|
20
|
+
return xlsx_1.default.utils.sheet_to_json(file.Sheets[file.SheetNames[sheetNumber]], {
|
|
21
|
+
raw: false,
|
|
22
|
+
defval: '',
|
|
23
|
+
range: range,
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
static async getFromCSV(path) {
|
|
27
|
+
const data = await CSVToJSON(path);
|
|
28
|
+
const Info = [];
|
|
29
|
+
for (let i = 1; i < data.length; i++) {
|
|
30
|
+
const temp = data[i];
|
|
31
|
+
Info.push(temp);
|
|
32
|
+
}
|
|
33
|
+
return Info;
|
|
34
|
+
}
|
|
35
|
+
static async appendFile(array, fileName) {
|
|
36
|
+
let csv = ''; // Construct a CSV row
|
|
37
|
+
for (const el of array) {
|
|
38
|
+
if (array.indexOf(el) === array.length - 1) {
|
|
39
|
+
csv += el + '\n'; // Add new line
|
|
40
|
+
break;
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
csv += el + ',';
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
if (!fs_1.default.existsSync('./result/')) {
|
|
47
|
+
fs_1.default.mkdirSync('./result/');
|
|
48
|
+
}
|
|
49
|
+
fs_1.default.appendFileSync('./result/' + fileName, csv); // Append the CSV row to the file
|
|
50
|
+
}
|
|
51
|
+
static createFile(data, header, fileName) {
|
|
52
|
+
const workbook = xlsx_1.default.utils.book_new();
|
|
53
|
+
const sheetName = 'Rapport';
|
|
54
|
+
const filePath = './result/' + fileName;
|
|
55
|
+
if (!fs_1.default.existsSync('./result/')) {
|
|
56
|
+
fs_1.default.mkdirSync('./result/');
|
|
57
|
+
}
|
|
58
|
+
// Création de la feuille avec les données
|
|
59
|
+
const worksheet = xlsx_1.default.utils.aoa_to_sheet([header, ...data]);
|
|
60
|
+
// Ajout de la feuille de calcul au classeur
|
|
61
|
+
xlsx_1.default.utils.book_append_sheet(workbook, worksheet, sheetName);
|
|
62
|
+
// Création du fichier Excel
|
|
63
|
+
xlsx_1.default.writeFile(workbook, filePath);
|
|
64
|
+
}
|
|
65
|
+
static createFileFromSheets(sheets, fileName) {
|
|
66
|
+
const filePath = './result/' + fileName;
|
|
67
|
+
if (!fs_1.default.existsSync('./result/')) {
|
|
68
|
+
fs_1.default.mkdirSync('./result/');
|
|
69
|
+
}
|
|
70
|
+
const workbook = xlsx_1.default.utils.book_new();
|
|
71
|
+
for (const sheet of sheets) {
|
|
72
|
+
// Création de la feuille avec les données
|
|
73
|
+
const worksheet = xlsx_1.default.utils.aoa_to_sheet([sheet.header, ...sheet.data]);
|
|
74
|
+
// Ajout de la feuille de calcul au classeur
|
|
75
|
+
xlsx_1.default.utils.book_append_sheet(workbook, worksheet, sheet.name);
|
|
76
|
+
}
|
|
77
|
+
// Création du fichier Excel
|
|
78
|
+
xlsx_1.default.writeFile(workbook, filePath);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
exports.default = readXlsx;
|
|
82
|
+
async function CSVToJSON(csv) {
|
|
83
|
+
let file = fs_1.default.readFileSync(csv, 'utf8');
|
|
84
|
+
file = file.replace('\r', '');
|
|
85
|
+
const rows = file.split('\n');
|
|
86
|
+
const titles = rows[0].split(',');
|
|
87
|
+
const data = [];
|
|
88
|
+
for (let i = 1; i < rows.length; i++) {
|
|
89
|
+
if (rows[i] === '')
|
|
90
|
+
continue;
|
|
91
|
+
const elements = rows[i].split(',');
|
|
92
|
+
const temp = {};
|
|
93
|
+
for (let j = 0; j < elements.length; j++) {
|
|
94
|
+
temp[titles[j]] = elements[j];
|
|
95
|
+
}
|
|
96
|
+
data.push(temp);
|
|
97
|
+
}
|
|
98
|
+
return data;
|
|
99
|
+
}
|