mirror of
https://github.com/n8n-io/n8n.git
synced 2024-12-26 05:04:05 -08:00
feat(Wise Node): Add Support to download statements as JSON, CSV or PDF (#3468)
This commit is contained in:
parent
7346da0b34
commit
51663c1fcb
|
@ -58,6 +58,10 @@ export async function wiseApiRequest(
|
||||||
delete options.qs;
|
delete options.qs;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (option.encoding) {
|
||||||
|
delete options.json;
|
||||||
|
}
|
||||||
|
|
||||||
if (Object.keys(option)) {
|
if (Object.keys(option)) {
|
||||||
Object.assign(options, option);
|
Object.assign(options, option);
|
||||||
}
|
}
|
||||||
|
@ -112,26 +116,6 @@ export async function wiseApiRequest(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Populate the binary property of node items with binary data for a PDF file.
|
|
||||||
*/
|
|
||||||
export async function handleBinaryData(
|
|
||||||
this: IExecuteFunctions,
|
|
||||||
items: INodeExecutionData[],
|
|
||||||
i: number,
|
|
||||||
endpoint: string,
|
|
||||||
) {
|
|
||||||
const data = await wiseApiRequest.call(this, 'GET', endpoint, {}, {}, { encoding: null });
|
|
||||||
const binaryProperty = this.getNodeParameter('binaryProperty', i) as string;
|
|
||||||
|
|
||||||
items[i].binary = items[i].binary ?? {};
|
|
||||||
items[i].binary![binaryProperty] = await this.helpers.prepareBinaryData(data);
|
|
||||||
items[i].binary![binaryProperty].fileName = this.getNodeParameter('fileName', i) as string;
|
|
||||||
items[i].binary![binaryProperty].fileExtension = 'pdf';
|
|
||||||
|
|
||||||
return items;
|
|
||||||
}
|
|
||||||
|
|
||||||
export function getTriggerName(eventName: string) {
|
export function getTriggerName(eventName: string) {
|
||||||
const events: IDataObject = {
|
const events: IDataObject = {
|
||||||
'tranferStateChange': 'transfers#state-change',
|
'tranferStateChange': 'transfers#state-change',
|
||||||
|
|
|
@ -28,7 +28,6 @@ import {
|
||||||
import {
|
import {
|
||||||
BorderlessAccount,
|
BorderlessAccount,
|
||||||
ExchangeRateAdditionalFields,
|
ExchangeRateAdditionalFields,
|
||||||
handleBinaryData,
|
|
||||||
Profile,
|
Profile,
|
||||||
Recipient,
|
Recipient,
|
||||||
StatementAdditionalFields,
|
StatementAdditionalFields,
|
||||||
|
@ -175,7 +174,7 @@ export class Wise implements INodeType {
|
||||||
|
|
||||||
let responseData;
|
let responseData;
|
||||||
const returnData: IDataObject[] = [];
|
const returnData: IDataObject[] = [];
|
||||||
let downloadReceipt = false;
|
let binaryOutput = false;
|
||||||
|
|
||||||
for (let i = 0; i < items.length; i++) {
|
for (let i = 0; i < items.length; i++) {
|
||||||
|
|
||||||
|
@ -221,7 +220,8 @@ export class Wise implements INodeType {
|
||||||
|
|
||||||
const profileId = this.getNodeParameter('profileId', i);
|
const profileId = this.getNodeParameter('profileId', i);
|
||||||
const borderlessAccountId = this.getNodeParameter('borderlessAccountId', i);
|
const borderlessAccountId = this.getNodeParameter('borderlessAccountId', i);
|
||||||
const endpoint = `v3/profiles/${profileId}/borderless-accounts/${borderlessAccountId}/statement.json`;
|
const format = this.getNodeParameter('format', i) as 'json' | 'csv' | 'pdf';
|
||||||
|
const endpoint = `v3/profiles/${profileId}/borderless-accounts/${borderlessAccountId}/statement.${format}`;
|
||||||
|
|
||||||
const qs = {
|
const qs = {
|
||||||
currency: this.getNodeParameter('currency', i),
|
currency: this.getNodeParameter('currency', i),
|
||||||
|
@ -241,8 +241,19 @@ export class Wise implements INodeType {
|
||||||
qs.intervalEnd = moment().utc().format();
|
qs.intervalEnd = moment().utc().format();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (format === 'json') {
|
||||||
responseData = await wiseApiRequest.call(this, 'GET', endpoint, {}, qs);
|
responseData = await wiseApiRequest.call(this, 'GET', endpoint, {}, qs);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
const data = await wiseApiRequest.call(this, 'GET', endpoint, {}, qs, {encoding: 'arraybuffer'});
|
||||||
|
const binaryProperty = this.getNodeParameter('binaryProperty', i) as string;
|
||||||
|
|
||||||
|
items[i].binary = items[i].binary ?? {};
|
||||||
|
items[i].binary![binaryProperty] = await this.helpers.prepareBinaryData(data, this.getNodeParameter('fileName', i) as string);
|
||||||
|
|
||||||
|
responseData = items;
|
||||||
|
binaryOutput = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
} else if (resource === 'exchangeRate') {
|
} else if (resource === 'exchangeRate') {
|
||||||
|
@ -454,14 +465,20 @@ export class Wise implements INodeType {
|
||||||
// ----------------------------------
|
// ----------------------------------
|
||||||
|
|
||||||
const transferId = this.getNodeParameter('transferId', i);
|
const transferId = this.getNodeParameter('transferId', i);
|
||||||
downloadReceipt = this.getNodeParameter('downloadReceipt', i) as boolean;
|
const downloadReceipt = this.getNodeParameter('downloadReceipt', i) as boolean;
|
||||||
|
|
||||||
if (downloadReceipt) {
|
if (downloadReceipt) {
|
||||||
|
|
||||||
// https://api-docs.transferwise.com/#transfers-get-receipt-pdf
|
// https://api-docs.transferwise.com/#transfers-get-receipt-pdf
|
||||||
|
|
||||||
responseData = await handleBinaryData.call(this, items, i, `v1/transfers/${transferId}/receipt.pdf`);
|
const data = await wiseApiRequest.call(this, 'GET', `v1/transfers/${transferId}/receipt.pdf`, {}, {}, {encoding: 'arraybuffer'});
|
||||||
|
const binaryProperty = this.getNodeParameter('binaryProperty', i) as string;
|
||||||
|
|
||||||
|
items[i].binary = items[i].binary ?? {};
|
||||||
|
items[i].binary![binaryProperty] = await this.helpers.prepareBinaryData(data, this.getNodeParameter('fileName', i) as string);
|
||||||
|
|
||||||
|
responseData = items;
|
||||||
|
binaryOutput = true;
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
// https://api-docs.transferwise.com/#transfers-get-by-id
|
// https://api-docs.transferwise.com/#transfers-get-by-id
|
||||||
|
@ -518,7 +535,7 @@ export class Wise implements INodeType {
|
||||||
: returnData.push(responseData);
|
: returnData.push(responseData);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (downloadReceipt && responseData !== undefined) {
|
if (binaryOutput && responseData !== undefined) {
|
||||||
return this.prepareOutputData(responseData);
|
return this.prepareOutputData(responseData);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -127,6 +127,82 @@ export const accountFields: INodeProperties[] = [
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
displayName: 'Format',
|
||||||
|
name: 'format',
|
||||||
|
type: 'options',
|
||||||
|
default: 'json',
|
||||||
|
description: 'File format to retrieve the statement in',
|
||||||
|
displayOptions: {
|
||||||
|
show: {
|
||||||
|
resource: [
|
||||||
|
'account',
|
||||||
|
],
|
||||||
|
operation: [
|
||||||
|
'getStatement',
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
options: [
|
||||||
|
{
|
||||||
|
name: 'JSON',
|
||||||
|
value: 'json',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'CSV',
|
||||||
|
value: 'csv',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'PDF',
|
||||||
|
value: 'pdf',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
displayName: 'Binary Property',
|
||||||
|
name: 'binaryProperty',
|
||||||
|
type: 'string',
|
||||||
|
required: true,
|
||||||
|
default: 'data',
|
||||||
|
description: 'Name of the binary property to which to write to',
|
||||||
|
displayOptions: {
|
||||||
|
show: {
|
||||||
|
resource: [
|
||||||
|
'account',
|
||||||
|
],
|
||||||
|
operation: [
|
||||||
|
'getStatement',
|
||||||
|
],
|
||||||
|
format: [
|
||||||
|
'csv',
|
||||||
|
'pdf',
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
displayName: 'File Name',
|
||||||
|
name: 'fileName',
|
||||||
|
type: 'string',
|
||||||
|
required: true,
|
||||||
|
default: '',
|
||||||
|
placeholder: 'data.pdf',
|
||||||
|
description: 'Name of the file that will be downloaded',
|
||||||
|
displayOptions: {
|
||||||
|
show: {
|
||||||
|
resource: [
|
||||||
|
'account',
|
||||||
|
],
|
||||||
|
operation: [
|
||||||
|
'getStatement',
|
||||||
|
],
|
||||||
|
format: [
|
||||||
|
'csv',
|
||||||
|
'pdf',
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
{
|
{
|
||||||
displayName: 'Additional Fields',
|
displayName: 'Additional Fields',
|
||||||
name: 'additionalFields',
|
name: 'additionalFields',
|
||||||
|
|
Loading…
Reference in a new issue