|
1 | | -const sdk = require('../index.js'); |
| 1 | +import { DefaultApi } from '../index.js'; |
| 2 | +import ApiClient from '../ApiClient.js'; |
2 | 3 |
|
3 | | -/** Class representing a Connection. */ |
| 4 | +/** |
| 5 | + * Class representing a connection to the Rel server |
| 6 | + */ |
4 | 7 | class Connection { |
5 | | - /** |
6 | | - * Create a Connection |
7 | | - * @param {Object} [params] - User specified override values. |
8 | | - * @param {string} [params.scheme="http"] - Connection scheme. |
9 | | - * @param {string} [params.host="127.0.0.1"] -Address of running server. |
10 | | - * @param {number} [params.port=8010] - Port of running server. *Must be an Integer.* |
11 | | - * @param {string} [params.debugLevel=0] - Desired debugging level. |
12 | | - * @param {number} [params.connectionTimeout=300] - Connection timeout duration. |
13 | | - * @param {Transaction.ModeEnum} [params.defaultOpenMode=OPEN] |
14 | | - */ |
15 | | - constructor(params) { |
16 | | - const _params = typeof params === 'undefined' ? new Object() : params |
17 | | - |
18 | | - this.scheme = _params.scheme || "http" |
19 | | - this.host = _params.host || "127.0.0.1" |
20 | | - this.port = _params.port || 8010 |
21 | | - this.debugLevel = _params.debugLevel || 0 |
22 | | - this.connectionTimeout = _params.connectionTimeout || 300 // seconds |
23 | | - this.defaultOpenMode = _params.defaultOpenMode || sdk.Transaction.ModeEnum.OPEN |
24 | | - } |
| 8 | + /** |
| 9 | + * Create a connection |
| 10 | + * @param {String} [params.basePath] - The base URL against which to resolve every API call's (relative) path. |
| 11 | + * The default is http://127.0.0.1:8010. |
| 12 | + * @param {Array.<String>} [params.authentications] - The authentication methods to be included for all API calls. |
| 13 | + * This is a placeholder for eventual use with the cloud connection. |
| 14 | + * @param {Array.<String>} [params.defaultHeaders] - The default HTTP headers to be included for all API calls. |
| 15 | + * The default is {} |
| 16 | + * @param {Number} [params.timeout] - The default HTTP timeout for all API calls. The default is 60000 |
| 17 | + * @param {Boolean} [params.cache] - If set to false an additional timestamp parameter is added to all API GET |
| 18 | + * calls to prevent browser caching. The default is true |
| 19 | + * @param {Boolean} [params.enableCookies] - If set to true, the client will save the cookies from each server |
| 20 | + * response, and return them in the next request. |
| 21 | + */ |
| 22 | + constructor(params = {}) { |
| 23 | + const apiClient = new ApiClient(); |
| 24 | + this._defaultApi = new DefaultApi(apiClient); |
| 25 | + this._api = this._defaultApi.apiClient; |
25 | 26 |
|
26 | | - /** |
27 | | - * Get connection scheme |
28 | | - */ |
29 | | - get scheme() { |
30 | | - return this._scheme |
| 27 | + if (params.basePath) { |
| 28 | + this._api.basePath = params.basePath; |
31 | 29 | } |
32 | | - |
33 | | - /** |
34 | | - * Setter for scheme |
35 | | - */ |
36 | | - set scheme(s) { |
37 | | - this._scheme = s |
| 30 | + if (params.authentications) { |
| 31 | + this._api.authentications = params.authentications; |
38 | 32 | } |
39 | | - |
40 | | - /** |
41 | | - * Get connection host |
42 | | - */ |
43 | | - get host() { |
44 | | - return this._host |
| 33 | + if (params.defaultHeaders) { |
| 34 | + this._api.defaultHeaders = params.defaultHeaders; |
45 | 35 | } |
46 | | - |
47 | | - /** |
48 | | - * Setter for host |
49 | | - */ |
50 | | - set host(addr) { |
51 | | - this._host = addr |
| 36 | + if (params.hasOwnProperty('timeout')) { |
| 37 | + this._api.timeout = params.timeout; |
52 | 38 | } |
53 | | - |
54 | | - /** |
55 | | - * Get connection port |
56 | | - */ |
57 | | - get port() { |
58 | | - return this._port |
| 39 | + if (params.hasOwnProperty('cache')) { |
| 40 | + this._api.cache = params.cache; |
59 | 41 | } |
60 | | - |
61 | | - /** |
62 | | - * Setter for port |
63 | | - */ |
64 | | - set port(p) { |
65 | | - this._port = p |
| 42 | + if (params.hasOwnProperty('enableCookies')) { |
| 43 | + this._api.enableCookies = params.enableCookies; |
66 | 44 | } |
| 45 | + } |
67 | 46 |
|
68 | | - /** |
69 | | - * Get debug level. |
70 | | - * @return {number} Current debug level. |
71 | | - */ |
72 | | - get debugLevel() { |
73 | | - return this._debugLevel |
74 | | - } |
| 47 | + get api() { |
| 48 | + return this._api; |
| 49 | + } |
75 | 50 |
|
76 | | - /** |
77 | | - * Set debug level. |
78 | | - * @param {number} level - Desired debug level. |
79 | | - */ |
80 | | - set debugLevel(level) { |
81 | | - this._debugLevel = level |
82 | | - } |
| 51 | + get defaultApi() { |
| 52 | + return this._defaultApi; |
| 53 | + } |
83 | 54 |
|
84 | | - /** |
85 | | - * Get duration of connection timeout (seconds). |
86 | | - * @return {number} Current connection timeout in seconds. |
87 | | - */ |
88 | | - get connectionTimeout() { |
89 | | - return this._connectionTimeout |
90 | | - } |
| 55 | + get transactionPost() { |
| 56 | + return this._transactionPost; |
| 57 | + } |
91 | 58 |
|
92 | | - /** |
93 | | - * Set duration of connection timeout (seconds). |
94 | | - * @param {number} duration - Duration of connection timeout, in seconds. |
95 | | - */ |
96 | | - set connectionTimeout(duration) { |
97 | | - this._connectionTimeout = duration |
98 | | - } |
| 59 | + get basePath() { |
| 60 | + return this._api.basePath; |
| 61 | + } |
| 62 | + set basePath(basePath) { |
| 63 | + this._api.basePath = basePath; |
| 64 | + } |
99 | 65 |
|
100 | | - /** |
101 | | - * Get connection defaultOpenMode |
102 | | - */ |
103 | | - get defaultOpenMode() { |
104 | | - return this._defaultOpenMode |
105 | | - } |
| 66 | + get authentications() { |
| 67 | + return this._api.authentications; |
| 68 | + } |
| 69 | + set authentications(authentications) { |
| 70 | + this._api.authentications = authentications; |
| 71 | + } |
106 | 72 |
|
107 | | - /** |
108 | | - * Setter for defaultOpenMode |
109 | | - */ |
110 | | - set defaultOpenMode(mode) { |
111 | | - this._defaultOpenMode = mode |
112 | | - } |
| 73 | + get defaultHeaders() { |
| 74 | + return this._api.defaultHeaders; |
| 75 | + } |
| 76 | + set defaultHeaders(defaultHeaders) { |
| 77 | + this._api.defaultHeaders = defaultHeaders; |
| 78 | + } |
| 79 | + |
| 80 | + get cache() { |
| 81 | + return this._api.cache; |
| 82 | + } |
| 83 | + set cache(cache) { |
| 84 | + this._api.cache = cache; |
| 85 | + } |
| 86 | + |
| 87 | + get timeout() { |
| 88 | + return this._api.timeout; |
| 89 | + } |
| 90 | + set timeout(timeout) { |
| 91 | + this._api.timeout = timeout; |
| 92 | + } |
| 93 | + |
| 94 | + get enableCookies() { |
| 95 | + return this._api.enableCookies; |
| 96 | + } |
| 97 | + set enableCookies(enableCookies) { |
| 98 | + this._api.enableCookies = enableCookies; |
| 99 | + } |
113 | 100 | } |
114 | 101 |
|
115 | | -module.exports = Connection |
| 102 | +export default Connection; |
0 commit comments