@pagepocket/lib 0.7.1 → 0.8.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.
Files changed (261) hide show
  1. package/README.md +7 -6
  2. package/dist/build-snapshot-from-bundle.d.ts +23 -0
  3. package/dist/build-snapshot-from-bundle.js +68 -0
  4. package/dist/builtin-blacklist.js +3 -6
  5. package/dist/bundle/from-network-store.d.ts +10 -0
  6. package/dist/bundle/from-network-store.js +26 -0
  7. package/dist/bundle/types.d.ts +32 -0
  8. package/dist/bundle/types.js +2 -0
  9. package/dist/capture/index.d.ts +14 -0
  10. package/dist/capture/index.js +86 -0
  11. package/dist/capture/memory-content-store.d.ts +4 -0
  12. package/dist/capture/memory-content-store.js +42 -0
  13. package/dist/capture/types.d.ts +61 -0
  14. package/dist/capture/types.js +2 -0
  15. package/dist/content-store.js +3 -8
  16. package/dist/content-type.d.ts +1 -1
  17. package/dist/content-type.js +2 -28
  18. package/dist/core/_impl/completion.d.ts +4 -0
  19. package/dist/core/_impl/completion.js +29 -0
  20. package/dist/core/_impl/content-store.d.ts +21 -0
  21. package/dist/core/_impl/content-store.js +91 -0
  22. package/dist/core/_impl/debug.d.ts +1 -0
  23. package/dist/core/_impl/debug.js +16 -0
  24. package/dist/core/_impl/inflight-tracker.d.ts +19 -0
  25. package/dist/core/_impl/inflight-tracker.js +48 -0
  26. package/dist/core/_impl/pagepocket.d.ts +27 -0
  27. package/dist/core/_impl/pagepocket.js +155 -0
  28. package/dist/core/capture/_impl/memory-content-store.d.ts +4 -0
  29. package/dist/core/capture/_impl/memory-content-store.js +42 -0
  30. package/dist/core/capture/_impl/types.d.ts +61 -0
  31. package/dist/core/capture/_impl/types.js +2 -0
  32. package/dist/core/capture/internal/memory-content-store.d.ts +4 -0
  33. package/dist/core/capture/internal/memory-content-store.js +42 -0
  34. package/dist/core/capture/internal/types.d.ts +61 -0
  35. package/dist/core/capture/internal/types.js +2 -0
  36. package/dist/core/capture/memory-content-store.d.ts +4 -0
  37. package/dist/core/capture/memory-content-store.js +38 -0
  38. package/dist/core/capture/types.d.ts +61 -0
  39. package/dist/core/capture/types.js +1 -0
  40. package/dist/core/completion.d.ts +4 -0
  41. package/dist/core/completion.js +23 -0
  42. package/dist/core/content-store.d.ts +21 -0
  43. package/dist/core/content-store.js +54 -0
  44. package/dist/core/debug.d.ts +1 -0
  45. package/dist/core/debug.js +12 -0
  46. package/dist/core/file-tree-merge.d.ts +2 -0
  47. package/dist/core/file-tree-merge.js +27 -0
  48. package/dist/core/file-tree.d.ts +36 -0
  49. package/dist/core/file-tree.js +1 -0
  50. package/dist/core/inflight-tracker.d.ts +19 -0
  51. package/dist/core/inflight-tracker.js +44 -0
  52. package/dist/core/internal/completion.d.ts +4 -0
  53. package/dist/core/internal/completion.js +29 -0
  54. package/dist/core/internal/content-store.d.ts +21 -0
  55. package/dist/core/internal/content-store.js +91 -0
  56. package/dist/core/internal/debug.d.ts +1 -0
  57. package/dist/core/internal/debug.js +16 -0
  58. package/dist/core/internal/inflight-tracker.d.ts +19 -0
  59. package/dist/core/internal/inflight-tracker.js +48 -0
  60. package/dist/core/internal/pagepocket.d.ts +27 -0
  61. package/dist/core/internal/pagepocket.js +155 -0
  62. package/dist/core/pagepocket.d.ts +38 -0
  63. package/dist/core/pagepocket.js +57 -0
  64. package/dist/core/plugin/_impl/context.d.ts +47 -0
  65. package/dist/core/plugin/_impl/context.js +142 -0
  66. package/dist/core/plugin/_impl/runner.d.ts +12 -0
  67. package/dist/core/plugin/_impl/runner.js +232 -0
  68. package/dist/core/plugin/_impl/types.d.ts +108 -0
  69. package/dist/core/plugin/_impl/types.js +2 -0
  70. package/dist/core/plugin/context.d.ts +47 -0
  71. package/dist/core/plugin/context.js +205 -0
  72. package/dist/core/plugin/internal/context.d.ts +47 -0
  73. package/dist/core/plugin/internal/context.js +142 -0
  74. package/dist/core/plugin/internal/runner.d.ts +12 -0
  75. package/dist/core/plugin/internal/runner.js +232 -0
  76. package/dist/core/plugin/internal/types.d.ts +108 -0
  77. package/dist/core/plugin/internal/types.js +2 -0
  78. package/dist/core/plugin/runner-utils.d.ts +9 -0
  79. package/dist/core/plugin/runner-utils.js +29 -0
  80. package/dist/core/plugin/runner.d.ts +12 -0
  81. package/dist/core/plugin/runner.js +118 -0
  82. package/dist/core/plugin/types.d.ts +117 -0
  83. package/dist/core/plugin/types.js +1 -0
  84. package/dist/core/runtime/types.d.ts +14 -0
  85. package/dist/core/runtime/types.js +2 -0
  86. package/dist/css-rewrite.js +1 -5
  87. package/dist/debug.d.ts +0 -1
  88. package/dist/debug.js +3 -5
  89. package/dist/files/types.d.ts +41 -0
  90. package/dist/files/types.js +2 -0
  91. package/dist/hack-html.js +20 -13
  92. package/dist/hackers/index.d.ts +1 -1
  93. package/dist/hackers/index.js +24 -27
  94. package/dist/hackers/preload-fetch.d.ts +1 -1
  95. package/dist/hackers/preload-fetch.js +1 -4
  96. package/dist/hackers/preload-xhr.d.ts +1 -1
  97. package/dist/hackers/preload-xhr.js +1 -4
  98. package/dist/hackers/replay-beacon.d.ts +1 -1
  99. package/dist/hackers/replay-beacon.js +1 -4
  100. package/dist/hackers/replay-block-text-fragment.d.ts +1 -1
  101. package/dist/hackers/replay-block-text-fragment.js +1 -4
  102. package/dist/hackers/replay-css-proxy.d.ts +1 -1
  103. package/dist/hackers/replay-css-proxy.js +9 -12
  104. package/dist/hackers/replay-dom-rewrite.d.ts +1 -1
  105. package/dist/hackers/replay-dom-rewrite.js +165 -154
  106. package/dist/hackers/replay-eventsource.d.ts +1 -1
  107. package/dist/hackers/replay-eventsource.js +1 -4
  108. package/dist/hackers/replay-fetch.d.ts +1 -1
  109. package/dist/hackers/replay-fetch.js +1 -4
  110. package/dist/hackers/replay-history-path.d.ts +1 -1
  111. package/dist/hackers/replay-history-path.js +1 -4
  112. package/dist/hackers/replay-svg-image.d.ts +1 -1
  113. package/dist/hackers/replay-svg-image.js +1 -4
  114. package/dist/hackers/replay-websocket.d.ts +1 -1
  115. package/dist/hackers/replay-websocket.js +1 -4
  116. package/dist/hackers/replay-xhr.d.ts +1 -1
  117. package/dist/hackers/replay-xhr.js +1 -4
  118. package/dist/hackers/types.js +1 -2
  119. package/dist/index.d.ts +29 -13
  120. package/dist/index.js +23 -44
  121. package/dist/kind-map.d.ts +68 -0
  122. package/dist/kind-map.js +58 -0
  123. package/dist/network-store.js +12 -1
  124. package/dist/pagepocket.d.ts +19 -4
  125. package/dist/pagepocket.js +36 -102
  126. package/dist/path-resolver.d.ts +1 -2
  127. package/dist/path-resolver.js +9 -16
  128. package/dist/plugin/builtins/build-snapshot-plugin.d.ts +5 -0
  129. package/dist/plugin/builtins/build-snapshot-plugin.js +84 -0
  130. package/dist/plugin/builtins/replace-elements-plugin.d.ts +8 -0
  131. package/dist/plugin/builtins/replace-elements-plugin.js +13 -0
  132. package/dist/plugin/builtins/to-directory-plugin.d.ts +7 -0
  133. package/dist/plugin/builtins/to-directory-plugin.js +20 -0
  134. package/dist/plugin/builtins/to-zip-plugin.d.ts +5 -0
  135. package/dist/plugin/builtins/to-zip-plugin.js +19 -0
  136. package/dist/plugin/context.d.ts +47 -0
  137. package/dist/plugin/context.js +142 -0
  138. package/dist/plugin/runner.d.ts +12 -0
  139. package/dist/plugin/runner.js +232 -0
  140. package/dist/plugin/types.d.ts +108 -0
  141. package/dist/plugin/types.js +2 -0
  142. package/dist/plugins/build-files-from-capture.d.ts +5 -0
  143. package/dist/plugins/build-files-from-capture.js +85 -0
  144. package/dist/plugins/build-warc.d.ts +5 -0
  145. package/dist/plugins/build-warc.js +225 -0
  146. package/dist/plugins/builtins/manifest.d.ts +2 -0
  147. package/dist/plugins/builtins/manifest.js +42 -0
  148. package/dist/plugins/builtins/snapshot-directory.d.ts +2 -0
  149. package/dist/plugins/builtins/snapshot-directory.js +24 -0
  150. package/dist/plugins/builtins/snapshot-zip.d.ts +2 -0
  151. package/dist/plugins/builtins/snapshot-zip.js +25 -0
  152. package/dist/plugins/capture-http-lighterceptor.d.ts +5 -0
  153. package/dist/plugins/capture-http-lighterceptor.js +85 -0
  154. package/dist/plugins/capture-http-puppeteer.d.ts +5 -0
  155. package/dist/plugins/capture-http-puppeteer.js +85 -0
  156. package/dist/plugins/host.d.ts +37 -0
  157. package/dist/plugins/host.js +105 -0
  158. package/dist/plugins/index.d.ts +6 -0
  159. package/dist/plugins/index.js +11 -0
  160. package/dist/plugins/ordering.d.ts +2 -0
  161. package/dist/plugins/ordering.js +19 -0
  162. package/dist/plugins/types.d.ts +51 -0
  163. package/dist/plugins/types.js +2 -0
  164. package/dist/preload.js +3 -7
  165. package/dist/replace-elements/actions.d.ts +5 -0
  166. package/dist/replace-elements/actions.js +86 -0
  167. package/dist/replace-elements/match.d.ts +5 -0
  168. package/dist/replace-elements/match.js +46 -0
  169. package/dist/replace-elements/normalize.d.ts +21 -0
  170. package/dist/replace-elements/normalize.js +50 -0
  171. package/dist/replace-elements.d.ts +1 -1
  172. package/dist/replace-elements.js +5 -185
  173. package/dist/replay/match-api.d.ts +10 -0
  174. package/dist/replay/match-api.js +162 -0
  175. package/dist/replay/templates/match-api-source.d.ts +1 -0
  176. package/dist/replay/templates/match-api-source.js +137 -0
  177. package/dist/replay/templates/replay-script-template.d.ts +5 -0
  178. package/dist/replay/templates/replay-script-template.js +337 -0
  179. package/dist/replay/templates/resource-proxy-script.d.ts +1 -0
  180. package/dist/replay/templates/resource-proxy-script.js +274 -0
  181. package/dist/replay-script.d.ts +3 -10
  182. package/dist/replay-script.js +11 -625
  183. package/dist/resource-filter.d.ts +1 -1
  184. package/dist/resource-filter.js +1 -5
  185. package/dist/resource-proxy/escape-percent.d.ts +1 -0
  186. package/dist/resource-proxy/escape-percent.js +12 -0
  187. package/dist/resource-proxy/multimap.d.ts +3 -0
  188. package/dist/resource-proxy/multimap.js +18 -0
  189. package/dist/resource-proxy/pathname-variants.d.ts +3 -0
  190. package/dist/resource-proxy/pathname-variants.js +54 -0
  191. package/dist/resource-proxy.d.ts +4 -2
  192. package/dist/resource-proxy.js +48 -117
  193. package/dist/resources.js +4 -42
  194. package/dist/rewrite-links/js-imports.d.ts +3 -0
  195. package/dist/rewrite-links/js-imports.js +56 -0
  196. package/dist/rewrite-links/link-rel.d.ts +2 -0
  197. package/dist/rewrite-links/link-rel.js +10 -0
  198. package/dist/rewrite-links/meta-refresh.d.ts +3 -0
  199. package/dist/rewrite-links/meta-refresh.js +22 -0
  200. package/dist/rewrite-links/skip.d.ts +1 -0
  201. package/dist/rewrite-links/skip.js +10 -0
  202. package/dist/rewrite-links/srcset.d.ts +3 -0
  203. package/dist/rewrite-links/srcset.js +63 -0
  204. package/dist/rewrite-links/url-resolve.d.ts +3 -0
  205. package/dist/rewrite-links/url-resolve.js +13 -0
  206. package/dist/rewrite-links.d.ts +3 -3
  207. package/dist/rewrite-links.js +31 -240
  208. package/dist/snapshot-builder/api.d.ts +3 -0
  209. package/dist/snapshot-builder/api.js +6 -0
  210. package/dist/snapshot-builder/build-snapshot.d.ts +3 -0
  211. package/dist/snapshot-builder/build-snapshot.js +138 -0
  212. package/dist/snapshot-builder/capture-index/index-capture.d.ts +13 -0
  213. package/dist/snapshot-builder/capture-index/index-capture.js +168 -0
  214. package/dist/snapshot-builder/capture-index/index.d.ts +2 -0
  215. package/dist/snapshot-builder/capture-index/index.js +1 -0
  216. package/dist/snapshot-builder/capture-index/types.d.ts +12 -0
  217. package/dist/snapshot-builder/capture-index/types.js +1 -0
  218. package/dist/snapshot-builder/capture-index.d.ts +12 -0
  219. package/dist/snapshot-builder/capture-index.js +173 -0
  220. package/dist/snapshot-builder/emit-document.d.ts +24 -0
  221. package/dist/snapshot-builder/emit-document.js +50 -0
  222. package/dist/snapshot-builder/grouping.d.ts +8 -0
  223. package/dist/snapshot-builder/grouping.js +87 -0
  224. package/dist/snapshot-builder/http.d.ts +6 -0
  225. package/dist/snapshot-builder/http.js +28 -0
  226. package/dist/snapshot-builder/index.d.ts +4 -0
  227. package/dist/snapshot-builder/index.js +2 -0
  228. package/dist/snapshot-builder/path-map.d.ts +3 -0
  229. package/dist/snapshot-builder/path-map.js +35 -0
  230. package/dist/snapshot-builder/resources-path.d.ts +23 -0
  231. package/dist/snapshot-builder/resources-path.js +47 -0
  232. package/dist/snapshot-builder/rewrite-resource.d.ts +18 -0
  233. package/dist/snapshot-builder/rewrite-resource.js +52 -0
  234. package/dist/snapshot-builder/types.d.ts +37 -0
  235. package/dist/snapshot-builder/types.js +2 -0
  236. package/dist/snapshot-builder.d.ts +12 -8
  237. package/dist/snapshot-builder.js +252 -27
  238. package/dist/types.d.ts +122 -78
  239. package/dist/types.js +4 -2
  240. package/dist/units/contracts-bridge.d.ts +76 -0
  241. package/dist/units/contracts-bridge.js +6 -0
  242. package/dist/units/index.d.ts +4 -0
  243. package/dist/units/index.js +2 -0
  244. package/dist/units/runner.d.ts +11 -0
  245. package/dist/units/runner.js +270 -0
  246. package/dist/units/types.d.ts +39 -0
  247. package/dist/units/types.js +1 -0
  248. package/dist/utils/streams.d.ts +2 -0
  249. package/dist/utils/streams.js +29 -0
  250. package/dist/utils.d.ts +35 -1
  251. package/dist/utils.js +107 -29
  252. package/dist/v3/contracts-bridge.d.ts +69 -0
  253. package/dist/v3/contracts-bridge.js +5 -0
  254. package/dist/v3/index.d.ts +4 -0
  255. package/dist/v3/index.js +2 -0
  256. package/dist/v3/runner.d.ts +20 -0
  257. package/dist/v3/runner.js +245 -0
  258. package/dist/v3/types.d.ts +39 -0
  259. package/dist/v3/types.js +1 -0
  260. package/dist/writers.js +3 -1
  261. package/package.json +11 -3
