@zola_do/document-manipulator 0.1.9
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/document-manipulator.module.d.ts +2 -0
- package/dist/document-manipulator.module.js +25 -0
- package/dist/document-manipulator.module.js.map +1 -0
- package/dist/document-manipulator.service.d.ts +12 -0
- package/dist/document-manipulator.service.js +124 -0
- package/dist/document-manipulator.service.js.map +1 -0
- package/dist/file-helper.service.d.ts +13 -0
- package/dist/file-helper.service.js +40 -0
- package/dist/file-helper.service.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +20 -0
- package/dist/index.js.map +1 -0
- package/package.json +41 -0
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
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
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.DocumentManipulatorModule = void 0;
|
|
10
|
+
const common_1 = require("@nestjs/common");
|
|
11
|
+
const document_manipulator_service_1 = require("./document-manipulator.service");
|
|
12
|
+
const minio_1 = require("@zola_do/minio");
|
|
13
|
+
const file_helper_service_1 = require("./file-helper.service");
|
|
14
|
+
let DocumentManipulatorModule = class DocumentManipulatorModule {
|
|
15
|
+
};
|
|
16
|
+
exports.DocumentManipulatorModule = DocumentManipulatorModule;
|
|
17
|
+
exports.DocumentManipulatorModule = DocumentManipulatorModule = __decorate([
|
|
18
|
+
(0, common_1.Module)({
|
|
19
|
+
imports: [minio_1.MinIOModule],
|
|
20
|
+
controllers: [],
|
|
21
|
+
providers: [document_manipulator_service_1.DocumentManipulatorService, file_helper_service_1.FileHelperService],
|
|
22
|
+
exports: [document_manipulator_service_1.DocumentManipulatorService, file_helper_service_1.FileHelperService],
|
|
23
|
+
})
|
|
24
|
+
], DocumentManipulatorModule);
|
|
25
|
+
//# sourceMappingURL=document-manipulator.module.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"document-manipulator.module.js","sourceRoot":"","sources":["../src/document-manipulator.module.ts"],"names":[],"mappings":";;;;;;;;;AAAA,2CAAwC;AACxC,iFAA4E;AAC5E,0CAA6C;AAC7C,+DAA0D;AAQnD,IAAM,yBAAyB,GAA/B,MAAM,yBAAyB;CAAG,CAAA;AAA5B,8DAAyB;oCAAzB,yBAAyB;IANrC,IAAA,eAAM,EAAC;QACN,OAAO,EAAE,CAAC,mBAAW,CAAC;QACtB,WAAW,EAAE,EAAE;QACf,SAAS,EAAE,CAAC,yDAA0B,EAAE,uCAAiB,CAAC;QAC1D,OAAO,EAAE,CAAC,yDAA0B,EAAE,uCAAiB,CAAC;KACzD,CAAC;GACW,yBAAyB,CAAG"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { MinIOService } from '@zola_do/minio';
|
|
2
|
+
export declare class DocumentManipulatorService {
|
|
3
|
+
private readonly minIOService;
|
|
4
|
+
constructor(minIOService: MinIOService);
|
|
5
|
+
mergePdf(pdfBuffers: Buffer[]): Promise<void>;
|
|
6
|
+
mergeDocx(docxBuffers: Buffer[]): Promise<void>;
|
|
7
|
+
merge(): Promise<void>;
|
|
8
|
+
convertDocument(inputBuffer: Buffer, fileType: string): Promise<Buffer<ArrayBufferLike>>;
|
|
9
|
+
streamToBuffer(readableStream: any): Promise<Buffer>;
|
|
10
|
+
populateTemplate(template: Buffer, data: any): Promise<Buffer<ArrayBuffer>>;
|
|
11
|
+
convertDocxToPdf(file: Buffer): Promise<Buffer>;
|
|
12
|
+
}
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
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
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.DocumentManipulatorService = void 0;
|
|
13
|
+
const common_1 = require("@nestjs/common");
|
|
14
|
+
const pdf_lib_1 = require("pdf-lib");
|
|
15
|
+
const minio_1 = require("@zola_do/minio");
|
|
16
|
+
const DocxMerger = require("@scholarcy/docx-merger");
|
|
17
|
+
const docx_templates_1 = require("docx-templates");
|
|
18
|
+
const libre = require("libreoffice-convert");
|
|
19
|
+
const util_1 = require("util");
|
|
20
|
+
const FormData = require("form-data");
|
|
21
|
+
const axios_1 = require("axios");
|
|
22
|
+
let DocumentManipulatorService = class DocumentManipulatorService {
|
|
23
|
+
constructor(minIOService) {
|
|
24
|
+
this.minIOService = minIOService;
|
|
25
|
+
}
|
|
26
|
+
async mergePdf(pdfBuffers) {
|
|
27
|
+
try {
|
|
28
|
+
const mergedPdf = await pdf_lib_1.PDFDocument.create();
|
|
29
|
+
for (const pdfBuffer of pdfBuffers) {
|
|
30
|
+
const pdf = await pdf_lib_1.PDFDocument.load(pdfBuffer);
|
|
31
|
+
const copiedPages = await mergedPdf.copyPages(pdf, pdf.getPageIndices());
|
|
32
|
+
copiedPages.forEach((page) => {
|
|
33
|
+
mergedPdf.addPage(page);
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
const result = await mergedPdf.save();
|
|
37
|
+
await this.minIOService.uploadBuffer(Buffer.from(result), 'preBudgetPlanReport.pdf', 'application/pdf', minio_1.BucketNameEnum.SPD_TEMPLATE);
|
|
38
|
+
}
|
|
39
|
+
catch (error) {
|
|
40
|
+
throw error;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
async mergeDocx(docxBuffers) {
|
|
44
|
+
try {
|
|
45
|
+
const docx = new DocxMerger();
|
|
46
|
+
await docx.initialize({}, [docxBuffers]);
|
|
47
|
+
const buffer = await docx.save('nodebuffer');
|
|
48
|
+
await this.minIOService.uploadBuffer(buffer, 'preBudgetPlanReport.docx', 'application/vnd.openxmlformats-officedocument.wordprocessingml.document', minio_1.BucketNameEnum.SPD_TEMPLATE);
|
|
49
|
+
}
|
|
50
|
+
catch (error) {
|
|
51
|
+
throw error;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
async merge() {
|
|
55
|
+
const bdsTemplateRead = await this.minIOService.downloadBuffer({
|
|
56
|
+
filepath: 'bds-template.docx',
|
|
57
|
+
bucketName: minio_1.BucketNameEnum.SPD_TEMPLATE,
|
|
58
|
+
});
|
|
59
|
+
const bdsTemplateBuffer = await this.streamToBuffer(bdsTemplateRead);
|
|
60
|
+
const bdsTemplatePopulatedBuffer = await this.populateTemplate(bdsTemplateBuffer, {
|
|
61
|
+
public_body: 'procurement of procedure',
|
|
62
|
+
});
|
|
63
|
+
const bdsTemplatePopulatedHtmlBuffer = await this.convertDocument(bdsTemplatePopulatedBuffer, '.html');
|
|
64
|
+
const bds = bdsTemplatePopulatedHtmlBuffer.toString();
|
|
65
|
+
const testRead = await this.minIOService.downloadBuffer({
|
|
66
|
+
filepath: 'test.docx',
|
|
67
|
+
bucketName: minio_1.BucketNameEnum.SPD_TEMPLATE,
|
|
68
|
+
});
|
|
69
|
+
const testBuffer = await this.streamToBuffer(testRead);
|
|
70
|
+
const testPopulatedBuffer = await this.populateTemplate(testBuffer, {
|
|
71
|
+
subject_of_procurement: 'procurement of procedure',
|
|
72
|
+
procurement_reference_no: 'procurement of procedure',
|
|
73
|
+
project_name: 'procurement of procedure',
|
|
74
|
+
public_body: 'procurement of procedure',
|
|
75
|
+
date_of_issue_of_bidding: new Date(),
|
|
76
|
+
bds: `${bds}`,
|
|
77
|
+
});
|
|
78
|
+
const pdfBuffer = await this.convertDocxToPdf(testPopulatedBuffer);
|
|
79
|
+
await this.minIOService.uploadBuffer(pdfBuffer, 'report.pdf', 'application/pdf', minio_1.BucketNameEnum.SPD_TEMPLATE);
|
|
80
|
+
await this.minIOService.uploadBuffer(testPopulatedBuffer, 'report.docx', 'application/vnd.openxmlformats-officedocument.wordprocessingml.document', minio_1.BucketNameEnum.SPD_TEMPLATE);
|
|
81
|
+
}
|
|
82
|
+
async convertDocument(inputBuffer, fileType) {
|
|
83
|
+
const libreConverterAsync = (0, util_1.promisify)(libre.convert);
|
|
84
|
+
const convertedBuffer = await libreConverterAsync(inputBuffer, fileType, undefined);
|
|
85
|
+
return convertedBuffer;
|
|
86
|
+
}
|
|
87
|
+
async streamToBuffer(readableStream) {
|
|
88
|
+
return new Promise((resolve, reject) => {
|
|
89
|
+
const chunks = [];
|
|
90
|
+
readableStream.on('data', (chunk) => chunks.push(chunk));
|
|
91
|
+
readableStream.on('end', () => resolve(Buffer.concat(chunks)));
|
|
92
|
+
readableStream.on('error', reject);
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
async populateTemplate(template, data) {
|
|
96
|
+
const buffer = await (0, docx_templates_1.createReport)({
|
|
97
|
+
template,
|
|
98
|
+
data,
|
|
99
|
+
});
|
|
100
|
+
return Buffer.from(buffer);
|
|
101
|
+
}
|
|
102
|
+
async convertDocxToPdf(file) {
|
|
103
|
+
var _a;
|
|
104
|
+
try {
|
|
105
|
+
const DOCUMENT_CONVERT_ENDPOINT = (_a = process.env.DOCUMENT_CONVERT_ENDPOINT) !== null && _a !== void 0 ? _a : 'http://196.189.44.48:3000/';
|
|
106
|
+
const form = new FormData();
|
|
107
|
+
form.append('file', file, 'inputFile.docx');
|
|
108
|
+
const request = await axios_1.default.post(DOCUMENT_CONVERT_ENDPOINT, form, {
|
|
109
|
+
responseType: 'arraybuffer',
|
|
110
|
+
});
|
|
111
|
+
const outputBuffer = request.data;
|
|
112
|
+
return outputBuffer;
|
|
113
|
+
}
|
|
114
|
+
catch (error) {
|
|
115
|
+
throw error;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
};
|
|
119
|
+
exports.DocumentManipulatorService = DocumentManipulatorService;
|
|
120
|
+
exports.DocumentManipulatorService = DocumentManipulatorService = __decorate([
|
|
121
|
+
(0, common_1.Injectable)(),
|
|
122
|
+
__metadata("design:paramtypes", [minio_1.MinIOService])
|
|
123
|
+
], DocumentManipulatorService);
|
|
124
|
+
//# sourceMappingURL=document-manipulator.service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"document-manipulator.service.js","sourceRoot":"","sources":["../src/document-manipulator.service.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,2CAA4C;AAC5C,qCAAsC;AACtC,0CAA8D;AAC9D,qDAAqD;AACrD,mDAA8C;AAC9C,6CAA6C;AAC7C,+BAAiC;AACjC,sCAAsC;AACtC,iCAA0B;AAGnB,IAAM,0BAA0B,GAAhC,MAAM,0BAA0B;IACrC,YAA6B,YAA0B;QAA1B,iBAAY,GAAZ,YAAY,CAAc;IAAG,CAAC;IAE3D,KAAK,CAAC,QAAQ,CAAC,UAAoB;QACjC,IAAI,CAAC;YACH,MAAM,SAAS,GAAG,MAAM,qBAAW,CAAC,MAAM,EAAE,CAAC;YAC7C,KAAK,MAAM,SAAS,IAAI,UAAU,EAAE,CAAC;gBACnC,MA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;gBAChE,YAAY,EAAE,aAAa;aAC5B,CAAC,CAAC;YAEH,MAAM,YAAY,GAAG,OAAO,CAAC,IAAI,CAAC;YAClC,OAAO,YAAY,CAAC;QACtB,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,MAAM,KAAK,CAAC;QACd,CAAC;IACH,CAAC;CACF,CAAA;AAtJY,gEAA0B;qCAA1B,0BAA0B;IADtC,IAAA,mBAAU,GAAE;qCAEgC,oBAAY;GAD5C,0BAA0B,CAsJtC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { MinIOService } from '@zola_do/minio';
|
|
2
|
+
import { DocumentManipulatorService } from './document-manipulator.service';
|
|
3
|
+
export declare class FileHelperService {
|
|
4
|
+
private readonly minIOService;
|
|
5
|
+
private readonly documentManipulatorService;
|
|
6
|
+
constructor(minIOService: MinIOService, documentManipulatorService: DocumentManipulatorService);
|
|
7
|
+
convertAndUpload(file: Express.Multer.File, bucketName: string): Promise<{
|
|
8
|
+
filepath: string;
|
|
9
|
+
bucketName: string;
|
|
10
|
+
contentType: string;
|
|
11
|
+
originalname: string;
|
|
12
|
+
}>;
|
|
13
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
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
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.FileHelperService = void 0;
|
|
13
|
+
const common_1 = require("@nestjs/common");
|
|
14
|
+
const minio_1 = require("@zola_do/minio");
|
|
15
|
+
const document_manipulator_service_1 = require("./document-manipulator.service");
|
|
16
|
+
let FileHelperService = class FileHelperService {
|
|
17
|
+
constructor(minIOService, documentManipulatorService) {
|
|
18
|
+
this.minIOService = minIOService;
|
|
19
|
+
this.documentManipulatorService = documentManipulatorService;
|
|
20
|
+
}
|
|
21
|
+
async convertAndUpload(file, bucketName) {
|
|
22
|
+
try {
|
|
23
|
+
const buffer = await this.documentManipulatorService.convertDocxToPdf(file.buffer);
|
|
24
|
+
const fileType = file.originalname.split('.');
|
|
25
|
+
const fileName = fileType[0] + '.pdf';
|
|
26
|
+
const fileInfo = await this.minIOService.uploadBuffer(buffer, fileName, 'application/pdf', bucketName);
|
|
27
|
+
return fileInfo;
|
|
28
|
+
}
|
|
29
|
+
catch (error) {
|
|
30
|
+
throw error;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
exports.FileHelperService = FileHelperService;
|
|
35
|
+
exports.FileHelperService = FileHelperService = __decorate([
|
|
36
|
+
(0, common_1.Injectable)(),
|
|
37
|
+
__metadata("design:paramtypes", [minio_1.MinIOService,
|
|
38
|
+
document_manipulator_service_1.DocumentManipulatorService])
|
|
39
|
+
], FileHelperService);
|
|
40
|
+
//# sourceMappingURL=file-helper.service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"file-helper.service.js","sourceRoot":"","sources":["../src/file-helper.service.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,2CAA4C;AAC5C,0CAA8C;AAC9C,iFAA4E;AAGrE,IAAM,iBAAiB,GAAvB,MAAM,iBAAiB;IAC5B,YACmB,YAA0B,EAC1B,0BAAsD;QADtD,iBAAY,GAAZ,YAAY,CAAc;QAC1B,+BAA0B,GAA1B,0BAA0B,CAA4B;IACtE,CAAC;IAEJ,KAAK,CAAC,gBAAgB,CAAC,IAAyB,EAAE,UAAkB;QAClE,IAAI,CAAC;YACH,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,0BAA0B,CAAC,gBAAgB,CACnE,IAAI,CAAC,MAAM,CACZ,CAAC;YAEF,MAAM,QAAQ,GAAG,IAAI,CAAC,YAAY,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;YAE9C,MAAM,QAAQ,GAAG,QAAQ,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC;YAEtC,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,YAAY,CAAC,YAAY,CACnD,MAAM,EACN,QAAQ,EACR,iBAAiB,EACjB,UAAU,CACX,CAAC;YAGF,OAAO,QAAQ,CAAC;QAClB,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,MAAM,KAAK,CAAC;QACd,CAAC;IACH,CAAC;CACF,CAAA;AA7BY,8CAAiB;4BAAjB,iBAAiB;IAD7B,IAAA,mBAAU,GAAE;qCAGsB,oBAAY;QACE,yDAA0B;GAH9D,iBAAiB,CA6B7B"}
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./document-manipulator.module"), exports);
|
|
18
|
+
__exportStar(require("./document-manipulator.service"), exports);
|
|
19
|
+
__exportStar(require("./file-helper.service"), exports);
|
|
20
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,gEAA8C;AAC9C,iEAA+C;AAC/C,wDAAsC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@zola_do/document-manipulator",
|
|
3
|
+
"version": "0.1.9",
|
|
4
|
+
"description": "PDF/DOCX merge, conversion, template population for NestJS",
|
|
5
|
+
"author": "zolaDO",
|
|
6
|
+
"license": "ISC",
|
|
7
|
+
"publishConfig": {
|
|
8
|
+
"access": "public"
|
|
9
|
+
},
|
|
10
|
+
"main": "./dist/index.js",
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"exports": {
|
|
13
|
+
".": {
|
|
14
|
+
"types": "./dist/index.d.ts",
|
|
15
|
+
"default": "./dist/index.js"
|
|
16
|
+
}
|
|
17
|
+
},
|
|
18
|
+
"files": ["dist", "README.md"],
|
|
19
|
+
"scripts": {
|
|
20
|
+
"build": "rimraf dist && tsc",
|
|
21
|
+
"prepublishOnly": "npm run build"
|
|
22
|
+
},
|
|
23
|
+
"peerDependencies": {
|
|
24
|
+
"@nestjs/common": "^10.0.0 || ^11.0.0",
|
|
25
|
+
"reflect-metadata": "^0.1.0 || ^0.2.0",
|
|
26
|
+
"rxjs": "^7.0.0 || ^8.0.0"
|
|
27
|
+
},
|
|
28
|
+
"dependencies": {
|
|
29
|
+
"@zola_do/minio": "file:../minio",
|
|
30
|
+
"@scholarcy/docx-merger": "^0.3.0",
|
|
31
|
+
"axios": "^1.13.2",
|
|
32
|
+
"docx-templates": "^4.14.1",
|
|
33
|
+
"form-data": "^4.0.4",
|
|
34
|
+
"libreoffice-convert": "^1.7.0",
|
|
35
|
+
"pdf-lib": "^1.17.1"
|
|
36
|
+
},
|
|
37
|
+
"devDependencies": {
|
|
38
|
+
"rimraf": "^6.1.0",
|
|
39
|
+
"typescript": "^5.9.3"
|
|
40
|
+
}
|
|
41
|
+
}
|