@avaprotocol/sdk-js 1.4.0 → 1.5.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.
Files changed (82) hide show
  1. package/CHANGELOG.md +11 -0
  2. package/dist/auth.d.ts +2 -0
  3. package/dist/auth.d.ts.map +1 -0
  4. package/dist/auth.js +10 -0
  5. package/dist/config.d.ts +9 -0
  6. package/dist/config.d.ts.map +1 -0
  7. package/dist/config.js +19 -0
  8. package/dist/index.d.ts +58 -2750
  9. package/dist/index.d.ts.map +1 -0
  10. package/dist/index.js +1260 -492
  11. package/dist/index.mjs +1257 -484
  12. package/dist/models/edge.d.ts +12 -0
  13. package/dist/models/edge.d.ts.map +1 -0
  14. package/dist/models/edge.js +19 -0
  15. package/dist/models/execution.d.ts +25 -0
  16. package/dist/models/execution.d.ts.map +1 -0
  17. package/dist/models/execution.js +48 -0
  18. package/dist/models/node/branch.d.ts +14 -0
  19. package/dist/models/node/branch.d.ts.map +1 -0
  20. package/dist/models/node/branch.js +33 -0
  21. package/dist/models/node/contractRead.d.ts +14 -0
  22. package/dist/models/node/contractRead.d.ts.map +1 -0
  23. package/dist/models/node/contractRead.js +29 -0
  24. package/dist/models/node/contractWrite.d.ts +14 -0
  25. package/dist/models/node/contractWrite.d.ts.map +1 -0
  26. package/dist/models/node/contractWrite.js +29 -0
  27. package/dist/models/node/customCode.d.ts +15 -0
  28. package/dist/models/node/customCode.d.ts.map +1 -0
  29. package/dist/models/node/customCode.js +29 -0
  30. package/dist/models/node/ethTransfer.d.ts +14 -0
  31. package/dist/models/node/ethTransfer.d.ts.map +1 -0
  32. package/dist/models/node/ethTransfer.js +28 -0
  33. package/dist/models/node/factory.d.ts +20 -0
  34. package/dist/models/node/factory.d.ts.map +1 -0
  35. package/dist/models/node/factory.js +67 -0
  36. package/dist/models/node/filter.d.ts +14 -0
  37. package/dist/models/node/filter.d.ts.map +1 -0
  38. package/dist/models/node/filter.js +28 -0
  39. package/dist/models/node/graphqlQuery.d.ts +14 -0
  40. package/dist/models/node/graphqlQuery.d.ts.map +1 -0
  41. package/dist/models/node/graphqlQuery.js +37 -0
  42. package/dist/models/node/interface.d.ts +18 -0
  43. package/dist/models/node/interface.d.ts.map +1 -0
  44. package/dist/models/node/interface.js +37 -0
  45. package/dist/models/node/restApi.d.ts +15 -0
  46. package/dist/models/node/restApi.d.ts.map +1 -0
  47. package/dist/models/node/restApi.js +34 -0
  48. package/dist/models/secret.d.ts +17 -0
  49. package/dist/models/secret.d.ts.map +1 -0
  50. package/dist/models/secret.js +22 -0
  51. package/dist/models/step.d.ts +19 -0
  52. package/dist/models/step.d.ts.map +1 -0
  53. package/dist/models/step.js +78 -0
  54. package/dist/models/trigger/block.d.ts +13 -0
  55. package/dist/models/trigger/block.d.ts.map +1 -0
  56. package/dist/models/trigger/block.js +30 -0
  57. package/dist/models/trigger/cron.d.ts +13 -0
  58. package/dist/models/trigger/cron.d.ts.map +1 -0
  59. package/dist/models/trigger/cron.js +30 -0
  60. package/dist/models/trigger/event.d.ts +13 -0
  61. package/dist/models/trigger/event.d.ts.map +1 -0
  62. package/dist/models/trigger/event.js +61 -0
  63. package/dist/models/trigger/factory.d.ts +27 -0
  64. package/dist/models/trigger/factory.d.ts.map +1 -0
  65. package/dist/models/trigger/factory.js +49 -0
  66. package/dist/models/trigger/fixedTime.d.ts +13 -0
  67. package/dist/models/trigger/fixedTime.d.ts.map +1 -0
  68. package/dist/models/trigger/fixedTime.js +30 -0
  69. package/dist/models/trigger/interface.d.ts +21 -0
  70. package/dist/models/trigger/interface.d.ts.map +1 -0
  71. package/dist/models/trigger/interface.js +16 -0
  72. package/dist/models/trigger/reason.d.ts +33 -0
  73. package/dist/models/trigger/reason.d.ts.map +1 -0
  74. package/dist/models/trigger/reason.js +93 -0
  75. package/dist/models/workflow.d.ts +54 -0
  76. package/dist/models/workflow.d.ts.map +1 -0
  77. package/dist/models/workflow.js +118 -0
  78. package/dist/utils.d.ts +3 -0
  79. package/dist/utils.d.ts.map +1 -0
  80. package/dist/utils.js +37 -0
  81. package/package.json +6 -4
  82. package/dist/index.d.mts +0 -2937
