How to use the @creditkarma/thrift-server-core.BufferedTransport.receiver function in @creditkarma/thrift-server-core

To help you get started, we’ve selected a few @creditkarma/thrift-server-core 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 guardian / editions / projects / backend / capi / articles.ts View on Github external
}
        if (hasFailed(last)) {
            console.error(last.error)
            throw new Error('Error when spliting CAPI request (second half)')
        }
        const firstArray = Object.entries(first)
        const lastArray = Object.entries(last)
        return fromPairs(firstArray.concat(lastArray))
    }
    console.log('Making CAPI query', endpoint)
    console.log('Debug link:', endpoint.replace(/thrift/g, 'json'))
    const resp = await attempt(fetch(endpoint))
    if (hasFailed(resp)) throw new Error('Could not connect to CAPI.')
    const buffer = await resp.arrayBuffer()

    const receiver: BufferedTransport = BufferedTransport.receiver(
        Buffer.from(buffer),
    )
    const input = new CompactProtocol(receiver)
    const data = SearchResponseCodec.decode(input)
    const results: IContent[] = data.results
    const articlePromises = await Promise.all(
        results.map(result => attempt(parseArticleResult(result, isFromPrint))),
    )

    //If we fail to get an article in a collection we just ignore it and move on.
    articlePromises.forEach(attempt => {
        if (hasFailed(attempt)) {
            console.log('failure when parsing', attempt.error)
        }
    })
    const articleEntries = articlePromises.filter(hasSucceeded)
github guardian / editions / projects / backend / controllers / article.ts View on Github external
export const getArticle = async (path: string): Promise<article> =&gt; {
    const resp = await fetch(url(path))
    const buffer = await resp.arrayBuffer()

    const receiver: BufferedTransport = BufferedTransport.receiver(
        new Buffer(buffer),
    )
    const input = new CompactProtocol(receiver)

    const data = ItemResponseCodec.decode(input)
    const title = data &amp;&amp; data.content &amp;&amp; data.content.webTitle
    if (title == null) throw new Error('Title was undefined!')

    const image =
        data &amp;&amp;
        data.content &amp;&amp;
        data.content.blocks &amp;&amp;
        data.content.blocks.main &amp;&amp;
        data.content.blocks.main.elements &amp;&amp;
        data.content.blocks.main.elements[0].assets &amp;&amp;
        extractImage(data.content.blocks.main.elements[0].assets)</article>