Skip to content

Commit ac8820b

Browse files
Extra TS checks
1 parent 643b48b commit ac8820b

File tree

24 files changed

+408
-30
lines changed

24 files changed

+408
-30
lines changed

bun.lock

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
},
1313
"packages/cre-sdk": {
1414
"name": "@chainlink/cre-sdk",
15-
"version": "0.0.4-alpha",
15+
"version": "0.0.5-alpha",
1616
"bin": {
1717
"cre-compile": "bin/cre-compile.ts",
1818
},
@@ -37,13 +37,16 @@
3737
},
3838
"packages/cre-sdk-examples": {
3939
"name": "@chainlink/cre-sdk-examples",
40-
"version": "0.0.4-alpha",
40+
"version": "0.0.5-alpha",
4141
"dependencies": {
4242
"@bufbuild/protobuf": "2.6.3",
4343
"@chainlink/cre-sdk": "workspace:*",
4444
"viem": "2.34.0",
4545
"zod": "3.25.76",
4646
},
47+
"devDependencies": {
48+
"@types/bun": "1.2.21",
49+
},
4750
},
4851
"packages/cre-sdk-javy-plugin": {
4952
"name": "@chainlink/cre-sdk-javy-plugin",

packages/cre-sdk-examples/README.md

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,31 +31,37 @@ The setup is done in a way that treats `cre-sdk-examples` root directory as a CR
3131
[Hello World workflow](https://github.com/smartcontractkit/cre-sdk-typescript/blob/main/packages/cre-sdk-examples/src/workflows/hello-world/index.ts):
3232

3333
```zsh
34-
cre workflow simulate ./src/workflows/hello-world --target local-simulation
34+
cre workflow simulate ./src/workflows/hello-world
3535
```
3636

3737
[Http Fetch workflow](https://github.com/smartcontractkit/cre-sdk-typescript/blob/main/packages/cre-sdk-examples/src/workflows/http-fetch/index.ts):
3838

3939
```zsh
40-
cre workflow simulate ./src/workflows/http-fetch --target local-simulation
40+
cre workflow simulate ./src/workflows/http-fetch
4141
```
4242

4343
[On Chain Read workflow](https://github.com/smartcontractkit/cre-sdk-typescript/blob/main/packages/cre-sdk-examples/src/workflows/on-chain/index.ts):
4444

4545
```zsh
46-
cre workflow simulate ./src/workflows/on-chain --target local-simulation
46+
cre workflow simulate ./src/workflows/on-chain
4747
```
4848

4949
[On Chain Write workflow](https://github.com/smartcontractkit/cre-sdk-typescript/blob/main/packages/cre-sdk-examples/src/workflows/on-chain-write/index.ts):
5050

5151
```zsh
52-
cre workflow simulate ./src/workflows/on-chain-write --target local-simulation --broadcast
52+
cre workflow simulate ./src/workflows/on-chain-write
5353
```
5454

5555
[Proof of Reserve workflow](https://github.com/smartcontractkit/cre-sdk-typescript/blob/main/packages/cre-sdk-examples/src/workflows/proof-of-reserve/index.ts):
5656

5757
```zsh
58-
cre workflow simulate ./src/workflows/proof-of-reserve --target local-simulation --broadcast --secrets ../../../secrets.yaml
58+
cre workflow simulate ./src/workflows/proof-of-reserve
59+
```
60+
61+
[Star Wars character example](https://github.com/smartcontractkit/cre-sdk-typescript/blob/main/packages/cre-sdk-examples/src/workflows/star-wars/index.ts):
62+
63+
```zsh
64+
cre workflow simulate ./src/workflows/star-wars
5965
```
6066

6167
## Testing workflow compilation only

packages/cre-sdk-examples/package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@chainlink/cre-sdk-examples",
33
"private": true,
4-
"version": "0.0.5-alpha",
4+
"version": "0.0.6-alpha",
55
"type": "module",
66
"author": "Ernest Nowacki",
77
"license": "BUSL-1.1",
@@ -19,6 +19,9 @@
1919
"viem": "2.34.0",
2020
"zod": "3.25.76"
2121
},
22+
"devDependencies": {
23+
"@types/bun": "1.2.21"
24+
},
2225
"engines": {
2326
"bun": ">=1.2.21"
2427
}

packages/cre-sdk-examples/src/workflows/proof-of-reserve/workflow.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ local-simulation:
3030
workflow-artifacts:
3131
workflow-path: "./index.ts"
3232
config-path: "./config.json"
33+
secrets-path: "../../../secrets.yaml"
3334

3435
# ==========================================================================
3536
production-testnet:
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"url": "https://swapi.info/api/people/{characterId}/"
3+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"characterId": 1
3+
}
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
import {
2+
consensusIdenticalAggregation,
3+
cre,
4+
decodeJson,
5+
type HTTPPayload,
6+
type HTTPSendRequester,
7+
json,
8+
ok,
9+
Runner,
10+
type Runtime,
11+
} from '@chainlink/cre-sdk'
12+
import { z } from 'zod'
13+
14+
const configSchema = z.object({
15+
url: z.string(),
16+
})
17+
18+
type Config = z.infer<typeof configSchema>
19+
20+
const responseSchema = z.object({
21+
name: z.string(),
22+
height: z.string(),
23+
mass: z.string(),
24+
hair_color: z.string(),
25+
skin_color: z.string(),
26+
eye_color: z.string(),
27+
birth_year: z.string(),
28+
gender: z.string(),
29+
homeworld: z.string(),
30+
films: z.array(z.string()),
31+
species: z.array(z.string()),
32+
vehicles: z.array(z.string()),
33+
starships: z.array(z.string()),
34+
created: z.string().datetime(),
35+
edited: z.string().datetime(),
36+
url: z.string(),
37+
})
38+
39+
type StarWarsCharacter = z.infer<typeof responseSchema>
40+
41+
const fetchStarWarsCharacter = (
42+
sendRequester: HTTPSendRequester,
43+
config: Config,
44+
payload: HTTPPayload,
45+
): StarWarsCharacter => {
46+
const input = decodeJson(payload.input)
47+
const url = config.url.replace('{characterId}', input.characterId)
48+
49+
const response = sendRequester.sendRequest({ url }).result()
50+
51+
// Check if the response is successful using the helper function
52+
if (!ok(response)) {
53+
throw new Error(`HTTP request failed with status: ${response.statusCode}`)
54+
}
55+
56+
const character = responseSchema.parse(json(response))
57+
58+
return character
59+
}
60+
61+
const onHTTPTrigger = async (runtime: Runtime<Config>, payload: HTTPPayload) => {
62+
const httpCapability = new cre.capabilities.HTTPClient()
63+
64+
const result: StarWarsCharacter = httpCapability
65+
.sendRequest(
66+
runtime,
67+
fetchStarWarsCharacter,
68+
consensusIdenticalAggregation(),
69+
)(runtime.config, payload)
70+
.result()
71+
72+
return result
73+
}
74+
75+
const initWorkflow = () => {
76+
const httpTrigger = new cre.capabilities.HTTPCapability()
77+
78+
return [cre.handler(httpTrigger.trigger({}), onHTTPTrigger)]
79+
}
80+
81+
export async function main() {
82+
const runner = await Runner.newRunner<Config>({
83+
configSchema,
84+
})
85+
await runner.run(initWorkflow)
86+
}
87+
88+
main()
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# ==========================================================================
2+
# CRE WORKFLOW SETTINGS FILE
3+
# ==========================================================================
4+
# This file defines environment-specific workflow settings used by the CRE CLI.
5+
#
6+
# Each top-level key is a target (e.g., `production`, `production-testnet`, etc.).
7+
# You can also define your own custom targets, such as `my-target`, and
8+
# point the CLI to it via an environment variable.
9+
#
10+
# Note: If any setting in this file conflicts with a setting in the CRE Project Settings File,
11+
# the value defined here in the workflow settings file will take precedence.
12+
#
13+
# Below is an example `my-target`:
14+
#
15+
# my-target:
16+
# user-workflow:
17+
# # Optional: The address of the workflow owner (wallet or MSIG contract).
18+
# # Used to establish ownership for encrypting the workflow's secrets.
19+
# # If omitted, defaults to an empty string.
20+
# workflow-owner-address: "0x1234567890abcdef1234567890abcdef12345678"
21+
#
22+
# # Required: The name of the workflow to register with the Workflow Registry contract.
23+
# workflow-name: "MyExampleWorkflow"
24+
25+
# ==========================================================================
26+
local-simulation:
27+
user-workflow:
28+
workflow-owner-address: "(optional) Multi-signature contract address"
29+
workflow-name: "star-wars"
30+
workflow-artifacts:
31+
workflow-path: "./index.ts"
32+
config-path: "./config.json"
33+
34+
# ==========================================================================
35+
production-testnet:
36+
user-workflow:
37+
workflow-owner-address: "(optional) Multi-signature contract address"
38+
workflow-name: "star-wars"

packages/cre-sdk-examples/tsconfig.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
{
22
"compilerOptions": {
33
// Enable latest features
4-
"lib": ["ESNext", "DOM", "DOM.Iterable"],
4+
"lib": ["ESNext"],
55
"target": "ESNext",
66
"module": "ESNext",
77
"moduleDetection": "force",
8-
"jsx": "react-jsx",
98
"allowJs": true,
109

1110
// Bundler mode
-889 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)