@avaprotocol/sdk-js 2.4.4 → 2.5.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.
@@ -1,58 +1,141 @@
1
1
  import * as avs_pb from "@/grpc_codegen/avs_pb";
2
2
  import Trigger from "./interface";
3
- import { convertInputToProtobuf, extractInputFromProtobuf } from "../../utils";
4
- import { TriggerType } from "@avaprotocol/types";
3
+ import { convertInputToProtobuf, extractInputFromProtobuf, convertProtobufValueToJs, } from "../../utils";
4
+ import { TriggerType, } from "@avaprotocol/types";
5
5
  class ManualTrigger extends Trigger {
6
6
  constructor(props) {
7
- super({ ...props, type: TriggerType.Manual, data: props.data || null });
7
+ super({
8
+ ...props,
9
+ type: TriggerType.Manual,
10
+ data: props.data,
11
+ input: props.input,
12
+ });
13
+ this.headers = props.headers;
14
+ this.pathParams = props.pathParams;
8
15
  }
9
16
  toRequest() {
10
17
  const trigger = new avs_pb.TaskTrigger();
11
18
  trigger.setId(this.id);
12
19
  trigger.setName(this.name);
13
20
  trigger.setType(avs_pb.TriggerType.TRIGGER_TYPE_MANUAL);
14
- trigger.setManual(true);
15
- // Convert input field to protobuf format and set on top-level TaskTrigger
16
- // Manual triggers use the top-level input field since they don't have nested structure
17
- const inputValue = convertInputToProtobuf(this.input);
18
- if (inputValue) {
19
- trigger.setInput(inputValue);
21
+ // Create ManualTrigger with proper config structure
22
+ const manualTrigger = new avs_pb.ManualTrigger();
23
+ const config = new avs_pb.ManualTrigger.Config();
24
+ // Set the data
25
+ const dataToSend = this.data ?? this.input;
26
+ if (dataToSend !== null && dataToSend !== undefined) {
27
+ const inputValue = convertInputToProtobuf(dataToSend);
28
+ if (inputValue) {
29
+ config.setData(inputValue);
30
+ }
31
+ }
32
+ // Set headers if provided - direct object to protobuf map mapping
33
+ if (this.headers && Object.keys(this.headers).length > 0) {
34
+ const headersMap = config.getHeadersMap();
35
+ Object.entries(this.headers).forEach(([key, value]) => {
36
+ headersMap.set(key, value);
37
+ });
20
38
  }
39
+ // Set pathParams if provided - direct object to protobuf map mapping
40
+ if (this.pathParams && Object.keys(this.pathParams).length > 0) {
41
+ const pathParamsMap = config.getPathparamsMap();
42
+ Object.entries(this.pathParams).forEach(([key, value]) => {
43
+ pathParamsMap.set(key, value);
44
+ });
45
+ }
46
+ manualTrigger.setConfig(config);
47
+ trigger.setManual(manualTrigger);
21
48
  return trigger;
22
49
  }
23
50
  static fromResponse(raw) {
24
51
  const obj = raw.toObject();
25
- // Extract input from top-level TaskTrigger input field for manual triggers
26
- let input = undefined;
27
- if (raw.hasInput()) {
28
- input = extractInputFromProtobuf(raw.getInput());
52
+ let data = null;
53
+ const input = undefined;
54
+ let headers = undefined;
55
+ let pathParams = undefined;
56
+ const manualTrigger = raw.getManual();
57
+ if (manualTrigger) {
58
+ const config = manualTrigger.getConfig();
59
+ if (config) {
60
+ // Extract data
61
+ if (config.hasData()) {
62
+ data = extractInputFromProtobuf(config.getData());
63
+ }
64
+ // Extract headers - direct protobuf map to object mapping
65
+ const headersMapProto = config.getHeadersMap();
66
+ if (headersMapProto && headersMapProto.getLength() > 0) {
67
+ headers = {};
68
+ headersMapProto.forEach((value, key) => {
69
+ headers[key] = value;
70
+ });
71
+ }
72
+ // Extract pathParams - direct protobuf map to object mapping
73
+ const pathParamsMapProto = config.getPathparamsMap();
74
+ if (pathParamsMapProto && pathParamsMapProto.getLength() > 0) {
75
+ pathParams = {};
76
+ pathParamsMapProto.forEach((value, key) => {
77
+ pathParams[key] = value;
78
+ });
79
+ }
80
+ }
29
81
  }
30
82
  return new ManualTrigger({
31
83
  ...obj,
32
84
  type: TriggerType.Manual,
33
- data: null, // Manual triggers don't have data in the protobuf response
85
+ data: data,
34
86
  input: input,
87
+ headers: headers,
88
+ pathParams: pathParams,
35
89
  });
36
90
  }
37
91
  getInputVariables() {
38
- return this.data;
39
- }
40
- /**
41
- * Convert raw data from runTrigger response to ManualOutput format
42
- * @param rawData - The raw data from the gRPC response
43
- * @returns {ManualTriggerOutput | undefined} - The converted data
44
- */
45
- getOutput() {
46
- return this.output;
92
+ // Return input variables that can be referenced by other nodes
93
+ return this.input;
47
94
  }
48
95
  /**
49
96
  * Extract output data from RunTriggerResp for manual triggers
50
97
  * @param outputData - The RunTriggerResp containing manual trigger output
51
- * @returns Plain JavaScript object with manual trigger data
98
+ * @returns Plain JavaScript object with manual trigger data in standard structure
52
99
  */
53
100
  static fromOutputData(outputData) {
54
101
  const manualOutput = outputData.getManualTrigger();
55
- return manualOutput?.toObject() || null;
102
+ if (!manualOutput) {
103
+ return null;
104
+ }
105
+ const result = {};
106
+ // Extract data
107
+ const dataValue = manualOutput.getData();
108
+ if (dataValue) {
109
+ try {
110
+ result.data = convertProtobufValueToJs(dataValue);
111
+ }
112
+ catch (error) {
113
+ console.warn("Failed to convert manual trigger data from protobuf Value:", error);
114
+ result.data = dataValue;
115
+ }
116
+ }
117
+ else {
118
+ result.data = null;
119
+ }
120
+ // Extract headers - always as object
121
+ const headersMapProto = manualOutput.getHeadersMap();
122
+ if (headersMapProto && headersMapProto.getLength() > 0) {
123
+ const headersObject = {};
124
+ headersMapProto.forEach((value, key) => {
125
+ headersObject[key] = value;
126
+ });
127
+ result.headers = headersObject;
128
+ }
129
+ // Extract pathParams - always as object
130
+ const pathParamsMapProto = manualOutput.getPathparamsMap();
131
+ if (pathParamsMapProto && pathParamsMapProto.getLength() > 0) {
132
+ const pathParamsObject = {};
133
+ pathParamsMapProto.forEach((value, key) => {
134
+ pathParamsObject[key] = value;
135
+ });
136
+ result.pathParams = pathParamsObject;
137
+ }
138
+ return result;
56
139
  }
57
140
  }
58
141
  export default ManualTrigger;
@@ -1 +1 @@
1
- {"version":3,"file":"workflow.d.ts","sourceRoot":"","sources":["../../src/models/workflow.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,MAAM,MAAM,uBAAuB,CAAC;AAChD,OAAO,IAAI,MAAM,kBAAkB,CAAC;AACpC,OAAO,IAAI,MAAM,QAAQ,CAAC;AAC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M,QAAQ,CAAC;AAC1B,OAAO,OAAO,MAAM,qBAAqB,CAAC;AAG1C,eAAO,MAAM,gBAAgB,KAAK,CAAC;AACnC,OAAO,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAGnE,wBAAgB,qBAAqB,CACnC,MAAM,EAAE,MAAM,CAAC,UAAU,GACxB,cAAc,CAUhB;AAED,cAAM,QAAS,YAAW,aAAa;IACrC,kBAAkB,EAAE,MAAM,CAAC;IAC3B,OAAO,EAAE,OAAO,CAAC;IACjB,KAAK,EAAE,IAAI,EAAE,CAAC;IACd,KAAK,EAAE,IAAI,EAAE,CAAC;IACd,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,MAAM,CAAC;IAClB,YAAY,EAAE,MAAM,CAAC;IAGrB,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,MAAM,CAAC,EAAE,cAAc,CAAC;IACxB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,cAAc,CAAC,EAAE,MAAM,CAAC;IAExB;;;OAGG;gBACS,KAAK,EAAE,aAAa;IAuBhC;;;;OAIG;IACH,MAAM,CAAC,YAAY,CAAC,GAAG,EAAE,MAAM,CAAC,IAAI,GAAG,QAAQ;IAkC/C;;;OAGG;IACH,MAAM,CAAC,gBAAgB,CAAC,GAAG,EAAE,MAAM,CAAC,IAAI,GAAG,QAAQ;IAyBnD,SAAS,IAAI,MAAM,CAAC,aAAa;IAsDjC;;;OAGG;IACH,MAAM,IAAI,aAAa;CAkBxB;AAED,eAAe,QAAQ,CAAC"}
@@ -145,8 +145,6 @@ class Workflow {
145
145
  if (this.name) {
146
146
  request.setName(this.name);
147
147
  }
148
- // Log final summary for debugging (only errors and counts)
149
- console.log(`📤 Workflow serialization: ${this.nodes.length} nodes, ${this.edges.length} edges -> protobuf: ${request.getNodesList().length} nodes, ${request.getEdgesList().length} edges`);
150
148
  return request;
151
149
  }
152
150
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@avaprotocol/sdk-js",
3
- "version": "2.4.4",
3
+ "version": "2.5.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.17",
34
+ "@avaprotocol/types": "^2.3.1",
35
35
  "@grpc/grpc-js": "^1.11.3",
36
36
  "@grpc/proto-loader": "^0.7.13",
37
37
  "dotenv": "^16.4.5",