0.2.1 • Published 7 years ago

jqllib-fetch v0.2.1

Weekly downloads
4,786
License
ISC
Repository
github
Last release
7 years ago

jqllib-fetch

You have a string containing a Mixpanel JQL query. You want to execute it programatically in Node.

This is a TINY wrapper around request-promises that sets auth headers and request format.

Just do

import * as jqlFetch from 'jqllib-fetch'

jqlFetch.setApiKey("MIXPANEL_SECRET_KEY")

jqlFetch
    .fetch(`return Events(...)...`)    // Returns a Bluebird promise
    .then(events => {
        // Do stuff with your list of events, or whatever your query was
    })

If your JQL is not already wrapped in a "main" function as required by Mixpanel, jqlFetch.fetch will wrap it for you.

jqllib-fetch also plays nicely with jqllib, if you are using TypeScript and want typesafe queries:

import {JQL, MPEvent} from 'jqllib'

const query: JQL<{distinctId: string, events: MPEvent[]}[]> = jqllib.groupedJql(
    ['2016-01-01', '2016-03-01'],
    ['Fantastic Event', 'Fun Event', 'Lil event']
)

jqlFetch
    .fetch(query)
    .then(groups => {
        // do stuff...
    })