@socketsecurity/lib 5.18.2 → 5.19.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 (305) hide show
  1. package/CHANGELOG.md +43 -0
  2. package/README.md +6 -5
  3. package/dist/abort.d.ts +3 -0
  4. package/dist/abort.js +1 -0
  5. package/dist/agent.d.ts +66 -49
  6. package/dist/agent.js +51 -50
  7. package/dist/ansi.d.ts +2 -5
  8. package/dist/ansi.js +3 -2
  9. package/dist/archives.d.ts +25 -21
  10. package/dist/archives.js +35 -34
  11. package/dist/argv/flags.d.ts +100 -91
  12. package/dist/argv/flags.js +88 -87
  13. package/dist/argv/parse.d.ts +30 -40
  14. package/dist/argv/parse.js +33 -32
  15. package/dist/arrays.d.ts +4 -8
  16. package/dist/arrays.js +1 -0
  17. package/dist/bin.d.ts +7 -5
  18. package/dist/bin.js +52 -29
  19. package/dist/cacache.d.ts +13 -12
  20. package/dist/cacache.js +9 -8
  21. package/dist/cache-with-ttl.d.ts +53 -35
  22. package/dist/cache-with-ttl.js +1 -0
  23. package/dist/colors.d.ts +5 -5
  24. package/dist/colors.js +1 -0
  25. package/dist/constants/agents.d.ts +5 -9
  26. package/dist/constants/agents.js +3 -2
  27. package/dist/constants/core.d.ts +5 -10
  28. package/dist/constants/core.js +2 -1
  29. package/dist/constants/encoding.d.ts +3 -3
  30. package/dist/constants/encoding.js +1 -0
  31. package/dist/constants/github.d.ts +3 -3
  32. package/dist/constants/github.js +1 -0
  33. package/dist/constants/licenses.d.ts +9 -2
  34. package/dist/constants/licenses.js +1 -0
  35. package/dist/constants/lifecycle-script-names.js +1 -0
  36. package/dist/constants/maintained-node-versions.d.ts +3 -0
  37. package/dist/constants/maintained-node-versions.js +1 -0
  38. package/dist/constants/node.d.ts +125 -16
  39. package/dist/constants/node.js +74 -73
  40. package/dist/constants/package-default-node-range.d.ts +3 -1
  41. package/dist/constants/package-default-node-range.js +2 -1
  42. package/dist/constants/package-default-socket-categories.d.ts +0 -1
  43. package/dist/constants/package-default-socket-categories.js +1 -0
  44. package/dist/constants/packages.d.ts +12 -17
  45. package/dist/constants/packages.js +31 -16
  46. package/dist/constants/platform.d.ts +1 -2
  47. package/dist/constants/platform.js +2 -1
  48. package/dist/constants/process.d.ts +18 -0
  49. package/dist/constants/process.js +1 -0
  50. package/dist/constants/socket.d.ts +4 -10
  51. package/dist/constants/socket.js +2 -1
  52. package/dist/constants/testing.d.ts +3 -3
  53. package/dist/constants/testing.js +1 -0
  54. package/dist/constants/time.d.ts +3 -4
  55. package/dist/constants/time.js +1 -0
  56. package/dist/constants/typescript.d.ts +10 -3
  57. package/dist/constants/typescript.js +5 -4
  58. package/dist/cover/code.d.ts +3 -0
  59. package/dist/cover/code.js +12 -12
  60. package/dist/cover/formatters.d.ts +12 -9
  61. package/dist/cover/formatters.js +19 -18
  62. package/dist/cover/type.d.ts +3 -0
  63. package/dist/cover/type.js +1 -0
  64. package/dist/cover/types.js +1 -0
  65. package/dist/debug.d.ts +32 -47
  66. package/dist/debug.js +97 -96
  67. package/dist/dlx/arborist.d.ts +134 -0
  68. package/dist/dlx/arborist.js +177 -0
  69. package/dist/dlx/binary.d.ts +25 -9
  70. package/dist/dlx/binary.js +34 -12
  71. package/dist/dlx/cache.d.ts +1 -0
  72. package/dist/dlx/cache.js +2 -1
  73. package/dist/dlx/detect.d.ts +15 -0
  74. package/dist/dlx/detect.js +28 -20
  75. package/dist/dlx/dir.d.ts +1 -11
  76. package/dist/dlx/dir.js +2 -12
  77. package/dist/dlx/integrity.d.ts +86 -0
  78. package/dist/dlx/integrity.js +112 -0
  79. package/dist/dlx/lockfile.d.ts +115 -0
  80. package/dist/dlx/lockfile.js +139 -0
  81. package/dist/dlx/manifest.d.ts +26 -1
  82. package/dist/dlx/manifest.js +9 -6
  83. package/dist/dlx/package.d.ts +58 -3
  84. package/dist/dlx/package.js +101 -74
  85. package/dist/dlx/packages.d.ts +1 -11
  86. package/dist/dlx/packages.js +3 -14
  87. package/dist/dlx/paths.d.ts +1 -0
  88. package/dist/dlx/paths.js +2 -1
  89. package/dist/effects/pulse-frames.js +1 -0
  90. package/dist/effects/text-shimmer.d.ts +13 -2
  91. package/dist/effects/text-shimmer.js +50 -46
  92. package/dist/effects/types.js +1 -0
  93. package/dist/effects/ultra.js +1 -0
  94. package/dist/env/ci.d.ts +6 -1
  95. package/dist/env/ci.js +1 -0
  96. package/dist/env/debug.d.ts +5 -1
  97. package/dist/env/debug.js +1 -0
  98. package/dist/env/github.d.ts +19 -23
  99. package/dist/env/github.js +5 -4
  100. package/dist/env/helpers.d.ts +21 -9
  101. package/dist/env/helpers.js +5 -11
  102. package/dist/env/home.d.ts +17 -4
  103. package/dist/env/home.js +2 -1
  104. package/dist/env/locale.d.ts +4 -3
  105. package/dist/env/locale.js +1 -0
  106. package/dist/env/node-auth-token.d.ts +5 -1
  107. package/dist/env/node-auth-token.js +1 -0
  108. package/dist/env/node-env.d.ts +5 -1
  109. package/dist/env/node-env.js +1 -0
  110. package/dist/env/npm.d.ts +4 -5
  111. package/dist/env/npm.js +1 -0
  112. package/dist/env/package-manager.d.ts +4 -3
  113. package/dist/env/package-manager.js +2 -1
  114. package/dist/env/path.d.ts +5 -1
  115. package/dist/env/path.js +1 -0
  116. package/dist/env/pre-commit.d.ts +5 -1
  117. package/dist/env/pre-commit.js +1 -0
  118. package/dist/env/rewire.d.ts +10 -0
  119. package/dist/env/rewire.js +7 -5
  120. package/dist/env/shell.d.ts +5 -1
  121. package/dist/env/shell.js +1 -0
  122. package/dist/env/socket-cli-shadow.d.ts +4 -5
  123. package/dist/env/socket-cli-shadow.js +1 -0
  124. package/dist/env/socket-cli.d.ts +4 -14
  125. package/dist/env/socket-cli.js +1 -0
  126. package/dist/env/socket.d.ts +6 -18
  127. package/dist/env/socket.js +4 -3
  128. package/dist/env/temp-dir.d.ts +4 -3
  129. package/dist/env/temp-dir.js +1 -0
  130. package/dist/env/term.d.ts +5 -1
  131. package/dist/env/term.js +1 -0
  132. package/dist/env/test.d.ts +4 -3
  133. package/dist/env/test.js +1 -0
  134. package/dist/env/windows.d.ts +4 -4
  135. package/dist/env/windows.js +1 -0
  136. package/dist/env/xdg.d.ts +4 -3
  137. package/dist/env/xdg.js +1 -0
  138. package/dist/env.d.ts +83 -23
  139. package/dist/env.js +112 -80
  140. package/dist/errors.js +1 -0
  141. package/dist/external/@npmcli/package-json.js +9 -3968
  142. package/dist/external/@socketregistry/packageurl-js.js +2 -2
  143. package/dist/external/debug.js +162 -328
  144. package/dist/external/external-pack.js +3 -2835
  145. package/dist/external/npm-pack.js +13939 -33342
  146. package/dist/external/zod.js +160 -7558
  147. package/dist/fs.d.ts +92 -113
  148. package/dist/fs.js +35 -35
  149. package/dist/git.d.ts +170 -164
  150. package/dist/git.js +113 -87
  151. package/dist/github.d.ts +249 -227
  152. package/dist/github.js +82 -81
  153. package/dist/globs.d.ts +31 -17
  154. package/dist/globs.js +51 -58
  155. package/dist/http-request.d.ts +99 -99
  156. package/dist/http-request.js +182 -156
  157. package/dist/ipc-cli.d.ts +28 -0
  158. package/dist/{utils/get-ipc.js → ipc-cli.js} +4 -3
  159. package/dist/ipc.d.ts +9 -299
  160. package/dist/ipc.js +18 -204
  161. package/dist/json/edit.d.ts +3 -1
  162. package/dist/json/edit.js +30 -30
  163. package/dist/json/format.d.ts +36 -36
  164. package/dist/json/format.js +22 -21
  165. package/dist/json/parse.d.ts +4 -2
  166. package/dist/json/parse.js +1 -0
  167. package/dist/json/types.js +1 -0
  168. package/dist/{links/index.d.ts → links.d.ts} +6 -2
  169. package/dist/{links/index.js → links.js} +5 -4
  170. package/dist/logger.d.ts +4 -6
  171. package/dist/logger.js +61 -53
  172. package/dist/memoization.d.ts +52 -49
  173. package/dist/memoization.js +55 -33
  174. package/dist/objects.d.ts +25 -44
  175. package/dist/objects.js +2 -1
  176. package/dist/package-extensions.d.ts +6 -0
  177. package/dist/package-extensions.js +2 -1
  178. package/dist/packages/edit.d.ts +3 -5
  179. package/dist/packages/edit.js +4 -3
  180. package/dist/packages/exports.d.ts +11 -14
  181. package/dist/packages/exports.js +11 -10
  182. package/dist/packages/isolation.d.ts +4 -0
  183. package/dist/packages/isolation.js +20 -19
  184. package/dist/packages/licenses.d.ts +3 -10
  185. package/dist/packages/licenses.js +2 -1
  186. package/dist/packages/manifest.d.ts +3 -3
  187. package/dist/packages/manifest.js +1 -0
  188. package/dist/packages/normalize.d.ts +3 -4
  189. package/dist/packages/normalize.js +1 -0
  190. package/dist/packages/operations.d.ts +3 -10
  191. package/dist/packages/operations.js +1 -0
  192. package/dist/packages/provenance.d.ts +10 -8
  193. package/dist/packages/provenance.js +55 -54
  194. package/dist/packages/specs.d.ts +3 -5
  195. package/dist/packages/specs.js +1 -0
  196. package/dist/packages/validation.d.ts +3 -3
  197. package/dist/packages/validation.js +1 -0
  198. package/dist/packages.d.ts +2 -17
  199. package/dist/packages.js +2 -1
  200. package/dist/paths/dirnames.d.ts +0 -2
  201. package/dist/paths/dirnames.js +1 -0
  202. package/dist/paths/exts.d.ts +0 -1
  203. package/dist/paths/exts.js +1 -0
  204. package/dist/paths/filenames.d.ts +0 -1
  205. package/dist/paths/filenames.js +1 -0
  206. package/dist/paths/globs.d.ts +0 -1
  207. package/dist/paths/globs.js +1 -0
  208. package/dist/paths/normalize.d.ts +115 -123
  209. package/dist/paths/normalize.js +128 -127
  210. package/dist/paths/packages.d.ts +3 -2
  211. package/dist/paths/packages.js +2 -1
  212. package/dist/paths/rewire.d.ts +9 -0
  213. package/dist/paths/rewire.js +5 -3
  214. package/dist/paths/socket.d.ts +37 -23
  215. package/dist/paths/socket.js +26 -25
  216. package/dist/performance.d.ts +87 -84
  217. package/dist/performance.js +97 -96
  218. package/dist/process-lock.d.ts +41 -1
  219. package/dist/process-lock.js +24 -17
  220. package/dist/promise-queue.d.ts +6 -0
  221. package/dist/promise-queue.js +1 -0
  222. package/dist/promises.d.ts +40 -55
  223. package/dist/promises.js +12 -11
  224. package/dist/regexps.d.ts +0 -5
  225. package/dist/regexps.js +1 -0
  226. package/dist/releases/github.d.ts +59 -63
  227. package/dist/releases/github.js +95 -100
  228. package/dist/releases/socket-btm.d.ts +9 -2
  229. package/dist/releases/socket-btm.js +32 -25
  230. package/dist/sea.d.ts +5 -0
  231. package/dist/sea.js +1 -0
  232. package/dist/shadow.d.ts +4 -0
  233. package/dist/shadow.js +1 -0
  234. package/dist/signal-exit.d.ts +7 -7
  235. package/dist/signal-exit.js +46 -45
  236. package/dist/sorts.d.ts +5 -7
  237. package/dist/sorts.js +11 -10
  238. package/dist/spawn.d.ts +96 -77
  239. package/dist/spawn.js +39 -38
  240. package/dist/spinner.d.ts +21 -22
  241. package/dist/spinner.js +15 -11
  242. package/dist/ssri.d.ts +31 -36
  243. package/dist/ssri.js +15 -14
  244. package/dist/stdio/_stream.d.ts +31 -0
  245. package/dist/stdio/_stream.js +57 -0
  246. package/dist/stdio/divider.d.ts +40 -36
  247. package/dist/stdio/divider.js +10 -9
  248. package/dist/stdio/footer.d.ts +20 -0
  249. package/dist/stdio/footer.js +12 -2
  250. package/dist/stdio/header.d.ts +4 -16
  251. package/dist/stdio/header.js +1 -9
  252. package/dist/stdio/stderr.d.ts +51 -39
  253. package/dist/stdio/stderr.js +19 -22
  254. package/dist/stdio/stdout.d.ts +54 -52
  255. package/dist/stdio/stdout.js +35 -33
  256. package/dist/streams.d.ts +4 -3
  257. package/dist/streams.js +1 -0
  258. package/dist/strings.d.ts +31 -85
  259. package/dist/strings.js +5 -49
  260. package/dist/suppress-warnings.d.ts +32 -15
  261. package/dist/suppress-warnings.js +14 -13
  262. package/dist/tables.d.ts +30 -26
  263. package/dist/tables.js +24 -23
  264. package/dist/temporary-executor.d.ts +4 -0
  265. package/dist/temporary-executor.js +1 -0
  266. package/dist/themes/context.d.ts +30 -26
  267. package/dist/themes/context.js +19 -18
  268. package/dist/themes/index.d.ts +0 -4
  269. package/dist/themes/index.js +1 -0
  270. package/dist/themes/themes.d.ts +1 -1
  271. package/dist/themes/themes.js +1 -0
  272. package/dist/themes/types.js +1 -0
  273. package/dist/themes/utils.d.ts +46 -43
  274. package/dist/themes/utils.js +45 -44
  275. package/dist/types.d.ts +48 -52
  276. package/dist/types.js +35 -35
  277. package/dist/url.d.ts +48 -53
  278. package/dist/url.js +38 -37
  279. package/dist/validation/json-parser.d.ts +19 -190
  280. package/dist/validation/json-parser.js +5 -69
  281. package/dist/validation/types.d.ts +9 -33
  282. package/dist/validation/types.js +1 -0
  283. package/dist/versions.d.ts +1 -0
  284. package/dist/versions.js +2 -1
  285. package/dist/words.d.ts +3 -6
  286. package/dist/words.js +1 -0
  287. package/dist/zod.js +1 -0
  288. package/package.json +34 -66
  289. package/dist/external/@inquirer/checkbox.js +0 -5
  290. package/dist/external/@inquirer/confirm.js +0 -5
  291. package/dist/external/@inquirer/input.js +0 -5
  292. package/dist/external/@inquirer/password.js +0 -5
  293. package/dist/external/@inquirer/search.js +0 -5
  294. package/dist/external/@inquirer/select.js +0 -5
  295. package/dist/functions.d.ts +0 -57
  296. package/dist/functions.js +0 -70
  297. package/dist/stdio/clear.d.ts +0 -140
  298. package/dist/stdio/clear.js +0 -95
  299. package/dist/stdio/mask.d.ts +0 -151
  300. package/dist/stdio/mask.js +0 -224
  301. package/dist/stdio/progress.d.ts +0 -148
  302. package/dist/stdio/progress.js +0 -212
  303. package/dist/stdio/prompts.d.ts +0 -195
  304. package/dist/stdio/prompts.js +0 -176
  305. package/dist/utils/get-ipc.d.ts +0 -15
