pi-harness-runtime 1.1.512 → 1.1.513
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/CHANGELOG.md +91 -0
- package/footer-status.ts +112 -43
- package/harness/cookie-import-refresh.ts +60 -0
- package/harness/quota-credential-choice.ts +67 -0
- package/harness/quota-refresh-coordinator.ts +129 -0
- package/index.ts +182 -97
- package/package.json +1 -1
- package/packages/agent-policy/package.json +1 -1
- package/packages/auth/package.json +1 -1
- package/packages/autonomous-runtime/package.json +1 -1
- package/packages/checkpoint/package.json +1 -1
- package/packages/clipboard/package.json +1 -1
- package/packages/codex-watcher/package.json +1 -1
- package/packages/config-capture/package.json +1 -1
- package/packages/contracts/package.json +1 -1
- package/packages/cookie-sanitizer/dist/detect-format.d.ts +26 -12
- package/packages/cookie-sanitizer/dist/detect-format.d.ts.map +1 -1
- package/packages/cookie-sanitizer/dist/detect-format.js +54 -39
- package/packages/cookie-sanitizer/dist/detect-format.js.map +1 -1
- package/packages/cookie-sanitizer/dist/index.d.ts +9 -3
- package/packages/cookie-sanitizer/dist/index.d.ts.map +1 -1
- package/packages/cookie-sanitizer/dist/index.js +5 -3
- package/packages/cookie-sanitizer/dist/index.js.map +1 -1
- package/packages/cookie-sanitizer/dist/parse-netscape-space.d.ts +73 -0
- package/packages/cookie-sanitizer/dist/parse-netscape-space.d.ts.map +1 -0
- package/packages/cookie-sanitizer/dist/parse-netscape-space.js +154 -0
- package/packages/cookie-sanitizer/dist/parse-netscape-space.js.map +1 -0
- package/packages/cookie-sanitizer/dist/parse-netscape.d.ts +28 -1
- package/packages/cookie-sanitizer/dist/parse-netscape.d.ts.map +1 -1
- package/packages/cookie-sanitizer/dist/parse-netscape.js +50 -13
- package/packages/cookie-sanitizer/dist/parse-netscape.js.map +1 -1
- package/packages/cookie-sanitizer/dist/source-state.d.ts +56 -0
- package/packages/cookie-sanitizer/dist/source-state.d.ts.map +1 -0
- package/packages/cookie-sanitizer/dist/source-state.js +61 -0
- package/packages/cookie-sanitizer/dist/source-state.js.map +1 -0
- package/packages/cookie-sanitizer/dist/sync.d.ts +9 -0
- package/packages/cookie-sanitizer/dist/sync.d.ts.map +1 -1
- package/packages/cookie-sanitizer/dist/sync.js +47 -16
- package/packages/cookie-sanitizer/dist/sync.js.map +1 -1
- package/packages/cookie-sanitizer/dist/types.d.ts +1 -1
- package/packages/cookie-sanitizer/dist/types.d.ts.map +1 -1
- package/packages/cookie-sanitizer/package.json +1 -1
- package/packages/cookie-sanitizer/src/detect-format.ts +78 -41
- package/packages/cookie-sanitizer/src/index.ts +34 -1
- package/packages/cookie-sanitizer/src/parse-netscape-space.ts +188 -0
- package/packages/cookie-sanitizer/src/parse-netscape.ts +81 -13
- package/packages/cookie-sanitizer/src/source-state.ts +95 -0
- package/packages/cookie-sanitizer/src/sync.ts +59 -16
- package/packages/cookie-sanitizer/src/types.ts +4 -1
- package/packages/evaluation-engine/package.json +1 -1
- package/packages/event-bus/package.json +1 -1
- package/packages/event-store/package.json +1 -1
- package/packages/experience-replay/package.json +1 -1
- package/packages/file-copy-helper/package.json +1 -1
- package/packages/intent-analyzer/package.json +1 -1
- package/packages/jev-judge/package.json +1 -1
- package/packages/knowledge-retrieval/package.json +1 -1
- package/packages/learning-engine/package.json +1 -1
- package/packages/logging/package.json +1 -1
- package/packages/memory-engine/package.json +1 -1
- package/packages/notification/package.json +1 -1
- package/packages/paperclip-integration/package.json +1 -1
- package/packages/performance-optimizer/package.json +1 -1
- package/packages/privilege-broker/package.json +1 -1
- package/packages/prompt-compiler/package.json +1 -1
- package/packages/providers/package.json +1 -1
- package/packages/qdrant-skills/package.json +1 -1
- package/packages/quota-manager/package.json +1 -1
- package/packages/relay/package.json +1 -1
- package/packages/skill-mcp-client/package.json +1 -1
- package/packages/skills/package.json +1 -1
- package/packages/todo-bd-sync/package.json +1 -1
- package/packages/token-estimation/package.json +1 -1
- package/packages/tooling-preference/package.json +1 -1
- package/packages/trajectory/package.json +1 -1
- package/packages/tui/package.json +1 -1
- package/packages/two-phase-review/package.json +1 -1
- package/packages/types/package.json +1 -1
- package/packages/webmcp-tester/package.json +1 -1
- package/packages/wiki/package.json +1 -1
- package/packages/write-review/package.json +1 -1
|
@@ -1,16 +1,23 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Format detection — does the input look like Netscape
|
|
2
|
+
* Format detection — does the input look like Netscape, a space-separated
|
|
3
|
+
* Netscape export, or EditThisCookie JSON?
|
|
3
4
|
*
|
|
4
5
|
* Detection rule:
|
|
5
|
-
* -
|
|
6
|
-
* -
|
|
7
|
-
*
|
|
8
|
-
* - Otherwise
|
|
6
|
+
* - First non-blank byte is `[` or `{` → JSON
|
|
7
|
+
* - ≥ 1 tab-separated 7-column row → Netscape
|
|
8
|
+
* - ≥ 1 row that the compatible parser accepts → Netscape (space)
|
|
9
|
+
* - Otherwise → unknown
|
|
9
10
|
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
11
|
+
* The header wording is not part of the rule: an export whose header
|
|
12
|
+
* differs from the canonical wording is still a supported format when its
|
|
13
|
+
* rows are readable.
|
|
14
|
+
*
|
|
15
|
+
* SEC-001: cookie values are never copied into a return value that gets
|
|
16
|
+
* logged. A diagnostic carries counts and reason codes only — never a
|
|
17
|
+
* line, a header, a cookie name, or a cookie value.
|
|
12
18
|
*/
|
|
13
19
|
import { basename } from "node:path";
|
|
20
|
+
import { hasCompatibleRow, looksSpaceSeparated, } from "./parse-netscape-space.js";
|
|
14
21
|
const HEADER_RE = /^# Netscape HTTP Cookie File/im;
|
|
15
22
|
const MIN_TAB_COLS = 7;
|
|
16
23
|
/**
|
|
@@ -21,42 +28,24 @@ export function safeBasename(filePath) {
|
|
|
21
28
|
return basename(filePath);
|
|
22
29
|
}
|
|
23
30
|
/**
|
|
24
|
-
*
|
|
25
|
-
* Strips cookie values to avoid leaking secrets.
|
|
31
|
+
* Detect the format of cookie file text and say why it failed.
|
|
26
32
|
*
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
*/
|
|
30
|
-
export function safePreview(text, maxChars = 64) {
|
|
31
|
-
const firstLine = text
|
|
32
|
-
.split("\n")
|
|
33
|
-
.map((l) => l.trim())
|
|
34
|
-
.find((l) => l.length > 0) ?? "";
|
|
35
|
-
const redacted = firstLine
|
|
36
|
-
.split("\t")
|
|
37
|
-
.map((col, i) => (i >= 5 ? "<redacted>" : col))
|
|
38
|
-
.join("\t");
|
|
39
|
-
return redacted.length > maxChars
|
|
40
|
-
? `${redacted.slice(0, maxChars)}…`
|
|
41
|
-
: redacted;
|
|
42
|
-
}
|
|
43
|
-
/**
|
|
44
|
-
* Detect the format of cookie file text.
|
|
33
|
+
* The reason is a code. A caller that wants to tell the user what to do
|
|
34
|
+
* maps the code to a sentence; the code itself never carries content.
|
|
45
35
|
*/
|
|
46
|
-
export function
|
|
47
|
-
if (typeof text !== "string" || text.length === 0)
|
|
48
|
-
return null;
|
|
36
|
+
export function diagnoseFormat(text) {
|
|
37
|
+
if (typeof text !== "string" || text.length === 0) {
|
|
38
|
+
return { format: null, reason: "empty" };
|
|
39
|
+
}
|
|
49
40
|
const trimmed = text.trimStart();
|
|
50
41
|
const firstByte = trimmed[0];
|
|
51
42
|
// JSON heuristic — array or object at the top.
|
|
52
43
|
if (firstByte === "[" || firstByte === "{") {
|
|
53
|
-
return "edit-this-cookie-json";
|
|
54
|
-
}
|
|
55
|
-
// Netscape heuristic — header OR a tab-separated 7-column row.
|
|
56
|
-
if (HEADER_RE.test(text)) {
|
|
57
|
-
return "netscape";
|
|
44
|
+
return { format: "edit-this-cookie-json" };
|
|
58
45
|
}
|
|
59
46
|
const lines = text.split(/\r?\n/);
|
|
47
|
+
// A tab-separated row is the strict Netscape format.
|
|
48
|
+
let hasTabRow = false;
|
|
60
49
|
for (const line of lines) {
|
|
61
50
|
if (!line || (line.startsWith("#") && !line.startsWith("#HttpOnly_"))) {
|
|
62
51
|
continue;
|
|
@@ -64,12 +53,38 @@ export function detectFormat(text) {
|
|
|
64
53
|
const trimmedLine = line.startsWith("#HttpOnly_")
|
|
65
54
|
? line.slice("#HttpOnly_".length)
|
|
66
55
|
: line;
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
56
|
+
if (trimmedLine.split("\t").length >= MIN_TAB_COLS) {
|
|
57
|
+
hasTabRow = true;
|
|
58
|
+
break;
|
|
70
59
|
}
|
|
71
60
|
}
|
|
72
|
-
|
|
61
|
+
if (hasTabRow) {
|
|
62
|
+
return { format: "netscape" };
|
|
63
|
+
}
|
|
64
|
+
// The header alone is not enough: the rows decide the format.
|
|
65
|
+
if (hasCompatibleRow(text)) {
|
|
66
|
+
return { format: "netscape-space" };
|
|
67
|
+
}
|
|
68
|
+
if (HEADER_RE.test(text)) {
|
|
69
|
+
// The wording of the header matches, but no row could be read.
|
|
70
|
+
// The file claims the format; the parse reports that it holds no
|
|
71
|
+
// cookie.
|
|
72
|
+
return { format: "netscape" };
|
|
73
|
+
}
|
|
74
|
+
if (looksSpaceSeparated(text)) {
|
|
75
|
+
return { format: null, reason: "space-rows-not-valid" };
|
|
76
|
+
}
|
|
77
|
+
const hasDataLine = lines.some((line) => line.trim().length > 0 && !line.startsWith("#"));
|
|
78
|
+
return {
|
|
79
|
+
format: null,
|
|
80
|
+
reason: hasDataLine ? "tab-rows-not-valid" : "no-rows",
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Detect the format of cookie file text.
|
|
85
|
+
*/
|
|
86
|
+
export function detectFormat(text) {
|
|
87
|
+
return diagnoseFormat(text).format;
|
|
73
88
|
}
|
|
74
89
|
/**
|
|
75
90
|
* Build a DetectedFile from a path and its text contents.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"detect-format.js","sourceRoot":"","sources":["../src/detect-format.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"detect-format.js","sourceRoot":"","sources":["../src/detect-format.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;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AAC,IAAI,CAAC,CAAC;IAClC,OAAO;QACN,IAAI,EAAE,QAAQ;QACd,QAAQ,EAAE,YAAY,CAAC,QAAQ,CAAC;QAChC,MAAM;QACN,IAAI;QACJ,gEAAgE;KAChE,CAAC;AACH,CAAC"}
|
|
@@ -28,14 +28,20 @@
|
|
|
28
28
|
* watcher.start();
|
|
29
29
|
* ```
|
|
30
30
|
*/
|
|
31
|
-
export {
|
|
32
|
-
export {
|
|
31
|
+
export { inspectCookieSource, hasCookieSourceState, } from "./source-state.js";
|
|
32
|
+
export { sync, hasAnyCookieSource, inferCachePath, enumerateDropFiles, readInputFile, formatRejectionReason, DEFAULT_DROP_DIR, } from "./sync.js";
|
|
33
|
+
export { parseNetscape, parseNetscapeDetailed, serializeNetscape, } from "./parse-netscape.js";
|
|
34
|
+
export { parseNetscapeSpace, parseCompatibleRow, hasCompatibleRow, looksSpaceSeparated, } from "./parse-netscape-space.js";
|
|
33
35
|
export { parseEditThisCookieJson } from "./parse-json.js";
|
|
34
36
|
export { inferProvider, inferProviderFromFilename, inferProviderFromCookies, knownProviders, } from "./infer-provider.js";
|
|
35
37
|
export { normalize, domainMatchesProvider, isExpired, } from "./normalize.js";
|
|
36
|
-
export { detectFormat, buildDetectedFile, safeBasename,
|
|
38
|
+
export { detectFormat, diagnoseFormat, buildDetectedFile, safeBasename, } from "./detect-format.js";
|
|
37
39
|
export { atomicWriteFileSync, defaultCachePathFor, } from "./atomic-write.js";
|
|
38
40
|
export { CookieWatcher, createWatcher, defaultDropDir, } from "./watcher.js";
|
|
39
41
|
export type { CanonicalCookie, CookieFileFormat, DetectedFile, ProviderId, SyncOptions, SyncResult, WatcherEvent, } from "./types.js";
|
|
42
|
+
export type { FormatDiagnosis, FormatRejection } from "./detect-format.js";
|
|
43
|
+
export type { CookieSourceStage, CookieSourceState, InspectCookieSourceOptions, } from "./source-state.js";
|
|
44
|
+
export type { CompatibleParseResult, CompatibleRowOutcome, CompatibleRowRejection, } from "./parse-netscape-space.js";
|
|
45
|
+
export type { ParseNetscapeOptions, ParseNetscapeResult, } from "./parse-netscape.js";
|
|
40
46
|
export type { CookieWatcherConfig } from "./watcher.js";
|
|
41
47
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AAEH,OAAO,EACN,IAAI,EACJ,kBAAkB,EAClB,cAAc,EACd,kBAAkB,EAClB,aAAa,EACb,gBAAgB,GAChB,MAAM,WAAW,CAAC;AAEnB,OAAO,EACN,aAAa,EACb,iBAAiB,GACjB,MAAM,qBAAqB,CAAC;AAE7B,OAAO,EAAE,uBAAuB,EAAE,MAAM,iBAAiB,CAAC;AAE1D,OAAO,EACN,aAAa,EACb,yBAAyB,EACzB,wBAAwB,EACxB,cAAc,GACd,MAAM,qBAAqB,CAAC;AAE7B,OAAO,EACN,SAAS,EACT,qBAAqB,EACrB,SAAS,GACT,MAAM,gBAAgB,CAAC;AAExB,OAAO,EACN,YAAY,EACZ,iBAAiB,EACjB,YAAY,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AAEH,OAAO,EACN,mBAAmB,EACnB,oBAAoB,GACpB,MAAM,mBAAmB,CAAC;AAE3B,OAAO,EACN,IAAI,EACJ,kBAAkB,EAClB,cAAc,EACd,kBAAkB,EAClB,aAAa,EACb,qBAAqB,EACrB,gBAAgB,GAChB,MAAM,WAAW,CAAC;AAEnB,OAAO,EACN,aAAa,EACb,qBAAqB,EACrB,iBAAiB,GACjB,MAAM,qBAAqB,CAAC;AAE7B,OAAO,EACN,kBAAkB,EAClB,kBAAkB,EAClB,gBAAgB,EAChB,mBAAmB,GACnB,MAAM,2BAA2B,CAAC;AAEnC,OAAO,EAAE,uBAAuB,EAAE,MAAM,iBAAiB,CAAC;AAE1D,OAAO,EACN,aAAa,EACb,yBAAyB,EACzB,wBAAwB,EACxB,cAAc,GACd,MAAM,qBAAqB,CAAC;AAE7B,OAAO,EACN,SAAS,EACT,qBAAqB,EACrB,SAAS,GACT,MAAM,gBAAgB,CAAC;AAExB,OAAO,EACN,YAAY,EACZ,cAAc,EACd,iBAAiB,EACjB,YAAY,GACZ,MAAM,oBAAoB,CAAC;AAE5B,OAAO,EACN,mBAAmB,EACnB,mBAAmB,GACnB,MAAM,mBAAmB,CAAC;AAE3B,OAAO,EACN,aAAa,EACb,aAAa,EACb,cAAc,GACd,MAAM,cAAc,CAAC;AAEtB,YAAY,EACX,eAAe,EACf,gBAAgB,EAChB,YAAY,EACZ,UAAU,EACV,WAAW,EACX,UAAU,EACV,YAAY,GACZ,MAAM,YAAY,CAAC;AAEpB,YAAY,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAE3E,YAAY,EACX,iBAAiB,EACjB,iBAAiB,EACjB,0BAA0B,GAC1B,MAAM,mBAAmB,CAAC;AAE3B,YAAY,EACX,qBAAqB,EACrB,oBAAoB,EACpB,sBAAsB,GACtB,MAAM,2BAA2B,CAAC;AAEnC,YAAY,EACX,oBAAoB,EACpB,mBAAmB,GACnB,MAAM,qBAAqB,CAAC;AAE7B,YAAY,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAC"}
|
|
@@ -28,12 +28,14 @@
|
|
|
28
28
|
* watcher.start();
|
|
29
29
|
* ```
|
|
30
30
|
*/
|
|
31
|
-
export {
|
|
32
|
-
export {
|
|
31
|
+
export { inspectCookieSource, hasCookieSourceState, } from "./source-state.js";
|
|
32
|
+
export { sync, hasAnyCookieSource, inferCachePath, enumerateDropFiles, readInputFile, formatRejectionReason, DEFAULT_DROP_DIR, } from "./sync.js";
|
|
33
|
+
export { parseNetscape, parseNetscapeDetailed, serializeNetscape, } from "./parse-netscape.js";
|
|
34
|
+
export { parseNetscapeSpace, parseCompatibleRow, hasCompatibleRow, looksSpaceSeparated, } from "./parse-netscape-space.js";
|
|
33
35
|
export { parseEditThisCookieJson } from "./parse-json.js";
|
|
34
36
|
export { inferProvider, inferProviderFromFilename, inferProviderFromCookies, knownProviders, } from "./infer-provider.js";
|
|
35
37
|
export { normalize, domainMatchesProvider, isExpired, } from "./normalize.js";
|
|
36
|
-
export { detectFormat, buildDetectedFile, safeBasename,
|
|
38
|
+
export { detectFormat, diagnoseFormat, buildDetectedFile, safeBasename, } from "./detect-format.js";
|
|
37
39
|
export { atomicWriteFileSync, defaultCachePathFor, } from "./atomic-write.js";
|
|
38
40
|
export { CookieWatcher, createWatcher, defaultDropDir, } from "./watcher.js";
|
|
39
41
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AAEH,OAAO,EACN,IAAI,EACJ,kBAAkB,EAClB,cAAc,EACd,kBAAkB,EAClB,aAAa,EACb,gBAAgB,GAChB,MAAM,WAAW,CAAC;AAEnB,OAAO,EACN,aAAa,EACb,iBAAiB,GACjB,MAAM,qBAAqB,CAAC;AAE7B,OAAO,EAAE,uBAAuB,EAAE,MAAM,iBAAiB,CAAC;AAE1D,OAAO,EACN,aAAa,EACb,yBAAyB,EACzB,wBAAwB,EACxB,cAAc,GACd,MAAM,qBAAqB,CAAC;AAE7B,OAAO,EACN,SAAS,EACT,qBAAqB,EACrB,SAAS,GACT,MAAM,gBAAgB,CAAC;AAExB,OAAO,EACN,YAAY,EACZ,iBAAiB,EACjB,YAAY,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AAEH,OAAO,EACN,mBAAmB,EACnB,oBAAoB,GACpB,MAAM,mBAAmB,CAAC;AAE3B,OAAO,EACN,IAAI,EACJ,kBAAkB,EAClB,cAAc,EACd,kBAAkB,EAClB,aAAa,EACb,qBAAqB,EACrB,gBAAgB,GAChB,MAAM,WAAW,CAAC;AAEnB,OAAO,EACN,aAAa,EACb,qBAAqB,EACrB,iBAAiB,GACjB,MAAM,qBAAqB,CAAC;AAE7B,OAAO,EACN,kBAAkB,EAClB,kBAAkB,EAClB,gBAAgB,EAChB,mBAAmB,GACnB,MAAM,2BAA2B,CAAC;AAEnC,OAAO,EAAE,uBAAuB,EAAE,MAAM,iBAAiB,CAAC;AAE1D,OAAO,EACN,aAAa,EACb,yBAAyB,EACzB,wBAAwB,EACxB,cAAc,GACd,MAAM,qBAAqB,CAAC;AAE7B,OAAO,EACN,SAAS,EACT,qBAAqB,EACrB,SAAS,GACT,MAAM,gBAAgB,CAAC;AAExB,OAAO,EACN,YAAY,EACZ,cAAc,EACd,iBAAiB,EACjB,YAAY,GACZ,MAAM,oBAAoB,CAAC;AAE5B,OAAO,EACN,mBAAmB,EACnB,mBAAmB,GACnB,MAAM,mBAAmB,CAAC;AAE3B,OAAO,EACN,aAAa,EACb,aAAa,EACb,cAAc,GACd,MAAM,cAAc,CAAC"}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The compatible parser for a space-delimited cookie export.
|
|
3
|
+
*
|
|
4
|
+
* The sanitizer promised forgiving input from its first commit: "any
|
|
5
|
+
* cookie file (any name, any format)". The strict parser splits a row on
|
|
6
|
+
* tabs only, so an export whose rows are separated by spaces was
|
|
7
|
+
* rejected — even though its rows carry exactly the fields of the
|
|
8
|
+
* Netscape format. The promise and the implementation disagreed, and the
|
|
9
|
+
* implementation won until now.
|
|
10
|
+
*
|
|
11
|
+
* The variant that this parser accepts:
|
|
12
|
+
*
|
|
13
|
+
* <domain> <flag> <path> <secure> <expiry> <name> <value…>
|
|
14
|
+
*
|
|
15
|
+
* The first six fields are single tokens; the value is the rest of the
|
|
16
|
+
* line, so a value may contain spaces. A row is accepted only when every
|
|
17
|
+
* field validates. An ambiguous row is rejected, never guessed: a wrong
|
|
18
|
+
* guess would publish a cookie that the account never had.
|
|
19
|
+
*
|
|
20
|
+
* SEC-001: values live in memory only. Nothing in this module logs a
|
|
21
|
+
* value, a cookie name, or a raw line.
|
|
22
|
+
*/
|
|
23
|
+
import type { CanonicalCookie } from "./types.js";
|
|
24
|
+
/** The outcome of a single row. */
|
|
25
|
+
export type CompatibleRowOutcome = {
|
|
26
|
+
kind: "accepted";
|
|
27
|
+
cookie: CanonicalCookie;
|
|
28
|
+
} | {
|
|
29
|
+
kind: "rejected";
|
|
30
|
+
reason: CompatibleRowRejection;
|
|
31
|
+
};
|
|
32
|
+
/** Why a row was rejected. A reason code, never the row itself. */
|
|
33
|
+
export type CompatibleRowRejection = "not-a-row" | "invalid-domain" | "invalid-flag" | "invalid-path" | "invalid-secure" | "invalid-expiry" | "missing-value";
|
|
34
|
+
/** The result of a whole file. */
|
|
35
|
+
export interface CompatibleParseResult {
|
|
36
|
+
cookies: CanonicalCookie[];
|
|
37
|
+
/** Rows that were read. */
|
|
38
|
+
accepted: number;
|
|
39
|
+
/** Rows that looked like a row but did not validate. */
|
|
40
|
+
rejected: number;
|
|
41
|
+
/** Why the rows were rejected, counted per reason. */
|
|
42
|
+
rejections: Record<CompatibleRowRejection, number>;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Parse one line of a space-delimited export.
|
|
46
|
+
*
|
|
47
|
+
* Returns `null` when the line is not a row at all (an empty line or a
|
|
48
|
+
* comment). A row that is not valid returns a rejection with its reason.
|
|
49
|
+
*/
|
|
50
|
+
export declare function parseCompatibleRow(line: string): CompatibleRowOutcome | null;
|
|
51
|
+
/**
|
|
52
|
+
* Parse a whole space-delimited export.
|
|
53
|
+
*
|
|
54
|
+
* Never throws. Returns the cookies and the counts of the rows that were
|
|
55
|
+
* read and of the rows that were rejected, so a diagnostic can report the
|
|
56
|
+
* counts without the content.
|
|
57
|
+
*/
|
|
58
|
+
export declare function parseNetscapeSpace(text: string): CompatibleParseResult;
|
|
59
|
+
/**
|
|
60
|
+
* Does the text hold a row that the compatible parser accepts?
|
|
61
|
+
*
|
|
62
|
+
* Used by the detection: a file whose rows are space-separated is a
|
|
63
|
+
* supported format, even when its header wording is unusual.
|
|
64
|
+
*/
|
|
65
|
+
export declare function hasCompatibleRow(text: string): boolean;
|
|
66
|
+
/**
|
|
67
|
+
* Does the text hold a row that looks space-separated, valid or not?
|
|
68
|
+
*
|
|
69
|
+
* The diagnostic needs to tell "the rows use spaces" from "the file holds
|
|
70
|
+
* no rows at all", and it may say so without naming a cookie.
|
|
71
|
+
*/
|
|
72
|
+
export declare function looksSpaceSeparated(text: string): boolean;
|
|
73
|
+
//# sourceMappingURL=parse-netscape-space.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parse-netscape-space.d.ts","sourceRoot":"","sources":["../src/parse-netscape-space.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAEH,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAgBlD,mCAAmC;AACnC,MAAM,MAAM,oBAAoB,GAC7B;IAAE,IAAI,EAAE,UAAU,CAAC;IAAC,MAAM,EAAE,eAAe,CAAA;CAAE,GAC7C;IAAE,IAAI,EAAE,UAAU,CAAC;IAAC,MAAM,EAAE,sBAAsB,CAAA;CAAE,CAAC;AAExD,mEAAmE;AACnE,MAAM,MAAM,sBAAsB,GAC/B,WAAW,GACX,gBAAgB,GAChB,cAAc,GACd,cAAc,GACd,gBAAgB,GAChB,gBAAgB,GAChB,eAAe,CAAC;AAEnB,kCAAkC;AAClC,MAAM,WAAW,qBAAqB;IACrC,OAAO,EAAE,eAAe,EAAE,CAAC;IAC3B,2BAA2B;IAC3B,QAAQ,EAAE,MAAM,CAAC;IACjB,wDAAwD;IACxD,QAAQ,EAAE,MAAM,CAAC;IACjB,sDAAsD;IACtD,UAAU,EAAE,MAAM,CAAC,sBAAsB,EAAE,MAAM,CAAC,CAAC;CACnD;AAED;;;;;GAKG;AACH,wBAAgB,kBAAkB,CACjC,IAAI,EAAE,MAAM,GACV,oBAAoB,GAAG,IAAI,CA2C7B;AAED;;;;;;GAMG;AACH,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,MAAM,GAAG,qBAAqB,CA+BtE;AAED;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAOtD;AAED;;;;;GAKG;AACH,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAQzD"}
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The compatible parser for a space-delimited cookie export.
|
|
3
|
+
*
|
|
4
|
+
* The sanitizer promised forgiving input from its first commit: "any
|
|
5
|
+
* cookie file (any name, any format)". The strict parser splits a row on
|
|
6
|
+
* tabs only, so an export whose rows are separated by spaces was
|
|
7
|
+
* rejected — even though its rows carry exactly the fields of the
|
|
8
|
+
* Netscape format. The promise and the implementation disagreed, and the
|
|
9
|
+
* implementation won until now.
|
|
10
|
+
*
|
|
11
|
+
* The variant that this parser accepts:
|
|
12
|
+
*
|
|
13
|
+
* <domain> <flag> <path> <secure> <expiry> <name> <value…>
|
|
14
|
+
*
|
|
15
|
+
* The first six fields are single tokens; the value is the rest of the
|
|
16
|
+
* line, so a value may contain spaces. A row is accepted only when every
|
|
17
|
+
* field validates. An ambiguous row is rejected, never guessed: a wrong
|
|
18
|
+
* guess would publish a cookie that the account never had.
|
|
19
|
+
*
|
|
20
|
+
* SEC-001: values live in memory only. Nothing in this module logs a
|
|
21
|
+
* value, a cookie name, or a raw line.
|
|
22
|
+
*/
|
|
23
|
+
/** The six leading fields and the value that follows them. */
|
|
24
|
+
const ROW_RE = /^(\S+)[ \t]+(\S+)[ \t]+(\S+)[ \t]+(\S+)[ \t]+(\S+)[ \t]+(\S+)(?:[ \t](.*))?$/;
|
|
25
|
+
/** A hostname, optionally with a leading dot for the sub-domains. */
|
|
26
|
+
const DOMAIN_RE = /^\.?[a-z0-9]([a-z0-9-]*[a-z0-9])?(\.[a-z0-9]([a-z0-9-]*[a-z0-9])?)+$/i;
|
|
27
|
+
/** The Netscape flag and the secure marker are TRUE or FALSE. */
|
|
28
|
+
const BOOLEAN_RE = /^(TRUE|FALSE)$/i;
|
|
29
|
+
/** The expiry is a whole number of seconds since the epoch. */
|
|
30
|
+
const EXPIRY_RE = /^\d+$/;
|
|
31
|
+
/**
|
|
32
|
+
* Parse one line of a space-delimited export.
|
|
33
|
+
*
|
|
34
|
+
* Returns `null` when the line is not a row at all (an empty line or a
|
|
35
|
+
* comment). A row that is not valid returns a rejection with its reason.
|
|
36
|
+
*/
|
|
37
|
+
export function parseCompatibleRow(line) {
|
|
38
|
+
let text = line;
|
|
39
|
+
let httpOnly = false;
|
|
40
|
+
if (text.startsWith("#HttpOnly_")) {
|
|
41
|
+
httpOnly = true;
|
|
42
|
+
text = text.slice("#HttpOnly_".length);
|
|
43
|
+
}
|
|
44
|
+
else if (text.startsWith("#")) {
|
|
45
|
+
// A comment of the Netscape format (including the header).
|
|
46
|
+
return null;
|
|
47
|
+
}
|
|
48
|
+
if (!text.trim())
|
|
49
|
+
return null;
|
|
50
|
+
const match = ROW_RE.exec(text);
|
|
51
|
+
if (!match)
|
|
52
|
+
return { kind: "rejected", reason: "not-a-row" };
|
|
53
|
+
const [, domain, flag, cookiePath, secure, expires, name, value] = match;
|
|
54
|
+
if (!DOMAIN_RE.test(domain))
|
|
55
|
+
return { kind: "rejected", reason: "invalid-domain" };
|
|
56
|
+
if (!BOOLEAN_RE.test(flag))
|
|
57
|
+
return { kind: "rejected", reason: "invalid-flag" };
|
|
58
|
+
if (!cookiePath.startsWith("/"))
|
|
59
|
+
return { kind: "rejected", reason: "invalid-path" };
|
|
60
|
+
if (!BOOLEAN_RE.test(secure))
|
|
61
|
+
return { kind: "rejected", reason: "invalid-secure" };
|
|
62
|
+
if (!EXPIRY_RE.test(expires))
|
|
63
|
+
return { kind: "rejected", reason: "invalid-expiry" };
|
|
64
|
+
// The value is the rest of the line. A row without one carries nothing.
|
|
65
|
+
if (value === undefined || value.length === 0) {
|
|
66
|
+
return { kind: "rejected", reason: "missing-value" };
|
|
67
|
+
}
|
|
68
|
+
const expiry = Number.parseInt(expires, 10);
|
|
69
|
+
return {
|
|
70
|
+
kind: "accepted",
|
|
71
|
+
cookie: {
|
|
72
|
+
name,
|
|
73
|
+
value,
|
|
74
|
+
domain,
|
|
75
|
+
path: cookiePath,
|
|
76
|
+
expires: expiry === 0 ? undefined : expiry,
|
|
77
|
+
secure: secure.toUpperCase() === "TRUE",
|
|
78
|
+
httpOnly,
|
|
79
|
+
},
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Parse a whole space-delimited export.
|
|
84
|
+
*
|
|
85
|
+
* Never throws. Returns the cookies and the counts of the rows that were
|
|
86
|
+
* read and of the rows that were rejected, so a diagnostic can report the
|
|
87
|
+
* counts without the content.
|
|
88
|
+
*/
|
|
89
|
+
export function parseNetscapeSpace(text) {
|
|
90
|
+
const result = {
|
|
91
|
+
cookies: [],
|
|
92
|
+
accepted: 0,
|
|
93
|
+
rejected: 0,
|
|
94
|
+
rejections: {
|
|
95
|
+
"not-a-row": 0,
|
|
96
|
+
"invalid-domain": 0,
|
|
97
|
+
"invalid-flag": 0,
|
|
98
|
+
"invalid-path": 0,
|
|
99
|
+
"invalid-secure": 0,
|
|
100
|
+
"invalid-expiry": 0,
|
|
101
|
+
"missing-value": 0,
|
|
102
|
+
},
|
|
103
|
+
};
|
|
104
|
+
if (typeof text !== "string" || text.length === 0)
|
|
105
|
+
return result;
|
|
106
|
+
for (const raw of text.split(/\r?\n/)) {
|
|
107
|
+
const outcome = parseCompatibleRow(raw);
|
|
108
|
+
if (!outcome)
|
|
109
|
+
continue;
|
|
110
|
+
if (outcome.kind === "accepted") {
|
|
111
|
+
result.cookies.push(outcome.cookie);
|
|
112
|
+
result.accepted++;
|
|
113
|
+
continue;
|
|
114
|
+
}
|
|
115
|
+
result.rejected++;
|
|
116
|
+
result.rejections[outcome.reason]++;
|
|
117
|
+
}
|
|
118
|
+
return result;
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Does the text hold a row that the compatible parser accepts?
|
|
122
|
+
*
|
|
123
|
+
* Used by the detection: a file whose rows are space-separated is a
|
|
124
|
+
* supported format, even when its header wording is unusual.
|
|
125
|
+
*/
|
|
126
|
+
export function hasCompatibleRow(text) {
|
|
127
|
+
if (typeof text !== "string" || text.length === 0)
|
|
128
|
+
return false;
|
|
129
|
+
for (const raw of text.split(/\r?\n/)) {
|
|
130
|
+
const outcome = parseCompatibleRow(raw);
|
|
131
|
+
if (outcome?.kind === "accepted")
|
|
132
|
+
return true;
|
|
133
|
+
}
|
|
134
|
+
return false;
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Does the text hold a row that looks space-separated, valid or not?
|
|
138
|
+
*
|
|
139
|
+
* The diagnostic needs to tell "the rows use spaces" from "the file holds
|
|
140
|
+
* no rows at all", and it may say so without naming a cookie.
|
|
141
|
+
*/
|
|
142
|
+
export function looksSpaceSeparated(text) {
|
|
143
|
+
if (typeof text !== "string" || text.length === 0)
|
|
144
|
+
return false;
|
|
145
|
+
for (const raw of text.split(/\r?\n/)) {
|
|
146
|
+
if (!raw || raw.startsWith("#"))
|
|
147
|
+
continue;
|
|
148
|
+
if (raw.includes("\t"))
|
|
149
|
+
continue;
|
|
150
|
+
return true;
|
|
151
|
+
}
|
|
152
|
+
return false;
|
|
153
|
+
}
|
|
154
|
+
//# sourceMappingURL=parse-netscape-space.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parse-netscape-space.js","sourceRoot":"","sources":["../src/parse-netscape-space.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAIH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AM,GAAG,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,EAAE,CAAC;QACvC,IAAI,CAAC,GAAG,IAAI,GAAG,CAAC,UAAU,CAAC,GAAG,CAAC;YAAE,SAAS;QAC1C,IAAI,GAAG,CAAC,QAAQ,CAAC,IAAI,CAAC;YAAE,SAAS;QACjC,OAAO,IAAI,CAAC;IACb,CAAC;IACD,OAAO,KAAK,CAAC;AACd,CAAC"}
|
|
@@ -18,6 +18,26 @@
|
|
|
18
18
|
* redaction before any path-touching log line.
|
|
19
19
|
*/
|
|
20
20
|
import type { CanonicalCookie } from "./types.js";
|
|
21
|
+
/** The options of the Netscape parser. */
|
|
22
|
+
export interface ParseNetscapeOptions {
|
|
23
|
+
/**
|
|
24
|
+
* Read a row that the tab split rejects with the compatible parser.
|
|
25
|
+
*
|
|
26
|
+
* A file may hold both kinds of rows: an export that a tool wrote with
|
|
27
|
+
* tabs and rows that a human typed with spaces. The fallback reads the
|
|
28
|
+
* second kind instead of dropping it. It stays off by default, so the
|
|
29
|
+
* strict parser keeps its documented behaviour.
|
|
30
|
+
*/
|
|
31
|
+
compatibleFallback?: boolean;
|
|
32
|
+
}
|
|
33
|
+
/** The outcome of a parse: the cookies and the counts of the rows. */
|
|
34
|
+
export interface ParseNetscapeResult {
|
|
35
|
+
cookies: CanonicalCookie[];
|
|
36
|
+
/** Rows that were read. */
|
|
37
|
+
accepted: number;
|
|
38
|
+
/** Rows that looked like a row but did not validate. */
|
|
39
|
+
rejected: number;
|
|
40
|
+
}
|
|
21
41
|
/**
|
|
22
42
|
* Parse a Netscape-format cookie string into canonical records.
|
|
23
43
|
*
|
|
@@ -28,7 +48,14 @@ import type { CanonicalCookie } from "./types.js";
|
|
|
28
48
|
*
|
|
29
49
|
* Never throws; returns empty array if input is invalid.
|
|
30
50
|
*/
|
|
31
|
-
export declare function parseNetscape(text: string): CanonicalCookie[];
|
|
51
|
+
export declare function parseNetscape(text: string, options?: ParseNetscapeOptions): CanonicalCookie[];
|
|
52
|
+
/**
|
|
53
|
+
* Parse a Netscape-format cookie string and report the counts of the rows.
|
|
54
|
+
*
|
|
55
|
+
* The counts are what a diagnostic may show. The rows themselves stay in
|
|
56
|
+
* memory and never reach a log line.
|
|
57
|
+
*/
|
|
58
|
+
export declare function parseNetscapeDetailed(text: string, options?: ParseNetscapeOptions): ParseNetscapeResult;
|
|
32
59
|
/**
|
|
33
60
|
* Serialize a list of canonical cookies back to Netscape format.
|
|
34
61
|
* Used by atomic-write.ts to produce the canonical cache.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parse-netscape.d.ts","sourceRoot":"","sources":["../src/parse-netscape.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"parse-netscape.d.ts","sourceRoot":"","sources":["../src/parse-netscape.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAclD,0CAA0C;AAC1C,MAAM,WAAW,oBAAoB;IACpC;;;;;;;OAOG;IACH,kBAAkB,CAAC,EAAE,OAAO,CAAC;CAC7B;AAED,sEAAsE;AACtE,MAAM,WAAW,mBAAmB;IACnC,OAAO,EAAE,eAAe,EAAE,CAAC;IAC3B,2BAA2B;IAC3B,QAAQ,EAAE,MAAM,CAAC;IACjB,wDAAwD;IACxD,QAAQ,EAAE,MAAM,CAAC;CACjB;AAED;;;;;;;;;GASG;AACH,wBAAgB,aAAa,CAC5B,IAAI,EAAE,MAAM,EACZ,OAAO,GAAE,oBAAyB,GAChC,eAAe,EAAE,CAEnB;AAED;;;;;GAKG;AACH,wBAAgB,qBAAqB,CACpC,IAAI,EAAE,MAAM,EACZ,OAAO,GAAE,oBAAyB,GAChC,mBAAmB,CA2ErB;AAED;;;;;;;;;GASG;AACH,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,eAAe,EAAE,GAAG,MAAM,CAgBpE"}
|
|
@@ -17,6 +17,7 @@
|
|
|
17
17
|
* never be logged. The scrubber in cookie-sanitizer applies value
|
|
18
18
|
* redaction before any path-touching log line.
|
|
19
19
|
*/
|
|
20
|
+
import { parseCompatibleRow } from "./parse-netscape-space.js";
|
|
20
21
|
/**
|
|
21
22
|
* Parse a Netscape-format cookie string into canonical records.
|
|
22
23
|
*
|
|
@@ -27,9 +28,23 @@
|
|
|
27
28
|
*
|
|
28
29
|
* Never throws; returns empty array if input is invalid.
|
|
29
30
|
*/
|
|
30
|
-
export function parseNetscape(text) {
|
|
31
|
+
export function parseNetscape(text, options = {}) {
|
|
32
|
+
return parseNetscapeDetailed(text, options).cookies;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Parse a Netscape-format cookie string and report the counts of the rows.
|
|
36
|
+
*
|
|
37
|
+
* The counts are what a diagnostic may show. The rows themselves stay in
|
|
38
|
+
* memory and never reach a log line.
|
|
39
|
+
*/
|
|
40
|
+
export function parseNetscapeDetailed(text, options = {}) {
|
|
41
|
+
const result = {
|
|
42
|
+
cookies: [],
|
|
43
|
+
accepted: 0,
|
|
44
|
+
rejected: 0,
|
|
45
|
+
};
|
|
31
46
|
if (typeof text !== "string" || text.length === 0)
|
|
32
|
-
return
|
|
47
|
+
return result;
|
|
33
48
|
const rows = [];
|
|
34
49
|
const lines = text.split(/\r?\n/);
|
|
35
50
|
for (const raw of lines) {
|
|
@@ -46,11 +61,29 @@ export function parseNetscape(text) {
|
|
|
46
61
|
continue;
|
|
47
62
|
}
|
|
48
63
|
const cols = line.split("\t");
|
|
49
|
-
if (cols.length < 7)
|
|
64
|
+
if (cols.length < 7) {
|
|
65
|
+
const compatible = options.compatibleFallback
|
|
66
|
+
? parseCompatibleRow(raw)
|
|
67
|
+
: null;
|
|
68
|
+
if (compatible?.kind === "accepted") {
|
|
69
|
+
result.cookies.push(compatible.cookie);
|
|
70
|
+
result.accepted++;
|
|
71
|
+
continue;
|
|
72
|
+
}
|
|
73
|
+
if (compatible?.kind === "rejected") {
|
|
74
|
+
result.rejected++;
|
|
75
|
+
continue;
|
|
76
|
+
}
|
|
77
|
+
// The strict parser skips a row it cannot read. The count is
|
|
78
|
+
// what a diagnostic may show; the row itself stays unread.
|
|
79
|
+
result.rejected++;
|
|
50
80
|
continue;
|
|
81
|
+
}
|
|
51
82
|
const [domain, _flag, cookiePath, secure, expires, name, value] = cols;
|
|
52
|
-
if (!name || !value)
|
|
83
|
+
if (!name || !value) {
|
|
84
|
+
result.rejected++;
|
|
53
85
|
continue;
|
|
86
|
+
}
|
|
54
87
|
rows.push({
|
|
55
88
|
domain: (domain ?? "").trim(),
|
|
56
89
|
path: (cookiePath ?? "/").trim() || "/",
|
|
@@ -62,15 +95,19 @@ export function parseNetscape(text) {
|
|
|
62
95
|
});
|
|
63
96
|
}
|
|
64
97
|
// Map to CanonicalCookie shape.
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
98
|
+
for (const r of rows) {
|
|
99
|
+
result.cookies.push({
|
|
100
|
+
name: r.name,
|
|
101
|
+
value: r.value,
|
|
102
|
+
domain: r.domain,
|
|
103
|
+
path: r.path,
|
|
104
|
+
expires: r.expires === 0 ? undefined : r.expires,
|
|
105
|
+
secure: r.secure,
|
|
106
|
+
httpOnly: r.httpOnly,
|
|
107
|
+
});
|
|
108
|
+
result.accepted++;
|
|
109
|
+
}
|
|
110
|
+
return result;
|
|
74
111
|
}
|
|
75
112
|
/**
|
|
76
113
|
* Serialize a list of canonical cookies back to Netscape format.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parse-netscape.js","sourceRoot":"","sources":["../src/parse-netscape.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;
|
|
1
|
+
{"version":3,"file":"parse-net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