@eway-crm/connector 1.0.119 → 1.0.121

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 (195) hide show
  1. package/lib/AnonymousSessionHandler.d.ts +5 -5
  2. package/lib/AnonymousSessionHandler.js +15 -15
  3. package/lib/ApiConnection.d.ts +66 -66
  4. package/lib/ApiConnection.js +321 -321
  5. package/lib/ApiMethods.d.ts +16 -16
  6. package/lib/ApiMethods.js +41 -42
  7. package/lib/CredentialsSessionHandler.d.ts +16 -16
  8. package/lib/CredentialsSessionHandler.js +60 -60
  9. package/lib/HttpMethod.d.ts +4 -4
  10. package/lib/HttpMethod.js +8 -8
  11. package/lib/ISessionHandler.d.ts +7 -7
  12. package/lib/ISessionHandler.js +2 -2
  13. package/lib/OAuthSessionHandler.d.ts +12 -12
  14. package/lib/OAuthSessionHandler.js +52 -52
  15. package/lib/OAuthSessionHandlerBase.d.ts +16 -16
  16. package/lib/OAuthSessionHandlerBase.js +78 -78
  17. package/lib/ReturnCodes.d.ts +9 -9
  18. package/lib/ReturnCodes.js +15 -16
  19. package/lib/axios/AxiosInstance.d.ts +2 -0
  20. package/lib/axios/AxiosInstance.js +5 -0
  21. package/lib/constants/ActionEventTypes.d.ts +9 -9
  22. package/lib/constants/ActionEventTypes.js +14 -14
  23. package/lib/constants/ColumnPermissionRules.d.ts +14 -14
  24. package/lib/constants/ColumnPermissionRules.js +22 -24
  25. package/lib/constants/CompletionLevels.d.ts +6 -6
  26. package/lib/constants/CompletionLevels.js +11 -11
  27. package/lib/constants/CustomizationStatsItemKeys.d.ts +11 -11
  28. package/lib/constants/CustomizationStatsItemKeys.js +17 -17
  29. package/lib/constants/Edition.d.ts +6 -6
  30. package/lib/constants/Edition.js +10 -10
  31. package/lib/constants/EnumTypes.d.ts +32 -32
  32. package/lib/constants/EnumTypes.js +38 -38
  33. package/lib/constants/ExpirationReason.d.ts +7 -7
  34. package/lib/constants/ExpirationReason.js +10 -10
  35. package/lib/constants/Feature.d.ts +6 -6
  36. package/lib/constants/Feature.js +10 -10
  37. package/lib/constants/FieldNames.d.ts +389 -389
  38. package/lib/constants/FieldNames.js +427 -427
  39. package/lib/constants/FieldTypes.d.ts +15 -15
  40. package/lib/constants/FieldTypes.js +20 -20
  41. package/lib/constants/FolderNames.d.ts +80 -80
  42. package/lib/constants/FolderNames.js +87 -88
  43. package/lib/constants/Functionality.d.ts +54 -54
  44. package/lib/constants/Functionality.js +60 -60
  45. package/lib/constants/GlobalSettingsNames.d.ts +71 -71
  46. package/lib/constants/GlobalSettingsNames.js +76 -76
  47. package/lib/constants/LicenseKeyInvoiceSeverity.d.ts +8 -8
  48. package/lib/constants/LicenseKeyInvoiceSeverity.js +11 -11
  49. package/lib/constants/LicenseRestrictionKeys.d.ts +62 -62
  50. package/lib/constants/LicenseRestrictionKeys.js +68 -68
  51. package/lib/constants/RelationTypes.d.ts +11 -11
  52. package/lib/constants/RelationTypes.js +16 -16
  53. package/lib/data/EWItem.d.ts +12 -12
  54. package/lib/data/EWItem.js +91 -91
  55. package/lib/data/IApiAdditionalField.d.ts +21 -21
  56. package/lib/data/IApiAdditionalField.js +2 -2
  57. package/lib/data/IApiAvailableBundle.d.ts +4 -4
  58. package/lib/data/IApiAvailableBundle.js +2 -2
  59. package/lib/data/IApiAvailableVersionResponse.d.ts +9 -9
  60. package/lib/data/IApiAvailableVersionResponse.js +2 -2
  61. package/lib/data/IApiBooleanResponse.d.ts +4 -4
  62. package/lib/data/IApiBooleanResponse.js +2 -2
  63. package/lib/data/IApiCapacityAvailableBundle.d.ts +5 -5
  64. package/lib/data/IApiCapacityAvailableBundle.js +2 -2
  65. package/lib/data/IApiCart.d.ts +48 -48
  66. package/lib/data/IApiCart.js +8 -8
  67. package/lib/data/IApiColumn.d.ts +51 -51
  68. package/lib/data/IApiColumn.js +2 -2
  69. package/lib/data/IApiColumnPermission.d.ts +15 -15
  70. package/lib/data/IApiColumnPermission.js +2 -2
  71. package/lib/data/IApiCompany.d.ts +55 -55
  72. package/lib/data/IApiCompany.js +8 -8
  73. package/lib/data/IApiContact.d.ts +58 -58
  74. package/lib/data/IApiContact.js +8 -8
  75. package/lib/data/IApiCurrencyExchangeRate.d.ts +9 -9
  76. package/lib/data/IApiCurrencyExchangeRate.js +8 -8
  77. package/lib/data/IApiCustomizationStatsItem.d.ts +6 -6
  78. package/lib/data/IApiCustomizationStatsItem.js +2 -2
  79. package/lib/data/IApiDataResponse.d.ts +4 -4
  80. package/lib/data/IApiDataResponse.js +2 -2
  81. package/lib/data/IApiDatumResponse.d.ts +4 -4
  82. package/lib/data/IApiDatumResponse.js +2 -2
  83. package/lib/data/IApiDocument.d.ts +22 -22
  84. package/lib/data/IApiDocument.js +8 -8
  85. package/lib/data/IApiEmail.d.ts +26 -26
  86. package/lib/data/IApiEmail.js +8 -8
  87. package/lib/data/IApiEnumType.d.ts +26 -26
  88. package/lib/data/IApiEnumType.js +9 -9
  89. package/lib/data/IApiEnumValue.d.ts +18 -18
  90. package/lib/data/IApiEnumValue.js +2 -2
  91. package/lib/data/IApiEnumValuesRelation.d.ts +8 -8
  92. package/lib/data/IApiEnumValuesRelation.js +8 -8
  93. package/lib/data/IApiFeature.d.ts +5 -5
  94. package/lib/data/IApiFeature.js +2 -2
  95. package/lib/data/IApiFeaturesLicenseBundle.d.ts +10 -10
  96. package/lib/data/IApiFeaturesLicenseBundle.js +2 -2
  97. package/lib/data/IApiFlow.d.ts +9 -9
  98. package/lib/data/IApiFlow.js +8 -8
  99. package/lib/data/IApiGlobalSetting.d.ts +33 -33
  100. package/lib/data/IApiGlobalSetting.js +2 -2
  101. package/lib/data/IApiGoal.d.ts +22 -22
  102. package/lib/data/IApiGoal.js +8 -8
  103. package/lib/data/IApiGood.d.ts +26 -26
  104. package/lib/data/IApiGood.js +8 -8
  105. package/lib/data/IApiGoodInCart.d.ts +62 -62
  106. package/lib/data/IApiGoodInCart.js +8 -8
  107. package/lib/data/IApiGroup.d.ts +16 -16
  108. package/lib/data/IApiGroup.js +2 -2
  109. package/lib/data/IApiItemBase.d.ts +14 -14
  110. package/lib/data/IApiItemBase.js +2 -2
  111. package/lib/data/IApiItemIdentifier.d.ts +5 -5
  112. package/lib/data/IApiItemIdentifier.js +2 -2
  113. package/lib/data/IApiItemUsageStatus.d.ts +4 -4
  114. package/lib/data/IApiItemUsageStatus.js +2 -2
  115. package/lib/data/IApiJournal.d.ts +25 -25
  116. package/lib/data/IApiJournal.js +8 -8
  117. package/lib/data/IApiLead.d.ts +36 -36
  118. package/lib/data/IApiLead.js +8 -8
  119. package/lib/data/IApiLicense.d.ts +65 -65
  120. package/lib/data/IApiLicense.js +2 -2
  121. package/lib/data/IApiLicenseBundleBase.d.ts +6 -6
  122. package/lib/data/IApiLicenseBundleBase.js +2 -2
  123. package/lib/data/IApiLocalizedLicenseBundle.d.ts +4 -4
  124. package/lib/data/IApiLocalizedLicenseBundle.js +2 -2
  125. package/lib/data/IApiLoginResponse.d.ts +8 -8
  126. package/lib/data/IApiLoginResponse.js +2 -2
  127. package/lib/data/IApiMarketingCampaign.d.ts +32 -32
  128. package/lib/data/IApiMarketingCampaign.js +8 -8
  129. package/lib/data/IApiMarketingList.d.ts +17 -17
  130. package/lib/data/IApiMarketingList.js +8 -8
  131. package/lib/data/IApiModulePermission.d.ts +14 -14
  132. package/lib/data/IApiModulePermission.js +2 -2
  133. package/lib/data/IApiObjectType.d.ts +9 -9
  134. package/lib/data/IApiObjectType.js +2 -2
  135. package/lib/data/IApiPasswordStrength.d.ts +5 -5
  136. package/lib/data/IApiPasswordStrength.js +2 -2
  137. package/lib/data/IApiPayment.d.ts +9 -9
  138. package/lib/data/IApiPayment.js +8 -8
  139. package/lib/data/IApiProject.d.ts +59 -59
  140. package/lib/data/IApiProject.js +8 -8
  141. package/lib/data/IApiRecurrencePattern.d.ts +16 -16
  142. package/lib/data/IApiRecurrencePattern.js +8 -8
  143. package/lib/data/IApiResult.d.ts +4 -4
  144. package/lib/data/IApiResult.js +2 -2
  145. package/lib/data/IApiSaveResponse.d.ts +4 -4
  146. package/lib/data/IApiSaveResponse.js +2 -2
  147. package/lib/data/IApiTask.d.ts +34 -34
  148. package/lib/data/IApiTask.js +8 -8
  149. package/lib/data/IApiUser.d.ts +22 -22
  150. package/lib/data/IApiUser.js +2 -2
  151. package/lib/data/IApiUserSetting.d.ts +6 -6
  152. package/lib/data/IApiUserSetting.js +2 -2
  153. package/lib/data/IApiWebServiceTaskStatus.d.ts +10 -10
  154. package/lib/data/IApiWebServiceTaskStatus.js +2 -2
  155. package/lib/data/IApiWorkReport.d.ts +36 -36
  156. package/lib/data/IApiWorkReport.js +8 -8
  157. package/lib/data/IApiWorkflowActionDerivedItem.d.ts +21 -21
  158. package/lib/data/IApiWorkflowActionDerivedItem.js +2 -2
  159. package/lib/data/IApiWorkflowModel.d.ts +8 -8
  160. package/lib/data/IApiWorkflowModel.js +2 -2
  161. package/lib/data/query/IApiQuery.d.ts +42 -42
  162. package/lib/data/query/IApiQuery.js +2 -2
  163. package/lib/data/query/IApiQueryFilters.d.ts +43 -43
  164. package/lib/data/query/IApiQueryFilters.js +2 -2
  165. package/lib/data/workflowActions/IApiAction.d.ts +106 -106
  166. package/lib/data/workflowActions/IApiAction.js +2 -2
  167. package/lib/exceptions/HttpRequestError.d.ts +7 -7
  168. package/lib/exceptions/HttpRequestError.js +29 -29
  169. package/lib/exceptions/WebServiceError.d.ts +5 -5
  170. package/lib/exceptions/WebServiceError.js +29 -29
  171. package/lib/helpers/ErrorHelper.d.ts +4 -4
  172. package/lib/helpers/ErrorHelper.js +21 -21
  173. package/lib/helpers/OAuthHelper.d.ts +8 -8
  174. package/lib/helpers/OAuthHelper.js +57 -60
  175. package/lib/helpers/VersionHelperBase.d.ts +5 -5
  176. package/lib/helpers/VersionHelperBase.js +21 -21
  177. package/lib/index.d.ts +85 -85
  178. package/lib/index.js +124 -124
  179. package/lib/interfaces/IEWJwtPayload.d.ts +4 -4
  180. package/lib/interfaces/IEWJwtPayload.js +2 -2
  181. package/lib/interfaces/IItemPreview.d.ts +5 -5
  182. package/lib/interfaces/IItemPreview.js +2 -2
  183. package/lib/interfaces/ITokenData.d.ts +9 -9
  184. package/lib/interfaces/ITokenData.js +2 -2
  185. package/lib/interfaces/ITranslatableString.d.ts +8 -8
  186. package/lib/interfaces/ITranslatableString.js +2 -2
  187. package/lib/interfaces/TNumericValidatorType.d.ts +1 -1
  188. package/lib/interfaces/TNumericValidatorType.js +2 -2
  189. package/lib/tokenizedServices/CommonDataConnection.d.ts +9 -9
  190. package/lib/tokenizedServices/CommonDataConnection.js +22 -22
  191. package/lib/tokenizedServices/ITokenizedApiResult.d.ts +4 -4
  192. package/lib/tokenizedServices/ITokenizedApiResult.js +2 -2
  193. package/lib/tokenizedServices/TokenizedServiceConnection.d.ts +25 -25
  194. package/lib/tokenizedServices/TokenizedServiceConnection.js +130 -130
  195. package/package.json +10 -10