@@ -0,0 +1,86 @@
1
+ /**
2
+ * @fileoverview Integrity specification helpers for dlx downloads.
3
+ *
4
+ * Single supported format per flavor:
5
+ * - integrity: SRI with sha512 only (what npm registry returns)
6
+ * - checksum: sha256 hex (what `shasum -a 256` produces; common for
7
+ * binary release assets on GitHub)
8
+ *
9
+ * Callers may pass a {@link HashSpec} as a bare string (sniffed via
10
+ * format) or as an explicit `{ type, value }` object. The normalized
11
+ * form carried around internally is always the object.
12
+ */
13
+ /**
14
+ * Tagged union representing an expected hash.
15
+ *
16
+ * @example
17
+ * // Bare SRI (sniffed as integrity):
18
+ * 'sha512-abc...'
19
+ *
20
+ * @example
21
+ * // Bare sha256 hex (sniffed as checksum):
22
+ * 'a1b2c3...'
23
+ *
24
+ * @example
25
+ * // Explicit:
26
+ * { type: 'integrity', value: 'sha512-abc...' }
27
+ * { type: 'checksum', value: 'a1b2c3...' }
28
+ */
29
+ export type HashSpec = string | {
30
+ type: 'integrity';
31
+ value: string;
32
+ } | {
33
+ type: 'checksum';
34
+ value: string;
35
+ };
36
+ /**
37
+ * Normalized internal form. Always an object.
38
+ */
39
+ export interface NormalizedHash {
40
+ type: 'integrity' | 'checksum';
41
+ value: string;
42
+ }
43
+ /**
44
+ * Both hash formats for the same bytes. Returned from downloads so callers
45
+ * can record whichever format their config uses.
46
+ */
47
+ export interface ComputedHashes {
48
+ /** SRI integrity: `sha512-<base64>`. Matches what the npm registry returns. */
49
+ integrity: string;
50
+ /** SHA-256 hex (64 chars). Matches `shasum -a 256`. */
51
+ checksum: string;
52
+ }
53
+ /**
54
+ * Normalize a {@link HashSpec} to its canonical `{ type, value }` form.
55
+ *
56
+ * - Object form is trusted (its `value` is validated for shape).
57
+ * - Bare string matching sha512 SRI → integrity.
58
+ * - Bare string of 64 hex chars → checksum.
59
+ * - Anything else throws TypeError.
60
+ *
61
+ * @throws TypeError if the string is not a recognized format, or if an
62
+ * explicit object's value doesn't match its declared type.
63
+ */
64
+ export declare function normalizeHash(spec: HashSpec): NormalizedHash;
65
+ /**
66
+ * Compute both integrity (sha512 SRI) and checksum (sha256 hex) for a
67
+ * buffer of bytes.
68
+ */
69
+ export declare function computeHashes(bytes: Buffer): ComputedHashes;
70
+ /**
71
+ * Verify computed hashes against an expected {@link NormalizedHash}.
72
+ * Uses `crypto.timingSafeEqual` for constant-time comparison.
73
+ *
74
+ * @throws DlxHashMismatchError when the hash of the matching type
75
+ * doesn't match the expected value.
76
+ */
77
+ export declare function verifyHash(expected: NormalizedHash, computed: ComputedHashes): void;
78
+ /**
79
+ * Thrown when an expected hash doesn't match the computed hash of the
80
+ * downloaded bytes. Carries both sides for diagnostics.
81
+ */
82
+ export declare class DlxHashMismatchError extends Error {
83
+ readonly expected: NormalizedHash;
84
+ readonly actual: ComputedHashes;
85
+ constructor(expected: NormalizedHash, actual: ComputedHashes);
86
+ }
@@ -0,0 +1,112 @@
1
+ "use strict";
2
+ /* Socket Lib - Built with esbuild */
3
+ "use strict";
4
+ var __defProp = Object.defineProperty;
5
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
+ var __getOwnPropNames = Object.getOwnPropertyNames;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
21
+ var integrity_exports = {};
22
+ __export(integrity_exports, {
23
+ DlxHashMismatchError: () => DlxHashMismatchError,
24
+ computeHashes: () => computeHashes,
25
+ normalizeHash: () => normalizeHash,
26
+ verifyHash: () => verifyHash
27
+ });
28
+ module.exports = __toCommonJS(integrity_exports);
29
+ var import_node_crypto = require("node:crypto");
30
+ const INTEGRITY_PREFIX = "sha512-";
31
+ const INTEGRITY_BODY_RE = /^[A-Za-z0-9+/=]+$/;
32
+ const CHECKSUM_RE = /^[a-f0-9]{64}$/i;
33
+ function isIntegrityString(s) {
34
+ if (!s.startsWith(INTEGRITY_PREFIX)) {
35
+ return false;
36
+ }
37
+ const body = s.slice(INTEGRITY_PREFIX.length);
38
+ return body.length > 0 && INTEGRITY_BODY_RE.test(body);
39
+ }
40
+ function isChecksumString(s) {
41
+ return CHECKSUM_RE.test(s);
42
+ }
43
+ function normalizeHash(spec) {
44
+ if (typeof spec === "object" && spec !== null) {
45
+ if (spec.type === "integrity") {
46
+ if (!isIntegrityString(spec.value)) {
47
+ throw new TypeError(
48
+ `Expected SRI integrity string "sha512-<base64>", got: ${spec.value}`
49
+ );
50
+ }
51
+ return { type: "integrity", value: spec.value };
52
+ }
53
+ if (spec.type === "checksum") {
54
+ if (!isChecksumString(spec.value)) {
55
+ throw new TypeError(
56
+ `Expected sha256 hex string (64 hex chars), got: ${spec.value}`
57
+ );
58
+ }
59
+ return { type: "checksum", value: spec.value };
60
+ }
61
+ throw new TypeError(
62
+ `Unknown hash type: ${spec.type}`
63
+ );
64
+ }
65
+ if (typeof spec !== "string") {
66
+ throw new TypeError(
67
+ `HashSpec must be a string or { type, value } object, got: ${typeof spec}`
68
+ );
69
+ }
70
+ if (isIntegrityString(spec)) {
71
+ return { type: "integrity", value: spec };
72
+ }
73
+ if (isChecksumString(spec)) {
74
+ return { type: "checksum", value: spec };
75
+ }
76
+ throw new TypeError(
77
+ `Unrecognized hash format. Expected SRI integrity ("sha512-<base64>") or sha256 hex (64 hex chars), got: ${spec}`
78
+ );
79
+ }
80
+ function computeHashes(bytes) {
81
+ const integrity = `sha512-${(0, import_node_crypto.createHash)("sha512").update(bytes).digest("base64")}`;
82
+ const checksum = (0, import_node_crypto.createHash)("sha256").update(bytes).digest("hex");
83
+ return { integrity, checksum };
84
+ }
85
+ function verifyHash(expected, computed) {
86
+ const actual = expected.type === "integrity" ? computed.integrity : computed.checksum;
87
+ const expectedBuf = Buffer.from(expected.value);
88
+ const actualBuf = Buffer.from(actual);
89
+ if (expectedBuf.length !== actualBuf.length || !(0, import_node_crypto.timingSafeEqual)(expectedBuf, actualBuf)) {
90
+ throw new DlxHashMismatchError(expected, computed);
91
+ }
92
+ }
93
+ class DlxHashMismatchError extends Error {
94
+ expected;
95
+ actual;
96
+ constructor(expected, actual) {
97
+ const actualValue = expected.type === "integrity" ? actual.integrity : actual.checksum;
98
+ super(
99
+ `Hash mismatch (${expected.type}): expected ${expected.value}, got ${actualValue}`
100
+ );
101
+ this.name = "DlxHashMismatchError";
102
+ this.expected = expected;
103
+ this.actual = actual;
104
+ }
105
+ }
106
+ // Annotate the CommonJS export names for ESM import in node:
107
+ 0 && (module.exports = {
108
+ DlxHashMismatchError,
109
+ computeHashes,
110
+ normalizeHash,
111
+ verifyHash
112
+ });
@@ -0,0 +1,115 @@
1
+ /**
2
+ * @fileoverview Package pin generation for dlx installs.
3
+ *
4
+ * `generatePackagePin` resolves an npm package against the registry
5
+ * using Arborist's lockfile-only mode and fetches its top-level tarball
6
+ * to return both hash formats plus the lockfile content — everything
7
+ * needed to vendor a reproducible install.
8
+ *
9
+ * The `LockfileSpec` type is also exported here for use as the
10
+ * `lockfile` option on `downloadPackage`. Sniff/write handling lives
11
+ * inline in `./package.ts` — no helper.
12
+ */
13
+ import type { ComputedHashes } from './integrity';
14
+ /**
15
+ * Lockfile source for the `lockfile` option on `downloadPackage`.
16
+ *
17
+ * Bare strings are sniffed: a leading `{` (after whitespace) means
18
+ * JSON content, anything else is treated as a filesystem path. Pass the
19
+ * explicit `{ type, value }` form to override sniffing.
20
+ *
21
+ * @example
22
+ * // Sniffed as path:
23
+ * './scripts/dlx/claude/package-lock.json'
24
+ * // Sniffed as content:
25
+ * '{ "lockfileVersion": 3, ... }'
26
+ * // Explicit:
27
+ * { type: 'path', value: '/abs/package-lock.json' }
28
+ * { type: 'content', value: '{ ... }' }
29
+ */
30
+ export type LockfileSpec = string | {
31
+ type: 'path';
32
+ value: string;
33
+ } | {
34
+ type: 'content';
35
+ value: string;
36
+ };
37
+ /**
38
+ * Default minimum release age in days applied when a caller passes
39
+ * neither `minReleaseDays` nor `minReleaseMins`. Pass `minReleaseDays: 0`
40
+ * to disable the cutoff explicitly.
41
+ */
42
+ export declare const DEFAULT_MIN_RELEASE_DAYS = 7;
43
+ /**
44
+ * Options for generating a vendorable pin for an npm package.
45
+ */
46
+ export interface GeneratePackagePinOptions {
47
+ /** Package spec, e.g. `'@anthropic-ai/claude-code@2.1.92'`. */
48
+ package: string;
49
+ /**
50
+ * Minimum release age in days. Refuses to resolve any version (direct
51
+ * or transitive) published more recently than `Date.now() - N days`.
52
+ *
53
+ * Matches npm's `min-release-age` config (unit: days). Mutually
54
+ * exclusive with {@link minReleaseMins}. Defaults to
55
+ * {@link DEFAULT_MIN_RELEASE_DAYS} (7) when neither field is set.
56
+ * Pass `0` to disable.
57
+ */
58
+ minReleaseDays?: number | undefined;
59
+ /**
60
+ * Minimum release age in minutes. Refuses to resolve any version
61
+ * published more recently than `Date.now() - N minutes`.
62
+ *
63
+ * Matches pnpm's `minimumReleaseAge` config (unit: minutes). Mutually
64
+ * exclusive with {@link minReleaseDays}.
65
+ */
66
+ minReleaseMins?: number | undefined;
67
+ }
68
+ /**
69
+ * Result of {@link generatePackagePin}. All file data is returned as
70
+ * content — the caller decides whether/where to write it.
71
+ */
72
+ export interface PinDetails {
73
+ /** Resolved package name. */
74
+ name: string;
75
+ /** Resolved package version. */
76
+ version: string;
77
+ /** Both hash formats of the top-level tarball. */
78
+ hash: ComputedHashes;
79
+ /** `package.json` JSON content, ready to write to disk. */
80
+ packageJson: string;
81
+ /** `package-lock.json` JSON content, ready to write to disk. */
82
+ lockfile: string;
83
+ }
84
+ /**
85
+ * Thrown when a lockfile spec is malformed (unrecognized string, missing
86
+ * file, invalid JSON) or drifts from its package.json.
87
+ */
88
+ export declare class DlxLockfileError extends Error {
89
+ constructor(message: string, options?: {
90
+ cause?: unknown;
91
+ } | undefined);
92
+ }
93
+ /**
94
+ * Generate a vendorable pin for an npm package without installing it.
95
+ *
96
+ * Runs Arborist in lockfile-only mode (`packageLockOnly: true`) against a
97
+ * temporary directory, fetches the top-level tarball once to compute
98
+ * sha256 hex (since Arborist only exposes SRI from the registry), then
99
+ * tears the tmp directory down before returning.
100
+ *
101
+ * The result contains everything a caller needs to pin the package for
102
+ * future installs: the exact resolved name/version, both hash formats,
103
+ * and the lockfile content (ready to commit).
104
+ *
105
+ * @example
106
+ * ```ts
107
+ * const pin = await generatePackagePin({
108
+ * package: '@anthropic-ai/claude-code@2.1.92',
109
+ * })
110
+ * await fs.writeFile('./claude.lock.json', pin.lockfile, 'utf8')
111
+ * // pin.hash.integrity → 'sha512-…'
112
+ * // pin.hash.checksum → hex
113
+ * ```
114
+ */
115
+ export declare function generatePackagePin(options: GeneratePackagePinOptions): Promise<PinDetails>;
@@ -0,0 +1,139 @@
1
+ "use strict";
2
+ /* Socket Lib - Built with esbuild */
3
+ "use strict";
4
+ var __create = Object.create;
5
+ var __defProp = Object.defineProperty;
6
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
7
+ var __getOwnPropNames = Object.getOwnPropertyNames;
8
+ var __getProtoOf = Object.getPrototypeOf;
9
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
10
+ var __export = (target, all) => {
11
+ for (var name in all)
12
+ __defProp(target, name, { get: all[name], enumerable: true });
13
+ };
14
+ var __copyProps = (to, from, except, desc) => {
15
+ if (from && typeof from === "object" || typeof from === "function") {
16
+ for (let key of __getOwnPropNames(from))
17
+ if (!__hasOwnProp.call(to, key) && key !== except)
18
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
19
+ }
20
+ return to;
21
+ };
22
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
23
+ // If the importer is in node compatibility mode or this is not an ESM
24
+ // file that has been converted to a CommonJS file using a Babel-
25
+ // compatible transform (i.e. "__esModule" has not been set), then set
26
+ // "default" to the CommonJS "module.exports" for node compatibility.
27
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
28
+ mod
29
+ ));
30
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
31
+ var lockfile_exports = {};
32
+ __export(lockfile_exports, {
33
+ DEFAULT_MIN_RELEASE_DAYS: () => DEFAULT_MIN_RELEASE_DAYS,
34
+ DlxLockfileError: () => DlxLockfileError,
35
+ generatePackagePin: () => generatePackagePin
36
+ });
37
+ module.exports = __toCommonJS(lockfile_exports);
38
+ var import_node_os = require("node:os");
39
+ var import_pacote = __toESM(require("../external/pacote"));
40
+ var import_fs = require("../fs");
41
+ var import_arborist = require("./arborist");
42
+ var import_integrity = require("./integrity");
43
+ let _fs;
44
+ // @__NO_SIDE_EFFECTS__
45
+ function getFs() {
46
+ if (_fs === void 0) {
47
+ _fs = require("node:fs");
48
+ }
49
+ return _fs;
50
+ }
51
+ let _path;
52
+ // @__NO_SIDE_EFFECTS__
53
+ function getPath() {
54
+ if (_path === void 0) {
55
+ _path = require("node:path");
56
+ }
57
+ return _path;
58
+ }
59
+ const DEFAULT_MIN_RELEASE_DAYS = 7;
60
+ class DlxLockfileError extends Error {
61
+ constructor(message, options) {
62
+ super(message, options);
63
+ this.name = "DlxLockfileError";
64
+ }
65
+ }
66
+ function specName(spec) {
67
+ const atIdx = spec.lastIndexOf("@");
68
+ if (atIdx <= 0) {
69
+ return spec;
70
+ }
71
+ return spec.slice(0, atIdx);
72
+ }
73
+ function specRange(spec) {
74
+ const atIdx = spec.lastIndexOf("@");
75
+ if (atIdx <= 0) {
76
+ return "latest";
77
+ }
78
+ return spec.slice(atIdx + 1) || "latest";
79
+ }
80
+ async function generatePackagePin(options) {
81
+ const fs = /* @__PURE__ */ getFs();
82
+ const path = /* @__PURE__ */ getPath();
83
+ const { minReleaseDays, minReleaseMins, package: spec } = options;
84
+ if (typeof spec !== "string" || spec.length === 0) {
85
+ throw new DlxLockfileError("generatePackagePin requires a package spec");
86
+ }
87
+ if (minReleaseDays !== void 0 && minReleaseMins !== void 0) {
88
+ throw new DlxLockfileError(
89
+ "generatePackagePin: minReleaseDays and minReleaseMins are mutually exclusive"
90
+ );
91
+ }
92
+ const effectiveDays = minReleaseDays !== void 0 ? minReleaseDays : minReleaseMins !== void 0 ? void 0 : DEFAULT_MIN_RELEASE_DAYS;
93
+ const ageMs = effectiveDays !== void 0 ? effectiveDays * 864e5 : minReleaseMins !== void 0 ? minReleaseMins * 6e4 : 0;
94
+ const before = ageMs > 0 ? new Date(Date.now() - ageMs) : void 0;
95
+ const scratch = path.join(
96
+ (0, import_node_os.tmpdir)(),
97
+ `socket-lib-pin-${process.pid}-${Date.now()}`
98
+ );
99
+ await (0, import_fs.safeMkdir)(scratch, { recursive: true });
100
+ try {
101
+ const packageJson = JSON.stringify(
102
+ {
103
+ name: "socket-lib-pin",
104
+ version: "0.0.0",
105
+ private: true,
106
+ dependencies: { [specName(spec)]: specRange(spec) }
107
+ },
108
+ null,
109
+ 2
110
+ );
111
+ await fs.promises.writeFile(
112
+ path.join(scratch, "package.json"),
113
+ packageJson + "\n",
114
+ "utf8"
115
+ );
116
+ await (0, import_arborist.writeSafeNpmrc)(scratch, {
117
+ minReleaseDays: effectiveDays,
118
+ minReleaseMins
119
+ });
120
+ const ideal = await (0, import_arborist.safeIdealTree)({ path: scratch, before });
121
+ const tarball = await import_pacote.default.tarball(`${ideal.name}@${ideal.version}`);
122
+ const hash = (0, import_integrity.computeHashes)(tarball);
123
+ return {
124
+ name: ideal.name,
125
+ version: ideal.version,
126
+ hash,
127
+ packageJson,
128
+ lockfile: ideal.lockfile
129
+ };
130
+ } finally {
131
+ await (0, import_fs.safeDelete)(scratch, { force: true });
132
+ }
133
+ }
134
+ // Annotate the CommonJS export names for ESM import in node:
135
+ 0 && (module.exports = {
136
+ DEFAULT_MIN_RELEASE_DAYS,
137
+ DlxLockfileError,
138
+ generatePackagePin
139
+ });
@@ -1,3 +1,29 @@
1
+ /**
2
+ * @fileoverview DLX manifest storage utilities.
3
+ * Manages persistent caching of DLX package and binary metadata with TTL support
4
+ * and atomic file operations.
5
+ *
6
+ * Key Functions:
7
+ * - getManifestEntry: Retrieve manifest entry by spec
8
+ * - setPackageEntry: Store npm package metadata
9
+ * - setBinaryEntry: Store binary download metadata
10
+ *
11
+ * Features:
12
+ * - TTL-based cache expiration
13
+ * - Atomic file operations with locking
14
+ * - JSON-based persistent storage
15
+ * - Error-resistant implementation
16
+ *
17
+ * Storage Format:
18
+ * - Stores in ~/.socket/_dlx/.dlx-manifest.json
19
+ * - Per-spec manifest entries with timestamps
20
+ * - Thread-safe operations using process lock utility
21
+ *
22
+ * Usage:
23
+ * - Update check caching
24
+ * - Binary metadata tracking
25
+ * - Rate limiting registry requests
26
+ */
1
27
  /**
2
28
  * Details for npm package entries.
3
29
  */
