@chainlink/cre-sdk 1.1.4 → 1.2.0-alpha.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 +12 -1
- package/bin/cre-compile.ts +6 -1
- package/dist/index.d.ts +3 -0
- package/dist/sdk/types/global.d.ts +146 -2
- package/dist/sdk/types/restricted-apis.d.ts +18 -23
- package/dist/sdk/types/restricted-node-modules.d.ts +462 -0
- package/dist/sdk/utils/capabilities/blockchain/blockchain-helpers.d.ts +2 -2
- package/dist/sdk/utils/prepare-runtime.d.ts +1 -1
- package/dist/sdk/utils/prepare-runtime.js +9 -2
- package/dist/sdk/wasm/host-bindings.d.ts +4 -4
- package/package.json +2 -2
- package/scripts/run.ts +7 -1
- package/scripts/src/build-types.ts +31 -1
- package/scripts/src/compile-to-js.ts +5 -6
- package/scripts/src/compile-workflow.ts +1 -11
- package/scripts/src/validate-workflow-runtime-compat.test.ts +433 -0
- package/scripts/src/validate-workflow-runtime-compat.ts +631 -0
package/README.md
CHANGED
|
@@ -8,6 +8,7 @@ The Chainlink Runtime Environment (CRE) SDK for TypeScript enables developers to
|
|
|
8
8
|
- [Examples](#examples)
|
|
9
9
|
- [Simulate locally with CRE CLI](#simulate-locally-with-cre-cli)
|
|
10
10
|
- [Installation](#installation)
|
|
11
|
+
- [Runtime Compatibility Constraints](#runtime-compatibility-constraints)
|
|
11
12
|
- [Core Concepts](#core-concepts)
|
|
12
13
|
- [Workflows](#workflows)
|
|
13
14
|
- [Runtime Modes](#runtime-modes)
|
|
@@ -47,10 +48,20 @@ This package must be used along with the [CRE CLI tool](https://github.com/smart
|
|
|
47
48
|
|
|
48
49
|
## Prerequisites
|
|
49
50
|
|
|
50
|
-
1. the [bun runtime](https://bun.com/)
|
|
51
|
+
1. the [bun runtime](https://bun.com/) for local tooling and workflow compilation.
|
|
51
52
|
|
|
52
53
|
2. the [CRE CLI tool](https://github.com/smartcontractkit/cre-cli) installed.
|
|
53
54
|
|
|
55
|
+
## Runtime Compatibility Constraints
|
|
56
|
+
|
|
57
|
+
CRE workflows are compiled to WASM and executed through Javy (QuickJS). This is **not** a full Node.js runtime.
|
|
58
|
+
|
|
59
|
+
- Node built-ins like `node:fs`, `node:crypto`, `node:http`, `node:net`, etc. are not supported in workflows.
|
|
60
|
+
- Browser globals like `fetch`, `window`, and `setTimeout` are also not available in workflow runtime.
|
|
61
|
+
- `cre compile:workflow` / `cre-compile` now validates workflow source and fails fast when unsupported APIs are used.
|
|
62
|
+
|
|
63
|
+
Use CRE capabilities (for example, `cre.capabilities.HTTPClient`) instead of direct Node/browser APIs.
|
|
64
|
+
|
|
54
65
|
## Getting Started
|
|
55
66
|
|
|
56
67
|
We recommend you consult the [getting started docs](https://docs.chain.link/cre/getting-started/cli-installation) and install the CRE CLI.
|
package/bin/cre-compile.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env bun
|
|
2
2
|
|
|
3
3
|
import { main as compileWorkflow } from "../scripts/src/compile-workflow";
|
|
4
|
+
import { WorkflowRuntimeCompatibilityError } from "../scripts/src/validate-workflow-runtime-compat";
|
|
4
5
|
|
|
5
6
|
const main = async () => {
|
|
6
7
|
const cliArgs = process.argv.slice(2);
|
|
@@ -26,6 +27,10 @@ const main = async () => {
|
|
|
26
27
|
|
|
27
28
|
// CLI entry point
|
|
28
29
|
main().catch((e) => {
|
|
29
|
-
|
|
30
|
+
if (e instanceof WorkflowRuntimeCompatibilityError) {
|
|
31
|
+
console.error(`\n❌ ${e.message}`);
|
|
32
|
+
} else {
|
|
33
|
+
console.error(e);
|
|
34
|
+
}
|
|
30
35
|
process.exit(1);
|
|
31
36
|
});
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
|
-
// Global type declarations for the CRE SDK runtime
|
|
2
|
-
//
|
|
1
|
+
// Global type declarations for the CRE SDK runtime.
|
|
2
|
+
// These are the methods and globals exposed by the Host to the Guest.
|
|
3
|
+
|
|
4
|
+
type ExistingGlobal<K extends PropertyKey, Fallback> =
|
|
5
|
+
typeof globalThis extends Record<K, infer T> ? T : Fallback
|
|
3
6
|
|
|
4
7
|
/**
|
|
5
8
|
* Host functions exposed by the CRE runtime to WASM guests
|
|
@@ -78,6 +81,147 @@ declare global {
|
|
|
78
81
|
* @returns Unix timestamp in milliseconds
|
|
79
82
|
*/
|
|
80
83
|
function now(): number
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Console API available in the QuickJS runtime
|
|
87
|
+
*/
|
|
88
|
+
type CreConsole = {
|
|
89
|
+
log(...args: unknown[]): void
|
|
90
|
+
warn(...args: unknown[]): void
|
|
91
|
+
error(...args: unknown[]): void
|
|
92
|
+
info(...args: unknown[]): void
|
|
93
|
+
debug(...args: unknown[]): void
|
|
94
|
+
}
|
|
95
|
+
var console: ExistingGlobal<'console', CreConsole>
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* TextEncoder/TextDecoder APIs available via Javy's text_encoding support
|
|
99
|
+
*/
|
|
100
|
+
interface CreTextEncoderEncodeIntoResult {
|
|
101
|
+
read: number
|
|
102
|
+
written: number
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
interface CreTextEncoder {
|
|
106
|
+
readonly encoding: string
|
|
107
|
+
encode(input?: string): Uint8Array
|
|
108
|
+
encodeInto(input: string, dest: Uint8Array): CreTextEncoderEncodeIntoResult
|
|
109
|
+
}
|
|
110
|
+
var TextEncoder: ExistingGlobal<
|
|
111
|
+
'TextEncoder',
|
|
112
|
+
{ prototype: CreTextEncoder; new (): CreTextEncoder }
|
|
113
|
+
>
|
|
114
|
+
|
|
115
|
+
interface CreTextDecoder {
|
|
116
|
+
readonly encoding: string
|
|
117
|
+
readonly fatal: boolean
|
|
118
|
+
readonly ignoreBOM: boolean
|
|
119
|
+
decode(input?: ArrayBuffer | ArrayBufferView, options?: { stream?: boolean }): string
|
|
120
|
+
}
|
|
121
|
+
var TextDecoder: ExistingGlobal<
|
|
122
|
+
'TextDecoder',
|
|
123
|
+
{
|
|
124
|
+
prototype: CreTextDecoder
|
|
125
|
+
new (label?: string, options?: { fatal?: boolean; ignoreBOM?: boolean }): CreTextDecoder
|
|
126
|
+
}
|
|
127
|
+
>
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* Buffer and Base64 APIs exposed via prepareRuntime() from node:buffer.
|
|
131
|
+
* Declared structurally so they work even when consumers opt out of @types/node.
|
|
132
|
+
*/
|
|
133
|
+
type CreBufferEncoding =
|
|
134
|
+
| 'ascii'
|
|
135
|
+
| 'base64'
|
|
136
|
+
| 'base64url'
|
|
137
|
+
| 'binary'
|
|
138
|
+
| 'hex'
|
|
139
|
+
| 'latin1'
|
|
140
|
+
| 'ucs-2'
|
|
141
|
+
| 'ucs2'
|
|
142
|
+
| 'utf-8'
|
|
143
|
+
| 'utf-16le'
|
|
144
|
+
| 'utf8'
|
|
145
|
+
| 'utf16le'
|
|
146
|
+
|
|
147
|
+
interface CreBuffer extends Uint8Array {
|
|
148
|
+
toString(encoding?: CreBufferEncoding, start?: number, end?: number): string
|
|
149
|
+
slice(start?: number, end?: number): CreBuffer
|
|
150
|
+
subarray(begin?: number, end?: number): CreBuffer
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
var Buffer: ExistingGlobal<
|
|
154
|
+
'Buffer',
|
|
155
|
+
{
|
|
156
|
+
prototype: CreBuffer
|
|
157
|
+
alloc(
|
|
158
|
+
size: number,
|
|
159
|
+
fill?: string | number | Uint8Array | ArrayBuffer | ArrayBufferView,
|
|
160
|
+
encoding?: CreBufferEncoding,
|
|
161
|
+
): CreBuffer
|
|
162
|
+
byteLength(
|
|
163
|
+
value: string | Uint8Array | ArrayBuffer | ArrayBufferView,
|
|
164
|
+
encoding?: CreBufferEncoding,
|
|
165
|
+
): number
|
|
166
|
+
concat(list: readonly Uint8Array[], totalLength?: number): CreBuffer
|
|
167
|
+
from(value: string, encoding?: CreBufferEncoding): CreBuffer
|
|
168
|
+
from(value: Uint8Array | ArrayBuffer | ArrayBufferView | ArrayLike<number>): CreBuffer
|
|
169
|
+
isBuffer(value: unknown): value is CreBuffer
|
|
170
|
+
}
|
|
171
|
+
>
|
|
172
|
+
|
|
173
|
+
function atob(encodedData: string): string
|
|
174
|
+
function btoa(stringToEncode: string): string
|
|
175
|
+
|
|
176
|
+
/**
|
|
177
|
+
* URL and URLSearchParams — exposed via prepareRuntime() from node:url
|
|
178
|
+
*/
|
|
179
|
+
interface CreURLSearchParams {
|
|
180
|
+
append(name: string, value: string): void
|
|
181
|
+
delete(name: string): void
|
|
182
|
+
get(name: string): string | null
|
|
183
|
+
getAll(name: string): string[]
|
|
184
|
+
has(name: string): boolean
|
|
185
|
+
set(name: string, value: string): void
|
|
186
|
+
sort(): void
|
|
187
|
+
toString(): string
|
|
188
|
+
forEach(callback: (value: string, key: string, parent: CreURLSearchParams) => void): void
|
|
189
|
+
entries(): IterableIterator<[string, string]>
|
|
190
|
+
keys(): IterableIterator<string>
|
|
191
|
+
values(): IterableIterator<string>
|
|
192
|
+
[Symbol.iterator](): IterableIterator<[string, string]>
|
|
193
|
+
readonly size: number
|
|
194
|
+
}
|
|
195
|
+
var URLSearchParams: ExistingGlobal<
|
|
196
|
+
'URLSearchParams',
|
|
197
|
+
{
|
|
198
|
+
prototype: CreURLSearchParams
|
|
199
|
+
new (
|
|
200
|
+
init?: string | Record<string, string> | [string, string][] | CreURLSearchParams,
|
|
201
|
+
): CreURLSearchParams
|
|
202
|
+
}
|
|
203
|
+
>
|
|
204
|
+
|
|
205
|
+
interface CreURL {
|
|
206
|
+
hash: string
|
|
207
|
+
host: string
|
|
208
|
+
hostname: string
|
|
209
|
+
href: string
|
|
210
|
+
readonly origin: string
|
|
211
|
+
password: string
|
|
212
|
+
pathname: string
|
|
213
|
+
port: string
|
|
214
|
+
protocol: string
|
|
215
|
+
search: string
|
|
216
|
+
readonly searchParams: CreURLSearchParams
|
|
217
|
+
username: string
|
|
218
|
+
toString(): string
|
|
219
|
+
toJSON(): string
|
|
220
|
+
}
|
|
221
|
+
var URL: ExistingGlobal<
|
|
222
|
+
'URL',
|
|
223
|
+
{ prototype: CreURL; new (url: string, base?: string | CreURL): CreURL }
|
|
224
|
+
>
|
|
81
225
|
}
|
|
82
226
|
|
|
83
227
|
export {}
|
|
@@ -1,27 +1,22 @@
|
|
|
1
1
|
declare global {
|
|
2
|
-
/**
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
/** @deprecated setTimeout is not available in CRE WASM workflows. Use cre.capabilities.CronCapability for scheduling. */
|
|
21
|
-
const setTimeout: never
|
|
22
|
-
|
|
23
|
-
/** @deprecated setInterval is not available in CRE WASM workflows. Use cre.capabilities.CronCapability for scheduling. */
|
|
24
|
-
const setInterval: never
|
|
2
|
+
/**
|
|
3
|
+
* @deprecated fetch is not available in CRE WASM workflows.
|
|
4
|
+
* Use cre.capabilities.HTTPClient instead.
|
|
5
|
+
* @see https://docs.chain.link/cre/concepts/typescript-wasm-runtime
|
|
6
|
+
*/
|
|
7
|
+
function fetch(_notAvailable: never): never
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* @deprecated setTimeout is not available in CRE WASM workflows. Use cre.capabilities.CronCapability for scheduling.
|
|
11
|
+
* @see https://docs.chain.link/cre/concepts/typescript-wasm-runtime
|
|
12
|
+
*/
|
|
13
|
+
function setTimeout(_notAvailable: never, ..._args: never[]): never
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* @deprecated setInterval is not available in CRE WASM workflows. Use cre.capabilities.CronCapability for scheduling.
|
|
17
|
+
* @see https://docs.chain.link/cre/concepts/typescript-wasm-runtime
|
|
18
|
+
*/
|
|
19
|
+
function setInterval(_notAvailable: never, ..._args: never[]): never
|
|
25
20
|
}
|
|
26
21
|
|
|
27
22
|
export {}
|