@avaprotocol/sdk-js 2.3.13-de.0 → 2.3.13-dev.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/index.js +1103 -401
- package/dist/index.mjs +1107 -405
- package/dist/models/node/branch.d.ts.map +1 -1
- package/dist/models/node/branch.js +12 -3
- package/dist/models/node/contractRead.d.ts.map +1 -1
- package/dist/models/node/contractRead.js +12 -3
- package/dist/models/node/contractWrite.d.ts.map +1 -1
- package/dist/models/node/contractWrite.js +12 -3
- package/dist/models/node/customCode.d.ts.map +1 -1
- package/dist/models/node/customCode.js +12 -4
- package/dist/models/node/ethTransfer.d.ts.map +1 -1
- package/dist/models/node/ethTransfer.js +12 -3
- package/dist/models/node/filter.d.ts.map +1 -1
- package/dist/models/node/filter.js +12 -3
- package/dist/models/node/graphqlQuery.d.ts.map +1 -1
- package/dist/models/node/graphqlQuery.js +12 -3
- package/dist/models/node/interface.d.ts +3 -2
- package/dist/models/node/interface.d.ts.map +1 -1
- package/dist/models/node/interface.js +17 -2
- package/dist/models/node/loop.d.ts.map +1 -1
- package/dist/models/node/loop.js +9 -0
- package/dist/models/node/restApi.d.ts.map +1 -1
- package/dist/models/node/restApi.js +15 -1
- package/dist/models/step.d.ts +1 -0
- package/dist/models/step.d.ts.map +1 -1
- package/dist/models/step.js +308 -206
- package/dist/models/trigger/block.d.ts.map +1 -1
- package/dist/models/trigger/block.js +13 -0
- package/dist/models/trigger/cron.d.ts.map +1 -1
- package/dist/models/trigger/cron.js +20 -0
- package/dist/models/trigger/event.d.ts.map +1 -1
- package/dist/models/trigger/fixedTime.d.ts.map +1 -1
- package/dist/models/trigger/interface.d.ts +4 -5
- package/dist/models/trigger/interface.d.ts.map +1 -1
- package/dist/models/trigger/interface.js +4 -2
- package/dist/models/trigger/manual.d.ts.map +1 -1
- package/dist/models/trigger/manual.js +13 -0
- package/dist/utils.d.ts +20 -0
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +52 -0
- package/package.json +2 -2
package/dist/models/step.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import * as avs_pb from "@/grpc_codegen/avs_pb";
|
|
2
|
-
import { Value as ProtobufValue } from "google-protobuf/google/protobuf/struct_pb";
|
|
3
2
|
import { convertProtobufValueToJs, convertProtobufStepTypeToSdk, } from "../utils";
|
|
4
3
|
class Step {
|
|
5
4
|
constructor(props) {
|
|
@@ -10,6 +9,7 @@ class Step {
|
|
|
10
9
|
this.error = props.error;
|
|
11
10
|
this.log = props.log;
|
|
12
11
|
this.inputsList = props.inputsList;
|
|
12
|
+
this.input = props.input;
|
|
13
13
|
this.output = props.output;
|
|
14
14
|
this.startAt = props.startAt;
|
|
15
15
|
this.endAt = props.endAt;
|
|
@@ -27,262 +27,364 @@ class Step {
|
|
|
27
27
|
error: this.error,
|
|
28
28
|
log: this.log,
|
|
29
29
|
inputsList: this.inputsList,
|
|
30
|
+
input: this.input,
|
|
30
31
|
output: this.output,
|
|
31
32
|
startAt: this.startAt,
|
|
32
33
|
endAt: this.endAt,
|
|
33
34
|
};
|
|
34
35
|
}
|
|
35
36
|
static getOutput(step) {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
37
|
+
// Handle both protobuf instances and plain objects
|
|
38
|
+
const getOutputDataCase = () => {
|
|
39
|
+
if (typeof step.getOutputDataCase === "function") {
|
|
40
|
+
return step.getOutputDataCase();
|
|
41
|
+
}
|
|
42
|
+
// For plain objects, determine the case by checking which properties exist
|
|
43
|
+
const stepObj = step;
|
|
44
|
+
if (stepObj.blockTrigger)
|
|
45
|
+
return avs_pb.Execution.Step.OutputDataCase.BLOCK_TRIGGER;
|
|
46
|
+
if (stepObj.fixedTimeTrigger)
|
|
47
|
+
return avs_pb.Execution.Step.OutputDataCase.FIXED_TIME_TRIGGER;
|
|
48
|
+
if (stepObj.cronTrigger)
|
|
49
|
+
return avs_pb.Execution.Step.OutputDataCase.CRON_TRIGGER;
|
|
50
|
+
if (stepObj.eventTrigger)
|
|
51
|
+
return avs_pb.Execution.Step.OutputDataCase.EVENT_TRIGGER;
|
|
52
|
+
if (stepObj.manualTrigger)
|
|
53
|
+
return avs_pb.Execution.Step.OutputDataCase.MANUAL_TRIGGER;
|
|
54
|
+
if (stepObj.ethTransfer)
|
|
55
|
+
return avs_pb.Execution.Step.OutputDataCase.ETH_TRANSFER;
|
|
56
|
+
if (stepObj.graphql)
|
|
57
|
+
return avs_pb.Execution.Step.OutputDataCase.GRAPHQL;
|
|
58
|
+
if (stepObj.contractRead)
|
|
59
|
+
return avs_pb.Execution.Step.OutputDataCase.CONTRACT_READ;
|
|
60
|
+
if (stepObj.contractWrite)
|
|
61
|
+
return avs_pb.Execution.Step.OutputDataCase.CONTRACT_WRITE;
|
|
62
|
+
if (stepObj.customCode)
|
|
63
|
+
return avs_pb.Execution.Step.OutputDataCase.CUSTOM_CODE;
|
|
64
|
+
if (stepObj.restApi)
|
|
65
|
+
return avs_pb.Execution.Step.OutputDataCase.REST_API;
|
|
66
|
+
if (stepObj.branch)
|
|
67
|
+
return avs_pb.Execution.Step.OutputDataCase.BRANCH;
|
|
68
|
+
if (stepObj.filter)
|
|
69
|
+
return avs_pb.Execution.Step.OutputDataCase.FILTER;
|
|
70
|
+
if (stepObj.loop)
|
|
71
|
+
return avs_pb.Execution.Step.OutputDataCase.LOOP;
|
|
72
|
+
return avs_pb.Execution.Step.OutputDataCase.OUTPUT_DATA_NOT_SET;
|
|
73
|
+
};
|
|
74
|
+
switch (getOutputDataCase()) {
|
|
39
75
|
case avs_pb.Execution.Step.OutputDataCase.OUTPUT_DATA_NOT_SET:
|
|
40
76
|
return undefined;
|
|
41
77
|
// Trigger outputs
|
|
42
78
|
case avs_pb.Execution.Step.OutputDataCase.BLOCK_TRIGGER:
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
: undefined;
|
|
79
|
+
return typeof step.getBlockTrigger === "function"
|
|
80
|
+
? step.getBlockTrigger()?.toObject()
|
|
81
|
+
: step.blockTrigger;
|
|
47
82
|
case avs_pb.Execution.Step.OutputDataCase.FIXED_TIME_TRIGGER:
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
timestamp: fixedTimeOutput.timestamp,
|
|
52
|
-
timestampIso: fixedTimeOutput.timestampIso,
|
|
53
|
-
}
|
|
54
|
-
: undefined;
|
|
83
|
+
return typeof step.getFixedTimeTrigger === "function"
|
|
84
|
+
? step.getFixedTimeTrigger()?.toObject()
|
|
85
|
+
: step.fixedTimeTrigger;
|
|
55
86
|
case avs_pb.Execution.Step.OutputDataCase.CRON_TRIGGER:
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
timestamp: cronOutput.timestamp,
|
|
60
|
-
timestampIso: cronOutput.timestampIso,
|
|
61
|
-
}
|
|
62
|
-
: undefined;
|
|
87
|
+
return typeof step.getCronTrigger === "function"
|
|
88
|
+
? step.getCronTrigger()?.toObject()
|
|
89
|
+
: step.cronTrigger;
|
|
63
90
|
case avs_pb.Execution.Step.OutputDataCase.EVENT_TRIGGER:
|
|
64
|
-
const eventTrigger = step.getEventTrigger
|
|
91
|
+
const eventTrigger = typeof step.getEventTrigger === "function"
|
|
92
|
+
? step.getEventTrigger()
|
|
93
|
+
: step.eventTrigger;
|
|
65
94
|
if (eventTrigger) {
|
|
66
|
-
if (eventTrigger.hasEvmLog
|
|
95
|
+
if (typeof eventTrigger.hasEvmLog === "function" &&
|
|
96
|
+
eventTrigger.hasEvmLog()) {
|
|
67
97
|
return eventTrigger.getEvmLog()?.toObject();
|
|
68
98
|
}
|
|
69
|
-
else if (eventTrigger.hasTransferLog
|
|
99
|
+
else if (typeof eventTrigger.hasTransferLog === "function" &&
|
|
100
|
+
eventTrigger.hasTransferLog()) {
|
|
70
101
|
return eventTrigger.getTransferLog()?.toObject();
|
|
71
102
|
}
|
|
103
|
+
else if (eventTrigger.evmLog) {
|
|
104
|
+
return eventTrigger.evmLog;
|
|
105
|
+
}
|
|
106
|
+
else if (eventTrigger.transferLog) {
|
|
107
|
+
return eventTrigger.transferLog;
|
|
108
|
+
}
|
|
72
109
|
}
|
|
73
110
|
return undefined;
|
|
74
111
|
case avs_pb.Execution.Step.OutputDataCase.MANUAL_TRIGGER:
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
112
|
+
return typeof step.getManualTrigger === "function"
|
|
113
|
+
? step.getManualTrigger()?.toObject() || undefined
|
|
114
|
+
: step.manualTrigger;
|
|
115
|
+
// Node outputs - RESTORE MISSING CASES
|
|
78
116
|
case avs_pb.Execution.Step.OutputDataCase.ETH_TRANSFER:
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
117
|
+
return typeof step.getEthTransfer === "function"
|
|
118
|
+
? step.getEthTransfer()?.toObject()
|
|
119
|
+
: step.ethTransfer;
|
|
120
|
+
case avs_pb.Execution.Step.OutputDataCase.CUSTOM_CODE:
|
|
121
|
+
const customCodeOutput = typeof step.getCustomCode === "function"
|
|
122
|
+
? step.getCustomCode()
|
|
123
|
+
: step.customCode;
|
|
124
|
+
if (customCodeOutput) {
|
|
125
|
+
if (typeof customCodeOutput.hasData === "function" &&
|
|
126
|
+
customCodeOutput.hasData()) {
|
|
127
|
+
try {
|
|
128
|
+
return convertProtobufValueToJs(customCodeOutput.getData());
|
|
129
|
+
}
|
|
130
|
+
catch {
|
|
131
|
+
// Fallback: if conversion fails, return the raw data
|
|
132
|
+
return customCodeOutput.getData();
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
else if (customCodeOutput.data) {
|
|
136
|
+
// For plain objects, try to convert or use directly
|
|
137
|
+
return typeof customCodeOutput.data.getKindCase === "function"
|
|
138
|
+
? convertProtobufValueToJs(customCodeOutput.data)
|
|
139
|
+
: customCodeOutput.data;
|
|
83
140
|
}
|
|
84
|
-
|
|
141
|
+
}
|
|
142
|
+
return undefined;
|
|
143
|
+
case avs_pb.Execution.Step.OutputDataCase.REST_API:
|
|
144
|
+
const restApiOutput = typeof step.getRestApi === "function"
|
|
145
|
+
? step.getRestApi()
|
|
146
|
+
: step.restApi;
|
|
147
|
+
if (restApiOutput) {
|
|
148
|
+
if (typeof restApiOutput.hasData === "function" &&
|
|
149
|
+
restApiOutput.hasData()) {
|
|
150
|
+
try {
|
|
151
|
+
return convertProtobufValueToJs(restApiOutput.getData());
|
|
152
|
+
}
|
|
153
|
+
catch {
|
|
154
|
+
// Fallback: if conversion fails, return the raw data
|
|
155
|
+
return restApiOutput.getData();
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
else if (restApiOutput.data) {
|
|
159
|
+
// For plain objects, try to convert or use directly
|
|
160
|
+
return typeof restApiOutput.data.getKindCase === "function"
|
|
161
|
+
? convertProtobufValueToJs(restApiOutput.data)
|
|
162
|
+
: restApiOutput.data;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
return undefined;
|
|
166
|
+
case avs_pb.Execution.Step.OutputDataCase.BRANCH:
|
|
167
|
+
return typeof step.getBranch === "function"
|
|
168
|
+
? step.getBranch()?.toObject()
|
|
169
|
+
: step.branch;
|
|
170
|
+
case avs_pb.Execution.Step.OutputDataCase.LOOP:
|
|
171
|
+
const loopOutput = typeof step.getLoop === "function"
|
|
172
|
+
? step.getLoop()
|
|
173
|
+
: step.loop;
|
|
174
|
+
if (loopOutput) {
|
|
175
|
+
if (typeof loopOutput.getData === "function" &&
|
|
176
|
+
loopOutput.getData()) {
|
|
177
|
+
try {
|
|
178
|
+
return JSON.parse(loopOutput.getData());
|
|
179
|
+
}
|
|
180
|
+
catch {
|
|
181
|
+
return loopOutput.getData();
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
else if (loopOutput.data) {
|
|
185
|
+
// For plain objects
|
|
186
|
+
try {
|
|
187
|
+
return typeof loopOutput.data === "string"
|
|
188
|
+
? JSON.parse(loopOutput.data)
|
|
189
|
+
: loopOutput.data;
|
|
190
|
+
}
|
|
191
|
+
catch {
|
|
192
|
+
return loopOutput.data;
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
return undefined;
|
|
85
197
|
case avs_pb.Execution.Step.OutputDataCase.GRAPHQL:
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
198
|
+
const graphqlOutput = typeof step.getGraphql === "function"
|
|
199
|
+
? step.getGraphql()
|
|
200
|
+
: step.graphql;
|
|
201
|
+
if (graphqlOutput) {
|
|
202
|
+
try {
|
|
203
|
+
return typeof graphqlOutput.toObject === "function"
|
|
204
|
+
? graphqlOutput.toObject()
|
|
205
|
+
: graphqlOutput;
|
|
206
|
+
}
|
|
207
|
+
catch {
|
|
208
|
+
return undefined;
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
return undefined;
|
|
90
212
|
case avs_pb.Execution.Step.OutputDataCase.CONTRACT_READ:
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
methodName: result.
|
|
105
|
-
success: result.
|
|
106
|
-
error: result.
|
|
107
|
-
data:
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
// Return wrapped format consistently for all cases
|
|
111
|
-
return { results: resultArray };
|
|
213
|
+
const contractReadOutput = typeof step.getContractRead === "function"
|
|
214
|
+
? step.getContractRead()
|
|
215
|
+
: step.contractRead;
|
|
216
|
+
if (contractReadOutput) {
|
|
217
|
+
// Get the raw output object
|
|
218
|
+
const outputObj = typeof contractReadOutput.toObject === "function"
|
|
219
|
+
? contractReadOutput.toObject()
|
|
220
|
+
: contractReadOutput;
|
|
221
|
+
// Convert resultsList to results for consistency with ContractReadNode.fromOutputData
|
|
222
|
+
if (outputObj && outputObj.resultsList) {
|
|
223
|
+
return {
|
|
224
|
+
...outputObj,
|
|
225
|
+
results: outputObj.resultsList.map((result) => ({
|
|
226
|
+
methodName: result.methodName,
|
|
227
|
+
success: result.success,
|
|
228
|
+
error: result.error,
|
|
229
|
+
data: result.dataList || []
|
|
230
|
+
}))
|
|
231
|
+
};
|
|
112
232
|
}
|
|
233
|
+
return outputObj;
|
|
113
234
|
}
|
|
114
235
|
return undefined;
|
|
115
236
|
case avs_pb.Execution.Step.OutputDataCase.CONTRACT_WRITE:
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
237
|
+
const contractWriteOutput = typeof step.getContractWrite === "function"
|
|
238
|
+
? step.getContractWrite()
|
|
239
|
+
: step.contractWrite;
|
|
240
|
+
if (contractWriteOutput) {
|
|
241
|
+
// Get the raw output object
|
|
242
|
+
const outputObj = typeof contractWriteOutput.toObject === "function"
|
|
243
|
+
? contractWriteOutput.toObject()
|
|
244
|
+
: contractWriteOutput;
|
|
245
|
+
// Convert resultsList to results for consistency with ContractWriteNode.fromOutputData
|
|
246
|
+
if (outputObj && outputObj.resultsList) {
|
|
247
|
+
const transformedResults = outputObj.resultsList.map((result) => ({
|
|
248
|
+
methodName: result.methodName,
|
|
249
|
+
success: result.success,
|
|
250
|
+
transaction: result.transaction ? {
|
|
251
|
+
hash: result.transaction.hash,
|
|
252
|
+
status: result.transaction.status,
|
|
253
|
+
blockNumber: result.transaction.blockNumber,
|
|
254
|
+
blockHash: result.transaction.blockHash,
|
|
255
|
+
gasUsed: result.transaction.gasUsed,
|
|
256
|
+
gasLimit: result.transaction.gasLimit,
|
|
257
|
+
gasPrice: result.transaction.gasPrice,
|
|
258
|
+
effectiveGasPrice: result.transaction.effectiveGasPrice,
|
|
259
|
+
from: result.transaction.from,
|
|
260
|
+
to: result.transaction.to,
|
|
261
|
+
value: result.transaction.value,
|
|
262
|
+
nonce: result.transaction.nonce,
|
|
263
|
+
transactionIndex: result.transaction.transactionIndex,
|
|
264
|
+
confirmations: result.transaction.confirmations,
|
|
265
|
+
timestamp: result.transaction.timestamp,
|
|
140
266
|
} : null,
|
|
141
|
-
events: result.
|
|
142
|
-
eventName: event.
|
|
143
|
-
address: event.
|
|
144
|
-
topics: event.
|
|
145
|
-
data: event.
|
|
146
|
-
decoded: event.
|
|
147
|
-
})),
|
|
148
|
-
error: result.
|
|
149
|
-
code: result.
|
|
150
|
-
message: result.
|
|
151
|
-
revertReason: result.
|
|
267
|
+
events: result.eventsList?.map((event) => ({
|
|
268
|
+
eventName: event.eventName,
|
|
269
|
+
address: event.address,
|
|
270
|
+
topics: event.topicsList || [],
|
|
271
|
+
data: event.data,
|
|
272
|
+
decoded: event.decodedMap || {},
|
|
273
|
+
})) || [],
|
|
274
|
+
error: result.error ? {
|
|
275
|
+
code: result.error.code,
|
|
276
|
+
message: result.error.message,
|
|
277
|
+
revertReason: result.error.revertReason,
|
|
152
278
|
} : null,
|
|
153
|
-
returnData: result.
|
|
154
|
-
name: result.
|
|
155
|
-
type: result.
|
|
156
|
-
value: result.
|
|
279
|
+
returnData: result.returnData ? {
|
|
280
|
+
name: result.returnData.name,
|
|
281
|
+
type: result.returnData.type,
|
|
282
|
+
value: result.returnData.value,
|
|
157
283
|
} : null,
|
|
158
|
-
inputData: result.
|
|
284
|
+
inputData: result.inputData,
|
|
159
285
|
}));
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
286
|
+
return {
|
|
287
|
+
...outputObj,
|
|
288
|
+
results: transformedResults,
|
|
289
|
+
// For backward compatibility, provide legacy fields from first result
|
|
290
|
+
...(transformedResults.length > 0 && {
|
|
165
291
|
transaction: transformedResults[0].transaction,
|
|
166
292
|
success: transformedResults[0].success,
|
|
167
293
|
hash: transformedResults[0].transaction?.hash,
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
else {
|
|
171
|
-
return { results: transformedResults };
|
|
172
|
-
}
|
|
294
|
+
}),
|
|
295
|
+
};
|
|
173
296
|
}
|
|
297
|
+
return outputObj;
|
|
174
298
|
}
|
|
175
299
|
return undefined;
|
|
176
|
-
case avs_pb.Execution.Step.OutputDataCase.CUSTOM_CODE:
|
|
177
|
-
nodeOutputMessage = step.getCustomCode();
|
|
178
|
-
return nodeOutputMessage && nodeOutputMessage.hasData()
|
|
179
|
-
? convertProtobufValueToJs(nodeOutputMessage.getData())
|
|
180
|
-
: undefined;
|
|
181
|
-
case avs_pb.Execution.Step.OutputDataCase.REST_API:
|
|
182
|
-
nodeOutputMessage = step.getRestApi();
|
|
183
|
-
return nodeOutputMessage && nodeOutputMessage.hasData()
|
|
184
|
-
? convertProtobufValueToJs(nodeOutputMessage.getData())
|
|
185
|
-
: undefined;
|
|
186
|
-
case avs_pb.Execution.Step.OutputDataCase.BRANCH:
|
|
187
|
-
return step.getBranch()?.toObject();
|
|
188
300
|
case avs_pb.Execution.Step.OutputDataCase.FILTER:
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
return convertProtobufValueToJs(unpackedValue);
|
|
200
|
-
}
|
|
201
|
-
}
|
|
202
|
-
catch (error) {
|
|
203
|
-
// If unpacking fails, log error and return undefined
|
|
204
|
-
console.warn('Failed to unpack FilterNode Any wrapper:', error);
|
|
205
|
-
return undefined;
|
|
206
|
-
}
|
|
207
|
-
}
|
|
208
|
-
// If no unpack method, this is unexpected for FilterNode
|
|
209
|
-
console.warn('FilterNode output data is not an Any wrapper - this is unexpected');
|
|
301
|
+
const filterOutput = typeof step.getFilter === "function"
|
|
302
|
+
? step.getFilter()
|
|
303
|
+
: step.filter;
|
|
304
|
+
if (filterOutput) {
|
|
305
|
+
try {
|
|
306
|
+
return typeof filterOutput.toObject === "function"
|
|
307
|
+
? filterOutput.toObject()
|
|
308
|
+
: filterOutput;
|
|
309
|
+
}
|
|
310
|
+
catch {
|
|
210
311
|
return undefined;
|
|
211
312
|
}
|
|
212
313
|
}
|
|
213
314
|
return undefined;
|
|
214
|
-
case avs_pb.Execution.Step.OutputDataCase.LOOP:
|
|
215
|
-
const loopOutput = step.getLoop();
|
|
216
|
-
if (!loopOutput)
|
|
217
|
-
return undefined;
|
|
218
|
-
const loopData = loopOutput.getData();
|
|
219
|
-
if (!loopData)
|
|
220
|
-
return undefined;
|
|
221
|
-
// Loop nodes return an array of results from child node executions
|
|
222
|
-
// The backend should serialize this as JSON, but may have issues
|
|
223
|
-
// Try to parse as JSON first (expected format for array of child results)
|
|
224
|
-
try {
|
|
225
|
-
const parsedData = JSON.parse(loopData);
|
|
226
|
-
// If it's an array, process each item with appropriate child node conversion
|
|
227
|
-
if (Array.isArray(parsedData)) {
|
|
228
|
-
return parsedData.map((item, index) => {
|
|
229
|
-
if (!item || typeof item !== 'object') {
|
|
230
|
-
return item; // Primitive values, return as-is
|
|
231
|
-
}
|
|
232
|
-
// Apply child node-specific conversions based on detected structure
|
|
233
|
-
// REST API child output (has statusCode, body, headers)
|
|
234
|
-
if (item.statusCode !== undefined && (item.body !== undefined || item.headers !== undefined)) {
|
|
235
|
-
return item; // Already in raw format
|
|
236
|
-
}
|
|
237
|
-
// Custom Code child output (arbitrary object structure)
|
|
238
|
-
if (item.result !== undefined || item.output !== undefined || item.error !== undefined) {
|
|
239
|
-
return item; // Already processed by convertProtobufValueToJs in backend
|
|
240
|
-
}
|
|
241
|
-
// ETH Transfer child output (has transactionHash)
|
|
242
|
-
if (item.transactionHash !== undefined) {
|
|
243
|
-
return { transactionHash: item.transactionHash };
|
|
244
|
-
}
|
|
245
|
-
// Contract Read child output (has methodName and data)
|
|
246
|
-
if (item.methodName !== undefined && item.data !== undefined) {
|
|
247
|
-
return item; // Already in structured format
|
|
248
|
-
}
|
|
249
|
-
// GraphQL child output (has data field)
|
|
250
|
-
if (item.data !== undefined && typeof item.data === 'object') {
|
|
251
|
-
return item; // Already processed
|
|
252
|
-
}
|
|
253
|
-
// Generic object - return as-is (might be custom structure)
|
|
254
|
-
return item;
|
|
255
|
-
});
|
|
256
|
-
}
|
|
257
|
-
// Single object result (not an array)
|
|
258
|
-
if (parsedData && typeof parsedData === 'object') {
|
|
259
|
-
return parsedData;
|
|
260
|
-
}
|
|
261
|
-
// Parsed successfully but primitive value
|
|
262
|
-
return { data: parsedData };
|
|
263
|
-
}
|
|
264
|
-
catch (e) {
|
|
265
|
-
// Not JSON or parsing failed - could be a simple string result
|
|
266
|
-
// This might happen if backend has serialization issues
|
|
267
|
-
return { data: loopData };
|
|
268
|
-
}
|
|
269
315
|
default:
|
|
270
|
-
console.warn(`Unhandled output data type in Step.getOutput: ${
|
|
316
|
+
console.warn(`Unhandled output data type in Step.getOutput: ${step.getOutputDataCase()}`);
|
|
271
317
|
return undefined;
|
|
272
318
|
}
|
|
273
319
|
}
|
|
274
320
|
static fromResponse(step) {
|
|
321
|
+
// Extract input data if present - USE PROPER PROTOBUF GETTER
|
|
322
|
+
let inputData = undefined;
|
|
323
|
+
// Check for input using proper protobuf methods
|
|
324
|
+
if (typeof step.hasInput === "function" && step.hasInput()) {
|
|
325
|
+
const inputValue = step.getInput();
|
|
326
|
+
if (inputValue) {
|
|
327
|
+
// If it's a protobuf Value instance, convert it
|
|
328
|
+
try {
|
|
329
|
+
inputData = convertProtobufValueToJs(inputValue);
|
|
330
|
+
}
|
|
331
|
+
catch (error) {
|
|
332
|
+
console.warn('Failed to convert protobuf input value:', error);
|
|
333
|
+
// Fallback: if conversion fails, use the raw value
|
|
334
|
+
inputData = inputValue;
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
else if (step.input) {
|
|
339
|
+
// Fallback for plain objects (from .toObject() calls)
|
|
340
|
+
const inputValue = step.input;
|
|
341
|
+
// If it's already a plain JavaScript object, use it directly
|
|
342
|
+
if (typeof inputValue === "object" && !inputValue.getKindCase) {
|
|
343
|
+
inputData = inputValue;
|
|
344
|
+
}
|
|
345
|
+
else {
|
|
346
|
+
// If it's a protobuf Value instance, convert it
|
|
347
|
+
try {
|
|
348
|
+
inputData = convertProtobufValueToJs(inputValue);
|
|
349
|
+
}
|
|
350
|
+
catch (error) {
|
|
351
|
+
// Fallback: if conversion fails, use the raw value
|
|
352
|
+
inputData = inputValue;
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
// Handle method calls safely for both protobuf instances and plain objects
|
|
357
|
+
const getId = () => typeof step.getId === "function" ? step.getId() : step.id;
|
|
358
|
+
const getType = () => typeof step.getType === "function" ? step.getType() : step.type;
|
|
359
|
+
const getName = () => typeof step.getName === "function" ? step.getName() : step.name;
|
|
360
|
+
const getSuccess = () => typeof step.getSuccess === "function"
|
|
361
|
+
? step.getSuccess()
|
|
362
|
+
: step.success;
|
|
363
|
+
const getError = () => typeof step.getError === "function"
|
|
364
|
+
? step.getError()
|
|
365
|
+
: step.error;
|
|
366
|
+
const getLog = () => typeof step.getLog === "function" ? step.getLog() : step.log;
|
|
367
|
+
const getInputsList = () => typeof step.getInputsList === "function"
|
|
368
|
+
? step.getInputsList()
|
|
369
|
+
: step.inputsList || [];
|
|
370
|
+
const getStartAt = () => typeof step.getStartAt === "function"
|
|
371
|
+
? step.getStartAt()
|
|
372
|
+
: step.startAt;
|
|
373
|
+
const getEndAt = () => typeof step.getEndAt === "function"
|
|
374
|
+
? step.getEndAt()
|
|
375
|
+
: step.endAt;
|
|
275
376
|
return new Step({
|
|
276
|
-
id:
|
|
277
|
-
type: convertProtobufStepTypeToSdk(
|
|
278
|
-
name:
|
|
279
|
-
success:
|
|
280
|
-
error:
|
|
281
|
-
log:
|
|
282
|
-
inputsList:
|
|
377
|
+
id: getId(),
|
|
378
|
+
type: convertProtobufStepTypeToSdk(getType()),
|
|
379
|
+
name: getName(),
|
|
380
|
+
success: getSuccess(),
|
|
381
|
+
error: getError(),
|
|
382
|
+
log: getLog(),
|
|
383
|
+
inputsList: getInputsList(),
|
|
384
|
+
input: inputData,
|
|
283
385
|
output: Step.getOutput(step),
|
|
284
|
-
startAt:
|
|
285
|
-
endAt:
|
|
386
|
+
startAt: getStartAt(),
|
|
387
|
+
endAt: getEndAt(),
|
|
286
388
|
});
|
|
287
389
|
}
|
|
288
390
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"block.d.ts","sourceRoot":"","sources":["../../../src/models/trigger/block.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,MAAM,uBAAuB,CAAC;AAChD,OAAO,
|
|
1
|
+
{"version":3,"file":"block.d.ts","sourceRoot":"","sources":["../../../src/models/trigger/block.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,MAAM,uBAAuB,CAAC;AAChD,OAAO,OAAO,MAAM,aAAa,CAAC;AAClC,OAAO,EAAqC,kBAAkB,EAAE,iBAAiB,EAA+B,MAAM,oBAAoB,CAAC;AAM3I,cAAM,YAAa,SAAQ,OAAO;gBACpB,KAAK,EAAE,iBAAiB;IAIpC,SAAS,IAAI,MAAM,CAAC,WAAW;IAsC/B,MAAM,CAAC,YAAY,CAAC,GAAG,EAAE,MAAM,CAAC,WAAW,GAAG,YAAY;IA+B1D;;;;OAIG;IACH,SAAS,IAAI,kBAAkB,GAAG,SAAS;IAI3C;;;;OAIG;IACH,MAAM,CAAC,cAAc,CAAC,UAAU,EAAE,MAAM,CAAC,cAAc,GAAG,GAAG;CAI9D;AAED,eAAe,YAAY,CAAC"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import * as avs_pb from "@/grpc_codegen/avs_pb";
|
|
2
2
|
import Trigger from "./interface";
|
|
3
3
|
import { TriggerType } from "@avaprotocol/types";
|
|
4
|
+
import { convertInputToProtobuf, extractInputFromProtobuf } from "../../utils";
|
|
4
5
|
// Required props for constructor: id, name, type and data: { interval }
|
|
5
6
|
class BlockTrigger extends Trigger {
|
|
6
7
|
constructor(props) {
|
|
@@ -27,6 +28,11 @@ class BlockTrigger extends Trigger {
|
|
|
27
28
|
const config = new avs_pb.BlockTrigger.Config();
|
|
28
29
|
config.setInterval(blockData.interval);
|
|
29
30
|
trigger.setConfig(config);
|
|
31
|
+
// Use utility function to convert input field to protobuf format
|
|
32
|
+
const inputValue = convertInputToProtobuf(this.input);
|
|
33
|
+
if (inputValue) {
|
|
34
|
+
trigger.setInput(inputValue);
|
|
35
|
+
}
|
|
30
36
|
request.setBlock(trigger);
|
|
31
37
|
return request;
|
|
32
38
|
}
|
|
@@ -34,6 +40,7 @@ class BlockTrigger extends Trigger {
|
|
|
34
40
|
// Convert the raw object to TriggerProps, which should keep name and id
|
|
35
41
|
const obj = raw.toObject();
|
|
36
42
|
let data = { interval: 0 };
|
|
43
|
+
let input = undefined;
|
|
37
44
|
if (raw.getBlock() && raw.getBlock().hasConfig()) {
|
|
38
45
|
const config = raw.getBlock().getConfig();
|
|
39
46
|
if (config) {
|
|
@@ -41,11 +48,17 @@ class BlockTrigger extends Trigger {
|
|
|
41
48
|
interval: config.getInterval() || 0
|
|
42
49
|
};
|
|
43
50
|
}
|
|
51
|
+
// Use utility function to extract input field from protobuf format
|
|
52
|
+
const blockTrigger = raw.getBlock();
|
|
53
|
+
if (blockTrigger.hasInput()) {
|
|
54
|
+
input = extractInputFromProtobuf(blockTrigger.getInput());
|
|
55
|
+
}
|
|
44
56
|
}
|
|
45
57
|
return new BlockTrigger({
|
|
46
58
|
...obj,
|
|
47
59
|
type: TriggerType.Block,
|
|
48
60
|
data: data,
|
|
61
|
+
input: input,
|
|
49
62
|
});
|
|
50
63
|
}
|
|
51
64
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cron.d.ts","sourceRoot":"","sources":["../../../src/models/trigger/cron.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,MAAM,uBAAuB,CAAC;
|
|
1
|
+
{"version":3,"file":"cron.d.ts","sourceRoot":"","sources":["../../../src/models/trigger/cron.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,MAAM,uBAAuB,CAAC;AAEhD,OAAO,OAAO,MAAM,aAAa,CAAC;AAClC,OAAO,EAAoC,iBAAiB,EAAE,gBAAgB,EAAgB,MAAM,oBAAoB,CAAC;AAEzH,cAAM,WAAY,SAAQ,OAAO;gBACnB,KAAK,EAAE,gBAAgB;IAInC,SAAS,IAAI,MAAM,CAAC,WAAW;IA0C/B,MAAM,CAAC,YAAY,CAAC,GAAG,EAAE,MAAM,CAAC,WAAW,GAAG,WAAW;IAiCzD;;;;OAIG;IACH,SAAS,IAAI,iBAAiB,GAAG,SAAS;IAI1C;;;;;OAKG;IACH,MAAM,CAAC,cAAc,CAAC,UAAU,EAAE,MAAM,CAAC,cAAc,GAAG,GAAG;CAW9D;AAED,eAAe,WAAW,CAAC"}
|