@socketsecurity/lib 1.0.4 → 1.1.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 (80) hide show
  1. package/CHANGELOG.md +25 -0
  2. package/dist/abort.js.map +2 -2
  3. package/dist/argv/parse.js.map +2 -2
  4. package/dist/arrays.d.ts +143 -0
  5. package/dist/arrays.js.map +2 -2
  6. package/dist/bin.js +1 -4
  7. package/dist/bin.js.map +2 -2
  8. package/dist/cacache.d.ts +0 -2
  9. package/dist/cacache.js +0 -1
  10. package/dist/cacache.js.map +2 -2
  11. package/dist/cache-with-ttl.js.map +2 -2
  12. package/dist/dlx.js.map +2 -2
  13. package/dist/external/@yarnpkg/extensions.d.ts +0 -1
  14. package/dist/external/cacache.d.ts +0 -7
  15. package/dist/external/debug.d.ts +0 -3
  16. package/dist/external/fast-sort.d.ts +0 -1
  17. package/dist/external/libnpmpack.d.ts +0 -1
  18. package/dist/external/make-fetch-happen.d.ts +0 -1
  19. package/dist/external/pacote.d.ts +0 -5
  20. package/dist/external/semver.d.ts +0 -1
  21. package/dist/external/validate-npm-package-name.js +1 -1
  22. package/dist/external/yargs-parser.d.ts +0 -1
  23. package/dist/external/yoctocolors-cjs.js +1 -1
  24. package/dist/external/zod.js +9 -9
  25. package/dist/fs.d.ts +595 -23
  26. package/dist/fs.js.map +2 -2
  27. package/dist/git.d.ts +488 -41
  28. package/dist/git.js.map +2 -2
  29. package/dist/github.d.ts +361 -12
  30. package/dist/github.js.map +2 -2
  31. package/dist/http-request.d.ts +463 -4
  32. package/dist/http-request.js.map +2 -2
  33. package/dist/json.d.ts +177 -4
  34. package/dist/json.js.map +2 -2
  35. package/dist/logger.d.ts +823 -70
  36. package/dist/logger.js +654 -51
  37. package/dist/logger.js.map +2 -2
  38. package/dist/objects.d.ts +386 -10
  39. package/dist/objects.js.map +2 -2
  40. package/dist/path.d.ts +270 -6
  41. package/dist/path.js.map +2 -2
  42. package/dist/promises.d.ts +432 -27
  43. package/dist/promises.js +3 -0
  44. package/dist/promises.js.map +2 -2
  45. package/dist/signal-exit.js.map +2 -2
  46. package/dist/sorts.js.map +2 -2
  47. package/dist/spawn.d.ts +242 -33
  48. package/dist/spawn.js.map +2 -2
  49. package/dist/spinner.d.ts +260 -20
  50. package/dist/spinner.js +201 -63
  51. package/dist/spinner.js.map +2 -2
  52. package/dist/stdio/clear.d.ts +130 -9
  53. package/dist/stdio/clear.js.map +2 -2
  54. package/dist/stdio/divider.d.ts +106 -10
  55. package/dist/stdio/divider.js +10 -0
  56. package/dist/stdio/divider.js.map +2 -2
  57. package/dist/stdio/footer.d.ts +70 -3
  58. package/dist/stdio/footer.js.map +2 -2
  59. package/dist/stdio/header.d.ts +93 -12
  60. package/dist/stdio/header.js.map +2 -2
  61. package/dist/stdio/mask.d.ts +82 -14
  62. package/dist/stdio/mask.js +25 -4
  63. package/dist/stdio/mask.js.map +2 -2
  64. package/dist/stdio/progress.d.ts +112 -15
  65. package/dist/stdio/progress.js +43 -3
  66. package/dist/stdio/progress.js.map +2 -2
  67. package/dist/stdio/prompts.d.ts +95 -5
  68. package/dist/stdio/prompts.js.map +2 -2
  69. package/dist/stdio/stderr.d.ts +114 -11
  70. package/dist/stdio/stderr.js.map +2 -2
  71. package/dist/stdio/stdout.d.ts +107 -11
  72. package/dist/stdio/stdout.js.map +2 -2
  73. package/dist/strings.d.ts +357 -28
  74. package/dist/strings.js.map +2 -2
  75. package/dist/suppress-warnings.js.map +2 -2
  76. package/dist/validation/json-parser.d.ts +226 -7
  77. package/dist/validation/json-parser.js.map +2 -2
  78. package/dist/validation/types.d.ts +114 -12
  79. package/dist/validation/types.js.map +1 -1
  80. package/package.json +5 -3
