@avaprotocol/sdk-js 2.3.17 → 2.4.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/CHANGELOG.md +30 -0
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5267 -6205
- package/dist/index.mjs +5269 -6204
- package/dist/models/node/contractRead.d.ts.map +1 -1
- package/dist/models/node/contractRead.js +27 -17
- package/dist/models/node/contractWrite.d.ts.map +1 -1
- package/dist/models/node/contractWrite.js +12 -53
- package/dist/models/node/loop.d.ts.map +1 -1
- package/dist/models/node/loop.js +3 -0
- package/dist/models/step.d.ts.map +1 -1
- package/dist/models/step.js +103 -66
- package/dist/models/trigger/event.d.ts.map +1 -1
- package/dist/models/trigger/event.js +71 -7
- package/dist/models/trigger/factory.d.ts.map +1 -1
- package/dist/models/trigger/factory.js +7 -38
- package/dist/utils.d.ts +6 -0
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +49 -23
- package/package.json +2 -2
package/dist/utils.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Value as ProtobufValue, Struct as ProtobufStruct, ListValue as ProtobufListValue } from "google-protobuf/google/protobuf/struct_pb";
|
|
1
|
+
import { Value as ProtobufValue, Struct as ProtobufStruct, ListValue as ProtobufListValue, } from "google-protobuf/google/protobuf/struct_pb";
|
|
2
2
|
import { TriggerType, NodeType } from "@avaprotocol/types";
|
|
3
3
|
/**
|
|
4
4
|
* Convert a protobuf Value to a JavaScript value
|
|
@@ -39,7 +39,7 @@ export function convertProtobufValueToJs(value) {
|
|
|
39
39
|
const list = value.getListValue();
|
|
40
40
|
if (!list)
|
|
41
41
|
return [];
|
|
42
|
-
return list.getValuesList().map(item => convertProtobufValueToJs(item));
|
|
42
|
+
return list.getValuesList().map((item) => convertProtobufValueToJs(item));
|
|
43
43
|
}
|
|
44
44
|
case ProtobufValue.KindCase.KIND_NOT_SET:
|
|
45
45
|
default:
|
|
@@ -158,17 +158,17 @@ export function convertJSValueToProtobuf(value) {
|
|
|
158
158
|
*/
|
|
159
159
|
export function convertProtobufTriggerTypeToSdk(protobufType) {
|
|
160
160
|
switch (protobufType) {
|
|
161
|
-
case
|
|
161
|
+
case "TRIGGER_TYPE_MANUAL":
|
|
162
162
|
return TriggerType.Manual; // "manualTrigger"
|
|
163
|
-
case
|
|
163
|
+
case "TRIGGER_TYPE_FIXED_TIME":
|
|
164
164
|
return TriggerType.FixedTime; // "fixedTimeTrigger"
|
|
165
|
-
case
|
|
165
|
+
case "TRIGGER_TYPE_CRON":
|
|
166
166
|
return TriggerType.Cron; // "cronTrigger"
|
|
167
|
-
case
|
|
167
|
+
case "TRIGGER_TYPE_BLOCK":
|
|
168
168
|
return TriggerType.Block; // "blockTrigger"
|
|
169
|
-
case
|
|
169
|
+
case "TRIGGER_TYPE_EVENT":
|
|
170
170
|
return TriggerType.Event; // "eventTrigger"
|
|
171
|
-
case
|
|
171
|
+
case "TRIGGER_TYPE_UNSPECIFIED":
|
|
172
172
|
return TriggerType.Unspecified; // "unspecified"
|
|
173
173
|
default:
|
|
174
174
|
console.warn(`Unknown trigger type: ${protobufType}, using raw value`);
|
|
@@ -183,25 +183,25 @@ export function convertProtobufTriggerTypeToSdk(protobufType) {
|
|
|
183
183
|
*/
|
|
184
184
|
export function convertProtobufNodeTypeToSdk(protobufType) {
|
|
185
185
|
switch (protobufType) {
|
|
186
|
-
case
|
|
186
|
+
case "NODE_TYPE_ETH_TRANSFER":
|
|
187
187
|
return NodeType.ETHTransfer; // "ethTransfer"
|
|
188
|
-
case
|
|
188
|
+
case "NODE_TYPE_CONTRACT_WRITE":
|
|
189
189
|
return NodeType.ContractWrite; // "contractWrite"
|
|
190
|
-
case
|
|
190
|
+
case "NODE_TYPE_CONTRACT_READ":
|
|
191
191
|
return NodeType.ContractRead; // "contractRead"
|
|
192
|
-
case
|
|
192
|
+
case "NODE_TYPE_GRAPHQL_QUERY":
|
|
193
193
|
return NodeType.GraphQLQuery; // "graphql"
|
|
194
|
-
case
|
|
194
|
+
case "NODE_TYPE_REST_API":
|
|
195
195
|
return NodeType.RestAPI; // "restApi"
|
|
196
|
-
case
|
|
196
|
+
case "NODE_TYPE_CUSTOM_CODE":
|
|
197
197
|
return NodeType.CustomCode; // "customCode"
|
|
198
|
-
case
|
|
198
|
+
case "NODE_TYPE_BRANCH":
|
|
199
199
|
return NodeType.Branch; // "branch"
|
|
200
|
-
case
|
|
200
|
+
case "NODE_TYPE_FILTER":
|
|
201
201
|
return NodeType.Filter; // "filter"
|
|
202
|
-
case
|
|
202
|
+
case "NODE_TYPE_LOOP":
|
|
203
203
|
return NodeType.Loop; // "loop"
|
|
204
|
-
case
|
|
204
|
+
case "NODE_TYPE_UNSPECIFIED":
|
|
205
205
|
return NodeType.Unspecified; // "unspecified"
|
|
206
206
|
default:
|
|
207
207
|
console.warn(`Unknown node type: ${protobufType}, using raw value`);
|
|
@@ -217,10 +217,10 @@ export function convertProtobufNodeTypeToSdk(protobufType) {
|
|
|
217
217
|
* @returns The SDK type string (e.g., "manualTrigger" or "customCode")
|
|
218
218
|
*/
|
|
219
219
|
export function convertProtobufStepTypeToSdk(protobufType) {
|
|
220
|
-
if (protobufType.startsWith(
|
|
220
|
+
if (protobufType.startsWith("TRIGGER_TYPE_")) {
|
|
221
221
|
return convertProtobufTriggerTypeToSdk(protobufType);
|
|
222
222
|
}
|
|
223
|
-
else if (protobufType.startsWith(
|
|
223
|
+
else if (protobufType.startsWith("NODE_TYPE_")) {
|
|
224
224
|
return convertProtobufNodeTypeToSdk(protobufType);
|
|
225
225
|
}
|
|
226
226
|
else {
|
|
@@ -257,7 +257,7 @@ export function extractInputFromProtobuf(inputValue) {
|
|
|
257
257
|
return undefined;
|
|
258
258
|
}
|
|
259
259
|
// Check if it's already a plain JavaScript object
|
|
260
|
-
if (typeof inputValue ===
|
|
260
|
+
if (typeof inputValue === "object" && !inputValue.toJavaScript) {
|
|
261
261
|
// It's a plain JavaScript object, return as-is
|
|
262
262
|
if (!Array.isArray(inputValue)) {
|
|
263
263
|
return inputValue;
|
|
@@ -268,15 +268,41 @@ export function extractInputFromProtobuf(inputValue) {
|
|
|
268
268
|
try {
|
|
269
269
|
const protobufValue = inputValue;
|
|
270
270
|
const inputJavaScript = protobufValue.toJavaScript();
|
|
271
|
-
if (inputJavaScript &&
|
|
271
|
+
if (inputJavaScript &&
|
|
272
|
+
typeof inputJavaScript === "object" &&
|
|
273
|
+
!Array.isArray(inputJavaScript)) {
|
|
272
274
|
return inputJavaScript;
|
|
273
275
|
}
|
|
274
276
|
}
|
|
275
277
|
catch (error) {
|
|
276
278
|
// If conversion fails, try to return the object as-is if it looks like a valid input object
|
|
277
|
-
if (typeof inputValue ===
|
|
279
|
+
if (typeof inputValue === "object" && !Array.isArray(inputValue)) {
|
|
278
280
|
return inputValue;
|
|
279
281
|
}
|
|
280
282
|
}
|
|
281
283
|
return undefined;
|
|
282
284
|
}
|
|
285
|
+
/**
|
|
286
|
+
* Clean up gRPC error messages by extracting the actual message
|
|
287
|
+
* @param message - The raw gRPC error message
|
|
288
|
+
* @returns {string} - The cleaned error message
|
|
289
|
+
*/
|
|
290
|
+
export function cleanGrpcErrorMessage(message) {
|
|
291
|
+
if (!message)
|
|
292
|
+
return message;
|
|
293
|
+
// Pattern to match: "gRPC Error (Code X): X STATUS_CODE: actual message"
|
|
294
|
+
// We want to extract everything after the status code
|
|
295
|
+
const grpcErrorPattern = /gRPC Error \(Code \d+\): \d+ [A-Z_]+: (.+)$/;
|
|
296
|
+
const match = message.match(grpcErrorPattern);
|
|
297
|
+
if (match && match[1]) {
|
|
298
|
+
return match[1].trim();
|
|
299
|
+
}
|
|
300
|
+
// Fallback: try to extract message after any status code pattern
|
|
301
|
+
const statusCodePattern = /\d+ [A-Z_]+: (.+)$/;
|
|
302
|
+
const statusMatch = message.match(statusCodePattern);
|
|
303
|
+
if (statusMatch && statusMatch[1]) {
|
|
304
|
+
return statusMatch[1].trim();
|
|
305
|
+
}
|
|
306
|
+
// If no pattern matches, return the original message
|
|
307
|
+
return message;
|
|
308
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@avaprotocol/sdk-js",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.4.1",
|
|
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.2.
|
|
34
|
+
"@avaprotocol/types": "^2.2.14",
|
|
35
35
|
"@grpc/grpc-js": "^1.11.3",
|
|
36
36
|
"@grpc/proto-loader": "^0.7.13",
|
|
37
37
|
"dotenv": "^16.4.5",
|