diff --git a/index.js b/index.js index eab7ec5..f90a594 100644 --- a/index.js +++ b/index.js @@ -1,9 +1,11 @@ 'use strict'; const Client = require('./lib/Client'); +const Orders = require('./lib/predefinedOrders'); const fsKeysStorage = require('./lib/storages/fsKeysStorage'); module.exports = { Client, + Orders, fsKeysStorage, }; diff --git a/lib/Client.js b/lib/Client.js index b173c71..b0fa455 100644 --- a/lib/Client.js +++ b/lib/Client.js @@ -107,22 +107,6 @@ module.exports = class Client { }); } - ini(order) { - return this.initialization(order); - } - - payment(order) { - return this.upload(order); - } - - statement(order) { - return this.download(order); - } - - status(order) { - return this.download(order); - } - keys() { const keysString = this.keyStorage.read(); diff --git a/lib/keymanagers/KeysManager.js b/lib/keymanagers/KeysManager.js index b9488ae..e82c724 100644 --- a/lib/keymanagers/KeysManager.js +++ b/lib/keymanagers/KeysManager.js @@ -47,7 +47,7 @@ module.exports = (keysStorage, passphrase, algorithm = 'aes-256-cbc') => { return key; }); - storage.save(encrypt(JSON.stringify(keysObject), algo, pass)); + storage.write(encrypt(JSON.stringify(keysObject), algo, pass)); return this; }, diff --git a/lib/predefinedOrders/AZV.js b/lib/predefinedOrders/AZV.js new file mode 100644 index 0000000..64074d8 --- /dev/null +++ b/lib/predefinedOrders/AZV.js @@ -0,0 +1,8 @@ +'use strict'; + +module.exports = document => ({ + version: 'h004', + orderDetails: { OrderType: 'AZV', OrderAttribute: 'OZHNN', StandardOrderParams: {} }, + operation: 'upload', + document, +}); diff --git a/lib/predefinedOrders/CCS.js b/lib/predefinedOrders/CCS.js new file mode 100644 index 0000000..ef9d54a --- /dev/null +++ b/lib/predefinedOrders/CCS.js @@ -0,0 +1,8 @@ +'use strict'; + +module.exports = document => ({ + version: 'h004', + orderDetails: { OrderType: 'CCS', OrderAttribute: 'OZHNN', StandardOrderParams: {} }, + operation: 'upload', + document, +}); diff --git a/lib/predefinedOrders/CCT.js b/lib/predefinedOrders/CCT.js new file mode 100644 index 0000000..bfafae6 --- /dev/null +++ b/lib/predefinedOrders/CCT.js @@ -0,0 +1,8 @@ +'use strict'; + +module.exports = document => ({ + version: 'h004', + orderDetails: { OrderType: 'CCT', OrderAttribute: 'OZHNN', StandardOrderParams: {} }, + operation: 'upload', + document, +}); diff --git a/lib/predefinedOrders/CD1.js b/lib/predefinedOrders/CD1.js new file mode 100644 index 0000000..2a353a0 --- /dev/null +++ b/lib/predefinedOrders/CD1.js @@ -0,0 +1,8 @@ +'use strict'; + +module.exports = document => ({ + version: 'h004', + orderDetails: { OrderType: 'CD1', OrderAttribute: 'OZHNN', StandardOrderParams: {} }, + operation: 'upload', + document, +}); diff --git a/lib/predefinedOrders/CDB.js b/lib/predefinedOrders/CDB.js new file mode 100644 index 0000000..989e068 --- /dev/null +++ b/lib/predefinedOrders/CDB.js @@ -0,0 +1,8 @@ +'use strict'; + +module.exports = document => ({ + version: 'h004', + orderDetails: { OrderType: 'CDB', OrderAttribute: 'OZHNN', StandardOrderParams: {} }, + operation: 'upload', + document, +}); diff --git a/lib/predefinedOrders/CDD.js b/lib/predefinedOrders/CDD.js new file mode 100644 index 0000000..a2ca793 --- /dev/null +++ b/lib/predefinedOrders/CDD.js @@ -0,0 +1,8 @@ +'use strict'; + +module.exports = document => ({ + version: 'h004', + orderDetails: { OrderType: 'CDD', OrderAttribute: 'OZHNN', StandardOrderParams: {} }, + operation: 'upload', + document, +}); diff --git a/lib/predefinedOrders/CDS.js b/lib/predefinedOrders/CDS.js new file mode 100644 index 0000000..530d48e --- /dev/null +++ b/lib/predefinedOrders/CDS.js @@ -0,0 +1,8 @@ +'use strict'; + +module.exports = document => ({ + version: 'h004', + orderDetails: { OrderType: 'CDS', OrderAttribute: 'OZHNN', StandardOrderParams: {} }, + operation: 'upload', + document, +}); diff --git a/lib/predefinedOrders/HAA.js b/lib/predefinedOrders/HAA.js new file mode 100644 index 0000000..82fe0cb --- /dev/null +++ b/lib/predefinedOrders/HAA.js @@ -0,0 +1,11 @@ +'use strict'; + +module.exports = { + version: 'h004', + orderDetails: { + OrderType: 'HAA', + OrderAttribute: 'DZHNN', + StandardOrderParams: {}, + }, + operation: 'download', +}; diff --git a/lib/predefinedOrders/HAC.js b/lib/predefinedOrders/HAC.js new file mode 100644 index 0000000..7700379 --- /dev/null +++ b/lib/predefinedOrders/HAC.js @@ -0,0 +1,23 @@ +'use strict'; + +const dateRange = (start, end) => { + if (start && end) + return { + DateRange: { + Start: start, + End: end, + }, + }; + + return {}; +}; + +module.exports = (start = null, end = null) => ({ + version: 'h004', + orderDetails: { + OrderType: 'HAC', + OrderAttribute: 'DZHNN', + StandardOrderParams: dateRange(start, end), + }, + operation: 'download', +}); diff --git a/lib/predefinedOrders/HIA.js b/lib/predefinedOrders/HIA.js new file mode 100644 index 0000000..3fa8cc6 --- /dev/null +++ b/lib/predefinedOrders/HIA.js @@ -0,0 +1,7 @@ +'use strict'; + +module.exports = { + version: 'h004', + orderDetails: { OrderType: 'HIA', OrderAttribute: 'DZNNN' }, + operation: 'ini', +}; diff --git a/lib/predefinedOrders/HKD.js b/lib/predefinedOrders/HKD.js new file mode 100644 index 0000000..95db15a --- /dev/null +++ b/lib/predefinedOrders/HKD.js @@ -0,0 +1,11 @@ +'use strict'; + +module.exports = { + version: 'h004', + orderDetails: { + OrderType: 'HKD', + OrderAttribute: 'DZHNN', + StandardOrderParams: {}, + }, + operation: 'download', +}; diff --git a/lib/predefinedOrders/HPB.js b/lib/predefinedOrders/HPB.js new file mode 100644 index 0000000..439b8fc --- /dev/null +++ b/lib/predefinedOrders/HPB.js @@ -0,0 +1,7 @@ +'use strict'; + +module.exports = { + version: 'h004', + orderDetails: { OrderType: 'HPB', OrderAttribute: 'DZHNN' }, + operation: 'ini', +}; diff --git a/lib/predefinedOrders/HPD.js b/lib/predefinedOrders/HPD.js new file mode 100644 index 0000000..962f9f6 --- /dev/null +++ b/lib/predefinedOrders/HPD.js @@ -0,0 +1,11 @@ +'use strict'; + +module.exports = { + version: 'h004', + orderDetails: { + OrderType: 'HPD', + OrderAttribute: 'DZHNN', + StandardOrderParams: {}, + }, + operation: 'download', +}; diff --git a/lib/predefinedOrders/HTD.js b/lib/predefinedOrders/HTD.js new file mode 100644 index 0000000..cb9cf28 --- /dev/null +++ b/lib/predefinedOrders/HTD.js @@ -0,0 +1,11 @@ +'use strict'; + +module.exports = { + version: 'h004', + orderDetails: { + OrderType: 'HTD', + OrderAttribute: 'DZHNN', + StandardOrderParams: {}, + }, + operation: 'download', +}; diff --git a/lib/predefinedOrders/INI.js b/lib/predefinedOrders/INI.js new file mode 100644 index 0000000..f777b73 --- /dev/null +++ b/lib/predefinedOrders/INI.js @@ -0,0 +1,7 @@ +'use strict'; + +module.exports = { + version: 'h004', + orderDetails: { OrderType: 'INI', OrderAttribute: 'DZNNN' }, + operation: 'ini', +}; diff --git a/lib/predefinedOrders/PTK.js b/lib/predefinedOrders/PTK.js new file mode 100644 index 0000000..37d5667 --- /dev/null +++ b/lib/predefinedOrders/PTK.js @@ -0,0 +1,23 @@ +'use strict'; + +const dateRange = (start, end) => { + if (start && end) + return { + DateRange: { + Start: start, + End: end, + }, + }; + + return {}; +}; + +module.exports = (start = null, end = null) => ({ + version: 'h004', + orderDetails: { + OrderType: 'PTK', + OrderAttribute: 'DZHNN', + StandardOrderParams: dateRange(start, end), + }, + operation: 'download', +}); diff --git a/lib/predefinedOrders/STA.js b/lib/predefinedOrders/STA.js new file mode 100644 index 0000000..1a0b39e --- /dev/null +++ b/lib/predefinedOrders/STA.js @@ -0,0 +1,23 @@ +'use strict'; + +const dateRange = (start, end) => { + if (start && end) + return { + DateRange: { + Start: start, + End: end, + }, + }; + + return {}; +}; + +module.exports = (start = null, end = null) => ({ + version: 'h004', + orderDetails: { + OrderType: 'STA', + OrderAttribute: 'DZHNN', + StandardOrderParams: dateRange(start, end), + }, + operation: 'download', +}); diff --git a/lib/predefinedOrders/VMK.js b/lib/predefinedOrders/VMK.js new file mode 100644 index 0000000..e2bcc9b --- /dev/null +++ b/lib/predefinedOrders/VMK.js @@ -0,0 +1,23 @@ +'use strict'; + +const dateRange = (start, end) => { + if (start && end) + return { + DateRange: { + Start: start, + End: end, + }, + }; + + return {}; +}; + +module.exports = (start = null, end = null) => ({ + version: 'h004', + orderDetails: { + OrderType: 'VMK', + OrderAttribute: 'DZHNN', + StandardOrderParams: dateRange(start, end), + }, + operation: 'download', +}); diff --git a/lib/predefinedOrders/XE3.js b/lib/predefinedOrders/XE3.js new file mode 100644 index 0000000..823948e --- /dev/null +++ b/lib/predefinedOrders/XE3.js @@ -0,0 +1,8 @@ +'use strict'; + +module.exports = document => ({ + version: 'h004', + orderDetails: { OrderType: 'XE3', OrderAttribute: 'OZHNN', StandardOrderParams: {} }, + operation: 'upload', + document, +}); diff --git a/lib/predefinedOrders/index.js b/lib/predefinedOrders/index.js new file mode 100644 index 0000000..3ebc4b2 --- /dev/null +++ b/lib/predefinedOrders/index.js @@ -0,0 +1,47 @@ +'use strict'; + +const INI = require('./INI'); +const HIA = require('./HIA'); +const HPB = require('./HPB'); + +const AZV = require('./AZV'); +const CD1 = require('./CD1'); +const CDB = require('./CDB'); +const CDD = require('./CDD'); +const CDS = require('./CDS'); +const CCT = require('./CCT'); +const CCS = require('./CCS'); +const XE3 = require('./XE3'); + +const STA = require('./STA'); +const VMK = require('./VMK'); +const HAA = require('./HAA'); +const HTD = require('./HTD'); +const HPD = require('./HPD'); +const HKD = require('./HKD'); +const PTK = require('./PTK'); +const HAC = require('./HAC'); + +module.exports = { + INI, + HIA, + HPB, + + AZV, + CD1, + CDB, + CDD, + CDS, + CCT, + CCS, + XE3, + + STA, + VMK, + HAA, + HTD, + HPD, + HKD, + PTK, + HAC, +};