@eway-crm/connector 1.0.114 → 1.0.116
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/OAuthSessionHandler.d.ts +2 -10
- package/lib/OAuthSessionHandler.js +30 -68
- package/lib/OAuthSessionHandlerBase.d.ts +16 -0
- package/lib/OAuthSessionHandlerBase.js +78 -0
- package/lib/ReturnCodes.d.ts +1 -0
- package/lib/ReturnCodes.js +1 -0
- package/lib/data/IApiWebServiceTaskStatus.d.ts +10 -0
- package/lib/data/IApiWebServiceTaskStatus.js +2 -0
- package/lib/index.d.ts +3 -1
- package/lib/index.js +4 -1
- package/package.json +1 -1
|
@@ -1,20 +1,12 @@
|
|
|
1
|
-
import { ISessionHandler } from './ISessionHandler';
|
|
2
|
-
import { ApiConnection } from './ApiConnection';
|
|
3
1
|
import { ITokenData } from './interfaces/ITokenData';
|
|
4
2
|
import { TUnionError } from './exceptions/HttpRequestError';
|
|
5
3
|
import { IApiLoginResponse } from './data/IApiLoginResponse';
|
|
6
|
-
|
|
7
|
-
|
|
4
|
+
import { OAuthSessionHandlerBase } from './OAuthSessionHandlerBase';
|
|
5
|
+
export declare class OAuthSessionHandler extends OAuthSessionHandlerBase {
|
|
8
6
|
private readonly refreshToken;
|
|
9
|
-
private readonly appVersion;
|
|
10
7
|
private readonly clientId;
|
|
11
8
|
private readonly clientSecret;
|
|
12
|
-
private readonly errorCallback;
|
|
13
9
|
private readonly refreshTokenCallback?;
|
|
14
10
|
lastSuccessfulLoginResponse?: IApiLoginResponse;
|
|
15
|
-
private accessToken;
|
|
16
11
|
constructor(username: string, clientId: string, clientSecret: string, refreshToken: string, accessToken: string, appVersion: string, errorCallback?: (error: TUnionError) => void, refreshTokenCallback?: (tokenData: ITokenData) => void);
|
|
17
|
-
readonly invalidateSessionId: (_: string, callback: () => void) => void;
|
|
18
|
-
readonly getSessionId: (connection: ApiConnection, callback: (sessionId: string) => void) => void;
|
|
19
|
-
readonly getNewAccessToken: (connection: ApiConnection, callback: (tokenData: ITokenData) => void) => void;
|
|
20
12
|
}
|
|
@@ -1,64 +1,31 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __extends = (this && this.__extends) || (function () {
|
|
3
|
+
var extendStatics = function (d, b) {
|
|
4
|
+
extendStatics = Object.setPrototypeOf ||
|
|
5
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
+
return extendStatics(d, b);
|
|
8
|
+
};
|
|
9
|
+
return function (d, b) {
|
|
10
|
+
if (typeof b !== "function" && b !== null)
|
|
11
|
+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
12
|
+
extendStatics(d, b);
|
|
13
|
+
function __() { this.constructor = d; }
|
|
14
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
|
+
};
|
|
16
|
+
})();
|
|
2
17
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
18
|
exports.OAuthSessionHandler = void 0;
|
|
4
19
|
var _1 = require(".");
|
|
5
|
-
var
|
|
6
|
-
var OAuthSessionHandler = /** @class */ (function () {
|
|
20
|
+
var OAuthSessionHandlerBase_1 = require("./OAuthSessionHandlerBase");
|
|
21
|
+
var OAuthSessionHandler = /** @class */ (function (_super) {
|
|
22
|
+
__extends(OAuthSessionHandler, _super);
|
|
7
23
|
function OAuthSessionHandler(username, clientId, clientSecret, refreshToken, accessToken, appVersion, errorCallback, refreshTokenCallback) {
|
|
8
24
|
var _this = this;
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
}
|
|
14
|
-
};
|
|
15
|
-
this.getSessionId = function (connection, callback) {
|
|
16
|
-
connection.callWithoutSession(_1.ApiMethods.logIn, {
|
|
17
|
-
userName: _this.username,
|
|
18
|
-
appVersion: _this.appVersion,
|
|
19
|
-
createSessionCookie: connection.supportsGetItemPreviewMethod
|
|
20
|
-
}, function (result) {
|
|
21
|
-
_this.lastSuccessfulLoginResponse = result;
|
|
22
|
-
var newSessionId = result.SessionId;
|
|
23
|
-
if (!newSessionId) {
|
|
24
|
-
var error = new Error('Successful login but no session came.');
|
|
25
|
-
if (_this.errorCallback) {
|
|
26
|
-
_this.errorCallback(error);
|
|
27
|
-
}
|
|
28
|
-
else {
|
|
29
|
-
throw error;
|
|
30
|
-
}
|
|
31
|
-
return;
|
|
32
|
-
}
|
|
33
|
-
if (callback) {
|
|
34
|
-
callback(newSessionId);
|
|
35
|
-
}
|
|
36
|
-
}, function (result) {
|
|
37
|
-
var error = new WebServiceError_1.WebServiceError(result.ReturnCode, 'Unable to login. Error response follows.\n' + JSON.stringify(result));
|
|
38
|
-
if (_this.errorCallback) {
|
|
39
|
-
_this.errorCallback(error);
|
|
40
|
-
}
|
|
41
|
-
else {
|
|
42
|
-
throw error;
|
|
43
|
-
}
|
|
44
|
-
}, {
|
|
45
|
-
'Authorization': 'Bearer ' + _this.accessToken
|
|
46
|
-
}, undefined, function (error) {
|
|
47
|
-
if ((error === null || error === void 0 ? void 0 : error.statusCode) === 401) {
|
|
48
|
-
_this.getNewAccessToken(connection, function (tokenData) {
|
|
49
|
-
_this.accessToken = tokenData.access_token;
|
|
50
|
-
if (!tokenData.error) {
|
|
51
|
-
_this.getSessionId(connection, callback);
|
|
52
|
-
}
|
|
53
|
-
});
|
|
54
|
-
return;
|
|
55
|
-
}
|
|
56
|
-
if (!_this.errorCallback)
|
|
57
|
-
throw error;
|
|
58
|
-
_this.errorCallback(error);
|
|
59
|
-
});
|
|
60
|
-
};
|
|
61
|
-
this.getNewAccessToken = function (connection, callback) {
|
|
25
|
+
if (!username || !refreshToken || !clientId || !clientSecret) {
|
|
26
|
+
throw new Error("Non of the arguments 'username', 'clientId', 'clientSecret', 'refreshToken' can be empty.");
|
|
27
|
+
}
|
|
28
|
+
var getNewAccessToken = function (connection, callback) {
|
|
62
29
|
_1.OAuthHelper.refreshToken(connection.wsUrl, _this.clientId, _this.clientSecret, _this.refreshToken, function (tokenData) {
|
|
63
30
|
try {
|
|
64
31
|
if (_this.refreshTokenCallback) {
|
|
@@ -70,21 +37,16 @@ var OAuthSessionHandler = /** @class */ (function () {
|
|
|
70
37
|
_this.errorCallback(new Error('Refresh token callback failed.\n' + JSON.stringify(error)));
|
|
71
38
|
}
|
|
72
39
|
}
|
|
73
|
-
callback(tokenData);
|
|
40
|
+
callback(tokenData.access_token, tokenData.error);
|
|
74
41
|
});
|
|
75
42
|
};
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
this.appVersion = appVersion;
|
|
83
|
-
this.clientId = clientId;
|
|
84
|
-
this.clientSecret = clientSecret;
|
|
85
|
-
this.errorCallback = errorCallback;
|
|
86
|
-
this.refreshTokenCallback = refreshTokenCallback;
|
|
43
|
+
_this = _super.call(this, username, accessToken, appVersion, getNewAccessToken, errorCallback) || this;
|
|
44
|
+
_this.refreshToken = refreshToken;
|
|
45
|
+
_this.clientId = clientId;
|
|
46
|
+
_this.clientSecret = clientSecret;
|
|
47
|
+
_this.refreshTokenCallback = refreshTokenCallback;
|
|
48
|
+
return _this;
|
|
87
49
|
}
|
|
88
50
|
return OAuthSessionHandler;
|
|
89
|
-
}());
|
|
51
|
+
}(OAuthSessionHandlerBase_1.OAuthSessionHandlerBase));
|
|
90
52
|
exports.OAuthSessionHandler = OAuthSessionHandler;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { ISessionHandler } from './ISessionHandler';
|
|
2
|
+
import { ApiConnection } from './ApiConnection';
|
|
3
|
+
import { TUnionError } from './exceptions/HttpRequestError';
|
|
4
|
+
import { IApiLoginResponse } from './data/IApiLoginResponse';
|
|
5
|
+
export declare abstract class OAuthSessionHandlerBase implements ISessionHandler {
|
|
6
|
+
lastSuccessfulLoginResponse?: IApiLoginResponse;
|
|
7
|
+
private accessToken;
|
|
8
|
+
private readonly username;
|
|
9
|
+
private readonly appVersion;
|
|
10
|
+
protected readonly errorCallback: ((error: TUnionError) => void) | undefined;
|
|
11
|
+
private readonly getNewAccessTokenCallback;
|
|
12
|
+
constructor(username: string, accessToken: string, appVersion: string, getNewAccessTokenCallback: ((connection: ApiConnection, callback: (accessToken: string, error?: string) => void) => void), errorCallback?: (error: TUnionError) => void);
|
|
13
|
+
readonly invalidateSessionId: (_: string, callback: () => void) => void;
|
|
14
|
+
readonly getSessionId: (connection: ApiConnection, callback: (sessionId: string) => void) => void;
|
|
15
|
+
}
|
|
16
|
+
export default OAuthSessionHandlerBase;
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.OAuthSessionHandlerBase = void 0;
|
|
4
|
+
var _1 = require(".");
|
|
5
|
+
var WebServiceError_1 = require("./exceptions/WebServiceError");
|
|
6
|
+
var OAuthSessionHandlerBase = /** @class */ (function () {
|
|
7
|
+
function OAuthSessionHandlerBase(username, accessToken, appVersion, getNewAccessTokenCallback, errorCallback) {
|
|
8
|
+
var _this = this;
|
|
9
|
+
this.invalidateSessionId = function (_, callback) {
|
|
10
|
+
// Nothing to invalidate.
|
|
11
|
+
if (callback) {
|
|
12
|
+
callback();
|
|
13
|
+
}
|
|
14
|
+
};
|
|
15
|
+
this.getSessionId = function (connection, callback) {
|
|
16
|
+
var successCallbackHandler = function (result) {
|
|
17
|
+
_this.lastSuccessfulLoginResponse = result;
|
|
18
|
+
var newSessionId = result.SessionId;
|
|
19
|
+
if (!newSessionId) {
|
|
20
|
+
var error = new Error('Successful login but no session came.');
|
|
21
|
+
if (_this.errorCallback) {
|
|
22
|
+
_this.errorCallback(error);
|
|
23
|
+
}
|
|
24
|
+
else {
|
|
25
|
+
throw error;
|
|
26
|
+
}
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
if (callback) {
|
|
30
|
+
callback(newSessionId);
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
var unsuccessCallbackHandler = function (result) {
|
|
34
|
+
var error = new WebServiceError_1.WebServiceError(result.ReturnCode, 'Unable to login. Error response follows.\n' + JSON.stringify(result));
|
|
35
|
+
if (_this.errorCallback) {
|
|
36
|
+
_this.errorCallback(error);
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
throw error;
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
var errorCallbackHandler = function (error) {
|
|
43
|
+
if ((error === null || error === void 0 ? void 0 : error.statusCode) === 401) {
|
|
44
|
+
_this.getNewAccessTokenCallback(connection, function (accessToken, error) {
|
|
45
|
+
_this.accessToken = accessToken;
|
|
46
|
+
if (!error) {
|
|
47
|
+
_this.getSessionId(connection, callback);
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
if (!_this.errorCallback)
|
|
53
|
+
throw error;
|
|
54
|
+
_this.errorCallback(error);
|
|
55
|
+
};
|
|
56
|
+
var loginInputData = {
|
|
57
|
+
userName: _this.username,
|
|
58
|
+
appVersion: _this.appVersion,
|
|
59
|
+
createSessionCookie: connection.supportsGetItemPreviewMethod
|
|
60
|
+
};
|
|
61
|
+
var loginHeaders = {
|
|
62
|
+
'Authorization': 'Bearer ' + _this.accessToken
|
|
63
|
+
};
|
|
64
|
+
connection.callWithoutSession(_1.ApiMethods.logIn, loginInputData, successCallbackHandler, unsuccessCallbackHandler, loginHeaders, undefined, errorCallbackHandler);
|
|
65
|
+
};
|
|
66
|
+
if (!username) {
|
|
67
|
+
throw new Error("Non of the arguments 'username', 'clientId', 'clientSecret', 'refreshToken' can be empty.");
|
|
68
|
+
}
|
|
69
|
+
this.username = username;
|
|
70
|
+
this.accessToken = accessToken;
|
|
71
|
+
this.appVersion = appVersion;
|
|
72
|
+
this.getNewAccessTokenCallback = getNewAccessTokenCallback;
|
|
73
|
+
this.errorCallback = errorCallback;
|
|
74
|
+
}
|
|
75
|
+
return OAuthSessionHandlerBase;
|
|
76
|
+
}());
|
|
77
|
+
exports.OAuthSessionHandlerBase = OAuthSessionHandlerBase;
|
|
78
|
+
exports.default = OAuthSessionHandlerBase;
|
package/lib/ReturnCodes.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export declare class ReturnCodes {
|
|
2
2
|
static readonly rcSuccess = "rcSuccess";
|
|
3
3
|
static readonly rcBadSession = "rcBadSession";
|
|
4
|
+
static readonly rcDuplicateContact = "rcDuplicateContact";
|
|
4
5
|
static readonly rcWebServiceMoved = "rcWebServiceMoved";
|
|
5
6
|
static readonly rcAccessDenied = "rcAccessDenied";
|
|
6
7
|
static readonly rcLoginUserNameChanged = "rcLoginUserNameChanged";
|
package/lib/ReturnCodes.js
CHANGED
|
@@ -6,6 +6,7 @@ var ReturnCodes = /** @class */ (function () {
|
|
|
6
6
|
}
|
|
7
7
|
ReturnCodes.rcSuccess = 'rcSuccess';
|
|
8
8
|
ReturnCodes.rcBadSession = 'rcBadSession';
|
|
9
|
+
ReturnCodes.rcDuplicateContact = 'rcDuplicateContact';
|
|
9
10
|
ReturnCodes.rcWebServiceMoved = 'rcWebServiceMoved';
|
|
10
11
|
ReturnCodes.rcAccessDenied = 'rcAccessDenied';
|
|
11
12
|
ReturnCodes.rcLoginUserNameChanged = 'rcLoginUserNameChanged';
|
package/lib/index.d.ts
CHANGED
|
@@ -24,6 +24,7 @@ import ExpirationReason from './constants/ExpirationReason';
|
|
|
24
24
|
import LicenseKeyInvoiceSeverity from './constants/LicenseKeyInvoiceSeverity';
|
|
25
25
|
import ErrorHelper from './helpers/ErrorHelper';
|
|
26
26
|
import VersionHelperBase from './helpers/VersionHelperBase';
|
|
27
|
+
import { OAuthSessionHandlerBase } from './OAuthSessionHandlerBase';
|
|
27
28
|
export default ApiConnection;
|
|
28
29
|
export * from './data/EWItem';
|
|
29
30
|
export * from './data/IApiAdditionalField';
|
|
@@ -74,10 +75,11 @@ export * from './data/IApiSaveResponse';
|
|
|
74
75
|
export * from './data/IApiTask';
|
|
75
76
|
export * from './data/IApiUser';
|
|
76
77
|
export * from './data/IApiUserSetting';
|
|
78
|
+
export * from './data/IApiWebServiceTaskStatus';
|
|
77
79
|
export * from './data/IApiWorkflowActionDerivedItem';
|
|
78
80
|
export * from './data/IApiWorkflowModel';
|
|
79
81
|
export * from './data/IApiWorkReport';
|
|
80
82
|
export * from './data/query/IApiQuery';
|
|
81
83
|
export * from './data/query/IApiQueryFilters';
|
|
82
84
|
export * from './interfaces/ITranslatableString';
|
|
83
|
-
export { HttpMethod, ISessionHandler, ReturnCodes, ITokenizedApiResult, TokenizedServiceConnection, CommonDataConnection, ApiMethods, GlobalSettingsNames, FolderNames, TFolderName, OAuthHelper, HttpRequestError, TUnionError, TInputData, FieldNames, EnumTypes, RelationTypes, ColumnPermissionPermissionRules, ColumnPermissionMandatoryRules, Edition, Feature, Functionality, CustomizationStatsItemKeys, LicenseRestrictionKeys, ExpirationReason, LicenseKeyInvoiceSeverity, ErrorHelper, VersionHelperBase };
|
|
85
|
+
export { HttpMethod, ISessionHandler, ReturnCodes, ITokenizedApiResult, TokenizedServiceConnection, CommonDataConnection, ApiMethods, GlobalSettingsNames, FolderNames, TFolderName, OAuthHelper, HttpRequestError, TUnionError, TInputData, FieldNames, EnumTypes, RelationTypes, ColumnPermissionPermissionRules, ColumnPermissionMandatoryRules, Edition, Feature, Functionality, CustomizationStatsItemKeys, LicenseRestrictionKeys, ExpirationReason, LicenseKeyInvoiceSeverity, ErrorHelper, VersionHelperBase, OAuthSessionHandlerBase };
|
package/lib/index.js
CHANGED
|
@@ -14,7 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.VersionHelperBase = exports.ErrorHelper = exports.LicenseKeyInvoiceSeverity = exports.ExpirationReason = exports.LicenseRestrictionKeys = exports.CustomizationStatsItemKeys = exports.Functionality = exports.Feature = exports.Edition = exports.ColumnPermissionMandatoryRules = exports.ColumnPermissionPermissionRules = exports.RelationTypes = exports.EnumTypes = exports.FieldNames = exports.HttpRequestError = exports.OAuthHelper = exports.FolderNames = exports.GlobalSettingsNames = exports.ApiMethods = exports.CommonDataConnection = exports.TokenizedServiceConnection = exports.ReturnCodes = exports.HttpMethod = void 0;
|
|
17
|
+
exports.OAuthSessionHandlerBase = exports.VersionHelperBase = exports.ErrorHelper = exports.LicenseKeyInvoiceSeverity = exports.ExpirationReason = exports.LicenseRestrictionKeys = exports.CustomizationStatsItemKeys = exports.Functionality = exports.Feature = exports.Edition = exports.ColumnPermissionMandatoryRules = exports.ColumnPermissionPermissionRules = exports.RelationTypes = exports.EnumTypes = exports.FieldNames = exports.HttpRequestError = exports.OAuthHelper = exports.FolderNames = exports.GlobalSettingsNames = exports.ApiMethods = exports.CommonDataConnection = exports.TokenizedServiceConnection = exports.ReturnCodes = exports.HttpMethod = void 0;
|
|
18
18
|
var Promise = require("es6-promise");
|
|
19
19
|
var ApiConnection_1 = require("./ApiConnection");
|
|
20
20
|
var HttpMethod_1 = require("./HttpMethod");
|
|
@@ -62,6 +62,8 @@ var ErrorHelper_1 = require("./helpers/ErrorHelper");
|
|
|
62
62
|
exports.ErrorHelper = ErrorHelper_1.default;
|
|
63
63
|
var VersionHelperBase_1 = require("./helpers/VersionHelperBase");
|
|
64
64
|
exports.VersionHelperBase = VersionHelperBase_1.default;
|
|
65
|
+
var OAuthSessionHandlerBase_1 = require("./OAuthSessionHandlerBase");
|
|
66
|
+
Object.defineProperty(exports, "OAuthSessionHandlerBase", { enumerable: true, get: function () { return OAuthSessionHandlerBase_1.OAuthSessionHandlerBase; } });
|
|
65
67
|
Promise.polyfill();
|
|
66
68
|
exports.default = ApiConnection_1.ApiConnection;
|
|
67
69
|
__exportStar(require("./data/EWItem"), exports);
|
|
@@ -113,6 +115,7 @@ __exportStar(require("./data/IApiSaveResponse"), exports);
|
|
|
113
115
|
__exportStar(require("./data/IApiTask"), exports);
|
|
114
116
|
__exportStar(require("./data/IApiUser"), exports);
|
|
115
117
|
__exportStar(require("./data/IApiUserSetting"), exports);
|
|
118
|
+
__exportStar(require("./data/IApiWebServiceTaskStatus"), exports);
|
|
116
119
|
__exportStar(require("./data/IApiWorkflowActionDerivedItem"), exports);
|
|
117
120
|
__exportStar(require("./data/IApiWorkflowModel"), exports);
|
|
118
121
|
__exportStar(require("./data/IApiWorkReport"), exports);
|