@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.
@@ -1,2 +1,2 @@
1
1
  import { LogLevel } from "../abstractions";
2
- export declare const getLevelValue: (level: LogLevel) => 1 | 0 | 2 | 3 | 4;
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;
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
  };
@@ -31192,5 +31245,5 @@ const processArrayItemMove = (items, input) => {
31192
31245
  }));
31193
31246
  };
31194
31247
 
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 };
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 };
31196
31249
  //# sourceMappingURL=index.js.map