UNPKG

n8n-nodes-base

Version:

Base nodes of n8n

57 lines 1.99 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.paddleApiRequest = paddleApiRequest; exports.paddleApiRequestAllItems = paddleApiRequestAllItems; exports.validateJSON = validateJSON; const n8n_workflow_1 = require("n8n-workflow"); async function paddleApiRequest(endpoint, method, body = {}, _query, _uri) { const credentials = await this.getCredentials('paddleApi'); const productionUrl = 'https://vendors.paddle.com/api'; const sandboxUrl = 'https://sandbox-vendors.paddle.com/api'; const isSandbox = credentials.sandbox; const options = { method, headers: { 'content-type': 'application/json', }, uri: `${isSandbox === true ? sandboxUrl : productionUrl}${endpoint}`, body, json: true, }; body.vendor_id = credentials.vendorId; body.vendor_auth_code = credentials.vendorAuthCode; try { const response = await this.helpers.request(options); if (!response.success) { throw new n8n_workflow_1.NodeApiError(this.getNode(), response); } return response; } catch (error) { throw new n8n_workflow_1.NodeApiError(this.getNode(), error); } } async function paddleApiRequestAllItems(propertyName, endpoint, method, body = {}, query = {}) { const returnData = []; let responseData; body.results_per_page = 200; body.page = 1; do { responseData = await paddleApiRequest.call(this, endpoint, method, body, query); returnData.push.apply(returnData, responseData[propertyName]); body.page++; } while (responseData[propertyName].length !== 0 && responseData[propertyName].length === body.results_per_page); return returnData; } function validateJSON(json) { let result; try { result = JSON.parse(json); } catch (exception) { result = undefined; } return result; } //# sourceMappingURL=GenericFunctions.js.map