cloreai 1.0.1 → 3.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.
Files changed (56) hide show
  1. package/README.md +78 -65
  2. package/build/{CloreAI.d.ts → Cloreai.d.ts} +26 -18
  3. package/build/{CloreAI.js → Cloreai.js} +41 -49
  4. package/build/CloreaiError.d.ts +12 -0
  5. package/build/CloreaiError.js +16 -0
  6. package/build/Gigaspot.d.ts +7 -7
  7. package/build/Gigaspot.js +10 -10
  8. package/build/constants.d.ts +20 -6
  9. package/build/constants.js +18 -4
  10. package/build/getQueueOptions.d.ts +3 -0
  11. package/build/getQueueOptions.js +8 -0
  12. package/build/index.d.ts +22 -20
  13. package/build/index.js +5 -4
  14. package/build/{endpoints → resources}/cancelOrder.d.ts +1 -1
  15. package/build/{endpoints → resources}/cancelOrders.d.ts +1 -1
  16. package/build/{endpoints → resources}/createGigaspotOrders.d.ts +4 -11
  17. package/build/{endpoints → resources}/createOrder.d.ts +5 -5
  18. package/build/resources/editGigaspotOrders.d.ts +12 -0
  19. package/build/{endpoints → resources}/getGigaspot.d.ts +8 -8
  20. package/build/{endpoints → resources}/marketplace.d.ts +4 -5
  21. package/build/{endpoints → resources}/myOrders.d.ts +6 -7
  22. package/build/resources/myServers.d.ts +16 -0
  23. package/build/{endpoints → resources}/pohBalance.d.ts +7 -7
  24. package/build/resources/renterFees.d.ts +22 -0
  25. package/build/{endpoints → resources}/serverConfig.d.ts +8 -5
  26. package/build/resources/setServerSettings.d.ts +18 -0
  27. package/build/resources/setSpotPrice.d.ts +15 -0
  28. package/build/{endpoints → resources}/spotMarketplace.d.ts +10 -10
  29. package/build/resources/spotMarketplace.js +1 -0
  30. package/build/{endpoints → resources}/wallets.d.ts +3 -3
  31. package/build/resources/wallets.js +1 -0
  32. package/build/types.d.ts +20 -25
  33. package/package.json +20 -20
  34. package/build/endpoints/editGigaspotOrders.d.ts +0 -19
  35. package/build/endpoints/myServers.d.ts +0 -15
  36. package/build/endpoints/setServerSettings.d.ts +0 -11
  37. package/build/endpoints/setSpotPrice.d.ts +0 -17
  38. package/build/endpoints/setSpotPrice.js +0 -2
  39. package/build/errors.d.ts +0 -22
  40. package/build/errors.js +0 -43
  41. package/build/helpers.d.ts +0 -19
  42. package/build/helpers.js +0 -29
  43. /package/build/{endpoints → resources}/cancelOrder.js +0 -0
  44. /package/build/{endpoints → resources}/cancelOrders.js +0 -0
  45. /package/build/{endpoints → resources}/createGigaspotOrders.js +0 -0
  46. /package/build/{endpoints → resources}/createOrder.js +0 -0
  47. /package/build/{endpoints → resources}/editGigaspotOrders.js +0 -0
  48. /package/build/{endpoints → resources}/getGigaspot.js +0 -0
  49. /package/build/{endpoints → resources}/marketplace.js +0 -0
  50. /package/build/{endpoints → resources}/myOrders.js +0 -0
  51. /package/build/{endpoints → resources}/myServers.js +0 -0
  52. /package/build/{endpoints → resources}/pohBalance.js +0 -0
  53. /package/build/{endpoints/serverConfig.js → resources/renterFees.js} +0 -0
  54. /package/build/{endpoints/setServerSettings.js → resources/serverConfig.js} +0 -0
  55. /package/build/{endpoints/spotMarketplace.js → resources/setServerSettings.js} +0 -0
  56. /package/build/{endpoints/wallets.js → resources/setSpotPrice.js} +0 -0
package/README.md CHANGED
@@ -2,37 +2,38 @@
2
2
 
3
3
  > CLORE.AI API client
4
4
 
5
- Особенности:
5
+ Features:
6
6
 
