cloreai 0.1.10 → 0.1.11

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.
@@ -1,6 +1,7 @@
1
- import type { Currency } from '../../common/index.js';
1
+ import type { Currency, OrderType } from '../../common/index.js';
2
2
  import type { Output } from '../types.js';
3
3
  export interface CreateOrderCommon {
4
+ type: OrderType;
4
5
  currency: Currency;
5
6
  image: string;
6
7
  renting_server: number;
@@ -9,13 +9,14 @@ import type { SetSpotPriceBody, SetSpotPriceOutput } from './endpoints/setSpotPr
9
9
  import type { Config } from './types.js';
10
10
  declare class WebAPI {
11
11
  readonly axios: AxiosInstance;
12
+ readonly rateLimitQueue: PQueue;
12
13
  readonly rateLimitCreateOrderQueue: PQueue;
13
14
  constructor(config: Config);
14
- servers(axiosConfig?: AxiosRequestConfig): Promise<ServersOutput>;
15
- orders(body: OrdersBody, axiosConfig?: AxiosRequestConfig<OrdersBody>): Promise<OrdersOutput>;
16
- getSpot(body: GetSpotBody, axiosConfig?: AxiosRequestConfig<GetSpotBody>): Promise<GetSpotOutput>;
17
- setSpotPrice(body: SetSpotPriceBody, axiosConfig?: AxiosRequestConfig<SetSpotPriceBody>): Promise<SetSpotPriceOutput>;
18
- cancelOrder(body: CancelOrderBody, axiosConfig?: AxiosRequestConfig<CancelOrderBody>): Promise<CancelOrderOutput>;
15
+ servers(axiosConfig?: AxiosRequestConfig, queueOptions?: QueueAddOptions): Promise<ServersOutput>;
16
+ orders(body: OrdersBody, axiosConfig?: AxiosRequestConfig<OrdersBody>, queueOptions?: QueueAddOptions): Promise<OrdersOutput>;
17
+ getSpot(body: GetSpotBody, axiosConfig?: AxiosRequestConfig<GetSpotBody>, queueOptions?: QueueAddOptions): Promise<GetSpotOutput>;
18
+ setSpotPrice(body: SetSpotPriceBody, axiosConfig?: AxiosRequestConfig<SetSpotPriceBody>, queueOptions?: QueueAddOptions): Promise<SetSpotPriceOutput>;
19
+ cancelOrder(body: CancelOrderBody, axiosConfig?: AxiosRequestConfig<CancelOrderBody>, queueOptions?: QueueAddOptions): Promise<CancelOrderOutput>;
19
20
  createOrder(body: CreateOrderBody, axiosConfig?: AxiosRequestConfig<CreateOrderBody>, queueOptions?: QueueAddOptions): Promise<CreateOrderOutput>;
20
21
  }
21
22
  export default WebAPI;
@@ -1,9 +1,14 @@
1
1
  import axios from 'axios';
2
2
  import PQueue from 'p-queue';
3
3
  import { UnknownError } from '../common/errors.js';
4
- import { getErrorMessage, RATE_LIMIT_CREATE_ORDER } from '../common/index.js';
4
+ import { getErrorMessage, RATE_LIMIT, RATE_LIMIT_CREATE_ORDER } from '../common/index.js';
5
5
  class WebAPI {
6
6
  axios;
7
+ rateLimitQueue = new PQueue({
8
+ interval: RATE_LIMIT,
9
+ intervalCap: 1,
10
+ concurrency: 1,
11
+ });
7
12
  rateLimitCreateOrderQueue = new PQueue({
8
13
  interval: RATE_LIMIT_CREATE_ORDER,
9
14
  intervalCap: 1,
@@ -31,29 +36,49 @@ class WebAPI {
31
36
  throw new UnknownError(errorMessage, undefined, response.config, response.request, response);
32
37
  });
33
38
  }
34
- async servers(axiosConfig) {
35
- const response = await this.axios.post('/marketplace/servers', null, axiosConfig);
39
+ async servers(axiosConfig, queueOptions) {
40
+ const response = await this.rateLimitQueue.add(async () => {
41
+ return await this.axios.post('/marketplace/servers', null, axiosConfig);
42
+ }, { ...queueOptions, throwOnTimeout: true });
36
43
  return response.data;
37
44
  }
38
- async orders(body, axiosConfig) {
39
- const response = await this.axios.post('/marketplace/orders', body, axiosConfig);
45
+ async orders(body, axiosConfig, queueOptions) {
46
+ const response = await this.rateLimitQueue.add(async () => {
47
+ return await this.axios.post('/marketplace/orders', body, axiosConfig);
48
+ }, { ...queueOptions, throwOnTimeout: true });
40
49
  return response.data;
41
50
  }
42
- async getSpot(body, axiosConfig) {
43
- const response = await this.axios.post('/marketplace/get_spot', body, axiosConfig);
51
+ async getSpot(body, axiosConfig, queueOptions) {
52
+ const response = await this.rateLimitQueue.add(async () => {
53
+ return await this.axios.post('/marketplace/get_spot', body, axiosConfig);
54
+ }, { ...queueOptions, throwOnTimeout: true });
44
55
  return response.data;
45
56
  }
46
- async setSpotPrice(body, axiosConfig) {
47
- const response = await this.axios.post('/marketplace/set_spot_price', body, axiosConfig);
57
+ async setSpotPrice(body, axiosConfig, queueOptions) {
58
+ const response = await this.rateLimitQueue.add(async () => {
59
+ return await this.axios.post('/marketplace/set_spot_price', body, axiosConfig);
60
+ }, { ...queueOptions, throwOnTimeout: true });
48
61
  return response.data;
49
62
  }
50
- async cancelOrder(body, axiosConfig) {
51
- const response = await this.axios.post('/marketplace/cancel_order', body, axiosConfig);
63
+ async cancelOrder(body, axiosConfig, queueOptions) {
64
+ const response = await this.rateLimitQueue.add(async () => {
65
+ return await this.axios.post('/marketplace/cancel_order', body, axiosConfig);
66
+ }, { ...queueOptions, throwOnTimeout: true });
52
67
  return response.data;
53
68
  }
54
69
  async createOrder(body, axiosConfig, queueOptions) {
55
- const response = await this.rateLimitCreateOrderQueue.add(async () => {
56
- return await this.axios.post('/create_order', body, axiosConfig);
70
+ const response = await this.rateLimitQueue.add(async () => {
71
+ this.rateLimitQueue.pause();
72
+ try {
73
+ return await this.rateLimitCreateOrderQueue.add(async () => {
74
+ return await this.axios.post('/create_order', body, axiosConfig);
75
+ }, { ...queueOptions, throwOnTimeout: true });
76
+ }
77
+ finally {
78
+ setTimeout(() => {
79
+ this.rateLimitQueue.start();
80
+ }, RATE_LIMIT);
81
+ }
57
82
  }, { ...queueOptions, throwOnTimeout: true });
58
83
  return response.data;
59
84
  }
@@ -1,6 +1,7 @@
1
- import type { Currency } from '../../common/index.js';
1
+ import type { Currency, OrderType } from '../../common/index.js';
2
2
  import type { Output } from '../types.js';
3
3
  export interface CreateOrderCommon {
4
+ type: OrderType;
4
5
  currency: Currency;
5
6
  image: string;
6
7
  renting_server: number;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cloreai",
3
- "version": "0.1.10",
3
+ "version": "0.1.11",
4
4
  "type": "module",
5
5
  "description": "CLORE.AI API client",
6
6
  "repository": {