From 9e0a1848066e31e05a08734553a99de2f438a9e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sven=20H=C3=B6ffler?= Date: Fri, 11 Jul 2025 10:45:56 +0200 Subject: [PATCH 1/2] Increased maximum timeout for retries --- templates/lib/utils/helpers.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/lib/utils/helpers.js b/templates/lib/utils/helpers.js index f953f00..95677d5 100644 --- a/templates/lib/utils/helpers.js +++ b/templates/lib/utils/helpers.js @@ -13,7 +13,7 @@ const executeSwaggerCall = async function (callParams) { retries: 5, factor: 2, minTimeout: 5000, - maxTimeout: 6000, + maxTimeout: 20000, randomize: true, }); return new Promise((resolve, reject) => { From 3da0d4ee989748f89abb7b5da200fba6beb35551 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sven=20H=C3=B6ffler?= Date: Fri, 11 Jul 2025 14:11:26 +0200 Subject: [PATCH 2/2] Added support for setting a component-specific rate limit --- bin/oih-gen.js | 1 + lib/do-generate.js | 4 +++- lib/generate.js | 3 ++- lib/utils/functions.js | 5 +++-- templates/component.json | 3 ++- templates/lib/actions/action.js | 2 +- templates/lib/triggers/trigger.js | 2 +- 7 files changed, 13 insertions(+), 7 deletions(-) diff --git a/bin/oih-gen.js b/bin/oih-gen.js index b76aecd..22a6924 100755 --- a/bin/oih-gen.js +++ b/bin/oih-gen.js @@ -62,6 +62,7 @@ async function oihGen() { connectorName: options.name, outputDir: options.output, snapshot: options.snapshot, + rateLimit: options.rateLimit, paginationConfig: { pageTokenOption: { fieldName: options.paginationTokenFieldName, diff --git a/lib/do-generate.js b/lib/do-generate.js index decad81..b39cb04 100644 --- a/lib/do-generate.js +++ b/lib/do-generate.js @@ -16,9 +16,10 @@ const generate = require("./generate"); * @param {string} paginationConfig.strategy.nextCursorPath * @param {object} paginationConfig.pageTokenOption * @param {string} paginationConfig.pageTokenOption.fieldName + * @param {number} rateLimit * @returns {Promise<*>} */ -module.exports = async function doGenerate({ swaggerUrl, outputDir, connectorName, snapshot, paginationConfig }) { +module.exports = async function doGenerate({ swaggerUrl, outputDir, connectorName, snapshot, paginationConfig, rateLimit }) { const downloadedSpecFile = path.join(outputDir, "openapi-original.json"); const validatedSpecFile = path.join(outputDir, "openapi-validated.json"); const generatePath = path.join(outputDir, connectorName); @@ -46,6 +47,7 @@ module.exports = async function doGenerate({ swaggerUrl, outputDir, connectorNam swaggerUrl: swaggerUrl, snapshot: snapshot || "", paginationConfig, + rateLimit: rateLimit || -1 }); console.log("\x1b[32m", "Successfully generated. Connector has been saved in output directory:", generatePath); diff --git a/lib/generate.js b/lib/generate.js index a5a0bf2..63e371b 100644 --- a/lib/generate.js +++ b/lib/generate.js @@ -32,6 +32,7 @@ module.exports = async function generate({ snapshot, paginationConfig, suffixServiceNameToTitle = false, + rateLimit = -1, }) { let api = await SwaggerParser.parse(inputFile); if (!api.components) { @@ -51,7 +52,7 @@ module.exports = async function generate({ fse.removeSync(libDir); } - let componentJson = await getComponentJson(apiTitle, api, swaggerUrl, this); + let componentJson = await getComponentJson(apiTitle, api, swaggerUrl, rateLimit, this); let existingNames = {}; // generate actions diff --git a/lib/utils/functions.js b/lib/utils/functions.js index 3ddd7dd..2769097 100644 --- a/lib/utils/functions.js +++ b/lib/utils/functions.js @@ -71,7 +71,7 @@ async function output(filename, text, data, outputDir) { if (data) { text = _.template(text, {})(data); } else if (typeof text !== "string") { - if(text.additionalProperties){ + if (text.additionalProperties) { text.properties = Object.assign({}, text.properties, text.additionalProperties); delete text.additionalProperties; } @@ -80,7 +80,7 @@ async function output(filename, text, data, outputDir) { //console.log('Writing file %s', filename); return await fse.outputFile(path.join(outputDir, filename), text); } -async function getComponentJson(apiTitle, api, swaggerUrl) { +async function getComponentJson(apiTitle, api, swaggerUrl, rateLimit) { const textDescription = toText(api.info.description); const componentJson = Object.assign(JSON.parse(templates.componentTemplate), { @@ -88,6 +88,7 @@ async function getComponentJson(apiTitle, api, swaggerUrl) { description: textDescription, docsUrl: (api.externalDocs && api.externalDocs.url) || "", url: swaggerUrl, + rateLimit: parseInt(rateLimit), }); await addCredentials(componentJson, api); diff --git a/templates/component.json b/templates/component.json index 4a84079..dd033e4 100644 --- a/templates/component.json +++ b/templates/component.json @@ -3,8 +3,9 @@ "description": "", "docsUrl": "", "url": "", + "rateLimit": -1, "envVars": {}, "credentials": {}, "triggers": {}, "actions": {} -} +} \ No newline at end of file diff --git a/templates/lib/actions/action.js b/templates/lib/actions/action.js index 0e5e022..ad085d6 100644 --- a/templates/lib/actions/action.js +++ b/templates/lib/actions/action.js @@ -104,7 +104,7 @@ async function processAction(msg, cfg, snapshot, incomingMessageHeaders, tokenDa const resp = await executeCall.call(this, callParams); // Wait for rate limit if specified - const rateLimit = cfg.nodeSettings && cfg.nodeSettings.rateLimit ? parseInt(cfg.nodeSettings.rateLimit) : 6100; + const rateLimit = cfg.nodeSettings && cfg.nodeSettings.rateLimit ? parseInt(cfg.nodeSettings.rateLimit) : (Number.isInteger(componentJson.rateLimit) ? componentJson.rateLimit : 0); if (rateLimit > 0) { this.logger.info(`Waiting for rate limit: ${rateLimit} ms`); await new Promise(resolve => setTimeout(resolve, rateLimit)); diff --git a/templates/lib/triggers/trigger.js b/templates/lib/triggers/trigger.js index 669a36f..1196476 100644 --- a/templates/lib/triggers/trigger.js +++ b/templates/lib/triggers/trigger.js @@ -151,7 +151,7 @@ async function processTrigger(msg, cfg, snapshot, incomingMessageHeaders, tokenD const { body, headers } = await executeCall.call(this, callParams); // Wait for rate limit if specified - const rateLimit = cfg.nodeSettings && cfg.nodeSettings.rateLimit ? parseInt(cfg.nodeSettings.rateLimit) : 6100; + const rateLimit = cfg.nodeSettings && cfg.nodeSettings.rateLimit ? parseInt(cfg.nodeSettings.rateLimit) : (Number.isInteger(componentJson.rateLimit) ? componentJson.rateLimit : 0); if (rateLimit > 0) { this.logger.info(`Waiting for rate limit: ${rateLimit} ms`); await new Promise(resolve => setTimeout(resolve, rateLimit));