@chainlink/cre-sdk 1.6.0-alpha.4 → 1.6.0-alpha.5

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 (36) hide show
  1. package/README.md +9 -0
  2. package/dist/generated/capabilities/blockchain/aptos/v1alpha/client_pb.d.ts +1023 -0
  3. package/dist/generated/capabilities/blockchain/aptos/v1alpha/client_pb.js +290 -0
  4. package/dist/generated/capabilities/blockchain/solana/v1alpha/client_pb.d.ts +2904 -0
  5. package/dist/generated/capabilities/blockchain/solana/v1alpha/client_pb.js +506 -0
  6. package/dist/generated/workflows/v2/cre_info_pb.d.ts +123 -0
  7. package/dist/generated/workflows/v2/cre_info_pb.js +17 -0
  8. package/dist/generated/workflows/v2/workflow_key_pb.d.ts +55 -0
  9. package/dist/generated/workflows/v2/workflow_key_pb.js +17 -0
  10. package/dist/generated/workflows/v2/workflow_user_metric_pb.d.ts +118 -0
  11. package/dist/generated/workflows/v2/workflow_user_metric_pb.js +41 -0
  12. package/dist/generated-sdk/capabilities/blockchain/aptos/v1alpha/client_sdk_gen.d.ts +52 -0
  13. package/dist/generated-sdk/capabilities/blockchain/aptos/v1alpha/client_sdk_gen.js +186 -0
  14. package/dist/generated-sdk/capabilities/blockchain/solana/v1alpha/client_sdk_gen.d.ts +92 -0
  15. package/dist/generated-sdk/capabilities/blockchain/solana/v1alpha/client_sdk_gen.js +343 -0
  16. package/dist/sdk/cre/index.d.ts +6 -0
  17. package/dist/sdk/cre/index.js +8 -0
  18. package/dist/sdk/impl/runtime-impl.d.ts +8 -0
  19. package/dist/sdk/impl/runtime-impl.js +15 -1
  20. package/dist/sdk/runtime.d.ts +3 -1
  21. package/dist/sdk/test/generated/capabilities/blockchain/aptos/v1alpha/aptos_mock_gen.d.ts +25 -0
  22. package/dist/sdk/test/generated/capabilities/blockchain/aptos/v1alpha/aptos_mock_gen.js +111 -0
  23. package/dist/sdk/test/generated/capabilities/blockchain/solana/v1alpha/solana_mock_gen.d.ts +33 -0
  24. package/dist/sdk/test/generated/capabilities/blockchain/solana/v1alpha/solana_mock_gen.js +178 -0
  25. package/dist/sdk/test/generated/index.d.ts +2 -0
  26. package/dist/sdk/test/generated/index.js +2 -0
  27. package/dist/sdk/testutils/test-runtime.d.ts +2 -0
  28. package/dist/sdk/testutils/test-runtime.js +7 -0
  29. package/dist/sdk/testutils/test-writer.d.ts +7 -1
  30. package/dist/sdk/testutils/test-writer.js +13 -1
  31. package/dist/sdk/types/global.d.ts +8 -0
  32. package/dist/sdk/wasm/host-bindings.d.ts +1 -0
  33. package/dist/sdk/wasm/host-bindings.js +4 -0
  34. package/dist/sdk/wasm/runtime.js +3 -0
  35. package/package.json +2 -2
  36. package/scripts/src/generate-sdks.ts +12 -0
