@blokjs/shared 0.6.12 → 0.6.14

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/dist/index.d.ts CHANGED
@@ -13,6 +13,7 @@ import FunctionContext from "./types/FunctionContext";
13
13
  import LoggerContext from "./types/LoggerContext";
14
14
  import NodeConfigContext from "./types/NodeConfigContext";
15
15
  import RequestContext from "./types/RequestContext";
16
+ import { RESPOND_BRAND, type RespondEnvelope, isRespondEnvelope } from "./types/RespondEnvelope";
16
17
  import ResponseContext from "./types/ResponseContext";
17
18
  import StateContext from "./types/StateContext";
18
19
  import Step from "./types/Step";
@@ -20,4 +21,4 @@ import type StreamContext from "./types/StreamContext";
20
21
  import VarsContext from "./types/VarsContext";
21
22
  import mapper from "./utils/Mapper";
22
23
  import MemoryUsage from "./utils/MemoryUsage";
23
- export { NodeBase, Context, RequestContext, ResponseContext, EnvContext, ErrorContext, LoggerContext, ConfigContext, type ConnectionContext, type StreamContext, Trigger, NodeConfigContext, FunctionContext, StateContext, VarsContext, Step, GlobalLogger, GlobalError, BlokError, type BlokErrorOpts, type NodeErrorPayload, ErrorCategory, ErrorSeverity, DEFAULT_HTTP_STATUS, DEFAULT_RETRYABLE, Metrics, MemoryUsage, type MetricsType, mapper, };
24
+ export { NodeBase, Context, RequestContext, ResponseContext, RESPOND_BRAND, type RespondEnvelope, isRespondEnvelope, EnvContext, ErrorContext, LoggerContext, ConfigContext, type ConnectionContext, type StreamContext, Trigger, NodeConfigContext, FunctionContext, StateContext, VarsContext, Step, GlobalLogger, GlobalError, BlokError, type BlokErrorOpts, type NodeErrorPayload, ErrorCategory, ErrorSeverity, DEFAULT_HTTP_STATUS, DEFAULT_RETRYABLE, Metrics, MemoryUsage, type MetricsType, mapper, };
package/dist/index.js CHANGED
@@ -4,7 +4,8 @@ import GlobalLogger from "./GlobalLogger";
4
4
  import { Metrics } from "./Metrics";
5
5
  import NodeBase from "./NodeBase";
6
6
  import Trigger from "./Trigger";
7
+ import { RESPOND_BRAND, isRespondEnvelope } from "./types/RespondEnvelope";
7
8
  import mapper from "./utils/Mapper";
8
9
  import MemoryUsage from "./utils/MemoryUsage";
