@chainlink/cre-sdk 0.0.3-alpha → 0.0.5-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 (43) 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 +149 -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 +27 -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 +3 -0
  9. package/dist/generated-sdk/capabilities/scheduler/cron/v1/cron_sdk_gen.js +3 -0
  10. package/dist/index.d.ts +1 -0
  11. package/dist/index.js +2 -0
  12. package/dist/sdk/cre/index.d.ts +1 -1
  13. package/dist/sdk/cre/index.js +1 -0
  14. package/dist/sdk/impl/runtime-impl.d.ts +5 -1
  15. package/dist/sdk/impl/runtime-impl.js +13 -2
  16. package/dist/sdk/index.d.ts +1 -0
  17. package/dist/sdk/index.js +1 -0
  18. package/dist/sdk/report.d.ts +6 -0
  19. package/dist/sdk/report.js +14 -0
  20. package/dist/sdk/runtime.d.ts +6 -0
  21. package/dist/sdk/utils/capabilities/blockchain/blockchain-helpers.d.ts +50 -0
  22. package/dist/sdk/utils/capabilities/blockchain/blockchain-helpers.js +48 -0
  23. package/dist/sdk/utils/capabilities/http/http-helpers.d.ts +112 -0
  24. package/dist/sdk/utils/capabilities/http/http-helpers.js +44 -0
  25. package/dist/sdk/utils/index.d.ts +2 -0
  26. package/dist/sdk/utils/index.js +2 -0
  27. package/dist/workflows/standard_tests/Makefile +19 -0
  28. package/dist/workflows/standard_tests/capability_calls_are_async/test.ts +39 -0
  29. package/dist/workflows/standard_tests/config/test.ts +23 -0
  30. package/dist/workflows/standard_tests/errors/test.ts +24 -0
  31. package/dist/workflows/standard_tests/logging/test.ts +25 -0
  32. package/dist/workflows/standard_tests/mode_switch/don_runtime_in_node_mode/test.ts +33 -0
  33. package/dist/workflows/standard_tests/mode_switch/node_runtime_in_don_mode/test.ts +41 -0
  34. package/dist/workflows/standard_tests/mode_switch/successful_mode_switch/test.ts +58 -0
  35. package/dist/workflows/standard_tests/multiple_triggers/test.ts +40 -0
  36. package/dist/workflows/standard_tests/random/test.ts +64 -0
  37. package/dist/workflows/standard_tests/secrets/test.ts +30 -0
  38. package/dist/workflows/standard_tests/secrets_fail_in_node_mode/test.ts +29 -0
  39. package/package.json +70 -69
  40. package/scripts/run-standard-tests.sh +0 -3
  41. package/scripts/src/cre-setup.ts +9 -0
  42. package/dist/sdk/utils/safeJsonStringify.d.ts +0 -6
  43. package/dist/sdk/utils/safeJsonStringify.js +0 -6
@@ -1,5 +1,7 @@
1
1
  import { fromJson } from '@bufbuild/protobuf';
2
2
  import { RequestSchema, ResponseSchema, } from '../../../../../generated/capabilities/networking/http/v1alpha/client_pb';