@@ -0,0 +1,178 @@
1
+ import { fromJson } from '@bufbuild/protobuf';
2
+ import { anyPack, anyUnpack } from '@bufbuild/protobuf/wkt';
3
+ import { GetAccountInfoWithOptsReplySchema, GetAccountInfoWithOptsRequestSchema, GetBalanceReplySchema, GetBalanceRequestSchema, GetBlockReplySchema, GetBlockRequestSchema, GetFeeForMessageReplySchema, GetFeeForMessageRequestSchema, GetMultipleAccountsWithOptsReplySchema, GetMultipleAccountsWithOptsRequestSchema, GetSignatureStatusesReplySchema, GetSignatureStatusesRequestSchema, GetSlotHeightReplySchema, GetSlotHeightRequestSchema, GetTransactionReplySchema, GetTransactionRequestSchema, WriteReportReplySchema, WriteReportRequestSchema, } from '../../../../../../../generated/capabilities/blockchain/solana/v1alpha/client_pb';
4
+ import { __getTestMockInstance, __setTestMockInstance, registerTestCapability, } from '../../../../../../testutils/test-runtime';
5
+ /**
6
+ * Mock for ClientCapability. Use testInstance() to obtain an instance; do not construct directly.
7
+ * Set per-method properties (e.g. performAction) to define return values. If a method is invoked without a handler set, an error is thrown.
8
+ */
9
+ export class SolanaMock {
10
+ static CAPABILITY_ID = 'solana@1.0.0';
11
+ /** Set to define the return value for GetAccountInfoWithOpts. May return a plain object (GetAccountInfoWithOptsReplyJson) or the message type. */
12
+ getAccountInfoWithOpts;
13
+ /** Set to define the return value for GetBalance. May return a plain object (GetBalanceReplyJson) or the message type. */
14
+ getBalance;
15
+ /** Set to define the return value for GetBlock. May return a plain object (GetBlockReplyJson) or the message type. */
16
+ getBlock;
17
+ /** Set to define the return value for GetFeeForMessage. May return a plain object (GetFeeForMessageReplyJson) or the message type. */
18
+ getFeeForMessage;
19
+ /** Set to define the return value for GetMultipleAccountsWithOpts. May return a plain object (GetMultipleAccountsWithOptsReplyJson) or the message type. */
20
+ getMultipleAccountsWithOpts;
21
+ /** Set to define the return value for GetSignatureStatuses. May return a plain object (GetSignatureStatusesReplyJson) or the message type. */
22
+ getSignatureStatuses;
23
+ /** Set to define the return value for GetSlotHeight. May return a plain object (GetSlotHeightReplyJson) or the message type. */
24
+ getSlotHeight;
25
+ /** Set to define the return value for GetTransaction. May return a plain object (GetTransactionReplyJson) or the message type. */
26
+ getTransaction;
27
+ /** Set to define the return value for WriteReport. May return a plain object (WriteReportReplyJson) or the message type. */
28
+ writeReport;
29
+ constructor(chainSelector) {
30
+ const self = this;
31
+ const qualifiedId = `solana:ChainSelector:${chainSelector}@1.0.0`;
32
+ try {
33
+ registerTestCapability(qualifiedId, (req) => {
34
+ switch (req.method) {
35
+ case 'GetAccountInfoWithOpts': {
36
+ const input = anyUnpack(req.payload, GetAccountInfoWithOptsRequestSchema);
37
+ const handler = self.getAccountInfoWithOpts;
38
+ if (typeof handler !== 'function')
39
+ throw new Error("GetAccountInfoWithOpts: no implementation provided; set the mock's getAccountInfoWithOpts property to define the return value.");
40
+ const raw = handler(input);
41
+ const output = raw && typeof raw.$typeName === 'string'
42
+ ? raw
43
+ : fromJson(GetAccountInfoWithOptsReplySchema, raw);
44
+ return {
45
+ response: {
46
+ case: 'payload',
47
+ value: anyPack(GetAccountInfoWithOptsReplySchema, output),
48
+ },
49
+ };
50
+ }
51
+ case 'GetBalance': {
52
+ const input = anyUnpack(req.payload, GetBalanceRequestSchema);
53
+ const handler = self.getBalance;
54
+ if (typeof handler !== 'function')
55
+ throw new Error("GetBalance: no implementation provided; set the mock's getBalance property to define the return value.");
56
+ const raw = handler(input);
57
+ const output = raw && typeof raw.$typeName === 'string'
58
+ ? raw
59
+ : fromJson(GetBalanceReplySchema, raw);
60
+ return { response: { case: 'payload', value: anyPack(GetBalanceReplySchema, output) } };
61
+ }
62
+ case 'GetBlock': {
63
+ const input = anyUnpack(req.payload, GetBlockRequestSchema);
64
+ const handler = self.getBlock;
65
+ if (typeof handler !== 'function')
66
+ throw new Error("GetBlock: no implementation provided; set the mock's getBlock property to define the return value.");
67
+ const raw = handler(input);
68
+ const output = raw && typeof raw.$typeName === 'string'
69
+ ? raw
70
+ : fromJson(GetBlockReplySchema, raw);
71
+ return { response: { case: 'payload', value: anyPack(GetBlockReplySchema, output) } };
72
+ }
73
+ case 'GetFeeForMessage': {
74
+ const input = anyUnpack(req.payload, GetFeeForMessageRequestSchema);
75
+ const handler = self.getFeeForMessage;
76
+ if (typeof handler !== 'function')
77
+ throw new Error("GetFeeForMessage: no implementation provided; set the mock's getFeeForMessage property to define the return value.");
78
+ const raw = handler(input);
79
+ const output = raw && typeof raw.$typeName === 'string'
80
+ ? raw
81
+ : fromJson(GetFeeForMessageReplySchema, raw);
82
+ return {
83
+ response: { case: 'payload', value: anyPack(GetFeeForMessageReplySchema, output) },
84
+ };
85
+ }
86
+ case 'GetMultipleAccountsWithOpts': {
87
+ const input = anyUnpack(req.payload, GetMultipleAccountsWithOptsRequestSchema);
88
+ const handler = self.getMultipleAccountsWithOpts;
89
+ if (typeof handler !== 'function')
90
+ throw new Error("GetMultipleAccountsWithOpts: no implementation provided; set the mock's getMultipleAccountsWithOpts property to define the return value.");
91
+ const raw = handler(input);
92
+ const output = raw && typeof raw.$typeName === 'string'
93
+ ? raw
94
+ : fromJson(GetMultipleAccountsWithOptsReplySchema, raw);
95
+ return {
96
+ response: {
97
+ case: 'payload',
98
+ value: anyPack(GetMultipleAccountsWithOptsReplySchema, output),
99
+ },
100
+ };
101
+ }
102
+ case 'GetSignatureStatuses': {
103
+ const input = anyUnpack(req.payload, GetSignatureStatusesRequestSchema);
104
+ const handler = self.getSignatureStatuses;
105
+ if (typeof handler !== 'function')
106
+ throw new Error("GetSignatureStatuses: no implementation provided; set the mock's getSignatureStatuses property to define the return value.");
107
+ const raw = handler(input);
108
+ const output = raw && typeof raw.$typeName === 'string'
109
+ ? raw
110
+ : fromJson(GetSignatureStatusesReplySchema, raw);
111
+ return {
112
+ response: {
113
+ case: 'payload',
114
+ value: anyPack(GetSignatureStatusesReplySchema, output),
115
+ },
116
+ };
117
+ }
118
+ case 'GetSlotHeight': {
119
+ const input = anyUnpack(req.payload, GetSlotHeightRequestSchema);
120
+ const handler = self.getSlotHeight;
121
+ if (typeof handler !== 'function')
122
+ throw new Error("GetSlotHeight: no implementation provided; set the mock's getSlotHeight property to define the return value.");
123
+ const raw = handler(input);
124
+ const output = raw && typeof raw.$typeName === 'string'
125
+ ? raw
126
+ : fromJson(GetSlotHeightReplySchema, raw);
127
+ return {
128
+ response: { case: 'payload', value: anyPack(GetSlotHeightReplySchema, output) },
129
+ };
130
+ }
131
+ case 'GetTransaction': {
132
+ const input = anyUnpack(req.payload, GetTransactionRequestSchema);
133
+ const handler = self.getTransaction;
134
+ if (typeof handler !== 'function')
135
+ throw new Error("GetTransaction: no implementation provided; set the mock's getTransaction property to define the return value.");
136
+ const raw = handler(input);
137
+ const output = raw && typeof raw.$typeName === 'string'
138
+ ? raw
139
+ : fromJson(GetTransactionReplySchema, raw);
140
+ return {
141
+ response: { case: 'payload', value: anyPack(GetTransactionReplySchema, output) },
142
+ };
143
+ }
144
+ case 'WriteReport': {
145
+ const input = anyUnpack(req.payload, WriteReportRequestSchema);
146
+ const handler = self.writeReport;
147
+ if (typeof handler !== 'function')
148
+ throw new Error("WriteReport: no implementation provided; set the mock's writeReport property to define the return value.");
149
+ const raw = handler(input);
150
+ const output = raw && typeof raw.$typeName === 'string'
151
+ ? raw
152
+ : fromJson(WriteReportReplySchema, raw);
153
+ return { response: { case: 'payload', value: anyPack(WriteReportReplySchema, output) } };
154
+ }
155
+ default:
156
+ return { response: { case: 'error', value: `unknown method ${req.method}` } };
157
+ }
158
+ });
159
+ }
160
+ catch {
161
+ throw new Error("Capability mocks must be used within the CRE test framework's test() method.");
162
+ }
163
+ }
164
+ /**
165
+ * Returns the mock instance for this capability and the specified tags.
166
+ * Multiple calls with the same tag values return the same instance.
167
+ * Must be called within the test framework's test() method.
168
+ */
169
+ static testInstance(chainSelector) {
170
+ const qualifiedId = `solana:ChainSelector:${chainSelector}@1.0.0`;
171
+ let instance = __getTestMockInstance(qualifiedId);
172
+ if (!instance) {
173
+ instance = new SolanaMock(chainSelector);
174
+ __setTestMockInstance(qualifiedId, instance);
175
+ }
176
+ return instance;
177
+ }
178
+ }
@@ -1,5 +1,7 @@
1
1
  /** Auto-generated barrel of capability mocks. Do not edit. */
2
+ export { AptosMock } from './capabilities/blockchain/aptos/v1alpha/aptos_mock_gen';
2
3
  export { EvmMock } from './capabilities/blockchain/evm/v1alpha/evm_mock_gen';
4
+ export { SolanaMock } from './capabilities/blockchain/solana/v1alpha/solana_mock_gen';
3
5
  export { BasicTestActionTriggerMock } from './capabilities/internal/actionandtrigger/v1/basic_test_action_trigger_mock_gen';
4
6
  export { BasicTestActionMock } from './capabilities/internal/basicaction/v1/basic_test_action_mock_gen';
5
7
  export { ConsensusMock } from './capabilities/internal/consensus/v1alpha/consensus_mock_gen';
@@ -1,5 +1,7 @@
1
1
  /** Auto-generated barrel of capability mocks. Do not edit. */
2
+ export { AptosMock } from './capabilities/blockchain/aptos/v1alpha/aptos_mock_gen';
2
3
  export { EvmMock } from './capabilities/blockchain/evm/v1alpha/evm_mock_gen';
4
+ export { SolanaMock } from './capabilities/blockchain/solana/v1alpha/solana_mock_gen';
3
5
  export { BasicTestActionTriggerMock } from './capabilities/internal/actionandtrigger/v1/basic_test_action_trigger_mock_gen';
