How to use the stanza-shims.fetch function in stanza-shims

To help you get started, we’ve selected a few stanza-shims 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 legastero / stanza / src / plugins / hostmeta.ts View on Github external
ssl: true,
        xrd: true,
        ...opts
    };

    const scheme = config.ssl ? 'https://' : 'http://';

    return promiseAny([
        fetch(`${scheme}${config.host}/.well-known/host-meta.json`).then(async res => {
            if (!res.ok) {
                throw new Error('could-not-fetch-json');
            }

            return res.json();
        }),
        fetch(`${scheme}${config.host}/.well-known/host-meta`).then(async res => {
            if (!res.ok) {
                throw new Error('could-not-fetch-xml');
            }

            const data = await res.text();
            const xml = JXT.parse(data);
            if (xml) {
                return registry.import(xml);
            }
        })
    ]);
}
github legastero / stanza / src / plugins / hostmeta.ts View on Github external
) {
    if (typeof opts === 'string') {
        opts = { host: opts };
    }

    const config = {
        json: true,
        ssl: true,
        xrd: true,
        ...opts
    };

    const scheme = config.ssl ? 'https://' : 'http://';

    return promiseAny([
        fetch(`${scheme}${config.host}/.well-known/host-meta.json`).then(async res => {
            if (!res.ok) {
                throw new Error('could-not-fetch-json');
            }

            return res.json();
        }),
        fetch(`${scheme}${config.host}/.well-known/host-meta`).then(async res => {
            if (!res.ok) {
                throw new Error('could-not-fetch-xml');
            }

            const data = await res.text();
            const xml = JXT.parse(data);
            if (xml) {
                return registry.import(xml);
            }
github legastero / stanza / src / transports / bosh.ts View on Github external
async function retryRequest(
    url: string,
    opts: RequestInit,
    timeout: number,
    allowedRetries: number = 5
): Promise {
    let attempt = 0;
    while (attempt <= allowedRetries) {
        try {
            const resp = await timeoutPromise(fetch(url, opts), timeout * 1000, () => {
                return new Error('Request timed out');
            });
            if (!resp.ok) {
                throw new Error('HTTP Status Error: ' + resp.status);
            }
            return resp.text();
        } catch (err) {
            attempt += 1;
            if (attempt > allowedRetries) {
                throw err;
            }
        }

        await sleep(Math.pow(attempt, 2) * 1000);
    }

stanza-shims

Runtime shims used by StanzaJS for node, browsers, and React Native

MIT
Latest version published 3 years ago

Package Health Score

42 / 100
Full package analysis