@chainlink/cre-sdk 0.0.3-alpha → 0.0.4-alpha

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.
Files changed (41) hide show
  1. package/README.md +78 -59
  2. package/dist/generated-sdk/capabilities/blockchain/evm/v1alpha/client_sdk_gen.d.ts +18 -3
  3. package/dist/generated-sdk/capabilities/blockchain/evm/v1alpha/client_sdk_gen.js +148 -41
  4. package/dist/generated-sdk/capabilities/internal/consensus/v1alpha/consensus_sdk_gen.d.ts +4 -3
  5. package/dist/generated-sdk/capabilities/internal/consensus/v1alpha/consensus_sdk_gen.js +26 -8
  6. package/dist/generated-sdk/capabilities/networking/http/v1alpha/client_sdk_gen.d.ts +1 -1
  7. package/dist/generated-sdk/capabilities/networking/http/v1alpha/client_sdk_gen.js +14 -4
  8. package/dist/generated-sdk/capabilities/networking/http/v1alpha/http_sdk_gen.js +2 -0
  9. package/dist/generated-sdk/capabilities/scheduler/cron/v1/cron_sdk_gen.js +2 -0
  10. package/dist/index.d.ts +1 -0
  11. package/dist/index.js +2 -0
  12. package/dist/sdk/impl/runtime-impl.d.ts +5 -1
  13. package/dist/sdk/impl/runtime-impl.js +13 -2
  14. package/dist/sdk/index.d.ts +1 -0
  15. package/dist/sdk/index.js +1 -0
  16. package/dist/sdk/report.d.ts +6 -0
  17. package/dist/sdk/report.js +14 -0
  18. package/dist/sdk/runtime.d.ts +6 -0
  19. package/dist/sdk/utils/capabilities/blockchain/blockchain-helpers.d.ts +50 -0
  20. package/dist/sdk/utils/capabilities/blockchain/blockchain-helpers.js +48 -0
  21. package/dist/sdk/utils/capabilities/http/http-helpers.d.ts +112 -0
  22. package/dist/sdk/utils/capabilities/http/http-helpers.js +44 -0
  23. package/dist/sdk/utils/index.d.ts +2 -0
  24. package/dist/sdk/utils/index.js +2 -0
  25. package/dist/workflows/standard_tests/Makefile +19 -0
  26. package/dist/workflows/standard_tests/capability_calls_are_async/test.ts +39 -0
  27. package/dist/workflows/standard_tests/config/test.ts +23 -0
  28. package/dist/workflows/standard_tests/errors/test.ts +24 -0
  29. package/dist/workflows/standard_tests/logging/test.ts +25 -0
  30. package/dist/workflows/standard_tests/mode_switch/don_runtime_in_node_mode/test.ts +33 -0
  31. package/dist/workflows/standard_tests/mode_switch/node_runtime_in_don_mode/test.ts +41 -0
  32. package/dist/workflows/standard_tests/mode_switch/successful_mode_switch/test.ts +58 -0
  33. package/dist/workflows/standard_tests/multiple_triggers/test.ts +40 -0
  34. package/dist/workflows/standard_tests/random/test.ts +64 -0
  35. package/dist/workflows/standard_tests/secrets/test.ts +30 -0
  36. package/dist/workflows/standard_tests/secrets_fail_in_node_mode/test.ts +29 -0
  37. package/package.json +70 -69
  38. package/scripts/run-standard-tests.sh +0 -3
  39. package/scripts/src/cre-setup.ts +9 -0
  40. package/dist/sdk/utils/safeJsonStringify.d.ts +0 -6
  41. package/dist/sdk/utils/safeJsonStringify.js +0 -6
