@things-factory/email-base 4.3.158 → 4.3.163

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.
@@ -0,0 +1,32 @@
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.sendEmailSes = void 0;
7
+ const env_1 = require("@things-factory/env");
8
+ const nodemailer_1 = __importDefault(require("nodemailer"));
9
+ const aws_sdk_1 = __importDefault(require("aws-sdk"));
10
+ const awsSesEmail = env_1.config.get('awsSesEmail', {});
11
+ async function sendEmailSes({ sender, toMailList, ccMailList, subject, content, attachments }) {
12
+ try {
13
+ let transporter = nodemailer_1.default.createTransport({
14
+ SES: new aws_sdk_1.default.SES({ region: 'ap-southeast-1' })
15
+ });
16
+ let emailp = await transporter.sendMail({
17
+ from: awsSesEmail,
18
+ to: toMailList,
19
+ cc: ccMailList,
20
+ subject: subject,
21
+ // text: '',
22
+ html: content,
23
+ attachments: attachments
24
+ });
25
+ return emailp;
26
+ }
27
+ catch (e) {
28
+ env_1.logger.error(`[sendEmailSes] ${e}`);
29
+ }
30
+ }
31
+ exports.sendEmailSes = sendEmailSes;
32
+ //# sourceMappingURL=email-sender.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"email-sender.js","sourceRoot":"","sources":["../../server/controllers/email-sender.ts"],"names":[],"mappings":";;;;;;AAAA,6CAAoD;AACpD,4DAAmC;AACnC,sDAAyB;AAEzB,MAAM,WAAW,GAAG,YAAM,CAAC,GAAG,CAAC,aAAa,EAAE,EAAE,CAAC,CAAA;AAE1C,KAAK,UAAU,YAAY,CAAC,EAAE,MAAM,EAAE,UAAU,EAAE,UAAU,EAAE,OAAO,EAAE,OAAO,EAAE,WAAW,EAAE;IAClG,IAAI;QACF,IAAI,WAAW,GAAG,oBAAU,CAAC,eAAe,CAAC;YAC3C,GAAG,EAAE,IAAI,iBAAG,CAAC,GAAG,CAAC,EAAE,MAAM,EAAE,gBAAgB,EAAE,CAAC;SAC/C,CAAC,CAAA;QAEF,IAAI,MAAM,GAAG,MAAM,WAAW,CAAC,QAAQ,CAAC;YACtC,IAAI,EAAE,WAAW;YACjB,EAAE,EAAE,UAAU;YACd,EAAE,EAAE,UAAU;YACd,OAAO,EAAE,OAAO;YAChB,YAAY;YACZ,IAAI,EAAE,OAAO;YACb,WAAW,EAAE,WAAW;SACzB,CAAC,CAAA;QAEF,OAAO,MAAM,CAAA;KACd;IAAC,OAAO,CAAC,EAAE;QACV,YAAM,CAAC,KAAK,CAAC,kBAAkB,CAAC,EAAE,CAAC,CAAA;KACpC;AACH,CAAC;AApBD,oCAoBC"}
@@ -0,0 +1,326 @@
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.objDataToExcel = void 0;
7
+ const exceljs_1 = __importDefault(require("exceljs"));
8
+ const lodash_1 = require("lodash");
9
+ async function objDataToExcel({ extension, name, data }) {
10
+ try {
11
+ const records = typeof data == 'function' ? await data.call() : data;
12
+ if (!records.header) {
13
+ throw new Error('data type has to be "{header: [{headerName, fieldName, type, arrData}], data: [{fieldName: value}], groups:[{ column, title }], totals: [value], sheetStyle:{}}"');
14
+ }
15
+ //Perform excel file manipulation. Requirement: import Excel from 'exceljs'
16
+ const EXCEL_FORMATS = {
17
+ DATE: { numFmt: 'dd.mmm.yyyy' },
18
+ DATE_TIME: { numFmt: 'dd.mmm.yyyy hh:mm' },
19
+ TIME: { numFmt: 'hh:mm' }
20
+ };
21
+ const wb = new exceljs_1.default.Workbook();
22
+ const ws = wb.addWorksheet(name);
23
+ let header = [
24
+ { header: 'id', key: 'id', width: 5 },
25
+ ...records.header.map(column => {
26
+ return {
27
+ header: column.header || '',
28
+ key: column.key || '',
29
+ width: column.width ? column.width : column.header.length < 12 ? 12 : column.header.length,
30
+ rowCount: column.rowCount || false
31
+ };
32
+ })
33
+ ];
34
+ var headerObjStructure = records.header.reduce(function (obj, item) {
35
+ obj[item.key] = '';
36
+ return obj;
37
+ }, {});
38
+ ws.columns = header;
39
+ ws._rows[0]._cells.map((cell, index) => {
40
+ cell.name = header[index].key;
41
+ //Set Header Cell Fill
42
+ cell.fill = {
43
+ type: 'pattern',
44
+ pattern: 'solid',
45
+ fgColor: { argb: 'FF0C5394' }
46
+ };
47
+ //Set Header Cell Font style
48
+ cell.font = {
49
+ name: 'Arial',
50
+ color: { argb: 'FFFFFFFF' },
51
+ family: 1,
52
+ size: 12,
53
+ bold: true
54
+ };
55
+ //Set Header Cell Alignment
56
+ cell.alignment = {
57
+ vertical: 'middle',
58
+ horizontal: 'center'
59
+ };
60
+ });
61
+ let [alternateA, alternateB] = ['FFFFFF', 'F3F3F3'];
62
+ let printData = JSON.parse(JSON.stringify(records.data));
63
+ printData = printData.map(data => {
64
+ return Object.assign(Object.assign({}, headerObjStructure), data);
65
+ });
66
+ if (!!records.groups && records.groups.length > 0) {
67
+ printData = multiGroupTree(printData, records.groups.map(itm => itm.column), records.groups, records.totals, header);
68
+ }
69
+ else {
70
+ printData = printData.map(row => {
71
+ ;
72
+ [alternateA, alternateB] = [alternateB, alternateA];
73
+ return {
74
+ data: row,
75
+ style: {
76
+ row: {
77
+ //Set alternate Cell Fill
78
+ fill: {
79
+ type: 'pattern',
80
+ pattern: 'solid',
81
+ fgColor: { argb: alternateA }
82
+ },
83
+ border: {
84
+ bottom: { style: 'thin' }
85
+ }
86
+ }
87
+ }
88
+ };
89
+ });
90
+ }
91
+ //Set each cell's design
92
+ printData.forEach((row, index) => {
93
+ ws.addRow(row.data);
94
+ if (!!row.style) {
95
+ ws._rows[index + 1]._cells.forEach(cell => {
96
+ let cellStyle = row.style[cell._column._key] || {};
97
+ cell.style = Object.assign(Object.assign(Object.assign({}, cell.style), row.style.row), cellStyle);
98
+ });
99
+ }
100
+ });
101
+ if (printData.length == 0) {
102
+ ws.addRow({ id: '' });
103
+ }
104
+ ws.getColumn('id').hidden = true;
105
+ // Cell Type: [ list, whole, decimal, textLength, date ]
106
+ records.header
107
+ .filter(column => column.type === 'array' && column.arrData && column.arrData.length > 0 && column.arrData instanceof Array)
108
+ .map(async (column) => {
109
+ let dataWs = {};
110
+ if (!wb.getWorksheet(column.key)) {
111
+ dataWs = wb.addWorksheet(column.key);
112
+ let header = Object.keys(column.arrData[0]).map(column => {
113
+ return {
114
+ header: column || '',
115
+ key: column || ''
116
+ };
117
+ });
118
+ dataWs.columns = header;
119
+ dataWs.addRows(column.arrData);
120
+ dataWs._rows[0]._cells.map((cell, index) => {
121
+ cell.name = header[index].key;
122
+ });
123
+ dataWs.state = 'veryHidden';
124
+ await dataWs.protect(Math.random().toString(36).substring(2), {
125
+ selectLockedCells: false,
126
+ selectUnlockedCells: false
127
+ });
128
+ }
129
+ else {
130
+ dataWs = wb.getWorksheet(column.key);
131
+ }
132
+ let charColumnCode = String.fromCharCode(97 + dataWs.columns.findIndex(ind => ind._key === 'name')).toUpperCase();
133
+ ws.getColumn(column.key).eachCell(function (cell, rowNumber) {
134
+ if (rowNumber !== 1)
135
+ cell.dataValidation = {
136
+ type: 'list',
137
+ allowBlank: true,
138
+ formulae: [
139
+ dataWs.name + '!$' + charColumnCode + '$2:$' + charColumnCode + '$' + dataWs.rowCount.toString()
140
+ ]
141
+ };
142
+ });
143
+ });
144
+ records.header
145
+ .filter(column => column.type === 'int')
146
+ .map(column => {
147
+ ws.getColumn(column.key).eachCell(function (cell, rowNumber) {
148
+ if (rowNumber !== 1)
149
+ cell.dataValidation = {
150
+ type: 'whole',
151
+ allowBlank: true
152
+ };
153
+ });
154
+ });
155
+ records.header
156
+ .filter(column => column.type === 'float')
157
+ .map(column => {
158
+ ws.getColumn(column.key).eachCell(function (cell, rowNumber) {
159
+ if (rowNumber !== 1)
160
+ cell.dataValidation = {
161
+ type: 'decimal',
162
+ allowBlank: true
163
+ };
164
+ });
165
+ });
166
+ records.header
167
+ .filter(column => column.type === 'date')
168
+ .map(column => {
169
+ ws.getColumn(column.key).eachCell(function (cell, rowNumber) {
170
+ if (rowNumber !== 1) {
171
+ cell.dataValidation = {
172
+ type: 'date',
173
+ allowBlank: true
174
+ };
175
+ cell.value = cell.value ? new Date(parseInt(cell.value)) : '';
176
+ }
177
+ });
178
+ });
179
+ return await wb.xlsx.writeBuffer(EXCEL_FORMATS);
180
+ }
181
+ catch (e) {
182
+ throw e;
183
+ }
184
+ }
185
+ exports.objDataToExcel = objDataToExcel;
186
+ function multiGroupTree(array, groups, groupsRaw, totals, header) {
187
+ if (!groups) {
188
+ return array;
189
+ }
190
+ const currentGroup = groups[0];
191
+ const restGroups = [...groups.slice(1, groups.length)];
192
+ let grouping = (0, lodash_1.groupBy)(array, currentGroup);
193
+ if (!restGroups.length) {
194
+ let rows = [];
195
+ Object.keys(grouping).forEach(itm => {
196
+ let currentGroupSetting = groupsRaw.filter(x => x.column === currentGroup)[0];
197
+ let [alternateA, alternateB] = ['F3F3F3', 'FFFFFF'];
198
+ grouping[itm] = grouping[itm].map((itm, index) => {
199
+ if (index != 0)
200
+ itm[currentGroup] = '';
201
+ [alternateA, alternateB] = [alternateB, alternateA];
202
+ return {
203
+ data: itm,
204
+ style: {
205
+ row: {
206
+ fill: {
207
+ type: 'pattern',
208
+ pattern: 'solid',
209
+ fgColor: { argb: alternateA }
210
+ }
211
+ }
212
+ }
213
+ };
214
+ });
215
+ let newRow = [];
216
+ if (currentGroupSetting.title) {
217
+ let sumData = stripObject(grouping[itm][0]);
218
+ sumData.data[currentGroup] = currentGroupSetting.title;
219
+ totals.forEach(total => {
220
+ sumData.data[total] = grouping[itm].reduce((acc, obj) => {
221
+ var _a;
222
+ acc = acc + ((((_a = header.find(x => x.key == total)) === null || _a === void 0 ? void 0 : _a.rowCount) ? 1 : parseFloat(obj === null || obj === void 0 ? void 0 : obj.data[total])) || 0);
223
+ return acc;
224
+ }, 0);
225
+ });
226
+ sumData.style = getGroupRowStyle([currentGroup]);
227
+ newRow = [sumData];
228
+ }
229
+ rows = [...grouping[itm], ...newRow, ...rows];
230
+ });
231
+ return rows;
232
+ }
233
+ let result = (0, lodash_1.transform)(grouping, (result, value, key) => {
234
+ let rows = multiGroupTree(value, restGroups, groupsRaw, totals, header);
235
+ let currentGroupSetting = groupsRaw.filter(x => x.column === currentGroup)[0];
236
+ rows.map((itm, index) => {
237
+ if (index != 0)
238
+ itm.data[currentGroup] = '';
239
+ return itm;
240
+ });
241
+ let newRow = [];
242
+ if (currentGroupSetting.title) {
243
+ let sumData = stripObject(rows[0]);
244
+ sumData.data[currentGroup] = currentGroupSetting.title;
245
+ totals.forEach(total => {
246
+ sumData.data[total] = value.reduce((acc, obj) => {
247
+ acc = acc + parseFloat(obj[total]) || 0;
248
+ return acc;
249
+ }, 0);
250
+ });
251
+ sumData.style = getGroupRowStyle([currentGroup]);
252
+ newRow = [sumData];
253
+ }
254
+ rows = [...rows, ...newRow];
255
+ if (groupsRaw.findIndex(x => x.column == currentGroupSetting.column) === 0) {
256
+ rows.forEach((row, index) => {
257
+ row.style = Object.assign(Object.assign({}, row.style), { [currentGroupSetting.column]: {
258
+ fill: {
259
+ type: 'pattern',
260
+ pattern: 'solid',
261
+ fgColor: { argb: 'FFCFE2F3' }
262
+ },
263
+ font: {
264
+ name: 'Arial',
265
+ color: { argb: 'FF000000' },
266
+ family: 1,
267
+ bold: true
268
+ }
269
+ } });
270
+ if (index != rows.length - 1) {
271
+ row.style = Object.assign(Object.assign({}, row.style), { [currentGroupSetting.column]: Object.assign(Object.assign({}, row.style[currentGroupSetting.column]), { border: {
272
+ top: { style: '' },
273
+ bottom: { style: '' }
274
+ } }) });
275
+ }
276
+ });
277
+ rows[rows.length - 1].style = Object.assign(Object.assign({}, rows[rows.length - 1].style), { row: Object.assign(Object.assign({}, rows[rows.length - 1].style.row), { border: {
278
+ bottom: { style: 'thin' }
279
+ } }) });
280
+ }
281
+ rows.map(row => result.push(row));
282
+ }, []);
283
+ return result;
284
+ }
285
+ function stripObject(source) {
286
+ var o = Array.isArray(source) ? [] : {};
287
+ for (var key in source) {
288
+ if (source.hasOwnProperty(key)) {
289
+ var t = typeof source[key];
290
+ o[key] =
291
+ source[key] === null
292
+ ? null
293
+ : t == 'object'
294
+ ? stripObject(source[key])
295
+ : { string: '', number: '', boolean: '' }[t];
296
+ }
297
+ }
298
+ return o;
299
+ }
300
+ function getGroupRowStyle(groupColumnName) {
301
+ return {
302
+ [groupColumnName]: {
303
+ alignment: {
304
+ horizontal: 'center'
305
+ }
306
+ },
307
+ row: {
308
+ border: {
309
+ top: { style: 'thin' },
310
+ bottom: { style: 'thin' }
311
+ },
312
+ fill: {
313
+ type: 'pattern',
314
+ pattern: 'solid',
315
+ fgColor: { argb: 'FFEEF7FF' }
316
+ },
317
+ font: {
318
+ name: 'Arial',
319
+ color: { argb: 'FF000000' },
320
+ family: 1,
321
+ bold: true
322
+ }
323
+ }
324
+ };
325
+ }
326
+ //# sourceMappingURL=excel-converter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"excel-converter.js","sourceRoot":"","sources":["../../server/controllers/excel-converter.ts"],"names":[],"mappings":";;;;;;AAAA,sDAA2B;AAC3B,mCAA2C;AAEpC,KAAK,UAAU,cAAc,CAAC,EAAE,SAAS,EAAE,IAAI,EAAE,IAAI,EAAE;IAC5D,IAAI;QACF,MAAM,OAAO,GAAG,OAAO,IAAI,IAAI,UAAU,CAAC,CAAC,CAAC,MAAM,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,IAAI,CAAA;QACpE,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE;YACnB,MAAM,IAAI,KAAK,CACb,kKAAkK,CACnK,CAAA;SACF;QACD,2EAA2E;QAC3E,MAAM,aAAa,GAAQ;YACzB,IAAI,EAAE,EAAE,MAAM,EAAE,aAAa,EAAE;YAC/B,SAAS,EAAE,EAAE,MAAM,EAAE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C,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAA;IACvC,KAAK,IAAI,GAAG,IAAI,MAAM,EAAE;QACtB,IAAI,MAAM,CAAC,cAAc,CAAC,GAAG,CAAC,EAAE;YAC9B,IAAI,CAAC,GAAG,OAAO,MAAM,CAAC,GAAG,CAAC,CAAA;YAC1B,CAAC,CAAC,GAAG,CAAC;gBACJ,MAAM,CAAC,GAAG,CAAC,KAAK,IAAI;oBAClB,CAAC,CAAC,IAAI;oBACN,CAAC,CAAC,CAAC,IAAI,QAAQ;wBACf,CAAC,CAAC,WAAW,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;wBAC1B,CAAC,CAAC,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC,CAAC,CAAC,CAAA;SACjD;KACF;IACD,OAAO,CAAC,CAAA;AACV,CAAC;AAED,SAAS,gBAAgB,CAAC,eAAe;IACvC,OAAO;QACL,CAAC,eAAe,CAAC,EAAE;YACjB,SAAS,EAAE;gBACT,UAAU,EAAE,QAAQ;aACrB;SACF;QACD,GAAG,EAAE;YACH,MAAM,EAAE;gBACN,GAAG,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE;gBACtB,MAAM,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE;aAC1B;YACD,IAAI,EAAE;gBACJ,IAAI,EAAE,SAAS;gBACf,OAAO,EAAE,OAAO;gBAChB,OAAO,EAAE,EAAE,IAAI,EAAE,UAAU,EAAE;aAC9B;YACD,IAAI,EAAE;gBACJ,IAAI,EAAE,OAAO;gBACb,KAAK,EAAE,EAAE,IAAI,EAAE,UAAU,EAAE;gBAC3B,MAAM,EAAE,CAAC;gBACT,IAAI,EAAE,IAAI;aACX;SACF;KACF,CAAA;AACH,CAAC"}
@@ -14,5 +14,9 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
+ exports.objDataToExcel = void 0;
17
18
  __exportStar(require("./email"), exports);
