@punks/backend-core 0.0.73 → 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 +55 -0
- 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/esm/index.js +54 -1
- 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/index.d.ts +19 -1
- 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
|
};
|
|
@@ -31261,6 +31314,7 @@ exports.last = last;
|
|
|
31261
31314
|
exports.logMemoryUsage = logMemoryUsage;
|
|
31262
31315
|
exports.mapAsync = mapAsync;
|
|
31263
31316
|
exports.mapOrThrow = mapOrThrow;
|
|
31317
|
+
exports.maskVariable = maskVariable;
|
|
31264
31318
|
exports.mergeDeep = mergeDeep;
|
|
31265
31319
|
exports.multipleSplit = multipleSplit;
|
|
31266
31320
|
exports.newUuid = newUuid;
|
|
@@ -31278,6 +31332,7 @@ exports.sort = sort;
|
|
|
31278
31332
|
exports.splitPath = splitPath;
|
|
31279
31333
|
exports.subArrays = subArrays;
|
|
31280
31334
|
exports.subtractTime = subtractTime;
|
|
31335
|
+
exports.testInternetConnection = testInternetConnection;
|
|
31281
31336
|
exports.toArrayDict = toArrayDict;
|
|
31282
31337
|
exports.toCamelCase = toCamelCase;
|
|
31283
31338
|
exports.toDict = toDict;
|