@@ -0,0 +1,41 @@
1
+ import { BasicCapability as BasicTriggerCapability } from '@cre/generated-sdk/capabilities/internal/basictrigger/v1/basic_sdk_gen'
2
+ import { BasicActionCapability as NodeActionCapability } from '@cre/generated-sdk/capabilities/internal/nodeaction/v1/basicaction_sdk_gen'
3
+ import { cre, type NodeRuntime, type Runtime } from '@cre/sdk/cre'
4
+ import { consensusIdenticalAggregation } from '@cre/sdk/utils'
5
+ import { Runner } from '@cre/sdk/wasm'
6
+
7
+ const handler = (runtime: Runtime<Uint8Array>) => {
8
+ // First, run in node mode and do consensus - this makes the expected CallCapability call
9
+ var nrt: NodeRuntime<Uint8Array> | undefined
10
+ runtime
11
+ .runInNodeMode((nodeRuntime: NodeRuntime<Uint8Array>) => {
12
+ nrt = nodeRuntime
13
+ return 'hi'
14
+ }, consensusIdenticalAggregation())()
15
+ .result()
16
+
17
+ // Now we're back in DON mode, try to use a NODE mode capability
18
+ // This should trigger assertNodeSafe() and throw "cannot use NodeRuntime outside RunInNodeMode"
19
+ const nodeActionCapability = new NodeActionCapability()
20
+ nodeActionCapability.performAction(nrt as NodeRuntime<Uint8Array>, { inputThing: true }).result()
21
+ return 'hi'
22
+ }
23
+
24
+ const initWorkflow = () => {
25
+ const basicTrigger = new BasicTriggerCapability()
26
+
27
+ return [cre.handler(basicTrigger.trigger({}), handler)]
28
+ }
29
+
30
+ export async function main() {
31
+ console.log(
32
+ `TS workflow: standard test: mode_switch: node_runtime_in_don_mode [${new Date().toISOString()}]`,
33
+ )
34
+
35
+ const runner = await Runner.newRunner<Uint8Array>({
36
+ configParser: (c) => c,
37
+ })
38
+ await runner.run(initWorkflow)
39
+ }
40
+
41
+ await main()
@@ -0,0 +1,58 @@
1
+ import { BasicActionCapability } from '@cre/generated-sdk/capabilities/internal/basicaction/v1/basicaction_sdk_gen'
2
+ import { BasicCapability as BasicTriggerCapability } from '@cre/generated-sdk/capabilities/internal/basictrigger/v1/basic_sdk_gen'
3
+ import { BasicActionCapability as NodeActionCapability } from '@cre/generated-sdk/capabilities/internal/nodeaction/v1/basicaction_sdk_gen'
4
+ import { cre, type Runtime } from '@cre/sdk/cre'
5
+ import type { NodeRuntime } from '@cre/sdk/runtime'
6
+ import { ConsensusAggregationByFields, Int64, median } from '@cre/sdk/utils'
7
+ import { Runner } from '@cre/sdk/wasm'
8
+
9
+ class Output {
10
+ constructor(public OutputThing: Int64) {}
11
+ }
12
+
13
+ const handler = (runtime: Runtime<Uint8Array>) => {
14
+ const donInput = { inputThing: true }
15
+ const basicActionCapability = new BasicActionCapability()
16
+ const donResponse = basicActionCapability.performAction(runtime, donInput).result()
17
+ runtime.now()
18
+
19
+ const consensusOutput = runtime.runInNodeMode(
20
+ (nodeRuntime: NodeRuntime<Uint8Array>): Output => {
21
+ nodeRuntime.now()
22
+ const nodeActionCapability = new NodeActionCapability()
23
+ const nodeResponse = nodeActionCapability
24
+ .performAction(nodeRuntime, {
25
+ inputThing: true,
26
+ })
27
+ .result()
28
+
29
+ return new Output(new Int64(nodeResponse.outputThing))
30
+ },
31
+ ConsensusAggregationByFields<Output>({ OutputThing: median }).withDefault(
32
+ new Output(new Int64(123)),
33
+ ),
34
+ )()
35
+
36
+ runtime.now()
37
+
38
+ return `${donResponse.adaptedThing}${consensusOutput.result().OutputThing.value}`
39
+ }
40
+
41
+ const initWorkflow = () => {
42
+ const basicTrigger = new BasicTriggerCapability()
43
+
44
+ return [cre.handler(basicTrigger.trigger({}), handler)]
45
+ }
46
+
47
+ export async function main() {
48
+ console.log(
49
+ `TS workflow: standard test: mode_switch: successful_mode_switch [${new Date().toISOString()}]`,
50
+ )
51
+
52
+ const runner = await Runner.newRunner<Uint8Array>({
53
+ configParser: (c) => c,
54
+ })
55
+ runner.run(initWorkflow)
56
+ }
57
+
58
+ await main()
@@ -0,0 +1,40 @@
1
+ import type { TriggerEvent } from '@cre/generated/capabilities/internal/actionandtrigger/v1/action_and_trigger_pb'
2
+ import type { Outputs } from '@cre/generated/capabilities/internal/basictrigger/v1/basic_trigger_pb'
3
+ import { BasicCapability as ActionAndTriggerCapability } from '@cre/generated-sdk/capabilities/internal/actionandtrigger/v1/basic_sdk_gen'
4
+ import { BasicCapability as BasicTriggerCapability } from '@cre/generated-sdk/capabilities/internal/basictrigger/v1/basic_sdk_gen'
5
+ import { cre, type Runtime } from '@cre/sdk/cre'
6
+ import { Runner } from '@cre/sdk/wasm'
7
+
8
+ const doLog0 = (_: Runtime<Uint8Array>, output: Outputs) => {
9
+ return `called 0 with ${output.coolOutput}`
10
+ }
11
+
12
+ const doLog1 = (_runtime: Runtime<Uint8Array>, output: TriggerEvent) => {
13
+ return `called 1 with ${output.coolOutput}`
14
+ }
15
+
16
+ const doLog2 = (_runtime: Runtime<Uint8Array>, output: Outputs) => {
17
+ return `called 2 with ${output.coolOutput}`
18
+ }
19
+
20
+ const initWorkflow = () => {
21
+ const basicTrigger = new BasicTriggerCapability()
22
+ const actionTrigger = new ActionAndTriggerCapability()
23
+
24
+ return [
25
+ cre.handler(basicTrigger.trigger({ name: 'first-trigger', number: 100 }), doLog0),
26
+ cre.handler(actionTrigger.trigger({ name: 'second-trigger', number: 150 }), doLog1),
27
+ cre.handler(basicTrigger.trigger({ name: 'third-trigger', number: 200 }), doLog2),
28
+ ]
29
+ }
30
+
31
+ export async function main() {
32
+ console.log(`TS workflow: standard test: multiple_triggers [${new Date().toISOString()}]`)
33
+
34
+ const runner = await Runner.newRunner<Uint8Array>({
35
+ configParser: (c) => c,
36
+ })
37
+ await runner.run(initWorkflow)
38
+ }
39
+
40
+ await main()
@@ -0,0 +1,64 @@
1
+ import { BasicCapability as BasicTriggerCapability } from '@cre/generated-sdk/capabilities/internal/basictrigger/v1/basic_sdk_gen'
2
+ import { BasicActionCapability as NodeActionCapability } from '@cre/generated-sdk/capabilities/internal/nodeaction/v1/basicaction_sdk_gen'
3
+ import { cre, type NodeRuntime, type Runtime } from '@cre/sdk/cre'
4
+ import { ConsensusAggregationByFields, Int64, median } from '@cre/sdk/utils'
5
+ import { Runner } from '@cre/sdk/wasm'
6
+
7
+ class Output {
8
+ constructor(public OutputThing: Int64) {}
9
+ }
10
+
11
+ const castRandomToUint64 = (randomFloat: number) =>
12
+ BigInt(Math.floor(randomFloat * Number.MAX_SAFE_INTEGER))
13
+
14
+ const randHandler = (runtime: Runtime<Uint8Array>) => {
15
+ const donRandomNumber = castRandomToUint64(Math.random())
16
+
17
+ let total = donRandomNumber
18
+
19
+ runtime
20
+ .runInNodeMode(
21
+ (nodeRuntime: NodeRuntime<Uint8Array>) => {
22
+ const nodeRandomNumber = castRandomToUint64(Math.random())
23
+
24
+ const nodeActionCapability = new NodeActionCapability()
25
+ const nodeResponse = nodeActionCapability
26
+ .performAction(nodeRuntime, {
27
+ inputThing: true,
28
+ })
29
+ .result()
30
+
31
+ if (nodeResponse.outputThing < 100n) {
32
+ runtime.log(`***${nodeRandomNumber.toString()}`)
33
+ }
34
+
35
+ return new Output(new Int64(nodeResponse.outputThing))
36
+ },
37
+ ConsensusAggregationByFields<Output>({
38
+ OutputThing: median,
39
+ }).withDefault(new Output(new Int64(123n))),
40
+ )()
41
+ .result()
42
+
43
+ total += donRandomNumber
44
+
45
+ return total
46
+ }
47
+
48
+ const initWorkflow = () => {
49
+ const basicTrigger = new BasicTriggerCapability()
50
+
51
+ return [cre.handler(basicTrigger.trigger({}), randHandler)]
52
+ }
53
+
54
+ export async function main() {
55
+ console.log(`TS workflow: standard test: random [${new Date().toISOString()}]`)
56
+
57
+ const runner = await Runner.newRunner<Uint8Array>({
58
+ configParser: (c) => c,
59
+ })
60
+
61
+ await runner.run(initWorkflow)
62
+ }
63
+
64
+ await main()
@@ -0,0 +1,30 @@
1
+ import { toJson } from '@bufbuild/protobuf'
2
+ import type { Outputs } from '@cre/generated/capabilities/internal/basictrigger/v1/basic_trigger_pb'
3
+ import { SecretSchema } from '@cre/generated/sdk/v1alpha/sdk_pb'
4
+ import { BasicCapability as BasicTriggerCapability } from '@cre/generated-sdk/capabilities/internal/basictrigger/v1/basic_sdk_gen'
5
+ import { cre, type Runtime } from '@cre/sdk/cre'
6
+ import { Runner } from '@cre/sdk/wasm'
7
+
8
+ const handleSecret = async (runtime: Runtime<Uint8Array>, _: Outputs) => {
9
+ const secret = runtime.getSecret({ id: 'Foo' }).result()
10
+ const secretJson = toJson(SecretSchema, secret)
11
+
12
+ return secretJson.value || ''
13
+ }
14
+
15
+ const initWorkflow = () => {
16
+ const basicTrigger = new BasicTriggerCapability()
17
+
18
+ return [cre.handler(basicTrigger.trigger({}), handleSecret)]
19
+ }
20
+
21
+ export async function main() {
22
+ console.log(`TS workflow: standard test: secrets [${new Date().toISOString()}]`)
23
+
24
+ const runner = await Runner.newRunner<Uint8Array>({
25
+ configParser: (c) => c,
26
+ })
27
+ await runner.run(initWorkflow)
28
+ }
29
+
30
+ await main()
@@ -0,0 +1,29 @@
1
+ import { BasicCapability as BasicTriggerCapability } from '@cre/generated-sdk/capabilities/internal/basictrigger/v1/basic_sdk_gen'
2
+ import { cre, type NodeRuntime, type Runtime } from '@cre/sdk/cre'
3
+ import { consensusIdenticalAggregation } from '@cre/sdk/utils'
4
+ import { Runner } from '@cre/sdk/wasm'
5
+
6
+ const secretAccessInNodeMode = (runtime: Runtime<Uint8Array>) => {
7
+ return runtime
8
+ .runInNodeMode((_nodeRuntime: NodeRuntime<Uint8Array>) => {
9
+ return runtime.getSecret({ id: 'anything' }).result()
10
+ }, consensusIdenticalAggregation())()
11
+ .result()
12
+ }
13
+
14
+ const initWorkflow = () => {
15
+ const basicTrigger = new BasicTriggerCapability()
16
+
17
+ return [cre.handler(basicTrigger.trigger({}), secretAccessInNodeMode)]
18
+ }
19
+
20
+ export async function main() {
21
+ console.log(`TS workflow: standard test: secrets_fail_in_node_mode [${new Date().toISOString()}]`)
22
+
23
+ const runner = await Runner.newRunner<Uint8Array>({
24
+ configParser: (c) => c,
25
+ })
26
+ await runner.run(initWorkflow)
27
+ }
28
+
29
+ await main()
package/package.json CHANGED
@@ -1,71 +1,72 @@
1
1
  {
2
- "name": "@chainlink/cre-sdk",
3
- "version": "0.0.3-alpha",
4
- "type": "module",
5
- "main": "dist/index.js",
6
- "types": "dist/index.d.ts",
7
- "exports": {
8
- ".": {
9
- "types": "./dist/index.d.ts",
10
- "import": "./dist/index.js"
11
- }
12
- },
13
- "bin": {
14
- "cre-compile": "bin/cre-compile.ts"
15
- },
16
- "files": [
17
- "bin/",
18
- "scripts/",
19
- "dist/",
20
- "package.json",
21
- "README.md",
22
- "LICENSE.md"
23
- ],
24
- "scripts": {
25
- "build": "bun run clean && bun run compile:build && bun run fix-imports",
26
- "check": "biome check --write ${BIOME_PATHS:-.}",
27
- "clean": "rm -rf dist",
28
- "compile:all-standard-tests": "bun scripts/run.ts compile-all-standard-tests",
29
- "compile:build": "tsc -p tsconfig.build.json",
30
- "compile:js-to-wasm": "bun scripts/run.ts compile-to-wasm",
31
- "compile:ts-to-js": "bun scripts/run.ts compile-to-js",
32
- "compile:workflow": "bun scripts/run.ts compile-workflow",
33
- "fix-imports": "bun scripts/run.ts fix-imports",
34
- "format": "biome format --write ${BIOME_PATHS:-.}",
35
- "full-checks": "bun generate:sdk && bun check && bun typecheck && bun lint && bun test && bun test:standard",
36
- "generate:chain-selectors": "bun scripts/run.ts generate-chain-selectors && BIOME_PATHS=\"src/generated\" bun check",
37
- "generate:proto": "bunx @bufbuild/buf generate && BIOME_PATHS=\"src/generated\" bun check",
38
- "generate:sdk": "bun generate:proto && bun generate:chain-selectors && bun scripts/run generate-sdks && BIOME_PATHS=\"src/generated src/generated-sdk\" bun check",
39
- "lint": "biome lint --write",
40
- "prepublishOnly": "bun typecheck && bun lint && bun test",
41
- "test": "bun test",
42
- "test:standard": "./scripts/run-standard-tests.sh",
43
- "typecheck": "tsc"
44
- },
45
- "dependencies": {
46
- "@bufbuild/protobuf": "2.6.3",
47
- "@bufbuild/protoc-gen-es": "2.6.3",
48
- "@chainlink/cre-sdk-javy-plugin": "0.0.3-alpha",
49
- "@standard-schema/spec": "1.0.0",
50
- "viem": "2.34.0",
51
- "zod": "3.25.76"
52
- },
53
- "devDependencies": {
54
- "@biomejs/biome": "2.2.4",
55
- "@bufbuild/buf": "1.56.0",
56
- "@types/bun": "1.2.21",
57
- "chain-selectors": "https://github.com/smartcontractkit/chain-selectors.git#8b963095ae797a3024c8e55822cced7bf618176f",
58
- "fast-glob": "3.3.3",
59
- "ts-proto": "2.7.5",
60
- "typescript": "5.9.2",
61
- "yaml": "2.8.1"
62
- },
63
- "publishConfig": {
64
- "access": "public"
65
- },
66
- "author": "SmartContract Chainlink Limited SEZC",
67
- "license": "BUSL-1.1",
68
- "engines": {
69
- "bun": ">=1.2.21"
70
- }
2
+ "name": "@chainlink/cre-sdk",
3
+ "version": "0.0.4-alpha",
4
+ "type": "module",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "exports": {
8
+ ".": {
9
+ "types": "./dist/index.d.ts",
10
+ "import": "./dist/index.js"
11
+ }
12
+ },
13
+ "bin": {
14
+ "cre-compile": "bin/cre-compile.ts"
15
+ },
16
+ "files": [
17
+ "bin/",
18
+ "scripts/",
19
+ "dist/",
20
+ "package.json",
21
+ "README.md",
22
+ "LICENSE.md"
23
+ ],
24
+ "scripts": {
25
+ "build": "bun run clean && bun run compile:build && bun run fix-imports",
26
+ "check": "biome check --write ${BIOME_PATHS:-.}",
27
+ "clean": "rm -rf dist",
28
+ "compile:all-standard-tests": "bun scripts/run.ts compile-all-standard-tests",
29
+ "compile:build": "tsc -p tsconfig.build.json",
30
+ "compile:cre-setup": "bun scripts/run.ts cre-setup",
31
+ "compile:js-to-wasm": "bun scripts/run.ts compile-to-wasm",
32
+ "compile:ts-to-js": "bun scripts/run.ts compile-to-js",
33
+ "compile:workflow": "bun scripts/run.ts compile-workflow",
34
+ "fix-imports": "bun scripts/run.ts fix-imports",
35
+ "format": "biome format --write ${BIOME_PATHS:-.}",
36
+ "full-checks": "bun generate:sdk && bun build && bun typecheck && bun lint && bun test && bun test:standard",
37
+ "generate:chain-selectors": "bun scripts/run.ts generate-chain-selectors && BIOME_PATHS=\"src/generated\" bun check",
38
+ "generate:proto": "bunx @bufbuild/buf generate && BIOME_PATHS=\"src/generated\" bun check",
39
+ "generate:sdk": "bun generate:proto && bun generate:chain-selectors && bun scripts/run generate-sdks && BIOME_PATHS=\"src/generated src/generated-sdk\" bun check",
40
+ "lint": "biome lint --write",
41
+ "prepublishOnly": "bun typecheck && bun lint && bun test && bun test:standard",
42
+ "test": "bun test",
43
+ "test:standard": "./scripts/run-standard-tests.sh",
44
+ "typecheck": "tsc"
45
+ },
46
+ "dependencies": {
47
+ "@bufbuild/protobuf": "2.6.3",
48
+ "@bufbuild/protoc-gen-es": "2.6.3",
49
+ "@chainlink/cre-sdk-javy-plugin": "0.0.4-alpha",
50
+ "@standard-schema/spec": "1.0.0",
51
+ "viem": "2.34.0",
52
+ "zod": "3.25.76"
53
+ },
54
+ "devDependencies": {
55
+ "@biomejs/biome": "2.2.4",
56
+ "@bufbuild/buf": "1.56.0",
57
+ "@types/bun": "1.2.21",
58
+ "chain-selectors": "https://github.com/smartcontractkit/chain-selectors.git#8b963095ae797a3024c8e55822cced7bf618176f",
59
+ "fast-glob": "3.3.3",
60
+ "ts-proto": "2.7.5",
61
+ "typescript": "5.9.2",
62
+ "yaml": "2.8.1"
63
+ },
64
+ "publishConfig": {
65
+ "access": "public"
66
+ },
67
+ "author": "SmartContract Chainlink Limited SEZC",
68
+ "license": "BUSL-1.1",
69
+ "engines": {
70
+ "bun": ">=1.2.21"
71
+ }
71
72
  }