19
+ __exportStar(require("./email-sender"), exports);
20
+ var excel_converter_1 = require("./excel-converter");
21
+ Object.defineProperty(exports, "objDataToExcel", { enumerable: true, get: function () { return excel_converter_1.objDataToExcel; } });
18
22
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../server/controllers/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,0CAAuB"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../server/controllers/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,0CAAuB;AACvB,iDAA8B;AAC9B,qDAAkD;AAAzC,iHAAA,cAAc,OAAA"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@things-factory/email-base",
3
- "version": "4.3.158",
3
+ "version": "4.3.163",
4
4
  "main": "dist-server/index.js",
5
5
  "browser": "client/index.js",
6
6
  "things-factory": true,
@@ -23,11 +23,16 @@
23
23
  "migration:create": "node ./node_modules/typ`eorm/cli.js migration:create"
24
24
  },
25
25
  "dependencies": {
26
- "@things-factory/shell": "^4.3.158",
27
- "nodemailer": "^6.3.1"
26
+ "@things-factory/shell": "^4.3.159",
27
+ "aws-sdk": "^2.1276.0",
28
+ "exceljs": "4.2.0",
29
+ "loadash": "^1.0.0",
30
+ "nodemailer": "^6.3.1",
31
+ "xlsx": "^0.16.8"
28
32
  },
