drapcode-utility 2.4.4 → 2.4.6-preview

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.
@@ -132,7 +132,6 @@ const drapcodeEncryptDecrypt = async (data, encrypt) => {
132
132
  };
133
133
  exports.drapcodeEncryptDecrypt = drapcodeEncryptDecrypt;
134
134
  const cryptFile = async (filePath, encryption, decrypt) => {
135
- console.log("encryption cryptFile:>> ", encryption);
136
135
  const data = await (0, file_1.processFileEncryptionDecryption)(filePath, encryption, decrypt);
137
136
  return data;
138
137
  };
@@ -1,9 +1,10 @@
1
+ interface ExtraFieldSetting {
2
+ dateDisplayType?: string;
3
+ }
1
4
  interface DateField {
2
5
  fieldName: string;
3
6
  type: string;
4
- extraFieldSetting?: {
5
- dateDisplayType?: string;
6
- };
7
+ extraFieldSetting?: Map<string, ExtraFieldSetting>;
7
8
  }
8
9
  interface DateRangeValue {
9
10
  [key: string]: {
@@ -5,6 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.formatProjectDates = exports.timezoneDateParse = exports.nextDayDate = exports.getDateRangeValue = exports.getDateValue = exports.createLogsDateFormat = exports.createLoggerPreviousDateFormat = exports.createLoggerDateFormat = exports.DATE_REGEX = void 0;
7
7
  const drapcode_constant_1 = require("drapcode-constant");
8
+ const lodash_1 = __importDefault(require("lodash"));
8
9
  const moment_1 = __importDefault(require("moment"));
9
10
  const dateFormat = "YYYY-MM-DDTHH:mm:ss.SSS";
10
11
  exports.DATE_REGEX = /^[12]\d{3}(-(0[1-9]|1[0-2])(-(0[1-9]|[12][0-9]|3[01]))?)(T| )?(([01][0-9]|2[0-3]):[0-5]\d(:[0-5]\d(\.\d+)?)?(Z|[+-]\d{2}:\d{2})?)?$/;
@@ -192,7 +193,17 @@ const formatItemDates = (item, fields, dateFormat, reverse) => {
192
193
  Object.keys(item).forEach((fieldName) => {
193
194
  const field = fields.find((field) => field.fieldName === fieldName);
194
195
  if (field?.type === "date") {
195
- if (field?.extraFieldSetting?.dateDisplayType === "datetime-local") {
196
+ let dateDisplayType = "";
197
+ if (field?.extraFieldSetting) {
198
+ const extraFieldSetting = field?.extraFieldSetting;
199
+ if (lodash_1.default.isPlainObject(extraFieldSetting)) {
200
+ dateDisplayType = extraFieldSetting?.dateDisplayType;
201
+ }
202
+ else if (extraFieldSetting instanceof Map) {
203
+ dateDisplayType = extraFieldSetting?.get("dateDisplayType") || "";
204
+ }
205
+ }
206
+ if (dateDisplayType === "datetime-local") {
196
207
  item[fieldName] = (0, moment_1.default)(item[fieldName], dateTimeFormat).isValid()
197
208
  ? item[fieldName]
198
209
  : "";
@@ -3,4 +3,11 @@ export declare const callCurlRequest: (setting: any, user?: any, tenant?: any, u
3
3
  status: number;
4
4
  success: boolean;
5
5
  headers: {};
6
+ mysqlError: {};
7
+ } | {
8
+ data: any;
9
+ status: number;
10
+ success: boolean;
11
+ headers: {};
12
+ mysqlError?: undefined;
6
13
  }>;
@@ -146,6 +146,13 @@ const callCurlRequest = async (setting, user = {}, tenant = {}, userSetting = {}
146
146
  const { setting: extDbSetting } = dtoExternalDb;
147
147
  data["searchQuery"] = dtoSearchString;
148
148
  result = await makeMySqlCall(projectId, data, extDbSetting);
149
+ if (!result) {
150
+ const errorMessage = "No Response from MySQL Server";
151
+ return prepareReturnObject(errorMessage);
152
+ }
153
+ drapcode_logger_1.logger.info(`MySQL result.status: ${result?.status}`, { label: projectId });
154
+ deleteLocalFiles(isMultipart, toDeleteFiles);
155
+ return prepareReturnObject(result.data, result.status, result?.success || (result.status >= 200 && result.status < 300), result?.headers, result?.mysqlError);
149
156
  }
150
157
  else {
151
158
  result = await makeAxiosCall(projectId, methodType, url, headerValue, data, timeout, wrapJsonDataInArray, awsSignPluginConfig);
@@ -208,13 +215,24 @@ const deleteLocalFiles = (isMultipart, toDeleteFiles) => {
208
215
  });
209
216
  }
210
217
  };
211
- const prepareReturnObject = (data, status = 400, success = false, headers = {}) => {
212
- return {
213
- data,
214
- status,
215
- success,
216
- headers,
217
- };
218
+ const prepareReturnObject = (data, status = 400, success = false, headers = {}, mysqlError = {}) => {
219
+ if (mysqlError && Object.keys(mysqlError).length > 0) {
220
+ return {
221
+ data,
222
+ status,
223
+ success,
224
+ headers,
225
+ mysqlError
226
+ };
227
+ }
228
+ else {
229
+ return {
230
+ data,
231
+ status,
232
+ success,
233
+ headers
234
+ };
235
+ }
218
236
  };
219
237
  const makeAxiosCall = async (projectId, methodType, url, axiosConfig, data, timeout, wrapJsonDataInArray, awsSignPluginConfig) => {
220
238
  axiosConfig = { url, method: methodType, ...axiosConfig };
@@ -334,6 +352,7 @@ const makeMySqlCall = async (projectId, data, extDbSetting) => {
334
352
  totalRecords: total,
335
353
  lastInsertedId: insertedId,
336
354
  lastUpdatedId: updatedId,
355
+ lastModifiedId: insertedId || updatedId,
337
356
  returned: Array.isArray(rows) ? rows.length : 0
338
357
  },
339
358
  totalRecords: total,
@@ -342,7 +361,12 @@ const makeMySqlCall = async (projectId, data, extDbSetting) => {
342
361
  }
343
362
  catch (err) {
344
363
  console.error(`==> MySQL projectID: ${projectId} ~ err:`, err);
345
- return { status: 500, error: err };
364
+ result = {
365
+ status: 500,
366
+ success: false,
367
+ mysqlError: err
368
+ };
369
+ return result;
346
370
  }
347
371
  finally {
348
372
  await connection.end();
@@ -352,6 +376,6 @@ const makeMySqlCall = async (projectId, data, extDbSetting) => {
352
376
  }
353
377
  catch (error) {
354
378
  console.error(`==> MySQL projectID: ${projectId} ~ error:`, error);
355
- return { status: 500, error };
379
+ return { status: 500, success: false, data: {}, mysqlError: error };
356
380
  }
357
381
  };
@@ -33,7 +33,6 @@ const createS3Client = (awsConfig) => {
33
33
  exports.createS3Client = createS3Client;
34
34
  const fileUploadToS3 = async (files, s3Client, s3Config, publicS3Client, publicS3Config, isGenerateIcons, encryption, options = {}, encrypted = false) => {
35
35
  if (Array.isArray(files)) {
36
- console.log("Multiple file");
37
36
  const fileOptions = [];
38
37
  const s3Key = s3Config.key;
39
38
  for (const file of files) {
@@ -49,21 +48,17 @@ const fileUploadToS3 = async (files, s3Client, s3Config, publicS3Client, publicS
49
48
  return fileOptions;
50
49
  }
51
50
  else {
52
- console.log("Single file");
53
51
  const fileSlug = slugifyFileName(files.originalname);
54
52
  if (s3Config.append) {
55
53
  s3Config.key = `${s3Config.key}/${(0, uuid_1.v4)()}/${fileSlug}`;
56
54
  }
57
- console.log("encryption :>> ", encryption);
58
55
  return await processFileUploadToS3(files, s3Client, s3Config, publicS3Client, publicS3Config, isGenerateIcons, encryption, options, encrypted);
59
56
  }
60
57
  };
61
58
  exports.fileUploadToS3 = fileUploadToS3;
62
59
  const processFileUploadToS3 = async (file, s3Client, s3Config, publicS3Client, publicS3Config, isGenerateIcons, encryption, options = {}, encrypt = false) => {
63
60
  try {
64
- console.log("encrypt :>> ", encrypt);
65
61
  const contentType = mime_types_1.default.lookup(file.originalname) || "";
66
- console.log("s3Config :>> ", s3Config);
67
62
  const { acl, key, bucket } = s3Config;
68
63
  let params = null;
69
64
  let encryptedFilePath = null;
@@ -88,8 +83,6 @@ const processFileUploadToS3 = async (file, s3Client, s3Config, publicS3Client, p
88
83
  ...options,
89
84
  };
90
85
  }
91
- console.log("encryptedFilePath :>> ", encryptedFilePath);
92
- console.log("params :>> ", params);
93
86
  const parallelUploads3 = new lib_storage_1.Upload({ client: s3Client, params });
94
87
  const data = await parallelUploads3.done();
95
88
  const { smallIcon, mediumIcon, largeIcon } = await handleIconUpload(file, contentType, publicS3Client, publicS3Config, isGenerateIcons, key, options);
@@ -299,7 +299,6 @@ const replaceDataValueIntoExpression = (expression, data, user, tenant, userSett
299
299
  const contentList = expression
300
300
  .match(/{{(.*?)}}/g)
301
301
  ?.map((b) => b.replace(/{{(.*?)}}/g, "$1"));
302
- console.log("1 replaceDataValueIntoExpression");
303
302
  contentList?.forEach((prop) => {
304
303
  const needle = `{{${prop}}}`;
305
304
  let dataOfItem = "";
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "drapcode-utility",
3
- "version": "2.4.4",
4
- "description": "DrapCode Utility",
3
+ "version": "2.4.6-preview",
4
+ "description": "",
5
5
  "main": "build/index.js",
6
6
  "types": "build/index.d.ts",
7
7
  "files": [
@@ -42,9 +42,9 @@
42
42
  "axios": "^1.1.2",
43
43
  "date-fns": "^4.1.0",
44
44
  "dompurify": "^3.1.7",
45
- "drapcode-constant": "^2.0.0",
45
+ "drapcode-constant": "^1.8.0",
46
46
  "drapcode-logger": "^1.3.5",
47
- "drapcode-redis": "^1.4.7",
47
+ "drapcode-redis": "^1.3.5",
48
48
  "exiftool-vendored": "^28.2.1",
49
49
  "express": "^4.17.1",
50
50
  "gm": "^1.25.0",