cloreai 0.1.6 → 0.1.8

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 (70) hide show
  1. package/build/{CloreAI.d.ts → cloreai/CloreAI.d.ts} +12 -12
  2. package/build/cloreai/CloreAI.js +86 -0
  3. package/build/{types/cloreai → cloreai/endpoints}/cancelOrder.d.ts +1 -1
  4. package/build/{types/cloreai → cloreai/endpoints}/createOrder.d.ts +2 -2
  5. package/build/{types/cloreai → cloreai/endpoints}/marketplace.d.ts +2 -2
  6. package/build/{types/cloreai → cloreai/endpoints}/myOrders.d.ts +2 -2
  7. package/build/{types/cloreai → cloreai/endpoints}/myServers.d.ts +2 -2
  8. package/build/{types/cloreai → cloreai/endpoints}/serverConfig.d.ts +2 -2
  9. package/build/{types/cloreai → cloreai/endpoints}/setServerSettings.d.ts +1 -1
  10. package/build/{types/cloreai → cloreai/endpoints}/setSpotPrice.d.ts +1 -1
  11. package/build/{types/cloreai → cloreai/endpoints}/spotMarketplace.d.ts +2 -2
  12. package/build/{types/cloreai → cloreai/endpoints}/wallets.d.ts +2 -2
  13. package/build/cloreai/index.d.ts +12 -0
  14. package/build/cloreai/index.js +12 -0
  15. package/build/cloreai/types.d.ts +7 -0
  16. package/build/common/constants.d.ts +11 -0
  17. package/build/{errors.d.ts → common/errors.d.ts} +1 -1
  18. package/build/{getErrorMessage.js → common/getErrorMessage.js} +4 -1
  19. package/build/common/index.d.ts +5 -0
  20. package/build/common/index.js +5 -0
  21. package/build/common/types.d.ts +8 -0
  22. package/build/index.d.ts +4 -23
  23. package/build/index.js +4 -23
  24. package/build/webapi/WebAPI.d.ts +18 -0
  25. package/build/{WebAPI.js → webapi/WebAPI.js} +12 -12
  26. package/build/webapi/endpoints/cancelOrder.d.ts +7 -0
  27. package/build/webapi/endpoints/createOrder.d.ts +25 -0
  28. package/build/webapi/endpoints/getSpot.d.ts +26 -0
  29. package/build/{types/webapi → webapi/endpoints}/orders.d.ts +6 -6
  30. package/build/{types/webapi → webapi/endpoints}/servers.d.ts +7 -7
  31. package/build/webapi/endpoints/setSpotPrice.d.ts +17 -0
  32. package/build/webapi/index.d.ts +8 -0
  33. package/build/webapi/index.js +8 -0
  34. package/build/webapi/types.d.ts +7 -0
  35. package/build/webapi/types.js +1 -0
  36. package/build/webapi.d.ts +4 -0
  37. package/build/webapi.js +4 -0
  38. package/package.json +24 -16
  39. package/build/CloreAI.js +0 -80
  40. package/build/WebAPI.d.ts +0 -18
  41. package/build/constants.d.ts +0 -3
  42. package/build/types/config.d.ts +0 -10
  43. package/build/types/output.d.ts +0 -9
  44. package/build/types/webapi/cancelOrder.d.ts +0 -7
  45. package/build/types/webapi/createOrder.d.ts +0 -25
  46. package/build/types/webapi/getSpot.d.ts +0 -26
  47. package/build/types/webapi/setSpotPrice.d.ts +0 -17
  48. /package/build/{types/cloreai → cloreai/endpoints}/cancelOrder.js +0 -0
  49. /package/build/{types/cloreai → cloreai/endpoints}/createOrder.js +0 -0
  50. /package/build/{types/cloreai → cloreai/endpoints}/marketplace.js +0 -0
  51. /package/build/{types/cloreai → cloreai/endpoints}/myOrders.js +0 -0
  52. /package/build/{types/cloreai → cloreai/endpoints}/myServers.js +0 -0
  53. /package/build/{types/cloreai → cloreai/endpoints}/serverConfig.js +0 -0
  54. /package/build/{types/cloreai → cloreai/endpoints}/setServerSettings.js +0 -0
  55. /package/build/{types/cloreai → cloreai/endpoints}/setSpotPrice.js +0 -0
  56. /package/build/{types/cloreai → cloreai/endpoints}/spotMarketplace.js +0 -0
  57. /package/build/{types/cloreai → cloreai/endpoints}/wallets.js +0 -0
  58. /package/build/{types/common.js → cloreai/types.js} +0 -0
  59. /package/build/{types/common.d.ts → common/api.d.ts} +0 -0
  60. /package/build/{types/config.js → common/api.js} +0 -0
  61. /package/build/{constants.js → common/constants.js} +0 -0
  62. /package/build/{errors.js → common/errors.js} +0 -0
  63. /package/build/{getErrorMessage.d.ts → common/getErrorMessage.d.ts} +0 -0
  64. /package/build/{types/output.js → common/types.js} +0 -0
  65. /package/build/{types/webapi → webapi/endpoints}/cancelOrder.js +0 -0
  66. /package/build/{types/webapi → webapi/endpoints}/createOrder.js +0 -0
  67. /package/build/{types/webapi → webapi/endpoints}/getSpot.js +0 -0
  68. /package/build/{types/webapi → webapi/endpoints}/orders.js +0 -0
  69. /package/build/{types/webapi → webapi/endpoints}/servers.js +0 -0
  70. /package/build/{types/webapi → webapi/endpoints}/setSpotPrice.js +0 -0