@@ -1,321 +1,321 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ApiConnection = void 0;
4
- var axios_1 = require("axios");
5
- var ReturnCodes_1 = require("./ReturnCodes");
6
- var HttpMethod_1 = require("./HttpMethod");
7
- var CredentialsSessionHandler_1 = require("./CredentialsSessionHandler");
8
- var AnonymousSessionHandler_1 = require("./AnonymousSessionHandler");
9
- var ApiMethods_1 = require("./ApiMethods");
10
- var OAuthSessionHandler_1 = require("./OAuthSessionHandler");
11
- var HttpRequestError_1 = require("./exceptions/HttpRequestError");
12
- var base64url = require("universal-base64url");
13
- var ErrorHelper_1 = require("./helpers/ErrorHelper");
14
- var ApiConnection = /** @class */ (function () {
15
- function ApiConnection(apiServiceUri, sessionHandler, errorCallback, supportGetItemPreviewMethod) {
16
- var _this = this;
17
- this.createOpenLink = function (folderName, guid, fileAs) {
18
- var ws = base64url.encode(_this.baseUri);
19
- var legacyLink = "eway://" + folderName;
20
- if (guid) {
21
- legacyLink += "/" + (guid === null || guid === void 0 ? void 0 : guid.toLowerCase());
22
- }
23
- legacyLink = base64url.encode(legacyLink);
24
- var url = "https://open.eway-crm.com/?ws=" + ws + "&l=" + legacyLink;
25
- if (fileAs) {
26
- url += "&n=" + encodeURIComponent(fileAs);
27
- }
28
- return url;
29
- };
30
- /**
31
- * Creates a promise for async file upload using binary stream
32
- * @param itemGuid Item identificator. Ex. '9ac561be-9b7d-4938-8e55-4cce97142483'.
33
- * @param fileName File name, ex. 'picture.img'.
34
- * @param data Single file to be uploaded.
35
- * @param config Optional. Additional config for the request.
36
- * @param catchGlobally Optional. If true, raises this the global error handler each time the promise is rejected.
37
- */
38
- this.askUploadMethod = function (itemGuid, fileName, data, config, catchGlobally) {
39
- return new Promise(function (resolve, reject) {
40
- var errClb = catchGlobally
41
- ? function (e) {
42
- reject(e);
43
- throw e;
44
- }
45
- : reject;
46
- _this.callUploadMethod(itemGuid, fileName, data, resolve, errClb, errClb, config);
47
- });
48
- };
49
- /**
50
- * Asynchronously uploads file using binary stream
51
- * @param itemGuid Item identificator. Ex. '9ac561be-9b7d-4938-8e55-4cce97142483'.
52
- * @param fileName File name, ex. 'picture.img'.
53
- * @param data Single file to be uploaded.
54
- * @param successCallback Handler callback when the method executes well. Gets the whole response JSON object as the only argument.
55
- * @param unsuccessCallback Optional. Handler callback for eWay-API app level failures. Gets the whole response JSON object as the only argument. If not supplied, the global error handler is used.
56
- * @param errorCallback Optional. Handler callback for any other failures. If not supplied, the global error handler is used.
57
- * @param config Optional. Additional config for the request.
58
- */
59
- this.callUploadMethod = function (itemGuid, fileName, data, successCallback, unsuccessCallback, errorCallback, config) {
60
- var noSessionCallback = function () {
61
- _this.sessionHandler.getSessionId(_this, function (newSessionId) {
62
- _this.sessionId = newSessionId;
63
- _this.callUploadMethod(itemGuid, fileName, data, successCallback, unsuccessCallback, errorCallback, config);
64
- });
65
- };
66
- var sessionId = _this.sessionId;
67
- if (!sessionId) {
68
- noSessionCallback();
69
- return;
70
- }
71
- var unsuccessClb = function (result) {
72
- if (result.ReturnCode === ReturnCodes_1.ReturnCodes.rcBadSession) {
73
- _this.sessionId = null;
74
- _this.sessionHandler.invalidateSessionId(sessionId, noSessionCallback);
75
- return;
76
- }
77
- if (unsuccessCallback) {
78
- unsuccessCallback(result);
79
- }
80
- else {
81
- var error = new Error('Unhandled connection return code ' + result.ReturnCode + ': ' + result.Description);
82
- if (_this.errorCallback) {
83
- _this.errorCallback(error);
84
- }
85
- else {
86
- throw error;
87
- }
88
- }
89
- };
90
- var errorClb = function (error) {
91
- var err = new Error('Unhandled connection error when calling ' + methodUrl + ': ' + ErrorHelper_1.default.stringifyError(error));
92
- if ('statusCode' in error && error.statusCode === 413) {
93
- err = new Error('The file has exceeded the maximum allowed file size for uploading. You can contact your IT administrator or eWay-CRM support if you would like to increase the limit.');
94
- }
95
- if (errorCallback) {
96
- errorCallback(err);
97
- }
98
- else if (_this.errorCallback) {
99
- _this.errorCallback(err);
100
- }
101
- else {
102
- throw err;
103
- }
104
- };
105
- var methodUrl = "".concat(_this.svcUri, "/SaveBinaryAttachment?sessionId=").concat(_this.sessionId, "&itemGuid=").concat(itemGuid, "&fileName=").concat(encodeURIComponent(fileName));
106
- var promise = axios_1.default.post(methodUrl, data, config);
107
- ApiConnection.handleCallPromise(promise, successCallback, unsuccessClb, errorClb);
108
- };
109
- /**
110
- * Creates a promise for async API method call.
111
- * @param methodName API method name. Ex. 'GetUsers'.
112
- * @param data Input data or empty object. Ex. {transmitObject: {FileAs: 'Peter File'}} or {itemGuids: ['9ac561be-9b7d-4938-8e55-4cce97142483']}.
113
- * @param httpMethod Optional. The used HTTP method. POST or GET. Default is POST.
114
- * @param catchGlobally Optional. If true, raises this the global error handler each time the promise is rejected.
115
- */
116
- this.askMethod = function (methodName, data, httpMethod, catchGlobally) {
117
- return new Promise(function (resolve, reject) {
118
- var errClb = catchGlobally
119
- ? function (e) {
120
- reject(e);
121
- throw e;
122
- }
123
- : reject;
124
- _this.callMethod(methodName, data, resolve, errClb, httpMethod, errClb);
125
- });
126
- };
127
- /**
128
- * Asynchronously calls API method with automatically added session data.
129
- * @param methodName API method name. Ex. 'GetUsers'.
130
- * @param data Input data or empty object. Ex. {transmitObject: {FileAs: 'Peter File'}} or {itemGuids: ['9ac561be-9b7d-4938-8e55-4cce97142483']}.
131
- * @param successCallback Handler callback when the method executes well. Gets the whole response JSON object as the only argument.
132
- * @param unsuccessCallback Optional. Handler callback for eWay-API app level failures. Gets the whole response JSON object as the only argument. If not supplied, the global error handler is used.
133
- * @param httpMethod Optional. The used HTTP method. POST or GET. Default is POST.
134
- * @param errorCallback Optional. Handler callback for any other failures. If not supplied, the global error handler is used.
135
- */
136
- this.callMethod = function (methodName, data, successCallback, unsuccessCallback, httpMethod, errorCallback) {
137
- if (!httpMethod) {
138
- httpMethod = HttpMethod_1.HttpMethod.post;
139
- }
140
- var noSessionCallback = function () {
141
- _this.sessionHandler.getSessionId(_this, function (newSessionId) {
142
- _this.sessionId = newSessionId;
143
- _this.callMethod(methodName, data, successCallback, unsuccessCallback, httpMethod, errorCallback);
144
- });
145
- };
146
- var sessionId = _this.sessionId;
147
- if (!sessionId) {
148
- noSessionCallback();
149
- return;
150
- }
151
- data.sessionId = sessionId;
152
- var unsuccessClb = function (result) {
153
- if (result.ReturnCode === ReturnCodes_1.ReturnCodes.rcBadSession) {
154
- _this.sessionId = null;
155
- if (methodName !== ApiMethods_1.ApiMethods.logOut) {
156
- _this.sessionHandler.invalidateSessionId(sessionId, noSessionCallback);
157
- return;
158
- }
159
- }
160
- if (unsuccessCallback) {
161
- unsuccessCallback(result);
162
- }
163
- else {
164
- var error = new Error('Unhandled connection return code ' + result.ReturnCode + ': ' + result.Description);
165
- if (_this.errorCallback) {
166
- _this.errorCallback(error, data);
167
- }
168
- else {
169
- throw error;
170
- }
171
- }
172
- };
173
- var successClb = methodName !== ApiMethods_1.ApiMethods.logOut
174
- ? successCallback
175
- : function (result) {
176
- _this.sessionId = null;
177
- successCallback(result);
178
- };
179
- _this.callWithoutSession(methodName, data, successClb, unsuccessClb, null, httpMethod, errorCallback);
180
- };
181
- this.callWithoutSession = function (methodName, data, successCallback, unsuccessCallback, headers, httpMethod, errorCallback) {
182
- var _a;
183
- if (!httpMethod) {
184
- httpMethod = HttpMethod_1.HttpMethod.post;
185
- }
186
- var methodUrl = _this.svcUri + '/' + methodName;
187
- var config;
188
- if (!!headers) {
189
- config = {
190
- headers: headers,
191
- withCredentials: (_a = _this.supportGetItemPreviewMethod) !== null && _a !== void 0 ? _a : methodName == ApiMethods_1.ApiMethods.logIn
192
- };
193
- }
194
- var promise;
195
- switch (httpMethod) {
196
- case HttpMethod_1.HttpMethod.get:
197
- if (data) {
198
- throw new Error('Calling api get method with data specified does not make any sense.');
199
- }
200
- promise = axios_1.default.get(methodUrl, config);
201
- break;
202
- case HttpMethod_1.HttpMethod.post:
203
- promise = axios_1.default.post(methodUrl, data, config);
204
- break;
205
- default:
206
- throw new Error("Unknown http method '".concat(httpMethod, "'."));
207
- }
208
- var errorClb = function (error) {
209
- if (errorCallback) {
210
- try {
211
- errorCallback(error);
212
- }
213
- catch (e) {
214
- if (_this.errorCallback) {
215
- _this.errorCallback(e, data);
216
- }
217
- else {
218
- throw e;
219
- }
220
- }
221
- }
222
- else {
223
- var err = new Error('Unhandled connection error when calling ' + methodUrl + ': ' + ErrorHelper_1.default.stringifyError(error));
224
- if (_this.errorCallback) {
225
- _this.errorCallback(err, data);
226
- }
227
- else {
228
- throw err;
229
- }
230
- }
231
- };
232
- ApiConnection.handleCallPromise(promise, successCallback, unsuccessCallback, errorClb);
233
- };
234
- this.getItemPreviewGetMethodUrl = function (folderName, itemGuid, itemVersion) {
235
- return _this.svcUri + '/' + ApiMethods_1.ApiMethods.getItemPreview + '?folderName=' + encodeURIComponent(folderName) + '&itemGuid=' + encodeURIComponent(itemGuid) + (!!itemVersion || itemVersion === 0 ? '&itemVersion=' + encodeURIComponent(itemVersion.toString()) : '');
236
- };
237
- this.getEmailAttachmentGetMethodUrl = function (itemGuid, contentId) {
238
- return _this.svcUri + '/' + ApiMethods_1.ApiMethods.getEmailAttachment + '?itemGuid=' + encodeURIComponent(itemGuid) + '&contentId=' + encodeURIComponent(contentId);
239
- };
240
- this.getAllEmailAttachmentsZipGetMethodUrl = function (itemGuid) {
241
- return _this.svcUri + '/' + ApiMethods_1.ApiMethods.getAllEmailAttachments + '?itemGuid=' + encodeURIComponent(itemGuid);
242
- };
243
- this.getActiveSessionId = function () {
244
- return _this.sessionId;
245
- };
246
- if (!apiServiceUri) {
247
- throw new Error("The argument 'apiServiceUri' cannot be empty.");
248
- }
249
- if (apiServiceUri.length < 8 || (apiServiceUri.substr(0, 8).toLowerCase() !== 'https://' && apiServiceUri.substr(0, 7).toLowerCase() !== 'http://')) {
250
- throw new Error("Api service uri must start either with 'https://' or with 'http://'.");
251
- }
252
- if (apiServiceUri.substr(apiServiceUri.length - 4).toLowerCase() === '.svc') {
253
- this.svcUri = apiServiceUri;
254
- var apiServiceOptions = ['/API.svc', '/InsecureAPI.svc', '/WcfService/Service.svc'];
255
- var apiOption = apiServiceOptions.find(function (option) { return option.toLowerCase() === apiServiceUri.substr(apiServiceUri.length - option.length).toLowerCase(); }) || '';
256
- this.baseUri = apiServiceUri.substr(0, apiServiceUri.length - apiOption.length);
257
- }
258
- else {
259
- this.baseUri = apiServiceUri;
260
- if (this.baseUri.substr(this.baseUri.length - 1) === '/') {
261
- this.baseUri = this.baseUri.substr(0, this.baseUri.length - 1);
262
- }
263
- if (apiServiceUri.substr(0, 8).toLowerCase() === 'https://') {
264
- this.svcUri = this.baseUri + '/API.svc';
265
- }
266
- else {
267
- this.svcUri = this.baseUri + '/InsecureAPI.svc';
268
- }
269
- }
270
- this.sessionHandler = sessionHandler;
271
- this.errorCallback = errorCallback;
272
- this.sessionId = null;
273
- this.supportGetItemPreviewMethod = supportGetItemPreviewMethod !== null && supportGetItemPreviewMethod !== void 0 ? supportGetItemPreviewMethod : false;
274
- }
275
- Object.defineProperty(ApiConnection.prototype, "supportsGetItemPreviewMethod", {
276
- get: function () {
277
- return this.supportGetItemPreviewMethod;
278
- },
279
- enumerable: false,
280
- configurable: true
281
- });
282
- ApiConnection.create = function (apiServiceUri, username, passwordHash, appVersion, clientMachineIdentifier, clientMachineName, errorCallback, supportGetItemPreviewMethod) {
283
- return new ApiConnection(apiServiceUri, new CredentialsSessionHandler_1.CredentialsSessionHandler(username, passwordHash, appVersion, clientMachineIdentifier, clientMachineName, errorCallback), errorCallback, supportGetItemPreviewMethod);
284
- };
285
- ApiConnection.createAnonymous = function (apiServiceUri, errorCallback) {
286
- return new ApiConnection(apiServiceUri, new AnonymousSessionHandler_1.AnonymousSessionHandler(), errorCallback);
287
- };
288
- ApiConnection.createUsingOAuth = function (apiServiceUri, username, clientId, clientSecret, refreshToken, accessToken, appVersion, errorCallback, refreshTokenCallback, supportGetItemPreviewMethod) {
289
- return new ApiConnection(apiServiceUri, new OAuthSessionHandler_1.OAuthSessionHandler(username, clientId, clientSecret, refreshToken, accessToken, appVersion, errorCallback, refreshTokenCallback), errorCallback, supportGetItemPreviewMethod);
290
- };
291
- Object.defineProperty(ApiConnection.prototype, "wsUrl", {
292
- get: function () {
293
- return this.baseUri;
294
- },
295
- enumerable: false,
296
- configurable: true
297
- });
298
- ApiConnection.handleCallPromise = function (call, successCallback, unsuccessCallback, errorCallback) {
299
- call.then(function (response) {
300
- if (response.status === 200) {
301
- if (response.data.ReturnCode === ReturnCodes_1.ReturnCodes.rcSuccess) {
302
- successCallback(response.data);
303
- }
304
- else {
305
- unsuccessCallback(response.data);
306
- }
307
- }
308
- else {
309
- errorCallback(new HttpRequestError_1.HttpRequestError(response.status, response.statusText));
310
- }
311
- }).catch(function (error) {
312
- if (error.response) {
313
- errorCallback(new HttpRequestError_1.HttpRequestError(error.response.status, error.response.statusText));
314
- return;
315
- }
316
- errorCallback(error);
317
- });
318
- };
319
- return ApiConnection;
320
- }());
321
- exports.ApiConnection = ApiConnection;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ApiConnection = void 0;
4
+ var ReturnCodes_1 = require("./ReturnCodes");
5
+ var HttpMethod_1 = require("./HttpMethod");
6
+ var CredentialsSessionHandler_1 = require("./CredentialsSessionHandler");
7
+ var AnonymousSessionHandler_1 = require("./AnonymousSessionHandler");
8
+ var ApiMethods_1 = require("./ApiMethods");
9
+ var OAuthSessionHandler_1 = require("./OAuthSessionHandler");
10
+ var HttpRequestError_1 = require("./exceptions/HttpRequestError");
11
+ var base64url = require("universal-base64url");
12
+ var ErrorHelper_1 = require("./helpers/ErrorHelper");
13
+ var AxiosInstance_1 = require("./axios/AxiosInstance");
14
+ var ApiConnection = /** @class */ (function () {
15
+ function ApiConnection(apiServiceUri, sessionHandler, errorCallback, supportGetItemPreviewMethod) {
16
+ var _this = this;
17
+ this.createOpenLink = function (folderName, guid, fileAs) {
18
+ var ws = base64url.encode(_this.baseUri);
19
+ var legacyLink = "eway://" + folderName;
20
+ if (guid) {
21
+ legacyLink += "/" + (guid === null || guid === void 0 ? void 0 : guid.toLowerCase());
22
+ }
23
+ legacyLink = base64url.encode(legacyLink);
24
+ var url = "https://open.eway-crm.com/?ws=" + ws + "&l=" + legacyLink;
25
+ if (fileAs) {
26
+ url += "&n=" + encodeURIComponent(fileAs);
27
+ }
28
+ return url;
29
+ };
30
+ /**
31
+ * Creates a promise for async file upload using binary stream
32
+ * @param itemGuid Item identificator. Ex. '9ac561be-9b7d-4938-8e55-4cce97142483'.
33
+ * @param fileName File name, ex. 'picture.img'.
34
+ * @param data Single file to be uploaded.
35
+ * @param config Optional. Additional config for the request.
36
+ * @param catchGlobally Optional. If true, raises this the global error handler each time the promise is rejected.
37
+ */
38
+ this.askUploadMethod = function (itemGuid, fileName, data, config, catchGlobally) {
39
+ return new Promise(function (resolve, reject) {
40
+ var errClb = catchGlobally
41
+ ? function (e) {
42
+ reject(e);
43
+ throw e;
44
+ }
45
+ : reject;
46
+ _this.callUploadMethod(itemGuid, fileName, data, resolve, errClb, errClb, config);
47
+ });
48
+ };
49
+ /**
50
+ * Asynchronously uploads file using binary stream
51
+ * @param itemGuid Item identificator. Ex. '9ac561be-9b7d-4938-8e55-4cce97142483'.
52
+ * @param fileName File name, ex. 'picture.img'.
53
+ * @param data Single file to be uploaded.
54
+ * @param successCallback Handler callback when the method executes well. Gets the whole response JSON object as the only argument.
55
+ * @param unsuccessCallback Optional. Handler callback for eWay-API app level failures. Gets the whole response JSON object as the only argument. If not supplied, the global error handler is used.
56
+ * @param errorCallback Optional. Handler callback for any other failures. If not supplied, the global error handler is used.
57
+ * @param config Optional. Additional config for the request.
58
+ */
59
+ this.callUploadMethod = function (itemGuid, fileName, data, successCallback, unsuccessCallback, errorCallback, config) {
60
+ var noSessionCallback = function () {
61
+ _this.sessionHandler.getSessionId(_this, function (newSessionId) {
62
+ _this.sessionId = newSessionId;
63
+ _this.callUploadMethod(itemGuid, fileName, data, successCallback, unsuccessCallback, errorCallback, config);
64
+ });
65
+ };
66
+ var sessionId = _this.sessionId;
67
+ if (!sessionId) {
68
+ noSessionCallback();
69
+ return;
70
+ }
71
+ var unsuccessClb = function (result) {
72
+ if (result.ReturnCode === ReturnCodes_1.ReturnCodes.rcBadSession) {
73
+ _this.sessionId = null;
74
+ _this.sessionHandler.invalidateSessionId(sessionId, noSessionCallback);
75
+ return;
76
+ }
77
+ if (unsuccessCallback) {
78
+ unsuccessCallback(result);
79
+ }
80
+ else {
81
+ var error = new Error('Unhandled connection return code ' + result.ReturnCode + ': ' + result.Description);
82
+ if (_this.errorCallback) {
83
+ _this.errorCallback(error);
84
+ }
85
+ else {
86
+ throw error;
87
+ }
88
+ }
89
+ };
90
+ var errorClb = function (error) {
91
+ var err = new Error('Unhandled connection error when calling ' + methodUrl + ': ' + ErrorHelper_1.default.stringifyError(error));
92
+ if ('statusCode' in error && error.statusCode === 413) {
93
+ err = new Error('The file has exceeded the maximum allowed file size for uploading. You can contact your IT administrator or eWay-CRM support if you would like to increase the limit.');
94
+ }
95
+ if (errorCallback) {
96
+ errorCallback(err);
97
+ }
98
+ else if (_this.errorCallback) {
99
+ _this.errorCallback(err);
100
+ }
101
+ else {
102
+ throw err;
103
+ }
104
+ };
105
+ var methodUrl = "".concat(_this.svcUri, "/SaveBinaryAttachment?sessionId=").concat(_this.sessionId, "&itemGuid=").concat(itemGuid, "&fileName=").concat(encodeURIComponent(fileName));
106
+ var promise = AxiosInstance_1.default.post(methodUrl, data, config);
107
+ ApiConnection.handleCallPromise(promise, successCallback, unsuccessClb, errorClb);
108
+ };
109
+ /**
110
+ * Creates a promise for async API method call.
111
+ * @param methodName API method name. Ex. 'GetUsers'.
112
+ * @param data Input data or empty object. Ex. {transmitObject: {FileAs: 'Peter File'}} or {itemGuids: ['9ac561be-9b7d-4938-8e55-4cce97142483']}.
113
+ * @param httpMethod Optional. The used HTTP method. POST or GET. Default is POST.
114
+ * @param catchGlobally Optional. If true, raises this the global error handler each time the promise is rejected.
115
+ */
116
+ this.askMethod = function (methodName, data, httpMethod, catchGlobally) {
117
+ return new Promise(function (resolve, reject) {
118
+ var errClb = catchGlobally
119
+ ? function (e) {
120
+ reject(e);
121
+ throw e;
122
+ }
123
+ : reject;
124
+ _this.callMethod(methodName, data, resolve, errClb, httpMethod, errClb);
125
+ });
126
+ };
127
+ /**
128
+ * Asynchronously calls API method with automatically added session data.
129
+ * @param methodName API method name. Ex. 'GetUsers'.
130
+ * @param data Input data or empty object. Ex. {transmitObject: {FileAs: 'Peter File'}} or {itemGuids: ['9ac561be-9b7d-4938-8e55-4cce97142483']}.
131
+ * @param successCallback Handler callback when the method executes well. Gets the whole response JSON object as the only argument.
132
+ * @param unsuccessCallback Optional. Handler callback for eWay-API app level failures. Gets the whole response JSON object as the only argument. If not supplied, the global error handler is used.
133
+ * @param httpMethod Optional. The used HTTP method. POST or GET. Default is POST.
134
+ * @param errorCallback Optional. Handler callback for any other failures. If not supplied, the global error handler is used.
135
+ */
136
+ this.callMethod = function (methodName, data, successCallback, unsuccessCallback, httpMethod, errorCallback) {
137
+ if (!httpMethod) {
138
+ httpMethod = HttpMethod_1.HttpMethod.post;
139
+ }
140
+ var noSessionCallback = function () {
141
+ _this.sessionHandler.getSessionId(_this, function (newSessionId) {
142
+ _this.sessionId = newSessionId;
143
+ _this.callMethod(methodName, data, successCallback, unsuccessCallback, httpMethod, errorCallback);
144
+ });
145
+ };
146
+ var sessionId = _this.sessionId;
147
+ if (!sessionId) {
148
+ noSessionCallback();
149
+ return;
150
+ }
151
+ data.sessionId = sessionId;
152
+ var unsuccessClb = function (result) {
153
+ if (result.ReturnCode === ReturnCodes_1.ReturnCodes.rcBadSession) {
154
+ _this.sessionId = null;
155
+ if (methodName !== ApiMethods_1.ApiMethods.logOut) {
156
+ _this.sessionHandler.invalidateSessionId(sessionId, noSessionCallback);
157
+ return;
158
+ }
159
+ }
160
+ if (unsuccessCallback) {
161
+ unsuccessCallback(result);
162
+ }
163
+ else {
164
+ var error = new Error('Unhandled connection return code ' + result.ReturnCode + ': ' + result.Description);
165
+ if (_this.errorCallback) {
166
+ _this.errorCallback(error, data);
167
+ }
168
+ else {
169
+ throw error;
170
+ }
171
+ }
172
+ };
173
+ var successClb = methodName !== ApiMethods_1.ApiMethods.logOut
174
+ ? successCallback
175
+ : function (result) {
176
+ _this.sessionId = null;
177
+ successCallback(result);
178
+ };
179
+ _this.callWithoutSession(methodName, data, successClb, unsuccessClb, null, httpMethod, errorCallback);
180
+ };
181
+ this.callWithoutSession = function (methodName, data, successCallback, unsuccessCallback, headers, httpMethod, errorCallback) {
182
+ var _a;
183
+ if (!httpMethod) {
184
+ httpMethod = HttpMethod_1.HttpMethod.post;
185
+ }
186
+ var methodUrl = _this.svcUri + '/' + methodName;
187
+ var config;
188
+ if (!!headers) {
189
+ config = {
190
+ headers: headers,
191
+ withCredentials: (_a = _this.supportGetItemPreviewMethod) !== null && _a !== void 0 ? _a : methodName == ApiMethods_1.ApiMethods.logIn
192
+ };
193
+ }
194
+ var promise;
195
+ switch (httpMethod) {
196
+ case HttpMethod_1.HttpMethod.get:
197
+ if (data) {
198
+ throw new Error('Calling api get method with data specified does not make any sense.');
199
+ }
200
+ promise = AxiosInstance_1.default.get(methodUrl, config);
201
+ break;
202
+ case HttpMethod_1.HttpMethod.post:
203
+ promise = AxiosInstance_1.default.post(methodUrl, data, config);
204
+ break;
205
+ default:
206
+ throw new Error("Unknown http method '".concat(httpMethod, "'."));
207
+ }
208
+ var errorClb = function (error) {
209
+ if (errorCallback) {
210
+ try {
211
+ errorCallback(error);
212
+ }
213
+ catch (e) {
214
+ if (_this.errorCallback) {
215
+ _this.errorCallback(e, data);
216
+ }
217
+ else {
218
+ throw e;
219
+ }
220
+ }
221
+ }
222
+ else {
223
+ var err = new Error('Unhandled connection error when calling ' + methodUrl + ': ' + ErrorHelper_1.default.stringifyError(error));
224
+ if (_this.errorCallback) {
225
+ _this.errorCallback(err, data);
226
+ }
227
+ else {
228
+ throw err;
229
+ }
230
+ }
231
+ };
232
+ ApiConnection.handleCallPromise(promise, successCallback, unsuccessCallback, errorClb);
233
+ };
234
+ this.getItemPreviewGetMethodUrl = function (folderName, itemGuid, itemVersion) {
235
+ return _this.svcUri + '/' + ApiMethods_1.ApiMethods.getItemPreview + '?folderName=' + encodeURIComponent(folderName) + '&itemGuid=' + encodeURIComponent(itemGuid) + (!!itemVersion || itemVersion === 0 ? '&itemVersion=' + encodeURIComponent(itemVersion.toString()) : '');
236
+ };
237
+ this.getEmailAttachmentGetMethodUrl = function (itemGuid, contentId) {
238
+ return _this.svcUri + '/' + ApiMethods_1.ApiMethods.getEmailAttachment + '?itemGuid=' + encodeURIComponent(itemGuid) + '&contentId=' + encodeURIComponent(contentId);
239
+ };
240
+ this.getAllEmailAttachmentsZipGetMethodUrl = function (itemGuid) {
241
+ return _this.svcUri + '/' + ApiMethods_1.ApiMethods.getAllEmailAttachments + '?itemGuid=' + encodeURIComponent(itemGuid);
242
+ };
243
+ this.getActiveSessionId = function () {
244
+ return _this.sessionId;
245
+ };
246
+ if (!apiServiceUri) {
247
+ throw new Error("The argument 'apiServiceUri' cannot be empty.");
248
+ }
249
+ if (apiServiceUri.length < 8 || (apiServiceUri.substr(0, 8).toLowerCase() !== 'https://' && apiServiceUri.substr(0, 7).toLowerCase() !== 'http://')) {
250
+ throw new Error("Api service uri must start either with 'https://' or with 'http://'.");
251
+ }
252
+ if (apiServiceUri.substr(apiServiceUri.length - 4).toLowerCase() === '.svc') {
253
+ this.svcUri = apiServiceUri;
254
+ var apiServiceOptions = ['/API.svc', '/InsecureAPI.svc', '/WcfService/Service.svc'];
255
+ var apiOption = apiServiceOptions.find(function (option) { return option.toLowerCase() === apiServiceUri.substr(apiServiceUri.length - option.length).toLowerCase(); }) || '';
256
+ this.baseUri = apiServiceUri.substr(0, apiServiceUri.length - apiOption.length);
257
+ }
258
+ else {
259
+ this.baseUri = apiServiceUri;
260
+ if (this.baseUri.substr(this.baseUri.length - 1) === '/') {
261
+ this.baseUri = this.baseUri.substr(0, this.baseUri.length - 1);
262
+ }
263
+ if (apiServiceUri.substr(0, 8).toLowerCase() === 'https://') {
264
+ this.svcUri = this.baseUri + '/API.svc';
265
+ }
266
+ else {
267
+ this.svcUri = this.baseUri + '/InsecureAPI.svc';
268
+ }
269
+ }
270
+ this.sessionHandler = sessionHandler;
271
+ this.errorCallback = errorCallback;
272
+ this.sessionId = null;
273
+ this.supportGetItemPreviewMethod = supportGetItemPreviewMethod !== null && supportGetItemPreviewMethod !== void 0 ? supportGetItemPreviewMethod : false;
274
+ }
275
+ Object.defineProperty(ApiConnection.prototype, "supportsGetItemPreviewMethod", {
276
+ get: function () {
277
+ return this.supportGetItemPreviewMethod;
278
+ },
279
+ enumerable: false,
280
+ configurable: true
281
+ });
282
+ ApiConnection.create = function (apiServiceUri, username, passwordHash, appVersion, clientMachineIdentifier, clientMachineName, errorCallback, supportGetItemPreviewMethod) {
283
+ return new ApiConnection(apiServiceUri, new CredentialsSessionHandler_1.CredentialsSessionHandler(username, passwordHash, appVersion, clientMachineIdentifier, clientMachineName, errorCallback), errorCallback, supportGetItemPreviewMethod);
284
+ };
285
+ ApiConnection.createAnonymous = function (apiServiceUri, errorCallback) {
286
+ return new ApiConnection(apiServiceUri, new AnonymousSessionHandler_1.AnonymousSessionHandler(), errorCallback);
287
+ };
288
+ ApiConnection.createUsingOAuth = function (apiServiceUri, username, clientId, clientSecret, refreshToken, accessToken, appVersion, errorCallback, refreshTokenCallback, supportGetItemPreviewMethod) {
289
+ return new ApiConnection(apiServiceUri, new OAuthSessionHandler_1.OAuthSessionHandler(username, clientId, clientSecret, refreshToken, accessToken, appVersion, errorCallback, refreshTokenCallback), errorCallback, supportGetItemPreviewMethod);
290
+ };
291
+ Object.defineProperty(ApiConnection.prototype, "wsUrl", {
292
+ get: function () {
293
+ return this.baseUri;
294
+ },
295
+ enumerable: false,
296
+ configurable: true
297
+ });
298
+ ApiConnection.handleCallPromise = function (call, successCallback, unsuccessCallback, errorCallback) {
299
+ call.then(function (response) {
300
+ if (response.status === 200) {
301
+ if (response.data.ReturnCode === ReturnCodes_1.ReturnCodes.rcSuccess) {
302
+ successCallback(response.data);
303
+ }
304
+ else {
305
+ unsuccessCallback(response.data);
306
+ }
307
+ }
308
+ else {
309
+ errorCallback(new HttpRequestError_1.HttpRequestError(response.status, response.statusText));
310
+ }
311
+ }).catch(function (error) {
312
+ if (error.response) {
313
+ errorCallback(new HttpRequestError_1.HttpRequestError(error.response.status, error.response.statusText));
314
+ return;
315
+ }
316
+ errorCallback(error);
317
+ });
318
+ };
319
+ return ApiConnection;
320
+ }());
321
+ exports.ApiConnection = ApiConnection;