4
6
  export { BasicTestActionMock } from './capabilities/internal/basicaction/v1/basic_test_action_mock_gen';
5
7
  export { ConsensusMock } from './capabilities/internal/consensus/v1alpha/consensus_mock_gen';
@@ -3,6 +3,7 @@
3
3
  * Registry is scoped per test via AsyncLocalStorage; use testWithRuntime to run tests with a registry.
4
4
  */
5
5
  import type { Any } from '@bufbuild/protobuf/wkt';
6
+ import type { WorkflowUserMetric } from '../../generated/workflows/v2/workflow_user_metric_pb';
6
7
  import type { RuntimeHelpers } from '../impl/runtime-impl';
7
8
  import { RuntimeImpl } from '../impl/runtime-impl';
8
9
  import { TestWriter } from './test-writer';
@@ -80,5 +81,6 @@ export declare class TestRuntime extends RuntimeImpl<unknown> {
80
81
  private readonly state;
81
82
  constructor(helpers: RuntimeHelpers, maxResponseSize: bigint, testWriter: TestWriter, state: TestRuntimeState);
82
83
  getLogs(): string[];
84
+ getMetrics(): WorkflowUserMetric[];
83
85
  setTimeProvider(timeProvider: () => number): void;
84
86
  }
@@ -236,6 +236,10 @@ function createTestRuntimeHelpers(registry, secrets, testWriter, state, _maxResp
236
236
  log(message) {
237
237
  testWriter.log(message);
238
238
  },
239
+ emitMetric(payload) {
240
+ testWriter.emitMetric(payload);
241
+ return true;
242
+ },
239
243
  };
