mirror of
https://github.com/node-ebics/node-ebics-client.git
synced 2025-09-15 21:25:07 +00:00
chore(download): Add support for segmented download
This commit is contained in:
@@ -22,6 +22,7 @@ const lastChild = (node) => {
|
||||
module.exports = (xml, keys) => ({
|
||||
keys,
|
||||
doc: new DOMParser().parseFromString(xml, 'text/xml'),
|
||||
obtainedTransactionKey: null,
|
||||
|
||||
isSegmented() {
|
||||
const select = xpath.useNamespaces({ xmlns: 'urn:org:ebics:H004' });
|
||||
@@ -30,6 +31,13 @@ module.exports = (xml, keys) => ({
|
||||
return !!node.length;
|
||||
},
|
||||
|
||||
segmentNumber() {
|
||||
const select = xpath.useNamespaces({ xmlns: 'urn:org:ebics:H004' });
|
||||
const node = select('//xmlns:header/xmlns:mutable/xmlns:SegmentNumber', this.doc);
|
||||
|
||||
return node.length ? Number.parseInt(node[0].textContent, 10) : null;
|
||||
},
|
||||
|
||||
isLastSegment() {
|
||||
const select = xpath.useNamespaces({ xmlns: 'urn:org:ebics:H004' });
|
||||
const node = select("//xmlns:header/xmlns:mutable/*[@lastSegment='true']", this.doc);
|
||||
@@ -40,7 +48,7 @@ module.exports = (xml, keys) => ({
|
||||
orderData() {
|
||||
const orderDataNode = this.doc.getElementsByTagNameNS('urn:org:ebics:H004', 'OrderData');
|
||||
|
||||
if (!orderDataNode.length) return {};
|
||||
if (!orderDataNode.length) return null;
|
||||
|
||||
const orderData = orderDataNode[0].textContent;
|
||||
const decipher = crypto.createDecipheriv('aes-128-cbc', this.transactionKey(), DEFAULT_IV).setAutoPadding(false);
|
||||
@@ -50,6 +58,7 @@ module.exports = (xml, keys) => ({
|
||||
},
|
||||
|
||||
transactionKey() {
|
||||
if (this.obtainedTransactionKey) return this.obtainedTransactionKey;
|
||||
const keyNodeText = this.doc.getElementsByTagNameNS('urn:org:ebics:H004', 'TransactionKey')[0].textContent;
|
||||
return Crypto.privateDecrypt(this.keys.e(), Buffer.from(keyNodeText, 'base64'));
|
||||
},
|
||||
|
@@ -13,7 +13,7 @@ module.exports = {
|
||||
userId: client.userId,
|
||||
hostId: client.hostId,
|
||||
};
|
||||
const { orderDetails, transactionId } = order;
|
||||
const { orderDetails, transactionId, segmentNumber } = order;
|
||||
const {
|
||||
rootName, xmlOptions, xmlSchema, receipt, transfer, productString,
|
||||
} = genericSerializer(client.hostId, transactionId);
|
||||
@@ -25,35 +25,46 @@ module.exports = {
|
||||
this.receipt = receipt;
|
||||
this.transfer = transfer;
|
||||
|
||||
if (transactionId) return this.receipt();
|
||||
if (!segmentNumber && transactionId) return this.receipt();
|
||||
|
||||
this.xmlSchema.header = {
|
||||
'@': { authenticate: true },
|
||||
static: {
|
||||
HostID: ebicsAccount.hostId,
|
||||
Nonce: Crypto.nonce(),
|
||||
Timestamp: Crypto.timestamp(),
|
||||
PartnerID: ebicsAccount.partnerId,
|
||||
UserID: ebicsAccount.userId,
|
||||
Product: {
|
||||
'@': { Language: 'en' },
|
||||
'#': productString,
|
||||
},
|
||||
OrderDetails: orderDetails,
|
||||
BankPubKeyDigests: {
|
||||
Authentication: {
|
||||
'@': { Version: 'X002', Algorithm: 'http://www.w3.org/2001/04/xmlenc#sha256' },
|
||||
'#': Crypto.digestPublicKey(keys.bankX()),
|
||||
...!transactionId && {
|
||||
Nonce: Crypto.nonce(),
|
||||
Timestamp: Crypto.timestamp(),
|
||||
PartnerID: ebicsAccount.partnerId,
|
||||
UserID: ebicsAccount.userId,
|
||||
Product: {
|
||||
'@': { Language: 'en' },
|
||||
'#': productString,
|
||||
},
|
||||
Encryption: {
|
||||
'@': { Version: 'E002', Algorithm: 'http://www.w3.org/2001/04/xmlenc#sha256' },
|
||||
'#': Crypto.digestPublicKey(keys.bankE()),
|
||||
OrderDetails: orderDetails,
|
||||
BankPubKeyDigests: {
|
||||
Authentication: {
|
||||
'@': { Version: 'X002', Algorithm: 'http://www.w3.org/2001/04/xmlenc#sha256' },
|
||||
'#': Crypto.digestPublicKey(keys.bankX()),
|
||||
},
|
||||
Encryption: {
|
||||
'@': { Version: 'E002', Algorithm: 'http://www.w3.org/2001/04/xmlenc#sha256' },
|
||||
'#': Crypto.digestPublicKey(keys.bankE()),
|
||||
},
|
||||
},
|
||||
SecurityMedium: '0000',
|
||||
},
|
||||
...transactionId && {
|
||||
TransactionID: transactionId,
|
||||
},
|
||||
SecurityMedium: '0000',
|
||||
},
|
||||
mutable: {
|
||||
TransactionPhase: 'Initialisation',
|
||||
TransactionPhase: segmentNumber ? 'Transfer' : 'Initialisation',
|
||||
...segmentNumber && {
|
||||
SegmentNumber: {
|
||||
'@': { lastSegment: false },
|
||||
'#': segmentNumber,
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
|
Reference in New Issue
Block a user