cloreai 0.1.18 → 0.1.19

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 (83) hide show
  1. package/build/{cloreai/CloreAI.d.ts → CloreAI.d.ts} +2 -1
  2. package/build/{cloreai/CloreAI.js → CloreAI.js} +35 -18
  3. package/build/{common/constants.d.ts → constants.d.ts} +4 -0
  4. package/build/{common/constants.js → constants.js} +4 -0
  5. package/build/endpoints/cancelOrder.d.ts +6 -0
  6. package/build/{cloreai/endpoints → endpoints}/createGigaspotOrders.d.ts +1 -2
  7. package/build/{common/endpoints → endpoints}/createOrder.d.ts +3 -2
  8. package/build/{cloreai/endpoints → endpoints}/getGigaspot.d.ts +1 -2
  9. package/build/endpoints/marketplace.d.ts +24 -0
  10. package/build/{common/endpoints → endpoints}/myOrders.d.ts +9 -2
  11. package/build/{cloreai/endpoints → endpoints}/myServers.d.ts +1 -2
  12. package/build/{cloreai/endpoints → endpoints}/serverConfig.d.ts +1 -2
  13. package/build/endpoints/setSpotPrice.d.ts +17 -0
  14. package/build/endpoints/spotMarketplace.d.ts +26 -0
  15. package/build/{cloreai/endpoints → endpoints}/wallets.d.ts +1 -2
  16. package/build/index.d.ts +18 -3
  17. package/build/index.js +3 -3
  18. package/build/{common/types.d.ts → types.d.ts} +5 -3
  19. package/package.json +4 -16
  20. package/build/cloreai/endpoints/cancelOrder.d.ts +0 -6
  21. package/build/cloreai/endpoints/createOrder.d.ts +0 -4
  22. package/build/cloreai/endpoints/marketplace.d.ts +0 -6
  23. package/build/cloreai/endpoints/myOrders.d.ts +0 -9
  24. package/build/cloreai/endpoints/setSpotPrice.d.ts +0 -4
  25. package/build/cloreai/endpoints/setSpotPrice.js +0 -1
  26. package/build/cloreai/endpoints/spotMarketplace.d.ts +0 -9
  27. package/build/cloreai/index.d.ts +0 -17
  28. package/build/cloreai/index.js +0 -2
  29. package/build/cloreai/types.d.ts +0 -7
  30. package/build/common/endpoints/cancelOrder.d.ts +0 -3
  31. package/build/common/endpoints/cancelOrder.js +0 -2
  32. package/build/common/endpoints/createOrder.js +0 -1
  33. package/build/common/endpoints/marketplace.d.ts +0 -19
  34. package/build/common/endpoints/marketplace.js +0 -1
  35. package/build/common/endpoints/myOrders.js +0 -1
  36. package/build/common/endpoints/setSpotPrice.d.ts +0 -16
  37. package/build/common/endpoints/spotMarketplace.d.ts +0 -19
  38. package/build/common/endpoints/spotMarketplace.js +0 -1
  39. package/build/common/helpers.d.ts +0 -6
  40. package/build/common/helpers.js +0 -25
  41. package/build/common/index.d.ts +0 -10
  42. package/build/common/index.js +0 -3
  43. package/build/common/types.js +0 -1
  44. package/build/webapi/WebAPI.d.ts +0 -22
  45. package/build/webapi/WebAPI.js +0 -80
  46. package/build/webapi/endpoints/cancelOrder.d.ts +0 -6
  47. package/build/webapi/endpoints/cancelOrder.js +0 -1
  48. package/build/webapi/endpoints/createOrder.d.ts +0 -4
  49. package/build/webapi/endpoints/createOrder.js +0 -1
  50. package/build/webapi/endpoints/marketplace.d.ts +0 -10
  51. package/build/webapi/endpoints/marketplace.js +0 -1
  52. package/build/webapi/endpoints/myOrders.d.ts +0 -15
  53. package/build/webapi/endpoints/myOrders.js +0 -1
  54. package/build/webapi/endpoints/setSpotPrice.d.ts +0 -4
  55. package/build/webapi/endpoints/setSpotPrice.js +0 -1
  56. package/build/webapi/endpoints/spotMarketplace.d.ts +0 -8
  57. package/build/webapi/endpoints/spotMarketplace.js +0 -1
  58. package/build/webapi/index.d.ts +0 -9
  59. package/build/webapi/index.js +0 -2
  60. package/build/webapi/types.d.ts +0 -7
  61. package/build/webapi/types.js +0 -1
  62. package/build/webapi.d.ts +0 -4
  63. package/build/webapi.js +0 -4
  64. /package/build/{cloreai/endpoints → endpoints}/cancelOrder.js +0 -0
  65. /package/build/{cloreai/endpoints → endpoints}/cancelOrders.d.ts +0 -0
  66. /package/build/{cloreai/endpoints → endpoints}/cancelOrders.js +0 -0
  67. /package/build/{cloreai/endpoints → endpoints}/createGigaspotOrders.js +0 -0
  68. /package/build/{cloreai/endpoints → endpoints}/createOrder.js +0 -0
  69. /package/build/{cloreai/endpoints → endpoints}/editGigaspotOrders.d.ts +0 -0
  70. /package/build/{cloreai/endpoints → endpoints}/editGigaspotOrders.js +0 -0
  71. /package/build/{cloreai/endpoints → endpoints}/getGigaspot.js +0 -0
  72. /package/build/{cloreai/endpoints → endpoints}/marketplace.js +0 -0
  73. /package/build/{cloreai/endpoints → endpoints}/myOrders.js +0 -0
  74. /package/build/{cloreai/endpoints → endpoints}/myServers.js +0 -0
  75. /package/build/{cloreai/endpoints → endpoints}/serverConfig.js +0 -0
  76. /package/build/{cloreai/endpoints → endpoints}/setServerSettings.d.ts +0 -0
  77. /package/build/{cloreai/endpoints → endpoints}/setServerSettings.js +0 -0
  78. /package/build/{common/endpoints → endpoints}/setSpotPrice.js +0 -0
  79. /package/build/{cloreai/endpoints → endpoints}/spotMarketplace.js +0 -0
  80. /package/build/{cloreai/endpoints → endpoints}/wallets.js +0 -0
  81. /package/build/{common/errors.d.ts → errors.d.ts} +0 -0
  82. /package/build/{common/errors.js → errors.js} +0 -0
  83. /package/build/{cloreai/types.js → types.js} +0 -0
