@workflow/core 5.0.0-beta.35 → 5.0.0-beta.37
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/capabilities.d.ts +6 -0
- package/dist/capabilities.d.ts.map +1 -1
- package/dist/capabilities.js +13 -1
- package/dist/classify-error.d.ts.map +1 -1
- package/dist/classify-error.js +5 -2
- package/dist/create-hook.d.ts +41 -22
- package/dist/create-hook.d.ts.map +1 -1
- package/dist/create-hook.js +1 -1
- package/dist/describe-error.d.ts.map +1 -1
- package/dist/describe-error.js +12 -1
- package/dist/encryption.d.ts +15 -2
- package/dist/encryption.d.ts.map +1 -1
- package/dist/encryption.js +28 -7
- package/dist/flushable-stream.d.ts +55 -0
- package/dist/flushable-stream.d.ts.map +1 -1
- package/dist/flushable-stream.js +106 -4
- package/dist/global.d.ts +2 -0
- package/dist/global.d.ts.map +1 -1
- package/dist/global.js +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -2
- package/dist/log-format.js +3 -3
- package/dist/private.d.ts +82 -50
- package/dist/private.d.ts.map +1 -1
- package/dist/private.js +149 -22
- package/dist/replay-payload-cache.d.ts +57 -0
- package/dist/replay-payload-cache.d.ts.map +1 -0
- package/dist/replay-payload-cache.js +143 -0
- package/dist/runtime/constants.d.ts +11 -0
- package/dist/runtime/constants.d.ts.map +1 -1
- package/dist/runtime/constants.js +26 -1
- package/dist/runtime/count-step-started-events.d.ts +52 -0
- package/dist/runtime/count-step-started-events.d.ts.map +1 -0
- package/dist/runtime/count-step-started-events.js +72 -0
- package/dist/runtime/get-port-lazy.js +4 -4
- package/dist/runtime/helpers.d.ts +47 -16
- package/dist/runtime/helpers.d.ts.map +1 -1
- package/dist/runtime/helpers.js +97 -28
- package/dist/runtime/resume-hook.d.ts +6 -3
- package/dist/runtime/resume-hook.d.ts.map +1 -1
- package/dist/runtime/resume-hook.js +180 -58
- package/dist/runtime/run.d.ts.map +1 -1
- package/dist/runtime/run.js +3 -3
- package/dist/runtime/runs.d.ts.map +1 -1
- package/dist/runtime/runs.js +5 -3
- package/dist/runtime/start.d.ts.map +1 -1
- package/dist/runtime/start.js +65 -18
- package/dist/runtime/step-executor.d.ts +48 -8
- package/dist/runtime/step-executor.d.ts.map +1 -1
- package/dist/runtime/step-executor.js +90 -20
- package/dist/runtime/suspension-handler.js +3 -3
- package/dist/runtime/world.d.ts +2 -7
- package/dist/runtime/world.d.ts.map +1 -1
- package/dist/runtime/world.js +3 -10
- package/dist/runtime.d.ts +1 -1
- package/dist/runtime.d.ts.map +1 -1
- package/dist/runtime.js +398 -184
- package/dist/sealed-box.d.ts +167 -0
- package/dist/sealed-box.d.ts.map +1 -0
- package/dist/sealed-box.js +571 -0
- package/dist/serialization/client.d.ts +3 -3
- package/dist/serialization/client.d.ts.map +1 -1
- package/dist/serialization/client.js +1 -1
- package/dist/serialization/codec.d.ts +6 -4
- package/dist/serialization/codec.d.ts.map +1 -1
- package/dist/serialization/codec.js +1 -1
- package/dist/serialization/encryption.d.ts +118 -17
- package/dist/serialization/encryption.d.ts.map +1 -1
- package/dist/serialization/encryption.js +131 -15
- package/dist/serialization/step.d.ts +4 -4
- package/dist/serialization/step.d.ts.map +1 -1
- package/dist/serialization/step.js +2 -2
- package/dist/serialization/types.d.ts +20 -0
- package/dist/serialization/types.d.ts.map +1 -1
- package/dist/serialization/types.js +11 -1
- package/dist/serialization-format.d.ts +44 -4
- package/dist/serialization-format.d.ts.map +1 -1
- package/dist/serialization-format.js +66 -9
- package/dist/serialization.d.ts +61 -21
- package/dist/serialization.d.ts.map +1 -1
- package/dist/serialization.js +556 -200
- package/dist/set-attributes.d.ts +2 -7
- package/dist/set-attributes.d.ts.map +1 -1
- package/dist/set-attributes.js +1 -6
- package/dist/step/context-storage.d.ts +2 -2
- package/dist/step/context-storage.d.ts.map +1 -1
- package/dist/step/context-storage.js +2 -2
- package/dist/step/writable-stream.d.ts.map +1 -1
- package/dist/step/writable-stream.js +14 -3
- package/dist/step.d.ts.map +1 -1
- package/dist/step.js +87 -22
- package/dist/symbols.d.ts +26 -0
- package/dist/symbols.d.ts.map +1 -1
- package/dist/symbols.js +27 -1
- package/dist/telemetry/semantic-conventions.d.ts +4 -4
- package/dist/telemetry/semantic-conventions.js +2 -2
- package/dist/version.d.ts +1 -1
- package/dist/version.js +2 -2
- package/dist/vm/index.d.ts.map +1 -1
- package/dist/vm/index.js +76 -9
- package/dist/workflow/abort-controller.d.ts +1 -1
- package/dist/workflow/abort-controller.d.ts.map +1 -1
- package/dist/workflow/abort-controller.js +38 -3
- package/dist/workflow/hook.d.ts.map +1 -1
- package/dist/workflow/hook.js +85 -30
- package/dist/workflow/index.d.ts +1 -1
- package/dist/workflow/index.d.ts.map +1 -1
- package/dist/workflow/index.js +2 -2
- package/dist/workflow/set-attributes.d.ts +0 -9
- package/dist/workflow/set-attributes.d.ts.map +1 -1
- package/dist/workflow/set-attributes.js +1 -6
- package/dist/workflow/sleep.d.ts.map +1 -1
- package/dist/workflow/sleep.js +21 -9
- package/dist/workflow.d.ts +14 -11
- package/dist/workflow.d.ts.map +1 -1
- package/dist/workflow.js +37 -92
- package/docs/api-reference/create-hook.mdx +43 -2
- package/docs/api-reference/define-hook.mdx +26 -24
- package/docs/api-reference/fatal-error.mdx +29 -7
- package/docs/api-reference/fetch.mdx +3 -4
- package/docs/api-reference/set-attributes.mdx +0 -4
- package/docs/api-reference/sleep.mdx +1 -1
- package/docs/foundations/hooks.mdx +1 -1
- package/docs/foundations/idempotency.mdx +16 -9
- package/docs/how-it-works/cancellation.mdx +2 -2
- package/docs/how-it-works/code-transform.mdx +19 -15
- package/docs/how-it-works/encryption.mdx +3 -3
- package/docs/how-it-works/event-sourcing.mdx +6 -6
- package/docs/how-it-works/framework-integrations.mdx +96 -342
- package/package.json +6 -6
- package/dist/runtime/step-handler.d.ts +0 -2
- package/dist/runtime/step-handler.d.ts.map +0 -1
- package/dist/runtime/step-handler.js +0 -839
- package/dist/step-hydration-cache.d.ts +0 -148
- package/dist/step-hydration-cache.d.ts.map +0 -1
- package/dist/step-hydration-cache.js +0 -171
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
import { type CryptoKey } from './encryption.js';
|
|
2
|
+
/**
|
|
3
|
+
* A per-run X25519 keypair, derived from the run's key material.
|
|
4
|
+
*
|
|
5
|
+
* Callers should derive this once per run and memoize it alongside the
|
|
6
|
+
* symmetric key — derivation costs several Web Crypto round trips.
|
|
7
|
+
*/
|
|
8
|
+
export interface RunKeyPair {
|
|
9
|
+
/** Raw 32-byte X25519 private scalar. Secret. */
|
|
10
|
+
readonly scalar: Uint8Array;
|
|
11
|
+
/** Raw 32-byte X25519 public key. Safe to publish. */
|
|
12
|
+
readonly publicKey: Uint8Array;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Derive the per-run X25519 keypair from the run's 32-byte key material.
|
|
16
|
+
*
|
|
17
|
+
* Deterministic: the same key material always yields the same keypair, which
|
|
18
|
+
* is what lets the owning deployment re-derive its private scalar on demand
|
|
19
|
+
* (from `VERCEL_DEPLOYMENT_KEY`) instead of storing it anywhere.
|
|
20
|
+
*
|
|
21
|
+
* @param runKeyMaterial - The 32 bytes returned by `World.getEncryptionKeyForRun()`
|
|
22
|
+
* @returns The run's X25519 scalar and public key
|
|
23
|
+
*/
|
|
24
|
+
export declare function deriveRunKeyPair(runKeyMaterial: Uint8Array): Promise<RunKeyPair>;
|
|
25
|
+
/**
|
|
26
|
+
* Encode bytes as standard (padded) base64.
|
|
27
|
+
*
|
|
28
|
+
* Hand-rolled for the same reason as {@link base64UrlToBytes}: this module
|
|
29
|
+
* runs in the browser (o11y decryption) and inside the workflow VM, so neither
|
|
30
|
+
* `Buffer` nor `btoa` can be assumed. Used for the wire encoding of run public
|
|
31
|
+
* keys, matching the base64 convention already used for `VERCEL_DEPLOYMENT_KEY`
|
|
32
|
+
* and the `run-key` API response.
|
|
33
|
+
*/
|
|
34
|
+
export declare function bytesToBase64(bytes: Uint8Array): string;
|
|
35
|
+
/**
|
|
36
|
+
* Decode standard base64 (padding optional) to bytes.
|
|
37
|
+
*
|
|
38
|
+
* Returns `undefined` for malformed input rather than throwing: callers decode
|
|
39
|
+
* public keys that arrive from storage or over the wire, where a corrupt value
|
|
40
|
+
* should degrade to "this run has no usable public key" (and fall back to the
|
|
41
|
+
* symmetric path) rather than crash a resumption.
|
|
42
|
+
*
|
|
43
|
+
* Validation is strict, because a lenient decoder is worse than a throwing one
|
|
44
|
+
* here — silently returning a short or truncated key makes a corrupt value look
|
|
45
|
+
* *present*, so the caller seals to garbage instead of taking the fallback.
|
|
46
|
+
* Rejected: characters outside the alphabet, a length that cannot describe a
|
|
47
|
+
* whole number of bytes (`length % 4 === 1`), padding anywhere but the end, and
|
|
48
|
+
* a final quantum whose unused low bits are not zero.
|
|
49
|
+
*/
|
|
50
|
+
export declare function base64ToBytes(value: string): Uint8Array | undefined;
|
|
51
|
+
/**
|
|
52
|
+
* The writer half of the KEM: generate an ephemeral keypair and derive a
|
|
53
|
+
* content key for a recipient's public key.
|
|
54
|
+
*
|
|
55
|
+
* Use this when many payloads share one KEM operation — i.e. stream frames.
|
|
56
|
+
* The returned `contentKey` can only encrypt, so a stream writer provably
|
|
57
|
+
* cannot read the recipient run's data even by mistake.
|
|
58
|
+
*
|
|
59
|
+
* **Callers own nonce discipline.** Encrypt each frame with a fresh random
|
|
60
|
+
* nonce, and call this function again for every new connection attempt or
|
|
61
|
+
* replay so that a restarted writer never reuses a content key. For one-shot
|
|
62
|
+
* payloads prefer {@link seal}, which handles this automatically.
|
|
63
|
+
*
|
|
64
|
+
* @param recipientPublicKey - The recipient run's raw 32-byte X25519 public key
|
|
65
|
+
* @returns The ephemeral public key to publish alongside the ciphertext, and
|
|
66
|
+
* the encrypt-only content key
|
|
67
|
+
*/
|
|
68
|
+
export declare function encapsulate(recipientPublicKey: Uint8Array): Promise<{
|
|
69
|
+
ephemeralPublicKey: Uint8Array;
|
|
70
|
+
contentKey: CryptoKey;
|
|
71
|
+
}>;
|
|
72
|
+
/**
|
|
73
|
+
* The recipient half of the KEM: recover the content key for a sealed
|
|
74
|
+
* payload from the run's own keypair and the sender's ephemeral public key.
|
|
75
|
+
*
|
|
76
|
+
* @param keyPair - The recipient run's keypair, from {@link deriveRunKeyPair}
|
|
77
|
+
* @param ephemeralPublicKey - The sender's raw 32-byte X25519 public key,
|
|
78
|
+
* read from the head of the sealed envelope
|
|
79
|
+
* @returns A decrypt-only content key
|
|
80
|
+
*/
|
|
81
|
+
export declare function decapsulate(keyPair: RunKeyPair, ephemeralPublicKey: Uint8Array): Promise<CryptoKey>;
|
|
82
|
+
/**
|
|
83
|
+
* Seal a payload to a run's public key.
|
|
84
|
+
*
|
|
85
|
+
* Each call performs its own KEM operation, so every sealed payload gets an
|
|
86
|
+
* independent content key — nonce reuse across calls is impossible by
|
|
87
|
+
* construction.
|
|
88
|
+
*
|
|
89
|
+
* @param recipientPublicKey - The recipient run's raw 32-byte X25519 public key
|
|
90
|
+
* @param data - Plaintext to seal
|
|
91
|
+
* @param aad - Optional additional authenticated data, covered by the GCM tag
|
|
92
|
+
* but not encrypted. Callers pass the recipient's `projectId|runId` so a
|
|
93
|
+
* sealed payload cannot be replayed against a different run.
|
|
94
|
+
* @returns `[ephemeral public key (32)][nonce (12)][ciphertext + tag]`
|
|
95
|
+
*/
|
|
96
|
+
export declare function seal(recipientPublicKey: Uint8Array, data: Uint8Array, aad?: Uint8Array): Promise<Uint8Array>;
|
|
97
|
+
/**
|
|
98
|
+
* Open a payload sealed to this run's public key.
|
|
99
|
+
*
|
|
100
|
+
* @param keyPair - The recipient run's keypair, from {@link deriveRunKeyPair}
|
|
101
|
+
* @param sealed - `[ephemeral public key (32)][nonce (12)][ciphertext + tag]`
|
|
102
|
+
* @param aad - The exact additional authenticated data passed to {@link seal}
|
|
103
|
+
* @returns The decrypted plaintext
|
|
104
|
+
*/
|
|
105
|
+
export declare function open(keyPair: RunKeyPair, sealed: Uint8Array, aad?: Uint8Array): Promise<Uint8Array>;
|
|
106
|
+
/**
|
|
107
|
+
* A writer-side session that amortizes one KEM operation across many sealed
|
|
108
|
+
* payloads — use it for streams, where one-shot {@link seal} would perform a
|
|
109
|
+
* fresh keygen + ECDH + HKDF for every frame.
|
|
110
|
+
*
|
|
111
|
+
* Safety rests on two properties:
|
|
112
|
+
*
|
|
113
|
+
* - Every payload still gets a **fresh random nonce** from `aesGcmEncrypt`, so
|
|
114
|
+
* sharing the content key does not risk `(key, nonce)` reuse. (A counter
|
|
115
|
+
* would: it restarts at zero whenever a writer restarts.)
|
|
116
|
+
* - The session is bound to one writer instance. A reconnect or a durable
|
|
117
|
+
* replay constructs a new session, so a restarted writer never inherits a
|
|
118
|
+
* previous incarnation's content key.
|
|
119
|
+
*
|
|
120
|
+
* The envelope layout is byte-identical to {@link seal}, so a reader cannot
|
|
121
|
+
* tell which was used and needs no matching session.
|
|
122
|
+
*/
|
|
123
|
+
export declare function createSealSession(recipientPublicKey: Uint8Array, aad?: Uint8Array): {
|
|
124
|
+
seal(data: Uint8Array): Promise<Uint8Array>;
|
|
125
|
+
};
|
|
126
|
+
/**
|
|
127
|
+
* A reader-side session that caches decapsulation per sender.
|
|
128
|
+
*
|
|
129
|
+
* The mirror of {@link createSealSession}: because every frame from one writer
|
|
130
|
+
* carries the same ephemeral public key, this turns an ECDH per frame into an
|
|
131
|
+
* ECDH per writer. Correctness does not depend on the writer having used a
|
|
132
|
+
* session — a stream of independently sealed payloads simply misses the cache
|
|
133
|
+
* on each new ephemeral key.
|
|
134
|
+
*
|
|
135
|
+
* The cache is keyed by the ephemeral public key and holds one entry, which is
|
|
136
|
+
* the common case (one writer per stream). A second writer evicts the first
|
|
137
|
+
* rather than growing without bound.
|
|
138
|
+
*/
|
|
139
|
+
export declare function createOpenSession(keyPair: RunKeyPair, aad?: Uint8Array): {
|
|
140
|
+
open(sealed: Uint8Array): Promise<Uint8Array>;
|
|
141
|
+
};
|
|
142
|
+
/**
|
|
143
|
+
* Build the additional authenticated data that binds a sealed payload to a
|
|
144
|
+
* specific run.
|
|
145
|
+
*
|
|
146
|
+
* Mirrors the `info` used for symmetric per-run key derivation so the two
|
|
147
|
+
* schemes agree on what "this run" means.
|
|
148
|
+
*
|
|
149
|
+
* Note that the sealed-box construction already binds a payload to its
|
|
150
|
+
* recipient without any AAD: the content key is derived over
|
|
151
|
+
* `ephemeralPublicKey ‖ recipientPublicKey`, and a recipient public key is
|
|
152
|
+
* unique per (deployment key × project × run). Replaying a sealed payload at
|
|
153
|
+
* a different run therefore fails at key agreement regardless. AAD is
|
|
154
|
+
* available for callers that want an additional, KDF-independent binding —
|
|
155
|
+
* both sides must supply byte-identical values or the payload will not open.
|
|
156
|
+
*/
|
|
157
|
+
export declare function runAad(projectId: string, runId: string): Uint8Array;
|
|
158
|
+
/**
|
|
159
|
+
* Decode a run's published public key, validating both encoding and length.
|
|
160
|
+
*
|
|
161
|
+
* Returns `undefined` when the value is absent, not valid base64, or not
|
|
162
|
+
* exactly 32 bytes. Callers treat that as "this run has no usable public key"
|
|
163
|
+
* and fall back to the symmetric path, so a corrupt or truncated stored value
|
|
164
|
+
* degrades to the pre-existing behavior instead of failing a resumption.
|
|
165
|
+
*/
|
|
166
|
+
export declare function decodeRunPublicKey(value: string | undefined): Uint8Array | undefined;
|
|
167
|
+
//# sourceMappingURL=sealed-box.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sealed-box.d.ts","sourceRoot":"","sources":["../src/sealed-box.ts"],"names":[],"mappings":"AACA,OAAO,EAGL,KAAK,SAAS,EAGf,MAAM,iBAAiB,CAAC;AA2IzB;;;;;GAKG;AACH,MAAM,WAAW,UAAU;IACzB,iDAAiD;IACjD,QAAQ,CAAC,MAAM,EAAE,UAAU,CAAC;IAC5B,sDAAsD;IACtD,QAAQ,CAAC,SAAS,EAAE,UAAU,CAAC;CAChC;AAkBD;;;;;;;;;GASG;AACH,wBAAsB,gBAAgB,CACpC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