@@ -1,35 +1,137 @@
1
1
  /**
2
2
  * @fileoverview Validation type definitions.
3
+ * Provides core types for schema validation and JSON parsing with security features.
3
4
  */
4
5
  /**
5
- * Schema parse result.
6
+ * Result of a schema validation operation.
7
+ * Contains either successful parsed data or error information.
8
+ *
9
+ * @template T - The expected type of the parsed data
10
+ *
11
+ * @example
12
+ * ```ts
13
+ * const result: ParseResult<User> = schema.safeParse(data)
14
+ * if (result.success) {
15
+ * console.log(result.data) // User object
16
+ * } else {
17
+ * console.error(result.error) // Error details
18
+ * }
19
+ * ```
6
20
  */
7
21
  export interface ParseResult<T> {
22
+ /** Indicates whether parsing was successful */
8
23
  success: boolean;
9
- data?: T;
10
- // biome-ignore lint/suspicious/noExplicitAny: Error can be any schema validation error.
24
+ /** Parsed and validated data (only present when `success` is `true`) */
25
+ data?: T | undefined;
26
+ /** Error information (only present when `success` is `false`) */
11
27
  error?: any;
12
28
  }
13
29
  /**
14
- * Base schema interface.
30
+ * Base schema interface compatible with Zod and similar validation libraries.
31
+ * Provides both safe and throwing parsing methods.
32
+ *
33
+ * @template T - The expected output type after validation
34
+ *
35
+ * @example
36
+ * ```ts
37
+ * import { z } from 'zod'
38
+ *
39
+ * const userSchema = z.object({
40
+ * name: z.string(),
41
+ * age: z.number()
42
+ * })
43
+ *
44
+ * // Schema satisfies this interface
45
+ * const schema: Schema<User> = userSchema
46
+ * const result = schema.safeParse({ name: 'Alice', age: 30 })
47
+ * ```
15
48
  */
16
- // biome-ignore lint/suspicious/noExplicitAny: Schema interface accepts any input data for validation.
17
49
  export interface Schema<T = any> {
18
- // biome-ignore lint/suspicious/noExplicitAny: Validation accepts any input data.
50
+ /**
51
+ * Safely parse data without throwing errors.
52
+ * Returns a result object indicating success or failure.
53
+ *
54
+ * @param data - The data to validate
55
+ * @returns Parse result with success flag and data or error
56
+ */
19
57
  safeParse(data: any): ParseResult<T>;
20
- // biome-ignore lint/suspicious/noExplicitAny: Validation accepts any input data.
58
+ /**
59
+ * Parse data and throw an error if validation fails.
60
+ * Use this when you want to fail fast on invalid data.
61
+ *
62
+ * @param data - The data to validate
63
+ * @returns The validated and parsed data
64
+ * @throws {Error} When validation fails
65
+ */
21
66
  parse(data: any): T;
22
- _name?: string;
67
+ /**
68
+ * Optional schema name for debugging and error messages.
69
+ * Useful for identifying which schema failed in complex validation chains.
70
+ */
71
+ _name?: string | undefined;
23
72
  }
24
73
  /**
25
- * JSON parse options.
74
+ * Options for configuring JSON parsing behavior with security controls.
75
+ *
76
+ * @example
77
+ * ```ts
78
+ * const options: JsonParseOptions = {
79
+ * maxSize: 1024 * 1024, // 1MB limit
80
+ * allowPrototype: false // Block prototype pollution
81
+ * }
82
+ * ```
26
83
  */
