@avaprotocol/sdk-js 2.6.12 → 2.7.0
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/CHANGELOG.md +19 -0
- package/dist/index.d.ts +13 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +811 -281
- package/dist/index.mjs +811 -281
- package/dist/models/step.d.ts +29 -0
- package/dist/models/step.d.ts.map +1 -1
- package/dist/models/step.js +52 -39
- package/dist/utils.d.ts +77 -0
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +19 -0
- package/package.json +2 -2
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import * as avs_pb from "@/grpc_codegen/avs_pb";
|
|
2
|
+
import { StepProps, OutputDataProps } from "@avaprotocol/types";
|
|
3
|
+
declare class Step implements StepProps {
|
|
4
|
+
id: string;
|
|
5
|
+
type: string;
|
|
6
|
+
name: string;
|
|
7
|
+
success: boolean;
|
|
8
|
+
error: string;
|
|
9
|
+
log: string;
|
|
10
|
+
inputsList: string[];
|
|
11
|
+
config?: any;
|
|
12
|
+
output: OutputDataProps;
|
|
13
|
+
startAt: number;
|
|
14
|
+
endAt: number;
|
|
15
|
+
metadata?: any;
|
|
16
|
+
executionContext?: any;
|
|
17
|
+
constructor(props: StepProps);
|
|
18
|
+
/**
|
|
19
|
+
* Convert Step instance to plain object (StepProps)
|
|
20
|
+
* This is useful for serialization, especially with Next.js Server Components
|
|
21
|
+
*/
|
|
22
|
+
toJson(): StepProps;
|
|
23
|
+
static getOutput(step: avs_pb.Execution.Step): OutputDataProps;
|
|
24
|
+
private static extractOutputData;
|
|
25
|
+
private static getOutputDataCase;
|
|
26
|
+
static fromResponse(step: avs_pb.Execution.Step): Step;
|
|
27
|
+
}
|
|
28
|
+
export default Step;
|
|
29
|
+
//# sourceMappingURL=step.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"step.d.ts","sourceRoot":"","sources":["../../src/models/step.ts"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AM,CAAC,SAAS,CAAC,IAAI,GAAG,eAAe;IAoC9D,OAAO,CAAC,MAAM,CAAC,iBAAiB;IAiEhC,OAAO,CAAC,MAAM,CAAC,iBAAiB;IAkChC,MAAM,CAAC,YAAY,CAAC,IAAI,EAAE,MAAM,CAAC,SAAS,CAAC,IAAI,GAAG,IAAI;CAuGvD;AAED,eAAe,IAAI,CAAC"}
|
package/dist/models/step.js
CHANGED
|
@@ -13,6 +13,8 @@ class Step {
|
|
|
13
13
|
this.output = props.output;
|
|
14
14
|
this.startAt = props.startAt;
|
|
15
15
|
this.endAt = props.endAt;
|
|
16
|
+
this.metadata = props.metadata;
|
|
17
|
+
this.executionContext = props.executionContext;
|
|
16
18
|
}
|
|
17
19
|
/**
|
|
18
20
|
* Convert Step instance to plain object (StepProps)
|
|
@@ -31,60 +33,41 @@ class Step {
|
|
|
31
33
|
output: this.output,
|
|
32
34
|
startAt: this.startAt,
|
|
33
35
|
endAt: this.endAt,
|
|
36
|
+
metadata: this.metadata,
|
|
37
|
+
executionContext: this.executionContext,
|
|
34
38
|
};
|
|
35
39
|
}
|
|
36
40
|
static getOutput(step) {
|
|
37
|
-
|
|
38
|
-
|
|
41
|
+
// Always return Output.data; step-level metadata is separate.
|
|
42
|
+
const outputObj = this.extractOutputData(step);
|
|
43
|
+
if (!outputObj)
|
|
39
44
|
return null;
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
const result = {};
|
|
46
|
-
// Extract data field (decoded events/results)
|
|
47
|
-
if (typeof outputData.getData === "function") {
|
|
48
|
-
result.data = convertProtobufValueToJs(outputData.getData());
|
|
49
|
-
}
|
|
50
|
-
// Extract metadata field (method execution details)
|
|
51
|
-
if (typeof outputData.getMetadata === "function") {
|
|
52
|
-
result.metadata = convertProtobufValueToJs(outputData.getMetadata());
|
|
53
|
-
}
|
|
54
|
-
// Return both data and metadata for ContractWrite and ContractRead
|
|
55
|
-
// This ensures consistent structure between simulated and deployed workflow execution
|
|
56
|
-
return result;
|
|
57
|
-
}
|
|
58
|
-
catch (error) {
|
|
59
|
-
console.warn("Failed to convert ContractWrite/ContractRead protobuf to JavaScript:", error);
|
|
60
|
-
return outputData.getData ? outputData.getData() : null;
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
// STANDARDIZED Direct Mapping - ALL other triggers and nodes use the same logic
|
|
64
|
-
if (typeof outputData.hasData === "function" && outputData.hasData()) {
|
|
45
|
+
// Protobuf accessor path
|
|
46
|
+
if (typeof outputObj.getData === "function") {
|
|
47
|
+
const val = outputObj.getData();
|
|
48
|
+
if (!val)
|
|
49
|
+
return null;
|
|
65
50
|
try {
|
|
66
|
-
return convertProtobufValueToJs(
|
|
51
|
+
return convertProtobufValueToJs(val);
|
|
67
52
|
}
|
|
68
53
|
catch (error) {
|
|
69
54
|
console.warn("Failed to convert protobuf Value to JavaScript:", error);
|
|
70
|
-
return
|
|
55
|
+
return val;
|
|
71
56
|
}
|
|
72
57
|
}
|
|
73
|
-
|
|
58
|
+
// Plain object fallback
|
|
59
|
+
const data = outputObj.data;
|
|
60
|
+
if (data) {
|
|
74
61
|
try {
|
|
75
|
-
return
|
|
62
|
+
return typeof data.getKindCase === "function"
|
|
63
|
+
? convertProtobufValueToJs(data)
|
|
64
|
+
: data;
|
|
76
65
|
}
|
|
77
66
|
catch (error) {
|
|
78
|
-
console.warn("Failed to convert
|
|
79
|
-
return
|
|
67
|
+
console.warn("Failed to convert plain object Value to JavaScript:", error);
|
|
68
|
+
return data;
|
|
80
69
|
}
|
|
81
70
|
}
|
|
82
|
-
else if (outputData.data) {
|
|
83
|
-
// For plain objects, try to convert or use directly
|
|
84
|
-
return typeof outputData.data.getKindCase === "function"
|
|
85
|
-
? convertProtobufValueToJs(outputData.data)
|
|
86
|
-
: outputData.data;
|
|
87
|
-
}
|
|
88
71
|
return null;
|
|
89
72
|
}
|
|
90
73
|
static extractOutputData(step) {
|
|
@@ -226,6 +209,34 @@ class Step {
|
|
|
226
209
|
const getEndAt = () => typeof step.getEndAt === "function"
|
|
227
210
|
? step.getEndAt()
|
|
228
211
|
: step.endAt;
|
|
212
|
+
// Extract step-level metadata if present (per protobuf: Execution.Step.metadata)
|
|
213
|
+
let stepMetadata = undefined;
|
|
214
|
+
if (typeof step.getMetadata === "function" &&
|
|
215
|
+
step.getMetadata()) {
|
|
216
|
+
try {
|
|
217
|
+
stepMetadata = convertProtobufValueToJs(step.getMetadata());
|
|
218
|
+
}
|
|
219
|
+
catch (e) {
|
|
220
|
+
stepMetadata = step.getMetadata();
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
else if (step.metadata) {
|
|
224
|
+
stepMetadata = step.metadata;
|
|
225
|
+
}
|
|
226
|
+
// Extract executionContext if present on the step
|
|
227
|
+
let executionContext = undefined;
|
|
228
|
+
if (typeof step.getExecutionContext === "function" &&
|
|
229
|
+
step.getExecutionContext()) {
|
|
230
|
+
try {
|
|
231
|
+
executionContext = convertProtobufValueToJs(step.getExecutionContext());
|
|
232
|
+
}
|
|
233
|
+
catch (e) {
|
|
234
|
+
executionContext = step.getExecutionContext();
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
else if (step.executionContext) {
|
|
238
|
+
executionContext = step.executionContext;
|
|
239
|
+
}
|
|
229
240
|
return new Step({
|
|
230
241
|
id: getId(),
|
|
231
242
|
type: convertProtobufStepTypeToSdk(getType()),
|
|
@@ -238,6 +249,8 @@ class Step {
|
|
|
238
249
|
output: Step.getOutput(step),
|
|
239
250
|
startAt: getStartAt(),
|
|
240
251
|
endAt: getEndAt(),
|
|
252
|
+
metadata: stepMetadata,
|
|
253
|
+
executionContext,
|
|
241
254
|
});
|
|
242
255
|
}
|
|
243
256
|
}
|
package/dist/utils.d.ts
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { Value as ProtobufValue } from "google-protobuf/google/protobuf/struct_pb";
|
|
2
|
+
/**
|
|
3
|
+
* Convert a protobuf Value to a JavaScript value
|
|
4
|
+
*
|
|
5
|
+
* **🏆 RECOMMENDED for modern protobuf usage**
|
|
6
|
+
*
|
|
7
|
+
* This is the primary implementation using proper TypeScript types and getKindCase()
|
|
8
|
+
* for the latest protobuf libraries. Use this for all new code.
|
|
9
|
+
*
|
|
10
|
+
* @param value - The protobuf Value to convert
|
|
11
|
+
* @returns The converted JavaScript value
|
|
12
|
+
*/
|
|
13
|
+
export declare function convertProtobufValueToJs(value?: ProtobufValue): any;
|
|
14
|
+
/**
|
|
15
|
+
* Convert a JavaScript value to a protobuf Value
|
|
16
|
+
*
|
|
17
|
+
* Uses proper TypeScript types for modern protobuf usage.
|
|
18
|
+
*
|
|
19
|
+
* @param value - The JavaScript value to convert
|
|
20
|
+
* @returns The protobuf Value object
|
|
21
|
+
*/
|
|
22
|
+
export declare function convertJSValueToProtobuf(value: any): ProtobufValue;
|
|
23
|
+
/**
|
|
24
|
+
* Recursively convert object keys from snake_case to camelCase.
|
|
25
|
+
* Leaves non-objects and arrays intact (arrays are mapped over).
|
|
26
|
+
*/
|
|
27
|
+
export declare function toCamelCaseKeys<T = any>(input: any): T;
|
|
28
|
+
/**
|
|
29
|
+
* Convert protobuf trigger type string to SDK trigger type string
|
|
30
|
+
*
|
|
31
|
+
* @param protobufType - The protobuf trigger type string (e.g., "TRIGGER_TYPE_MANUAL")
|
|
32
|
+
* @returns The SDK trigger type string (e.g., "manualTrigger")
|
|
33
|
+
*/
|
|
34
|
+
export declare function convertProtobufTriggerTypeToSdk(protobufType: string): string;
|
|
35
|
+
/**
|
|
36
|
+
* Convert protobuf node type string to SDK node type string
|
|
37
|
+
*
|
|
38
|
+
* @param protobufType - The protobuf node type string (e.g., "NODE_TYPE_CUSTOM_CODE")
|
|
39
|
+
* @returns The SDK node type string (e.g., "customCode")
|
|
40
|
+
*/
|
|
41
|
+
export declare function convertProtobufNodeTypeToSdk(protobufType: string): string;
|
|
42
|
+
/**
|
|
43
|
+
* Convert protobuf step type string to SDK step type string
|
|
44
|
+
*
|
|
45
|
+
* Automatically detects whether the type is a trigger or node type and converts accordingly.
|
|
46
|
+
*
|
|
47
|
+
* @param protobufType - The protobuf type string (e.g., "TRIGGER_TYPE_MANUAL" or "NODE_TYPE_CUSTOM_CODE")
|
|
48
|
+
* @returns The SDK type string (e.g., "manualTrigger" or "customCode")
|
|
49
|
+
*/
|
|
50
|
+
export declare function convertProtobufStepTypeToSdk(protobufType: string): string;
|
|
51
|
+
/**
|
|
52
|
+
* Convert input field from JavaScript object to protobuf Value format
|
|
53
|
+
*
|
|
54
|
+
* Pure utility function for converting trigger/node input data to protobuf format.
|
|
55
|
+
* Can be used by both triggers and nodes.
|
|
56
|
+
*
|
|
57
|
+
* @param input - JavaScript object with input data, or undefined
|
|
58
|
+
* @returns protobuf Value or undefined if no input
|
|
59
|
+
*/
|
|
60
|
+
export declare function convertInputToProtobuf(input?: Record<string, any>): ProtobufValue | undefined;
|
|
61
|
+
/**
|
|
62
|
+
* Extract input field from protobuf Value format to JavaScript object
|
|
63
|
+
*
|
|
64
|
+
* Pure utility function for extracting trigger/node input data from protobuf format.
|
|
65
|
+
* Can be used by both triggers and nodes.
|
|
66
|
+
*
|
|
67
|
+
* @param inputValue - protobuf Value from response, plain JavaScript object, or undefined
|
|
68
|
+
* @returns JavaScript object or undefined
|
|
69
|
+
*/
|
|
70
|
+
export declare function extractInputFromProtobuf(inputValue?: ProtobufValue | Record<string, any>): Record<string, any> | undefined;
|
|
71
|
+
/**
|
|
72
|
+
* Clean up gRPC error messages by extracting the actual message
|
|
73
|
+
* @param message - The raw gRPC error message
|
|
74
|
+
* @returns {string} - The cleaned error message
|
|
75
|
+
*/
|
|
76
|
+
export declare function cleanGrpcErrorMessage(message: string): string;
|
|
77
|
+
//# sourceMappingURL=utils.d.ts.map
|
package/dist/utils.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,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,GAAG,EAAE,KAAK,EAAE,GAAG,GAAG,CAAC,CAatD;AAED;;;;;GAKG;AACH,wBAAgB,+BAA+B,CAAC,YAAY,EAAE,MAAM,GAAG,MAAM,CAkB5E;AAED;;;;;GAKG;AACH,wBAAgB,4BAA4B,CAAC,YAAY,EAAE,MAAM,GAAG,MAAM,CA0BzE;AAED;;;;;;;GAOG;AACH,wBAAgB,4BAA4B,CAAC,YAAY,EAAE,MAAM,GAAG,MAAM,CASzE;AAED;;;;;;;;GAQG;AACH,wBAAgB,sBAAsB,CACpC,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAC1B,aAAa,GAAG,SAAS,CAK3B;AAED;;;;;;;;GAQG;AACH,wBAAgB,wBAAwB,CACtC,UAAU,CAAC,EAAE,aAAa,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAC/C,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,SAAS,CAiCjC;AAED;;;;GAIG;AACH,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAsB7D"}
|
package/dist/utils.js
CHANGED
|
@@ -88,6 +88,25 @@ export function convertJSValueToProtobuf(value) {
|
|
|
88
88
|
}
|
|
89
89
|
return protobufValue;
|
|
90
90
|
}
|
|
91
|
+
/**
|
|
92
|
+
* Recursively convert object keys from snake_case to camelCase.
|
|
93
|
+
* Leaves non-objects and arrays intact (arrays are mapped over).
|
|
94
|
+
*/
|
|
95
|
+
export function toCamelCaseKeys(input) {
|
|
96
|
+
if (input === null || input === undefined)
|
|
97
|
+
return input;
|
|
98
|
+
if (Array.isArray(input)) {
|
|
99
|
+
return input.map((item) => toCamelCaseKeys(item));
|
|
100
|
+
}
|
|
101
|
+
if (typeof input !== "object")
|
|
102
|
+
return input;
|
|
103
|
+
const result = {};
|
|
104
|
+
for (const [key, value] of Object.entries(input)) {
|
|
105
|
+
const camelKey = key.replace(/_([a-z])/g, (_, c) => c.toUpperCase());
|
|
106
|
+
result[camelKey] = toCamelCaseKeys(value);
|
|
107
|
+
}
|
|
108
|
+
return result;
|
|
109
|
+
}
|
|
91
110
|
/**
|
|
92
111
|
* Convert protobuf trigger type string to SDK trigger type string
|
|
93
112
|
*
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@avaprotocol/sdk-js",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.7.0",
|
|
4
4
|
"description": "A JavaScript/TypeScript SDK designed to simplify integration with Ava Protocol's AVS",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
"prepare": "node ../../scripts/prepare-package.js"
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
|
-
"@avaprotocol/types": "^2.
|
|
34
|
+
"@avaprotocol/types": "^2.5.0",
|
|
35
35
|
"@grpc/grpc-js": "^1.11.3",
|
|
36
36
|
"@grpc/proto-loader": "^0.7.13",
|
|
37
37
|
"dotenv": "^16.4.5",
|