240
244
  }
241
245
  /**
@@ -307,6 +311,9 @@ export class TestRuntime extends RuntimeImpl {
307
311
  getLogs() {
308
312
  return this.testWriter.getLogs();
309
313
  }
314
+ getMetrics() {
315
+ return this.testWriter.getMetrics();
316
+ }
310
317
  setTimeProvider(timeProvider) {
311
318
  this.state.timeProvider = timeProvider;
312
319
  }
@@ -1,13 +1,19 @@
1
+ import { type WorkflowUserMetric } from '../../generated/workflows/v2/workflow_user_metric_pb';
1
2
  /**
2
3
  * In-memory log sink for tests. Captures messages so tests can assert on log output.
3
4
  * Equivalent to Go's cre/testutils/test_writer.go.
4
5
  */
5
6
  export declare class TestWriter {
6
7
  private logs;
8
+ private metrics;
7
9
  /** Appends a message to the captured log buffer. */
8
10
  log(message: string): void;
9
11
  /** Returns a copy of all captured log messages in order. */
10
12
  getLogs(): string[];
11
- /** Clears the captured log buffer. */
13
+ /** Captures a serialized WorkflowUserMetric payload. */
14
+ emitMetric(payload: Uint8Array): void;
15
+ /** Returns captured metric payloads decoded as `WorkflowUserMetric` protos. */
16
+ getMetrics(): WorkflowUserMetric[];
17
+ /** Clears captured logs and metrics. */
12
18
  clear(): void;
13
19
  }
@@ -1,9 +1,12 @@
1
+ import { fromBinary } from '@bufbuild/protobuf';
2
+ import { WorkflowUserMetricSchema, } from '../../generated/workflows/v2/workflow_user_metric_pb';
1
3
  /**
2
4
  * In-memory log sink for tests. Captures messages so tests can assert on log output.
3
5
  * Equivalent to Go's cre/testutils/test_writer.go.
4
6
  */