@@ -0,0 +1,274 @@
1
+ export const resourceProxyScript = `
2
+ const __pagepocketResourceProxy = (() => {
3
+ const stripHash = (value) => {
4
+ const input = String(value || "");
5
+ const index = input.indexOf("#");
6
+ return index === -1 ? input : input.slice(0, index);
7
+ };
8
+
9
+ const stripTrailingSlash = (value) => {
10
+ const input = String(value || "");
11
+ if (!input || input === "/") return input;
12
+ return input.endsWith("/") ? input.slice(0, -1) : input;
13
+ };
14
+
15
+ const looksAlreadyEscapedForStaticServers = (value) => {
16
+ return /%25[0-9a-fA-F]{2}/.test(String(value || ""));
17
+ };
18
+
19
+ const escapePercentForStaticServersOnce = (value) => {
20
+ const input = String(value || "");
21
+ if (!input) return input;
22
+ if (looksAlreadyEscapedForStaticServers(input)) return input;
23
+ return input.split("%").join("%25");
24
+ };
25
+
26
+ const isLikelyHostname = (value) => {
27
+ const input = String(value || "");
28
+ if (!input) return false;
29
+ if (input === "localhost") return true;
30
+ return input.includes(".");
31
+ };
32
+
33
+ const encodeEmbeddedUrlTailIfPresent = (pathname) => {
34
+ const raw = String(pathname || "");
35
+ if (!raw.includes("/http")) return null;
36
+ const parts = raw.split("/");
37
+ for (let i = 0; i < parts.length; i += 1) {
38
+ const scheme = parts[i];
39
+ if (scheme !== "http:" && scheme !== "https:") continue;
40
+ const hasDoubleSlash = parts[i + 1] === "";
41
+ const host = parts[i + 2] || "";
42
+ if (!hasDoubleSlash || !isLikelyHostname(host)) continue;
43
+ const embedded = scheme + "//" + parts.slice(i + 2).join("/");
44
+ const encoded = encodeURIComponent(embedded);
45
+ const nextParts = parts.slice(0, i).concat(encoded);
46
+ const rebuilt = nextParts.join("/") || "/";
47
+ return rebuilt.startsWith("/") ? rebuilt : "/" + rebuilt;
48
+ }
49
+ return null;
50
+ };
51
+
52
+ const makePathnameVariants = (pathname) => {
53
+ const variants = new Set();
54
+ const push = (value) => {
55
+ if (!value) return;
56
+ variants.add(value);
57
+ };
58
+
59
+ const raw = String(pathname || "");
60
+ push(raw);
61
+ push(stripTrailingSlash(raw));
62
+
63
+ const encodedTail = encodeEmbeddedUrlTailIfPresent(raw);
64
+ if (encodedTail && encodedTail !== raw) {
65
+ push(encodedTail);
66
+ push(stripTrailingSlash(encodedTail));
67
+ }
68
+
69
+ return Array.from(variants);
70
+ };
71
+
72
+ const toUrlOrNull = (value, base) => {
73
+ try {
74
+ return new URL(String(value || ""), String(base || ""));
75
+ } catch {
76
+ return null;
77
+ }
78
+ };
79
+
80
+ const getBasename = (pathname) => {
81
+ const clean = String(pathname || "").split("?")[0] || "";
82
+ const parts = clean.split("/").filter(Boolean);
83
+ return parts[parts.length - 1] || "";
84
+ };
85
+
86
+ const makeSuffixes = (pathname) => {
87
+ const parts = String(pathname || "").split("/").filter(Boolean);
88
+ const out = [];
89
+ for (let i = 0; i < parts.length; i += 1) {
90
+ out.push({ key: "/" + parts.slice(i).join("/"), depth: parts.length - i });
91
+ }
92
+ return out;
93
+ };
94
+
95
+ const toArray = (value) => {
96
+ if (!value) return [];
97
+ return Array.isArray(value) ? value : [value];
98
+ };
99
+
100
+ const addMulti = (map, key, value) => {
101
+ const existing = map.get(key);
102
+ if (!existing) {
103
+ map.set(key, value);
104
+ return;
105
+ }
106
+ if (Array.isArray(existing)) {
107
+ existing.push(value);
108
+ return;
109
+ }
110
+ map.set(key, [existing, value]);
111
+ };
112
+
113
+ const uniqByPath = (items) => {
114
+ const seen = new Set();
115
+ const out = [];
116
+ for (const item of items || []) {
117
+ const p = item && item.path;
118
+ if (!p || seen.has(p)) continue;
119
+ seen.add(p);
120
+ out.push(item);
121
+ }
122
+ return out;
123
+ };
124
+
125
+ const chooseUnique = (items, baseUrl, depth) => {
126
+ const unique = uniqByPath(items);
127
+ if (unique.length === 0) return null;
128
+ if (unique.length === 1) return unique[0];
129
+
130
+ try {
131
+ const base = new URL(String(baseUrl || ""));
132
+ const sameOrigin = unique.filter((i) => i && i.origin === base.origin);
133
+ if (sameOrigin.length === 1) {
134
+ return sameOrigin[0];
135
+ }
136
+ if (sameOrigin.length > 1) {
137
+ items = sameOrigin;
138
+ }
139
+ } catch {}
140
+
141
+ if (depth < 2) {
142
+ return null;
143
+ }
144
+
145
+ return null;
146
+ };
147
+
148
+ const buildIndex = (snapshot) => {
149
+ const byExactUrl = new Map();
150
+ const byCanonicalUrl = new Map();
151
+ const byPathnameWithSearch = new Map();
152
+ const byPathname = new Map();
153
+ const byBasename = new Map();
154
+
155
+ const canonicalizeHttpUrlForIndex = (url) => {
156
+ try {
157
+ if (!url || !url.protocol) return String(url || "");
158
+ if (url.protocol === "http:" || url.protocol === "https:") {
159
+ return "//" + url.host + (url.pathname || "") + (url.search || "");
160
+ }
161
+ return url.toString();
162
+ } catch {
163
+ return String(url || "");
164
+ }
165
+ };
166
+
167
+ for (const item of (snapshot && snapshot.items) || []) {
168
+ if (!item || !item.url || !item.path) continue;
169
+ let parsed = null;
170
+ try {
171
+ parsed = new URL(item.url);
172
+ } catch {
173
+ parsed = null;
174
+ }
175
+ if (!parsed) continue;
176
+
177
+ const pathname = parsed.pathname || "/";
178
+ const pathnameWithSearch = pathname + (parsed.search || "");
179
+ const basename = getBasename(pathname);
180
+
181
+ const indexed = {
182
+ url: parsed.toString(),
183
+ canonicalUrl: canonicalizeHttpUrlForIndex(parsed),
184
+ origin: parsed.origin,
185
+ pathname,
186
+ pathnameWithSearch,
187
+ basename,
188
+ path: item.path,
189
+ resourceType: item.resourceType,
190
+ mimeType: item.mimeType,
191
+ size: item.size
192
+ };
193
+
194
+ if (!byExactUrl.has(indexed.url)) {
195
+ byExactUrl.set(indexed.url, indexed);
196
+ }
197
+
198
+ if (!byCanonicalUrl.has(indexed.canonicalUrl)) {
199
+ byCanonicalUrl.set(indexed.canonicalUrl, indexed);
200
+ }
201
+ addMulti(byPathnameWithSearch, pathnameWithSearch, indexed);
202
+ addMulti(byPathname, pathname, indexed);
203
+ if (basename) {
204
+ addMulti(byBasename, basename, indexed);
205
+ }
206
+ }
207
+
208
+ return { byExactUrl, byCanonicalUrl, byPathnameWithSearch, byPathname, byBasename };
209
+ };
210
+
211
+ const resolveToLocalPath = (requestUrl, baseUrl, index) => {
212
+ if (!requestUrl) return null;
213
+ const abs = toUrlOrNull(String(requestUrl), baseUrl);
214
+ if (!abs) return null;
215
+
216
+ const absString = abs.toString();
217
+ const exact = index && index.byExactUrl && index.byExactUrl.get(absString);
218
+ if (exact) return escapePercentForStaticServersOnce(exact.path);
219
+
220
+ const canonicalAbs = "//" + abs.host + (abs.pathname || "") + (abs.search || "");
221
+ const canonicalExact = index && index.byCanonicalUrl && index.byCanonicalUrl.get(canonicalAbs);
222
+ if (canonicalExact) return escapePercentForStaticServersOnce(canonicalExact.path);
223
+
224
+ const withoutHash = stripHash(absString);
225
+ if (withoutHash !== absString) {
226
+ const found = index.byExactUrl.get(withoutHash);
227
+ if (found) return escapePercentForStaticServersOnce(found.path);
228
+
229
+ try {
230
+ const w = new URL(withoutHash);
231
+ const canonicalWithoutHash = "//" + w.host + (w.pathname || "") + (w.search || "");
232
+ const canonicalFound = index && index.byCanonicalUrl && index.byCanonicalUrl.get(canonicalWithoutHash);
233
+ if (canonicalFound) return escapePercentForStaticServersOnce(canonicalFound.path);
234
+ } catch {}
235
+ }
236
+
237
+ const pathname = abs.pathname || "/";
238
+ const pathnameVariants = makePathnameVariants(pathname);
239
+ const search = abs.search || "";
240
+ const pathnameWithSearchVariants = pathnameVariants.map((p) => String(p) + search);
241
+
242
+ for (const key of pathnameWithSearchVariants) {
243
+ const items = toArray(index.byPathnameWithSearch.get(key));
244
+ const chosen = chooseUnique(items, baseUrl, 99);
245
+ if (chosen) return escapePercentForStaticServersOnce(chosen.path);
246
+ }
247
+
248
+ for (const key of pathnameVariants) {
249
+ const items = toArray(index.byPathname.get(key));
250
+ const chosen = chooseUnique(items, baseUrl, 99);
251
+ if (chosen) return escapePercentForStaticServersOnce(chosen.path);
252
+ }
253
+
254
+ for (const variant of pathnameVariants) {
255
+ for (const suffix of makeSuffixes(variant)) {
256
+ const items = toArray(index.byPathname.get(suffix.key));
257
+ const chosen = chooseUnique(items, baseUrl, suffix.depth);
258
+ if (chosen) return escapePercentForStaticServersOnce(chosen.path);
259
+ }
260
+ }
261
+
262
+ const basename = getBasename(pathname);
263
+ if (basename) {
264
+ const items = toArray(index.byBasename.get(basename));
265
+ const chosen = chooseUnique(items, baseUrl, 1);
266
+ if (chosen) return escapePercentForStaticServersOnce(chosen.path);
267
+ }
268
+
269
+ return null;
270
+ };
271
+
272
+ return { buildIndex, resolveToLocalPath };
273
+ })();
274
+ `;
@@ -1,11 +1,4 @@
1
- import type { ApiRecord } from "./types";
2
- export type MatchApiOptions = {
3
- records: ApiRecord[];
4
- byKey?: Map<string, ApiRecord>;
5
- baseUrl: string;
6
- method: string;
7
- url: string;
8
- body?: unknown;
9
- };
10
- export declare function matchAPI(options: MatchApiOptions): ApiRecord | undefined;
1
+ import { matchAPI, type MatchApiOptions } from "./replay/match-api.js";
11
2
  export declare const buildReplayScript: (apiPath: string, baseUrl: string) => string;
3
+ export { matchAPI };
4
+ export type { MatchApiOptions };