This repository has been archived by the owner on Jan 20, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Client.js
75 lines (70 loc) · 2.99 KB
/
Client.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
const EnvironmentConfigProvider = require('../EnvironmentConfigProvider');
(function (root, factory) {
factory(require('../index'));
}(this, function (SalesforceMarketingCloud) {
class Client {
constructor(clientConfig) {
let _authBaseUrl;
this.getAuthBaseUrl = () => { return _authBaseUrl; };
let _clientId;
this.getClientId = () => { return _clientId; };
let _clientSecret;
this.getClientSecret = () => { return _clientSecret; };
let _accountId;
this.getAccountId = () => { return _accountId; };
let _scope;
this.getScope = () => { return _scope; };
this._assetApi = undefined;
this._campaignApi = undefined;
this._transactionalMessagingApi = undefined;
if (!clientConfig) {
let environmentConfigProvider = new EnvironmentConfigProvider();
_authBaseUrl = environmentConfigProvider.get('SFMC_AUTH_BASE_URL');
_clientId = environmentConfigProvider.get('SFMC_CLIENT_ID');
_clientSecret = environmentConfigProvider.get('SFMC_CLIENT_SECRET');
_accountId = environmentConfigProvider.get('SFMC_ACCOUNT_ID');
_scope = environmentConfigProvider.get('SFMC_SCOPE', false);
} else {
_authBaseUrl = clientConfig.authBaseUrl;
_clientId = clientConfig.clientId;
_clientSecret = clientConfig.clientSecret;
_accountId = clientConfig.accountId;
_scope = clientConfig.scope;
}
}
get assetApi() {
if(this._assetApi === undefined){
this._assetApi = new SalesforceMarketingCloud.AssetApi(
this.getAuthBaseUrl(),
this.getClientId(),
this.getClientSecret(),
this.getAccountId(),
this.getScope());
}
return this._assetApi;
}
get campaignApi() {
if(this._campaignApi === undefined){
this._campaignApi = new SalesforceMarketingCloud.CampaignApi(
this.getAuthBaseUrl(),
this.getClientId(),
this.getClientSecret(),
this.getAccountId(),
this.getScope());
}
return this._campaignApi;
}
get transactionalMessagingApi() {
if(this._transactionalMessagingApi === undefined){
this._transactionalMessagingApi = new SalesforceMarketingCloud.TransactionalMessagingApi(
this.getAuthBaseUrl(),
this.getClientId(),
this.getClientSecret(),
this.getAccountId(),
this.getScope());
}
return this._transactionalMessagingApi;
}
}
module.exports = Client;
}));