27
84
  export interface JsonParseOptions {
28
- maxSize?: number;
29
- allowPrototype?: boolean;
85
+ /**
86
+ * Allow dangerous prototype pollution keys (`__proto__`, `constructor`, `prototype`).
87
+ * Set to `true` only if you trust the JSON source completely.
88
+ *
89
+ * @default false
90
+ *
91
+ * @example
92
+ * ```ts
93
+ * // Will throw error by default
94
+ * safeJsonParse('{"__proto__": {"polluted": true}}')
95
+ *
96
+ * // Allows the parse (dangerous!)
97
+ * safeJsonParse('{"__proto__": {"polluted": true}}', undefined, {
98
+ * allowPrototype: true
99
+ * })
100
+ * ```
101
+ */
102
+ allowPrototype?: boolean | undefined;
103
+ /**
104
+ * Maximum allowed size of JSON string in bytes.
105
+ * Prevents memory exhaustion from extremely large payloads.
106
+ *
107
+ * @default 10485760 (10 MB)
108
+ *
109
+ * @example
110
+ * ```ts
111
+ * // Limit to 1KB
112
+ * safeJsonParse(jsonString, undefined, { maxSize: 1024 })
113
+ * ```
114
+ */
115
+ maxSize?: number | undefined;
30
116
  }
31
117
  /**
32
- * JSON parse result.
118
+ * Discriminated union type for JSON parsing results.
119
+ * Enables type-safe handling of success and failure cases.
120
+ *
121
+ * @template T - The expected type of the parsed data
122
+ *
123
+ * @example
124
+ * ```ts
125
+ * const result: JsonParseResult<User> = parseJsonWithResult(jsonString)
126
+ *
127
+ * if (result.success) {
128
+ * // TypeScript knows result.data is available
129
+ * console.log(result.data.name)
130
+ * } else {
131
+ * // TypeScript knows result.error is available
132
+ * console.error(result.error)
133
+ * }
134
+ * ```
33
135
  */
