snaptrade-typescript-sdk 8.19.0 → 8.20.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 (75) hide show
  1. package/README.md +2 -2
  2. package/dist/api/account-information-api-generated.d.ts +525 -0
  3. package/dist/api/account-information-api-generated.js +765 -0
  4. package/dist/api/account-information-api.d.ts +3 -525
  5. package/dist/api/account-information-api.js +17 -1044
  6. package/dist/api/api-status-api-generated.d.ts +69 -0
  7. package/dist/api/api-status-api-generated.js +131 -0
  8. package/dist/api/api-status-api.d.ts +3 -69
  9. package/dist/api/api-status-api.js +17 -198
  10. package/dist/api/authentication-api-generated.d.ts +266 -0
  11. package/dist/api/authentication-api-generated.js +461 -0
  12. package/dist/api/authentication-api.d.ts +3 -266
  13. package/dist/api/authentication-api.js +17 -656
  14. package/dist/api/connections-api-generated.d.ts +274 -0
  15. package/dist/api/connections-api-generated.js +411 -0
  16. package/dist/api/connections-api.d.ts +3 -274
  17. package/dist/api/connections-api.js +17 -578
  18. package/dist/api/error-logs-api-generated.d.ts +93 -0
  19. package/dist/api/error-logs-api-generated.js +152 -0
  20. package/dist/api/error-logs-api.d.ts +3 -93
  21. package/dist/api/error-logs-api.js +17 -235
  22. package/dist/api/options-api-generated.d.ts +368 -0
  23. package/dist/api/options-api-generated.js +530 -0
  24. package/dist/api/options-api.d.ts +3 -368
  25. package/dist/api/options-api.js +17 -725
  26. package/dist/api/reference-data-api-generated.d.ts +467 -0
  27. package/dist/api/reference-data-api-generated.js +872 -0
  28. package/dist/api/reference-data-api.d.ts +3 -467
  29. package/dist/api/reference-data-api.js +17 -1241
  30. package/dist/api/trading-api-generated.d.ts +402 -0
  31. package/dist/api/trading-api-generated.js +613 -0
  32. package/dist/api/trading-api.d.ts +3 -402
  33. package/dist/api/trading-api.js +17 -836
  34. package/dist/api/transactions-and-reporting-api-generated.d.ts +217 -0
  35. package/dist/api/transactions-and-reporting-api-generated.js +287 -0
  36. package/dist/api/transactions-and-reporting-api.d.ts +3 -217
  37. package/dist/api/transactions-and-reporting-api.js +17 -398
  38. package/dist/base.js +10 -31
  39. package/dist/client-custom.js +3 -5
  40. package/dist/client.d.ts +1 -1
  41. package/dist/client.js +17 -35
  42. package/dist/common.js +64 -123
  43. package/dist/configuration.d.ts +1 -1
  44. package/dist/configuration.js +9 -11
  45. package/dist/error.d.ts +56 -0
  46. package/dist/error.js +104 -0
  47. package/dist/index.d.ts +1 -0
  48. package/dist/index.js +1 -0
  49. package/dist/jest.config.js +1 -1
  50. package/dist/pagination/page.js +15 -43
  51. package/dist/pagination/pageable.js +32 -88
  52. package/dist/pagination/paginate.js +15 -53
  53. package/dist/requestAfterHook.js +14 -14
  54. package/dist/requestBeforeHook.js +1 -1
  55. package/dist/requestBeforeUrlHook.d.ts +7 -0
  56. package/dist/requestBeforeUrlHook.js +5 -0
  57. package/package.json +2 -2
  58. package/dist/api/account-information-api-custom.d.ts +0 -3
  59. package/dist/api/account-information-api-custom.js +0 -27
  60. package/dist/api/api-status-api-custom.d.ts +0 -3
  61. package/dist/api/api-status-api-custom.js +0 -27
  62. package/dist/api/authentication-api-custom.d.ts +0 -3
  63. package/dist/api/authentication-api-custom.js +0 -27
  64. package/dist/api/connections-api-custom.d.ts +0 -3
  65. package/dist/api/connections-api-custom.js +0 -27
  66. package/dist/api/error-logs-api-custom.d.ts +0 -3
  67. package/dist/api/error-logs-api-custom.js +0 -27
  68. package/dist/api/options-api-custom.d.ts +0 -3
  69. package/dist/api/options-api-custom.js +0 -27
  70. package/dist/api/reference-data-api-custom.d.ts +0 -3
  71. package/dist/api/reference-data-api-custom.js +0 -27
  72. package/dist/api/trading-api-custom.d.ts +0 -3
  73. package/dist/api/trading-api-custom.js +0 -27
  74. package/dist/api/transactions-and-reporting-api-custom.d.ts +0 -3
  75. package/dist/api/transactions-and-reporting-api-custom.js +0 -27
