@stitchwire/client 0.31.1 → 0.32.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/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # @stitchwire/client
2
2
 
3
- Optional typed Node/Bun client for the current Stitchwire local Unix door. One agent per
3
+ Optional typed Node/Bun client for the current StitchWire local Unix door. One agent per
4
4
  machine owns the broker connections. This package starts no daemon, opens no network
5
5
  listener, reads no token file and retries nothing automatically. Importing it does not start an
6
6
  agent: it talks to the one already running on the machine.
@@ -76,13 +76,13 @@ the operator.
76
76
  on `request.signal` are not under it. Create the ingress once per descriptor, not per request.
77
77
  - `serviceCaller(context)`: `{caller, operation, id, traceId}` of the request `createServiceIngress` built,
78
78
  `undefined` for any other request, including a copy or clone of one and a request carrying the same
79
- headers. `context` is the Stitchkit endpoint context (a handler, `authorize`, `beforeHandle` or `onError`);
80
- the value travels in Stitchkit's `defineRequestIngress` channel.
79
+ headers. `context` is the StitchKit endpoint context (a handler, `authorize`, `beforeHandle` or `onError`);
80
+ the value travels in StitchKit's `defineRequestIngress` channel.
81
81
 
82
82
  The node agent dispatches only to an owner socket that is `0600` in a directory no other user can enter. Bind
83
- it with Stitchkit's `bindUnixSocket` (`stitchkit/files`, 0.123.4 or later), which makes the socket `0600` from the
83
+ it with StitchKit's `bindUnixSocket` (`stitchkit/files`, 0.123.4 or later), which makes the socket `0600` from the
84
84
  moment it exists: `bindUnixSocket({ path, mode: 0o600 }, (unix) => Bun.serve({ unix, fetch: ingress }))`, or
85
- `createServer({ unix: { path, mode: 0o600 }, … })` for a Stitchkit server. A socket takes the process umask at
85
+ `createServer({ unix: { path, mode: 0o600 }, … })` for a StitchKit server. A socket takes the process umask at
86
86
  bind, so a `chmod` after `listen` leaves it on disk with the wider mode until the `chmod` runs, and the node agent
87
87
  or a release check that finds it then refuses it.
88
88
 
