@socketsecurity/lib 5.19.0 → 5.20.1

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 (39) hide show
  1. package/CHANGELOG.md +44 -0
  2. package/dist/cache-with-ttl.d.ts +7 -0
  3. package/dist/cache-with-ttl.js +26 -7
  4. package/dist/constants/socket.js +1 -1
  5. package/dist/dlx/lockfile.js +4 -1
  6. package/dist/dlx/manifest.d.ts +10 -4
  7. package/dist/dlx/package.d.ts +1 -1
  8. package/dist/dlx/package.js +5 -2
  9. package/dist/external/@inquirer/checkbox.js +5 -0
  10. package/dist/external/@inquirer/confirm.js +5 -0
  11. package/dist/external/@inquirer/input.js +5 -0
  12. package/dist/external/@inquirer/password.js +5 -0
  13. package/dist/external/@inquirer/search.js +5 -0
  14. package/dist/external/@inquirer/select.js +5 -0
  15. package/dist/external/@npmcli/package-json/lib/read-package.js +40 -32
  16. package/dist/external/@npmcli/package-json/lib/sort.js +104 -92
  17. package/dist/external/@sinclair/typebox/value.js +9007 -0
  18. package/dist/external/@sinclair/typebox.js +7891 -0
  19. package/dist/external/external-pack.js +2749 -28
  20. package/dist/http-request.d.ts +0 -25
  21. package/dist/http-request.js +6 -5
  22. package/dist/ipc.js +43 -10
  23. package/dist/json/edit.d.ts +1 -1
  24. package/dist/memoization.js +6 -0
  25. package/dist/paths/packages.js +6 -2
  26. package/dist/promise-queue.js +1 -1
  27. package/dist/stdio/clear.d.ts +163 -0
  28. package/dist/stdio/clear.js +96 -0
  29. package/dist/stdio/progress.d.ts +152 -0
  30. package/dist/stdio/progress.js +217 -0
  31. package/dist/stdio/prompts.d.ts +196 -0
  32. package/dist/stdio/prompts.js +177 -0
  33. package/dist/tables.js +2 -3
  34. package/dist/validation/validate-schema.d.ts +124 -0
  35. package/dist/validation/validate-schema.js +108 -0
  36. package/package.json +25 -6
  37. package/dist/external/zod.js +0 -7825
  38. package/dist/zod.d.ts +0 -5
  39. package/dist/zod.js +0 -30
