@typescriptprime/securereq 1.0.0 โ 1.0.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.
- package/README.md +57 -97
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,145 +1,105 @@
|
|
|
1
|
-
#
|
|
1
|
+
# SecureReq ๐
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
This package provides two small helpers:
|
|
6
|
-
|
|
7
|
-
- `PreProcessing` โ trims `process.argv` to remove the node executable and optional script filename, returning the array of option tokens.
|
|
8
|
-
- `PostProcessing` โ parses the token list that looks like `--Name Value` into a typed options object and an array of positional arguments (everything after `--`).
|
|
3
|
+
**SecureReq** is a lightweight TypeScript utility for making secure HTTPS requests with strict TLS defaults and typed response parsing.
|
|
9
4
|
|
|
10
5
|
---
|
|
11
6
|
|
|
12
|
-
##
|
|
13
|
-
|
|
14
|
-
```bash
|
|
15
|
-
npm install @typescriptprime/parsing
|
|
16
|
-
```
|
|
7
|
+
## ๐ Quick Summary
|
|
17
8
|
|
|
18
|
-
|
|
19
|
-
|
|
9
|
+
- **Small, dependency-light** wrapper around Node's `https` for typed responses and safer TLS defaults.
|
|
10
|
+
- Defaults to **TLSv1.3**, Post Quantum Cryptography key exchange, a limited set of strongest ciphers, and a `User-Agent` header.
|
|
11
|
+
- Supports typed response parsing: `JSON`, `String`, or raw `ArrayBuffer`.
|
|
20
12
|
|
|
21
13
|
---
|
|
22
14
|
|
|
23
|
-
##
|
|
24
|
-
|
|
25
|
-
Import the helpers from the package and combine them to parse `process.argv`:
|
|
15
|
+
## ๐ฆ Installation
|
|
26
16
|
|
|
27
|
-
```
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
async function Main(Argv: string[]) {
|
|
31
|
-
// Step 1: Trim the node executable and optional script path
|
|
32
|
-
const Filtered = PreProcessing(Argv)
|
|
33
|
-
|
|
34
|
-
// Step 2: Parse CLI-style parameters into an options object and positional arguments
|
|
35
|
-
const { Options, Positional } = await PostProcessing(Filtered)
|
|
36
|
-
|
|
37
|
-
console.log('Options:', Options)
|
|
38
|
-
console.log('Positional args:', Positional)
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
Main(process.argv)
|
|
17
|
+
```bash
|
|
18
|
+
npm install @typescriptprime/securereq
|
|
42
19
|
```
|
|
43
20
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
By default, `PostProcessing` converts parameter names into PascalCase using `es-toolkit` (so `--parameter-name` becomes `ParameterName`). You can supply a custom `NamingConvention` function via `IParsingOptions`:
|
|
47
|
-
|
|
48
|
-
```typescript
|
|
49
|
-
import * as ESToolkit from 'es-toolkit'
|
|
50
|
-
|
|
51
|
-
await PostProcessing(argv, { NamingConvention: ESToolkit.camelCase })
|
|
52
|
-
// or custom:
|
|
53
|
-
await PostProcessing(argv, { NamingConvention: (s) => s.replace(/^--/, '') })
|
|
54
|
-
```
|
|
21
|
+
**Requirements:** Node.js >= 24
|
|
55
22
|
|
|
56
23
|
---
|
|
57
24
|
|
|
58
|
-
##
|
|
25
|
+
## Usage Examples ๐ง
|
|
59
26
|
|
|
60
|
-
|
|
27
|
+
Import and call the helper:
|
|
61
28
|
|
|
62
|
-
```
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
const Tokens = PreProcessing(Argv)
|
|
66
|
-
// tokens === ['--enable-feature', '--parameter', 'value', '--', 'positional1', 'positional2']
|
|
29
|
+
```ts
|
|
30
|
+
import { HTTPSRequest } from '@typescriptprime/securereq'
|
|
67
31
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
32
|
+
// JSON (auto-detected by .json path) or explicit
|
|
33
|
+
const url = new URL('https://api64.ipify.org?format=json')
|
|
34
|
+
const res = await HTTPSRequest(url)
|
|
35
|
+
console.log(res.StatusCode) // number
|
|
36
|
+
console.log(res.Body) // ArrayBuffer or parsed JSON depending on `ExpectedAs` and URL
|
|
72
37
|
|
|
73
|
-
|
|
38
|
+
// Force string
|
|
39
|
+
const html = await HTTPSRequest(new URL('https://www.example.com/'), { ExpectedAs: 'String' })
|
|
40
|
+
console.log(typeof html.Body) // 'string'
|
|
74
41
|
|
|
75
|
-
|
|
76
|
-
const
|
|
77
|
-
|
|
78
|
-
const { Options } = await PostProcessing(Tokens)
|
|
79
|
-
// Options === { Flag: true, Other: 'value' }
|
|
42
|
+
// Force ArrayBuffer
|
|
43
|
+
const raw = await HTTPSRequest(new URL('https://example.com/'), { ExpectedAs: 'ArrayBuffer' })
|
|
44
|
+
console.log(raw.Body instanceof ArrayBuffer)
|
|
80
45
|
```
|
|
81
46
|
|
|
82
47
|
---
|
|
83
48
|
|
|
84
|
-
## API
|
|
85
|
-
|
|
86
|
-
- `PreProcessing(argv: typeof process.argv): string[]`
|
|
87
|
-
- Removes the node executable and optional file argument and returns the tokens starting at the first option.
|
|
49
|
+
## API Reference ๐
|
|
88
50
|
|
|
89
|
-
|
|
90
|
-
- Converts `--key value` pairs into a typed `Options` object; flags without values are treated as `true`.
|
|
91
|
-
- Stops parsing options when it hits `--` and returns the rest as `Positional` arguments.
|
|
51
|
+
### HTTPSRequest(Url, Options?)
|
|
92
52
|
|
|
93
|
-
|
|
53
|
+
- `Url: URL` โ Target URL (must be an instance of `URL`).
|
|
54
|
+
- `Options?: HTTPSRequestOptions` โ Optional configuration object.
|
|
94
55
|
|
|
95
|
-
|
|
96
|
-
- `IParsingOptions` โ currently supports:
|
|
97
|
-
- `NamingConvention?: (PropertyName: string) => string | Promise<string>`
|
|
56
|
+
Returns: `Promise<HTTPSResponse<T>>` where `T` is determined by `ExpectedAs`.
|
|
98
57
|
|
|
99
|
-
|
|
58
|
+
Throws:
|
|
59
|
+
- `TypeError` when `Url` is not a `URL` instance.
|
|
60
|
+
- `Error` on request failure or on failed response parsing (e.g., invalid JSON).
|
|
100
61
|
|
|
101
|
-
|
|
62
|
+
### HTTPSRequestOptions
|
|
102
63
|
|
|
103
|
-
|
|
104
|
-
- `
|
|
105
|
-
- `
|
|
64
|
+
Fields:
|
|
65
|
+
- `TLS?: { IsHTTPSEnforced?: boolean, MinTLSVersion?: 'TLSv1.2'|'TLSv1.3', MaxTLSVersion?: 'TLSv1.2'|'TLSv1.3', Ciphers?: string[], KeyExchanges?: string[] }`
|
|
66
|
+
- Defaults: `IsHTTPSEnforced: true`, both Min and Max set to `TLSv1.3`, a small secure cipher list and key exchange choices.
|
|
67
|
+
- When `IsHTTPSEnforced` is `true`, a non-`https:` URL will throw.
|
|
68
|
+
- `HttpHeaders?: Record<string,string>` โ Custom headers. A `User-Agent` header is provided by default.
|
|
69
|
+
- `ExpectedAs?: 'JSON'|'String'|'ArrayBuffer'` โ How to parse the response body.
|
|
106
70
|
|
|
107
|
-
|
|
71
|
+
### HTTPSResponse
|
|
108
72
|
|
|
109
|
-
- `
|
|
110
|
-
- `npm run build:tsc` โ emit TypeScript declarations only
|
|
73
|
+
- `{ StatusCode: number, Headers: Record<string,string|string[]|undefined>, Body: T }`
|
|
111
74
|
|
|
112
|
-
|
|
75
|
+
Notes:
|
|
76
|
+
- If `ExpectedAs` is omitted, a heuristic is used: `.json` โ `JSON`, `.txt` โ `String`, otherwise `ArrayBuffer`.
|
|
77
|
+
- When `ExpectedAs` is `JSON`, the body is parsed and an error is thrown if parsing fails.
|
|
113
78
|
|
|
114
79
|
---
|
|
115
80
|
|
|
116
|
-
##
|
|
81
|
+
## Security & Behavior Notes ๐
|
|
117
82
|
|
|
118
|
-
|
|
83
|
+
- Strict TLS defaults lean on **TLSv1.3** and a reduced cipher list to encourage secure transport out of the box.
|
|
84
|
+
- TLS options are forwarded to Node's HTTPS layer (`minVersion`, `maxVersion`, `ciphers`, `ecdhCurve`).
|
|
85
|
+
- The library uses `zod` for runtime validation of options.
|
|
119
86
|
|
|
120
|
-
|
|
121
|
-
- PostProcessing: parsing single/two parameters, boolean flags, and the `--` positional argument separator.
|
|
87
|
+
---
|
|
122
88
|
|
|
123
|
-
|
|
89
|
+
## Development & Testing ๐งช
|
|
124
90
|
|
|
125
|
-
|
|
126
|
-
npm test
|
|
127
|
-
|
|
91
|
+
- Build: `npm run build` (uses `esbuild` + `tsc` for types)
|
|
92
|
+
- Test: `npm test` (uses `ava`)
|
|
93
|
+
- Lint: `npm run lint`
|
|
128
94
|
|
|
129
95
|
---
|
|
130
96
|
|
|
131
|
-
##
|
|
97
|
+
## Contributing
|
|
132
98
|
|
|
133
|
-
|
|
134
|
-
- `index.ts` โ entry exports
|
|
135
|
-
- `preprocessing/index.ts` โ `PreProcessing` implementation
|
|
136
|
-
- `postprocessing/index.ts` โ `PostProcessing` implementation
|
|
137
|
-
- `types.ts` โ JSON types and `IParsingOptions`
|
|
138
|
-
- `dist/` โ build output (ignored in source control)
|
|
139
|
-
- `tests/` โ unit tests using AVA
|
|
99
|
+
Contributions, bug reports and PRs are welcome โ please follow the repository's contribution guidelines.
|
|
140
100
|
|
|
141
101
|
---
|
|
142
102
|
|
|
143
103
|
## License
|
|
144
104
|
|
|
145
|
-
|
|
105
|
+
This project is licensed under the **Apache-2.0** License. See the `LICENSE` file for details.
|
package/package.json
CHANGED