@@ -1,17 +1,17 @@
1
1
  import { type AxiosInstance, type AxiosRequestConfig } from 'axios';
2
- import type { CancelOrderBody, CancelOrderOutput } from './types/cloreai/cancelOrder.js';
3
- import type { CreateOrderBody, CreateOrderOutput } from './types/cloreai/createOrder.js';
4
- import type { MarketplaceOutput } from './types/cloreai/marketplace.js';
5
- import type { MyOrdersOutput, MyOrdersParams } from './types/cloreai/myOrders.js';
6
- import type { MyServersOutput } from './types/cloreai/myServers.js';
7
- import type { ServerConfigBody, ServerConfigOutput } from './types/cloreai/serverConfig.js';
8
- import type { SetServerSettingsBody, SetServerSettingsOutput } from './types/cloreai/setServerSettings.js';
9
- import type { SetSpotPriceBody, SetSpotPriceOutput } from './types/cloreai/setSpotPrice.js';
10
- import type { SpotMarketplaceOutput, SpotMarketplaceParams } from './types/cloreai/spotMarketplace.js';
11
- import type { WalletsOutput } from './types/cloreai/wallets.js';
12
- import type { Config } from './types/config.js';
2
+ import type { CancelOrderBody, CancelOrderOutput } from './endpoints/cancelOrder.js';
3
+ import type { CreateOrderBody, CreateOrderOutput } from './endpoints/createOrder.js';
4
+ import type { MarketplaceOutput } from './endpoints/marketplace.js';
5
+ import type { MyOrdersOutput, MyOrdersParams } from './endpoints/myOrders.js';
6
+ import type { MyServersOutput } from './endpoints/myServers.js';
7
+ import type { ServerConfigBody, ServerConfigOutput } from './endpoints/serverConfig.js';
8
+ import type { SetServerSettingsBody, SetServerSettingsOutput } from './endpoints/setServerSettings.js';
9
+ import type { SetSpotPriceBody, SetSpotPriceOutput } from './endpoints/setSpotPrice.js';
10
+ import type { SpotMarketplaceOutput, SpotMarketplaceParams } from './endpoints/spotMarketplace.js';
11
+ import type { WalletsOutput } from './endpoints/wallets.js';
12
+ import type { Config } from './types.js';
13
13
  export declare class CloreAI {
14
- readonly api: AxiosInstance;
14
+ readonly axios: AxiosInstance;
15
15
  constructor(config: Config);
16
16
  wallets(config?: AxiosRequestConfig): Promise<WalletsOutput>;
17
17
  myServers(config?: AxiosRequestConfig): Promise<MyServersOutput>;
@@ -0,0 +1,86 @@
1
+ import axios from 'axios';
2
+ import { CustomError, DatabaseError, ExceededError, InvalidApiTokenError, InvalidEndpointError, InvalidInputDataError, UnknownError } from '../common/errors.js';
3
+ import { getErrorMessage, statusCodes } from '../common/index.js';
4
+ export class CloreAI {
5
+ axios;
6
+ constructor(config) {
7
+ const { apiKey, axiosConfig = {} } = config;
8
+ this.axios = axios.create({
9
+ ...axiosConfig,
10
+ baseURL: 'https://api.clore.ai/v1',
11
+ headers: {
12
+ ...axiosConfig.headers,
13
+ auth: apiKey,
14
+ },
15
+ });
16
+ this.axios.interceptors.response.use((response) => {
17
+ if (response.data.code === statusCodes.NORMAL) {
18
+ return response;
19
+ }
20
+ const errorMessage = getErrorMessage(response.data.code, response.data.error);
21
+ const axiosErrorParameters = [
22
+ errorMessage,
23
+ undefined,
24
+ response.config,
25
+ response.request,
26
+ response,
27
+ ];
28
+ switch (response.data.code) {
29
+ case statusCodes.DATABASE_ERROR:
30
+ throw new DatabaseError(...axiosErrorParameters);
31
+ case statusCodes.INVALID_INPUT_DATA:
32
+ throw new InvalidInputDataError(...axiosErrorParameters);
33
+ case statusCodes.INVALID_API_TOKEN:
34
+ throw new InvalidApiTokenError(...axiosErrorParameters);
35
+ case statusCodes.INVALID_ENDPOINT:
36
+ throw new InvalidEndpointError(...axiosErrorParameters);
37
+ case statusCodes.EXCEEDED:
38
+ throw new ExceededError(...axiosErrorParameters);
39
+ case statusCodes.ERROR:
40
+ throw new CustomError(...axiosErrorParameters);
41
+ default:
42
+ throw new UnknownError(...axiosErrorParameters);
43
+ }
44
+ });
45
+ }
46
+ async wallets(config) {
47
+ const response = await this.axios.get('/wallets', config);
48
+ return response.data;
49
+ }
50
+ async myServers(config) {
51
+ const response = await this.axios.get('/my_servers', config);
52
+ return response.data;
53
+ }
54
+ async serverConfig(body, config) {
55
+ const response = await this.axios.get('/server_config', { ...config, data: body });
56
+ return response.data;
57
+ }
58
+ async marketplace(config) {
59
+ const response = await this.axios.get('/marketplace', config);
60
+ return response.data;
61
+ }
62
+ async myOrders(params, config) {
63
+ const response = await this.axios.get('/my_orders', { ...config, params });
64
+ return response.data;
65
+ }
66
+ async spotMarketplace(params, config) {
67
+ const response = await this.axios.get('/spot_marketplace', { ...config, params });
68
+ return response.data;
69
+ }
70
+ async setServerSettings(body, config) {
71
+ const response = await this.axios.post('/set_server_settings', body, config);
72
+ return response.data;
73
+ }
74
+ async setSpotPrice(body, config) {
75
+ const response = await this.axios.post('/set_spot_price', body, config);
76
+ return response.data;
77
+ }
78
+ async cancelOrder(body, config) {
79
+ const response = await this.axios.post('/cancel_order', body, config);
80
+ return response.data;
81
+ }
82
+ async createOrder(body, config) {
83
+ const response = await this.axios.post('/create_order', body, config);
84
+ return response.data;
85
+ }
86
+ }
@@ -1,4 +1,4 @@
1
- import type { Output } from '../output.js';
1
+ import type { Output } from '../types.js';
2
2
  export interface CancelOrderBody {
3
3
  id: number;
4
4
  issue?: string;
@@ -1,5 +1,5 @@
1
- import type { Currency } from '../common.js';
2
- import type { Output } from '../output.js';
1
+ import type { Currency } from '../../common/index.js';
2
+ import type { Output } from '../types.js';
3
3
  export interface CreateOrderCommon {
4
4
  currency: Currency;
5
5
  image: string;
@@ -1,5 +1,5 @@
1
- import type { Price, Specs } from '../common.js';
2
- import type { Output } from '../output.js';
1
+ import type { Price, Specs } from '../../common/index.js';
2
+ import type { Output } from '../types.js';
3
3
  export interface MarketplaceServer {
4
4
  id: number;
5
5
  owner: number;
@@ -1,5 +1,5 @@
1
- import type { Currency, Specs } from '../common.js';
2
- import type { Output } from '../output.js';
1
+ import type { Currency, Specs } from '../../common/index.js';
2
+ import type { Output } from '../types.js';
3
3
  export interface MyOrdersParams {
4
4
  return_completed?: boolean;
5
5
  }
@@ -1,5 +1,5 @@
1
- import type { Pricing, Specs, Visibility } from '../common.js';
2
- import type { Output } from '../output.js';
1
+ import type { Pricing, Specs, Visibility } from '../../common/index.js';
2
+ import type { Output } from '../types.js';
3
3
  export interface MyServersServer {
4
4
  name: string;
5
5
  connected: boolean;
@@ -1,5 +1,5 @@
1
- import type { Pricing, Specs, Visibility } from '../common.js';
2
- import type { Output } from '../output.js';
1
+ import type { Pricing, Specs, Visibility } from '../../common/index.js';
2
+ import type { Output } from '../types.js';
3
3
  export interface ServerConfigBody {
4
4
  server_name: string;
5
5
  }
@@ -1,4 +1,4 @@
1
- import type { Output } from '../output.js';
1
+ import type { Output } from '../types.js';
2
2
  export interface SetServerSettingsBody {
3
3
  name: string;
4
4
  availability: boolean;
@@ -1,4 +1,4 @@
1
- import type { Output } from '../output.js';
1
+ import type { Output } from '../types.js';
2
2
  export interface SetSpotPriceBody {
3
3
  order_id: number;
4
4
  desired_price: number;
@@ -1,5 +1,5 @@
1
- import type { Pricing, Visibility } from '../common.js';
2
- import type { Output } from '../output.js';
1
+ import type { Pricing, Visibility } from '../../common/index.js';
2
+ import type { Output } from '../types.js';
3
3
  export interface SpotMarketplaceParams {
4
4
  market: number;
5
5
  }
@@ -1,5 +1,5 @@
1
- import type { Currency } from '../common.js';
2
- import type { Output } from '../output.js';
1
+ import type { Currency } from '../../common/index.js';
2
+ import type { Output } from '../types.js';
3
3
  export interface WalletsWallet {
4
4
  name: Currency;
5
5
  deposit: string;
@@ -0,0 +1,12 @@
1
+ export { CloreAI as default } from './CloreAI.js';
2
+ export * from './endpoints/cancelOrder.js';
3
+ export * from './endpoints/createOrder.js';
4
+ export * from './endpoints/marketplace.js';
5
+ export * from './endpoints/myOrders.js';
6
+ export * from './endpoints/myServers.js';
7
+ export * from './endpoints/serverConfig.js';
8
+ export * from './endpoints/setServerSettings.js';
9
+ export * from './endpoints/setSpotPrice.js';
10
+ export * from './endpoints/spotMarketplace.js';
11
+ export * from './endpoints/wallets.js';
12
+ export * from './types.js';
@@ -0,0 +1,12 @@
1
+ export { CloreAI as default } from './CloreAI.js';
2
+ export * from './endpoints/cancelOrder.js';
3
+ export * from './endpoints/createOrder.js';
4
+ export * from './endpoints/marketplace.js';
5
+ export * from './endpoints/myOrders.js';
6
+ export * from './endpoints/myServers.js';
7
+ export * from './endpoints/serverConfig.js';
8
+ export * from './endpoints/setServerSettings.js';
9
+ export * from './endpoints/setSpotPrice.js';
10
+ export * from './endpoints/spotMarketplace.js';
11
+ export * from './endpoints/wallets.js';
12
+ export * from './types.js';
@@ -0,0 +1,7 @@
1
+ import type { CommonConfig, CommonOutput } from '../common/types.js';
2
+ export interface Config extends CommonConfig {
3
+ apiKey: string;
4
+ }
5
+ export interface Output<T = string> extends CommonOutput<T> {
6
+ code: number;
7
+ }
@@ -0,0 +1,11 @@
1
+ export declare const GLOBAL_RATE_LIMIT = 1000;
2
+ export declare const CREATE_ORDER_RATE_LIMIT = 5000;
3
+ export declare const statusCodes: {
4
+ NORMAL: number;
5
+ DATABASE_ERROR: number;
6
+ INVALID_INPUT_DATA: number;
7
+ INVALID_API_TOKEN: number;
8
+ INVALID_ENDPOINT: number;
9
+ EXCEEDED: number;
10
+ ERROR: number;
11
+ };
@@ -1,5 +1,5 @@
1
1
  import { AxiosError } from 'axios';
2
- export type AxiosErrorParameters = ConstructorParameters<typeof AxiosError>;
2
+ import type { AxiosErrorParameters } from './types.js';
3
3
  export declare class DatabaseError extends AxiosError {
4
4
  constructor(...args: AxiosErrorParameters);
5
5
  }
@@ -1,7 +1,10 @@
1
1
  export function getErrorMessage(statusCode, errorField) {
2
2
  const statusCodeMessage = statusCode != null ? `Status code "${statusCode}".` : null;
3
3
  const errorFieldMessage = errorField != null ? `Error field "${errorField}".` : null;
4
- const errorMessageArray = [statusCodeMessage, errorFieldMessage].filter((message) => {
4
+ const errorMessageArray = [
5
+ statusCodeMessage,
6
+ errorFieldMessage,
7
+ ].filter((message) => {
5
8
  return message != null;
6
9
  });
7
10
  return errorMessageArray.join(' ');
@@ -0,0 +1,5 @@
1
+ export * from './api.js';
2
+ export * from './constants.js';
3
+ export * from './errors.js';
4
+ export * from './getErrorMessage.js';
5
+ export * from './types.js';
@@ -0,0 +1,5 @@
1
+ export * from './api.js';
2
+ export * from './constants.js';
3
+ export * from './errors.js';
4
+ export * from './getErrorMessage.js';
5
+ export * from './types.js';
@@ -0,0 +1,8 @@
1
+ import type { AxiosError, CreateAxiosDefaults } from 'axios';
2
+ export type AxiosErrorParameters = ConstructorParameters<typeof AxiosError>;
3
+ export interface CommonConfig {
4
+ axiosConfig?: CreateAxiosDefaults;
5
+ }
6
+ export interface CommonOutput<T = string> {
7
+ error?: T | undefined;
8
+ }
package/build/index.d.ts CHANGED
@@ -1,23 +1,4 @@
1
- export { CloreAI as default } from './CloreAI.js';
2
- export * from './constants.js';
3
- export * from './errors.js';
4
- export * from './types/cloreai/cancelOrder.js';
5
- export * from './types/cloreai/createOrder.js';
6
- export * from './types/cloreai/marketplace.js';
7
- export * from './types/cloreai/myOrders.js';
8
- export * from './types/cloreai/myServers.js';
9
- export * from './types/cloreai/serverConfig.js';
10
- export * from './types/cloreai/setServerSettings.js';
11
- export * from './types/cloreai/setSpotPrice.js';
12
- export * from './types/cloreai/spotMarketplace.js';
13
- export * from './types/cloreai/wallets.js';
14
- export * from './types/common.js';
15
- export * from './types/config.js';
16
- export * from './types/output.js';
17
- export * from './types/webapi/cancelOrder.js';
18
- export * from './types/webapi/createOrder.js';
19
- export * from './types/webapi/getSpot.js';
20
- export * from './types/webapi/orders.js';
21
- export * from './types/webapi/servers.js';
22
- export * from './types/webapi/setSpotPrice.js';
23
- export * from './WebAPI.js';
1
+ import CloreAI from './cloreai/index.js';
2
+ export * from './cloreai/index.js';
3
+ export * from './common/index.js';
4
+ export default CloreAI;
package/build/index.js CHANGED
@@ -1,23 +1,4 @@
1
- export { CloreAI as default } from './CloreAI.js';
2
- export * from './constants.js';
3
- export * from './errors.js';
4
- export * from './types/cloreai/cancelOrder.js';
5
- export * from './types/cloreai/createOrder.js';
6
- export * from './types/cloreai/marketplace.js';
7
- export * from './types/cloreai/myOrders.js';
8
- export * from './types/cloreai/myServers.js';
9
- export * from './types/cloreai/serverConfig.js';
10
- export * from './types/cloreai/setServerSettings.js';
11
- export * from './types/cloreai/setSpotPrice.js';
12
- export * from './types/cloreai/spotMarketplace.js';
13
- export * from './types/cloreai/wallets.js';
14
- export * from './types/common.js';
15
- export * from './types/config.js';
16
- export * from './types/output.js';
17
- export * from './types/webapi/cancelOrder.js';
18
- export * from './types/webapi/createOrder.js';
19
- export * from './types/webapi/getSpot.js';
20
- export * from './types/webapi/orders.js';
21
- export * from './types/webapi/servers.js';
22
- export * from './types/webapi/setSpotPrice.js';
23
- export * from './WebAPI.js';
1
+ import CloreAI from './cloreai/index.js';
2
+ export * from './cloreai/index.js';
3
+ export * from './common/index.js';
4
+ export default CloreAI;
@@ -0,0 +1,18 @@
1
+ import { type AxiosInstance, type AxiosRequestConfig } from 'axios';
2
+ import type { CancelOrderBody, CancelOrderOutput } from './endpoints/cancelOrder.js';
3
+ import type { CreateOrderBody, CreateOrderOutput } from './endpoints/createOrder.js';
4
+ import type { GetSpotBody, GetSpotOutput } from './endpoints/getSpot.js';
5
+ import type { OrdersBody, OrdersOutput } from './endpoints/orders.js';
6
+ import type { ServersOutput } from './endpoints/servers.js';
7
+ import type { SetSpotPriceBody, SetSpotPriceOutput } from './endpoints/setSpotPrice.js';
8
+ import type { Config } from './types.js';
9
+ export declare class WebAPI {
10
+ readonly axios: AxiosInstance;
11
+ constructor(config: Config);
12
+ servers(config?: AxiosRequestConfig): Promise<ServersOutput>;
13
+ orders(body: OrdersBody, config?: AxiosRequestConfig<OrdersBody>): Promise<OrdersOutput>;
14
+ getSpot(body: GetSpotBody, config?: AxiosRequestConfig<GetSpotBody>): Promise<GetSpotOutput>;
15
+ setSpotPrice(body: SetSpotPriceBody, config?: AxiosRequestConfig<SetSpotPriceBody>): Promise<SetSpotPriceOutput>;
16
+ cancelOrder(body: CancelOrderBody, config?: AxiosRequestConfig<CancelOrderBody>): Promise<CancelOrderOutput>;
17
+ createOrder(body: CreateOrderBody, config?: AxiosRequestConfig<CreateOrderBody>): Promise<CreateOrderOutput>;
18
+ }
@@ -1,22 +1,22 @@
1
1
  import axios from 'axios';
2
- import { UnknownError } from './errors.js';
3
- import { getErrorMessage } from './getErrorMessage.js';
2
+ import { UnknownError } from '../common/errors.js';
3
+ import { getErrorMessage } from '../common/index.js';
4
4
  export class WebAPI {
5
- api;
5
+ axios;
6
6
  constructor(config) {
7
7
  const { token, axiosConfig = {} } = config;
8
- this.api = axios.create({
8
+ this.axios = axios.create({
9
9
  ...axiosConfig,
10
10
  baseURL: 'https://clore.ai/webapi',
11
11
  });
12
- this.api.interceptors.request.use((request) => {
12
+ this.axios.interceptors.request.use((request) => {
13
13
  request.data = {
14
14
  ...request.data,
15
15
  token,
16
16
  };
17
17
  return request;
18
18
  });
19
- this.api.interceptors.response.use((response) => {
19
+ this.axios.interceptors.response.use((response) => {
20
20
  const hasError = Boolean(response.data.error);
21
21
  if (!hasError) {
22
22
  return response;
@@ -26,27 +26,27 @@ export class WebAPI {
26
26
  });
27
27
  }
28
28
  async servers(config) {
29
- const response = await this.api.post('/marketplace/servers', null, config);
29
+ const response = await this.axios.post('/marketplace/servers', null, config);
30
30
  return response.data;
31
31
  }
32
32
  async orders(body, config) {
33
- const response = await this.api.post('/marketplace/orders', body, config);
33
+ const response = await this.axios.post('/marketplace/orders', body, config);
34
34
  return response.data;
35
35
  }
36
36
  async getSpot(body, config) {
37
- const response = await this.api.post('/marketplace/get_spot', body, config);
37
+ const response = await this.axios.post('/marketplace/get_spot', body, config);
38
38
  return response.data;
39
39
  }
40
40
  async setSpotPrice(body, config) {
41
- const response = await this.api.post('/marketplace/set_spot_price', body, config);
41
+ const response = await this.axios.post('/marketplace/set_spot_price', body, config);
42
42
  return response.data;
43
43
  }
44
44
  async cancelOrder(body, config) {
45
- const response = await this.api.post('/marketplace/cancel_order', body, config);
45
+ const response = await this.axios.post('/marketplace/cancel_order', body, config);
46
46
  return response.data;
47
47
  }
48
48
  async createOrder(body, config) {
49
- const response = await this.api.post('/create_order', body, config);
49
+ const response = await this.axios.post('/create_order', body, config);
50
50
  return response.data;
51
51
  }
52
52
  }
@@ -0,0 +1,7 @@
1
+ import type { Output } from '../types.js';
2
+ export interface CancelOrderBody {
3
+ id: number;
4
+ rating: number;
5
+ }
6
+ export interface CancelOrderOutput extends Output {
7
+ }
@@ -0,0 +1,25 @@
1
+ import type { Currency } from '../../common/index.js';
2
+ import type { Output } from '../types.js';
3
+ export interface CreateOrderCommon {
4
+ currency: Currency;
5
+ image: string;
6
+ renting_server: number;
7
+ ports?: Record<string, string>;
8
+ env?: Record<string, string>;
9
+ jupyter_token?: string;
10
+ ssh_key?: string;
11
+ ssh_password?: string;
12
+ command?: string;
13
+ required_price?: number;
14
+ autossh_entrypoint?: boolean;
15
+ }
16
+ export interface CreateOrderOnDemand extends CreateOrderCommon {
17
+ type: 'on-demand';
18
+ }
19
+ export interface CreateOrderSpot extends CreateOrderCommon {
20
+ type: 'spot';
21
+ spotprice: number;
22
+ }
23
+ export type CreateOrderBody = CreateOrderOnDemand | CreateOrderSpot;
24
+ export interface CreateOrderOutput extends Output {
25
+ }
@@ -0,0 +1,26 @@
1
+ import type { Currency, Pricing, Visibility } from '../../common/index.js';
2
+ import type { Output } from '../types.js';
3
+ export interface GetSpotBody {
4
+ id: number;
5
+ }
6
+ export interface GetSpotDataOffer {
7
+ offer_id: number;
8
+ bid: number;
9
+ active: boolean;
10
+ my: boolean;
11
+ currency: Currency;
12
+ }
13
+ export interface GetSpotDataServer {
14
+ min_pricing: Pricing;
15
+ mrl: number;
16
+ visibility: Visibility;
17
+ online: boolean;
18
+ }
19
+ export interface GetSpotData {
20
+ currency_rates_in_usd: Pricing;
21
+ offers: GetSpotDataOffer[];
22
+ server: GetSpotDataServer;
23
+ }
24
+ export interface GetSpotOutput extends Output {
25
+ data: GetSpotData;
26
+ }
@@ -1,9 +1,9 @@
1
- import type { Currency, Price, Specs } from '../common.js';
2
- import type { WebOutput } from '../output.js';
3
- export interface WebOrdersBody {
1
+ import type { Currency, Price, Specs } from '../../common/index.js';
2
+ import type { Output } from '../types.js';
3
+ export interface OrdersBody {
4
4
  rc: boolean;
5
5
  }
6
- export interface WebOrdersOrder {
6
+ export interface OrdersOrder {
7
7
  id: number;
8
8
  fee: number;
9
9
  creation_fee: number;
@@ -23,8 +23,8 @@ export interface WebOrdersOrder {
23
23
  tcp_ports: string[];
24
24
  http_port: string;
25
25
  }
26
- export interface WebOrdersOutput extends WebOutput {
27
- orders: WebOrdersOrder[];
26
+ export interface OrdersOutput extends Output {
27
+ orders: OrdersOrder[];
28
28
  ol: number;
29
29
  eo: boolean;
30
30
  http_endpoint_by_proxy: Record<string, string>;
@@ -1,10 +1,10 @@
1
- import type { Currency, Price, Specs } from '../common.js';
2
- import type { WebOutput } from '../output.js';
3
- export interface WebServersServerRating {
1
+ import type { Currency, Price, Specs } from '../../common/index.js';
2
+ import type { Output } from '../types.js';
3
+ export interface ServersServerRating {
4
4
  avg: number;
5
5
  cnt: number;
6
6
  }
7
- export interface WebServersServer {
7
+ export interface ServersServer {
8
8
  id: number;
9
9
  owner: number;
10
10
  mrl: number;
@@ -13,11 +13,11 @@ export interface WebServersServer {
13
13
  specs: Specs;
14
14
  reliability: number;
15
15
  allowed_coins: Currency[];
16
- rating: WebServersServerRating;
16
+ rating: ServersServerRating;
17
17
  cuda_version: string;
18
18
  }
19
- export interface WebServersOutput extends WebOutput {
20
- all_servers: WebServersServer[];
19
+ export interface ServersOutput extends Output {
20
+ all_servers: ServersServer[];
21
21
  creation_fees: number;
22
22
  disable_usd: number;
23
23
  my_servers: number;
@@ -0,0 +1,17 @@
1
+ import type { Output } from '../types.js';
2
+ export interface SetSpotPriceBody {
3
+ desired_price: number;
4
+ order_id: number;
5
+ }
6
+ export interface SetSpotPriceMaxStep extends Output {
7
+ error: 'exceeded_max_step';
8
+ max_step: number;
9
+ }
10
+ export interface SetSpotPriceTimeToLowering extends Output {
11
+ error: 'can_lower_every_600_seconds';
12
+ time_to_lowering: number;
13
+ }
14
+ export interface SetSpotPriceSuccess extends Output {
15
+ error: undefined;
16
+ }
17
+ export type SetSpotPriceOutput = SetSpotPriceMaxStep | SetSpotPriceTimeToLowering | SetSpotPriceSuccess;
@@ -0,0 +1,8 @@
1
+ export * from './endpoints/cancelOrder.js';
2
+ export * from './endpoints/createOrder.js';
3
+ export * from './endpoints/getSpot.js';
4
+ export * from './endpoints/orders.js';
5
+ export * from './endpoints/servers.js';
6
+ export * from './endpoints/setSpotPrice.js';
7
+ export * from './types.js';
8
+ export { WebAPI as default } from './WebAPI.js';
@@ -0,0 +1,8 @@
1
+ export * from './endpoints/cancelOrder.js';
2
+ export * from './endpoints/createOrder.js';
3
+ export * from './endpoints/getSpot.js';
4
+ export * from './endpoints/orders.js';
5
+ export * from './endpoints/servers.js';
6
+ export * from './endpoints/setSpotPrice.js';
7
+ export * from './types.js';
8
+ export { WebAPI as default } from './WebAPI.js';
@@ -0,0 +1,7 @@
1
+ import type { CommonConfig, CommonOutput } from '../common/types.js';
2
+ export interface Config extends CommonConfig {
3
+ token: string;
4
+ }
5
+ export interface Output<T = string> extends CommonOutput<T> {
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,21 +1,29 @@
1
1
  {
2
2
  "name": "cloreai",
3
- "version": "0.1.6",
3
+ "version": "0.1.8",
4
+ "type": "module",
4
5
  "description": "CLORE.AI API client",
5
- "keywords": [
6
- "cloreai",
7
- "clore",
8
- "api"
9
- ],
10
6
  "repository": {
11
7
  "type": "git",
12
8
  "url": "git+https://github.com/vladpuz/cloreai.git"
13
9
  },
14
- "license": "MIT",
15
10
  "author": "Vladislav Puzyrev",
16
- "type": "module",
17
- "main": "build/index.js",
18
- "types": "build/index.d.ts",
11
+ "license": "MIT",
12
+ "exports": {
13
+ ".": {
14
+ "default": "./build/index.js",
15
+ "types": "./build/index.d.ts"
16
+ },
17
+ "./webapi": {
18
+ "default": "./build/webapi.js",
19
+ "types": "./build/webapi.d.ts"
20
+ }
21
+ },
22
+ "keywords": [
23
+ "cloreai",
24
+ "clore",
25
+ "api"
26
+ ],
19
27
  "scripts": {
20
28
  "build": "tsc --project tsconfig.build.json",
21
29
  "check": "npm run typecheck && npm run lint && npm run format",
@@ -24,21 +32,21 @@
24
32
  "lint": "eslint .",
25
33
  "prepack": "npm run clean && npm run build && npm run check",
26
34
  "prepare": "husky",
27
- "start-playground": "node playground/main.js",
35
+ "start-playground": "node playground/index.js",
28
36
  "typecheck": "tsc --noEmit",
29
37
  "update-latest": "rimraf package-lock.json && npm-check-updates --peer --upgrade && npm install"
30
38
  },
31
39
  "dependencies": {
32
- "axios": "^1.7.2"
40
+ "axios": "^1.7.4"
33
41
  },
34
42
  "devDependencies": {
35
43
  "@tsconfig/strictest": "^2.0.5",
36
44
  "eslint": "^8.57.0",
37
- "eslint-config-vladpuz": "^0.8.0",
38
- "husky": "^9.1.1",
39
- "npm-check-updates": "^16.14.20",
45
+ "eslint-config-vladpuz": "^0.10.0",
46
+ "husky": "^9.1.4",
47
+ "npm-check-updates": "^17.0.6",
40
48
  "prettier": "^3.3.3",
41
- "prettier-config-vladpuz": "^0.5.0",
49
+ "prettier-config-vladpuz": "^0.8.0",
42
50
  "rimraf": "^6.0.1",
43
51
  "typescript": "^5.5.4"
44
52
  }
package/build/CloreAI.js DELETED
@@ -1,80 +0,0 @@
1
- import axios from 'axios';
2
- import { statusCodes } from './constants.js';
3
- import { CustomError, DatabaseError, ExceededError, InvalidApiTokenError, InvalidEndpointError, InvalidInputDataError, UnknownError } from './errors.js';
4
- import { getErrorMessage } from './getErrorMessage.js';
5
- export class CloreAI {
6
- api;
7
- constructor(config) {
8
- const { apiKey, axiosConfig = {} } = config;
9
- this.api = axios.create({
10
- ...axiosConfig,
11
- baseURL: 'https://api.clore.ai/v1',
12
- headers: {
13
- ...axiosConfig.headers,
14
- auth: apiKey,
15
- },
16
- });
17
- this.api.interceptors.response.use((response) => {
18
- if (response.data.code === statusCodes['NORMAL']) {
19
- return response;
20
- }
21
- const errorMessage = getErrorMessage(response.data.code, response.data.error);
22
- switch (response.data.code) {
23
- case statusCodes['DATABASE_ERROR']:
24
- throw new DatabaseError(errorMessage, undefined, response.config, response.request, response);
25
- case statusCodes['INVALID_INPUT_DATA']:
26
- throw new InvalidInputDataError(errorMessage, undefined, response.config, response.request, response);
27
- case statusCodes['INVALID_API_TOKEN']:
28
- throw new InvalidApiTokenError(errorMessage, undefined, response.config, response.request, response);
29
- case statusCodes['INVALID_ENDPOINT']:
30
- throw new InvalidEndpointError(errorMessage, undefined, response.config, response.request, response);
31
- case statusCodes['EXCEEDED']:
32
- throw new ExceededError(errorMessage, undefined, response.config, response.request, response);
33
- case statusCodes['ERROR']:
34
- throw new CustomError(errorMessage, undefined, response.config, response.request, response);
35
- default:
36
- throw new UnknownError(errorMessage, undefined, response.config, response.request, response);
37
- }
38
- });
39
- }
40
- async wallets(config) {
41
- const response = await this.api.get('/wallets', config);
42
- return response.data;
43
- }
44
- async myServers(config) {
45
- const response = await this.api.get('/my_servers', config);
46
- return response.data;
47
- }
48
- async serverConfig(body, config) {
49
- const response = await this.api.get('/server_config', { ...config, data: body });
50
- return response.data;
51
- }
52
- async marketplace(config) {
53
- const response = await this.api.get('/marketplace', config);
54
- return response.data;
55
- }
56
- async myOrders(params, config) {
57
- const response = await this.api.get('/my_orders', { ...config, params });
58
- return response.data;
59
- }
60
- async spotMarketplace(params, config) {
61
- const response = await this.api.get('/spot_marketplace', { ...config, params });
62
- return response.data;
63
- }
64
- async setServerSettings(body, config) {
65
- const response = await this.api.post('/set_server_settings', body, config);
66
- return response.data;
67
- }
68
- async setSpotPrice(body, config) {
69
- const response = await this.api.post('/set_spot_price', body, config);
70
- return response.data;
71
- }
72
- async cancelOrder(body, config) {
73
- const response = await this.api.post('/cancel_order', body, config);
74
- return response.data;
75
- }
76
- async createOrder(body, config) {
77
- const response = await this.api.post('/create_order', body, config);
78
- return response.data;
79
- }
80
- }
package/build/WebAPI.d.ts DELETED
@@ -1,18 +0,0 @@
1
- import { type AxiosInstance, type AxiosRequestConfig } from 'axios';
2
- import type { WebConfig } from './types/config.js';
3
- import type { WebCancelOrderBody, WebCancelOrderOutput } from './types/webapi/cancelOrder.js';
4
- import type { WebCreateOrderBody, WebCreateOrderOutput } from './types/webapi/createOrder.js';
5
- import type { WebGetSpotBody, WebGetSpotOutput } from './types/webapi/getSpot.js';
6
- import type { WebOrdersBody } from './types/webapi/orders.js';
7
- import type { WebServersOutput } from './types/webapi/servers.js';
8
- import type { WebSetSpotPriceBody, WebSetSpotPriceOutput } from './types/webapi/setSpotPrice.js';
9
- export declare class WebAPI {
10
- readonly api: AxiosInstance;
11
- constructor(config: WebConfig);
12
- servers(config?: AxiosRequestConfig): Promise<WebServersOutput>;
13
- orders(body: WebOrdersBody, config?: AxiosRequestConfig<WebOrdersBody>): Promise<WebServersOutput>;
14
- getSpot(body: WebGetSpotBody, config?: AxiosRequestConfig<WebGetSpotBody>): Promise<WebGetSpotOutput>;
15
- setSpotPrice(body: WebSetSpotPriceBody, config?: AxiosRequestConfig<WebSetSpotPriceBody>): Promise<WebSetSpotPriceOutput>;
16
- cancelOrder(body: WebCancelOrderBody, config?: AxiosRequestConfig<WebCancelOrderBody>): Promise<WebCancelOrderOutput>;
17
- createOrder(body: WebCreateOrderBody, config?: AxiosRequestConfig<WebCreateOrderBody>): Promise<WebCreateOrderOutput>;
18
- }
@@ -1,3 +0,0 @@
1
- export declare const GLOBAL_RATE_LIMIT = 1000;
2
- export declare const CREATE_ORDER_RATE_LIMIT = 5000;
3
- export declare const statusCodes: Record<string, number>;
@@ -1,10 +0,0 @@
1
- import type { CreateAxiosDefaults } from 'axios';
2
- export interface CommonConfig {
3
- axiosConfig?: CreateAxiosDefaults;
4
- }
5
- export interface Config extends CommonConfig {
6
- apiKey: string;
7
- }
8
- export interface WebConfig extends CommonConfig {
9
- token: string;
10
- }
@@ -1,9 +0,0 @@
1
- export interface CommonOutput<T = string> {
2
- error?: T | undefined;
3
- }
4
- export interface Output<T = string> extends CommonOutput<T> {
5
- code: number;
6
- }
7
- export interface WebOutput<T = string> extends CommonOutput<T> {
8
- status: string;
9
- }
@@ -1,7 +0,0 @@
1
- import type { WebOutput } from '../output.js';
2
- export interface WebCancelOrderBody {
3
- id: number;
4
- rating: number;
5
- }
6
- export interface WebCancelOrderOutput extends WebOutput {
7
- }
@@ -1,25 +0,0 @@
1
- import type { Currency } from '../common.js';
2
- import type { WebOutput } from '../output.js';
3
- export interface WebCreateOrderCommon {
4
- currency: Currency;
5
- image: string;
6
- renting_server: number;
7
- ports?: Record<string, string>;
8
- env?: Record<string, string>;
9
- jupyter_token?: string;
10
- ssh_key?: string;
11
- ssh_password?: string;
12
- command?: string;
13
- required_price?: number;
14
- autossh_entrypoint?: boolean;
15
- }
16
- export interface WebCreateOrderOnDemand extends WebCreateOrderCommon {
17
- type: 'on-demand';
18
- }
19
- export interface WebCreateOrderSpot extends WebCreateOrderCommon {
20
- type: 'spot';
21
- spotprice: number;
22
- }
23
- export type WebCreateOrderBody = WebCreateOrderOnDemand | WebCreateOrderSpot;
24
- export interface WebCreateOrderOutput extends WebOutput {
25
- }
@@ -1,26 +0,0 @@
1
- import type { Currency, Pricing, Visibility } from '../common.js';
2
- import type { WebOutput } from '../output.js';
3
- export interface WebGetSpotBody {
4
- id: number;
5
- }
6
- export interface WebGetSpotDataOffer {
7
- offer_id: number;
8
- bid: number;
9
- active: boolean;
10
- my: boolean;
11
- currency: Currency;
12
- }
13
- export interface WebGetSpotDataServer {
14
- min_pricing: Pricing;
15
- mrl: number;
16
- visibility: Visibility;
17
- online: boolean;
18
- }
19
- export interface WebGetSpotData {
20
- currency_rates_in_usd: Pricing;
21
- offers: WebGetSpotDataOffer[];
22
- server: WebGetSpotDataServer;
23
- }
24
- export interface WebGetSpotOutput extends WebOutput {
25
- data: WebGetSpotData;
26
- }
@@ -1,17 +0,0 @@
1
- import type { WebOutput } from '../output.js';
2
- export interface WebSetSpotPriceBody {
3
- desired_price: number;
4
- order_id: number;
5
- }
6
- export interface WebSetSpotPriceMaxStep extends WebOutput {
7
- error: 'exceeded_max_step';
8
- max_step: number;
9
- }
10
- export interface WebSetSpotPriceTimeToLowering extends WebOutput {
11
- error: 'can_lower_every_600_seconds';
12
- time_to_lowering: number;
13
- }
14
- export interface WebSetSpotPriceSuccess extends WebOutput {
15
- error: undefined;
16
- }
17
- export type WebSetSpotPriceOutput = WebSetSpotPriceMaxStep | WebSetSpotPriceTimeToLowering | WebSetSpotPriceSuccess;
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes