@punks/backend-core 0.0.71 → 0.0.74
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 +72 -7
- 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/strings.d.ts +1 -0
- package/dist/cjs/types/utils/variables/index.d.ts +1 -0
- package/dist/esm/index.js +70 -8
- 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/strings.d.ts +1 -0
- package/dist/esm/types/utils/variables/index.d.ts +1 -0
- package/dist/index.d.ts +20 -1
- 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";
|
|
@@ -7,3 +7,4 @@ export declare const toCamelCase: (str: string) => string;
|
|
|
7
7
|
export declare const toTitleCase: (str: string) => string;
|
|
8
8
|
export declare const ensureTailingSlash: (value: string) => string;
|
|
9
9
|
export declare const ensureStartSlash: (value: string) => string;
|
|
10
|
+
export declare const multipleSplit: (str: string, separators: string[]) => string[];
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const maskVariable: (value: string | undefined, unmaskedLength?: number) => string;
|
package/dist/esm/index.js
CHANGED
|
@@ -93,28 +93,28 @@ const notNull = (x) => {
|
|
|
93
93
|
return x !== null;
|
|
94
94
|
};
|
|
95
95
|
const selectMany = (array, selector) => {
|
|
96
|
-
return array
|
|
96
|
+
return (array?.reduce(function (a, b) {
|
|
97
97
|
return a.concat(selector(b));
|
|
98
|
-
}, []);
|
|
98
|
+
}, []) ?? []);
|
|
99
99
|
};
|
|
100
100
|
const flatten = (array) => selectMany(array, (x) => x);
|
|
101
101
|
const distinct = (values) => {
|
|
102
|
-
return values
|
|
102
|
+
return values?.filter((n, i) => values.indexOf(n) === i) ?? [];
|
|
103
103
|
};
|
|
104
104
|
const distinctElements = (values, comparer) => {
|
|
105
|
-
return values
|
|
105
|
+
return (values?.filter((other, i, arr) => arr.findIndex((t) => comparer(t) === comparer(other)) === i) ?? []);
|
|
106
106
|
};
|
|
107
107
|
const jsonDistinct = (values) => {
|
|
108
108
|
return distinctElements(values, (x) => JSON.stringify(x));
|
|
109
109
|
};
|
|
110
110
|
const iterate = (values, action) => {
|
|
111
|
-
values
|
|
111
|
+
values?.forEach((value, index) => {
|
|
112
112
|
action(value, values?.[index + 1], values?.[index - 1]);
|
|
113
113
|
});
|
|
114
114
|
};
|
|
115
115
|
const groupBy = (values, keySelector) => {
|
|
116
116
|
const map = new Map();
|
|
117
|
-
values
|
|
117
|
+
values?.forEach((value) => {
|
|
118
118
|
const key = keySelector(value);
|
|
119
119
|
const items = map.get(key) || [];
|
|
120
120
|
items.push(value);
|
|
@@ -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);
|
|
@@ -249,6 +296,15 @@ const toCamelCase = (str) => `${str[0].toLowerCase()}${str.slice(1)}`;
|
|
|
249
296
|
const toTitleCase = (str) => `${str[0].toUpperCase()}${str.slice(1)}`;
|
|
250
297
|
const ensureTailingSlash = (value) => value?.endsWith("/") ? value : value + "/";
|
|
251
298
|
const ensureStartSlash = (value) => value?.startsWith("/") ? value : "/" + value;
|
|
299
|
+
const multipleSplit = (str, separators) => {
|
|
300
|
+
const escapeRegExp = (separator) => {
|
|
301
|
+
return separator.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"); // $& means the whole matched string
|
|
302
|
+
};
|
|
303
|
+
const regexPattern = separators
|
|
304
|
+
.map((separator) => escapeRegExp(separator))
|
|
305
|
+
.join("|");
|
|
306
|
+
return str.split(new RegExp(regexPattern));
|
|
307
|
+
};
|
|
252
308
|
|
|
253
309
|
const removeUndefinedProps = (obj, options = { recursive: false }) => {
|
|
254
310
|
const { recursive } = options;
|
|
@@ -356,6 +412,12 @@ const jsonSerialize = (obj, options) => {
|
|
|
356
412
|
return JSON.stringify(obj, replacer, spaces);
|
|
357
413
|
};
|
|
358
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
|
+
|
|
359
421
|
const pluralize = (word) => {
|
|
360
422
|
return word.endsWith("s") ? `${word}es` : `${word}s`;
|
|
361
423
|
};
|
|
@@ -30845,7 +30907,7 @@ const excelBuild = (...sheets) => {
|
|
|
30845
30907
|
const sheetContents = [];
|
|
30846
30908
|
for (const sheet of sheets) {
|
|
30847
30909
|
sheetContents.push({
|
|
30848
|
-
name: sheet.sheetName,
|
|
30910
|
+
name: sheet.sheetName.substring(0, 31),
|
|
30849
30911
|
data: [
|
|
30850
30912
|
sheet.columns.map((x) => x.header),
|
|
30851
30913
|
...sheet.data.map((d) => Array.from(buildRow(d, sheet))),
|
|
@@ -31183,5 +31245,5 @@ const processArrayItemMove = (items, input) => {
|
|
|
31183
31245
|
}));
|
|
31184
31246
|
};
|
|
31185
31247
|
|
|
31186
|
-
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, 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 };
|
|
31248
|
+
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 };
|
|
31187
31249
|
//# sourceMappingURL=index.js.map
|