cloreai 0.1.17 → 0.1.18

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.d.ts → cloreai/CloreAI.d.ts} +0 -1
  2. package/build/{CloreAI.js → cloreai/CloreAI.js} +18 -35
  3. package/build/cloreai/endpoints/cancelOrder.d.ts +6 -0
  4. package/build/{endpoints → cloreai/endpoints}/createGigaspotOrders.d.ts +2 -1
  5. package/build/cloreai/endpoints/createOrder.d.ts +4 -0
  6. package/build/{endpoints → cloreai/endpoints}/getGigaspot.d.ts +2 -1
  7. package/build/cloreai/endpoints/marketplace.d.ts +6 -0
  8. package/build/cloreai/endpoints/myOrders.d.ts +9 -0
  9. package/build/{endpoints → cloreai/endpoints}/myServers.d.ts +2 -1
  10. package/build/{endpoints → cloreai/endpoints}/serverConfig.d.ts +2 -1
  11. package/build/cloreai/endpoints/setSpotPrice.d.ts +4 -0
  12. package/build/cloreai/endpoints/spotMarketplace.d.ts +9 -0
  13. package/build/{endpoints → cloreai/endpoints}/wallets.d.ts +2 -1
  14. package/build/cloreai/index.d.ts +17 -0
  15. package/build/cloreai/index.js +2 -0
  16. package/build/cloreai/types.d.ts +7 -0
  17. package/build/cloreai/types.js +1 -0
  18. package/build/{constants.d.ts → common/constants.d.ts} +0 -4
  19. package/build/{constants.js → common/constants.js} +0 -4
  20. package/build/common/endpoints/cancelOrder.d.ts +3 -0
  21. package/build/{endpoints → common/endpoints}/createOrder.d.ts +2 -3
  22. package/build/common/endpoints/createOrder.js +1 -0
  23. package/build/common/endpoints/marketplace.d.ts +19 -0
  24. package/build/common/endpoints/marketplace.js +1 -0
  25. package/build/{endpoints → common/endpoints}/myOrders.d.ts +2 -9
  26. package/build/common/endpoints/myOrders.js +1 -0
  27. package/build/common/endpoints/setSpotPrice.d.ts +16 -0
  28. package/build/common/endpoints/setSpotPrice.js +2 -0
  29. package/build/common/endpoints/spotMarketplace.d.ts +19 -0
  30. package/build/common/endpoints/spotMarketplace.js +1 -0
  31. package/build/common/helpers.d.ts +6 -0
  32. package/build/common/helpers.js +25 -0
  33. package/build/common/index.d.ts +10 -0
  34. package/build/common/index.js +3 -0
  35. package/build/{types.d.ts → common/types.d.ts} +3 -5
  36. package/build/common/types.js +1 -0
  37. package/build/index.d.ts +3 -14
  38. package/build/index.js +3 -3
  39. package/build/webapi/WebAPI.d.ts +22 -0
  40. package/build/webapi/WebAPI.js +80 -0
  41. package/build/webapi/endpoints/cancelOrder.d.ts +6 -0
  42. package/build/webapi/endpoints/cancelOrder.js +1 -0
  43. package/build/webapi/endpoints/createOrder.d.ts +4 -0
  44. package/build/webapi/endpoints/createOrder.js +1 -0
  45. package/build/webapi/endpoints/marketplace.d.ts +10 -0
  46. package/build/webapi/endpoints/marketplace.js +1 -0
  47. package/build/webapi/endpoints/myOrders.d.ts +15 -0
  48. package/build/webapi/endpoints/myOrders.js +1 -0
  49. package/build/webapi/endpoints/setSpotPrice.d.ts +4 -0
  50. package/build/webapi/endpoints/setSpotPrice.js +1 -0
  51. package/build/webapi/endpoints/spotMarketplace.d.ts +8 -0
  52. package/build/webapi/endpoints/spotMarketplace.js +1 -0
  53. package/build/webapi/index.d.ts +9 -0
  54. package/build/webapi/index.js +2 -0
  55. package/build/webapi/types.d.ts +7 -0
  56. package/build/webapi/types.js +1 -0
  57. package/build/webapi.d.ts +4 -0
  58. package/build/webapi.js +4 -0
  59. package/package.json +15 -3
  60. package/build/endpoints/cancelOrder.d.ts +0 -6
  61. package/build/endpoints/marketplace.d.ts +0 -24
  62. package/build/endpoints/setSpotPrice.d.ts +0 -17
  63. package/build/endpoints/spotMarketplace.d.ts +0 -26
  64. /package/build/{endpoints → cloreai/endpoints}/cancelOrder.js +0 -0
  65. /package/build/{endpoints → cloreai/endpoints}/cancelOrders.d.ts +0 -0
  66. /package/build/{endpoints → cloreai/endpoints}/cancelOrders.js +0 -0
  67. /package/build/{endpoints → cloreai/endpoints}/createGigaspotOrders.js +0 -0
  68. /package/build/{endpoints → cloreai/endpoints}/createOrder.js +0 -0
  69. /package/build/{endpoints → cloreai/endpoints}/editGigaspotOrders.d.ts +0 -0
  70. /package/build/{endpoints → cloreai/endpoints}/editGigaspotOrders.js +0 -0
  71. /package/build/{endpoints → cloreai/endpoints}/getGigaspot.js +0 -0
  72. /package/build/{endpoints → cloreai/endpoints}/marketplace.js +0 -0
  73. /package/build/{endpoints → cloreai/endpoints}/myOrders.js +0 -0
  74. /package/build/{endpoints → cloreai/endpoints}/myServers.js +0 -0
  75. /package/build/{endpoints → cloreai/endpoints}/serverConfig.js +0 -0
  76. /package/build/{endpoints → cloreai/endpoints}/setServerSettings.d.ts +0 -0
  77. /package/build/{endpoints → cloreai/endpoints}/setServerSettings.js +0 -0
  78. /package/build/{endpoints/spotMarketplace.js → cloreai/endpoints/setSpotPrice.js} +0 -0
  79. /package/build/{endpoints/wallets.js → cloreai/endpoints/spotMarketplace.js} +0 -0
  80. /package/build/{types.js → cloreai/endpoints/wallets.js} +0 -0
  81. /package/build/{endpoints/setSpotPrice.js → common/endpoints/cancelOrder.js} +0 -0
  82. /package/build/{errors.d.ts → common/errors.d.ts} +0 -0
  83. /package/build/{errors.js → common/errors.js} +0 -0