@@ -20,11 +20,12 @@ declare class CloreAI {
20
20
  rateLimitQueue: PQueue;
21
21
  rateLimitQueueCreateOrder: PQueue;
22
22
  constructor(config: Config);
23
+ private getQueueOptions;
23
24
  wallets(config?: AxiosRequestConfig): Promise<WalletsResponseData>;
24
25
  myServers(config?: AxiosRequestConfig): Promise<MyServersResponseData>;
25
26
  serverConfig(data: ServerConfigRequestData, config?: AxiosRequestConfig): Promise<ServerConfigResponseData>;
26
27
  marketplace(config?: AxiosRequestConfig): Promise<MarketplaceResponseData>;
27
- myOrders(params: MyOrdersRequestParams, config?: AxiosRequestConfig): Promise<MyOrdersResponseData>;
28
+ myOrders(params?: MyOrdersRequestParams, config?: AxiosRequestConfig): Promise<MyOrdersResponseData>;
28
29
  spotMarketplace(params: SpotMarketplaceRequestParams, config?: AxiosRequestConfig): Promise<SpotMarketplaceResponseData>;
29
30
  setServerSettings(data: SetServerSettingsRequestData, config?: AxiosRequestConfig): Promise<SetServerSettingsResponseData>;
30
31
  setSpotPrice(data: SetSpotPriceRequestData, config?: AxiosRequestConfig): Promise<SetSpotPriceResponseData>;
@@ -1,8 +1,7 @@
1
1
  import axios from 'axios';
2
2
  import PQueue from 'p-queue';
3
- import { priorityLevels, RATE_LIMIT, RATE_LIMIT_CREATE_ORDER, statusCodes } from '../common/constants.js';
4
- import { DatabaseError, ExceededError, InvalidApiTokenError, InvalidEndpointError, InvalidInputDataError, OtherError, UnknownError } from '../common/errors.js';
5
- import { getErrorMessage, getQueueOptions } from '../common/helpers.js';
3
+ import { priorityLevels, RATE_LIMIT, RATE_LIMIT_CREATE_ORDER, statusCodes } from './constants.js';
4
+ import { DatabaseError, ExceededError, InvalidApiTokenError, InvalidEndpointError, InvalidInputDataError, OtherError, UnknownError } from './errors.js';
6
5
  class CloreAI {
7
6
  axios;
8
7
  rateLimitQueue;
@@ -32,7 +31,9 @@ class CloreAI {
32
31
  if (response.data.code === statusCodes.NORMAL) {
33
32
  return response;
34
33
  }
35
- const errorMessage = getErrorMessage(response.data.code, response.data.error);
34
+ const errorMessage = response.data.error != null
35
+ ? `Code "${response.status}", error "${response.data.error}"`
36
+ : `Code "${response.status}"`;
36
37
  const axiosErrorParameters = [
37
38
  errorMessage,
38
39
  undefined,
@@ -58,64 +59,80 @@ class CloreAI {
58
59
  }
59
60
  });
60
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
+ };
77
+ }
61
78
  async wallets(config) {
62
79
  const response = await this.rateLimitQueue.add(async () => {
63
80
  return await this.axios.get('/wallets', config);
64
- }, getQueueOptions(priorityLevels.NORMAL, config));
81
+ }, this.getQueueOptions(priorityLevels.NORMAL, config));
65
82
  return response.data;
66
83
  }
67
84
  async myServers(config) {
68
85
  const response = await this.rateLimitQueue.add(async () => {
69
86
  return await this.axios.get('/my_servers', config);
70
- }, getQueueOptions(priorityLevels.NORMAL, config));
87
+ }, this.getQueueOptions(priorityLevels.NORMAL, config));
71
88
  return response.data;
72
89
  }
73
90
  async serverConfig(data, config) {
74
91
  const response = await this.rateLimitQueue.add(async () => {
75
92
  return await this.axios.get('/server_config', { ...config, data });
76
- }, getQueueOptions(priorityLevels.NORMAL, config));
93
+ }, this.getQueueOptions(priorityLevels.NORMAL, config));
77
94
  return response.data;
78
95
  }
79
96
  async marketplace(config) {
80
97
  const response = await this.rateLimitQueue.add(async () => {
81
98
  return await this.axios.get('/marketplace', config);
82
- }, getQueueOptions(priorityLevels.NORMAL, config));
99
+ }, this.getQueueOptions(priorityLevels.NORMAL, config));
83
100
  return response.data;
84
101
  }
