From 2b71564b5662465bf807fe6ce86dd977b87e873d Mon Sep 17 00:00:00 2001 From: gitcommitshow Date: Mon, 11 Dec 2023 15:21:31 +0530 Subject: [PATCH 1/9] feat: rate limit requests using aperture --- contributors.js | 6 ++-- network.js | 85 ++++++++++++++++++++++++++++++++++++++++++++----- 2 files changed, 80 insertions(+), 11 deletions(-) diff --git a/contributors.js b/contributors.js index 2681723..e8c39f3 100644 --- a/contributors.js +++ b/contributors.js @@ -10,7 +10,7 @@ exports.getRepoContributors = getRepoContributors; const path = require('path'); -const { makeRequest } = require('./network.js'); +const { makeRequestWithRateLimit } = require('./network.js'); // Configurations (Optional) // Repo owner that you want to analyze @@ -43,7 +43,7 @@ async function getAllRepos(owner=REPO_OWNER, options) { GITHUB_REQUEST_OPTIONS.headers["Authorization"] = "token "+options.GITHUB_PERSONAL_TOKEN; } let url = `https://api.github.com/orgs/${owner}/repos?per_page=100&page=${pageNo}`; - const { res, data } = await makeRequest('GET', url, Object.assign({},GITHUB_REQUEST_OPTIONS)); + const { res, data } = await makeRequestWithRateLimit('GET', url, Object.assign({},GITHUB_REQUEST_OPTIONS)); console.log("Repo list request finished"); console.log('HTTP status: ', res.statusCode); // console.log(data) @@ -71,7 +71,7 @@ async function getAllRepos(owner=REPO_OWNER, options) { async function getRepoContributors(fullRepoName, pageNo = 1) { let url = `https://api.github.com/repos/${fullRepoName}/contributors?per_page=100&page=${pageNo}`; console.log(url); - const { res, data } = await makeRequest('GET', url, Object.assign({},GITHUB_REQUEST_OPTIONS)); + const { res, data } = await makeRequestWithRateLimit('GET', url, Object.assign({},GITHUB_REQUEST_OPTIONS)); console.log("Contributors request finished for " + fullRepoName) // console.log(data) let dataJsonArray = JSON.parse(data); diff --git a/network.js b/network.js index 3fd5711..c3bba68 100644 --- a/network.js +++ b/network.js @@ -1,13 +1,29 @@ const https = require('https'); +const { ApertureClient } = require("@fluxninja/aperture-js"); exports.makeRequest = makeRequest; +exports.makeRequestWithRateLimit = makeRequestWithRateLimit; + +var apertureClient; + +function getApertureClient(){ + if(!apertureClient) { + apertureClient = new ApertureClient({ + address: process.env.APERTURE_SERVICE_ADDRESS, + apiKey: process.env.APERTURE_API_KEY, + }); + } + return apertureClient; +} /** * Sends an HTTPS request based on the specified method and options * This function returns a Promise that resolves with the response and data received from the server * @param {string} method - The HTTP method to use (e.g., 'GET', 'POST'). * @param {string} url - The URL to which the request is sent. - * @param {Object} [options] - The options for the request. This includes headers, request body (for POST/PUT), etc. + * @param {Object} [requestOptions] - The options for the request. This includes headers, request body (for POST/PUT), etc. + * @param {Object} [requestOptions.body] - The data that needs to be sent with the request, used for POST/PUT requests + * @param {Object} [requestOptions.headers] - The headers that needs to be sent with the request * @returns {Promise<{res: https.IncomingMessage, data: string}>} A Promise that resolves with the response object and the body data as a string. * @throws {Error} Throws an error if the request cannot be completed * @@ -23,13 +39,13 @@ exports.makeRequest = makeRequest; * } * } * */ -async function makeRequest(method, url, options) { +async function makeRequest(method, url, requestOptions) { return new Promise((resolve, reject) => { // Ensure options is an object and set the method - options = typeof options === 'object' ? options : {}; - options.method = method; + requestOptions = typeof requestOptions === 'object' ? requestOptions : {}; + requestOptions.method = method; - const req = https.request(url, options, res => { + const req = https.request(url, requestOptions, res => { // Handle HTTP response stream let data = ''; res.on('data', chunk => data += chunk); @@ -42,10 +58,63 @@ async function makeRequest(method, url, options) { }); // Handle POST/PUT data if provided - if (options.data) { - req.write(options.data); + if (requestOptions.data) { + req.write(requestOptions.data); } req.end(); }); -} \ No newline at end of file +} + + +/** + * Sends an HTTPS request with rate limiting. The function checks if the request is allowed by the rate limiter, + * and if so, sends an HTTPS request based on the specified method and options. This function returns a Promise + * that resolves with the response and data received from the server or rejects if an error occurs or the rate limit is exceeded. + * + * @param {string} method - The HTTP method to use (e.g., 'GET', 'POST'). + * @param {string} url - The URL to which the request is sent. + * @param {Object} [options] - The options for the request. This includes headers, request body (for POST/PUT), etc. + * @param {Object} [options.rateLimitOptions] - Options related to rate limits + * @param {Object} [options.body] - The data that needs to be sent with the request, used for POST/PUT requests + * @param {Object} [options.headers] - The headers that needs to be sent with the request + * @returns {Promise<{res: https.IncomingMessage, data: string}>} A Promise that resolves with the response object and the body data as a string. + * @throws {Error} Throws an error if the rate limit is exceeded or if an invalid argument is passed. + * + * @example + * // Example usage for a GET request within an async function + * async function getExample() { + * try { + * const { res, data } = await makeRequest('GET', 'https://example.com'); + * console.log('Status Code:', res.statusCode); + * console.log('Body:', data); + * } catch (error) { + * console.error('Error:', error.message); + * } + * } + * */ +async function makeRequestWithRateLimit(method, url, requestOptions){ + const flow = await apertureClient.startFlow("external-api-request", { + labels: { + url: url, + }, + grpcCallOptions: { + deadline: Date.now() + 300, // ms + }, + }); + + if (flow.shouldRun()) { + // Add business logic to process incoming request + console.log("Request accepted. Processing..."); + const {res, data} = await makeRequest(...arguments) + return { res, data} + } else { + console.log("Request rate-limited. Try again later."); + // Handle flow rejection + flow.setStatus(FlowStatus.Error); + } + + if (flow) { + flow.end(); + } + } \ No newline at end of file From 5c46bc2e07ccbdaab62e5edb4335f4a2ce69c129 Mon Sep 17 00:00:00 2001 From: gitcommitshow Date: Mon, 11 Dec 2023 15:23:38 +0530 Subject: [PATCH 2/9] fix: add aperture dependency --- package.json | 3 +++ 1 file changed, 3 insertions(+) diff --git a/package.json b/package.json index 077b4c9..eb9a389 100644 --- a/package.json +++ b/package.json @@ -7,6 +7,9 @@ "ock": "cli.js", "open-community-kit": "cli.js" }, + "dependencies": { + "@fluxninja/aperture-js": "^2.5.0" + }, "devDependencies": { "chai": "^4.3.10", "mocha": "^10.2.0", From ed4f3946cd8c319ec086ee23df6e7335577a65a4 Mon Sep 17 00:00:00 2001 From: gitcommitshow Date: Mon, 11 Dec 2023 15:34:46 +0530 Subject: [PATCH 3/9] chore: update package lock for ci install --- package-lock.json | 498 ++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 483 insertions(+), 15 deletions(-) diff --git a/package-lock.json b/package-lock.json index 4e6ac39..91b2f6b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -8,6 +8,9 @@ "name": "open-community-kit", "version": "1.1.1", "license": "MIT", + "dependencies": { + "@fluxninja/aperture-js": "^2.5.0" + }, "bin": { "ock": "cli.js", "open-community-kit": "cli.js" @@ -471,6 +474,93 @@ "node": ">=6.9.0" } }, + "node_modules/@fluxninja/aperture-js": { + "version": "2.5.0", + "resolved": "https://registry.npmjs.org/@fluxninja/aperture-js/-/aperture-js-2.5.0.tgz", + "integrity": "sha512-JR7arTvAac5Mm5rYIHIMejtEzuXASOA7y0wb20EVyBM27QCwqkM1sTTPJPCB3wxBYG26kLdsmdkHodOf7KbnvA==", + "dependencies": { + "@grpc/grpc-js": "^1.9.5", + "@grpc/proto-loader": "^0.7.10", + "@opentelemetry/api": "1.6.0", + "@opentelemetry/exporter-trace-otlp-grpc": "0.43.0", + "@opentelemetry/resources": "1.17.0", + "@opentelemetry/sdk-trace-base": "1.17.0", + "@opentelemetry/sdk-trace-node": "1.17.0", + "@opentelemetry/semantic-conventions": "1.17.0", + "serialize-error": "^11.0.2" + }, + "engines": { + "node": ">=16.19.1", + "npm": ">=8.19.3" + } + }, + "node_modules/@grpc/grpc-js": { + "version": "1.9.12", + "resolved": "https://registry.npmjs.org/@grpc/grpc-js/-/grpc-js-1.9.12.tgz", + "integrity": "sha512-Um5MBuge32TS3lAKX02PGCnFM4xPT996yLgZNb5H03pn6NyJ4Iwn5YcPq6Jj9yxGRk7WOgaZFtVRH5iTdYBeUg==", + "dependencies": { + "@grpc/proto-loader": "^0.7.8", + "@types/node": ">=12.12.47" + }, + "engines": { + "node": "^8.13.0 || >=10.10.0" + } + }, + "node_modules/@grpc/proto-loader": { + "version": "0.7.10", + "resolved": "https://registry.npmjs.org/@grpc/proto-loader/-/proto-loader-0.7.10.tgz", + "integrity": "sha512-CAqDfoaQ8ykFd9zqBDn4k6iWT9loLAlc2ETmDFS9JCD70gDcnA4L3AFEo2iV7KyAtAAHFW9ftq1Fz+Vsgq80RQ==", + "dependencies": { + "lodash.camelcase": "^4.3.0", + "long": "^5.0.0", + "protobufjs": "^7.2.4", + "yargs": "^17.7.2" + }, + "bin": { + "proto-loader-gen-types": "build/bin/proto-loader-gen-types.js" + }, + "engines": { + "node": ">=6" + } + }, + "node_modules/@grpc/proto-loader/node_modules/cliui": { + "version": "8.0.1", + "resolved": "https://registry.npmjs.org/cliui/-/cliui-8.0.1.tgz", + "integrity": "sha512-BSeNnyus75C4//NQ9gQt1/csTXyo/8Sb+afLAkzAptFuMsod9HFokGNudZpi/oQV73hnVK+sR+5PVRMd+Dr7YQ==", + "dependencies": { + "string-width": "^4.2.0", + "strip-ansi": "^6.0.1", + "wrap-ansi": "^7.0.0" + }, + "engines": { + "node": ">=12" + } + }, + "node_modules/@grpc/proto-loader/node_modules/yargs": { + "version": "17.7.2", + "resolved": "https://registry.npmjs.org/yargs/-/yargs-17.7.2.tgz", + "integrity": "sha512-7dSzzRQ++CKnNI/krKnYRV7JKKPUXMEh61soaHKg9mrWEhzFWhFnxPxGl+69cD1Ou63C13NUPCnmIcrvqCuM6w==", + "dependencies": { + "cliui": "^8.0.1", + "escalade": "^3.1.1", + "get-caller-file": "^2.0.5", + "require-directory": "^2.1.1", + "string-width": "^4.2.3", + "y18n": "^5.0.5", + "yargs-parser": "^21.1.1" + }, + "engines": { + "node": ">=12" + } + }, + "node_modules/@grpc/proto-loader/node_modules/yargs-parser": { + "version": "21.1.1", + "resolved": "https://registry.npmjs.org/yargs-parser/-/yargs-parser-21.1.1.tgz", + "integrity": "sha512-tVpsJW7DdjecAiFpbIB1e3qxIQsE6NoPc5/eTdrbbIC4h0LVsWhnoa3g+m2HclBIujHzsxZ4VJVA+GUuc2/LBw==", + "engines": { + "node": ">=12" + } + }, "node_modules/@istanbuljs/load-nyc-config": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/@istanbuljs/load-nyc-config/-/load-nyc-config-1.1.0.tgz", @@ -618,6 +708,321 @@ "@jridgewell/sourcemap-codec": "^1.4.14" } }, + "node_modules/@opentelemetry/api": { + "version": "1.6.0", + "resolved": "https://registry.npmjs.org/@opentelemetry/api/-/api-1.6.0.tgz", + "integrity": "sha512-OWlrQAnWn9577PhVgqjUvMr1pg57Bc4jv0iL4w0PRuOSRvq67rvHW9Ie/dZVMvCzhSCB+UxhcY/PmCmFj33Q+g==", + "engines": { + "node": ">=8.0.0" + } + }, + "node_modules/@opentelemetry/api-logs": { + "version": "0.43.0", + "resolved": "https://registry.npmjs.org/@opentelemetry/api-logs/-/api-logs-0.43.0.tgz", + "integrity": "sha512-0CXMOYPXgAdLM2OzVkiUfAL6QQwWVhnMfUXCqLsITY42FZ9TxAhZIHkoc4mfVxvPuXsBnRYGR8UQZX86p87z4A==", + "dependencies": { + "@opentelemetry/api": "^1.0.0" + }, + "engines": { + "node": ">=14" + } + }, + "node_modules/@opentelemetry/context-async-hooks": { + "version": "1.17.0", + "resolved": "https://registry.npmjs.org/@opentelemetry/context-async-hooks/-/context-async-hooks-1.17.0.tgz", + "integrity": "sha512-bDIRCgpKniSyhORU0fTL9ISW6ucU9nruKyXKwYrEBep/2f3uLz8LFyF51ZUK9QxIwBHw6WJudK/2UqttWzER4w==", + "engines": { + "node": ">=14" + }, + "peerDependencies": { + "@opentelemetry/api": ">=1.0.0 <1.7.0" + } + }, + "node_modules/@opentelemetry/core": { + "version": "1.17.0", + "resolved": "https://registry.npmjs.org/@opentelemetry/core/-/core-1.17.0.tgz", + "integrity": "sha512-tfnl3h+UefCgx1aeN2xtrmr6BmdWGKXypk0pflQR0urFS40aE88trnkOMc2HTJZbMrqEEl4HsaBeFhwLVXsrJg==", + "dependencies": { + "@opentelemetry/semantic-conventions": "1.17.0" + }, + "engines": { + "node": ">=14" + }, + "peerDependencies": { + "@opentelemetry/api": ">=1.0.0 <1.7.0" + } + }, + "node_modules/@opentelemetry/exporter-trace-otlp-grpc": { + "version": "0.43.0", + "resolved": "https://registry.npmjs.org/@opentelemetry/exporter-trace-otlp-grpc/-/exporter-trace-otlp-grpc-0.43.0.tgz", + "integrity": "sha512-h/oofzwyONMcAeBXD6+E6+foFQg9CPadBFcKAGoMIyVSK7iZgtK5DLEwAF4jz5MhfxWNmwZjHXFRc0GqCRx/tA==", + "dependencies": { + "@grpc/grpc-js": "^1.7.1", + "@opentelemetry/core": "1.17.0", + "@opentelemetry/otlp-grpc-exporter-base": "0.43.0", + "@opentelemetry/otlp-transformer": "0.43.0", + "@opentelemetry/resources": "1.17.0", + "@opentelemetry/sdk-trace-base": "1.17.0" + }, + "engines": { + "node": ">=14" + }, + "peerDependencies": { + "@opentelemetry/api": "^1.0.0" + } + }, + "node_modules/@opentelemetry/otlp-exporter-base": { + "version": "0.43.0", + "resolved": "https://registry.npmjs.org/@opentelemetry/otlp-exporter-base/-/otlp-exporter-base-0.43.0.tgz", + "integrity": "sha512-LXNtRFVuPRXB9q0qdvrLikQ3NtT9Jmv255Idryz3RJPhOh/Fa03sBASQoj3D55OH3xazmA90KFHfhJ/d8D8y4A==", + "dependencies": { + "@opentelemetry/core": "1.17.0" + }, + "engines": { + "node": ">=14" + }, + "peerDependencies": { + "@opentelemetry/api": "^1.0.0" + } + }, + "node_modules/@opentelemetry/otlp-grpc-exporter-base": { + "version": "0.43.0", + "resolved": "https://registry.npmjs.org/@opentelemetry/otlp-grpc-exporter-base/-/otlp-grpc-exporter-base-0.43.0.tgz", + "integrity": "sha512-oOpqtDJo9BBa1+nD6ID1qZ55ZdTwEwSSn2idMobw8jmByJKaanVLdr9SJKsn5T9OBqo/c5QY2brMf0TNZkobJQ==", + "dependencies": { + "@grpc/grpc-js": "^1.7.1", + "@opentelemetry/core": "1.17.0", + "@opentelemetry/otlp-exporter-base": "0.43.0", + "protobufjs": "^7.2.3" + }, + "engines": { + "node": ">=14" + }, + "peerDependencies": { + "@opentelemetry/api": "^1.0.0" + } + }, + "node_modules/@opentelemetry/otlp-transformer": { + "version": "0.43.0", + "resolved": "https://registry.npmjs.org/@opentelemetry/otlp-transformer/-/otlp-transformer-0.43.0.tgz", + "integrity": "sha512-KXYmgzWdVBOD5NvPmGW1nEMJjyQ8gK3N8r6pi4HvmEhTp0v4T13qDSax4q0HfsqmbPJR355oqQSJUnu1dHNutw==", + "dependencies": { + "@opentelemetry/api-logs": "0.43.0", + "@opentelemetry/core": "1.17.0", + "@opentelemetry/resources": "1.17.0", + "@opentelemetry/sdk-logs": "0.43.0", + "@opentelemetry/sdk-metrics": "1.17.0", + "@opentelemetry/sdk-trace-base": "1.17.0" + }, + "engines": { + "node": ">=14" + }, + "peerDependencies": { + "@opentelemetry/api": ">=1.3.0 <1.7.0" + } + }, + "node_modules/@opentelemetry/propagator-b3": { + "version": "1.17.0", + "resolved": "https://registry.npmjs.org/@opentelemetry/propagator-b3/-/propagator-b3-1.17.0.tgz", + "integrity": "sha512-oklstXImtaly4vDaL+rGtX41YXZR50jp5a7CSEPMcStp1B7ozdZ5G2I5wftrDvOlOcLt/TIkGWDCr/OkVN7kWg==", + "dependencies": { + "@opentelemetry/core": "1.17.0" + }, + "engines": { + "node": ">=14" + }, + "peerDependencies": { + "@opentelemetry/api": ">=1.0.0 <1.7.0" + } + }, + "node_modules/@opentelemetry/propagator-jaeger": { + "version": "1.17.0", + "resolved": "https://registry.npmjs.org/@opentelemetry/propagator-jaeger/-/propagator-jaeger-1.17.0.tgz", + "integrity": "sha512-iZzu8K0QkZZ16JH9yox6hZk7/Rxc4SPeGU37pvlB9DtzfNxAEX1FMK9zvowv3ve7r2uzZNpa7JGVUwpy5ewdHQ==", + "dependencies": { + "@opentelemetry/core": "1.17.0" + }, + "engines": { + "node": ">=14" + }, + "peerDependencies": { + "@opentelemetry/api": ">=1.0.0 <1.7.0" + } + }, + "node_modules/@opentelemetry/resources": { + "version": "1.17.0", + "resolved": "https://registry.npmjs.org/@opentelemetry/resources/-/resources-1.17.0.tgz", + "integrity": "sha512-+u0ciVnj8lhuL/qGRBPeVYvk7fL+H/vOddfvmOeJaA1KC+5/3UED1c9KoZQlRsNT5Kw1FaK8LkY2NVLYfOVZQw==", + "dependencies": { + "@opentelemetry/core": "1.17.0", + "@opentelemetry/semantic-conventions": "1.17.0" + }, + "engines": { + "node": ">=14" + }, + "peerDependencies": { + "@opentelemetry/api": ">=1.0.0 <1.7.0" + } + }, + "node_modules/@opentelemetry/sdk-logs": { + "version": "0.43.0", + "resolved": "https://registry.npmjs.org/@opentelemetry/sdk-logs/-/sdk-logs-0.43.0.tgz", + "integrity": "sha512-JyJ2BBRKm37Mc4cSEhFmsMl5ASQn1dkGhEWzAAMSlhPtLRTv5PfvJwhR+Mboaic/eDLAlciwsgijq8IFlf6IgQ==", + "dependencies": { + "@opentelemetry/core": "1.17.0", + "@opentelemetry/resources": "1.17.0" + }, + "engines": { + "node": ">=14" + }, + "peerDependencies": { + "@opentelemetry/api": ">=1.4.0 <1.7.0", + "@opentelemetry/api-logs": ">=0.39.1" + } + }, + "node_modules/@opentelemetry/sdk-metrics": { + "version": "1.17.0", + "resolved": "https://registry.npmjs.org/@opentelemetry/sdk-metrics/-/sdk-metrics-1.17.0.tgz", + "integrity": "sha512-HlWM27yGmYuwCoVRe3yg2PqKnIsq0kEF0HQgvkeDWz2NYkq9fFaSspR6kvjxUTbghAlZrabiqbgyKoYpYaXS3w==", + "dependencies": { + "@opentelemetry/core": "1.17.0", + "@opentelemetry/resources": "1.17.0", + "lodash.merge": "^4.6.2" + }, + "engines": { + "node": ">=14" + }, + "peerDependencies": { + "@opentelemetry/api": ">=1.3.0 <1.7.0" + } + }, + "node_modules/@opentelemetry/sdk-trace-base": { + "version": "1.17.0", + "resolved": "https://registry.npmjs.org/@opentelemetry/sdk-trace-base/-/sdk-trace-base-1.17.0.tgz", + "integrity": "sha512-2T5HA1/1iE36Q9eg6D4zYlC4Y4GcycI1J6NsHPKZY9oWfAxWsoYnRlkPfUqyY5XVtocCo/xHpnJvGNHwzT70oQ==", + "dependencies": { + "@opentelemetry/core": "1.17.0", + "@opentelemetry/resources": "1.17.0", + "@opentelemetry/semantic-conventions": "1.17.0" + }, + "engines": { + "node": ">=14" + }, + "peerDependencies": { + "@opentelemetry/api": ">=1.0.0 <1.7.0" + } + }, + "node_modules/@opentelemetry/sdk-trace-node": { + "version": "1.17.0", + "resolved": "https://registry.npmjs.org/@opentelemetry/sdk-trace-node/-/sdk-trace-node-1.17.0.tgz", + "integrity": "sha512-Twlaje+t16b5j62CfcaKU869rP9oyBG/sVQWBI5+kDaWuP/YIFnF4LbovaEahK9GwAnW8vPIn6iYLAl/jZBidA==", + "dependencies": { + "@opentelemetry/context-async-hooks": "1.17.0", + "@opentelemetry/core": "1.17.0", + "@opentelemetry/propagator-b3": "1.17.0", + "@opentelemetry/propagator-jaeger": "1.17.0", + "@opentelemetry/sdk-trace-base": "1.17.0", + "semver": "^7.5.2" + }, + "engines": { + "node": ">=14" + }, + "peerDependencies": { + "@opentelemetry/api": ">=1.0.0 <1.7.0" + } + }, + "node_modules/@opentelemetry/sdk-trace-node/node_modules/lru-cache": { + "version": "6.0.0", + "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-6.0.0.tgz", + "integrity": "sha512-Jo6dJ04CmSjuznwJSS3pUeWmd/H0ffTlkXXgwZi+eq1UCmqQwCh+eLsYOYCwY991i2Fah4h1BEMCx4qThGbsiA==", + "dependencies": { + "yallist": "^4.0.0" + }, + "engines": { + "node": ">=10" + } + }, + "node_modules/@opentelemetry/sdk-trace-node/node_modules/semver": { + "version": "7.5.4", + "resolved": "https://registry.npmjs.org/semver/-/semver-7.5.4.tgz", + "integrity": "sha512-1bCSESV6Pv+i21Hvpxp3Dx+pSD8lIPt8uVjRrxAUt/nbswYc+tK6Y2btiULjd4+fnq15PX+nqQDC7Oft7WkwcA==", + "dependencies": { + "lru-cache": "^6.0.0" + }, + "bin": { + "semver": "bin/semver.js" + }, + "engines": { + "node": ">=10" + } + }, + "node_modules/@opentelemetry/sdk-trace-node/node_modules/yallist": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/yallist/-/yallist-4.0.0.tgz", + "integrity": "sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==" + }, + "node_modules/@opentelemetry/semantic-conventions": { + "version": "1.17.0", + "resolved": "https://registry.npmjs.org/@opentelemetry/semantic-conventions/-/semantic-conventions-1.17.0.tgz", + "integrity": "sha512-+fguCd2d8d2qruk0H0DsCEy2CTK3t0Tugg7MhZ/UQMvmewbZLNnJ6heSYyzIZWG5IPfAXzoj4f4F/qpM7l4VBA==", + "engines": { + "node": ">=14" + } + }, + "node_modules/@protobufjs/aspromise": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/@protobufjs/aspromise/-/aspromise-1.1.2.tgz", + "integrity": "sha512-j+gKExEuLmKwvz3OgROXtrJ2UG2x8Ch2YZUxahh+s1F2HZ+wAceUNLkvy6zKCPVRkU++ZWQrdxsUeQXmcg4uoQ==" + }, + "node_modules/@protobufjs/base64": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/@protobufjs/base64/-/base64-1.1.2.tgz", + "integrity": "sha512-AZkcAA5vnN/v4PDqKyMR5lx7hZttPDgClv83E//FMNhR2TMcLUhfRUBHCmSl0oi9zMgDDqRUJkSxO3wm85+XLg==" + }, + "node_modules/@protobufjs/codegen": { + "version": "2.0.4", + "resolved": "https://registry.npmjs.org/@protobufjs/codegen/-/codegen-2.0.4.tgz", + "integrity": "sha512-YyFaikqM5sH0ziFZCN3xDC7zeGaB/d0IUb9CATugHWbd1FRFwWwt4ld4OYMPWu5a3Xe01mGAULCdqhMlPl29Jg==" + }, + "node_modules/@protobufjs/eventemitter": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/@protobufjs/eventemitter/-/eventemitter-1.1.0.tgz", + "integrity": "sha512-j9ednRT81vYJ9OfVuXG6ERSTdEL1xVsNgqpkxMsbIabzSo3goCjDIveeGv5d03om39ML71RdmrGNjG5SReBP/Q==" + }, + "node_modules/@protobufjs/fetch": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/@protobufjs/fetch/-/fetch-1.1.0.tgz", + "integrity": "sha512-lljVXpqXebpsijW71PZaCYeIcE5on1w5DlQy5WH6GLbFryLUrBD4932W/E2BSpfRJWseIL4v/KPgBFxDOIdKpQ==", + "dependencies": { + "@protobufjs/aspromise": "^1.1.1", + "@protobufjs/inquire": "^1.1.0" + } + }, + "node_modules/@protobufjs/float": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/@protobufjs/float/-/float-1.0.2.tgz", + "integrity": "sha512-Ddb+kVXlXst9d+R9PfTIxh1EdNkgoRe5tOX6t01f1lYWOvJnSPDBlG241QLzcyPdoNTsblLUdujGSE4RzrTZGQ==" + }, + "node_modules/@protobufjs/inquire": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/@protobufjs/inquire/-/inquire-1.1.0.tgz", + "integrity": "sha512-kdSefcPdruJiFMVSbn801t4vFK7KB/5gd2fYvrxhuJYg8ILrmn9SKSX2tZdV6V+ksulWqS7aXjBcRXl3wHoD9Q==" + }, + "node_modules/@protobufjs/path": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/@protobufjs/path/-/path-1.1.2.tgz", + "integrity": "sha512-6JOcJ5Tm08dOHAbdR3GrvP+yUUfkjG5ePsHYczMFLq3ZmMkAD98cDgcT2iA1lJ9NVwFd4tH/iSSoe44YWkltEA==" + }, + "node_modules/@protobufjs/pool": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/@protobufjs/pool/-/pool-1.1.0.tgz", + "integrity": "sha512-0kELaGSIDBKvcgS4zkjz1PeddatrjYcmMWOlAuAPwAeccUrPHdUqo/J6LiymHHEiJT5NrF1UVwxY14f+fy4WQw==" + }, + "node_modules/@protobufjs/utf8": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/@protobufjs/utf8/-/utf8-1.1.0.tgz", + "integrity": "sha512-Vvn3zZrhQZkkBE8LSuW3em98c0FwgO4nxzv6OdSxPKJIEKY2bGbHn+mhGIPerzI4twdxaP8/0+06HBpwf345Lw==" + }, "node_modules/@sinonjs/commons": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/@sinonjs/commons/-/commons-3.0.0.tgz", @@ -662,6 +1067,14 @@ "integrity": "sha512-sXXKG+uL9IrKqViTtao2Ws6dy0znu9sOaP1di/jKGW1M6VssO8vlpXCQcpZ+jisQ1tTFAC5Jo/EOzFbggBagFQ==", "dev": true }, + "node_modules/@types/node": { + "version": "20.10.4", + "resolved": "https://registry.npmjs.org/@types/node/-/node-20.10.4.tgz", + "integrity": "sha512-D08YG6rr8X90YB56tSIuBaddy/UXAA9RKJoFvrsnogAum/0pmjkgi4+2nx96A330FmioegBWmEYQ+syqCFaveg==", + "dependencies": { + "undici-types": "~5.26.4" + } + }, "node_modules/aggregate-error": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/aggregate-error/-/aggregate-error-3.1.0.tgz", @@ -688,7 +1101,6 @@ "version": "5.0.1", "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-5.0.1.tgz", "integrity": "sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ==", - "dev": true, "engines": { "node": ">=8" } @@ -697,7 +1109,6 @@ "version": "4.3.0", "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.3.0.tgz", "integrity": "sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg==", - "dev": true, "dependencies": { "color-convert": "^2.0.1" }, @@ -981,7 +1392,6 @@ "version": "2.0.1", "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz", "integrity": "sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==", - "dev": true, "dependencies": { "color-name": "~1.1.4" }, @@ -992,8 +1402,7 @@ "node_modules/color-name": { "version": "1.1.4", "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz", - "integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==", - "dev": true + "integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==" }, "node_modules/commondir": { "version": "1.0.1", @@ -1104,8 +1513,7 @@ "node_modules/emoji-regex": { "version": "8.0.0", "resolved": "https://registry.npmjs.org/emoji-regex/-/emoji-regex-8.0.0.tgz", - "integrity": "sha512-MSjYzcWNOA0ewAHpz0MxpYFvwg6yjy1NG3xteoqz644VCo/RPgnr1/GGt+ic3iJTzQ8Eu3TdM14SawnVUmGE6A==", - "dev": true + "integrity": "sha512-MSjYzcWNOA0ewAHpz0MxpYFvwg6yjy1NG3xteoqz644VCo/RPgnr1/GGt+ic3iJTzQ8Eu3TdM14SawnVUmGE6A==" }, "node_modules/es6-error": { "version": "4.1.1", @@ -1117,7 +1525,6 @@ "version": "3.1.1", "resolved": "https://registry.npmjs.org/escalade/-/escalade-3.1.1.tgz", "integrity": "sha512-k0er2gUkLf8O0zKJiAhmkTnJlTvINGv7ygDNPbeIsX/TJjGJZHuh9B2UxbsaEkmlEo9MfhrSzmhIlhRlI2GXnw==", - "dev": true, "engines": { "node": ">=6" } @@ -1267,7 +1674,6 @@ "version": "2.0.5", "resolved": "https://registry.npmjs.org/get-caller-file/-/get-caller-file-2.0.5.tgz", "integrity": "sha512-DyFP3BM/3YHTQOCUL/w0OZHR0lpKeGrxotcHWcqNEdnltqFwXVfhEBQ94eIo34AfQpo0rGki4cyIiftY06h2Fg==", - "dev": true, "engines": { "node": "6.* || 8.* || >= 10.*" } @@ -1458,7 +1864,6 @@ "version": "3.0.0", "resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-3.0.0.tgz", "integrity": "sha512-zymm5+u+sCsSWyD9qNaejV3DFvhCKclKdizYaJUuHA83RLjb7nSuGnddCHGv0hk+KY7BMAlsWeK4Ueg6EV6XQg==", - "dev": true, "engines": { "node": ">=8" } @@ -1761,6 +2166,11 @@ "url": "https://github.com/sponsors/sindresorhus" } }, + "node_modules/lodash.camelcase": { + "version": "4.3.0", + "resolved": "https://registry.npmjs.org/lodash.camelcase/-/lodash.camelcase-4.3.0.tgz", + "integrity": "sha512-TwuEnCnxbc3rAvhf/LbG7tJUDzhqXyFnv3dtzLOPgCG/hODL7WFnsbwktkD7yUV0RrreP/l1PALq/YSg6VvjlA==" + }, "node_modules/lodash.flattendeep": { "version": "4.4.0", "resolved": "https://registry.npmjs.org/lodash.flattendeep/-/lodash.flattendeep-4.4.0.tgz", @@ -1773,6 +2183,11 @@ "integrity": "sha512-z+Uw/vLuy6gQe8cfaFWD7p0wVv8fJl3mbzXh33RS+0oW2wvUqiRXiQ69gLWSLpgB5/6sU+r6BlQR0MBILadqTQ==", "dev": true }, + "node_modules/lodash.merge": { + "version": "4.6.2", + "resolved": "https://registry.npmjs.org/lodash.merge/-/lodash.merge-4.6.2.tgz", + "integrity": "sha512-0KpjqXRVvrYyCsX1swR/XTK0va6VQkQM6MNo7PqW77ByjAhoARA8EfrP1N4+KlKj8YS0ZUCtRT/YUuhyYDujIQ==" + }, "node_modules/log-symbols": { "version": "4.1.0", "resolved": "https://registry.npmjs.org/log-symbols/-/log-symbols-4.1.0.tgz", @@ -1789,6 +2204,11 @@ "url": "https://github.com/sponsors/sindresorhus" } }, + "node_modules/long": { + "version": "5.2.3", + "resolved": "https://registry.npmjs.org/long/-/long-5.2.3.tgz", + "integrity": "sha512-lcHwpNoggQTObv5apGNCTdJrO69eHOZMi4BNC+rTLER8iHAqGrUVeLh/irVIM7zTw2bOXA8T6uNPeujwOLg/2Q==" + }, "node_modules/loupe": { "version": "2.3.7", "resolved": "https://registry.npmjs.org/loupe/-/loupe-2.3.7.tgz", @@ -2314,6 +2734,29 @@ "node": ">=8" } }, + "node_modules/protobufjs": { + "version": "7.2.5", + "resolved": "https://registry.npmjs.org/protobufjs/-/protobufjs-7.2.5.tgz", + "integrity": "sha512-gGXRSXvxQ7UiPgfw8gevrfRWcTlSbOFg+p/N+JVJEK5VhueL2miT6qTymqAmjr1Q5WbOCyJbyrk6JfWKwlFn6A==", + "hasInstallScript": true, + "dependencies": { + "@protobufjs/aspromise": "^1.1.2", + "@protobufjs/base64": "^1.1.2", + "@protobufjs/codegen": "^2.0.4", + "@protobufjs/eventemitter": "^1.1.0", + "@protobufjs/fetch": "^1.1.0", + "@protobufjs/float": "^1.0.2", + "@protobufjs/inquire": "^1.1.0", + "@protobufjs/path": "^1.1.2", + "@protobufjs/pool": "^1.1.0", + "@protobufjs/utf8": "^1.1.0", + "@types/node": ">=13.7.0", + "long": "^5.0.0" + }, + "engines": { + "node": ">=12.0.0" + } + }, "node_modules/randombytes": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/randombytes/-/randombytes-2.1.0.tgz", @@ -2351,7 +2794,6 @@ "version": "2.1.1", "resolved": "https://registry.npmjs.org/require-directory/-/require-directory-2.1.1.tgz", "integrity": "sha512-fGxEI7+wsG9xrvdjsrlmL22OMTTiHRwAMroiEeMgq8gzoLC/PQr7RsRDSTLUg/bZAZtF+TVIkHc6/4RIKrui+Q==", - "dev": true, "engines": { "node": ">=0.10.0" } @@ -2415,6 +2857,31 @@ "semver": "bin/semver.js" } }, + "node_modules/serialize-error": { + "version": "11.0.3", + "resolved": "https://registry.npmjs.org/serialize-error/-/serialize-error-11.0.3.tgz", + "integrity": "sha512-2G2y++21dhj2R7iHAdd0FIzjGwuKZld+7Pl/bTU6YIkrC2ZMbVUjm+luj6A6V34Rv9XfKJDKpTWu9W4Gse1D9g==", + "dependencies": { + "type-fest": "^2.12.2" + }, + "engines": { + "node": ">=14.16" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/serialize-error/node_modules/type-fest": { + "version": "2.19.0", + "resolved": "https://registry.npmjs.org/type-fest/-/type-fest-2.19.0.tgz", + "integrity": "sha512-RAH822pAdBgcNMAfWnCBU3CFZcfZ/i1eZjwFU/dsLKumyuuP3niueg2UAukXYF0E2AAoc82ZSSf9J0WQBinzHA==", + "engines": { + "node": ">=12.20" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, "node_modules/serialize-javascript": { "version": "6.0.0", "resolved": "https://registry.npmjs.org/serialize-javascript/-/serialize-javascript-6.0.0.tgz", @@ -2532,7 +2999,6 @@ "version": "4.2.3", "resolved": "https://registry.npmjs.org/string-width/-/string-width-4.2.3.tgz", "integrity": "sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==", - "dev": true, "dependencies": { "emoji-regex": "^8.0.0", "is-fullwidth-code-point": "^3.0.0", @@ -2546,7 +3012,6 @@ "version": "6.0.1", "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-6.0.1.tgz", "integrity": "sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==", - "dev": true, "dependencies": { "ansi-regex": "^5.0.1" }, @@ -2674,6 +3139,11 @@ "is-typedarray": "^1.0.0" } }, + "node_modules/undici-types": { + "version": "5.26.5", + "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-5.26.5.tgz", + "integrity": "sha512-JlCMO+ehdEIKqlFxk6IfVoAUVmgz7cU7zD/h9XZ0qzeosSHmUJVOzSQvvYSYWXkFXC+IfLKSIffhv0sVZup6pA==" + }, "node_modules/update-browserslist-db": { "version": "1.0.13", "resolved": "https://registry.npmjs.org/update-browserslist-db/-/update-browserslist-db-1.0.13.tgz", @@ -2744,7 +3214,6 @@ "version": "7.0.0", "resolved": "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-7.0.0.tgz", "integrity": "sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==", - "dev": true, "dependencies": { "ansi-styles": "^4.0.0", "string-width": "^4.1.0", @@ -2779,7 +3248,6 @@ "version": "5.0.8", "resolved": "https://registry.npmjs.org/y18n/-/y18n-5.0.8.tgz", "integrity": "sha512-0pfFzegeDWJHJIAmTLRP2DwHjdF5s7jo9tuztdQxAhINCdvS+3nGINqPd00AphqJR/0LhANUS6/+7SCb98YOfA==", - "dev": true, "engines": { "node": ">=10" } From 71ac8fd130edd3542f6aeeced4c083ba58f5212e Mon Sep 17 00:00:00 2001 From: gitcommitshow Date: Mon, 11 Dec 2023 16:13:11 +0530 Subject: [PATCH 4/9] fix: import aperture client --- network.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/network.js b/network.js index 827e159..d61c60f 100644 --- a/network.js +++ b/network.js @@ -92,7 +92,7 @@ export async function makeRequest(method, url, options) { * } * */ export async function makeRequestWithRateLimit(method, url, requestOptions){ - const flow = await apertureClient.startFlow("external-api-request", { + const flow = await getApertureClient().startFlow("external-api-request", { labels: { url: url, }, From 8622b615072b7e7e94b106aa58047b7f7508d9fa Mon Sep 17 00:00:00 2001 From: gitcommitshow <56937085+gitcommitshow@users.noreply.github.com> Date: Mon, 11 Dec 2023 16:17:48 +0530 Subject: [PATCH 5/9] chore: add env secrets for test --- .github/workflows/test.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 1b4c826..b37aee1 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -10,6 +10,10 @@ on: pull_request: branches: [ "main" ] +env: + APERTURE_SERVICE_ADDRESS: ${{ secrets.APERTURE_SERVICE_ADDRESS }} + APERTURE_API_KEY: ${{ secrets.APERTURE_API_KEY }} + jobs: build: From 830e70ec364e845930b4cdc22733f79736534628 Mon Sep 17 00:00:00 2001 From: gitcommitshow Date: Mon, 11 Dec 2023 16:20:37 +0530 Subject: [PATCH 6/9] fix: function param bug --- network.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/network.js b/network.js index d61c60f..95272ef 100644 --- a/network.js +++ b/network.js @@ -37,7 +37,7 @@ function getApertureClient(){ * } * } * */ -export async function makeRequest(method, url, options) { +export async function makeRequest(method, url, requestOptions) { return new Promise((resolve, reject) => { // Ensure options is an object and set the method requestOptions = typeof requestOptions === 'object' ? requestOptions : {}; @@ -91,7 +91,7 @@ export async function makeRequest(method, url, options) { * } * } * */ -export async function makeRequestWithRateLimit(method, url, requestOptions){ +export async function makeRequestWithRateLimit(method, url, options){ const flow = await getApertureClient().startFlow("external-api-request", { labels: { url: url, From 0c922d8bfa6d7330acb9abf90218ee6e1afda5af Mon Sep 17 00:00:00 2001 From: gitcommitshow Date: Fri, 15 Dec 2023 01:46:06 +0530 Subject: [PATCH 7/9] fix: crash due to missing aperture config --- network.js | 24 +++++++++++++++++------- package-lock.json | 17 +++++++++++++++-- package.json | 3 ++- test/index.test.js | 2 +- 4 files changed, 35 insertions(+), 11 deletions(-) diff --git a/network.js b/network.js index 95272ef..0b3d8ec 100644 --- a/network.js +++ b/network.js @@ -92,7 +92,9 @@ export async function makeRequest(method, url, requestOptions) { * } * */ export async function makeRequestWithRateLimit(method, url, options){ - const flow = await getApertureClient().startFlow("external-api-request", { + let flow; + try { + flow = await getApertureClient().startFlow("external-api", { labels: { url: url, }, @@ -100,19 +102,27 @@ export async function makeRequestWithRateLimit(method, url, options){ deadline: Date.now() + 300, // ms }, }); - - if (flow.shouldRun()) { + } catch(err){ + console.error("Aperture client for rate limiting is not setup correctly"); + console.log("Make sure to setup set correct APERTURE_SERVICE_ADDRESS and APERTURE_API_KEY in environment variables"); + console.log("Going to make request without rate limit"); + } finally { + // Make request if allowed as per rate limit + // In case rate limiting is not setup properly, make request anyway + if (!flow || flow.shouldRun()) { // Add business logic to process incoming request console.log("Request accepted. Processing..."); const {res, data} = await makeRequest(...arguments) return { res, data} } else { console.log("Request rate-limited. Try again later."); - // Handle flow rejection - flow.setStatus(FlowStatus.Error); + if(flow) { + // Handle flow rejection + flow.setStatus(FlowStatus.Error); + } } - if (flow) { flow.end(); } - } \ No newline at end of file + } +} \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index 91b2f6b..8372782 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "open-community-kit", - "version": "1.1.1", + "version": "1.2.1", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "open-community-kit", - "version": "1.1.1", + "version": "1.2.1", "license": "MIT", "dependencies": { "@fluxninja/aperture-js": "^2.5.0" @@ -17,6 +17,7 @@ }, "devDependencies": { "chai": "^4.3.10", + "dotenv": "^16.3.1", "mocha": "^10.2.0", "nyc": "^15.1.0", "sinon": "^16.1.3" @@ -1504,6 +1505,18 @@ "node": ">=0.3.1" } }, + "node_modules/dotenv": { + "version": "16.3.1", + "resolved": "https://registry.npmjs.org/dotenv/-/dotenv-16.3.1.tgz", + "integrity": "sha512-IPzF4w4/Rd94bA9imS68tZBaYyBWSCE47V1RGuMrB94iyTOIEwRmVL2x/4An+6mETpLrKJ5hQkB8W4kFAadeIQ==", + "dev": true, + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://github.com/motdotla/dotenv?sponsor=1" + } + }, "node_modules/electron-to-chromium": { "version": "1.4.609", "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.4.609.tgz", diff --git a/package.json b/package.json index 29183d9..99731ff 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "open-community-kit", - "version": "1.1.1", + "version": "1.2.1", "description": "Tools and stats for open-source communities", "main": "contributors.js", "type": "module", @@ -13,6 +13,7 @@ }, "devDependencies": { "chai": "^4.3.10", + "dotenv": "^16.3.1", "mocha": "^10.2.0", "nyc": "^15.1.0", "sinon": "^16.1.3" diff --git a/test/index.test.js b/test/index.test.js index 57e387f..3c3427e 100644 --- a/test/index.test.js +++ b/test/index.test.js @@ -1,7 +1,7 @@ +import 'dotenv/config' import { expect, assert } from "chai"; import OCK from "../index.js"; - import * as contributorsFixture from "./fixtures/contributors.fixture.js"; describe('index.js', function() { From 062955f402d5cb3f8cf979375b29d0ea82f55b53 Mon Sep 17 00:00:00 2001 From: gitcommitshow Date: Fri, 15 Dec 2023 01:52:53 +0530 Subject: [PATCH 8/9] feat: more labels for aperture --- network.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/network.js b/network.js index 0b3d8ec..eaa107f 100644 --- a/network.js +++ b/network.js @@ -97,6 +97,9 @@ export async function makeRequestWithRateLimit(method, url, options){ flow = await getApertureClient().startFlow("external-api", { labels: { url: url, + priority: 1, + tokens: 1, + workload: 'api.github' }, grpcCallOptions: { deadline: Date.now() + 300, // ms From 7f9ff05314f58407ea244e8b495c1643a2e23dcd Mon Sep 17 00:00:00 2001 From: gitcommitshow Date: Fri, 15 Dec 2023 15:19:54 +0530 Subject: [PATCH 9/9] fix: change request body property to data --- network.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/network.js b/network.js index eaa107f..8df2f47 100644 --- a/network.js +++ b/network.js @@ -20,7 +20,7 @@ function getApertureClient(){ * @param {string} method - The HTTP method to use (e.g., 'GET', 'POST'). * @param {string} url - The URL to which the request is sent. * @param {Object} [requestOptions] - The options for the request. This includes headers, request body (for POST/PUT), etc. - * @param {Object} [requestOptions.body] - The data that needs to be sent with the request, used for POST/PUT requests + * @param {Object} [requestOptions.data] - The data that needs to be sent with the request, used for POST/PUT requests * @param {Object} [requestOptions.headers] - The headers that needs to be sent with the request * @returns {Promise<{res: https.IncomingMessage, data: string}>} A Promise that resolves with the response object and the body data as a string. * @throws {Error} Throws an error if the request cannot be completed @@ -74,7 +74,7 @@ export async function makeRequest(method, url, requestOptions) { * @param {string} url - The URL to which the request is sent. * @param {Object} [options] - The options for the request. This includes headers, request body (for POST/PUT), etc. * @param {Object} [options.rateLimitOptions] - Options related to rate limits - * @param {Object} [options.body] - The data that needs to be sent with the request, used for POST/PUT requests + * @param {Object} [options.data] - The data that needs to be sent with the request, used for POST/PUT requests * @param {Object} [options.headers] - The headers that needs to be sent with the request * @returns {Promise<{res: https.IncomingMessage, data: string}>} A Promise that resolves with the response object and the body data as a string. * @throws {Error} Throws an error if the rate limit is exceeded or if an invalid argument is passed.