@@ -20,7 +20,6 @@ declare class CloreAI {
20
20
  rateLimitQueue: PQueue;
21
21
  rateLimitQueueCreateOrder: PQueue;
22
22
  constructor(config: Config);
23
- private getQueueOptions;
24
23
  wallets(config?: AxiosRequestConfig): Promise<WalletsResponseData>;
25
24
  myServers(config?: AxiosRequestConfig): Promise<MyServersResponseData>;
26
25
  serverConfig(data: ServerConfigRequestData, config?: AxiosRequestConfig): Promise<ServerConfigResponseData>;
@@ -1,7 +1,8 @@
1
1
  import axios from 'axios';
2
2
  import PQueue from 'p-queue';
3
- import { priorityLevels, RATE_LIMIT, RATE_LIMIT_CREATE_ORDER, statusCodes } from './constants.js';
4
- import { DatabaseError, ExceededError, InvalidApiTokenError, InvalidEndpointError, InvalidInputDataError, OtherError, UnknownError } from './errors.js';
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';
5
6
  class CloreAI {
6
7
  axios;
7
8
  rateLimitQueue;
@@ -31,9 +32,7 @@ class CloreAI {
31
32
  if (response.data.code === statusCodes.NORMAL) {
32
33
  return response;
33
34
  }
34
- const errorMessage = response.data.error != null
35
- ? `Code "${response.status}", error "${response.data.error}"`
36
- : `Code "${response.status}"`;
35
+ const errorMessage = getErrorMessage(response.data.code, response.data.error);
37
36
  const axiosErrorParameters = [
38
37
  errorMessage,
39
38
  undefined,
@@ -59,80 +58,64 @@ class CloreAI {
59
58
  }
60
59
  });
61
60
  }
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
- }
78
61
  async wallets(config) {
79
62
  const response = await this.rateLimitQueue.add(async () => {
80
63
  return await this.axios.get('/wallets', config);
81
- }, this.getQueueOptions(priorityLevels.NORMAL, config));
64
+ }, getQueueOptions(priorityLevels.NORMAL, config));
82
65
  return response.data;
83
66
  }
