@typescriptprime/securereq 1.0.0-build.2 โ†’ 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.
Files changed (2) hide show
  1. package/README.md +57 -97
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -1,145 +1,105 @@
1
- # @typescriptprime/parsing
1
+ # SecureReq ๐Ÿ”
2
2
 
3
- Lightweight helper utilities for parsing CLI-style arguments, implemented in TypeScript.
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
- ## ๐Ÿ“ฆ Install
13
-
14
- ```bash
15
- npm install @typescriptprime/parsing
16
- ```
7
+ ## ๐Ÿš€ Quick Summary
17
8
 
18
- > [!NOTE]
19
- > This repo is authored as an ES module and fully typed with TypeScript.
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
- ## Usage
24
-
25
- Import the helpers from the package and combine them to parse `process.argv`:
15
+ ## ๐Ÿ“ฆ Installation
26
16
 
27
- ```typescript
28
- import { PreProcessing, PostProcessing } from '@typescriptprime/parsing'
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
- ### Naming Convention
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
- ## โšก Quick Examples
25
+ ## Usage Examples ๐Ÿ”ง
59
26
 
60
- From `process.argv` in Node.js:
27
+ Import and call the helper:
61
28
 
62
- ```typescript
63
- const Argv = ['/usr/local/bin/node', '/path/to/script.js', '--enable-feature', '--parameter', 'value', '--', 'positional1', 'positional2']
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
- const { Options, Positional } = await PostProcessing(Tokens)
69
- // Options === { EnableFeature: true, Parameter: 'value' }
70
- // Positional === ['positional1', 'positional2']
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
- Boolean flags example:
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
- ```ts
76
- const Tokens = PreProcessing(['/usr/bin/node', '/script.js', '--flag', '--other', 'value'])
77
- // tokens === ['--flag', '--other', 'value']
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
- - `PostProcessing<I extends JSONValue>(Args: string[], FuncOptions?: IParsingOptions): Promise<{ Options: I, Positional: string[] }>`
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
- ### Types
53
+ - `Url: URL` โ€” Target URL (must be an instance of `URL`).
54
+ - `Options?: HTTPSRequestOptions` โ€” Optional configuration object.
94
55
 
95
- - `JSONValue`, `JSONObject`, `JSONArray`, `JSONPrimitive` โ€” standard JSON type helpers
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
- ## Scripts
62
+ ### HTTPSRequestOptions
102
63
 
103
- - `npm run build` โ€” runs: `esbuild` to bundle the compiled JS and TypeScript compiler to emit declarations.
104
- - `npm test` โ€” runs AVA tests.
105
- - `npm run lint` โ€” runs ESLint checks.
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
- This project is published as an ES module. If you are developing locally, the following commands are useful:
71
+ ### HTTPSResponse
108
72
 
109
- - `npm run build:esbuild` โ€” bundle with esbuild (JS output)
110
- - `npm run build:tsc` โ€” emit TypeScript declarations only
73
+ - `{ StatusCode: number, Headers: Record<string,string|string[]|undefined>, Body: T }`
111
74
 
112
- The package `exports` are configured in `package.json` so importing the default entry works with ESM loaders.
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
- ## Tests
81
+ ## Security & Behavior Notes ๐Ÿ”
117
82
 
118
- The `tests/` directory contains unit tests for both `PreProcessing` and `PostProcessing` with AVA. They include:
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
- - PreProcessing: removes node executable and file name using different `process.argv` shapes
121
- - PostProcessing: parsing single/two parameters, boolean flags, and the `--` positional argument separator.
87
+ ---
122
88
 
123
- Run tests with:
89
+ ## Development & Testing ๐Ÿงช
124
90
 
125
- ```bash
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
- ## Project Layout
97
+ ## Contributing
132
98
 
133
- - `sources/` โ€” TypeScript source files for the package
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
- Licensed under the Apache-2.0 license โ€” see `LICENSE` for details.
105
+ This project is licensed under the **Apache-2.0** License. See the `LICENSE` file for details.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@typescriptprime/securereq",
3
3
  "type": "module",
4
- "version": "1.0.0-build.2",
4
+ "version": "1.0.1",
5
5
  "description": "SecureReq is a lightweight utility for making secure HTTP requests, implemented in TypeScript",
6
6
  "keywords": [
7
7
  "https",