Skip to content

Commit bf77dc6

Browse files
authored
Merge pull request #60 from CyberSource/merger
Merged Authentication SDK into Client SDK
2 parents 83217b3 + 578b3ca commit bf77dc6

16 files changed

+1127
-12
lines changed

generator/cybersource-javascript-template/ApiClient.mustache

+9-10
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,18 @@
22
(function(root, factory) {
33
if (typeof define === 'function' && define.amd) {
44
// AMD. Register as an anonymous module.
5-
define(['superagent', 'superagent-proxy', 'querystring'], factory);
5+
define(['superagent', 'superagent-proxy', 'querystring', 'Authentication/MerchantConfig', 'Authentication/Logger', 'Authentication/Constants', 'Authentication/Authorization', 'Authentication/PayloadDigest'], factory);
66
} else if (typeof module === 'object' && module.exports) {
77
// CommonJS-like environments that support module.exports, like Node.
8-
module.exports = factory(require('superagent'), require('superagent-proxy'), require('querystring'));
8+
module.exports = factory(require('superagent'), require('superagent-proxy'), require('querystring'), require('./authentication/core/MerchantConfig'), require('./authentication/logging/Logger'), require('./authentication/util/Constants'), require('./authentication/core/Authorization'), require('./authentication/payloadDigest/DigestGenerator'));
99
} else {
1010
// Browser globals (root is window)
1111
if (!root.{{moduleName}}) {
1212
root.{{moduleName}} = {};
1313
}
14-
root.{{moduleName}}.ApiClient = factory(root.superagent, root.superagent_proxy, root.querystring);
14+
root.{{moduleName}}.ApiClient = factory(root.superagent, root.superagent_proxy, root.querystring, root.Authentication.MerchantConfig, root.Authentication.Logger, root.Authentication.Constants, root.Authentication.Authorization, root.Authentication.PayloadDigest);
1515
}
16-
}(this, function(superagent, superagent_proxy, querystring) {
16+
}(this, function(superagent, superagent_proxy, querystring, MerchantConfig, Logger, Constants, Authorization, PayloadDigest) {
1717
'use strict';
1818
1919
{{#emitJSDoc}} /**
@@ -354,18 +354,17 @@
354354

355355
// Code added by Infosys dev team
356356

357-
var AuthenticationSDK = require('cybersource-rest-auth');
358357
/**
359358
* This method will set the merchantConfig object global
360359
*
361360
* @param {Configuration} configObject merchantConfiguration properties.
362361
*/
363362
exports.prototype.setConfiguration = function (configObject) {
364363
365-
this.merchantConfig = new AuthenticationSDK.MerchantConfig(configObject);
366-
this.constants = AuthenticationSDK.Constants;
364+
this.merchantConfig = new MerchantConfig(configObject);
365+
this.constants = Constants;
367366
this.basePath = this.constants.HTTP_URL_PREFIX + this.merchantConfig.getRequestHost();
368-
this.logger = AuthenticationSDK.Logger.getLogger(this.merchantConfig, 'ApiClient');
367+
this.logger = Logger.getLogger(this.merchantConfig, 'ApiClient');
369368
}
370369

371370
/**
@@ -384,7 +383,7 @@
384383
this.logger.info('Authentication Type : ' + this.merchantConfig.getAuthenticationType());
385384
this.logger.info(this.constants.REQUEST_TYPE + ' : ' + httpMethod.toUpperCase());
386385
387-
var token = AuthenticationSDK.Authorization.getToken(this.merchantConfig, this.logger);
386+
var token = Authorization.getToken(this.merchantConfig, this.logger);
388387
389388
var clientId = getClientId();
390389
@@ -405,7 +404,7 @@
405404
if (httpMethod.toLowerCase() === this.constants.POST
406405
|| httpMethod.toLowerCase() === this.constants.PATCH
407406
|| httpMethod.toLowerCase() === this.constants.PUT) {
408-
var digest = AuthenticationSDK.PayloadDigest.generateDigest(this.merchantConfig, this.logger);
407+
var digest = PayloadDigest.generateDigest(this.merchantConfig, this.logger);
409408
digest = this.constants.SIGNATURE_ALGORITHAM + digest;
410409
this.logger.info(this.constants.DIGEST + " : " + digest);
411410
headerParams['digest'] = digest;

generator/cybersource-javascript-template/index.mustache

+5
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,11 @@
6060
};
6161

6262
exports.TokenVerification = require('./utilities/flex/TokenVerification.js');
63+
exports.Authorization = require('./authentication/core/Authorization.js'),
64+
exports.MerchantConfig = require('./authentication/core/MerchantConfig.js'),
65+
exports.Logger = require('./authentication/logging/Logger.js'),
66+
exports.Constants = require('./authentication/util/Constants.js'),
67+
exports.PayloadDigest = require('./authentication/payloadDigest/DigestGenerator.js')
6368

6469
return exports;<={{ }}=>
6570
}));

package.json

+18-2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
"name": "cybersource-rest-client",
33
"version": "0.0.26",
44
"description": "Node.js SDK for the CyberSource REST API",
5+
"author": "[email protected]",
56
"license": "CyberSource",
67
"main": "src/index.js",
78
"scripts": {
@@ -13,10 +14,25 @@
1314
"dependencies": {
1415
"superagent": "3.8.3",
1516
"superagent-proxy": "^2.0.0",
16-
"cybersource-rest-auth": "0.0.10"
17+
"app-root-path": "^2.1.0",
18+
"chai": "^4.1.2",
19+
"chai-as-promised": "^7.1.1",
20+
"collections": "^5.1.2",
21+
"jwt-simple": "^0.5.1",
22+
"memory-cache": "^0.2.0",
23+
"node-forge": "^0.10.0",
24+
"promise": "^8.0.1",
25+
"winston": "^3.3.3",
26+
"winston-daily-rotate-file": "^4.5.1"
1727
},
28+
"keywords": [
29+
"nodeJS"
30+
],
1831
"devDependencies": {
19-
"mocha": "~5.2.0",
32+
"mocha": "^5.2.0",
33+
"mocha-sonarqube-reporter": "^1.0.1",
34+
"nyc": "^12.0.2",
35+
"sonar-scanner": "^3.1.0",
2036
"@sinonjs/formatio": "3.0.0",
2137
"expect.js": "~0.3.1"
2238
}
+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
'use strict';
2+
3+
var Constants = require('../util/Constants');
4+
var HttpSingToken = require('../http/HTTPSigToken');
5+
var JWTSigToken = require('../jwt/JWTSigToken');
6+
var ApiException = require('../util/ApiException');
7+
8+
/**
9+
* This function calls for the generation of Signature message depending on the authentication type.
10+
*
11+
*/
12+
exports.getToken = function(merchantConfig, logger){
13+
14+
var authenticationType = merchantConfig.getAuthenticationType().toLowerCase();
15+
var httpSigToken;
16+
var jwtSingToken;
17+
18+
if(authenticationType === Constants.HTTP) {
19+
httpSigToken = HttpSingToken.getToken(merchantConfig, logger);
20+
return httpSigToken;
21+
}
22+
else if(authenticationType === Constants.JWT) {
23+
jwtSingToken = JWTSigToken.getToken(merchantConfig, logger);
24+
return jwtSingToken;
25+
}
26+
else{
27+
ApiException.ApiException(Constants.AUTH_ERROR, logger);
28+
}
29+
}

0 commit comments

Comments
 (0)