Flow.js (javascript processing)


Overview


flow.js is our server side javascript processing environment. It gives you a library under the Flow namespace. It also executes your code on our servers, ensuring that your code executes safely–both for you and for everyone else on our platform.

flow.js provides methods for CRUD operations on select Flow domain objects from within tracks. These methods are available in the global namespace 'Flow'. The 'Flow' namespace provides 'find' and 'get' under the subnamespaces Flow, Drop, and Track. Drop also includes 'aggregate', 'findOne', and 'findFHash' methods.

The Flow namespace also houses a custom error object, Flow.Error, which is thrown when a fatal error is encountered during the invocation of certain methods. Flow.Error objects have two properties, "message" and "details". "message" is a string value that represents the general cause of error. "details" is an array of strings that represent more specific information relating to the cause of error.

Processing Environment


The environment that executes your code in strict mode, a restricted subset of javascript. Generally, this shouldn't change that much about how you use javascript. But, it does change some things. Most noticeably, you should avoid declaring global variables (use var x = 1 instead of just simply x = 1). For more information about strict mode, I'd recommend reading the Mozilla Developer Network article.

We do not support most features of ECMAScript 6. We also disallow the use of eval.

Lodash


Our environment comes preloaded with lodash. If you're not familiar with lodash, you can read the documentation for our version.

Generally, it provides you with a lot of easy methods that you wish javascript had, but that it doesn't.

Drop Find


Flow.Drop.find(flowId, options)

Arguments

  • flowId - the string value of the flow's id
  • options - an optional object literal of query options:
    • filter - a filter string, for more info see filters
    • start - start index of the search, integer, default value 0
    • limit - maximum response size, integer, default value 20
    • sort - string representation of the member key to sort the results over, default value creationDate
    • order - string, available options are 'asc' and 'desc', default value desc

Return

returns an array of json representations of the matching Drops

Throws

throws an instance of Flow.Error

Drop FindOne


Flow.Drop.findOne(flowId, options)

Takes the same parameters as Flow.Drop.find, but returns only first result. Value returned as json representation of Drop.

Drop FindFHash


Function allows for referencing a particular Drop by a unique hash value. See FHashes for further detail.

Flow Find


Flow.Flow.find(options)

Arguments

  • options - see below:
    • filter - a filter string, for more info see filters
    • start - start index of the search, integer, default value 0
    • limit - maximum response size, integer, default value 20
    • sort - string representation of the member key to sort the results over, default value creationDate
    • order - string, available options are 'asc' and 'desc', default value desc

Return

returns an array of json representations of the matching Flows

Throws

throws an instance of Flow.Error

Track Find


Flow.Track.find(options)

Arguments

  • options - see below:
    • filter - a filter string, for more info see filters
    • start - start index of the search, integer, default value 0
    • limit - maximum response size, integer, default value 20
    • sort - string representation of the member key to sort the results over, default value creationDate
    • order - string, available options are 'asc' and 'desc', default value desc

Return

returns an array of json representations of the matching Flows

Throws

throws an instance of Flow.Error

Drop Get


Flow.Drop.get(flowId, dropId)

Arguments

  • flowId - the string value of the Flow's Id
  • dropId - the string value of the Drop's Id

Return

returns the json representation of the Drop

Throws

throws an instance of Flow.Error

Flow Get


Flow.Flow.get(flowId)

Arguments

  • flowId - the string value of the Flow's Id

Return

returns the json representation of the Flow

Throws

throws an instance of Flow.Error

Track Get


Flow.Track.get(trackId)

Arguments

  • trackId - the string value of the Track's Id

Return

returns the json representation of the Track

Throws

throws an instance of Flow.Error

Drop Aggregate


Flow.Drop.aggregate(flowId, options)

Usage of aggregate is explained at length at Drop Aggregate

Example Usage

{
  "filter":"EXISTS cpu_temp",
  "rules": {"x":"cpu_temp > 50"},
  "groupBy":["$month"],
  "output":["$avg:cpu_temp","$min:cpu_temp","$max:cpu_temp","$avg:x","$count"],
  "sorts":["$avg:x:desc", "$avg:cpu_temp:asc"]
}

HTTP GET (webhook)


Flow.Http.get(url, headers)

Arguments

  • url - url to GET
  • headers - a mapping of header names and values

Return

returns a response object with the following keys:

  • headers - (map of strings)
  • status - HTTP status code (integer)
  • message - HTTP status message (string)
  • contentType - (string)
  • content - response body (string)

Throws

throws an instance of Flow.Error

HTTP POST (webhook)


Flow.Http.post(url, headers, data)

Arguments

  • url - url to POST
  • headers - a mapping of header names and values
  • data - the POST body

Return

returns a response object with the following keys:

  • headers - (map of strings)
  • status - HTTP status code (integer)
  • message - HTTP status message (string)
  • contentType - (string)
  • content - response body (string)

Throws

throws an instance of Flow.Error

HTTP PUT (webhook)


Flow.Http.put(url, headers, data)

Arguments

  • url - url to PUT
  • headers - a mapping of header names and values
  • data - the PUT body

Return

returns a response object with the following keys:

  • headers - (map of strings)
  • status - HTTP status code (integer)
  • message - HTTP status message (string)
  • contentType - (string)
  • content - response body (string)

Throws

throws an instance of Flow.Error

HTTP DELETE (webhook)


`Flow.Http.delete(url, headers)

Arguments

  • url - url to DELETE
  • headers - a mapping of header names and values

Return

returns a response object with the following keys:

  • headers - (map of strings)
  • status - HTTP status code (integer)
  • message - HTTP status message (string)
  • contentType - (string)
  • content - response body (string)

Throws

throws an instance of Flow.Error