drapcode-utility 2.7.3 → 2.7.4-sandbox.1
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/build/aws/aws-util.d.ts +6 -0
- package/build/aws/aws-util.d.ts.map +1 -0
- package/build/aws/aws-util.js +34 -0
- package/build/aws/aws-util.js.map +1 -0
- package/build/aws/encryption/KMS.d.ts +9 -0
- package/build/aws/encryption/KMS.d.ts.map +1 -0
- package/build/aws/encryption/KMS.js +65 -0
- package/build/aws/encryption/KMS.js.map +1 -0
- package/build/{encryption → aws/encryption}/crypt.d.ts +1 -0
- package/build/aws/encryption/crypt.d.ts.map +1 -0
- package/build/{encryption → aws/encryption}/crypt.js +25 -36
- package/build/aws/encryption/crypt.js.map +1 -0
- package/build/{encryption → aws/encryption}/file.d.ts +2 -1
- package/build/aws/encryption/file.d.ts.map +1 -0
- package/build/{encryption → aws/encryption}/file.js +2 -3
- package/build/aws/encryption/file.js.map +1 -0
- package/build/{encryption → aws/encryption}/index.d.ts +4 -3
- package/build/aws/encryption/index.d.ts.map +1 -0
- package/build/{encryption → aws/encryption}/index.js +41 -41
- package/build/aws/encryption/index.js.map +1 -0
- package/build/{encryption → aws/encryption}/utility.d.ts +1 -0
- package/build/aws/encryption/utility.d.ts.map +1 -0
- package/build/{encryption → aws/encryption}/utility.js +3 -2
- package/build/aws/encryption/utility.js.map +1 -0
- package/build/aws/model.d.ts +30 -0
- package/build/aws/model.d.ts.map +1 -0
- package/build/{encryption → aws}/model.js +1 -0
- package/build/aws/model.js.map +1 -0
- package/build/aws/s3-util.d.ts +36 -0
- package/build/aws/s3-util.d.ts.map +1 -0
- package/build/aws/s3-util.js +198 -0
- package/build/aws/s3-util.js.map +1 -0
- package/build/errors/app-error.d.ts +17 -4
- package/build/errors/app-error.d.ts.map +1 -0
- package/build/errors/app-error.js +184 -6
- package/build/errors/app-error.js.map +1 -0
- package/build/errors/async-handler.d.ts +3 -0
- package/build/errors/async-handler.d.ts.map +1 -0
- package/build/errors/async-handler.js +9 -0
- package/build/errors/async-handler.js.map +1 -0
- package/build/errors/axios-error.d.ts +2 -1
- package/build/errors/axios-error.d.ts.map +1 -0
- package/build/errors/axios-error.js +12 -8
- package/build/errors/axios-error.js.map +1 -0
- package/build/errors/bad-request-error.d.ts +2 -1
- package/build/errors/bad-request-error.d.ts.map +1 -0
- package/build/errors/bad-request-error.js +1 -0
- package/build/errors/bad-request-error.js.map +1 -0
- package/build/errors/custom-error.d.ts +1 -0
- package/build/errors/custom-error.d.ts.map +1 -0
- package/build/errors/custom-error.js +1 -0
- package/build/errors/custom-error.js.map +1 -0
- package/build/errors/error-classes.d.ts +23 -0
- package/build/errors/error-classes.d.ts.map +1 -0
- package/build/errors/error-classes.js +87 -0
- package/build/errors/error-classes.js.map +1 -0
- package/build/errors/error-codes.d.ts +47 -0
- package/build/errors/error-codes.d.ts.map +1 -0
- package/build/errors/error-codes.js +78 -0
- package/build/errors/error-codes.js.map +1 -0
- package/build/errors/error-obj.d.ts +10 -0
- package/build/errors/error-obj.d.ts.map +1 -0
- package/build/errors/error-obj.js +55 -0
- package/build/errors/error-obj.js.map +1 -0
- package/build/errors/get-error-details.d.ts +11 -0
- package/build/errors/get-error-details.d.ts.map +1 -0
- package/build/errors/get-error-details.js +28 -0
- package/build/errors/get-error-details.js.map +1 -0
- package/build/errors/not-found.d.ts +2 -1
- package/build/errors/not-found.d.ts.map +1 -0
- package/build/errors/not-found.js +3 -2
- package/build/errors/not-found.js.map +1 -0
- package/build/errors/wrap-error.d.ts +9 -0
- package/build/errors/wrap-error.d.ts.map +1 -0
- package/build/errors/wrap-error.js +17 -0
- package/build/errors/wrap-error.js.map +1 -0
- package/build/format-fields/index.d.ts +1 -0
- package/build/format-fields/index.d.ts.map +1 -0
- package/build/format-fields/index.js +13 -13
- package/build/format-fields/index.js.map +1 -0
- package/build/index.d.ts +25 -21
- package/build/index.d.ts.map +1 -0
- package/build/index.js +13 -7
- package/build/index.js.map +1 -0
- package/build/middlewares/redis/request-log.d.ts +1 -0
- package/build/middlewares/redis/request-log.d.ts.map +1 -0
- package/build/middlewares/redis/request-log.js +3 -2
- package/build/middlewares/redis/request-log.js.map +1 -0
- package/build/query/queryBuilder.d.ts +1 -0
- package/build/query/queryBuilder.d.ts.map +1 -0
- package/build/query/queryBuilder.js +66 -129
- package/build/query/queryBuilder.js.map +1 -0
- package/build/utils/check-error.d.ts +1 -0
- package/build/utils/check-error.d.ts.map +1 -0
- package/build/utils/check-error.js +14 -15
- package/build/utils/check-error.js.map +1 -0
- package/build/utils/common-util.d.ts +2 -1
- package/build/utils/common-util.d.ts.map +1 -0
- package/build/utils/common-util.js +46 -47
- package/build/utils/common-util.js.map +1 -0
- package/build/utils/date-util.d.ts +1 -0
- package/build/utils/date-util.d.ts.map +1 -0
- package/build/utils/date-util.js +59 -60
- package/build/utils/date-util.js.map +1 -0
- package/build/utils/file-util.d.ts +9 -0
- package/build/utils/file-util.d.ts.map +1 -0
- package/build/utils/file-util.js +120 -9
- package/build/utils/file-util.js.map +1 -0
- package/build/utils/prepare-query.d.ts +1 -0
- package/build/utils/prepare-query.d.ts.map +1 -0
- package/build/utils/prepare-query.js +15 -17
- package/build/utils/prepare-query.js.map +1 -0
- package/build/utils/project-util.d.ts +2 -1
- package/build/utils/project-util.d.ts.map +1 -0
- package/build/utils/project-util.js +45 -50
- package/build/utils/project-util.js.map +1 -0
- package/build/utils/query-parser.d.ts +1 -1
- package/build/utils/query-parser.d.ts.map +1 -0
- package/build/utils/query-parser.js +6 -568
- package/build/utils/query-parser.js.map +1 -0
- package/build/utils/query-utils.d.ts +1 -0
- package/build/utils/query-utils.d.ts.map +1 -0
- package/build/utils/query-utils.js +46 -50
- package/build/utils/query-utils.js.map +1 -0
- package/build/utils/rest-client.d.ts +1 -0
- package/build/utils/rest-client.d.ts.map +1 -0
- package/build/utils/rest-client.js +88 -122
- package/build/utils/rest-client.js.map +1 -0
- package/build/utils/token.d.ts +1 -0
- package/build/utils/token.d.ts.map +1 -0
- package/build/utils/token.js +4 -3
- package/build/utils/token.js.map +1 -0
- package/build/utils/util.d.ts +2 -1
- package/build/utils/util.d.ts.map +1 -0
- package/build/utils/util.js +340 -392
- package/build/utils/util.js.map +1 -0
- package/build/utils/uuid-generator.d.ts +1 -0
- package/build/utils/uuid-generator.d.ts.map +1 -0
- package/build/utils/uuid-generator.js +9 -8
- package/build/utils/uuid-generator.js.map +1 -0
- package/package.json +7 -6
- package/build/encryption/KMS.d.ts +0 -8
- package/build/encryption/KMS.js +0 -67
- package/build/encryption/model.d.ts +0 -17
- package/build/middlewares/error-logger.d.ts +0 -3
- package/build/middlewares/error-logger.js +0 -74
- package/build/utils/s3-util.d.ts +0 -36
- package/build/utils/s3-util.js +0 -275
package/build/utils/s3-util.js
DELETED
|
@@ -1,275 +0,0 @@
|
|
|
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.processAndRemoveScriptFromSVG = exports.processAndRemoveExifDataFromImg = exports.fileUploadToS3 = exports.createS3Client = void 0;
|
|
7
|
-
const drapcode_constant_1 = require("drapcode-constant");
|
|
8
|
-
const client_s3_1 = require("@aws-sdk/client-s3");
|
|
9
|
-
const fs_1 = __importDefault(require("fs"));
|
|
10
|
-
const mime_types_1 = __importDefault(require("mime-types"));
|
|
11
|
-
const lib_storage_1 = require("@aws-sdk/lib-storage");
|
|
12
|
-
const encryption_1 = require("../encryption");
|
|
13
|
-
const uuid_1 = require("uuid");
|
|
14
|
-
const gm_1 = __importDefault(require("gm"));
|
|
15
|
-
const svgo_1 = require("svgo");
|
|
16
|
-
const promises_1 = __importDefault(require("fs/promises"));
|
|
17
|
-
const exiftool_vendored_1 = require("exiftool-vendored");
|
|
18
|
-
const exiftool = new exiftool_vendored_1.ExifTool({});
|
|
19
|
-
const createS3Client = (awsConfig) => {
|
|
20
|
-
if (!awsConfig) {
|
|
21
|
-
return null;
|
|
22
|
-
}
|
|
23
|
-
const { region, accessKey, accessSecret } = awsConfig;
|
|
24
|
-
const s3client = new client_s3_1.S3Client({
|
|
25
|
-
region,
|
|
26
|
-
credentials: {
|
|
27
|
-
accessKeyId: accessKey,
|
|
28
|
-
secretAccessKey: accessSecret,
|
|
29
|
-
},
|
|
30
|
-
});
|
|
31
|
-
return s3client;
|
|
32
|
-
};
|
|
33
|
-
exports.createS3Client = createS3Client;
|
|
34
|
-
const fileUploadToS3 = async (files, s3Client, s3Config, publicS3Client, publicS3Config, isGenerateIcons, encryption, options = {}, encrypted = false) => {
|
|
35
|
-
if (Array.isArray(files)) {
|
|
36
|
-
console.log("Multiple file");
|
|
37
|
-
const fileOptions = [];
|
|
38
|
-
const s3Key = s3Config.key;
|
|
39
|
-
for (const file of files) {
|
|
40
|
-
const fileSlug = slugifyFileName(file.originalname);
|
|
41
|
-
if (s3Config.append) {
|
|
42
|
-
s3Config.key = `${s3Key}/${(0, uuid_1.v4)()}/${fileSlug}`;
|
|
43
|
-
}
|
|
44
|
-
const fileObj = await processFileUploadToS3(file, s3Client, s3Config, publicS3Client, publicS3Config, isGenerateIcons, encryption, options, encrypted);
|
|
45
|
-
if (fileObj) {
|
|
46
|
-
fileOptions.push(fileObj);
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
return fileOptions;
|
|
50
|
-
}
|
|
51
|
-
else {
|
|
52
|
-
console.log("Single file");
|
|
53
|
-
const fileSlug = slugifyFileName(files.originalname);
|
|
54
|
-
if (s3Config.append) {
|
|
55
|
-
s3Config.key = `${s3Config.key}/${(0, uuid_1.v4)()}/${fileSlug}`;
|
|
56
|
-
}
|
|
57
|
-
console.log("encryption :>> ", encryption);
|
|
58
|
-
return await processFileUploadToS3(files, s3Client, s3Config, publicS3Client, publicS3Config, isGenerateIcons, encryption, options, encrypted);
|
|
59
|
-
}
|
|
60
|
-
};
|
|
61
|
-
exports.fileUploadToS3 = fileUploadToS3;
|
|
62
|
-
const processFileUploadToS3 = async (file, s3Client, s3Config, publicS3Client, publicS3Config, isGenerateIcons, encryption, options = {}, encrypt = false) => {
|
|
63
|
-
try {
|
|
64
|
-
console.log("encrypt :>> ", encrypt);
|
|
65
|
-
const contentType = mime_types_1.default.lookup(file.originalname) || "";
|
|
66
|
-
console.log("s3Config :>> ", s3Config);
|
|
67
|
-
const { acl, key, bucket } = s3Config;
|
|
68
|
-
let params = null;
|
|
69
|
-
let encryptedFilePath = null;
|
|
70
|
-
if (encrypt) {
|
|
71
|
-
encryptedFilePath = await (0, encryption_1.cryptFile)(file.path, encryption, false);
|
|
72
|
-
params = {
|
|
73
|
-
Bucket: bucket,
|
|
74
|
-
ACL: acl,
|
|
75
|
-
Key: key,
|
|
76
|
-
Body: fs_1.default.createReadStream(encryptedFilePath),
|
|
77
|
-
ContentType: contentType,
|
|
78
|
-
...options,
|
|
79
|
-
};
|
|
80
|
-
}
|
|
81
|
-
else {
|
|
82
|
-
params = {
|
|
83
|
-
Bucket: bucket,
|
|
84
|
-
ACL: acl,
|
|
85
|
-
Key: key,
|
|
86
|
-
Body: fs_1.default.createReadStream(file.path),
|
|
87
|
-
ContentType: contentType,
|
|
88
|
-
...options,
|
|
89
|
-
};
|
|
90
|
-
}
|
|
91
|
-
console.log("encryptedFilePath :>> ", encryptedFilePath);
|
|
92
|
-
console.log("params :>> ", params);
|
|
93
|
-
const parallelUploads3 = new lib_storage_1.Upload({ client: s3Client, params });
|
|
94
|
-
const data = await parallelUploads3.done();
|
|
95
|
-
const { smallIcon, mediumIcon, largeIcon } = await handleIconUpload(file, contentType, publicS3Client, publicS3Config, isGenerateIcons, key, options);
|
|
96
|
-
if (data) {
|
|
97
|
-
if (encryptedFilePath) {
|
|
98
|
-
fs_1.default.unlinkSync(encryptedFilePath);
|
|
99
|
-
}
|
|
100
|
-
fs_1.default.unlinkSync(file.path);
|
|
101
|
-
}
|
|
102
|
-
const { originalname, mimetype, size } = file;
|
|
103
|
-
return {
|
|
104
|
-
originalname,
|
|
105
|
-
mimetype,
|
|
106
|
-
size,
|
|
107
|
-
key: data.Key,
|
|
108
|
-
contentType,
|
|
109
|
-
smallIcon,
|
|
110
|
-
mediumIcon,
|
|
111
|
-
largeIcon,
|
|
112
|
-
};
|
|
113
|
-
}
|
|
114
|
-
catch (error) {
|
|
115
|
-
console.error("Error uploading file to S3:", error);
|
|
116
|
-
return null;
|
|
117
|
-
}
|
|
118
|
-
};
|
|
119
|
-
const imageTypeFiles = [...drapcode_constant_1.imageMimeTypes, "image/jpg"];
|
|
120
|
-
const processAndRemoveExifDataFromImg = async (files) => {
|
|
121
|
-
try {
|
|
122
|
-
files = Array.isArray(files) ? files : [files];
|
|
123
|
-
files = files.filter((file) => imageTypeFiles.includes(file.mimetype));
|
|
124
|
-
let promises = [];
|
|
125
|
-
if (files.length) {
|
|
126
|
-
promises = files.map(async (file) => {
|
|
127
|
-
// Remove EXIF data using exiftool
|
|
128
|
-
return await exiftool
|
|
129
|
-
.write(file.path, {}, { writeArgs: ["-all=", "-overwrite_original"] })
|
|
130
|
-
.catch((err) => {
|
|
131
|
-
console.error("Error processing image:", err);
|
|
132
|
-
throw err;
|
|
133
|
-
});
|
|
134
|
-
});
|
|
135
|
-
await Promise.all(promises);
|
|
136
|
-
}
|
|
137
|
-
return promises;
|
|
138
|
-
}
|
|
139
|
-
catch (error) {
|
|
140
|
-
console.error("\n error :>> ", error);
|
|
141
|
-
}
|
|
142
|
-
};
|
|
143
|
-
exports.processAndRemoveExifDataFromImg = processAndRemoveExifDataFromImg;
|
|
144
|
-
const processAndRemoveScriptFromSVG = async (files) => {
|
|
145
|
-
if (!files || !files.length) {
|
|
146
|
-
return;
|
|
147
|
-
}
|
|
148
|
-
try {
|
|
149
|
-
files = Array.isArray(files) ? files : [files];
|
|
150
|
-
files = files.filter((file) => file.mimetype === "image/svg+xml");
|
|
151
|
-
if (!files || !files.length) {
|
|
152
|
-
return;
|
|
153
|
-
}
|
|
154
|
-
let promises = files.map(async (file) => {
|
|
155
|
-
const fileContent = await promises_1.default.readFile(file.path, "utf-8");
|
|
156
|
-
const sanitizedContent = (0, svgo_1.optimize)(fileContent, {
|
|
157
|
-
plugins: [
|
|
158
|
-
"removeScriptElement", // Remove <script>,
|
|
159
|
-
"removeDesc",
|
|
160
|
-
"removeTitle",
|
|
161
|
-
"removeMetadata",
|
|
162
|
-
"removeComments",
|
|
163
|
-
"removeXMLProcInst",
|
|
164
|
-
"removeDoctype",
|
|
165
|
-
"cleanupAttrs",
|
|
166
|
-
{
|
|
167
|
-
name: "removeAttrs", // Plugin to remove event handlers (e.g., onclick)
|
|
168
|
-
params: {
|
|
169
|
-
attrs: "(on.*)", // Matches attributes starting with "on" (e.g., onclick, onmouseover)
|
|
170
|
-
},
|
|
171
|
-
},
|
|
172
|
-
{
|
|
173
|
-
name: "removeForeignObject", // Custom plugin to remove <foreignObject>
|
|
174
|
-
fn: (item) => {
|
|
175
|
-
if (item.name === "foreignObject") {
|
|
176
|
-
return null; // Remove this element
|
|
177
|
-
}
|
|
178
|
-
else
|
|
179
|
-
return item;
|
|
180
|
-
},
|
|
181
|
-
},
|
|
182
|
-
],
|
|
183
|
-
});
|
|
184
|
-
await promises_1.default.writeFile(file.path, sanitizedContent.data, "utf-8");
|
|
185
|
-
});
|
|
186
|
-
await Promise.all(promises);
|
|
187
|
-
}
|
|
188
|
-
catch (error) {
|
|
189
|
-
console.error("\n error :>> ", error);
|
|
190
|
-
}
|
|
191
|
-
};
|
|
192
|
-
exports.processAndRemoveScriptFromSVG = processAndRemoveScriptFromSVG;
|
|
193
|
-
const handleIconUpload = async (file, contentType, publicS3Client, publicS3Config, isGenerateIcons, key, options = {}) => {
|
|
194
|
-
const { path: filePath, size: fileSize } = file;
|
|
195
|
-
const iconSizes = [200, 300, 500];
|
|
196
|
-
const iconLabels = ["small", "medium", "large"];
|
|
197
|
-
try {
|
|
198
|
-
if (isGenerateIcons &&
|
|
199
|
-
fileSize < 157286400 && //150mb
|
|
200
|
-
[...drapcode_constant_1.imageMimeTypes, "application/pdf", "image/gif"].includes(contentType)) {
|
|
201
|
-
const iconFiles = await generateDynamicIcons(filePath, iconSizes, contentType);
|
|
202
|
-
const { bucket, acl } = publicS3Config;
|
|
203
|
-
const iconUploads = iconFiles.map(async (iconFilePath, index) => {
|
|
204
|
-
const iconLabel = iconLabels[index];
|
|
205
|
-
const iconKey = `${key}/icons/${(0, uuid_1.v4)()}_${iconLabel}.png`;
|
|
206
|
-
const iconParams = {
|
|
207
|
-
Bucket: bucket,
|
|
208
|
-
ACL: acl,
|
|
209
|
-
Key: iconKey,
|
|
210
|
-
Body: fs_1.default.createReadStream(iconFilePath),
|
|
211
|
-
ContentType: "image/png",
|
|
212
|
-
...options,
|
|
213
|
-
};
|
|
214
|
-
const iconUpload = new lib_storage_1.Upload({
|
|
215
|
-
client: publicS3Client,
|
|
216
|
-
params: iconParams,
|
|
217
|
-
});
|
|
218
|
-
const iconData = await iconUpload.done();
|
|
219
|
-
fs_1.default.unlinkSync(iconFilePath);
|
|
220
|
-
return iconData.Key;
|
|
221
|
-
});
|
|
222
|
-
const [smallKey, mediumKey, largeKey] = await Promise.all(iconUploads);
|
|
223
|
-
return {
|
|
224
|
-
smallIcon: generateS3IconUrl(bucket, smallKey),
|
|
225
|
-
mediumIcon: generateS3IconUrl(bucket, mediumKey),
|
|
226
|
-
largeIcon: generateS3IconUrl(bucket, largeKey),
|
|
227
|
-
};
|
|
228
|
-
}
|
|
229
|
-
else {
|
|
230
|
-
return generateStaticIcons(contentType);
|
|
231
|
-
}
|
|
232
|
-
}
|
|
233
|
-
catch (iconError) {
|
|
234
|
-
console.error("Error generating or uploading icons:", iconError);
|
|
235
|
-
return generateStaticIcons(contentType);
|
|
236
|
-
}
|
|
237
|
-
};
|
|
238
|
-
const generateS3IconUrl = (bucket, key) => {
|
|
239
|
-
if (!key)
|
|
240
|
-
return null;
|
|
241
|
-
return `https://${bucket}.s3.amazonaws.com/${key}`;
|
|
242
|
-
};
|
|
243
|
-
const generateDynamicIcons = (filePath, sizes, contentType) => {
|
|
244
|
-
return Promise.all(sizes.map((size) => {
|
|
245
|
-
const outputFilePath = `${filePath}_${size}.png`;
|
|
246
|
-
return new Promise((resolve, reject) => {
|
|
247
|
-
let gmInstance = (0, gm_1.default)(filePath);
|
|
248
|
-
if (contentType === "application/pdf") {
|
|
249
|
-
gmInstance = gmInstance.selectFrame(0);
|
|
250
|
-
}
|
|
251
|
-
gmInstance.resize(size, size).write(outputFilePath, (err) => {
|
|
252
|
-
if (err) {
|
|
253
|
-
reject(err);
|
|
254
|
-
}
|
|
255
|
-
else {
|
|
256
|
-
resolve(outputFilePath);
|
|
257
|
-
}
|
|
258
|
-
});
|
|
259
|
-
});
|
|
260
|
-
}));
|
|
261
|
-
};
|
|
262
|
-
const generateStaticIcons = (type) => {
|
|
263
|
-
const icon = drapcode_constant_1.iconMaps[type] || drapcode_constant_1.defaultIcon;
|
|
264
|
-
return {
|
|
265
|
-
smallIcon: icon,
|
|
266
|
-
mediumIcon: icon,
|
|
267
|
-
largeIcon: icon,
|
|
268
|
-
};
|
|
269
|
-
};
|
|
270
|
-
const slugifyFileName = (fileName) => {
|
|
271
|
-
return fileName
|
|
272
|
-
.replace(/\s+/g, "_") // Replace spaces with underscores
|
|
273
|
-
.replace(/[^a-zA-Z0-9._]/g, "") // Remove anything that's not a letter, number, dot, or underscore
|
|
274
|
-
.toLowerCase(); // Convert to lowercase
|
|
275
|
-
};
|