@@ -0,0 +1,15 @@
1
+ import { NodeProps } from "./interface";
2
+ import Node from "./interface";
3
+ import * as avs_pb from "@/grpc_codegen/avs_pb";
4
+ export type RestAPINodeData = avs_pb.RestAPINode.AsObject;
5
+ export type RestAPINodeOutput = avs_pb.RestAPINode.Output.AsObject;
6
+ export type RestAPINodeProps = NodeProps & {
7
+ data: RestAPINodeData;
8
+ };
9
+ declare class RestAPINode extends Node {
10
+ constructor(props: RestAPINodeProps);
11
+ static fromResponse(raw: avs_pb.TaskNode): RestAPINode;
12
+ toRequest(): avs_pb.TaskNode;
13
+ }
14
+ export default RestAPINode;
15
+ //# sourceMappingURL=restApi.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"restApi.d.ts","sourceRoot":"","sources":["../../../src/models/node/restApi.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,IAAI,MAAM,aAAa,CAAC;AAC/B,OAAO,KAAK,MAAM,MAAM,uBAAuB,CAAC;AAIhD,MAAM,MAAM,eAAe,GAAG,MAAM,CAAC,WAAW,CAAC,QAAQ,CAAC;AAC1D,MAAM,MAAM,iBAAiB,GAAG,MAAM,CAAC,WAAW,CAAC,MAAM,CAAC,QAAQ,CAAC;AAEnE,MAAM,MAAM,gBAAgB,GAAG,SAAS,GAAG;IACzC,IAAI,EAAE,eAAe,CAAC;CACvB,CAAC;AAEF,cAAM,WAAY,SAAQ,IAAI;gBAChB,KAAK,EAAE,gBAAgB;IAInC,MAAM,CAAC,YAAY,CAAC,GAAG,EAAE,MAAM,CAAC,QAAQ,GAAG,WAAW;IAUtD,SAAS,IAAI,MAAM,CAAC,QAAQ;CAqB7B;AAED,eAAe,WAAW,CAAC"}
@@ -0,0 +1,34 @@
1
+ import Node from "./interface";
2
+ import * as avs_pb from "@/grpc_codegen/avs_pb";
3
+ import { NodeType } from "@avaprotocol/types";
4
+ class RestAPINode extends Node {
5
+ constructor(props) {
6
+ super({ ...props, type: NodeType.RestAPI, data: props.data });
7
+ }
8
+ static fromResponse(raw) {
9
+ // Convert the raw object to RestAPINodeProps, which should keep name and id
10
+ const obj = raw.toObject();
11
+ return new RestAPINode({
12
+ ...obj,
13
+ type: NodeType.RestAPI,
14
+ data: raw.getRestApi().toObject(),
15
+ });
16
+ }
17
+ toRequest() {
18
+ const request = new avs_pb.TaskNode();
19
+ request.setId(this.id);
20
+ request.setName(this.name);
21
+ const nodeData = new avs_pb.RestAPINode();
22
+ nodeData.setUrl(this.data.url);
23
+ nodeData.setMethod(this.data.method);
24
+ nodeData.setBody(this.data.body);
25
+ const headers = this.data.headersMap;
26
+ const headersMap = nodeData.getHeadersMap();
27
+ headers.forEach(([key, value]) => {
28
+ headersMap.set(key, value);
29
+ });
30
+ request.setRestApi(nodeData);
31
+ return request;
32
+ }
33
+ }
34
+ export default RestAPINode;
@@ -0,0 +1,17 @@
1
+ import * as avs_pb from "@/grpc_codegen/avs_pb";
2
+ export type SecretProps = {
3
+ name: string;
4
+ secret: string;
5
+ workflowId?: string;
6
+ orgId?: string;
7
+ };
8
+ declare class Secret implements SecretProps {
9
+ name: string;
10
+ secret: string;
11
+ workflowId?: string;
12
+ orgId?: string;
13
+ constructor(props: SecretProps);
14
+ toRequest(): avs_pb.CreateOrUpdateSecretReq;
15
+ }
16
+ export default Secret;
17
+ //# sourceMappingURL=secret.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"secret.d.ts","sourceRoot":"","sources":["../../src/models/secret.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,MAAM,uBAAuB,CAAC;AAEhD,MAAM,MAAM,WAAW,GAAG;IACxB,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF,cAAM,MAAO,YAAW,WAAW;IACjC,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,KAAK,CAAC,EAAE,MAAM,CAAC;gBAEH,KAAK,EAAE,WAAW;IAO9B,SAAS,IAAI,MAAM,CAAC,uBAAuB;CAc5C;AAED,eAAe,MAAM,CAAC"}
@@ -0,0 +1,22 @@
1
+ import * as avs_pb from "@/grpc_codegen/avs_pb";
2
+ class Secret {
3
+ constructor(props) {
4
+ this.name = props.name;
5
+ this.secret = props.secret;
6
+ this.workflowId = props.workflowId;
7
+ this.orgId = props.orgId;
8
+ }
9
+ toRequest() {
10
+ const request = new avs_pb.CreateOrUpdateSecretReq();
11
+ request.setName(this.name);
12
+ request.setSecret(this.secret);
13
+ if (this.orgId) {
14
+ request.setOrgId(this.orgId);
15
+ }
16
+ if (this.workflowId) {
17
+ request.setWorkflowId(this.workflowId);
18
+ }
19
+ return request;
20
+ }
21
+ }
22
+ export default Secret;
@@ -0,0 +1,19 @@
1
+ import * as avs_pb from "@/grpc_codegen/avs_pb";
2
+ export type StepProps = Omit<avs_pb.Execution.Step.AsObject, "outputDataCase" | "ethTransfer" | "graphql" | "contractRead" | "contractWrite" | "customCode" | "restApi" | "branch" | "filter" | "loop"> & {
3
+ output: any;
4
+ };
5
+ declare class Step implements StepProps {
6
+ nodeId: string;
7
+ success: boolean;
8
+ log: string;
9
+ error: string;
10
+ startAt: number;
11
+ endAt: number;
12
+ inputsList: string[];
13
+ output: any;
14
+ constructor(props: StepProps);
15
+ static getOutput(step: avs_pb.Execution.Step): any;
16
+ static fromResponse(step: avs_pb.Execution.Step): Step;
17
+ }
18
+ export default Step;
19
+ //# sourceMappingURL=step.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"step.d.ts","sourceRoot":"","sources":["../../src/models/step.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,MAAM,uBAAuB,CAAC;AAGhD,MAAM,MAAM,SAAS,GAAG,IAAI,CAC1B,MAAM,CAAC,SAAS,CAAC,IAAI,CAAC,QAAQ,EAC5B,gBAAgB,GAChB,aAAa,GACb,SAAS,GACT,cAAc,GACd,eAAe,GACf,YAAY,GACZ,SAAS,GACT,QAAQ,GACR,QAAQ,GACR,MAAM,CACT,GAAG;IACF,MAAM,EAAE,GAAG,CAAC;CACb,CAAC;AAKF,cAAM,IAAK,YAAW,SAAS;IAC7B,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,OAAO,CAAC;IACjB,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,EAAE,MAAM,CAAC;IACd,UAAU,EAAE,MAAM,EAAE,CAAC;IACrB,MAAM,EAAE,GAAG,CAAC;gBAEA,KAAK,EAAE,SAAS;IAW5B,MAAM,CAAC,SAAS,CAAC,IAAI,EAAE,MAAM,CAAC,SAAS,CAAC,IAAI,GAAG,GAAG;IAqDlD,MAAM,CAAC,YAAY,CAAC,IAAI,EAAE,MAAM,CAAC,SAAS,CAAC,IAAI,GAAG,IAAI;CAcvD;AAED,eAAe,IAAI,CAAC"}
@@ -0,0 +1,78 @@
1
+ import * as avs_pb from "@/grpc_codegen/avs_pb";
2
+ import { convertProtobufValueToJs } from "../utils";
3
+ // OutputDataProps is no longer a union of AsObject, it will be the converted JS type via 'output'
4
+ // export type OutputDataProps = ... (removed)
5
+ class Step {
6
+ constructor(props) {
7
+ this.nodeId = props.nodeId;
8
+ this.success = props.success;
9
+ this.log = props.log;
10
+ this.error = props.error;
11
+ this.startAt = props.startAt;
12
+ this.endAt = props.endAt;
13
+ this.inputsList = props.inputsList;
14
+ this.output = props.output;
15
+ }
16
+ static getOutput(step) {
17
+ const outputDataType = step.getOutputDataCase();
18
+ let nodeOutputMessage;
19
+ switch (outputDataType) {
20
+ case avs_pb.Execution.Step.OutputDataCase.OUTPUT_DATA_NOT_SET:
21
+ return null;
22
+ case avs_pb.Execution.Step.OutputDataCase.ETH_TRANSFER:
23
+ return step.getEthTransfer()?.toObject(); // Specific structure, not google.protobuf.Value
24
+ case avs_pb.Execution.Step.OutputDataCase.GRAPHQL:
25
+ nodeOutputMessage = step.getGraphql();
26
+ return nodeOutputMessage && nodeOutputMessage.hasData()
27
+ ? nodeOutputMessage.getData()
28
+ : undefined;
29
+ case avs_pb.Execution.Step.OutputDataCase.CONTRACT_READ:
30
+ // ContractReadNode.Output has 'repeated google.protobuf.Value data'
31
+ nodeOutputMessage = step.getContractRead();
32
+ if (nodeOutputMessage) {
33
+ return nodeOutputMessage
34
+ .getDataList()
35
+ .map((val) => convertProtobufValueToJs(val));
36
+ }
37
+ return []; // Default to empty array if no data
38
+ case avs_pb.Execution.Step.OutputDataCase.CONTRACT_WRITE:
39
+ return step.getContractWrite()?.toObject(); // Specific structure
40
+ case avs_pb.Execution.Step.OutputDataCase.CUSTOM_CODE:
41
+ nodeOutputMessage = step.getCustomCode();
42
+ return nodeOutputMessage && nodeOutputMessage.hasData()
43
+ ? convertProtobufValueToJs(nodeOutputMessage.getData())
44
+ : undefined;
45
+ case avs_pb.Execution.Step.OutputDataCase.REST_API:
46
+ nodeOutputMessage = step.getRestApi();
47
+ return nodeOutputMessage && nodeOutputMessage.hasData()
48
+ ? nodeOutputMessage.getData()
49
+ : undefined;
50
+ case avs_pb.Execution.Step.OutputDataCase.BRANCH:
51
+ return step.getBranch()?.toObject(); // Specific structure
52
+ case avs_pb.Execution.Step.OutputDataCase.FILTER:
53
+ nodeOutputMessage = step.getFilter();
54
+ return nodeOutputMessage && nodeOutputMessage.hasData()
55
+ ? nodeOutputMessage.getData()
56
+ : undefined;
57
+ case avs_pb.Execution.Step.OutputDataCase.LOOP:
58
+ // LoopNode.Output has 'string data' - handle as plain string for now
59
+ return step.getLoop()?.getData();
60
+ default:
61
+ console.warn(`Unhandled output data type in Step.getOutput: ${outputDataType}`);
62
+ return undefined;
63
+ }
64
+ }
65
+ static fromResponse(step) {
66
+ return new Step({
67
+ nodeId: step.getNodeId(),
68
+ success: step.getSuccess(),
69
+ log: step.getLog(),
70
+ error: step.getError(),
71
+ startAt: step.getStartAt(),
72
+ endAt: step.getEndAt(),
73
+ inputsList: step.getInputsList(),
74
+ output: Step.getOutput(step),
75
+ });
76
+ }
77
+ }
78
+ export default Step;
@@ -0,0 +1,13 @@
1
+ import * as avs_pb from "@/grpc_codegen/avs_pb";
2
+ import Trigger, { TriggerProps } from "./interface";
3
+ export type BlockTriggerDataType = avs_pb.BlockCondition.AsObject;
4
+ export type BlockTriggerProps = TriggerProps & {
5
+ data: BlockTriggerDataType;
6
+ };
7
+ declare class BlockTrigger extends Trigger {
8
+ constructor(props: BlockTriggerProps);
9
+ toRequest(): avs_pb.TaskTrigger;
10
+ static fromResponse(raw: avs_pb.TaskTrigger): BlockTrigger;
11
+ }
12
+ export default BlockTrigger;
13
+ //# sourceMappingURL=block.d.ts.map
@@ -0,0 +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,OAAO,EAAE,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAIpD,MAAM,MAAM,oBAAoB,GAAG,MAAM,CAAC,cAAc,CAAC,QAAQ,CAAC;AAClE,MAAM,MAAM,iBAAiB,GAAG,YAAY,GAAG;IAAE,IAAI,EAAE,oBAAoB,CAAA;CAAE,CAAC;AAE9E,cAAM,YAAa,SAAQ,OAAO;gBACpB,KAAK,EAAE,iBAAiB;IAIpC,SAAS,IAAI,MAAM,CAAC,WAAW;IAgB/B,MAAM,CAAC,YAAY,CAAC,GAAG,EAAE,MAAM,CAAC,WAAW,GAAG,YAAY;CAU3D;AAED,eAAe,YAAY,CAAC"}
@@ -0,0 +1,30 @@
1
+ import * as avs_pb from "@/grpc_codegen/avs_pb";
2
+ import Trigger from "./interface";
3
+ import { TriggerType } from "@avaprotocol/types";
4
+ class BlockTrigger extends Trigger {
5
+ constructor(props) {
6
+ super({ ...props, type: TriggerType.Block, data: props.data });
7
+ }
8
+ toRequest() {
9
+ const request = new avs_pb.TaskTrigger();
10
+ request.setName(this.name);
11
+ request.setId(this.id);
12
+ if (!this.data) {
13
+ throw new Error(`Trigger data is missing for ${this.type}`);
14
+ }
15
+ const condition = new avs_pb.BlockCondition();
16
+ condition.setInterval(this.data.interval);
17
+ request.setBlock(condition);
18
+ return request;
19
+ }
20
+ static fromResponse(raw) {
21
+ // Convert the raw object to TriggerProps, which should keep name and id
22
+ const obj = raw.toObject();
23
+ return new BlockTrigger({
24
+ ...obj,
25
+ type: TriggerType.Block,
26
+ data: raw.getBlock().toObject(),
27
+ });
28
+ }
29
+ }
30
+ export default BlockTrigger;
@@ -0,0 +1,13 @@
1
+ import * as avs_pb from "@/grpc_codegen/avs_pb";
2
+ import Trigger, { TriggerProps } from "./interface";
3
+ export type CronTriggerDataType = avs_pb.CronCondition.AsObject;
4
+ export type CronTriggerProps = TriggerProps & {
5
+ data: CronTriggerDataType;
6
+ };
7
+ declare class CronTrigger extends Trigger {
8
+ constructor(props: CronTriggerProps);
9
+ toRequest(): avs_pb.TaskTrigger;
10
+ static fromResponse(raw: avs_pb.TaskTrigger): CronTrigger;
11
+ }
12
+ export default CronTrigger;
13
+ //# sourceMappingURL=cron.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cron.d.ts","sourceRoot":"","sources":["../../../src/models/trigger/cron.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,MAAM,uBAAuB,CAAC;AAChD,OAAO,OAAO,EAAE,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAGpD,MAAM,MAAM,mBAAmB,GAAG,MAAM,CAAC,aAAa,CAAC,QAAQ,CAAC;AAChE,MAAM,MAAM,gBAAgB,GAAG,YAAY,GAAG;IAAE,IAAI,EAAE,mBAAmB,CAAA;CAAE,CAAC;AAE5E,cAAM,WAAY,SAAQ,OAAO;gBACnB,KAAK,EAAE,gBAAgB;IAInC,SAAS,IAAI,MAAM,CAAC,WAAW;IAgB/B,MAAM,CAAC,YAAY,CAAC,GAAG,EAAE,MAAM,CAAC,WAAW,GAAG,WAAW;CAU1D;AAED,eAAe,WAAW,CAAC"}
@@ -0,0 +1,30 @@
1
+ import * as avs_pb from "@/grpc_codegen/avs_pb";
2
+ import Trigger from "./interface";
3
+ import { TriggerType } from "@avaprotocol/types";
4
+ class CronTrigger extends Trigger {
5
+ constructor(props) {
6
+ super({ ...props, type: TriggerType.Cron, data: props.data });
7
+ }
8
+ toRequest() {
9
+ const request = new avs_pb.TaskTrigger();
10
+ request.setName(this.name);
11
+ request.setId(this.id);
12
+ if (!this.data) {
13
+ throw new Error(`Trigger data is missing for ${this.type}`);
14
+ }
15
+ const condition = new avs_pb.CronCondition();
16
+ condition.setScheduleList(this.data.scheduleList);
17
+ request.setCron(condition);
18
+ return request;
19
+ }
20
+ static fromResponse(raw) {
21
+ // Convert the raw object to TriggerProps, which should keep name and id
22
+ const obj = raw.toObject();
23
+ return new CronTrigger({
24
+ ...obj,
25
+ type: TriggerType.Cron,
26
+ data: raw.getCron().toObject(),
27
+ });
28
+ }
29
+ }
30
+ export default CronTrigger;
@@ -0,0 +1,13 @@
1
+ import * as avs_pb from "@/grpc_codegen/avs_pb";
2
+ import Trigger, { TriggerProps } from "./interface";
3
+ export type EventTriggerDataType = avs_pb.EventCondition.AsObject;
4
+ export type EventTriggerProps = TriggerProps & {
5
+ data: EventTriggerDataType;
6
+ };
7
+ declare class EventTrigger extends Trigger {
8
+ constructor(props: EventTriggerProps);
9
+ toRequest(): avs_pb.TaskTrigger;
10
+ static fromResponse(raw: avs_pb.TaskTrigger): EventTrigger;
11
+ }
12
+ export default EventTrigger;
13
+ //# sourceMappingURL=event.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"event.d.ts","sourceRoot":"","sources":["../../../src/models/trigger/event.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,MAAM,MAAM,uBAAuB,CAAC;AAChD,OAAO,OAAO,EAAE,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAuBpD,MAAM,MAAM,oBAAoB,GAAG,MAAM,CAAC,cAAc,CAAC,QAAQ,CAAC;AAElE,MAAM,MAAM,iBAAiB,GAAG,YAAY,GAAG;IAAE,IAAI,EAAE,oBAAoB,CAAA;CAAE,CAAC;AAE9E,cAAM,YAAa,SAAQ,OAAO;gBACpB,KAAK,EAAE,iBAAiB;IAIpC,SAAS,IAAI,MAAM,CAAC,WAAW;IAqC/B,MAAM,CAAC,YAAY,CAAC,GAAG,EAAE,MAAM,CAAC,WAAW,GAAG,YAAY;CA4B3D;AAED,eAAe,YAAY,CAAC"}
@@ -0,0 +1,61 @@
1
+ import * as _ from "lodash";
2
+ import * as avs_pb from "@/grpc_codegen/avs_pb";
3
+ import Trigger from "./interface";
4
+ import { TriggerType } from "@avaprotocol/types";
5
+ class EventTrigger extends Trigger {
6
+ constructor(props) {
7
+ super({ ...props, type: TriggerType.Event, data: props.data });
8
+ }
9
+ toRequest() {
10
+ const request = new avs_pb.TaskTrigger();
11
+ request.setName(this.name);
12
+ request.setId(this.id);
13
+ if (!this.data) {
14
+ throw new Error(`Trigger data is missing for ${this.type}`);
15
+ }
16
+ const condition = new avs_pb.EventCondition();
17
+ const expression = this.data.expression;
18
+ const matcherList = this.data.matcherList;
19
+ if (_.isUndefined(expression)) {
20
+ throw new Error(`Expression is undefined for ${this.type}`);
21
+ }
22
+ condition.setExpression(expression);
23
+ if (_.isUndefined(matcherList)) {
24
+ throw new Error(`Matcher list is undefined for ${this.type}`);
25
+ }
26
+ condition.setMatcherList(matcherList.map((element) => {
27
+ const m = new avs_pb.EventCondition.Matcher();
28
+ m.setType(element["type"]);
29
+ m.setValueList(element["valueList"]);
30
+ return m;
31
+ }));
32
+ request.setEvent(condition);
33
+ return request;
34
+ }
35
+ static fromResponse(raw) {
36
+ // Convert the raw object to TriggerProps, which should keep name and id
37
+ const obj = raw.toObject();
38
+ let data = {};
39
+ if (raw.getEvent().getExpression()) {
40
+ data.expression = raw.getEvent().getExpression();
41
+ }
42
+ if (raw.getEvent().getMatcherList()) {
43
+ data.matcherList = raw
44
+ .getEvent()
45
+ .getMatcherList()
46
+ .map((item) => {
47
+ return {
48
+ type: item.getType(),
49
+ valueList: item.getValueList(),
50
+ };
51
+ });
52
+ }
53
+ //raw.getEvent()!.toObject() as EventTriggerDataType;
54
+ return new EventTrigger({
55
+ ...obj,
56
+ type: TriggerType.Event,
57
+ data: data,
58
+ });
59
+ }
60
+ }
61
+ export default EventTrigger;
@@ -0,0 +1,27 @@
1
+ import * as avs_pb from "@/grpc_codegen/avs_pb";
2
+ import BlockTrigger, { BlockTriggerDataType } from "./block";
3
+ import { BlockTriggerProps } from "./block";
4
+ import CronTrigger, { CronTriggerDataType, CronTriggerProps } from "./cron";
5
+ import EventTrigger, { EventTriggerDataType, EventTriggerProps } from "./event";
6
+ import FixedTimeTrigger, { FixedTimeTriggerDataType, FixedTimeTriggerProps } from "./fixedTime";
7
+ import Trigger from "./interface";
8
+ import { TriggerProps } from "./interface";
9
+ declare class TriggerFactory {
10
+ /**
11
+ * Static factory method to create Trigger instances
12
+ * @param props
13
+ * @returns
14
+ */
15
+ static create(props: TriggerProps): Trigger;
16
+ /**
17
+ * Create an instance of Trigger from AVS getWorkflow or getWorkflows response
18
+ * @param trigger
19
+ * @returns
20
+ */
21
+ static fromResponse(raw: avs_pb.TaskTrigger): Trigger;
22
+ }
23
+ export default TriggerFactory;
24
+ export { Trigger, BlockTrigger, CronTrigger, EventTrigger, FixedTimeTrigger, };
25
+ export type { TriggerProps, BlockTriggerProps, CronTriggerProps, EventTriggerProps, FixedTimeTriggerProps, };
26
+ export type { BlockTriggerDataType, CronTriggerDataType, EventTriggerDataType, FixedTimeTriggerDataType, };
27
+ //# sourceMappingURL=factory.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"factory.d.ts","sourceRoot":"","sources":["../../../src/models/trigger/factory.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,MAAM,uBAAuB,CAAC;AAChD,OAAO,YAAY,EAAE,EAAE,oBAAoB,EAAE,MAAM,SAAS,CAAC;AAC7D,OAAO,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAC;AAC5C,OAAO,WAAW,EAAE,EAAE,mBAAmB,EAAE,gBAAgB,EAAE,MAAM,QAAQ,CAAC;AAC5E,OAAO,YAAY,EAAE,EAAE,oBAAoB,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAC;AAChF,OAAO,gBAAgB,EAAE,EACvB,wBAAwB,EACxB,qBAAqB,EACtB,MAAM,aAAa,CAAC;AACrB,OAAO,OAAO,MAAM,aAAa,CAAC;AAClC,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAE3C,cAAM,cAAc;IAClB;;;;OAIG;IACH,MAAM,CAAC,MAAM,CAAC,KAAK,EAAE,YAAY,GAAG,OAAO;IAgB3C;;;;OAIG;IACH,MAAM,CAAC,YAAY,CAAC,GAAG,EAAE,MAAM,CAAC,WAAW,GAAG,OAAO;CActD;AAED,eAAe,cAAc,CAAC;AAG9B,OAAO,EACL,OAAO,EACP,YAAY,EACZ,WAAW,EACX,YAAY,EACZ,gBAAgB,GACjB,CAAC;AAGF,YAAY,EACV,YAAY,EACZ,iBAAiB,EACjB,gBAAgB,EAChB,iBAAiB,EACjB,qBAAqB,GACtB,CAAC;AAGF,YAAY,EACV,oBAAoB,EACpB,mBAAmB,EACnB,oBAAoB,EACpB,wBAAwB,GACzB,CAAC"}
@@ -0,0 +1,49 @@
1
+ import BlockTrigger from "./block";
2
+ import CronTrigger from "./cron";
3
+ import EventTrigger from "./event";
4
+ import FixedTimeTrigger from "./fixedTime";
5
+ import Trigger from "./interface";
6
+ import { TriggerType } from "@avaprotocol/types";
7
+ class TriggerFactory {
8
+ /**
9
+ * Static factory method to create Trigger instances
10
+ * @param props
11
+ * @returns
12
+ */
13
+ static create(props) {
14
+ switch (props.type) {
15
+ case TriggerType.Block:
16
+ return new BlockTrigger(props);
17
+ case TriggerType.Cron:
18
+ return new CronTrigger(props);
19
+ case TriggerType.Event:
20
+ return new EventTrigger(props);
21
+ case TriggerType.FixedTime:
22
+ return new FixedTimeTrigger(props);
23
+ }
24
+ // Add more conditions for other subclasses
25
+ throw new Error("Unsupported trigger type");
26
+ }
27
+ /**
28
+ * Create an instance of Trigger from AVS getWorkflow or getWorkflows response
29
+ * @param trigger
30
+ * @returns
31
+ */
32
+ static fromResponse(raw) {
33
+ switch (true) {
34
+ case !!raw.getFixedTime():
35
+ return FixedTimeTrigger.fromResponse(raw);
36
+ case !!raw.getCron():
37
+ return CronTrigger.fromResponse(raw);
38
+ case !!raw.getBlock():
39
+ return BlockTrigger.fromResponse(raw);
40
+ case !!raw.getEvent():
41
+ return EventTrigger.fromResponse(raw);
42
+ default:
43
+ throw new Error("Unknown trigger type");
44
+ }
45
+ }
46
+ }
47
+ export default TriggerFactory;
48
+ // Trigger object definitions
49
+ export { Trigger, BlockTrigger, CronTrigger, EventTrigger, FixedTimeTrigger, };
@@ -0,0 +1,13 @@
1
+ import * as avs_pb from "@/grpc_codegen/avs_pb";
2
+ import Trigger, { TriggerProps } from "./interface";
3
+ export type FixedTimeTriggerDataType = avs_pb.FixedTimeCondition.AsObject;
4
+ export type FixedTimeTriggerProps = TriggerProps & {
5
+ data: FixedTimeTriggerDataType;
6
+ };
7
+ declare class FixedTimeTrigger extends Trigger {
8
+ constructor(props: FixedTimeTriggerProps);
9
+ toRequest(): avs_pb.TaskTrigger;
10
+ static fromResponse(raw: avs_pb.TaskTrigger): FixedTimeTrigger;
11
+ }
12
+ export default FixedTimeTrigger;
13
+ //# sourceMappingURL=fixedTime.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fixedTime.d.ts","sourceRoot":"","sources":["../../../src/models/trigger/fixedTime.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,MAAM,uBAAuB,CAAC;AAChD,OAAO,OAAO,EAAE,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAIpD,MAAM,MAAM,wBAAwB,GAAG,MAAM,CAAC,kBAAkB,CAAC,QAAQ,CAAC;AAC1E,MAAM,MAAM,qBAAqB,GAAG,YAAY,GAAG;IACjD,IAAI,EAAE,wBAAwB,CAAC;CAChC,CAAC;AAEF,cAAM,gBAAiB,SAAQ,OAAO;gBACxB,KAAK,EAAE,qBAAqB;IAIxC,SAAS,IAAI,MAAM,CAAC,WAAW;IAgB/B,MAAM,CAAC,YAAY,CAAC,GAAG,EAAE,MAAM,CAAC,WAAW,GAAG,gBAAgB;CAU/D;AAED,eAAe,gBAAgB,CAAC"}
@@ -0,0 +1,30 @@
1
+ import * as avs_pb from "@/grpc_codegen/avs_pb";
2
+ import Trigger from "./interface";
3
+ import { TriggerType } from "@avaprotocol/types";
4
+ class FixedTimeTrigger extends Trigger {
5
+ constructor(props) {
6
+ super({ ...props, type: TriggerType.FixedTime, data: props.data });
7
+ }
8
+ toRequest() {
9
+ const request = new avs_pb.TaskTrigger();
10
+ request.setName(this.name);
11
+ request.setId(this.id);
12
+ if (!this.data) {
13
+ throw new Error(`Trigger data is missing for ${this.type}`);
14
+ }
15
+ const condition = new avs_pb.FixedTimeCondition();
16
+ condition.setEpochsList(this.data.epochsList);
17
+ request.setFixedTime(condition);
18
+ return request;
19
+ }
20
+ static fromResponse(raw) {
21
+ // Convert the raw object to TriggerProps, which should keep name and id
22
+ const obj = raw.toObject();
23
+ return new FixedTimeTrigger({
24
+ ...obj,
25
+ type: TriggerType.FixedTime,
26
+ data: raw.getFixedTime().toObject(),
27
+ });
28
+ }
29
+ }
30
+ export default FixedTimeTrigger;
@@ -0,0 +1,21 @@
1
+ import * as avs_pb from "@/grpc_codegen/avs_pb";
2
+ import { TriggerType } from "@avaprotocol/types";
3
+ export type TriggerData = avs_pb.FixedTimeCondition.AsObject | avs_pb.CronCondition.AsObject | avs_pb.BlockCondition.AsObject | avs_pb.EventCondition.AsObject | null;
4
+ export type TriggerProps = Omit<avs_pb.TaskTrigger.AsObject, "manual" | "fixedTime" | "cron" | "block" | "event"> & {
5
+ type: TriggerType;
6
+ data: TriggerData;
7
+ };
8
+ declare class Trigger implements TriggerProps {
9
+ id: string;
10
+ name: string;
11
+ type: TriggerType;
12
+ data: TriggerData;
13
+ /**
14
+ * Create an instance of Trigger from user inputs
15
+ * @param props
16
+ */
17
+ constructor(props: TriggerProps);
18
+ toRequest(): avs_pb.TaskTrigger;
19
+ }
20
+ export default Trigger;
21
+ //# sourceMappingURL=interface.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"interface.d.ts","sourceRoot":"","sources":["../../../src/models/trigger/interface.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,MAAM,uBAAuB,CAAC;AAChD,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAEjD,MAAM,MAAM,WAAW,GACnB,MAAM,CAAC,kBAAkB,CAAC,QAAQ,GAClC,MAAM,CAAC,aAAa,CAAC,QAAQ,GAC7B,MAAM,CAAC,cAAc,CAAC,QAAQ,GAC9B,MAAM,CAAC,cAAc,CAAC,QAAQ,GAC9B,IAAI,CAAC;AAET,MAAM,MAAM,YAAY,GAAG,IAAI,CAC7B,MAAM,CAAC,WAAW,CAAC,QAAQ,EAC3B,QAAQ,GAAG,WAAW,GAAG,MAAM,GAAG,OAAO,GAAG,OAAO,CACpD,GAAG;IACF,IAAI,EAAE,WAAW,CAAC;IAClB,IAAI,EAAE,WAAW,CAAC;CACnB,CAAC;AAEF,cAAM,OAAQ,YAAW,YAAY;IACnC,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,WAAW,CAAC;IAClB,IAAI,EAAE,WAAW,CAAC;IAElB;;;OAGG;gBACS,KAAK,EAAE,YAAY;IAO/B,SAAS,IAAI,MAAM,CAAC,WAAW;CAGhC;AAED,eAAe,OAAO,CAAC"}
@@ -0,0 +1,16 @@
1
+ class Trigger {
2
+ /**
3
+ * Create an instance of Trigger from user inputs
4
+ * @param props
5
+ */
6
+ constructor(props) {
7
+ this.id = props.id;
8
+ this.name = props.name;
9
+ this.type = props.type;
10
+ this.data = props.data;
11
+ }
12
+ toRequest() {
13
+ throw new Error("Method not implemented.");
14
+ }
15
+ }
16
+ export default Trigger;
@@ -0,0 +1,33 @@
1
+ import * as avs_pb from "@/grpc_codegen/avs_pb";
2
+ import { TriggerType } from "@avaprotocol/types";
3
+ export type TriggerReasonProps = {
4
+ type: TriggerType.FixedTime;
5
+ epoch: number;
6
+ } | {
7
+ type: TriggerType.Cron;
8
+ epoch: number;
9
+ } | {
10
+ type: TriggerType.Block;
11
+ blockNumber: number;
12
+ } | {
13
+ type: TriggerType.Event;
14
+ blockNumber: number;
15
+ logIndex: number;
16
+ txHash: string;
17
+ } | {
18
+ type: TriggerType.Manual;
19
+ } | {
20
+ type: TriggerType.Unset;
21
+ };
22
+ declare class TriggerReason {
23
+ type: TriggerType;
24
+ blockNumber?: number;
25
+ epoch?: number;
26
+ logIndex?: number;
27
+ txHash?: string;
28
+ constructor(props: TriggerReasonProps);
29
+ static fromResponse(data: avs_pb.TriggerReason | undefined): TriggerReason | undefined;
30
+ toRequest(): avs_pb.TriggerReason;
31
+ }
32
+ export default TriggerReason;
33
+ //# sourceMappingURL=reason.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"reason.d.ts","sourceRoot":"","sources":["../../../src/models/trigger/reason.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,MAAM,uBAAuB,CAAC;AAChD,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAGjD,MAAM,MAAM,kBAAkB,GAC1B;IAAE,IAAI,EAAE,WAAW,CAAC,SAAS,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,GAC9C;IAAE,IAAI,EAAE,WAAW,CAAC,IAAI,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,GACzC;IAAE,IAAI,EAAE,WAAW,CAAC,KAAK,CAAC;IAAC,WAAW,EAAE,MAAM,CAAA;CAAE,GAChD;IACE,IAAI,EAAE,WAAW,CAAC,KAAK,CAAC;IACxB,WAAW,EAAE,MAAM,CAAC;IACpB,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,MAAM,CAAC;CAChB,GACD;IAAE,IAAI,EAAE,WAAW,CAAC,MAAM,CAAA;CAAE,GAC5B;IAAE,IAAI,EAAE,WAAW,CAAC,KAAK,CAAA;CAAE,CAAC;AAoBhC,cAAM,aAAa;IACjB,IAAI,EAAE,WAAW,CAAC;IAClB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,MAAM,CAAC,EAAE,MAAM,CAAC;gBAEJ,KAAK,EAAE,kBAAkB;IAsBrC,MAAM,CAAC,YAAY,CACjB,IAAI,EAAE,MAAM,CAAC,aAAa,GAAG,SAAS,GACrC,aAAa,GAAG,SAAS;IAc5B,SAAS,IAAI,MAAM,CAAC,aAAa;CA8ClC;AAED,eAAe,aAAa,CAAC"}