@ottoai/documents 1.0.18 → 1.0.19
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/create/index.d.ts +2 -1
- package/dist/create/index.js +3 -1
- package/dist/create/index.js.map +1 -1
- package/dist/create/zip/index.d.ts +2 -0
- package/dist/create/zip/index.js +29 -0
- package/dist/create/zip/index.js.map +1 -0
- package/dist/create/zip/util/index.d.ts +11 -0
- package/dist/create/zip/util/index.js +116 -0
- package/dist/create/zip/util/index.js.map +1 -0
- package/dist/create/zip/util/parser.d.ts +4 -0
- package/dist/create/zip/util/parser.js +29 -0
- package/dist/create/zip/util/parser.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +23 -2
package/dist/create/index.d.ts
CHANGED
package/dist/create/index.js
CHANGED
|
@@ -23,7 +23,9 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
23
23
|
return result;
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.pdf = void 0;
|
|
26
|
+
exports.zip = exports.pdf = void 0;
|
|
27
27
|
const pdf = __importStar(require("./pdf"));
|
|
28
28
|
exports.pdf = pdf;
|
|
29
|
+
const zip = __importStar(require("./zip"));
|
|
30
|
+
exports.zip = zip;
|
|
29
31
|
//# sourceMappingURL=index.js.map
|
package/dist/create/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/create/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,2CAA6B;AAMpB,kBAAG"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/create/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,2CAA6B;AAMpB,kBAAG;AALZ,2CAA6B;AAKf,kBAAG"}
|
|
@@ -0,0 +1,29 @@
|
|
|
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
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.util = void 0;
|
|
27
|
+
const util = __importStar(require("./util"));
|
|
28
|
+
exports.util = util;
|
|
29
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/create/zip/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,6CAA+B;AAKtB,oBAAI"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import * as parser from "./parser";
|
|
2
|
+
interface BundleFile {
|
|
3
|
+
data: Buffer;
|
|
4
|
+
filename: string;
|
|
5
|
+
}
|
|
6
|
+
export declare const getFileFromZip: (buf: Buffer, filenames: string[], password?: string) => BundleFile[];
|
|
7
|
+
export declare const getAllFilesFromZip: (buf: Buffer, password?: string) => BundleFile[];
|
|
8
|
+
export declare const generatePassword: (pepper: string, salt: string) => string;
|
|
9
|
+
export declare const getFileChecksum: (bundle: Buffer) => string;
|
|
10
|
+
export declare const generateZipFile: (files: BundleFile[], password?: string) => Promise<Buffer>;
|
|
11
|
+
export { parser };
|
|
@@ -0,0 +1,116 @@
|
|
|
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
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
+
};
|
|
28
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
+
exports.parser = exports.generateZipFile = exports.getFileChecksum = exports.generatePassword = exports.getAllFilesFromZip = exports.getFileFromZip = void 0;
|
|
30
|
+
const crypto_1 = require("crypto");
|
|
31
|
+
const Minizip = require("minizip-asm.js");
|
|
32
|
+
const archiver_zip_encrypted_1 = __importDefault(require("archiver-zip-encrypted"));
|
|
33
|
+
const archiver_1 = __importDefault(require("archiver"));
|
|
34
|
+
const parser = __importStar(require("./parser"));
|
|
35
|
+
exports.parser = parser;
|
|
36
|
+
const buffer_1 = require("../../pdf/util/buffer");
|
|
37
|
+
const encryptedZipFormat = "zip-encrypted";
|
|
38
|
+
const ENCRYPTION_METHOD = "aes256";
|
|
39
|
+
archiver_1.default.registerFormat(encryptedZipFormat, archiver_zip_encrypted_1.default);
|
|
40
|
+
const getFileFromZip = (buf, filenames, password) => {
|
|
41
|
+
try {
|
|
42
|
+
const mz = new Minizip(buf);
|
|
43
|
+
return filenames.map((name) => ({
|
|
44
|
+
data: (0, buffer_1.toBuffer)(mz.extract(parser.stringToBuffer(name), { password })),
|
|
45
|
+
filename: name.toString(),
|
|
46
|
+
}));
|
|
47
|
+
}
|
|
48
|
+
catch (error) {
|
|
49
|
+
throw new Error(`Extracting zip ${error}`);
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
exports.getFileFromZip = getFileFromZip;
|
|
53
|
+
const getAllFilesFromZip = (buf, password) => {
|
|
54
|
+
const mz = new Minizip(buf);
|
|
55
|
+
const fileList = mz.list();
|
|
56
|
+
return fileList.map(({ filepath }) => ({
|
|
57
|
+
data: (0, buffer_1.toBuffer)(mz.extract(parser.stringToBuffer(filepath), { password })),
|
|
58
|
+
filename: filepath,
|
|
59
|
+
}));
|
|
60
|
+
};
|
|
61
|
+
exports.getAllFilesFromZip = getAllFilesFromZip;
|
|
62
|
+
const generatePassword = (pepper, salt) => {
|
|
63
|
+
try {
|
|
64
|
+
return (0, crypto_1.createHash)("sha256")
|
|
65
|
+
.update(`${pepper}${salt}`)
|
|
66
|
+
.digest()
|
|
67
|
+
.toString("base64")
|
|
68
|
+
.slice(0, 10);
|
|
69
|
+
}
|
|
70
|
+
catch (error) {
|
|
71
|
+
throw new Error(`Password error: ${error}`);
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
exports.generatePassword = generatePassword;
|
|
75
|
+
const getFileChecksum = (bundle) => {
|
|
76
|
+
try {
|
|
77
|
+
return (0, crypto_1.createHash)("sha256").update(bundle).digest("hex");
|
|
78
|
+
}
|
|
79
|
+
catch (error) {
|
|
80
|
+
throw new Error(`File checksum: ${error}`);
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
exports.getFileChecksum = getFileChecksum;
|
|
84
|
+
const generateZipFile = async (files, password) => {
|
|
85
|
+
try {
|
|
86
|
+
let options = {
|
|
87
|
+
zlib: { level: 8 },
|
|
88
|
+
readableObjectMode: true,
|
|
89
|
+
};
|
|
90
|
+
let zipFormat = "zip";
|
|
91
|
+
if (password) {
|
|
92
|
+
zipFormat = encryptedZipFormat;
|
|
93
|
+
options = {
|
|
94
|
+
encryptionMethod: ENCRYPTION_METHOD,
|
|
95
|
+
password,
|
|
96
|
+
...options,
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
return new Promise((resolve, reject) => {
|
|
100
|
+
const bufs = [];
|
|
101
|
+
const archive = archiver_1.default.create(zipFormat, options);
|
|
102
|
+
archive.on("error", (error) => reject(error));
|
|
103
|
+
archive.on("finish", () => resolve(Buffer.concat(bufs)));
|
|
104
|
+
archive.on("data", (data) => {
|
|
105
|
+
bufs.push(data);
|
|
106
|
+
});
|
|
107
|
+
files.forEach((file) => archive.append(file.data, { name: `${file.filename}` }));
|
|
108
|
+
archive.finalize();
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
catch (error) {
|
|
112
|
+
throw new Error(`Compressing zip ${error}`);
|
|
113
|
+
}
|
|
114
|
+
};
|
|
115
|
+
exports.generateZipFile = generateZipFile;
|
|
116
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/create/zip/util/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,mCAAoC;AACpC,0CAA2C;AAC3C,oFAAuD;AACvD,wDAA6D;AAE7D,iDAAmC;AAkG1B,wBAAM;AAjGf,kDAAiD;AAEjD,MAAM,kBAAkB,GAAG,eAAe,CAAC;AAC3C,MAAM,iBAAiB,GAAG,QAAQ,CAAC;AAEnC,kBAAQ,CAAC,cAAc,CAAC,kBAAkB,EAAE,gCAAiB,CAAC,CAAC;AAOxD,MAAM,cAAc,GAAG,CAC5B,GAAW,EACX,SAAmB,EACnB,QAAiB,EACH,EAAE;IAChB,IAAI,CAAC;QAEH,MAAM,EAAE,GAAG,IAAI,OAAO,CAAC,GAAG,CAAC,CAAC;QAC5B,OAAO,SAAS,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;YAC9B,IAAI,EAAE,IAAA,iBAAQ,EAAC,EAAE,CAAC,OAAO,CAAC,MAAM,CAAC,cAAc,CAAC,IAAI,CAAC,EAAE,EAAE,QAAQ,EAAE,CAAC,CAAC;YACrE,QAAQ,EAAE,IAAI,CAAC,QAAQ,EAAE;SAC1B,CAAC,CAAC,CAAC;IACN,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,IAAI,KAAK,CAAC,kBAAkB,KAAK,EAAE,CAAC,CAAC;IAC7C,CAAC;AACH,CAAC,CAAC;AAfW,QAAA,cAAc,kBAezB;AAEK,MAAM,kBAAkB,GAAG,CAChC,GAAW,EACX,QAAiB,EACH,EAAE;IAChB,MAAM,EAAE,GAAG,IAAI,OAAO,CAAC,GAAG,CAAC,CAAC;IAC5B,MAAM,QAAQ,GAAG,EAAE,CAAC,IAAI,EAAE,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}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.bufferToStream = exports.streamToBuffer = exports.stringToBuffer = void 0;
|
|
4
|
+
const stream_1 = require("stream");
|
|
5
|
+
const stringToBuffer = (str) => {
|
|
6
|
+
return Buffer.from(str);
|
|
7
|
+
};
|
|
8
|
+
exports.stringToBuffer = stringToBuffer;
|
|
9
|
+
const streamToBuffer = (streamData) => {
|
|
10
|
+
return new Promise((resolve, reject) => {
|
|
11
|
+
const contentBuffer = [];
|
|
12
|
+
let buf;
|
|
13
|
+
streamData.on('data', data => contentBuffer.push(data));
|
|
14
|
+
streamData.on('error', error => reject(error));
|
|
15
|
+
streamData.on('end', () => {
|
|
16
|
+
buf = Buffer.concat(contentBuffer);
|
|
17
|
+
resolve(buf);
|
|
18
|
+
});
|
|
19
|
+
});
|
|
20
|
+
};
|
|
21
|
+
exports.streamToBuffer = streamToBuffer;
|
|
22
|
+
const bufferToStream = (buf) => {
|
|
23
|
+
const stream = new stream_1.Duplex();
|
|
24
|
+
stream.push(buf);
|
|
25
|
+
stream.push(null);
|
|
26
|
+
return stream;
|
|
27
|
+
};
|
|
28
|
+
exports.bufferToStream = bufferToStream;
|
|
29
|
+
//# sourceMappingURL=parser.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parser.js","sourceRoot":"","sources":["../../../../src/create/zip/util/parser.ts"],"names":[],"mappings":";;;AAAA,mCAAkD;AAE3C,MAAM,cAAc,GAAG,CAAC,GAAW,EAAU,EAAE;IACpD,OAAO,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAC1B,CAAC,CAAC;AAFW,QAAA,cAAc,kBAEzB;AAEK,MAAM,cAAc,GAAG,CAAC,UAAkB,EAAmB,EAAE;IACpE,OAAO,IAAI,OAAO,CAAS,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QAC7C,MAAM,aAAa,GAAiB,EAAE,CAAC;QACvC,IAAI,GAAW,CAAC;QAChB,UAAU,CAAC,EAAE,CAAC,MAAM,EAAE,IAAI,CAAC,EAAE,CAAC,aAAa,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;QACxD,UAAU,CAAC,EAAE,CAAC,OAAO,EAAE,KAAK,CAAC,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;QAC/C,UAAU,CAAC,EAAE,CAAC,KAAK,EAAE,GAAG,EAAE;YACxB,GAAG,GAAG,MAAM,CAAC,MAAM,CAAC,aAAa,CAAC,CAAC;YACnC,OAAO,CAAC,GAAG,CAAC,CAAC;QACf,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC;AAXW,QAAA,cAAc,kBAWzB;AAEK,MAAM,cAAc,GAAG,CAAC,GAAW,EAAY,EAAE;IACtD,MAAM,MAAM,GAAG,IAAI,eAAM,EAAE,CAAC;IAC5B,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IACjB,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAClB,OAAO,MAAM,CAAC;AAChB,CAAC,CAAC;AALW,QAAA,cAAc,kBAKzB"}
|