@chainlink/cre-sdk 1.1.3-alpha.1 → 1.1.3
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 +1 -12
- package/dist/index.d.ts +0 -3
- package/dist/sdk/types/global.d.ts +2 -105
- package/dist/sdk/types/restricted-apis.d.ts +23 -18
- package/dist/sdk/utils/prepare-runtime.d.ts +1 -1
- package/dist/sdk/utils/prepare-runtime.js +2 -9
- package/package.json +1 -1
- package/scripts/run.ts +1 -5
- package/scripts/src/build-types.ts +1 -31
- package/scripts/src/compile-to-js.ts +0 -2
- package/dist/sdk/types/restricted-node-modules.d.ts +0 -405
- package/scripts/src/validate-workflow-runtime-compat.test.ts +0 -412
- package/scripts/src/validate-workflow-runtime-compat.ts +0 -573
package/README.md
CHANGED
|
@@ -8,7 +8,6 @@ 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)
|
|
12
11
|
- [Core Concepts](#core-concepts)
|
|
13
12
|
- [Workflows](#workflows)
|
|
14
13
|
- [Runtime Modes](#runtime-modes)
|
|
@@ -48,20 +47,10 @@ This package must be used along with the [CRE CLI tool](https://github.com/smart
|
|
|
48
47
|
|
|
49
48
|
## Prerequisites
|
|
50
49
|
|
|
51
|
-
1. the [bun runtime](https://bun.com/)
|
|
50
|
+
1. the [bun runtime](https://bun.com/). The wasm compilation currently is only supported by the bun runtime which has near-complete NodeJS compatibility.
|
|
52
51
|
|
|
53
52
|
2. the [CRE CLI tool](https://github.com/smartcontractkit/cre-cli) installed.
|
|
54
53
|
|
|
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
|
-
|
|
65
54
|
## Getting Started
|
|
66
55
|
|
|
67
56
|
We recommend you consult the [getting started docs](https://docs.chain.link/cre/getting-started/cli-installation) and install the CRE CLI.
|
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
// Global type declarations for the CRE SDK runtime
|
|
2
|
-
//
|
|
3
|
-
|
|
4
|
-
type ExistingGlobal<K extends PropertyKey, Fallback> =
|
|
5
|
-
typeof globalThis extends Record<K, infer T> ? T : Fallback
|
|
1
|
+
// Global type declarations for the CRE SDK runtime
|
|
2
|
+
// Those are the methods that the Host exposes to the Guest.
|
|
6
3
|
|
|
7
4
|
/**
|
|
8
5
|
* Host functions exposed by the CRE runtime to WASM guests
|
|
@@ -81,106 +78,6 @@ declare global {
|
|
|
81
78
|
* @returns Unix timestamp in milliseconds
|
|
82
79
|
*/
|
|
83
80
|
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
|
-
* Base64 encoding/decoding — exposed via prepareRuntime() from node:buffer
|
|
131
|
-
*/
|
|
132
|
-
function atob(encodedData: string): string
|
|
133
|
-
function btoa(stringToEncode: string): string
|
|
134
|
-
|
|
135
|
-
/**
|
|
136
|
-
* URL and URLSearchParams — exposed via prepareRuntime() from node:url
|
|
137
|
-
*/
|
|
138
|
-
interface CreURLSearchParams {
|
|
139
|
-
append(name: string, value: string): void
|
|
140
|
-
delete(name: string): void
|
|
141
|
-
get(name: string): string | null
|
|
142
|
-
getAll(name: string): string[]
|
|
143
|
-
has(name: string): boolean
|
|
144
|
-
set(name: string, value: string): void
|
|
145
|
-
sort(): void
|
|
146
|
-
toString(): string
|
|
147
|
-
forEach(callback: (value: string, key: string, parent: CreURLSearchParams) => void): void
|
|
148
|
-
entries(): IterableIterator<[string, string]>
|
|
149
|
-
keys(): IterableIterator<string>
|
|
150
|
-
values(): IterableIterator<string>
|
|
151
|
-
[Symbol.iterator](): IterableIterator<[string, string]>
|
|
152
|
-
readonly size: number
|
|
153
|
-
}
|
|
154
|
-
var URLSearchParams: ExistingGlobal<
|
|
155
|
-
'URLSearchParams',
|
|
156
|
-
{
|
|
157
|
-
prototype: CreURLSearchParams
|
|
158
|
-
new (
|
|
159
|
-
init?: string | Record<string, string> | [string, string][] | CreURLSearchParams,
|
|
160
|
-
): CreURLSearchParams
|
|
161
|
-
}
|
|
162
|
-
>
|
|
163
|
-
|
|
164
|
-
interface CreURL {
|
|
165
|
-
hash: string
|
|
166
|
-
host: string
|
|
167
|
-
hostname: string
|
|
168
|
-
href: string
|
|
169
|
-
readonly origin: string
|
|
170
|
-
password: string
|
|
171
|
-
pathname: string
|
|
172
|
-
port: string
|
|
173
|
-
protocol: string
|
|
174
|
-
search: string
|
|
175
|
-
readonly searchParams: CreURLSearchParams
|
|
176
|
-
username: string
|
|
177
|
-
toString(): string
|
|
178
|
-
toJSON(): string
|
|
179
|
-
}
|
|
180
|
-
var URL: ExistingGlobal<
|
|
181
|
-
'URL',
|
|
182
|
-
{ prototype: CreURL; new (url: string, base?: string | CreURL): CreURL }
|
|
183
|
-
>
|
|
184
81
|
}
|
|
185
82
|
|
|
186
83
|
export {}
|
|
@@ -1,22 +1,27 @@
|
|
|
1
1
|
declare global {
|
|
2
|
-
/**
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
2
|
+
/** @deprecated fetch is not available in CRE WASM workflows. Use cre.capabilities.HTTPClient instead. */
|
|
3
|
+
const fetch: never
|
|
4
|
+
|
|
5
|
+
/** @deprecated window is not available in CRE WASM workflows. */
|
|
6
|
+
const window: never
|
|
7
|
+
|
|
8
|
+
/** @deprecated document is not available in CRE WASM workflows. */
|
|
9
|
+
const document: never
|
|
10
|
+
|
|
11
|
+
/** @deprecated XMLHttpRequest is not available in CRE WASM workflows. Use cre.capabilities.HTTPClient instead. */
|
|
12
|
+
const XMLHttpRequest: never
|
|
13
|
+
|
|
14
|
+
/** @deprecated localStorage is not available in CRE WASM workflows. */
|
|
15
|
+
const localStorage: never
|
|
16
|
+
|
|
17
|
+
/** @deprecated sessionStorage is not available in CRE WASM workflows. */
|
|
18
|
+
const sessionStorage: never
|
|
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
|
|
20
25
|
}
|
|
21
26
|
|
|
22
27
|
export {}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* This function is used to prepare the runtime for the SDK to work.
|
|
3
3
|
* It should be called as a part of SDK initialization.
|
|
4
|
-
* It exposes
|
|
4
|
+
* It exposes NodeJS Buffer in global namespace, so it can be bundled and used in workflow code.
|
|
5
5
|
*/
|
|
6
6
|
export declare const prepareRuntime: () => void;
|
|
@@ -1,16 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { URL, URLSearchParams } from 'node:url';
|
|
1
|
+
import { Buffer } from 'node:buffer';
|
|
3
2
|
/**
|
|
4
3
|
* This function is used to prepare the runtime for the SDK to work.
|
|
5
4
|
* It should be called as a part of SDK initialization.
|
|
6
|
-
* It exposes
|
|
5
|
+
* It exposes NodeJS Buffer in global namespace, so it can be bundled and used in workflow code.
|
|
7
6
|
*/
|
|
8
7
|
export const prepareRuntime = () => {
|
|
9
8
|
globalThis.Buffer = Buffer;
|
|
10
|
-
globalThis.atob = atob;
|
|
11
|
-
globalThis.btoa = btoa;
|
|
12
|
-
// node:url constructor types are slightly narrower than lib.dom/global types.
|
|
13
|
-
// Runtime behavior is compatible; cast to the global constructor shapes.
|
|
14
|
-
globalThis.URL = URL;
|
|
15
|
-
globalThis.URLSearchParams = URLSearchParams;
|
|
16
9
|
};
|
package/package.json
CHANGED
package/scripts/run.ts
CHANGED
|
@@ -37,11 +37,7 @@ const main = async () => {
|
|
|
37
37
|
process.exit(1)
|
|
38
38
|
}
|
|
39
39
|
} catch (error) {
|
|
40
|
-
|
|
41
|
-
console.error(error.message)
|
|
42
|
-
} else {
|
|
43
|
-
console.error(`Failed to run script ${scriptName}:`, error)
|
|
44
|
-
}
|
|
40
|
+
console.error(`Failed to load script ${scriptName}:`, error)
|
|
45
41
|
process.exit(1)
|
|
46
42
|
}
|
|
47
43
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { glob } from 'fast-glob'
|
|
2
|
-
import { copyFile, mkdir
|
|
2
|
+
import { copyFile, mkdir } from 'fs/promises'
|
|
3
3
|
import { join } from 'path'
|
|
4
4
|
|
|
5
5
|
const buildTypes = async () => {
|
|
@@ -28,36 +28,6 @@ const buildTypes = async () => {
|
|
|
28
28
|
}
|
|
29
29
|
|
|
30
30
|
console.log(`✅ Copied ${typeFiles.length} type definition file(s) to dist/sdk/types`)
|
|
31
|
-
|
|
32
|
-
// Prepend triple-slash references to dist/index.d.ts so consumers pick up
|
|
33
|
-
// global type augmentations (e.g. restricted-apis.d.ts) automatically.
|
|
34
|
-
// tsc strips these from the emitted .d.ts, so we add them back here.
|
|
35
|
-
const indexDts = join(packageRoot, 'dist/index.d.ts')
|
|
36
|
-
const sourceIndex = join(packageRoot, 'src/index.ts')
|
|
37
|
-
const sourceContent = await readFile(sourceIndex, 'utf-8')
|
|
38
|
-
|
|
39
|
-
const refsFromSource = sourceContent
|
|
40
|
-
.split('\n')
|
|
41
|
-
.filter((line) => line.startsWith('/// <reference types='))
|
|
42
|
-
|
|
43
|
-
// Add references for consumer-only type declarations that cannot be in src/index.ts
|
|
44
|
-
// because they would break the SDK's own scripts/tests (which legitimately use Node.js APIs).
|
|
45
|
-
const consumerOnlyRefs = ['/// <reference types="./sdk/types/restricted-node-modules" />']
|
|
46
|
-
|
|
47
|
-
const tripleSlashRefs = [...refsFromSource, ...consumerOnlyRefs].join('\n')
|
|
48
|
-
|
|
49
|
-
if (tripleSlashRefs) {
|
|
50
|
-
const indexContent = await readFile(indexDts, 'utf-8')
|
|
51
|
-
// Strip any existing triple-slash references from the top of the file
|
|
52
|
-
// so that re-running build-types is idempotent.
|
|
53
|
-
const withoutExistingRefs = indexContent
|
|
54
|
-
.split('\n')
|
|
55
|
-
.filter((line) => !line.startsWith('/// <reference types='))
|
|
56
|
-
.join('\n')
|
|
57
|
-
.replace(/^\n+/, '') // trim leading blank lines left after stripping
|
|
58
|
-
await writeFile(indexDts, `${tripleSlashRefs}\n${withoutExistingRefs}`)
|
|
59
|
-
console.log('✅ Added triple-slash references to dist/index.d.ts')
|
|
60
|
-
}
|
|
61
31
|
}
|
|
62
32
|
|
|
63
33
|
export const main = buildTypes
|
|
@@ -2,7 +2,6 @@ import { existsSync, readFileSync, unlinkSync, writeFileSync } from 'node:fs'
|
|
|
2
2
|
import { mkdir } from 'node:fs/promises'
|
|
3
3
|
import path from 'node:path'
|
|
4
4
|
import { $ } from 'bun'
|
|
5
|
-
import { assertWorkflowRuntimeCompatibility } from './validate-workflow-runtime-compat'
|
|
6
5
|
import { wrapWorkflowCode } from './workflow-wrapper'
|
|
7
6
|
|
|
8
7
|
export const main = async (tsFilePath?: string, outputFilePath?: string) => {
|
|
@@ -20,7 +19,6 @@ export const main = async (tsFilePath?: string, outputFilePath?: string) => {
|
|
|
20
19
|
}
|
|
21
20
|
|
|
22
21
|
const resolvedInput = path.resolve(inputPath)
|
|
23
|
-
assertWorkflowRuntimeCompatibility(resolvedInput)
|
|
24
22
|
console.info(`📁 Using input file: ${resolvedInput}`)
|
|
25
23
|
|
|
26
24
|
// If no explicit output path → same dir, swap extension to .js
|