cloreai 3.0.0 → 4.0.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.
- package/README.md +68 -47
- package/{build → dist}/Cloreai.d.ts +20 -17
- package/dist/Cloreai.js +267 -0
- package/dist/CloreaiError.d.ts +17 -0
- package/dist/CloreaiError.js +13 -0
- package/dist/Gigaspot.d.ts +15 -0
- package/dist/Gigaspot.js +71 -0
- package/{build → dist}/constants.d.ts +0 -1
- package/{build → dist}/constants.js +0 -1
- package/package.json +12 -14
- package/build/Cloreai.js +0 -125
- package/build/CloreaiError.d.ts +0 -12
- package/build/CloreaiError.js +0 -16
- package/build/Gigaspot.d.ts +0 -17
- package/build/Gigaspot.js +0 -46
- package/build/getQueueOptions.d.ts +0 -3
- package/build/getQueueOptions.js +0 -8
- package/{build → dist}/index.d.ts +0 -0
- package/{build → dist}/index.js +0 -0
- package/{build → dist}/resources/cancelOrder.d.ts +0 -0
- package/{build → dist}/resources/cancelOrder.js +0 -0
- package/{build → dist}/resources/cancelOrders.d.ts +0 -0
- package/{build → dist}/resources/cancelOrders.js +0 -0
- package/{build → dist}/resources/createGigaspotOrders.d.ts +1 -1
- package/{build → dist}/resources/createGigaspotOrders.js +0 -0
- package/{build → dist}/resources/createOrder.d.ts +8 -8
- package/{build → dist}/resources/createOrder.js +0 -0
- package/{build → dist}/resources/editGigaspotOrders.d.ts +1 -1
- package/{build → dist}/resources/editGigaspotOrders.js +0 -0
- package/{build → dist}/resources/getGigaspot.d.ts +23 -23
- package/{build → dist}/resources/getGigaspot.js +0 -0
- package/{build → dist}/resources/marketplace.d.ts +3 -3
- package/{build → dist}/resources/marketplace.js +0 -0
- package/{build → dist}/resources/myOrders.d.ts +4 -4
- package/{build → dist}/resources/myOrders.js +0 -0
- package/{build → dist}/resources/myServers.d.ts +4 -4
- package/{build → dist}/resources/myServers.js +0 -0
- package/{build → dist}/resources/pohBalance.d.ts +16 -16
- package/{build → dist}/resources/pohBalance.js +0 -0
- package/{build → dist}/resources/renterFees.d.ts +12 -12
- package/{build → dist}/resources/renterFees.js +0 -0
- package/{build → dist}/resources/serverConfig.d.ts +8 -8
- package/{build → dist}/resources/serverConfig.js +0 -0
- package/{build → dist}/resources/setServerSettings.d.ts +0 -0
- package/{build → dist}/resources/setServerSettings.js +0 -0
- package/{build → dist}/resources/setSpotPrice.d.ts +1 -1
- package/{build → dist}/resources/setSpotPrice.js +0 -0
- package/{build → dist}/resources/spotMarketplace.d.ts +9 -9
- package/{build → dist}/resources/spotMarketplace.js +0 -0
- package/{build → dist}/resources/wallets.d.ts +3 -3
- /package/{build → dist}/resources/wallets.js +0 -0
- /package/{build → dist}/types.d.ts +0 -0
- /package/{build → dist}/types.js +0 -0
package/README.md
CHANGED
|
@@ -4,11 +4,11 @@
|
|
|
4
4
|
|
|
5
5
|
Features:
|
|
6
6
|
|
|
7
|
-
- Based on
|
|
8
|
-
- Protects
|
|
7
|
+
- Based on native fetch
|
|
8
|
+
- Protects against rate limit exceeded (429 errors) through
|
|
9
9
|
[p-queue](https://github.com/sindresorhus/p-queue)
|
|
10
|
-
-
|
|
11
|
-
- Full
|
|
10
|
+
- Convenient error handling
|
|
11
|
+
- Full type safety
|
|
12
12
|
- Supports GigaSPOT
|
|
13
13
|
|
|
14
14
|
Official documentation: [clore.ai/api-docs](https://clore.ai/api-docs)
|
|
@@ -30,10 +30,11 @@ npm install cloreai
|
|
|
30
30
|
import Cloreai from 'cloreai'
|
|
31
31
|
|
|
32
32
|
const cloreai = new Cloreai('API_KEY', {
|
|
33
|
-
|
|
33
|
+
baseURL: 'https://api.clore.ai/v1', // (optional) Override the default base URL for the API
|
|
34
|
+
fetchOptions: {}, // (optional) Additional `RequestInit` options to be passed to `fetch` calls
|
|
35
|
+
fetch: globalThis.fetch, // (optional) Specify a custom `fetch` function implementation
|
|
34
36
|
queueOptions: {}, // (optional) Queue instance options https://github.com/sindresorhus/p-queue
|
|
35
37
|
queueCreateOrderOptions: {}, // (optional) Create order queue instance options https://github.com/sindresorhus/p-queue
|
|
36
|
-
queueGigaspotOptions: {}, // (optional) Gigaspot queue instance options https://github.com/sindresorhus/p-queue
|
|
37
38
|
})
|
|
38
39
|
```
|
|
39
40
|
|
|
@@ -142,7 +143,7 @@ await cloreai.createOrder({
|
|
|
142
143
|
})
|
|
143
144
|
```
|
|
144
145
|
|
|
145
|
-
### 11.
|
|
146
|
+
### 11. poh_balance
|
|
146
147
|
|
|
147
148
|
```typescript
|
|
148
149
|
const pohBalance = await cloreai.pohBalance()
|
|
@@ -206,41 +207,23 @@ await cloreai.gigaspot.cancelOrders({
|
|
|
206
207
|
})
|
|
207
208
|
```
|
|
208
209
|
|
|
209
|
-
|
|
210
|
+
## Fetch Options
|
|
210
211
|
|
|
211
|
-
All methods accept
|
|
212
|
-
parameter, for example:
|
|
212
|
+
All methods accept fetch options as the last parameter, for example:
|
|
213
213
|
|
|
214
214
|
```typescript
|
|
215
215
|
const marketplace = await cloreai.marketplace({
|
|
216
|
-
//
|
|
216
|
+
// `RequestInit` options
|
|
217
217
|
})
|
|
218
218
|
```
|
|
219
219
|
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
Use the field `cloreai.axios`.
|
|
223
|
-
|
|
224
|
-
Refer to the documentation [axios](https://github.com/axios/axios).
|
|
225
|
-
|
|
226
|
-
### Access to p-queue instances
|
|
227
|
-
|
|
228
|
-
Use the fields:
|
|
229
|
-
|
|
230
|
-
- `cloreai.queue` - for the main request queue
|
|
231
|
-
- `cloreai.queueCreateOrder` - for the createOrder request queue
|
|
232
|
-
- `cloreai.gigaspot.queue` - for the gigaspot request queue
|
|
233
|
-
|
|
234
|
-
Refer to the documentation [p-queue](https://github.com/sindresorhus/p-queue).
|
|
235
|
-
|
|
236
|
-
### Error Handling
|
|
220
|
+
## Error Handling
|
|
237
221
|
|
|
238
222
|
Use the `CloreaiError` class for error handling.
|
|
239
223
|
|
|
240
|
-
|
|
241
|
-
information `error.code` and `error.error`.
|
|
224
|
+
Errors have fields with information `error.statusCode` and `error.description`.
|
|
242
225
|
|
|
243
|
-
|
|
226
|
+
Use the constant `statusCodes` to check the error type.
|
|
244
227
|
|
|
245
228
|
```typescript
|
|
246
229
|
import { CloreaiError, statusCodes } from 'cloreai'
|
|
@@ -249,9 +232,9 @@ try {
|
|
|
249
232
|
const marketplace = await cloreai.marketplace()
|
|
250
233
|
} catch (error) {
|
|
251
234
|
if (error instanceof CloreaiError) {
|
|
252
|
-
console.log(error.
|
|
235
|
+
console.log(error.statusCode, error.description)
|
|
253
236
|
|
|
254
|
-
if (error.
|
|
237
|
+
if (error.statusCode === statusCodes.EXCEEDED) {
|
|
255
238
|
console.log('Rate limit exceeded error')
|
|
256
239
|
}
|
|
257
240
|
} else {
|
|
@@ -260,31 +243,24 @@ try {
|
|
|
260
243
|
}
|
|
261
244
|
```
|
|
262
245
|
|
|
263
|
-
|
|
246
|
+
## Rate limit
|
|
264
247
|
|
|
265
|
-
All methods are protected from rate limit exceeded
|
|
248
|
+
All methods are protected from rate limit exceeded through
|
|
266
249
|
[p-queue](https://github.com/sindresorhus/p-queue), they automatically delay for
|
|
267
|
-
the
|
|
250
|
+
the needed time to avoid exceeding the limit.
|
|
268
251
|
|
|
269
252
|
Default rate limit values are available as constants:
|
|
270
253
|
|
|
271
254
|
```typescript
|
|
272
|
-
import {
|
|
273
|
-
RATE_LIMIT,
|
|
274
|
-
RATE_LIMIT_CREATE_ORDER,
|
|
275
|
-
RATE_LIMIT_GIGASPOT,
|
|
276
|
-
} from 'cloreai'
|
|
255
|
+
import { RATE_LIMIT, RATE_LIMIT_CREATE_ORDER } from 'cloreai'
|
|
277
256
|
|
|
278
257
|
console.log(RATE_LIMIT)
|
|
279
258
|
console.log(RATE_LIMIT_CREATE_ORDER)
|
|
280
|
-
console.log(RATE_LIMIT_GIGASPOT)
|
|
281
259
|
```
|
|
282
260
|
|
|
283
|
-
You can set
|
|
261
|
+
You can set your own rate limit values for each request queue:
|
|
284
262
|
|
|
285
263
|
```typescript
|
|
286
|
-
import Cloreai from 'cloreai'
|
|
287
|
-
|
|
288
264
|
const cloreai = new Cloreai('API_KEY', {
|
|
289
265
|
queueOptions: {
|
|
290
266
|
interval: 2000, // For example 2 seconds
|
|
@@ -292,8 +268,53 @@ const cloreai = new Cloreai('API_KEY', {
|
|
|
292
268
|
queueCreateOrderOptions: {
|
|
293
269
|
interval: 6000, // For example 6 seconds
|
|
294
270
|
},
|
|
295
|
-
|
|
296
|
-
|
|
271
|
+
})
|
|
272
|
+
```
|
|
273
|
+
|
|
274
|
+
Access to p-queue instances:
|
|
275
|
+
|
|
276
|
+
- `cloreai.queue` - main request queue
|
|
277
|
+
- `cloreai.queueCreateOrder` - createOrder request queue
|
|
278
|
+
|
|
279
|
+
## Retries
|
|
280
|
+
|
|
281
|
+
For retrying, it's recommended to use
|
|
282
|
+
[p-retry](https://github.com/sindresorhus/p-retry):
|
|
283
|
+
|
|
284
|
+
```typescript
|
|
285
|
+
import pRetry from 'p-retry'
|
|
286
|
+
|
|
287
|
+
const marketplace = await pRetry(
|
|
288
|
+
async () => {
|
|
289
|
+
return await cloreai.marketplace()
|
|
290
|
+
},
|
|
291
|
+
{
|
|
292
|
+
retries: 5,
|
|
297
293
|
},
|
|
294
|
+
)
|
|
295
|
+
```
|
|
296
|
+
|
|
297
|
+
## Timeouts
|
|
298
|
+
|
|
299
|
+
Use `AbortSignal.timeout`:
|
|
300
|
+
|
|
301
|
+
```typescript
|
|
302
|
+
const marketplace = await cloreai.marketplace({
|
|
303
|
+
signal: AbortSignal.timeout(5000),
|
|
304
|
+
})
|
|
305
|
+
```
|
|
306
|
+
|
|
307
|
+
Combine signals using `AbortSignal.any`. In the following example, the request
|
|
308
|
+
will be aborted after 5 seconds, but can also be aborted earlier by calling
|
|
309
|
+
`controller.abort()`:
|
|
310
|
+
|
|
311
|
+
```typescript
|
|
312
|
+
const controller = new AbortController()
|
|
313
|
+
|
|
314
|
+
// You can abort by event
|
|
315
|
+
// controller.abort()
|
|
316
|
+
|
|
317
|
+
const marketplace = await cloreai.marketplace({
|
|
318
|
+
signal: AbortSignal.any([AbortSignal.timeout(5000), controller.signal]),
|
|
298
319
|
})
|
|
299
320
|
```
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { type AxiosInstance, type AxiosRequestConfig, type CreateAxiosDefaults } from 'axios';
|
|
2
1
|
import PQueue, { type Options as PQueueOptions, type Queue, type QueueAddOptions } from 'p-queue';
|
|
3
2
|
import type { CancelOrderRequestData, CancelOrderResponseData } from './resources/cancelOrder.ts';
|
|
4
3
|
import type { CreateOrderRequestData, CreateOrderResponseData } from './resources/createOrder.ts';
|
|
@@ -13,30 +12,34 @@ import type { SetSpotPriceRequestData, SetSpotPriceResponseData } from './resour
|
|
|
13
12
|
import type { SpotMarketplaceRequestParams, SpotMarketplaceResponseData } from './resources/spotMarketplace.ts';
|
|
14
13
|
import type { WalletsResponseData } from './resources/wallets.ts';
|
|
15
14
|
import Gigaspot from './Gigaspot.ts';
|
|
16
|
-
export type QueueOptions = PQueueOptions<Queue<() => Promise<unknown>, QueueAddOptions>, QueueAddOptions>;
|
|
17
15
|
export interface Options {
|
|
18
|
-
|
|
16
|
+
baseURL?: string;
|
|
17
|
+
fetchOptions?: RequestInit;
|
|
18
|
+
fetch?: typeof fetch;
|
|
19
19
|
queueOptions?: QueueOptions;
|
|
20
20
|
queueCreateOrderOptions?: QueueOptions;
|
|
21
|
-
queueGigaspotOptions?: QueueOptions;
|
|
22
21
|
}
|
|
22
|
+
export type QueueOptions = PQueueOptions<Queue<() => Promise<unknown>, QueueAddOptions>, QueueAddOptions>;
|
|
23
23
|
declare class Cloreai {
|
|
24
|
-
|
|
24
|
+
#private;
|
|
25
|
+
baseURL: string;
|
|
26
|
+
fetchOptions: RequestInit;
|
|
27
|
+
fetch: typeof fetch;
|
|
25
28
|
queue: PQueue;
|
|
26
29
|
queueCreateOrder: PQueue;
|
|
27
30
|
gigaspot: Gigaspot;
|
|
28
31
|
constructor(apiKey: string, options?: Options);
|
|
29
|
-
wallets(
|
|
30
|
-
myServers(
|
|
31
|
-
serverConfig(data: ServerConfigRequestData,
|
|
32
|
-
marketplace(
|
|
33
|
-
myOrders(params?: MyOrdersRequestParams,
|
|
34
|
-
spotMarketplace(params: SpotMarketplaceRequestParams,
|
|
35
|
-
setServerSettings(data: SetServerSettingsRequestData,
|
|
36
|
-
setSpotPrice(data: SetSpotPriceRequestData,
|
|
37
|
-
cancelOrder(data: CancelOrderRequestData,
|
|
38
|
-
createOrder(data: CreateOrderRequestData,
|
|
39
|
-
pohBalance(
|
|
40
|
-
renterFees(
|
|
32
|
+
wallets(init?: RequestInit): Promise<WalletsResponseData>;
|
|
33
|
+
myServers(init?: RequestInit): Promise<MyServersResponseData>;
|
|
34
|
+
serverConfig(data: ServerConfigRequestData, init?: RequestInit): Promise<ServerConfigResponseData>;
|
|
35
|
+
marketplace(init?: RequestInit): Promise<MarketplaceResponseData>;
|
|
36
|
+
myOrders(params?: MyOrdersRequestParams, init?: RequestInit): Promise<MyOrdersResponseData>;
|
|
37
|
+
spotMarketplace(params: SpotMarketplaceRequestParams, init?: RequestInit): Promise<SpotMarketplaceResponseData>;
|
|
38
|
+
setServerSettings(data: SetServerSettingsRequestData, init?: RequestInit): Promise<SetServerSettingsResponseData>;
|
|
39
|
+
setSpotPrice(data: SetSpotPriceRequestData, init?: RequestInit): Promise<SetSpotPriceResponseData>;
|
|
40
|
+
cancelOrder(data: CancelOrderRequestData, init?: RequestInit): Promise<CancelOrderResponseData>;
|
|
41
|
+
createOrder(data: CreateOrderRequestData, init?: RequestInit): Promise<CreateOrderResponseData>;
|
|
42
|
+
pohBalance(init?: RequestInit): Promise<PohBalanceResponseData>;
|
|
43
|
+
renterFees(init?: RequestInit): Promise<RenterFeesResponseData>;
|
|
41
44
|
}
|
|
42
45
|
export default Cloreai;
|
package/dist/Cloreai.js
ADDED
|
@@ -0,0 +1,267 @@
|
|
|
1
|
+
import PQueue, {} from 'p-queue';
|
|
2
|
+
import { CloreaiError } from "./CloreaiError.js";
|
|
3
|
+
import { priorityLevels, RATE_LIMIT, RATE_LIMIT_CREATE_ORDER, statusCodes } from "./constants.js";
|
|
4
|
+
import Gigaspot from "./Gigaspot.js";
|
|
5
|
+
class Cloreai {
|
|
6
|
+
baseURL;
|
|
7
|
+
fetchOptions;
|
|
8
|
+
fetch;
|
|
9
|
+
queue;
|
|
10
|
+
queueCreateOrder;
|
|
11
|
+
gigaspot;
|
|
12
|
+
#apiKey;
|
|
13
|
+
constructor(apiKey, options = {}) {
|
|
14
|
+
this.baseURL = options.baseURL ?? 'https://api.clore.ai/v1';
|
|
15
|
+
this.fetchOptions = options.fetchOptions ?? {};
|
|
16
|
+
this.fetch = options.fetch ?? fetch;
|
|
17
|
+
this.queue = new PQueue({
|
|
18
|
+
interval: RATE_LIMIT,
|
|
19
|
+
intervalCap: 1,
|
|
20
|
+
concurrency: 1,
|
|
21
|
+
...options.queueOptions,
|
|
22
|
+
});
|
|
23
|
+
this.queueCreateOrder = new PQueue({
|
|
24
|
+
interval: RATE_LIMIT_CREATE_ORDER,
|
|
25
|
+
intervalCap: 1,
|
|
26
|
+
concurrency: 1,
|
|
27
|
+
...options.queueCreateOrderOptions,
|
|
28
|
+
});
|
|
29
|
+
this.gigaspot = new Gigaspot(this, this.#fetch.bind(this));
|
|
30
|
+
this.#apiKey = apiKey;
|
|
31
|
+
}
|
|
32
|
+
async #fetch(input, init = {}) {
|
|
33
|
+
const headers = new Headers({
|
|
34
|
+
'Content-Type': 'application/json',
|
|
35
|
+
'auth': this.#apiKey,
|
|
36
|
+
});
|
|
37
|
+
for (const [key, value] of new Headers(this.fetchOptions.headers)) {
|
|
38
|
+
headers.set(key, value);
|
|
39
|
+
}
|
|
40
|
+
for (const [key, value] of new Headers(init.headers)) {
|
|
41
|
+
headers.set(key, value);
|
|
42
|
+
}
|
|
43
|
+
const signal = AbortSignal.any([
|
|
44
|
+
...(this.fetchOptions.signal ? [this.fetchOptions.signal] : []),
|
|
45
|
+
...(init.signal ? [init.signal] : []),
|
|
46
|
+
]);
|
|
47
|
+
const mergedInit = {
|
|
48
|
+
...this.fetchOptions,
|
|
49
|
+
...init,
|
|
50
|
+
headers,
|
|
51
|
+
signal,
|
|
52
|
+
};
|
|
53
|
+
const url = new URL(input);
|
|
54
|
+
const request = new Request(url, mergedInit);
|
|
55
|
+
let response;
|
|
56
|
+
try {
|
|
57
|
+
response = await this.fetch(request);
|
|
58
|
+
}
|
|
59
|
+
catch (error) {
|
|
60
|
+
throw new CloreaiError(error instanceof Error ? error.message : String(error), {
|
|
61
|
+
cause: error,
|
|
62
|
+
init: mergedInit,
|
|
63
|
+
request,
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
const originalJson = response.json;
|
|
67
|
+
// @ts-expect-error: json is readonly
|
|
68
|
+
response.json = async () => {
|
|
69
|
+
let data;
|
|
70
|
+
try {
|
|
71
|
+
data = await originalJson.call(response);
|
|
72
|
+
}
|
|
73
|
+
catch (error) {
|
|
74
|
+
throw new CloreaiError(error instanceof Error ? error.message : String(error), {
|
|
75
|
+
cause: error,
|
|
76
|
+
init: mergedInit,
|
|
77
|
+
request,
|
|
78
|
+
response,
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
if (data.code === statusCodes.NORMAL) {
|
|
82
|
+
return data;
|
|
83
|
+
}
|
|
84
|
+
const hasError = Boolean(data.error);
|
|
85
|
+
const errorMessage = hasError
|
|
86
|
+
? `Code "${data.code}, error "${data.error}"`
|
|
87
|
+
: `Code "${data.code}"`;
|
|
88
|
+
throw new CloreaiError(errorMessage, {
|
|
89
|
+
init: mergedInit,
|
|
90
|
+
request,
|
|
91
|
+
response,
|
|
92
|
+
statusCode: data.code,
|
|
93
|
+
description: data.error ?? '',
|
|
94
|
+
data,
|
|
95
|
+
});
|
|
96
|
+
};
|
|
97
|
+
return response;
|
|
98
|
+
}
|
|
99
|
+
async wallets(init = {}) {
|
|
100
|
+
const url = new URL(this.baseURL + '/wallets');
|
|
101
|
+
const response = await this.queue.add(async () => {
|
|
102
|
+
return await this.#fetch(url, {
|
|
103
|
+
...init,
|
|
104
|
+
method: 'GET',
|
|
105
|
+
});
|
|
106
|
+
}, {
|
|
107
|
+
priority: priorityLevels.NORMAL,
|
|
108
|
+
signal: init.signal ?? undefined,
|
|
109
|
+
});
|
|
110
|
+
return await response.json();
|
|
111
|
+
}
|
|
112
|
+
async myServers(init = {}) {
|
|
113
|
+
const url = new URL(this.baseURL + '/my_servers');
|
|
114
|
+
const response = await this.queue.add(async () => {
|
|
115
|
+
return await this.#fetch(url, {
|
|
116
|
+
...init,
|
|
117
|
+
method: 'GET',
|
|
118
|
+
});
|
|
119
|
+
}, {
|
|
120
|
+
priority: priorityLevels.NORMAL,
|
|
121
|
+
signal: init.signal ?? undefined,
|
|
122
|
+
});
|
|
123
|
+
return await response.json();
|
|
124
|
+
}
|
|
125
|
+
async serverConfig(data, init = {}) {
|
|
126
|
+
const url = new URL(this.baseURL + '/server_config');
|
|
127
|
+
const response = await this.queue.add(async () => {
|
|
128
|
+
return await this.#fetch(url, {
|
|
129
|
+
...init,
|
|
130
|
+
method: 'GET',
|
|
131
|
+
body: JSON.stringify(data),
|
|
132
|
+
});
|
|
133
|
+
}, {
|
|
134
|
+
priority: priorityLevels.NORMAL,
|
|
135
|
+
signal: init.signal ?? undefined,
|
|
136
|
+
});
|
|
137
|
+
return await response.json();
|
|
138
|
+
}
|
|
139
|
+
async marketplace(init = {}) {
|
|
140
|
+
const url = new URL(this.baseURL + '/marketplace');
|
|
141
|
+
const response = await this.queue.add(async () => {
|
|
142
|
+
return await this.#fetch(url, {
|
|
143
|
+
...init,
|
|
144
|
+
method: 'GET',
|
|
145
|
+
});
|
|
146
|
+
}, {
|
|
147
|
+
priority: priorityLevels.NORMAL,
|
|
148
|
+
signal: init.signal ?? undefined,
|
|
149
|
+
});
|
|
150
|
+
return await response.json();
|
|
151
|
+
}
|
|
152
|
+
async myOrders(params = {}, init = {}) {
|
|
153
|
+
const url = new URL(this.baseURL + '/my_orders');
|
|
154
|
+
for (const [key, value] of Object.entries(params)) {
|
|
155
|
+
url.searchParams.set(key, String(value));
|
|
156
|
+
}
|
|
157
|
+
const response = await this.queue.add(async () => {
|
|
158
|
+
return await this.#fetch(url, {
|
|
159
|
+
...init,
|
|
160
|
+
method: 'GET',
|
|
161
|
+
});
|
|
162
|
+
}, {
|
|
163
|
+
priority: priorityLevels.NORMAL,
|
|
164
|
+
signal: init.signal ?? undefined,
|
|
165
|
+
});
|
|
166
|
+
return await response.json();
|
|
167
|
+
}
|
|
168
|
+
async spotMarketplace(params, init = {}) {
|
|
169
|
+
const url = new URL(this.baseURL + '/spot_marketplace');
|
|
170
|
+
for (const [key, value] of Object.entries(params)) {
|
|
171
|
+
url.searchParams.set(key, String(value));
|
|
172
|
+
}
|
|
173
|
+
const response = await this.queue.add(async () => {
|
|
174
|
+
return await this.#fetch(url, {
|
|
175
|
+
...init,
|
|
176
|
+
method: 'GET',
|
|
177
|
+
});
|
|
178
|
+
}, {
|
|
179
|
+
priority: priorityLevels.NORMAL,
|
|
180
|
+
signal: init.signal ?? undefined,
|
|
181
|
+
});
|
|
182
|
+
return await response.json();
|
|
183
|
+
}
|
|
184
|
+
async setServerSettings(data, init = {}) {
|
|
185
|
+
const url = new URL(this.baseURL + '/set_server_settings');
|
|
186
|
+
const response = await this.queue.add(async () => {
|
|
187
|
+
return await this.#fetch(url, {
|
|
188
|
+
...init,
|
|
189
|
+
method: 'POST',
|
|
190
|
+
body: JSON.stringify(data),
|
|
191
|
+
});
|
|
192
|
+
}, {
|
|
193
|
+
priority: priorityLevels.HIGH,
|
|
194
|
+
signal: init.signal ?? undefined,
|
|
195
|
+
});
|
|
196
|
+
return await response.json();
|
|
197
|
+
}
|
|
198
|
+
async setSpotPrice(data, init = {}) {
|
|
199
|
+
const url = new URL(this.baseURL + '/set_spot_price');
|
|
200
|
+
const response = await this.queue.add(async () => {
|
|
201
|
+
return await this.#fetch(url, {
|
|
202
|
+
...init,
|
|
203
|
+
method: 'POST',
|
|
204
|
+
body: JSON.stringify(data),
|
|
205
|
+
});
|
|
206
|
+
}, {
|
|
207
|
+
priority: priorityLevels.HIGH,
|
|
208
|
+
signal: init.signal ?? undefined,
|
|
209
|
+
});
|
|
210
|
+
return await response.json();
|
|
211
|
+
}
|
|
212
|
+
async cancelOrder(data, init = {}) {
|
|
213
|
+
const url = new URL(this.baseURL + '/cancel_order');
|
|
214
|
+
const response = await this.queue.add(async () => {
|
|
215
|
+
return await this.#fetch(url, {
|
|
216
|
+
...init,
|
|
217
|
+
method: 'POST',
|
|
218
|
+
body: JSON.stringify(data),
|
|
219
|
+
});
|
|
220
|
+
}, {
|
|
221
|
+
priority: priorityLevels.HIGH,
|
|
222
|
+
signal: init.signal ?? undefined,
|
|
223
|
+
});
|
|
224
|
+
return await response.json();
|
|
225
|
+
}
|
|
226
|
+
async createOrder(data, init = {}) {
|
|
227
|
+
const url = new URL(this.baseURL + '/create_order');
|
|
228
|
+
const response = await this.queue.add(async () => {
|
|
229
|
+
return await this.#fetch(url, {
|
|
230
|
+
...init,
|
|
231
|
+
method: 'POST',
|
|
232
|
+
body: JSON.stringify(data),
|
|
233
|
+
});
|
|
234
|
+
}, {
|
|
235
|
+
priority: priorityLevels.HIGHEST,
|
|
236
|
+
signal: init.signal ?? undefined,
|
|
237
|
+
});
|
|
238
|
+
return await response.json();
|
|
239
|
+
}
|
|
240
|
+
async pohBalance(init = {}) {
|
|
241
|
+
const url = new URL(this.baseURL + '/poh_balance');
|
|
242
|
+
const response = await this.queue.add(async () => {
|
|
243
|
+
return await this.#fetch(url, {
|
|
244
|
+
...init,
|
|
245
|
+
method: 'GET',
|
|
246
|
+
});
|
|
247
|
+
}, {
|
|
248
|
+
priority: priorityLevels.NORMAL,
|
|
249
|
+
signal: init.signal ?? undefined,
|
|
250
|
+
});
|
|
251
|
+
return await response.json();
|
|
252
|
+
}
|
|
253
|
+
async renterFees(init = {}) {
|
|
254
|
+
const url = new URL(this.baseURL + '/renter_fees');
|
|
255
|
+
const response = await this.queue.add(async () => {
|
|
256
|
+
return await this.#fetch(url, {
|
|
257
|
+
...init,
|
|
258
|
+
method: 'GET',
|
|
259
|
+
});
|
|
260
|
+
}, {
|
|
261
|
+
priority: priorityLevels.NORMAL,
|
|
262
|
+
signal: init.signal ?? undefined,
|
|
263
|
+
});
|
|
264
|
+
return await response.json();
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
export default Cloreai;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export interface CloreaiErrorOptions extends ErrorOptions {
|
|
2
|
+
init?: RequestInit;
|
|
3
|
+
request?: Request;
|
|
4
|
+
response?: Response;
|
|
5
|
+
statusCode?: number;
|
|
6
|
+
description?: string;
|
|
7
|
+
data?: unknown;
|
|
8
|
+
}
|
|
9
|
+
export declare class CloreaiError extends Error {
|
|
10
|
+
init?: RequestInit;
|
|
11
|
+
request?: Request;
|
|
12
|
+
response?: Response;
|
|
13
|
+
statusCode?: number;
|
|
14
|
+
description?: string;
|
|
15
|
+
data?: unknown;
|
|
16
|
+
constructor(message?: string, options?: CloreaiErrorOptions);
|
|
17
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type Cloreai from './Cloreai.ts';
|
|
2
|
+
import type { CancelOrdersRequestData, CancelOrdersResponseData } from './resources/cancelOrders.ts';
|
|
3
|
+
import type { CreateGigaspotOrdersRequestData, CreateGigaspotOrdersResponseData } from './resources/createGigaspotOrders.ts';
|
|
4
|
+
import type { EditGigaspotOrdersRequestData, EditGigaspotOrdersResponseData } from './resources/editGigaspotOrders.ts';
|
|
5
|
+
import type { GetGigaspotResponseData } from './resources/getGigaspot.ts';
|
|
6
|
+
type Fetch = (input: string | URL, init?: RequestInit) => Promise<Response>;
|
|
7
|
+
declare class Gigaspot {
|
|
8
|
+
#private;
|
|
9
|
+
constructor(cloreai: Cloreai, fetch: Fetch);
|
|
10
|
+
getGigaspot(init?: RequestInit): Promise<GetGigaspotResponseData>;
|
|
11
|
+
createGigaspotOrders(data: CreateGigaspotOrdersRequestData, init?: RequestInit): Promise<CreateGigaspotOrdersResponseData>;
|
|
12
|
+
editGigaspotOrders(data: EditGigaspotOrdersRequestData, init?: RequestInit): Promise<EditGigaspotOrdersResponseData>;
|
|
13
|
+
cancelOrders(data: CancelOrdersRequestData, init?: RequestInit): Promise<CancelOrdersResponseData>;
|
|
14
|
+
}
|
|
15
|
+
export default Gigaspot;
|
package/dist/Gigaspot.js
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { priorityLevels } from "./constants.js";
|
|
2
|
+
class Gigaspot {
|
|
3
|
+
#cloreai;
|
|
4
|
+
#fetch;
|
|
5
|
+
constructor(cloreai, fetch) {
|
|
6
|
+
this.#cloreai = cloreai;
|
|
7
|
+
this.#fetch = fetch;
|
|
8
|
+
}
|
|
9
|
+
async getGigaspot(init = {}) {
|
|
10
|
+
const url = new URL(this.#cloreai.baseURL + '/get_gigaspot');
|
|
11
|
+
const response = await this.#cloreai.queue.add(async () => {
|
|
12
|
+
return await this.#fetch(url, {
|
|
13
|
+
...init,
|
|
14
|
+
method: 'GET',
|
|
15
|
+
});
|
|
16
|
+
}, {
|
|
17
|
+
priority: priorityLevels.NORMAL,
|
|
18
|
+
signal: init.signal ?? undefined,
|
|
19
|
+
});
|
|
20
|
+
const data = await response.json();
|
|
21
|
+
const snapshotResponse = await fetch(data.v1_snapshot_url);
|
|
22
|
+
const snapshotData = await snapshotResponse.json();
|
|
23
|
+
return {
|
|
24
|
+
...data,
|
|
25
|
+
snapshot: snapshotData,
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
async createGigaspotOrders(data, init = {}) {
|
|
29
|
+
const url = new URL(this.#cloreai.baseURL + '/create_gigaspot_orders');
|
|
30
|
+
const response = await this.#cloreai.queue.add(async () => {
|
|
31
|
+
return await this.#fetch(url, {
|
|
32
|
+
...init,
|
|
33
|
+
method: 'POST',
|
|
34
|
+
body: JSON.stringify(data),
|
|
35
|
+
});
|
|
36
|
+
}, {
|
|
37
|
+
priority: priorityLevels.HIGH,
|
|
38
|
+
signal: init.signal ?? undefined,
|
|
39
|
+
});
|
|
40
|
+
return await response.json();
|
|
41
|
+
}
|
|
42
|
+
async editGigaspotOrders(data, init = {}) {
|
|
43
|
+
const url = new URL(this.#cloreai.baseURL + '/edit_gigaspot_orders');
|
|
44
|
+
const response = await this.#cloreai.queue.add(async () => {
|
|
45
|
+
return await this.#fetch(url, {
|
|
46
|
+
...init,
|
|
47
|
+
method: 'POST',
|
|
48
|
+
body: JSON.stringify(data),
|
|
49
|
+
});
|
|
50
|
+
}, {
|
|
51
|
+
priority: priorityLevels.HIGH,
|
|
52
|
+
signal: init.signal ?? undefined,
|
|
53
|
+
});
|
|
54
|
+
return await response.json();
|
|
55
|
+
}
|
|
56
|
+
async cancelOrders(data, init = {}) {
|
|
57
|
+
const url = new URL(this.#cloreai.baseURL + '/cancel_orders');
|
|
58
|
+
const response = await this.#cloreai.queue.add(async () => {
|
|
59
|
+
return await this.#fetch(url, {
|
|
60
|
+
...init,
|
|
61
|
+
method: 'POST',
|
|
62
|
+
body: JSON.stringify(data),
|
|
63
|
+
});
|
|
64
|
+
}, {
|
|
65
|
+
priority: priorityLevels.HIGH,
|
|
66
|
+
signal: init.signal ?? undefined,
|
|
67
|
+
});
|
|
68
|
+
return await response.json();
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
export default Gigaspot;
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
export declare const RATE_LIMIT = 1000;
|
|
2
2
|
export declare const RATE_LIMIT_CREATE_ORDER = 5000;
|
|
3
|
-
export declare const RATE_LIMIT_GIGASPOT = 1000;
|
|
4
3
|
export declare const gigaspotBaseImages: Readonly<{
|
|
5
4
|
UBUNTU: "a3f9c4d7e5b088d8a0bff880";
|
|
6
5
|
HIVEOS: "c9a4e2f6b7d488d8f0bab0ff";
|