84
67
  async myServers(config) {
85
68
  const response = await this.rateLimitQueue.add(async () => {
86
69
  return await this.axios.get('/my_servers', config);
87
- }, this.getQueueOptions(priorityLevels.NORMAL, config));
70
+ }, getQueueOptions(priorityLevels.NORMAL, config));
88
71
  return response.data;
89
72
  }
90
73
  async serverConfig(data, config) {
91
74
  const response = await this.rateLimitQueue.add(async () => {
92
75
  return await this.axios.get('/server_config', { ...config, data });
93
- }, this.getQueueOptions(priorityLevels.NORMAL, config));
76
+ }, getQueueOptions(priorityLevels.NORMAL, config));
94
77
  return response.data;
95
78
  }
96
79
  async marketplace(config) {
97
80
  const response = await this.rateLimitQueue.add(async () => {
98
81
  return await this.axios.get('/marketplace', config);
99
- }, this.getQueueOptions(priorityLevels.NORMAL, config));
82
+ }, getQueueOptions(priorityLevels.NORMAL, config));
100
83
  return response.data;
101
84
  }
102
85
  async myOrders(params, config) {
103
86
  const response = await this.rateLimitQueue.add(async () => {
104
87
  return await this.axios.get('/my_orders', { ...config, params });
105
- }, this.getQueueOptions(priorityLevels.NORMAL, config));
88
+ }, getQueueOptions(priorityLevels.NORMAL, config));
106
89
  return response.data;
107
90
  }
108
91
  async spotMarketplace(params, config) {
109
92
  const response = await this.rateLimitQueue.add(async () => {
110
93
  return await this.axios.get('/spot_marketplace', { ...config, params });
111
- }, this.getQueueOptions(priorityLevels.NORMAL, config));
94
+ }, getQueueOptions(priorityLevels.NORMAL, config));
112
95
  return response.data;
113
96
  }
114
97
  async setServerSettings(data, config) {
115
98
  const response = await this.rateLimitQueue.add(async () => {
116
99
  return await this.axios.post('/set_server_settings', data, config);
117
- }, this.getQueueOptions(priorityLevels.HIGH, config));
100
+ }, getQueueOptions(priorityLevels.HIGH, config));
118
101
  return response.data;
119
102
  }
120
103
  async setSpotPrice(data, config) {
121
104
  const response = await this.rateLimitQueue.add(async () => {
122
105
  return await this.axios.post('/set_spot_price', data, config);
123
- }, this.getQueueOptions(priorityLevels.HIGH, config));
106
+ }, getQueueOptions(priorityLevels.HIGH, config));
124
107
  return response.data;
125
108
  }
126
109
  async cancelOrder(data, config) {
127
110
  const response = await this.rateLimitQueue.add(async () => {
128
111
  return await this.axios.post('/cancel_order', data, config);
129
- }, this.getQueueOptions(priorityLevels.HIGH, config));
112
+ }, getQueueOptions(priorityLevels.HIGH, config));
130
113
  return response.data;
131
114
  }
132
115
  async createOrder(data, config) {
133
116
  const response = await this.rateLimitQueueCreateOrder.add(async () => {
134
117
  return await this.axios.post('/create_order', data, config);
135
- }, this.getQueueOptions(priorityLevels.HIGHEST, config));
118
+ }, getQueueOptions(priorityLevels.HIGHEST, config));
136
119
  return response.data;
137
120
  }
138
121
  async getGigaspot(config) {
@@ -143,24 +126,24 @@ class CloreAI {
143
126
  ...response.data,
144
127
  snapshot: snapshot.data,
145
128
  };
146
- }, this.getQueueOptions(priorityLevels.NORMAL, config));
129
+ }, getQueueOptions(priorityLevels.NORMAL, config));
147
130
  }
148
131
  async createGigaspotOrders(data, config) {
149
132
  const response = await this.rateLimitQueue.add(async () => {
150
133
  return await this.axios.post('/create_gigaspot_orders', data, config);
151
- }, this.getQueueOptions(priorityLevels.HIGH, config));
134
+ }, getQueueOptions(priorityLevels.HIGH, config));
152
135
  return response.data;
153
136
  }
154
137
  async editGigaspotOrders(data, config) {
155
138
  const response = await this.rateLimitQueue.add(async () => {
156
139
  return await this.axios.post('/edit_gigaspot_orders', data, config);
157
- }, this.getQueueOptions(priorityLevels.HIGH, config));
140
+ }, getQueueOptions(priorityLevels.HIGH, config));
158
141
  return response.data;
