@eway-crm/connector 1.0.120 → 1.0.122

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