@reyaxyz/api-sdk 0.8.0 → 0.9.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.
@@ -1,4 +1,15 @@
1
1
  "use strict";
2
+ var __assign = (this && this.__assign) || function () {
3
+ __assign = Object.assign || function(t) {
4
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
5
+ s = arguments[i];
6
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
+ t[p] = s[p];
8
+ }
9
+ return t;
10
+ };
11
+ return __assign.apply(this, arguments);
12
+ };
2
13
  var __importDefault = (this && this.__importDefault) || function (mod) {
3
14
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
15
  };
@@ -11,13 +22,23 @@ var account_1 = __importDefault(require("./modules/account"));
11
22
  * @description Client for API
12
23
  */
13
24
  var ApiClient = /** @class */ (function () {
14
- function ApiClient(config, apiTimeout) {
15
- this.config = config;
16
- this.apiTimeout = apiTimeout !== null && apiTimeout !== void 0 ? apiTimeout : constants_1.API_TIMEOUT;
17
- this._markets = new markets_1.default(config.restEndpoint);
18
- this._account = new account_1.default(config.restEndpoint);
25
+ function ApiClient(config) {
26
+ this.apiEndpoint = config.production ? constants_1.API_PRODUCTION : constants_1.API_TESTNET;
27
+ ApiClient.config = __assign(__assign({}, ApiClient.config), config);
28
+ this._markets = new markets_1.default(this.apiEndpoint);
29
+ this._account = new account_1.default(this.apiEndpoint);
19
30
  }
20
- Object.defineProperty(ApiClient.prototype, "markets", {
31
+ ApiClient.configure = function (config) {
32
+ ApiClient.config = config;
33
+ ApiClient.instance = new ApiClient(config);
34
+ };
35
+ ApiClient.getInstance = function () {
36
+ if (!ApiClient.instance) {
37
+ throw new Error('ApiClient is not configured. Please configure it before using.');
38
+ }
39
+ return ApiClient.instance;
40
+ };
41
+ Object.defineProperty(ApiClient, "markets", {
21
42
  /**
22
43
  * Provides access to the MarketsClient instance.
23
44
  * This getter allows for interacting with market-related API functionalities.
@@ -26,12 +47,12 @@ var ApiClient = /** @class */ (function () {
26
47
  * @memberof ApiClient
27
48
  */
28
49
  get: function () {
29
- return this._markets;
50
+ return ApiClient.getInstance()._markets;
30
51
  },
31
52
  enumerable: false,
32
53
  configurable: true
33
54
  });
34
- Object.defineProperty(ApiClient.prototype, "account", {
55
+ Object.defineProperty(ApiClient, "account", {
35
56
  /**
36
57
  * Provides access to the AccountClient instance.
37
58
  * This getter allows for interacting with account-related API functionalities.
@@ -40,11 +61,15 @@ var ApiClient = /** @class */ (function () {
40
61
  * @memberof ApiClient
41
62
  */
42
63
  get: function () {
43
- return this._account;
64
+ return ApiClient.getInstance()._account;
44
65
  },
45
66
  enumerable: false,
46
67
  configurable: true
47
68
  });
69
+ ApiClient.config = {
70
+ production: true, // default value
71
+ timeout: constants_1.API_TIMEOUT, // default value, e.g., 5000 milliseconds
72
+ };
48
73
  return ApiClient;
49
74
  }());
50
75
  exports.ApiClient = ApiClient;
@@ -1 +1 @@
1
- {"version":3,"file":"api-client.js","sourceRoot":"/","sources":["clients/api-client.ts"],"names":[],"mappings":";;;;;;AAAA,iDAAiE;AACjE,8DAA8C;AAC9C,8DAA8C;AAE9C;;GAEG;AACH;IAME,mBAAY,MAAqB,EAAE,UAAmB;QACpD,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,UAAU,GAAG,UAAU,aAAV,UAAU,cAAV,UAAU,GAAI,uBAAW,CAAC;QAE5C,IAAI,CAAC,QAAQ,GAAG,IAAI,iBAAa,CAAC,MAAM,CAAC,YAAY,CAAC,CAAC;QACvD,IAAI,CAAC,QAAQ,GAAG,IAAI,iBAAa,CAAC,MAAM,CAAC,YAAY,CAAC,CAAC;IACzD,CAAC;IASD,sBAAI,8BAAO;QAPX;;;;;;WAMG;aACH;YACE,OAAO,IAAI,CAAC,QAAQ,CAAC;QACvB,CAAC;;;OAAA;IASD,sBAAI,8BAAO;QAPX;;;;;;WAMG;aACH;YACE,OAAO,IAAI,CAAC,QAAQ,CAAC;QACvB,CAAC;;;OAAA;IACH,gBAAC;AAAD,CAAC,AAnCD,IAmCC;AAnCY,8BAAS","sourcesContent":["import { ServiceConfig, API_TIMEOUT } from './helpers/constants';\nimport MarketsClient from './modules/markets';\nimport AccountClient from './modules/account';\n\n/**\n * @description Client for API\n */\nexport class ApiClient {\n public readonly config: ServiceConfig;\n readonly apiTimeout: number;\n readonly _markets: MarketsClient;\n readonly _account: AccountClient;\n\n constructor(config: ServiceConfig, apiTimeout?: number) {\n this.config = config;\n this.apiTimeout = apiTimeout ?? API_TIMEOUT;\n\n this._markets = new MarketsClient(config.restEndpoint);\n this._account = new AccountClient(config.restEndpoint);\n }\n\n /**\n * Provides access to the MarketsClient instance.\n * This getter allows for interacting with market-related API functionalities.\n *\n * @returns {MarketsClient} An instance of MarketsClient for market-related operations.\n * @memberof ApiClient\n */\n get markets(): MarketsClient {\n return this._markets;\n }\n\n /**\n * Provides access to the AccountClient instance.\n * This getter allows for interacting with account-related API functionalities.\n *\n * @returns {AccountClient} An instance of AccountClient for account-related operations.\n * @memberof ApiClient\n */\n get account(): AccountClient {\n return this._account;\n }\n}\n"]}
1
+ {"version":3,"file":"api-client.js","sourceRoot":"/","sources":["clients/api-client.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,iDAK6B;AAC7B,8DAA8C;AAC9C,8DAA8C;AAE9C;;GAEG;AACH;IAUE,mBAAoB,MAAqB;QACvC,IAAI,CAAC,WAAW,GAAG,MAAM,CAAC,UAAU,CAAC,CAAC,CAAC,0BAAc,CAAC,CAAC,CAAC,uBAAW,CAAC;QACpE,SAAS,CAAC,MAAM,yBAAQ,SAAS,CAAC,MAAM,GAAK,MAAM,CAAE,CAAC;QACtD,IAAI,CAAC,QAAQ,GAAG,IAAI,iBAAa,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;QACpD,IAAI,CAAC,QAAQ,GAAG,IAAI,iBAAa,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;IACtD,CAAC;IAEa,mBAAS,GAAvB,UAAwB,MAAqB;QAC3C,SAAS,CAAC,MAAM,GAAG,MAAM,CAAC;QAC1B,SAAS,CAAC,QAAQ,GAAG,IAAI,SAAS,CAAC,MAAM,CAAC,CAAC;IAC7C,CAAC;IAEc,qBAAW,GAA1B;QACE,IAAI,CAAC,SAAS,CAAC,QAAQ,EAAE,CAAC;YACxB,MAAM,IAAI,KAAK,CACb,gEAAgE,CACjE,CAAC;QACJ,CAAC;QACD,OAAO,SAAS,CAAC,QAAQ,CAAC;IAC5B,CAAC;IASD,sBAAkB,oBAAO;QAPzB;;;;;;WAMG;aACH;YACE,OAAO,SAAS,CAAC,WAAW,EAAE,CAAC,QAAQ,CAAC;QAC1C,CAAC;;;OAAA;IASD,sBAAkB,oBAAO;QAPzB;;;;;;WAMG;aACH;YACE,OAAO,SAAS,CAAC,WAAW,EAAE,CAAC,QAAQ,CAAC;QAC1C,CAAC;;;OAAA;IAjDc,gBAAM,GAAkB;QACrC,UAAU,EAAE,IAAI,EAAE,gBAAgB;QAClC,OAAO,EAAE,uBAAW,EAAE,yCAAyC;KAChE,CAAC;IA+CJ,gBAAC;CAAA,AApDD,IAoDC;AApDY,8BAAS","sourcesContent":["import {\n ServiceConfig,\n API_TIMEOUT,\n API_TESTNET,\n API_PRODUCTION,\n} from './helpers/constants';\nimport MarketsClient from './modules/markets';\nimport AccountClient from './modules/account';\n\n/**\n * @description Client for API\n */\nexport class ApiClient {\n private static instance: ApiClient;\n private static config: ServiceConfig = {\n production: true, // default value\n timeout: API_TIMEOUT, // default value, e.g., 5000 milliseconds\n };\n private readonly apiEndpoint: string;\n private readonly _markets: MarketsClient;\n private readonly _account: AccountClient;\n\n private constructor(config: ServiceConfig) {\n this.apiEndpoint = config.production ? API_PRODUCTION : API_TESTNET;\n ApiClient.config = { ...ApiClient.config, ...config };\n this._markets = new MarketsClient(this.apiEndpoint);\n this._account = new AccountClient(this.apiEndpoint);\n }\n\n public static configure(config: ServiceConfig): void {\n ApiClient.config = config;\n ApiClient.instance = new ApiClient(config);\n }\n\n private static getInstance(): ApiClient {\n if (!ApiClient.instance) {\n throw new Error(\n 'ApiClient is not configured. Please configure it before using.',\n );\n }\n return ApiClient.instance;\n }\n\n /**\n * Provides access to the MarketsClient instance.\n * This getter allows for interacting with market-related API functionalities.\n *\n * @returns {MarketsClient} An instance of MarketsClient for market-related operations.\n * @memberof ApiClient\n */\n public static get markets(): MarketsClient {\n return ApiClient.getInstance()._markets;\n }\n\n /**\n * Provides access to the AccountClient instance.\n * This getter allows for interacting with account-related API functionalities.\n *\n * @returns {AccountClient} An instance of AccountClient for account-related operations.\n * @memberof ApiClient\n */\n public static get account(): AccountClient {\n return ApiClient.getInstance()._account;\n }\n}\n"]}
@@ -1,13 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ServiceConfig = exports.API_TIMEOUT = void 0;
3
+ exports.API_TESTNET = exports.API_PRODUCTION = exports.API_TIMEOUT = void 0;
4
4
  exports.API_TIMEOUT = 2500;
5
- var ServiceConfig = /** @class */ (function () {
6
- function ServiceConfig(restEndpoint, websocketEndpoint) {
7
- this.restEndpoint = restEndpoint;
8
- this.websocketEndpoint = websocketEndpoint;
9
- }
10
- return ServiceConfig;
11
- }());
12
- exports.ServiceConfig = ServiceConfig;
5
+ exports.API_PRODUCTION = 'https://m8mjgmqmte.eu-central-1.awsapprunner.com';
6
+ exports.API_TESTNET = 'https://m8mjgmqmte.eu-central-1.awsapprunner.com';
13
7
  //# sourceMappingURL=constants.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"constants.js","sourceRoot":"/","sources":["clients/helpers/constants.ts"],"names":[],"mappings":";;;AAAa,QAAA,WAAW,GAAW,IAAI,CAAC;AAExC;IAIE,uBAAY,YAAoB,EAAE,iBAAyB;QACzD,IAAI,CAAC,YAAY,GAAG,YAAY,CAAC;QACjC,IAAI,CAAC,iBAAiB,GAAG,iBAAiB,CAAC;IAC7C,CAAC;IACH,oBAAC;AAAD,CAAC,AARD,IAQC;AARY,sCAAa","sourcesContent":["export const API_TIMEOUT: number = 2500;\n\nexport class ServiceConfig {\n public restEndpoint: string;\n public websocketEndpoint: string;\n\n constructor(restEndpoint: string, websocketEndpoint: string) {\n this.restEndpoint = restEndpoint;\n this.websocketEndpoint = websocketEndpoint;\n }\n}\n"]}
1
+ {"version":3,"file":"constants.js","sourceRoot":"/","sources":["clients/helpers/constants.ts"],"names":[],"mappings":";;;AAAa,QAAA,WAAW,GAAW,IAAI,CAAC;AAO3B,QAAA,cAAc,GACzB,kDAAkD,CAAC;AAExC,QAAA,WAAW,GACtB,kDAAkD,CAAC","sourcesContent":["export const API_TIMEOUT: number = 2500;\n\nexport interface ServiceConfig {\n production?: boolean; // Base URL for the REST API\n timeout?: number; // Optional timeout for API requests\n}\n\nexport const API_PRODUCTION: string =\n 'https://m8mjgmqmte.eu-central-1.awsapprunner.com';\n\nexport const API_TESTNET: string =\n 'https://m8mjgmqmte.eu-central-1.awsapprunner.com';\n"]}
@@ -5,11 +5,14 @@ import AccountClient from './modules/account';
5
5
  * @description Client for API
6
6
  */
7
7
  export declare class ApiClient {
8
- readonly config: ServiceConfig;
9
- readonly apiTimeout: number;
10
- readonly _markets: MarketsClient;
11
- readonly _account: AccountClient;
12
- constructor(config: ServiceConfig, apiTimeout?: number);
8
+ private static instance;
9
+ private static config;
10
+ private readonly apiEndpoint;
11
+ private readonly _markets;
12
+ private readonly _account;
13
+ private constructor();
14
+ static configure(config: ServiceConfig): void;
15
+ private static getInstance;
13
16
  /**
14
17
  * Provides access to the MarketsClient instance.
15
18
  * This getter allows for interacting with market-related API functionalities.
@@ -17,7 +20,7 @@ export declare class ApiClient {
17
20
  * @returns {MarketsClient} An instance of MarketsClient for market-related operations.
18
21
  * @memberof ApiClient
19
22
  */
20
- get markets(): MarketsClient;
23
+ static get markets(): MarketsClient;
21
24
  /**
22
25
  * Provides access to the AccountClient instance.
23
26
  * This getter allows for interacting with account-related API functionalities.
@@ -25,6 +28,6 @@ export declare class ApiClient {
25
28
  * @returns {AccountClient} An instance of AccountClient for account-related operations.
26
29
  * @memberof ApiClient
27
30
  */
28
- get account(): AccountClient;
31
+ static get account(): AccountClient;
29
32
  }
30
33
  //# sourceMappingURL=api-client.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"api-client.d.ts","sourceRoot":"/","sources":["clients/api-client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAe,MAAM,qBAAqB,CAAC;AACjE,OAAO,aAAa,MAAM,mBAAmB,CAAC;AAC9C,OAAO,aAAa,MAAM,mBAAmB,CAAC;AAE9C;;GAEG;AACH,qBAAa,SAAS;IACpB,SAAgB,MAAM,EAAE,aAAa,CAAC;IACtC,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,QAAQ,EAAE,aAAa,CAAC;IACjC,QAAQ,CAAC,QAAQ,EAAE,aAAa,CAAC;gBAErB,MAAM,EAAE,aAAa,EAAE,UAAU,CAAC,EAAE,MAAM;IAQtD;;;;;;OAMG;IACH,IAAI,OAAO,IAAI,aAAa,CAE3B;IAED;;;;;;OAMG;IACH,IAAI,OAAO,IAAI,aAAa,CAE3B;CACF"}
1
+ {"version":3,"file":"api-client.d.ts","sourceRoot":"/","sources":["clients/api-client.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,aAAa,EAId,MAAM,qBAAqB,CAAC;AAC7B,OAAO,aAAa,MAAM,mBAAmB,CAAC;AAC9C,OAAO,aAAa,MAAM,mBAAmB,CAAC;AAE9C;;GAEG;AACH,qBAAa,SAAS;IACpB,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAY;IACnC,OAAO,CAAC,MAAM,CAAC,MAAM,CAGnB;IACF,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAS;IACrC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAgB;IACzC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAgB;IAEzC,OAAO;WAOO,SAAS,CAAC,MAAM,EAAE,aAAa,GAAG,IAAI;IAKpD,OAAO,CAAC,MAAM,CAAC,WAAW;IAS1B;;;;;;OAMG;IACH,WAAkB,OAAO,IAAI,aAAa,CAEzC;IAED;;;;;;OAMG;IACH,WAAkB,OAAO,IAAI,aAAa,CAEzC;CACF"}
@@ -1,7 +1,8 @@
1
1
  export declare const API_TIMEOUT: number;
2
- export declare class ServiceConfig {
3
- restEndpoint: string;
4
- websocketEndpoint: string;
5
- constructor(restEndpoint: string, websocketEndpoint: string);
2
+ export interface ServiceConfig {
3
+ production?: boolean;
4
+ timeout?: number;
6
5
  }
6
+ export declare const API_PRODUCTION: string;
7
+ export declare const API_TESTNET: string;
7
8
  //# sourceMappingURL=constants.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"constants.d.ts","sourceRoot":"/","sources":["clients/helpers/constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,WAAW,EAAE,MAAa,CAAC;AAExC,qBAAa,aAAa;IACjB,YAAY,EAAE,MAAM,CAAC;IACrB,iBAAiB,EAAE,MAAM,CAAC;gBAErB,YAAY,EAAE,MAAM,EAAE,iBAAiB,EAAE,MAAM;CAI5D"}
1
+ {"version":3,"file":"constants.d.ts","sourceRoot":"/","sources":["clients/helpers/constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,WAAW,EAAE,MAAa,CAAC;AAExC,MAAM,WAAW,aAAa;IAC5B,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,eAAO,MAAM,cAAc,EAAE,MACuB,CAAC;AAErD,eAAO,MAAM,WAAW,EAAE,MAC0B,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@reyaxyz/api-sdk",
3
- "version": "0.8.0",
3
+ "version": "0.9.0",
4
4
  "publishConfig": {
5
5
  "access": "public",
6
6
  "registry": "https://registry.npmjs.org"
@@ -36,5 +36,5 @@
36
36
  "axios": "^1.6.2"
37
37
  },
38
38
  "packageManager": "pnpm@8.10.4",
39
- "gitHead": "f762d6bc89fe5866fc0f22e21c4c804dc6147f08"
39
+ "gitHead": "21e2e1bd85d1a87ed212743419f0f3e8785be09a"
40
40
  }
@@ -1,4 +1,9 @@
1
- import { ServiceConfig, API_TIMEOUT } from './helpers/constants';
1
+ import {
2
+ ServiceConfig,
3
+ API_TIMEOUT,
4
+ API_TESTNET,
5
+ API_PRODUCTION,
6
+ } from './helpers/constants';
2
7
  import MarketsClient from './modules/markets';
3
8
  import AccountClient from './modules/account';
4
9
 
@@ -6,17 +11,34 @@ import AccountClient from './modules/account';
6
11
  * @description Client for API
7
12
  */
8
13
  export class ApiClient {
9
- public readonly config: ServiceConfig;
10
- readonly apiTimeout: number;
11
- readonly _markets: MarketsClient;
12
- readonly _account: AccountClient;
14
+ private static instance: ApiClient;
15
+ private static config: ServiceConfig = {
16
+ production: true, // default value
17
+ timeout: API_TIMEOUT, // default value, e.g., 5000 milliseconds
18
+ };
19
+ private readonly apiEndpoint: string;
20
+ private readonly _markets: MarketsClient;
21
+ private readonly _account: AccountClient;
13
22
 
14
- constructor(config: ServiceConfig, apiTimeout?: number) {
15
- this.config = config;
16
- this.apiTimeout = apiTimeout ?? API_TIMEOUT;
23
+ private constructor(config: ServiceConfig) {
24
+ this.apiEndpoint = config.production ? API_PRODUCTION : API_TESTNET;
25
+ ApiClient.config = { ...ApiClient.config, ...config };
26
+ this._markets = new MarketsClient(this.apiEndpoint);
27
+ this._account = new AccountClient(this.apiEndpoint);
28
+ }
29
+
30
+ public static configure(config: ServiceConfig): void {
31
+ ApiClient.config = config;
32
+ ApiClient.instance = new ApiClient(config);
33
+ }
17
34
 
18
- this._markets = new MarketsClient(config.restEndpoint);
19
- this._account = new AccountClient(config.restEndpoint);
35
+ private static getInstance(): ApiClient {
36
+ if (!ApiClient.instance) {
37
+ throw new Error(
38
+ 'ApiClient is not configured. Please configure it before using.',
39
+ );
40
+ }
41
+ return ApiClient.instance;
20
42
  }
21
43
 
22
44
  /**
@@ -26,8 +48,8 @@ export class ApiClient {
26
48
  * @returns {MarketsClient} An instance of MarketsClient for market-related operations.
27
49
  * @memberof ApiClient
28
50
  */
29
- get markets(): MarketsClient {
30
- return this._markets;
51
+ public static get markets(): MarketsClient {
52
+ return ApiClient.getInstance()._markets;
31
53
  }
32
54
 
33
55
  /**
@@ -37,7 +59,7 @@ export class ApiClient {
37
59
  * @returns {AccountClient} An instance of AccountClient for account-related operations.
38
60
  * @memberof ApiClient
39
61
  */
40
- get account(): AccountClient {
41
- return this._account;
62
+ public static get account(): AccountClient {
63
+ return ApiClient.getInstance()._account;
42
64
  }
43
65
  }
@@ -1,11 +1,12 @@
1
1
  export const API_TIMEOUT: number = 2500;
2
2
 
3
- export class ServiceConfig {
4
- public restEndpoint: string;
5
- public websocketEndpoint: string;
6
-
7
- constructor(restEndpoint: string, websocketEndpoint: string) {
8
- this.restEndpoint = restEndpoint;
9
- this.websocketEndpoint = websocketEndpoint;
10
- }
3
+ export interface ServiceConfig {
4
+ production?: boolean; // Base URL for the REST API
5
+ timeout?: number; // Optional timeout for API requests
11
6
  }
7
+
8
+ export const API_PRODUCTION: string =
9
+ 'https://m8mjgmqmte.eu-central-1.awsapprunner.com';
10
+
11
+ export const API_TESTNET: string =
12
+ 'https://m8mjgmqmte.eu-central-1.awsapprunner.com';