@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.
- package/CHANGELOG.md +25 -0
- package/dist/abort.js.map +2 -2
- package/dist/argv/parse.js.map +2 -2
- package/dist/arrays.d.ts +143 -0
- package/dist/arrays.js.map +2 -2
- package/dist/bin.js +1 -4
- package/dist/bin.js.map +2 -2
- package/dist/cacache.d.ts +0 -2
- package/dist/cacache.js +0 -1
- package/dist/cacache.js.map +2 -2
- package/dist/cache-with-ttl.js.map +2 -2
- package/dist/dlx.js.map +2 -2
- package/dist/external/@yarnpkg/extensions.d.ts +0 -1
- package/dist/external/cacache.d.ts +0 -7
- package/dist/external/debug.d.ts +0 -3
- package/dist/external/fast-sort.d.ts +0 -1
- package/dist/external/libnpmpack.d.ts +0 -1
- package/dist/external/make-fetch-happen.d.ts +0 -1
- package/dist/external/pacote.d.ts +0 -5
- package/dist/external/semver.d.ts +0 -1
- package/dist/external/validate-npm-package-name.js +1 -1
- package/dist/external/yargs-parser.d.ts +0 -1
- package/dist/external/yoctocolors-cjs.js +1 -1
- package/dist/external/zod.js +9 -9
- package/dist/fs.d.ts +595 -23
- package/dist/fs.js.map +2 -2
- package/dist/git.d.ts +488 -41
- package/dist/git.js.map +2 -2
- package/dist/github.d.ts +361 -12
- package/dist/github.js.map +2 -2
- package/dist/http-request.d.ts +463 -4
- package/dist/http-request.js.map +2 -2
- package/dist/json.d.ts +177 -4
- package/dist/json.js.map +2 -2
- package/dist/logger.d.ts +823 -70
- package/dist/logger.js +654 -51
- package/dist/logger.js.map +2 -2
- package/dist/objects.d.ts +386 -10
- package/dist/objects.js.map +2 -2
- package/dist/path.d.ts +270 -6
- package/dist/path.js.map +2 -2
- package/dist/promises.d.ts +432 -27
- package/dist/promises.js +3 -0
- package/dist/promises.js.map +2 -2
- package/dist/signal-exit.js.map +2 -2
- package/dist/sorts.js.map +2 -2
- package/dist/spawn.d.ts +242 -33
- package/dist/spawn.js.map +2 -2
- package/dist/spinner.d.ts +260 -20
- package/dist/spinner.js +201 -63
- package/dist/spinner.js.map +2 -2
- package/dist/stdio/clear.d.ts +130 -9
- package/dist/stdio/clear.js.map +2 -2
- package/dist/stdio/divider.d.ts +106 -10
- package/dist/stdio/divider.js +10 -0
- package/dist/stdio/divider.js.map +2 -2
- package/dist/stdio/footer.d.ts +70 -3
- package/dist/stdio/footer.js.map +2 -2
- package/dist/stdio/header.d.ts +93 -12
- package/dist/stdio/header.js.map +2 -2
- package/dist/stdio/mask.d.ts +82 -14
- package/dist/stdio/mask.js +25 -4
- package/dist/stdio/mask.js.map +2 -2
- package/dist/stdio/progress.d.ts +112 -15
- package/dist/stdio/progress.js +43 -3
- package/dist/stdio/progress.js.map +2 -2
- package/dist/stdio/prompts.d.ts +95 -5
- package/dist/stdio/prompts.js.map +2 -2
- package/dist/stdio/stderr.d.ts +114 -11
- package/dist/stdio/stderr.js.map +2 -2
- package/dist/stdio/stdout.d.ts +107 -11
- package/dist/stdio/stdout.js.map +2 -2
- package/dist/strings.d.ts +357 -28
- package/dist/strings.js.map +2 -2
- package/dist/suppress-warnings.js.map +2 -2
- package/dist/validation/json-parser.d.ts +226 -7
- package/dist/validation/json-parser.js.map +2 -2
- package/dist/validation/types.d.ts +114 -12
- package/dist/validation/types.js.map +1 -1
- 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
|
-
*
|
|
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
|
|
10
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
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
|
-
|
|
29
|
-
|
|
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
|
|
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 *
|
|
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
|
|
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",
|