@n8n/utils 1.37.1 → 1.38.0
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/assert.cjs +11 -2
- package/dist/assert.cjs.map +1 -0
- package/dist/assert.d.cts +5 -2
- package/dist/assert.d.mts +5 -2
- package/dist/assert.mjs +10 -2
- package/dist/assert.mjs.map +1 -0
- package/dist/client-assertion.cjs +49 -0
- package/dist/client-assertion.cjs.map +1 -0
- package/dist/client-assertion.d.cts +12 -0
- package/dist/client-assertion.d.mts +12 -0
- package/dist/client-assertion.mjs +48 -0
- package/dist/client-assertion.mjs.map +1 -0
- package/dist/create-event-queue.cjs +40 -2
- package/dist/create-event-queue.cjs.map +1 -0
- package/dist/create-event-queue.d.cts +7 -2
- package/dist/create-event-queue.d.mts +7 -2
- package/dist/create-event-queue.mjs +39 -2
- package/dist/create-event-queue.mjs.map +1 -0
- package/dist/ensure-error.cjs +15 -0
- package/dist/ensure-error.cjs.map +1 -0
- package/dist/ensure-error.mjs +9 -0
- package/dist/ensure-error.mjs.map +1 -0
- package/dist/errors/ensure-error.cjs +3 -0
- package/dist/errors/ensure-error.d.cts +5 -0
- package/dist/errors/ensure-error.d.mts +5 -0
- package/dist/errors/ensure-error.mjs +3 -0
- package/dist/event-bus.cjs +43 -2
- package/dist/event-bus.cjs.map +1 -0
- package/dist/event-bus.d.cts +14 -2
- package/dist/event-bus.d.mts +14 -2
- package/dist/event-bus.mjs +42 -2
- package/dist/event-bus.mjs.map +1 -0
- package/dist/files/is-windows-file-path.cjs +11 -2
- package/dist/files/is-windows-file-path.cjs.map +1 -0
- package/dist/files/is-windows-file-path.d.cts +5 -2
- package/dist/files/is-windows-file-path.d.mts +5 -2
- package/dist/files/is-windows-file-path.mjs +10 -2
- package/dist/files/is-windows-file-path.mjs.map +1 -0
- package/dist/files/sanitize-filename.cjs +61 -2
- package/dist/files/sanitize-filename.cjs.map +1 -0
- package/dist/files/sanitize-filename.d.cts +5 -2
- package/dist/files/sanitize-filename.d.mts +5 -2
- package/dist/files/sanitize-filename.mjs +60 -2
- package/dist/files/sanitize-filename.mjs.map +1 -0
- package/dist/format-pem-block.d.cts +5 -2
- package/dist/format-pem-block.d.mts +5 -2
- package/dist/generate-nano-id.cjs +28 -2
- package/dist/generate-nano-id.cjs.map +1 -0
- package/dist/generate-nano-id.d.cts +5 -2
- package/dist/generate-nano-id.d.mts +5 -2
- package/dist/generate-nano-id.mjs +28 -2
- package/dist/generate-nano-id.mjs.map +1 -0
- package/dist/get-jwt-expiry.cjs +22 -2
- package/dist/get-jwt-expiry.cjs.map +1 -0
- package/dist/get-jwt-expiry.d.cts +5 -2
- package/dist/get-jwt-expiry.d.mts +5 -2
- package/dist/get-jwt-expiry.mjs +21 -2
- package/dist/get-jwt-expiry.mjs.map +1 -0
- package/dist/is-record.cjs +8 -2
- package/dist/is-record.cjs.map +1 -0
- package/dist/is-record.d.cts +5 -2
- package/dist/is-record.d.mts +5 -2
- package/dist/is-record.mjs +7 -2
- package/dist/is-record.mjs.map +1 -0
- package/dist/number/smart-decimal.cjs +10 -2
- package/dist/number/smart-decimal.cjs.map +1 -0
- package/dist/number/smart-decimal.d.cts +5 -2
- package/dist/number/smart-decimal.d.mts +5 -2
- package/dist/number/smart-decimal.mjs +9 -2
- package/dist/number/smart-decimal.mjs.map +1 -0
- package/dist/placeholder.cjs +80 -7
- package/dist/placeholder.cjs.map +1 -0
- package/dist/placeholder.d.cts +14 -2
- package/dist/placeholder.d.mts +14 -2
- package/dist/placeholder.mjs +74 -2
- package/dist/placeholder.mjs.map +1 -0
- package/dist/promise/deferred-promise.cjs +14 -0
- package/dist/promise/deferred-promise.cjs.map +1 -0
- package/dist/promise/deferred-promise.d.cts +12 -0
- package/dist/promise/deferred-promise.d.mts +12 -0
- package/dist/promise/deferred-promise.mjs +13 -0
- package/dist/promise/deferred-promise.mjs.map +1 -0
- package/dist/result.cjs +30 -0
- package/dist/result.cjs.map +1 -0
- package/dist/result.d.cts +16 -0
- package/dist/result.d.mts +16 -0
- package/dist/result.mjs +28 -0
- package/dist/result.mjs.map +1 -0
- package/dist/retry.cjs +39 -2
- package/dist/retry.cjs.map +1 -0
- package/dist/retry.d.cts +6 -2
- package/dist/retry.d.mts +6 -2
- package/dist/retry.mjs +38 -2
- package/dist/retry.mjs.map +1 -0
- package/dist/scrub-secrets.cjs +44 -4
- package/dist/scrub-secrets.cjs.map +1 -0
- package/dist/scrub-secrets.d.cts +7 -2
- package/dist/scrub-secrets.d.mts +7 -2
- package/dist/scrub-secrets.mjs +41 -2
- package/dist/scrub-secrets.mjs.map +1 -0
- package/dist/search/re-rank-search-results.cjs +19 -2
- package/dist/search/re-rank-search-results.cjs.map +1 -0
- package/dist/search/re-rank-search-results.d.cts +13 -2
- package/dist/search/re-rank-search-results.d.mts +13 -2
- package/dist/search/re-rank-search-results.mjs +18 -2
- package/dist/search/re-rank-search-results.mjs.map +1 -0
- package/dist/search/sublime-search.cjs +182 -3
- package/dist/search/sublime-search.cjs.map +1 -0
- package/dist/search/sublime-search.d.cts +15 -2
- package/dist/search/sublime-search.d.mts +15 -2
- package/dist/search/sublime-search.mjs +180 -2
- package/dist/search/sublime-search.mjs.map +1 -0
- package/dist/sort/sort-by-property.cjs +12 -2
- package/dist/sort/sort-by-property.cjs.map +1 -0
- package/dist/sort/sort-by-property.d.cts +5 -2
- package/dist/sort/sort-by-property.d.mts +5 -2
- package/dist/sort/sort-by-property.mjs +11 -2
- package/dist/sort/sort-by-property.mjs.map +1 -0
- package/dist/string/truncate.cjs +32 -3
- package/dist/string/truncate.cjs.map +1 -0
- package/dist/string/truncate.d.cts +6 -2
- package/dist/string/truncate.d.mts +6 -2
- package/dist/string/truncate.mjs +30 -2
- package/dist/string/truncate.mjs.map +1 -0
- package/dist/types.d.cts +5 -2
- package/dist/types.d.mts +5 -2
- package/package.json +11 -12
- package/dist/assert2.cjs +0 -17
- package/dist/assert2.cjs.map +0 -1
- package/dist/assert2.d.cts +0 -5
- package/dist/assert2.d.mts +0 -5
- package/dist/assert2.mjs +0 -11
- package/dist/assert2.mjs.map +0 -1
- package/dist/create-event-queue2.cjs +0 -46
- package/dist/create-event-queue2.cjs.map +0 -1
- package/dist/create-event-queue2.d.cts +0 -7
- package/dist/create-event-queue2.d.mts +0 -7
- package/dist/create-event-queue2.mjs +0 -40
- package/dist/create-event-queue2.mjs.map +0 -1
- package/dist/event-bus2.cjs +0 -49
- package/dist/event-bus2.cjs.map +0 -1
- package/dist/event-bus2.d.cts +0 -14
- package/dist/event-bus2.d.mts +0 -14
- package/dist/event-bus2.mjs +0 -43
- package/dist/event-bus2.mjs.map +0 -1
- package/dist/format-pem-block2.d.cts +0 -5
- package/dist/format-pem-block2.d.mts +0 -5
- package/dist/generate-nano-id2.cjs +0 -34
- package/dist/generate-nano-id2.cjs.map +0 -1
- package/dist/generate-nano-id2.d.cts +0 -5
- package/dist/generate-nano-id2.d.mts +0 -5
- package/dist/generate-nano-id2.mjs +0 -29
- package/dist/generate-nano-id2.mjs.map +0 -1
- package/dist/get-jwt-expiry2.cjs +0 -28
- package/dist/get-jwt-expiry2.cjs.map +0 -1
- package/dist/get-jwt-expiry2.d.cts +0 -5
- package/dist/get-jwt-expiry2.d.mts +0 -5
- package/dist/get-jwt-expiry2.mjs +0 -22
- package/dist/get-jwt-expiry2.mjs.map +0 -1
- package/dist/index.cjs +0 -44
- package/dist/index.d.cts +0 -19
- package/dist/index.d.mts +0 -19
- package/dist/index.mjs +0 -19
- package/dist/is-record2.cjs +0 -14
- package/dist/is-record2.cjs.map +0 -1
- package/dist/is-record2.d.cts +0 -5
- package/dist/is-record2.d.mts +0 -5
- package/dist/is-record2.mjs +0 -8
- package/dist/is-record2.mjs.map +0 -1
- package/dist/is-windows-file-path.cjs +0 -17
- package/dist/is-windows-file-path.cjs.map +0 -1
- package/dist/is-windows-file-path.d.cts +0 -5
- package/dist/is-windows-file-path.d.mts +0 -5
- package/dist/is-windows-file-path.mjs +0 -11
- package/dist/is-windows-file-path.mjs.map +0 -1
- package/dist/placeholder2.cjs +0 -111
- package/dist/placeholder2.cjs.map +0 -1
- package/dist/placeholder2.d.cts +0 -14
- package/dist/placeholder2.d.mts +0 -14
- package/dist/placeholder2.mjs +0 -75
- package/dist/placeholder2.mjs.map +0 -1
- package/dist/re-rank-search-results.cjs +0 -25
- package/dist/re-rank-search-results.cjs.map +0 -1
- package/dist/re-rank-search-results.d.cts +0 -13
- package/dist/re-rank-search-results.d.mts +0 -13
- package/dist/re-rank-search-results.mjs +0 -19
- package/dist/re-rank-search-results.mjs.map +0 -1
- package/dist/retry2.cjs +0 -45
- package/dist/retry2.cjs.map +0 -1
- package/dist/retry2.d.cts +0 -6
- package/dist/retry2.d.mts +0 -6
- package/dist/retry2.mjs +0 -39
- package/dist/retry2.mjs.map +0 -1
- package/dist/sanitize-filename.cjs +0 -67
- package/dist/sanitize-filename.cjs.map +0 -1
- package/dist/sanitize-filename.d.cts +0 -5
- package/dist/sanitize-filename.d.mts +0 -5
- package/dist/sanitize-filename.mjs +0 -61
- package/dist/sanitize-filename.mjs.map +0 -1
- package/dist/scrub-secrets2.cjs +0 -59
- package/dist/scrub-secrets2.cjs.map +0 -1
- package/dist/scrub-secrets2.d.cts +0 -7
- package/dist/scrub-secrets2.d.mts +0 -7
- package/dist/scrub-secrets2.mjs +0 -41
- package/dist/scrub-secrets2.mjs.map +0 -1
- package/dist/smart-decimal.cjs +0 -16
- package/dist/smart-decimal.cjs.map +0 -1
- package/dist/smart-decimal.d.cts +0 -5
- package/dist/smart-decimal.d.mts +0 -5
- package/dist/smart-decimal.mjs +0 -10
- package/dist/smart-decimal.mjs.map +0 -1
- package/dist/sort-by-property.cjs +0 -18
- package/dist/sort-by-property.cjs.map +0 -1
- package/dist/sort-by-property.d.cts +0 -5
- package/dist/sort-by-property.d.mts +0 -5
- package/dist/sort-by-property.mjs +0 -12
- package/dist/sort-by-property.mjs.map +0 -1
- package/dist/sublime-search.cjs +0 -193
- package/dist/sublime-search.cjs.map +0 -1
- package/dist/sublime-search.d.cts +0 -15
- package/dist/sublime-search.d.mts +0 -15
- package/dist/sublime-search.mjs +0 -181
- package/dist/sublime-search.mjs.map +0 -1
- package/dist/truncate.cjs +0 -43
- package/dist/truncate.cjs.map +0 -1
- package/dist/truncate.d.cts +0 -6
- package/dist/truncate.d.mts +0 -6
- package/dist/truncate.mjs +0 -31
- package/dist/truncate.mjs.map +0 -1
- package/dist/types2.d.cts +0 -5
- package/dist/types2.d.mts +0 -5
package/dist/placeholder.mjs
CHANGED
|
@@ -1,3 +1,75 @@
|
|
|
1
|
-
|
|
1
|
+
//#region src/placeholder.ts
|
|
2
|
+
const PLACEHOLDER_SUFFIX = "__>";
|
|
3
|
+
const PLACEHOLDER_VALUE_PREFIX = "<__PLACEHOLDER_VALUE__";
|
|
4
|
+
const PLACEHOLDER_REGEX = /<__PLACEHOLDER.*?__>/;
|
|
5
|
+
/** Check if a value is a placeholder sentinel string (format: `<__PLACEHOLDER_VALUE__hint__>`). */
|
|
6
|
+
function isPlaceholderString(value) {
|
|
7
|
+
return typeof value === "string" && value.startsWith(PLACEHOLDER_VALUE_PREFIX) && value.endsWith(PLACEHOLDER_SUFFIX);
|
|
8
|
+
}
|
|
9
|
+
/** Recursively check if a value (string, array, or object) contains any placeholder sentinel strings. */
|
|
10
|
+
function hasPlaceholderDeep(value) {
|
|
11
|
+
if (typeof value === "string") return isPlaceholderString(value);
|
|
12
|
+
if (Array.isArray(value)) return value.some(hasPlaceholderDeep);
|
|
13
|
+
if (value !== null && typeof value === "object") return Object.values(value).some(hasPlaceholderDeep);
|
|
14
|
+
return false;
|
|
15
|
+
}
|
|
16
|
+
/** Checks if a value is a placeholder value (matches the placeholder regex pattern). */
|
|
17
|
+
function isPlaceholderValue(value) {
|
|
18
|
+
if (typeof value !== "string") return false;
|
|
19
|
+
return !!value.match(PLACEHOLDER_REGEX);
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Extracts the label from a single placeholder string.
|
|
23
|
+
* Handles formats like:
|
|
24
|
+
* - <__PLACEHOLDER_VALUE__label__>
|
|
25
|
+
* - <__PLACEHOLDER__: label__>
|
|
26
|
+
*/
|
|
27
|
+
function extractLabelFromPlaceholder(placeholder) {
|
|
28
|
+
let label = placeholder.slice(14, -3);
|
|
29
|
+
if (label.startsWith("_VALUE__")) label = label.slice(8);
|
|
30
|
+
else if (label.startsWith("__:")) label = label.slice(3);
|
|
31
|
+
else if (label.startsWith("__")) label = label.slice(2);
|
|
32
|
+
return label.trim();
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Extracts all placeholder labels from a string value.
|
|
36
|
+
* Handles both cases where the entire value is a placeholder and where
|
|
37
|
+
* placeholders are embedded within code (e.g., Code node).
|
|
38
|
+
* Returns an array of labels found.
|
|
39
|
+
*/
|
|
40
|
+
function extractPlaceholderLabels(value) {
|
|
41
|
+
if (typeof value !== "string") return [];
|
|
42
|
+
const labels = [];
|
|
43
|
+
const regex = new RegExp(PLACEHOLDER_REGEX.source, "g");
|
|
44
|
+
let match;
|
|
45
|
+
while ((match = regex.exec(value)) !== null) {
|
|
46
|
+
const label = extractLabelFromPlaceholder(match[0]);
|
|
47
|
+
if (label.length > 0) labels.push(label);
|
|
48
|
+
}
|
|
49
|
+
return labels;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Recursively searches through a value (object, array, or primitive) to find
|
|
53
|
+
* all placeholder values and their paths.
|
|
54
|
+
*/
|
|
55
|
+
function findPlaceholderDetails(value, path = []) {
|
|
56
|
+
if (typeof value === "string") return extractPlaceholderLabels(value).map((label) => ({
|
|
57
|
+
path,
|
|
58
|
+
label
|
|
59
|
+
}));
|
|
60
|
+
if (Array.isArray(value)) return value.flatMap((item, index) => findPlaceholderDetails(item, [...path, `[${index}]`]));
|
|
61
|
+
if (value !== null && typeof value === "object") return Object.entries(value).flatMap(([key, nested]) => findPlaceholderDetails(nested, [...path, key]));
|
|
62
|
+
return [];
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Formats a path array into a dot-notation string for display.
|
|
66
|
+
* Array indices are preserved as [N] without leading dots.
|
|
67
|
+
*/
|
|
68
|
+
function formatPlaceholderPath(path) {
|
|
69
|
+
if (path.length === 0) return "parameters";
|
|
70
|
+
return path.map((segment, index) => segment.startsWith("[") || index === 0 ? segment : `.${segment}`).join("");
|
|
71
|
+
}
|
|
2
72
|
|
|
3
|
-
|
|
73
|
+
//#endregion
|
|
74
|
+
export { extractPlaceholderLabels, findPlaceholderDetails, formatPlaceholderPath, hasPlaceholderDeep, isPlaceholderString, isPlaceholderValue };
|
|
75
|
+
//# sourceMappingURL=placeholder.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"placeholder.mjs","names":["labels: string[]"],"sources":["../src/placeholder.ts"],"sourcesContent":["const PLACEHOLDER_PREFIX = '<__PLACEHOLDER';\nconst PLACEHOLDER_SUFFIX = '__>';\nconst PLACEHOLDER_VALUE_PREFIX = '<__PLACEHOLDER_VALUE__';\n\nconst PLACEHOLDER_REGEX = /<__PLACEHOLDER.*?__>/;\n\nexport interface PlaceholderDetail {\n\tpath: string[];\n\tlabel: string;\n}\n\n/** Check if a value is a placeholder sentinel string (format: `<__PLACEHOLDER_VALUE__hint__>`). */\nexport function isPlaceholderString(value: unknown): boolean {\n\treturn (\n\t\ttypeof value === 'string' &&\n\t\tvalue.startsWith(PLACEHOLDER_VALUE_PREFIX) &&\n\t\tvalue.endsWith(PLACEHOLDER_SUFFIX)\n\t);\n}\n\n/** Recursively check if a value (string, array, or object) contains any placeholder sentinel strings. */\nexport function hasPlaceholderDeep(value: unknown): boolean {\n\tif (typeof value === 'string') return isPlaceholderString(value);\n\tif (Array.isArray(value)) return value.some(hasPlaceholderDeep);\n\tif (value !== null && typeof value === 'object') {\n\t\treturn Object.values(value as Record<string, unknown>).some(hasPlaceholderDeep);\n\t}\n\treturn false;\n}\n\n/** Checks if a value is a placeholder value (matches the placeholder regex pattern). */\nexport function isPlaceholderValue(value: unknown): boolean {\n\tif (typeof value !== 'string') return false;\n\treturn !!value.match(PLACEHOLDER_REGEX);\n}\n\n/**\n * Extracts the label from a single placeholder string.\n * Handles formats like:\n * - <__PLACEHOLDER_VALUE__label__>\n * - <__PLACEHOLDER__: label__>\n */\nfunction extractLabelFromPlaceholder(placeholder: string): string {\n\tlet label = placeholder.slice(PLACEHOLDER_PREFIX.length, -PLACEHOLDER_SUFFIX.length);\n\n\tif (label.startsWith('_VALUE__')) {\n\t\tlabel = label.slice('_VALUE__'.length);\n\t} else if (label.startsWith('__:')) {\n\t\tlabel = label.slice('__:'.length);\n\t} else if (label.startsWith('__')) {\n\t\tlabel = label.slice('__'.length);\n\t}\n\n\treturn label.trim();\n}\n\n/**\n * Extracts all placeholder labels from a string value.\n * Handles both cases where the entire value is a placeholder and where\n * placeholders are embedded within code (e.g., Code node).\n * Returns an array of labels found.\n */\nexport function extractPlaceholderLabels(value: unknown): string[] {\n\tif (typeof value !== 'string') return [];\n\n\tconst labels: string[] = [];\n\tconst regex = new RegExp(PLACEHOLDER_REGEX.source, 'g');\n\tlet match;\n\n\twhile ((match = regex.exec(value)) !== null) {\n\t\tconst label = extractLabelFromPlaceholder(match[0]);\n\t\tif (label.length > 0) {\n\t\t\tlabels.push(label);\n\t\t}\n\t}\n\n\treturn labels;\n}\n\n/**\n * Recursively searches through a value (object, array, or primitive) to find\n * all placeholder values and their paths.\n */\nexport function findPlaceholderDetails(value: unknown, path: string[] = []): PlaceholderDetail[] {\n\tif (typeof value === 'string') {\n\t\tconst labels = extractPlaceholderLabels(value);\n\t\treturn labels.map((label) => ({ path, label }));\n\t}\n\n\tif (Array.isArray(value)) {\n\t\treturn value.flatMap((item, index) => findPlaceholderDetails(item, [...path, `[${index}]`]));\n\t}\n\n\tif (value !== null && typeof value === 'object') {\n\t\treturn Object.entries(value).flatMap(([key, nested]) =>\n\t\t\tfindPlaceholderDetails(nested, [...path, key]),\n\t\t);\n\t}\n\n\treturn [];\n}\n\n/**\n * Formats a path array into a dot-notation string for display.\n * Array indices are preserved as [N] without leading dots.\n */\nexport function formatPlaceholderPath(path: string[]): string {\n\tif (path.length === 0) return 'parameters';\n\n\treturn path\n\t\t.map((segment, index) => (segment.startsWith('[') || index === 0 ? segment : `.${segment}`))\n\t\t.join('');\n}\n"],"mappings":";AACA,MAAM,qBAAqB;AAC3B,MAAM,2BAA2B;AAEjC,MAAM,oBAAoB;;AAQ1B,SAAgB,oBAAoB,OAAyB;AAC5D,QACC,OAAO,UAAU,YACjB,MAAM,WAAW,yBAAyB,IAC1C,MAAM,SAAS,mBAAmB;;;AAKpC,SAAgB,mBAAmB,OAAyB;AAC3D,KAAI,OAAO,UAAU,SAAU,QAAO,oBAAoB,MAAM;AAChE,KAAI,MAAM,QAAQ,MAAM,CAAE,QAAO,MAAM,KAAK,mBAAmB;AAC/D,KAAI,UAAU,QAAQ,OAAO,UAAU,SACtC,QAAO,OAAO,OAAO,MAAiC,CAAC,KAAK,mBAAmB;AAEhF,QAAO;;;AAIR,SAAgB,mBAAmB,OAAyB;AAC3D,KAAI,OAAO,UAAU,SAAU,QAAO;AACtC,QAAO,CAAC,CAAC,MAAM,MAAM,kBAAkB;;;;;;;;AASxC,SAAS,4BAA4B,aAA6B;CACjE,IAAI,QAAQ,YAAY,MAAM,IAA2B,GAA2B;AAEpF,KAAI,MAAM,WAAW,WAAW,CAC/B,SAAQ,MAAM,MAAM,EAAkB;UAC5B,MAAM,WAAW,MAAM,CACjC,SAAQ,MAAM,MAAM,EAAa;UACvB,MAAM,WAAW,KAAK,CAChC,SAAQ,MAAM,MAAM,EAAY;AAGjC,QAAO,MAAM,MAAM;;;;;;;;AASpB,SAAgB,yBAAyB,OAA0B;AAClE,KAAI,OAAO,UAAU,SAAU,QAAO,EAAE;CAExC,MAAMA,SAAmB,EAAE;CAC3B,MAAM,QAAQ,IAAI,OAAO,kBAAkB,QAAQ,IAAI;CACvD,IAAI;AAEJ,SAAQ,QAAQ,MAAM,KAAK,MAAM,MAAM,MAAM;EAC5C,MAAM,QAAQ,4BAA4B,MAAM,GAAG;AACnD,MAAI,MAAM,SAAS,EAClB,QAAO,KAAK,MAAM;;AAIpB,QAAO;;;;;;AAOR,SAAgB,uBAAuB,OAAgB,OAAiB,EAAE,EAAuB;AAChG,KAAI,OAAO,UAAU,SAEpB,QADe,yBAAyB,MAAM,CAChC,KAAK,WAAW;EAAE;EAAM;EAAO,EAAE;AAGhD,KAAI,MAAM,QAAQ,MAAM,CACvB,QAAO,MAAM,SAAS,MAAM,UAAU,uBAAuB,MAAM,CAAC,GAAG,MAAM,IAAI,MAAM,GAAG,CAAC,CAAC;AAG7F,KAAI,UAAU,QAAQ,OAAO,UAAU,SACtC,QAAO,OAAO,QAAQ,MAAM,CAAC,SAAS,CAAC,KAAK,YAC3C,uBAAuB,QAAQ,CAAC,GAAG,MAAM,IAAI,CAAC,CAC9C;AAGF,QAAO,EAAE;;;;;;AAOV,SAAgB,sBAAsB,MAAwB;AAC7D,KAAI,KAAK,WAAW,EAAG,QAAO;AAE9B,QAAO,KACL,KAAK,SAAS,UAAW,QAAQ,WAAW,IAAI,IAAI,UAAU,IAAI,UAAU,IAAI,UAAW,CAC3F,KAAK,GAAG"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
|
|
2
|
+
//#region src/promise/deferred-promise.ts
|
|
3
|
+
function createDeferredPromise() {
|
|
4
|
+
const deferred = {};
|
|
5
|
+
deferred.promise = new Promise((resolve, reject) => {
|
|
6
|
+
deferred.resolve = resolve;
|
|
7
|
+
deferred.reject = reject;
|
|
8
|
+
});
|
|
9
|
+
return deferred;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
//#endregion
|
|
13
|
+
exports.createDeferredPromise = createDeferredPromise;
|
|
14
|
+
//# sourceMappingURL=deferred-promise.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"deferred-promise.cjs","names":["deferred: Partial<IDeferredPromise<T>>"],"sources":["../../src/promise/deferred-promise.ts"],"sourcesContent":["type ResolveFn<T> = (result: T | PromiseLike<T>) => void;\ntype RejectFn = (error: Error) => void;\n\nexport interface IDeferredPromise<T> {\n\tpromise: Promise<T>;\n\tresolve: ResolveFn<T>;\n\treject: RejectFn;\n}\n\nexport function createDeferredPromise<T = void>(): IDeferredPromise<T> {\n\tconst deferred: Partial<IDeferredPromise<T>> = {};\n\tdeferred.promise = new Promise<T>((resolve, reject) => {\n\t\tdeferred.resolve = resolve;\n\t\tdeferred.reject = reject;\n\t});\n\treturn deferred as IDeferredPromise<T>;\n}\n"],"mappings":";;AASA,SAAgB,wBAAuD;CACtE,MAAMA,WAAyC,EAAE;AACjD,UAAS,UAAU,IAAI,SAAY,SAAS,WAAW;AACtD,WAAS,UAAU;AACnB,WAAS,SAAS;GACjB;AACF,QAAO"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
//#region src/promise/deferred-promise.d.ts
|
|
2
|
+
type ResolveFn<T> = (result: T | PromiseLike<T>) => void;
|
|
3
|
+
type RejectFn = (error: Error) => void;
|
|
4
|
+
interface IDeferredPromise<T> {
|
|
5
|
+
promise: Promise<T>;
|
|
6
|
+
resolve: ResolveFn<T>;
|
|
7
|
+
reject: RejectFn;
|
|
8
|
+
}
|
|
9
|
+
declare function createDeferredPromise<T = void>(): IDeferredPromise<T>;
|
|
10
|
+
//#endregion
|
|
11
|
+
export { IDeferredPromise, createDeferredPromise };
|
|
12
|
+
//# sourceMappingURL=deferred-promise.d.cts.map
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
//#region src/promise/deferred-promise.d.ts
|
|
2
|
+
type ResolveFn<T> = (result: T | PromiseLike<T>) => void;
|
|
3
|
+
type RejectFn = (error: Error) => void;
|
|
4
|
+
interface IDeferredPromise<T> {
|
|
5
|
+
promise: Promise<T>;
|
|
6
|
+
resolve: ResolveFn<T>;
|
|
7
|
+
reject: RejectFn;
|
|
8
|
+
}
|
|
9
|
+
declare function createDeferredPromise<T = void>(): IDeferredPromise<T>;
|
|
10
|
+
//#endregion
|
|
11
|
+
export { IDeferredPromise, createDeferredPromise };
|
|
12
|
+
//# sourceMappingURL=deferred-promise.d.mts.map
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
//#region src/promise/deferred-promise.ts
|
|
2
|
+
function createDeferredPromise() {
|
|
3
|
+
const deferred = {};
|
|
4
|
+
deferred.promise = new Promise((resolve, reject) => {
|
|
5
|
+
deferred.resolve = resolve;
|
|
6
|
+
deferred.reject = reject;
|
|
7
|
+
});
|
|
8
|
+
return deferred;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
//#endregion
|
|
12
|
+
export { createDeferredPromise };
|
|
13
|
+
//# sourceMappingURL=deferred-promise.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"deferred-promise.mjs","names":["deferred: Partial<IDeferredPromise<T>>"],"sources":["../../src/promise/deferred-promise.ts"],"sourcesContent":["type ResolveFn<T> = (result: T | PromiseLike<T>) => void;\ntype RejectFn = (error: Error) => void;\n\nexport interface IDeferredPromise<T> {\n\tpromise: Promise<T>;\n\tresolve: ResolveFn<T>;\n\treject: RejectFn;\n}\n\nexport function createDeferredPromise<T = void>(): IDeferredPromise<T> {\n\tconst deferred: Partial<IDeferredPromise<T>> = {};\n\tdeferred.promise = new Promise<T>((resolve, reject) => {\n\t\tdeferred.resolve = resolve;\n\t\tdeferred.reject = reject;\n\t});\n\treturn deferred as IDeferredPromise<T>;\n}\n"],"mappings":";AASA,SAAgB,wBAAuD;CACtE,MAAMA,WAAyC,EAAE;AACjD,UAAS,UAAU,IAAI,SAAY,SAAS,WAAW;AACtD,WAAS,UAAU;AACnB,WAAS,SAAS;GACjB;AACF,QAAO"}
|
package/dist/result.cjs
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
const require_ensure_error = require('./ensure-error.cjs');
|
|
2
|
+
|
|
3
|
+
//#region src/result.ts
|
|
4
|
+
const createResultOk = (data) => ({
|
|
5
|
+
ok: true,
|
|
6
|
+
result: data
|
|
7
|
+
});
|
|
8
|
+
const createResultError = (error) => ({
|
|
9
|
+
ok: false,
|
|
10
|
+
error
|
|
11
|
+
});
|
|
12
|
+
/**
|
|
13
|
+
* Executes the given function and converts it to a Result object.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* const result = toResult(() => fs.writeFileSync('file.txt', 'Hello, World!'));
|
|
17
|
+
*/
|
|
18
|
+
const toResult = (fn) => {
|
|
19
|
+
try {
|
|
20
|
+
return createResultOk(fn());
|
|
21
|
+
} catch (e) {
|
|
22
|
+
return createResultError(require_ensure_error.ensureError(e));
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
//#endregion
|
|
27
|
+
exports.createResultError = createResultError;
|
|
28
|
+
exports.createResultOk = createResultOk;
|
|
29
|
+
exports.toResult = toResult;
|
|
30
|
+
//# sourceMappingURL=result.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"result.cjs","names":["ensureError"],"sources":["../src/result.ts"],"sourcesContent":["import { ensureError } from './errors/ensure-error';\n\nexport type ResultOk<T> = { ok: true; result: T };\nexport type ResultError<E> = { ok: false; error: E };\nexport type Result<T, E> = ResultOk<T> | ResultError<E>;\n\nexport const createResultOk = <T>(data: T): ResultOk<T> => ({\n\tok: true,\n\tresult: data,\n});\n\nexport const createResultError = <E = unknown>(error: E): ResultError<E> => ({\n\tok: false,\n\terror,\n});\n\n/**\n * Executes the given function and converts it to a Result object.\n *\n * @example\n * const result = toResult(() => fs.writeFileSync('file.txt', 'Hello, World!'));\n */\nexport const toResult = <T, E extends Error = Error>(fn: () => T): Result<T, E> => {\n\ttry {\n\t\treturn createResultOk<T>(fn());\n\t} catch (e) {\n\t\tconst error = ensureError(e);\n\t\treturn createResultError<E>(error as E);\n\t}\n};\n"],"mappings":";;;AAMA,MAAa,kBAAqB,UAA0B;CAC3D,IAAI;CACJ,QAAQ;CACR;AAED,MAAa,qBAAkC,WAA8B;CAC5E,IAAI;CACJ;CACA;;;;;;;AAQD,MAAa,YAAwC,OAA8B;AAClF,KAAI;AACH,SAAO,eAAkB,IAAI,CAAC;UACtB,GAAG;AAEX,SAAO,kBADOA,iCAAY,EAAE,CACW"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
//#region src/result.d.ts
|
|
2
|
+
type ResultOk<T> = {
|
|
3
|
+
ok: true;
|
|
4
|
+
result: T;
|
|
5
|
+
};
|
|
6
|
+
type ResultError<E> = {
|
|
7
|
+
ok: false;
|
|
8
|
+
error: E;
|
|
9
|
+
};
|
|
10
|
+
type Result<T, E> = ResultOk<T> | ResultError<E>;
|
|
11
|
+
declare const createResultOk: <T>(data: T) => ResultOk<T>;
|
|
12
|
+
declare const createResultError: <E = unknown>(error: E) => ResultError<E>;
|
|
13
|
+
declare const toResult: <T, E extends Error = Error>(fn: () => T) => Result<T, E>;
|
|
14
|
+
//#endregion
|
|
15
|
+
export { Result, ResultError, ResultOk, createResultError, createResultOk, toResult };
|
|
16
|
+
//# sourceMappingURL=result.d.cts.map
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
//#region src/result.d.ts
|
|
2
|
+
type ResultOk<T> = {
|
|
3
|
+
ok: true;
|
|
4
|
+
result: T;
|
|
5
|
+
};
|
|
6
|
+
type ResultError<E> = {
|
|
7
|
+
ok: false;
|
|
8
|
+
error: E;
|
|
9
|
+
};
|
|
10
|
+
type Result<T, E> = ResultOk<T> | ResultError<E>;
|
|
11
|
+
declare const createResultOk: <T>(data: T) => ResultOk<T>;
|
|
12
|
+
declare const createResultError: <E = unknown>(error: E) => ResultError<E>;
|
|
13
|
+
declare const toResult: <T, E extends Error = Error>(fn: () => T) => Result<T, E>;
|
|
14
|
+
//#endregion
|
|
15
|
+
export { Result, ResultError, ResultOk, createResultError, createResultOk, toResult };
|
|
16
|
+
//# sourceMappingURL=result.d.mts.map
|
package/dist/result.mjs
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { t as ensureError } from "./ensure-error.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/result.ts
|
|
4
|
+
const createResultOk = (data) => ({
|
|
5
|
+
ok: true,
|
|
6
|
+
result: data
|
|
7
|
+
});
|
|
8
|
+
const createResultError = (error) => ({
|
|
9
|
+
ok: false,
|
|
10
|
+
error
|
|
11
|
+
});
|
|
12
|
+
/**
|
|
13
|
+
* Executes the given function and converts it to a Result object.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* const result = toResult(() => fs.writeFileSync('file.txt', 'Hello, World!'));
|
|
17
|
+
*/
|
|
18
|
+
const toResult = (fn) => {
|
|
19
|
+
try {
|
|
20
|
+
return createResultOk(fn());
|
|
21
|
+
} catch (e) {
|
|
22
|
+
return createResultError(ensureError(e));
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
//#endregion
|
|
27
|
+
export { createResultError, createResultOk, toResult };
|
|
28
|
+
//# sourceMappingURL=result.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"result.mjs","names":[],"sources":["../src/result.ts"],"sourcesContent":["import { ensureError } from './errors/ensure-error';\n\nexport type ResultOk<T> = { ok: true; result: T };\nexport type ResultError<E> = { ok: false; error: E };\nexport type Result<T, E> = ResultOk<T> | ResultError<E>;\n\nexport const createResultOk = <T>(data: T): ResultOk<T> => ({\n\tok: true,\n\tresult: data,\n});\n\nexport const createResultError = <E = unknown>(error: E): ResultError<E> => ({\n\tok: false,\n\terror,\n});\n\n/**\n * Executes the given function and converts it to a Result object.\n *\n * @example\n * const result = toResult(() => fs.writeFileSync('file.txt', 'Hello, World!'));\n */\nexport const toResult = <T, E extends Error = Error>(fn: () => T): Result<T, E> => {\n\ttry {\n\t\treturn createResultOk<T>(fn());\n\t} catch (e) {\n\t\tconst error = ensureError(e);\n\t\treturn createResultError<E>(error as E);\n\t}\n};\n"],"mappings":";;;AAMA,MAAa,kBAAqB,UAA0B;CAC3D,IAAI;CACJ,QAAQ;CACR;AAED,MAAa,qBAAkC,WAA8B;CAC5E,IAAI;CACJ;CACA;;;;;;;AAQD,MAAa,YAAwC,OAA8B;AAClF,KAAI;AACH,SAAO,eAAkB,IAAI,CAAC;UACtB,GAAG;AAEX,SAAO,kBADO,YAAY,EAAE,CACW"}
|
package/dist/retry.cjs
CHANGED
|
@@ -1,3 +1,40 @@
|
|
|
1
|
-
const require_retry = require('./retry2.cjs');
|
|
2
1
|
|
|
3
|
-
|
|
2
|
+
//#region src/retry.ts
|
|
3
|
+
/**
|
|
4
|
+
* A utility that retries a function every `interval` milliseconds
|
|
5
|
+
* until the function returns true or the maximum number of retries is reached.
|
|
6
|
+
*
|
|
7
|
+
* @param fn - A function that returns a boolean or a Promise resolving to a boolean.
|
|
8
|
+
* @param interval - The time interval (in milliseconds) between each retry. Defaults to 1000.
|
|
9
|
+
* @param maxRetries - The maximum number of retry attempts. Defaults to 3.
|
|
10
|
+
* @param backoff - The backoff strategy to use: 'linear', 'exponential', or null.
|
|
11
|
+
* @returns {Promise<boolean>} - A promise that resolves to:
|
|
12
|
+
* - true: If the function returns true before reaching maxRetries.
|
|
13
|
+
* - false: If the function never returns true or if an error occurs.
|
|
14
|
+
*/
|
|
15
|
+
async function retry(fn, interval = 1e3, maxRetries = 3, backoff = "linear") {
|
|
16
|
+
let attempt = 0;
|
|
17
|
+
while (attempt < maxRetries) {
|
|
18
|
+
attempt++;
|
|
19
|
+
try {
|
|
20
|
+
if (await fn()) return true;
|
|
21
|
+
} catch (error) {
|
|
22
|
+
console.error("Error during retry:", error);
|
|
23
|
+
throw error;
|
|
24
|
+
}
|
|
25
|
+
if (attempt < maxRetries) {
|
|
26
|
+
let computedInterval = interval;
|
|
27
|
+
if (backoff === "linear") computedInterval = interval * attempt;
|
|
28
|
+
else if (backoff === "exponential") {
|
|
29
|
+
computedInterval = Math.pow(2, attempt - 1) * interval;
|
|
30
|
+
computedInterval = Math.min(computedInterval, 3e4);
|
|
31
|
+
}
|
|
32
|
+
await new Promise((resolve) => setTimeout(resolve, computedInterval));
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
return false;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
//#endregion
|
|
39
|
+
exports.retry = retry;
|
|
40
|
+
//# sourceMappingURL=retry.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"retry.cjs","names":[],"sources":["../src/retry.ts"],"sourcesContent":["type RetryFn = () => boolean | Promise<boolean>;\n\n/**\n * A utility that retries a function every `interval` milliseconds\n * until the function returns true or the maximum number of retries is reached.\n *\n * @param fn - A function that returns a boolean or a Promise resolving to a boolean.\n * @param interval - The time interval (in milliseconds) between each retry. Defaults to 1000.\n * @param maxRetries - The maximum number of retry attempts. Defaults to 3.\n * @param backoff - The backoff strategy to use: 'linear', 'exponential', or null.\n * @returns {Promise<boolean>} - A promise that resolves to:\n * - true: If the function returns true before reaching maxRetries.\n * - false: If the function never returns true or if an error occurs.\n */\nexport async function retry(\n\tfn: RetryFn,\n\tinterval: number = 1000,\n\tmaxRetries: number = 3,\n\tbackoff: 'exponential' | 'linear' | null = 'linear',\n): Promise<boolean> {\n\tlet attempt = 0;\n\n\twhile (attempt < maxRetries) {\n\t\tattempt++;\n\t\ttry {\n\t\t\tconst result = await fn();\n\t\t\tif (result) {\n\t\t\t\treturn true;\n\t\t\t}\n\t\t} catch (error) {\n\t\t\tconsole.error('Error during retry:', error);\n\t\t\tthrow error;\n\t\t}\n\n\t\t// Wait for the specified interval before the next attempt, if any attempts remain.\n\t\tif (attempt < maxRetries) {\n\t\t\tlet computedInterval = interval;\n\n\t\t\tif (backoff === 'linear') {\n\t\t\t\tcomputedInterval = interval * attempt;\n\t\t\t} else if (backoff === 'exponential') {\n\t\t\t\tcomputedInterval = Math.pow(2, attempt - 1) * interval;\n\t\t\t\tcomputedInterval = Math.min(computedInterval, 30000); // Cap the maximum interval to 30 seconds\n\t\t\t}\n\n\t\t\tawait new Promise<void>((resolve) => setTimeout(resolve, computedInterval));\n\t\t}\n\t}\n\n\treturn false;\n}\n"],"mappings":";;;;;;;;;;;;;;AAcA,eAAsB,MACrB,IACA,WAAmB,KACnB,aAAqB,GACrB,UAA2C,UACxB;CACnB,IAAI,UAAU;AAEd,QAAO,UAAU,YAAY;AAC5B;AACA,MAAI;AAEH,OADe,MAAM,IAAI,CAExB,QAAO;WAEA,OAAO;AACf,WAAQ,MAAM,uBAAuB,MAAM;AAC3C,SAAM;;AAIP,MAAI,UAAU,YAAY;GACzB,IAAI,mBAAmB;AAEvB,OAAI,YAAY,SACf,oBAAmB,WAAW;YACpB,YAAY,eAAe;AACrC,uBAAmB,KAAK,IAAI,GAAG,UAAU,EAAE,GAAG;AAC9C,uBAAmB,KAAK,IAAI,kBAAkB,IAAM;;AAGrD,SAAM,IAAI,SAAe,YAAY,WAAW,SAAS,iBAAiB,CAAC;;;AAI7E,QAAO"}
|
package/dist/retry.d.cts
CHANGED
|
@@ -1,2 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
//#region src/retry.d.ts
|
|
2
|
+
type RetryFn = () => boolean | Promise<boolean>;
|
|
3
|
+
declare function retry(fn: RetryFn, interval?: number, maxRetries?: number, backoff?: 'exponential' | 'linear' | null): Promise<boolean>;
|
|
4
|
+
//#endregion
|
|
5
|
+
export { retry };
|
|
6
|
+
//# sourceMappingURL=retry.d.cts.map
|
package/dist/retry.d.mts
CHANGED
|
@@ -1,2 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
//#region src/retry.d.ts
|
|
2
|
+
type RetryFn = () => boolean | Promise<boolean>;
|
|
3
|
+
declare function retry(fn: RetryFn, interval?: number, maxRetries?: number, backoff?: 'exponential' | 'linear' | null): Promise<boolean>;
|
|
4
|
+
//#endregion
|
|
5
|
+
export { retry };
|
|
6
|
+
//# sourceMappingURL=retry.d.mts.map
|
package/dist/retry.mjs
CHANGED
|
@@ -1,3 +1,39 @@
|
|
|
1
|
-
|
|
1
|
+
//#region src/retry.ts
|
|
2
|
+
/**
|
|
3
|
+
* A utility that retries a function every `interval` milliseconds
|
|
4
|
+
* until the function returns true or the maximum number of retries is reached.
|
|
5
|
+
*
|
|
6
|
+
* @param fn - A function that returns a boolean or a Promise resolving to a boolean.
|
|
7
|
+
* @param interval - The time interval (in milliseconds) between each retry. Defaults to 1000.
|
|
8
|
+
* @param maxRetries - The maximum number of retry attempts. Defaults to 3.
|
|
9
|
+
* @param backoff - The backoff strategy to use: 'linear', 'exponential', or null.
|
|
10
|
+
* @returns {Promise<boolean>} - A promise that resolves to:
|
|
11
|
+
* - true: If the function returns true before reaching maxRetries.
|
|
12
|
+
* - false: If the function never returns true or if an error occurs.
|
|
13
|
+
*/
|
|
14
|
+
async function retry(fn, interval = 1e3, maxRetries = 3, backoff = "linear") {
|
|
15
|
+
let attempt = 0;
|
|
16
|
+
while (attempt < maxRetries) {
|
|
17
|
+
attempt++;
|
|
18
|
+
try {
|
|
19
|
+
if (await fn()) return true;
|
|
20
|
+
} catch (error) {
|
|
21
|
+
console.error("Error during retry:", error);
|
|
22
|
+
throw error;
|
|
23
|
+
}
|
|
24
|
+
if (attempt < maxRetries) {
|
|
25
|
+
let computedInterval = interval;
|
|
26
|
+
if (backoff === "linear") computedInterval = interval * attempt;
|
|
27
|
+
else if (backoff === "exponential") {
|
|
28
|
+
computedInterval = Math.pow(2, attempt - 1) * interval;
|
|
29
|
+
computedInterval = Math.min(computedInterval, 3e4);
|
|
30
|
+
}
|
|
31
|
+
await new Promise((resolve) => setTimeout(resolve, computedInterval));
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
return false;
|
|
35
|
+
}
|
|
2
36
|
|
|
3
|
-
|
|
37
|
+
//#endregion
|
|
38
|
+
export { retry };
|
|
39
|
+
//# sourceMappingURL=retry.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"retry.mjs","names":[],"sources":["../src/retry.ts"],"sourcesContent":["type RetryFn = () => boolean | Promise<boolean>;\n\n/**\n * A utility that retries a function every `interval` milliseconds\n * until the function returns true or the maximum number of retries is reached.\n *\n * @param fn - A function that returns a boolean or a Promise resolving to a boolean.\n * @param interval - The time interval (in milliseconds) between each retry. Defaults to 1000.\n * @param maxRetries - The maximum number of retry attempts. Defaults to 3.\n * @param backoff - The backoff strategy to use: 'linear', 'exponential', or null.\n * @returns {Promise<boolean>} - A promise that resolves to:\n * - true: If the function returns true before reaching maxRetries.\n * - false: If the function never returns true or if an error occurs.\n */\nexport async function retry(\n\tfn: RetryFn,\n\tinterval: number = 1000,\n\tmaxRetries: number = 3,\n\tbackoff: 'exponential' | 'linear' | null = 'linear',\n): Promise<boolean> {\n\tlet attempt = 0;\n\n\twhile (attempt < maxRetries) {\n\t\tattempt++;\n\t\ttry {\n\t\t\tconst result = await fn();\n\t\t\tif (result) {\n\t\t\t\treturn true;\n\t\t\t}\n\t\t} catch (error) {\n\t\t\tconsole.error('Error during retry:', error);\n\t\t\tthrow error;\n\t\t}\n\n\t\t// Wait for the specified interval before the next attempt, if any attempts remain.\n\t\tif (attempt < maxRetries) {\n\t\t\tlet computedInterval = interval;\n\n\t\t\tif (backoff === 'linear') {\n\t\t\t\tcomputedInterval = interval * attempt;\n\t\t\t} else if (backoff === 'exponential') {\n\t\t\t\tcomputedInterval = Math.pow(2, attempt - 1) * interval;\n\t\t\t\tcomputedInterval = Math.min(computedInterval, 30000); // Cap the maximum interval to 30 seconds\n\t\t\t}\n\n\t\t\tawait new Promise<void>((resolve) => setTimeout(resolve, computedInterval));\n\t\t}\n\t}\n\n\treturn false;\n}\n"],"mappings":";;;;;;;;;;;;;AAcA,eAAsB,MACrB,IACA,WAAmB,KACnB,aAAqB,GACrB,UAA2C,UACxB;CACnB,IAAI,UAAU;AAEd,QAAO,UAAU,YAAY;AAC5B;AACA,MAAI;AAEH,OADe,MAAM,IAAI,CAExB,QAAO;WAEA,OAAO;AACf,WAAQ,MAAM,uBAAuB,MAAM;AAC3C,SAAM;;AAIP,MAAI,UAAU,YAAY;GACzB,IAAI,mBAAmB;AAEvB,OAAI,YAAY,SACf,oBAAmB,WAAW;YACpB,YAAY,eAAe;AACrC,uBAAmB,KAAK,IAAI,GAAG,UAAU,EAAE,GAAG;AAC9C,uBAAmB,KAAK,IAAI,kBAAkB,IAAM;;AAGrD,SAAM,IAAI,SAAe,YAAY,WAAW,SAAS,iBAAiB,CAAC;;;AAI7E,QAAO"}
|
package/dist/scrub-secrets.cjs
CHANGED
|
@@ -1,5 +1,45 @@
|
|
|
1
|
-
const require_scrub_secrets = require('./scrub-secrets2.cjs');
|
|
2
1
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
2
|
+
//#region src/scrub-secrets.ts
|
|
3
|
+
/**
|
|
4
|
+
* Replace common credential patterns in free-form text with `[REDACTED]`.
|
|
5
|
+
*
|
|
6
|
+
* Used before persisting or transmitting user-supplied text (telemetry
|
|
7
|
+
* excerpts, eval report HTML, free-form feedback) where keys/tokens
|
|
8
|
+
* accidentally pasted into prompts or command lines could otherwise leak
|
|
9
|
+
* downstream.
|
|
10
|
+
*
|
|
11
|
+
* Conservative by design: matches well-known prefixed tokens, explicit
|
|
12
|
+
* `key=value` pairs, and quoted JSON/JS-object fields with sensitive
|
|
13
|
+
* names. We don't attempt to redact arbitrary long opaque strings — false
|
|
14
|
+
* positives on file paths, IDs, or base64 payloads would make the output
|
|
15
|
+
* unreadable.
|
|
16
|
+
*/
|
|
17
|
+
const SECRET_KEYS = "password|passwd|secret|credentials?|api[_-]?key|authorization|access[_-]?token|refresh[_-]?token|id[_-]?token|session[_-]?token|auth[_-]?token";
|
|
18
|
+
const SECRET_VALUE_PATTERNS = [
|
|
19
|
+
/-----BEGIN (?:RSA |EC |DSA |OPENSSH |PGP )?PRIVATE KEY-----[\s\S]*?-----END (?:RSA |EC |DSA |OPENSSH |PGP )?PRIVATE KEY-----/g,
|
|
20
|
+
/\beyJ[A-Za-z0-9_-]+\.eyJ[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+/g,
|
|
21
|
+
/\b(?:Bearer|Basic|Token)\s+[A-Za-z0-9._~+/=-]{12,}/gi,
|
|
22
|
+
/\bsk-(?:ant-|proj-)?[A-Za-z0-9_-]{16,}/g,
|
|
23
|
+
/\b(?:sk|rk|pk)_(?:live|test)_[A-Za-z0-9]{16,}/g,
|
|
24
|
+
/\bAIza[0-9A-Za-z_-]{35}\b/g,
|
|
25
|
+
/\bxox[abprso]-[A-Za-z0-9-]{10,}/g,
|
|
26
|
+
/\bgh[psoru]_[A-Za-z0-9]{20,}/g,
|
|
27
|
+
/\bgithub_pat_[A-Za-z0-9_]{22,}/g,
|
|
28
|
+
/\bAKIA[0-9A-Z]{16}\b/g,
|
|
29
|
+
/\b(?:bot)?\d{8,10}:[A-Za-z0-9_-]{35}\b/g,
|
|
30
|
+
/(?<=:\/\/)[^\s:/@]+:[^\s:/@]+(?=@)/g,
|
|
31
|
+
new RegExp(`"(?:${SECRET_KEYS})"\\s*:\\s*"(?!\\[(?:redacted|REDACTED)(?::[^"\\]]*)?\\]")(?:\\\\.|[^"\\r\\n])*"`, "gi"),
|
|
32
|
+
new RegExp(`'(?:${SECRET_KEYS})'\\s*:\\s*'(?!\\[(?:redacted|REDACTED)(?::[^'\\]]*)?\\]')(?:\\\\.|[^'\\r\\n])*'`, "gi"),
|
|
33
|
+
new RegExp(`(?<!\\[(?:redacted|REDACTED):)\\b(?:${SECRET_KEYS})\\s*[:=]\\s*(?!\\[?(?:redacted|REDACTED)\\b)\\S+`, "gi")
|
|
34
|
+
];
|
|
35
|
+
function scrubSecretsInText(input) {
|
|
36
|
+
let out = input;
|
|
37
|
+
for (const pattern of SECRET_VALUE_PATTERNS) out = out.replace(pattern, "[REDACTED]");
|
|
38
|
+
return out;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
//#endregion
|
|
42
|
+
exports.SECRET_KEYS = SECRET_KEYS;
|
|
43
|
+
exports.SECRET_VALUE_PATTERNS = SECRET_VALUE_PATTERNS;
|
|
44
|
+
exports.scrubSecretsInText = scrubSecretsInText;
|
|
45
|
+
//# sourceMappingURL=scrub-secrets.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scrub-secrets.cjs","names":["SECRET_VALUE_PATTERNS: readonly RegExp[]"],"sources":["../src/scrub-secrets.ts"],"sourcesContent":["/**\n * Replace common credential patterns in free-form text with `[REDACTED]`.\n *\n * Used before persisting or transmitting user-supplied text (telemetry\n * excerpts, eval report HTML, free-form feedback) where keys/tokens\n * accidentally pasted into prompts or command lines could otherwise leak\n * downstream.\n *\n * Conservative by design: matches well-known prefixed tokens, explicit\n * `key=value` pairs, and quoted JSON/JS-object fields with sensitive\n * names. We don't attempt to redact arbitrary long opaque strings — false\n * positives on file paths, IDs, or base64 payloads would make the output\n * unreadable.\n */\nexport const SECRET_KEYS =\n\t'password|passwd|secret|credentials?|api[_-]?key|authorization|access[_-]?token|refresh[_-]?token|id[_-]?token|session[_-]?token|auth[_-]?token';\n\nexport const SECRET_VALUE_PATTERNS: readonly RegExp[] = [\n\t// PEM private-key blocks (RSA/EC/DSA/OpenSSH/PGP). Whole block, multiline.\n\t/-----BEGIN (?:RSA |EC |DSA |OPENSSH |PGP )?PRIVATE KEY-----[\\s\\S]*?-----END (?:RSA |EC |DSA |OPENSSH |PGP )?PRIVATE KEY-----/g,\n\t// JWTs: `eyJ<header>.eyJ<payload>.<signature>` (both leading segments are\n\t// base64url of a `{\"` object, which makes this highly distinctive).\n\t/\\beyJ[A-Za-z0-9_-]+\\.eyJ[A-Za-z0-9_-]+\\.[A-Za-z0-9_-]+/g,\n\t// Authorization-header substrings: `Bearer <token>`, `Basic <token>`, `Token <token>`\n\t/\\b(?:Bearer|Basic|Token)\\s+[A-Za-z0-9._~+/=-]{12,}/gi,\n\t// OpenAI / Anthropic API keys\n\t/\\bsk-(?:ant-|proj-)?[A-Za-z0-9_-]{16,}/g,\n\t// Stripe secret/restricted/publishable keys (`sk_live_…`, `rk_test_…`, …)\n\t/\\b(?:sk|rk|pk)_(?:live|test)_[A-Za-z0-9]{16,}/g,\n\t// Google API keys\n\t/\\bAIza[0-9A-Za-z_-]{35}\\b/g,\n\t// Slack tokens (xoxb, xoxp, xoxa, xoxr, xoxs, xoxo)\n\t/\\bxox[abprso]-[A-Za-z0-9-]{10,}/g,\n\t// GitHub tokens (ghp, ghs, gho, ghr, ghu)\n\t/\\bgh[psoru]_[A-Za-z0-9]{20,}/g,\n\t// GitHub fine-grained personal access tokens\n\t/\\bgithub_pat_[A-Za-z0-9_]{22,}/g,\n\t// AWS access key id\n\t/\\bAKIA[0-9A-Z]{16}\\b/g,\n\t// Telegram bot token (`<bot id>:<35-char secret>`, also inside `/bot…/` URLs)\n\t/\\b(?:bot)?\\d{8,10}:[A-Za-z0-9_-]{35}\\b/g,\n\t// Credentials embedded in a URL: `scheme://user:password@` — redact the userinfo.\n\t/(?<=:\\/\\/)[^\\s:/@]+:[^\\s:/@]+(?=@)/g,\n\t// JSON-shaped `\"key\": \"value\"` — matches the quoted field as a whole.\n\t// Run before the loose pattern so nested objects like\n\t// `{\"credentials\": {\"apiKey\": \"...\"}}` don't have the outer key consume\n\t// the inner key on its way to a non-quoted (object) value. The value\n\t// body uses the standard JSON-string idiom `(?:\\\\.|[^\"\\r\\n])*` so an\n\t// escaped quote inside the value (`\"abc\\\"def\"`) doesn't end the match\n\t// early and leak the rest of the secret. The negative lookahead skips\n\t// values that are already a `[redacted]` / `[REDACTED]` / typed\n\t// `[REDACTED:<type>:<index>]` placeholder so this stays idempotent when\n\t// chained behind upstream object-walking redaction (langsmith trace\n\t// payloads, mcp-browser markers).\n\tnew RegExp(\n\t\t`\"(?:${SECRET_KEYS})\"\\\\s*:\\\\s*\"(?!\\\\[(?:redacted|REDACTED)(?::[^\"\\\\]]*)?\\\\]\")(?:\\\\\\\\.|[^\"\\\\r\\\\n])*\"`,\n\t\t'gi',\n\t),\n\t// JS-object-shaped `'key': 'value'`\n\tnew RegExp(\n\t\t`'(?:${SECRET_KEYS})'\\\\s*:\\\\s*'(?!\\\\[(?:redacted|REDACTED)(?::[^'\\\\]]*)?\\\\]')(?:\\\\\\\\.|[^'\\\\r\\\\n])*'`,\n\t\t'gi',\n\t),\n\t// Generic `password=...` / `api_key=...` / `secret=...` style assignments.\n\t// The negative lookbehind skips a keyword sitting at the `<type>` position of\n\t// an upstream `[REDACTED:<type>:<index>]` marker (e.g. mcp-browser output), so\n\t// the `secret:1]` tail isn't re-matched into a nested `[REDACTED:[REDACTED]`.\n\t// Checking only the `[REDACTED:` prefix suffices: inside a marker a keyword can\n\t// only start a `\\b` match right after that prefix — every other keyword-shaped\n\t// substring is preceded by `_` (snake_case type slug) or a digit, so no word\n\t// boundary opens there. The value lookahead skips values that are already a\n\t// redaction placeholder (bracketed, typed, or URL-safe bare form) — the same\n\t// idempotency convention as the quoted forms.\n\tnew RegExp(\n\t\t`(?<!\\\\[(?:redacted|REDACTED):)\\\\b(?:${SECRET_KEYS})\\\\s*[:=]\\\\s*(?!\\\\[?(?:redacted|REDACTED)\\\\b)\\\\S+`,\n\t\t'gi',\n\t),\n];\n\nexport function scrubSecretsInText(input: string): string {\n\tlet out = input;\n\tfor (const pattern of SECRET_VALUE_PATTERNS) {\n\t\tout = out.replace(pattern, '[REDACTED]');\n\t}\n\treturn out;\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAcA,MAAa,cACZ;AAED,MAAaA,wBAA2C;CAEvD;CAGA;CAEA;CAEA;CAEA;CAEA;CAEA;CAEA;CAEA;CAEA;CAEA;CAEA;CAYA,IAAI,OACH,OAAO,YAAY,mFACnB,KACA;CAED,IAAI,OACH,OAAO,YAAY,mFACnB,KACA;CAWD,IAAI,OACH,uCAAuC,YAAY,oDACnD,KACA;CACD;AAED,SAAgB,mBAAmB,OAAuB;CACzD,IAAI,MAAM;AACV,MAAK,MAAM,WAAW,sBACrB,OAAM,IAAI,QAAQ,SAAS,aAAa;AAEzC,QAAO"}
|
package/dist/scrub-secrets.d.cts
CHANGED
|
@@ -1,2 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
//#region src/scrub-secrets.d.ts
|
|
2
|
+
declare const SECRET_KEYS = "password|passwd|secret|credentials?|api[_-]?key|authorization|access[_-]?token|refresh[_-]?token|id[_-]?token|session[_-]?token|auth[_-]?token";
|
|
3
|
+
declare const SECRET_VALUE_PATTERNS: readonly RegExp[];
|
|
4
|
+
declare function scrubSecretsInText(input: string): string;
|
|
5
|
+
//#endregion
|
|
6
|
+
export { SECRET_KEYS, SECRET_VALUE_PATTERNS, scrubSecretsInText };
|
|
7
|
+
//# sourceMappingURL=scrub-secrets.d.cts.map
|
package/dist/scrub-secrets.d.mts
CHANGED
|
@@ -1,2 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
//#region src/scrub-secrets.d.ts
|
|
2
|
+
declare const SECRET_KEYS = "password|passwd|secret|credentials?|api[_-]?key|authorization|access[_-]?token|refresh[_-]?token|id[_-]?token|session[_-]?token|auth[_-]?token";
|
|
3
|
+
declare const SECRET_VALUE_PATTERNS: readonly RegExp[];
|
|
4
|
+
declare function scrubSecretsInText(input: string): string;
|
|
5
|
+
//#endregion
|
|
6
|
+
export { SECRET_KEYS, SECRET_VALUE_PATTERNS, scrubSecretsInText };
|
|
7
|
+
//# sourceMappingURL=scrub-secrets.d.mts.map
|
package/dist/scrub-secrets.mjs
CHANGED
|
@@ -1,3 +1,42 @@
|
|
|
1
|
-
|
|
1
|
+
//#region src/scrub-secrets.ts
|
|
2
|
+
/**
|
|
3
|
+
* Replace common credential patterns in free-form text with `[REDACTED]`.
|
|
4
|
+
*
|
|
5
|
+
* Used before persisting or transmitting user-supplied text (telemetry
|
|
6
|
+
* excerpts, eval report HTML, free-form feedback) where keys/tokens
|
|
7
|
+
* accidentally pasted into prompts or command lines could otherwise leak
|
|
8
|
+
* downstream.
|
|
9
|
+
*
|
|
10
|
+
* Conservative by design: matches well-known prefixed tokens, explicit
|
|
11
|
+
* `key=value` pairs, and quoted JSON/JS-object fields with sensitive
|
|
12
|
+
* names. We don't attempt to redact arbitrary long opaque strings — false
|
|
13
|
+
* positives on file paths, IDs, or base64 payloads would make the output
|
|
14
|
+
* unreadable.
|
|
15
|
+
*/
|
|
16
|
+
const SECRET_KEYS = "password|passwd|secret|credentials?|api[_-]?key|authorization|access[_-]?token|refresh[_-]?token|id[_-]?token|session[_-]?token|auth[_-]?token";
|
|
17
|
+
const SECRET_VALUE_PATTERNS = [
|
|
18
|
+
/-----BEGIN (?:RSA |EC |DSA |OPENSSH |PGP )?PRIVATE KEY-----[\s\S]*?-----END (?:RSA |EC |DSA |OPENSSH |PGP )?PRIVATE KEY-----/g,
|
|
19
|
+
/\beyJ[A-Za-z0-9_-]+\.eyJ[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+/g,
|
|
20
|
+
/\b(?:Bearer|Basic|Token)\s+[A-Za-z0-9._~+/=-]{12,}/gi,
|
|
21
|
+
/\bsk-(?:ant-|proj-)?[A-Za-z0-9_-]{16,}/g,
|
|
22
|
+
/\b(?:sk|rk|pk)_(?:live|test)_[A-Za-z0-9]{16,}/g,
|
|
23
|
+
/\bAIza[0-9A-Za-z_-]{35}\b/g,
|
|
24
|
+
/\bxox[abprso]-[A-Za-z0-9-]{10,}/g,
|
|
25
|
+
/\bgh[psoru]_[A-Za-z0-9]{20,}/g,
|
|
26
|
+
/\bgithub_pat_[A-Za-z0-9_]{22,}/g,
|
|
27
|
+
/\bAKIA[0-9A-Z]{16}\b/g,
|
|
28
|
+
/\b(?:bot)?\d{8,10}:[A-Za-z0-9_-]{35}\b/g,
|
|
29
|
+
/(?<=:\/\/)[^\s:/@]+:[^\s:/@]+(?=@)/g,
|
|
30
|
+
new RegExp(`"(?:${SECRET_KEYS})"\\s*:\\s*"(?!\\[(?:redacted|REDACTED)(?::[^"\\]]*)?\\]")(?:\\\\.|[^"\\r\\n])*"`, "gi"),
|
|
31
|
+
new RegExp(`'(?:${SECRET_KEYS})'\\s*:\\s*'(?!\\[(?:redacted|REDACTED)(?::[^'\\]]*)?\\]')(?:\\\\.|[^'\\r\\n])*'`, "gi"),
|
|
32
|
+
new RegExp(`(?<!\\[(?:redacted|REDACTED):)\\b(?:${SECRET_KEYS})\\s*[:=]\\s*(?!\\[?(?:redacted|REDACTED)\\b)\\S+`, "gi")
|
|
33
|
+
];
|
|
34
|
+
function scrubSecretsInText(input) {
|
|
35
|
+
let out = input;
|
|
36
|
+
for (const pattern of SECRET_VALUE_PATTERNS) out = out.replace(pattern, "[REDACTED]");
|
|
37
|
+
return out;
|
|
38
|
+
}
|
|
2
39
|
|
|
3
|
-
|
|
40
|
+
//#endregion
|
|
41
|
+
export { SECRET_KEYS, SECRET_VALUE_PATTERNS, scrubSecretsInText };
|
|
42
|
+
//# sourceMappingURL=scrub-secrets.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scrub-secrets.mjs","names":["SECRET_VALUE_PATTERNS: readonly RegExp[]"],"sources":["../src/scrub-secrets.ts"],"sourcesContent":["/**\n * Replace common credential patterns in free-form text with `[REDACTED]`.\n *\n * Used before persisting or transmitting user-supplied text (telemetry\n * excerpts, eval report HTML, free-form feedback) where keys/tokens\n * accidentally pasted into prompts or command lines could otherwise leak\n * downstream.\n *\n * Conservative by design: matches well-known prefixed tokens, explicit\n * `key=value` pairs, and quoted JSON/JS-object fields with sensitive\n * names. We don't attempt to redact arbitrary long opaque strings — false\n * positives on file paths, IDs, or base64 payloads would make the output\n * unreadable.\n */\nexport const SECRET_KEYS =\n\t'password|passwd|secret|credentials?|api[_-]?key|authorization|access[_-]?token|refresh[_-]?token|id[_-]?token|session[_-]?token|auth[_-]?token';\n\nexport const SECRET_VALUE_PATTERNS: readonly RegExp[] = [\n\t// PEM private-key blocks (RSA/EC/DSA/OpenSSH/PGP). Whole block, multiline.\n\t/-----BEGIN (?:RSA |EC |DSA |OPENSSH |PGP )?PRIVATE KEY-----[\\s\\S]*?-----END (?:RSA |EC |DSA |OPENSSH |PGP )?PRIVATE KEY-----/g,\n\t// JWTs: `eyJ<header>.eyJ<payload>.<signature>` (both leading segments are\n\t// base64url of a `{\"` object, which makes this highly distinctive).\n\t/\\beyJ[A-Za-z0-9_-]+\\.eyJ[A-Za-z0-9_-]+\\.[A-Za-z0-9_-]+/g,\n\t// Authorization-header substrings: `Bearer <token>`, `Basic <token>`, `Token <token>`\n\t/\\b(?:Bearer|Basic|Token)\\s+[A-Za-z0-9._~+/=-]{12,}/gi,\n\t// OpenAI / Anthropic API keys\n\t/\\bsk-(?:ant-|proj-)?[A-Za-z0-9_-]{16,}/g,\n\t// Stripe secret/restricted/publishable keys (`sk_live_…`, `rk_test_…`, …)\n\t/\\b(?:sk|rk|pk)_(?:live|test)_[A-Za-z0-9]{16,}/g,\n\t// Google API keys\n\t/\\bAIza[0-9A-Za-z_-]{35}\\b/g,\n\t// Slack tokens (xoxb, xoxp, xoxa, xoxr, xoxs, xoxo)\n\t/\\bxox[abprso]-[A-Za-z0-9-]{10,}/g,\n\t// GitHub tokens (ghp, ghs, gho, ghr, ghu)\n\t/\\bgh[psoru]_[A-Za-z0-9]{20,}/g,\n\t// GitHub fine-grained personal access tokens\n\t/\\bgithub_pat_[A-Za-z0-9_]{22,}/g,\n\t// AWS access key id\n\t/\\bAKIA[0-9A-Z]{16}\\b/g,\n\t// Telegram bot token (`<bot id>:<35-char secret>`, also inside `/bot…/` URLs)\n\t/\\b(?:bot)?\\d{8,10}:[A-Za-z0-9_-]{35}\\b/g,\n\t// Credentials embedded in a URL: `scheme://user:password@` — redact the userinfo.\n\t/(?<=:\\/\\/)[^\\s:/@]+:[^\\s:/@]+(?=@)/g,\n\t// JSON-shaped `\"key\": \"value\"` — matches the quoted field as a whole.\n\t// Run before the loose pattern so nested objects like\n\t// `{\"credentials\": {\"apiKey\": \"...\"}}` don't have the outer key consume\n\t// the inner key on its way to a non-quoted (object) value. The value\n\t// body uses the standard JSON-string idiom `(?:\\\\.|[^\"\\r\\n])*` so an\n\t// escaped quote inside the value (`\"abc\\\"def\"`) doesn't end the match\n\t// early and leak the rest of the secret. The negative lookahead skips\n\t// values that are already a `[redacted]` / `[REDACTED]` / typed\n\t// `[REDACTED:<type>:<index>]` placeholder so this stays idempotent when\n\t// chained behind upstream object-walking redaction (langsmith trace\n\t// payloads, mcp-browser markers).\n\tnew RegExp(\n\t\t`\"(?:${SECRET_KEYS})\"\\\\s*:\\\\s*\"(?!\\\\[(?:redacted|REDACTED)(?::[^\"\\\\]]*)?\\\\]\")(?:\\\\\\\\.|[^\"\\\\r\\\\n])*\"`,\n\t\t'gi',\n\t),\n\t// JS-object-shaped `'key': 'value'`\n\tnew RegExp(\n\t\t`'(?:${SECRET_KEYS})'\\\\s*:\\\\s*'(?!\\\\[(?:redacted|REDACTED)(?::[^'\\\\]]*)?\\\\]')(?:\\\\\\\\.|[^'\\\\r\\\\n])*'`,\n\t\t'gi',\n\t),\n\t// Generic `password=...` / `api_key=...` / `secret=...` style assignments.\n\t// The negative lookbehind skips a keyword sitting at the `<type>` position of\n\t// an upstream `[REDACTED:<type>:<index>]` marker (e.g. mcp-browser output), so\n\t// the `secret:1]` tail isn't re-matched into a nested `[REDACTED:[REDACTED]`.\n\t// Checking only the `[REDACTED:` prefix suffices: inside a marker a keyword can\n\t// only start a `\\b` match right after that prefix — every other keyword-shaped\n\t// substring is preceded by `_` (snake_case type slug) or a digit, so no word\n\t// boundary opens there. The value lookahead skips values that are already a\n\t// redaction placeholder (bracketed, typed, or URL-safe bare form) — the same\n\t// idempotency convention as the quoted forms.\n\tnew RegExp(\n\t\t`(?<!\\\\[(?:redacted|REDACTED):)\\\\b(?:${SECRET_KEYS})\\\\s*[:=]\\\\s*(?!\\\\[?(?:redacted|REDACTED)\\\\b)\\\\S+`,\n\t\t'gi',\n\t),\n];\n\nexport function scrubSecretsInText(input: string): string {\n\tlet out = input;\n\tfor (const pattern of SECRET_VALUE_PATTERNS) {\n\t\tout = out.replace(pattern, '[REDACTED]');\n\t}\n\treturn out;\n}\n"],"mappings":";;;;;;;;;;;;;;;AAcA,MAAa,cACZ;AAED,MAAaA,wBAA2C;CAEvD;CAGA;CAEA;CAEA;CAEA;CAEA;CAEA;CAEA;CAEA;CAEA;CAEA;CAEA;CAYA,IAAI,OACH,OAAO,YAAY,mFACnB,KACA;CAED,IAAI,OACH,OAAO,YAAY,mFACnB,KACA;CAWD,IAAI,OACH,uCAAuC,YAAY,oDACnD,KACA;CACD;AAED,SAAgB,mBAAmB,OAAuB;CACzD,IAAI,MAAM;AACV,MAAK,MAAM,WAAW,sBACrB,OAAM,IAAI,QAAQ,SAAS,aAAa;AAEzC,QAAO"}
|
|
@@ -1,3 +1,20 @@
|
|
|
1
|
-
const require_re_rank_search_results = require('../re-rank-search-results.cjs');
|
|
2
1
|
|
|
3
|
-
|
|
2
|
+
//#region src/search/re-rank-search-results.ts
|
|
3
|
+
function reRankSearchResults(searchResults, additionalFactors) {
|
|
4
|
+
return searchResults.map(({ score, item }) => {
|
|
5
|
+
return {
|
|
6
|
+
score: score + Object.entries(additionalFactors).reduce((acc, [_, factorScores]) => {
|
|
7
|
+
const factorScore = factorScores[item.key];
|
|
8
|
+
if (factorScore) return acc + factorScore;
|
|
9
|
+
return acc;
|
|
10
|
+
}, 0),
|
|
11
|
+
item
|
|
12
|
+
};
|
|
13
|
+
}).sort((a, b) => {
|
|
14
|
+
return b.score - a.score;
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
//#endregion
|
|
19
|
+
exports.reRankSearchResults = reRankSearchResults;
|
|
20
|
+
//# sourceMappingURL=re-rank-search-results.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"re-rank-search-results.cjs","names":[],"sources":["../../src/search/re-rank-search-results.ts"],"sourcesContent":["export function reRankSearchResults<T extends { key: string }>(\n\tsearchResults: Array<{ score: number; item: T }>,\n\tadditionalFactors: Record<string, Record<string, number>>,\n): Array<{ score: number; item: T }> {\n\treturn searchResults\n\t\t.map(({ score, item }) => {\n\t\t\t// For each additional factor, we check if it exists for the item and type,\n\t\t\t// and if so, we add the score to the item's score.\n\t\t\tconst additionalScore = Object.entries(additionalFactors).reduce((acc, [_, factorScores]) => {\n\t\t\t\tconst factorScore = factorScores[item.key];\n\t\t\t\tif (factorScore) {\n\t\t\t\t\treturn acc + factorScore;\n\t\t\t\t}\n\n\t\t\t\treturn acc;\n\t\t\t}, 0);\n\n\t\t\treturn {\n\t\t\t\tscore: score + additionalScore,\n\t\t\t\titem,\n\t\t\t};\n\t\t})\n\t\t.sort((a, b) => {\n\t\t\treturn b.score - a.score;\n\t\t});\n}\n"],"mappings":";;AAAA,SAAgB,oBACf,eACA,mBACoC;AACpC,QAAO,cACL,KAAK,EAAE,OAAO,WAAW;AAYzB,SAAO;GACN,OAAO,QAVgB,OAAO,QAAQ,kBAAkB,CAAC,QAAQ,KAAK,CAAC,GAAG,kBAAkB;IAC5F,MAAM,cAAc,aAAa,KAAK;AACtC,QAAI,YACH,QAAO,MAAM;AAGd,WAAO;MACL,EAAE;GAIJ;GACA;GACA,CACD,MAAM,GAAG,MAAM;AACf,SAAO,EAAE,QAAQ,EAAE;GAClB"}
|
|
@@ -1,2 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
//#region src/search/re-rank-search-results.d.ts
|
|
2
|
+
declare function reRankSearchResults<T extends {
|
|
3
|
+
key: string;
|
|
4
|
+
}>(searchResults: Array<{
|
|
5
|
+
score: number;
|
|
6
|
+
item: T;
|
|
7
|
+
}>, additionalFactors: Record<string, Record<string, number>>): Array<{
|
|
8
|
+
score: number;
|
|
9
|
+
item: T;
|
|
10
|
+
}>;
|
|
11
|
+
//#endregion
|
|
12
|
+
export { reRankSearchResults };
|
|
13
|
+
//# sourceMappingURL=re-rank-search-results.d.cts.map
|
|
@@ -1,2 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
//#region src/search/re-rank-search-results.d.ts
|
|
2
|
+
declare function reRankSearchResults<T extends {
|
|
3
|
+
key: string;
|
|
4
|
+
}>(searchResults: Array<{
|
|
5
|
+
score: number;
|
|
6
|
+
item: T;
|
|
7
|
+
}>, additionalFactors: Record<string, Record<string, number>>): Array<{
|
|
8
|
+
score: number;
|
|
9
|
+
item: T;
|
|
10
|
+
}>;
|
|
11
|
+
//#endregion
|
|
12
|
+
export { reRankSearchResults };
|
|
13
|
+
//# sourceMappingURL=re-rank-search-results.d.mts.map
|
|
@@ -1,3 +1,19 @@
|
|
|
1
|
-
|
|
1
|
+
//#region src/search/re-rank-search-results.ts
|
|
2
|
+
function reRankSearchResults(searchResults, additionalFactors) {
|
|
3
|
+
return searchResults.map(({ score, item }) => {
|
|
4
|
+
return {
|
|
5
|
+
score: score + Object.entries(additionalFactors).reduce((acc, [_, factorScores]) => {
|
|
6
|
+
const factorScore = factorScores[item.key];
|
|
7
|
+
if (factorScore) return acc + factorScore;
|
|
8
|
+
return acc;
|
|
9
|
+
}, 0),
|
|
10
|
+
item
|
|
11
|
+
};
|
|
12
|
+
}).sort((a, b) => {
|
|
13
|
+
return b.score - a.score;
|
|
14
|
+
});
|
|
15
|
+
}
|
|
2
16
|
|
|
3
|
-
|
|
17
|
+
//#endregion
|
|
18
|
+
export { reRankSearchResults };
|
|
19
|
+
//# sourceMappingURL=re-rank-search-results.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"re-rank-search-results.mjs","names":[],"sources":["../../src/search/re-rank-search-results.ts"],"sourcesContent":["export function reRankSearchResults<T extends { key: string }>(\n\tsearchResults: Array<{ score: number; item: T }>,\n\tadditionalFactors: Record<string, Record<string, number>>,\n): Array<{ score: number; item: T }> {\n\treturn searchResults\n\t\t.map(({ score, item }) => {\n\t\t\t// For each additional factor, we check if it exists for the item and type,\n\t\t\t// and if so, we add the score to the item's score.\n\t\t\tconst additionalScore = Object.entries(additionalFactors).reduce((acc, [_, factorScores]) => {\n\t\t\t\tconst factorScore = factorScores[item.key];\n\t\t\t\tif (factorScore) {\n\t\t\t\t\treturn acc + factorScore;\n\t\t\t\t}\n\n\t\t\t\treturn acc;\n\t\t\t}, 0);\n\n\t\t\treturn {\n\t\t\t\tscore: score + additionalScore,\n\t\t\t\titem,\n\t\t\t};\n\t\t})\n\t\t.sort((a, b) => {\n\t\t\treturn b.score - a.score;\n\t\t});\n}\n"],"mappings":";AAAA,SAAgB,oBACf,eACA,mBACoC;AACpC,QAAO,cACL,KAAK,EAAE,OAAO,WAAW;AAYzB,SAAO;GACN,OAAO,QAVgB,OAAO,QAAQ,kBAAkB,CAAC,QAAQ,KAAK,CAAC,GAAG,kBAAkB;IAC5F,MAAM,cAAc,aAAa,KAAK;AACtC,QAAI,YACH,QAAO,MAAM;AAGd,WAAO;MACL,EAAE;GAIJ;GACA;GACA,CACD,MAAM,GAAG,MAAM;AACf,SAAO,EAAE,QAAQ,EAAE;GAClB"}
|