cloreai 3.0.0 → 4.0.0

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 (53) hide show
  1. package/README.md +69 -47
  2. package/{build → dist}/Cloreai.d.ts +17 -17
  3. package/dist/Cloreai.js +267 -0
  4. package/dist/CloreaiError.d.ts +17 -0
  5. package/dist/CloreaiError.js +13 -0
  6. package/dist/Gigaspot.d.ts +14 -0
  7. package/dist/Gigaspot.js +74 -0
  8. package/{build → dist}/constants.d.ts +0 -1
  9. package/{build → dist}/constants.js +0 -1
  10. package/package.json +12 -14
  11. package/build/Cloreai.js +0 -125
  12. package/build/CloreaiError.d.ts +0 -12
  13. package/build/CloreaiError.js +0 -16
  14. package/build/Gigaspot.d.ts +0 -17
  15. package/build/Gigaspot.js +0 -46
  16. package/build/getQueueOptions.d.ts +0 -3
  17. package/build/getQueueOptions.js +0 -8
  18. package/{build → dist}/index.d.ts +0 -0
  19. package/{build → dist}/index.js +0 -0
  20. package/{build → dist}/resources/cancelOrder.d.ts +0 -0
  21. package/{build → dist}/resources/cancelOrder.js +0 -0
  22. package/{build → dist}/resources/cancelOrders.d.ts +0 -0
  23. package/{build → dist}/resources/cancelOrders.js +0 -0
  24. package/{build → dist}/resources/createGigaspotOrders.d.ts +1 -1
  25. package/{build → dist}/resources/createGigaspotOrders.js +0 -0
  26. package/{build → dist}/resources/createOrder.d.ts +8 -8
  27. package/{build → dist}/resources/createOrder.js +0 -0
  28. package/{build → dist}/resources/editGigaspotOrders.d.ts +1 -1
  29. package/{build → dist}/resources/editGigaspotOrders.js +0 -0
  30. package/{build → dist}/resources/getGigaspot.d.ts +23 -23
  31. package/{build → dist}/resources/getGigaspot.js +0 -0
  32. package/{build → dist}/resources/marketplace.d.ts +3 -3
  33. package/{build → dist}/resources/marketplace.js +0 -0
  34. package/{build → dist}/resources/myOrders.d.ts +4 -4
  35. package/{build → dist}/resources/myOrders.js +0 -0
  36. package/{build → dist}/resources/myServers.d.ts +4 -4
  37. package/{build → dist}/resources/myServers.js +0 -0
  38. package/{build → dist}/resources/pohBalance.d.ts +16 -16
  39. package/{build → dist}/resources/pohBalance.js +0 -0
  40. package/{build → dist}/resources/renterFees.d.ts +12 -12
  41. package/{build → dist}/resources/renterFees.js +0 -0
  42. package/{build → dist}/resources/serverConfig.d.ts +8 -8
  43. package/{build → dist}/resources/serverConfig.js +0 -0
  44. package/{build → dist}/resources/setServerSettings.d.ts +0 -0
  45. package/{build → dist}/resources/setServerSettings.js +0 -0
  46. package/{build → dist}/resources/setSpotPrice.d.ts +1 -1
  47. package/{build → dist}/resources/setSpotPrice.js +0 -0
  48. package/{build → dist}/resources/spotMarketplace.d.ts +9 -9
  49. package/{build → dist}/resources/spotMarketplace.js +0 -0
  50. package/{build → dist}/resources/wallets.d.ts +3 -3
  51. /package/{build → dist}/resources/wallets.js +0 -0
  52. /package/{build → dist}/types.d.ts +0 -0
  53. /package/{build → dist}/types.js +0 -0
package/README.md CHANGED
@@ -4,11 +4,11 @@
4
4
 
5
5
  Features:
6
6
 
