lurqrun 0.1.5 → 0.1.7

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 (192) hide show
  1. package/README.md +23 -13
  2. package/dist/auditHandler-JCOJSUYW.js +23 -0
  3. package/dist/bin/lurq.js +3085 -17723
  4. package/dist/browserAuth-B6G27USY.js +95 -0
  5. package/dist/cache-DKI34SVS.js +12 -0
  6. package/dist/check-2FDGUOV7.js +192 -0
  7. package/dist/checkUpgrade-F2WESBPM.js +103 -0
  8. package/dist/chunk-2VMOWSRY.js +300 -0
  9. package/dist/chunk-3GHJR7XR.js +2049 -0
  10. package/dist/chunk-3N3Q3DSW.js +214 -0
  11. package/dist/chunk-4ESO33J6.js +34 -0
  12. package/dist/chunk-4F7ZESPO.js +132 -0
  13. package/dist/chunk-4KCPOMG6.js +68 -0
  14. package/dist/chunk-4ZYCIMY4.js +155 -0
  15. package/dist/chunk-63MUJNZL.js +318 -0
  16. package/dist/chunk-6AAEVQ7I.js +6336 -0
  17. package/dist/chunk-6EQ3ARXA.js +304 -0
  18. package/dist/chunk-6L3U7DZ5.js +23 -0
  19. package/dist/chunk-AHBP533R.js +220 -0
  20. package/dist/chunk-B43LCXBM.js +223 -0
  21. package/dist/chunk-BCANRN5B.js +33 -0
  22. package/dist/chunk-BUALU27S.js +123 -0
  23. package/dist/chunk-BULZAX2U.js +1554 -0
  24. package/dist/chunk-BV32UNLL.js +154 -0
  25. package/dist/chunk-C6GLE626.js +160 -0
  26. package/dist/chunk-CIDWNUAP.js +145 -0
  27. package/dist/chunk-CUP36ND3.js +2126 -0
  28. package/dist/chunk-CW5HJ3LX.js +96 -0
  29. package/dist/chunk-DB2VF5UD.js +315 -0
  30. package/dist/chunk-DWAGCNEL.js +210 -0
  31. package/dist/chunk-EA3DP5HG.js +293 -0
  32. package/dist/chunk-ELGCAM7P.js +184 -0
  33. package/dist/chunk-FW6BD2NO.js +1915 -0
  34. package/dist/chunk-GE37NVLN.js +15 -0
  35. package/dist/chunk-GPTKSNR6.js +171 -0
  36. package/dist/chunk-GRJXQBQZ.js +793 -0
  37. package/dist/chunk-HWBBVLOT.js +92 -0
  38. package/dist/chunk-I2JUKN6Z.js +24 -0
  39. package/dist/chunk-I3M2KJXB.js +56 -0
  40. package/dist/chunk-IQ4SDKKY.js +733 -0
  41. package/dist/chunk-J5FZYN4A.js +116 -0
  42. package/dist/chunk-L6N4JFW2.js +263 -0
  43. package/dist/chunk-LBFGSSF2.js +126 -0
  44. package/dist/chunk-LEGPB7DO.js +81 -0
  45. package/dist/chunk-LO35HLQZ.js +219 -0
  46. package/dist/chunk-LRD4GBYE.js +73 -0
  47. package/dist/chunk-LUAKDHLZ.js +40 -0
  48. package/dist/chunk-LYMPYETA.js +965 -0
  49. package/dist/chunk-M6NYEXCW.js +38 -0
  50. package/dist/chunk-MHUEVBVO.js +35 -0
  51. package/dist/chunk-MYGSLK44.js +37 -0
  52. package/dist/chunk-NH5I4KHH.js +201 -0
  53. package/dist/chunk-OQS4GUSI.js +1391 -0
  54. package/dist/chunk-PSX3GIAN.js +176 -0
  55. package/dist/chunk-Q5VPF4WI.js +26 -0
  56. package/dist/chunk-QKGYDMWB.js +7409 -0
  57. package/dist/chunk-QSL6QN5X.js +115 -0
  58. package/dist/chunk-SHCEBP3J.js +107 -0
  59. package/dist/chunk-SJOVFF7B.js +201 -0
  60. package/dist/chunk-ST2X2GYN.js +373 -0
  61. package/dist/chunk-TNTXWSYA.js +19 -0
  62. package/dist/chunk-U5AT3TD4.js +2128 -0
  63. package/dist/chunk-UDVNA7EA.js +483 -0
  64. package/dist/chunk-VL2E5T2A.js +109 -0
  65. package/dist/chunk-VLRHFMGJ.js +58 -0
  66. package/dist/chunk-WHX2ZFCG.js +4048 -0
  67. package/dist/chunk-WQ23REYT.js +37 -0
  68. package/dist/chunk-XBIDMHSK.js +15425 -0
  69. package/dist/chunk-Y5GI7RL3.js +66 -0
  70. package/dist/client-IRKAMDYZ.js +15 -0
  71. package/dist/commands-FIL5ET6P.js +911 -0
  72. package/dist/compat-R3UTFQ5Q.js +201 -0
  73. package/dist/dashboardIssue-WYYMBFIB.js +192 -0
  74. package/dist/diff-GZA2774U.js +13 -0
  75. package/dist/dist-4XXIXHHZ.js +12945 -0
  76. package/dist/e2b-FVPHDULZ.js +172 -0
  77. package/dist/extract-NKGKLIVT.js +444 -0
  78. package/dist/fetch-QYTUJVG2.js +22 -0
  79. package/dist/firstTouch-QQTJH4QX.js +55 -0
  80. package/dist/handlers-GEJAVZDK.js +53 -0
  81. package/dist/http-ETPYMBGD.js +5360 -0
  82. package/dist/ingestQueue-VKN4KBIF.js +35 -0
  83. package/dist/install-EK3W2COX.js +20 -0
  84. package/dist/installSkill-VQJWJVCL.js +52 -0
  85. package/dist/inventory-5AWSLJYU.js +31 -0
  86. package/dist/local-XPZMRH5R.js +13 -0
  87. package/dist/mcp-3JHD5SUZ.js +472 -0
  88. package/dist/mcpHandlers-QFN4MCFL.js +22 -0
  89. package/dist/mcpScan-QZHWENIP.js +1871 -0
  90. package/dist/mcpScanWorkflow-JPYCBGC4.js +81 -0
  91. package/dist/mcpStack-BYJCZNIV.js +20 -0
  92. package/dist/packages-THVFMWFP.js +42 -0
  93. package/dist/plan-V4OEI3J4.js +463 -0
  94. package/dist/planView-JRXGCG2N.js +79 -0
  95. package/dist/policy-3P6BGRDN.js +115 -0
  96. package/dist/references-6N7VEPHT.js +14 -0
  97. package/dist/release-4U4ABNSJ.js +128 -0
  98. package/dist/remote-YGCXYI4V.js +32 -0
  99. package/dist/reportRuns-CKQQYLY4.js +64 -0
  100. package/dist/sandbox-MEZLAODF.js +39 -0
  101. package/dist/server-KFUD5X57.js +55 -0
  102. package/dist/surface-V62GE554.js +141 -0
  103. package/dist/surface-YL6O67W3.js +36 -0
  104. package/dist/surfaceHandlers-X2IZKA3E.js +20 -0
  105. package/dist/typecheck-X7U5ELMR.js +268 -0
  106. package/dist/types-M5JP2W3D.js +10 -0
  107. package/dist/uninstall-P7RGBX6G.js +174 -0
  108. package/dist/upgrade-NQ5IWFZB.js +596 -0
  109. package/dist/upgradePlan-A4LRKLEG.js +146 -0
  110. package/dist/userConfig-Z3GQE776.js +20 -0
  111. package/dist/watch-DGFMWUDL.js +214 -0
  112. package/package.json +41 -26
  113. package/templates/agent-rules.md +4 -4
  114. package/templates/skill-instructions.md +18 -14
  115. package/dist/bin/lurq.js.map +0 -1
  116. package/dist/index.d.ts +0 -764
  117. package/dist/index.js +0 -17992
  118. package/dist/index.js.map +0 -1
  119. package/drizzle/0000_confused_fabian_cortez.sql +0 -54
  120. package/drizzle/0001_aspiring_timeslip.sql +0 -15
  121. package/drizzle/0002_lyrical_lila_cheney.sql +0 -14
  122. package/drizzle/0003_violet_giant_girl.sql +0 -14
  123. package/drizzle/0004_slim_valeria_richards.sql +0 -15
  124. package/drizzle/0005_petite_luke_cage.sql +0 -12
  125. package/drizzle/0006_calm_nighthawk.sql +0 -3
  126. package/drizzle/0007_slimy_naoko.sql +0 -1
  127. package/drizzle/0008_peaceful_tigra.sql +0 -1
  128. package/drizzle/0009_smooth_harrier.sql +0 -10
  129. package/drizzle/0010_curved_amphibian.sql +0 -2
  130. package/drizzle/0011_compat_provenance_closures.sql +0 -11
  131. package/drizzle/0012_api_surfaces.sql +0 -9
  132. package/drizzle/0013_nice_thanos.sql +0 -1
  133. package/drizzle/0014_luxuriant_malcolm_colcord.sql +0 -10
  134. package/drizzle/0015_past_fat_cobra.sql +0 -11
  135. package/drizzle/0016_futuristic_junta.sql +0 -50
  136. package/drizzle/0017_absent_grandmaster.sql +0 -20
  137. package/drizzle/0018_rainy_proemial_gods.sql +0 -1
  138. package/drizzle/0019_dashing_korvac.sql +0 -11
  139. package/drizzle/0020_normal_vulture.sql +0 -3
  140. package/drizzle/0021_dazzling_blue_shield.sql +0 -17
  141. package/drizzle/0022_massive_ghost_rider.sql +0 -24
  142. package/drizzle/0023_next_shatterstar.sql +0 -1
  143. package/drizzle/0024_dusty_maelstrom.sql +0 -15
  144. package/drizzle/0025_gifted_harpoon.sql +0 -5
  145. package/drizzle/0026_awesome_mordo.sql +0 -1
  146. package/drizzle/0027_charming_ulik.sql +0 -2
  147. package/drizzle/0028_romantic_loners.sql +0 -2
  148. package/drizzle/0029_busy_korvac.sql +0 -16
  149. package/drizzle/0030_steady_mathemanic.sql +0 -6
  150. package/drizzle/0031_redundant_maginty.sql +0 -2
  151. package/drizzle/0032_stack_resolutions.sql +0 -14
  152. package/drizzle/0033_graceful_tyger_tiger.sql +0 -3
  153. package/drizzle/0034_api_key_scopes.sql +0 -1
  154. package/drizzle/0035_policy_audit.sql +0 -21
  155. package/drizzle/meta/0000_snapshot.json +0 -370
  156. package/drizzle/meta/0001_snapshot.json +0 -482
  157. package/drizzle/meta/0002_snapshot.json +0 -575
  158. package/drizzle/meta/0003_snapshot.json +0 -667
  159. package/drizzle/meta/0004_snapshot.json +0 -769
  160. package/drizzle/meta/0005_snapshot.json +0 -864
  161. package/drizzle/meta/0006_snapshot.json +0 -882
  162. package/drizzle/meta/0007_snapshot.json +0 -876
  163. package/drizzle/meta/0008_snapshot.json +0 -882
  164. package/drizzle/meta/0009_snapshot.json +0 -948
  165. package/drizzle/meta/0010_snapshot.json +0 -969
  166. package/drizzle/meta/0011_snapshot.json +0 -1049
  167. package/drizzle/meta/0012_snapshot.json +0 -1115
  168. package/drizzle/meta/0013_snapshot.json +0 -1121
  169. package/drizzle/meta/0014_snapshot.json +0 -1190
  170. package/drizzle/meta/0015_snapshot.json +0 -1280
  171. package/drizzle/meta/0016_snapshot.json +0 -1683
  172. package/drizzle/meta/0017_snapshot.json +0 -1834
  173. package/drizzle/meta/0018_snapshot.json +0 -1834
  174. package/drizzle/meta/0019_snapshot.json +0 -1909
  175. package/drizzle/meta/0020_snapshot.json +0 -1921
  176. package/drizzle/meta/0021_snapshot.json +0 -2045
  177. package/drizzle/meta/0022_snapshot.json +0 -2246
  178. package/drizzle/meta/0023_snapshot.json +0 -2252
  179. package/drizzle/meta/0024_snapshot.json +0 -2375
  180. package/drizzle/meta/0025_snapshot.json +0 -2407
  181. package/drizzle/meta/0026_snapshot.json +0 -2413
  182. package/drizzle/meta/0027_snapshot.json +0 -2425
  183. package/drizzle/meta/0028_snapshot.json +0 -2438
  184. package/drizzle/meta/0029_snapshot.json +0 -2546
  185. package/drizzle/meta/0030_snapshot.json +0 -2586
  186. package/drizzle/meta/0031_snapshot.json +0 -2598
  187. package/drizzle/meta/0032_snapshot.json +0 -2699
  188. package/drizzle/meta/0033_snapshot.json +0 -2712
  189. package/drizzle/meta/0034_snapshot.json +0 -2719
  190. package/drizzle/meta/0035_snapshot.json +0 -2869
  191. package/drizzle/meta/_journal.json +0 -258
  192. package/src/data/seed.json +0 -253
