n8n-nodes-jegyhu-api
Version:
n8n community node for Jegy.hu API integration
657 lines (656 loc) • 27.7 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.JegyHu = void 0;
const n8n_workflow_1 = require("n8n-workflow");
class JegyHu {
constructor() {
this.description = {
displayName: 'Jegy.hu',
name: 'jegyHu',
icon: 'fa:ticket',
group: ['transform'],
version: 1,
description: 'Interact with Jegy.hu ticketing API',
defaults: {
name: 'Jegy.hu',
},
inputs: ["main" /* NodeConnectionType.Main */],
outputs: ["main" /* NodeConnectionType.Main */],
credentials: [
{
name: 'jegyHuApi',
required: true,
},
],
properties: [
{
displayName: 'Operation',
name: 'operation',
type: 'options',
noDataExpression: true,
options: [
{
name: 'Add Ticket to Basket',
value: 'addTicketToBasket',
description: 'Add tickets to shopping basket',
action: 'Add ticket to basket',
},
{
name: 'Get Audit Free Tickets',
value: 'getAuditFreeTickets',
description: 'Get free tickets for auditorium event',
action: 'Get audit free tickets',
},
{
name: 'Get Audit Seats',
value: 'getAuditSeats',
description: 'Get seat layout for auditorium',
action: 'Get audit seats',
},
{
name: 'Get Basket',
value: 'getBasket',
description: 'Get basket contents by ID',
action: 'Get basket',
},
{
name: 'Get Event Capacity Report',
value: 'getEventCapacityReport',
description: 'Get capacity report for a specific event',
action: 'Get event capacity report',
},
{
name: 'Get Event List',
value: 'getEventList',
description: 'Get list of events',
action: 'Get event list',
},
{
name: 'Get Sector Prices',
value: 'getSectorPrices',
description: 'Get sector prices for an event',
action: 'Get sector prices',
},
{
name: 'Get Transaction Status',
value: 'getTransactionStatus',
action: 'Get transaction status',
},
{
name: 'Start Transaction',
value: 'startTransaction',
description: 'Start payment transaction',
action: 'Start transaction',
},
],
default: 'getEventCapacityReport',
},
// Event Capacity Report Parameters
{
displayName: 'Venue ID',
name: 'venueId',
type: 'number',
required: true,
displayOptions: {
show: {
operation: ['getEventCapacityReport'],
},
},
default: 40,
description: 'The ID of the venue',
},
{
displayName: 'Event ID',
name: 'eventId',
type: 'number',
required: true,
displayOptions: {
show: {
operation: ['getEventCapacityReport'],
},
},
default: 17510,
description: 'The ID of the event',
},
// Event List Parameters
{
displayName: 'Venues',
name: 'venues',
type: 'number',
displayOptions: {
show: {
operation: ['getEventList'],
},
},
default: 40,
description: 'Venue ID to filter events',
},
{
displayName: 'Per Page',
name: 'perPage',
type: 'number',
displayOptions: {
show: {
operation: ['getEventList'],
},
},
default: 50,
description: 'Number of events per page',
},
{
displayName: 'Page',
name: 'page',
type: 'number',
displayOptions: {
show: {
operation: ['getEventList'],
},
},
default: 1,
description: 'Page number',
},
// Sector Prices Parameters
{
displayName: 'Net Event ID',
name: 'netEventId',
type: 'number',
required: true,
displayOptions: {
show: {
operation: ['getSectorPrices', 'getAuditFreeTickets'],
},
},
default: 4406,
},
{
displayName: 'Available Only',
name: 'availableOnly',
type: 'boolean',
displayOptions: {
show: {
operation: ['getSectorPrices'],
},
},
default: true,
description: 'Whether to show only available sectors',
},
// Add Ticket to Basket Parameters
{
displayName: 'Venue ID',
name: 'venueIdBasket',
type: 'number',
required: true,
displayOptions: {
show: {
operation: ['addTicketToBasket'],
},
},
default: 40,
description: 'The ID of the venue',
},
{
displayName: 'Net Event ID',
name: 'netEventIdBasket',
type: 'number',
required: true,
displayOptions: {
show: {
operation: ['addTicketToBasket'],
},
},
default: 4406,
},
{
displayName: 'Net Program ID',
name: 'netProgramId',
type: 'number',
required: true,
displayOptions: {
show: {
operation: ['addTicketToBasket'],
},
},
default: 4520,
},
{
displayName: 'Tickets',
name: 'ticketArray',
type: 'fixedCollection',
typeOptions: {
multipleValues: true,
},
displayOptions: {
show: {
operation: ['addTicketToBasket'],
},
},
default: {},
options: [
{
name: 'ticket',
displayName: 'Ticket',
values: [
{
displayName: 'Price',
name: 'price',
type: 'number',
required: true,
default: 1000,
description: 'Ticket price',
},
{
displayName: 'Price Category ID',
name: 'pricecatId',
type: 'number',
required: true,
default: 421,
},
{
displayName: 'Quantity',
name: 'quantity',
type: 'number',
required: true,
default: 1,
description: 'Number of tickets',
},
{
displayName: 'Seat ID',
name: 'seatId',
type: 'number',
default: 1,
description: 'Seat ID (for seated events)',
},
{
displayName: 'Sector ID',
name: 'sectorId',
type: 'number',
required: true,
default: 798,
},
],
},
],
description: 'Array of tickets to add to basket',
},
// Basket Parameters
{
displayName: 'Basket ID',
name: 'basketId',
type: 'string',
required: true,
displayOptions: {
show: {
operation: ['getBasket', 'startTransaction', 'getTransactionStatus'],
},
},
default: '',
},
// Transaction Parameters
{
displayName: 'Delivery Option',
name: 'deliveryOption',
type: 'options',
options: [
{
name: 'PDF',
value: 'PDF',
},
],
displayOptions: {
show: {
operation: ['startTransaction'],
},
},
default: 'PDF',
description: 'Delivery method for tickets',
},
{
displayName: 'Payment Option',
name: 'paymentOption',
type: 'options',
options: [
{
name: 'PAYUHU',
value: 'PAYUHU',
},
],
displayOptions: {
show: {
operation: ['startTransaction'],
},
},
default: 'PAYUHU',
description: 'Payment method',
},
{
displayName: 'Buyer Data',
name: 'buyerData',
type: 'fixedCollection',
typeOptions: {
multipleValues: false,
},
displayOptions: {
show: {
operation: ['startTransaction'],
},
},
default: {},
options: [
{
name: 'buyer',
displayName: 'Buyer Information',
values: [
{
displayName: 'City',
name: 'city',
type: 'string',
required: true,
default: '',
description: 'Buyer city',
},
{
displayName: 'Country',
name: 'country',
type: 'string',
required: true,
default: 'HU',
description: 'Buyer country code',
},
{
displayName: 'Email',
name: 'email',
type: 'string',
placeholder: 'name@email.com',
required: true,
default: '',
description: 'Buyer email address',
},
{
displayName: 'First Name',
name: 'firstname',
type: 'string',
required: true,
default: '',
description: 'Buyer first name',
},
{
displayName: 'Last Name',
name: 'lastname',
type: 'string',
required: true,
default: '',
description: 'Buyer last name',
},
{
displayName: 'Phone',
name: 'phone',
type: 'string',
required: true,
default: '',
description: 'Buyer phone number',
},
{
displayName: 'Street',
name: 'street',
type: 'string',
required: true,
default: '',
description: 'Buyer street address',
},
{
displayName: 'ZIP Code',
name: 'zip',
type: 'string',
required: true,
default: '',
description: 'Buyer ZIP code',
},
],
},
],
description: 'Buyer information for transaction',
},
{
displayName: 'Return URLs',
name: 'returnUrl',
type: 'fixedCollection',
typeOptions: {
multipleValues: false,
},
displayOptions: {
show: {
operation: ['startTransaction'],
},
},
default: {},
options: [
{
name: 'urls',
displayName: 'Return URLs',
values: [
{
displayName: 'Success URL',
name: 'success',
type: 'string',
required: true,
default: 'http://localhost',
description: 'URL to redirect on successful payment',
},
{
displayName: 'Fail URL',
name: 'fail',
type: 'string',
required: true,
default: 'http://localhost',
description: 'URL to redirect on failed payment',
},
],
},
],
description: 'Return URLs for payment process',
},
// Audit Seats Parameters
{
displayName: 'Net Audit ID',
name: 'netAuditId',
type: 'number',
required: true,
displayOptions: {
show: {
operation: ['getAuditSeats'],
},
},
default: 145,
},
{
displayName: 'Sector ID',
name: 'sectorIdAudit',
type: 'number',
required: true,
displayOptions: {
show: {
operation: ['getAuditSeats'],
},
},
default: 744,
},
{
displayName: 'Show Extra Sector',
name: 'showExtraSector',
type: 'boolean',
displayOptions: {
show: {
operation: ['getAuditSeats'],
},
},
default: true,
description: 'Whether to show extra sector information',
},
{
displayName: 'Show Capacity Sector',
name: 'showCapacitySector',
type: 'boolean',
displayOptions: {
show: {
operation: ['getAuditSeats'],
},
},
default: true,
description: 'Whether to show capacity sector information',
},
],
};
}
async execute() {
const items = this.getInputData();
const returnData = [];
const operation = this.getNodeParameter('operation', 0);
const credentials = await this.getCredentials('jegyHuApi');
for (let i = 0; i < items.length; i++) {
try {
let requestData = {};
let functionName = '';
let httpMethod = 'GET';
if (operation === 'getEventCapacityReport') {
const venueId = this.getNodeParameter('venueId', i);
const eventId = this.getNodeParameter('eventId', i);
requestData = {
venue_id: venueId,
event_id: eventId,
};
functionName = 'get_event_capacity_report';
}
else if (operation === 'getEventList') {
const venues = this.getNodeParameter('venues', i);
const perPage = this.getNodeParameter('perPage', i);
const page = this.getNodeParameter('page', i);
requestData = {
venues: venues,
per_page: perPage,
page: page,
};
functionName = 'get_event_list';
}
else if (operation === 'getSectorPrices') {
const netEventId = this.getNodeParameter('netEventId', i);
const availableOnly = this.getNodeParameter('availableOnly', i);
requestData = {
netevent_id: netEventId,
available_only: availableOnly,
};
functionName = 'get_sector_prices';
}
else if (operation === 'addTicketToBasket') {
const venueId = this.getNodeParameter('venueIdBasket', i);
const netEventId = this.getNodeParameter('netEventIdBasket', i);
const netProgramId = this.getNodeParameter('netProgramId', i);
const ticketArray = this.getNodeParameter('ticketArray', i);
const tickets = ticketArray.ticket || [];
const ticketData = tickets.map((ticket) => ({
sector_id: ticket.sectorId,
pricecat_id: ticket.pricecatId,
price: ticket.price,
quantity: ticket.quantity,
...(ticket.seatId && { seat_id: ticket.seatId }),
}));
requestData = {
venue_id: venueId,
netevent_id: netEventId,
netprogram_id: netProgramId,
ticket_array: ticketData,
};
functionName = 'add_ticket_to_basket';
httpMethod = 'POST';
}
else if (operation === 'getBasket') {
const basketId = this.getNodeParameter('basketId', i);
requestData = {
basket_id: basketId,
};
functionName = 'get_basket';
}
else if (operation === 'startTransaction') {
const basketId = this.getNodeParameter('basketId', i);
const deliveryOption = this.getNodeParameter('deliveryOption', i);
const paymentOption = this.getNodeParameter('paymentOption', i);
const buyerData = this.getNodeParameter('buyerData', i);
const returnUrl = this.getNodeParameter('returnUrl', i);
requestData = {
basket_id: basketId,
delivery_option: deliveryOption,
payment_option: paymentOption,
buyer_data: buyerData.buyer,
return_url: returnUrl.urls,
};
functionName = 'start_transaction';
httpMethod = 'POST';
}
else if (operation === 'getTransactionStatus') {
const basketId = this.getNodeParameter('basketId', i);
requestData = {
basket_id: basketId,
};
functionName = 'get_transaction_in_progress';
}
else if (operation === 'getAuditSeats') {
const netAuditId = this.getNodeParameter('netAuditId', i);
const sectorId = this.getNodeParameter('sectorIdAudit', i);
const showExtraSector = this.getNodeParameter('showExtraSector', i);
const showCapacitySector = this.getNodeParameter('showCapacitySector', i);
requestData = {
netaudit_id: netAuditId,
sector_id: sectorId,
show_extra_sector: showExtraSector,
show_capacity_sector: showCapacitySector,
};
functionName = 'audit_get_seats';
}
else if (operation === 'getAuditFreeTickets') {
const netEventId = this.getNodeParameter('netEventId', i);
requestData = {
netevent_id: netEventId,
};
functionName = 'get_audit_free_tickets';
}
const options = {
method: httpMethod,
uri: credentials.baseUrl,
qs: {
_function_name: functionName,
_version: '2',
_request: JSON.stringify(requestData),
},
headers: {
'Cookie': 'cache_params=a%3A3%3A%7Bs%3A7%3A%22param_3%22%3Bb%3A1%3Bs%3A7%3A%22param_2%22%3Bb%3A0%3Bs%3A7%3A%22param_1%22%3Bs%3A32%3A%220748a1054986265de50e60e29bc6fff1%22%3B%7D; ticketsess=d44gu854bhgjr3b3jseqhbbpmrg40d88',
},
json: true,
};
const responseData = await this.helpers.request(options);
returnData.push({
json: responseData,
pairedItem: {
item: i,
},
});
}
catch (error) {
if (this.continueOnFail()) {
returnData.push({
json: {
error: error instanceof Error ? error.message : String(error),
},
pairedItem: {
item: i,
},
});
continue;
}
throw new n8n_workflow_1.NodeOperationError(this.getNode(), error, {
itemIndex: i,
});
}
}
return [returnData];
}
}
exports.JegyHu = JegyHu;