package/dist/base.js CHANGED
@@ -11,26 +11,11 @@
11
11
  * NOTE: This file is auto generated by Konfig (https://konfigthis.com).
12
12
  * Do not edit the class manually.
13
13
  */
14
- var __extends = (this && this.__extends) || (function () {
15
- var extendStatics = function (d, b) {
16
- extendStatics = Object.setPrototypeOf ||
17
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
18
- function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
19
- return extendStatics(d, b);
20
- };
21
- return function (d, b) {
22
- if (typeof b !== "function" && b !== null)
23
- throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
24
- extendStatics(d, b);
25
- function __() { this.constructor = d; }
26
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
27
- };
28
- })();
29
14
  Object.defineProperty(exports, "__esModule", { value: true });
30
15
  exports.RequiredError = exports.BaseAPI = exports.COLLECTION_FORMATS = exports.BASE_PATH = void 0;
31
16
  // Some imports not used depending on template conditions
32
17
  // @ts-ignore
33
- var axios_1 = require("axios");
18
+ const axios_1 = require("axios");
34
19
  exports.BASE_PATH = "https://api.snaptrade.com/api/v1".replace(/\/+$/, "");
35
20
  /**
36
21
  *
@@ -47,10 +32,8 @@ exports.COLLECTION_FORMATS = {
47
32
  * @export
48
33
  * @class BaseAPI
49
34
  */
50
- var BaseAPI = /** @class */ (function () {
51
- function BaseAPI(configuration, basePath, axios) {
52
- if (basePath === void 0) { basePath = exports.BASE_PATH; }
53
- if (axios === void 0) { axios = axios_1.default; }
35
+ class BaseAPI {
36
+ constructor(configuration, basePath = exports.BASE_PATH, axios = axios_1.default) {
54
37
  this.basePath = basePath;
55
38
  this.axios = axios;
56
39
  if (configuration) {
@@ -58,8 +41,7 @@ var BaseAPI = /** @class */ (function () {
58
41
  this.basePath = configuration.basePath || this.basePath;
59
42
  }
60
43
  }
61
- return BaseAPI;
62
- }());
44
+ }
63
45
  exports.BaseAPI = BaseAPI;
64
46
  ;
65
47
  /**
@@ -68,14 +50,11 @@ exports.BaseAPI = BaseAPI;
68
50
  * @class RequiredError
69
51
  * @extends {Error}
70
52
  */
71
- var RequiredError = /** @class */ (function (_super) {
72
- __extends(RequiredError, _super);
73
- function RequiredError(field, msg) {
74
- var _this = _super.call(this, msg) || this;
75
- _this.field = field;
76
- _this.name = "RequiredError";
77
- return _this;
53
+ class RequiredError extends Error {
54
+ constructor(field, msg) {
55
+ super(msg);
56
+ this.field = field;
57
+ this.name = "RequiredError";
78
58
  }
79
- return RequiredError;
80
- }(Error));
59
+ }
81
60
  exports.RequiredError = RequiredError;
@@ -1,9 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.SnaptradeCustom = void 0;
4
- var SnaptradeCustom = /** @class */ (function () {
5
- function SnaptradeCustom(configurationParameters) {
6
- }
7
- return SnaptradeCustom;
8
- }());
4
+ class SnaptradeCustom {
5
+ constructor(configurationParameters) { }
6
+ }
9
7
  exports.SnaptradeCustom = SnaptradeCustom;
package/dist/client.d.ts CHANGED
@@ -21,5 +21,5 @@ export declare class Snaptrade extends SnaptradeCustom {
21
21
  readonly referenceData: ReferenceDataApi;
22
22
  readonly trading: TradingApi;
23
23
  readonly transactionsAndReporting: TransactionsAndReportingApi;
24
- constructor(configurationParameters: ConfigurationParameters);
24
+ constructor(configurationParameters?: ConfigurationParameters);
25
25
  }
package/dist/client.js CHANGED
@@ -9,42 +9,24 @@
9
9
  * NOTE: This file is auto generated by Konfig (https://konfigthis.com).
10
10
  * Do not edit the class manually.
11
11
  */
12
- var __extends = (this && this.__extends) || (function () {
13
- var extendStatics = function (d, b) {
14
- extendStatics = Object.setPrototypeOf ||
15
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
16
- function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
17
- return extendStatics(d, b);
18
- };
19
- return function (d, b) {
20
- if (typeof b !== "function" && b !== null)
21
- throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
22
- extendStatics(d, b);
23
- function __() { this.constructor = d; }
24
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
25
- };
26
- })();
27
12
  Object.defineProperty(exports, "__esModule", { value: true });
28
13
  exports.Snaptrade = void 0;
29
- var api_1 = require("./api");
30
- var configuration_1 = require("./configuration");
31
- var client_custom_1 = require("./client-custom");
32
- var Snaptrade = /** @class */ (function (_super) {
33
- __extends(Snaptrade, _super);
34
- function Snaptrade(configurationParameters) {
35
- var _this = _super.call(this, configurationParameters) || this;
36
- var configuration = new configuration_1.Configuration(configurationParameters);
37
- _this.accountInformation = new api_1.AccountInformationApi(configuration);
38
- _this.apiStatus = new api_1.ApiStatusApi(configuration);
39
- _this.authentication = new api_1.AuthenticationApi(configuration);
40
- _this.connections = new api_1.ConnectionsApi(configuration);
41
- _this.errorLogs = new api_1.ErrorLogsApi(configuration);
42
- _this.options = new api_1.OptionsApi(configuration);
43
- _this.referenceData = new api_1.ReferenceDataApi(configuration);
44
- _this.trading = new api_1.TradingApi(configuration);
45
- _this.transactionsAndReporting = new api_1.TransactionsAndReportingApi(configuration);
46
- return _this;
14
+ const api_1 = require("./api");
15
+ const configuration_1 = require("./configuration");
16
+ const client_custom_1 = require("./client-custom");
17
+ class Snaptrade extends client_custom_1.SnaptradeCustom {
18
+ constructor(configurationParameters = {}) {
19
+ super(configurationParameters);
20
+ const configuration = new configuration_1.Configuration(configurationParameters);
21
+ this.accountInformation = new api_1.AccountInformationApi(configuration);
22
+ this.apiStatus = new api_1.ApiStatusApi(configuration);
23
+ this.authentication = new api_1.AuthenticationApi(configuration);
24
+ this.connections = new api_1.ConnectionsApi(configuration);
25
+ this.errorLogs = new api_1.ErrorLogsApi(configuration);
26
+ this.options = new api_1.OptionsApi(configuration);
27
+ this.referenceData = new api_1.ReferenceDataApi(configuration);
28
+ this.trading = new api_1.TradingApi(configuration);
29
+ this.transactionsAndReporting = new api_1.TransactionsAndReportingApi(configuration);
47
30
  }
48
- return Snaptrade;
49
- }(client_custom_1.SnaptradeCustom));
31
+ }
50
32
  exports.Snaptrade = Snaptrade;
package/dist/common.js CHANGED
@@ -11,17 +11,6 @@
11
11
  * NOTE: This file is auto generated by Konfig (https://konfigthis.com).
12
12
  * Do not edit the class manually.
13
13
  */
14
- var __assign = (this && this.__assign) || function () {
15
- __assign = Object.assign || function(t) {
16
- for (var s, i = 1, n = arguments.length; i < n; i++) {
17
- s = arguments[i];
18
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
19
- t[p] = s[p];
20
- }
21
- return t;
22
- };
23
- return __assign.apply(this, arguments);
24
- };
25
14
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
26
15
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
27
16
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -31,37 +20,13 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
31
20
  step((generator = generator.apply(thisArg, _arguments || [])).next());
32
21
  });
33
22
  };
34
- var __generator = (this && this.__generator) || function (thisArg, body) {
35
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
36
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
37
- function verb(n) { return function (v) { return step([n, v]); }; }
38
- function step(op) {
39
- if (f) throw new TypeError("Generator is already executing.");
40
- while (g && (g = 0, op[0] && (_ = 0)), _) try {
41
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
42
- if (y = 0, t) op = [op[0] & 2, t.value];
43
- switch (op[0]) {
44
- case 0: case 1: t = op; break;
45
- case 4: _.label++; return { value: op[1], done: false };
46
- case 5: _.label++; y = op[1]; op = [0]; continue;
47
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
48
- default:
49
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
50
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
51
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
52
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
53
- if (t[2]) _.ops.pop();
54
- _.trys.pop(); continue;
55
- }
56
- op = body.call(thisArg, _);
57
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
58
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
59
- }
60
- };
61
23
  Object.defineProperty(exports, "__esModule", { value: true });
62
24
  exports.isBrowser = exports.createRequestFunction = exports.toPathString = exports.serializeDataIfNeeded = exports.setSearchParams = exports.setBearerAuthToObject = exports.setBasicAuthToObject = exports.setApiKeyToObject = exports.assertParamExists = exports.DUMMY_BASE_URL = void 0;
63
- var base_1 = require("./base");
64
- var requestAfterHook_1 = require("./requestAfterHook");
25
+ const base_1 = require("./base");
26
+ const axios_1 = require("axios");
27
+ const requestAfterHook_1 = require("./requestAfterHook");
28
+ const requestBeforeUrlHook_1 = require("./requestBeforeUrlHook");
29
+ const error_1 = require("./error");
65
30
  /**
66
31
  *
67
32
  * @export
@@ -72,9 +37,9 @@ exports.DUMMY_BASE_URL = 'https://example.com';
72
37
  * @throws {RequiredError}
73
38
  * @export
74
39
  */
75
- var assertParamExists = function (functionName, paramName, paramValue) {
40
+ const assertParamExists = function (functionName, paramName, paramValue) {
76
41
  if (paramValue === null || paramValue === undefined) {
77
- throw new base_1.RequiredError(paramName, "Required parameter ".concat(paramName, " was null or undefined when calling ").concat(functionName, "."));
42
+ throw new base_1.RequiredError(paramName, `Required parameter ${paramName} was null or undefined when calling ${functionName}.`);
78
43
  }
79
44
  };
80
45
  exports.assertParamExists = assertParamExists;
@@ -82,40 +47,27 @@ exports.assertParamExists = assertParamExists;
82
47
  *
83
48
  * @export
84
49
  */
85
- var setApiKeyToObject = function (_a) {
86
- var object = _a.object, key = _a.key, type = _a.type, keyParamName = _a.keyParamName, configuration = _a.configuration, prefix = _a.prefix;
87
- return __awaiter(this, void 0, void 0, function () {
88
- var apiKey;
89
- return __generator(this, function (_b) {
90
- switch (_b.label) {
91
- case 0:
92
- key = key ? key : keyParamName;
93
- apiKey = null;
94
- if (!(configuration && configuration.apiKey)) return [3 /*break*/, 3];
95
- if (!(typeof configuration.apiKey === 'function')) return [3 /*break*/, 2];
96
- return [4 /*yield*/, configuration.apiKey(keyParamName)];
97
- case 1:
98
- apiKey = _b.sent();
99
- return [3 /*break*/, 3];
100
- case 2:
101
- if (typeof configuration.apiKey === 'string')
102
- apiKey = configuration.apiKey;
103
- else if (typeof configuration.apiKey === 'object') {
104
- if (keyParamName in configuration.apiKey)
105
- apiKey = configuration.apiKey[keyParamName];
106
- }
107
- else
108
- throw Error("Unexpected type ".concat(typeof configuration.apiKey, " for Configuration.apiKey"));
109
- _b.label = 3;
110
- case 3:
111
- if (!apiKey)
112
- return [2 /*return*/];
113
- object[key] = prefix !== undefined ? "".concat(prefix).concat(apiKey) : apiKey;
114
- if (type === "Cookie")
115
- object[key] = "".concat(keyParamName, "=").concat(object[key]);
116
- return [2 /*return*/];
50
+ const setApiKeyToObject = function ({ object, key, type, keyParamName, configuration, prefix }) {
51
+ return __awaiter(this, void 0, void 0, function* () {
52
+ key = key ? key : keyParamName;
53
+ let apiKey = null;
54
+ if (configuration && configuration.apiKey) {
55
+ if (typeof configuration.apiKey === 'function')
56
+ apiKey = yield configuration.apiKey(keyParamName);
57
+ else if (typeof configuration.apiKey === 'string')
58
+ apiKey = configuration.apiKey;
59
+ else if (typeof configuration.apiKey === 'object') {
60
+ if (keyParamName in configuration.apiKey)
61
+ apiKey = configuration.apiKey[keyParamName];
117
62
  }
118
- });
63
+ else
64
+ throw Error(`Unexpected type ${typeof configuration.apiKey} for Configuration.apiKey`);
65
+ }
66
+ if (!apiKey)
67
+ return;
68
+ object[key] = prefix !== undefined ? `${prefix}${apiKey}` : apiKey;
69
+ if (type === "Cookie")
70
+ object[key] = `${keyParamName}=${object[key]}`;
119
71
  });
120
72
  };
121
73
  exports.setApiKeyToObject = setApiKeyToObject;
@@ -123,7 +75,7 @@ exports.setApiKeyToObject = setApiKeyToObject;
123
75
  *
124
76
  * @export
125
77
  */
126
- var setBasicAuthToObject = function (object, configuration) {
78
+ const setBasicAuthToObject = function (object, configuration) {
127
79
  if (configuration && (configuration.username || configuration.password)) {
128
80
  object["auth"] = { username: configuration.username, password: configuration.password };
129
81
  }
@@ -133,42 +85,24 @@ exports.setBasicAuthToObject = setBasicAuthToObject;
133
85
  *
134
86
  * @export
135
87
  */
136
- var setBearerAuthToObject = function (object, configuration) {
137
- return __awaiter(this, void 0, void 0, function () {
138
- var accessToken, _a;
139
- return __generator(this, function (_b) {
140
- switch (_b.label) {
141
- case 0:
142
- if (!(configuration && configuration.accessToken)) return [3 /*break*/, 5];
143
- if (!(typeof configuration.accessToken === 'function')) return [3 /*break*/, 2];
144
- return [4 /*yield*/, configuration.accessToken()];
145
- case 1:
146
- _a = _b.sent();
147
- return [3 /*break*/, 4];
148
- case 2: return [4 /*yield*/, configuration.accessToken];
149
- case 3:
150
- _a = _b.sent();
151
- _b.label = 4;
152
- case 4:
153
- accessToken = _a;
154
- object["Authorization"] = "Bearer " + accessToken;
155
- _b.label = 5;
156
- case 5: return [2 /*return*/];
157
- }
158
- });
88
+ const setBearerAuthToObject = function (object, configuration) {
89
+ return __awaiter(this, void 0, void 0, function* () {
90
+ if (configuration && configuration.accessToken) {
91
+ const accessToken = typeof configuration.accessToken === 'function'
92
+ ? yield configuration.accessToken()
93
+ : yield configuration.accessToken;
94
+ object["Authorization"] = "Bearer " + accessToken;
95
+ }
159
96
  });
160
97
  };
161
98
  exports.setBearerAuthToObject = setBearerAuthToObject;
162
- function setFlattenedQueryParams(urlSearchParams, parameter, key) {
163
- if (key === void 0) { key = ""; }
99
+ function setFlattenedQueryParams(urlSearchParams, parameter, key = "") {
164
100
  if (typeof parameter === "object") {
165
101
  if (Array.isArray(parameter)) {
166
- parameter.forEach(function (item) { return setFlattenedQueryParams(urlSearchParams, item, key); });
102
+ parameter.forEach(item => setFlattenedQueryParams(urlSearchParams, item, key));
167
103
  }
168
104
  else {
169
- Object.keys(parameter).forEach(function (currentKey) {
170
- return setFlattenedQueryParams(urlSearchParams, parameter[currentKey], "".concat(key).concat(key !== '' ? '.' : '').concat(currentKey));
171
- });
105
+ Object.keys(parameter).forEach(currentKey => setFlattenedQueryParams(urlSearchParams, parameter[currentKey], `${key}${key !== '' ? '.' : ''}${currentKey}`));
172
106
  }
173
107
  }
174
108
  else {
@@ -184,12 +118,8 @@ function setFlattenedQueryParams(urlSearchParams, parameter, key) {
184
118
  *
185
119
  * @export
186
120
  */
187
- var setSearchParams = function (url) {
188
- var objects = [];
189
- for (var _i = 1; _i < arguments.length; _i++) {
190
- objects[_i - 1] = arguments[_i];
191
- }
192
- var searchParams = new URLSearchParams(url.search);
121
+ const setSearchParams = function (url, ...objects) {
122
+ const searchParams = new URLSearchParams(url.search);
193
123
  setFlattenedQueryParams(searchParams, objects);
194
124
  url.search = searchParams.toString();
195
125
  };
@@ -198,9 +128,9 @@ exports.setSearchParams = setSearchParams;
198
128
  *
199
129
  * @export
200
130
  */
201
- var serializeDataIfNeeded = function (value, requestOptions, configuration) {
202
- var nonString = typeof value !== 'string';
203
- var needsSerialization = nonString && configuration && configuration.isJsonMime
131
+ const serializeDataIfNeeded = function (value, requestOptions, configuration) {
132
+ const nonString = typeof value !== 'string';
133
+ const needsSerialization = nonString && configuration && configuration.isJsonMime
204
134
  ? configuration.isJsonMime(requestOptions.headers['Content-Type'])
205
135
  : nonString;
206
136
  return needsSerialization
@@ -212,7 +142,7 @@ exports.serializeDataIfNeeded = serializeDataIfNeeded;
212
142
  *
213
143
  * @export
214
144
  */
215
- var toPathString = function (url) {
145
+ const toPathString = function (url) {
216
146
  return url.pathname + url.search + url.hash;
217
147
  };
218
148
  exports.toPathString = toPathString;
@@ -220,14 +150,25 @@ exports.toPathString = toPathString;
220
150
  *
221
151
  * @export
222
152
  */
223
- var createRequestFunction = function (axiosArgs, globalAxios, BASE_PATH, configuration) {
224
- return function (axios, basePath) {
225
- if (axios === void 0) { axios = globalAxios; }
226
- if (basePath === void 0) { basePath = BASE_PATH; }
227
- var url = ((configuration === null || configuration === void 0 ? void 0 : configuration.basePath) || basePath) + axiosArgs.url;
228
- (0, requestAfterHook_1.requestAfterHook)({ axiosArgs: axiosArgs, basePath: basePath, url: url, configuration: configuration });
229
- return axios.request(__assign(__assign({}, axiosArgs.options), { url: url }));
230
- };
153
+ const createRequestFunction = function (axiosArgs, globalAxios, BASE_PATH, configuration) {
154
+ return (axios = globalAxios, basePath = BASE_PATH) => __awaiter(this, void 0, void 0, function* () {
155
+ var _a, _b;
156
+ (0, requestBeforeUrlHook_1.requestBeforeUrlHook)({ axiosArgs, basePath, configuration });
157
+ const url = ((configuration === null || configuration === void 0 ? void 0 : configuration.basePath) || basePath) + axiosArgs.url;
158
+ (0, requestAfterHook_1.requestAfterHook)({ axiosArgs, basePath, url, configuration });
159
+ try {
160
+ return yield axios.request(Object.assign(Object.assign({}, axiosArgs.options), { url }));
161
+ }
162
+ catch (e) {
163
+ if (e instanceof axios_1.AxiosError && e.isAxiosError) {
164
+ const responseBody = ((_a = e.response) === null || _a === void 0 ? void 0 : _a.data) instanceof ReadableStream
165
+ ? yield (0, error_1.readableStreamToString)(e.response.data)
166
+ : (_b = e.response) === null || _b === void 0 ? void 0 : _b.data;
167
+ throw new error_1.SnaptradeError(e, (0, error_1.parseIfJson)(responseBody));
168
+ }
169
+ throw e;
170
+ }
171
+ });
231
172
  };
232
173
  exports.createRequestFunction = createRequestFunction;
233
174
  function isBrowser() {
@@ -14,7 +14,7 @@ type ApiKey = string | ((keyParamName: string) => string) | ((keyParamName: stri
14
14
  export interface ConfigurationParameters {
15
15
  consumerKey?: string;
16
16
  clientId?: string;
17
- Signature?: string;
17
+ signature?: string;
18
18
  timestamp?: string;
19
19
  apiKey?: ApiKey;
20
20
  username?: string;
@@ -13,9 +13,8 @@
13
13
  */
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
15
  exports.Configuration = void 0;
16
- var Configuration = /** @class */ (function () {
17
- function Configuration(param) {
18
- if (param === void 0) { param = {}; }
16
+ class Configuration {
17
+ constructor(param = {}) {
19
18
  var _a;
20
19
  this.consumerKey = param.consumerKey;
21
20
  this.apiKey = param.apiKey;
@@ -23,8 +22,8 @@ var Configuration = /** @class */ (function () {
23
22
  this.apiKey = {};
24
23
  if (param.clientId !== undefined)
25
24
  this.apiKey["clientId"] = param.clientId;
26
- if (param.Signature !== undefined)
27
- this.apiKey["Signature"] = param.Signature;
25
+ if (param.signature !== undefined)
26
+ this.apiKey["Signature"] = param.signature;
28
27
  if (param.timestamp !== undefined)
29
28
  this.apiKey["timestamp"] = param.timestamp;
30
29
  }
@@ -33,7 +32,7 @@ var Configuration = /** @class */ (function () {
33
32
  this.accessToken = param.accessToken;
34
33
  this.basePath = param.basePath;
35
34
  this.baseOptions = (_a = param.baseOptions) !== null && _a !== void 0 ? _a : {};
36
- this.userAgent = param.userAgent === undefined ? "Konfig/8.19.0/typescript" : param.userAgent;
35
+ this.userAgent = param.userAgent === undefined ? "Konfig/8.20.0/typescript" : param.userAgent;
37
36
  this.formDataCtor = param.formDataCtor;
38
37
  }
39
38
  /**
@@ -46,10 +45,9 @@ var Configuration = /** @class */ (function () {
46
45
  * @param mime - MIME (Multipurpose Internet Mail Extensions)
47
46
  * @return True if the given MIME is JSON, false otherwise.
48
47
  */
49
- Configuration.prototype.isJsonMime = function (mime) {
50
- var jsonMime = new RegExp('^(application\/json|[^;/ \t]+\/[^;/ \t]+[+]json)[ \t]*(;.*)?$', 'i');
48
+ isJsonMime(mime) {
49
+ const jsonMime = new RegExp('^(application\/json|[^;/ \t]+\/[^;/ \t]+[+]json)[ \t]*(;.*)?$', 'i');
51
50
  return mime !== null && (jsonMime.test(mime) || mime.toLowerCase() === 'application/json-patch+json');
52
- };
53
- return Configuration;
54
- }());
51
+ }
52
+ }
55
53
  exports.Configuration = Configuration;
@@ -0,0 +1,56 @@
1
+ /**
2
+ * SnapTrade
3
+ * Connect brokerage accounts to your app for live positions and trading
4
+ *
5
+ * The version of the OpenAPI document: 1.0.0
6
+ * Contact: api@snaptrade.com
7
+ *
8
+ * NOTE: This file is auto generated by Konfig (https://konfigthis.com).
9
+ * Do not edit the class manually.
10
+ */
11
+ import type { AxiosError } from "axios";
12
+ /**
13
+ * This class provides a wrapper for network errors when making requests to SnapTrade
14
+ */
15
+ export declare class SnaptradeError extends Error {
16
+ /**
17
+ * The response body
18
+ */
19
+ readonly responseBody: unknown;
20
+ /**
21
+ * The error code provided from the underlying "axios" library which can be
22
+ * more descriptive than the HTTP status descriptions.
23
+ */
24
+ readonly code?: string;
25
+ /**
26
+ * The status code from the response.
27
+ * For explanations, refer to https://developer.mozilla.org/en-US/docs/Web/HTTP/Status
28
+ */
29
+ readonly status?: number;
30
+ /**
31
+ * The status text from the response.
32
+ * For explanations, refer to https://developer.mozilla.org/en-US/docs/Web/HTTP/Status
33
+ */
34
+ readonly statusText?: string;
35
+ /**
36
+ * The URL that the original request was sent to
37
+ */
38
+ readonly url?: string;
39
+ /**
40
+ * HTTP request method (see https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods)
41
+ */
42
+ readonly method?: string;
43
+ constructor(axiosError: AxiosError, responseBody: unknown);
44
+ toJSON(): {
45
+ name: string;
46
+ message: string;
47
+ method: string;
48
+ url: string;
49
+ code: string;
50
+ status: number;
51
+ statusText: string;
52
+ responseBody: unknown;
53
+ };
54
+ }
55
+ export declare function readableStreamToString(stream: ReadableStream): Promise<string>;
56
+ export declare function parseIfJson(input: unknown): object | unknown;
package/dist/error.js ADDED
@@ -0,0 +1,104 @@
1
+ "use strict";
2
+ /**
3
+ * SnapTrade
4
+ * Connect brokerage accounts to your app for live positions and trading
5
+ *
6
+ * The version of the OpenAPI document: 1.0.0
7
+ * Contact: api@snaptrade.com
8
+ *
9
+ * NOTE: This file is auto generated by Konfig (https://konfigthis.com).
10
+ * Do not edit the class manually.
11
+ */
12
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
13
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
14
+ return new (P || (P = Promise))(function (resolve, reject) {
15
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
16
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
17
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
18
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
19
+ });
20
+ };
21
+ Object.defineProperty(exports, "__esModule", { value: true });
22
+ exports.parseIfJson = exports.readableStreamToString = exports.SnaptradeError = void 0;
23
+ /**
24
+ * This class provides a wrapper for network errors when making requests to SnapTrade
25
+ */
26
+ class SnaptradeError extends Error {
27
+ constructor(axiosError, responseBody) {
28
+ var _a, _b, _c;
29
+ super(axiosError.message);
30
+ this.name = "SnaptradeError";
31
+ this.code = axiosError.code;
32
+ this.method = (_a = axiosError.config.method) === null || _a === void 0 ? void 0 : _a.toUpperCase();
33
+ this.url = axiosError.config.url;
34
+ this.status = (_b = axiosError.response) === null || _b === void 0 ? void 0 : _b.status;
35
+ this.statusText = (_c = axiosError.response) === null || _c === void 0 ? void 0 : _c.statusText;
36
+ this.responseBody = responseBody;
37
+ }
38
+ toJSON() {
39
+ return {
40
+ name: this.name,
41
+ message: this.message,
42
+ method: this.method,
43
+ url: this.url,
44
+ code: this.code,
45
+ status: this.status,
46
+ statusText: this.statusText,
47
+ responseBody: this.responseBody,
48
+ };
49
+ }
50
+ }
51
+ exports.SnaptradeError = SnaptradeError;
52
+ function readableStreamToString(stream) {
53
+ return __awaiter(this, void 0, void 0, function* () {
54
+ // Step 1: Create a new TextDecoder
55
+ const decoder = new TextDecoder();
56
+ // Step 2: Create a new ReadableStreamDefaultReader
57
+ const reader = stream.getReader();
58
+ // Step 3: Initialize an empty string to hold the result
59
+ let result = "";
60
+ try {
61
+ while (true) {
62
+ // Step 4: Read data from the stream
63
+ const { done, value } = yield reader.read();
64
+ // If there is no more data to read, break the loop
65
+ if (done)
66
+ break;
67
+ // Convert the chunk of data to a string using the TextDecoder
68
+ const chunk = decoder.decode(value, { stream: true });
69
+ // Concatenate the chunk to the result
70
+ result += chunk;
71
+ }
72
+ }
73
+ finally {
74
+ // Step 5: Release the ReadableStreamDefaultReader when done or in case of an error
75
+ reader.releaseLock();
76
+ }
77
+ // Return the final result as a string
78
+ return result;
79
+ });
80
+ }
81
+ exports.readableStreamToString = readableStreamToString;
82
+ function parseIfJson(input) {
83
+ if (typeof input !== "string") {
84
+ // If the input is not a string, return the original input
85
+ return input;
86
+ }
87
+ try {
88
+ // Attempt to parse the input as JSON
89
+ const parsedJSON = JSON.parse(input);
90
+ // Check if the parsed result is an object (not an array or primitive value)
91
+ if (typeof parsedJSON === "object" && parsedJSON !== null) {
92
+ return parsedJSON;
93
+ }
94
+ else {
95
+ // Return the original input if the parsed result is not an object
96
+ return input;
97
+ }
98
+ }
99
+ catch (error) {
100
+ // Return the original input if parsing fails (invalid JSON)
101
+ return input;
102
+ }
103
+ }
104
+ exports.parseIfJson = parseIfJson;
package/dist/index.d.ts CHANGED
@@ -12,3 +12,4 @@ export * from "./api";
12
12
  export * from "./configuration";
13
13
  export * from "./models";
14
14
  export * from "./client";
15
+ export * from "./error";
package/dist/index.js CHANGED
@@ -30,3 +30,4 @@ __exportStar(require("./api"), exports);
30
30
  __exportStar(require("./configuration"), exports);
31
31
  __exportStar(require("./models"), exports);
32
32
  __exportStar(require("./client"), exports);
33
+ __exportStar(require("./error"), exports);
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- var config = {
3
+ const config = {
4
4
  verbose: true,
5
5
  preset: "ts-jest",
6
6
  testEnvironment: "node",