@@ -0,0 +1,115 @@
1
+ import { createRequire as __lurqCreateRequire } from 'node:module'; const require = __lurqCreateRequire(import.meta.url);
2
+ import {
3
+ init_esm_shims
4
+ } from "./chunk-I3M2KJXB.js";
5
+
6
+ // src/security/verdict.ts
7
+ init_esm_shims();
8
+ var SEVERE = /* @__PURE__ */ new Set(["critical", "high"]);
9
+ function describeScope(i) {
10
+ if (!i.exists) return "this name";
11
+ if (!i.subjectVersion) {
12
+ return i.subjectInstalled ? "the installed version" : "the latest published version";
13
+ }
14
+ return i.subjectInstalled ? `the installed ${i.subjectVersion}` : `${i.subjectVersion} (latest)`;
15
+ }
16
+ function hasSevereAdvisory(advisories) {
17
+ return advisories.some((a) => SEVERE.has(a.severity));
18
+ }
19
+ function assessVerdict(i) {
20
+ const reasons = [];
21
+ const unknowns = [];
22
+ if (!i.exists) {
23
+ return {
24
+ level: "invalid",
25
+ reasons: [
26
+ i.typosquatOf ? `no such package on npm \u2014 the name closely mimics "${i.typosquatOf}", which is what a typosquat looks like. Do not install it; check the spelling you meant.` : "no such package on npm. This name does not exist, so there is nothing to assess \u2014 check the spelling, or that you are not recalling a package that was never published."
27
+ ],
28
+ unknowns: [],
29
+ complete: true,
30
+ reassuring: false,
31
+ advisoryCount: null,
32
+ scope: describeScope(i)
33
+ };
34
+ }
35
+ const analysed = i.advisories !== null;
36
+ const advisories = i.advisories ?? [];
37
+ if (!analysed) {
38
+ unknowns.push("advisories have not been checked for this package yet");
39
+ }
40
+ if (i.vulnLookupComplete === false) {
41
+ unknowns.push("the vulnerability lookup did not complete, so results are partial");
42
+ }
43
+ const severe = hasSevereAdvisory(advisories);
44
+ const versionVulns = i.versionVulns ?? [];
45
+ if (i.typosquatOf) {
46
+ reasons.push(`name closely mimics "${i.typosquatOf}" \u2014 possible typosquat`);
47
+ }
48
+ if (versionVulns.length) {
49
+ reasons.push(
50
+ `the installed version is affected by ${versionVulns.length} advisory(ies): ${versionVulns.slice(0, 4).join(", ")}`
51
+ );
52
+ }
53
+ if (severe) {
54
+ const worst = advisories.filter((a) => SEVERE.has(a.severity));
55
+ reasons.push(`${worst.length} critical/high advisory(ies) recorded against this package`);
56
+ }
57
+ const malwarePattern = Boolean(i.installScripts && i.brandNew && i.lowTrust);
58
+ if (malwarePattern) {
59
+ reasons.push(
60
+ "published within the last 7 days, runs install scripts, and has almost no adoption \u2014 the shape of a malicious package"
61
+ );
62
+ }
63
+ if (i.typosquatOf || versionVulns.length || severe || malwarePattern) {
64
+ return {
65
+ level: "high",
66
+ reasons,
67
+ unknowns,
68
+ complete: analysed && i.vulnLookupComplete !== false,
69
+ reassuring: false,
70
+ advisoryCount: analysed ? advisories.length : null,
71
+ scope: describeScope(i)
72
+ };
73
+ }
74
+ if (advisories.length > 0) {
75
+ reasons.push(
76
+ `${advisories.length} advisory(ies) recorded against this package (none critical or high)`
77
+ );
78
+ }
79
+ if (i.deprecated) reasons.push("the publisher has marked this package deprecated");
80
+ if (i.archived) reasons.push("the source repository is archived");
81
+ if (i.installScripts && (i.lowTrust || i.brandNew)) {
82
+ reasons.push("runs install scripts and has little adoption or history");
83
+ }
84
+ if (i.lowTrust && i.singleMaintainer) {
85
+ reasons.push("a single maintainer and very low adoption");
86
+ }
87
+ if (reasons.length > 0) {
88
+ return {
89
+ level: "medium",
90
+ reasons,
91
+ unknowns,
92
+ complete: analysed && i.vulnLookupComplete !== false,
93
+ reassuring: false,
94
+ advisoryCount: analysed ? advisories.length : null,
95
+ scope: describeScope(i)
96
+ };
97
+ }
98
+ const complete = analysed && i.vulnLookupComplete !== false;
99
+ return {
100
+ level: "low",
101
+ reasons: [],
102
+ unknowns,
103
+ complete,
104
+ // The only path that produces a green tick, and it requires the evidence to
105
+ // be complete. An unanalysed package reads as "not checked yet", never as
106
+ // "nothing wrong with it".
107
+ reassuring: complete,
108
+ advisoryCount: analysed ? advisories.length : null,
109
+ scope: describeScope(i)
110
+ };
111
+ }
112
+
113
+ export {
114
+ assessVerdict
115
+ };
@@ -0,0 +1,107 @@
1
+ import { createRequire as __lurqCreateRequire } from 'node:module'; const require = __lurqCreateRequire(import.meta.url);
2
+ import {
3
+ init_esm_shims
4
+ } from "./chunk-I3M2KJXB.js";
5
+
6
+ // src/surface/types.ts
7
+ init_esm_shims();
8
+ function runtimeSymbols(surface) {
9
+ return surface.symbols.filter((s) => s.kind !== "type_only" && s.origin === "local");
10
+ }
11
+ function starReExports(surface) {
12
+ return surface.externalReExports.filter(
13
+ (spec) => !surface.symbols.some((s) => s.origin === `external:${spec}`)
14
+ );
15
+ }
16
+
17
+ // src/surface/diff.ts
18
+ init_esm_shims();
19
+ var empty = (from, to, reason) => ({
20
+ package: from.package,
21
+ fromVersion: from.version,
22
+ toVersion: to.version,
23
+ tier: from.tier,
24
+ removed: [],
25
+ added: [],
26
+ arityChanged: [],
27
+ signatureChanged: [],
28
+ typeOnlyRemoved: [],
29
+ deprecated: [],
30
+ renamed: [],
31
+ inconclusive: reason
32
+ });
33
+ function diffSurfaces(from, to) {
34
+ if (from.tier !== to.tier) {
35
+ return empty(from, to, `cross-tier comparison refused: ${from.tier} vs ${to.tier}`);
36
+ }
37
+ if (from.symbols.length === 0) {
38
+ return empty(from, to, "source surface is empty, extraction failed, not a removal");
39
+ }
40
+ if (to.symbols.length === 0) {
41
+ return empty(from, to, "target surface is empty, extraction failed, not a removal");
42
+ }
43
+ const fromRuntime = new Map(runtimeSymbols(from).map((s) => [s.path, s]));
44
+ const toRuntime = new Map(runtimeSymbols(to).map((s) => [s.path, s]));
45
+ const toPresent = new Set(to.symbols.filter((s) => s.kind !== "type_only").map((s) => s.path));
46
+ const removed = [...fromRuntime.values()].filter((s) => !toPresent.has(s.path));
47
+ const added = [...toRuntime.values()].filter((s) => !fromRuntime.has(s.path));
48
+ const arityChanged = [];
49
+ for (const [path, a] of fromRuntime) {
50
+ const b = toRuntime.get(path);
51
+ if (!b) continue;
52
+ const requiredChanged = a.arity !== null && b.arity !== null && a.arity !== b.arity;
53
+ const measured = a.maxArity !== void 0 && b.maxArity !== void 0;
54
+ const maxShrank = typeof a.maxArity === "number" && typeof b.maxArity === "number" && b.maxArity < a.maxArity;
55
+ if (requiredChanged || maxShrank) {
56
+ arityChanged.push({
57
+ path,
58
+ from: a.arity,
59
+ to: b.arity,
60
+ ...measured ? { fromMax: a.maxArity, toMax: b.maxArity } : {}
61
+ });
62
+ }
63
+ }
64
+ const typeOnlyFrom = from.symbols.filter((s) => s.kind === "type_only");
65
+ const toPaths = new Set(to.symbols.map((s) => s.path));
66
+ const typeOnlyRemoved = typeOnlyFrom.filter((s) => !toPaths.has(s.path));
67
+ const signatureChanged = [];
68
+ if (from.tier === "bundled_dts") {
69
+ const fromAll = new Map(from.symbols.map((s) => [s.path, s]));
70
+ for (const b of to.symbols) {
71
+ const a = fromAll.get(b.path);
72
+ if (a?.signature && b.signature && a.signature !== b.signature) {
73
+ signatureChanged.push({ path: b.path, from: a.signature, to: b.signature });
74
+ }
75
+ }
76
+ }
77
+ const deprecated = [...toRuntime.values()].filter(
78
+ (s) => s.deprecated && !fromRuntime.get(s.path)?.deprecated
79
+ );
80
+ const declKey = (s) => s.sourceRef?.offset === void 0 ? null : `${s.sourceRef.file}#${s.sourceRef.offset}`;
81
+ const renamed = [];
82
+ for (const r of removed) {
83
+ const key = declKey(r);
84
+ if (key === null) continue;
85
+ const survivors = [...fromRuntime.values()].filter((s) => s.path !== r.path && toRuntime.has(s.path) && declKey(s) === key).map((s) => s.path);
86
+ if (survivors.length) renamed.push({ path: r.path, to: survivors });
87
+ }
88
+ return {
89
+ package: from.package,
90
+ fromVersion: from.version,
91
+ toVersion: to.version,
92
+ tier: from.tier,
93
+ removed,
94
+ added,
95
+ arityChanged,
96
+ signatureChanged,
97
+ typeOnlyRemoved,
98
+ deprecated,
99
+ renamed
100
+ };
101
+ }
102
+
103
+ export {
104
+ runtimeSymbols,
105
+ starReExports,
106
+ diffSurfaces
107
+ };
@@ -0,0 +1,201 @@
1
+ import { createRequire as __lurqCreateRequire } from 'node:module'; const require = __lurqCreateRequire(import.meta.url);
2
+ import {
3
+ logger
4
+ } from "./chunk-MYGSLK44.js";
5
+ import {
6
+ init_esm_shims
7
+ } from "./chunk-I3M2KJXB.js";
8
+
9
+ // src/core/http.ts
10
+ init_esm_shims();
11
+ import { createHash } from "crypto";
12
+ import { mkdir, readFile, writeFile } from "fs/promises";
13
+ import { existsSync } from "fs";
14
+ import { homedir } from "os";
15
+ import { dirname, join } from "path";
16
+ var HttpError = class extends Error {
17
+ constructor(message, status, url) {
18
+ super(message);
19
+ this.status = status;
20
+ this.url = url;
21
+ this.name = "HttpError";
22
+ }
23
+ status;
24
+ url;
25
+ };
26
+ var DEFAULT_HOST_CONFIG = { maxConcurrent: 6, minIntervalMs: 0 };
27
+ var HOST_CONFIG = {
28
+ "api.github.com": { maxConcurrent: 4, minIntervalMs: 50 },
29
+ "registry.npmjs.org": { maxConcurrent: 4, minIntervalMs: 50 },
30
+ // The downloads API rate-limits aggressively — serialize with a steady gap.
31
+ // Weekly downloads go through the bulk endpoint; only growth hits this often.
32
+ "api.npmjs.org": { maxConcurrent: 1, minIntervalMs: 250 },
33
+ "api.deps.dev": { maxConcurrent: 4, minIntervalMs: 40 },
34
+ "raw.githubusercontent.com": { maxConcurrent: 4, minIntervalMs: 30 },
35
+ // Bundlephobia is slow/flaky — be gentle (§9.5).
36
+ "bundlephobia.com": { maxConcurrent: 2, minIntervalMs: 200 }
37
+ };
38
+ var HostLimiter = class {
39
+ constructor(config) {
40
+ this.config = config;
41
+ }
42
+ config;
43
+ active = 0;
44
+ nextAvailable = 0;
45
+ queue = [];
46
+ async acquire() {
47
+ if (this.active >= this.config.maxConcurrent) {
48
+ await new Promise((resolve) => this.queue.push(resolve));
49
+ }
50
+ this.active++;
51
+ const now = Date.now();
52
+ const wait = Math.max(0, this.nextAvailable - now);
53
+ this.nextAvailable = Math.max(now, this.nextAvailable) + this.config.minIntervalMs;
54
+ if (wait > 0) await delay(wait);
55
+ }
56
+ release() {
57
+ this.active--;
58
+ const next = this.queue.shift();
59
+ if (next) next();
60
+ }
61
+ };
62
+ var limiters = /* @__PURE__ */ new Map();
63
+ function limiterFor(host) {
64
+ let limiter = limiters.get(host);
65
+ if (!limiter) {
66
+ limiter = new HostLimiter(HOST_CONFIG[host] ?? DEFAULT_HOST_CONFIG);
67
+ limiters.set(host, limiter);
68
+ }
69
+ return limiter;
70
+ }
71
+ var MEMORY_CACHE_MAX = 500;
72
+ var memoryCache = /* @__PURE__ */ new Map();
73
+ function memoryCacheSet(key, entry) {
74
+ memoryCache.delete(key);
75
+ memoryCache.set(key, entry);
76
+ if (memoryCache.size > MEMORY_CACHE_MAX) {
77
+ const oldest = memoryCache.keys().next();
78
+ if (!oldest.done) memoryCache.delete(oldest.value);
79
+ }
80
+ }
81
+ var bypassCacheRead = false;
82
+ function cacheDir() {
83
+ return process.env.LURQ_CACHE_DIR ?? join(homedir(), ".cache", "lurq", "http");
84
+ }
85
+ function cacheFile(key) {
86
+ const hash = createHash("sha256").update(key).digest("hex");
87
+ return join(cacheDir(), `${hash}.json`);
88
+ }
89
+ async function readCache(key, ttlMs) {
90
+ const now = Date.now();
91
+ const mem = memoryCache.get(key);
92
+ if (mem && now - mem.fetchedAt < ttlMs) {
93
+ memoryCacheSet(key, mem);
94
+ return mem;
95
+ }
96
+ const file = cacheFile(key);
97
+ if (!existsSync(file)) return void 0;
98
+ try {
99
+ const entry = JSON.parse(await readFile(file, "utf8"));
100
+ if (now - entry.fetchedAt < ttlMs) {
101
+ memoryCacheSet(key, entry);
102
+ return entry;
103
+ }
104
+ } catch {
105
+ }
106
+ return void 0;
107
+ }
108
+ async function writeCache(key, entry) {
109
+ memoryCacheSet(key, entry);
110
+ const file = cacheFile(key);
111
+ try {
112
+ await mkdir(dirname(file), { recursive: true });
113
+ await writeFile(file, JSON.stringify(entry), "utf8");
114
+ } catch (err) {
115
+ logger.debug(`http cache write failed: ${err.message}`);
116
+ }
117
+ }
118
+ var RETRYABLE = /* @__PURE__ */ new Set([429, 500, 502, 503, 504]);
119
+ async function httpRequest(url, opts) {
120
+ const {
121
+ host,
122
+ ttlMs,
123
+ method = "GET",
124
+ headers = {},
125
+ body,
126
+ accept = "json",
127
+ timeoutMs = 15e3,
128
+ retries = 3,
129
+ fetchImpl = fetch
130
+ } = opts;
131
+ const key = opts.cacheKey ?? `${method} ${url} ${body ?? ""}`;
132
+ if (ttlMs > 0 && !bypassCacheRead) {
133
+ const cached = await readCache(key, ttlMs);
134
+ if (cached) {
135
+ return { status: cached.status, data: decode(cached.body, accept), fromCache: true };
136
+ }
137
+ }
138
+ const limiter = limiterFor(host);
139
+ let lastErr;
140
+ for (let attempt = 0; attempt <= retries; attempt++) {
141
+ await limiter.acquire();
142
+ const controller = new AbortController();
143
+ const timer = setTimeout(() => controller.abort(), timeoutMs);
144
+ try {
145
+ const res = await fetchImpl(url, { method, headers, body, signal: controller.signal });
146
+ const text = await res.text();
147
+ if (res.ok) {
148
+ if (ttlMs > 0) await writeCache(key, { fetchedAt: Date.now(), status: res.status, body: text });
149
+ return { status: res.status, data: decode(text, accept), fromCache: false };
150
+ }
151
+ if (RETRYABLE.has(res.status) && attempt < retries) {
152
+ const retryAfter = parseRetryAfter(res.headers.get("retry-after"));
153
+ await delay(retryAfter ?? backoff(attempt));
154
+ lastErr = new HttpError(`HTTP ${res.status} for ${url}`, res.status, url);
155
+ continue;
156
+ }
157
+ throw new HttpError(`HTTP ${res.status} for ${url}`, res.status, url);
158
+ } catch (err) {
159
+ lastErr = err;
160
+ const isAbort = err instanceof Error && err.name === "AbortError";
161
+ const isHttp = err instanceof HttpError;
162
+ if (isHttp && !RETRYABLE.has(err.status)) throw err;
163
+ if (attempt < retries) {
164
+ await delay(backoff(attempt));
165
+ continue;
166
+ }
167
+ if (isAbort) throw new HttpError(`Timeout after ${timeoutMs}ms for ${url}`, 0, url);
168
+ } finally {
169
+ clearTimeout(timer);
170
+ limiter.release();
171
+ }
172
+ }
173
+ throw lastErr instanceof Error ? lastErr : new HttpError(`Request failed for ${url}`, 0, url);
174
+ }
175
+ async function httpGetJson(url, opts) {
176
+ return httpRequest(url, { ...opts, method: "GET", accept: "json" });
177
+ }
178
+ function decode(text, accept) {
179
+ if (accept === "text") return text;
180
+ return text ? JSON.parse(text) : null;
181
+ }
182
+ function backoff(attempt) {
183
+ const base = 500 * 2 ** attempt;
184
+ return base + Math.floor(attempt * 137 % 100 * 3);
185
+ }
186
+ function parseRetryAfter(value) {
187
+ if (!value) return void 0;
188
+ const seconds = Number(value);
189
+ if (!Number.isNaN(seconds)) return seconds * 1e3;
190
+ const date = Date.parse(value);
191
+ return Number.isNaN(date) ? void 0 : Math.max(0, date - Date.now());
192
+ }
193
+ function delay(ms) {
194
+ return new Promise((resolve) => setTimeout(resolve, ms));
195
+ }
196
+
197
+ export {
198
+ HttpError,
199
+ httpRequest,
200
+ httpGetJson
201
+ };