drapcode-utility 2.4.3 → 2.4.5
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.
|
@@ -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
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
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
|
-
|
|
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
|
};
|
package/build/utils/util.d.ts
CHANGED
|
@@ -179,4 +179,5 @@ export declare const getTotalRecords: (connection: any, sqlQuery: string, sqlPar
|
|
|
179
179
|
* MySQL Helper to get last updated ID
|
|
180
180
|
*/
|
|
181
181
|
export declare const getLastUpdatedId: (connection: any, sqlParams: any[]) => Promise<number | null>;
|
|
182
|
+
export declare const masking: (subject: string | number, visibleCharCount?: number | string, maskPosition?: "START" | "END" | "MIDDLE", maskCharacter?: string) => string;
|
|
182
183
|
export {};
|
package/build/utils/util.js
CHANGED
|
@@ -4,7 +4,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.multiply = exports.average = exports.substraction = exports.addition = exports.validateNumbers = exports.checkAndConvertNumber = exports.evaluateCustomSentence = exports.strJoin = exports.markdownToHtml = exports.substr = exports.truncate = exports.titleCase = exports.trim = exports.slugify = exports.upperCase = exports.lowerCase = exports.capitalize = exports.replaceUnderscoreWithSlash = exports.replaceSlashWithUnderscore = exports.toggleConsoleLogs = exports.validateUrl = exports.validateData = exports.fillDefaultValues = exports.replaceValueFromSource = exports.processFieldsInclude = exports.removeMongoDbId = exports.replaceTransferObjectValueIntoExpression = exports.unflattenObject = exports.parseValueFromData = exports.parseJsonString = exports.replaceDataValueIntoExpression = exports.formatCustomCSSClasses = exports.validateAlphanumericString = exports.convertItemToArray = exports.arraysEqual = exports.checkAndCompareValue = exports.restructureData = exports.formatCollectionAndFieldName = exports.cleanCollectionAndFieldName = exports.getSpecialCharectorReplacedExpression = exports.validateUuidString = exports.validateEmail = exports.dynamicSort = exports.isObject = exports.isEmptyObject = exports.isEmpty = exports.clearSpaceAndReformat = exports.camelize = exports.validateString = exports.nonFindQuery = void 0;
|
|
7
|
-
exports.getLastUpdatedId = exports.getTotalRecords = exports.buildLimitOffsetClause = exports.buildOrderByClause = exports.buildWhereClause = exports.createMySqlConnection = exports.getAwsSignature = exports.replaceValuesFromRequestMapping = exports.replaceValuesFromObjArr = exports.checkFieldValueType = exports.getPrimaryFieldNameOfDataSource = exports.getFieldSchemaForDataSourcePrimaryId = exports.getMappingObjKey = exports.getItemDataForArrayFields = exports.getFileObjectList = exports.getFindQuery = exports.mergeObjects = exports.dateDifference = exports.formatDate = exports.evaluateJSLogic = exports.evaluateCurrency = exports.evaluateExpression = exports.divide = void 0;
|
|
7
|
+
exports.masking = exports.getLastUpdatedId = exports.getTotalRecords = exports.buildLimitOffsetClause = exports.buildOrderByClause = exports.buildWhereClause = exports.createMySqlConnection = exports.getAwsSignature = exports.replaceValuesFromRequestMapping = exports.replaceValuesFromObjArr = exports.checkFieldValueType = exports.getPrimaryFieldNameOfDataSource = exports.getFieldSchemaForDataSourcePrimaryId = exports.getMappingObjKey = exports.getItemDataForArrayFields = exports.getFileObjectList = exports.getFindQuery = exports.mergeObjects = exports.dateDifference = exports.formatDate = exports.evaluateJSLogic = exports.evaluateCurrency = exports.evaluateExpression = exports.divide = void 0;
|
|
8
8
|
const drapcode_constant_1 = require("drapcode-constant");
|
|
9
9
|
const lodash_1 = __importDefault(require("lodash"));
|
|
10
10
|
const showdown_1 = __importDefault(require("showdown"));
|
|
@@ -1286,3 +1286,32 @@ const getLastUpdatedId = async (connection, sqlParams) => {
|
|
|
1286
1286
|
return lastUpdatedIdRows[0]?.lastId ?? null;
|
|
1287
1287
|
};
|
|
1288
1288
|
exports.getLastUpdatedId = getLastUpdatedId;
|
|
1289
|
+
const masking = (subject, visibleCharCount = 2, maskPosition = "END", maskCharacter = "*") => {
|
|
1290
|
+
if (subject === null || subject === undefined)
|
|
1291
|
+
return "";
|
|
1292
|
+
if (subject === 0)
|
|
1293
|
+
return "0";
|
|
1294
|
+
const str = String(subject);
|
|
1295
|
+
const visibleCount = parseInt(visibleCharCount, 10);
|
|
1296
|
+
if (isNaN(visibleCount) || visibleCount <= 0)
|
|
1297
|
+
return str;
|
|
1298
|
+
const maskChar = maskCharacter || "*";
|
|
1299
|
+
const length = str.length;
|
|
1300
|
+
if (visibleCount >= length)
|
|
1301
|
+
return str;
|
|
1302
|
+
const maskedPart = maskChar.repeat(length - visibleCount);
|
|
1303
|
+
if (maskPosition === "START") {
|
|
1304
|
+
return str.slice(0, visibleCount) + maskedPart;
|
|
1305
|
+
}
|
|
1306
|
+
else if (maskPosition === "END") {
|
|
1307
|
+
return maskedPart + str.slice(-visibleCount);
|
|
1308
|
+
}
|
|
1309
|
+
else {
|
|
1310
|
+
const start = Math.floor((length - visibleCount) / 2);
|
|
1311
|
+
const end = start + visibleCount;
|
|
1312
|
+
return (str.slice(0, start) +
|
|
1313
|
+
maskChar.repeat(length - visibleCount) +
|
|
1314
|
+
str.slice(end));
|
|
1315
|
+
}
|
|
1316
|
+
};
|
|
1317
|
+
exports.masking = masking;
|