9
- export { NodeBase, Trigger, GlobalLogger, GlobalError, BlokError, ErrorCategory, ErrorSeverity, DEFAULT_HTTP_STATUS, DEFAULT_RETRYABLE, Metrics, MemoryUsage, mapper, };
10
+ export { NodeBase, RESPOND_BRAND, isRespondEnvelope, Trigger, GlobalLogger, GlobalError, BlokError, ErrorCategory, ErrorSeverity, DEFAULT_HTTP_STATUS, DEFAULT_RETRYABLE, Metrics, MemoryUsage, mapper, };
10
11
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,SAAS,EAAE,EAEjB,mBAAmB,EACnB,iBAAiB,EACjB,aAAa,EACb,aAAa,GAEb,MAAM,aAAa,CAAC;AACrB,OAAO,WAAW,MAAM,eAAe,CAAC;AACxC,OAAO,YAAY,MAAM,gBAAgB,CAAC;AAC1C,OAAO,EAAE,OAAO,EAAoB,MAAM,WAAW,CAAC;AACtD,OAAO,QAAQ,MAAM,YAAY,CAAC;AAClC,OAAO,OAAO,MAAM,WAAW,CAAC;AAehC,OAAO,MAAM,MAAM,gBAAgB,CAAC;AACpC,OAAO,WAAW,MAAM,qBAAqB,CAAC;AAE9C,OAAO,EACN,QAAQ,EAUR,OAAO,EAMP,YAAY,EACZ,WAAW,EACX,SAAS,EAGT,aAAa,EACb,aAAa,EACb,mBAAmB,EACnB,iBAAiB,EACjB,OAAO,EACP,WAAW,EAEX,MAAM,GACN,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,SAAS,EAAE,EAEjB,mBAAmB,EACnB,iBAAiB,EACjB,aAAa,EACb,aAAa,GAEb,MAAM,aAAa,CAAC;AACrB,OAAO,WAAW,MAAM,eAAe,CAAC;AACxC,OAAO,YAAY,MAAM,gBAAgB,CAAC;AAC1C,OAAO,EAAE,OAAO,EAAoB,MAAM,WAAW,CAAC;AACtD,OAAO,QAAQ,MAAM,YAAY,CAAC;AAClC,OAAO,OAAO,MAAM,WAAW,CAAC;AAUhC,OAAO,EAAE,aAAa,EAAwB,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAMjG,OAAO,MAAM,MAAM,gBAAgB,CAAC;AACpC,OAAO,WAAW,MAAM,qBAAqB,CAAC;AAE9C,OAAO,EACN,QAAQ,EAIR,aAAa,EAEb,iBAAiB,EAOjB,OAAO,EAMP,YAAY,EACZ,WAAW,EACX,SAAS,EAGT,aAAa,EACb,aAAa,EACb,mBAAmB,EACnB,iBAAiB,EACjB,OAAO,EACP,WAAW,EAEX,MAAM,GACN,CAAC"}
@@ -0,0 +1,48 @@
1
+ /**
2
+ * Branded HTTP-response envelope.
3
+ *
4
+ * A workflow step (typically the `@blokjs/respond` node, as the final step)
5
+ * returns a `RespondEnvelope` to control the full HTTP response — status code,
6
+ * arbitrary headers (incl. `Location` for redirects), repeatable `Set-Cookie`
7
+ * values, the body, and the `Content-Type`. The `http` trigger recognizes the
8
+ * brand on the final `ctx.response.data` and unpacks it; any non-branded result
9
+ * keeps the default behaviour (JSON / string body, status 200).
10
+ *
11
+ * The envelope is the carrier for *dynamic* response metadata (status/headers
12
+ * depend on runtime inputs, so they can't ride a static node field like
13
+ * `contentType`). It travels as ordinary step data — no `ctx` mutation, no
14
+ * runner-core changes — so the mechanism is fully additive and HTTP-specific.
15
+ */
16
+ export declare const RESPOND_BRAND: "__blokRespond__";
17
+ export interface RespondEnvelope {
18
+ readonly [RESPOND_BRAND]: true;
19
+ /**
20
+ * Response body. `string` → written verbatim; `Uint8Array`/`Buffer`/
21
+ * `ArrayBuffer` → written as raw bytes; any other value → JSON-encoded.
22
+ * Omit (or `null`/`undefined`) for empty-body responses (e.g. a 302).
23
+ */
24
+ body?: unknown;
25
+ /** HTTP status code. Defaults to 200. */
26
+ status?: number;
27
+ /**
28
+ * Content-Type. Overrides the default. When omitted: `application/json`
29
+ * for object bodies, `application/octet-stream` for binary bodies.
30
+ */
31
+ contentType?: string;
32
+ /** Response headers, e.g. `{ Location: "/next" }` or `{ "Content-Disposition": "attachment; filename=\"x.pdf\"" }`. */
33
+ headers?: Record<string, string>;
34
+ /**
35
+ * Raw `Set-Cookie` header values. Each entry becomes its own `Set-Cookie`
36
+ * header (the header legitimately repeats), so a single response can set
37
+ * multiple cookies. Format each value yourself, e.g.
38
+ * `"session=abc; Path=/; HttpOnly; SameSite=Lax"`.
39
+ */
40
+ cookies?: string[];
41
+ }
42
+ /**
43
+ * Type guard: is `value` a branded {@link RespondEnvelope}? Used by the `http`
44
+ * trigger to decide whether to unpack response metadata or fall through to the
45
+ * default JSON/string/binary handling.
46
+ */
47
+ export declare function isRespondEnvelope(value: unknown): value is RespondEnvelope;
48
+ export default RespondEnvelope;
@@ -0,0 +1,25 @@
1
+ /**
2
+ * Branded HTTP-response envelope.
3
+ *
4
+ * A workflow step (typically the `@blokjs/respond` node, as the final step)
5
+ * returns a `RespondEnvelope` to control the full HTTP response — status code,
6
+ * arbitrary headers (incl. `Location` for redirects), repeatable `Set-Cookie`
7
+ * values, the body, and the `Content-Type`. The `http` trigger recognizes the
8
+ * brand on the final `ctx.response.data` and unpacks it; any non-branded result
9
+ * keeps the default behaviour (JSON / string body, status 200).
10
+ *
11
+ * The envelope is the carrier for *dynamic* response metadata (status/headers
12
+ * depend on runtime inputs, so they can't ride a static node field like
13
+ * `contentType`). It travels as ordinary step data — no `ctx` mutation, no
14
+ * runner-core changes — so the mechanism is fully additive and HTTP-specific.
15
+ */
16
+ export const RESPOND_BRAND = "__blokRespond__";
17
+ /**
18
+ * Type guard: is `value` a branded {@link RespondEnvelope}? Used by the `http`
19
+ * trigger to decide whether to unpack response metadata or fall through to the
20
+ * default JSON/string/binary handling.
21
+ */
22
+ export function isRespondEnvelope(value) {
23
+ return (typeof value === "object" && value !== null && value[RESPOND_BRAND] === true);
24
+ }
25
+ //# sourceMappingURL=RespondEnvelope.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"RespondEnvelope.js","sourceRoot":"","sources":["../../src/types/RespondEnvelope.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG,iBAA0B,CAAC;AA4BxD;;;;GAIG;AACH,MAAM,UAAU,iBAAiB,CAAC,KAAc;IAC/C,OAAO,CACN,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAK,KAA0C,CAAC,aAAa,CAAC,KAAK,IAAI,CAClH,CAAC;AACH,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blokjs/shared",
3
- "version": "0.6.12",
3
+ "version": "0.6.14",
4
4
  "description": "Shared class, interfaces and types",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",