@jini-ai/devops 0.3.3 → 0.5.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 +120 -0
- package/README.md +65 -5
- package/dist/agent-jobs/entry.d.ts +4 -0
- package/dist/agent-jobs/entry.js +4 -0
- package/dist/agent-jobs/jobs.d.ts +25 -0
- package/dist/agent-jobs/jobs.js +115 -0
- package/dist/agent-jobs/node.d.ts +12 -0
- package/dist/agent-jobs/node.js +53 -0
- package/dist/agent-jobs/ports.d.ts +69 -0
- package/dist/agent-jobs/ports.js +2 -0
- package/dist/checks/coverage/diff.d.ts +57 -0
- package/dist/checks/coverage/diff.js +48 -0
- package/dist/checks/coverage/disk.d.ts +65 -0
- package/dist/checks/coverage/disk.js +136 -0
- package/dist/checks/coverage/floors.d.ts +31 -0
- package/dist/checks/coverage/floors.js +24 -0
- package/dist/checks/coverage/index.d.ts +7 -0
- package/dist/checks/coverage/index.js +6 -0
- package/dist/checks/coverage/integrity.d.ts +79 -0
- package/dist/checks/coverage/integrity.js +140 -0
- package/dist/checks/coverage/lcov.d.ts +65 -0
- package/dist/checks/coverage/lcov.js +64 -0
- package/dist/checks/node.d.ts +19 -0
- package/dist/checks/node.js +40 -0
- package/dist/checks/ports.d.ts +67 -0
- package/dist/checks/ports.js +2 -0
- package/dist/checks/published-types/index.d.ts +77 -0
- package/dist/checks/published-types/index.js +186 -0
- package/dist/deploy/host-kit.d.ts +27 -10
- package/dist/deploy/index.d.ts +0 -4
- package/dist/deploy/index.js +0 -4
- package/dist/deploy/naming.d.ts +9 -6
- package/dist/deploy/naming.js +5 -7
- package/dist/deploy/node.d.ts +18 -0
- package/dist/deploy/node.js +57 -0
- package/dist/deploy/reachability.d.ts +47 -18
- package/dist/deploy/reachability.js +77 -71
- package/dist/deploy/redirect-guard.d.ts +15 -11
- package/dist/deploy/redirect-guard.js +11 -12
- package/dist/deploy/tokens.d.ts +17 -14
- package/dist/deploy/tokens.js +16 -16
- package/dist/deploy/tool.d.ts +12 -8
- package/dist/deploy/tool.js +9 -10
- package/dist/deploy/types.d.ts +27 -15
- package/dist/deploy/types.js +3 -3
- package/dist/index.d.ts +2 -1
- package/dist/index.js +2 -1
- package/dist/local-dev/index.d.ts +34 -0
- package/dist/local-dev/index.js +37 -0
- package/dist/packaging/electron/archive.d.ts +41 -0
- package/dist/packaging/electron/archive.js +77 -0
- package/dist/packaging/electron/asar-adapter.d.ts +13 -0
- package/dist/packaging/electron/asar-adapter.js +5 -0
- package/dist/packaging/electron/entry.d.ts +9 -0
- package/dist/packaging/electron/entry.js +9 -0
- package/dist/packaging/electron/imports.d.ts +13 -0
- package/dist/packaging/electron/imports.js +44 -0
- package/dist/packaging/electron/node.d.ts +8 -0
- package/dist/packaging/electron/node.js +51 -0
- package/dist/packaging/electron/policies.d.ts +64 -0
- package/dist/packaging/electron/policies.js +63 -0
- package/dist/packaging/electron/ports.d.ts +113 -0
- package/dist/packaging/electron/ports.js +2 -0
- package/dist/packaging/electron/stability.d.ts +9 -0
- package/dist/packaging/electron/stability.js +12 -0
- package/dist/packaging/electron/staging.d.ts +108 -0
- package/dist/packaging/electron/staging.js +249 -0
- package/dist/packaging/electron/typescript.d.ts +7 -0
- package/dist/packaging/electron/typescript.js +18 -0
- package/dist/source-control/commit.d.ts +11 -0
- package/dist/source-control/commit.js +71 -0
- package/dist/source-control/contracts.d.ts +327 -0
- package/dist/source-control/contracts.js +2 -0
- package/dist/source-control/entry.d.ts +6 -0
- package/dist/source-control/entry.js +6 -0
- package/dist/source-control/kit.d.ts +15 -0
- package/dist/source-control/kit.js +17 -0
- package/dist/source-control/registry.d.ts +100 -0
- package/dist/source-control/registry.js +174 -0
- package/dist/source-control/repository-target.d.ts +13 -0
- package/dist/source-control/repository-target.js +28 -0
- package/dist/static-export/contracts.d.ts +138 -0
- package/dist/static-export/contracts.js +5 -0
- package/dist/static-export/entry.d.ts +6 -0
- package/dist/static-export/entry.js +6 -0
- package/dist/static-export/failure-summary.d.ts +12 -0
- package/dist/static-export/failure-summary.js +12 -0
- package/dist/static-export/fetch-adapter.d.ts +6 -0
- package/dist/static-export/fetch-adapter.js +5 -0
- package/dist/static-export/node-adapters.d.ts +11 -0
- package/dist/static-export/node-adapters.js +111 -0
- package/dist/static-export/runner.d.ts +6 -0
- package/dist/static-export/runner.js +135 -0
- package/dist/static-export/transforms.d.ts +53 -0
- package/dist/static-export/transforms.js +154 -0
- package/package.json +82 -5
- package/dist/deploy/cloudflare-pages.d.ts +0 -105
- package/dist/deploy/cloudflare-pages.js +0 -943
- package/dist/deploy/github-pages.d.ts +0 -62
- package/dist/deploy/github-pages.js +0 -373
- package/dist/deploy/netlify.d.ts +0 -40
- package/dist/deploy/netlify.js +0 -299
- package/dist/deploy/vercel.d.ts +0 -56
- package/dist/deploy/vercel.js +0 -258
|
@@ -1,20 +1,49 @@
|
|
|
1
|
-
import { createValidatingLookup } from '@jini-ai/platform';
|
|
2
1
|
import type { DeployLinkStatus, DeploymentUrlCheck } from './types.js';
|
|
3
2
|
/**
|
|
4
3
|
* Provider-supplied hook for recognizing a deployment URL that responded
|
|
5
|
-
* but is gated behind the provider's own auth wall (
|
|
6
|
-
*
|
|
7
|
-
* instead of hardcoding
|
|
8
|
-
*
|
|
9
|
-
* detector or omit one entirely.
|
|
4
|
+
* but is gated behind the provider's own auth wall (a deployment-protection
|
|
5
|
+
* login page, for example) rather than genuinely down. Kept pluggable
|
|
6
|
+
* instead of hardcoding one provider's SSO-nonce/header sniffing here, so
|
|
7
|
+
* each target can supply its own detector or omit one entirely.
|
|
10
8
|
*/
|
|
11
|
-
export type ProtectedResponseDetector = (
|
|
9
|
+
export type ProtectedResponseDetector = (requiredArgs: {
|
|
10
|
+
resp: Response;
|
|
11
|
+
body: string;
|
|
12
|
+
}) => boolean;
|
|
13
|
+
/** Synchronous outbound URL policy, shaped like the OAuth guard without an OAuth dependency.
|
|
14
|
+
* Connection-time DNS enforcement belongs to the paired transport, never a preflight lookup. */
|
|
15
|
+
export interface DeploymentUrlGuard {
|
|
16
|
+
assertSafeUrl(requiredArgs: {
|
|
17
|
+
raw: string;
|
|
18
|
+
label: string;
|
|
19
|
+
}): URL;
|
|
20
|
+
}
|
|
21
|
+
/** HTTP transport port. Hosts must enforce connection-time DNS policy and honor redirects/signals. */
|
|
22
|
+
export type ReachabilityFetchPort = (requiredArgs: {
|
|
23
|
+
url: string;
|
|
24
|
+
}, optionalArgs?: {
|
|
25
|
+
init?: RequestInit;
|
|
26
|
+
}) => Promise<Response>;
|
|
27
|
+
/** The caller supplies the paired URL guard and connection-time policy-enforcing transport. */
|
|
28
|
+
export interface ReachabilityArgs {
|
|
29
|
+
url: unknown;
|
|
30
|
+
fetch: ReachabilityFetchPort;
|
|
31
|
+
guard: DeploymentUrlGuard;
|
|
32
|
+
}
|
|
33
|
+
/** Polling uses host-supplied time and delay ports for deterministic scheduling. */
|
|
34
|
+
export interface ReachabilityWaitArgs {
|
|
35
|
+
urls: unknown[];
|
|
36
|
+
fetch: ReachabilityFetchPort;
|
|
37
|
+
guard: DeploymentUrlGuard;
|
|
38
|
+
now(requiredArgs: Record<string, never>): number;
|
|
39
|
+
sleep(requiredArgs: {
|
|
40
|
+
ms: number;
|
|
41
|
+
}): Promise<void>;
|
|
42
|
+
}
|
|
12
43
|
export interface ReachabilityOptions {
|
|
13
44
|
timeoutMs?: number;
|
|
14
45
|
detectProtected?: ProtectedResponseDetector;
|
|
15
46
|
protectedMessage?: string;
|
|
16
|
-
/** Injectable `dns.lookup` for the connection-time SSRF guard (tests only — see `assertSafeDeploymentUrl`). */
|
|
17
|
-
lookupImpl?: Parameters<typeof createValidatingLookup>[0];
|
|
18
47
|
}
|
|
19
48
|
export interface ReachabilityWaitOptions {
|
|
20
49
|
timeoutMs?: number;
|
|
@@ -22,8 +51,6 @@ export interface ReachabilityWaitOptions {
|
|
|
22
51
|
providerLabel?: string;
|
|
23
52
|
detectProtected?: ProtectedResponseDetector;
|
|
24
53
|
protectedMessage?: string;
|
|
25
|
-
/** Injectable `dns.lookup` for the connection-time SSRF guard (tests only). */
|
|
26
|
-
lookupImpl?: Parameters<typeof createValidatingLookup>[0];
|
|
27
54
|
}
|
|
28
55
|
export interface ReachabilityWaitResult {
|
|
29
56
|
status: DeployLinkStatus;
|
|
@@ -33,33 +60,35 @@ export interface ReachabilityWaitResult {
|
|
|
33
60
|
}
|
|
34
61
|
/**
|
|
35
62
|
* Normalizes a raw provider-returned URL/hostname into an absolute
|
|
36
|
-
* `https://` URL (bare hostnames like `foo.
|
|
63
|
+
* `https://` URL (bare hostnames like `foo.example.app` are assumed https).
|
|
37
64
|
*
|
|
38
|
-
* @param
|
|
65
|
+
* @param requiredArgs - Raw `url` from a provider response; may be undefined/non-string.
|
|
39
66
|
* @returns The normalized absolute URL, or `''` if `url` was empty/non-string.
|
|
40
67
|
* @complexity O(1).
|
|
41
68
|
* @overallScore 100/100
|
|
42
69
|
*/
|
|
43
|
-
export declare function normalizeDeploymentUrl(url
|
|
70
|
+
export declare function normalizeDeploymentUrl({ url }: {
|
|
71
|
+
url: unknown;
|
|
72
|
+
}): string;
|
|
44
73
|
/**
|
|
45
74
|
* Probes a single deployment URL, trying HEAD first and falling back to
|
|
46
75
|
* GET when HEAD is rejected or ambiguous (some hosts don't implement HEAD
|
|
47
76
|
* correctly on generated static routes).
|
|
48
77
|
*
|
|
49
|
-
* @param
|
|
78
|
+
* @param requiredArgs - Raw URL/hostname and paired fetch and outbound-guard ports.
|
|
50
79
|
* @param options - Timeout (default 8s) and optional protected-response detector.
|
|
51
80
|
* @returns A `DeploymentUrlCheck` for the best of the HEAD/GET attempts.
|
|
52
81
|
* @complexity O(1)-O(2) network round-trips.
|
|
53
82
|
* @overallScore 100/100
|
|
54
83
|
*/
|
|
55
|
-
export declare function checkDeploymentUrl(url:
|
|
84
|
+
export declare function checkDeploymentUrl({ url, fetch: fetchPort, guard }: ReachabilityArgs, options?: ReachabilityOptions): Promise<DeploymentUrlCheck>;
|
|
56
85
|
/**
|
|
57
86
|
* Polls a set of deployment URL candidates until one becomes reachable, one
|
|
58
87
|
* reports as provider-protected, or `timeoutMs` elapses. Used right after a
|
|
59
88
|
* publish call returns, since providers frequently accept the deploy before
|
|
60
89
|
* the URL is actually resolvable.
|
|
61
90
|
*
|
|
62
|
-
* @param
|
|
91
|
+
* @param requiredArgs - Candidate URLs/hostnames and required fetch, guard, clock and delay ports.
|
|
63
92
|
* @param options - `timeoutMs` (default 60s), `intervalMs` between sweeps (default 2s),
|
|
64
93
|
* `providerLabel` for messages, and the optional protected-response detector.
|
|
65
94
|
* @returns `{ status, url, statusMessage, reachableAt? }`. `status: 'link-delayed'`
|
|
@@ -68,5 +97,5 @@ export declare function checkDeploymentUrl(url: unknown, options?: ReachabilityO
|
|
|
68
97
|
* @complexity O(candidates * timeoutMs/intervalMs) network round-trips, bounded by timeoutMs.
|
|
69
98
|
* @overallScore 100/100
|
|
70
99
|
*/
|
|
71
|
-
export declare function waitForReachableDeploymentUrl(urls:
|
|
100
|
+
export declare function waitForReachableDeploymentUrl({ urls, fetch: fetchPort, guard, now, sleep }: ReachabilityWaitArgs, options?: ReachabilityWaitOptions): Promise<ReachabilityWaitResult>;
|
|
72
101
|
//# sourceMappingURL=reachability.d.ts.map
|
|
@@ -1,38 +1,36 @@
|
|
|
1
|
-
import { Agent } from 'undici';
|
|
2
|
-
import { assertSafePublicUrl, AssetCacheError, createValidatingLookup } from '@jini-ai/platform';
|
|
3
1
|
/**
|
|
4
2
|
* SEC-003: reachability probes fetch a *provider-returned* URL/alias
|
|
5
|
-
* (
|
|
3
|
+
* (a deployment's `url`/`alias`/`aliases[]` from the host), so a compromised or
|
|
6
4
|
* malicious provider response is a live SSRF vector — the same trust-boundary
|
|
7
|
-
* shape
|
|
8
|
-
* Reused
|
|
5
|
+
* shape the Node default adapter's asset-cache guard solves for a caller-supplied media URL.
|
|
6
|
+
* Reused by `./node.ts` rather than reinvented (see
|
|
9
7
|
* ADS-memory/reports/security/SEC-backend-coverage-push-2026-07-20.md, SEC-003,
|
|
10
8
|
* which cites asset-cache as "a good model for deploy reachability"):
|
|
11
|
-
* `assertSafePublicUrl` fast-rejects bad schemes/credentials/localhost/literal
|
|
9
|
+
* The Node adapter pairs these ports: `assertSafePublicUrl` fast-rejects bad schemes/credentials/localhost/literal
|
|
12
10
|
* private IPs before any socket opens, and `createValidatingLookup` is wired
|
|
13
11
|
* as the fetch dispatcher's connection-time `lookup` so the address that is
|
|
14
12
|
* *validated* is the exact address the socket *connects to* — closing the
|
|
15
13
|
* DNS-rebinding/TOCTOU gap a separate pre-validation lookup would leave open.
|
|
16
14
|
*/
|
|
17
|
-
function assertSafeDeploymentUrl(raw) {
|
|
18
|
-
const url =
|
|
15
|
+
function assertSafeDeploymentUrl(raw, guard) {
|
|
16
|
+
const url = guard.assertSafeUrl({ raw, label: 'deployment url' });
|
|
19
17
|
if (url.protocol !== 'https:') {
|
|
20
18
|
// Deployment providers always serve over TLS; an http:// candidate is
|
|
21
19
|
// never legitimate and downgrading a probe to plaintext is its own risk.
|
|
22
|
-
throw new
|
|
20
|
+
throw new Error('deployment url must use https');
|
|
23
21
|
}
|
|
24
22
|
return url;
|
|
25
23
|
}
|
|
26
24
|
/**
|
|
27
25
|
* Normalizes a raw provider-returned URL/hostname into an absolute
|
|
28
|
-
* `https://` URL (bare hostnames like `foo.
|
|
26
|
+
* `https://` URL (bare hostnames like `foo.example.app` are assumed https).
|
|
29
27
|
*
|
|
30
|
-
* @param
|
|
28
|
+
* @param requiredArgs - Raw `url` from a provider response; may be undefined/non-string.
|
|
31
29
|
* @returns The normalized absolute URL, or `''` if `url` was empty/non-string.
|
|
32
30
|
* @complexity O(1).
|
|
33
31
|
* @overallScore 100/100
|
|
34
32
|
*/
|
|
35
|
-
export function normalizeDeploymentUrl(url) {
|
|
33
|
+
export function normalizeDeploymentUrl({ url }) {
|
|
36
34
|
if (typeof url !== 'string')
|
|
37
35
|
return '';
|
|
38
36
|
const trimmed = url.trim();
|
|
@@ -53,71 +51,54 @@ export function normalizeDeploymentUrl(url) {
|
|
|
53
51
|
* @complexity O(1) network round-trip.
|
|
54
52
|
* @overallScore 100/100
|
|
55
53
|
*/
|
|
56
|
-
|
|
57
|
-
// (no test override) case shares one lazily-created dispatcher. A caller-supplied
|
|
58
|
-
// `lookupImpl` (tests only) always gets its own dispatcher instead of touching the shared one.
|
|
59
|
-
let defaultDispatcher = null;
|
|
60
|
-
function resolveDispatcher(lookupImpl) {
|
|
61
|
-
if (lookupImpl) {
|
|
62
|
-
return new Agent({ connect: { lookup: createValidatingLookup(lookupImpl) } });
|
|
63
|
-
}
|
|
64
|
-
defaultDispatcher ??= new Agent({ connect: { lookup: createValidatingLookup() } });
|
|
65
|
-
return defaultDispatcher;
|
|
66
|
-
}
|
|
67
|
-
async function requestDeploymentUrl(url, method, timeoutMs, options) {
|
|
54
|
+
async function requestDeploymentUrl(url, method, timeoutMs, options, fetchPort, guard) {
|
|
68
55
|
let safeUrl;
|
|
69
56
|
try {
|
|
70
|
-
safeUrl = assertSafeDeploymentUrl(url);
|
|
57
|
+
safeUrl = assertSafeDeploymentUrl(url, guard);
|
|
71
58
|
}
|
|
72
59
|
catch (err) {
|
|
73
|
-
//
|
|
74
|
-
//
|
|
75
|
-
// two throw sources are `assertSafePublicUrl` (which itself only ever
|
|
76
|
-
// throws `AssetCacheError`, per `packages/platform/src/asset-cache.ts` —
|
|
77
|
-
// every one of its conditionals is an explicit `throw new
|
|
78
|
-
// AssetCacheError(...)`, including the `new URL(raw)` parse failure
|
|
79
|
-
// case) and this function's own explicit `throw new AssetCacheError(...)`
|
|
80
|
-
// for a non-https URL. `AssetCacheError extends Error`, so `err` here can
|
|
81
|
-
// only ever be a real `Error` instance. Kept (not simplified to
|
|
82
|
-
// `err.message`) because `err` is typed `unknown`, and a future edit to
|
|
83
|
-
// this function's own throw sites, or to `assertSafePublicUrl`'s, could
|
|
84
|
-
// reintroduce a non-Error throw without this file changing at all — see
|
|
85
|
-
// packages/devops/source-map.md's 2026-07-22 addition for the full
|
|
86
|
-
// re-derivation.
|
|
60
|
+
// Keep unknown throw values readable: host guards may throw values other than Error.
|
|
61
|
+
// The old concrete guard only threw AssetCacheError, but ports cannot assume that contract.
|
|
87
62
|
return {
|
|
88
63
|
reachable: false,
|
|
89
64
|
statusMessage: `Public link is not reachable yet: ${err instanceof Error ? err.message : String(err)}`,
|
|
90
65
|
};
|
|
91
66
|
}
|
|
92
67
|
const controller = new AbortController();
|
|
93
|
-
|
|
68
|
+
let timer;
|
|
69
|
+
// Race the transport as well as signalling it: an injected fetch/body reader may ignore abort.
|
|
70
|
+
const timeout = new Promise((_resolve, reject) => {
|
|
71
|
+
timer = setTimeout(() => {
|
|
72
|
+
reject(new Error(`probe timed out after ${timeoutMs}ms`));
|
|
73
|
+
controller.abort();
|
|
74
|
+
}, timeoutMs);
|
|
75
|
+
});
|
|
94
76
|
// Real refactor, not a padded test: this used to be `try { ... } catch {
|
|
95
77
|
// ... } finally { clearTimeout(timer); }`. A throwaway local repro (see
|
|
96
|
-
//
|
|
78
|
+
// the archived extraction source map's 2026-07-22 addition) proved that V8's own
|
|
97
79
|
// coverage instrumentation for a `try/catch/finally` where the `catch`
|
|
98
80
|
// always returns (never rethrows) emits a synthetic branch, at the
|
|
99
81
|
// `finally` keyword's own position, that no test can ever satisfy — a
|
|
100
82
|
// compiler/instrumentation artifact, not a real code path. Restructuring to
|
|
101
|
-
// `try/catch` with an explicit `clearTimeout(timer)`
|
|
102
|
-
//
|
|
83
|
+
// `try/catch` with an explicit `clearTimeout(timer)` after the complete
|
|
84
|
+
// response (headers and any body read) resolves (covering every path that can reach
|
|
103
85
|
// a return from inside the try) plus one in `catch` (covering the case
|
|
104
86
|
// `fetch` itself rejects, before that clear runs) has 100%-coverable
|
|
105
|
-
// branches
|
|
106
|
-
// every exit from this function either way.
|
|
87
|
+
// branches. That historical refactor preserved runtime behavior — the timer
|
|
88
|
+
// is cleared on every exit from this function either way. The deadline fix
|
|
89
|
+
// additionally keeps it active until body consumption finishes.
|
|
107
90
|
try {
|
|
108
|
-
//
|
|
109
|
-
//
|
|
110
|
-
// undici-types (bundled with @types/node) vs undici@7 Dispatcher version skew a typed
|
|
111
|
-
// field would trip over.
|
|
91
|
+
// The injected transport owns DNS pinning (the Node adapter attaches its validating dispatcher).
|
|
92
|
+
// A separate preflight resolver would leave the validation/connect TOCTOU gap open.
|
|
112
93
|
const init = { method, redirect: 'manual', signal: controller.signal };
|
|
113
|
-
|
|
114
|
-
const resp = await fetch(safeUrl.toString(), init);
|
|
115
|
-
clearTimeout(timer);
|
|
94
|
+
const resp = await Promise.race([fetchPort({ url: safeUrl.toString() }, { init }), timeout]);
|
|
116
95
|
if (resp.status >= 200 && resp.status < 400) {
|
|
96
|
+
clearTimeout(timer);
|
|
117
97
|
return { reachable: true, statusCode: resp.status };
|
|
118
98
|
}
|
|
119
|
-
const body = method === 'GET' || resp.status === 401 ? await resp.text() : '';
|
|
120
|
-
if (resp.status === 401 && options.detectProtected?.(resp, body)) {
|
|
99
|
+
const body = method === 'GET' || resp.status === 401 ? await Promise.race([resp.text(), timeout]) : '';
|
|
100
|
+
if (resp.status === 401 && options.detectProtected?.({ resp, body })) {
|
|
101
|
+
clearTimeout(timer);
|
|
121
102
|
return {
|
|
122
103
|
reachable: false,
|
|
123
104
|
status: 'protected',
|
|
@@ -125,6 +106,7 @@ async function requestDeploymentUrl(url, method, timeoutMs, options) {
|
|
|
125
106
|
statusMessage: options.protectedMessage ?? 'Deployment is protected by the provider.',
|
|
126
107
|
};
|
|
127
108
|
}
|
|
109
|
+
clearTimeout(timer);
|
|
128
110
|
return {
|
|
129
111
|
reachable: false,
|
|
130
112
|
statusCode: resp.status,
|
|
@@ -144,25 +126,30 @@ async function requestDeploymentUrl(url, method, timeoutMs, options) {
|
|
|
144
126
|
* GET when HEAD is rejected or ambiguous (some hosts don't implement HEAD
|
|
145
127
|
* correctly on generated static routes).
|
|
146
128
|
*
|
|
147
|
-
* @param
|
|
129
|
+
* @param requiredArgs - Raw URL/hostname and paired fetch and outbound-guard ports.
|
|
148
130
|
* @param options - Timeout (default 8s) and optional protected-response detector.
|
|
149
131
|
* @returns A `DeploymentUrlCheck` for the best of the HEAD/GET attempts.
|
|
150
132
|
* @complexity O(1)-O(2) network round-trips.
|
|
151
133
|
* @overallScore 100/100
|
|
152
134
|
*/
|
|
153
|
-
export async function checkDeploymentUrl(url, options = {}) {
|
|
154
|
-
const normalized = normalizeDeploymentUrl(url);
|
|
135
|
+
export async function checkDeploymentUrl({ url, fetch: fetchPort, guard }, options = {}) {
|
|
136
|
+
const normalized = normalizeDeploymentUrl({ url });
|
|
155
137
|
if (!normalized) {
|
|
156
138
|
return { reachable: false, statusMessage: 'Deployment URL is empty.' };
|
|
157
139
|
}
|
|
158
140
|
const timeoutMs = options.timeoutMs ?? 8_000;
|
|
159
|
-
const
|
|
141
|
+
const deadlineAt = Date.now() + timeoutMs;
|
|
142
|
+
const head = await requestDeploymentUrl(normalized, 'HEAD', timeoutMs, options, fetchPort, guard);
|
|
160
143
|
if (head.reachable)
|
|
161
144
|
return head;
|
|
162
145
|
if (head.status === 'protected')
|
|
163
146
|
return head;
|
|
147
|
+
// HEAD and its fallback share one probe budget; do not restart the clock for GET.
|
|
148
|
+
const remainingMs = deadlineAt - Date.now();
|
|
149
|
+
if (remainingMs <= 0)
|
|
150
|
+
return head;
|
|
164
151
|
if (head.statusCode && (head.statusCode === 405 || head.statusCode === 403 || head.statusCode >= 400)) {
|
|
165
|
-
const get = await requestDeploymentUrl(normalized, 'GET',
|
|
152
|
+
const get = await requestDeploymentUrl(normalized, 'GET', remainingMs, options, fetchPort, guard);
|
|
166
153
|
if (get.reachable)
|
|
167
154
|
return get;
|
|
168
155
|
if (get.status === 'protected')
|
|
@@ -177,11 +164,11 @@ export async function checkDeploymentUrl(url, options = {}) {
|
|
|
177
164
|
// remaining `reachable: false` shape (`status: 'protected'`) is already
|
|
178
165
|
// excluded by the `get.status === 'protected'` check just above. So the
|
|
179
166
|
// `: head` fallback branch could never actually be selected — see
|
|
180
|
-
//
|
|
167
|
+
// the archived extraction source map's 2026-07-22 addition for the exhaustive
|
|
181
168
|
// case-by-case proof this was re-derived from.
|
|
182
169
|
return get;
|
|
183
170
|
}
|
|
184
|
-
const get = await requestDeploymentUrl(normalized, 'GET',
|
|
171
|
+
const get = await requestDeploymentUrl(normalized, 'GET', remainingMs, options, fetchPort, guard);
|
|
185
172
|
// Same reasoning as the `get.statusMessage ? get : head` case just above,
|
|
186
173
|
// plus: when `get.reachable` is true, `get` is returned directly regardless
|
|
187
174
|
// (matching the removed ternary's consequent) — so this whole expression
|
|
@@ -195,7 +182,7 @@ export async function checkDeploymentUrl(url, options = {}) {
|
|
|
195
182
|
* publish call returns, since providers frequently accept the deploy before
|
|
196
183
|
* the URL is actually resolvable.
|
|
197
184
|
*
|
|
198
|
-
* @param
|
|
185
|
+
* @param requiredArgs - Candidate URLs/hostnames and required fetch, guard, clock and delay ports.
|
|
199
186
|
* @param options - `timeoutMs` (default 60s), `intervalMs` between sweeps (default 2s),
|
|
200
187
|
* `providerLabel` for messages, and the optional protected-response detector.
|
|
201
188
|
* @returns `{ status, url, statusMessage, reachableAt? }`. `status: 'link-delayed'`
|
|
@@ -204,9 +191,9 @@ export async function checkDeploymentUrl(url, options = {}) {
|
|
|
204
191
|
* @complexity O(candidates * timeoutMs/intervalMs) network round-trips, bounded by timeoutMs.
|
|
205
192
|
* @overallScore 100/100
|
|
206
193
|
*/
|
|
207
|
-
export async function waitForReachableDeploymentUrl(urls, options = {}) {
|
|
194
|
+
export async function waitForReachableDeploymentUrl({ urls, fetch: fetchPort, guard, now, sleep }, options = {}) {
|
|
208
195
|
const { timeoutMs = 60_000, intervalMs = 2_000, providerLabel = 'Deployment provider' } = options;
|
|
209
|
-
const candidates = [...new Set((urls || []).map(normalizeDeploymentUrl).filter(Boolean))];
|
|
196
|
+
const candidates = [...new Set((urls || []).map((url) => normalizeDeploymentUrl({ url })).filter(Boolean))];
|
|
210
197
|
const fallbackUrl = candidates[0] || '';
|
|
211
198
|
if (!fallbackUrl) {
|
|
212
199
|
return {
|
|
@@ -215,13 +202,16 @@ export async function waitForReachableDeploymentUrl(urls, options = {}) {
|
|
|
215
202
|
statusMessage: `${providerLabel} did not return a public deployment URL.`,
|
|
216
203
|
};
|
|
217
204
|
}
|
|
218
|
-
const startedAt =
|
|
205
|
+
const startedAt = now({});
|
|
219
206
|
let lastMessage = '';
|
|
220
|
-
while (
|
|
207
|
+
while (now({}) - startedAt < timeoutMs) {
|
|
221
208
|
for (const url of candidates) {
|
|
222
|
-
const
|
|
209
|
+
const remainingMs = timeoutMs - (now({}) - startedAt);
|
|
210
|
+
if (remainingMs <= 0)
|
|
211
|
+
break;
|
|
212
|
+
const result = await checkDeploymentUrl({ url, fetch: fetchPort, guard }, { ...options, timeoutMs: Math.min(options.timeoutMs ?? 8_000, remainingMs) });
|
|
223
213
|
if (result.reachable) {
|
|
224
|
-
return { status: 'ready', url, statusMessage: 'Public link is ready.', reachableAt:
|
|
214
|
+
return { status: 'ready', url, statusMessage: 'Public link is ready.', reachableAt: now({}) };
|
|
225
215
|
}
|
|
226
216
|
if (result.status === 'protected') {
|
|
227
217
|
return {
|
|
@@ -240,16 +230,18 @@ export async function waitForReachableDeploymentUrl(urls, options = {}) {
|
|
|
240
230
|
// handled by the two `return`s directly above this line, so neither
|
|
241
231
|
// can reach here. `|| lastMessage` (falling back to the *previous*
|
|
242
232
|
// sweep's message) could therefore never actually be selected — see
|
|
243
|
-
//
|
|
233
|
+
// the archived extraction source map's 2026-07-22 addition for the proof.
|
|
244
234
|
// Non-null assertion (not `||`/`??`, which would just reintroduce the
|
|
245
235
|
// same dead branch): the type is `string | undefined` because
|
|
246
236
|
// `DeploymentUrlCheck.statusMessage` is optional in general, but this
|
|
247
237
|
// exact call site's result is always defined per the proof above.
|
|
248
238
|
lastMessage = result.statusMessage;
|
|
249
239
|
}
|
|
250
|
-
|
|
240
|
+
const remainingMs = timeoutMs - (now({}) - startedAt);
|
|
241
|
+
if (remainingMs <= 0)
|
|
242
|
+
break;
|
|
243
|
+
if (!await sleepWithinBudget({ sleep, ms: Math.min(intervalMs, remainingMs), timeoutMs: remainingMs }))
|
|
251
244
|
break;
|
|
252
|
-
await new Promise((resolve) => setTimeout(resolve, intervalMs));
|
|
253
245
|
}
|
|
254
246
|
return {
|
|
255
247
|
status: 'link-delayed',
|
|
@@ -257,4 +249,18 @@ export async function waitForReachableDeploymentUrl(urls, options = {}) {
|
|
|
257
249
|
statusMessage: lastMessage || `${providerLabel} returned a deployment URL, but it is not reachable yet.`,
|
|
258
250
|
};
|
|
259
251
|
}
|
|
252
|
+
/** An injected delay can stall too; its completion cannot extend the whole polling deadline.
|
|
253
|
+
* @complexity O(1) time and space apart from the host's delay implementation. */
|
|
254
|
+
async function sleepWithinBudget({ sleep, ms, timeoutMs }) {
|
|
255
|
+
let timer;
|
|
256
|
+
try {
|
|
257
|
+
return await Promise.race([
|
|
258
|
+
sleep({ ms }).then(() => true),
|
|
259
|
+
new Promise((resolve) => { timer = setTimeout(() => resolve(false), timeoutMs); }),
|
|
260
|
+
]);
|
|
261
|
+
}
|
|
262
|
+
finally {
|
|
263
|
+
clearTimeout(timer);
|
|
264
|
+
}
|
|
265
|
+
}
|
|
260
266
|
//# sourceMappingURL=reachability.js.map
|
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Shared redirect guard for
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
* origin redirects these endpoints, but a redirect is exactly the mechanism a compromised edge,
|
|
2
|
+
* Shared redirect guard for deploy targets whose `fetch()` calls carry a live
|
|
3
|
+
* `Authorization: Bearer <token>` header. Without a `redirect` option, a 3xx response from a
|
|
4
|
+
* target's hardcoded, trusted API origin would be followed transparently by `fetch()`, replaying
|
|
5
|
+
* that Authorization header at whatever `Location` the response named. Under normal operation no
|
|
6
|
+
* such origin redirects these endpoints, but a redirect is exactly the mechanism a compromised edge,
|
|
8
7
|
* misconfigured origin, or MITM would use to exfiltrate the token to an attacker-controlled host —
|
|
9
|
-
* flagged 2026-08-15 (a downstream product's deploy-publishing dispatch) and fixed here, in the
|
|
8
|
+
* flagged 2026-08-15 (a downstream product's deploy-publishing dispatch) and fixed here, in the shared helper every target uses,
|
|
10
9
|
* rather than only papering over it from a caller.
|
|
11
10
|
*
|
|
12
11
|
* `redirectGuardInit` is the one place every call site adds `redirect: 'manual'`.
|
|
@@ -19,15 +18,20 @@
|
|
|
19
18
|
* keeps this correct even if a future runtime implements manual mode differently).
|
|
20
19
|
*/
|
|
21
20
|
/** Adds `redirect: 'manual'` to `init` without mutating the caller's object. */
|
|
22
|
-
export declare function redirectGuardInit(init
|
|
21
|
+
export declare function redirectGuardInit({ init }: {
|
|
22
|
+
init: RequestInit;
|
|
23
|
+
}): RequestInit;
|
|
23
24
|
/**
|
|
24
25
|
* @throws {DeployError} `resp` is an opaque-redirect filtered response (the server tried to
|
|
25
26
|
* redirect this authenticated request elsewhere). Call immediately after every guarded
|
|
26
27
|
* `fetch()`, before reading `resp.status`/`resp.json()` for any other reason — a caller that
|
|
27
|
-
* checks `resp.status === 404` (a real, expected branch in
|
|
28
|
+
* checks `resp.status === 404` (a real, expected branch in some targets) before this guard
|
|
28
29
|
* would never see that check misfire, since an opaque-redirect response's `status` is `0`, not
|
|
29
30
|
* `404` — but call ordering here still matters for every OTHER status-sensitive branch in
|
|
30
|
-
*
|
|
31
|
+
* a target.
|
|
31
32
|
*/
|
|
32
|
-
export declare function assertNotRedirected(resp
|
|
33
|
+
export declare function assertNotRedirected({ resp, providerLabel }: {
|
|
34
|
+
resp: Response;
|
|
35
|
+
providerLabel: string;
|
|
36
|
+
}): void;
|
|
33
37
|
//# sourceMappingURL=redirect-guard.d.ts.map
|
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
import { DeployError } from './types.js';
|
|
2
2
|
/**
|
|
3
|
-
* Shared redirect guard for
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
* origin redirects these endpoints, but a redirect is exactly the mechanism a compromised edge,
|
|
3
|
+
* Shared redirect guard for deploy targets whose `fetch()` calls carry a live
|
|
4
|
+
* `Authorization: Bearer <token>` header. Without a `redirect` option, a 3xx response from a
|
|
5
|
+
* target's hardcoded, trusted API origin would be followed transparently by `fetch()`, replaying
|
|
6
|
+
* that Authorization header at whatever `Location` the response named. Under normal operation no
|
|
7
|
+
* such origin redirects these endpoints, but a redirect is exactly the mechanism a compromised edge,
|
|
9
8
|
* misconfigured origin, or MITM would use to exfiltrate the token to an attacker-controlled host —
|
|
10
|
-
* flagged 2026-08-15 (a downstream product's deploy-publishing dispatch) and fixed here, in the
|
|
9
|
+
* flagged 2026-08-15 (a downstream product's deploy-publishing dispatch) and fixed here, in the shared helper every target uses,
|
|
11
10
|
* rather than only papering over it from a caller.
|
|
12
11
|
*
|
|
13
12
|
* `redirectGuardInit` is the one place every call site adds `redirect: 'manual'`.
|
|
@@ -20,21 +19,21 @@ import { DeployError } from './types.js';
|
|
|
20
19
|
* keeps this correct even if a future runtime implements manual mode differently).
|
|
21
20
|
*/
|
|
22
21
|
/** Adds `redirect: 'manual'` to `init` without mutating the caller's object. */
|
|
23
|
-
export function redirectGuardInit(init) {
|
|
22
|
+
export function redirectGuardInit({ init }) {
|
|
24
23
|
return { ...init, redirect: 'manual' };
|
|
25
24
|
}
|
|
26
25
|
/**
|
|
27
26
|
* @throws {DeployError} `resp` is an opaque-redirect filtered response (the server tried to
|
|
28
27
|
* redirect this authenticated request elsewhere). Call immediately after every guarded
|
|
29
28
|
* `fetch()`, before reading `resp.status`/`resp.json()` for any other reason — a caller that
|
|
30
|
-
* checks `resp.status === 404` (a real, expected branch in
|
|
29
|
+
* checks `resp.status === 404` (a real, expected branch in some targets) before this guard
|
|
31
30
|
* would never see that check misfire, since an opaque-redirect response's `status` is `0`, not
|
|
32
31
|
* `404` — but call ordering here still matters for every OTHER status-sensitive branch in
|
|
33
|
-
*
|
|
32
|
+
* a target.
|
|
34
33
|
*/
|
|
35
|
-
export function assertNotRedirected(resp, providerLabel) {
|
|
34
|
+
export function assertNotRedirected({ resp, providerLabel }) {
|
|
36
35
|
if (resp.type === 'opaqueredirect' || (resp.status >= 300 && resp.status < 400)) {
|
|
37
|
-
throw new DeployError(`${providerLabel} attempted to redirect an authenticated request — refused to follow it (possible credential-leak vector)
|
|
36
|
+
throw new DeployError({ message: `${providerLabel} attempted to redirect an authenticated request — refused to follow it (possible credential-leak vector).` }, { status: 502 });
|
|
38
37
|
}
|
|
39
38
|
}
|
|
40
39
|
//# sourceMappingURL=redirect-guard.js.map
|
package/dist/deploy/tokens.d.ts
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import { type DeployFile, type DeployPublishResult, type DeployTarget, type
|
|
1
|
+
import { type DeployFile, type DeployPublishOptions, type DeployPublishResult, type DeployTarget, type UnknownRecord } from './types.js';
|
|
2
2
|
/**
|
|
3
3
|
* Many-bound composition token for deploy providers, per extraction-plan.md
|
|
4
4
|
* §2.2's own worked example (`DeployTarget = manyToken<DeployProvider>
|
|
5
|
-
* ('jini.deployTarget')`, `bindMany(DeployTarget,
|
|
5
|
+
* ('jini.deployTarget')`, `bindMany(DeployTarget, someTarget)`, paraphrased). A host
|
|
6
6
|
* composition binds every deploy provider it wants available against this
|
|
7
7
|
* one token:
|
|
8
8
|
*
|
|
9
9
|
* ```ts
|
|
10
|
-
* bindings().bindMany(DeployTargetToken,
|
|
11
|
-
* .bindMany(DeployTargetToken,
|
|
10
|
+
* bindings().bindMany(DeployTargetToken, hostTargetA)
|
|
11
|
+
* .bindMany(DeployTargetToken, hostTargetB)
|
|
12
12
|
* ```
|
|
13
13
|
*
|
|
14
14
|
* A pack then resolves `c.getMany(DeployTargetToken)` to get every bound
|
|
@@ -24,34 +24,37 @@ export interface DeployPublishToolInput {
|
|
|
24
24
|
targetId: string;
|
|
25
25
|
files: DeployFile[];
|
|
26
26
|
projectName: string;
|
|
27
|
-
metadata?:
|
|
27
|
+
metadata?: UnknownRecord;
|
|
28
28
|
}
|
|
29
29
|
/**
|
|
30
30
|
* `deploy.publish` as a plain async function.
|
|
31
31
|
*
|
|
32
|
-
*
|
|
33
|
-
*
|
|
34
|
-
* task 6, §2.5)
|
|
32
|
+
* Tool wiring is implemented by `createDeployPublishToolRegistration` in
|
|
33
|
+
* `tool.ts`, using `@jini-ai/core`'s `ToolRegistry` and `@jini-ai/daemon`'s
|
|
34
|
+
* `ToolExecutor` (extraction-plan.md §8 task 6, §2.5). The registration shape is:
|
|
35
35
|
*
|
|
36
36
|
* ```ts
|
|
37
37
|
* toolRegistry.register({
|
|
38
38
|
* descriptor: { id: 'deploy.publish', ... },
|
|
39
|
-
* handler: (
|
|
39
|
+
* handler: (ctx) => publishDeploy({ ...ctx.input, targets }),
|
|
40
40
|
* policy: { ... }, // e.g. requires confirmation before an external publish
|
|
41
41
|
* });
|
|
42
42
|
* ```
|
|
43
43
|
*
|
|
44
44
|
* so callers only ever reach it through `ToolExecutor.execute(principal,
|
|
45
45
|
* run, 'deploy.publish', input, signal)` — never by holding a direct
|
|
46
|
-
* reference to a handler.
|
|
47
|
-
*
|
|
46
|
+
* reference to a handler. This plain function remains available to trusted
|
|
47
|
+
* composition code; routes and agents use the registration so they cannot
|
|
48
|
+
* bypass authorization and the audit trail. The registration denies by default.
|
|
48
49
|
*
|
|
49
|
-
* @param
|
|
50
|
-
* @param
|
|
50
|
+
* @param requiredArgs - Target id, file set, project name and injected bound targets.
|
|
51
|
+
* @param options - Optional metadata and response headers forwarded to the selected target.
|
|
51
52
|
* @returns The chosen target's publish result.
|
|
52
53
|
* @throws {DeployError} (status 404) if no bound target matches `input.targetId`.
|
|
53
54
|
* @complexity O(targets) to find the match, then whatever the target's own `publish` costs.
|
|
54
55
|
* @overallScore 100/100
|
|
55
56
|
*/
|
|
56
|
-
export declare function publishDeploy(input: DeployPublishToolInput,
|
|
57
|
+
export declare function publishDeploy({ targets, ...input }: Omit<DeployPublishToolInput, 'metadata'> & {
|
|
58
|
+
targets: readonly DeployTarget[];
|
|
59
|
+
}, options?: DeployPublishOptions): Promise<DeployPublishResult>;
|
|
57
60
|
//# sourceMappingURL=tokens.d.ts.map
|