cloreai 0.1.9 → 0.1.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/cloreai/CloreAI.d.ts +15 -11
- package/build/cloreai/CloreAI.js +64 -22
- package/build/cloreai/index.d.ts +2 -1
- package/build/cloreai/index.js +2 -1
- package/build/common/constants.d.ts +2 -2
- package/build/common/constants.js +2 -2
- package/build/webapi/WebAPI.d.ts +10 -7
- package/build/webapi/WebAPI.js +23 -14
- package/build/webapi/index.d.ts +2 -1
- package/build/webapi/index.js +2 -1
- package/package.json +10 -8
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { type AxiosInstance, type AxiosRequestConfig } from 'axios';
|
|
2
|
+
import PQueue, { type QueueAddOptions } from 'p-queue';
|
|
2
3
|
import type { CancelOrderBody, CancelOrderOutput } from './endpoints/cancelOrder.js';
|
|
3
4
|
import type { CreateOrderBody, CreateOrderOutput } from './endpoints/createOrder.js';
|
|
4
5
|
import type { MarketplaceOutput } from './endpoints/marketplace.js';
|
|
@@ -10,17 +11,20 @@ import type { SetSpotPriceBody, SetSpotPriceOutput } from './endpoints/setSpotPr
|
|
|
10
11
|
import type { SpotMarketplaceOutput, SpotMarketplaceParams } from './endpoints/spotMarketplace.js';
|
|
11
12
|
import type { WalletsOutput } from './endpoints/wallets.js';
|
|
12
13
|
import type { Config } from './types.js';
|
|
13
|
-
|
|
14
|
+
declare class CloreAI {
|
|
14
15
|
readonly axios: AxiosInstance;
|
|
16
|
+
readonly rateLimitQueue: PQueue;
|
|
17
|
+
readonly rateLimitCreateOrderQueue: PQueue;
|
|
15
18
|
constructor(config: Config);
|
|
16
|
-
wallets(
|
|
17
|
-
myServers(
|
|
18
|
-
serverConfig(body: ServerConfigBody,
|
|
19
|
-
marketplace(
|
|
20
|
-
myOrders(params?: MyOrdersParams,
|
|
21
|
-
spotMarketplace(params: SpotMarketplaceParams,
|
|
22
|
-
setServerSettings(body: SetServerSettingsBody,
|
|
23
|
-
setSpotPrice(body: SetSpotPriceBody,
|
|
24
|
-
cancelOrder(body: CancelOrderBody,
|
|
25
|
-
createOrder(body: CreateOrderBody,
|
|
19
|
+
wallets(axiosConfig?: AxiosRequestConfig, queueOptions?: QueueAddOptions): Promise<WalletsOutput>;
|
|
20
|
+
myServers(axiosConfig?: AxiosRequestConfig, queueOptions?: QueueAddOptions): Promise<MyServersOutput>;
|
|
21
|
+
serverConfig(body: ServerConfigBody, axiosConfig?: AxiosRequestConfig<ServerConfigBody>, queueOptions?: QueueAddOptions): Promise<ServerConfigOutput>;
|
|
22
|
+
marketplace(axiosConfig?: AxiosRequestConfig, queueOptions?: QueueAddOptions): Promise<MarketplaceOutput>;
|
|
23
|
+
myOrders(params?: MyOrdersParams, axiosConfig?: AxiosRequestConfig, queueOptions?: QueueAddOptions): Promise<MyOrdersOutput>;
|
|
24
|
+
spotMarketplace(params: SpotMarketplaceParams, axiosConfig?: AxiosRequestConfig, queueOptions?: QueueAddOptions): Promise<SpotMarketplaceOutput>;
|
|
25
|
+
setServerSettings(body: SetServerSettingsBody, axiosConfig?: AxiosRequestConfig<SetServerSettingsBody>, queueOptions?: QueueAddOptions): Promise<SetServerSettingsOutput>;
|
|
26
|
+
setSpotPrice(body: SetSpotPriceBody, axiosConfig?: AxiosRequestConfig<SetSpotPriceBody>, queueOptions?: QueueAddOptions): Promise<SetSpotPriceOutput>;
|
|
27
|
+
cancelOrder(body: CancelOrderBody, axiosConfig?: AxiosRequestConfig<CancelOrderBody>, queueOptions?: QueueAddOptions): Promise<CancelOrderOutput>;
|
|
28
|
+
createOrder(body: CreateOrderBody, axiosConfig?: AxiosRequestConfig<CreateOrderBody>, queueOptions?: QueueAddOptions): Promise<CreateOrderOutput>;
|
|
26
29
|
}
|
|
30
|
+
export default CloreAI;
|
package/build/cloreai/CloreAI.js
CHANGED
|
@@ -1,8 +1,19 @@
|
|
|
1
1
|
import axios from 'axios';
|
|
2
|
+
import PQueue from 'p-queue';
|
|
2
3
|
import { CustomError, DatabaseError, ExceededError, InvalidApiTokenError, InvalidEndpointError, InvalidInputDataError, UnknownError } from '../common/errors.js';
|
|
3
|
-
import { getErrorMessage, statusCodes } from '../common/index.js';
|
|
4
|
-
|
|
4
|
+
import { getErrorMessage, RATE_LIMIT, RATE_LIMIT_CREATE_ORDER, statusCodes } from '../common/index.js';
|
|
5
|
+
class CloreAI {
|
|
5
6
|
axios;
|
|
7
|
+
rateLimitQueue = new PQueue({
|
|
8
|
+
interval: RATE_LIMIT,
|
|
9
|
+
intervalCap: 1,
|
|
10
|
+
concurrency: 1,
|
|
11
|
+
});
|
|
12
|
+
rateLimitCreateOrderQueue = new PQueue({
|
|
13
|
+
interval: RATE_LIMIT_CREATE_ORDER,
|
|
14
|
+
intervalCap: 1,
|
|
15
|
+
concurrency: 1,
|
|
16
|
+
});
|
|
6
17
|
constructor(config) {
|
|
7
18
|
const { apiKey, axiosConfig = {} } = config;
|
|
8
19
|
this.axios = axios.create({
|
|
@@ -43,44 +54,75 @@ export class CloreAI {
|
|
|
43
54
|
}
|
|
44
55
|
});
|
|
45
56
|
}
|
|
46
|
-
async wallets(
|
|
47
|
-
const response = await this.
|
|
57
|
+
async wallets(axiosConfig, queueOptions) {
|
|
58
|
+
const response = await this.rateLimitQueue.add(async () => {
|
|
59
|
+
return await this.axios.get('/wallets', axiosConfig);
|
|
60
|
+
}, { ...queueOptions, throwOnTimeout: true });
|
|
48
61
|
return response.data;
|
|
49
62
|
}
|
|
50
|
-
async myServers(
|
|
51
|
-
const response = await this.
|
|
63
|
+
async myServers(axiosConfig, queueOptions) {
|
|
64
|
+
const response = await this.rateLimitQueue.add(async () => {
|
|
65
|
+
return await this.axios.get('/my_servers', axiosConfig);
|
|
66
|
+
}, { ...queueOptions, throwOnTimeout: true });
|
|
52
67
|
return response.data;
|
|
53
68
|
}
|
|
54
|
-
async serverConfig(body,
|
|
55
|
-
const response = await this.
|
|
69
|
+
async serverConfig(body, axiosConfig, queueOptions) {
|
|
70
|
+
const response = await this.rateLimitQueue.add(async () => {
|
|
71
|
+
return await this.axios.get('/server_config', { ...axiosConfig, data: body });
|
|
72
|
+
}, { ...queueOptions, throwOnTimeout: true });
|
|
56
73
|
return response.data;
|
|
57
74
|
}
|
|
58
|
-
async marketplace(
|
|
59
|
-
const response = await this.
|
|
75
|
+
async marketplace(axiosConfig, queueOptions) {
|
|
76
|
+
const response = await this.rateLimitQueue.add(async () => {
|
|
77
|
+
return await this.axios.get('/marketplace', axiosConfig);
|
|
78
|
+
}, { ...queueOptions, throwOnTimeout: true });
|
|
60
79
|
return response.data;
|
|
61
80
|
}
|
|
62
|
-
async myOrders(params,
|
|
63
|
-
const response = await this.
|
|
81
|
+
async myOrders(params, axiosConfig, queueOptions) {
|
|
82
|
+
const response = await this.rateLimitQueue.add(async () => {
|
|
83
|
+
return await this.axios.get('/my_orders', { ...axiosConfig, params });
|
|
84
|
+
}, { ...queueOptions, throwOnTimeout: true });
|
|
64
85
|
return response.data;
|
|
65
86
|
}
|
|
66
|
-
async spotMarketplace(params,
|
|
67
|
-
const response = await this.
|
|
87
|
+
async spotMarketplace(params, axiosConfig, queueOptions) {
|
|
88
|
+
const response = await this.rateLimitQueue.add(async () => {
|
|
89
|
+
return await this.axios.get('/spot_marketplace', { ...axiosConfig, params });
|
|
90
|
+
}, { ...queueOptions, throwOnTimeout: true });
|
|
68
91
|
return response.data;
|
|
69
92
|
}
|
|
70
|
-
async setServerSettings(body,
|
|
71
|
-
const response = await this.
|
|
93
|
+
async setServerSettings(body, axiosConfig, queueOptions) {
|
|
94
|
+
const response = await this.rateLimitQueue.add(async () => {
|
|
95
|
+
return await this.axios.post('/set_server_settings', body, axiosConfig);
|
|
96
|
+
}, { ...queueOptions, throwOnTimeout: true });
|
|
72
97
|
return response.data;
|
|
73
98
|
}
|
|
74
|
-
async setSpotPrice(body,
|
|
75
|
-
const response = await this.
|
|
99
|
+
async setSpotPrice(body, axiosConfig, queueOptions) {
|
|
100
|
+
const response = await this.rateLimitQueue.add(async () => {
|
|
101
|
+
return await this.axios.post('/set_spot_price', body, axiosConfig);
|
|
102
|
+
}, { ...queueOptions, throwOnTimeout: true });
|
|
76
103
|
return response.data;
|
|
77
104
|
}
|
|
78
|
-
async cancelOrder(body,
|
|
79
|
-
const response = await this.
|
|
105
|
+
async cancelOrder(body, axiosConfig, queueOptions) {
|
|
106
|
+
const response = await this.rateLimitQueue.add(async () => {
|
|
107
|
+
return await this.axios.post('/cancel_order', body, axiosConfig);
|
|
108
|
+
}, { ...queueOptions, throwOnTimeout: true });
|
|
80
109
|
return response.data;
|
|
81
110
|
}
|
|
82
|
-
async createOrder(body,
|
|
83
|
-
const response = await this.
|
|
111
|
+
async createOrder(body, axiosConfig, queueOptions) {
|
|
112
|
+
const response = await this.rateLimitQueue.add(async () => {
|
|
113
|
+
this.rateLimitQueue.pause();
|
|
114
|
+
try {
|
|
115
|
+
return await this.rateLimitCreateOrderQueue.add(async () => {
|
|
116
|
+
return await this.axios.post('/create_order', body, axiosConfig);
|
|
117
|
+
}, { ...queueOptions, throwOnTimeout: true });
|
|
118
|
+
}
|
|
119
|
+
finally {
|
|
120
|
+
setTimeout(() => {
|
|
121
|
+
this.rateLimitQueue.start();
|
|
122
|
+
}, RATE_LIMIT);
|
|
123
|
+
}
|
|
124
|
+
}, { ...queueOptions, throwOnTimeout: true });
|
|
84
125
|
return response.data;
|
|
85
126
|
}
|
|
86
127
|
}
|
|
128
|
+
export default CloreAI;
|
package/build/cloreai/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
import CloreAI from './CloreAI.js';
|
|
2
2
|
export * from './endpoints/cancelOrder.js';
|
|
3
3
|
export * from './endpoints/createOrder.js';
|
|
4
4
|
export * from './endpoints/marketplace.js';
|
|
@@ -10,3 +10,4 @@ export * from './endpoints/setSpotPrice.js';
|
|
|
10
10
|
export * from './endpoints/spotMarketplace.js';
|
|
11
11
|
export * from './endpoints/wallets.js';
|
|
12
12
|
export * from './types.js';
|
|
13
|
+
export default CloreAI;
|
package/build/cloreai/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
import CloreAI from './CloreAI.js';
|
|
2
2
|
export * from './endpoints/cancelOrder.js';
|
|
3
3
|
export * from './endpoints/createOrder.js';
|
|
4
4
|
export * from './endpoints/marketplace.js';
|
|
@@ -10,3 +10,4 @@ export * from './endpoints/setSpotPrice.js';
|
|
|
10
10
|
export * from './endpoints/spotMarketplace.js';
|
|
11
11
|
export * from './endpoints/wallets.js';
|
|
12
12
|
export * from './types.js';
|
|
13
|
+
export default CloreAI;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export declare const
|
|
2
|
-
export declare const
|
|
1
|
+
export declare const RATE_LIMIT = 1000;
|
|
2
|
+
export declare const RATE_LIMIT_CREATE_ORDER = 5000;
|
|
3
3
|
export declare const statusCodes: {
|
|
4
4
|
NORMAL: number;
|
|
5
5
|
DATABASE_ERROR: number;
|
package/build/webapi/WebAPI.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { type AxiosInstance, type AxiosRequestConfig } from 'axios';
|
|
2
|
+
import PQueue, { type QueueAddOptions } from 'p-queue';
|
|
2
3
|
import type { CancelOrderBody, CancelOrderOutput } from './endpoints/cancelOrder.js';
|
|
3
4
|
import type { CreateOrderBody, CreateOrderOutput } from './endpoints/createOrder.js';
|
|
4
5
|
import type { GetSpotBody, GetSpotOutput } from './endpoints/getSpot.js';
|
|
@@ -6,13 +7,15 @@ import type { OrdersBody, OrdersOutput } from './endpoints/orders.js';
|
|
|
6
7
|
import type { ServersOutput } from './endpoints/servers.js';
|
|
7
8
|
import type { SetSpotPriceBody, SetSpotPriceOutput } from './endpoints/setSpotPrice.js';
|
|
8
9
|
import type { Config } from './types.js';
|
|
9
|
-
|
|
10
|
+
declare class WebAPI {
|
|
10
11
|
readonly axios: AxiosInstance;
|
|
12
|
+
readonly rateLimitCreateOrderQueue: PQueue;
|
|
11
13
|
constructor(config: Config);
|
|
12
|
-
servers(
|
|
13
|
-
orders(body: OrdersBody,
|
|
14
|
-
getSpot(body: GetSpotBody,
|
|
15
|
-
setSpotPrice(body: SetSpotPriceBody,
|
|
16
|
-
cancelOrder(body: CancelOrderBody,
|
|
17
|
-
createOrder(body: CreateOrderBody,
|
|
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>;
|
|
19
|
+
createOrder(body: CreateOrderBody, axiosConfig?: AxiosRequestConfig<CreateOrderBody>, queueOptions?: QueueAddOptions): Promise<CreateOrderOutput>;
|
|
18
20
|
}
|
|
21
|
+
export default WebAPI;
|
package/build/webapi/WebAPI.js
CHANGED
|
@@ -1,8 +1,14 @@
|
|
|
1
1
|
import axios from 'axios';
|
|
2
|
+
import PQueue from 'p-queue';
|
|
2
3
|
import { UnknownError } from '../common/errors.js';
|
|
3
|
-
import { getErrorMessage } from '../common/index.js';
|
|
4
|
-
|
|
4
|
+
import { getErrorMessage, RATE_LIMIT_CREATE_ORDER } from '../common/index.js';
|
|
5
|
+
class WebAPI {
|
|
5
6
|
axios;
|
|
7
|
+
rateLimitCreateOrderQueue = new PQueue({
|
|
8
|
+
interval: RATE_LIMIT_CREATE_ORDER,
|
|
9
|
+
intervalCap: 1,
|
|
10
|
+
concurrency: 1,
|
|
11
|
+
});
|
|
6
12
|
constructor(config) {
|
|
7
13
|
const { token, axiosConfig = {} } = config;
|
|
8
14
|
this.axios = axios.create({
|
|
@@ -25,28 +31,31 @@ export class WebAPI {
|
|
|
25
31
|
throw new UnknownError(errorMessage, undefined, response.config, response.request, response);
|
|
26
32
|
});
|
|
27
33
|
}
|
|
28
|
-
async servers(
|
|
29
|
-
const response = await this.axios.post('/marketplace/servers', null,
|
|
34
|
+
async servers(axiosConfig) {
|
|
35
|
+
const response = await this.axios.post('/marketplace/servers', null, axiosConfig);
|
|
30
36
|
return response.data;
|
|
31
37
|
}
|
|
32
|
-
async orders(body,
|
|
33
|
-
const response = await this.axios.post('/marketplace/orders', body,
|
|
38
|
+
async orders(body, axiosConfig) {
|
|
39
|
+
const response = await this.axios.post('/marketplace/orders', body, axiosConfig);
|
|
34
40
|
return response.data;
|
|
35
41
|
}
|
|
36
|
-
async getSpot(body,
|
|
37
|
-
const response = await this.axios.post('/marketplace/get_spot', body,
|
|
42
|
+
async getSpot(body, axiosConfig) {
|
|
43
|
+
const response = await this.axios.post('/marketplace/get_spot', body, axiosConfig);
|
|
38
44
|
return response.data;
|
|
39
45
|
}
|
|
40
|
-
async setSpotPrice(body,
|
|
41
|
-
const response = await this.axios.post('/marketplace/set_spot_price', body,
|
|
46
|
+
async setSpotPrice(body, axiosConfig) {
|
|
47
|
+
const response = await this.axios.post('/marketplace/set_spot_price', body, axiosConfig);
|
|
42
48
|
return response.data;
|
|
43
49
|
}
|
|
44
|
-
async cancelOrder(body,
|
|
45
|
-
const response = await this.axios.post('/marketplace/cancel_order', body,
|
|
50
|
+
async cancelOrder(body, axiosConfig) {
|
|
51
|
+
const response = await this.axios.post('/marketplace/cancel_order', body, axiosConfig);
|
|
46
52
|
return response.data;
|
|
47
53
|
}
|
|
48
|
-
async createOrder(body,
|
|
49
|
-
const response = await this.
|
|
54
|
+
async createOrder(body, axiosConfig, queueOptions) {
|
|
55
|
+
const response = await this.rateLimitCreateOrderQueue.add(async () => {
|
|
56
|
+
return await this.axios.post('/create_order', body, axiosConfig);
|
|
57
|
+
}, { ...queueOptions, throwOnTimeout: true });
|
|
50
58
|
return response.data;
|
|
51
59
|
}
|
|
52
60
|
}
|
|
61
|
+
export default WebAPI;
|
package/build/webapi/index.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import WebAPI from './WebAPI.js';
|
|
1
2
|
export * from './endpoints/cancelOrder.js';
|
|
2
3
|
export * from './endpoints/createOrder.js';
|
|
3
4
|
export * from './endpoints/getSpot.js';
|
|
@@ -5,4 +6,4 @@ export * from './endpoints/orders.js';
|
|
|
5
6
|
export * from './endpoints/servers.js';
|
|
6
7
|
export * from './endpoints/setSpotPrice.js';
|
|
7
8
|
export * from './types.js';
|
|
8
|
-
export
|
|
9
|
+
export default WebAPI;
|
package/build/webapi/index.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import WebAPI from './WebAPI.js';
|
|
1
2
|
export * from './endpoints/cancelOrder.js';
|
|
2
3
|
export * from './endpoints/createOrder.js';
|
|
3
4
|
export * from './endpoints/getSpot.js';
|
|
@@ -5,4 +6,4 @@ export * from './endpoints/orders.js';
|
|
|
5
6
|
export * from './endpoints/servers.js';
|
|
6
7
|
export * from './endpoints/setSpotPrice.js';
|
|
7
8
|
export * from './types.js';
|
|
8
|
-
export
|
|
9
|
+
export default WebAPI;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cloreai",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.10",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "CLORE.AI API client",
|
|
6
6
|
"repository": {
|
|
@@ -30,24 +30,26 @@
|
|
|
30
30
|
"clean": "rimraf build",
|
|
31
31
|
"format": "prettier --check .",
|
|
32
32
|
"lint": "eslint .",
|
|
33
|
+
"playground": "jiti playground/index.ts",
|
|
33
34
|
"prepack": "npm run clean && npm run build && npm run check",
|
|
34
35
|
"prepare": "husky",
|
|
35
|
-
"start-playground": "node playground/index.js",
|
|
36
36
|
"typecheck": "tsc --noEmit",
|
|
37
|
-
"update-latest": "
|
|
37
|
+
"update-latest": "npm-check-updates --peer --upgrade && npm update"
|
|
38
38
|
},
|
|
39
39
|
"dependencies": {
|
|
40
|
-
"axios": "^1.7.
|
|
40
|
+
"axios": "^1.7.7",
|
|
41
|
+
"p-queue": "^8.0.1"
|
|
41
42
|
},
|
|
42
43
|
"devDependencies": {
|
|
43
44
|
"@tsconfig/strictest": "^2.0.5",
|
|
44
45
|
"eslint": "^8.57.0",
|
|
45
|
-
"eslint-config-vladpuz": "^0.
|
|
46
|
-
"husky": "^9.1.
|
|
47
|
-
"
|
|
46
|
+
"eslint-config-vladpuz": "^0.15.0",
|
|
47
|
+
"husky": "^9.1.6",
|
|
48
|
+
"jiti": "^1.21.6",
|
|
49
|
+
"npm-check-updates": "^17.1.1",
|
|
48
50
|
"prettier": "^3.3.3",
|
|
49
51
|
"prettier-config-vladpuz": "^0.8.0",
|
|
50
52
|
"rimraf": "^6.0.1",
|
|
51
|
-
"typescript": "^5.
|
|
53
|
+
"typescript": "^5.6.2"
|
|
52
54
|
}
|
|
53
55
|
}
|