How to use the @hint/utils-network.requestAsync function in @hint/utils-network

To help you get started, we’ve selected a few @hint/utils-network examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github webhintio / hint / packages / hint-sri / src / hint.ts View on Github external
if (!requestAsync && !response.body.content) {
            // Stop the validations.
            return false;
        }

        if (!requestAsync) {
            return true;
        }

        /* If the content already exists, we don't need to download it. */
        if (response.body.content) {
            return true;
        }

        try {
            response.body.content = await requestAsync({
                gzip: true,
                method: 'GET',
                rejectUnauthorized: false,
                url: resource
            });

            return true;
        } catch (e) {
            debug(`Error accessing ${resource}. ${JSON.stringify(e)}`);

            this.context.report(
                urls.final,
                getMessage('canNotGetResource', this.context.language, resource),
                { element, severity: Severity.error }
            );
github webhintio / hint / packages / hint-no-vulnerable-javascript-libraries / src / hint.ts View on Github external
/* istanbul ignore if */
            if (process.env.webpack) { // eslint-disable-line no-process-env
                return require('./snyk-snapshot.json');
            }

            try {
                const snykDBPath = require.resolve('./snyk-snapshot.json');
                const snykStat = await promisify(fs.stat)(snykDBPath);
                const modified = new Date(snykStat.mtime).getTime();

                // We check if the file is older than 24h to update it
                /* istanbul ignore if */
                if (now - modified > oneDay) {
                    debug('snkyDB is older than 24h.');
                    debug('Updating snykDB');
                    const res = await requestAsync('https://snyk.io/partners/api/v2/vulndb/clientside.json');

                    await writeFileAsync(snykDBPath, res);
                }
            } catch (e) /* istanbul ignore next */ {
                debug(e);
                debug(`Error loading snyk's data`);
            }

            return require('./snyk-snapshot.json');
        };