@avaprotocol/sdk-js 1.3.6 → 1.4.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.
- package/CHANGELOG.md +70 -0
- package/README.md +122 -0
- package/dist/index.d.mts +788 -46
- package/dist/index.d.ts +788 -46
- package/dist/index.js +5301 -2117
- package/dist/index.mjs +5298 -2116
- package/package.json +2 -1
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
# @avaprotocol/sdk-js
|
|
2
|
+
|
|
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
|
+
|
|
14
|
+
## 1.3.8
|
|
15
|
+
|
|
16
|
+
### Patch Changes
|
|
17
|
+
|
|
18
|
+
- Made Client a regular export instead of default
|
|
19
|
+
|
|
20
|
+
## 1.3.7
|
|
21
|
+
|
|
22
|
+
### Patch Changes
|
|
23
|
+
|
|
24
|
+
- Added Secret and TriggerReason
|
|
25
|
+
|
|
26
|
+
## 1.3.6
|
|
27
|
+
|
|
28
|
+
### Patch Changes
|
|
29
|
+
|
|
30
|
+
- Fix the build file problem in 1.3.5
|
|
31
|
+
|
|
32
|
+
## 1.3.5
|
|
33
|
+
|
|
34
|
+
### Patch Changes
|
|
35
|
+
|
|
36
|
+
- b04cca3: Improved secret related code and tests
|
|
37
|
+
|
|
38
|
+
## 1.3.4
|
|
39
|
+
|
|
40
|
+
### Patch Changes
|
|
41
|
+
|
|
42
|
+
- Migrated getKeyRequestMessage to types; Added secret functions
|
|
43
|
+
- Updated dependencies
|
|
44
|
+
- @avaprotocol/types@0.9.4
|
|
45
|
+
|
|
46
|
+
## 1.3.3
|
|
47
|
+
|
|
48
|
+
### Patch Changes
|
|
49
|
+
|
|
50
|
+
- update the new auth method and trigger matcher array
|
|
51
|
+
|
|
52
|
+
## 1.3.2
|
|
53
|
+
|
|
54
|
+
### Patch Changes
|
|
55
|
+
|
|
56
|
+
- Updated Task.memo to Task.name and fixed a build warning in types package
|
|
57
|
+
- Updated dependencies
|
|
58
|
+
- @avaprotocol/types@0.9.3
|
|
59
|
+
|
|
60
|
+
## 1.3.1
|
|
61
|
+
|
|
62
|
+
### Patch Changes
|
|
63
|
+
|
|
64
|
+
- Update reference to types
|
|
65
|
+
|
|
66
|
+
## 1.3.0
|
|
67
|
+
|
|
68
|
+
### Minor Changes
|
|
69
|
+
|
|
70
|
+
- Initialize types package
|
package/README.md
ADDED
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
# Ava SDK for JavaScript/TypeScript
|
|
2
|
+
|
|
3
|
+
`@avaprotocol/sdk-js` is a simple, type-safe wrapper around gRPC designed to simplify integration with Ava Protocol’s AVS. It enables developers to interact with Ava Protocol efficiently, whether on the client-side or server-side, and provides full TypeScript support for a seamless development experience.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- Type-Safe SDK: Automatically generated TypeScript types from gRPC protocol buffers ensure type safety and reduce errors during development.
|
|
8
|
+
- Seamless Integration: Works in both Node.js and browser environments, optimized for frameworks like Next.js.
|
|
9
|
+
- Easy to Use: Abstracts the complexity of gRPC with a simple JavaScript/TypeScript API.
|
|
10
|
+
- Efficient Communication: Leverages gRPC for fast, efficient communication with Ava Protocol’s AVS (Actively Validated Services).
|
|
11
|
+
|
|
12
|
+
## Installation
|
|
13
|
+
|
|
14
|
+
To install `@avaprotocol/sdk-js`, run the following command:
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
npm install @avaprotocol/sdk-js
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
Or with Yarn:
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
yarn add @avaprotocol/sdk-js
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
## Getting Started
|
|
27
|
+
|
|
28
|
+
Here’s a quick example of how to use the SDK to get started with Ava Protocol:
|
|
29
|
+
|
|
30
|
+
```typescript
|
|
31
|
+
import { Client } from "@avaprotocol/sdk-js";
|
|
32
|
+
import { getServerSession } from "next-auth";
|
|
33
|
+
import { isAuthKeyValid } from "./utils";
|
|
34
|
+
import { authOptions } from "./auth/[...nextauth]/route";
|
|
35
|
+
|
|
36
|
+
let avaClient: Client | null = null;
|
|
37
|
+
const EXPIRED_AT = Math.floor(Date.now() / 1000) + 24 * 60 * 60; // 24 hours from now
|
|
38
|
+
|
|
39
|
+
async function initializeClient() {
|
|
40
|
+
if (avaClient) return avaClient;
|
|
41
|
+
|
|
42
|
+
if (!process.env.AVS_ENDPOINT) {
|
|
43
|
+
throw new Error("AVS_ENDPOINT is not set in environment variables.");
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
avaClient = new Client({
|
|
47
|
+
endpoint: process.env.AVS_ENDPOINT,
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
return avaClient;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Get the client instance, lazy initialize it if it's not initialized yet
|
|
55
|
+
* @returns
|
|
56
|
+
*/
|
|
57
|
+
export async function getClient() {
|
|
58
|
+
if (avaClient) {
|
|
59
|
+
return avaClient;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
return await initializeClient();
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Get the auth key using authWithAPIKey() for a wallet address before user signs in with a wallet signature
|
|
67
|
+
* @param walletAddress
|
|
68
|
+
* @returns
|
|
69
|
+
*/
|
|
70
|
+
async function getPresignAuthKey(walletAddress: string): Promise<string> {
|
|
71
|
+
const client = await getClient();
|
|
72
|
+
|
|
73
|
+
// Since we almost certainly need this env variable, we throw an error if it's not set
|
|
74
|
+
if (!process.env.AVS_API_KEY) {
|
|
75
|
+
throw new Error("AVS_API_KEY is not set in environment variables.");
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
const resp = await client.authWithAPIKey(
|
|
79
|
+
walletAddress,
|
|
80
|
+
process.env.AVS_API_KEY,
|
|
81
|
+
EXPIRED_AT
|
|
82
|
+
);
|
|
83
|
+
return resp.authKey;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Get the auth key for a wallet address
|
|
88
|
+
* First checks if the current session contains a valid auth key
|
|
89
|
+
* If not, it will get the auth key using authWithAPIKey() for the wallet address
|
|
90
|
+
* @param walletAddress
|
|
91
|
+
* @returns
|
|
92
|
+
*/
|
|
93
|
+
export async function getAuthKey(
|
|
94
|
+
walletAddress: string | undefined
|
|
95
|
+
): Promise<string | undefined> {
|
|
96
|
+
const session = await getServerSession(authOptions);
|
|
97
|
+
|
|
98
|
+
if (session?.user?.authKey) {
|
|
99
|
+
if (isAuthKeyValid(session?.user?.authKey)) {
|
|
100
|
+
return session?.user?.authKey;
|
|
101
|
+
} else {
|
|
102
|
+
console.warn(
|
|
103
|
+
`AuthKey is found for ${session?.user?.walletAddress} in session, but expired. Atempting to use authWithAPIKey`
|
|
104
|
+
);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
if (walletAddress) {
|
|
109
|
+
return await getPresignAuthKey(walletAddress);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
return undefined;
|
|
113
|
+
}
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
## Contributing
|
|
117
|
+
|
|
118
|
+
We welcome contributions! Feel free to submit pull requests or open issues for any bugs or feature requests.
|
|
119
|
+
|
|
120
|
+
## License
|
|
121
|
+
|
|
122
|
+
This project is licensed under the Apache 2.0 License. See the LICENSE file for more details.
|