@@ -105,7 +105,7 @@ const result = await wire.invokeService({
105
105
  ```
106
106
 
107
107
  The source checkout's `examples/service/run.ts` includes the actual owner
108
- contract, Stitchkit typed client, two brokers, agents, binding and negative authorization gate.
108
+ contract, StitchKit typed client, two brokers, agents, binding and negative authorization gate.
109
109
  Its owner client uses `createServiceFetch`; this lower-level snippet assumes that setup exists.
110
110
 
111
111
  An owner's installer checks the declaration file it is about to write with `parseServiceDeclaration(value)`,
@@ -126,7 +126,7 @@ or exact operations.
126
126
  Owner clients may wrap a `WireServiceError`; delivery certainty remains on the typed cause and
127
127
  must not trigger replay when it is `unknown`.
128
128
 
129
- The SDK takes Stitchkit and Zod from the consumer as peers (the supported ranges are in its package manifest): its schemas are handed to Stitchkit, so both must be the consumer's one copy. Stitchkit owns Unix I/O, contract stream
129
+ The SDK takes StitchKit and Zod from the consumer as peers (the supported ranges are in its package manifest): its schemas are handed to StitchKit, so both must be the consumer's one copy. StitchKit owns Unix I/O, contract stream
130
130
  framing/terminal validation and pull-driven response bodies. Wire adds routing credit, cancellation
131
131
  and total transport budgets without parsing the owner's domain frames.
132
132
  Wire owns protocol decoding and failure mapping; it never starts a daemon. Internal framework
@@ -192,7 +192,7 @@ recipes and `docs/architecture/sdk-adoption.md` for the exact distribution proce
192
192
  - **Broker `/health` reader:** `brokerHealthUrl(laneUrl)` converts `ws://`/`wss://`/`http://`/`https://` lane URLs to `/health` under the one lane rule the agent and enrollment apply: no credentials, query or fragment, and plain `http:`/`ws:` only to loopback (`127.0.0.0/8`, `::1`, `localhost`), so `readBrokerHealth` does not read a remote broker over plain text. `readBrokerHealth(laneUrl, options?)` performs a bounded GET (`8s` default timeout, `8 MiB` default cap, `redirect: 'error'`, strict UTF-8) validated by `BrokerHealthSchema`; a body that is not JSON is `invalid-response` with the parse error as its cause. A broker of an earlier release that writes no `transport`, `application`, `bundle` or `admission` block is read without it: those fields are optional in `BrokerHealth`.
193
193
  - **Browser-safe contracts (`@stitchwire/client/contracts`):** zero `node:*`, `stitchkit`, `process` or `Buffer` dependencies — exports forward-compatible Zod readers of `/status` and `/health` (`StatusResultSchema`, `BrokerHealthSchema`, `AuditStatusSchema`, `LaneStatusSchema`, `FleetNodeStatusSchema`, `FleetEditionStatusSchema`, `FleetConfigStateSchema`), `PeerResultSchema` (it drops fields it does not know, while its values stay closed), authoring schemas (`ServiceDeclarationSchema`, `TopicDescriptorSchema`, `TopicProfileSchema`, `ServiceBindingSchema`, `ServiceDescriptorSchema`), failure code enums (`ClientErrorCodeSchema`, `ServiceFailureCodeSchema`) and pure helpers (`brokerHealthUrl`, `parseServiceDeclaration`, `parseTopicDescriptor`, `isTopicInNamespace`, `isTopicAuthorized`).
194
194
  - **Error chain inspection:** `extractWireServiceError(error)` and `extractWireClientError(error)` walk `.cause` safely — cycle-guarded, 16 links deep by default (the outermost error included; the optional second argument changes it), ignoring `AggregateError.errors`, matched by `instanceof`, so an error from a second copy of the package is not recognised, and never throwing: a link whose property or prototype traps throw ends the walk with no match; `wireErrorCode(error)` returns `{ source: 'service' | 'client', code }` of the nearest one — the two code spaces overlap (`timeout`, `cancelled`, `unavailable`, …), and `source` tells a service's refusal from a local failure.
195
- - **Local path discovery:** `defaultConfigDir(options?)`, `defaultStateDir(options?)`, `defaultWireSocketPath(options?)`, `defaultNodeConfigPath(options?)`, `defaultServiceDropInDir(options?)` and `defaultEventDropInDir(options?)` resolve the one layout Stitchwire installs on macOS and Linux — `<home>/.config/stitchwire/node.json` and `<home>/.local/state/stitchwire/agent.sock`, a system unit included (pass its user's home as `homeDir`). There is no second, system-wide door such as `/run/stitchwire/wire.sock`: a unit that serves the door elsewhere names that path as `agentSocket` in its `node.json`, and its consumers pass the same path as `socketPath` (or `STITCHWIRE_AGENT_SOCKET`). `STITCHWIRE_AGENT_SOCKET`, `STITCHWIRE_STATE_DIR` and `STITCHWIRE_CONFIG_DIR` are read at call time, verbatim, and must be absolute paths (a relative one is a `RangeError`: it would resolve against each process's own working directory); an empty one counts as unset. An agent whose `node.json` names another `agentSocket` is reached only there. Only a file named `node.json` has default drop-in directories (`services.d/`, `events.d/` beside it). This package never reads `node.json` or broker tokens.
195
+ - **Local path discovery:** `defaultConfigDir(options?)`, `defaultStateDir(options?)`, `defaultWireSocketPath(options?)`, `defaultNodeConfigPath(options?)`, `defaultServiceDropInDir(options?)` and `defaultEventDropInDir(options?)` resolve the one layout StitchWire installs on macOS and Linux — `<home>/.config/stitchwire/node.json` and `<home>/.local/state/stitchwire/agent.sock`, a system unit included (pass its user's home as `homeDir`). There is no second, system-wide door such as `/run/stitchwire/wire.sock`: a unit that serves the door elsewhere names that path as `agentSocket` in its `node.json`, and its consumers pass the same path as `socketPath` (or `STITCHWIRE_AGENT_SOCKET`). `STITCHWIRE_AGENT_SOCKET`, `STITCHWIRE_STATE_DIR` and `STITCHWIRE_CONFIG_DIR` are read at call time, verbatim, and must be absolute paths (a relative one is a `RangeError`: it would resolve against each process's own working directory); an empty one counts as unset. An agent whose `node.json` names another `agentSocket` is reached only there. Only a file named `node.json` has default drop-in directories (`services.d/`, `events.d/` beside it). This package never reads `node.json` or broker tokens.
196
196
  - **Drop-in declarations without touching `node.json`:** `writeServiceDeclarationFile`, `removeServiceDeclarationFile`, `writeTopicDescriptorFile` and `removeTopicDescriptorFile` validate the owner's value against the agent's exact schemas and atomically write it as given (no defaults filled in) as a `0600` file in the `services.d/` or `events.d/` directory. A directory the SDK creates is `0700`; an existing one is used as it is and must be owned by the writer and not writable by group or others, or the write is refused; the agent reads it on its next poll, with no `node.json` edit and no restart. Requirements: an agent of runtime 0.57.0 or newer (an older one reads no drop-in directory); the writer runs as the agent's user (the agent reads only files owned by its own uid and writable by nobody else); a `node.json` that sets `services.dropInDir`/`events.dropInDir` must be matched by passing `dropInDir`; `dropInDir` and `configPath` must be absolute paths (a relative one is `invalid-request`). A written file is not yet a loaded declaration: confirm it in `status()` — `services.declarations.descriptors` / `events.declarations.descriptors` list each file by `path` with its `state`, and `refused` names one the node will not serve. Failures: `invalid-request` (bad name or value), `limit` (size), `permission` (access denied, or a directory/file the agent would refuse), `transport` (any other filesystem failure: no space, read-only filesystem, I/O).
197
197
 
198
198
  ## Node identity
@@ -286,7 +286,7 @@ publications and peer observations still refuse a value they do not know.
286
286
  - Maximum NDJSON line 512 KiB, stream payload total 256 MiB. Limits can be reduced through
287
287
  `maxResponseBytes` and `maxFrameBytes`. The parser is pull-driven.
288
288
 
289
- Typed item-framed streams use Stitchkit's strict newline and terminal completion policy.
289
+ Typed item-framed streams use StitchKit's strict newline and terminal completion policy.
290
290
  Packed stalled-reader gates verify bounded backpressure plateaus (`2/512` and `6/512` frames) and
291
291
  multi-megabyte continuous subscriptions (600 frames across 26 MiB on one request without a lifetime
292
292
  cutoff) on both Bun and Node. No `node:http` streaming fallback, implicit replay or inactivity
@@ -576,6 +576,7 @@ var BrokerAdmissionHealthSchema = z10.strictObject({
576
576
  });
577
577
  var BrokerHealthContractSchema = z10.strictObject({
578
578
  ok: z10.boolean(),
579
+ brokerVersion: z10.string().min(1).max(64),
579
580
  nodes: z10.array(PresenceSchema).max(MAX_NODES),
580
581
  observingSince: z10.string(),
581
582
  transport: TransportObservationSnapshotSchema,
@@ -698,6 +699,7 @@ var brokerFleet = BrokerHealthContractSchema.shape.fleet;
698
699
  var brokerEvents = BrokerHealthContractSchema.shape.events;
699
700
  var brokerTopic = BrokerHealthContractSchema.shape.topics.element;
700
701
  var BrokerHealthSchema2 = BrokerHealthContractSchema.extend({
702
+ brokerVersion: BrokerHealthContractSchema.shape.brokerVersion.optional(),
701
703
  nodes: z11.array(PresenceReaderSchema),
702
704
  transport: TransportObservationReaderSchema.optional(),
703
705
  audit: AuditStatusSchema2,
package/dist/contracts.js CHANGED
@@ -11,7 +11,7 @@ import {
11
11
  CallResultSchema2,
12
12
  PublishResultSchema2,
13
13
  PeerResultSchema2
14
- } from "./chunk-d3248e3w.js";
14
+ } from "./chunk-3pa01nyh.js";
15
15
  import {
16
16
  LOCAL_API_VERSION2,
17
17
  SERVICE_DEFAULT_REQUEST_BYTES2,
package/dist/index.js CHANGED
@@ -84,7 +84,7 @@ import {
84
84
  CallResultSchema2,
85
85
  PublishResultSchema2,
86
86
  PeerResultSchema2
87
- } from "./chunk-d3248e3w.js";
87
+ } from "./chunk-3pa01nyh.js";
88
88
 
89
89
  // packages/contracts/src/service/contract-descriptor.ts
90
90
  import { requireContractOperationEffects } from "stitchkit/contract";
@@ -102,7 +102,7 @@ function serviceDescriptorFromContract(contract, config) {
102
102
  operations: endpointNames.map((id) => {
103
103
  const endpoint = contract.endpoints[id];
104
104
  if (!endpoint)
105
- throw new TypeError(`Missing Stitchkit endpoint '${id}'`);
105
+ throw new TypeError(`Missing StitchKit endpoint '${id}'`);
106
106
  const path = endpoint.path.replace(/^\/+|\/+$/g, "");
107
107
  const exposedOnHttp = endpoint.expose === undefined || endpoint.expose.includes("HTTP");
108
108
  if (endpoint.method !== "POST" || !exposedOnHttp || endpoint.params !== undefined || endpoint.multipart !== undefined || endpoint.rawResponse === true || endpoint.rawBody === true || endpoint.responseMeta !== undefined || endpoint.path.includes(":") || endpoint.path.includes("*")) {
@@ -156,6 +156,7 @@ export declare const BrokerAdmissionHealthSchema: z.ZodObject<{
156
156
  */
157
157
  export declare const BrokerHealthContractSchema: z.ZodObject<{
158
158
  ok: z.ZodBoolean;
159
+ brokerVersion: z.ZodString;
159
160
  nodes: z.ZodArray<z.ZodObject<{
160
161
  nodeId: z.ZodString;
161
162
  online: z.ZodBoolean;
@@ -1,6 +1,6 @@
1
1
  import type { ContractDef, EndpointDef } from 'stitchkit';
2
2
  import { type ServiceDescriptor } from './policy-schema.ts';
3
- /** Projects a Stitchkit owner contract into the policy facts Wire must route and bound. */
3
+ /** Projects a StitchKit owner contract into the policy facts Wire must route and bound. */
4
4
  export declare function serviceDescriptorFromContract<T extends Record<string, EndpointDef>>(contract: ContractDef<T, string>, config: {
5
5
  service: string;
6
6
  revision: string;
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Browser-safe Stitchwire contracts, forward-compatible Zod readers and pure helpers.
2
+ * Browser-safe StitchWire contracts, forward-compatible Zod readers and pure helpers.
3
3
  *
4
4
  * Imports ONLY `zod` and pure contract modules (no `node:*`, no `stitchkit`, no `process`, no
5
5
  * `Buffer`), so browser/Tauri/React/Vite consumers can validate status, broker health, topic
@@ -8,13 +8,13 @@ export interface ServiceCaller {
8
8
  }
9
9
  /**
10
10
  * The node-authenticated caller of the request an endpoint received from `createServiceIngress`;
11
- * `undefined` for any other. The parameter is structural so that a Node consumer's declarations do not pull Stitchkit's server types (they need Bun's); `source` is the endpoint context (`authorize`, `beforeHandle`, a handler or `onError`).
11
+ * `undefined` for any other. The parameter is structural so that a Node consumer's declarations do not pull StitchKit's server types (they need Bun's); `source` is the endpoint context (`authorize`, `beforeHandle`, a handler or `onError`).
12
12
  */
13
13
  export declare function serviceCaller(source: {
14
14
  readonly req?: Request | undefined;
15
15
  }): ServiceCaller | undefined;
16
16
  /**
17
- * Turns the node's envelope POST into the owner's own Stitchkit request.
17
+ * Turns the node's envelope POST into the owner's own StitchKit request.
18
18
  *
19
19
  * The returned fetch handler is the whole door of a service owner: it answers `invalid-request` (400)
20
20
  * without calling `handler` for anything the descriptor does not declare, and otherwise calls
@@ -1,5 +1,5 @@
1
1
  /**
2
- * The one local layout Stitchwire installs, on macOS and Linux alike: configuration under
2
+ * The one local layout StitchWire installs, on macOS and Linux alike: configuration under
3
3
  * `<home>/.config/stitchwire`, the agent's door and journals under `<home>/.local/state/stitchwire`.
4
4
  * A system unit runs the same layout under its own user's home; there is no second, system-wide one.
5
5
  */
@@ -528,6 +528,7 @@ export type StatusResult = z.output<typeof StatusResultSchema>;
528
528
  export declare const BrokerHealthSchema: z.ZodObject<{
529
529
  ok: z.ZodBoolean;
530
530
  observingSince: z.ZodString;
531
+ brokerVersion: z.ZodOptional<z.ZodString>;
531
532
  nodes: z.ZodArray<z.ZodObject<{
532
533
  nodeId: z.ZodString;
533
534
  online: z.ZodBoolean;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@stitchwire/client",
3
- "version": "0.31.1",
4
- "description": "Bounded typed client for the Stitchwire local Unix door; no daemon or broker credentials.",
3
+ "version": "0.32.1",
4
+ "description": "Bounded typed client for the StitchWire local Unix door; no daemon or broker credentials.",
5
5
  "type": "module",
6
6
  "license": "MIT",
7
7
  "author": "Max Listov",