7
- - Базируется на [axios](https://github.com/axios/axios)
8
- - Защищает от превышения rate limit (ошибки 429) через
7
+ - Based on [axios](https://github.com/axios/axios)
8
+ - Protects from rate limit exceeded (429 errors) via
9
9
  [p-queue](https://github.com/sindresorhus/p-queue)
10
- - Поддерживает GigaSPOT
10
+ - User-friendly error handling
11
+ - Full typing
12
+ - Supports GigaSPOT
11
13
 
12
- Официальная документация: [clore.ai/api-docs](https://clore.ai/api-docs)
14
+ Official documentation: [clore.ai/api-docs](https://clore.ai/api-docs)
13
15
 
14
- Официальная документация GigaSPOT:
16
+ Official GigaSPOT documentation:
15
17
  [gigaspot-api-docs.clore.ai](https://gigaspot-api-docs.clore.ai)
16
18
 
17
- ## Установка
19
+ ## Installation
18
20
 
19
21
  ```shell
20
22
  npm install cloreai
21
23
  ```
22
24
 
23
- ## Использование
25
+ ## Usage
24
26
 
25
- ### Создание экземпляра
27
+ ### Creating an instance
26
28
 
27
29
  ```typescript
28
- import CloreAI from 'cloreai'
30
+ import Cloreai from 'cloreai'
29
31
 
30
- const cloreai = new CloreAI({
31
- apiKey: '<API_KEY>', // (required)
32
+ const cloreai = new Cloreai('API_KEY', {
32
33
  axiosOptions: {}, // (optional) Axios instance options https://github.com/axios/axios
33
34
  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
35
+ 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
36
37
  })
37
38
  ```
38
39
 
@@ -52,7 +53,7 @@ const myServers = await cloreai.myServers()
52
53
 
53
54
  ```typescript
54
55
  const serverConfig = await cloreai.serverConfig({
55
- server_name: 'server_name',
56
+ server_name: 'SERVER_NAME',
56
57
  })
57
58
  ```
58
59
 
@@ -81,13 +82,28 @@ const spotMarketplace = await cloreai.spotMarketplace({
81
82
 
82
83
  ```typescript
83
84
  await cloreai.setServerSettings({
84
- 'name': 'name', // Server name
85
+ 'name': 'NAME', // Server name
85
86
  'availability': true,
86
87
  'mrl': 24,
87
- 'on_demand': 50,
88
- 'spot': 50,
89
- 'CLORE-Blockchain_on_demand': 50,
90
- 'CLORE-Blockchain_spot': 50,
88
+ 'bitcoin_on_demand': 1,
89
+ 'bitcoin_spot': 1,
90
+ 'CLORE-Blockchain_on_demand': 1,
91
+ 'CLORE-Blockchain_spot': 1,
92
+ 'USD-Blockchain_on_demand': 1,
93
+ 'USD-Blockchain_spot': 1,
94
+ 'enabled-USD-Blockchain': true,
95
+ 'enabled-CLORE-Blockchain': true,
96
+ 'enabled-bitcoin': true,
97
+ 'autoprice': {
98
+ 'CLORE-Blockchain': 'usd',
99
+ 'USD-Blockchain': 'usd',
100
+ 'bitcoin': 'usd',
101
+ },
102
+ 'usd_pricing': {
103
+ 'CLORE-Blockchain': { on_demand: 1, spot: 1 },
104
+ 'USD-Blockchain': { on_demand: 1, spot: 1 },
105
+ 'bitcoin': { on_demand: 1, spot: 1 },
106
+ },
91
107
  })
92
108
  ```
93
109
 
@@ -119,8 +135,8 @@ await cloreai.createOrder({
119
135
  renting_server: 5738,
120
136
  ports: { 22: 'tcp', 8888: 'http' },
121
137
  env: { SSH_PASSWORD: 'SSH_PASSWORD', JUPYTER_TOKEN: 'JUPYTER_TOKEN' },
122
- jupyter_token: 'jupyter_token',
123
- ssh_password: 'ssh_password',
138
+ jupyter_token: 'JUPYTER_TOKEN',
139
+ ssh_password: 'SSH_PASSWORD',
124
140
  required_price: 50,
125
141
  remember_password: true,
126
142
  })
@@ -132,6 +148,12 @@ await cloreai.createOrder({
132
148
  const pohBalance = await cloreai.pohBalance()
133
149
  ```
134
150
 
151
+ ### 12. renter_fees
152
+
153
+ ```typescript
154
+ const renterFees = await cloreai.renterFees()
155
+ ```
156
+
135
157
  ### GigaSPOT
136
158
 
137
159
  #### getGigaspot
@@ -184,10 +206,10 @@ await cloreai.gigaspot.cancelOrders({
184
206
  })
185
207
  ```
186
208
 
187
- ### Конфигурация запросов
209
+ ### Request Configuration
188
210
 
189
- Каждый метод принимает опциональную конфигурацию запроса для axios последним
190
- параметром, например:
211
+ All methods accept an optional request configuration for axios as the last
212
+ parameter, for example:
191
213
 
192
214
  ```typescript
193
215
  const marketplace = await cloreai.marketplace({
@@ -195,50 +217,42 @@ const marketplace = await cloreai.marketplace({
195
217
  })
196
218
  ```
197
219
 
198
- ### Доступ к экземпляру axios
199
-
200
- Используйте поле `cloreai.axios`.
220
+ ### Access to axios instance
201
221
 
202
- Обратитесь к документации [axios](https://github.com/axios/axios).
222
+ Use the field `cloreai.axios`.
203
223
 
204
- ### Доступ к экземплярам p-queue
224
+ Refer to the documentation [axios](https://github.com/axios/axios).
205
225
 
206
- Используйте поля:
226
+ ### Access to p-queue instances
207
227
 
208
- - `cloreai.queue` - для основной очереди запросов
209
- - `cloreai.queueCreateOrder` - для очереди запросов createOrder
210
- - `cloreai.gigaspot.queue` - для очереди запросов gigaspot
228
+ Use the fields:
211
229
 
212
- Обратитесь к документации [p-queue](https://github.com/sindresorhus/p-queue).
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
213
233
 
214
- ### Обработка ошибок
234
+ Refer to the documentation [p-queue](https://github.com/sindresorhus/p-queue).
215
235
 
216
- Библиотека экспортирует следующие виды ошибок:
236
+ ### Error Handling
217
237
 
218
- - `DatabaseError`
219
- - `InvalidInputDataError`
220
- - `InvalidApiTokenError`
221
- - `InvalidEndpointError`
222
- - `ExceededError`
223
- - `OtherError`
224
- - `UnknownError`
238
+ Use the `CloreaiError` class for error handling.
225
239
 
226
- Все эти ошибки наследуются от `AxiosError`.
240
+ This class inherits from `AxiosError` and has additional fields with error
241
+ information `error.code` and `error.error`.
227
242
 
228
- Проверяйте тип ошибки через оператор `instanceof`:
243
+ To check the error type use the constant `statusCodes`.
229
244
 
230
245
  ```typescript
231
- import { AxiosError } from 'axios'
232
- import { ExceededError } from 'cloreai'
246
+ import { CloreaiError, statusCodes } from 'cloreai'
233
247
 
234
248
  try {
235
249
  const marketplace = await cloreai.marketplace()
236
250
  } catch (error) {
237
- if (error instanceof AxiosError) {
238
- console.log('AxiosError')
251
+ if (error instanceof CloreaiError) {
252
+ console.log(error.code, error.error)
239
253
 
240
- if (error instanceof ExceededError) {
241
- console.log('ExceededError')
254
+ if (error.code === statusCodes.EXCEEDED) {
255
+ console.log('Rate limit exceeded error')
242
256
  }
243
257
  } else {
244
258
  throw error
@@ -248,11 +262,11 @@ try {
248
262
 
249
263
  ### Rate limit
250
264
 
251
- Все методы защищены от превышения rate limit через
252
- [p-queue](https://github.com/sindresorhus/p-queue), они автоматически
253
- задерживаются на нужное время, чтобы избежать превышения лимита.
265
+ All methods are protected from rate limit exceeded via
266
+ [p-queue](https://github.com/sindresorhus/p-queue), they automatically delay for
267
+ the required time to avoid exceeding the limit.
254
268
 
255
- Значения rate limit по умолчанию доступны как константы:
269
+ Default rate limit values are available as constants:
256
270
 
257
271
  ```typescript
258
272
  import {
@@ -266,21 +280,20 @@ console.log(RATE_LIMIT_CREATE_ORDER)
266
280
  console.log(RATE_LIMIT_GIGASPOT)
267
281
  ```
268
282
 
269
- Можно задать собственные значение rate limit для каждой очереди запросов:
283
+ You can set custom rate limit values for each request queue:
270
284
 
271
285
  ```typescript
272
- import CloreAI from 'cloreai'
286
+ import Cloreai from 'cloreai'
273
287
 
274
- const cloreai = new CloreAI({
275
- apiKey: '<API_KEY>',
288
+ const cloreai = new Cloreai('API_KEY', {
276
289
  queueOptions: {
277
- interval: 10000, // 10 seconds
290
+ interval: 2000, // For example 2 seconds
278
291
  },
279
- queueOptionsCreateOrder: {
280
- interval: 10000, // 10 seconds
292
+ queueCreateOrderOptions: {
293
+ interval: 6000, // For example 6 seconds
281
294
  },
282
- queueOptionsGigaspot: {
283
- interval: 10000, // 10 seconds
295
+ queueGigaspotOptions: {
296
+ interval: 2000, // For example 2 seconds
284
297
  },
285
298
  })
286
299
  ```
@@ -1,24 +1,31 @@
1
- import { type AxiosInstance, type AxiosRequestConfig } from 'axios';
2
- import PQueue from 'p-queue';
3
- import type { CancelOrderRequestData, CancelOrderResponseData } from './endpoints/cancelOrder.js';
4
- import type { CreateOrderRequestData, CreateOrderResponseData } from './endpoints/createOrder.js';
5
- import type { MarketplaceResponseData } from './endpoints/marketplace.js';
6
- import type { MyOrdersRequestParams, MyOrdersResponseData } from './endpoints/myOrders.js';
7
- import type { MyServersResponseData } from './endpoints/myServers.js';
8
- import type { PohBalanceResponseData } from './endpoints/pohBalance.js';
9
- import type { ServerConfigRequestData, ServerConfigResponseData } from './endpoints/serverConfig.js';
10
- import type { SetServerSettingsRequestData, SetServerSettingsResponseData } from './endpoints/setServerSettings.js';
11
- import type { SetSpotPriceRequestData, SetSpotPriceResponseData } from './endpoints/setSpotPrice.js';
12
- import type { SpotMarketplaceRequestParams, SpotMarketplaceResponseData } from './endpoints/spotMarketplace.js';
13
- import type { WalletsResponseData } from './endpoints/wallets.js';
14
- import type { Config } from './types.js';
15
- import Gigaspot from './Gigaspot.js';
16
- declare class CloreAI {
1
+ import { type AxiosInstance, type AxiosRequestConfig, type CreateAxiosDefaults } from 'axios';
2
+ import PQueue, { type Options as PQueueOptions, type Queue, type QueueAddOptions } from 'p-queue';
3
+ import type { CancelOrderRequestData, CancelOrderResponseData } from './resources/cancelOrder.ts';
4
+ import type { CreateOrderRequestData, CreateOrderResponseData } from './resources/createOrder.ts';
5
+ import type { MarketplaceResponseData } from './resources/marketplace.ts';
6
+ import type { MyOrdersRequestParams, MyOrdersResponseData } from './resources/myOrders.ts';
7
+ import type { MyServersResponseData } from './resources/myServers.ts';
8
+ import type { PohBalanceResponseData } from './resources/pohBalance.ts';
9
+ import type { RenterFeesResponseData } from './resources/renterFees.ts';
10
+ import type { ServerConfigRequestData, ServerConfigResponseData } from './resources/serverConfig.ts';
11
+ import type { SetServerSettingsRequestData, SetServerSettingsResponseData } from './resources/setServerSettings.ts';
12
+ import type { SetSpotPriceRequestData, SetSpotPriceResponseData } from './resources/setSpotPrice.ts';
13
+ import type { SpotMarketplaceRequestParams, SpotMarketplaceResponseData } from './resources/spotMarketplace.ts';
14
+ import type { WalletsResponseData } from './resources/wallets.ts';
15
+ import Gigaspot from './Gigaspot.ts';
16
+ export type QueueOptions = PQueueOptions<Queue<() => Promise<unknown>, QueueAddOptions>, QueueAddOptions>;
17
+ export interface Options {
18
+ axiosOptions?: CreateAxiosDefaults;
19
+ queueOptions?: QueueOptions;
20
+ queueCreateOrderOptions?: QueueOptions;
21
+ queueGigaspotOptions?: QueueOptions;
22
+ }
23
+ declare class Cloreai {
17
24
  axios: AxiosInstance;
18
25
  queue: PQueue;
19
26
  queueCreateOrder: PQueue;
20
27
  gigaspot: Gigaspot;
21
- constructor(config: Config);
28
+ constructor(apiKey: string, options?: Options);
22
29
  wallets(config?: AxiosRequestConfig): Promise<WalletsResponseData>;
23
30
  myServers(config?: AxiosRequestConfig): Promise<MyServersResponseData>;
24
31
  serverConfig(data: ServerConfigRequestData, config?: AxiosRequestConfig): Promise<ServerConfigResponseData>;
@@ -30,5 +37,6 @@ declare class CloreAI {
30
37
  cancelOrder(data: CancelOrderRequestData, config?: AxiosRequestConfig): Promise<CancelOrderResponseData>;
31
38
  createOrder(data: CreateOrderRequestData, config?: AxiosRequestConfig): Promise<CreateOrderResponseData>;
32
39
  pohBalance(config?: AxiosRequestConfig): Promise<PohBalanceResponseData>;
40
+ renterFees(config?: AxiosRequestConfig): Promise<RenterFeesResponseData>;
33
41
  }
34
- export default CloreAI;
42
+ export default Cloreai;
@@ -1,133 +1,125 @@
1
- import axios from 'axios';
2
- import PQueue from 'p-queue';
3
- import { RATE_LIMIT, RATE_LIMIT_CREATE_ORDER } from './constants.js';
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';
7
- class CloreAI {
1
+ import axios, {} from 'axios';
2
+ import PQueue, {} from 'p-queue';
3
+ import { CloreaiError } from "./CloreaiError.js";
4
+ import { priorityLevels, RATE_LIMIT, RATE_LIMIT_CREATE_ORDER, statusCodes } from "./constants.js";
5
+ import { getQueueOptions } from "./getQueueOptions.js";
6
+ import Gigaspot from "./Gigaspot.js";
7
+ class Cloreai {
8
8
  axios;
9
9
  queue;
10
10
  queueCreateOrder;
11
11
  gigaspot;
12
- constructor(config) {
12
+ constructor(apiKey, options = {}) {
13
13
  this.queue = new PQueue({
14
14
  interval: RATE_LIMIT,
15
15
  intervalCap: 1,
16
16
  concurrency: 1,
17
- ...config.queueOptions,
17
+ ...options.queueOptions,
18
18
  });
19
19
  this.queueCreateOrder = new PQueue({
20
20
  interval: RATE_LIMIT_CREATE_ORDER,
21
21
  intervalCap: 1,
22
22
  concurrency: 1,
23
- ...config.queueOptionsCreateOrder,
23
+ ...options.queueCreateOrderOptions,
24
24
  });
25
25
  this.axios = axios.create({
26
- ...config.axiosOptions,
27
26
  baseURL: 'https://api.clore.ai/v1',
27
+ ...options.axiosOptions,
28
28
  });
29
29
  this.axios.interceptors.request.use((request) => {
30
- request.headers.set('auth', config.apiKey);
30
+ request.headers.set('auth', apiKey);
31
31
  return request;
32
32
  });
33
33
  this.axios.interceptors.response.use((response) => {
34
34
  if (response.data.code === statusCodes.NORMAL) {
35
35
  return response;
36
36
  }
37
- const errorMessage = response.data.error != null
38
- ? `Code "${response.data.code}", error "${response.data.error}"`
39
- : `Code "${response.data.code}"`;
40
- const axiosErrorParameters = [
41
- errorMessage,
42
- undefined,
43
- response.config,
44
- response.request,
37
+ const errorMessage = `Code "${response.data.code}"`;
38
+ const error = new CloreaiError(errorMessage, {
39
+ code: String(response.data.code),
40
+ config: response.config,
41
+ request: response.request,
45
42
  response,
46
- ];
47
- switch (response.data.code) {
48
- case statusCodes.DATABASE_ERROR:
49
- throw new DatabaseError(...axiosErrorParameters);
50
- case statusCodes.INVALID_INPUT_DATA:
51
- throw new InvalidInputDataError(...axiosErrorParameters);
52
- case statusCodes.INVALID_API_TOKEN:
53
- throw new InvalidApiTokenError(...axiosErrorParameters);
54
- case statusCodes.INVALID_ENDPOINT:
55
- throw new InvalidEndpointError(...axiosErrorParameters);
56
- case statusCodes.EXCEEDED:
57
- throw new ExceededError(...axiosErrorParameters);
58
- case statusCodes.OTHER:
59
- throw new OtherError(...axiosErrorParameters);
60
- default:
61
- throw new UnknownError(...axiosErrorParameters);
43
+ });
44
+ if (response.data.error != null) {
45
+ error.message += `, error "${response.data.error}"`;
46
+ error.error = response.data.error;
62
47
  }
48
+ throw error;
63
49
  });
64
- this.gigaspot = new Gigaspot(config, this.axios);
50
+ this.gigaspot = new Gigaspot(options, this.axios);
65
51
  }
66
52
  async wallets(config) {
67
53
  const response = await this.queue.add(async () => {
68
54
  return await this.axios.get('/wallets', config);
69
- }, getQueueOptions(priorityLevels.NORMAL, config));
55
+ }, getQueueOptions(priorityLevels.NORMAL, this.axios, config));
70
56
  return response.data;
71
57
  }
72
58
  async myServers(config) {
73
59
  const response = await this.queue.add(async () => {
74
60
  return await this.axios.get('/my_servers', config);
75
- }, getQueueOptions(priorityLevels.NORMAL, config));
61
+ }, getQueueOptions(priorityLevels.NORMAL, this.axios, config));
76
62
  return response.data;
77
63
  }
78
64
  async serverConfig(data, config) {
79
65
  const response = await this.queue.add(async () => {
80
66
  return await this.axios.get('/server_config', { ...config, data });
81
- }, getQueueOptions(priorityLevels.NORMAL, config));
67
+ }, getQueueOptions(priorityLevels.NORMAL, this.axios, config));
82
68
  return response.data;
83
69
  }
84
70
  async marketplace(config) {
85
71
  const response = await this.queue.add(async () => {
86
72
  return await this.axios.get('/marketplace', config);
87
- }, getQueueOptions(priorityLevels.NORMAL, config));
73
+ }, getQueueOptions(priorityLevels.NORMAL, this.axios, config));
88
74
  return response.data;
89
75
  }
90
76
  async myOrders(params, config) {
91
77
  const response = await this.queue.add(async () => {
92
78
  return await this.axios.get('/my_orders', { ...config, params });
93
- }, getQueueOptions(priorityLevels.NORMAL, config));
79
+ }, getQueueOptions(priorityLevels.NORMAL, this.axios, config));
94
80
  return response.data;
95
81
  }
96
82
  async spotMarketplace(params, config) {
97
83
  const response = await this.queue.add(async () => {
98
84
  return await this.axios.get('/spot_marketplace', { ...config, params });
99
- }, getQueueOptions(priorityLevels.NORMAL, config));
85
+ }, getQueueOptions(priorityLevels.NORMAL, this.axios, config));
100
86
  return response.data;
101
87
  }
102
88
  async setServerSettings(data, config) {
103
89
  const response = await this.queue.add(async () => {
104
90
  return await this.axios.post('/set_server_settings', data, config);
105
- }, getQueueOptions(priorityLevels.HIGH, config));
91
+ }, getQueueOptions(priorityLevels.HIGH, this.axios, config));
106
92
  return response.data;
107
93
  }
108
94
  async setSpotPrice(data, config) {
109
95
  const response = await this.queue.add(async () => {
110
96
  return await this.axios.post('/set_spot_price', data, config);
111
- }, getQueueOptions(priorityLevels.HIGH, config));
97
+ }, getQueueOptions(priorityLevels.HIGH, this.axios, config));
112
98
  return response.data;
113
99
  }
114
100
  async cancelOrder(data, config) {
115
101
  const response = await this.queue.add(async () => {
116
102
  return await this.axios.post('/cancel_order', data, config);
117
- }, getQueueOptions(priorityLevels.HIGH, config));
103
+ }, getQueueOptions(priorityLevels.HIGH, this.axios, config));
118
104
  return response.data;
119
105
  }
120
106
  async createOrder(data, config) {
121
107
  const response = await this.queueCreateOrder.add(async () => {
122
108
  return await this.axios.post('/create_order', data, config);
123
- }, getQueueOptions(priorityLevels.HIGHEST, config));
109
+ }, getQueueOptions(priorityLevels.HIGHEST, this.axios, config));
124
110
  return response.data;
125
111
  }
126
112
  async pohBalance(config) {
127
113
  const response = await this.queue.add(async () => {
128
114
  return await this.axios.get('/poh_balance', config);
129
- }, getQueueOptions(priorityLevels.NORMAL, config));
115
+ }, getQueueOptions(priorityLevels.NORMAL, this.axios, config));
116
+ return response.data;
117
+ }
118
+ async renterFees(config) {
119
+ const response = await this.queue.add(async () => {
120
+ return await this.axios.get('/renter_fees', config);
121
+ }, getQueueOptions(priorityLevels.NORMAL, this.axios, config));
130
122
  return response.data;
131
123
  }
132
124
  }
133
- export default CloreAI;
125
+ export default Cloreai;
@@ -0,0 +1,12 @@
1
+ import { AxiosError, type AxiosResponse, type InternalAxiosRequestConfig } from 'axios';
2
+ export interface CloreaiErrorOptions<T = unknown, D = unknown> extends ErrorOptions {
3
+ code?: string;
4
+ config?: InternalAxiosRequestConfig<D>;
5
+ request?: unknown;
6
+ response?: AxiosResponse<T, D>;
7
+ error?: string;
8
+ }
9
+ export declare class CloreaiError<T = unknown, D = unknown> extends AxiosError<T, D> {
10
+ error?: string;
11
+ constructor(message?: string, options?: CloreaiErrorOptions<T, D>);
12
+ }
@@ -0,0 +1,16 @@
1
+ import { AxiosError } from 'axios';
2
+ export class CloreaiError extends AxiosError {
3
+ error;
4
+ constructor(message, options = {}) {
5
+ super(message, options.code, options.config, options.request, options.response);
6
+ this.name = 'CloreaiError';
7
+ if (options.cause != null) {
8
+ this.cause = (options.cause instanceof Error)
9
+ ? options.cause
10
+ : new Error(String(options.cause));
11
+ }
12
+ if (options.error != null) {
13
+ this.error = options.error;
14
+ }
15
+ }
16
+ }
@@ -1,14 +1,14 @@
1
1
  import { type AxiosInstance, type AxiosRequestConfig } from 'axios';
2
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';
3
+ import type { Options } from './Cloreai.ts';
4
+ import type { CancelOrdersRequestData, CancelOrdersResponseData } from './resources/cancelOrders.ts';
5
+ import type { CreateGigaspotOrdersRequestData, CreateGigaspotOrdersResponseData } from './resources/createGigaspotOrders.ts';
6
+ import type { EditGigaspotOrdersRequestData, EditGigaspotOrdersResponseData } from './resources/editGigaspotOrders.ts';
7
+ import type { GetGigaspotResponseData } from './resources/getGigaspot.ts';
8
8
  declare class Gigaspot {
9
+ axios: AxiosInstance;
9
10
  queue: PQueue;
10
- private readonly axios;
11
- constructor(config: Config, axios: AxiosInstance);
11
+ constructor(options: Options, axios: AxiosInstance);
12
12
  getGigaspot(config?: AxiosRequestConfig): Promise<GetGigaspotResponseData>;
13
13
  createGigaspotOrders(data: CreateGigaspotOrdersRequestData, config?: AxiosRequestConfig): Promise<CreateGigaspotOrdersResponseData>;
14
14
  editGigaspotOrders(data: EditGigaspotOrdersRequestData, config?: AxiosRequestConfig): Promise<EditGigaspotOrdersResponseData>;
package/build/Gigaspot.js CHANGED
@@ -1,16 +1,16 @@
1
- import axios from 'axios';
1
+ import axios, {} from 'axios';
2
2
  import PQueue from 'p-queue';
3
- import { RATE_LIMIT_GIGASPOT } from './constants.js';
4
- import { getQueueOptions, priorityLevels } from './helpers.js';
3
+ import { priorityLevels, RATE_LIMIT_GIGASPOT } from "./constants.js";
4
+ import { getQueueOptions } from "./getQueueOptions.js";
5
5
  class Gigaspot {
6
- queue;
7
6
  axios;
8
- constructor(config, axios) {
7
+ queue;
8
+ constructor(options, axios) {
9
9
  this.queue = new PQueue({
10
10
  interval: RATE_LIMIT_GIGASPOT,
11
11
  intervalCap: 1,
12
12
  concurrency: 1,
13
- ...config.queueOptionsGigaspot,
13
+ ...options.queueGigaspotOptions,
14
14
  });
15
15
  this.axios = axios;
16
16
  }
@@ -22,24 +22,24 @@ class Gigaspot {
22
22
  ...response.data,
23
23
  snapshot: snapshot.data,
24
24
  };
25
- }, getQueueOptions(priorityLevels.NORMAL, config));
25
+ }, getQueueOptions(priorityLevels.NORMAL, this.axios, config));
26
26
  }
27
27
  async createGigaspotOrders(data, config) {
28
28
  const response = await this.queue.add(async () => {
29
29
  return await this.axios.post('/create_gigaspot_orders', data, config);
30
- }, getQueueOptions(priorityLevels.HIGH, config));
30
+ }, getQueueOptions(priorityLevels.HIGH, this.axios, config));
31
31
  return response.data;
32
32
  }
33
33
  async editGigaspotOrders(data, config) {
34
34
  const response = await this.queue.add(async () => {
35
35
  return await this.axios.post('/edit_gigaspot_orders', data, config);
36
- }, getQueueOptions(priorityLevels.HIGH, config));
36
+ }, getQueueOptions(priorityLevels.HIGH, this.axios, config));
37
37
  return response.data;
38
38
  }
39
39
  async cancelOrders(data, config) {
40
40
  const response = await this.queue.add(async () => {
41
41
  return await this.axios.post('/cancel_orders', data, config);
42
- }, getQueueOptions(priorityLevels.HIGH, config));
42
+ }, getQueueOptions(priorityLevels.HIGH, this.axios, config));
43
43
  return response.data;
44
44
  }
45
45
  }
@@ -1,7 +1,21 @@
1
- export declare const RATE_LIMIT = 1800;
1
+ export declare const RATE_LIMIT = 1000;
2
2
  export declare const RATE_LIMIT_CREATE_ORDER = 5000;
3
- export declare const RATE_LIMIT_GIGASPOT = 1800;
4
- export declare const gigaspotBaseImages: {
5
- UBUNTU: string;
6
- HIVEOS: string;
7
- };
3
+ export declare const RATE_LIMIT_GIGASPOT = 1000;
4
+ export declare const gigaspotBaseImages: Readonly<{
5
+ UBUNTU: "a3f9c4d7e5b088d8a0bff880";
6
+ HIVEOS: "c9a4e2f6b7d488d8f0bab0ff";
7
+ }>;
8
+ export declare const statusCodes: Readonly<{
9
+ NORMAL: 0;
10
+ DATABASE_ERROR: 1;
11
+ INVALID_INPUT_DATA: 2;
12
+ INVALID_API_TOKEN: 3;
13
+ INVALID_ENDPOINT: 4;
14
+ EXCEEDED: 5;
15
+ CUSTOM: 6;
16
+ }>;
17
+ export declare const priorityLevels: Readonly<{
18
+ NORMAL: 0;
19
+ HIGH: 1;
20
+ HIGHEST: 2;
21
+ }>;
@@ -1,7 +1,21 @@
1
- export const RATE_LIMIT = 1800;
1
+ export const RATE_LIMIT = 1000;
2
2
  export const RATE_LIMIT_CREATE_ORDER = 5000;
3
- export const RATE_LIMIT_GIGASPOT = 1800;
4
- export const gigaspotBaseImages = {
3
+ export const RATE_LIMIT_GIGASPOT = 1000;
4
+ export const gigaspotBaseImages = Object.freeze({
5
5
  UBUNTU: 'a3f9c4d7e5b088d8a0bff880',
6
6
  HIVEOS: 'c9a4e2f6b7d488d8f0bab0ff',
7
- };
7
+ });
8
+ export const statusCodes = Object.freeze({
9
+ NORMAL: 0,
10
+ DATABASE_ERROR: 1,
11
+ INVALID_INPUT_DATA: 2,
12
+ INVALID_API_TOKEN: 3,
13
+ INVALID_ENDPOINT: 4,
14
+ EXCEEDED: 5,
15
+ CUSTOM: 6,
16
+ });
17
+ export const priorityLevels = Object.freeze({
18
+ NORMAL: 0,
19
+ HIGH: 1,
20
+ HIGHEST: 2,
21
+ });
@@ -0,0 +1,3 @@
1
+ import type { AxiosInstance, AxiosRequestConfig } from 'axios';
2
+ import type { QueueAddOptions } from 'p-queue';
3
+ export declare function getQueueOptions(priority: number, axios: AxiosInstance, config?: AxiosRequestConfig): QueueAddOptions;