Airship Node.js
Installation
npm install --save airship-nodejs
Usage
import Airship from "airship-nodejs"
// Create an instance with apiKey and envKey
let airship = new Airship({apiKey: <apiKey>, envKey: <envKey>})
// Should be used as a singleton
// e.g.,
// let airship = new Airship({apiKey: "r9b72kqdh1wbzkpkf7gntwfapqoc26bl", envKey: "nxmqp35umrd3djth"})
// Initialize the instance, returns a Promise.
airship.init()
// Define your object
let object = {
type: "User", // "type" starts with a capital letter "[U]ser", "[H]ome", "[C]ar". If omitted, it will default to "User"
id: "1234", // "id" must be a string or integer
displayName: "ironman@stark.com" // must be a string. If omitted, the SDK will use the same value as "id" (converted to a string)
}
// The most compact form can be:
let object = {
id: 1234
}
// as this will translate into:
let object = {
type: "User",
id: "1234",
displayName: "1234"
}
airship.isEnabled("bitcoin-pay", object) // Does the object have the feature "bitcoin-pay"?
airship.getVariation("bitcoin-pay", object) // Get the variation associated with a multi-variate flag
airship.isEligible("bitcoin-pay", object)
// Returns true if the object can potentially receive the feature via sampling
// or is already receiving the feature.
// Note: It may take up to a minute for objects gated to show up on our web app.
Attributes (for complex targeting)
// Define your object with an attributes dictionary of key-value pairs.
// Values must be a string, a number, or a boolean. null values are not accepted.
// For date or datetime string value, use iso8601 format.
let object = {
type: "User",
id: "1234",
displayName: "ironman@stark.com",
attributes: {
tShirtSize: "M",
dateCreated: "2018-02-18",
timeConverted: "2018-02-20T21:54:00.630815+00:00",
ownsProperty: true,
age: 39
}
}
// Now in app.airshiphq.com, you can target this particular user using its
// attributes
Group (for membership-like cascading behavior)
// An object can be a member of a group.
// The structure of a group object is just like that of the base object.
let object = {
type: "User",
id: "1234",
displayName: "ironman@stark.com",
attributes: {
tShirtSize: "M",
dateCreated: "2018-02-18",
timeConverted: "2018-02-20T21:54:00.630815+00:00",
ownsProperty: true,
age: 39
},
group: {
type: "Club",
id: "5678",
displayName: "SF Homeowners Club",
attributes: {
founded: "2016-01-01",
active: true
}
}
}
// Inheritance of values `isEnabled`, `getVariation`, and `isEligible` works as follows:
// 1. If the group is enabled, but the base object is not,
// then the base object will inherit the values `isEnabled`, `getVariation`, and
// `isEligible` of the group object.
// 2. If the base object is explicitly blacklisted, then it will not inherit.
// 3. If the base object is not given a variation in rule-based variation assignment,
// but the group is and both are enabled, then the base object will inherit
// the variation of the group's.
// You can ask questions about the group directly (use the `isGroup` flag):
let object = {
isGroup: true,
type: "Club",
id: "5678",
displayName: "SF Homeowners Club",
attributes: {
founded: "2016-01-01",
active: true
}
}
airship.isEnabled("bitcoin-pay", object)