cloreai 0.1.19 → 1.0.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/README.md CHANGED
@@ -0,0 +1,286 @@
1
+ # cloreai
2
+
3
+ > CLORE.AI API client
4
+
5
+ Особенности:
6
+
7
+ - Базируется на [axios](https://github.com/axios/axios)
8
+ - Защищает от превышения rate limit (ошибки 429) через
9
+ [p-queue](https://github.com/sindresorhus/p-queue)
10
+ - Поддерживает GigaSPOT
11
+
12
+ Официальная документация: [clore.ai/api-docs](https://clore.ai/api-docs)
13
+
14
+ Официальная документация GigaSPOT:
15
+ [gigaspot-api-docs.clore.ai](https://gigaspot-api-docs.clore.ai)
16
+
17
+ ## Установка
18
+
19
+ ```shell
20
+ npm install cloreai
21
+ ```
22
+
23
+ ## Использование
24
+
25
+ ### Создание экземпляра
26
+
27
+ ```typescript
28
+ import CloreAI from 'cloreai'
29
+
30
+ const cloreai = new CloreAI({
31
+ apiKey: '<API_KEY>', // (required)
32
+ axiosOptions: {}, // (optional) Axios instance options https://github.com/axios/axios
33
+ queueOptions: {}, // (optional) Queue instance options https://github.com/sindresorhus/p-queue
34
+ queueOptionsCreateOrder: {}, // (optional) Create order queue instance options https://github.com/sindresorhus/p-queue
35
+ queueOptionsGigaspot: {}, // (optional) Gigaspot queue instance options https://github.com/sindresorhus/p-queue
36
+ })
37
+ ```
38
+
39
+ ### 1. wallets
40
+
41
+ ```typescript
42
+ const wallets = await cloreai.wallets()
43
+ ```
44
+
45
+ ### 2. my_servers
46
+
47
+ ```typescript
48
+ const myServers = await cloreai.myServers()
49
+ ```
50
+
51
+ ### 3. server_config
52
+
53
+ ```typescript
54
+ const serverConfig = await cloreai.serverConfig({
55
+ server_name: 'server_name',
56
+ })
57
+ ```
58
+
59
+ ### 4. marketplace
60
+
61
+ ```typescript
62
+ const marketplace = await cloreai.marketplace()
63
+ ```
64
+
65
+ ### 5. my_orders
66
+
67
+ ```typescript
68
+ const myOrders = await cloreai.myOrders() // Current orders
69
+ const allMyOrders = await cloreai.myOrders({ return_completed: true }) // All orders
70
+ ```
71
+
72
+ ### 6. spot_marketplace
73
+
74
+ ```typescript
75
+ const spotMarketplace = await cloreai.spotMarketplace({
76
+ market: 6718, // Server id
77
+ })
78
+ ```
79
+
80
+ ### 7. set_server_settings
81
+
82
+ ```typescript
83
+ await cloreai.setServerSettings({
84
+ 'name': 'name', // Server name
85
+ 'availability': true,
86
+ 'mrl': 24,
87
+ 'on_demand': 50,
88
+ 'spot': 50,
89
+ 'CLORE-Blockchain_on_demand': 50,
90
+ 'CLORE-Blockchain_spot': 50,
91
+ })
92
+ ```
93
+
94
+ ### 8. set_spot_price
95
+
96
+ ```typescript
97
+ await cloreai.setSpotPrice({
98
+ order_id: 38176,
99
+ desired_price: 50,
100
+ })
101
+ ```
102
+
103
+ ### 9. cancel_order
104
+
105
+ ```typescript
106
+ await cloreai.cancelOrder({
107
+ id: 6718,
108
+ issue: 'issue',
109
+ })
110
+ ```
111
+
112
+ ### 10. create_order
113
+
114
+ ```typescript
115
+ await cloreai.createOrder({
116
+ type: 'on-demand',
117
+ currency: 'CLORE-Blockchain',
118
+ image: 'cloreai/jupyter:ubuntu24.04-v2',
119
+ renting_server: 5738,
120
+ ports: { 22: 'tcp', 8888: 'http' },
121
+ env: { SSH_PASSWORD: 'SSH_PASSWORD', JUPYTER_TOKEN: 'JUPYTER_TOKEN' },
122
+ jupyter_token: 'jupyter_token',
123
+ ssh_password: 'ssh_password',
124
+ required_price: 50,
125
+ remember_password: true,
126
+ })
127
+ ```
128
+
129
+ ### 11. PoH Info
130
+
131
+ ```typescript
132
+ const pohBalance = await cloreai.pohBalance()
133
+ ```
134
+
135
+ ### GigaSPOT
136
+
137
+ #### getGigaspot
138
+
139
+ ```typescript
140
+ const gigaspot = await cloreai.gigaspot.getGigaspot()
141
+ ```
142
+
143
+ #### createGigaspotOrders
144
+
145
+ ```typescript
146
+ import { gigaspotBaseImages } from 'cloreai'
147
+
148
+ await cloreai.gigaspot.createGigaspotOrders([
149
+ {
150
+ currency: 'CLORE-Blockchain',
151
+ image: gigaspotBaseImages.UBUNTU, // Use the base image constant
152
+ renting_server: 5941,
153
+ price: 50,
154
+ oc: [
155
+ {
156
+ pl: 150,
157
+ },
158
+ ],
159
+ },
160
+ ])
161
+ ```
162
+
163
+ #### editGigaspotOrders
164
+
165
+ ```typescript
166
+ await cloreai.gigaspot.editGigaspotOrders([
167
+ {
168
+ order_id: 58991,
169
+ price: 50,
170
+ oc: [
171
+ {
172
+ pl: 150,
173
+ },
174
+ ],
175
+ },
176
+ ])
177
+ ```
178
+
179
+ #### cancelOrders
180
+
181
+ ```typescript
182
+ await cloreai.gigaspot.cancelOrders({
183
+ order_ids: [8383],
184
+ })
185
+ ```
186
+
187
+ ### Конфигурация запросов
188
+
189
+ Каждый метод принимает опциональную конфигурацию запроса для axios последним
190
+ параметром, например:
191
+
192
+ ```typescript
193
+ const marketplace = await cloreai.marketplace({
194
+ // axios config
195
+ })
196
+ ```
197
+
198
+ ### Доступ к экземпляру axios
199
+
200
+ Используйте поле `cloreai.axios`.
201
+
202
+ Обратитесь к документации [axios](https://github.com/axios/axios).
203
+
204
+ ### Доступ к экземплярам p-queue
205
+
206
+ Используйте поля:
207
+
208
+ - `cloreai.queue` - для основной очереди запросов
209
+ - `cloreai.queueCreateOrder` - для очереди запросов createOrder
210
+ - `cloreai.gigaspot.queue` - для очереди запросов gigaspot
211
+
212
+ Обратитесь к документации [p-queue](https://github.com/sindresorhus/p-queue).
213
+
214
+ ### Обработка ошибок
215
+
216
+ Библиотека экспортирует следующие виды ошибок:
217
+
218
+ - `DatabaseError`
219
+ - `InvalidInputDataError`
220
+ - `InvalidApiTokenError`
221
+ - `InvalidEndpointError`
222
+ - `ExceededError`
223
+ - `OtherError`
224
+ - `UnknownError`
225
+
226
+ Все эти ошибки наследуются от `AxiosError`.
227
+
228
+ Проверяйте тип ошибки через оператор `instanceof`:
229
+
230
+ ```typescript
231
+ import { AxiosError } from 'axios'
232
+ import { ExceededError } from 'cloreai'
233
+
234
+ try {
235
+ const marketplace = await cloreai.marketplace()
236
+ } catch (error) {
237
+ if (error instanceof AxiosError) {
238
+ console.log('AxiosError')
239
+
240
+ if (error instanceof ExceededError) {
241
+ console.log('ExceededError')
242
+ }
243
+ } else {
244
+ throw error
245
+ }
246
+ }
247
+ ```
248
+
249
+ ### Rate limit
250
+
251
+ Все методы защищены от превышения rate limit через
252
+ [p-queue](https://github.com/sindresorhus/p-queue), они автоматически
253
+ задерживаются на нужное время, чтобы избежать превышения лимита.
254
+
255
+ Значения rate limit по умолчанию доступны как константы:
256
+
257
+ ```typescript
258
+ import {
259
+ RATE_LIMIT,
260
+ RATE_LIMIT_CREATE_ORDER,
261
+ RATE_LIMIT_GIGASPOT,
262
+ } from 'cloreai'
263
+
264
+ console.log(RATE_LIMIT)
265
+ console.log(RATE_LIMIT_CREATE_ORDER)
266
+ console.log(RATE_LIMIT_GIGASPOT)
267
+ ```
268
+
269
+ Можно задать собственные значение rate limit для каждой очереди запросов:
270
+
271
+ ```typescript
272
+ import CloreAI from 'cloreai'
273
+
274
+ const cloreai = new CloreAI({
275
+ apiKey: '<API_KEY>',
276
+ queueOptions: {
277
+ interval: 10000, // 10 seconds
278
+ },
279
+ queueOptionsCreateOrder: {
280
+ interval: 10000, // 10 seconds
281
+ },
282
+ queueOptionsGigaspot: {
283
+ interval: 10000, // 10 seconds
284
+ },
285
+ })
286
+ ```
@@ -1,26 +1,24 @@
1
1
  import { type AxiosInstance, type AxiosRequestConfig } from 'axios';
2
2
  import PQueue from 'p-queue';
3
3
  import type { CancelOrderRequestData, CancelOrderResponseData } from './endpoints/cancelOrder.js';
4
- import type { CancelOrdersRequestData, CancelOrdersResponseData } from './endpoints/cancelOrders.js';
5
- import type { CreateGigaspotOrdersRequestData, CreateGigaspotOrdersResponseData } from './endpoints/createGigaspotOrders.js';
6
4
  import type { CreateOrderRequestData, CreateOrderResponseData } from './endpoints/createOrder.js';
7
- import type { EditGigaspotOrdersRequestData, EditGigaspotOrdersResponseData } from './endpoints/editGigaspotOrders.js';
8
- import type { GetGigaspotResponseData } from './endpoints/getGigaspot.js';
9
5
  import type { MarketplaceResponseData } from './endpoints/marketplace.js';
10
6
  import type { MyOrdersRequestParams, MyOrdersResponseData } from './endpoints/myOrders.js';
11
7
  import type { MyServersResponseData } from './endpoints/myServers.js';
8
+ import type { PohBalanceResponseData } from './endpoints/pohBalance.js';
12
9
  import type { ServerConfigRequestData, ServerConfigResponseData } from './endpoints/serverConfig.js';
13
10
  import type { SetServerSettingsRequestData, SetServerSettingsResponseData } from './endpoints/setServerSettings.js';
14
11
  import type { SetSpotPriceRequestData, SetSpotPriceResponseData } from './endpoints/setSpotPrice.js';
15
12
  import type { SpotMarketplaceRequestParams, SpotMarketplaceResponseData } from './endpoints/spotMarketplace.js';
16
13
  import type { WalletsResponseData } from './endpoints/wallets.js';
17
14
  import type { Config } from './types.js';
15
+ import Gigaspot from './Gigaspot.js';
18
16
  declare class CloreAI {
19
17
  axios: AxiosInstance;
20
- rateLimitQueue: PQueue;
21
- rateLimitQueueCreateOrder: PQueue;
18
+ queue: PQueue;
19
+ queueCreateOrder: PQueue;
20
+ gigaspot: Gigaspot;
22
21
  constructor(config: Config);
23
- private getQueueOptions;
24
22
  wallets(config?: AxiosRequestConfig): Promise<WalletsResponseData>;
25
23
  myServers(config?: AxiosRequestConfig): Promise<MyServersResponseData>;
26
24
  serverConfig(data: ServerConfigRequestData, config?: AxiosRequestConfig): Promise<ServerConfigResponseData>;
@@ -31,9 +29,6 @@ declare class CloreAI {
31
29
  setSpotPrice(data: SetSpotPriceRequestData, config?: AxiosRequestConfig): Promise<SetSpotPriceResponseData>;
32
30
  cancelOrder(data: CancelOrderRequestData, config?: AxiosRequestConfig): Promise<CancelOrderResponseData>;
33
31
  createOrder(data: CreateOrderRequestData, config?: AxiosRequestConfig): Promise<CreateOrderResponseData>;
34
- getGigaspot(config?: AxiosRequestConfig): Promise<GetGigaspotResponseData>;
35
- createGigaspotOrders(data: CreateGigaspotOrdersRequestData, config?: AxiosRequestConfig): Promise<CreateGigaspotOrdersResponseData>;
36
- editGigaspotOrders(data: EditGigaspotOrdersRequestData, config?: AxiosRequestConfig): Promise<EditGigaspotOrdersResponseData>;
37
- cancelOrders(data: CancelOrdersRequestData, config?: AxiosRequestConfig): Promise<CancelOrdersResponseData>;
32
+ pohBalance(config?: AxiosRequestConfig): Promise<PohBalanceResponseData>;
38
33
  }
39
34
  export default CloreAI;
package/build/CloreAI.js CHANGED
@@ -1,26 +1,29 @@
1
1
  import axios from 'axios';
2
2
  import PQueue from 'p-queue';
3
- import { priorityLevels, RATE_LIMIT, RATE_LIMIT_CREATE_ORDER, statusCodes } from './constants.js';
3
+ import { RATE_LIMIT, RATE_LIMIT_CREATE_ORDER } from './constants.js';
4
4
  import { DatabaseError, ExceededError, InvalidApiTokenError, InvalidEndpointError, InvalidInputDataError, OtherError, UnknownError } from './errors.js';
5
+ import Gigaspot from './Gigaspot.js';
6
+ import { getQueueOptions, priorityLevels, statusCodes } from './helpers.js';
5
7
  class CloreAI {
6
8
  axios;
7
- rateLimitQueue;
8
- rateLimitQueueCreateOrder;
9
+ queue;
10
+ queueCreateOrder;
11
+ gigaspot;
9
12
  constructor(config) {
10
- this.rateLimitQueue = new PQueue({
13
+ this.queue = new PQueue({
11
14
  interval: RATE_LIMIT,
12
15
  intervalCap: 1,
13
16
  concurrency: 1,
14
- ...config.rateLimitQueueOptions,
17
+ ...config.queueOptions,
15
18
  });
16
- this.rateLimitQueueCreateOrder = new PQueue({
19
+ this.queueCreateOrder = new PQueue({
17
20
  interval: RATE_LIMIT_CREATE_ORDER,
18
21
  intervalCap: 1,
19
22
  concurrency: 1,
20
- ...config.rateLimitQueueOptionsCreateOrder,
23
+ ...config.queueOptionsCreateOrder,
21
24
  });
22
25
  this.axios = axios.create({
23
- ...config.axiosConfig,
26
+ ...config.axiosOptions,
24
27
  baseURL: 'https://api.clore.ai/v1',
25
28
  });
26
29
  this.axios.interceptors.request.use((request) => {
@@ -32,8 +35,8 @@ class CloreAI {
32
35
  return response;
33
36
  }
34
37
  const errorMessage = response.data.error != null
35
- ? `Code "${response.status}", error "${response.data.error}"`
36
- : `Code "${response.status}"`;
38
+ ? `Code "${response.data.code}", error "${response.data.error}"`
39
+ : `Code "${response.data.code}"`;
37
40
  const axiosErrorParameters = [
38
41
  errorMessage,
39
42
  undefined,
@@ -58,109 +61,72 @@ class CloreAI {
58
61
  throw new UnknownError(...axiosErrorParameters);
59
62
  }
60
63
  });
61
- }
62
- // eslint-disable-next-line @typescript-eslint/class-methods-use-this -- Ignore
63
- getQueueOptions(priority, config) {
64
- const defaultQueueOptions = {
65
- throwOnTimeout: true,
66
- priority,
67
- };
68
- // eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion -- GenericAbortSignal
69
- const signal = config?.signal;
70
- if (signal == null) {
71
- return defaultQueueOptions;
72
- }
73
- return {
74
- ...defaultQueueOptions,
75
- signal,
76
- };
64
+ this.gigaspot = new Gigaspot(config, this.axios);
77
65
  }
78
66
  async wallets(config) {
79
- const response = await this.rateLimitQueue.add(async () => {
67
+ const response = await this.queue.add(async () => {
80
68
  return await this.axios.get('/wallets', config);
81
- }, this.getQueueOptions(priorityLevels.NORMAL, config));
69
+ }, getQueueOptions(priorityLevels.NORMAL, config));
82
70
  return response.data;
83
71
  }
84
72
  async myServers(config) {
85
- const response = await this.rateLimitQueue.add(async () => {
73
+ const response = await this.queue.add(async () => {
86
74
  return await this.axios.get('/my_servers', config);
87
- }, this.getQueueOptions(priorityLevels.NORMAL, config));
75
+ }, getQueueOptions(priorityLevels.NORMAL, config));
88
76
  return response.data;
89
77
  }
90
78
  async serverConfig(data, config) {
91
- const response = await this.rateLimitQueue.add(async () => {
79
+ const response = await this.queue.add(async () => {
92
80
  return await this.axios.get('/server_config', { ...config, data });
93
- }, this.getQueueOptions(priorityLevels.NORMAL, config));
81
+ }, getQueueOptions(priorityLevels.NORMAL, config));
94
82
  return response.data;
95
83
  }
96
84
  async marketplace(config) {
97
- const response = await this.rateLimitQueue.add(async () => {
85
+ const response = await this.queue.add(async () => {
98
86
  return await this.axios.get('/marketplace', config);
99
- }, this.getQueueOptions(priorityLevels.NORMAL, config));
87
+ }, getQueueOptions(priorityLevels.NORMAL, config));
100
88
  return response.data;
101
89
  }
102
90
  async myOrders(params, config) {
103
- const response = await this.rateLimitQueue.add(async () => {
91
+ const response = await this.queue.add(async () => {
104
92
  return await this.axios.get('/my_orders', { ...config, params });
105
- }, this.getQueueOptions(priorityLevels.NORMAL, config));
93
+ }, getQueueOptions(priorityLevels.NORMAL, config));
106
94
  return response.data;
107
95
  }
108
96
  async spotMarketplace(params, config) {
109
- const response = await this.rateLimitQueue.add(async () => {
97
+ const response = await this.queue.add(async () => {
110
98
  return await this.axios.get('/spot_marketplace', { ...config, params });
111
- }, this.getQueueOptions(priorityLevels.NORMAL, config));
99
+ }, getQueueOptions(priorityLevels.NORMAL, config));
112
100
  return response.data;
113
101
  }
114
102
  async setServerSettings(data, config) {
115
- const response = await this.rateLimitQueue.add(async () => {
103
+ const response = await this.queue.add(async () => {
116
104
  return await this.axios.post('/set_server_settings', data, config);
117
- }, this.getQueueOptions(priorityLevels.HIGH, config));
105
+ }, getQueueOptions(priorityLevels.HIGH, config));
118
106
  return response.data;
119
107
  }
120
108
  async setSpotPrice(data, config) {
121
- const response = await this.rateLimitQueue.add(async () => {
109
+ const response = await this.queue.add(async () => {
122
110
  return await this.axios.post('/set_spot_price', data, config);
123
- }, this.getQueueOptions(priorityLevels.HIGH, config));
111
+ }, getQueueOptions(priorityLevels.HIGH, config));
124
112
  return response.data;
125
113
  }
126
114
  async cancelOrder(data, config) {
127
- const response = await this.rateLimitQueue.add(async () => {
115
+ const response = await this.queue.add(async () => {
128
116
  return await this.axios.post('/cancel_order', data, config);
129
- }, this.getQueueOptions(priorityLevels.HIGH, config));
117
+ }, getQueueOptions(priorityLevels.HIGH, config));
130
118
  return response.data;
131
119
  }
132
120
  async createOrder(data, config) {
133
- const response = await this.rateLimitQueueCreateOrder.add(async () => {
121
+ const response = await this.queueCreateOrder.add(async () => {
134
122
  return await this.axios.post('/create_order', data, config);
135
- }, this.getQueueOptions(priorityLevels.HIGHEST, config));
136
- return response.data;
137
- }
138
- async getGigaspot(config) {
139
- return await this.rateLimitQueue.add(async () => {
140
- const response = await this.axios.get('/get_gigaspot', config);
141
- const snapshot = await axios.get(response.data.v1_snapshot_url);
142
- return {
143
- ...response.data,
144
- snapshot: snapshot.data,
145
- };
146
- }, this.getQueueOptions(priorityLevels.NORMAL, config));
147
- }
148
- async createGigaspotOrders(data, config) {
149
- const response = await this.rateLimitQueue.add(async () => {
150
- return await this.axios.post('/create_gigaspot_orders', data, config);
151
- }, this.getQueueOptions(priorityLevels.HIGH, config));
152
- return response.data;
153
- }
154
- async editGigaspotOrders(data, config) {
155
- const response = await this.rateLimitQueue.add(async () => {
156
- return await this.axios.post('/edit_gigaspot_orders', data, config);
157
- }, this.getQueueOptions(priorityLevels.HIGH, config));
123
+ }, getQueueOptions(priorityLevels.HIGHEST, config));
158
124
  return response.data;
159
125
  }
160
- async cancelOrders(data, config) {
161
- const response = await this.rateLimitQueue.add(async () => {
162
- return await this.axios.post('/cancel_orders', data, config);
163
- }, this.getQueueOptions(priorityLevels.HIGH, config));
126
+ async pohBalance(config) {
127
+ const response = await this.queue.add(async () => {
128
+ return await this.axios.get('/poh_balance', config);
129
+ }, getQueueOptions(priorityLevels.NORMAL, config));
164
130
  return response.data;
165
131
  }
166
132
  }
@@ -0,0 +1,17 @@
1
+ import { type AxiosInstance, type AxiosRequestConfig } from 'axios';
2
+ import PQueue from 'p-queue';
3
+ import type { CancelOrdersRequestData, CancelOrdersResponseData } from './endpoints/cancelOrders.js';
4
+ import type { CreateGigaspotOrdersRequestData, CreateGigaspotOrdersResponseData } from './endpoints/createGigaspotOrders.js';
5
+ import type { EditGigaspotOrdersRequestData, EditGigaspotOrdersResponseData } from './endpoints/editGigaspotOrders.js';
6
+ import type { GetGigaspotResponseData } from './endpoints/getGigaspot.js';
7
+ import type { Config } from './types.js';
8
+ declare class Gigaspot {
9
+ queue: PQueue;
10
+ private readonly axios;
11
+ constructor(config: Config, axios: AxiosInstance);
12
+ getGigaspot(config?: AxiosRequestConfig): Promise<GetGigaspotResponseData>;
13
+ createGigaspotOrders(data: CreateGigaspotOrdersRequestData, config?: AxiosRequestConfig): Promise<CreateGigaspotOrdersResponseData>;
14
+ editGigaspotOrders(data: EditGigaspotOrdersRequestData, config?: AxiosRequestConfig): Promise<EditGigaspotOrdersResponseData>;
15
+ cancelOrders(data: CancelOrdersRequestData, config?: AxiosRequestConfig): Promise<CancelOrdersResponseData>;
16
+ }
17
+ export default Gigaspot;
@@ -0,0 +1,46 @@
1
+ import axios from 'axios';
2
+ import PQueue from 'p-queue';
3
+ import { RATE_LIMIT_GIGASPOT } from './constants.js';
4
+ import { getQueueOptions, priorityLevels } from './helpers.js';
5
+ class Gigaspot {
6
+ queue;
7
+ axios;
8
+ constructor(config, axios) {
9
+ this.queue = new PQueue({
10
+ interval: RATE_LIMIT_GIGASPOT,
11
+ intervalCap: 1,
12
+ concurrency: 1,
13
+ ...config.queueOptionsGigaspot,
14
+ });
15
+ this.axios = axios;
16
+ }
17
+ async getGigaspot(config) {
18
+ return await this.queue.add(async () => {
19
+ const response = await this.axios.get('/get_gigaspot', config);
20
+ const snapshot = await axios.get(response.data.v1_snapshot_url);
21
+ return {
22
+ ...response.data,
23
+ snapshot: snapshot.data,
24
+ };
25
+ }, getQueueOptions(priorityLevels.NORMAL, config));
26
+ }
27
+ async createGigaspotOrders(data, config) {
28
+ const response = await this.queue.add(async () => {
29
+ return await this.axios.post('/create_gigaspot_orders', data, config);
30
+ }, getQueueOptions(priorityLevels.HIGH, config));
31
+ return response.data;
32
+ }
33
+ async editGigaspotOrders(data, config) {
34
+ const response = await this.queue.add(async () => {
35
+ return await this.axios.post('/edit_gigaspot_orders', data, config);
36
+ }, getQueueOptions(priorityLevels.HIGH, config));
37
+ return response.data;
38
+ }
39
+ async cancelOrders(data, config) {
40
+ const response = await this.queue.add(async () => {
41
+ return await this.axios.post('/cancel_orders', data, config);
42
+ }, getQueueOptions(priorityLevels.HIGH, config));
43
+ return response.data;
44
+ }
45
+ }
46
+ export default Gigaspot;
@@ -1,19 +1,6 @@
1
1
  export declare const RATE_LIMIT = 1800;
2
2
  export declare const RATE_LIMIT_CREATE_ORDER = 5000;
3
- export declare const statusCodes: {
4
- NORMAL: number;
5
- DATABASE_ERROR: number;
6
- INVALID_INPUT_DATA: number;
7
- INVALID_API_TOKEN: number;
8
- INVALID_ENDPOINT: number;
9
- EXCEEDED: number;
10
- OTHER: number;
11
- };
12
- export declare const priorityLevels: {
13
- NORMAL: number;
14
- HIGH: number;
15
- HIGHEST: number;
16
- };
3
+ export declare const RATE_LIMIT_GIGASPOT = 1800;
17
4
  export declare const gigaspotBaseImages: {
18
5
  UBUNTU: string;
19
6
  HIVEOS: string;
@@ -1,19 +1,6 @@
1
- export const RATE_LIMIT = 1_800;
2
- export const RATE_LIMIT_CREATE_ORDER = 5_000;
3
- export const statusCodes = {
4
- NORMAL: 0,
5
- DATABASE_ERROR: 1,
6
- INVALID_INPUT_DATA: 2,
7
- INVALID_API_TOKEN: 3,
8
- INVALID_ENDPOINT: 4,
9
- EXCEEDED: 5,
10
- OTHER: 6,
11
- };
12
- export const priorityLevels = {
13
- NORMAL: 0,
14
- HIGH: 1,
15
- HIGHEST: 2,
16
- };
1
+ export const RATE_LIMIT = 1800;
2
+ export const RATE_LIMIT_CREATE_ORDER = 5000;
3
+ export const RATE_LIMIT_GIGASPOT = 1800;
17
4
  export const gigaspotBaseImages = {
18
5
  UBUNTU: 'a3f9c4d7e5b088d8a0bff880',
19
6
  HIVEOS: 'c9a4e2f6b7d488d8f0bab0ff',
@@ -3,5 +3,5 @@ export interface CancelOrdersRequestData {
3
3
  order_ids: number[];
4
4
  }
5
5
  export interface CancelOrdersResponseData extends ResponseData {
6
- failed_to_cancel: number[];
6
+ failed_to_cancel: string[];
7
7
  }
@@ -4,19 +4,19 @@ export interface MarketplaceResponseDataServerRating {
4
4
  cnt: number;
5
5
  }
6
6
  export interface MarketplaceResponseDataServer {
7
- allowed_coins: Currency[];
8
- cuda_version: string;
9
- gigaspot: boolean;
10
- gpu_array: string[];
11
7
  id: number;
12
- mrl: number;
13
- oc: boolean;
14
8
  owner: number;
9
+ mrl: number;
15
10
  price: Price;
16
- rating: MarketplaceResponseDataServerRating;
17
- reliability: number;
18
11
  rented: boolean;
19
12
  specs: Specs;
13
+ reliability: number;
14
+ allowed_coins: Currency[];
15
+ rating: MarketplaceResponseDataServerRating;
16
+ gpu_array: string[];
17
+ gigaspot: boolean;
18
+ oc?: boolean;
19
+ cuda_version: string;
20
20
  }
21
21
  export interface MarketplaceResponseData extends ResponseData {
22
22
  servers: MarketplaceResponseDataServer[];
@@ -3,26 +3,26 @@ export interface MyOrdersRequestParams {
3
3
  return_completed?: boolean;
4
4
  }
5
5
  export interface MyOrdersResponseDataOrder {
6
- auto_login: string;
7
6
  id: number;
8
7
  fee: number;
9
8
  creation_fee: number;
10
9
  price: number;
11
10
  mrl: number;
12
- online: boolean;
13
11
  image: string;
14
- mon_container: number;
15
12
  currency: Currency;
16
13
  spend: number;
17
14
  ct: number;
18
- p: number;
19
15
  specs: Specs;
20
16
  si: number;
21
- spot: boolean;
22
- expired: boolean;
17
+ auto_login: string;
18
+ mon_container: number;
19
+ online: boolean;
23
20
  pub_cluster: string[];
24
21
  tcp_ports: string[];
25
22
  http_port: string;
23
+ http_pub: string;
24
+ spot: boolean;
25
+ expired: boolean;
26
26
  }
27
27
  export interface MyOrdersResponseData extends ResponseData {
28
28
  orders: MyOrdersResponseDataOrder[];
@@ -0,0 +1,31 @@
1
+ import type { ResponseData } from '../types.js';
2
+ export interface PohBalanceResponseDataBalanceOffers {
3
+ rented_amount: number;
4
+ rented_on_marketplace_amount: number;
5
+ rented_finished_amount: number;
6
+ leased_amount: number;
7
+ leased_finished_amount: number;
8
+ }
9
+ export interface PohBalanceResponseDataBalance {
10
+ total: number;
11
+ free_amount: number;
12
+ reward_amount: number;
13
+ offers: PohBalanceResponseDataBalanceOffers;
14
+ }
15
+ export interface PohBalanceResponseDataItem {
16
+ user: number;
17
+ address: string;
18
+ signature: string;
19
+ message: string;
20
+ created: number;
21
+ unique: string;
22
+ remove: number;
23
+ status: string;
24
+ balance: number;
25
+ last_check: number;
26
+ }
27
+ export interface PohBalanceResponseData extends ResponseData {
28
+ items: PohBalanceResponseDataItem[];
29
+ balance: PohBalanceResponseDataBalance;
30
+ count: number;
31
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -1,9 +1,11 @@
1
1
  import type { ResponseData } from '../types.js';
2
2
  export interface SetServerSettingsRequestData {
3
- name: string;
4
- availability: boolean;
5
- mrl: number;
6
- on_demand: number;
7
- spot: number;
3
+ 'name': string;
4
+ 'availability': boolean;
5
+ 'mrl': number;
6
+ 'on_demand': number;
7
+ 'spot': number;
8
+ 'CLORE-Blockchain_on_demand': number;
9
+ 'CLORE-Blockchain_spot': number;
8
10
  }
9
11
  export type SetServerSettingsResponseData = ResponseData;
package/build/errors.d.ts CHANGED
@@ -1,23 +1,22 @@
1
1
  import { AxiosError } from 'axios';
2
- export type AxiosErrorParameters = ConstructorParameters<typeof AxiosError>;
3
2
  export declare class DatabaseError extends AxiosError {
4
- constructor(...args: AxiosErrorParameters);
3
+ constructor(...args: ConstructorParameters<typeof AxiosError>);
5
4
  }
6
5
  export declare class InvalidInputDataError extends AxiosError {
7
- constructor(...args: AxiosErrorParameters);
6
+ constructor(...args: ConstructorParameters<typeof AxiosError>);
8
7
  }
9
8
  export declare class InvalidApiTokenError extends AxiosError {
10
- constructor(...args: AxiosErrorParameters);
9
+ constructor(...args: ConstructorParameters<typeof AxiosError>);
11
10
  }
12
11
  export declare class InvalidEndpointError extends AxiosError {
13
- constructor(...args: AxiosErrorParameters);
12
+ constructor(...args: ConstructorParameters<typeof AxiosError>);
14
13
  }
15
14
  export declare class ExceededError extends AxiosError {
16
- constructor(...args: AxiosErrorParameters);
15
+ constructor(...args: ConstructorParameters<typeof AxiosError>);
17
16
  }
18
17
  export declare class OtherError extends AxiosError {
19
- constructor(...args: AxiosErrorParameters);
18
+ constructor(...args: ConstructorParameters<typeof AxiosError>);
20
19
  }
21
20
  export declare class UnknownError extends AxiosError {
22
- constructor(...args: AxiosErrorParameters);
21
+ constructor(...args: ConstructorParameters<typeof AxiosError>);
23
22
  }
@@ -0,0 +1,19 @@
1
+ import type { AxiosRequestConfig } from 'axios';
2
+ import type { QueueAddOptions } from 'p-queue';
3
+ export declare const statusCodes: {
4
+ NORMAL: number;
5
+ DATABASE_ERROR: number;
6
+ INVALID_INPUT_DATA: number;
7
+ INVALID_API_TOKEN: number;
8
+ INVALID_ENDPOINT: number;
9
+ EXCEEDED: number;
10
+ OTHER: number;
11
+ };
12
+ export declare const priorityLevels: {
13
+ NORMAL: number;
14
+ HIGH: number;
15
+ HIGHEST: number;
16
+ };
17
+ export declare function getQueueOptions(priority: number, config?: AxiosRequestConfig): QueueAddOptions & {
18
+ throwOnTimeout: true;
19
+ };
@@ -0,0 +1,29 @@
1
+ export const statusCodes = {
2
+ NORMAL: 0,
3
+ DATABASE_ERROR: 1,
4
+ INVALID_INPUT_DATA: 2,
5
+ INVALID_API_TOKEN: 3,
6
+ INVALID_ENDPOINT: 4,
7
+ EXCEEDED: 5,
8
+ OTHER: 6,
9
+ };
10
+ export const priorityLevels = {
11
+ NORMAL: 0,
12
+ HIGH: 1,
13
+ HIGHEST: 2,
14
+ };
15
+ export function getQueueOptions(priority, config) {
16
+ const defaultQueueOptions = {
17
+ throwOnTimeout: true,
18
+ priority,
19
+ };
20
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
21
+ const signal = config?.signal;
22
+ if (signal == null) {
23
+ return defaultQueueOptions;
24
+ }
25
+ return {
26
+ ...defaultQueueOptions,
27
+ signal,
28
+ };
29
+ }
package/build/index.d.ts CHANGED
@@ -9,6 +9,7 @@ export type * from './endpoints/getGigaspot.js';
9
9
  export type * from './endpoints/marketplace.js';
10
10
  export type * from './endpoints/myOrders.js';
11
11
  export type * from './endpoints/myServers.js';
12
+ export type * from './endpoints/pohBalance.js';
12
13
  export type * from './endpoints/serverConfig.js';
13
14
  export type * from './endpoints/setServerSettings.js';
14
15
  export type * from './endpoints/setSpotPrice.js';
package/build/types.d.ts CHANGED
@@ -3,9 +3,10 @@ import type { Options, Queue, QueueAddOptions } from 'p-queue';
3
3
  export type PQueueOptions = Options<Queue<() => Promise<unknown>, QueueAddOptions>, QueueAddOptions>;
4
4
  export interface Config {
5
5
  apiKey: string;
6
- axiosConfig?: CreateAxiosDefaults;
7
- rateLimitQueueOptions?: PQueueOptions;
8
- rateLimitQueueOptionsCreateOrder?: PQueueOptions;
6
+ axiosOptions?: CreateAxiosDefaults;
7
+ queueOptions?: PQueueOptions;
8
+ queueOptionsCreateOrder?: PQueueOptions;
9
+ queueOptionsGigaspot?: PQueueOptions;
9
10
  }
10
11
  export interface ResponseData {
11
12
  code: number;
@@ -42,22 +43,29 @@ export interface Overclock {
42
43
  core_lock: number | null;
43
44
  mem_lock: number | null;
44
45
  }
46
+ export interface Gpu {
47
+ type: string;
48
+ mem: number;
49
+ pcie_gen: number;
50
+ pcie_width: number;
51
+ }
45
52
  export interface Specs {
46
- backend_version: number;
53
+ mb: string;
47
54
  cpu: string;
48
55
  cpus: string;
49
- disk: string;
50
- disk_speed: number;
56
+ ram: number;
51
57
  gpu: string;
52
58
  gpuram: number;
53
- mb: string;
59
+ disk: string;
60
+ disk_speed: number;
54
61
  net: Net;
62
+ backend_version: number;
55
63
  pcie_rev: number;
56
64
  pcie_width: number;
65
+ xfs?: number;
66
+ stock_oc_override?: boolean;
57
67
  pl: number[];
58
- ram: number;
59
- stock_oc: Overclock[] | 'default';
60
- stock_oc_override: boolean;
68
+ gpus?: Gpu[];
61
69
  stock_pl: number[];
62
- xfs: number;
70
+ stock_oc: Overclock[] | 'default';
63
71
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cloreai",
3
- "version": "0.1.19",
3
+ "version": "1.0.0",
4
4
  "type": "module",
5
5
  "description": "CLORE.AI API client",
6
6
  "repository": {
@@ -22,28 +22,25 @@
22
22
  "clean": "rimraf build",
23
23
  "format": "prettier --check .",
24
24
  "lint": "eslint .",
25
- "playground": "jiti playground/index.ts",
26
25
  "prepack": "npm run clean && npm run build && npm run check",
27
26
  "prepare": "husky",
28
- "typecheck": "tsc --noEmit",
29
- "upgrade": "npm-check-updates --peer --upgrade && npm update"
27
+ "typecheck": "tsc --noEmit"
30
28
  },
31
29
  "dependencies": {
32
- "axios": "^1.7.9",
30
+ "axios": "^1.8.4",
33
31
  "p-queue": "^8.1.0"
34
32
  },
35
33
  "devDependencies": {
36
34
  "@tsconfig/node-lts": "^22.0.1",
37
35
  "@tsconfig/strictest": "^2.0.5",
38
- "@types/node": "^22.10.9",
39
- "eslint": "^9.18.0",
40
- "eslint-config-vladpuz": "^0.24.0",
36
+ "@types/node": "^22.13.17",
37
+ "eslint": "^9.23.0",
38
+ "eslint-config-vladpuz": "^1.1.0",
41
39
  "husky": "^9.1.7",
42
40
  "jiti": "^2.4.2",
43
- "npm-check-updates": "^17.1.14",
44
- "prettier": "^3.4.2",
45
- "prettier-config-vladpuz": "^0.9.0",
41
+ "prettier": "^3.5.3",
42
+ "prettier-config-vladpuz": "^1.0.0",
46
43
  "rimraf": "^6.0.1",
47
- "typescript": "^5.7.3"
44
+ "typescript": "^5.8.2"
48
45
  }
49
46
  }