29
33
  "devDependencies": {
34
+ "@types/lodash-es": "^4.17.6",
30
35
  "@types/nodemailer": "^6.2.2"
31
36
  },
32
- "gitHead": "04729e3f63b5aee8184c56a36b6572c05d6abecd"
37
+ "gitHead": "082339ccf43992dc550c7078c605cc2794758c7f"
33
38
  }
@@ -0,0 +1,27 @@
1
+ import { logger, config } from '@things-factory/env'
2
+ import nodemailer from 'nodemailer'
3
+ import AWS from 'aws-sdk'
4
+
5
+ const awsSesEmail = config.get('awsSesEmail', {})
6
+
7
+ export async function sendEmailSes({ sender, toMailList, ccMailList, subject, content, attachments }) {
8
+ try {
9
+ let transporter = nodemailer.createTransport({
10
+ SES: new AWS.SES({ region: 'ap-southeast-1' })
11
+ })
12
+
13
+ let emailp = await transporter.sendMail({
14
+ from: awsSesEmail,
15
+ to: toMailList,
16
+ cc: ccMailList,
17
+ subject: subject,
18
+ // text: '',
19
+ html: content,
20
+ attachments: attachments
21
+ })
22
+
23
+ return emailp
24
+ } catch (e) {
25
+ logger.error(`[sendEmailSes] ${e}`)
26
+ }
27
+ }
@@ -0,0 +1,385 @@
1
+ import Excel from 'exceljs'
2
+ import { groupBy, transform } from 'lodash'
3
+
4
+ export async function objDataToExcel({ extension, name, data }) {
5
+ try {
6
+ const records = typeof data == 'function' ? await data.call() : data
7
+ if (!records.header) {
8
+ throw new Error(
9
+ 'data type has to be "{header: [{headerName, fieldName, type, arrData}], data: [{fieldName: value}], groups:[{ column, title }], totals: [value], sheetStyle:{}}"'
10
+ )
11
+ }
12
+ //Perform excel file manipulation. Requirement: import Excel from 'exceljs'
13
+ const EXCEL_FORMATS: any = {
14
+ DATE: { numFmt: 'dd.mmm.yyyy' },
15
+ DATE_TIME: { numFmt: 'dd.mmm.yyyy hh:mm' },
16
+ TIME: { numFmt: 'hh:mm' }
17
+ }
18
+
19
+ const wb = new Excel.Workbook()
20
+ const ws: any = wb.addWorksheet(name)
21
+ let header = [
22
+ { header: 'id', key: 'id', width: 5 },
23
+ ...records.header.map(column => {
24
+ return {
25
+ header: column.header || '',
26
+ key: column.key || '',
27
+ width: column.width ? column.width : column.header.length < 12 ? 12 : column.header.length,
28
+ rowCount: column.rowCount || false
29
+ }
30
+ })
31
+ ]
32
+
33
+ var headerObjStructure = records.header.reduce(function (obj, item) {
34
+ obj[item.key] = ''
35
+ return obj
36
+ }, {})
37
+
38
+ ws.columns = header
39
+ ws._rows[0]._cells.map((cell, index) => {
40
+ cell.name = header[index].key
41
+
42
+ //Set Header Cell Fill
43
+ cell.fill = {
44
+ type: 'pattern',
45
+ pattern: 'solid',
46
+ fgColor: { argb: 'FF0C5394' }
47
+ }
48
+ //Set Header Cell Font style
49
+ cell.font = {
50
+ name: 'Arial',
51
+ color: { argb: 'FFFFFFFF' },
52
+ family: 1,
53
+ size: 12,
54
+ bold: true
55
+ }
56
+ //Set Header Cell Alignment
57
+ cell.alignment = {
58
+ vertical: 'middle',
59
+ horizontal: 'center'
60
+ }
61
+ })
62
+
63
+ let [alternateA, alternateB] = ['FFFFFF', 'F3F3F3']
64
+ let printData = JSON.parse(JSON.stringify(records.data))
65
+
66
+ printData = printData.map(data => {
67
+ return { ...headerObjStructure, ...data }
68
+ })
69
+
70
+ if (!!records.groups && records.groups.length > 0) {
71
+ printData = multiGroupTree(
72
+ printData,
73
+ records.groups.map(itm => itm.column),
74
+ records.groups,
75
+ records.totals,
76
+ header
77
+ )
78
+ } else {
79
+ printData = printData.map(row => {
80
+ ;[alternateA, alternateB] = [alternateB, alternateA]
81
+ return {
82
+ data: row,
83
+ style: {
84
+ row: {
85
+ //Set alternate Cell Fill
86
+ fill: {
87
+ type: 'pattern',
88
+ pattern: 'solid',
89
+ fgColor: { argb: alternateA }
90
+ },
91
+ border: {
92
+ bottom: { style: 'thin' }
93
+ }
94
+ }
95
+ }
96
+ }
97
+ })
98
+ }
99
+
100
+ //Set each cell's design
101
+ printData.forEach((row, index) => {
102
+ ws.addRow(row.data)
103
+
104
+ if (!!row.style) {
105
+ ws._rows[index + 1]._cells.forEach(cell => {
106
+ let cellStyle = row.style[cell._column._key] || {}
107
+ cell.style = { ...cell.style, ...row.style.row, ...cellStyle }
108
+ })
109
+ }
110
+ })
111
+
112
+ if (printData.length == 0) {
113
+ ws.addRow({ id: '' })
114
+ }
115
+
116
+ ws.getColumn('id').hidden = true
117
+
118
+ // Cell Type: [ list, whole, decimal, textLength, date ]
119
+ records.header
120
+ .filter(
121
+ column =>
122
+ column.type === 'array' && column.arrData && column.arrData.length > 0 && column.arrData instanceof Array
123
+ )
124
+ .map(async column => {
125
+ let dataWs: any = {}
126
+ if (!wb.getWorksheet(column.key)) {
127
+ dataWs = wb.addWorksheet(column.key)
128
+ let header = Object.keys(column.arrData[0]).map(column => {
129
+ return {
130
+ header: column || '',
131
+ key: column || ''
132
+ }
133
+ })
134
+ dataWs.columns = header
135
+ dataWs.addRows(column.arrData)
136
+ dataWs._rows[0]._cells.map((cell, index) => {
137
+ cell.name = header[index].key
138
+ })
139
+
140
+ dataWs.state = 'veryHidden'
141
+ await dataWs.protect(Math.random().toString(36).substring(2), {
142
+ selectLockedCells: false,
143
+ selectUnlockedCells: false
144
+ })
145
+ } else {
146
+ dataWs = wb.getWorksheet(column.key)
147
+ }
148
+
149
+ let charColumnCode = String.fromCharCode(
150
+ 97 + dataWs.columns.findIndex(ind => ind._key === 'name')
151
+ ).toUpperCase()
152
+
153
+ ws.getColumn(column.key).eachCell(function (cell, rowNumber) {
154
+ if (rowNumber !== 1)
155
+ cell.dataValidation = {
156
+ type: 'list',
157
+ allowBlank: true,
158
+ formulae: [
159
+ dataWs.name + '!$' + charColumnCode + '$2:$' + charColumnCode + '$' + dataWs.rowCount.toString()
160
+ ]
161
+ }
162
+ })
163
+ })
164
+
165
+ records.header
166
+ .filter(column => column.type === 'int')
167
+ .map(column => {
168
+ ws.getColumn(column.key).eachCell(function (cell, rowNumber) {
169
+ if (rowNumber !== 1)
170
+ cell.dataValidation = {
171
+ type: 'whole',
172
+ allowBlank: true
173
+ }
174
+ })
175
+ })
176
+
177
+ records.header
178
+ .filter(column => column.type === 'float')
179
+ .map(column => {
180
+ ws.getColumn(column.key).eachCell(function (cell, rowNumber) {
181
+ if (rowNumber !== 1)
182
+ cell.dataValidation = {
183
+ type: 'decimal',
184
+ allowBlank: true
185
+ }
186
+ })
187
+ })
188
+
189
+ records.header
190
+ .filter(column => column.type === 'date')
191
+ .map(column => {
192
+ ws.getColumn(column.key).eachCell(function (cell, rowNumber) {
193
+ if (rowNumber !== 1) {
194
+ cell.dataValidation = {
195
+ type: 'date',
196
+ allowBlank: true
197
+ }
198
+ cell.value = cell.value ? new Date(parseInt(cell.value)) : ''
199
+ }
200
+ })
201
+ })
202
+
203
+ return await wb.xlsx.writeBuffer(EXCEL_FORMATS)
204
+ } catch (e) {
205
+ throw e
206
+ }
207
+ }
208
+
209
+ function multiGroupTree(array, groups, groupsRaw, totals, header) {
210
+ if (!groups) {
211
+ return array
212
+ }
213
+ const currentGroup = groups[0]
214
+ const restGroups = [...groups.slice(1, groups.length)]
215
+ let grouping = groupBy(array, currentGroup)
216
+
217
+ if (!restGroups.length) {
218
+ let rows = []
219
+ Object.keys(grouping).forEach(itm => {
220
+ let currentGroupSetting = groupsRaw.filter(x => x.column === currentGroup)[0]
221
+
222
+ let [alternateA, alternateB] = ['F3F3F3', 'FFFFFF']
223
+ grouping[itm] = grouping[itm].map((itm, index) => {
224
+ if (index != 0) itm[currentGroup] = ''
225
+ ;[alternateA, alternateB] = [alternateB, alternateA]
226
+
227
+ return {
228
+ data: itm,
229
+ style: {
230
+ row: {
231
+ fill: {
232
+ type: 'pattern',
233
+ pattern: 'solid',
234
+ fgColor: { argb: alternateA }
235
+ }
236
+ }
237
+ }
238
+ }
239
+ })
240
+
241
+ let newRow = []
242
+ if (currentGroupSetting.title) {
243
+ let sumData: any = stripObject(grouping[itm][0])
244
+ sumData.data[currentGroup] = currentGroupSetting.title
245
+
246
+ totals.forEach(total => {
247
+ sumData.data[total] = grouping[itm].reduce((acc: any, obj: any) => {
248
+ acc = acc + ((header.find(x => x.key == total)?.rowCount ? 1 : parseFloat(obj?.data[total])) || 0)
249
+ return acc
250
+ }, 0)
251
+ })
252
+
253
+ sumData.style = getGroupRowStyle([currentGroup])
254
+ newRow = [sumData]
255
+ }
256
+
257
+ rows = [...grouping[itm], ...newRow, ...rows]
258
+ })
259
+
260
+ return rows
261
+ }
262
+
263
+ let result = transform(
264
+ grouping,
265
+ (result, value, key) => {
266
+ let rows = multiGroupTree(value, restGroups, groupsRaw, totals, header)
267
+
268
+ let currentGroupSetting = groupsRaw.filter(x => x.column === currentGroup)[0]
269
+
270
+ rows.map((itm, index) => {
271
+ if (index != 0) itm.data[currentGroup] = ''
272
+ return itm
273
+ })
274
+
275
+ let newRow = []
276
+ if (currentGroupSetting.title) {
277
+ let sumData: any = stripObject(rows[0])
278
+ sumData.data[currentGroup] = currentGroupSetting.title
279
+
280
+ totals.forEach(total => {
281
+ sumData.data[total] = value.reduce((acc: any, obj) => {
282
+ acc = acc + parseFloat(obj[total]) || 0
283
+ return acc
284
+ }, 0)
285
+ })
286
+
287
+ sumData.style = getGroupRowStyle([currentGroup])
288
+ newRow = [sumData]
289
+ }
290
+
291
+ rows = [...rows, ...newRow]
292
+
293
+ if (groupsRaw.findIndex(x => x.column == currentGroupSetting.column) === 0) {
294
+ rows.forEach((row, index) => {
295
+ row.style = {
296
+ ...row.style,
297
+ [currentGroupSetting.column]: {
298
+ fill: {
299
+ type: 'pattern',
300
+ pattern: 'solid',
301
+ fgColor: { argb: 'FFCFE2F3' }
302
+ },
303
+ font: {
304
+ name: 'Arial',
305
+ color: { argb: 'FF000000' },
306
+ family: 1,
307
+ bold: true
308
+ }
309
+ }
310
+ }
311
+
312
+ if (index != rows.length - 1) {
313
+ row.style = {
314
+ ...row.style,
315
+ [currentGroupSetting.column]: {
316
+ ...row.style[currentGroupSetting.column],
317
+ border: {
318
+ top: { style: '' },
319
+ bottom: { style: '' }
320
+ }
321
+ }
322
+ }
323
+ }
324
+ })
325
+
326
+ rows[rows.length - 1].style = {
327
+ ...rows[rows.length - 1].style,
328
+ row: {
329
+ ...rows[rows.length - 1].style.row,
330
+ border: {
331
+ bottom: { style: 'thin' }
332
+ }
333
+ }
334
+ }
335
+ }
336
+
337
+ rows.map(row => result.push(row))
338
+ },
339
+ []
340
+ )
341
+ return result
342
+ }
343
+
344
+ function stripObject(source) {
345
+ var o = Array.isArray(source) ? [] : {}
346
+ for (var key in source) {
347
+ if (source.hasOwnProperty(key)) {
348
+ var t = typeof source[key]
349
+ o[key] =
350
+ source[key] === null
351
+ ? null
352
+ : t == 'object'
353
+ ? stripObject(source[key])
354
+ : { string: '', number: '', boolean: '' }[t]
355
+ }
356
+ }
357
+ return o
358
+ }
359
+
360
+ function getGroupRowStyle(groupColumnName) {
361
+ return {
362
+ [groupColumnName]: {
363
+ alignment: {
364
+ horizontal: 'center'
365
+ }
366
+ },
367
+ row: {
368
+ border: {
369
+ top: { style: 'thin' },
370
+ bottom: { style: 'thin' }
371
+ },
372
+ fill: {
373
+ type: 'pattern',
374
+ pattern: 'solid',
375
+ fgColor: { argb: 'FFEEF7FF' }
376
+ },
377
+ font: {
378
+ name: 'Arial',
379
+ color: { argb: 'FF000000' },
380
+ family: 1,
381
+ bold: true
382
+ }
383
+ }
384
+ }
385
+ }
@@ -1 +1,3 @@
1
1
  export * from './email'
2
+ export * from './email-sender'
3
+ export { objDataToExcel } from './excel-converter'