7
- - Based on [axios](https://github.com/axios/axios)
8
- - Protects from rate limit exceeded (429 errors) via
7
+ - Based on native fetch
8
+ - Protects against rate limit exceeded (429 errors) through
9
9
  [p-queue](https://github.com/sindresorhus/p-queue)
10
- - User-friendly error handling
11
- - Full typing
10
+ - Convenient error handling
11
+ - Full type safety
12
12
  - Supports GigaSPOT
13
13
 
14
14
  Official documentation: [clore.ai/api-docs](https://clore.ai/api-docs)
@@ -30,10 +30,11 @@ npm install cloreai
30
30
  import Cloreai from 'cloreai'
31
31
 
32
32
  const cloreai = new Cloreai('API_KEY', {
33
- axiosOptions: {}, // (optional) Axios instance options https://github.com/axios/axios
33
+ baseURL: 'https://api.clore.ai/v1', // (optional) Override the default base URL for the API
34
+ fetch: globalThis.fetch, // (optional) Specify a custom `fetch` function implementation
35
+ fetchOptions: {}, // (optional) Additional `RequestInit` options to be passed to `fetch` calls
34
36
  queueOptions: {}, // (optional) Queue instance options https://github.com/sindresorhus/p-queue
35
37
  queueCreateOrderOptions: {}, // (optional) Create order queue instance options https://github.com/sindresorhus/p-queue
36
- queueGigaspotOptions: {}, // (optional) Gigaspot queue instance options https://github.com/sindresorhus/p-queue
37
38
  })
38
39
  ```
39
40
 
@@ -142,7 +143,7 @@ await cloreai.createOrder({
142
143
  })
143
144
  ```
144
145
 
145
- ### 11. PoH Info
146
+ ### 11. poh_balance
146
147
 
147
148
  ```typescript
148
149
  const pohBalance = await cloreai.pohBalance()
@@ -206,41 +207,23 @@ await cloreai.gigaspot.cancelOrders({
206
207
  })
207
208
  ```
208
209
 
209
- ### Request Configuration
210
+ ## Fetch Options
210
211
 
211
- All methods accept an optional request configuration for axios as the last
212
- parameter, for example:
212
+ All methods accept fetch options as the last parameter, for example:
213
213
 
214
214
  ```typescript
215
215
  const marketplace = await cloreai.marketplace({
216
- // axios config
216
+ // `RequestInit` options
217
217
  })
218
218
  ```
219
219
 
220
- ### Access to axios instance
221
-
222
- Use the field `cloreai.axios`.
223
-
224
- Refer to the documentation [axios](https://github.com/axios/axios).
225
-
226
- ### Access to p-queue instances
227
-
228
- Use the fields:
229
-
230
- - `cloreai.queue` - for the main request queue
231
- - `cloreai.queueCreateOrder` - for the createOrder request queue
232
- - `cloreai.gigaspot.queue` - for the gigaspot request queue
233
-
234
- Refer to the documentation [p-queue](https://github.com/sindresorhus/p-queue).
235
-
236
- ### Error Handling
220
+ ## Error Handling
237
221
 
238
222
  Use the `CloreaiError` class for error handling.
239
223
 
240
- This class inherits from `AxiosError` and has additional fields with error
241
- information `error.code` and `error.error`.
224
+ Errors have fields with information `error.statusCode` and `error.description`.
242
225
 
243
- To check the error type use the constant `statusCodes`.
226
+ Use the constant `statusCodes` to check the error type.
244
227
 
245
228
  ```typescript
246
229
  import { CloreaiError, statusCodes } from 'cloreai'
@@ -249,9 +232,9 @@ try {
249
232
  const marketplace = await cloreai.marketplace()
250
233
  } catch (error) {
251
234
  if (error instanceof CloreaiError) {
252
- console.log(error.code, error.error)
235
+ console.log(error.statusCode, error.description)
253
236
 
254
- if (error.code === statusCodes.EXCEEDED) {
237
+ if (error.statusCode === statusCodes.EXCEEDED) {
255
238
  console.log('Rate limit exceeded error')
256
239
  }
257
240
  } else {
@@ -260,31 +243,24 @@ try {
260
243
  }
261
244
  ```
262
245
 
263
- ### Rate limit
246
+ ## Rate limit
264
247
 
265
- All methods are protected from rate limit exceeded via
248
+ All methods are protected from rate limit exceeded through
266
249
  [p-queue](https://github.com/sindresorhus/p-queue), they automatically delay for
267
- the required time to avoid exceeding the limit.
250
+ the needed time to avoid exceeding the limit.
268
251
 
269
252
  Default rate limit values are available as constants:
270
253
 
271
254
  ```typescript
272
- import {
273
- RATE_LIMIT,
274
- RATE_LIMIT_CREATE_ORDER,
275
- RATE_LIMIT_GIGASPOT,
276
- } from 'cloreai'
255
+ import { RATE_LIMIT, RATE_LIMIT_CREATE_ORDER } from 'cloreai'
277
256
 
278
257
  console.log(RATE_LIMIT)
279
258
  console.log(RATE_LIMIT_CREATE_ORDER)
280
- console.log(RATE_LIMIT_GIGASPOT)
281
259
  ```
282
260
 
283
- You can set custom rate limit values for each request queue:
261
+ You can set your own rate limit values for each request queue:
284
262
 
285
263
  ```typescript
286
- import Cloreai from 'cloreai'
287
-
288
264
  const cloreai = new Cloreai('API_KEY', {
289
265
  queueOptions: {
290
266
  interval: 2000, // For example 2 seconds
@@ -292,8 +268,54 @@ const cloreai = new Cloreai('API_KEY', {
292
268
  queueCreateOrderOptions: {
293
269
  interval: 6000, // For example 6 seconds
294
270
  },
295
- queueGigaspotOptions: {
296
- interval: 2000, // For example 2 seconds
271
+ })
272
+ ```
273
+
274
+ Access to p-queue instances:
275
+
276
+ - `cloreai.queue` - main request queue
277
+ - `cloreai.queueCreateOrder` - createOrder request queue
278
+
279
+ ## Retries
280
+
281
+ For retrying, it's recommended to use
282
+ [p-retry](https://github.com/sindresorhus/p-retry):
283
+
284
+ ```typescript
285
+ import pRetry from 'p-retry'
286
+
287
+ const marketplace = await pRetry(
288
+ async () => {
289
+ return await cloreai.marketplace()
297
290
  },
291
+ {
292
+ retries: 5,
293
+ },
294
+ )
295
+ ```
296
+
297
+ ## Timeouts
298
+
299
+ Use `AbortSignal.timeout`.
300
+
301
+ Options signal from fetchOptions and request options are combined. In the
302
+ following example, the request will be aborted after 5 seconds, but it can also
303
+ be aborted earlier by calling `controller.abort()`.
304
+
305
+ ```typescript
306
+ const cloreai = new Cloreai('API_KEY', {
307
+ fetchOptions: {
308
+ signal: AbortSignal.timeout(5000),
309
+ },
310
+ })
311
+
312
+ const controller = new AbortController()
313
+
314
+ setTimeout(() => {
315
+ controller.abort()
316
+ }, 10000)
317
+
318
+ const marketplace = await cloreai.marketplace({
319
+ signal: controller.signal, // Combined with `AbortSignal.timeout(5000)`
298
320
  })
299
321
  ```
@@ -1,4 +1,3 @@
1
- import { type AxiosInstance, type AxiosRequestConfig, type CreateAxiosDefaults } from 'axios';
2
1
  import PQueue, { type Options as PQueueOptions, type Queue, type QueueAddOptions } from 'p-queue';
3
2
  import type { CancelOrderRequestData, CancelOrderResponseData } from './resources/cancelOrder.ts';
4
3
  import type { CreateOrderRequestData, CreateOrderResponseData } from './resources/createOrder.ts';
@@ -13,30 +12,31 @@ import type { SetSpotPriceRequestData, SetSpotPriceResponseData } from './resour
13
12
  import type { SpotMarketplaceRequestParams, SpotMarketplaceResponseData } from './resources/spotMarketplace.ts';
14
13
  import type { WalletsResponseData } from './resources/wallets.ts';
15
14
  import Gigaspot from './Gigaspot.ts';
16
- export type QueueOptions = PQueueOptions<Queue<() => Promise<unknown>, QueueAddOptions>, QueueAddOptions>;
17
15
  export interface Options {
18
- axiosOptions?: CreateAxiosDefaults;
16
+ baseURL?: string;
17
+ fetch?: typeof fetch;
18
+ fetchOptions?: RequestInit;
19
19
  queueOptions?: QueueOptions;
20
20
  queueCreateOrderOptions?: QueueOptions;
21
- queueGigaspotOptions?: QueueOptions;
22
21
  }
22
+ export type QueueOptions = PQueueOptions<Queue<() => Promise<unknown>, QueueAddOptions>, QueueAddOptions>;
23
23
  declare class Cloreai {
24
- axios: AxiosInstance;
24
+ #private;
25
25
  queue: PQueue;
26
26
  queueCreateOrder: PQueue;
27
27
  gigaspot: Gigaspot;
28
28
  constructor(apiKey: string, options?: Options);
29
- wallets(config?: AxiosRequestConfig): Promise<WalletsResponseData>;
30
- myServers(config?: AxiosRequestConfig): Promise<MyServersResponseData>;
31
- serverConfig(data: ServerConfigRequestData, config?: AxiosRequestConfig): Promise<ServerConfigResponseData>;
32
- marketplace(config?: AxiosRequestConfig): Promise<MarketplaceResponseData>;
33
- myOrders(params?: MyOrdersRequestParams, config?: AxiosRequestConfig): Promise<MyOrdersResponseData>;
34
- spotMarketplace(params: SpotMarketplaceRequestParams, config?: AxiosRequestConfig): Promise<SpotMarketplaceResponseData>;
35
- setServerSettings(data: SetServerSettingsRequestData, config?: AxiosRequestConfig): Promise<SetServerSettingsResponseData>;
36
- setSpotPrice(data: SetSpotPriceRequestData, config?: AxiosRequestConfig): Promise<SetSpotPriceResponseData>;
37
- cancelOrder(data: CancelOrderRequestData, config?: AxiosRequestConfig): Promise<CancelOrderResponseData>;
38
- createOrder(data: CreateOrderRequestData, config?: AxiosRequestConfig): Promise<CreateOrderResponseData>;
39
- pohBalance(config?: AxiosRequestConfig): Promise<PohBalanceResponseData>;
40
- renterFees(config?: AxiosRequestConfig): Promise<RenterFeesResponseData>;
29
+ wallets(init?: RequestInit): Promise<WalletsResponseData>;
30
+ myServers(init?: RequestInit): Promise<MyServersResponseData>;
31
+ serverConfig(data: ServerConfigRequestData, init?: RequestInit): Promise<ServerConfigResponseData>;
32
+ marketplace(init?: RequestInit): Promise<MarketplaceResponseData>;
33
+ myOrders(params?: MyOrdersRequestParams, init?: RequestInit): Promise<MyOrdersResponseData>;
34
+ spotMarketplace(params: SpotMarketplaceRequestParams, init?: RequestInit): Promise<SpotMarketplaceResponseData>;
35
+ setServerSettings(data: SetServerSettingsRequestData, init?: RequestInit): Promise<SetServerSettingsResponseData>;
36
+ setSpotPrice(data: SetSpotPriceRequestData, init?: RequestInit): Promise<SetSpotPriceResponseData>;
37
+ cancelOrder(data: CancelOrderRequestData, init?: RequestInit): Promise<CancelOrderResponseData>;
38
+ createOrder(data: CreateOrderRequestData, init?: RequestInit): Promise<CreateOrderResponseData>;
39
+ pohBalance(init?: RequestInit): Promise<PohBalanceResponseData>;
40
+ renterFees(init?: RequestInit): Promise<RenterFeesResponseData>;
41
41
  }
42
42
  export default Cloreai;
@@ -0,0 +1,267 @@
1
+ import PQueue, {} from 'p-queue';
2
+ import { CloreaiError } from "./CloreaiError.js";
3
+ import { priorityLevels, RATE_LIMIT, RATE_LIMIT_CREATE_ORDER, statusCodes } from "./constants.js";
4
+ import Gigaspot from "./Gigaspot.js";
5
+ class Cloreai {
6
+ queue;
7
+ queueCreateOrder;
8
+ gigaspot;
9
+ #baseURL;
10
+ #fetch;
11
+ constructor(apiKey, options = {}) {
12
+ this.#baseURL = options.baseURL ?? 'https://api.clore.ai/v1';
13
+ const fetchFunction = options.fetch ?? fetch;
14
+ const fetchOptions = options.fetchOptions ?? {};
15
+ this.#fetch = async (input, init = {}) => {
16
+ if (input instanceof Request) {
17
+ throw new TypeError('Input must be a string or URL');
18
+ }
19
+ const headers = new Headers({
20
+ 'Content-Type': 'application/json',
21
+ 'auth': apiKey,
22
+ });
23
+ for (const [key, value] of new Headers(fetchOptions.headers)) {
24
+ headers.set(key, value);
25
+ }
26
+ for (const [key, value] of new Headers(init.headers)) {
27
+ headers.set(key, value);
28
+ }
29
+ const signal = AbortSignal.any([
30
+ ...(fetchOptions.signal ? [fetchOptions.signal] : []),
31
+ ...(init.signal ? [init.signal] : []),
32
+ ]);
33
+ const mergedInit = {
34
+ ...fetchOptions,
35
+ ...init,
36
+ headers,
37
+ signal,
38
+ };
39
+ const url = new URL(input);
40
+ const request = new Request(url, mergedInit);
41
+ let response;
42
+ try {
43
+ response = await fetchFunction(request);
44
+ }
45
+ catch (error) {
46
+ throw new CloreaiError(error instanceof Error ? error.message : String(error), {
47
+ cause: error,
48
+ init: mergedInit,
49
+ request,
50
+ });
51
+ }
52
+ const originalJson = response.json;
53
+ // @ts-expect-error: json is readonly
54
+ response.json = async () => {
55
+ let data;
56
+ try {
57
+ data = await originalJson.call(response);
58
+ }
59
+ catch (error) {
60
+ throw new CloreaiError(error instanceof Error ? error.message : String(error), {
61
+ cause: error,
62
+ init: mergedInit,
63
+ request,
64
+ response,
65
+ });
66
+ }
67
+ if (data.code === statusCodes.NORMAL) {
68
+ return data;
69
+ }
70
+ const hasError = Boolean(data.error);
71
+ const errorMessage = hasError
72
+ ? `Code "${data.code}, error "${data.error}"`
73
+ : `Code "${data.code}"`;
74
+ throw new CloreaiError(errorMessage, {
75
+ init: mergedInit,
76
+ request,
77
+ response,
78
+ statusCode: data.code,
79
+ description: data.error ?? '',
80
+ data,
81
+ });
82
+ };
83
+ return response;
84
+ };
85
+ this.queue = new PQueue({
86
+ interval: RATE_LIMIT,
87
+ intervalCap: 1,
88
+ concurrency: 1,
89
+ ...options.queueOptions,
90
+ });
91
+ this.queueCreateOrder = new PQueue({
92
+ interval: RATE_LIMIT_CREATE_ORDER,
93
+ intervalCap: 1,
94
+ concurrency: 1,
95
+ ...options.queueCreateOrderOptions,
96
+ });
97
+ this.gigaspot = new Gigaspot(this.queue, this.#baseURL, this.#fetch);
98
+ }
99
+ async wallets(init = {}) {
100
+ const url = new URL(this.#baseURL + '/wallets');
101
+ const response = await this.queue.add(async () => {
102
+ return await this.#fetch(url, {
103
+ ...init,
104
+ method: 'GET',
105
+ });
106
+ }, {
107
+ priority: priorityLevels.NORMAL,
108
+ signal: init.signal ?? undefined,
109
+ });
110
+ return await response.json();
111
+ }
112
+ async myServers(init = {}) {
113
+ const url = new URL(this.#baseURL + '/my_servers');
114
+ const response = await this.queue.add(async () => {
115
+ return await this.#fetch(url, {
116
+ ...init,
117
+ method: 'GET',
118
+ });
119
+ }, {
120
+ priority: priorityLevels.NORMAL,
121
+ signal: init.signal ?? undefined,
122
+ });
123
+ return await response.json();
124
+ }
125
+ async serverConfig(data, init = {}) {
126
+ const url = new URL(this.#baseURL + '/server_config');
127
+ const response = await this.queue.add(async () => {
128
+ return await this.#fetch(url, {
129
+ ...init,
130
+ method: 'GET',
131
+ body: JSON.stringify(data),
132
+ });
133
+ }, {
134
+ priority: priorityLevels.NORMAL,
135
+ signal: init.signal ?? undefined,
136
+ });
137
+ return await response.json();
138
+ }
139
+ async marketplace(init = {}) {
140
+ const url = new URL(this.#baseURL + '/marketplace');
141
+ const response = await this.queue.add(async () => {
142
+ return await this.#fetch(url, {
143
+ ...init,
144
+ method: 'GET',
145
+ });
146
+ }, {
147
+ priority: priorityLevels.NORMAL,
148
+ signal: init.signal ?? undefined,
149
+ });
150
+ return await response.json();
151
+ }
152
+ async myOrders(params = {}, init = {}) {
153
+ const url = new URL(this.#baseURL + '/my_orders');
154
+ for (const [key, value] of Object.entries(params)) {
155
+ url.searchParams.set(key, String(value));
156
+ }
157
+ const response = await this.queue.add(async () => {
158
+ return await this.#fetch(url, {
159
+ ...init,
160
+ method: 'GET',
161
+ });
162
+ }, {
163
+ priority: priorityLevels.NORMAL,
164
+ signal: init.signal ?? undefined,
165
+ });
166
+ return await response.json();
167
+ }
168
+ async spotMarketplace(params, init = {}) {
169
+ const url = new URL(this.#baseURL + '/spot_marketplace');
170
+ for (const [key, value] of Object.entries(params)) {
171
+ url.searchParams.set(key, String(value));
172
+ }
173
+ const response = await this.queue.add(async () => {
174
+ return await this.#fetch(url, {
175
+ ...init,
176
+ method: 'GET',
177
+ });
178
+ }, {
179
+ priority: priorityLevels.NORMAL,
180
+ signal: init.signal ?? undefined,
181
+ });
182
+ return await response.json();
183
+ }
184
+ async setServerSettings(data, init = {}) {
185
+ const url = new URL(this.#baseURL + '/set_server_settings');
186
+ const response = await this.queue.add(async () => {
187
+ return await this.#fetch(url, {
188
+ ...init,
189
+ method: 'POST',
190
+ body: JSON.stringify(data),
191
+ });
192
+ }, {
193
+ priority: priorityLevels.HIGH,
194
+ signal: init.signal ?? undefined,
195
+ });
196
+ return await response.json();
197
+ }
198
+ async setSpotPrice(data, init = {}) {
199
+ const url = new URL(this.#baseURL + '/set_spot_price');
200
+ const response = await this.queue.add(async () => {
201
+ return await this.#fetch(url, {
202
+ ...init,
203
+ method: 'POST',
204
+ body: JSON.stringify(data),
205
+ });
206
+ }, {
207
+ priority: priorityLevels.HIGH,
208
+ signal: init.signal ?? undefined,
209
+ });
210
+ return await response.json();
211
+ }
212
+ async cancelOrder(data, init = {}) {
213
+ const url = new URL(this.#baseURL + '/cancel_order');
214
+ const response = await this.queue.add(async () => {
215
+ return await this.#fetch(url, {
216
+ ...init,
217
+ method: 'POST',
218
+ body: JSON.stringify(data),
219
+ });
220
+ }, {
221
+ priority: priorityLevels.HIGH,
222
+ signal: init.signal ?? undefined,
223
+ });
224
+ return await response.json();
225
+ }
226
+ async createOrder(data, init = {}) {
227
+ const url = new URL(this.#baseURL + '/create_order');
228
+ const response = await this.queue.add(async () => {
229
+ return await this.#fetch(url, {
230
+ ...init,
231
+ method: 'POST',
232
+ body: JSON.stringify(data),
233
+ });
234
+ }, {
235
+ priority: priorityLevels.HIGHEST,
236
+ signal: init.signal ?? undefined,
237
+ });
238
+ return await response.json();
239
+ }
240
+ async pohBalance(init = {}) {
241
+ const url = new URL(this.#baseURL + '/poh_balance');
242
+ const response = await this.queue.add(async () => {
243
+ return await this.#fetch(url, {
244
+ ...init,
245
+ method: 'GET',
246
+ });
247
+ }, {
248
+ priority: priorityLevels.NORMAL,
249
+ signal: init.signal ?? undefined,
250
+ });
251
+ return await response.json();
252
+ }
253
+ async renterFees(init = {}) {
254
+ const url = new URL(this.#baseURL + '/renter_fees');
255
+ const response = await this.queue.add(async () => {
256
+ return await this.#fetch(url, {
257
+ ...init,
258
+ method: 'GET',
259
+ });
260
+ }, {
261
+ priority: priorityLevels.NORMAL,
262
+ signal: init.signal ?? undefined,
263
+ });
264
+ return await response.json();
265
+ }
266
+ }
267
+ export default Cloreai;
@@ -0,0 +1,17 @@
1
+ export interface CloreaiErrorOptions extends ErrorOptions {
2
+ init?: RequestInit;
3
+ request?: Request;
4
+ response?: Response;
5
+ statusCode?: number;
6
+ description?: string;
7
+ data?: unknown;
8
+ }
9
+ export declare class CloreaiError extends Error {
10
+ init?: RequestInit;
11
+ request?: Request;
12
+ response?: Response;
13
+ statusCode?: number;
14
+ description?: string;
15
+ data?: unknown;
16
+ constructor(message?: string, options?: CloreaiErrorOptions);
17
+ }
@@ -0,0 +1,13 @@
1
+ export class CloreaiError extends Error {
2
+ init;
3
+ request;
4
+ response;
5
+ statusCode;
6
+ description;
7
+ data;
8
+ constructor(message, options) {
9
+ super(message);
10
+ this.name = 'CloreaiError';
11
+ Object.assign(this, options);
12
+ }
13
+ }
@@ -0,0 +1,14 @@
1
+ import type PQueue from 'p-queue';
2
+ import type { CancelOrdersRequestData, CancelOrdersResponseData } from './resources/cancelOrders.ts';
3
+ import type { CreateGigaspotOrdersRequestData, CreateGigaspotOrdersResponseData } from './resources/createGigaspotOrders.ts';
4
+ import type { EditGigaspotOrdersRequestData, EditGigaspotOrdersResponseData } from './resources/editGigaspotOrders.ts';
5
+ import type { GetGigaspotResponseData } from './resources/getGigaspot.ts';
6
+ declare class Gigaspot {
7
+ #private;
8
+ constructor(queue: PQueue, baseURL: string, fetchFunction: typeof fetch);
9
+ getGigaspot(init?: RequestInit): Promise<GetGigaspotResponseData>;
10
+ createGigaspotOrders(data: CreateGigaspotOrdersRequestData, init?: RequestInit): Promise<CreateGigaspotOrdersResponseData>;
11
+ editGigaspotOrders(data: EditGigaspotOrdersRequestData, init?: RequestInit): Promise<EditGigaspotOrdersResponseData>;
12
+ cancelOrders(data: CancelOrdersRequestData, init?: RequestInit): Promise<CancelOrdersResponseData>;
13
+ }
14
+ export default Gigaspot;
@@ -0,0 +1,74 @@
1
+ import { priorityLevels } from "./constants.js";
2
+ /* eslint-disable @typescript-eslint/no-unsafe-type-assertion */
3
+ class Gigaspot {
4
+ #queue;
5
+ #baseURL;
6
+ #fetch;
7
+ constructor(queue, baseURL, fetchFunction) {
8
+ this.#queue = queue;
9
+ this.#baseURL = baseURL;
10
+ this.#fetch = fetchFunction;
11
+ }
12
+ async getGigaspot(init = {}) {
13
+ const url = new URL(this.#baseURL + '/get_gigaspot');
14
+ const response = await this.#queue.add(async () => {
15
+ return await this.#fetch(url, {
16
+ ...init,
17
+ method: 'GET',
18
+ });
19
+ }, {
20
+ priority: priorityLevels.NORMAL,
21
+ signal: init.signal ?? undefined,
22
+ });
23
+ const data = await response.json();
24
+ const snapshotResponse = await fetch(data.v1_snapshot_url);
25
+ const snapshotData = await snapshotResponse.json();
26
+ return {
27
+ ...data,
28
+ snapshot: snapshotData,
29
+ };
30
+ }
31
+ async createGigaspotOrders(data, init = {}) {
32
+ const url = new URL(this.#baseURL + '/create_gigaspot_orders');
33
+ const response = await this.#queue.add(async () => {
34
+ return await this.#fetch(url, {
35
+ ...init,
36
+ method: 'POST',
37
+ body: JSON.stringify(data),
38
+ });
39
+ }, {
40
+ priority: priorityLevels.HIGH,
41
+ signal: init.signal ?? undefined,
42
+ });
43
+ return await response.json();
44
+ }
45
+ async editGigaspotOrders(data, init = {}) {
46
+ const url = new URL(this.#baseURL + '/edit_gigaspot_orders');
47
+ const response = await this.#queue.add(async () => {
48
+ return await this.#fetch(url, {
49
+ ...init,
50
+ method: 'POST',
51
+ body: JSON.stringify(data),
52
+ });
53
+ }, {
54
+ priority: priorityLevels.HIGH,
55
+ signal: init.signal ?? undefined,
56
+ });
57
+ return await response.json();
58
+ }
59
+ async cancelOrders(data, init = {}) {
60
+ const url = new URL(this.#baseURL + '/cancel_orders');
61
+ const response = await this.#queue.add(async () => {
62
+ return await this.#fetch(url, {
63
+ ...init,
64
+ method: 'POST',
65
+ body: JSON.stringify(data),
66
+ });
67
+ }, {
68
+ priority: priorityLevels.HIGH,
69
+ signal: init.signal ?? undefined,
70
+ });
71
+ return await response.json();
72
+ }
73
+ }
74
+ export default Gigaspot;
@@ -1,6 +1,5 @@
1
1
  export declare const RATE_LIMIT = 1000;
2
2
  export declare const RATE_LIMIT_CREATE_ORDER = 5000;
3
- export declare const RATE_LIMIT_GIGASPOT = 1000;
4
3
  export declare const gigaspotBaseImages: Readonly<{
5
4
  UBUNTU: "a3f9c4d7e5b088d8a0bff880";
6
5
  HIVEOS: "c9a4e2f6b7d488d8f0bab0ff";
@@ -1,6 +1,5 @@
1
1
  export const RATE_LIMIT = 1000;
2
2
  export const RATE_LIMIT_CREATE_ORDER = 5000;
3
- export const RATE_LIMIT_GIGASPOT = 1000;
4
3
  export const gigaspotBaseImages = Object.freeze({
5
4
  UBUNTU: 'a3f9c4d7e5b088d8a0bff880',
6
5
  HIVEOS: 'c9a4e2f6b7d488d8f0bab0ff',