@alienplatform/commands 1.14.1-dev.e74fae6cd01b61e77a285276f264b5480977f41a
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/client.d.ts +137 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/errors.d.ts +302 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/index.d.ts +36 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +5072 -0
- package/dist/presigned.d.ts +29 -0
- package/dist/presigned.d.ts.map +1 -0
- package/dist/protocol.d.ts +31 -0
- package/dist/protocol.d.ts.map +1 -0
- package/dist/receiver.d.ts +186 -0
- package/dist/receiver.d.ts.map +1 -0
- package/dist/wire.d.ts +32 -0
- package/dist/wire.d.ts.map +1 -0
- package/package.json +62 -0
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Presigned-transfer mechanics shared by the sender and the receiver:
|
|
3
|
+
* expiration check, http vs local backend dispatch, and the `..` traversal
|
|
4
|
+
* guard for local paths.
|
|
5
|
+
*
|
|
6
|
+
* Mechanics are identical everywhere; POLICY is explicit at each call site
|
|
7
|
+
* via `allowLocal`:
|
|
8
|
+
* - The sender ({@link ../client.js}) gates the local (dev-only) backend
|
|
9
|
+
* behind its `allowLocalStorage` client option, default off.
|
|
10
|
+
* - The receiver passes `allowLocal: true` — receivers run inside the
|
|
11
|
+
* deployment, and the local backend is how the local platform delivers
|
|
12
|
+
* bodies.
|
|
13
|
+
*/
|
|
14
|
+
import type { PresignedRequest } from "./protocol.js";
|
|
15
|
+
export interface PresignedTransferOptions {
|
|
16
|
+
/** fetch implementation for http backends (default: global fetch). */
|
|
17
|
+
fetchImpl?: typeof fetch;
|
|
18
|
+
/** Allow the local filesystem backend (see module docs for the policy). */
|
|
19
|
+
allowLocal: boolean;
|
|
20
|
+
/** Optional caller-owned deadline/cancellation signal. */
|
|
21
|
+
signal?: AbortSignal;
|
|
22
|
+
}
|
|
23
|
+
/** Remove bearer-equivalent URL credentials before reporting a failure. */
|
|
24
|
+
export declare function redactUrlForError(raw: string): string;
|
|
25
|
+
/** Download the bytes behind a presigned GET request. */
|
|
26
|
+
export declare function downloadPresigned(request: PresignedRequest, options: PresignedTransferOptions): Promise<Uint8Array>;
|
|
27
|
+
/** Upload bytes to the target of a presigned PUT request. */
|
|
28
|
+
export declare function uploadPresigned(request: PresignedRequest, bytes: Uint8Array, options: PresignedTransferOptions): Promise<void>;
|
|
29
|
+
//# sourceMappingURL=presigned.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"presigned.d.ts","sourceRoot":"","sources":["../src/presigned.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAIH,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAA;AAErD,MAAM,WAAW,wBAAwB;IACvC,sEAAsE;IACtE,SAAS,CAAC,EAAE,OAAO,KAAK,CAAA;IACxB,2EAA2E;IAC3E,UAAU,EAAE,OAAO,CAAA;IACnB,0DAA0D;IAC1D,MAAM,CAAC,EAAE,WAAW,CAAA;CACrB;AAiBD,2EAA2E;AAC3E,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAcrD;AAyDD,yDAAyD;AACzD,wBAAsB,iBAAiB,CACrC,OAAO,EAAE,gBAAgB,EACzB,OAAO,EAAE,wBAAwB,GAChC,OAAO,CAAC,UAAU,CAAC,CAuCrB;AAED,6DAA6D;AAC7D,wBAAsB,eAAe,CACnC,OAAO,EAAE,gBAAgB,EACzB,KAAK,EAAE,UAAU,EACjB,OAAO,EAAE,wBAAwB,GAChC,OAAO,CAAC,IAAI,CAAC,CAwCf"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Command wire protocol — the on-the-wire JSON shapes exchanged with the command
|
|
3
|
+
* server (`/v1/commands…`).
|
|
4
|
+
*
|
|
5
|
+
* These shapes are the Kubb-generated types in `@alienplatform/core` (themselves
|
|
6
|
+
* generated from the same OpenAPI schema the Rust serde shapes in
|
|
7
|
+
* `crates/alien-core/src/commands_types.rs` and `presigned.rs` are pinned to), so
|
|
8
|
+
* they are re-exported here rather than hand-transcribed — the commands package
|
|
9
|
+
* keeps one named protocol surface without duplicating a second copy that could
|
|
10
|
+
* drift from the generated one. Only the constants and the handful of shapes core
|
|
11
|
+
* does not surface publicly live locally below.
|
|
12
|
+
*/
|
|
13
|
+
export type { BodySpec, CommandResponse, CommandState, CommandStatusResponse, CreateCommandRequest, CreateCommandResponse, Envelope, LeaseInfo, LeaseRequest, LeaseResponse, PresignedRequest, ReleaseRequest, ResponseHandling, StorageUpload, SubmitResponseRequest, TraceContext, UploadCompleteRequest, UploadCompleteResponse, } from "@alienplatform/core";
|
|
14
|
+
/**
|
|
15
|
+
* Target resource type — lowercase; `worker` is only valid for the worker
|
|
16
|
+
* runtime. Not surfaced from `@alienplatform/core`'s public API, so it stays
|
|
17
|
+
* local; kept structurally identical to the generated `CommandTargetType`.
|
|
18
|
+
*/
|
|
19
|
+
export type CommandTargetType = "worker" | "container" | "daemon";
|
|
20
|
+
/** Identifies the specific resource a command is addressed to. */
|
|
21
|
+
export type CommandTarget = {
|
|
22
|
+
resourceId: string;
|
|
23
|
+
resourceType: CommandTargetType;
|
|
24
|
+
};
|
|
25
|
+
/** Error envelope returned by the axum handlers on non-2xx responses. */
|
|
26
|
+
export type ErrorResponse = {
|
|
27
|
+
code: string;
|
|
28
|
+
message: string;
|
|
29
|
+
details?: string;
|
|
30
|
+
};
|
|
31
|
+
//# sourceMappingURL=protocol.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"protocol.d.ts","sourceRoot":"","sources":["../src/protocol.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,YAAY,EACV,QAAQ,EACR,eAAe,EACf,YAAY,EACZ,qBAAqB,EACrB,oBAAoB,EACpB,qBAAqB,EACrB,QAAQ,EACR,SAAS,EACT,YAAY,EACZ,aAAa,EACb,gBAAgB,EAChB,cAAc,EACd,gBAAgB,EAChB,aAAa,EACb,qBAAqB,EACrB,YAAY,EACZ,qBAAqB,EACrB,sBAAsB,GACvB,MAAM,qBAAqB,CAAA;AAE5B;;;;GAIG;AACH,MAAM,MAAM,iBAAiB,GAAG,QAAQ,GAAG,WAAW,GAAG,QAAQ,CAAA;AAEjE,kEAAkE;AAClE,MAAM,MAAM,aAAa,GAAG;IAC1B,UAAU,EAAE,MAAM,CAAA;IAClB,YAAY,EAAE,iBAAiB,CAAA;CAChC,CAAA;AAED,yEAAyE;AACzE,MAAM,MAAM,aAAa,GAAG;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAC;IAAC,OAAO,CAAC,EAAE,MAAM,CAAA;CAAE,CAAA"}
|
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pull command receiver — the app-owned lease loop for Containers and Daemons.
|
|
3
|
+
*
|
|
4
|
+
* Behavior-identical twin of the Rust `alien_commands::Receiver`. It leases
|
|
5
|
+
* commands addressed to its own target resource from the command server over
|
|
6
|
+
* outbound HTTPS (no inbound connections, no gRPC), dispatches them to
|
|
7
|
+
* in-process handlers, and submits responses through the envelope's
|
|
8
|
+
* response-handling flow (inline or presigned storage upload).
|
|
9
|
+
*
|
|
10
|
+
* Pure `fetch`; no bindings, no gRPC. The receiver implements these public
|
|
11
|
+
* command-delivery semantics:
|
|
12
|
+
* - required identity plus token-or-token-file env, with fail-fast validation
|
|
13
|
+
* - execution budget = `min(envelope.deadline, leaseExpiresAt − safety margin)`;
|
|
14
|
+
* on expiry the handler's `signal` fires and a `HANDLER_TIMEOUT` is submitted
|
|
15
|
+
* - error codes `UNKNOWN_COMMAND` / handler `error.code` (falling back to
|
|
16
|
+
* `HANDLER_ERROR`) / `HANDLER_TIMEOUT`, with params-decode failures retaining
|
|
17
|
+
* their decode error code
|
|
18
|
+
* - at-least-once delivery; `ctx.attempt` starts at 1
|
|
19
|
+
* - drain: shutdown stops polls, waits up to 30s, then aborts and releases
|
|
20
|
+
* - lease params 5s / maxLeases 1 / leaseSeconds 60, all env-tunable
|
|
21
|
+
* - `ctx.input` = decoded param bytes; success body = `JSON.stringify(return)`;
|
|
22
|
+
* `ctx.deadline` = the effective budget, always present while a lease is held
|
|
23
|
+
*
|
|
24
|
+
* # Bootstrap
|
|
25
|
+
*
|
|
26
|
+
* ```typescript
|
|
27
|
+
* import { createCommandReceiver } from "@alienplatform/commands"
|
|
28
|
+
*
|
|
29
|
+
* const receiver = createCommandReceiver()
|
|
30
|
+
* receiver.handle("generate-report", async ctx => {
|
|
31
|
+
* const params = JSON.parse(new TextDecoder().decode(ctx.input))
|
|
32
|
+
* return { report: params }
|
|
33
|
+
* })
|
|
34
|
+
* await receiver.run() // call receiver.stop() to drain and return
|
|
35
|
+
* ```
|
|
36
|
+
*/
|
|
37
|
+
import type { CommandTargetType, Envelope, TraceContext } from "./protocol.js";
|
|
38
|
+
/** Error code submitted when a leased command has no registered handler. */
|
|
39
|
+
export declare const ERROR_CODE_UNKNOWN_COMMAND = "UNKNOWN_COMMAND";
|
|
40
|
+
/** Error code submitted when a handler exceeds its execution budget. */
|
|
41
|
+
export declare const ERROR_CODE_HANDLER_TIMEOUT = "HANDLER_TIMEOUT";
|
|
42
|
+
/** Error code submitted when a handler throws/rejects (or its response fails to serialize). */
|
|
43
|
+
export declare const ERROR_CODE_HANDLER_ERROR = "HANDLER_ERROR";
|
|
44
|
+
/**
|
|
45
|
+
* Per-command context passed to a {@link CommandHandler}.
|
|
46
|
+
*
|
|
47
|
+
* These fields match the Rust `Context` struct
|
|
48
|
+
* (`input`/`deadline`/`command_id`/`attempt`/`cancellation`), the last mapping
|
|
49
|
+
* to `signal` here.
|
|
50
|
+
*/
|
|
51
|
+
export interface CommandContext {
|
|
52
|
+
/**
|
|
53
|
+
* Decoded command param bytes — the same bytes the params envelope carries
|
|
54
|
+
* after decode, prior to any handler-side parsing. This is byte-for-byte
|
|
55
|
+
* identical to the Rust receiver's `ctx.input`.
|
|
56
|
+
*/
|
|
57
|
+
input: Uint8Array;
|
|
58
|
+
/**
|
|
59
|
+
* Fires when the execution budget expires. The handler promise is abandoned
|
|
60
|
+
* regardless; observe this to stop cooperative work the handler started.
|
|
61
|
+
* Twin of the Rust `ctx.cancellation` token.
|
|
62
|
+
*/
|
|
63
|
+
signal: AbortSignal;
|
|
64
|
+
/**
|
|
65
|
+
* The effective execution budget: `min(envelope.deadline, leaseExpiresAt)`.
|
|
66
|
+
* Always present while a lease is held.
|
|
67
|
+
*/
|
|
68
|
+
deadline: Date;
|
|
69
|
+
/** Unique command identifier. */
|
|
70
|
+
commandId: string;
|
|
71
|
+
/** The resource identity this receiver owns. */
|
|
72
|
+
target: {
|
|
73
|
+
resourceId: string;
|
|
74
|
+
resourceType: Exclude<CommandTargetType, "worker">;
|
|
75
|
+
};
|
|
76
|
+
/** Optional W3C trace context propagated from the command envelope. */
|
|
77
|
+
traceContext?: TraceContext;
|
|
78
|
+
/**
|
|
79
|
+
* Delivery attempt, starting at 1. Greater than 1 means redelivery
|
|
80
|
+
* (at-least-once semantics); handlers must tolerate running more than once.
|
|
81
|
+
*/
|
|
82
|
+
attempt: number;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* A command handler. Receives a {@link CommandContext} and returns any
|
|
86
|
+
* JSON-serializable value, submitted as the command's success response
|
|
87
|
+
* (`JSON.stringify`-encoded). Throwing/rejecting submits the error's non-empty
|
|
88
|
+
* string `code` when present, otherwise `HANDLER_ERROR`.
|
|
89
|
+
*/
|
|
90
|
+
export type CommandHandler = (ctx: CommandContext) => unknown | Promise<unknown>;
|
|
91
|
+
/**
|
|
92
|
+
* The pull receiver handle. Register handlers with {@link CommandReceiver.handle},
|
|
93
|
+
* drive the lease loop with {@link CommandReceiver.run}, and stop it with
|
|
94
|
+
* {@link CommandReceiver.stop}.
|
|
95
|
+
*/
|
|
96
|
+
export interface CommandReceiver {
|
|
97
|
+
/** Register a handler for a command name. Registering a name twice replaces it. */
|
|
98
|
+
handle(name: string, handler: CommandHandler): CommandReceiver;
|
|
99
|
+
/**
|
|
100
|
+
* Drive the lease loop until {@link CommandReceiver.stop} is called. No new
|
|
101
|
+
* lease poll *starts* once draining begins; a poll already in flight
|
|
102
|
+
* completes and its leases are dispatched. In-flight commands may finish
|
|
103
|
+
* within the drain timeout; remaining handlers are aborted and released.
|
|
104
|
+
* Retryable or unknown transport failures continue polling; non-retryable
|
|
105
|
+
* {@link AlienError}s terminate the receiver after draining.
|
|
106
|
+
*/
|
|
107
|
+
run(): Promise<void>;
|
|
108
|
+
/** Signal the receiver to drain and stop (see {@link CommandReceiver.run}). */
|
|
109
|
+
stop(): void;
|
|
110
|
+
}
|
|
111
|
+
/** Options for {@link createCommandReceiver}; every field has a production default. */
|
|
112
|
+
export interface CommandReceiverOptions {
|
|
113
|
+
/** Environment source (defaults to `process.env`). */
|
|
114
|
+
env?: Record<string, string | undefined>;
|
|
115
|
+
/** `fetch` implementation (defaults to the global `fetch`). */
|
|
116
|
+
fetch?: typeof fetch;
|
|
117
|
+
/** Lease poll interval in ms (default 5000). Overrides the environment. */
|
|
118
|
+
pollIntervalMs?: number;
|
|
119
|
+
/** Maximum empty/error poll interval in ms (default 30000). */
|
|
120
|
+
pollMaxIntervalMs?: number;
|
|
121
|
+
/** Poll jitter fraction from 0 to 1 (default 0.1). */
|
|
122
|
+
pollJitter?: number;
|
|
123
|
+
/** Requested lease duration in seconds (default 60). Overrides the environment. */
|
|
124
|
+
leaseSeconds?: number;
|
|
125
|
+
/** Max leases requested per poll (default 1). Overrides the environment. */
|
|
126
|
+
maxLeases?: number;
|
|
127
|
+
/** Graceful drain timeout in ms (default 30000). */
|
|
128
|
+
drainTimeoutMs?: number;
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* Construct the pull receiver from environment configuration.
|
|
132
|
+
*
|
|
133
|
+
* Validates required identity, token source, and numeric tuning values
|
|
134
|
+
* **synchronously**. An invalid value throws
|
|
135
|
+
* {@link CommandReceiverConfigInvalidError} naming the offending variable in
|
|
136
|
+
* `context.envVar`. `resourceType` must be
|
|
137
|
+
* `container` or `daemon`; `worker` (and anything else) is rejected — a receiver
|
|
138
|
+
* must not guess its target type.
|
|
139
|
+
*/
|
|
140
|
+
export declare function createCommandReceiver(options?: CommandReceiverOptions): CommandReceiver;
|
|
141
|
+
/**
|
|
142
|
+
* Per-command execution budget: `min(envelope.deadline, leaseExpiresAt −
|
|
143
|
+
* LEASE_SAFETY_MARGIN_MS)`. The LEASE bound is clamped to now; an
|
|
144
|
+
* already-past deadline is not — it yields a zero budget and an immediate
|
|
145
|
+
* HANDLER_TIMEOUT, the correct outcome for a command delivered after its
|
|
146
|
+
* deadline. There is no
|
|
147
|
+
* lease-renew call, so the safety-margined lease expiry always bounds it. Twin
|
|
148
|
+
* of the Rust receiver's `command_budget`.
|
|
149
|
+
*/
|
|
150
|
+
export declare function commandBudget(deadline: string | undefined, leaseExpiresAt: string): Date;
|
|
151
|
+
/**
|
|
152
|
+
* Build the `/commands/leases` endpoint from the configured base URL.
|
|
153
|
+
*
|
|
154
|
+
* Twin of the Rust receiver's `acquire_leases`, which parses the base as a
|
|
155
|
+
* `Url` and appends segments via `path_segments_mut()` — that mutates only
|
|
156
|
+
* the path, leaving any query string untouched and correctly ordered after
|
|
157
|
+
* the appended segments (M1). The naive string approach this replaced
|
|
158
|
+
* (`url.replace(/\/+$/, "") + "/commands/leases"`) corrupted any base URL
|
|
159
|
+
* carrying a query string, e.g. `https://h/v1?token=x` became
|
|
160
|
+
* `https://h/v1?token=x/commands/leases` instead of
|
|
161
|
+
* `https://h/v1/commands/leases?token=x`.
|
|
162
|
+
*
|
|
163
|
+
* `path_segments_mut()` fails (and the Rust receiver raises
|
|
164
|
+
* `COMMAND_RECEIVER_CONFIG_INVALID`) for a base that cannot be a hierarchical
|
|
165
|
+
* URL — in practice, anything that isn't HTTP(S). This mirrors that check.
|
|
166
|
+
*/
|
|
167
|
+
export declare function buildLeaseEndpoint(baseUrl: string): string;
|
|
168
|
+
/** Build the authenticated lease-release endpoint without corrupting base queries. */
|
|
169
|
+
export declare function buildReleaseEndpoint(baseUrl: string, leaseId: string): string;
|
|
170
|
+
/**
|
|
171
|
+
* Resolve path-relative envelope URLs in place against the exact lease
|
|
172
|
+
* endpoint used to acquire them.
|
|
173
|
+
*
|
|
174
|
+
* The manager cannot know an address reachable from behind every consumer's
|
|
175
|
+
* network boundary or a reverse-proxy prefix added outside the manager. The
|
|
176
|
+
* successful lease endpoint contains both. Absolute cloud-presigned storage
|
|
177
|
+
* URLs pass through byte-for-byte. Twin of Rust `resolve_envelope_urls`.
|
|
178
|
+
*/
|
|
179
|
+
export declare function resolveEnvelopeUrls(envelope: Envelope, leaseEndpoint: string): void;
|
|
180
|
+
/**
|
|
181
|
+
* Decode command param bytes for `ctx.input`: inline base64 → raw bytes;
|
|
182
|
+
* storage → GET the presigned request and use the body bytes. Never JSON-parses
|
|
183
|
+
* (that is the handler's job).
|
|
184
|
+
*/
|
|
185
|
+
export declare function decodeParamsBytes(envelope: Envelope, fetchImpl: typeof fetch, signal?: AbortSignal): Promise<Uint8Array>;
|
|
186
|
+
//# sourceMappingURL=receiver.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"receiver.d.ts","sourceRoot":"","sources":["../src/receiver.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AAWH,OAAO,KAAK,EAGV,iBAAiB,EACjB,QAAQ,EAIR,YAAY,EACb,MAAM,eAAe,CAAA;AAWtB,4EAA4E;AAC5E,eAAO,MAAM,0BAA0B,oBAAoB,CAAA;AAC3D,wEAAwE;AACxE,eAAO,MAAM,0BAA0B,oBAAoB,CAAA;AAC3D,+FAA+F;AAC/F,eAAO,MAAM,wBAAwB,kBAAkB,CAAA;AA8CvD;;;;;;GAMG;AACH,MAAM,WAAW,cAAc;IAC7B;;;;OAIG;IACH,KAAK,EAAE,UAAU,CAAA;IACjB;;;;OAIG;IACH,MAAM,EAAE,WAAW,CAAA;IACnB;;;OAGG;IACH,QAAQ,EAAE,IAAI,CAAA;IACd,iCAAiC;IACjC,SAAS,EAAE,MAAM,CAAA;IACjB,gDAAgD;IAChD,MAAM,EAAE;QACN,UAAU,EAAE,MAAM,CAAA;QAClB,YAAY,EAAE,OAAO,CAAC,iBAAiB,EAAE,QAAQ,CAAC,CAAA;KACnD,CAAA;IACD,uEAAuE;IACvE,YAAY,CAAC,EAAE,YAAY,CAAA;IAC3B;;;OAGG;IACH,OAAO,EAAE,MAAM,CAAA;CAChB;AAED;;;;;GAKG;AACH,MAAM,MAAM,cAAc,GAAG,CAAC,GAAG,EAAE,cAAc,KAAK,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,CAAA;AAEhF;;;;GAIG;AACH,MAAM,WAAW,eAAe;IAC9B,mFAAmF;IACnF,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,cAAc,GAAG,eAAe,CAAA;IAC9D;;;;;;;OAOG;IACH,GAAG,IAAI,OAAO,CAAC,IAAI,CAAC,CAAA;IACpB,+EAA+E;IAC/E,IAAI,IAAI,IAAI,CAAA;CACb;AAED,uFAAuF;AACvF,MAAM,WAAW,sBAAsB;IACrC,sDAAsD;IACtD,GAAG,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,CAAA;IACxC,+DAA+D;IAC/D,KAAK,CAAC,EAAE,OAAO,KAAK,CAAA;IACpB,2EAA2E;IAC3E,cAAc,CAAC,EAAE,MAAM,CAAA;IACvB,+DAA+D;IAC/D,iBAAiB,CAAC,EAAE,MAAM,CAAA;IAC1B,sDAAsD;IACtD,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,mFAAmF;IACnF,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,4EAA4E;IAC5E,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,oDAAoD;IACpD,cAAc,CAAC,EAAE,MAAM,CAAA;CACxB;AAiBD;;;;;;;;;GASG;AACH,wBAAgB,qBAAqB,CAAC,OAAO,GAAE,sBAA2B,GAAG,eAAe,CAI3F;AA0lBD;;;;;;;;GAQG;AACH,wBAAgB,aAAa,CAAC,QAAQ,EAAE,MAAM,GAAG,SAAS,EAAE,cAAc,EAAE,MAAM,GAAG,IAAI,CASxF;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CA8B1D;AAED,sFAAsF;AACtF,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,MAAM,CAM7E;AAED;;;;;;;;GAQG;AACH,wBAAgB,mBAAmB,CAAC,QAAQ,EAAE,QAAQ,EAAE,aAAa,EAAE,MAAM,GAAG,IAAI,CAoCnF;AA4GD;;;;GAIG;AACH,wBAAsB,iBAAiB,CACrC,QAAQ,EAAE,QAAQ,EAClB,SAAS,EAAE,OAAO,KAAK,EACvB,MAAM,CAAC,EAAE,WAAW,GACnB,OAAO,CAAC,UAAU,CAAC,CAqBrB"}
|
package/dist/wire.d.ts
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Wire-response validation.
|
|
3
|
+
*
|
|
4
|
+
* The command server's JSON responses are validated at the fetch boundary
|
|
5
|
+
* against the Kubb-generated zod schemas in `@alienplatform/core`. A body that
|
|
6
|
+
* doesn't match its schema becomes a typed {@link MalformedResponseError} here,
|
|
7
|
+
* rather than a `TypeError` thrown deep in the caller when a missing field is
|
|
8
|
+
* later dereferenced.
|
|
9
|
+
*/
|
|
10
|
+
/**
|
|
11
|
+
* Minimal structural view of a zod schema — just the `safeParse` we use. Lets
|
|
12
|
+
* this helper accept the core schemas without importing zod (a dev-only
|
|
13
|
+
* dependency) into the published type surface.
|
|
14
|
+
*/
|
|
15
|
+
export interface WireSchema<T> {
|
|
16
|
+
safeParse(value: unknown): {
|
|
17
|
+
success: true;
|
|
18
|
+
data: T;
|
|
19
|
+
} | {
|
|
20
|
+
success: false;
|
|
21
|
+
error: {
|
|
22
|
+
message: string;
|
|
23
|
+
};
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Validate a decoded JSON response against `schema`, returning the typed value
|
|
28
|
+
* or throwing a {@link MalformedResponseError} naming the request that produced
|
|
29
|
+
* the malformed body.
|
|
30
|
+
*/
|
|
31
|
+
export declare function parseWireResponse<T>(schema: WireSchema<T>, value: unknown, method: string, url: string): T;
|
|
32
|
+
//# sourceMappingURL=wire.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"wire.d.ts","sourceRoot":"","sources":["../src/wire.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAKH;;;;GAIG;AACH,MAAM,WAAW,UAAU,CAAC,CAAC;IAC3B,SAAS,CACP,KAAK,EAAE,OAAO,GACb;QAAE,OAAO,EAAE,IAAI,CAAC;QAAC,IAAI,EAAE,CAAC,CAAA;KAAE,GAAG;QAAE,OAAO,EAAE,KAAK,CAAC;QAAC,KAAK,EAAE;YAAE,OAAO,EAAE,MAAM,CAAA;SAAE,CAAA;KAAE,CAAA;CAC/E;AAED;;;;GAIG;AACH,wBAAgB,iBAAiB,CAAC,CAAC,EACjC,MAAM,EAAE,UAAU,CAAC,CAAC,CAAC,EACrB,KAAK,EAAE,OAAO,EACd,MAAM,EAAE,MAAM,EACd,GAAG,EAAE,MAAM,GACV,CAAC,CAMH"}
|
package/package.json
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@alienplatform/commands",
|
|
3
|
+
"version": "1.14.1-dev.e74fae6cd01b61e77a285276f264b5480977f41a",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"sideEffects": false,
|
|
6
|
+
"types": "./dist/index.d.ts",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"types": "./dist/index.d.ts",
|
|
10
|
+
"import": "./dist/index.js"
|
|
11
|
+
}
|
|
12
|
+
},
|
|
13
|
+
"files": [
|
|
14
|
+
"dist"
|
|
15
|
+
],
|
|
16
|
+
"engines": {
|
|
17
|
+
"node": ">=18",
|
|
18
|
+
"bun": ">=1.0.23"
|
|
19
|
+
},
|
|
20
|
+
"scripts": {
|
|
21
|
+
"build": "tsdown && tsc -p tsconfig.build.json --emitDeclarationOnly",
|
|
22
|
+
"prepare": "npm run build",
|
|
23
|
+
"test": "vitest run",
|
|
24
|
+
"test:integration": "vitest run --config vitest.integration.config.ts",
|
|
25
|
+
"test:bun": "BUN_EXPECTED=1 bun test tests/runtime-canary.test.ts tests/commands-client.test.ts tests/receiver.test.ts tests/presigned.test.ts",
|
|
26
|
+
"test:ts": "tsc --noEmit",
|
|
27
|
+
"format-and-lint": "biome check .",
|
|
28
|
+
"format-and-lint:fix": "biome check . --write"
|
|
29
|
+
},
|
|
30
|
+
"keywords": [
|
|
31
|
+
"alien",
|
|
32
|
+
"commands",
|
|
33
|
+
"invoke",
|
|
34
|
+
"receiver",
|
|
35
|
+
"deployment",
|
|
36
|
+
"fetch"
|
|
37
|
+
],
|
|
38
|
+
"author": "Alien Software, Inc. <hi@alien.dev>",
|
|
39
|
+
"license": "FSL-1.1-Apache-2.0",
|
|
40
|
+
"description": "Pure-TypeScript command sender and pull receiver for the Alien platform, over fetch",
|
|
41
|
+
"homepage": "https://alien.dev",
|
|
42
|
+
"repository": {
|
|
43
|
+
"type": "git",
|
|
44
|
+
"url": "https://github.com/alienplatform/alien.git",
|
|
45
|
+
"directory": "packages/commands"
|
|
46
|
+
},
|
|
47
|
+
"publishConfig": {
|
|
48
|
+
"access": "public"
|
|
49
|
+
},
|
|
50
|
+
"devDependencies": {
|
|
51
|
+
"@alienplatform/typescript-config": "workspace:^",
|
|
52
|
+
"@biomejs/biome": "^1.9.4",
|
|
53
|
+
"@types/node": "^24.0.15",
|
|
54
|
+
"tsdown": "^0.13.0",
|
|
55
|
+
"typescript": "^5.8.3",
|
|
56
|
+
"vitest": "^3.1.4",
|
|
57
|
+
"zod": "4.3.2"
|
|
58
|
+
},
|
|
59
|
+
"dependencies": {
|
|
60
|
+
"@alienplatform/core": "1.14.1-dev.e74fae6cd01b61e77a285276f264b5480977f41a"
|
|
61
|
+
}
|
|
62
|
+
}
|