85
102
  async myOrders(params, config) {
86
103
  const response = await this.rateLimitQueue.add(async () => {
87
104
  return await this.axios.get('/my_orders', { ...config, params });
88
- }, getQueueOptions(priorityLevels.NORMAL, config));
105
+ }, this.getQueueOptions(priorityLevels.NORMAL, config));
89
106
  return response.data;
90
107
  }
91
108
  async spotMarketplace(params, config) {
92
109
  const response = await this.rateLimitQueue.add(async () => {
93
110
  return await this.axios.get('/spot_marketplace', { ...config, params });
94
- }, getQueueOptions(priorityLevels.NORMAL, config));
111
+ }, this.getQueueOptions(priorityLevels.NORMAL, config));
95
112
  return response.data;
96
113
  }
97
114
  async setServerSettings(data, config) {
98
115
  const response = await this.rateLimitQueue.add(async () => {
99
116
  return await this.axios.post('/set_server_settings', data, config);
100
- }, getQueueOptions(priorityLevels.HIGH, config));
117
+ }, this.getQueueOptions(priorityLevels.HIGH, config));
101
118
  return response.data;
102
119
  }
103
120
  async setSpotPrice(data, config) {
104
121
  const response = await this.rateLimitQueue.add(async () => {
105
122
  return await this.axios.post('/set_spot_price', data, config);
106
- }, getQueueOptions(priorityLevels.HIGH, config));
123
+ }, this.getQueueOptions(priorityLevels.HIGH, config));
107
124
  return response.data;
108
125
  }
109
126
  async cancelOrder(data, config) {
110
127
  const response = await this.rateLimitQueue.add(async () => {
111
128
  return await this.axios.post('/cancel_order', data, config);
112
- }, getQueueOptions(priorityLevels.HIGH, config));
129
+ }, this.getQueueOptions(priorityLevels.HIGH, config));
113
130
  return response.data;
114
131
  }
115
132
  async createOrder(data, config) {
116
133
  const response = await this.rateLimitQueueCreateOrder.add(async () => {
117
134
  return await this.axios.post('/create_order', data, config);
118
- }, getQueueOptions(priorityLevels.HIGHEST, config));
135
+ }, this.getQueueOptions(priorityLevels.HIGHEST, config));
119
136
  return response.data;
120
137
  }
121
138
  async getGigaspot(config) {
@@ -126,24 +143,24 @@ class CloreAI {
126
143
  ...response.data,
127
144
  snapshot: snapshot.data,
128
145
  };
129
- }, getQueueOptions(priorityLevels.NORMAL, config));
146
+ }, this.getQueueOptions(priorityLevels.NORMAL, config));
130
147
  }
131
148
  async createGigaspotOrders(data, config) {
132
149
  const response = await this.rateLimitQueue.add(async () => {
133
150
  return await this.axios.post('/create_gigaspot_orders', data, config);
134
- }, getQueueOptions(priorityLevels.HIGH, config));
151
+ }, this.getQueueOptions(priorityLevels.HIGH, config));
135
152
  return response.data;
136
153
  }
137
154
  async editGigaspotOrders(data, config) {
138
155
  const response = await this.rateLimitQueue.add(async () => {
139
156
  return await this.axios.post('/edit_gigaspot_orders', data, config);
140
- }, getQueueOptions(priorityLevels.HIGH, config));
157
+ }, this.getQueueOptions(priorityLevels.HIGH, config));
141
158
  return response.data;
142
159
  }
143
160
  async cancelOrders(data, config) {
144
161
  const response = await this.rateLimitQueue.add(async () => {
145
162
  return await this.axios.post('/cancel_orders', data, config);
146
- }, getQueueOptions(priorityLevels.HIGH, config));
163
+ }, this.getQueueOptions(priorityLevels.HIGH, config));
147
164
  return response.data;
148
165
  }
149
166
  }
@@ -14,3 +14,7 @@ export declare const priorityLevels: {
14
14
  HIGH: number;
15
15
  HIGHEST: number;
16
16
  };
17
+ export declare const gigaspotBaseImages: {
18
+ UBUNTU: string;
19
+ HIVEOS: string;
20
+ };
@@ -14,3 +14,7 @@ export const priorityLevels = {
14
14
  HIGH: 1,
15
15
  HIGHEST: 2,
16
16
  };
