- Change back from PNG to SVG for better n8n compatibility - Update SVG icon with larger viewBox and Strike green color (#00D924) - Improve lightning bolt design for better visibility 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
484 lines
25 KiB
JavaScript
484 lines
25 KiB
JavaScript
"use strict";
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
exports.Strike = void 0;
|
|
const StrikeApi_1 = require("./StrikeApi");
|
|
const descriptions_1 = require("./descriptions");
|
|
class Strike {
|
|
constructor() {
|
|
this.description = {
|
|
displayName: 'Strike',
|
|
name: 'strike',
|
|
icon: 'file:strike.svg',
|
|
group: ['transform'],
|
|
version: 1,
|
|
subtitle: '={{$parameter["operation"] + ": " + $parameter["resource"]}}',
|
|
description: 'Interact with Strike API for Bitcoin and Lightning payments',
|
|
defaults: {
|
|
name: 'Strike',
|
|
},
|
|
inputs: ['main'],
|
|
outputs: ['main'],
|
|
credentials: [
|
|
{
|
|
name: 'strikeApi',
|
|
required: true,
|
|
},
|
|
],
|
|
properties: [
|
|
{
|
|
displayName: 'Resource',
|
|
name: 'resource',
|
|
type: 'options',
|
|
noDataExpression: true,
|
|
options: [
|
|
{
|
|
name: 'Account',
|
|
value: 'account',
|
|
},
|
|
{
|
|
name: 'Balance',
|
|
value: 'balance',
|
|
},
|
|
{
|
|
name: 'Currency Exchange',
|
|
value: 'currencyExchange',
|
|
},
|
|
{
|
|
name: 'Deposit',
|
|
value: 'deposit',
|
|
},
|
|
{
|
|
name: 'Event',
|
|
value: 'event',
|
|
},
|
|
{
|
|
name: 'Invoice',
|
|
value: 'invoice',
|
|
},
|
|
{
|
|
name: 'Payment',
|
|
value: 'payment',
|
|
},
|
|
{
|
|
name: 'Payment Method',
|
|
value: 'paymentMethod',
|
|
},
|
|
{
|
|
name: 'Payout',
|
|
value: 'payout',
|
|
},
|
|
{
|
|
name: 'Rates',
|
|
value: 'rates',
|
|
},
|
|
],
|
|
default: 'balance',
|
|
},
|
|
// Operations and fields for each resource
|
|
...descriptions_1.accountOperations,
|
|
...descriptions_1.accountFields,
|
|
...descriptions_1.balanceOperations,
|
|
...descriptions_1.balanceFields,
|
|
...descriptions_1.currencyExchangeOperations,
|
|
...descriptions_1.currencyExchangeFields,
|
|
...descriptions_1.depositOperations,
|
|
...descriptions_1.depositFields,
|
|
...descriptions_1.eventOperations,
|
|
...descriptions_1.eventFields,
|
|
...descriptions_1.invoiceOperations,
|
|
...descriptions_1.invoiceFields,
|
|
...descriptions_1.paymentOperations,
|
|
...descriptions_1.paymentFields,
|
|
...descriptions_1.paymentMethodOperations,
|
|
...descriptions_1.paymentMethodFields,
|
|
...descriptions_1.payoutOperations,
|
|
...descriptions_1.payoutFields,
|
|
...descriptions_1.ratesOperations,
|
|
...descriptions_1.ratesFields,
|
|
],
|
|
};
|
|
}
|
|
async execute() {
|
|
const items = this.getInputData();
|
|
const returnData = [];
|
|
const resource = this.getNodeParameter('resource', 0);
|
|
const operation = this.getNodeParameter('operation', 0);
|
|
for (let i = 0; i < items.length; i++) {
|
|
try {
|
|
let responseData;
|
|
// ----------------------------------------
|
|
// account
|
|
// ----------------------------------------
|
|
if (resource === 'account') {
|
|
if (operation === 'getProfile') {
|
|
const accountId = this.getNodeParameter('accountId', i);
|
|
responseData = await StrikeApi_1.strikeApiRequest.call(this, 'GET', `/accounts/${accountId}/profile`);
|
|
}
|
|
else if (operation === 'getProfileByHandle') {
|
|
const handle = this.getNodeParameter('handle', i);
|
|
responseData = await StrikeApi_1.strikeApiRequest.call(this, 'GET', `/accounts/handle/${handle}/profile`);
|
|
}
|
|
else if (operation === 'getLimits') {
|
|
responseData = await StrikeApi_1.strikeApiRequest.call(this, 'GET', '/accounts/limits');
|
|
}
|
|
}
|
|
// ----------------------------------------
|
|
// balance
|
|
// ----------------------------------------
|
|
if (resource === 'balance') {
|
|
if (operation === 'get') {
|
|
responseData = await StrikeApi_1.strikeApiRequest.call(this, 'GET', '/balances');
|
|
}
|
|
}
|
|
// ----------------------------------------
|
|
// currencyExchange
|
|
// ----------------------------------------
|
|
if (resource === 'currencyExchange') {
|
|
if (operation === 'createQuote') {
|
|
const sell = this.getNodeParameter('sell', i);
|
|
const buy = this.getNodeParameter('buy', i);
|
|
const amount = this.getNodeParameter('amount', i);
|
|
const amountCurrency = this.getNodeParameter('amountCurrency', i);
|
|
const body = {
|
|
sell,
|
|
buy,
|
|
amount: {
|
|
amount: amount.toString(),
|
|
currency: amountCurrency === 'sell' ? sell : buy,
|
|
},
|
|
};
|
|
responseData = await StrikeApi_1.strikeApiRequest.call(this, 'POST', '/currency-exchange-quotes', body);
|
|
}
|
|
else if (operation === 'getQuote') {
|
|
const quoteId = this.getNodeParameter('quoteId', i);
|
|
responseData = await StrikeApi_1.strikeApiRequest.call(this, 'GET', `/currency-exchange-quotes/${quoteId}`);
|
|
}
|
|
else if (operation === 'executeQuote') {
|
|
const quoteId = this.getNodeParameter('quoteId', i);
|
|
responseData = await StrikeApi_1.strikeApiRequest.call(this, 'PATCH', `/currency-exchange-quotes/${quoteId}/execute`);
|
|
}
|
|
}
|
|
// ----------------------------------------
|
|
// event
|
|
// ----------------------------------------
|
|
if (resource === 'event') {
|
|
if (operation === 'get') {
|
|
const eventId = this.getNodeParameter('eventId', i);
|
|
responseData = await StrikeApi_1.strikeApiRequest.call(this, 'GET', `/events/${eventId}`);
|
|
}
|
|
else if (operation === 'getAll') {
|
|
const returnAll = this.getNodeParameter('returnAll', i);
|
|
const filters = this.getNodeParameter('filters', i);
|
|
const query = {};
|
|
if (filters.filter) {
|
|
query.$filter = filters.filter;
|
|
}
|
|
if (filters.orderBy) {
|
|
query.$orderby = filters.orderBy;
|
|
}
|
|
if (returnAll) {
|
|
responseData = await StrikeApi_1.strikeApiRequestAllItems.call(this, 'GET', '/events', {}, query);
|
|
}
|
|
else {
|
|
const limit = this.getNodeParameter('limit', i);
|
|
query.$top = limit;
|
|
responseData = await StrikeApi_1.strikeApiRequest.call(this, 'GET', '/events', {}, query);
|
|
responseData = responseData.items || responseData;
|
|
}
|
|
}
|
|
}
|
|
// ----------------------------------------
|
|
// deposit
|
|
// ----------------------------------------
|
|
if (resource === 'deposit') {
|
|
if (operation === 'create') {
|
|
const paymentMethodId = this.getNodeParameter('paymentMethodId', i);
|
|
const amount = this.getNodeParameter('amount', i);
|
|
const currency = this.getNodeParameter('currency', i);
|
|
const body = {
|
|
paymentMethodId,
|
|
amount: {
|
|
amount: amount.toString(),
|
|
currency,
|
|
},
|
|
};
|
|
responseData = await StrikeApi_1.strikeApiRequest.call(this, 'POST', '/deposits', body);
|
|
}
|
|
else if (operation === 'get') {
|
|
const depositId = this.getNodeParameter('depositId', i);
|
|
responseData = await StrikeApi_1.strikeApiRequest.call(this, 'GET', `/deposits/${depositId}`);
|
|
}
|
|
else if (operation === 'getAll') {
|
|
const returnAll = this.getNodeParameter('returnAll', i);
|
|
const filters = this.getNodeParameter('filters', i);
|
|
const query = {};
|
|
if (filters.filter) {
|
|
query.$filter = filters.filter;
|
|
}
|
|
if (filters.orderBy) {
|
|
query.$orderby = filters.orderBy;
|
|
}
|
|
if (returnAll) {
|
|
responseData = await StrikeApi_1.strikeApiRequestAllItems.call(this, 'GET', '/deposits', {}, query);
|
|
}
|
|
else {
|
|
const limit = this.getNodeParameter('limit', i);
|
|
query.$top = limit;
|
|
responseData = await StrikeApi_1.strikeApiRequest.call(this, 'GET', '/deposits', {}, query);
|
|
responseData = responseData.items || responseData;
|
|
}
|
|
}
|
|
else if (operation === 'estimateFee') {
|
|
const amount = this.getNodeParameter('amount', i);
|
|
const currency = this.getNodeParameter('currency', i);
|
|
const feePolicy = this.getNodeParameter('feePolicy', i);
|
|
const body = {
|
|
amount: {
|
|
amount: amount.toString(),
|
|
currency,
|
|
},
|
|
feePolicy,
|
|
};
|
|
responseData = await StrikeApi_1.strikeApiRequest.call(this, 'POST', '/deposits/fee', body);
|
|
}
|
|
}
|
|
// ----------------------------------------
|
|
// invoice
|
|
// ----------------------------------------
|
|
if (resource === 'invoice') {
|
|
if (operation === 'create') {
|
|
const correlationId = this.getNodeParameter('correlationId', i);
|
|
const description = this.getNodeParameter('description', i);
|
|
const amount = this.getNodeParameter('amount', i);
|
|
const currency = this.getNodeParameter('currency', i);
|
|
const body = {};
|
|
if (correlationId) {
|
|
body.correlationId = correlationId;
|
|
}
|
|
if (description) {
|
|
body.description = description;
|
|
}
|
|
if (amount > 0) {
|
|
body.amount = {
|
|
amount: amount.toString(),
|
|
currency,
|
|
};
|
|
}
|
|
responseData = await StrikeApi_1.strikeApiRequest.call(this, 'POST', '/invoices', body);
|
|
}
|
|
else if (operation === 'get') {
|
|
const invoiceId = this.getNodeParameter('invoiceId', i);
|
|
responseData = await StrikeApi_1.strikeApiRequest.call(this, 'GET', `/invoices/${invoiceId}`);
|
|
}
|
|
else if (operation === 'getAll') {
|
|
const returnAll = this.getNodeParameter('returnAll', i);
|
|
const filters = this.getNodeParameter('filters', i);
|
|
const query = {};
|
|
if (filters.filter) {
|
|
query.$filter = filters.filter;
|
|
}
|
|
if (filters.orderBy) {
|
|
query.$orderby = filters.orderBy;
|
|
}
|
|
if (returnAll) {
|
|
responseData = await StrikeApi_1.strikeApiRequestAllItems.call(this, 'GET', '/invoices', {}, query);
|
|
}
|
|
else {
|
|
const limit = this.getNodeParameter('limit', i);
|
|
query.$top = limit;
|
|
responseData = await StrikeApi_1.strikeApiRequest.call(this, 'GET', '/invoices', {}, query);
|
|
responseData = responseData.items || responseData;
|
|
}
|
|
}
|
|
else if (operation === 'createQuote') {
|
|
const invoiceId = this.getNodeParameter('invoiceId', i);
|
|
const descriptionHash = this.getNodeParameter('descriptionHash', i);
|
|
const body = {};
|
|
if (descriptionHash) {
|
|
body.descriptionHash = descriptionHash;
|
|
}
|
|
responseData = await StrikeApi_1.strikeApiRequest.call(this, 'POST', `/invoices/${invoiceId}/quote`, body);
|
|
}
|
|
else if (operation === 'cancel') {
|
|
const invoiceId = this.getNodeParameter('invoiceId', i);
|
|
responseData = await StrikeApi_1.strikeApiRequest.call(this, 'PATCH', `/invoices/${invoiceId}/cancel`);
|
|
}
|
|
}
|
|
// ----------------------------------------
|
|
// payment
|
|
// ----------------------------------------
|
|
if (resource === 'payment') {
|
|
if (operation === 'get') {
|
|
const paymentId = this.getNodeParameter('paymentId', i);
|
|
responseData = await StrikeApi_1.strikeApiRequest.call(this, 'GET', `/payments/${paymentId}`);
|
|
}
|
|
else if (operation === 'createLightningQuote') {
|
|
const lnInvoice = this.getNodeParameter('lnInvoice', i);
|
|
const sourceCurrency = this.getNodeParameter('sourceCurrency', i);
|
|
const body = {
|
|
lnInvoice,
|
|
sourceCurrency,
|
|
};
|
|
responseData = await StrikeApi_1.strikeApiRequest.call(this, 'POST', '/payment-quotes/lightning', body);
|
|
}
|
|
else if (operation === 'createOnchainQuote') {
|
|
const btcAddress = this.getNodeParameter('btcAddress', i);
|
|
const sourceCurrency = this.getNodeParameter('sourceCurrency', i);
|
|
const amount = this.getNodeParameter('amount', i);
|
|
const amountCurrency = this.getNodeParameter('amountCurrency', i);
|
|
const body = {
|
|
btcAddress,
|
|
sourceCurrency,
|
|
amount: {
|
|
amount: amount.toString(),
|
|
currency: amountCurrency,
|
|
},
|
|
};
|
|
responseData = await StrikeApi_1.strikeApiRequest.call(this, 'POST', '/payment-quotes/onchain', body);
|
|
}
|
|
else if (operation === 'createLnurlQuote') {
|
|
const lnAddressOrUrl = this.getNodeParameter('lnAddressOrUrl', i);
|
|
const amount = this.getNodeParameter('amount', i);
|
|
const amountCurrency = this.getNodeParameter('amountCurrency', i);
|
|
const sourceCurrency = this.getNodeParameter('sourceCurrency', i);
|
|
const body = {
|
|
lnAddressOrUrl,
|
|
sourceCurrency,
|
|
amount: {
|
|
amount: amount.toString(),
|
|
currency: amountCurrency,
|
|
},
|
|
};
|
|
responseData = await StrikeApi_1.strikeApiRequest.call(this, 'POST', '/payment-quotes/lightning/lnurl', body);
|
|
}
|
|
else if (operation === 'getLnurlDetails') {
|
|
const lnAddressOrUrl = this.getNodeParameter('lnAddressOrUrl', i);
|
|
responseData = await StrikeApi_1.strikeApiRequest.call(this, 'GET', `/payment-quotes/lightning/lnurl/${encodeURIComponent(lnAddressOrUrl)}`);
|
|
}
|
|
else if (operation === 'executeQuote') {
|
|
const paymentQuoteId = this.getNodeParameter('paymentQuoteId', i);
|
|
responseData = await StrikeApi_1.strikeApiRequest.call(this, 'PATCH', `/payment-quotes/${paymentQuoteId}/execute`);
|
|
}
|
|
}
|
|
// ----------------------------------------
|
|
// paymentMethod
|
|
// ----------------------------------------
|
|
if (resource === 'paymentMethod') {
|
|
if (operation === 'createBank') {
|
|
const accountNumber = this.getNodeParameter('accountNumber', i);
|
|
const routingNumber = this.getNodeParameter('routingNumber', i);
|
|
const accountType = this.getNodeParameter('accountType', i);
|
|
const body = {
|
|
accountNumber,
|
|
routingNumber,
|
|
accountType,
|
|
};
|
|
responseData = await StrikeApi_1.strikeApiRequest.call(this, 'POST', '/payment-methods/bank', body);
|
|
}
|
|
else if (operation === 'get') {
|
|
const paymentMethodId = this.getNodeParameter('paymentMethodId', i);
|
|
responseData = await StrikeApi_1.strikeApiRequest.call(this, 'GET', `/payment-methods/bank/${paymentMethodId}`);
|
|
}
|
|
else if (operation === 'getAll') {
|
|
const returnAll = this.getNodeParameter('returnAll', i);
|
|
const options = this.getNodeParameter('options', i);
|
|
const query = {};
|
|
if (options.depositEligible) {
|
|
query.depositEligible = true;
|
|
}
|
|
if (returnAll) {
|
|
responseData = await StrikeApi_1.strikeApiRequestAllItems.call(this, 'GET', '/payment-methods/bank', {}, query);
|
|
}
|
|
else {
|
|
const limit = this.getNodeParameter('limit', i);
|
|
query.$top = limit;
|
|
responseData = await StrikeApi_1.strikeApiRequest.call(this, 'GET', '/payment-methods/bank', {}, query);
|
|
responseData = responseData.items || responseData;
|
|
}
|
|
}
|
|
else if (operation === 'delete') {
|
|
const paymentMethodId = this.getNodeParameter('paymentMethodId', i);
|
|
responseData = await StrikeApi_1.strikeApiRequest.call(this, 'DELETE', `/payment-methods/bank/${paymentMethodId}`);
|
|
responseData = { success: true };
|
|
}
|
|
}
|
|
// ----------------------------------------
|
|
// payout
|
|
// ----------------------------------------
|
|
if (resource === 'payout') {
|
|
if (operation === 'create') {
|
|
const paymentMethodId = this.getNodeParameter('paymentMethodId', i);
|
|
const amount = this.getNodeParameter('amount', i);
|
|
const currency = this.getNodeParameter('currency', i);
|
|
const additionalFields = this.getNodeParameter('additionalFields', i);
|
|
const body = {
|
|
paymentMethodId,
|
|
amount: {
|
|
amount: amount.toString(),
|
|
currency,
|
|
},
|
|
};
|
|
if (additionalFields.feePolicy) {
|
|
body.feePolicy = additionalFields.feePolicy;
|
|
}
|
|
if (additionalFields.originatorId) {
|
|
body.originatorId = additionalFields.originatorId;
|
|
}
|
|
responseData = await StrikeApi_1.strikeApiRequest.call(this, 'POST', '/payouts', body);
|
|
}
|
|
else if (operation === 'get') {
|
|
const payoutId = this.getNodeParameter('payoutId', i);
|
|
responseData = await StrikeApi_1.strikeApiRequest.call(this, 'GET', `/payouts/${payoutId}`);
|
|
}
|
|
else if (operation === 'getAll') {
|
|
const returnAll = this.getNodeParameter('returnAll', i);
|
|
const filters = this.getNodeParameter('filters', i);
|
|
const query = {};
|
|
if (filters.filter) {
|
|
query.$filter = filters.filter;
|
|
}
|
|
if (filters.orderBy) {
|
|
query.$orderby = filters.orderBy;
|
|
}
|
|
if (returnAll) {
|
|
responseData = await StrikeApi_1.strikeApiRequestAllItems.call(this, 'GET', '/payouts', {}, query);
|
|
}
|
|
else {
|
|
const limit = this.getNodeParameter('limit', i);
|
|
query.$top = limit;
|
|
responseData = await StrikeApi_1.strikeApiRequest.call(this, 'GET', '/payouts', {}, query);
|
|
responseData = responseData.items || responseData;
|
|
}
|
|
}
|
|
else if (operation === 'initiate') {
|
|
const payoutId = this.getNodeParameter('payoutId', i);
|
|
responseData = await StrikeApi_1.strikeApiRequest.call(this, 'PATCH', `/payouts/${payoutId}/initiate`);
|
|
}
|
|
}
|
|
// ----------------------------------------
|
|
// rates
|
|
// ----------------------------------------
|
|
if (resource === 'rates') {
|
|
if (operation === 'getTicker') {
|
|
const currencyPair = this.getNodeParameter('currencyPair', i);
|
|
responseData = await StrikeApi_1.strikeApiRequest.call(this, 'GET', `/rates/ticker/${currencyPair}`);
|
|
}
|
|
}
|
|
// Return data
|
|
const executionData = this.helpers.constructExecutionMetaData(this.helpers.returnJsonArray(responseData), { itemData: { item: i } });
|
|
returnData.push(...executionData);
|
|
}
|
|
catch (error) {
|
|
if (this.continueOnFail()) {
|
|
const executionData = this.helpers.constructExecutionMetaData(this.helpers.returnJsonArray({ error: error.message }), { itemData: { item: i } });
|
|
returnData.push(...executionData);
|
|
continue;
|
|
}
|
|
throw error;
|
|
}
|
|
}
|
|
return [returnData];
|
|
}
|
|
}
|
|
exports.Strike = Strike;
|