5
7
  export class TestWriter {
6
8
  logs = [];
9
+ metrics = [];
7
10
  /** Appends a message to the captured log buffer. */
8
11
  log(message) {
9
12
  this.logs.push(message);
@@ -12,8 +15,17 @@ export class TestWriter {
12
15
  getLogs() {
13
16
  return [...this.logs];
14
17
  }
15
- /** Clears the captured log buffer. */
18
+ /** Captures a serialized WorkflowUserMetric payload. */
19
+ emitMetric(payload) {
20
+ this.metrics.push(payload);
21
+ }
22
+ /** Returns captured metric payloads decoded as `WorkflowUserMetric` protos. */
23
+ getMetrics() {
24
+ return this.metrics.map((bytes) => fromBinary(WorkflowUserMetricSchema, bytes));
25
+ }
26
+ /** Clears captured logs and metrics. */
16
27
  clear() {
17
28
  this.logs = [];
29
+ this.metrics = [];
18
30
  }
19
31
  }
@@ -45,6 +45,14 @@ declare global {
45
45
  */
46
46
  function log(message: string): void
47
47
 
48
+ /**
49
+ * Emits a user metric to the host. The payload is a protobuf-encoded
50
+ * `workflows.v2.WorkflowUserMetric` message.
51
+ * @param payload - protobuf-encoded WorkflowUserMetric bytes
52
+ * @returns 0 on success, negative on error (rate-limited, oversized, invalid name, etc.)
53
+ */
54
+ function emitMetric(payload: Uint8Array): number
55
+
48
56
  /**
49
57
  * Sends a response back to the host
50
58
  * @param response - bytes response
@@ -5,6 +5,7 @@ export declare const hostBindings: {
5
5
  getSecrets: (args_0: Uint8Array<ArrayBufferLike> | Uint8Array<ArrayBuffer>, args_1: number, ...args: unknown[]) => any;
6
6
  awaitSecrets: (args_0: Uint8Array<ArrayBufferLike> | Uint8Array<ArrayBuffer>, args_1: number, ...args: unknown[]) => Uint8Array<ArrayBufferLike> | Uint8Array<ArrayBuffer>;
7
7
  log: (args_0: string, ...args: unknown[]) => void;
8
+ emitMetric: (args_0: Uint8Array<ArrayBufferLike> | Uint8Array<ArrayBuffer>, ...args: unknown[]) => number;
8
9
  sendResponse: (args_0: Uint8Array<ArrayBufferLike> | Uint8Array<ArrayBuffer>, ...args: unknown[]) => number;
9
10
  switchModes: (args_0: Mode, ...args: unknown[]) => void;
10
11
  versionV2: (...args: unknown[]) => void;
@@ -27,6 +27,10 @@ const globalHostBindingsSchema = z.object({
27
27
  .returns(z.union([z.instanceof(Uint8Array), z.custom()])),
28
28
  getWasiArgs: z.function().args().returns(z.string()),
29
29
  now: z.function().args().returns(z.number()),
30
+ emitMetric: z
31
+ .function()
32
+ .args(z.union([z.instanceof(Uint8Array), z.custom()]))
33
+ .returns(z.number()),
30
34
  });
31
35
  // Validate global host functions at runtime
32
36
  const validateGlobalHostBindings = () => {
@@ -56,4 +56,7 @@ class WasmRuntimeHelpers {
56
56
  log(message) {
57
57
  hostBindings.log(message);
58
58
  }
59
+ emitMetric(payload) {
60
+ return hostBindings.emitMetric(payload) >= 0;
61
+ }
59
62
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@chainlink/cre-sdk",
3
- "version": "1.6.0-alpha.4",
3
+ "version": "1.6.0-alpha.5",
4
4
  "type": "module",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -60,7 +60,7 @@
60
60
  "dependencies": {
61
61
  "@bufbuild/protobuf": "2.6.3",
62
62
  "@bufbuild/protoc-gen-es": "2.6.3",
63
- "@chainlink/cre-sdk-javy-plugin": "1.6.0-alpha.4",
63
+ "@chainlink/cre-sdk-javy-plugin": "1.6.0-alpha.5",
64
64
  "@standard-schema/spec": "1.0.0",
65
65
  "viem": "2.34.0",
66
66
  "zod": "3.25.76"
@@ -1,5 +1,7 @@
1
1
  import { rmSync } from 'node:fs'
2
+ import { file_capabilities_blockchain_aptos_v1alpha_client } from '@cre/generated/capabilities/blockchain/aptos/v1alpha/client_pb'
2
3
  import { file_capabilities_blockchain_evm_v1alpha_client } from '@cre/generated/capabilities/blockchain/evm/v1alpha/client_pb'
4
+ import { file_capabilities_blockchain_solana_v1alpha_client } from '@cre/generated/capabilities/blockchain/solana/v1alpha/client_pb'
3
5
  import { file_capabilities_internal_actionandtrigger_v1_action_and_trigger } from '@cre/generated/capabilities/internal/actionandtrigger/v1/action_and_trigger_pb'
4
6
  import { file_capabilities_internal_basicaction_v1_basic_action } from '@cre/generated/capabilities/internal/basicaction/v1/basic_action_pb'
5
7
  import { file_capabilities_internal_basictrigger_v1_basic_trigger } from '@cre/generated/capabilities/internal/basictrigger/v1/basic_trigger_pb'
@@ -63,6 +65,16 @@ export const main = () => {
63
65
  ...generateMocks(file_capabilities_blockchain_evm_v1alpha_client, TEST_GENERATED_DIR),
64
66
  )
65
67
 
68
+ generateSdk(file_capabilities_blockchain_aptos_v1alpha_client, './src/generated-sdk')
69
+ allMockExports.push(
70
+ ...generateMocks(file_capabilities_blockchain_aptos_v1alpha_client, TEST_GENERATED_DIR),
71
+ )
72
+
73
+ generateSdk(file_capabilities_blockchain_solana_v1alpha_client, './src/generated-sdk')
74
+ allMockExports.push(
75
+ ...generateMocks(file_capabilities_blockchain_solana_v1alpha_client, TEST_GENERATED_DIR),
76
+ )
77
+
66
78
  generateSdk(file_capabilities_networking_http_v1alpha_client, './src/generated-sdk')
67
79
  allMockExports.push(
68
80
  ...generateMocks(file_capabilities_networking_http_v1alpha_client, TEST_GENERATED_DIR),