3
+ import {} from '../../../../../sdk';
4
+ import { Report } from '../../../../../sdk/report';
3
5
  export class SendRequester {
4
6
  runtime;
5
7
  client;
@@ -34,9 +36,16 @@ export class ClientCapability {
34
36
  return this.sendRequestCallHelper(runtime, input);
35
37
  }
36
38
  sendRequestCallHelper(runtime, input) {
37
- const payload = input.$typeName
38
- ? input
39
- : fromJson(RequestSchema, input);
39
+ // Handle input conversion - unwrap if it's a wrapped type, convert from JSON if needed
40
+ let payload;
41
+ if (input.$typeName) {
42
+ // It's the original protobuf type
43
+ payload = input;
44
+ }
45
+ else {
46
+ // It's regular JSON, convert using fromJson
47
+ payload = fromJson(RequestSchema, input);
48
+ }
40
49
  const capabilityId = ClientCapability.CAPABILITY_ID;
41
50
  const capabilityResponse = runtime.callCapability({
42
51
  capabilityId,
@@ -47,7 +56,8 @@ export class ClientCapability {
47
56
  });
48
57
  return {
49
58
  result: () => {
50
- return capabilityResponse.result();
59
+ const result = capabilityResponse.result();
60
+ return result;
51
61
  },
52
62
  };
53
63
  }
@@ -1,6 +1,9 @@
1
1
  import { create, fromJson } from '@bufbuild/protobuf';
2
2
  import { AnySchema, anyPack } from '@bufbuild/protobuf/wkt';
3
3
  import { ConfigSchema, PayloadSchema, } from '../../../../../generated/capabilities/networking/http/v1alpha/trigger_pb';
4
+ import {} from '../../../../../sdk';
5
+ import { Report } from '../../../../../sdk/report';
6
+ import { hexToBytes } from '../../../../../sdk/utils/hex-utils';
4
7
  import {} from '../../../../../sdk/utils/triggers/trigger-interface';
5
8
  /**
6
9
  * HTTP Capability
@@ -1,6 +1,9 @@
1
1
  import { create, fromJson } from '@bufbuild/protobuf';
2
2
  import { AnySchema, anyPack } from '@bufbuild/protobuf/wkt';
3
3
  import { ConfigSchema, LegacyPayloadSchema, PayloadSchema, } from '../../../../../generated/capabilities/scheduler/cron/v1/trigger_pb';
4
+ import {} from '../../../../../sdk';
5
+ import { Report } from '../../../../../sdk/report';
6
+ import { hexToBytes } from '../../../../../sdk/utils/hex-utils';
4
7
  import {} from '../../../../../sdk/utils/triggers/trigger-interface';
5
8
  /**
6
9
  * Cron Capability
package/dist/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  export * from './sdk';
2
2
  export * from './sdk/runtime';
3
3
  export * from './sdk/utils';
4
+ export * from './sdk/utils/capabilities/http/http-helpers';
4
5
  export * from './sdk/wasm';
package/dist/index.js CHANGED
@@ -2,4 +2,6 @@
2
2
  export * from './sdk';
3
3
  export * from './sdk/runtime';
4
4
  export * from './sdk/utils';
5
+ // Export HTTP response helpers
6
+ export * from './sdk/utils/capabilities/http/http-helpers';
5
7
  export * from './sdk/wasm';
@@ -5,7 +5,7 @@ import { ClientCapability as EVMClient } from '../../generated-sdk/capabilities/
5
5
  import { ClientCapability as HTTPClient, type SendRequester as HTTPSendRequester } from '../../generated-sdk/capabilities/networking/http/v1alpha/client_sdk_gen';
6
6
  import { HTTPCapability } from '../../generated-sdk/capabilities/networking/http/v1alpha/http_sdk_gen';
7
7
  import { CronCapability } from '../../generated-sdk/capabilities/scheduler/cron/v1/cron_sdk_gen';
8
- export type { Log as EVMLog } from '../../generated/capabilities/blockchain/evm/v1alpha/client_pb';
8
+ export { type Log as EVMLog, TxStatus, } from '../../generated/capabilities/blockchain/evm/v1alpha/client_pb';
9
9
  export type { Payload as HTTPPayload } from '../../generated/capabilities/networking/http/v1alpha/trigger_pb';
10
10
  export type { Payload as CronPayload } from '../../generated/capabilities/scheduler/cron/v1/trigger_pb';
11
11
  export type { NodeRuntime, Runtime } from '../runtime';
@@ -7,6 +7,7 @@ import { HTTPCapability } from '../../generated-sdk/capabilities/networking/http
7
7
  import { CronCapability } from '../../generated-sdk/capabilities/scheduler/cron/v1/cron_sdk_gen';
8
8
  import { prepareRuntime } from '../utils/prepare-runtime';
9
9
  import { handler } from '../workflow';
10
+ export { TxStatus, } from '../../generated/capabilities/blockchain/evm/v1alpha/client_pb';
10
11
  prepareRuntime();
11
12
  export const cre = {
12
13
  capabilities: {
@@ -1,6 +1,7 @@
1
1
  import { type Message } from '@bufbuild/protobuf';
2
2
  import { type AwaitCapabilitiesRequest, type AwaitCapabilitiesResponse, type AwaitSecretsRequest, type AwaitSecretsResponse, type CapabilityRequest, type GetSecretsRequest, Mode, type Secret, type SecretRequest, type SecretRequestJson } from '../../generated/sdk/v1alpha/sdk_pb';
3
- import type { BaseRuntime, CallCapabilityParams, NodeRuntime, Runtime } from '../runtime';
3
+ import type { BaseRuntime, CallCapabilityParams, NodeRuntime, ReportRequest, ReportRequestJson, Runtime } from '..';
4
+ import type { Report } from '../report';
4
5
  import { type ConsensusAggregation, type PrimitiveTypes, type UnwrapOptions } from '../utils';
5
6
  export declare class BaseRuntimeImpl<C> implements BaseRuntime<C> {
6
7
  config: C;
@@ -30,6 +31,9 @@ export declare class RuntimeImpl<C> extends BaseRuntimeImpl<C> implements Runtim
30
31
  getSecret(request: SecretRequest | SecretRequestJson): {
31
32
  result: () => Secret;
32
33
  };
34
+ report(input: ReportRequest | ReportRequestJson): {
35
+ result: () => Report;
36
+ };
33
37
  }
34
38
  export interface RuntimeHelpers {
35
39
  call(request: CapabilityRequest): boolean;
@@ -38,10 +38,12 @@ export class BaseRuntimeImpl {
38
38
  // - etc...
39
39
  const anyPayload = anyPack(inputSchema, payload);
40
40
  const callbackId = this.nextCallId;
41
- if (this.mode === Mode.DON)
41
+ if (this.mode === Mode.DON) {
42
42
  this.nextCallId++;
43
- else
43
+ }
44
+ else {
44
45
  this.nextCallId--;
46
+ }
45
47
  const req = create(CapabilityRequestSchema, {
46
48
  id: capabilityId,
47
49
  method,
@@ -210,4 +212,13 @@ export class RuntimeImpl extends BaseRuntimeImpl {
210
212
  },
211
213
  };
212
214
  }
215
+ report(input) {
216
+ const consensus = new ConsensusCapability();
217
+ const call = consensus.report(this, input);
218
+ return {
219
+ result: () => {
220
+ return call.result();
221
+ },
222
+ };
223
+ }
213
224
  }
@@ -1,4 +1,5 @@
1
1
  export * from './cre';
2
+ export * from './report';
2
3
  export type * from './runtime';
3
4
  export * from './runtime';
4
5
  export * from './workflow';
package/dist/sdk/index.js CHANGED
@@ -1,3 +1,4 @@
1
1
  export * from './cre';
2
+ export * from './report';
2
3
  export * from './runtime';
3
4
  export * from './workflow';
@@ -0,0 +1,6 @@
1
+ import { type ReportResponse, type ReportResponseJson } from '../generated/sdk/v1alpha/sdk_pb';
2
+ export declare class Report {
3
+ private readonly report;
4
+ constructor(report: ReportResponse | ReportResponseJson);
5
+ x_generatedCodeOnly_unwrap(): ReportResponse;
6
+ }
@@ -0,0 +1,14 @@
1
+ import { fromJson } from '@bufbuild/protobuf';
2
+ import { ReportResponseSchema, } from '../generated/sdk/v1alpha/sdk_pb';
3
+ export class Report {
4
+ report;
5
+ constructor(report) {
6
+ this.report = report.$typeName
7
+ ? report
8
+ : fromJson(ReportResponseSchema, report);
9
+ }
10
+ // x_generatedCodeOnly_unwrap is meant to be used by the code generator only.
11
+ x_generatedCodeOnly_unwrap() {
12
+ return this.report;
13
+ }
14
+ }
@@ -1,7 +1,9 @@
1
1
  import type { Message } from '@bufbuild/protobuf';
2
2
  import type { GenMessage } from '@bufbuild/protobuf/codegenv2';
3
+ import type { ReportRequest, ReportRequestJson } from '../generated/sdk/v1alpha/sdk_pb';
3
4
  import type { ConsensusAggregation, PrimitiveTypes, UnwrapOptions } from './utils';
4
5
  import type { SecretsProvider } from '.';
6
+ export type { ReportRequest, ReportRequestJson };
5
7
  export type CallCapabilityParams<I extends Message, O extends Message> = {
6
8
  capabilityId: string;
7
9
  method: string;
@@ -9,6 +11,7 @@ export type CallCapabilityParams<I extends Message, O extends Message> = {
9
11
  inputSchema: GenMessage<I>;
10
12
  outputSchema: GenMessage<O>;
11
13
  };
14
+ import type { Report } from './report';
12
15
  export type BaseRuntime<C> = {
13
16
  config: C;
14
17
  callCapability<I extends Message, O extends Message>(params: CallCapabilityParams<I, O>): {
@@ -21,6 +24,9 @@ export type Runtime<C> = BaseRuntime<C> & SecretsProvider & {
21
24
  runInNodeMode<TArgs extends unknown[], TOutput>(fn: (nodeRuntime: NodeRuntime<C>, ...args: TArgs) => TOutput, consensusAggregation: ConsensusAggregation<TOutput, true>, unwrapOptions?: TOutput extends PrimitiveTypes ? never : UnwrapOptions<TOutput>): (...args: TArgs) => {
22
25
  result: () => TOutput;
23
26
  };
27
+ report(input: ReportRequest | ReportRequestJson): {
28
+ result: () => Report;
29
+ };
24
30
  };
25
31
  export type NodeRuntime<C> = BaseRuntime<C> & {
26
32
  readonly _isNodeRuntime: true;
@@ -0,0 +1,50 @@
1
+ import type { CallMsgJson } from '../../../../generated/capabilities/blockchain/evm/v1alpha/client_pb';
2
+ import type { Address, Hex } from 'viem';
3
+ /**
4
+ * EVM Capability Helper.
5
+ *
6
+ * `CallContractRequest`, used by EVM capability, has arguments for reading a contract as specified in the call message at a block height defined by blockNumber.
7
+ * That blockNumber can be:
8
+ * - the latest mined block (`LATEST_BLOCK_NUMBER`) (default)
9
+ * - the last finalized block (`LAST_FINALIZED_BLOCK_NUMBER`)
10
+ *
11
+ * Using this constant will indicate that the call should be executed at the last finalized block.
12
+ */
13
+ export declare const LAST_FINALIZED_BLOCK_NUMBER: {
14
+ absVal: string;
15
+ sign: string;
16
+ };
17
+ /**
18
+ * EVM Capability Helper.
19
+ *
20
+ * `CallContractRequest`, used by EVM capability, has arguments for reading a contract as specified in the call message at a block height defined by blockNumber.
21
+ * That blockNumber can be:
22
+ * - the latest mined block (`LATEST_BLOCK_NUMBER`) (default)
23
+ * - the last finalized block (`LAST_FINALIZED_BLOCK_NUMBER`)
24
+ *
25
+ * Using this constant will indicate that the call should be executed at the latest mined block.
26
+ */
27
+ export declare const LATEST_BLOCK_NUMBER: {
28
+ absVal: string;
29
+ sign: string;
30
+ };
31
+ export interface EncodeCallMsgPayload {
32
+ from: Address;
33
+ to: Address;
34
+ data: Hex;
35
+ }
36
+ /**
37
+ * Encodes a call message payload into a `CallMsgJson` protobuf structure, expected by the EVM capability.
38
+ *
39
+ * When creating a `CallContractRequest` 3 parameters are required:
40
+ *
41
+ * - `from` - The sender address.
42
+ * - `to` - The contract address.
43
+ * - `data` - The data to call the contract with.
44
+ *
45
+ * This helper wraps that data and packs into format acceptable by the EVM capability.
46
+ *
47
+ * @param payload - The call message payload to encode.
48
+ * @returns The encoded call message payload.
49
+ */
50
+ export declare const encodeCallMsg: (payload: EncodeCallMsgPayload) => CallMsgJson;
@@ -0,0 +1,48 @@
1
+ import { hexToBase64 } from '../../hex-utils';
2
+ /**
3
+ * EVM Capability Helper.
4
+ *
5
+ * `CallContractRequest`, used by EVM capability, has arguments for reading a contract as specified in the call message at a block height defined by blockNumber.
6
+ * That blockNumber can be:
7
+ * - the latest mined block (`LATEST_BLOCK_NUMBER`) (default)
8
+ * - the last finalized block (`LAST_FINALIZED_BLOCK_NUMBER`)
9
+ *
10
+ * Using this constant will indicate that the call should be executed at the last finalized block.
11
+ */
12
+ export const LAST_FINALIZED_BLOCK_NUMBER = {
13
+ absVal: Buffer.from([3]).toString('base64'), // 3 for finalized block
14
+ sign: '-1',
15
+ };
16
+ /**
17
+ * EVM Capability Helper.
18
+ *
19
+ * `CallContractRequest`, used by EVM capability, has arguments for reading a contract as specified in the call message at a block height defined by blockNumber.
20
+ * That blockNumber can be:
21
+ * - the latest mined block (`LATEST_BLOCK_NUMBER`) (default)
22
+ * - the last finalized block (`LAST_FINALIZED_BLOCK_NUMBER`)
23
+ *
24
+ * Using this constant will indicate that the call should be executed at the latest mined block.
25
+ */
26
+ export const LATEST_BLOCK_NUMBER = {
27
+ absVal: Buffer.from([2]).toString('base64'), // 2 for the latest block
28
+ sign: '-1',
29
+ };
30
+ /**
31
+ * Encodes a call message payload into a `CallMsgJson` protobuf structure, expected by the EVM capability.
32
+ *
33
+ * When creating a `CallContractRequest` 3 parameters are required:
34
+ *
35
+ * - `from` - The sender address.
36
+ * - `to` - The contract address.
37
+ * - `data` - The data to call the contract with.
38
+ *
39
+ * This helper wraps that data and packs into format acceptable by the EVM capability.
40
+ *
41
+ * @param payload - The call message payload to encode.
42
+ * @returns The encoded call message payload.
43
+ */
44
+ export const encodeCallMsg = (payload) => ({
45
+ from: hexToBase64(payload.from),
46
+ to: hexToBase64(payload.to),
47
+ data: hexToBase64(payload.data),
48
+ });
@@ -0,0 +1,112 @@
1
+ import type { Response } from '../../../../generated/capabilities/networking/http/v1alpha/client_pb';
2
+ /**
3
+ * HTTP Response Helper Functions
4
+ *
5
+ * These utility functions provide a convenient way to work with HTTP Response objects,
6
+ * mimicking the native Response API methods like .json(), .text(), and .arrayBuffer().
7
+ *
8
+ * @example
9
+ * ```typescript
10
+ * import { text, json, ok, getHeader } from './http-helpers'
11
+ *
12
+ * // Direct usage with Response object
13
+ * const response = sendRequester.sendRequest({ url: 'https://api.example.com/data' }).result()
14
+ *
15
+ * // Check if response is successful
16
+ * if (!ok(response)) {
17
+ * throw new Error(`Request failed with status: ${response.statusCode}`)
18
+ * }
19
+ *
20
+ * // Get response as text (automatically trimmed)
21
+ * const responseText = text(response)
22
+ *
23
+ * // Parse JSON response
24
+ * const data = json(response)
25
+ *
26
+ * // Get specific header
27
+ * const contentType = getHeader(response, 'content-type')
28
+ * ```
29
+ *
30
+ * @example
31
+ * ```typescript
32
+ * // Function overload usage
33
+ * const responseFn = sendRequester.sendRequest({ url: 'https://api.example.com/data' })
34
+ *
35
+ * // Check if response is successful
36
+ * if (!ok(() => ({ result: responseFn.result() })).result()) {
37
+ * const response = responseFn.result()
38
+ * throw new Error(`Request failed with status: ${response.statusCode}`)
39
+ * }
40
+ *
41
+ * // Get response as text (automatically trimmed)
42
+ * const responseText = text(() => ({ result: responseFn.result() })).result()
43
+ * ```
44
+ */
45
+ /**
46
+ * Returns the response body as a UTF-8 string, automatically trimmed
47
+ * @param response - The Response object
48
+ * @returns The body as a trimmed string
49
+ */
50
+ export declare function text(response: Response): string;
51
+ /**
52
+ * Returns the response body as a UTF-8 string, automatically trimmed
53
+ * @param responseFn - Function that returns an object with result function that returns Response
54
+ * @returns Object with result function that returns the body as a trimmed string
55
+ */
56
+ export declare function text(responseFn: () => {
57
+ result: Response;
58
+ }): {
59
+ result: () => string;
60
+ };
61
+ /**
62
+ * Parses the response body as JSON
63
+ * @param response - The Response object
64
+ * @returns The parsed JSON
65
+ * @throws Error if the body is not valid JSON
66
+ */
67
+ export declare function json(response: Response): unknown;
68
+ /**
69
+ * Parses the response body as JSON
70
+ * @param responseFn - Function that returns an object with result function that returns Response
71
+ * @returns Object with result function that returns the parsed JSON
72
+ * @throws Error if the body is not valid JSON
73
+ */
74
+ export declare function json(responseFn: () => {
75
+ result: Response;
76
+ }): {
77
+ result: () => unknown;
78
+ };
79
+ /**
80
+ * Gets a specific header value
81
+ * @param response - The Response object
82
+ * @param name - The header name (case-insensitive)
83
+ * @returns The header value or undefined if not found
84
+ */
85
+ export declare function getHeader(response: Response, name: string): string | undefined;
86
+ /**
87
+ * Gets a specific header value
88
+ * @param responseFn - Function that returns an object with result function that returns Response
89
+ * @param name - The header name (case-insensitive)
90
+ * @returns Object with result function that returns the header value or undefined if not found
91
+ */
92
+ export declare function getHeader(responseFn: () => {
93
+ result: Response;
94
+ }, name: string): {
95
+ result: () => string | undefined;
96
+ };
97
+ /**
98
+ * Checks if the response status indicates success (200-299)
99
+ * @param response - The Response object
100
+ * @returns True if the status code is in the 200-299 range
101
+ */
102
+ export declare function ok(response: Response): boolean;
103
+ /**
104
+ * Checks if the response status indicates success (200-299)
105
+ * @param responseFn - Function that returns an object with result function that returns Response
106
+ * @returns Object with result function that returns true if the status code is in the 200-299 range
107
+ */
108
+ export declare function ok(responseFn: () => {
109
+ result: Response;
110
+ }): {
111
+ result: () => boolean;
112
+ };
@@ -0,0 +1,44 @@
1
+ export function text(responseOrFn) {
2
+ if (typeof responseOrFn === 'function') {
3
+ return {
4
+ result: () => text(responseOrFn().result),
5
+ };
6
+ }
7
+ else {
8
+ const decoder = new TextDecoder('utf-8');
9
+ return decoder.decode(responseOrFn.body).trim();
10
+ }
11
+ }
12
+ export function json(responseOrFn) {
13
+ if (typeof responseOrFn === 'function') {
14
+ return {
15
+ result: () => json(responseOrFn().result),
16
+ };
17
+ }
18
+ else {
19
+ const decoder = new TextDecoder('utf-8');
20
+ const textBody = decoder.decode(responseOrFn.body);
21
+ return JSON.parse(textBody);
22
+ }
23
+ }
24
+ export function getHeader(responseOrFn, name) {
25
+ if (typeof responseOrFn === 'function') {
26
+ return {
27
+ result: () => getHeader(responseOrFn().result, name),
28
+ };
29
+ }
30
+ else {
31
+ const lowerName = name.toLowerCase();
32
+ return Object.entries(responseOrFn.headers).find(([key]) => key.toLowerCase() === lowerName)?.[1];
33
+ }
34
+ }
35
+ export function ok(responseOrFn) {
36
+ if (typeof responseOrFn === 'function') {
37
+ return {
38
+ result: () => ok(responseOrFn().result),
39
+ };
40
+ }
41
+ else {
42
+ return responseOrFn.statusCode >= 200 && responseOrFn.statusCode < 300;
43
+ }
44
+ }
@@ -1,3 +1,5 @@
1
+ export * from './capabilities/blockchain/blockchain-helpers';
2
+ export * from './capabilities/http/http-helpers';
1
3
  export * from './chain-selectors';
2
4
  export * from './hex-utils';
3
5
  export * from './values/consensus_aggregators';
@@ -1,3 +1,5 @@
1
+ export * from './capabilities/blockchain/blockchain-helpers';
2
+ export * from './capabilities/http/http-helpers';
1
3
  export * from './chain-selectors';
2
4
  export * from './hex-utils';
3
5
  export * from './values/consensus_aggregators';
@@ -0,0 +1,19 @@
1
+ # Declare all matching test.wasm targets as phony
2
+ .PHONY: FORCE
3
+ FORCE:
4
+
5
+ # Pattern rule to build test.wasm in any subdirectory
6
+ %/test.wasm: FORCE
7
+ @echo "Building test: $*"
8
+ @case "$*" in \
9
+ */*/*) \
10
+ echo "❌ Unsupported test path depth: $*"; \
11
+ exit 1; \
12
+ ;; \
13
+ */*) \
14
+ cd ../.. && bun compile:workflow src/standard_tests/$$(echo "$*" | cut -d'/' -f1)/$$(echo "$*" | cut -d'/' -f2)/test.ts .temp/standard_tests/$$(echo "$*" | cut -d'/' -f1)/$$(echo "$*" | cut -d'/' -f2)/test.wasm; \
15
+ ;; \
16
+ *) \
17
+ cd ../.. && bun compile:workflow src/standard_tests/$*/test.ts .temp/standard_tests/$*/test.wasm; \
18
+ ;; \
19
+ esac
@@ -0,0 +1,39 @@
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 { cre, type Runtime } from '@cre/sdk/cre'
4
+ import { Runner } from '@cre/sdk/wasm'
5
+
6
+ const asyncCalls = (runtime: Runtime<Uint8Array>) => {
7
+ const basicAction = new BasicActionCapability()
8
+
9
+ const input1 = { inputThing: true }
10
+ const input2 = { inputThing: false }
11
+
12
+ // Notice: we call perform action on input1 and then input 2.
13
+ const p1 = basicAction.performAction(runtime, input1)
14
+ const p2 = basicAction.performAction(runtime, input2)
15
+
16
+ // We get results in the reverse order.
17
+ const r2 = p2.result()
18
+ const r1 = p1.result()
19
+
20
+ return `${r1.adaptedThing}${r2.adaptedThing}`
21
+ }
22
+
23
+ const initWorkflow = () => {
24
+ const basicTrigger = new BasicTriggerCapability()
25
+ return [cre.handler(basicTrigger.trigger({}), asyncCalls)]
26
+ }
27
+
28
+ export async function main() {
29
+ console.log(
30
+ `TS workflow: standard test: capability calls are async [${new Date().toISOString()}]`,
31
+ )
32
+
33
+ const runner = await Runner.newRunner<Uint8Array>({
34
+ configParser: (c) => c,
35
+ })
36
+ runner.run(initWorkflow)
37
+ }
38
+
39
+ await main()
@@ -0,0 +1,23 @@
1
+ import { BasicCapability as BasicTriggerCapability } from '@cre/generated-sdk/capabilities/internal/basictrigger/v1/basic_sdk_gen'
2
+ import { cre, type Runtime } from '@cre/sdk/cre'
3
+ import { Runner } from '@cre/sdk/wasm'
4
+
5
+ const sendBackConfig = (runtime: Runtime<Uint8Array>) => {
6
+ return runtime.config
7
+ }
8
+
9
+ const initWorkflow = () => {
10
+ const basicTrigger = new BasicTriggerCapability()
11
+ return [cre.handler(basicTrigger.trigger({}), sendBackConfig)]
12
+ }
13
+
14
+ export async function main() {
15
+ console.log(`TS workflow: standard test: config [${new Date().toISOString()}]`)
16
+
17
+ const runner = await Runner.newRunner<Uint8Array>({
18
+ configParser: (c) => c,
19
+ })
20
+ await runner.run(initWorkflow)
21
+ }
22
+
23
+ await main()
@@ -0,0 +1,24 @@
1
+ import { BasicCapability as BasicTriggerCapability } from '@cre/generated-sdk/capabilities/internal/basictrigger/v1/basic_sdk_gen'
2
+ import { cre, type Runtime } from '@cre/sdk/cre'
3
+ import { Runner } from '@cre/sdk/wasm'
4
+
5
+ const simulateWorkflowFailure = (_: Runtime<Uint8Array>) => {
6
+ throw new Error('workflow execution failure')
7
+ }
8
+
9
+ const initWorkflow = () => {
10
+ const basicTrigger = new BasicTriggerCapability()
11
+
12
+ return [cre.handler(basicTrigger.trigger({}), simulateWorkflowFailure)]
13
+ }
14
+
15
+ export async function main() {
16
+ console.log(`TS workflow: standard test: errors [${new Date().toISOString()}]`)
17
+
18
+ const runner = await Runner.newRunner<Uint8Array>({
19
+ configParser: (c) => c,
20
+ })
21
+ await runner.run(initWorkflow)
22
+ }
23
+
24
+ await main()
@@ -0,0 +1,25 @@
1
+ import { BasicCapability as BasicTriggerCapability } from '@cre/generated-sdk/capabilities/internal/basictrigger/v1/basic_sdk_gen'
2
+ import { cre, type Runtime } from '@cre/sdk/cre'
3
+ import { Runner } from '@cre/sdk/wasm'
4
+
5
+ const doLog = (runtime: Runtime<string>) => {
6
+ runtime.log('log from wasm!')
7
+ return runtime.config
8
+ }
9
+
10
+ const initWorkflow = () => {
11
+ const basicTrigger = new BasicTriggerCapability()
12
+
13
+ return [cre.handler(basicTrigger.trigger({}), doLog)]
14
+ }
15
+
16
+ export async function main() {
17
+ console.log(`TS workflow: standard test: logging [${new Date().toISOString()}]`)
18
+
19
+ const runner = await Runner.newRunner<string>({
20
+ configParser: (c) => c.toString(),
21
+ })
22
+ await runner.run(initWorkflow)
23
+ }
24
+
25
+ await main()
@@ -0,0 +1,33 @@
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 { cre, 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
+ return runtime
9
+ .runInNodeMode(() => {
10
+ const basicCap = new BasicActionCapability()
11
+ return basicCap.performAction(runtime, { inputThing: true }).result().adaptedThing
12
+ }, consensusIdenticalAggregation())()
13
+ .result()
14
+ }
15
+
16
+ const initWorkflow = () => {
17
+ const basicTrigger = new BasicTriggerCapability()
18
+
19
+ return [cre.handler(basicTrigger.trigger({}), handler)]
20
+ }
21
+
22
+ export async function main() {
23
+ console.log(
24
+ `TS workflow: standard test: mode_switch: successful_mode_switch [${new Date().toISOString()}]`,
25
+ )
26
+
27
+ const runner = await Runner.newRunner<Uint8Array>({
28
+ configParser: (c) => c,
29
+ })
30
+ await runner.run(initWorkflow)
31
+ }
32
+
33
+ await main()