@punks/backend-core 0.0.73 → 0.0.75
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/cjs/index.js +66 -6
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/types/logging/utils.d.ts +1 -1
- package/dist/cjs/types/utils/connection/index.d.ts +15 -0
- package/dist/cjs/types/utils/index.d.ts +2 -0
- package/dist/cjs/types/utils/variables/index.d.ts +1 -0
- package/dist/cjs/types/utils/xls.d.ts +1 -1
- package/dist/esm/index.js +65 -7
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/types/logging/utils.d.ts +1 -1
- package/dist/esm/types/utils/connection/index.d.ts +15 -0
- package/dist/esm/types/utils/index.d.ts +2 -0
- package/dist/esm/types/utils/variables/index.d.ts +1 -0
- package/dist/esm/types/utils/xls.d.ts +1 -1
- package/dist/index.d.ts +20 -2
- package/package.json +1 -1
package/dist/cjs/index.js
CHANGED
|
@@ -154,6 +154,53 @@ const subArrays = (array1, array2, eqFn) => {
|
|
|
154
154
|
return array1.filter((a1) => !array2.some((a2) => eqFn(a1, a2)));
|
|
155
155
|
};
|
|
156
156
|
|
|
157
|
+
const testConnection = async (url) => {
|
|
158
|
+
try {
|
|
159
|
+
const controller = new AbortController();
|
|
160
|
+
const timeoutId = setTimeout(() => controller.abort(), 30 * 1000);
|
|
161
|
+
const response = await fetch(url, { signal: controller.signal });
|
|
162
|
+
clearTimeout(timeoutId);
|
|
163
|
+
if (response.ok) {
|
|
164
|
+
return {
|
|
165
|
+
status: "success",
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
else {
|
|
169
|
+
return {
|
|
170
|
+
status: "error",
|
|
171
|
+
message: `HTTP error: ${response.status}`,
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
catch (e) {
|
|
176
|
+
return {
|
|
177
|
+
status: "error",
|
|
178
|
+
message: e.name === "AbortError" ? "Request timed out" : e.message,
|
|
179
|
+
};
|
|
180
|
+
}
|
|
181
|
+
};
|
|
182
|
+
const DEFAULT_HEALTH_CHECK_URLS = [
|
|
183
|
+
"https://www.google.com",
|
|
184
|
+
"https://www.cloudflare.com",
|
|
185
|
+
"https://www.microsoft.com",
|
|
186
|
+
];
|
|
187
|
+
const testInternetConnection = async (options) => {
|
|
188
|
+
const websitesToCheck = options?.healthCheckUrls ?? DEFAULT_HEALTH_CHECK_URLS;
|
|
189
|
+
const results = await Promise.all(websitesToCheck.map(testConnection));
|
|
190
|
+
const allSuccess = results.every((result) => result.status === "success");
|
|
191
|
+
if (allSuccess) {
|
|
192
|
+
return {
|
|
193
|
+
status: "success",
|
|
194
|
+
};
|
|
195
|
+
}
|
|
196
|
+
else {
|
|
197
|
+
return {
|
|
198
|
+
status: "error",
|
|
199
|
+
details: results,
|
|
200
|
+
};
|
|
201
|
+
}
|
|
202
|
+
};
|
|
203
|
+
|
|
157
204
|
const addTime = (date, offset) => {
|
|
158
205
|
const { value, unit } = offset;
|
|
159
206
|
const newDate = new Date(date);
|
|
@@ -393,6 +440,12 @@ const jsonSerialize = (obj, options) => {
|
|
|
393
440
|
return JSON.stringify(obj, replacer, spaces);
|
|
394
441
|
};
|
|
395
442
|
|
|
443
|
+
const maskVariable = (value, unmaskedLength = 4) => value
|
|
444
|
+
? value.substring(0, unmaskedLength).concat(Array.from(value.substring(unmaskedLength))
|
|
445
|
+
.map(() => "*")
|
|
446
|
+
.join(""))
|
|
447
|
+
: "";
|
|
448
|
+
|
|
396
449
|
const pluralize = (word) => {
|
|
397
450
|
return word.endsWith("s") ? `${word}es` : `${word}s`;
|
|
398
451
|
};
|
|
@@ -30946,12 +30999,17 @@ const aggregateRow = (header, row, options) => {
|
|
|
30946
30999
|
return record;
|
|
30947
31000
|
};
|
|
30948
31001
|
const excelParse = (file, options) => {
|
|
30949
|
-
const sheets = parseExcelRaw(file);
|
|
30950
|
-
|
|
30951
|
-
|
|
30952
|
-
|
|
30953
|
-
|
|
30954
|
-
|
|
31002
|
+
const sheets = parseExcelRaw(file).map((x) => parseSheet(x, options));
|
|
31003
|
+
return sheets.length === 1
|
|
31004
|
+
? sheets[0]
|
|
31005
|
+
: sheets.reduce((acc, sheet, index) => {
|
|
31006
|
+
acc[sheet.name || `Sheet${index + 1}`] = sheets[index];
|
|
31007
|
+
return acc;
|
|
31008
|
+
}, {});
|
|
31009
|
+
};
|
|
31010
|
+
const parseSheet = (sheet, options) => {
|
|
31011
|
+
const [header, ...lines] = sheet.data.filter((x) => isValidRow(x));
|
|
31012
|
+
return lines.map((x) => aggregateRow(header, x, options));
|
|
30955
31013
|
};
|
|
30956
31014
|
|
|
30957
31015
|
const getLevelValue = (level) => {
|
|
@@ -31261,6 +31319,7 @@ exports.last = last;
|
|
|
31261
31319
|
exports.logMemoryUsage = logMemoryUsage;
|
|
31262
31320
|
exports.mapAsync = mapAsync;
|
|
31263
31321
|
exports.mapOrThrow = mapOrThrow;
|
|
31322
|
+
exports.maskVariable = maskVariable;
|
|
31264
31323
|
exports.mergeDeep = mergeDeep;
|
|
31265
31324
|
exports.multipleSplit = multipleSplit;
|
|
31266
31325
|
exports.newUuid = newUuid;
|
|
@@ -31278,6 +31337,7 @@ exports.sort = sort;
|
|
|
31278
31337
|
exports.splitPath = splitPath;
|
|
31279
31338
|
exports.subArrays = subArrays;
|
|
31280
31339
|
exports.subtractTime = subtractTime;
|
|
31340
|
+
exports.testInternetConnection = testInternetConnection;
|
|
31281
31341
|
exports.toArrayDict = toArrayDict;
|
|
31282
31342
|
exports.toCamelCase = toCamelCase;
|
|
31283
31343
|
exports.toDict = toDict;
|