@chainlink/cre-sdk 0.0.4-alpha → 0.0.6-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.
@@ -4,6 +4,7 @@ import { BalanceAtReplySchema, BalanceAtRequestSchema, CallContractReplySchema,
4
4
  import { ReportResponseSchema, } from '../../../../../generated/sdk/v1alpha/sdk_pb';
5
5
  import {} from '../../../../../sdk';
6
6
  import { Report } from '../../../../../sdk/report';
7
+ import { hexToBytes } from '../../../../../sdk/utils/hex-utils';
7
8
  import {} from '../../../../../sdk/utils/triggers/trigger-interface';
8
9
  export function x_generatedCodeOnly_wrap_WriteCreReportRequest(input) {
9
10
  return {
@@ -15,7 +16,7 @@ export function x_generatedCodeOnly_wrap_WriteCreReportRequest(input) {
15
16
  }
16
17
  export function createWriteCreReportRequest(input) {
17
18
  return {
18
- receiver: new Uint8Array(Buffer.from(input.receiver, 'base64')),
19
+ receiver: hexToBytes(input.receiver),
19
20
  report: input.report,
20
21
  gasConfig: input.gasConfig !== undefined ? fromJson(GasConfigSchema, input.gasConfig) : undefined,
21
22
  $report: true,
@@ -3,6 +3,7 @@ import { ReportRequestSchema, ReportResponseSchema, SimpleConsensusInputsSchema,
3
3
  import { ValueSchema } from '../../../../../generated/values/v1/values_pb';
4
4
  import {} from '../../../../../sdk';
5
5
  import { Report } from '../../../../../sdk/report';
6
+ import { hexToBytes } from '../../../../../sdk/utils/hex-utils';
6
7
  /**
7
8
  * Consensus Capability
8
9
  *
@@ -3,6 +3,7 @@ import { AnySchema, anyPack } from '@bufbuild/protobuf/wkt';
3
3
  import { ConfigSchema, PayloadSchema, } from '../../../../../generated/capabilities/networking/http/v1alpha/trigger_pb';
4
4
  import {} from '../../../../../sdk';
5
5
  import { Report } from '../../../../../sdk/report';
6
+ import { hexToBytes } from '../../../../../sdk/utils/hex-utils';
6
7
  import {} from '../../../../../sdk/utils/triggers/trigger-interface';
7
8
  /**
8
9
  * HTTP Capability
@@ -3,6 +3,7 @@ import { AnySchema, anyPack } from '@bufbuild/protobuf/wkt';
3
3
  import { ConfigSchema, LegacyPayloadSchema, PayloadSchema, } from '../../../../../generated/capabilities/scheduler/cron/v1/trigger_pb';
4
4
  import {} from '../../../../../sdk';
5
5
  import { Report } from '../../../../../sdk/report';
6
+ import { hexToBytes } from '../../../../../sdk/utils/hex-utils';
6
7
  import {} from '../../../../../sdk/utils/triggers/trigger-interface';
7
8
  /**
8
9
  * Cron Capability
package/dist/index.d.ts CHANGED
@@ -1,5 +1 @@
1
1
  export * from './sdk';
2
- export * from './sdk/runtime';
3
- export * from './sdk/utils';
4
- export * from './sdk/utils/capabilities/http/http-helpers';
5
- export * from './sdk/wasm';
package/dist/index.js CHANGED
@@ -1,7 +1,3 @@
1
1
  /// <reference types="./sdk/types/global" />
2
+ /// <reference types="./sdk/types/restricted-apis" />
2
3
  export * from './sdk';
3
- export * from './sdk/runtime';
4
- export * from './sdk/utils';
5
- // Export HTTP response helpers
6
- export * from './sdk/utils/capabilities/http/http-helpers';
7
- export * from './sdk/wasm';
package/dist/pb.d.ts ADDED
@@ -0,0 +1,6 @@
1
+ export * as EVM_PB from './generated/capabilities/blockchain/evm/v1alpha/client_pb';
2
+ export * as HTTP_CLIENT_PB from './generated/capabilities/networking/http/v1alpha/client_pb';
3
+ export * as HTTP_TRIGGER_PB from './generated/capabilities/networking/http/v1alpha/trigger_pb';
4
+ export * as CRON_TRIGGER_PB from './generated/capabilities/scheduler/cron/v1/trigger_pb';
5
+ export * as SDK_PB from './generated/sdk/v1alpha/sdk_pb';
6
+ export * as VALUES_PB from './generated/values/v1/values_pb';
package/dist/pb.js ADDED
@@ -0,0 +1,6 @@
1
+ export * as EVM_PB from './generated/capabilities/blockchain/evm/v1alpha/client_pb';
2
+ export * as HTTP_CLIENT_PB from './generated/capabilities/networking/http/v1alpha/client_pb';
3
+ export * as HTTP_TRIGGER_PB from './generated/capabilities/networking/http/v1alpha/trigger_pb';
4
+ export * as CRON_TRIGGER_PB from './generated/capabilities/scheduler/cron/v1/trigger_pb';
5
+ export * as SDK_PB from './generated/sdk/v1alpha/sdk_pb';
6
+ export * as VALUES_PB from './generated/values/v1/values_pb';
@@ -0,0 +1,27 @@
1
+ declare global {
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
25
+ }
26
+
27
+ export {}
@@ -2,14 +2,21 @@
2
2
  * Public API for the CRE SDK.
3
3
  */
4
4
  import { ClientCapability as EVMClient } from '../../generated-sdk/capabilities/blockchain/evm/v1alpha/client_sdk_gen';
5
- import { ClientCapability as HTTPClient, type SendRequester as HTTPSendRequester } from '../../generated-sdk/capabilities/networking/http/v1alpha/client_sdk_gen';
5
+ import { ClientCapability as HTTPClient } 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
+ /**
9
+ * Public exports for the CRE SDK.
10
+ */
11
+ export { type Log as EVMLog, TxStatus, } from '../../generated/capabilities/blockchain/evm/v1alpha/client_pb';
9
12
  export type { Payload as HTTPPayload } from '../../generated/capabilities/networking/http/v1alpha/trigger_pb';
10
13
  export type { Payload as CronPayload } from '../../generated/capabilities/scheduler/cron/v1/trigger_pb';
14
+ export { ClientCapability as EVMClient } from '../../generated-sdk/capabilities/blockchain/evm/v1alpha/client_sdk_gen';
15
+ export { ClientCapability as HTTPClient, type SendRequester as HTTPSendRequester, } from '../../generated-sdk/capabilities/networking/http/v1alpha/client_sdk_gen';
16
+ export { HTTPCapability } from '../../generated-sdk/capabilities/networking/http/v1alpha/http_sdk_gen';
17
+ export { CronCapability } from '../../generated-sdk/capabilities/scheduler/cron/v1/cron_sdk_gen';
11
18
  export type { NodeRuntime, Runtime } from '../runtime';
12
- export type { HTTPSendRequester };
19
+ export { handler } from '../workflow';
13
20
  export declare const cre: {
14
21
  capabilities: {
15
22
  CronCapability: typeof CronCapability;
@@ -2,11 +2,23 @@
2
2
  * Public API for the CRE SDK.
3
3
  */
4
4
  import { ClientCapability as EVMClient } from '../../generated-sdk/capabilities/blockchain/evm/v1alpha/client_sdk_gen';
5
- import { ClientCapability as HTTPClient, } from '../../generated-sdk/capabilities/networking/http/v1alpha/client_sdk_gen';
5
+ import { ClientCapability as HTTPClient } 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
8
  import { prepareRuntime } from '../utils/prepare-runtime';
9
9
  import { handler } from '../workflow';
10
+ /**
11
+ * Public exports for the CRE SDK.
12
+ */
13
+ export { TxStatus, } from '../../generated/capabilities/blockchain/evm/v1alpha/client_pb';
14
+ // EVM Capability
15
+ export { ClientCapability as EVMClient } from '../../generated-sdk/capabilities/blockchain/evm/v1alpha/client_sdk_gen';
16
+ // HTTP Capability
17
+ export { ClientCapability as HTTPClient, } from '../../generated-sdk/capabilities/networking/http/v1alpha/client_sdk_gen';
18
+ export { HTTPCapability } from '../../generated-sdk/capabilities/networking/http/v1alpha/http_sdk_gen';
19
+ // CRON Capability
20
+ export { CronCapability } from '../../generated-sdk/capabilities/scheduler/cron/v1/cron_sdk_gen';
21
+ export { handler } from '../workflow';
10
22
  prepareRuntime();
11
23
  export const cre = {
12
24
  capabilities: {
@@ -2,4 +2,7 @@ export * from './cre';
2
2
  export * from './report';
3
3
  export type * from './runtime';
4
4
  export * from './runtime';
5
+ export * from './utils';
6
+ export * from './utils/capabilities/http/http-helpers';
7
+ export * from './wasm';
5
8
  export * from './workflow';
package/dist/sdk/index.js CHANGED
@@ -1,4 +1,8 @@
1
1
  export * from './cre';
2
2
  export * from './report';
3
3
  export * from './runtime';
4
+ export * from './utils';
5
+ // Export HTTP response helpers
6
+ export * from './utils/capabilities/http/http-helpers';
7
+ export * from './wasm';
4
8
  export * from './workflow';
@@ -1,4 +1,7 @@
1
- import type { Response } from '../../../../generated/capabilities/networking/http/v1alpha/client_pb';
1
+ import type { Request, RequestJson, Response } from '../../../../generated/capabilities/networking/http/v1alpha/client_pb';
2
+ import type { ReportResponse } from '../../../../generated/sdk/v1alpha/sdk_pb';
3
+ import type { NodeRuntime } from '../../..';
4
+ import type { Report } from '../../../report';
2
5
  /**
3
6
  * HTTP Response Helper Functions
4
7
  *
@@ -110,3 +113,36 @@ export declare function ok(responseFn: () => {
110
113
  }): {
111
114
  result: () => boolean;
112
115
  };
116
+ declare module '../../../../generated-sdk/capabilities/networking/http/v1alpha/client_sdk_gen' {
117
+ interface ClientCapability {
118
+ /**
119
+ * SendReport functions the same as SendRequest, but takes a Report and a function
120
+ * to convert the inner ReportResponse to a Request.
121
+ * Note that caching is limited as reports may contain different sets of signatures
122
+ * on different nodes, leading to a cache miss.
123
+ *
124
+ * @param runtime - The runtime instance
125
+ * @param report - The Report to process
126
+ * @param fn - Function to convert ReportResponse to Request
127
+ * @returns Response result function
128
+ */
129
+ sendReport(runtime: NodeRuntime<unknown>, report: Report, fn: (reportResponse: ReportResponse) => Request | RequestJson): {
130
+ result: () => Response;
131
+ };
132
+ }
133
+ interface SendRequester {
134
+ /**
135
+ * SendReport functions the same as SendRequest, but takes a Report and a function
136
+ * to convert the inner ReportResponse to a Request.
137
+ * Note that caching is limited as reports may contain different sets of signatures
138
+ * on different nodes, leading to a cache miss.
139
+ *
140
+ * @param report - The Report to process
141
+ * @param fn - Function to convert ReportResponse to Request
142
+ * @returns Response result function
143
+ */
144
+ sendReport(report: Report, fn: (reportResponse: ReportResponse) => Request | RequestJson): {
145
+ result: () => Response;
146
+ };
147
+ }
148
+ }
@@ -1,3 +1,4 @@
1
+ import { decodeJson } from '../../decode-json';
1
2
  export function text(responseOrFn) {
2
3
  if (typeof responseOrFn === 'function') {
3
4
  return {
@@ -15,11 +16,7 @@ export function json(responseOrFn) {
15
16
  result: () => json(responseOrFn().result),
16
17
  };
17
18
  }
18
- else {
19
- const decoder = new TextDecoder('utf-8');
20
- const textBody = decoder.decode(responseOrFn.body);
21
- return JSON.parse(textBody);
22
- }
19
+ return decodeJson(responseOrFn.body);
23
20
  }
24
21
  export function getHeader(responseOrFn, name) {
25
22
  if (typeof responseOrFn === 'function') {
@@ -42,3 +39,46 @@ export function ok(responseOrFn) {
42
39
  return responseOrFn.statusCode >= 200 && responseOrFn.statusCode < 300;
43
40
  }
44
41
  }
42
+ // ============================================================================
43
+ // SendReport Helper Methods for ClientCapability and SendRequester
44
+ // ============================================================================
45
+ /**
46
+ * SendReport functions the same as SendRequest, but takes a Report and a function
47
+ * to convert the inner ReportResponse to a Request.
48
+ * Note that caching is limited as reports may contain different sets of signatures
49
+ * on different nodes, leading to a cache miss.
50
+ *
51
+ * @param runtime - The runtime instance
52
+ * @param report - The Report to process
53
+ * @param fn - Function to convert ReportResponse to Request
54
+ * @returns Response result function
55
+ */
56
+ function sendReport(runtime, report, fn) {
57
+ const rawReport = report.x_generatedCodeOnly_unwrap();
58
+ const request = fn(rawReport);
59
+ return this.sendRequest(runtime, request);
60
+ }
61
+ /**
62
+ * SendReport functions the same as SendRequest, but takes a Report and a function
63
+ * to convert the inner ReportResponse to a Request.
64
+ * Note that caching is limited as reports may contain different sets of signatures
65
+ * on different nodes, leading to a cache miss.
66
+ *
67
+ * @param report - The Report to process
68
+ * @param fn - Function to convert ReportResponse to Request
69
+ * @returns Response result function
70
+ */
71
+ function sendRequesterSendReport(report, fn) {
72
+ const rawReport = report.x_generatedCodeOnly_unwrap();
73
+ const request = fn(rawReport);
74
+ return this.sendRequest(request);
75
+ }
76
+ // ============================================================================
77
+ // Prototype Extensions
78
+ // ============================================================================
79
+ // Import the actual classes for prototype extension
80
+ import { ClientCapability as ClientCapabilityClass, SendRequester as SendRequesterClass, } from '../../../../generated-sdk/capabilities/networking/http/v1alpha/client_sdk_gen';
81
+ // Extend ClientCapability prototype
82
+ ClientCapabilityClass.prototype.sendReport = sendReport;
83
+ // Extend SendRequester prototype
84
+ SendRequesterClass.prototype.sendReport = sendRequesterSendReport;
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Decodes a Uint8Array into a JSON object.
3
+ * Function would throw if the input is not a valid JSON string encoded as bytes.
4
+ *
5
+ * @param input - The Uint8Array to decode.
6
+ * @returns The decoded JSON object.
7
+ */
8
+ export declare const decodeJson: (input: Uint8Array) => any;
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Decodes a Uint8Array into a JSON object.
3
+ * Function would throw if the input is not a valid JSON string encoded as bytes.
4
+ *
5
+ * @param input - The Uint8Array to decode.
6
+ * @returns The decoded JSON object.
7
+ */
8
+ export const decodeJson = (input) => {
9
+ const decoder = new TextDecoder('utf-8');
10
+ const textBody = decoder.decode(input);
11
+ return JSON.parse(textBody);
12
+ };
@@ -1,6 +1,7 @@
1
1
  export * from './capabilities/blockchain/blockchain-helpers';
2
2
  export * from './capabilities/http/http-helpers';
3
3
  export * from './chain-selectors';
4
+ export * from './decode-json';
4
5
  export * from './hex-utils';
5
6
  export * from './values/consensus_aggregators';
6
7
  export * from './values/serializer_types';
@@ -1,6 +1,7 @@
1
1
  export * from './capabilities/blockchain/blockchain-helpers';
2
2
  export * from './capabilities/http/http-helpers';
3
3
  export * from './chain-selectors';
4
+ export * from './decode-json';
4
5
  export * from './hex-utils';
5
6
  export * from './values/consensus_aggregators';
6
7
  export * from './values/serializer_types';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@chainlink/cre-sdk",
3
- "version": "0.0.4-alpha",
3
+ "version": "0.0.6-alpha",
4
4
  "type": "module",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -8,6 +8,13 @@
8
8
  ".": {
9
9
  "types": "./dist/index.d.ts",
10
10
  "import": "./dist/index.js"
11
+ },
12
+ "./restricted-apis": {
13
+ "types": "./dist/restricted-apis.d.ts"
14
+ },
15
+ "./pb": {
16
+ "types": "./dist/pb.d.ts",
17
+ "import": "./dist/pb.js"
11
18
  }
12
19
  },
13
20
  "bin": {
@@ -22,7 +29,8 @@
22
29
  "LICENSE.md"
23
30
  ],
24
31
  "scripts": {
25
- "build": "bun run clean && bun run compile:build && bun run fix-imports",
32
+ "build": "bun run clean && bun run compile:build && bun run build:types && bun run fix-imports",
33
+ "build:types": "bun run scripts/run.ts build-types",
26
34
  "check": "biome check --write ${BIOME_PATHS:-.}",
27
35
  "clean": "rm -rf dist",
28
36
  "compile:all-standard-tests": "bun scripts/run.ts compile-all-standard-tests",
@@ -33,12 +41,12 @@
33
41
  "compile:workflow": "bun scripts/run.ts compile-workflow",
34
42
  "fix-imports": "bun scripts/run.ts fix-imports",
35
43
  "format": "biome format --write ${BIOME_PATHS:-.}",
36
- "full-checks": "bun generate:sdk && bun build && bun typecheck && bun lint && bun test && bun test:standard",
44
+ "full-checks": "bun generate:sdk && bun build && bun typecheck && bun check && bun test && bun test:standard",
37
45
  "generate:chain-selectors": "bun scripts/run.ts generate-chain-selectors && BIOME_PATHS=\"src/generated\" bun check",
38
46
  "generate:proto": "bunx @bufbuild/buf generate && BIOME_PATHS=\"src/generated\" bun check",
39
47
  "generate:sdk": "bun generate:proto && bun generate:chain-selectors && bun scripts/run generate-sdks && BIOME_PATHS=\"src/generated src/generated-sdk\" bun check",
40
48
  "lint": "biome lint --write",
41
- "prepublishOnly": "bun typecheck && bun lint && bun test && bun test:standard",
49
+ "prepublishOnly": "bun typecheck && bun check && bun test && bun test:standard",
42
50
  "test": "bun test",
43
51
  "test:standard": "./scripts/run-standard-tests.sh",
44
52
  "typecheck": "tsc"
@@ -46,7 +54,7 @@
46
54
  "dependencies": {
47
55
  "@bufbuild/protobuf": "2.6.3",
48
56
  "@bufbuild/protoc-gen-es": "2.6.3",
49
- "@chainlink/cre-sdk-javy-plugin": "0.0.4-alpha",
57
+ "@chainlink/cre-sdk-javy-plugin": "0.0.5-alpha",
50
58
  "@standard-schema/spec": "1.0.0",
51
59
  "viem": "2.34.0",
52
60
  "zod": "3.25.76"
package/scripts/run.ts CHANGED
@@ -1,14 +1,14 @@
1
1
  #!/usr/bin/env bun
2
2
 
3
3
  const availableScripts = [
4
+ 'build-types',
4
5
  'compile-to-js',
5
6
  'compile-to-wasm',
6
7
  'compile-workflow', // TS -> JS -> WASM compilation in single script
7
8
  'compile-all-standard-tests', // Do the above but for all standard tests
8
-
9
+ 'fix-imports', // Fix @cre/* imports to relative paths
9
10
  'generate-chain-selectors',
10
11
  'generate-sdks',
11
- 'fix-imports', // Fix @cre/* imports to relative paths
12
12
  ]
13
13
 
14
14
  /**
@@ -0,0 +1,22 @@
1
+ import { glob } from 'fast-glob'
2
+ import { copyFile, mkdir } from 'fs/promises'
3
+ import { dirname, join, relative } from 'path'
4
+
5
+ const buildTypes = async () => {
6
+ console.log('🔧 Including restricted-apis type in built files...')
7
+
8
+ // Define paths relative to the scripts directory
9
+ const packageRoot = join(import.meta.dir, '../..')
10
+ const sourceFile = join(packageRoot, 'src/sdk/types/restricted-apis.d.ts')
11
+ const destFile = join(packageRoot, 'dist/restricted-apis.d.ts')
12
+
13
+ // Ensure the dist directory exists
14
+ await mkdir(dirname(destFile), { recursive: true })
15
+
16
+ // Copy the file
17
+ await copyFile(sourceFile, destFile)
18
+
19
+ console.log('✅ Included restricted-apis type in the build.')
20
+ }
21
+
22
+ export const main = buildTypes