@meltwater/conversations-api-services 1.0.18 → 1.0.20
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/.github/workflows/release.yml +2 -0
- package/babel.config.js +18 -0
- package/dist/cjs/data-access/http/InstagramVideoClient.js +42 -0
- package/dist/cjs/data-access/http/WarpZoneApi.client.js +32 -0
- package/dist/cjs/data-access/http/amazonS3.js +44 -0
- package/dist/cjs/data-access/http/asset-manager-tvm.client.js +35 -0
- package/dist/cjs/data-access/http/companiesApi.client.js +38 -0
- package/dist/cjs/data-access/http/credentialsApi.client.js +102 -0
- package/dist/cjs/data-access/http/entitlementsApi.client.js +40 -0
- package/dist/cjs/data-access/http/facebook.native.js +344 -0
- package/dist/cjs/data-access/http/facebookApi.client.js +631 -0
- package/dist/cjs/data-access/http/featureToggleApi.client.js +31 -0
- package/dist/cjs/data-access/http/identityServices.client.js +97 -0
- package/dist/cjs/data-access/http/instagramApi.client.js +428 -0
- package/dist/cjs/data-access/http/ir.client.js +242 -0
- package/dist/cjs/data-access/http/linkedInApi.client.js +491 -0
- package/dist/cjs/data-access/http/masf.client.js +101 -0
- package/dist/cjs/data-access/http/tiktokApi.client.js +441 -0
- package/dist/cjs/data-access/index.js +129 -0
- package/dist/cjs/errors/engage-error.js +16 -0
- package/dist/cjs/errors/http-error.js +23 -0
- package/dist/cjs/lib/applicationTags.helpers.js +30 -0
- package/dist/cjs/lib/configuration.js +14 -0
- package/dist/cjs/lib/document-action-events.js +12 -0
- package/dist/cjs/lib/externalId.helpers.js +19 -0
- package/dist/cjs/lib/hidden.helpers.js +13 -0
- package/dist/cjs/lib/hiddenComment.helper.js +119 -0
- package/dist/cjs/lib/logger.helpers.js +68 -0
- package/dist/cjs/lib/logger.js +23 -0
- package/dist/cjs/lib/message.helpers.js +58 -0
- package/dist/cjs/lib/metrics.helper.js +97 -0
- package/dist/esm/data-access/http/InstagramVideoClient.js +34 -0
- package/dist/esm/data-access/http/WarpZoneApi.client.js +24 -0
- package/dist/esm/data-access/http/amazonS3.js +37 -0
- package/dist/esm/data-access/http/asset-manager-tvm.client.js +28 -0
- package/dist/esm/data-access/http/companiesApi.client.js +30 -0
- package/dist/esm/data-access/http/credentialsApi.client.js +92 -0
- package/dist/esm/data-access/http/entitlementsApi.client.js +32 -0
- package/dist/esm/data-access/http/facebook.native.js +325 -0
- package/dist/esm/data-access/http/facebookApi.client.js +621 -0
- package/dist/esm/data-access/http/featureToggleApi.client.js +23 -0
- package/dist/esm/data-access/http/identityServices.client.js +89 -0
- package/dist/esm/data-access/http/instagramApi.client.js +420 -0
- package/dist/esm/data-access/http/ir.client.js +234 -0
- package/dist/esm/data-access/http/linkedInApi.client.js +481 -0
- package/dist/esm/data-access/http/masf.client.js +93 -0
- package/dist/esm/data-access/http/tiktokApi.client.js +433 -0
- package/dist/esm/data-access/index.js +29 -0
- package/dist/esm/errors/engage-error.js +9 -0
- package/dist/esm/errors/http-error.js +16 -0
- package/dist/esm/lib/applicationTags.helpers.js +22 -0
- package/dist/esm/lib/configuration.js +8 -0
- package/dist/esm/lib/document-action-events.js +6 -0
- package/dist/esm/lib/externalId.helpers.js +12 -0
- package/dist/esm/lib/hidden.helpers.js +6 -0
- package/dist/esm/lib/hiddenComment.helper.js +112 -0
- package/dist/esm/lib/logger.helpers.js +60 -0
- package/dist/esm/lib/logger.js +16 -0
- package/dist/esm/lib/message.helpers.js +52 -0
- package/dist/esm/lib/metrics.helper.js +90 -0
- package/package.json +14 -4
- package/src/data-access/http/facebook.native.js +542 -0
- package/src/data-access/http/masf.client.js +5 -0
- package/src/data-access/index.js +2 -0
- package/src/errors/engage-error.js +11 -0
- package/src/errors/http-error.js +19 -0
- package/src/lib/logger.helpers.js +15 -0
- package/src/lib/message.helpers.js +7 -1
|
@@ -31,6 +31,8 @@ jobs:
|
|
|
31
31
|
run: echo "//registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }}" > ~/.npmrc
|
|
32
32
|
- name: Install dependencies
|
|
33
33
|
run: npm clean-install
|
|
34
|
+
- name: Run Babel Build
|
|
35
|
+
run: npm run build
|
|
34
36
|
- name: Verify signatures
|
|
35
37
|
run: npm audit signatures
|
|
36
38
|
- name: Release
|
package/babel.config.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
module.exports = function (api) {
|
|
2
|
+
api.cache(true);
|
|
3
|
+
|
|
4
|
+
const isESM = process.env.BABEL_ENV === 'esm';
|
|
5
|
+
|
|
6
|
+
return {
|
|
7
|
+
presets: [
|
|
8
|
+
[
|
|
9
|
+
'@babel/preset-env',
|
|
10
|
+
{
|
|
11
|
+
modules: isESM ? false : 'commonjs', // 'false' for ESM, 'commonjs' for CJS
|
|
12
|
+
targets: '> 0.25%, not dead', // specify your target environment if needed
|
|
13
|
+
},
|
|
14
|
+
],
|
|
15
|
+
],
|
|
16
|
+
};
|
|
17
|
+
};
|
|
18
|
+
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.InstagramVideoClient = void 0;
|
|
7
|
+
var _superagent = _interopRequireDefault(require("superagent"));
|
|
8
|
+
var _configuration = _interopRequireDefault(require("../../lib/configuration.js"));
|
|
9
|
+
var _logger = _interopRequireDefault(require("../../lib/logger.js"));
|
|
10
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
11
|
+
class InstagramVideoClient {
|
|
12
|
+
/**
|
|
13
|
+
* @private
|
|
14
|
+
* @param {string} url
|
|
15
|
+
* @returns {Promise<object>}
|
|
16
|
+
*/
|
|
17
|
+
_getDownloadLink = async url => {
|
|
18
|
+
const apiUrl = _configuration.default.get('UGC_MEDIA_API_URL');
|
|
19
|
+
const apiToken = _configuration.default.get('UGC_MEDIA_API_TOKEN');
|
|
20
|
+
try {
|
|
21
|
+
const response = await _superagent.default.get(`${apiUrl}/instagram/video/`).set('x-api-token', apiToken).query({
|
|
22
|
+
url
|
|
23
|
+
});
|
|
24
|
+
return response.body?.data;
|
|
25
|
+
} catch (error) {
|
|
26
|
+
_logger.default.error(`Could not retrieve video link from ${url}`, {
|
|
27
|
+
error
|
|
28
|
+
});
|
|
29
|
+
throw new Error('Could not retrieve video link');
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
*
|
|
35
|
+
* @param {string} url
|
|
36
|
+
* @returns {Promise<object>}
|
|
37
|
+
*/
|
|
38
|
+
getVideoLink = async url => {
|
|
39
|
+
return await this._getDownloadLink(url);
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
exports.InstagramVideoClient = InstagramVideoClient;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.WarpZoneApiClient = void 0;
|
|
7
|
+
var _superagent = _interopRequireDefault(require("superagent"));
|
|
8
|
+
var _logger = _interopRequireDefault(require("../../lib/logger.js"));
|
|
9
|
+
var _configuration = _interopRequireDefault(require("../../lib/configuration.js"));
|
|
10
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
11
|
+
class WarpZoneApiClient {
|
|
12
|
+
constructor() {
|
|
13
|
+
this.warpzoneURL = _configuration.default.get('WARPZONE_API_URL');
|
|
14
|
+
this.warpzoneAPI = _configuration.default.get('WARPZONE_API_KEY');
|
|
15
|
+
}
|
|
16
|
+
async sendPost() {
|
|
17
|
+
let postData = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : undefined;
|
|
18
|
+
let response = {};
|
|
19
|
+
try {
|
|
20
|
+
response = await _superagent.default.post(this.warpzoneURL + 'event').set('Accept', 'application/json').set('Content-Type', 'application/json').set('X-API-Key', this.warpzoneAPI).send(postData);
|
|
21
|
+
} catch (err) {
|
|
22
|
+
if (err && err.response && err.response.body && err.response.body.error) {
|
|
23
|
+
_logger.default.error(`Failed to call warp zone api: ${err.response.body.error.message}`);
|
|
24
|
+
} else {
|
|
25
|
+
_logger.default.error(`Failed to call warp zone api`, err);
|
|
26
|
+
}
|
|
27
|
+
throw err;
|
|
28
|
+
}
|
|
29
|
+
return response;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
exports.WarpZoneApiClient = WarpZoneApiClient;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.awsS3Client = void 0;
|
|
7
|
+
var _awsSdk = _interopRequireDefault(require("aws-sdk"));
|
|
8
|
+
var _assert = _interopRequireDefault(require("assert"));
|
|
9
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
10
|
+
class AWS_S3 {
|
|
11
|
+
constructor() {}
|
|
12
|
+
async getClient() {
|
|
13
|
+
const {
|
|
14
|
+
Credentials: {
|
|
15
|
+
AccessKeyId,
|
|
16
|
+
SecretAccessKey,
|
|
17
|
+
SessionToken
|
|
18
|
+
} = {}
|
|
19
|
+
} = await assetManagerTvmRepository.get(companyId);
|
|
20
|
+
if (!AccessKeyId || !SecretAccessKey || !SessionToken) {
|
|
21
|
+
// probably a bit extreme, what would you prefer to do
|
|
22
|
+
throw 'No Credentials available';
|
|
23
|
+
}
|
|
24
|
+
return new _awsSdk.default.S3({
|
|
25
|
+
accessKeyId: AccessKeyId,
|
|
26
|
+
secretAccessKey: SecretAccessKey,
|
|
27
|
+
sessionToken: SessionToken,
|
|
28
|
+
useAccelerateEndpoint: true
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
GetS3ObjectQuery(bucket, filename) {
|
|
32
|
+
(0, _assert.default)(bucket, 'S3 bucket is required');
|
|
33
|
+
(0, _assert.default)(filename, 'filePath is required');
|
|
34
|
+
(0, _assert.default)(typeof filename === 'string', 'filePath should be a string.');
|
|
35
|
+
return {
|
|
36
|
+
config: {
|
|
37
|
+
Bucket: bucket,
|
|
38
|
+
Key: filename.replace(`/${bucket}/`, ''),
|
|
39
|
+
GrantRead: 'uri=http://acs.amazonaws.com/groups/global/AllUsers'
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
const awsS3Client = exports.awsS3Client = new AWS_S3();
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.assetManagerTvmRepository = void 0;
|
|
7
|
+
var _superagent = _interopRequireDefault(require("superagent"));
|
|
8
|
+
var _logger = _interopRequireDefault(require("../../lib/logger.js"));
|
|
9
|
+
var _loggerHelpers = require("../../lib/logger.helpers.js");
|
|
10
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
11
|
+
const {
|
|
12
|
+
ASSET_MANAGER_TVM_API_KEY,
|
|
13
|
+
ASSET_MANAGER_TVM_URL
|
|
14
|
+
} = process.env;
|
|
15
|
+
class AssetManagerTVMRepository {
|
|
16
|
+
apiKey;
|
|
17
|
+
constructor() {}
|
|
18
|
+
async get(companyId) {
|
|
19
|
+
let response;
|
|
20
|
+
try {
|
|
21
|
+
response = await _superagent.default.get(`https://${ASSET_MANAGER_TVM_URL}/tvm`).query({
|
|
22
|
+
companyId
|
|
23
|
+
}).timeout(5000).set({
|
|
24
|
+
'x-api-key': ASSET_MANAGER_TVM_API_KEY
|
|
25
|
+
}).then(result => result.body);
|
|
26
|
+
} catch (error) {
|
|
27
|
+
_logger.default.error("Failed requesting Asset Manager TVM API", error, {
|
|
28
|
+
[_loggerHelpers.MeltwaterAttributes.COMPANYID]: companyId
|
|
29
|
+
});
|
|
30
|
+
throw error;
|
|
31
|
+
}
|
|
32
|
+
return response;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
const assetManagerTvmRepository = exports.assetManagerTvmRepository = new AssetManagerTVMRepository();
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.CompanyApiClient = void 0;
|
|
7
|
+
var _superagent = _interopRequireDefault(require("superagent"));
|
|
8
|
+
var _logger = _interopRequireDefault(require("../../lib/logger.js"));
|
|
9
|
+
var _configuration = _interopRequireDefault(require("../../lib/configuration.js"));
|
|
10
|
+
var _loggerHelpers = require("../../lib/logger.helpers.js");
|
|
11
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
12
|
+
class CompanyApiClient {
|
|
13
|
+
constructor(_ref) {
|
|
14
|
+
let {
|
|
15
|
+
services
|
|
16
|
+
} = _ref;
|
|
17
|
+
this.companiesApiUrl = _configuration.default.get('COMPANIES_API_URL');
|
|
18
|
+
this.authService = services.auth;
|
|
19
|
+
}
|
|
20
|
+
async getById(companyId, jwt) {
|
|
21
|
+
let retries = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
|
|
22
|
+
let company;
|
|
23
|
+
try {
|
|
24
|
+
let resignedToken = await this.authService.getResignedToken(jwt);
|
|
25
|
+
company = await _superagent.default.get(`${this.companiesApiUrl}/${companyId}`).set('Authorization', resignedToken).set('x-client-name', _configuration.default.get('CLIENT_NAME_HEADER')).then(result => result.body);
|
|
26
|
+
} catch (error) {
|
|
27
|
+
_logger.default.error(`Failed requesting Companies Api for companyId ${companyId} retry ${retries}`, error, {
|
|
28
|
+
[_loggerHelpers.MeltwaterAttributes.COMPANYID]: companyId
|
|
29
|
+
});
|
|
30
|
+
if (retries <= 3) {
|
|
31
|
+
return this.getById(companyId, jwt, ++retries);
|
|
32
|
+
}
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
return company;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
exports.CompanyApiClient = CompanyApiClient;
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.CredentialsApiClient = void 0;
|
|
7
|
+
var _superagent = _interopRequireDefault(require("superagent"));
|
|
8
|
+
var _logger = _interopRequireDefault(require("../../lib/logger.js"));
|
|
9
|
+
var _configuration = _interopRequireDefault(require("../../lib/configuration.js"));
|
|
10
|
+
var _loggerHelpers = require("../../lib/logger.helpers.js");
|
|
11
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
12
|
+
// @todo remove superagent
|
|
13
|
+
|
|
14
|
+
class CredentialsApiClient {
|
|
15
|
+
constructor() {
|
|
16
|
+
this.credentialsApiUrl = _configuration.default.get('CREDENTIALS_API_URL');
|
|
17
|
+
this.credentialsApiApplicationId = _configuration.default.get('CREDENTIALS_API_APPLICATION_ID');
|
|
18
|
+
}
|
|
19
|
+
async getCredential(_ref, userPermissionsEnabled) {
|
|
20
|
+
let {
|
|
21
|
+
companyId,
|
|
22
|
+
userId,
|
|
23
|
+
accountId,
|
|
24
|
+
productArea
|
|
25
|
+
} = _ref;
|
|
26
|
+
const credentials = await this.getCredentialsByCompany({
|
|
27
|
+
companyId,
|
|
28
|
+
userId,
|
|
29
|
+
productArea
|
|
30
|
+
}, userPermissionsEnabled);
|
|
31
|
+
if (!credentials) {
|
|
32
|
+
throw 'No credentials returned';
|
|
33
|
+
}
|
|
34
|
+
const credential = credentials.find(credential => credential.social_account_id == accountId);
|
|
35
|
+
if (!credential) {
|
|
36
|
+
throw `${sourceId} credential was not found.`;
|
|
37
|
+
}
|
|
38
|
+
return credential;
|
|
39
|
+
}
|
|
40
|
+
async getCredentialsByCompany(_ref2, userPermissionsEnabled) {
|
|
41
|
+
let {
|
|
42
|
+
companyId,
|
|
43
|
+
userId,
|
|
44
|
+
productArea
|
|
45
|
+
} = _ref2;
|
|
46
|
+
const loggerChild = _logger.default.child({
|
|
47
|
+
[_loggerHelpers.MeltwaterAttributes.COMPANYID]: companyId,
|
|
48
|
+
[_loggerHelpers.MeltwaterAttributes.USERID]: userId
|
|
49
|
+
});
|
|
50
|
+
let credentials;
|
|
51
|
+
try {
|
|
52
|
+
if (productArea) {
|
|
53
|
+
loggerChild.info(`Get Credentials for company: ${companyId} and user: ${userId}`);
|
|
54
|
+
credentials = await _superagent.default.get(`${this.credentialsApiUrl}/api/v4.0/CompanyCredentials/${this.credentialsApiApplicationId}/${companyId}/${userId}`).query({
|
|
55
|
+
productArea
|
|
56
|
+
}).then(result => result.body.data);
|
|
57
|
+
} else if (userPermissionsEnabled) {
|
|
58
|
+
credentials = await _superagent.default.get(`${this.credentialsApiUrl}/api/v4.0/CompanyCredentials/${this.credentialsApiApplicationId}/${companyId}/${userId}`).then(result => result.body.data);
|
|
59
|
+
} else {
|
|
60
|
+
credentials = await _superagent.default.get(`${this.credentialsApiUrl}/api/v3.0/CompanyCredentials/${this.credentialsApiApplicationId}/${companyId}/${userId}`).then(result => result.body.data);
|
|
61
|
+
}
|
|
62
|
+
} catch (error) {
|
|
63
|
+
loggerChild.error(`Failed requesting Credentials API for companyId ${companyId} ${userId}`, error);
|
|
64
|
+
return [];
|
|
65
|
+
}
|
|
66
|
+
loggerChild.info(`Finished requesting Credentials API for companyId ${companyId}`);
|
|
67
|
+
return credentials;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// todo: will this need to ever use productArea?
|
|
71
|
+
async getToken(credentialId, companyId) {
|
|
72
|
+
const loggerChild = _logger.default.child({
|
|
73
|
+
[_loggerHelpers.MeltwaterAttributes.COMPANYID]: companyId,
|
|
74
|
+
[_loggerHelpers.MeltwaterAttributes.CREDENTIALID]: credentialId
|
|
75
|
+
});
|
|
76
|
+
let token;
|
|
77
|
+
try {
|
|
78
|
+
token = await _superagent.default.get(`${this.credentialsApiUrl}/api/Token/${credentialId}/${companyId}`).then(result => {
|
|
79
|
+
return result.body;
|
|
80
|
+
});
|
|
81
|
+
} catch (error) {
|
|
82
|
+
loggerChild.error(`Failed requesting Credentials API for credentialId ${credentialId} and companyId ${companyId}`, error);
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
loggerChild.info(`Finished requesting Credentials API for credentialId ${credentialId} and companyId ${companyId}`);
|
|
86
|
+
return token;
|
|
87
|
+
}
|
|
88
|
+
async getCredentialIdByAccountId(accountId, channel) {
|
|
89
|
+
let credentialId;
|
|
90
|
+
try {
|
|
91
|
+
credentialId = await _superagent.default.get(`${this.credentialsApiUrl}/api/CompanyCredentials/GetCredential/${channel}/${accountId}`).then(result => {
|
|
92
|
+
return result.body && result.body.data && result.body.data.credentialId;
|
|
93
|
+
});
|
|
94
|
+
} catch (error) {
|
|
95
|
+
_logger.default.error(`Failed requesting Credentials API for credentialId ${accountId} and channel ${channel}`, error);
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
_logger.default.info(`Finished requesting Credentials API for credentialId ${accountId} and channel ${channel}`);
|
|
99
|
+
return credentialId;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
exports.CredentialsApiClient = CredentialsApiClient;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.EntitlementsApiClient = void 0;
|
|
7
|
+
var _superagent = _interopRequireDefault(require("superagent"));
|
|
8
|
+
var _logger = _interopRequireDefault(require("../../lib/logger.js"));
|
|
9
|
+
var _configuration = _interopRequireDefault(require("../../lib/configuration.js"));
|
|
10
|
+
var _loggerHelpers = require("../../lib/logger.helpers.js");
|
|
11
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
12
|
+
class EntitlementsApiClient {
|
|
13
|
+
constructor(_ref) {
|
|
14
|
+
let {
|
|
15
|
+
services
|
|
16
|
+
} = _ref;
|
|
17
|
+
this.entitlementsApiUrl = _configuration.default.get('ENTITLEMENTS_API_URL');
|
|
18
|
+
this.authService = services.auth;
|
|
19
|
+
}
|
|
20
|
+
async getById(entitlementId, companyId, jwt) {
|
|
21
|
+
let retries = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 0;
|
|
22
|
+
const loggerChild = _logger.default.child({
|
|
23
|
+
[_loggerHelpers.MeltwaterAttributes.COMPANYID]: companyId
|
|
24
|
+
});
|
|
25
|
+
let entitlement;
|
|
26
|
+
try {
|
|
27
|
+
let resignedToken = await this.authService.getResignedToken(jwt);
|
|
28
|
+
entitlement = await _superagent.default.get(`${this.entitlementsApiUrl}/company/${companyId}/${entitlementId}`).set('Authorization', resignedToken).set('x-client-name', _configuration.default.get('CLIENT_NAME_HEADER')).then(result => result.body);
|
|
29
|
+
} catch (error) {
|
|
30
|
+
loggerChild.error(`Failed requesting entitlement ${entitlementId} for companyId ${companyId} retry ${retries}`, error);
|
|
31
|
+
if (retries <= 3) {
|
|
32
|
+
return this.getById(entitlementId, companyId, jwt, ++retries);
|
|
33
|
+
}
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
loggerChild.info(`Finished requesting entitlement ${entitlementId} for companyId ${companyId}`);
|
|
37
|
+
return entitlement;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
exports.EntitlementsApiClient = EntitlementsApiClient;
|