@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
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { LogLevel } from "../abstractions";
|
|
2
|
-
export declare const getLevelValue: (level: LogLevel) => 1 | 0 | 2 |
|
|
2
|
+
export declare const getLevelValue: (level: LogLevel) => 1 | 0 | 2 | 4 | 3;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export declare const testInternetConnection: (options?: {
|
|
2
|
+
healthCheckUrls?: string[];
|
|
3
|
+
}) => Promise<{
|
|
4
|
+
status: string;
|
|
5
|
+
details?: undefined;
|
|
6
|
+
} | {
|
|
7
|
+
status: string;
|
|
8
|
+
details: ({
|
|
9
|
+
status: string;
|
|
10
|
+
message?: undefined;
|
|
11
|
+
} | {
|
|
12
|
+
status: string;
|
|
13
|
+
message: any;
|
|
14
|
+
})[];
|
|
15
|
+
}>;
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
export * from "./array";
|
|
2
|
+
export { testInternetConnection } from "./connection";
|
|
2
3
|
export { addTime, subtractTime, floorDateToSecond, TimeUnit } from "./dates";
|
|
3
4
|
export { CsvColumnDefinition, CsvBuildOptions, csvBuild, csvParse } from "./csv";
|
|
4
5
|
export { getDirectoryFilePaths } from "./files";
|
|
5
6
|
export { joinPath, splitPath, ensureDirectory, getDirectoryPath, createDayPath, } from "./paths";
|
|
6
7
|
export * from "./strings";
|
|
7
8
|
export * from "./objects";
|
|
9
|
+
export { maskVariable } from "./variables";
|
|
8
10
|
export * from "./text";
|
|
9
11
|
export * from "./threading";
|
|
10
12
|
export { buildTree, TreeNodeBuilder } from "./trees";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const maskVariable: (value: string | undefined, unmaskedLength?: number) => string;
|
|
@@ -22,4 +22,4 @@ export type ExcelParseOptions = {
|
|
|
22
22
|
sheetIndex?: number;
|
|
23
23
|
dateColumns?: string[];
|
|
24
24
|
};
|
|
25
|
-
export declare const excelParse: (file: string | ArrayBuffer, options?: ExcelParseOptions) => any
|
|
25
|
+
export declare const excelParse: (file: string | ArrayBuffer, options?: ExcelParseOptions) => any;
|
package/dist/esm/index.js
CHANGED
|
@@ -126,6 +126,53 @@ const subArrays = (array1, array2, eqFn) => {
|
|
|
126
126
|
return array1.filter((a1) => !array2.some((a2) => eqFn(a1, a2)));
|
|
127
127
|
};
|
|
128
128
|
|
|
129
|
+
const testConnection = async (url) => {
|
|
130
|
+
try {
|
|
131
|
+
const controller = new AbortController();
|
|
132
|
+
const timeoutId = setTimeout(() => controller.abort(), 30 * 1000);
|
|
133
|
+
const response = await fetch(url, { signal: controller.signal });
|
|
134
|
+
clearTimeout(timeoutId);
|
|
135
|
+
if (response.ok) {
|
|
136
|
+
return {
|
|
137
|
+
status: "success",
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
else {
|
|
141
|
+
return {
|
|
142
|
+
status: "error",
|
|
143
|
+
message: `HTTP error: ${response.status}`,
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
catch (e) {
|
|
148
|
+
return {
|
|
149
|
+
status: "error",
|
|
150
|
+
message: e.name === "AbortError" ? "Request timed out" : e.message,
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
};
|
|
154
|
+
const DEFAULT_HEALTH_CHECK_URLS = [
|
|
155
|
+
"https://www.google.com",
|
|
156
|
+
"https://www.cloudflare.com",
|
|
157
|
+
"https://www.microsoft.com",
|
|
158
|
+
];
|
|
159
|
+
const testInternetConnection = async (options) => {
|
|
160
|
+
const websitesToCheck = options?.healthCheckUrls ?? DEFAULT_HEALTH_CHECK_URLS;
|
|
161
|
+
const results = await Promise.all(websitesToCheck.map(testConnection));
|
|
162
|
+
const allSuccess = results.every((result) => result.status === "success");
|
|
163
|
+
if (allSuccess) {
|
|
164
|
+
return {
|
|
165
|
+
status: "success",
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
else {
|
|
169
|
+
return {
|
|
170
|
+
status: "error",
|
|
171
|
+
details: results,
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
};
|
|
175
|
+
|
|
129
176
|
const addTime = (date, offset) => {
|
|
130
177
|
const { value, unit } = offset;
|
|
131
178
|
const newDate = new Date(date);
|
|
@@ -365,6 +412,12 @@ const jsonSerialize = (obj, options) => {
|
|
|
365
412
|
return JSON.stringify(obj, replacer, spaces);
|
|
366
413
|
};
|
|
367
414
|
|
|
415
|
+
const maskVariable = (value, unmaskedLength = 4) => value
|
|
416
|
+
? value.substring(0, unmaskedLength).concat(Array.from(value.substring(unmaskedLength))
|
|
417
|
+
.map(() => "*")
|
|
418
|
+
.join(""))
|
|
419
|
+
: "";
|
|
420
|
+
|
|
368
421
|
const pluralize = (word) => {
|
|
369
422
|
return word.endsWith("s") ? `${word}es` : `${word}s`;
|
|
370
423
|
};
|
|
@@ -30918,12 +30971,17 @@ const aggregateRow = (header, row, options) => {
|
|
|
30918
30971
|
return record;
|
|
30919
30972
|
};
|
|
30920
30973
|
const excelParse = (file, options) => {
|
|
30921
|
-
const sheets = parseExcelRaw(file);
|
|
30922
|
-
|
|
30923
|
-
|
|
30924
|
-
|
|
30925
|
-
|
|
30926
|
-
|
|
30974
|
+
const sheets = parseExcelRaw(file).map((x) => parseSheet(x, options));
|
|
30975
|
+
return sheets.length === 1
|
|
30976
|
+
? sheets[0]
|
|
30977
|
+
: sheets.reduce((acc, sheet, index) => {
|
|
30978
|
+
acc[sheet.name || `Sheet${index + 1}`] = sheets[index];
|
|
30979
|
+
return acc;
|
|
30980
|
+
}, {});
|
|
30981
|
+
};
|
|
30982
|
+
const parseSheet = (sheet, options) => {
|
|
30983
|
+
const [header, ...lines] = sheet.data.filter((x) => isValidRow(x));
|
|
30984
|
+
return lines.map((x) => aggregateRow(header, x, options));
|
|
30927
30985
|
};
|
|
30928
30986
|
|
|
30929
30987
|
const getLevelValue = (level) => {
|
|
@@ -31192,5 +31250,5 @@ const processArrayItemMove = (items, input) => {
|
|
|
31192
31250
|
}));
|
|
31193
31251
|
};
|
|
31194
31252
|
|
|
31195
|
-
export { ConsoleLogger, DatadogLogger, ExcelKeyTransform, FileLogger, Log, LogLevel, MetaSerializationType, addTime, buildObject, buildTree, buildUrl, byField, byFieldDesc, camelToKebabCase, camelToSnakeCase, createDayPath, csvBuild, csvParse, deserializeQueryString, distinct, distinctElements, ensureDirectory, ensureStartSlash, ensureTailingSlash, excelBuild, excelParse, first, flatten, floorDateToSecond, getDirectoryFilePaths, getDirectoryPath, getQueryParameter, groupBy, indexes, isNullOrUndefined, iterate, joinPath, joinUrl, jsonDistinct, jsonSerialize, last, logMemoryUsage, mapAsync, mapOrThrow, mergeDeep, multipleSplit, newUuid, notNull, notUndefined, pluralize, processArrayDifferences, processArrayItemMove, range, removeUndefinedProps, selectMany, serializeQueryString, sleep, sort, splitPath, subArrays, subtractTime, toArrayDict, toCamelCase, toDict, toItemsDict, toItemsMap, toMap, toTitleCase, trim$1 as trim, trimEnd, trimStart, updateQueryParameters };
|
|
31253
|
+
export { ConsoleLogger, DatadogLogger, ExcelKeyTransform, FileLogger, Log, LogLevel, MetaSerializationType, addTime, buildObject, buildTree, buildUrl, byField, byFieldDesc, camelToKebabCase, camelToSnakeCase, createDayPath, csvBuild, csvParse, deserializeQueryString, distinct, distinctElements, ensureDirectory, ensureStartSlash, ensureTailingSlash, excelBuild, excelParse, first, flatten, floorDateToSecond, getDirectoryFilePaths, getDirectoryPath, getQueryParameter, groupBy, indexes, isNullOrUndefined, iterate, joinPath, joinUrl, jsonDistinct, jsonSerialize, last, logMemoryUsage, mapAsync, mapOrThrow, maskVariable, mergeDeep, multipleSplit, newUuid, notNull, notUndefined, pluralize, processArrayDifferences, processArrayItemMove, range, removeUndefinedProps, selectMany, serializeQueryString, sleep, sort, splitPath, subArrays, subtractTime, testInternetConnection, toArrayDict, toCamelCase, toDict, toItemsDict, toItemsMap, toMap, toTitleCase, trim$1 as trim, trimEnd, trimStart, updateQueryParameters };
|
|
31196
31254
|
//# sourceMappingURL=index.js.map
|