@chainlink/cre-sdk 1.6.0-alpha.5 → 1.7.0-alpha.1
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.
- package/dist/sdk/cre/index.d.ts +0 -6
- package/dist/sdk/cre/index.js +0 -8
- package/dist/sdk/errors.d.ts +5 -0
- package/dist/sdk/errors.js +10 -0
- package/dist/sdk/impl/runtime-impl.d.ts +8 -12
- package/dist/sdk/impl/runtime-impl.js +61 -33
- package/dist/sdk/runtime.d.ts +1 -3
- package/dist/sdk/test/generated/index.d.ts +0 -2
- package/dist/sdk/test/generated/index.js +0 -2
- package/dist/sdk/testutils/test-runtime.d.ts +0 -2
- package/dist/sdk/testutils/test-runtime.js +0 -8
- package/dist/sdk/testutils/test-writer.d.ts +1 -7
- package/dist/sdk/testutils/test-writer.js +1 -13
- package/dist/sdk/types/global.d.ts +0 -8
- package/dist/sdk/wasm/host-bindings.d.ts +0 -1
- package/dist/sdk/wasm/host-bindings.js +0 -4
- package/dist/sdk/wasm/runner.js +1 -0
- package/dist/sdk/wasm/runtime.js +1 -4
- package/dist/sdk/workflow.d.ts +5 -2
- package/dist/sdk/workflow.js +0 -1
- package/package.json +2 -2
- package/scripts/src/generate-sdks.ts +0 -12
- package/dist/generated/capabilities/blockchain/aptos/v1alpha/client_pb.d.ts +0 -1023
- package/dist/generated/capabilities/blockchain/aptos/v1alpha/client_pb.js +0 -290
- package/dist/generated/capabilities/blockchain/solana/v1alpha/client_pb.d.ts +0 -2904
- package/dist/generated/capabilities/blockchain/solana/v1alpha/client_pb.js +0 -506
- package/dist/generated/workflows/v2/cre_info_pb.d.ts +0 -123
- package/dist/generated/workflows/v2/cre_info_pb.js +0 -17
- package/dist/generated/workflows/v2/workflow_key_pb.d.ts +0 -55
- package/dist/generated/workflows/v2/workflow_key_pb.js +0 -17
- package/dist/generated/workflows/v2/workflow_user_metric_pb.d.ts +0 -118
- package/dist/generated/workflows/v2/workflow_user_metric_pb.js +0 -41
- package/dist/generated-sdk/capabilities/blockchain/aptos/v1alpha/client_sdk_gen.d.ts +0 -52
- package/dist/generated-sdk/capabilities/blockchain/aptos/v1alpha/client_sdk_gen.js +0 -186
- package/dist/generated-sdk/capabilities/blockchain/solana/v1alpha/client_sdk_gen.d.ts +0 -92
- package/dist/generated-sdk/capabilities/blockchain/solana/v1alpha/client_sdk_gen.js +0 -343
- package/dist/sdk/test/generated/capabilities/blockchain/aptos/v1alpha/aptos_mock_gen.d.ts +0 -25
- package/dist/sdk/test/generated/capabilities/blockchain/aptos/v1alpha/aptos_mock_gen.js +0 -111
- package/dist/sdk/test/generated/capabilities/blockchain/solana/v1alpha/solana_mock_gen.d.ts +0 -33
- package/dist/sdk/test/generated/capabilities/blockchain/solana/v1alpha/solana_mock_gen.js +0 -178
- package/dist/sdk/utils/secrets-error.d.ts +0 -3
- package/dist/sdk/utils/secrets-error.js +0 -6
package/dist/sdk/cre/index.d.ts
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Public API for the CRE SDK.
|
|
3
3
|
*/
|
|
4
|
-
import { ClientCapability as AptosClient } from '../../generated-sdk/capabilities/blockchain/aptos/v1alpha/client_sdk_gen';
|
|
5
4
|
import { ClientCapability as EVMClient } from '../../generated-sdk/capabilities/blockchain/evm/v1alpha/client_sdk_gen';
|
|
6
|
-
import { ClientCapability as SolanaClient } from '../../generated-sdk/capabilities/blockchain/solana/v1alpha/client_sdk_gen';
|
|
7
5
|
import { ClientCapability as ConfidentialHTTPClient } from '../../generated-sdk/capabilities/networking/confidentialhttp/v1alpha/client_sdk_gen';
|
|
8
6
|
import { ClientCapability as HTTPClient } from '../../generated-sdk/capabilities/networking/http/v1alpha/client_sdk_gen';
|
|
9
7
|
import { HTTPCapability } from '../../generated-sdk/capabilities/networking/http/v1alpha/http_sdk_gen';
|
|
@@ -14,9 +12,7 @@ import { CronCapability } from '../../generated-sdk/capabilities/scheduler/cron/
|
|
|
14
12
|
export { type Log as EVMLog, TxStatus, } from '../../generated/capabilities/blockchain/evm/v1alpha/client_pb';
|
|
15
13
|
export type { Payload as HTTPPayload } from '../../generated/capabilities/networking/http/v1alpha/trigger_pb';
|
|
16
14
|
export type { Payload as CronPayload } from '../../generated/capabilities/scheduler/cron/v1/trigger_pb';
|
|
17
|
-
export { ClientCapability as AptosClient, type WriteCreReportRequest as AptosWriteCreReportRequest, type WriteCreReportRequestJson as AptosWriteCreReportRequestJson, } from '../../generated-sdk/capabilities/blockchain/aptos/v1alpha/client_sdk_gen';
|
|
18
15
|
export { ClientCapability as EVMClient, type WriteCreReportRequest, type WriteCreReportRequestJson, } from '../../generated-sdk/capabilities/blockchain/evm/v1alpha/client_sdk_gen';
|
|
19
|
-
export { ClientCapability as SolanaClient, type WriteCreReportRequest as SolanaWriteCreReportRequest, type WriteCreReportRequestJson as SolanaWriteCreReportRequestJson, } from '../../generated-sdk/capabilities/blockchain/solana/v1alpha/client_sdk_gen';
|
|
20
16
|
export { ClientCapability as ConfidentialHTTPClient } from '../../generated-sdk/capabilities/networking/confidentialhttp/v1alpha/client_sdk_gen';
|
|
21
17
|
export { ClientCapability as HTTPClient, type SendRequester as HTTPSendRequester, } from '../../generated-sdk/capabilities/networking/http/v1alpha/client_sdk_gen';
|
|
22
18
|
export { HTTPCapability } from '../../generated-sdk/capabilities/networking/http/v1alpha/http_sdk_gen';
|
|
@@ -30,8 +26,6 @@ export declare const cre: {
|
|
|
30
26
|
ConfidentialHTTPClient: typeof ConfidentialHTTPClient;
|
|
31
27
|
HTTPClient: typeof HTTPClient;
|
|
32
28
|
EVMClient: typeof EVMClient;
|
|
33
|
-
AptosClient: typeof AptosClient;
|
|
34
|
-
SolanaClient: typeof SolanaClient;
|
|
35
29
|
};
|
|
36
30
|
handler: <TRawTriggerOutput extends import("@bufbuild/protobuf").Message<string>, TTriggerOutput, TConfig, TResult>(trigger: import("../utils/triggers/trigger-interface").Trigger<TRawTriggerOutput, TTriggerOutput>, fn: import("../workflow").HandlerFn<TConfig, TTriggerOutput, TResult>) => import("../workflow").HandlerEntry<TConfig, TRawTriggerOutput, TTriggerOutput, TResult>;
|
|
37
31
|
};
|
package/dist/sdk/cre/index.js
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Public API for the CRE SDK.
|
|
3
3
|
*/
|
|
4
|
-
import { ClientCapability as AptosClient } from '../../generated-sdk/capabilities/blockchain/aptos/v1alpha/client_sdk_gen';
|
|
5
4
|
import { ClientCapability as EVMClient } from '../../generated-sdk/capabilities/blockchain/evm/v1alpha/client_sdk_gen';
|
|
6
|
-
import { ClientCapability as SolanaClient } from '../../generated-sdk/capabilities/blockchain/solana/v1alpha/client_sdk_gen';
|
|
7
5
|
import { ClientCapability as ConfidentialHTTPClient } from '../../generated-sdk/capabilities/networking/confidentialhttp/v1alpha/client_sdk_gen';
|
|
8
6
|
import { ClientCapability as HTTPClient } from '../../generated-sdk/capabilities/networking/http/v1alpha/client_sdk_gen';
|
|
9
7
|
import { HTTPCapability } from '../../generated-sdk/capabilities/networking/http/v1alpha/http_sdk_gen';
|
|
@@ -14,12 +12,8 @@ import { handler } from '../workflow';
|
|
|
14
12
|
* Public exports for the CRE SDK.
|
|
15
13
|
*/
|
|
16
14
|
export { TxStatus, } from '../../generated/capabilities/blockchain/evm/v1alpha/client_pb';
|
|
17
|
-
// Aptos Capability
|
|
18
|
-
export { ClientCapability as AptosClient, } from '../../generated-sdk/capabilities/blockchain/aptos/v1alpha/client_sdk_gen';
|
|
19
15
|
// EVM Capability
|
|
20
16
|
export { ClientCapability as EVMClient, } from '../../generated-sdk/capabilities/blockchain/evm/v1alpha/client_sdk_gen';
|
|
21
|
-
// Solana Capability
|
|
22
|
-
export { ClientCapability as SolanaClient, } from '../../generated-sdk/capabilities/blockchain/solana/v1alpha/client_sdk_gen';
|
|
23
17
|
// Confidential HTTP Capability
|
|
24
18
|
export { ClientCapability as ConfidentialHTTPClient } from '../../generated-sdk/capabilities/networking/confidentialhttp/v1alpha/client_sdk_gen';
|
|
25
19
|
// HTTP Capability
|
|
@@ -36,8 +30,6 @@ export const cre = {
|
|
|
36
30
|
ConfidentialHTTPClient,
|
|
37
31
|
HTTPClient,
|
|
38
32
|
EVMClient,
|
|
39
|
-
AptosClient,
|
|
40
|
-
SolanaClient,
|
|
41
33
|
},
|
|
42
34
|
handler,
|
|
43
35
|
};
|
package/dist/sdk/errors.d.ts
CHANGED
|
@@ -10,6 +10,11 @@ export declare class SecretsError extends Error {
|
|
|
10
10
|
error: string;
|
|
11
11
|
constructor(secretRequest: SecretRequest, error: string);
|
|
12
12
|
}
|
|
13
|
+
export declare class SecretsBatchError extends Error {
|
|
14
|
+
readonly secretRequests: SecretRequest[];
|
|
15
|
+
readonly error: string;
|
|
16
|
+
constructor(secretRequests: SecretRequest[], error: string);
|
|
17
|
+
}
|
|
13
18
|
export declare class NullReportError extends Error {
|
|
14
19
|
constructor();
|
|
15
20
|
}
|
package/dist/sdk/errors.js
CHANGED
|
@@ -20,6 +20,16 @@ export class SecretsError extends Error {
|
|
|
20
20
|
this.name = 'SecretsError';
|
|
21
21
|
}
|
|
22
22
|
}
|
|
23
|
+
export class SecretsBatchError extends Error {
|
|
24
|
+
secretRequests;
|
|
25
|
+
error;
|
|
26
|
+
constructor(secretRequests, error) {
|
|
27
|
+
super(`batch secret retrieval failed for ${secretRequests.length} request(s): ${error}. Verify the host response is complete and that the workflow has access to the requested secrets`);
|
|
28
|
+
this.secretRequests = secretRequests;
|
|
29
|
+
this.error = error;
|
|
30
|
+
this.name = 'SecretsBatchError';
|
|
31
|
+
}
|
|
32
|
+
}
|
|
23
33
|
export class NullReportError extends Error {
|
|
24
34
|
constructor() {
|
|
25
35
|
super('null report');
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type Message } from '@bufbuild/protobuf';
|
|
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';
|
|
2
|
+
import { type AwaitCapabilitiesRequest, type AwaitCapabilitiesResponse, type AwaitSecretsRequest, type AwaitSecretsResponse, type CapabilityRequest, type GetSecretsRequest, Mode, type Secret, type SecretRequest, type SecretRequestJson, type SecretResponse } from '../../generated/sdk/v1alpha/sdk_pb';
|
|
3
3
|
import type { BaseRuntime, CallCapabilityParams, NodeRuntime, ReportRequest, ReportRequestJson, Runtime } from '..';
|
|
4
4
|
import type { Report } from '../report';
|
|
5
5
|
import { type ConsensusAggregation, type PrimitiveTypes, type UnwrapOptions } from '../utils';
|
|
@@ -43,10 +43,7 @@ export declare class BaseRuntimeImpl<C> implements BaseRuntime<C> {
|
|
|
43
43
|
getNextCallId(): number;
|
|
44
44
|
now(): Date;
|
|
45
45
|
log(message: string): void;
|
|
46
|
-
emitMetric(name: string, value: number, type: MetricType, labels?: Record<string, string>): boolean;
|
|
47
46
|
}
|
|
48
|
-
/** Ergonomic union for {@link BaseRuntimeImpl.emitMetric}. */
|
|
49
|
-
export type MetricType = 'counter' | 'gauge';
|
|
50
47
|
/**
|
|
51
48
|
* It is used when a BFT guarantee cannot be provided automatically (e.g. calling a standard API).
|
|
52
49
|
* You tell each node to perform a task on its own.
|
|
@@ -85,10 +82,14 @@ export declare class RuntimeImpl<C> extends BaseRuntimeImpl<C> implements Runtim
|
|
|
85
82
|
private captureError;
|
|
86
83
|
private restoreDonMode;
|
|
87
84
|
private runConsensusAndWrap;
|
|
85
|
+
getSecrets(requests: Array<SecretRequest | SecretRequestJson>): {
|
|
86
|
+
result: () => SecretResponse[];
|
|
87
|
+
};
|
|
88
88
|
getSecret(request: SecretRequest | SecretRequestJson): {
|
|
89
89
|
result: () => Secret;
|
|
90
90
|
};
|
|
91
|
-
private
|
|
91
|
+
private awaitAndUnwrapSecrets;
|
|
92
|
+
private unwrapSingleSecretResult;
|
|
92
93
|
/**
|
|
93
94
|
* Generates a report via consensus mechanism.
|
|
94
95
|
*/
|
|
@@ -105,8 +106,8 @@ export interface RuntimeHelpers {
|
|
|
105
106
|
call(request: CapabilityRequest): boolean;
|
|
106
107
|
/** Awaits capability responses. Blocks until responses are ready. */
|
|
107
108
|
await(request: AwaitCapabilitiesRequest, maxResponseSize: bigint): AwaitCapabilitiesResponse;
|
|
108
|
-
/** Requests secrets from host.
|
|
109
|
-
getSecrets(request: GetSecretsRequest, maxResponseSize: bigint):
|
|
109
|
+
/** Requests secrets from host. Throws if host rejects the request. */
|
|
110
|
+
getSecrets(request: GetSecretsRequest, maxResponseSize: bigint): void;
|
|
110
111
|
/** Awaits secret responses. Blocks until secrets are ready. */
|
|
111
112
|
awaitSecrets(request: AwaitSecretsRequest, maxResponseSize: bigint): AwaitSecretsResponse;
|
|
112
113
|
/** Switches execution mode (DON vs Node). Affects available operations. */
|
|
@@ -115,9 +116,4 @@ export interface RuntimeHelpers {
|
|
|
115
116
|
now(): number;
|
|
116
117
|
/** Logs a message to the host environment. */
|
|
117
118
|
log(message: string): void;
|
|
118
|
-
/**
|
|
119
|
-
* Emits a user metric to the host. Payload is a protobuf-encoded
|
|
120
|
-
* `workflows.v2.WorkflowUserMetric`. Returns false if the host rejected it.
|
|
121
|
-
*/
|
|
122
|
-
emitMetric(payload: Uint8Array): boolean;
|
|
123
119
|
}
|
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
import { create
|
|
1
|
+
import { create } from '@bufbuild/protobuf';
|
|
2
2
|
import { anyPack, anyUnpack } from '@bufbuild/protobuf/wkt';
|
|
3
3
|
import { AwaitCapabilitiesRequestSchema, AwaitSecretsRequestSchema, CapabilityRequestSchema, GetSecretsRequestSchema, Mode, SecretRequestSchema, SimpleConsensusInputsSchema, } from '../../generated/sdk/v1alpha/sdk_pb';
|
|
4
|
-
import { UserMetricType, WorkflowUserMetricSchema, } from '../../generated/workflows/v2/workflow_user_metric_pb';
|
|
5
4
|
import { ConsensusCapability } from '../../generated-sdk/capabilities/internal/consensus/v1alpha/consensus_sdk_gen';
|
|
6
5
|
import { Value, } from '../utils';
|
|
7
6
|
import { CapabilityError } from '../utils/capabilities/capability-error';
|
|
8
|
-
import { DonModeError, NodeModeError, SecretsError } from '../errors';
|
|
7
|
+
import { DonModeError, NodeModeError, SecretsBatchError, SecretsError } from '../errors';
|
|
9
8
|
/**
|
|
10
9
|
* Base implementation shared by DON and Node runtimes.
|
|
11
10
|
*
|
|
@@ -140,20 +139,7 @@ export class BaseRuntimeImpl {
|
|
|
140
139
|
log(message) {
|
|
141
140
|
this.helpers.log(message);
|
|
142
141
|
}
|
|
143
|
-
emitMetric(name, value, type, labels) {
|
|
144
|
-
const metric = create(WorkflowUserMetricSchema, {
|
|
145
|
-
name,
|
|
146
|
-
value,
|
|
147
|
-
type: METRIC_TYPE_TO_PROTO[type],
|
|
148
|
-
labels: labels ?? {},
|
|
149
|
-
});
|
|
150
|
-
return this.helpers.emitMetric(toBinary(WorkflowUserMetricSchema, metric));
|
|
151
|
-
}
|
|
152
142
|
}
|
|
153
|
-
const METRIC_TYPE_TO_PROTO = {
|
|
154
|
-
counter: UserMetricType.COUNTER,
|
|
155
|
-
gauge: UserMetricType.GAUGE,
|
|
156
|
-
};
|
|
157
143
|
/**
|
|
158
144
|
* It is used when a BFT guarantee cannot be provided automatically (e.g. calling a standard API).
|
|
159
145
|
* You tell each node to perform a task on its own.
|
|
@@ -259,7 +245,7 @@ export class RuntimeImpl extends BaseRuntimeImpl {
|
|
|
259
245
|
},
|
|
260
246
|
};
|
|
261
247
|
}
|
|
262
|
-
|
|
248
|
+
getSecrets(requests) {
|
|
263
249
|
// Enforce mode restrictions
|
|
264
250
|
if (this.modeError) {
|
|
265
251
|
return {
|
|
@@ -268,48 +254,90 @@ export class RuntimeImpl extends BaseRuntimeImpl {
|
|
|
268
254
|
},
|
|
269
255
|
};
|
|
270
256
|
}
|
|
271
|
-
// Normalize
|
|
272
|
-
const
|
|
257
|
+
// Normalize requests (accept both protobuf and JSON formats)
|
|
258
|
+
const normalizedRequests = requests.map((request) => request.$typeName
|
|
273
259
|
? request
|
|
274
|
-
: create(SecretRequestSchema, request);
|
|
260
|
+
: create(SecretRequestSchema, request));
|
|
261
|
+
if (normalizedRequests.length === 0) {
|
|
262
|
+
return {
|
|
263
|
+
result: () => [],
|
|
264
|
+
};
|
|
265
|
+
}
|
|
275
266
|
// Allocate callback ID and send request
|
|
276
267
|
const id = this.nextCallId;
|
|
277
268
|
this.nextCallId++;
|
|
278
269
|
const secretsReq = create(GetSecretsRequestSchema, {
|
|
279
270
|
callbackId: id,
|
|
280
|
-
requests:
|
|
271
|
+
requests: normalizedRequests,
|
|
281
272
|
});
|
|
282
|
-
|
|
273
|
+
try {
|
|
274
|
+
this.helpers.getSecrets(secretsReq, this.maxResponseSize);
|
|
275
|
+
}
|
|
276
|
+
catch (err) {
|
|
277
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
283
278
|
return {
|
|
284
279
|
result: () => {
|
|
285
|
-
throw new
|
|
280
|
+
throw new SecretsBatchError(normalizedRequests, message);
|
|
286
281
|
},
|
|
287
282
|
};
|
|
288
283
|
}
|
|
289
284
|
// Return lazy result
|
|
290
285
|
return {
|
|
291
|
-
result: () => this.
|
|
286
|
+
result: () => this.awaitAndUnwrapSecrets(id, normalizedRequests),
|
|
292
287
|
};
|
|
293
288
|
}
|
|
294
|
-
|
|
289
|
+
getSecret(request) {
|
|
290
|
+
const secretRequest = request.$typeName
|
|
291
|
+
? request
|
|
292
|
+
: create(SecretRequestSchema, request);
|
|
293
|
+
const getSecretsCall = this.getSecrets([secretRequest]);
|
|
294
|
+
return {
|
|
295
|
+
result: () => {
|
|
296
|
+
let responseList;
|
|
297
|
+
try {
|
|
298
|
+
responseList = getSecretsCall.result();
|
|
299
|
+
}
|
|
300
|
+
catch (err) {
|
|
301
|
+
if (err instanceof SecretsBatchError) {
|
|
302
|
+
throw new SecretsError(secretRequest, err.error);
|
|
303
|
+
}
|
|
304
|
+
throw err;
|
|
305
|
+
}
|
|
306
|
+
return this.unwrapSingleSecretResult(responseList, secretRequest);
|
|
307
|
+
},
|
|
308
|
+
};
|
|
309
|
+
}
|
|
310
|
+
awaitAndUnwrapSecrets(id, requests) {
|
|
295
311
|
const awaitRequest = create(AwaitSecretsRequestSchema, { ids: [id] });
|
|
296
|
-
|
|
312
|
+
let awaitResponse;
|
|
313
|
+
try {
|
|
314
|
+
awaitResponse = this.helpers.awaitSecrets(awaitRequest, this.maxResponseSize);
|
|
315
|
+
}
|
|
316
|
+
catch (err) {
|
|
317
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
318
|
+
throw new SecretsBatchError(requests, message);
|
|
319
|
+
}
|
|
297
320
|
const secretsResponse = awaitResponse.responses[id];
|
|
298
321
|
if (!secretsResponse) {
|
|
299
|
-
throw new
|
|
322
|
+
throw new SecretsBatchError(requests, 'no response');
|
|
323
|
+
}
|
|
324
|
+
if (secretsResponse.responses.length !== requests.length) {
|
|
325
|
+
throw new SecretsBatchError(requests, 'invalid value returned from host');
|
|
300
326
|
}
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
327
|
+
return secretsResponse.responses;
|
|
328
|
+
}
|
|
329
|
+
unwrapSingleSecretResult(responseList, request) {
|
|
330
|
+
if (responseList.length !== 1) {
|
|
331
|
+
throw new SecretsError(request, 'invalid value returned from host');
|
|
304
332
|
}
|
|
305
|
-
const response =
|
|
333
|
+
const response = responseList[0].response;
|
|
306
334
|
switch (response.case) {
|
|
307
335
|
case 'secret':
|
|
308
336
|
return response.value;
|
|
309
337
|
case 'error':
|
|
310
|
-
throw new SecretsError(
|
|
338
|
+
throw new SecretsError(request, response.value.error);
|
|
311
339
|
default:
|
|
312
|
-
throw new SecretsError(
|
|
340
|
+
throw new SecretsError(request, 'cannot unmarshal returned value from host');
|
|
313
341
|
}
|
|
314
342
|
}
|
|
315
343
|
/**
|
package/dist/sdk/runtime.d.ts
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import type { Message } from '@bufbuild/protobuf';
|
|
2
2
|
import type { GenMessage } from '@bufbuild/protobuf/codegenv2';
|
|
3
3
|
import type { ReportRequest, ReportRequestJson } from '../generated/sdk/v1alpha/sdk_pb';
|
|
4
|
-
import type { MetricType } from './impl/runtime-impl';
|
|
5
4
|
import type { Report } from './report';
|
|
6
5
|
import type { ConsensusAggregation, PrimitiveTypes, UnwrapOptions } from './utils';
|
|
7
6
|
import type { SecretsProvider } from '.';
|
|
8
|
-
export type { ReportRequest, ReportRequestJson
|
|
7
|
+
export type { ReportRequest, ReportRequestJson };
|
|
9
8
|
export type CallCapabilityParams<I extends Message, O extends Message> = {
|
|
10
9
|
capabilityId: string;
|
|
11
10
|
method: string;
|
|
@@ -24,7 +23,6 @@ export interface BaseRuntime<C> {
|
|
|
24
23
|
};
|
|
25
24
|
now(): Date;
|
|
26
25
|
log(message: string): void;
|
|
27
|
-
emitMetric(name: string, value: number, type: MetricType, labels?: Record<string, string>): boolean;
|
|
28
26
|
}
|
|
29
27
|
/**
|
|
30
28
|
* Runtime for Node mode execution.
|
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
/** Auto-generated barrel of capability mocks. Do not edit. */
|
|
2
|
-
export { AptosMock } from './capabilities/blockchain/aptos/v1alpha/aptos_mock_gen';
|
|
3
2
|
export { EvmMock } from './capabilities/blockchain/evm/v1alpha/evm_mock_gen';
|
|
4
|
-
export { SolanaMock } from './capabilities/blockchain/solana/v1alpha/solana_mock_gen';
|
|
5
3
|
export { BasicTestActionTriggerMock } from './capabilities/internal/actionandtrigger/v1/basic_test_action_trigger_mock_gen';
|
|
6
4
|
export { BasicTestActionMock } from './capabilities/internal/basicaction/v1/basic_test_action_mock_gen';
|
|
7
5
|
export { ConsensusMock } from './capabilities/internal/consensus/v1alpha/consensus_mock_gen';
|
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
/** Auto-generated barrel of capability mocks. Do not edit. */
|
|
2
|
-
export { AptosMock } from './capabilities/blockchain/aptos/v1alpha/aptos_mock_gen';
|
|
3
2
|
export { EvmMock } from './capabilities/blockchain/evm/v1alpha/evm_mock_gen';
|
|
4
|
-
export { SolanaMock } from './capabilities/blockchain/solana/v1alpha/solana_mock_gen';
|
|
5
3
|
export { BasicTestActionTriggerMock } from './capabilities/internal/actionandtrigger/v1/basic_test_action_trigger_mock_gen';
|
|
6
4
|
export { BasicTestActionMock } from './capabilities/internal/basicaction/v1/basic_test_action_mock_gen';
|
|
7
5
|
export { ConsensusMock } from './capabilities/internal/consensus/v1alpha/consensus_mock_gen';
|
|
@@ -3,7 +3,6 @@
|
|
|
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';
|
|
7
6
|
import type { RuntimeHelpers } from '../impl/runtime-impl';
|
|
8
7
|
import { RuntimeImpl } from '../impl/runtime-impl';
|
|
9
8
|
import { TestWriter } from './test-writer';
|
|
@@ -81,6 +80,5 @@ export declare class TestRuntime extends RuntimeImpl<unknown> {
|
|
|
81
80
|
private readonly state;
|
|
82
81
|
constructor(helpers: RuntimeHelpers, maxResponseSize: bigint, testWriter: TestWriter, state: TestRuntimeState);
|
|
83
82
|
getLogs(): string[];
|
|
84
|
-
getMetrics(): WorkflowUserMetric[];
|
|
85
83
|
setTimeProvider(timeProvider: () => number): void;
|
|
86
84
|
}
|
|
@@ -217,7 +217,6 @@ function createTestRuntimeHelpers(registry, secrets, testWriter, state, _maxResp
|
|
|
217
217
|
}
|
|
218
218
|
}
|
|
219
219
|
pendingSecrets.set(req.callbackId, resp);
|
|
220
|
-
return true;
|
|
221
220
|
},
|
|
222
221
|
awaitSecrets(request, _maxResponseSize) {
|
|
223
222
|
const responses = {};
|
|
@@ -236,10 +235,6 @@ function createTestRuntimeHelpers(registry, secrets, testWriter, state, _maxResp
|
|
|
236
235
|
log(message) {
|
|
237
236
|
testWriter.log(message);
|
|
238
237
|
},
|
|
239
|
-
emitMetric(payload) {
|
|
240
|
-
testWriter.emitMetric(payload);
|
|
241
|
-
return true;
|
|
242
|
-
},
|
|
243
238
|
};
|
|
244
239
|
}
|
|
245
240
|
/**
|
|
@@ -311,9 +306,6 @@ export class TestRuntime extends RuntimeImpl {
|
|
|
311
306
|
getLogs() {
|
|
312
307
|
return this.testWriter.getLogs();
|
|
313
308
|
}
|
|
314
|
-
getMetrics() {
|
|
315
|
-
return this.testWriter.getMetrics();
|
|
316
|
-
}
|
|
317
309
|
setTimeProvider(timeProvider) {
|
|
318
310
|
this.state.timeProvider = timeProvider;
|
|
319
311
|
}
|
|
@@ -1,19 +1,13 @@
|
|
|
1
|
-
import { type WorkflowUserMetric } from '../../generated/workflows/v2/workflow_user_metric_pb';
|
|
2
1
|
/**
|
|
3
2
|
* In-memory log sink for tests. Captures messages so tests can assert on log output.
|
|
4
3
|
* Equivalent to Go's cre/testutils/test_writer.go.
|
|
5
4
|
*/
|
|
6
5
|
export declare class TestWriter {
|
|
7
6
|
private logs;
|
|
8
|
-
private metrics;
|
|
9
7
|
/** Appends a message to the captured log buffer. */
|
|
10
8
|
log(message: string): void;
|
|
11
9
|
/** Returns a copy of all captured log messages in order. */
|
|
12
10
|
getLogs(): string[];
|
|
13
|
-
/**
|
|
14
|
-
emitMetric(payload: Uint8Array): void;
|
|
15
|
-
/** Returns captured metric payloads decoded as `WorkflowUserMetric` protos. */
|
|
16
|
-
getMetrics(): WorkflowUserMetric[];
|
|
17
|
-
/** Clears captured logs and metrics. */
|
|
11
|
+
/** Clears the captured log buffer. */
|
|
18
12
|
clear(): void;
|
|
19
13
|
}
|
|
@@ -1,12 +1,9 @@
|
|
|
1
|
-
import { fromBinary } from '@bufbuild/protobuf';
|
|
2
|
-
import { WorkflowUserMetricSchema, } from '../../generated/workflows/v2/workflow_user_metric_pb';
|
|
3
1
|
/**
|
|
4
2
|
* In-memory log sink for tests. Captures messages so tests can assert on log output.
|
|
5
3
|
* Equivalent to Go's cre/testutils/test_writer.go.
|
|
6
4
|
*/
|
|
7
5
|
export class TestWriter {
|
|
8
6
|
logs = [];
|
|
9
|
-
metrics = [];
|
|
10
7
|
/** Appends a message to the captured log buffer. */
|
|
11
8
|
log(message) {
|
|
12
9
|
this.logs.push(message);
|
|
@@ -15,17 +12,8 @@ export class TestWriter {
|
|
|
15
12
|
getLogs() {
|
|
16
13
|
return [...this.logs];
|
|
17
14
|
}
|
|
18
|
-
/**
|
|
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. */
|
|
15
|
+
/** Clears the captured log buffer. */
|
|
27
16
|
clear() {
|
|
28
17
|
this.logs = [];
|
|
29
|
-
this.metrics = [];
|
|
30
18
|
}
|
|
31
19
|
}
|
|
@@ -45,14 +45,6 @@ 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
|
-
|
|
56
48
|
/**
|
|
57
49
|
* Sends a response back to the host
|
|
58
50
|
* @param response - bytes response
|
|
@@ -5,7 +5,6 @@ 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;
|
|
9
8
|
sendResponse: (args_0: Uint8Array<ArrayBufferLike> | Uint8Array<ArrayBuffer>, ...args: unknown[]) => number;
|
|
10
9
|
switchModes: (args_0: Mode, ...args: unknown[]) => void;
|
|
11
10
|
versionV2: (...args: unknown[]) => void;
|
|
@@ -27,10 +27,6 @@ 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()),
|
|
34
30
|
});
|
|
35
31
|
// Validate global host functions at runtime
|
|
36
32
|
const validateGlobalHostBindings = () => {
|
package/dist/sdk/wasm/runner.js
CHANGED
package/dist/sdk/wasm/runtime.js
CHANGED
|
@@ -42,7 +42,7 @@ class WasmRuntimeHelpers {
|
|
|
42
42
|
}
|
|
43
43
|
getSecrets(request, maxResponseSize) {
|
|
44
44
|
const responseSize = toI32ResponseSize(maxResponseSize);
|
|
45
|
-
|
|
45
|
+
hostBindings.getSecrets(toBinary(GetSecretsRequestSchema, request), responseSize);
|
|
46
46
|
}
|
|
47
47
|
awaitSecrets(request, maxResponseSize) {
|
|
48
48
|
const responseSize = toI32ResponseSize(maxResponseSize);
|
|
@@ -56,7 +56,4 @@ class WasmRuntimeHelpers {
|
|
|
56
56
|
log(message) {
|
|
57
57
|
hostBindings.log(message);
|
|
58
58
|
}
|
|
59
|
-
emitMetric(payload) {
|
|
60
|
-
return hostBindings.emitMetric(payload) >= 0;
|
|
61
|
-
}
|
|
62
59
|
}
|
package/dist/sdk/workflow.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Message } from '@bufbuild/protobuf';
|
|
2
|
-
import type { Secret, SecretRequest, SecretRequestJson } from '../generated/sdk/v1alpha/sdk_pb';
|
|
3
|
-
import {
|
|
2
|
+
import type { Secret, SecretRequest, SecretRequestJson, SecretResponse } from '../generated/sdk/v1alpha/sdk_pb';
|
|
3
|
+
import type { Runtime } from './runtime';
|
|
4
4
|
import type { Trigger } from './utils/triggers/trigger-interface';
|
|
5
5
|
import type { CreSerializable } from './utils';
|
|
6
6
|
export type HandlerFn<TConfig, TTriggerOutput, TResult> = (runtime: Runtime<TConfig>, triggerOutput: TTriggerOutput) => Promise<CreSerializable<TResult>> | CreSerializable<TResult>;
|
|
@@ -11,6 +11,9 @@ export interface HandlerEntry<TConfig, TRawTriggerOutput extends Message<string>
|
|
|
11
11
|
export type Workflow<TConfig> = ReadonlyArray<HandlerEntry<TConfig, any, any, any>>;
|
|
12
12
|
export declare const handler: <TRawTriggerOutput extends Message<string>, TTriggerOutput, TConfig, TResult>(trigger: Trigger<TRawTriggerOutput, TTriggerOutput>, fn: HandlerFn<TConfig, TTriggerOutput, TResult>) => HandlerEntry<TConfig, TRawTriggerOutput, TTriggerOutput, TResult>;
|
|
13
13
|
export type SecretsProvider = {
|
|
14
|
+
getSecrets(requests: Array<SecretRequest | SecretRequestJson>): {
|
|
15
|
+
result: () => SecretResponse[];
|
|
16
|
+
};
|
|
14
17
|
getSecret(request: SecretRequest | SecretRequestJson): {
|
|
15
18
|
result: () => Secret;
|
|
16
19
|
};
|
package/dist/sdk/workflow.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@chainlink/cre-sdk",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.7.0-alpha.1",
|
|
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
|
|
63
|
+
"@chainlink/cre-sdk-javy-plugin": "1.6.0",
|
|
64
64
|
"@standard-schema/spec": "1.0.0",
|
|
65
65
|
"viem": "2.34.0",
|
|
66
66
|
"zod": "3.25.76"
|
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
import { rmSync } from 'node:fs'
|
|
2
|
-
import { file_capabilities_blockchain_aptos_v1alpha_client } from '@cre/generated/capabilities/blockchain/aptos/v1alpha/client_pb'
|
|
3
2
|
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'
|
|
5
3
|
import { file_capabilities_internal_actionandtrigger_v1_action_and_trigger } from '@cre/generated/capabilities/internal/actionandtrigger/v1/action_and_trigger_pb'
|
|
6
4
|
import { file_capabilities_internal_basicaction_v1_basic_action } from '@cre/generated/capabilities/internal/basicaction/v1/basic_action_pb'
|
|
7
5
|
import { file_capabilities_internal_basictrigger_v1_basic_trigger } from '@cre/generated/capabilities/internal/basictrigger/v1/basic_trigger_pb'
|
|
@@ -65,16 +63,6 @@ export const main = () => {
|
|
|
65
63
|
...generateMocks(file_capabilities_blockchain_evm_v1alpha_client, TEST_GENERATED_DIR),
|
|
66
64
|
)
|
|
67
65
|
|
|
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
|
-
|
|
78
66
|
generateSdk(file_capabilities_networking_http_v1alpha_client, './src/generated-sdk')
|
|
79
67
|
allMockExports.push(
|
|
80
68
|
...generateMocks(file_capabilities_networking_http_v1alpha_client, TEST_GENERATED_DIR),
|