Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
'use strict'
const { expect } = require('chai')
// https://github.com/nock/nock/issues/1523
const got = require('got').extend({ retry: 0 })
const isSvg = require('is-svg')
let server
before(function() {
this.timeout('5s')
// remove args comming from mocha
// https://github.com/badges/shields/issues/3365
process.argv = []
server = require('./server')
})
after('shut down the server', async function() {
await server.stop()
})
it('should render a badge', async function() {
const logger = require('./logger');
const config = require('@/config').value;
const got = require('got');
const queryString = require('query-string');
const custom = got.extend({
retry: {
retries: config.requestRetry,
statusCodes: [408, 413, 429, 500, 502, 503, 504, 404], // add 404 to default for unit test
},
hooks: {
beforeRetry: [
(options, err, count) => {
logger.error(`Request ${err.url} fail, retry attempt #${count}: ${err}`);
},
],
afterResponse: [
(response) => {
try {
response.data = JSON.parse(response.body);
} catch (e) {
response.data = response.body;
import * as gotDefault from "got";
import { IncomingMessage, RequestOptions } from "http";
import { basename, resolve as pathResolve } from "path";
import { fileURLToPath, parse } from "url";
const IS_ELECTRON = false; // process.versions.hasOwnProperty("electron");
export interface UpdatedObject {
timestamp: string;
}
export const got = gotDefault.extend({
useElectronNet: IS_ELECTRON,
});
export const fetchJson = gotDefault.extend({
json: true,
useElectronNet: IS_ELECTRON,
});
export const fetchBuffer = gotDefault.extend({
encoding: null,
useElectronNet: IS_ELECTRON,
});
export async function getRawIfUpdate(url: string, timestamp?: string): Promise<{ timestamp: string; content: string | undefined }> {
const lastModified = timestamp;
const resp = await got(url, {
encoding: "utf-8",
headers: lastModified ? { "If-Modified-Since": lastModified } : undefined,
});
export default (restUri: string, token: string) => {
const instance = got.extend({
baseUrl: restUri,
headers: {
'user-agent': `${name}/${version}`
},
json: true,
hooks: {
beforeRequest: [
addAccessTokenHook(token)
]
// should be used with rate limiter to handle throttling cases
// afterResponse: [
// (response) => {
// return response
// }
// ]
}
export function createGotClient(config: ClientConfig): GotClient {
// @ts-ignore
const client = got.extend({
baseUrl: 'https://serverless.twilio.com/v1',
json: true,
auth: `${config.accountSid}:${config.authToken}`,
headers: {
'User-Agent': 'twilio-serverless-api',
},
});
return client;
}
const IS_ELECTRON = false; // process.versions.hasOwnProperty("electron");
export interface UpdatedObject {
timestamp: string;
}
export const got = gotDefault.extend({
useElectronNet: IS_ELECTRON,
});
export const fetchJson = gotDefault.extend({
json: true,
useElectronNet: IS_ELECTRON,
});
export const fetchBuffer = gotDefault.extend({
encoding: null,
useElectronNet: IS_ELECTRON,
});
export async function getRawIfUpdate(url: string, timestamp?: string): Promise<{ timestamp: string; content: string | undefined }> {
const lastModified = timestamp;
const resp = await got(url, {
encoding: "utf-8",
headers: lastModified ? { "If-Modified-Since": lastModified } : undefined,
});
const lastModifiedReturn = resp.headers["last-modified"] || resp.headers["Last-Modified"] as string || "";
if (resp.statusCode === 304) {
return { timestamp: lastModifiedReturn, content: undefined };
}
return {
constructor(ctx) {
super({ objectMode: true });
const { options } = ctx;
const { endpoint = 'https://kinesis.us-east-1.amazonaws.com', region } = options;
const credentialsChain = new AWS.CredentialProviderChain();
const signRequest = async requestOptions => {
let { accessKeyId, secretAccessKey, sessionToken } = options;
if (!accessKeyId && !secretAccessKey && !sessionToken)
({ accessKeyId, secretAccessKey, sessionToken } = await credentialsChain.resolvePromise());
aws4.sign(requestOptions, { accessKeyId, secretAccessKey, sessionToken });
};
const httpClient = got.extend({
baseUrl: endpoint,
headers: { 'content-type': AWS_JSON },
hooks: { beforeRequest: [signRequest] },
region,
throwHttpErrors: false
});
Object.assign(internal(this), { ...ctx, httpClient });
}
elem,
equals,
filter,
justs,
map,
prop,
props,
pipe,
reject,
} = require('sanctuary');
const main = require('./main.js');
dotenv.config();
const dropboxPaperApi = got.extend({
method: 'POST',
baseUrl: 'https://api.dropbox.com/2/paper/',
json: true,
headers: {
Authorization: `Bearer ${process.env.DROPBOX_API_TOKEN}`,
},
});
const jsonToFrontmatter = json => `---\n${ JSON.stringify(json, null, 2) }\n---\n`;
const isDeletedDoc = pipe([
props(['metaData', 'status', '.tag']),
equals('deleted'),
]);
const {
export default (restURI: string, accessToken?: string) => {
const client = got.extend({
baseUrl: restURI,
headers: {
'user-agent': `@2bad/bitrix`
},
json: true,
hooks: {
beforeRequest: [
addAccessToken(accessToken)
]
}
})
const queue = new Queue({
intervalCap: BITRIX_API_RATE_LIMIT,
interval: BITRIX_API_RATE_INTERVAL
})