mirror of
https://github.com/node-ebics/node-ebics-client.git
synced 2024-11-24 15:12:06 +00:00
feat: generalize examples
This commit is contained in:
parent
fcbf4ca165
commit
f6dfdf4c40
@ -1,25 +0,0 @@
|
||||
const _ = require('lodash');
|
||||
|
||||
const ebics = require('../index');
|
||||
const config = require('./config.json');
|
||||
var myArgs = process.argv.slice(2);
|
||||
//We can run this script with an argument. I.e. "testing" or "production" and it will load the corresponding configuration values for the corresponding environment from config.json
|
||||
const whichEnvironment = myArgs[0].trim().toLowerCase();
|
||||
const defaultConfig = config.testing;
|
||||
//We default back to test in case whichEnvironment argument is not passed while running the script, so we don't accidentally end up making changes in production.
|
||||
const environment = whichEnvironment || 'testing';
|
||||
const environmentConfig = config[environment];
|
||||
if (!environmentConfig) {
|
||||
console.log("ERROR! Could not find configuration for \""+whichEnvironment+"\" using configuration for \"testing\" instead");
|
||||
}
|
||||
|
||||
global.gFinalConfig = _.merge(defaultConfig, environmentConfig);
|
||||
|
||||
global.gClient = new ebics.Client({
|
||||
url: gFinalConfig.serverAddress,
|
||||
partnerId: gFinalConfig.partnerId,
|
||||
userId: gFinalConfig.userId,
|
||||
hostId: gFinalConfig.hostId,
|
||||
passphrase: gFinalConfig.passphrase, // keys-test will be encrypted with this passphrase
|
||||
keyStorage: ebics.fsKeysStorage(gFinalConfig.keyStorage),
|
||||
});
|
@ -1,42 +0,0 @@
|
||||
{
|
||||
"testing": {
|
||||
"serverAddress": "https://ebics-test.server",
|
||||
"partnerId": "EBICS ParnerID Test",
|
||||
"userId": "MyUserIdTest",
|
||||
"hostId": "MyHostIdTest",
|
||||
"passphrase": "MyPasswordTest",
|
||||
"keyStorage": "./keys-test",
|
||||
"bankName":"Test Bank",
|
||||
"languageCode":"en"
|
||||
},
|
||||
"development": {
|
||||
"serverAddress": "https://ebics-development.server",
|
||||
"partnerId": "EBICS ParnerID Development",
|
||||
"userId": "MyUserIdDevelopment",
|
||||
"hostId": "MyHostIdDevelopment",
|
||||
"passphrase": "MyPasswordDevelopment",
|
||||
"keyStorage": "./keys-development",
|
||||
"bankName":"Development Bank",
|
||||
"languageCode":"en"
|
||||
},
|
||||
"staging": {
|
||||
"serverAddress": "https://ebics-staging.server",
|
||||
"partnerId": "EBICS ParnerID Staging",
|
||||
"userId": "MyUserIdStaging",
|
||||
"hostId": "MyHostIdStaging",
|
||||
"passphrase": "MyPasswordStaging",
|
||||
"keyStorage": "./keys-staging",
|
||||
"bankName":"Staging Bank",
|
||||
"languageCode":"en"
|
||||
},
|
||||
"production": {
|
||||
"serverAddress": "https://ebics.server",
|
||||
"partnerId": "EBICS ParnerID Production",
|
||||
"userId": "MyUserIdProduction",
|
||||
"hostId": "MyHostIdProduction",
|
||||
"passphrase": "MyPasswordProduction",
|
||||
"keyStorage": "./keys-prod",
|
||||
"bankName":"Production Bank",
|
||||
"languageCode":"en"
|
||||
}
|
||||
}
|
10
examples/config/config.json
Normal file
10
examples/config/config.json
Normal file
@ -0,0 +1,10 @@
|
||||
{
|
||||
"serverAddress": "https://ebics-test.server",
|
||||
"partnerId": "EBICS ParnerID Test",
|
||||
"userId": "MyUserIdTest",
|
||||
"hostId": "MyHostIdTest",
|
||||
"passphrase": "MyPasswordTest",
|
||||
"keyStorage": "./keys-test",
|
||||
"bankName":"Test Bank",
|
||||
"languageCode":"en"
|
||||
}
|
10
examples/config/config.production.json
Normal file
10
examples/config/config.production.json
Normal file
@ -0,0 +1,10 @@
|
||||
{
|
||||
"serverAddress": "https://ebics.server",
|
||||
"partnerId": "EBICS ParnerID Production",
|
||||
"userId": "MyUserIdProduction",
|
||||
"hostId": "MyHostIdProduction",
|
||||
"passphrase": "MyPasswordProduction",
|
||||
"keyStorage": "./keys-prod",
|
||||
"bankName":"Production Bank",
|
||||
"languageCode":"en"
|
||||
}
|
21
examples/getClient.js
Normal file
21
examples/getClient.js
Normal file
@ -0,0 +1,21 @@
|
||||
'use strict';
|
||||
|
||||
const { Client, fsKeysStorage } = require('../index');
|
||||
|
||||
const loadConfig = require('./loadConfig');
|
||||
|
||||
module.exports = ({
|
||||
serverAddress,
|
||||
partnerId,
|
||||
userId,
|
||||
hostId,
|
||||
passphrase,
|
||||
keyStoragePath,
|
||||
} = loadConfig()) => new Client({
|
||||
serverAddress,
|
||||
partnerId,
|
||||
userId,
|
||||
hostId,
|
||||
passphrase,
|
||||
keyStorage: fsKeysStorage(keyStoragePath),
|
||||
});
|
35
examples/loadConfig.js
Normal file
35
examples/loadConfig.js
Normal file
@ -0,0 +1,35 @@
|
||||
'use strict';
|
||||
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
|
||||
const safeLoadJson = (file) => {
|
||||
if (!file)
|
||||
return {};
|
||||
|
||||
try {
|
||||
return JSON.parse(fs.readFileSync(file));
|
||||
} catch (e) {
|
||||
console.warn(`Couldn't load ${file} config file.`);
|
||||
return {};
|
||||
}
|
||||
}
|
||||
|
||||
const getDefaultEnv = () => {
|
||||
const [,,parArg] = process.argv;
|
||||
return parArg || process.env.NODE_ENV;
|
||||
}
|
||||
|
||||
const loadConfig = (configDirectory = path.join(__dirname, './config'), env = getDefaultEnv()) => {
|
||||
console.log(`Loading config form ${configDirectory} with env set to ${env}.`);
|
||||
|
||||
const baseConfigFile = path.join(configDirectory, 'config.json');
|
||||
const envConfigFile = env ? path.join(configDirectory, `config.${env}.json`) : null;
|
||||
|
||||
return {
|
||||
...safeLoadJson(baseConfigFile),
|
||||
...safeLoadJson(envConfigFile),
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = loadConfig();
|
@ -2,10 +2,7 @@
|
||||
|
||||
'use strict';
|
||||
|
||||
const ebics = require('../index');
|
||||
const configjs = require('./config.js');
|
||||
|
||||
const client = gClient;
|
||||
const client = require('./getClient')();
|
||||
|
||||
// Client keys must be already generated and send by letter.
|
||||
// The bank should have enabled the user
|
||||
|
@ -2,10 +2,7 @@
|
||||
|
||||
'use strict';
|
||||
|
||||
const ebics = require('../index');
|
||||
const configjs = require('./config.js');
|
||||
|
||||
const client = gClient;
|
||||
const client = require('./getClient')();
|
||||
|
||||
// The bank keys must have been already saved
|
||||
client.send(ebics.Orders.C52(null, null)) // startDate 'YYYY-MM-DD', endDate 'YYYY-MM-DD'
|
||||
|
@ -2,10 +2,7 @@
|
||||
|
||||
'use strict';
|
||||
|
||||
const ebics = require('../index');
|
||||
const configjs = require('./config.js');
|
||||
|
||||
const client = gClient;
|
||||
const client = require('./getClient')();
|
||||
|
||||
// The bank keys must have been already saved
|
||||
client.send(ebics.Orders.C53(null, null)) // startDate 'YYYY-MM-DD', endDate 'YYYY-MM-DD'
|
||||
|
@ -2,10 +2,7 @@
|
||||
|
||||
'use strict';
|
||||
|
||||
const ebics = require('../index');
|
||||
const configjs = require('./config.js');
|
||||
|
||||
const client = gClient;
|
||||
const client = require('./getClient')();
|
||||
|
||||
// The bank keys must have been already saved
|
||||
client.send(ebics.Orders.DKI(null, null)) // startDate 'YYYY-MM-DD', endDate 'YYYY-MM-DD'
|
||||
|
@ -2,10 +2,7 @@
|
||||
|
||||
'use strict';
|
||||
|
||||
const ebics = require('../index');
|
||||
const configjs = require('./config.js');
|
||||
|
||||
const client = gClient;
|
||||
const client = require('./getClient')();
|
||||
|
||||
// The bank keys must have been already saved
|
||||
client.send(ebics.Orders.HKD)
|
||||
|
@ -2,10 +2,7 @@
|
||||
|
||||
'use strict';
|
||||
|
||||
const ebics = require('../index');
|
||||
const configjs = require('./config.js');
|
||||
|
||||
const client = gClient;
|
||||
const client = require('./getClient')();
|
||||
|
||||
// The bank keys must have been already saved
|
||||
client.send(ebics.Orders.HTD)
|
||||
|
@ -2,10 +2,7 @@
|
||||
|
||||
'use strict';
|
||||
|
||||
const ebics = require('../index');
|
||||
const configjs = require('./config.js');
|
||||
|
||||
const client = gClient;
|
||||
const client = require('./getClient')();
|
||||
|
||||
// The bank keys must have been already saved
|
||||
client.send(ebics.Orders.STA(null, null)) // startDate 'YYYY-MM-DD', endDate 'YYYY-MM-DD'
|
||||
|
@ -2,10 +2,7 @@
|
||||
|
||||
'use strict';
|
||||
|
||||
const ebics = require('../index');
|
||||
const configjs = require('./config.js');
|
||||
|
||||
const client = gClient;
|
||||
const client = require('./getClient')();
|
||||
|
||||
// The bank keys must have been already saved
|
||||
client.send(ebics.Orders.VMK(null, null)) // startDate 'YYYY-MM-DD', endDate 'YYYY-MM-DD'
|
||||
|
@ -5,14 +5,7 @@
|
||||
const ebics = require('../index');
|
||||
const fs = require('fs');
|
||||
|
||||
const client = new ebics.Client({
|
||||
url: 'https://ebics.server',
|
||||
partnerId: '',
|
||||
userId: '',
|
||||
hostId: '',
|
||||
passphrase: 'test', // keys-test will be decrypted with this passphrase
|
||||
keyStorage: ebics.fsKeysStorage('./keys-test'),
|
||||
});
|
||||
const client = require('./getClient')();
|
||||
|
||||
// The bank keys must have been already saved
|
||||
const paymentFile = fs.readFileSync('mytestfile.xml').toString();
|
||||
|
Loading…
Reference in New Issue
Block a user