Skip to content

Commit 44147d3

Browse files
authored
Minor release: Added Execution.Step, getWorkflowCount and getExecutionCount (#103)
* Renamed methods to use the same ones as sdk * Added getWorkflowCount and getExecutionCount * Record changeset minor release * Added step.test.ts and tested triggerOutput in tests/triggerWorkflow.test.ts * Added Step tests to package.json and Github Actions * Added Output to Execution Step model * Renovated auth tests * Renovated create, cancel, delete * Renovated existing tests and verified execution output in triggerWorkflow.test.ts * docs(changeset): Added Output and Step properties to Execution response * Remove failed execution tests from the current PR * RELEASING: Releasing 1 package(s) Releases: @avaprotocol/[email protected] [skip ci] * Remove unintended code for a non-existent node * Disable getExecution test runs in github actions
1 parent 465c43b commit 44147d3

29 files changed

+1785
-1226
lines changed

.changeset/config.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"$schema": "https://unpkg.com/@changesets/[email protected]/schema.json",
33
"changelog": "@changesets/cli/changelog",
4-
"commit": false,
4+
"commit": true,
55
"fixed": [],
66
"linked": [],
77
"access": "restricted",

.changeset/strange-countries-draw.md

-5
This file was deleted.

.github/workflows/dev-test-on-pr.yml

+12-8
Original file line numberDiff line numberDiff line change
@@ -27,31 +27,31 @@ jobs:
2727
echo "PR Base SHA: ${{ github.event.pull_request.base.sha }}"
2828
echo "PR Head SHA: ${{ github.event.pull_request.head.sha }}"
2929
echo "GitHub Ref: ${{ github.ref }}"
30-
30+
3131
# Ensure we have the base branch
3232
git fetch origin ${{ github.base_ref }} --depth=1
33-
33+
3434
# Get all changed files
3535
CHANGED_FILES=$(git diff --name-only origin/${{ github.base_ref }} HEAD)
36-
36+
3737
# Define the source code patterns we want to monitor
3838
SOURCE_PATTERN='^(packages/sdk-js/src|packages/types/src|tests)'
39-
39+
4040
echo "=== Debug Information ==="
4141
echo "Base ref: ${{ github.base_ref }}"
4242
echo "Current branch: $(git branch --show-current)"
4343
echo "Git status:"
4444
git status
45-
45+
4646
echo "=== Changed Files ==="
4747
echo "$CHANGED_FILES"
48-
48+
4949
# Check if any files in our monitored directories have changed
5050
MATCHING_FILES=$(echo "$CHANGED_FILES" | grep -E "$SOURCE_PATTERN" || echo "")
51-
51+
5252
echo "=== Matching Files ==="
5353
echo "$MATCHING_FILES"
54-
54+
5555
if [ -z "$MATCHING_FILES" ]; then
5656
echo "source_changed=false" >> $GITHUB_OUTPUT
5757
echo "No changes detected in monitored directories, skipping tests"
@@ -121,6 +121,10 @@ jobs:
121121
if: steps.check_source_changes.outputs.source_changed == 'true'
122122
run: yarn test:deleteWorkflow
123123

124+
# - name: Test Get Execution
125+
# if: steps.check_source_changes.outputs.source_changed == 'true'
126+
# run: yarn test:getExecution
127+
124128
- name: Test Get Executions
125129
if: steps.check_source_changes.outputs.source_changed == 'true'
126130
run: yarn test:getExecutions

.github/workflows/staging-test-on-pr.yml

+13-9
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ jobs:
2828
uses: actions/checkout@v4
2929
with:
3030
ref: ${{ github.event.pull_request.head.ref }}
31-
fetch-depth: 0 # Fetch all history for all branches
31+
fetch-depth: 0 # Fetch all history for all branches
3232

3333
- name: Debug environment variables
3434
run: |
@@ -43,31 +43,31 @@ jobs:
4343
echo "PR Head Ref: ${{ github.event.pull_request.head.ref }}"
4444
echo "GitHub Ref: ${{ github.ref }}"
4545
echo "Base Branch: ${{ github.base_ref }}"
46-
46+
4747
# Fetch both branches
4848
git fetch origin ${{ github.base_ref }}
4949
git fetch origin ${{ github.event.pull_request.head.ref }}
50-
50+
5151
# Get all changed files (only names)
5252
CHANGED_FILES=$(git diff --name-only origin/${{ github.base_ref }} HEAD)
53-
53+
5454
# Define the source code patterns we want to monitor
5555
SOURCE_PATTERN='^(packages/sdk-js/src|packages/types/src|tests)'
56-
56+
5757
echo "=== Git Information ==="
5858
echo "Current branch: $(git branch --show-current)"
5959
echo "Git status:"
6060
git status
61-
61+
6262
echo "=== Changed Files ==="
6363
echo "$CHANGED_FILES"
64-
64+
6565
# Check if any files in our monitored directories have changed
6666
MATCHING_FILES=$(echo "$CHANGED_FILES" | grep -E "$SOURCE_PATTERN" || echo "")
67-
67+
6868
echo "=== Matching Files ==="
6969
echo "$MATCHING_FILES"
70-
70+
7171
if [ -z "$MATCHING_FILES" ]; then
7272
echo "source_changed=false" >> $GITHUB_OUTPUT
7373
echo "No changes detected in monitored directories, skipping tests"
@@ -117,6 +117,10 @@ jobs:
117117
if: steps.check_source_changes.outputs.source_changed == 'true'
118118
run: yarn test:deleteWorkflow
119119

120+
# - name: Test Get Execution
121+
# if: steps.check_source_changes.outputs.source_changed == 'true'
122+
# run: yarn test:getExecution
123+
120124
- name: Test Get Executions
121125
if: steps.check_source_changes.outputs.source_changed == 'true'
122126
run: yarn test:getExecutions

examples/example.ts

+41-32
Original file line numberDiff line numberDiff line change
@@ -59,23 +59,24 @@ async function signMessageWithEthers(wallet, message: string) {
5959
return signature;
6060
}
6161

62-
async function listTask(owner: string, token: string) {
63-
const opts = {
64-
cursor: process.argv[5] || "",
65-
limit: parseInt(process.argv[4]) || DEFAULT_PAGE_LIMIT,
66-
authKey: token,
67-
};
68-
69-
const input = process.argv[3];
70-
62+
async function getWorkflows(
63+
address: string,
64+
options: { authKey: string; cursor: string; limit: number }
65+
) {
7166
let params = [];
67+
const validOptions = {
68+
authKey: options.authKey,
69+
cursor: options.cursor || "",
70+
limit: options.limit || DEFAULT_PAGE_LIMIT,
71+
};
7272

73-
if (_.isEmpty(input)) {
73+
if (_.isEmpty(address)) {
7474
console.log(
75-
"process.argv[3] is empty, fetching all wallet addresses as params ..."
75+
"address is empty, fetching all wallet addresses as params ..."
7676
);
7777

78-
const wallets = await getWallets(owner, token);
78+
const wallets = await client.getWallets({ authKey: validOptions.authKey });
79+
7980
console.log(`Found ${wallets.length} smart wallets ...`);
8081
params = _.map(wallets, (wallet: any) => wallet.address);
8182

@@ -87,20 +88,25 @@ async function listTask(owner: string, token: string) {
8788
return;
8889
}
8990
} else {
90-
params = _.split(input, ",");
91+
params = _.split(address, ",");
9192
}
9293

93-
const result = await client.getWorkflows(params, opts);
94+
console.log(
95+
`Calling getWorkflows with cursor`,
96+
validOptions.cursor,
97+
`and limit`,
98+
validOptions.limit
99+
);
94100

95-
console.log(`List tasks with cursor`, opts.cursor, `and limit`, opts.limit);
101+
const result = await client.getWorkflows(params, validOptions);
96102

97103
console.log(
98104
"getWorkflows response:\n",
99105
util.inspect(result, { depth: 6, colors: true })
100106
);
101107
}
102108

103-
async function listExecutions(
109+
async function getExecutions(
104110
workflowIdsString: string,
105111
options: {
106112
authKey: string;
@@ -674,14 +680,14 @@ const main = async (cmd: string) => {
674680
case "auth-key":
675681
console.log("The authkey associate with the EOA is", authKey);
676682
break;
677-
case "wallet":
683+
case "getWallets":
678684
const wallets = await client.getWallets({ authKey });
679685
console.log(
680686
"getWallets response:\n",
681687
util.inspect(wallets, { depth: 6, colors: true })
682688
);
683689
break;
684-
case "create-wallet":
690+
case "getWallet":
685691
const salt = commandArgs.args[0];
686692
const factoryAddress = getConfig().FACTORY_ADDRESS;
687693
let smartWalletAddress = await client.getWallet(
@@ -721,11 +727,16 @@ const main = async (cmd: string) => {
721727
);
722728
break;
723729

724-
case "tasks":
725-
await listTask(owner, authKey);
730+
case "getWorkflows":
731+
const address = commandArgs.args[0];
732+
await getWorkflows(address, {
733+
cursor: commandArgs.args[1],
734+
limit: _.toNumber(commandArgs.args[2]),
735+
authKey,
736+
});
726737
break;
727738

728-
case "get":
739+
case "getWorkflow":
729740
const taskId = commandArgs.args[0];
730741
const result = await client.getWorkflow(taskId, {
731742
authKey,
@@ -737,8 +748,8 @@ const main = async (cmd: string) => {
737748
);
738749
break;
739750

740-
case "executions":
741-
await listExecutions(commandArgs.args[0], {
751+
case "getExecutions":
752+
await getExecutions(commandArgs.args[0], {
742753
authKey,
743754
cursor: commandArgs.args[1],
744755
limit: _.toNumber(commandArgs.args[2]),
@@ -757,18 +768,16 @@ const main = async (cmd: string) => {
757768
);
758769
break;
759770
case "cancel":
760-
const resultCancel = await client.cancelWorkflow(
761-
commandArgs.args[0],
762-
{ authKey }
763-
);
771+
const resultCancel = await client.cancelWorkflow(commandArgs.args[0], {
772+
authKey,
773+
});
764774

765775
console.log("Response:\n", resultCancel);
766776
break;
767-
case "delete":
768-
const resultDelete = await client.deleteWorkflow(
769-
commandArgs.args[0],
770-
{ authKey }
771-
);
777+
case "deleteWorkflow":
778+
const resultDelete = await client.deleteWorkflow(commandArgs.args[0], {
779+
authKey,
780+
});
772781

773782
console.log("Response:\n", resultDelete);
774783
break;

jest.config.cjs

+1
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,5 @@ module.exports = {
1212
"^@/grpc_codegen/(.*)$": "<rootDir>/grpc_codegen/$1",
1313
"^@/types/(.*)$": "<rootDir>/packages/types/$1",
1414
},
15+
setupFilesAfterEnv: ["<rootDir>/tests/mocks/api.ts"],
1516
};

package.json

+3
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
"test:getWorkflows": "jest tests/getWorkflows.test.ts --verbose --runInBand",
2727
"test:cancelWorkflow": "jest tests/cancelWorkflow.test.ts --verbose --runInBand",
2828
"test:deleteWorkflow": "jest tests/deleteWorkflow.test.ts --verbose --runInBand",
29+
"test:getExecution": "jest tests/getExecution.test.ts --verbose --runInBand",
2930
"test:getExecutions": "jest tests/getExecutions.test.ts --verbose --runInBand",
3031
"test:getWallet": "jest tests/getWallet.test.ts --verbose --runInBand",
3132
"test:getWallets": "jest tests/getWallets.test.ts --verbose --runInBand",
@@ -41,10 +42,12 @@
4142
"@changesets/cli": "^2.27.9",
4243
"@eslint/js": "^9.16.0",
4344
"@jest/globals": "^29.7.0",
45+
"@types/axios": "^0.14.4",
4446
"@types/jest": "^29.5.13",
4547
"@types/lodash": "^4.17.12",
4648
"@typescript-eslint/eslint-plugin": "^8.17.0",
4749
"@typescript-eslint/parser": "^8.17.0",
50+
"axios": "^1.8.4",
4851
"babel-jest": "^29.7.0",
4952
"eslint": "^9.16.0",
5053
"globals": "^15.13.0",

packages/sdk-js/CHANGELOG.md

+11
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
11
# @avaprotocol/sdk-js
22

3+
## 1.4.0
4+
5+
### Minor Changes
6+
7+
- 5a4bad7: Added getWorkflowCount and getExecutionCount methods
8+
- 4769b3c: Added Output and Step properties to Execution response
9+
10+
### Patch Changes
11+
12+
- ba9b001: Sync to the latest grpc_codegen and remove step.outputdata that caused build error
13+
314
## 1.3.8
415

516
### Patch Changes

packages/sdk-js/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@avaprotocol/sdk-js",
3-
"version": "1.3.8",
3+
"version": "1.4.0",
44
"description": "A JavaScript/TypeScript SDK designed to simplify integration with Ava Protocol's AVS",
55
"main": "dist/index.js",
66
"types": "dist/index.d.ts",

packages/sdk-js/src/index.ts

+42
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,27 @@ class Client extends BaseClient {
327327
};
328328
}
329329

330+
/**
331+
* Get the count of workflows for multiple addresses
332+
* @param addresses - The list of addresses
333+
* @param options - Request options
334+
* @returns {Promise<number>} - The count of workflows
335+
*/
336+
async getWorkflowCount(
337+
addresses: string[],
338+
options?: RequestOptions
339+
): Promise<number> {
340+
const request = new avs_pb.GetWorkflowCountReq();
341+
request.setAddressesList(addresses);
342+
343+
const result = await this.sendGrpcRequest<
344+
avs_pb.GetWorkflowCountResp,
345+
avs_pb.GetWorkflowCountReq
346+
>("getWorkflowCount", request, options);
347+
348+
return result.getTotal();
349+
}
350+
330351
/**
331352
* Get the list of executions for multiple workflow given in the workflows argument.
332353
* @param {string[]} workflows - The list of workflow ids to fetch execution for
@@ -386,6 +407,27 @@ class Client extends BaseClient {
386407
return Execution.fromResponse(result);
387408
}
388409

410+
/**
411+
* Get the count of executions for multiple workflows
412+
* @param workflowIds - The list of workflow ids
413+
* @param options - Request options
414+
* @returns {Promise<number>} - The count of executions
415+
*/
416+
async getExecutionCount(
417+
workflowIds: string[],
418+
options?: RequestOptions
419+
): Promise<number> {
420+
const request = new avs_pb.GetExecutionCountReq();
421+
request.setWorkflowIdsList(workflowIds);
422+
423+
const result = await this.sendGrpcRequest<
424+
avs_pb.GetExecutionCountResp,
425+
avs_pb.GetExecutionCountReq
426+
>("getExecutionCount", request, options);
427+
428+
return result.getTotal();
429+
}
430+
389431
/**
390432
* Get status of an execution.
391433
*

0 commit comments

Comments
 (0)