@sogni-ai/sogni-client 0.3.3 → 0.4.0-aplha.10
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/README.md +3 -2
- package/dist/Account/CurrentAccount.d.ts +12 -2
- package/dist/Account/CurrentAccount.js.map +1 -1
- package/dist/Account/index.d.ts +130 -7
- package/dist/Account/index.js +135 -7
- package/dist/Account/index.js.map +1 -1
- package/dist/ApiClient/WebSocketClient/events.d.ts +7 -1
- package/dist/ApiClient/WebSocketClient/index.d.ts +1 -1
- package/dist/ApiClient/WebSocketClient/index.js +14 -5
- package/dist/ApiClient/WebSocketClient/index.js.map +1 -1
- package/dist/ApiClient/WebSocketClient/messages.d.ts +2 -0
- package/dist/Projects/Job.d.ts +25 -1
- package/dist/Projects/Job.js +78 -1
- package/dist/Projects/Job.js.map +1 -1
- package/dist/Projects/Project.d.ts +21 -3
- package/dist/Projects/Project.js +110 -2
- package/dist/Projects/Project.js.map +1 -1
- package/dist/Projects/createJobRequestMessage.d.ts +1 -61
- package/dist/Projects/createJobRequestMessage.js +5 -1
- package/dist/Projects/createJobRequestMessage.js.map +1 -1
- package/dist/Projects/index.d.ts +22 -3
- package/dist/Projects/index.js +82 -14
- package/dist/Projects/index.js.map +1 -1
- package/dist/Projects/types/RawProject.d.ts +87 -0
- package/dist/Projects/types/RawProject.js +3 -0
- package/dist/Projects/types/RawProject.js.map +1 -0
- package/dist/Projects/types/events.d.ts +2 -0
- package/dist/Projects/types/index.d.ts +4 -0
- package/dist/lib/DataEntity.d.ts +1 -0
- package/dist/lib/DataEntity.js +2 -0
- package/dist/lib/DataEntity.js.map +1 -1
- package/dist/lib/base64.js +8 -6
- package/dist/lib/base64.js.map +1 -1
- package/dist/types/ErrorData.d.ts +1 -0
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/dist/version.js.map +1 -1
- package/package.json +1 -1
- package/src/Account/CurrentAccount.ts +11 -1
- package/src/Account/index.ts +137 -9
- package/src/ApiClient/WebSocketClient/events.ts +5 -1
- package/src/ApiClient/WebSocketClient/index.ts +15 -6
- package/src/ApiClient/WebSocketClient/messages.ts +2 -0
- package/src/Projects/Job.ts +90 -1
- package/src/Projects/Project.ts +134 -5
- package/src/Projects/createJobRequestMessage.ts +5 -1
- package/src/Projects/index.ts +87 -16
- package/src/Projects/types/RawProject.ts +121 -0
- package/src/Projects/types/events.ts +2 -0
- package/src/Projects/types/index.ts +4 -0
- package/src/lib/DataEntity.ts +3 -0
- package/src/lib/base64.ts +8 -4
- package/src/types/ErrorData.ts +1 -0
- package/src/version.ts +1 -1
package/README.md
CHANGED
|
@@ -57,10 +57,10 @@ const options ={
|
|
|
57
57
|
}
|
|
58
58
|
const client = await SogniClient.createInstance(options);
|
|
59
59
|
// Login to Sogni account and establish WebSocket connection to Supernet
|
|
60
|
-
await client.login(USERNAME, PASSWORD);
|
|
60
|
+
await client.account.login(USERNAME, PASSWORD);
|
|
61
61
|
// Now wait until list of available models is received.
|
|
62
62
|
// This step is only needed if you want to create project immediately.
|
|
63
|
-
const models = await client.waitForModels();
|
|
63
|
+
const models = await client.projects.waitForModels();
|
|
64
64
|
// You can get list of available models any time from `client.projects.availableModels`
|
|
65
65
|
```
|
|
66
66
|
**Important Note:**
|
|
@@ -160,5 +160,6 @@ project.on('failed', async (errorData) => {
|
|
|
160
160
|
console.log('Project failed:', errorData);
|
|
161
161
|
});
|
|
162
162
|
```
|
|
163
|
+
|
|
163
164
|
## Code examples
|
|
164
165
|
You can find more code examples in the [examples](./examples) directory.
|
|
@@ -6,7 +6,17 @@ import { SupernetType } from '../ApiClient/WebSocketClient/types';
|
|
|
6
6
|
*/
|
|
7
7
|
export interface AccountData {
|
|
8
8
|
token: string | null;
|
|
9
|
-
|
|
9
|
+
/**
|
|
10
|
+
* Current network status:\
|
|
11
|
+
* - `connected` - connected to the socket
|
|
12
|
+
* - `disconnected` - disconnected from the socket
|
|
13
|
+
* - `connecting` - connecting to the socket
|
|
14
|
+
* - `switching` - switching network type (fast/relaxed)
|
|
15
|
+
* @enum
|
|
16
|
+
* @values 'connected', 'disconnected', 'connecting', 'switching'
|
|
17
|
+
* @default 'disconnected'
|
|
18
|
+
*/
|
|
19
|
+
networkStatus: 'connected' | 'disconnected' | 'connecting' | 'switching';
|
|
10
20
|
network: SupernetType | null;
|
|
11
21
|
balance: BalanceData;
|
|
12
22
|
walletAddress?: string;
|
|
@@ -22,7 +32,7 @@ declare class CurrentAccount extends DataEntity<AccountData> {
|
|
|
22
32
|
_update<K extends keyof AccountData>(delta: Partial<AccountData>): void;
|
|
23
33
|
_clear(): void;
|
|
24
34
|
get isAuthenicated(): boolean;
|
|
25
|
-
get networkStatus(): "connected" | "disconnected" | "connecting";
|
|
35
|
+
get networkStatus(): "connected" | "disconnected" | "connecting" | "switching";
|
|
26
36
|
get network(): SupernetType | null;
|
|
27
37
|
get balance(): BalanceData;
|
|
28
38
|
get walletAddress(): string | undefined;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CurrentAccount.js","sourceRoot":"","sources":["../../src/Account/CurrentAccount.ts"],"names":[],"mappings":";;;;;AAAA,mEAA2C;AAE3C,2CAAuC;
|
|
1
|
+
{"version":3,"file":"CurrentAccount.js","sourceRoot":"","sources":["../../src/Account/CurrentAccount.ts"],"names":[],"mappings":";;;;;AAAA,mEAA2C;AAE3C,2CAAuC;AAyBvC,SAAS,WAAW;IAClB,OAAO;QACL,KAAK,EAAE,IAAI;QACX,aAAa,EAAE,cAAc;QAC7B,OAAO,EAAE,IAAI;QACb,OAAO,EAAE;YACP,MAAM,EAAE,GAAG;YACX,KAAK,EAAE,GAAG;YACV,GAAG,EAAE,GAAG;YACR,OAAO,EAAE,GAAG;SACb;KACF,CAAC;AACJ,CAAC;AAED,SAAS,WAAW,CAAC,KAAa;IAChC,MAAM,IAAI,GAAG,IAAA,sBAAS,EAA0D,KAAK,CAAC,CAAC;IACvF,OAAO;QACL,aAAa,EAAE,IAAI,CAAC,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ACjC,CAAC;IAED,IAAI,OAAO;QACT,OAAO,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC;IAC3B,CAAC;IAED,IAAI,OAAO;QACT,OAAO,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC;IAC3B,CAAC;IAED,IAAI,aAAa;QACf,OAAO,IAAI,CAAC,IAAI,CAAC,aAAa,CAAC;IACjC,CAAC;IAED,IAAI,SAAS;QACX,OAAO,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC;IAC7B,CAAC;IAED,IAAI,QAAQ;QACV,OAAO,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC;IAC5B,CAAC;IAED,IAAI,KAAK;QACP,OAAO,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC;IACzB,CAAC;CACF;AAED,kBAAe,cAAc,CAAC"}
|
package/dist/Account/index.d.ts
CHANGED
|
@@ -6,6 +6,14 @@ import CurrentAccount from './CurrentAccount';
|
|
|
6
6
|
import { SupernetType } from '../ApiClient/WebSocketClient/types';
|
|
7
7
|
/**
|
|
8
8
|
* Account API methods that let you interact with the user's account.
|
|
9
|
+
* Can be accessed via `client.account`. Look for more samples below.
|
|
10
|
+
*
|
|
11
|
+
* @example Retrieve the current account balance
|
|
12
|
+
* ```typescript
|
|
13
|
+
* const balance = await client.account.refreshBalance();
|
|
14
|
+
* console.log(balance);
|
|
15
|
+
* ```
|
|
16
|
+
*
|
|
9
17
|
*/
|
|
10
18
|
declare class AccountApi extends ApiGroup {
|
|
11
19
|
readonly currentAccount: CurrentAccount;
|
|
@@ -13,49 +21,164 @@ declare class AccountApi extends ApiGroup {
|
|
|
13
21
|
private handleBalanceUpdate;
|
|
14
22
|
private handleServerConnected;
|
|
15
23
|
private handleServerDisconnected;
|
|
16
|
-
getNonce
|
|
24
|
+
private getNonce;
|
|
25
|
+
/**
|
|
26
|
+
* Create Ethers.js Wallet instance from username and password.
|
|
27
|
+
* This method is used internally to create a wallet for the user.
|
|
28
|
+
* You can use this method to create a wallet if you need to sign transactions.
|
|
29
|
+
*
|
|
30
|
+
* @example Create a wallet from username and password
|
|
31
|
+
* ```typescript
|
|
32
|
+
* const wallet = client.account.getWallet('username', 'password');
|
|
33
|
+
* console.log(wallet.address);
|
|
34
|
+
* ```
|
|
35
|
+
*
|
|
36
|
+
* @param username - Sogni account username
|
|
37
|
+
* @param password - Sogni account password
|
|
38
|
+
*/
|
|
17
39
|
getWallet(username: string, password: string): Wallet;
|
|
40
|
+
/**
|
|
41
|
+
* Create a new account with the given username, email, and password.
|
|
42
|
+
* @internal
|
|
43
|
+
*
|
|
44
|
+
* @param username
|
|
45
|
+
* @param email
|
|
46
|
+
* @param password
|
|
47
|
+
* @param subscribe
|
|
48
|
+
* @param referralCode
|
|
49
|
+
*/
|
|
18
50
|
create(username: string, email: string, password: string, subscribe?: boolean, referralCode?: string): Promise<AccountCreateData>;
|
|
51
|
+
/**
|
|
52
|
+
* Restore session with username and access token.
|
|
53
|
+
*
|
|
54
|
+
* You can save access token that you get from the login method and restore the session with this method.
|
|
55
|
+
*
|
|
56
|
+
* @example Store access token to local storage
|
|
57
|
+
* ```typescript
|
|
58
|
+
* const { username, token } = await client.account.login('username', 'password');
|
|
59
|
+
* localStorage.setItem('sogni-username', username);
|
|
60
|
+
* localStorage.setItem('sogni-token', token);
|
|
61
|
+
* ```
|
|
62
|
+
*
|
|
63
|
+
* @example Restore session from local storage
|
|
64
|
+
* ```typescript
|
|
65
|
+
* const username = localStorage.getItem('sogni-username');
|
|
66
|
+
* const token = localStorage.getItem('sogni-token');
|
|
67
|
+
* if (username && token) {
|
|
68
|
+
* client.account.setToken(username, token);
|
|
69
|
+
* console.log('Session restored');
|
|
70
|
+
* }
|
|
71
|
+
* ```
|
|
72
|
+
*
|
|
73
|
+
* @param username
|
|
74
|
+
* @param token
|
|
75
|
+
*/
|
|
19
76
|
setToken(username: string, token: string): void;
|
|
20
77
|
/**
|
|
21
78
|
* Login with username and password. WebSocket connection is established after successful login.
|
|
79
|
+
*
|
|
80
|
+
* @example Login with username and password
|
|
81
|
+
* ```typescript
|
|
82
|
+
* await client.account.login('username', 'password');
|
|
83
|
+
* console.log('Logged in');
|
|
84
|
+
* ```
|
|
85
|
+
*
|
|
22
86
|
* @param username
|
|
23
87
|
* @param password
|
|
24
88
|
*/
|
|
25
89
|
login(username: string, password: string): Promise<LoginData>;
|
|
26
90
|
/**
|
|
27
91
|
* Logout the user and close the WebSocket connection.
|
|
92
|
+
*
|
|
93
|
+
* @example Logout the user
|
|
94
|
+
* ```typescript
|
|
95
|
+
* await client.account.logout();
|
|
96
|
+
* console.log('Logged out');
|
|
97
|
+
* ```
|
|
28
98
|
*/
|
|
29
99
|
logout(): Promise<void>;
|
|
30
100
|
/**
|
|
31
101
|
* Refresh the balance of the current account.
|
|
102
|
+
*
|
|
103
|
+
* Usually, you don't need to call this method manually. Balance is updated automatically
|
|
104
|
+
* through WebSocket events. But you can call this method to force a balance refresh.
|
|
105
|
+
*
|
|
106
|
+
* @example Refresh user account balance
|
|
107
|
+
* ```typescript
|
|
108
|
+
* const balance = await client.account.refreshBalance();
|
|
109
|
+
* console.log(balance);
|
|
110
|
+
* // { net: '100.000000', settled: '100.000000', credit: '0.000000', debit: '0.000000' }
|
|
111
|
+
* ```
|
|
32
112
|
*/
|
|
33
113
|
refreshBalance(): Promise<BalanceData>;
|
|
34
114
|
/**
|
|
35
|
-
* Get the balance of
|
|
115
|
+
* Get the balance of the wallet address.
|
|
116
|
+
*
|
|
117
|
+
* This method is used to get the balance of the wallet address. It returns $SOGNI and ETH balance.
|
|
118
|
+
*
|
|
119
|
+
* @example Get the balance of the wallet address
|
|
120
|
+
* ```typescript
|
|
121
|
+
* const address = client.account.currentAccount.walletAddress;
|
|
122
|
+
* const balance = await client.account.walletBalance(address);
|
|
123
|
+
* console.log(balance);
|
|
124
|
+
* // { token: '100.000000', ether: '0.000000' }
|
|
125
|
+
* ```
|
|
126
|
+
*
|
|
36
127
|
* @param walletAddress
|
|
37
128
|
*/
|
|
38
129
|
walletBalance(walletAddress: string): Promise<{
|
|
39
130
|
token: string;
|
|
40
131
|
ether: string;
|
|
41
132
|
}>;
|
|
133
|
+
/**
|
|
134
|
+
* Validate the username before signup
|
|
135
|
+
* @internal
|
|
136
|
+
* @param username
|
|
137
|
+
*/
|
|
42
138
|
validateUsername(username: string): Promise<import("../ApiClient").ApiErrorResponse | ApiReponse<undefined>>;
|
|
43
139
|
/**
|
|
44
140
|
* Switch between fast and relaxed networks.
|
|
45
|
-
*
|
|
46
|
-
*
|
|
47
|
-
*
|
|
141
|
+
* This will change default network used to process projects. After switching, you will updated
|
|
142
|
+
* list of AI models available for on selected network.
|
|
143
|
+
*
|
|
144
|
+
* @example Switch to the fast network
|
|
145
|
+
* ```typescript
|
|
146
|
+
* await client.account.switchNetwork('fast');
|
|
147
|
+
* console.log('Switched to the fast network, now lets wait until we get list of models');
|
|
148
|
+
* await client.projects.waitForModels();
|
|
149
|
+
* ```
|
|
150
|
+
* @param network - Network type to switch to
|
|
48
151
|
*/
|
|
49
|
-
switchNetwork(network: SupernetType): Promise<
|
|
152
|
+
switchNetwork(network: SupernetType): Promise<SupernetType>;
|
|
50
153
|
/**
|
|
51
154
|
* Get the transaction history of the current account.
|
|
52
|
-
*
|
|
155
|
+
*
|
|
156
|
+
* @example Get the transaction history
|
|
157
|
+
* ```typescript
|
|
158
|
+
* const { entries, next } = await client.account.transactionHistory({
|
|
159
|
+
* status: 'completed',
|
|
160
|
+
* limit: 10,
|
|
161
|
+
* address: client.account.currentAccount.walletAddress
|
|
162
|
+
* });
|
|
163
|
+
* ```
|
|
164
|
+
*
|
|
165
|
+
* @param params - Transaction history query parameters
|
|
166
|
+
* @returns Transaction history entries and next query parameters
|
|
53
167
|
*/
|
|
54
168
|
transactionHistory(params: TxHistoryParams): Promise<{
|
|
55
169
|
entries: TxHistoryEntry[];
|
|
56
170
|
next: TxHistoryParams;
|
|
57
171
|
}>;
|
|
172
|
+
/**
|
|
173
|
+
* Get the rewards of the current account.
|
|
174
|
+
* @internal
|
|
175
|
+
*/
|
|
58
176
|
rewards(): Promise<Reward[]>;
|
|
177
|
+
/**
|
|
178
|
+
* Claim rewards by reward IDs.
|
|
179
|
+
* @internal
|
|
180
|
+
* @param rewardIds
|
|
181
|
+
*/
|
|
59
182
|
claimRewards(rewardIds: string[]): Promise<void>;
|
|
60
183
|
}
|
|
61
184
|
export default AccountApi;
|
package/dist/Account/index.js
CHANGED
|
@@ -18,6 +18,14 @@ const ApiClient_1 = require("../ApiClient");
|
|
|
18
18
|
const CurrentAccount_1 = __importDefault(require("./CurrentAccount"));
|
|
19
19
|
/**
|
|
20
20
|
* Account API methods that let you interact with the user's account.
|
|
21
|
+
* Can be accessed via `client.account`. Look for more samples below.
|
|
22
|
+
*
|
|
23
|
+
* @example Retrieve the current account balance
|
|
24
|
+
* ```typescript
|
|
25
|
+
* const balance = await client.account.refreshBalance();
|
|
26
|
+
* console.log(balance);
|
|
27
|
+
* ```
|
|
28
|
+
*
|
|
21
29
|
*/
|
|
22
30
|
class AccountApi extends ApiGroup_1.default {
|
|
23
31
|
constructor(config) {
|
|
@@ -47,12 +55,36 @@ class AccountApi extends ApiGroup_1.default {
|
|
|
47
55
|
return res.data.nonce;
|
|
48
56
|
});
|
|
49
57
|
}
|
|
58
|
+
/**
|
|
59
|
+
* Create Ethers.js Wallet instance from username and password.
|
|
60
|
+
* This method is used internally to create a wallet for the user.
|
|
61
|
+
* You can use this method to create a wallet if you need to sign transactions.
|
|
62
|
+
*
|
|
63
|
+
* @example Create a wallet from username and password
|
|
64
|
+
* ```typescript
|
|
65
|
+
* const wallet = client.account.getWallet('username', 'password');
|
|
66
|
+
* console.log(wallet.address);
|
|
67
|
+
* ```
|
|
68
|
+
*
|
|
69
|
+
* @param username - Sogni account username
|
|
70
|
+
* @param password - Sogni account password
|
|
71
|
+
*/
|
|
50
72
|
getWallet(username, password) {
|
|
51
73
|
const pwd = (0, ethers_1.toUtf8Bytes)(username.toLowerCase() + password);
|
|
52
74
|
const salt = (0, ethers_1.toUtf8Bytes)('sogni-salt-value');
|
|
53
75
|
const pkey = (0, ethers_1.pbkdf2)(pwd, salt, 10000, 32, 'sha256');
|
|
54
76
|
return new ethers_1.Wallet(pkey, this.provider);
|
|
55
77
|
}
|
|
78
|
+
/**
|
|
79
|
+
* Create a new account with the given username, email, and password.
|
|
80
|
+
* @internal
|
|
81
|
+
*
|
|
82
|
+
* @param username
|
|
83
|
+
* @param email
|
|
84
|
+
* @param password
|
|
85
|
+
* @param subscribe
|
|
86
|
+
* @param referralCode
|
|
87
|
+
*/
|
|
56
88
|
create(username_1, email_1, password_1) {
|
|
57
89
|
return __awaiter(this, arguments, void 0, function* (username, email, password, subscribe = false, referralCode) {
|
|
58
90
|
const wallet = this.getWallet(username, password);
|
|
@@ -71,6 +103,31 @@ class AccountApi extends ApiGroup_1.default {
|
|
|
71
103
|
return res.data;
|
|
72
104
|
});
|
|
73
105
|
}
|
|
106
|
+
/**
|
|
107
|
+
* Restore session with username and access token.
|
|
108
|
+
*
|
|
109
|
+
* You can save access token that you get from the login method and restore the session with this method.
|
|
110
|
+
*
|
|
111
|
+
* @example Store access token to local storage
|
|
112
|
+
* ```typescript
|
|
113
|
+
* const { username, token } = await client.account.login('username', 'password');
|
|
114
|
+
* localStorage.setItem('sogni-username', username);
|
|
115
|
+
* localStorage.setItem('sogni-token', token);
|
|
116
|
+
* ```
|
|
117
|
+
*
|
|
118
|
+
* @example Restore session from local storage
|
|
119
|
+
* ```typescript
|
|
120
|
+
* const username = localStorage.getItem('sogni-username');
|
|
121
|
+
* const token = localStorage.getItem('sogni-token');
|
|
122
|
+
* if (username && token) {
|
|
123
|
+
* client.account.setToken(username, token);
|
|
124
|
+
* console.log('Session restored');
|
|
125
|
+
* }
|
|
126
|
+
* ```
|
|
127
|
+
*
|
|
128
|
+
* @param username
|
|
129
|
+
* @param token
|
|
130
|
+
*/
|
|
74
131
|
setToken(username, token) {
|
|
75
132
|
this.client.authenticate(token);
|
|
76
133
|
this.currentAccount._update({
|
|
@@ -80,6 +137,13 @@ class AccountApi extends ApiGroup_1.default {
|
|
|
80
137
|
}
|
|
81
138
|
/**
|
|
82
139
|
* Login with username and password. WebSocket connection is established after successful login.
|
|
140
|
+
*
|
|
141
|
+
* @example Login with username and password
|
|
142
|
+
* ```typescript
|
|
143
|
+
* await client.account.login('username', 'password');
|
|
144
|
+
* console.log('Logged in');
|
|
145
|
+
* ```
|
|
146
|
+
*
|
|
83
147
|
* @param username
|
|
84
148
|
* @param password
|
|
85
149
|
*/
|
|
@@ -101,6 +165,12 @@ class AccountApi extends ApiGroup_1.default {
|
|
|
101
165
|
}
|
|
102
166
|
/**
|
|
103
167
|
* Logout the user and close the WebSocket connection.
|
|
168
|
+
*
|
|
169
|
+
* @example Logout the user
|
|
170
|
+
* ```typescript
|
|
171
|
+
* await client.account.logout();
|
|
172
|
+
* console.log('Logged out');
|
|
173
|
+
* ```
|
|
104
174
|
*/
|
|
105
175
|
logout() {
|
|
106
176
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -113,6 +183,16 @@ class AccountApi extends ApiGroup_1.default {
|
|
|
113
183
|
}
|
|
114
184
|
/**
|
|
115
185
|
* Refresh the balance of the current account.
|
|
186
|
+
*
|
|
187
|
+
* Usually, you don't need to call this method manually. Balance is updated automatically
|
|
188
|
+
* through WebSocket events. But you can call this method to force a balance refresh.
|
|
189
|
+
*
|
|
190
|
+
* @example Refresh user account balance
|
|
191
|
+
* ```typescript
|
|
192
|
+
* const balance = await client.account.refreshBalance();
|
|
193
|
+
* console.log(balance);
|
|
194
|
+
* // { net: '100.000000', settled: '100.000000', credit: '0.000000', debit: '0.000000' }
|
|
195
|
+
* ```
|
|
116
196
|
*/
|
|
117
197
|
refreshBalance() {
|
|
118
198
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -122,7 +202,18 @@ class AccountApi extends ApiGroup_1.default {
|
|
|
122
202
|
});
|
|
123
203
|
}
|
|
124
204
|
/**
|
|
125
|
-
* Get the balance of
|
|
205
|
+
* Get the balance of the wallet address.
|
|
206
|
+
*
|
|
207
|
+
* This method is used to get the balance of the wallet address. It returns $SOGNI and ETH balance.
|
|
208
|
+
*
|
|
209
|
+
* @example Get the balance of the wallet address
|
|
210
|
+
* ```typescript
|
|
211
|
+
* const address = client.account.currentAccount.walletAddress;
|
|
212
|
+
* const balance = await client.account.walletBalance(address);
|
|
213
|
+
* console.log(balance);
|
|
214
|
+
* // { token: '100.000000', ether: '0.000000' }
|
|
215
|
+
* ```
|
|
216
|
+
*
|
|
126
217
|
* @param walletAddress
|
|
127
218
|
*/
|
|
128
219
|
walletBalance(walletAddress) {
|
|
@@ -133,6 +224,11 @@ class AccountApi extends ApiGroup_1.default {
|
|
|
133
224
|
return res.data;
|
|
134
225
|
});
|
|
135
226
|
}
|
|
227
|
+
/**
|
|
228
|
+
* Validate the username before signup
|
|
229
|
+
* @internal
|
|
230
|
+
* @param username
|
|
231
|
+
*/
|
|
136
232
|
validateUsername(username) {
|
|
137
233
|
return __awaiter(this, void 0, void 0, function* () {
|
|
138
234
|
try {
|
|
@@ -153,22 +249,45 @@ class AccountApi extends ApiGroup_1.default {
|
|
|
153
249
|
}
|
|
154
250
|
/**
|
|
155
251
|
* Switch between fast and relaxed networks.
|
|
156
|
-
*
|
|
157
|
-
*
|
|
158
|
-
*
|
|
252
|
+
* This will change default network used to process projects. After switching, you will updated
|
|
253
|
+
* list of AI models available for on selected network.
|
|
254
|
+
*
|
|
255
|
+
* @example Switch to the fast network
|
|
256
|
+
* ```typescript
|
|
257
|
+
* await client.account.switchNetwork('fast');
|
|
258
|
+
* console.log('Switched to the fast network, now lets wait until we get list of models');
|
|
259
|
+
* await client.projects.waitForModels();
|
|
260
|
+
* ```
|
|
261
|
+
* @param network - Network type to switch to
|
|
159
262
|
*/
|
|
160
263
|
switchNetwork(network) {
|
|
161
264
|
return __awaiter(this, void 0, void 0, function* () {
|
|
162
265
|
this.currentAccount._update({
|
|
163
|
-
networkStatus: '
|
|
266
|
+
networkStatus: 'switching',
|
|
164
267
|
network: null
|
|
165
268
|
});
|
|
166
|
-
this.client.socket.switchNetwork(network);
|
|
269
|
+
const newNetwork = yield this.client.socket.switchNetwork(network);
|
|
270
|
+
this.currentAccount._update({
|
|
271
|
+
networkStatus: 'connected',
|
|
272
|
+
network: newNetwork
|
|
273
|
+
});
|
|
274
|
+
return newNetwork;
|
|
167
275
|
});
|
|
168
276
|
}
|
|
169
277
|
/**
|
|
170
278
|
* Get the transaction history of the current account.
|
|
171
|
-
*
|
|
279
|
+
*
|
|
280
|
+
* @example Get the transaction history
|
|
281
|
+
* ```typescript
|
|
282
|
+
* const { entries, next } = await client.account.transactionHistory({
|
|
283
|
+
* status: 'completed',
|
|
284
|
+
* limit: 10,
|
|
285
|
+
* address: client.account.currentAccount.walletAddress
|
|
286
|
+
* });
|
|
287
|
+
* ```
|
|
288
|
+
*
|
|
289
|
+
* @param params - Transaction history query parameters
|
|
290
|
+
* @returns Transaction history entries and next query parameters
|
|
172
291
|
*/
|
|
173
292
|
transactionHistory(params) {
|
|
174
293
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -195,6 +314,10 @@ class AccountApi extends ApiGroup_1.default {
|
|
|
195
314
|
};
|
|
196
315
|
});
|
|
197
316
|
}
|
|
317
|
+
/**
|
|
318
|
+
* Get the rewards of the current account.
|
|
319
|
+
* @internal
|
|
320
|
+
*/
|
|
198
321
|
rewards() {
|
|
199
322
|
return __awaiter(this, void 0, void 0, function* () {
|
|
200
323
|
const r = yield this.client.rest.get('/v2/account/rewards');
|
|
@@ -213,6 +336,11 @@ class AccountApi extends ApiGroup_1.default {
|
|
|
213
336
|
}));
|
|
214
337
|
});
|
|
215
338
|
}
|
|
339
|
+
/**
|
|
340
|
+
* Claim rewards by reward IDs.
|
|
341
|
+
* @internal
|
|
342
|
+
* @param rewardIds
|
|
343
|
+
*/
|
|
216
344
|
claimRewards(rewardIds) {
|
|
217
345
|
return __awaiter(this, void 0, void 0, function* () {
|
|
218
346
|
yield this.client.rest.post('/v2/account/reward/claim', {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/Account/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAWA,2DAAkD;AAClD,mCAAqD;AACrD,4CAAoD;AACpD,sEAA8C;AAG9C
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/Account/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAWA,2DAAkD;AAClD,mCAAqD;AACrD,4CAAoD;AACpD,sEAA8C;AAG9C;;;;;;;;;;GAUG;AACH,MAAM,UAAW,SAAQ,kBAAQ;IAG/B,YAAY,MAAiB;QAC3B,KAAK,CAAC,MAAM,CAAC,CAAC;QAHP,mBAAc,GAAG,IAAI,wBAAc,EAAE,CAAC;QAI7C,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC,eAAe,EAAE,IAAI,CAAC,mBAAmB,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;QAC5E,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC,WAAW,EAAE,IAAI,CAAC,qBAAqB,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;QACnE,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC,cAAc,EAAE,IAAI,CAAC,wBAAwB,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;IAC3E,CAAC;IAEO,mBAAmB,CAAC,IAAiB;QAC3C,IAAI,CAAC,cAAc,CAAC,OAAO,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC;IACjD,CAAC;IAEO,qBAAqB,CAAC,EAAE,OAAO,EAA6B;QAClE,IAAI,CAAC,cAAc,CAAC,OAAO,CAAC;YAC1B,aAAa,EAAE,WAAW;YAC1B,OAAO;SACR,CAAC,CAAC;IACL,CAAC;IAEO,wBAAwB;QAC9B,IAAI,CAAC,cAAc,CAAC,MAAM,EAAE,CAAC;IA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,CAAC,IAAI,CAAC,0BAA0B,EAAE;gBACtD,MAAM,EAAE,SAAS;aAClB,CAAC,CAAC;QACL,CAAC;KAAA;CACF;AAED,kBAAe,UAAU,CAAC"}
|
|
@@ -10,7 +10,7 @@ export type JobErrorData = {
|
|
|
10
10
|
imgID?: string;
|
|
11
11
|
isFromWorker: boolean;
|
|
12
12
|
error_message: string;
|
|
13
|
-
error: number;
|
|
13
|
+
error: number | string;
|
|
14
14
|
};
|
|
15
15
|
export type JobProgressData = {
|
|
16
16
|
jobID: string;
|
|
@@ -52,6 +52,12 @@ export type SocketEventMap = {
|
|
|
52
52
|
* @event WebSocketClient#balanceUpdate - Received balance update
|
|
53
53
|
*/
|
|
54
54
|
balanceUpdate: BalanceData;
|
|
55
|
+
/**
|
|
56
|
+
* @event WebSocketClient#changeNetwork - Default network changed
|
|
57
|
+
*/
|
|
58
|
+
changeNetwork: {
|
|
59
|
+
network: SupernetType;
|
|
60
|
+
};
|
|
55
61
|
/**
|
|
56
62
|
* @event WebSocketClient#jobError - Job error occurred
|
|
57
63
|
*/
|
|
@@ -17,7 +17,7 @@ declare class WebSocketClient extends RestClient<SocketEventMap> {
|
|
|
17
17
|
disconnect(): void;
|
|
18
18
|
private startPing;
|
|
19
19
|
private stopPing;
|
|
20
|
-
switchNetwork(supernetType: SupernetType):
|
|
20
|
+
switchNetwork(supernetType: SupernetType): Promise<SupernetType>;
|
|
21
21
|
/**
|
|
22
22
|
* Ensure the WebSocket connection is open, waiting if necessary and throwing an error if it fails
|
|
23
23
|
* @private
|
|
@@ -21,11 +21,15 @@ const version_1 = require("../../version");
|
|
|
21
21
|
const PING_INTERVAL = 15000;
|
|
22
22
|
class WebSocketClient extends RestClient_1.default {
|
|
23
23
|
constructor(baseUrl, appId, supernetType, logger) {
|
|
24
|
-
|
|
24
|
+
const _baseUrl = new URL(baseUrl);
|
|
25
|
+
if (_baseUrl.protocol === 'wss:') {
|
|
26
|
+
_baseUrl.protocol = 'https:';
|
|
27
|
+
}
|
|
28
|
+
super(_baseUrl.toString(), logger);
|
|
25
29
|
this.socket = null;
|
|
26
30
|
this._pingInterval = null;
|
|
27
31
|
this.appId = appId;
|
|
28
|
-
this.baseUrl =
|
|
32
|
+
this.baseUrl = _baseUrl.toString();
|
|
29
33
|
this._supernetType = supernetType;
|
|
30
34
|
}
|
|
31
35
|
set auth(auth) {
|
|
@@ -58,6 +62,7 @@ class WebSocketClient extends RestClient_1.default {
|
|
|
58
62
|
}
|
|
59
63
|
const userAgent = `Sogni/${version_1.LIB_VERSION} (sogni-client)`;
|
|
60
64
|
const url = new URL(this.baseUrl);
|
|
65
|
+
url.protocol = 'wss:';
|
|
61
66
|
url.searchParams.set('appId', this.appId);
|
|
62
67
|
url.searchParams.set('clientName', userAgent);
|
|
63
68
|
url.searchParams.set('clientType', 'artist');
|
|
@@ -107,9 +112,13 @@ class WebSocketClient extends RestClient_1.default {
|
|
|
107
112
|
}
|
|
108
113
|
}
|
|
109
114
|
switchNetwork(supernetType) {
|
|
110
|
-
this
|
|
111
|
-
|
|
112
|
-
|
|
115
|
+
return new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
|
|
116
|
+
this.once('changeNetwork', ({ network }) => {
|
|
117
|
+
this._supernetType = network;
|
|
118
|
+
resolve(network);
|
|
119
|
+
});
|
|
120
|
+
yield this.send('changeNetwork', supernetType);
|
|
121
|
+
}));
|
|
113
122
|
}
|
|
114
123
|
/**
|
|
115
124
|
* Ensure the WebSocket connection is open, waiting if necessary and throwing an error if it fails
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/ApiClient/WebSocketClient/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAEA,sEAA4D;AAE5D,kEAAgF;AAChF,6CAA8D;AAC9D,kEAA0C;AAC1C,0DAA+B;AAC/B,2CAA4C;AAG5C,MAAM,aAAa,GAAG,KAAK,CAAC;AAE5B,MAAM,eAAgB,SAAQ,oBAA0B;IAO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