159
142
  }
160
143
  async cancelOrders(data, config) {
161
144
  const response = await this.rateLimitQueue.add(async () => {
162
145
  return await this.axios.post('/cancel_orders', data, config);
163
- }, this.getQueueOptions(priorityLevels.HIGH, config));
146
+ }, getQueueOptions(priorityLevels.HIGH, config));
164
147
  return response.data;
165
148
  }
166
149
  }
@@ -0,0 +1,6 @@
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 +1,5 @@
1
- import type { Currency, ResponseData } from '../types.js';
1
+ import type { Currency } from '../../common/types.js';
2
+ import type { ResponseData } from '../types.js';
2
3
  export interface CreateGigaspotOrdersRequestDataOrderOverclock {
3
4
  pl: number;
4
5
  core_lock?: number;
@@ -0,0 +1,4 @@
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,4 +1,5 @@
1
- import type { Currency, Pricing, ResponseData } from '../types.js';
1
+ import type { Currency, Pricing } from '../../common/types.js';
2
+ import type { ResponseData } from '../types.js';
2
3
  export interface GetGigaspotResponseDataSnapshotServerBid {
3
4
  owner: number;
4
5
  id: number;
@@ -0,0 +1,6 @@
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
+ }
@@ -0,0 +1,9 @@
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 +1,5 @@
1
- import type { Pricing, ResponseData, Specs, Visibility } from '../types.js';
1
+ import type { Pricing, Specs, Visibility } from '../../common/types.js';
2
+ import type { ResponseData } from '../types.js';
2
3
  export interface MyServersResponseDataServer {
3
4
  name: string;
4
5
  connected: boolean;
@@ -1,4 +1,5 @@
1
- import type { Pricing, ResponseData, Specs, Visibility } from '../types.js';
1
+ import type { Pricing, Specs, Visibility } from '../../common/types.js';
2
+ import type { ResponseData } from '../types.js';
2
3
  export interface ServerConfigRequestData {
3
4
  server_name: string;
4
5
  }
@@ -0,0 +1,4 @@
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;
@@ -0,0 +1,9 @@
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,4 +1,5 @@
1
- import type { Currency, ResponseData } from '../types.js';
1
+ import type { Currency } from '../../common/types.js';
2
+ import type { ResponseData } from '../types.js';
2
3
  export interface WalletsResponseDataWallet {
3
4
  name: Currency;
4
5
  deposit: string;
@@ -0,0 +1,17 @@
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;
@@ -0,0 +1,2 @@
1
+ import CloreAI from './CloreAI.js';
2
+ export default CloreAI;
@@ -0,0 +1,7 @@
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
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -14,7 +14,3 @@ 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,7 +14,3 @@ 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,3 @@
1
+ export interface CancelOrderRequestDataCommon {
2
+ id: number;
3
+ }
@@ -1,4 +1,4 @@
1
- import type { Currency, OrderType, ResponseData } from '../types.js';
1
+ import type { Currency, OrderType } from '../types.js';
2
2
  export interface CreateOrderRequestDataBase {
3
3
  type: OrderType;
4
4
  currency: Currency;
@@ -22,5 +22,4 @@ export interface CreateOrderRequestDataSpot extends CreateOrderRequestDataBase {
22
22
  type: 'spot';
23
23
  spotprice: number;
24
24
  }
25
- export type CreateOrderRequestData = CreateOrderRequestDataOnDemand | CreateOrderRequestDataSpot;
26
- export type CreateOrderResponseData = ResponseData;
25
+ export type CreateOrderRequestDataCommon = CreateOrderRequestDataOnDemand | CreateOrderRequestDataSpot;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,19 @@
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
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -1,8 +1,5 @@
1
- import type { Currency, ResponseData, Specs } from '../types.js';
2
- export interface MyOrdersRequestParams {
3
- return_completed?: boolean;
4
- }
5
- export interface MyOrdersResponseDataOrder {
1
+ import type { Currency, Specs } from '../types.js';
2
+ export interface MyOrdersResponseDataOrderCommon {
6
3
  auto_login: string;
7
4
  id: number;
8
5
  fee: number;
@@ -24,7 +21,3 @@ export interface MyOrdersResponseDataOrder {
24
21
  tcp_ports: string[];
25
22
  http_port: string;
26
23
  }
27
- export interface MyOrdersResponseData extends ResponseData {
28
- orders: MyOrdersResponseDataOrder[];
29
- limit: number;
30
- }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,16 @@
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;
@@ -0,0 +1,2 @@
1
+ /* RequestData */
2
+ export {};
@@ -0,0 +1,19 @@
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
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,6 @@
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
+ };
@@ -0,0 +1,25 @@
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
+ }
@@ -0,0 +1,10 @@
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';
@@ -0,0 +1,3 @@
1
+ export * from './constants.js';
2
+ export * from './errors.js';
3
+ export * from './helpers.js';
@@ -1,15 +1,13 @@
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 Config {
5
- apiKey: string;
4
+ export interface CommonConfig {
6
5
  axiosConfig?: CreateAxiosDefaults;
7
6
  rateLimitQueueOptions?: PQueueOptions;
8
7
  rateLimitQueueOptionsCreateOrder?: PQueueOptions;
9
8
  }
10
- export interface ResponseData {
11
- code: number;
12
- error?: string | null;
9
+ export interface CommonResponseData {
10
+ error?: string;
13
11
  }
14
12
  export type OrderType = 'on-demand' | 'spot';
15
13
  export type Visibility = 'public' | 'hidden';
@@ -0,0 +1 @@
1
+ export {};
package/build/index.d.ts CHANGED
@@ -1,15 +1,4 @@
1
- import CloreAI from './CloreAI.js';
2
- export * from './constants.js';
3
- export type * from './endpoints/cancelOrder.js';
4
- export type * from './endpoints/createOrder.js';
5
- export type * from './endpoints/marketplace.js';
6
- export type * from './endpoints/myOrders.js';
7
- export type * from './endpoints/myServers.js';
8
- export type * from './endpoints/serverConfig.js';
9
- export type * from './endpoints/setServerSettings.js';
10
- export type * from './endpoints/setSpotPrice.js';
11
- export type * from './endpoints/spotMarketplace.js';
12
- export type * from './endpoints/wallets.js';
13
- export * from './errors.js';
14
- export type * from './types.js';
1
+ import CloreAI from './cloreai/index.js';
2
+ export * from './cloreai/index.js';
3
+ export * from './common/index.js';
15
4
  export default CloreAI;
package/build/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import CloreAI from './CloreAI.js';
2
- export * from './constants.js';
3
- export * from './errors.js';
1
+ import CloreAI from './cloreai/index.js';
2
+ export * from './cloreai/index.js';
3
+ export * from './common/index.js';
4
4
  export default CloreAI;
@@ -0,0 +1,22 @@
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;
@@ -0,0 +1,80 @@
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;
@@ -0,0 +1,6 @@
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;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,4 @@
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;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,10 @@
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
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,15 @@
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
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,4 @@
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;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,8 @@
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
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,9 @@
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;
@@ -0,0 +1,2 @@
1
+ import WebAPI from './WebAPI.js';
2
+ export default WebAPI;
@@ -0,0 +1,7 @@
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
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,4 @@
1
+ import WebAPI from './webapi/index.js';
2
+ export * from './common/index.js';
3
+ export * from './webapi/index.js';
4
+ export default WebAPI;
@@ -0,0 +1,4 @@
1
+ import WebAPI from './webapi/index.js';
2
+ export * from './common/index.js';
3
+ export * from './webapi/index.js';
4
+ export default WebAPI;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cloreai",
3
- "version": "0.1.17",
3
+ "version": "0.1.18",
4
4
  "type": "module",
5
5
  "description": "CLORE.AI API client",
6
6
  "repository": {
@@ -9,8 +9,20 @@
9
9
  },
10
10
  "author": "Vladislav Puzyrev",
11
11
  "license": "MIT",
12
- "main": "build/index.js",
13
- "types": "build/index.d.ts",
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
+ },
14
26
  "keywords": [
15
27
  "cloreai",
16
28
  "clore",
@@ -1,6 +0,0 @@
1
- import type { ResponseData } from '../types.js';
2
- export interface CancelOrderRequestData {
3
- id: number;
4
- issue?: string;
5
- }
6
- export type CancelOrderResponseData = ResponseData;
@@ -1,24 +0,0 @@
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,17 +0,0 @@
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;
@@ -1,26 +0,0 @@
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
- }
File without changes
File without changes