@akai-workflow-builder/cli-sdk 0.6.0 → 0.6.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/CHANGELOG.md CHANGED
@@ -4,6 +4,13 @@ All notable changes to `@akai-workflow-builder/cli-sdk` are documented here.
4
4
 
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).
6
6
 
7
+ ## [0.6.1](https://github.com/akai-workflow-builder/akai-cli-sdk/compare/cli-sdk-v0.6.0...cli-sdk-v0.6.1) (2026-08-23)
8
+
9
+
10
+ ### Bug Fixes
11
+
12
+ * **ctx:** document and release the redirect 'manual' change (AKAI-2446) ([de0b7d2](https://github.com/akai-workflow-builder/akai-cli-sdk/commit/de0b7d23e655a8ac1e748897a1c71b16e010a3d8))
13
+
7
14
  ## [0.6.0](https://github.com/akai-workflow-builder/akai-cli-sdk/compare/cli-sdk-v0.5.0...cli-sdk-v0.6.0) (2026-08-21)
8
15
 
9
16
 
package/README.md CHANGED
@@ -349,10 +349,10 @@ options: {
349
349
  - **Protocol** — HTTPS-only in production. HTTP allowed only when `NODE_ENV === 'development'`.
350
350
  - **Host** — exact-or-suffix-with-dot. `api.example.com` matches itself and `*.api.example.com`; `evil.api.example.com.attacker.tld` does not.
351
351
  - **DNS preflight** — hostname resolved before the request. In production, addresses in private (RFC 1918), loopback, link-local, or unique-local IPv6 ranges are refused (IPv4, IPv6, v4-mapped, and canonicalized forms). In development the private-IP refusal is skipped so handlers can target local services.
352
- - **Redirects** — `redirect: 'error'` is pinned on every request, non-overridable. If the target responds with a 3xx, `fetch` itself rejects; the SDK never follows redirects, so a `Location:` to a public host cannot smuggle the request past the egress check.
352
+ - **Redirects** — the SDK never follows a redirect, so a `Location:` to another host cannot smuggle a request past the egress check. `redirect: 'error'` is the default and `'follow'` is refused (it is downgraded to `'error'`), because following is the one mode that could leave the allowlisted host after the check has passed. `redirect: 'manual'` is honoured: it follows nothing, so the handler receives the 3xx itself — which is how a form-post portal reports success — and reaching the `Location:` costs a fresh `ctx.fetch` that re-runs the whole preflight.
353
353
  - **Identity headers** — `user-agent`, `x-akai-cli`, `x-akai-tool`, `x-akai-request-id` are stamped on every request. `x-akai-tenant` is stamped only when the host runtime passes a tenant id to `buildCtx`; otherwise it is removed even if a handler tried to set it. Handler-supplied values for any of these are always overwritten.
354
354
 
355
- Protocol, host, and DNS-preflight failures reject with `AkaiEgressError` before any network request is made. Redirect failures surface as a `fetch` rejection after the initial response — same outcome (no follow-through), different error type.
355
+ Protocol, host, and DNS-preflight failures reject with `AkaiEgressError` before any network request is made. Under `redirect: 'error'` — the default, and where `'follow'` is downgraded to — a redirect surfaces instead as a `fetch` rejection after the initial response: same outcome (no follow-through), different error type. Under `'manual'` there is no failure to surface, because the 3xx is a successful result: it is returned to the handler as an ordinary response.
356
356
 
357
357
  Spec validation also rejects egress hosts that don't pass a syntactic DNS-hostname check — `localhost` (single label), IP literals, hosts with spaces or slashes — so they can't be declared in the first place. The check is shape-only; it doesn't verify the name is publicly resolvable, so internal DNS zones still pass the spec and are then handled at DNS-preflight time.
358
358
 
@@ -41,5 +41,24 @@ export interface SafeFetchBinding {
41
41
  readonly maxResponseBytes?: number;
42
42
  }
43
43
  export type SafeFetch = (url: string, init?: RequestInit) => Promise<Response>;
44
+ /** The redirect modes a caller may ask for (lib.dom's `RequestRedirect`). */
45
+ type RedirectMode = 'error' | 'follow' | 'manual';
46
+ /**
47
+ * Decide the redirect mode for one call.
48
+ *
49
+ * The default stays `'error'`: a followed redirect is the one way a fetch can
50
+ * leave the allowlisted host after the egress check has passed, so `'follow'`
51
+ * is never honoured.
52
+ *
53
+ * `'manual'` is honoured, because it does not follow anything — the caller gets
54
+ * the 3xx itself and has to issue a fresh `safeFetch` for the Location, which
55
+ * runs the whole egress + DNS preflight again. Tools that speak to form-post
56
+ * portals need this: a Django or Struts login answers 302 on success, and the
57
+ * status and Set-Cookie headers on that 302 ARE the result. Without it those
58
+ * flows fail with undici's opaque `TypeError: fetch failed` / `unexpected
59
+ * redirect`.
60
+ */
61
+ export declare function resolveRedirect(requested: RedirectMode | undefined): RedirectMode;
44
62
  export declare function createSafeFetch(binding: SafeFetchBinding): SafeFetch;
63
+ export {};
45
64
  //# sourceMappingURL=safe-fetch.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"safe-fetch.d.ts","sourceRoot":"","sources":["../../src/ctx/safe-fetch.ts"],"names":[],"mappings":"AAOA;;;;;;;;;;GAUG;AACH,eAAO,MAAM,0BAA0B,QAAkB,CAAC;AAE1D;;;;;;;;GAQG;AACH,eAAO,MAAM,iCAAiC,QAAoB,CAAC;AAEnE;;;;;GAKG;AACH,MAAM,WAAW,kBAAkB;IACjC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;CACtB;AAED,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,CAAC,MAAM,EAAE,SAAS,MAAM,EAAE,CAAC;IACnC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,UAAU,CAAC,EAAE,kBAAkB,CAAC;IACzC,kEAAkE;IAClE,QAAQ,CAAC,gBAAgB,CAAC,EAAE,MAAM,CAAC;CACpC;AAED,MAAM,MAAM,SAAS,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,WAAW,KAAK,OAAO,CAAC,QAAQ,CAAC,CAAC;AAyG/E,wBAAgB,eAAe,CAAC,OAAO,EAAE,gBAAgB,GAAG,SAAS,CAoGpE"}
1
+ {"version":3,"file":"safe-fetch.d.ts","sourceRoot":"","sources":["../../src/ctx/safe-fetch.ts"],"names":[],"mappings":"AAOA;;;;;;;;;;GAUG;AACH,eAAO,MAAM,0BAA0B,QAAkB,CAAC;AAE1D;;;;;;;;GAQG;AACH,eAAO,MAAM,iCAAiC,QAAoB,CAAC;AAEnE;;;;;GAKG;AACH,MAAM,WAAW,kBAAkB;IACjC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;CACtB;AAED,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,CAAC,MAAM,EAAE,SAAS,MAAM,EAAE,CAAC;IACnC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,UAAU,CAAC,EAAE,kBAAkB,CAAC;IACzC,kEAAkE;IAClE,QAAQ,CAAC,gBAAgB,CAAC,EAAE,MAAM,CAAC;CACpC;AAED,MAAM,MAAM,SAAS,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,WAAW,KAAK,OAAO,CAAC,QAAQ,CAAC,CAAC;AA8D/E,6EAA6E;AAC7E,KAAK,YAAY,GAAG,OAAO,GAAG,QAAQ,GAAG,QAAQ,CAAC;AAElD;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,eAAe,CAAC,SAAS,EAAE,YAAY,GAAG,SAAS,GAAG,YAAY,CAEjF;AA8CD,wBAAgB,eAAe,CAAC,OAAO,EAAE,gBAAgB,GAAG,SAAS,CAoGpE"}
@@ -89,6 +89,24 @@ function hostMatches(hostname, allowed) {
89
89
  return hostname === a || hostname.endsWith(`.${a}`);
90
90
  });
91
91
  }
92
+ /**
93
+ * Decide the redirect mode for one call.
94
+ *
95
+ * The default stays `'error'`: a followed redirect is the one way a fetch can
96
+ * leave the allowlisted host after the egress check has passed, so `'follow'`
97
+ * is never honoured.
98
+ *
99
+ * `'manual'` is honoured, because it does not follow anything — the caller gets
100
+ * the 3xx itself and has to issue a fresh `safeFetch` for the Location, which
101
+ * runs the whole egress + DNS preflight again. Tools that speak to form-post
102
+ * portals need this: a Django or Struts login answers 302 on success, and the
103
+ * status and Set-Cookie headers on that 302 ARE the result. Without it those
104
+ * flows fail with undici's opaque `TypeError: fetch failed` / `unexpected
105
+ * redirect`.
106
+ */
107
+ export function resolveRedirect(requested) {
108
+ return requested === 'manual' || requested === 'error' ? requested : 'error';
109
+ }
92
110
  function abortError(signal) {
93
111
  return signal.reason ?? new DOMException('The operation was aborted.', 'AbortError');
94
112
  }
@@ -112,7 +130,8 @@ async function lookupWithSignal(hostname, signal) {
112
130
  }
113
131
  // Caller-supplied `init` keys forwarded to fetch. Excludes Node/undici
114
132
  // transport options like `dispatcher` that can route around the egress
115
- // check. `headers`, `redirect`, and `signal` are constructed/pinned below.
133
+ // check. `headers` and `signal` are constructed/pinned below; `redirect` is
134
+ // handled by {@link resolveRedirect}.
116
135
  const FORWARDED_INIT_FIELDS = [
117
136
  'method',
118
137
  'body',
@@ -192,7 +211,7 @@ export function createSafeFetch(binding) {
192
211
  // Allow-list forwarding: blocks `init.dispatcher` (undici) and other
193
212
  // Node-specific transport options that could reroute past the egress
194
213
  // check and the DNS-resolved address.
195
- const sanitized = { headers, redirect: 'error', signal };
214
+ const sanitized = { headers, redirect: resolveRedirect(init.redirect), signal };
196
215
  for (const key of FORWARDED_INIT_FIELDS) {
197
216
  if (init[key] !== undefined) {
198
217
  sanitized[key] = init[key];
@@ -258,8 +277,10 @@ const NULL_BODY_STATUSES = new Set([204, 205, 304]);
258
277
  /**
259
278
  * Minimal fetch-over-`node:https` used only for mutual-TLS requests. Parity
260
279
  * notes vs global fetch:
261
- * - `redirect: 'error'` semantics are enforced by rejecting on any 3xx with
262
- * a Location header (https.request never follows redirects itself).
280
+ * - `https.request` never follows redirects itself, so redirect handling is
281
+ * explicit: under `redirect: 'manual'` a 3xx is returned to the caller like
282
+ * any other response, and otherwise it is rejected — matching what
283
+ * {@link resolveRedirect} asks of the global-fetch path.
263
284
  * - The request body is serialized by round-tripping through `new Response()`,
264
285
  * which applies WHATWG body extraction — FormData multipart boundaries,
265
286
  * URLSearchParams/Blob content-types — identically to fetch. Bodies are
@@ -300,7 +321,10 @@ async function mtlsFetch(url, init, identity) {
300
321
  // event handling.
301
322
  try {
302
323
  const status = res.statusCode ?? 0;
303
- if (status >= 300 && status < 400 && res.headers.location !== undefined) {
324
+ if (init.redirect !== 'manual' &&
325
+ status >= 300 &&
326
+ status < 400 &&
327
+ res.headers.location !== undefined) {
304
328
  res.resume();
305
329
  reject(new AkaiEgressError(`safe-fetch: refusing redirect (${status}) on mutual-TLS request to ${url.hostname}`, { hostname: url.hostname, status }));
306
330
  return;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@akai-workflow-builder/cli-sdk",
3
- "version": "0.6.0",
3
+ "version": "0.6.1",
4
4
  "description": "Authoring SDK for atomic, agent-executable CLIs and tools.",
5
5
  "keywords": [
6
6
  "akai",