@@ -136,5 +162,4 @@ export declare class DlxManifest {
136
162
  */
137
163
  setPackageEntry(spec: string, cacheKey: string, details: PackageDetails): Promise<void>;
138
164
  }
139
- // Export singleton instance using default manifest location.
140
165
  export declare const dlxManifest: DlxManifest;
@@ -1,5 +1,6 @@
1
1
  "use strict";
2
2
  /* Socket Lib - Built with esbuild */
3
+ "use strict";
3
4
  var __defProp = Object.defineProperty;
4
5
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
6
  var __getOwnPropNames = Object.getOwnPropertyNames;
@@ -34,14 +35,14 @@ let _path;
34
35
  // @__NO_SIDE_EFFECTS__
35
36
  function getFs() {
36
37
  if (_fs === void 0) {
37
- _fs = require("fs");
38
+ _fs = require("node:fs");
38
39
  }
39
40
  return _fs;
40
41
  }
41
42
  // @__NO_SIDE_EFFECTS__
42
43
  function getPath() {
43
44
  if (_path === void 0) {
44
- _path = require("path");
45
+ _path = require("node:path");
45
46
  }
46
47
  return _path;
47
48
  }
@@ -69,19 +70,19 @@ class DlxManifest {
69
70
  readManifest() {
70
71
  try {
71
72
  if (!fs.existsSync(this.manifestPath)) {
72
- return /* @__PURE__ */ Object.create(null);
73
+ return { __proto__: null };
73
74
  }
74
75
  const rawContent = (0, import_fs.readFileUtf8Sync)(this.manifestPath);
75
76
  const content = (typeof rawContent === "string" ? rawContent : rawContent.toString("utf8")).trim();
76
77
  if (!content) {
77
- return /* @__PURE__ */ Object.create(null);
78
+ return { __proto__: null };
78
79
  }
79
80
  return JSON.parse(content);
80
81
  } catch (error) {
81
82
  logger.warn(
82
83
  `Failed to read manifest: ${error instanceof Error ? error.message : String(error)}`
83
84
  );
84
- return /* @__PURE__ */ Object.create(null);
85
+ return { __proto__: null };
85
86
  }
86
87
  }
87
88
  /**
@@ -212,7 +213,9 @@ class DlxManifest {
212
213
  */
213
214
  async set(name, record) {
214
215
  await import_process_lock.processLock.withLock(this.lockPath, async () => {
215
- let data = /* @__PURE__ */ Object.create(null);
216
+ let data = {
217
+ __proto__: null
218
+ };
216
219
  try {
217
220
  if (fs.existsSync(this.manifestPath)) {
218
221
  const content2 = fs.readFileSync(this.manifestPath, "utf8");
@@ -1,5 +1,38 @@
1
- import type { SpawnExtra, SpawnOptions } from '../spawn';
1
+ /**
2
+ * @fileoverview DLX package execution - Install and execute npm packages.
3
+ *
4
+ * This module provides functionality to install and execute npm packages
5
+ * in the ~/.socket/_dlx directory, similar to npx but with Socket's own cache.
6
+ *
7
+ * Uses content-addressed storage like npm's _npx:
8
+ * - Hash is generated from package spec (name@version)
9
+ * - Each unique spec gets its own directory: ~/.socket/_dlx/<hash>/
10
+ * - Allows caching multiple versions of the same package
11
+ *
12
+ * Concurrency protection:
13
+ * - Uses process-lock to prevent concurrent installation corruption
14
+ * - Lock file created at ~/.socket/_dlx/<hash>/concurrency.lock
15
+ * - Uses npm npx's concurrency.lock naming convention (5s stale, 2s touching)
16
+ * - Prevents multiple processes from corrupting the same package installation
17
+ *
18
+ * Version range handling:
19
+ * - Exact versions (1.0.0) use cache if available
20
+ * - Range versions (^1.0.0, ~1.0.0) auto-force to get latest within range
21
+ * - User can override with explicit force: false
22
+ *
23
+ * Key difference from dlx-binary.ts:
24
+ * - dlx-binary.ts: Downloads standalone binaries from URLs
25
+ * - dlx-package.ts: Installs npm packages from registries
26
+ *
27
+ * Implementation:
28
+ * - Uses Arborist for package installation (like npx, no npm CLI required)
29
+ * - Split into downloadPackage() and executePackage() for flexibility
30
+ * - dlxPackage() combines both for convenience
31
+ */
2
32
  import { spawn } from '../spawn';
33
+ import type { HashSpec } from './integrity';
34
+ import type { LockfileSpec } from './lockfile';
35
+ import type { SpawnExtra, SpawnOptions } from '../spawn';
3
36
  export interface DownloadPackageResult {
4
37
  /** Path to the installed package directory. */
5
38
  packageDir: string;
@@ -8,7 +41,29 @@ export interface DownloadPackageResult {
8
41
  /** Whether the package was newly installed. */
9
42
  installed: boolean;
10
43
  }
11
- export interface DlxPackageOptions {
44
+ /**
45
+ * Shared install-pinning options used by both {@link DlxPackageOptions}
46
+ * and the lower-level {@link ensurePackageInstalled}.
47
+ */
48
+ export interface EnsurePackageInstallOptions {
49
+ /**
50
+ * Expected hash of the top-level package tarball. Accepts either:
51
+ * - A bare sha512 SRI string (sniffed as integrity).
52
+ * - A bare sha256 hex string (sniffed as checksum).
53
+ * - An explicit `{ type: 'integrity' | 'checksum', value }` object.
54
+ */
55
+ hash?: HashSpec | undefined;
56
+ /**
57
+ * Vendored `package-lock.json` to drive a reproducible install. Accepts
58
+ * a filesystem path (sniffed) or raw JSON content (sniffed via leading
59
+ * `{`), or an explicit `{ type: 'path' | 'content', value }` object.
60
+ *
61
+ * When provided, the lockfile is written into the install dir before
62
+ * Arborist runs and a hardened `.npmrc` is placed alongside it.
63
+ */
64
+ lockfile?: LockfileSpec | undefined;
65
+ }
66
+ export interface DlxPackageOptions extends EnsurePackageInstallOptions {
12
67
  /**
13
68
  * Package to install (e.g., '@cyclonedx/cdxgen@10.0.0').
14
69
  * Aligns with npx --package flag.
@@ -114,7 +169,7 @@ export declare function downloadPackage(options: DlxPackageOptions): Promise<Dow
114
169
  * console.log(`Installed: ${installed}, dir: ${packageDir}`)
115
170
  * ```
116
171
  */
117
- export declare function ensurePackageInstalled(packageName: string, packageSpec: string, force: boolean): Promise<{
172
+ export declare function ensurePackageInstalled(packageName: string, packageSpec: string, force: boolean, install?: EnsurePackageInstallOptions | undefined): Promise<{
118
173
  installed: boolean;
119
174
  packageDir: string;
120
175
  }>;