@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.
- package/lib/AnonymousSessionHandler.js +5 -10
- package/lib/ApiConnection.js +115 -129
- package/lib/ApiMethods.js +35 -40
- package/lib/CredentialsSessionHandler.js +22 -28
- package/lib/HttpMethod.js +2 -5
- package/lib/ISessionHandler.js +1 -2
- package/lib/OAuthSessionHandler.js +16 -39
- package/lib/OAuthSessionHandlerBase.js +30 -36
- package/lib/ReturnCodes.js +10 -15
- package/lib/axios/AxiosInstance.d.ts +2 -0
- package/lib/axios/AxiosInstance.js +3 -0
- package/lib/constants/ActionEventTypes.js +9 -14
- package/lib/constants/ColumnPermissionRules.js +15 -22
- package/lib/constants/CompletionLevels.js +6 -11
- package/lib/constants/CustomizationStatsItemKeys.js +12 -17
- package/lib/constants/Edition.js +2 -5
- package/lib/constants/EnumTypes.js +33 -38
- package/lib/constants/ExpirationReason.js +1 -3
- package/lib/constants/Feature.js +2 -5
- package/lib/constants/FieldNames.js +421 -426
- package/lib/constants/FieldTypes.js +15 -20
- package/lib/constants/FolderNames.js +82 -87
- package/lib/constants/Functionality.js +55 -60
- package/lib/constants/GlobalSettingsNames.js +71 -76
- package/lib/constants/LicenseKeyInvoiceSeverity.js +1 -3
- package/lib/constants/LicenseRestrictionKeys.js +63 -68
- package/lib/constants/RelationTypes.js +11 -16
- package/lib/data/EWItem.js +29 -34
- package/lib/data/IApiAdditionalField.js +1 -2
- package/lib/data/IApiAvailableBundle.js +1 -2
- package/lib/data/IApiAvailableVersionResponse.js +1 -2
- package/lib/data/IApiBooleanResponse.js +1 -2
- package/lib/data/IApiCapacityAvailableBundle.js +1 -2
- package/lib/data/IApiCart.js +1 -2
- package/lib/data/IApiColumn.js +1 -2
- package/lib/data/IApiColumnPermission.js +1 -2
- package/lib/data/IApiCompany.js +1 -2
- package/lib/data/IApiContact.js +1 -2
- package/lib/data/IApiCurrencyExchangeRate.js +1 -2
- package/lib/data/IApiCustomizationStatsItem.js +1 -2
- package/lib/data/IApiDataResponse.js +1 -2
- package/lib/data/IApiDatumResponse.js +1 -2
- package/lib/data/IApiDocument.js +1 -2
- package/lib/data/IApiEmail.js +1 -2
- package/lib/data/IApiEnumType.js +2 -5
- package/lib/data/IApiEnumValue.js +1 -2
- package/lib/data/IApiEnumValuesRelation.js +1 -2
- package/lib/data/IApiFeature.js +1 -2
- package/lib/data/IApiFeaturesLicenseBundle.js +1 -2
- package/lib/data/IApiFlow.js +1 -2
- package/lib/data/IApiGlobalSetting.js +1 -2
- package/lib/data/IApiGoal.js +1 -2
- package/lib/data/IApiGood.js +1 -2
- package/lib/data/IApiGoodInCart.js +1 -2
- package/lib/data/IApiGroup.js +1 -2
- package/lib/data/IApiItemBase.js +1 -2
- package/lib/data/IApiItemIdentifier.js +1 -2
- package/lib/data/IApiItemUsageStatus.js +1 -2
- package/lib/data/IApiJournal.js +1 -2
- package/lib/data/IApiLead.js +1 -2
- package/lib/data/IApiLicense.js +1 -2
- package/lib/data/IApiLicenseBundleBase.js +1 -2
- package/lib/data/IApiLocalizedLicenseBundle.js +1 -2
- package/lib/data/IApiLoginResponse.js +1 -2
- package/lib/data/IApiMarketingCampaign.js +1 -2
- package/lib/data/IApiMarketingList.js +1 -2
- package/lib/data/IApiModulePermission.js +1 -2
- package/lib/data/IApiObjectType.js +1 -2
- package/lib/data/IApiPasswordStrength.js +1 -2
- package/lib/data/IApiPayment.js +1 -2
- package/lib/data/IApiProject.js +1 -2
- package/lib/data/IApiRecurrencePattern.js +1 -2
- package/lib/data/IApiResult.js +1 -2
- package/lib/data/IApiSaveResponse.js +1 -2
- package/lib/data/IApiTask.js +1 -2
- package/lib/data/IApiUser.js +1 -2
- package/lib/data/IApiUserSetting.js +1 -2
- package/lib/data/IApiWebServiceTaskStatus.js +1 -2
- package/lib/data/IApiWorkReport.js +1 -2
- package/lib/data/IApiWorkflowActionDerivedItem.js +1 -2
- package/lib/data/IApiWorkflowModel.js +1 -2
- package/lib/data/query/IApiQuery.js +1 -2
- package/lib/data/query/IApiQueryFilters.js +1 -2
- package/lib/data/workflowActions/IApiAction.js +1 -2
- package/lib/exceptions/HttpRequestError.js +6 -28
- package/lib/exceptions/WebServiceError.js +6 -28
- package/lib/helpers/ErrorHelper.js +15 -20
- package/lib/helpers/OAuthHelper.js +49 -56
- package/lib/helpers/VersionHelperBase.js +15 -20
- package/lib/index.js +83 -123
- package/lib/interfaces/IEWJwtPayload.js +1 -2
- package/lib/interfaces/IItemPreview.js +1 -2
- package/lib/interfaces/ITokenData.js +1 -2
- package/lib/interfaces/ITranslatableString.js +1 -2
- package/lib/interfaces/TNumericValidatorType.js +1 -2
- package/lib/tokenizedServices/CommonDataConnection.js +11 -17
- package/lib/tokenizedServices/ITokenizedApiResult.js +1 -2
- package/lib/tokenizedServices/TokenizedServiceConnection.js +53 -59
- package/package.json +2 -2
|
@@ -1,15 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
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 =
|
|
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
|
-
|
|
14
|
-
}());
|
|
15
|
-
exports.AnonymousSessionHandler = AnonymousSessionHandler;
|
|
10
|
+
}
|
package/lib/ApiConnection.js
CHANGED
|
@@ -1,27 +1,23 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
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
|
-
|
|
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 =
|
|
39
|
-
return new Promise(
|
|
40
|
-
|
|
41
|
-
?
|
|
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
|
-
|
|
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 =
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
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
|
-
|
|
62
|
+
const sessionId = this.sessionId;
|
|
67
63
|
if (!sessionId) {
|
|
68
64
|
noSessionCallback();
|
|
69
65
|
return;
|
|
70
66
|
}
|
|
71
|
-
|
|
72
|
-
if (result.ReturnCode ===
|
|
73
|
-
|
|
74
|
-
|
|
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
|
-
|
|
82
|
-
if (
|
|
83
|
-
|
|
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
|
-
|
|
91
|
-
|
|
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 (
|
|
99
|
-
|
|
94
|
+
else if (this.errorCallback) {
|
|
95
|
+
this.errorCallback(err);
|
|
100
96
|
}
|
|
101
97
|
else {
|
|
102
98
|
throw err;
|
|
103
99
|
}
|
|
104
100
|
};
|
|
105
|
-
|
|
106
|
-
|
|
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 =
|
|
117
|
-
return new Promise(
|
|
118
|
-
|
|
119
|
-
?
|
|
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
|
-
|
|
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 =
|
|
132
|
+
this.callMethod = (methodName, data, successCallback, unsuccessCallback, httpMethod, errorCallback) => {
|
|
137
133
|
if (!httpMethod) {
|
|
138
|
-
httpMethod =
|
|
134
|
+
httpMethod = HttpMethod.post;
|
|
139
135
|
}
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
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
|
-
|
|
142
|
+
const sessionId = this.sessionId;
|
|
147
143
|
if (!sessionId) {
|
|
148
144
|
noSessionCallback();
|
|
149
145
|
return;
|
|
150
146
|
}
|
|
151
147
|
data.sessionId = sessionId;
|
|
152
|
-
|
|
153
|
-
if (result.ReturnCode ===
|
|
154
|
-
|
|
155
|
-
if (methodName !==
|
|
156
|
-
|
|
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
|
-
|
|
165
|
-
if (
|
|
166
|
-
|
|
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
|
-
|
|
169
|
+
const successClb = methodName !== ApiMethods.logOut
|
|
174
170
|
? successCallback
|
|
175
|
-
:
|
|
176
|
-
|
|
171
|
+
: (result) => {
|
|
172
|
+
this.sessionId = null;
|
|
177
173
|
successCallback(result);
|
|
178
174
|
};
|
|
179
|
-
|
|
175
|
+
this.callWithoutSession(methodName, data, successClb, unsuccessClb, null, httpMethod, errorCallback);
|
|
180
176
|
};
|
|
181
|
-
this.callWithoutSession =
|
|
177
|
+
this.callWithoutSession = (methodName, data, successCallback, unsuccessCallback, headers, httpMethod, errorCallback) => {
|
|
182
178
|
var _a;
|
|
183
179
|
if (!httpMethod) {
|
|
184
|
-
httpMethod =
|
|
180
|
+
httpMethod = HttpMethod.post;
|
|
185
181
|
}
|
|
186
|
-
|
|
187
|
-
|
|
182
|
+
const methodUrl = this.svcUri + '/' + methodName;
|
|
183
|
+
let config;
|
|
188
184
|
if (!!headers) {
|
|
189
185
|
config = {
|
|
190
|
-
headers
|
|
191
|
-
withCredentials: (_a =
|
|
186
|
+
headers,
|
|
187
|
+
withCredentials: (_a = this.supportGetItemPreviewMethod) !== null && _a !== void 0 ? _a : methodName == ApiMethods.logIn
|
|
192
188
|
};
|
|
193
189
|
}
|
|
194
|
-
|
|
190
|
+
let promise;
|
|
195
191
|
switch (httpMethod) {
|
|
196
|
-
case
|
|
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 =
|
|
196
|
+
promise = axiosInstance.get(methodUrl, config);
|
|
201
197
|
break;
|
|
202
|
-
case
|
|
203
|
-
promise =
|
|
198
|
+
case HttpMethod.post:
|
|
199
|
+
promise = axiosInstance.post(methodUrl, data, config);
|
|
204
200
|
break;
|
|
205
201
|
default:
|
|
206
|
-
throw new Error(
|
|
202
|
+
throw new Error(`Unknown http method '${httpMethod}'.`);
|
|
207
203
|
}
|
|
208
|
-
|
|
204
|
+
const errorClb = (error) => {
|
|
209
205
|
if (errorCallback) {
|
|
210
206
|
try {
|
|
211
207
|
errorCallback(error);
|
|
212
208
|
}
|
|
213
209
|
catch (e) {
|
|
214
|
-
if (
|
|
215
|
-
|
|
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
|
-
|
|
224
|
-
if (
|
|
225
|
-
|
|
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 =
|
|
235
|
-
return
|
|
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 =
|
|
238
|
-
return
|
|
233
|
+
this.getEmailAttachmentGetMethodUrl = (itemGuid, contentId) => {
|
|
234
|
+
return this.svcUri + '/' + ApiMethods.getEmailAttachment + '?itemGuid=' + encodeURIComponent(itemGuid) + '&contentId=' + encodeURIComponent(contentId);
|
|
239
235
|
};
|
|
240
|
-
this.getAllEmailAttachmentsZipGetMethodUrl =
|
|
241
|
-
return
|
|
236
|
+
this.getAllEmailAttachmentsZipGetMethodUrl = (itemGuid) => {
|
|
237
|
+
return this.svcUri + '/' + ApiMethods.getAllEmailAttachments + '?itemGuid=' + encodeURIComponent(itemGuid);
|
|
242
238
|
};
|
|
243
|
-
this.getActiveSessionId =
|
|
244
|
-
return
|
|
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
|
-
|
|
255
|
-
|
|
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
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
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 ===
|
|
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
|
|
297
|
+
errorCallback(new HttpRequestError(response.status, response.statusText));
|
|
310
298
|
}
|
|
311
|
-
}).catch(
|
|
299
|
+
}).catch((error) => {
|
|
312
300
|
if (error.response) {
|
|
313
|
-
errorCallback(new
|
|
301
|
+
errorCallback(new HttpRequestError(error.response.status, error.response.statusText));
|
|
314
302
|
return;
|
|
315
303
|
}
|
|
316
304
|
errorCallback(error);
|
|
317
305
|
});
|
|
318
|
-
}
|
|
319
|
-
|
|
320
|
-
}());
|
|
321
|
-
exports.ApiConnection = ApiConnection;
|
|
306
|
+
}
|
|
307
|
+
}
|
package/lib/ApiMethods.js
CHANGED
|
@@ -1,41 +1,36 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
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
|
-
|
|
9
|
-
|
|
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
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
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 =
|
|
15
|
-
connection.callWithoutSession(
|
|
16
|
-
userName:
|
|
17
|
-
passwordHash:
|
|
18
|
-
appVersion:
|
|
19
|
-
clientMachineIdentifier:
|
|
20
|
-
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
|
-
},
|
|
23
|
-
|
|
24
|
-
|
|
18
|
+
}, (result) => {
|
|
19
|
+
this.lastSuccessfulLoginResponse = result;
|
|
20
|
+
const newSessionId = result.SessionId;
|
|
25
21
|
if (!newSessionId) {
|
|
26
|
-
|
|
27
|
-
if (
|
|
28
|
-
|
|
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
|
-
},
|
|
39
|
-
|
|
40
|
-
if (
|
|
41
|
-
|
|
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
|
-
|
|
59
|
-
}());
|
|
60
|
-
exports.CredentialsSessionHandler = CredentialsSessionHandler;
|
|
54
|
+
}
|
package/lib/HttpMethod.js
CHANGED
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
|
|
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
|
|
5
|
+
})(HttpMethod || (HttpMethod = {}));
|
package/lib/ISessionHandler.js
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
|
+
export {};
|