@@ -0,0 +1,124 @@
1
+ /**
2
+ * @fileoverview Universal schema validation for Zod-style schemas (Zod v3,
3
+ * v4, and any `safeParse`-shaped duck type).
4
+ *
5
+ * Accepts a schema and returns a tagged result.
6
+ * - `{ ok: true, value }` — validation passed, `value` is typed as the
7
+ * schema's inferred output (`z.infer<typeof S>`).
8
+ * - `{ ok: false, errors }` — validation failed, `errors` is a normalized
9
+ * list of `{ path, message }`.
10
+ *
11
+ * Zod is detected purely structurally via `.safeParse` — no runtime import of
12
+ * the `zod` package is required by socket-lib.
13
+ *
14
+ * @internal
15
+ * Socket-lib additionally recognizes TypeBox schemas for its own internal
16
+ * use (e.g. `src/ipc.ts`'s stub-file validation). That path is not a
17
+ * supported consumer API — callers should use Zod.
18
+ */
19
+ import type { Schema } from './types';
20
+ /**
21
+ * TypeBox's `Kind` symbol. We reference it structurally for schema detection
22
+ * rather than importing it from `@sinclair/typebox` — detection scans the
23
+ * schema's own-symbol keys for one whose description is `'TypeBox.Kind'`.
24
+ * The `Value` runtime is only loaded lazily when a TypeBox schema is seen.
25
+ */
26
+ type TypeBoxKindSymbol = symbol & {
27
+ __typeBoxKindBrand?: never;
28
+ };
29
+ /**
30
+ * Structural minimum of a TypeBox `TSchema`. The phantom `static` field is
31
+ * the type TypeBox uses for inference (`Static<T> = T['static']`).
32
+ */
33
+ interface TypeBoxLikeSchema {
34
+ [k: TypeBoxKindSymbol]: string;
35
+ static: unknown;
36
+ }
37
+ /**
38
+ * Structural shape of a Zod v4 schema — carries output type on `_zod.output`.
39
+ */
40
+ interface ZodV4LikeSchema<O = unknown> {
41
+ _zod: {
42
+ output: O;
43
+ };
44
+ safeParse(data: unknown): unknown;
45
+ }
46
+ /**
47
+ * Structural shape of a Zod v3 schema — carries output type on `_output`.
48
+ */
49
+ interface ZodV3LikeSchema<O = unknown> {
50
+ _output: O;
51
+ safeParse(data: unknown): unknown;
52
+ }
53
+ /**
54
+ * Any schema kind this helper accepts.
55
+ */
56
+ export type AnySchema = TypeBoxLikeSchema | ZodV4LikeSchema<unknown> | ZodV3LikeSchema<unknown> | Schema<unknown>;
57
+ /**
58
+ * Infer the validated output type from any supported schema kind.
59
+ *
60
+ * Order matters: TypeBox schemas also carry a phantom `static` field, so we
61
+ * check for TypeBox before falling through to Zod and the duck-type.
62
+ */
63
+ export type Infer<S> = S extends {
64
+ static: infer Static;
65
+ } ? Static : S extends {
66
+ _zod: {
67
+ output: infer O;
68
+ };
69
+ } ? O : S extends {
70
+ _output: infer O;
71
+ } ? O : S extends Schema<infer T> ? T : unknown;
72
+ /**
73
+ * A single normalized validation error.
74
+ * - `path` is a dotted or slash-separated identifier locating the bad value.
75
+ * - `message` is human-readable.
76
+ */
77
+ export interface ValidationIssue {
78
+ /** Array path into the value (e.g. `['user', 'age']`). */
79
+ path: Array<string | number>;
80
+ /** Human-readable description of the failure. */
81
+ message: string;
82
+ }
83
+ /**
84
+ * Tagged-union result of {@link validateSchema}. Callers narrow on `ok`.
85
+ */
86
+ export type ValidateResult<T> = {
87
+ ok: true;
88
+ value: T;
89
+ } | {
90
+ ok: false;
91
+ errors: ValidationIssue[];
92
+ };
93
+ /**
94
+ * Validate `data` against a Zod-style `schema`. Non-throwing.
95
+ *
96
+ * Accepted schemas:
97
+ * - `zod` schemas, v3 and v4 (detected via `.safeParse` on the schema)
98
+ * - Any object conforming to {@link Schema} (the socket-lib duck type)
99
+ *
100
+ * The return type narrows `value` to {@link Infer | `Infer<S>`}, so callers
101
+ * get `z.infer<typeof S>` with no casts.
102
+ *
103
+ * @example
104
+ * ```ts
105
+ * import { z } from 'zod'
106
+ * const U = z.object({ name: z.string() })
107
+ * const r = validateSchema(U, data)
108
+ * if (r.ok) r.value.name // string
109
+ * ```
110
+ *
111
+ * Errors are normalized to {@link ValidationIssue}: `{ path, message }`.
112
+ */
113
+ export declare function validateSchema<S>(schema: S, data: unknown): ValidateResult<Infer<S>>;
114
+ /**
115
+ * Parse `data` against `schema` and return the validated value. Throws if
116
+ * validation fails. This is the throwing twin of {@link validateSchema}.
117
+ *
118
+ * Use when you want fail-fast semantics at a trust boundary. For recoverable
119
+ * validation (form input, external configs), prefer {@link validateSchema}.
120
+ *
121
+ * @throws {Error} When validation fails. The message lists all issues.
122
+ */
123
+ export declare function parseSchema<S>(schema: S, data: unknown): Infer<S>;
124
+ export {};
@@ -0,0 +1,108 @@
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 validate_schema_exports = {};
22
+ __export(validate_schema_exports, {
23
+ parseSchema: () => parseSchema,
24
+ validateSchema: () => validateSchema
25
+ });
26
+ module.exports = __toCommonJS(validate_schema_exports);
27
+ function isTypeBoxSchema(schema) {
28
+ if (schema === null || typeof schema !== "object") {
29
+ return false;
30
+ }
31
+ for (const sym of Object.getOwnPropertySymbols(schema)) {
32
+ if (sym.description === "TypeBox.Kind") {
33
+ return typeof schema[sym] === "string";
34
+ }
35
+ }
36
+ return false;
37
+ }
38
+ function normalizeTypeBoxErrors(errors) {
39
+ const out = [];
40
+ for (const err of errors) {
41
+ const segs = err.path.split("/").filter(Boolean);
42
+ out.push({
43
+ path: segs.map((s) => {
44
+ const n = Number(s);
45
+ return Number.isInteger(n) && String(n) === s ? n : s;
46
+ }),
47
+ message: err.message
48
+ });
49
+ }
50
+ return out;
51
+ }
52
+ function normalizeZodError(err) {
53
+ if (err === null || typeof err !== "object") {
54
+ return [{ path: [], message: String(err) }];
55
+ }
56
+ const issues = err.issues;
57
+ if (!Array.isArray(issues)) {
58
+ return [{ path: [], message: "Unknown validation error" }];
59
+ }
60
+ return issues.map((issue) => {
61
+ const i = issue;
62
+ return {
63
+ path: Array.isArray(i.path) ? i.path : [],
64
+ message: typeof i.message === "string" ? i.message : "Invalid value"
65
+ };
66
+ });
67
+ }
68
+ function validateSchema(schema, data) {
69
+ if (isTypeBoxSchema(schema)) {
70
+ const { Value } = require("../external/@sinclair/typebox/value");
71
+ if (Value.Check(schema, data)) {
72
+ return { ok: true, value: data };
73
+ }
74
+ return {
75
+ ok: false,
76
+ errors: normalizeTypeBoxErrors(Value.Errors(schema, data))
77
+ };
78
+ }
79
+ if (schema !== null && typeof schema === "object" && typeof schema.safeParse === "function") {
80
+ const result = schema.safeParse(data);
81
+ if (result.success === true) {
82
+ return {
83
+ ok: true,
84
+ value: result.data
85
+ };
86
+ }
87
+ return {
88
+ ok: false,
89
+ errors: normalizeZodError(result.error)
90
+ };
91
+ }
92
+ throw new TypeError(
93
+ "validateSchema: unsupported schema kind. Expected a TypeBox schema, a Zod schema, or an object with a safeParse method."
94
+ );
95
+ }
96
+ function parseSchema(schema, data) {
97
+ const result = validateSchema(schema, data);
98
+ if (result.ok) {
99
+ return result.value;
100
+ }
101
+ const summary = result.errors.map((e) => `${e.path.join(".") || "(root)"}: ${e.message}`).join(", ");
102
+ throw new Error(`Validation failed: ${summary}`);
103
+ }
104
+ // Annotate the CommonJS export names for ESM import in node:
105
+ 0 && (module.exports = {
106
+ parseSchema,
107
+ validateSchema
108
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@socketsecurity/lib",
3
- "version": "5.19.0",
3
+ "version": "5.20.1",
4
4
  "packageManager": "pnpm@11.0.0-rc.2",
5
5
  "license": "MIT",
6
6
  "description": "Core utilities and infrastructure for Socket.dev security tools",
@@ -575,6 +575,10 @@
575
575
  "types": "./dist/ssri.d.ts",
576
576
  "default": "./dist/ssri.js"
577
577
  },
578
+ "./stdio/clear": {
579
+ "types": "./dist/stdio/clear.d.ts",
580
+ "default": "./dist/stdio/clear.js"
581
+ },
578
582
  "./stdio/divider": {
579
583
  "types": "./dist/stdio/divider.d.ts",
580
584
  "default": "./dist/stdio/divider.js"
@@ -587,6 +591,14 @@
587
591
  "types": "./dist/stdio/header.d.ts",
588
592
  "default": "./dist/stdio/header.js"
589
593
  },
594
+ "./stdio/progress": {
595
+ "types": "./dist/stdio/progress.d.ts",
596
+ "default": "./dist/stdio/progress.js"
597
+ },
598
+ "./stdio/prompts": {
599
+ "types": "./dist/stdio/prompts.d.ts",
600
+ "default": "./dist/stdio/prompts.js"
601
+ },
590
602
  "./stdio/stderr": {
591
603
  "types": "./dist/stdio/stderr.d.ts",
592
604
  "default": "./dist/stdio/stderr.js"
@@ -651,6 +663,10 @@
651
663
  "types": "./dist/validation/types.d.ts",
652
664
  "default": "./dist/validation/types.js"
653
665
  },
666
+ "./validation/validate-schema": {
667
+ "types": "./dist/validation/validate-schema.d.ts",
668
+ "default": "./dist/validation/validate-schema.js"
669
+ },
654
670
  "./versions": {
655
671
  "types": "./dist/versions.d.ts",
656
672
  "default": "./dist/versions.js"
@@ -659,10 +675,6 @@
659
675
  "types": "./dist/words.d.ts",
660
676
  "default": "./dist/words.js"
661
677
  },
662
- "./zod": {
663
- "types": "./dist/zod.d.ts",
664
- "default": "./dist/zod.js"
665
- },
666
678
  "./data/extensions.json": "./data/extensions.json",
667
679
  "./package.json": "./package.json",
668
680
  "./tsconfig.dts.json": "./tsconfig.dts.json",
@@ -699,13 +711,20 @@
699
711
  "@babel/parser": "7.28.4",
700
712
  "@babel/traverse": "7.28.4",
701
713
  "@babel/types": "7.28.4",
714
+ "@inquirer/checkbox": "5.1.3",
715
+ "@inquirer/confirm": "6.0.11",
716
+ "@inquirer/input": "5.0.11",
717
+ "@inquirer/password": "5.0.11",
718
+ "@inquirer/search": "4.1.7",
719
+ "@inquirer/select": "5.1.3",
702
720
  "@npmcli/arborist": "9.1.4",
703
721
  "@npmcli/package-json": "7.0.0",
704
722
  "@npmcli/promise-spawn": "8.0.3",
723
+ "@sinclair/typebox": "0.34.49",
705
724
  "@socketregistry/is-unicode-supported": "1.0.5",
706
725
  "@socketregistry/packageurl-js": "1.4.2",
707
726
  "@socketregistry/yocto-spinner": "1.0.25",
708
- "@socketsecurity/lib-stable": "npm:@socketsecurity/lib@5.18.2",
727
+ "@socketsecurity/lib-stable": "npm:@socketsecurity/lib@5.19.1",
709
728
  "@types/node": "24.9.2",
710
729
  "@typescript/native-preview": "7.0.0-dev.20260415.1",
711
730
  "@vitest/coverage-v8": "4.0.3",