@jini-ai/cli 0.7.3-next.1 → 0.7.3-next.3
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 +8 -0
- package/README.md +4 -0
- package/dist/flags.d.ts +18 -0
- package/dist/flags.js +15 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/request-fields.d.ts +41 -0
- package/dist/request-fields.js +57 -0
- package/package.json +5 -5
package/CHANGELOG.md
CHANGED
package/README.md
CHANGED
|
@@ -96,3 +96,7 @@ bounded lowercase-marker output preserved. Former direct `redactSecretLike` call
|
|
|
96
96
|
`redactSecrets({ input }, { policy: 'aggressive' })`; this explicit policy emits category markers
|
|
97
97
|
and also masks recognized PII. Core's default stays conservative for diagnostics. The CLI keeps
|
|
98
98
|
`sanitizeUnknownDeep` for bounded recursive JSON. Loopback warnings use `@jini-ai/core/net`.
|
|
99
|
+
|
|
100
|
+
## Wiring
|
|
101
|
+
|
|
102
|
+
**Strict request fields** — for a host command that reads one JSON request on stdin: `parseRequestObject`, `assertKnownFields`, `require*`. Every refusal comes from the host's `invalid()` factory, so wire codes and wording stay the host's. `parsePortValue` likewise hands the host a refusal reason so it keeps its own `--port` messages.
|
package/dist/flags.d.ts
CHANGED
|
@@ -64,4 +64,22 @@ export type CoercedCliValue = boolean | number | string;
|
|
|
64
64
|
export declare function coerceCliValue({ raw }: {
|
|
65
65
|
raw: string;
|
|
66
66
|
}): CoercedCliValue;
|
|
67
|
+
/** Why {@link parsePortValue} refused a port; the host maps each to its own wording. */
|
|
68
|
+
export interface PortRefusal {
|
|
69
|
+
reason: 'not-integer' | 'out-of-range';
|
|
70
|
+
raw: string | number;
|
|
71
|
+
/** The parsed number, present only for `out-of-range`. */
|
|
72
|
+
value?: number;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* A TCP port: an integer in 1..65535 after trimming. Out-of-range or non-integer input is a refusal,
|
|
76
|
+
* never a fall-through to another source, so `invalid` receives the reason and the host keeps its
|
|
77
|
+
* exact messages.
|
|
78
|
+
* @throws the error `invalid` returns.
|
|
79
|
+
*/
|
|
80
|
+
export declare function parsePortValue({ raw }: {
|
|
81
|
+
raw: string | number;
|
|
82
|
+
}, { invalid }: {
|
|
83
|
+
invalid: (refusal: PortRefusal) => Error;
|
|
84
|
+
}): number;
|
|
67
85
|
//# sourceMappingURL=flags.d.ts.map
|
package/dist/flags.js
CHANGED
|
@@ -114,4 +114,19 @@ export function coerceCliValue({ raw }) {
|
|
|
114
114
|
return Number(raw);
|
|
115
115
|
return raw;
|
|
116
116
|
}
|
|
117
|
+
/**
|
|
118
|
+
* A TCP port: an integer in 1..65535 after trimming. Out-of-range or non-integer input is a refusal,
|
|
119
|
+
* never a fall-through to another source, so `invalid` receives the reason and the host keeps its
|
|
120
|
+
* exact messages.
|
|
121
|
+
* @throws the error `invalid` returns.
|
|
122
|
+
*/
|
|
123
|
+
export function parsePortValue({ raw }, { invalid }) {
|
|
124
|
+
const str = String(raw).trim();
|
|
125
|
+
if (!/^\d+$/.test(str))
|
|
126
|
+
throw invalid({ reason: 'not-integer', raw });
|
|
127
|
+
const value = Number(str);
|
|
128
|
+
if (value < 1 || value > 65535)
|
|
129
|
+
throw invalid({ reason: 'out-of-range', raw, value });
|
|
130
|
+
return value;
|
|
131
|
+
}
|
|
117
132
|
//# sourceMappingURL=flags.js.map
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/** The host's refusal factory; its error is thrown for every rejected input. */
|
|
2
|
+
export interface InvalidRequestPort {
|
|
3
|
+
invalid: () => Error;
|
|
4
|
+
}
|
|
5
|
+
/**
|
|
6
|
+
* Parse bounded JSON without allowing parser diagnostics (which can quote secrets) to escape.
|
|
7
|
+
* @throws the host's `invalid()` error for null or over-cap text, bad JSON, arrays and non-objects.
|
|
8
|
+
* @complexity O(n) time and space for n bytes of JSON.
|
|
9
|
+
*/
|
|
10
|
+
export declare function parseRequestObject({ text }: {
|
|
11
|
+
text: string | null;
|
|
12
|
+
}, { maxBytes, invalid }: InvalidRequestPort & {
|
|
13
|
+
maxBytes?: number;
|
|
14
|
+
}): Record<string, unknown>;
|
|
15
|
+
/**
|
|
16
|
+
* Unknown fields fail before any file is opened; sensitive input cannot become an accidental
|
|
17
|
+
* future option.
|
|
18
|
+
*/
|
|
19
|
+
export declare function assertKnownFields({ record, fields }: {
|
|
20
|
+
record: Record<string, unknown>;
|
|
21
|
+
fields: readonly string[];
|
|
22
|
+
}, { invalid }: InvalidRequestPort): void;
|
|
23
|
+
export declare function requireObject({ value }: {
|
|
24
|
+
value: unknown;
|
|
25
|
+
}, { invalid }: InvalidRequestPort): Record<string, unknown>;
|
|
26
|
+
/** Non-empty after trim and free of NUL bytes. */
|
|
27
|
+
export declare function requireString({ value }: {
|
|
28
|
+
value: unknown;
|
|
29
|
+
}, { invalid }: InvalidRequestPort): string;
|
|
30
|
+
/** Absolute and free of `..` segments on both separators, so a request cannot walk out of the
|
|
31
|
+
* directory it names (Windows accepts `/` and `\`; drive and UNC roots stay absolute).
|
|
32
|
+
*/
|
|
33
|
+
export declare function requireAbsolutePath({ value }: {
|
|
34
|
+
value: unknown;
|
|
35
|
+
}, { invalid, isAbsolute: absolute }: InvalidRequestPort & {
|
|
36
|
+
isAbsolute?: (path: string) => boolean;
|
|
37
|
+
}): string;
|
|
38
|
+
export declare function requirePositiveInt({ value }: {
|
|
39
|
+
value: unknown;
|
|
40
|
+
}, { invalid }: InvalidRequestPort): number;
|
|
41
|
+
//# sourceMappingURL=request-fields.d.ts.map
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Strict field validation for a host command that reads one JSON request on stdin.
|
|
3
|
+
* `invalid` is always injected by the host, so wire codes and wording stay the host's;
|
|
4
|
+
* this module mints no error class.
|
|
5
|
+
*/
|
|
6
|
+
import { isAbsolute } from 'node:path';
|
|
7
|
+
/**
|
|
8
|
+
* Parse bounded JSON without allowing parser diagnostics (which can quote secrets) to escape.
|
|
9
|
+
* @throws the host's `invalid()` error for null or over-cap text, bad JSON, arrays and non-objects.
|
|
10
|
+
* @complexity O(n) time and space for n bytes of JSON.
|
|
11
|
+
*/
|
|
12
|
+
export function parseRequestObject({ text }, { maxBytes, invalid }) {
|
|
13
|
+
if (text === null || (maxBytes !== undefined && Buffer.byteLength(text) > maxBytes))
|
|
14
|
+
throw invalid();
|
|
15
|
+
let parsed;
|
|
16
|
+
try {
|
|
17
|
+
parsed = JSON.parse(text);
|
|
18
|
+
}
|
|
19
|
+
catch {
|
|
20
|
+
throw invalid();
|
|
21
|
+
}
|
|
22
|
+
return requireObject({ value: parsed }, { invalid });
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Unknown fields fail before any file is opened; sensitive input cannot become an accidental
|
|
26
|
+
* future option.
|
|
27
|
+
*/
|
|
28
|
+
export function assertKnownFields({ record, fields }, { invalid }) {
|
|
29
|
+
if (Object.keys(record).some(field => !fields.includes(field)))
|
|
30
|
+
throw invalid();
|
|
31
|
+
}
|
|
32
|
+
export function requireObject({ value }, { invalid }) {
|
|
33
|
+
if (!value || typeof value !== 'object' || Array.isArray(value))
|
|
34
|
+
throw invalid();
|
|
35
|
+
return value;
|
|
36
|
+
}
|
|
37
|
+
/** Non-empty after trim and free of NUL bytes. */
|
|
38
|
+
export function requireString({ value }, { invalid }) {
|
|
39
|
+
if (typeof value !== 'string' || value.trim().length === 0 || value.includes('\0'))
|
|
40
|
+
throw invalid();
|
|
41
|
+
return value;
|
|
42
|
+
}
|
|
43
|
+
/** Absolute and free of `..` segments on both separators, so a request cannot walk out of the
|
|
44
|
+
* directory it names (Windows accepts `/` and `\`; drive and UNC roots stay absolute).
|
|
45
|
+
*/
|
|
46
|
+
export function requireAbsolutePath({ value }, { invalid, isAbsolute: absolute = isAbsolute }) {
|
|
47
|
+
const path = requireString({ value }, { invalid });
|
|
48
|
+
if (!absolute(path) || path.split(/[\\/]/).includes('..'))
|
|
49
|
+
throw invalid();
|
|
50
|
+
return path;
|
|
51
|
+
}
|
|
52
|
+
export function requirePositiveInt({ value }, { invalid }) {
|
|
53
|
+
if (typeof value !== 'number' || !Number.isSafeInteger(value) || value < 1)
|
|
54
|
+
throw invalid();
|
|
55
|
+
return value;
|
|
56
|
+
}
|
|
57
|
+
//# sourceMappingURL=request-fields.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jini-ai/cli",
|
|
3
|
-
"version": "0.7.3-next.
|
|
3
|
+
"version": "0.7.3-next.3",
|
|
4
4
|
"description": "CLI transport shell for driving a Jini daemon over HTTP: flag parsing, daemon-URL resolution, local daemon discovery, and a pluggable command registry.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"repository": {
|
|
@@ -54,12 +54,12 @@
|
|
|
54
54
|
},
|
|
55
55
|
"devDependencies": {
|
|
56
56
|
"commander": "^15.0.0",
|
|
57
|
-
"@jini-ai/
|
|
58
|
-
"@jini-ai/
|
|
57
|
+
"@jini-ai/sidecar": "0.7.3-next.3",
|
|
58
|
+
"@jini-ai/core": "0.7.3-next.3"
|
|
59
59
|
},
|
|
60
60
|
"dependencies": {
|
|
61
|
-
"@jini-ai/
|
|
62
|
-
"@jini-ai/
|
|
61
|
+
"@jini-ai/core": "^0.7.3-next.3",
|
|
62
|
+
"@jini-ai/sidecar": "^0.7.3-next.3"
|
|
63
63
|
},
|
|
64
64
|
"scripts": {
|
|
65
65
|
"build": "tsc -p tsconfig.json && chmod +x dist/main.js",
|