34
136
  export type JsonParseResult<T> = {
35
137
  success: true;
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/validation/types.ts"],
4
- "sourcesContent": ["/**\n * @fileoverview Validation type definitions.\n */\n\n/**\n * Schema parse result.\n */\nexport interface ParseResult<T> {\n success: boolean\n data?: T\n // biome-ignore lint/suspicious/noExplicitAny: Error can be any schema validation error.\n error?: any\n}\n\n/**\n * Base schema interface.\n */\n// biome-ignore lint/suspicious/noExplicitAny: Schema interface accepts any input data for validation.\nexport interface Schema<T = any> {\n // biome-ignore lint/suspicious/noExplicitAny: Validation accepts any input data.\n safeParse(data: any): ParseResult<T>\n // biome-ignore lint/suspicious/noExplicitAny: Validation accepts any input data.\n parse(data: any): T\n _name?: string\n}\n\n/**\n * JSON parse options.\n */\nexport interface JsonParseOptions {\n maxSize?: number\n allowPrototype?: boolean\n}\n\n/**\n * JSON parse result.\n */\nexport type JsonParseResult<T> =\n | { success: true; data: T }\n | { success: false; error: string }\n"],
4
+ "sourcesContent": ["/**\n * @fileoverview Validation type definitions.\n * Provides core types for schema validation and JSON parsing with security features.\n */\n\n/**\n * Result of a schema validation operation.\n * Contains either successful parsed data or error information.\n *\n * @template T - The expected type of the parsed data\n *\n * @example\n * ```ts\n * const result: ParseResult<User> = schema.safeParse(data)\n * if (result.success) {\n * console.log(result.data) // User object\n * } else {\n * console.error(result.error) // Error details\n * }\n * ```\n */\nexport interface ParseResult<T> {\n /** Indicates whether parsing was successful */\n success: boolean\n /** Parsed and validated data (only present when `success` is `true`) */\n data?: T | undefined\n /** Error information (only present when `success` is `false`) */\n error?: any\n}\n\n/**\n * Base schema interface compatible with Zod and similar validation libraries.\n * Provides both safe and throwing parsing methods.\n *\n * @template T - The expected output type after validation\n *\n * @example\n * ```ts\n * import { z } from 'zod'\n *\n * const userSchema = z.object({\n * name: z.string(),\n * age: z.number()\n * })\n *\n * // Schema satisfies this interface\n * const schema: Schema<User> = userSchema\n * const result = schema.safeParse({ name: 'Alice', age: 30 })\n * ```\n */\nexport interface Schema<T = any> {\n /**\n * Safely parse data without throwing errors.\n * Returns a result object indicating success or failure.\n *\n * @param data - The data to validate\n * @returns Parse result with success flag and data or error\n */\n safeParse(data: any): ParseResult<T>\n\n /**\n * Parse data and throw an error if validation fails.\n * Use this when you want to fail fast on invalid data.\n *\n * @param data - The data to validate\n * @returns The validated and parsed data\n * @throws {Error} When validation fails\n */\n parse(data: any): T\n\n /**\n * Optional schema name for debugging and error messages.\n * Useful for identifying which schema failed in complex validation chains.\n */\n _name?: string | undefined\n}\n\n/**\n * Options for configuring JSON parsing behavior with security controls.\n *\n * @example\n * ```ts\n * const options: JsonParseOptions = {\n * maxSize: 1024 * 1024, // 1MB limit\n * allowPrototype: false // Block prototype pollution\n * }\n * ```\n */\nexport interface JsonParseOptions {\n /**\n * Allow dangerous prototype pollution keys (`__proto__`, `constructor`, `prototype`).\n * Set to `true` only if you trust the JSON source completely.\n *\n * @default false\n *\n * @example\n * ```ts\n * // Will throw error by default\n * safeJsonParse('{\"__proto__\": {\"polluted\": true}}')\n *\n * // Allows the parse (dangerous!)\n * safeJsonParse('{\"__proto__\": {\"polluted\": true}}', undefined, {\n * allowPrototype: true\n * })\n * ```\n */\n allowPrototype?: boolean | undefined\n\n /**\n * Maximum allowed size of JSON string in bytes.\n * Prevents memory exhaustion from extremely large payloads.\n *\n * @default 10485760 (10 MB)\n *\n * @example\n * ```ts\n * // Limit to 1KB\n * safeJsonParse(jsonString, undefined, { maxSize: 1024 })\n * ```\n */\n maxSize?: number | undefined\n}\n\n/**\n * Discriminated union type for JSON parsing results.\n * Enables type-safe handling of success and failure cases.\n *\n * @template T - The expected type of the parsed data\n *\n * @example\n * ```ts\n * const result: JsonParseResult<User> = parseJsonWithResult(jsonString)\n *\n * if (result.success) {\n * // TypeScript knows result.data is available\n * console.log(result.data.name)\n * } else {\n * // TypeScript knows result.error is available\n * console.error(result.error)\n * }\n * ```\n */\nexport type JsonParseResult<T> =\n | { success: true; data: T }\n | { success: false; error: string }\n"],
5
5
  "mappings": ";;;;;;;;;;;;;;AAAA;AAAA;",
6
6
  "names": []
7
7
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@socketsecurity/lib",
3
- "version": "1.0.4",
3
+ "version": "1.1.0",
4
4
  "license": "MIT",
5
5
  "description": "Core utilities and infrastructure for Socket.dev security tools",
6
6
  "keywords": [
@@ -697,7 +697,8 @@
697
697
  "./package.json": "./package.json",
698
698
  "./taze.config.json": "./taze.config.json",
699
699
  "./tsconfig.dts.json": "./tsconfig.dts.json",
700
- "./tsconfig.json": "./tsconfig.json"
700
+ "./tsconfig.json": "./tsconfig.json",
701
+ "./tsconfig.test.json": "./tsconfig.test.json"
701
702
  },
702
703
  "imports": {
703
704
  "#constants/*": "./dist/constants/*.js",
@@ -732,7 +733,8 @@
732
733
  "prepublishOnly": "pnpm run build",
733
734
  "test": "node scripts/test.mjs",
734
735
  "test-ci": "vitest run",
735
- "type-ci": "pnpm run check"
736
+ "type-ci": "pnpm run check",
737
+ "update": "node scripts/update.mjs"
736
738
  },
737
739
  "devDependencies": {
738
740
  "@babel/core": "7.28.4",