@@ -5,9 +5,6 @@
5
5
 
6
6
  set -e
7
7
 
8
- # Set GOROOT to the correct location for Homebrew Go installation
9
- export GOROOT=/opt/homebrew/opt/go/libexec
10
-
11
8
  # Create dist test workflow folder
12
9
  mkdir -p ./dist/workflows/standard_tests
13
10
 
@@ -0,0 +1,9 @@
1
+ import { $ } from 'bun'
2
+
3
+ export const main = async () => {
4
+ try {
5
+ await $`bunx cre-setup`
6
+ } catch {
7
+ await $`bun --bun ../cre-sdk-javy-plugin/bin/setup.ts`
8
+ }
9
+ }
@@ -1,6 +0,0 @@
1
- /**
2
- * Supports stringifying an object with bigints, treating bigints as strings.
3
- * @param obj - The object to stringify
4
- * @returns The stringified object
5
- */
6
- export declare const safeJsonStringify: (obj: any) => string;
@@ -1,6 +0,0 @@
1
- /**
2
- * Supports stringifying an object with bigints, treating bigints as strings.
3
- * @param obj - The object to stringify
4
- * @returns The stringified object
5
- */
6
- export const safeJsonStringify = (obj) => JSON.stringify(obj, (_, value) => (typeof value === 'bigint' ? value.toString() : value), 2);