17
+ export const gigaspotBaseImages = {
18
+ UBUNTU: 'a3f9c4d7e5b088d8a0bff880',
19
+ HIVEOS: 'c9a4e2f6b7d488d8f0bab0ff',
20
+ };
@@ -0,0 +1,6 @@
1
+ import type { ResponseData } from '../types.js';
2
+ export interface CancelOrderRequestData {
3
+ id: number;
4
+ issue?: string;
5
+ }
6
+ export type CancelOrderResponseData = ResponseData;
@@ -1,5 +1,4 @@
1
- import type { Currency } from '../../common/types.js';
2
- import type { ResponseData } from '../types.js';
1
+ import type { Currency, ResponseData } from '../types.js';
3
2
  export interface CreateGigaspotOrdersRequestDataOrderOverclock {
4
3
  pl: number;
5
4
  core_lock?: number;
@@ -1,4 +1,4 @@
1
- import type { Currency, OrderType } from '../types.js';
1
+ import type { Currency, OrderType, ResponseData } from '../types.js';
2
2
  export interface CreateOrderRequestDataBase {
3
3
  type: OrderType;
4
4
  currency: Currency;
@@ -22,4 +22,5 @@ export interface CreateOrderRequestDataSpot extends CreateOrderRequestDataBase {
22
22
  type: 'spot';
23
23
  spotprice: number;
24
24
  }
25
- export type CreateOrderRequestDataCommon = CreateOrderRequestDataOnDemand | CreateOrderRequestDataSpot;
25
+ export type CreateOrderRequestData = CreateOrderRequestDataOnDemand | CreateOrderRequestDataSpot;
26
+ export type CreateOrderResponseData = ResponseData;
@@ -1,5 +1,4 @@
1
- import type { Currency, Pricing } from '../../common/types.js';
2
- import type { ResponseData } from '../types.js';
1
+ import type { Currency, Pricing, ResponseData } from '../types.js';
3
2
  export interface GetGigaspotResponseDataSnapshotServerBid {
4
3
  owner: number;
5
4
  id: number;
@@ -0,0 +1,24 @@
1
+ import type { Currency, Price, ResponseData, Specs } from '../types.js';
2
+ export interface MarketplaceResponseDataServerRating {
3
+ avg: number;
4
+ cnt: number;
5
+ }
6
+ export interface MarketplaceResponseDataServer {
7
+ allowed_coins: Currency[];
8
+ cuda_version: string;
9
+ gigaspot: boolean;
10
+ gpu_array: string[];
11
+ id: number;
12
+ mrl: number;
13
+ oc: boolean;
14
+ owner: number;
15
+ price: Price;
16
+ rating: MarketplaceResponseDataServerRating;
17
+ reliability: number;
18
+ rented: boolean;
19
+ specs: Specs;
20
+ }
21
+ export interface MarketplaceResponseData extends ResponseData {
22
+ servers: MarketplaceResponseDataServer[];
23
+ my_servers: number[];
24
+ }
@@ -1,5 +1,8 @@
1
- import type { Currency, Specs } from '../types.js';
2
- export interface MyOrdersResponseDataOrderCommon {
1
+ import type { Currency, ResponseData, Specs } from '../types.js';
2
+ export interface MyOrdersRequestParams {
3
+ return_completed?: boolean;
4
+ }
5
+ export interface MyOrdersResponseDataOrder {
3
6
  auto_login: string;
4
7
  id: number;
5
8
  fee: number;
@@ -21,3 +24,7 @@ export interface MyOrdersResponseDataOrderCommon {
21
24
  tcp_ports: string[];
22
25
  http_port: string;
23
26
  }
27
+ export interface MyOrdersResponseData extends ResponseData {
28
+ orders: MyOrdersResponseDataOrder[];
29
+ limit: number;
30
+ }
@@ -1,5 +1,4 @@
1
- import type { Pricing, Specs, Visibility } from '../../common/types.js';
2
- import type { ResponseData } from '../types.js';
1
+ import type { Pricing, ResponseData, Specs, Visibility } from '../types.js';
3
2
  export interface MyServersResponseDataServer {
4
3
  name: string;
5
4
  connected: boolean;
@@ -1,5 +1,4 @@
1
- import type { Pricing, Specs, Visibility } from '../../common/types.js';
2
- import type { ResponseData } from '../types.js';
1
+ import type { Pricing, ResponseData, Specs, Visibility } from '../types.js';
3
2
  export interface ServerConfigRequestData {
4
3
  server_name: string;
5
4
  }
@@ -0,0 +1,17 @@
1
+ import type { ResponseData } from '../types.js';
2
+ export interface SetSpotPriceRequestData {
3
+ order_id: number;
4
+ desired_price: number;
5
+ }
6
+ export interface SetSpotPriceResponseDataMaxStep extends ResponseData {
7
+ error: 'exceeded_max_step';
8
+ max_step: number;
9
+ }
10
+ export interface SetSpotPriceResponseDataTimeToLowering extends ResponseData {
11
+ error: 'can_lower_every_600_seconds';
12
+ time_to_lowering: number;
13
+ }
14
+ export interface SetSpotPriceResponseDataNormal extends ResponseData {
15
+ error: null;
16
+ }
17
+ export type SetSpotPriceResponseData = SetSpotPriceResponseDataMaxStep | SetSpotPriceResponseDataTimeToLowering | SetSpotPriceResponseDataNormal;
@@ -0,0 +1,26 @@
1
+ import type { Currency, Pricing, ResponseData, Visibility } from '../types.js';
2
+ export interface SpotMarketplaceRequestParams {
3
+ market: number;
4
+ }
5
+ export interface SpotMarketplaceResponseDataOffer {
6
+ active: boolean;
7
+ bid: number;
8
+ currency: Currency;
9
+ my: boolean;
10
+ offer_id: number;
11
+ }
12
+ export interface SpotMarketplaceResponseDataServer {
13
+ min_pricing: Pricing;
14
+ mrl: number;
15
+ online: boolean;
16
+ visibility: Visibility;
17
+ }
18
+ export interface SpotMarketplaceResponseDataMarket {
19
+ currency_rates_in_usd: Pricing;
20
+ offers: SpotMarketplaceResponseDataOffer[];
21
+ server: SpotMarketplaceResponseDataServer;
22
+ }
23
+ export interface SpotMarketplaceResponseData extends ResponseData {
24
+ market: SpotMarketplaceResponseDataMarket;
25
+ exists: boolean;
26
+ }
@@ -1,5 +1,4 @@
1
- import type { Currency } from '../../common/types.js';
2
- import type { ResponseData } from '../types.js';
1
+ import type { Currency, ResponseData } from '../types.js';
3
2
  export interface WalletsResponseDataWallet {
4
3
  name: Currency;
5
4
  deposit: string;
package/build/index.d.ts CHANGED
@@ -1,4 +1,19 @@
1
- import CloreAI from './cloreai/index.js';
2
- export * from './cloreai/index.js';
3
- export * from './common/index.js';
1
+ import CloreAI from './CloreAI.js';
2
+ export * from './constants.js';
3
+ export type * from './endpoints/cancelOrder.js';
4
+ export type * from './endpoints/cancelOrders.js';
5
+ export type * from './endpoints/createGigaspotOrders.js';
6
+ export type * from './endpoints/createOrder.js';
7
+ export type * from './endpoints/editGigaspotOrders.js';
8
+ export type * from './endpoints/getGigaspot.js';
9
+ export type * from './endpoints/marketplace.js';
10
+ export type * from './endpoints/myOrders.js';
11
+ export type * from './endpoints/myServers.js';
12
+ export type * from './endpoints/serverConfig.js';
13
+ export type * from './endpoints/setServerSettings.js';
14
+ export type * from './endpoints/setSpotPrice.js';
15
+ export type * from './endpoints/spotMarketplace.js';
16
+ export type * from './endpoints/wallets.js';
17
+ export * from './errors.js';
18
+ export type * from './types.js';
4
19
  export default CloreAI;
package/build/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import CloreAI from './cloreai/index.js';
2
- export * from './cloreai/index.js';
3
- export * from './common/index.js';
1
+ import CloreAI from './CloreAI.js';
2
+ export * from './constants.js';
3
+ export * from './errors.js';
4
4
  export default CloreAI;
@@ -1,13 +1,15 @@
1
1
  import type { CreateAxiosDefaults } from 'axios';
2
2
  import type { Options, Queue, QueueAddOptions } from 'p-queue';
3
3
  export type PQueueOptions = Options<Queue<() => Promise<unknown>, QueueAddOptions>, QueueAddOptions>;
4
- export interface CommonConfig {
4
+ export interface Config {
5
+ apiKey: string;
5
6
  axiosConfig?: CreateAxiosDefaults;
6
7
  rateLimitQueueOptions?: PQueueOptions;
7
8
  rateLimitQueueOptionsCreateOrder?: PQueueOptions;
8
9
  }
9
- export interface CommonResponseData {
10
- error?: string;
10
+ export interface ResponseData {
11
+ code: number;
12
+ error?: string | null;
11
13
  }
12
14
  export type OrderType = 'on-demand' | 'spot';
13
15
  export type Visibility = 'public' | 'hidden';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cloreai",
3
- "version": "0.1.18",
3
+ "version": "0.1.19",
4
4
  "type": "module",
5
5
  "description": "CLORE.AI API client",
6
6
  "repository": {
@@ -9,20 +9,8 @@
9
9
  },
10
10
  "author": "Vladislav Puzyrev",
11
11
  "license": "MIT",
12
- "exports": {
13
- ".": "./build/index.js",
14
- "./webapi": "./build/webapi.js"
15
- },
16
- "typesVersions": {
17
- "*": {
18
- ".": [
19
- "build/index.d.ts"
20
- ],
21
- "webapi": [
22
- "build/webapi.d.ts"
23
- ]
24
- }
25
- },
12
+ "main": "build/index.js",
13
+ "types": "build/index.d.ts",
26
14
  "keywords": [
27
15
  "cloreai",
28
16
  "clore",
@@ -47,7 +35,7 @@
47
35
  "devDependencies": {
48
36
  "@tsconfig/node-lts": "^22.0.1",
49
37
  "@tsconfig/strictest": "^2.0.5",
50
- "@types/node": "^22.10.7",
38
+ "@types/node": "^22.10.9",
51
39
  "eslint": "^9.18.0",
52
40
  "eslint-config-vladpuz": "^0.24.0",
53
41
  "husky": "^9.1.7",
@@ -1,6 +0,0 @@
1
- import type { CancelOrderRequestDataCommon } from '../../common/endpoints/cancelOrder.js';
2
- import type { ResponseData } from '../types.js';
3
- export interface CancelOrderRequestData extends CancelOrderRequestDataCommon {
4
- issue?: string;
5
- }
6
- export type CancelOrderResponseData = ResponseData;
@@ -1,4 +0,0 @@
1
- import type { CreateOrderRequestDataCommon } from '../../common/endpoints/createOrder.js';
2
- import type { ResponseData } from '../types.js';
3
- export type CreateOrderRequestData = CreateOrderRequestDataCommon;
4
- export type CreateOrderResponseData = ResponseData;
@@ -1,6 +0,0 @@
1
- import type { MarketplaceResponseDataServerCommon } from '../../common/endpoints/marketplace.js';
2
- import type { ResponseData } from '../types.js';
3
- export interface MarketplaceResponseData extends ResponseData {
4
- servers: MarketplaceResponseDataServerCommon[];
5
- my_servers: number[];
6
- }
@@ -1,9 +0,0 @@
1
- import type { MyOrdersResponseDataOrderCommon } from '../../common/endpoints/myOrders.js';
2
- import type { ResponseData } from '../types.js';
3
- export interface MyOrdersRequestParams {
4
- return_completed?: boolean;
5
- }
6
- export interface MyOrdersResponseData extends ResponseData {
7
- orders: MyOrdersResponseDataOrderCommon[];
8
- limit: number;
9
- }
@@ -1,4 +0,0 @@
1
- import type { SetSpotPriceRequestDataCommon, SetSpotPriceResponseDataCommon } from '../../common/endpoints/setSpotPrice.js';
2
- import type { ResponseData } from '../types.js';
3
- export type SetSpotPriceRequestData = SetSpotPriceRequestDataCommon;
4
- export type SetSpotPriceResponseData = SetSpotPriceResponseDataCommon & ResponseData;
@@ -1 +0,0 @@
1
- export {};
@@ -1,9 +0,0 @@
1
- import type { SpotMarketplaceResponseDataCommon } from '../../common/endpoints/spotMarketplace.js';
2
- import type { ResponseData } from '../types.js';
3
- export interface SpotMarketplaceRequestParams {
4
- market: number;
5
- }
6
- export interface SpotMarketplaceResponseData extends ResponseData {
7
- market: SpotMarketplaceResponseDataCommon;
8
- exists: boolean;
9
- }
@@ -1,17 +0,0 @@
1
- import CloreAI from './CloreAI.js';
2
- export type * from './endpoints/cancelOrder.js';
3
- export type * from './endpoints/cancelOrders.js';
4
- export type * from './endpoints/createGigaspotOrders.js';
5
- export type * from './endpoints/createOrder.js';
6
- export type * from './endpoints/editGigaspotOrders.js';
7
- export type * from './endpoints/getGigaspot.js';
8
- export type * from './endpoints/marketplace.js';
9
- export type * from './endpoints/myOrders.js';
10
- export type * from './endpoints/myServers.js';
11
- export type * from './endpoints/serverConfig.js';
12
- export type * from './endpoints/setServerSettings.js';
13
- export type * from './endpoints/setSpotPrice.js';
14
- export type * from './endpoints/spotMarketplace.js';
15
- export type * from './endpoints/wallets.js';
16
- export type * from './types.js';
17
- export default CloreAI;
@@ -1,2 +0,0 @@
1
- import CloreAI from './CloreAI.js';
2
- export default CloreAI;
@@ -1,7 +0,0 @@
1
- import type { CommonConfig, CommonResponseData } from '../common/types.js';
2
- export interface Config extends CommonConfig {
3
- apiKey: string;
4
- }
5
- export interface ResponseData extends CommonResponseData {
6
- code: number;
7
- }
@@ -1,3 +0,0 @@
1
- export interface CancelOrderRequestDataCommon {
2
- id: number;
3
- }
@@ -1,2 +0,0 @@
1
- /* RequestData */
2
- export {};
@@ -1 +0,0 @@
1
- export {};
@@ -1,19 +0,0 @@
1
- import type { Currency, Price, Specs } from '../types.js';
2
- export interface MarketplaceResponseDataServerRatingCommon {
3
- avg: number;
4
- cnt: number;
5
- }
6
- export interface MarketplaceResponseDataServerCommon {
7
- allowed_coins: Currency[];
8
- cuda_version: string;
9
- gpu_array: string[];
10
- id: number;
11
- mrl: number;
12
- oc: boolean;
13
- owner: number;
14
- price: Price;
15
- rating: MarketplaceResponseDataServerRatingCommon;
16
- reliability: number;
17
- rented: boolean;
18
- specs: Specs;
19
- }
@@ -1 +0,0 @@
1
- export {};
@@ -1 +0,0 @@
1
- export {};
@@ -1,16 +0,0 @@
1
- export interface SetSpotPriceRequestDataCommon {
2
- order_id: number;
3
- desired_price: number;
4
- }
5
- export interface SetSpotPriceResponseDataMaxStep {
6
- error: 'exceeded_max_step';
7
- max_step: number;
8
- }
9
- export interface SetSpotPriceResponseDataTimeToLowering {
10
- error: 'can_lower_every_600_seconds';
11
- time_to_lowering: number;
12
- }
13
- export interface SetSpotPriceResponseDataNormal {
14
- error: undefined;
15
- }
16
- export type SetSpotPriceResponseDataCommon = SetSpotPriceResponseDataMaxStep | SetSpotPriceResponseDataTimeToLowering | SetSpotPriceResponseDataNormal;
@@ -1,19 +0,0 @@
1
- import type { Currency, Pricing, Visibility } from '../types.js';
2
- export interface SpotMarketplaceResponseDataOfferCommon {
3
- active: boolean;
4
- bid: number;
5
- currency: Currency;
6
- my: boolean;
7
- offer_id: number;
8
- }
9
- export interface SpotMarketplaceResponseDataServerCommon {
10
- min_pricing: Pricing;
11
- mrl: number;
12
- online: boolean;
13
- visibility: Visibility;
14
- }
15
- export interface SpotMarketplaceResponseDataCommon {
16
- currency_rates_in_usd: Pricing;
17
- offers: SpotMarketplaceResponseDataOfferCommon[];
18
- server: SpotMarketplaceResponseDataServerCommon;
19
- }
@@ -1 +0,0 @@
1
- export {};
@@ -1,6 +0,0 @@
1
- import type { AxiosRequestConfig } from 'axios';
2
- import type { QueueAddOptions } from 'p-queue';
3
- export declare function getErrorMessage(statusCode?: number | string, errorField?: string): string;
4
- export declare function getQueueOptions(priority: number, config?: AxiosRequestConfig): QueueAddOptions & {
5
- throwOnTimeout: true;
6
- };
@@ -1,25 +0,0 @@
1
- export function getErrorMessage(statusCode, errorField) {
2
- const messages = [];
3
- if (statusCode != null) {
4
- messages.push(`Status code "${statusCode}".`);
5
- }
6
- if (errorField != null) {
7
- messages.push(`Error field "${errorField}".`);
8
- }
9
- return messages.join(' ');
10
- }
11
- export function getQueueOptions(priority, config) {
12
- const defaultQueueOptions = {
13
- throwOnTimeout: true,
14
- priority,
15
- };
16
- // eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion -- GenericAbortSignal
17
- const signal = config?.signal;
18
- if (signal == null) {
19
- return defaultQueueOptions;
20
- }
21
- return {
22
- ...defaultQueueOptions,
23
- signal,
24
- };
25
- }
@@ -1,10 +0,0 @@
1
- export * from './constants.js';
2
- export type * from './endpoints/cancelOrder.js';
3
- export type * from './endpoints/createOrder.js';
4
- export type * from './endpoints/marketplace.js';
5
- export type * from './endpoints/myOrders.js';
6
- export type * from './endpoints/setSpotPrice.js';
7
- export type * from './endpoints/spotMarketplace.js';
8
- export * from './errors.js';
9
- export * from './helpers.js';
10
- export type * from './types.js';
@@ -1,3 +0,0 @@
1
- export * from './constants.js';
2
- export * from './errors.js';
3
- export * from './helpers.js';
@@ -1 +0,0 @@
1
- export {};
@@ -1,22 +0,0 @@
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 { MyOrdersRequestData, MyOrdersResponseData } from './endpoints/myOrders.js';
7
- import type { SetSpotPriceRequestData, SetSpotPriceResponseData } from './endpoints/setSpotPrice.js';
8
- import type { SpotMarketplaceRequestData, SpotMarketplaceResponseData } from './endpoints/spotMarketplace.js';
9
- import type { Config } from './types.js';
10
- declare class WebAPI {
11
- axios: AxiosInstance;
12
- rateLimitQueue: PQueue;
13
- rateLimitQueueCreateOrder: PQueue;
14
- constructor(config: Config);
15
- marketplace(config?: AxiosRequestConfig): Promise<MarketplaceResponseData>;
16
- myOrders(data: MyOrdersRequestData, config?: AxiosRequestConfig): Promise<MyOrdersResponseData>;
17
- spotMarketplace(data: SpotMarketplaceRequestData, config?: AxiosRequestConfig): Promise<SpotMarketplaceResponseData>;
18
- setSpotPrice(data: SetSpotPriceRequestData, config?: AxiosRequestConfig): Promise<SetSpotPriceResponseData>;
19
- cancelOrder(data: CancelOrderRequestData, config?: AxiosRequestConfig): Promise<CancelOrderResponseData>;
20
- createOrder(data: CreateOrderRequestData, config?: AxiosRequestConfig): Promise<CreateOrderResponseData>;
21
- }
22
- export default WebAPI;
@@ -1,80 +0,0 @@
1
- import axios from 'axios';
2
- import PQueue from 'p-queue';
3
- import { priorityLevels, RATE_LIMIT, RATE_LIMIT_CREATE_ORDER } from '../common/constants.js';
4
- import { UnknownError } from '../common/errors.js';
5
- import { getErrorMessage, getQueueOptions } from '../common/helpers.js';
6
- class WebAPI {
7
- axios;
8
- rateLimitQueue;
9
- rateLimitQueueCreateOrder;
10
- constructor(config) {
11
- this.rateLimitQueue = new PQueue({
12
- interval: RATE_LIMIT,
13
- intervalCap: 1,
14
- concurrency: 1,
15
- ...config.rateLimitQueueOptions,
16
- });
17
- this.rateLimitQueueCreateOrder = new PQueue({
18
- interval: RATE_LIMIT_CREATE_ORDER,
19
- intervalCap: 1,
20
- concurrency: 1,
21
- ...config.rateLimitQueueOptionsCreateOrder,
22
- });
23
- this.axios = axios.create({
24
- ...config.axiosConfig,
25
- baseURL: 'https://clore.ai/webapi',
26
- });
27
- this.axios.interceptors.request.use((request) => {
28
- request.data = {
29
- ...request.data,
30
- token: config.token,
31
- };
32
- return request;
33
- });
34
- this.axios.interceptors.response.use((response) => {
35
- const hasError = Boolean(response.data.error);
36
- if (!hasError) {
37
- return response;
38
- }
39
- const errorMessage = getErrorMessage(response.data.status, response.data.error);
40
- throw new UnknownError(errorMessage, undefined, response.config, response.request, response);
41
- });
42
- }
43
- async marketplace(config) {
44
- const response = await this.rateLimitQueue.add(async () => {
45
- return await this.axios.post('/marketplace/servers', null, config);
46
- }, getQueueOptions(priorityLevels.NORMAL, config));
47
- return response.data;
48
- }
49
- async myOrders(data, config) {
50
- const response = await this.rateLimitQueue.add(async () => {
51
- return await this.axios.post('/marketplace/orders', data, config);
52
- }, getQueueOptions(priorityLevels.NORMAL, config));
53
- return response.data;
54
- }
55
- async spotMarketplace(data, config) {
56
- const response = await this.rateLimitQueue.add(async () => {
57
- return await this.axios.post('/marketplace/get_spot', data, config);
58
- }, getQueueOptions(priorityLevels.NORMAL, config));
59
- return response.data;
60
- }
61
- async setSpotPrice(data, config) {
62
- const response = await this.rateLimitQueue.add(async () => {
63
- return await this.axios.post('/marketplace/set_spot_price', data, config);
64
- }, getQueueOptions(priorityLevels.HIGH, config));
65
- return response.data;
66
- }
67
- async cancelOrder(data, config) {
68
- const response = await this.rateLimitQueue.add(async () => {
69
- return await this.axios.post('/marketplace/cancel_order', data, config);
70
- }, getQueueOptions(priorityLevels.HIGH, config));
71
- return response.data;
72
- }
73
- async createOrder(data, config) {
74
- const response = await this.rateLimitQueueCreateOrder.add(async () => {
75
- return await this.axios.post('/create_order', data, config);
76
- }, getQueueOptions(priorityLevels.HIGHEST, config));
77
- return response.data;
78
- }
79
- }
80
- export default WebAPI;
@@ -1,6 +0,0 @@
1
- import type { CancelOrderRequestDataCommon } from '../../common/endpoints/cancelOrder.js';
2
- import type { ResponseData } from '../types.js';
3
- export interface CancelOrderRequestData extends CancelOrderRequestDataCommon {
4
- rating: number;
5
- }
6
- export type CancelOrderResponseData = ResponseData;
@@ -1 +0,0 @@
1
- export {};
@@ -1,4 +0,0 @@
1
- import type { CreateOrderRequestDataCommon } from '../../common/endpoints/createOrder.js';
2
- import type { ResponseData } from '../types.js';
3
- export type CreateOrderRequestData = CreateOrderRequestDataCommon;
4
- export type CreateOrderResponseData = ResponseData;
@@ -1 +0,0 @@
1
- export {};
@@ -1,10 +0,0 @@
1
- import type { MarketplaceResponseDataServerCommon } from '../../common/endpoints/marketplace.js';
2
- import type { Price } from '../../common/types.js';
3
- import type { ResponseData } from '../types.js';
4
- export interface MarketplaceResponseData extends ResponseData {
5
- all_servers: MarketplaceResponseDataServerCommon[];
6
- creation_fees: Price;
7
- disable_usd: boolean;
8
- my_servers: MarketplaceResponseDataServerCommon[];
9
- not_rented_available_servers: MarketplaceResponseDataServerCommon[];
10
- }
@@ -1 +0,0 @@
1
- export {};
@@ -1,15 +0,0 @@
1
- import type { MyOrdersResponseDataOrderCommon } from '../../common/endpoints/myOrders.js';
2
- import type { Currency, Price } from '../../common/types.js';
3
- import type { ResponseData } from '../types.js';
4
- export interface MyOrdersRequestData {
5
- rc: boolean;
6
- }
7
- export interface MyOrdersResponseData extends ResponseData {
8
- PoH_active: boolean;
9
- PoH_rates: Record<Currency, Record<string, Price>>;
10
- allowed_features: string[];
11
- eo: boolean;
12
- http_endpoint_by_proxy: Record<string, string>;
13
- ol: number;
14
- orders: MyOrdersResponseDataOrderCommon[];
15
- }
@@ -1 +0,0 @@
1
- export {};
@@ -1,4 +0,0 @@
1
- import type { SetSpotPriceRequestDataCommon, SetSpotPriceResponseDataCommon } from '../../common/endpoints/setSpotPrice.js';
2
- import type { ResponseData } from '../types.js';
3
- export type SetSpotPriceRequestData = SetSpotPriceRequestDataCommon;
4
- export type SetSpotPriceResponseData = SetSpotPriceResponseDataCommon & ResponseData;
@@ -1 +0,0 @@
1
- export {};
@@ -1,8 +0,0 @@
1
- import type { SpotMarketplaceResponseDataCommon } from '../../common/endpoints/spotMarketplace.js';
2
- import type { ResponseData } from '../types.js';
3
- export interface SpotMarketplaceRequestData {
4
- id: number;
5
- }
6
- export interface SpotMarketplaceResponseData extends ResponseData {
7
- data: SpotMarketplaceResponseDataCommon;
8
- }
@@ -1 +0,0 @@
1
- export {};
@@ -1,9 +0,0 @@
1
- import WebAPI from './WebAPI.js';
2
- export type * from './endpoints/cancelOrder.js';
3
- export type * from './endpoints/createOrder.js';
4
- export type * from './endpoints/marketplace.js';
5
- export type * from './endpoints/myOrders.js';
6
- export type * from './endpoints/setSpotPrice.js';
7
- export type * from './endpoints/spotMarketplace.js';
8
- export type * from './types.js';
9
- export default WebAPI;
@@ -1,2 +0,0 @@
1
- import WebAPI from './WebAPI.js';
2
- export default WebAPI;
@@ -1,7 +0,0 @@
1
- import type { CommonConfig, CommonResponseData } from '../common/types.js';
2
- export interface Config extends CommonConfig {
3
- token: string;
4
- }
5
- export interface ResponseData extends CommonResponseData {
6
- status: string;
7
- }
@@ -1 +0,0 @@
1
- export {};
package/build/webapi.d.ts DELETED
@@ -1,4 +0,0 @@
1
- import WebAPI from './webapi/index.js';
2
- export * from './common/index.js';
3
- export * from './webapi/index.js';
4
- export default WebAPI;
package/build/webapi.js DELETED
@@ -1,4 +0,0 @@
1
- import WebAPI from './webapi/index.js';
2
- export * from './common/index.js';
3
- export * from './webapi/index.js';
4
- export default WebAPI;
File without changes
File without changes
File without changes