Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

clevertap

Package Overview
Dependencies
Maintainers
3
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

clevertap - npm Package Compare versions

Comparing version 1.1.1 to 1.2.0

CHANGELOG.md

52

lib/clevertap-api.js

@@ -1,3 +0,4 @@

const request = require('request'),
querystring = require('querystring');
const REGIONS = require('./regions');
const request = require('request');
const querystring = require('querystring');

@@ -15,16 +16,18 @@ const API_HOSTNAME = "api.clevertap.com";

var CleverTapAPI = function (CleverTapAccountId, CleverTapAccountPasscode) {
if(!CleverTapAccountId) {
const CleverTapAPI = function (CleverTapAccountId, CleverTapAccountPasscode, CleverTapAccountRegion) {
if (!CleverTapAccountId) {
throw new Error("Please provide a CleverTap Account Id");
}
if(!CleverTapAccountPasscode) {
if (!CleverTapAccountPasscode) {
throw new Error("Please provide a CleverTap Account Passcode");
}
if (!REGIONS.regionIsValid(CleverTapAccountRegion)) {
throw new Error("Please provide a valid CleverTap Account Region");
}
this.accountId = CleverTapAccountId;
this.accountPasscode = CleverTapAccountPasscode;
this.apiEndpoint = `https://${API_HOSTNAME}/${API_VERSION}`
this.apiEndpoint = `https://${CleverTapAccountRegion}.${API_HOSTNAME}/${API_VERSION}`;
};

@@ -113,3 +116,3 @@

}
var endpoint = "profile.json";

@@ -120,11 +123,11 @@

}
else if (options.identity) {
endpoint += "?identity="+options.identity;
}
else if (options.objectId) {
endpoint += "?objectId="+options.objectId;
}
this._call(endpoint, options, (res) => {

@@ -141,3 +144,3 @@

return this._fetch("profiles", query, options, callback);
};
};

@@ -147,3 +150,3 @@

return this._fetch("events", query, options, callback);
};
};

@@ -202,16 +205,17 @@

}
batchSize = (batchSize > maxBatchSize) ? maxBatchSize : batchSize;
var fetchNext = () => {
var new_records = null;
const fetchNext = () => {
let endpoint
let new_records = null
if(!cursor) {
var args = {"batch_size":batchSize, "query":JSON.stringify(query)};
const args = {'batch_size': batchSize, 'query': JSON.stringify(query)}
endpoint = `${type}.json?${querystring.stringify(args)}`
} else {
endpoint = `${type}.json?cursor=${cursor}`
}
}

@@ -226,7 +230,7 @@ this._call(endpoint, options, (res) => {

Array.prototype.push.apply(records, new_records);
}
}
} else {
cursor = null;
}
}

@@ -257,3 +261,3 @@ if (cursor) {

method = options.method || "GET";
// add the authentication headers

@@ -260,0 +264,0 @@ headers['X-CleverTap-Account-Id'] = this.accountId;

/**
Copyright (c) 2016 CleverTap

@@ -9,2 +9,3 @@ Released under the MIT license.

const CleverTapAPI = require("./clevertap-api");
const REGIONS = require('./regions');

@@ -19,20 +20,24 @@ const CREATE = "create",

var CleverTap = function (CleverTapAccountId, CleverTapAccountPasscode) {
if(!CleverTapAccountId) {
const CleverTap = function (CleverTapAccountId, CleverTapAccountPasscode, CleverTapAccountRegion) {
if (!CleverTapAccountId) {
throw new Error("Please provide a CleverTap Account Id");
}
if(!CleverTapAccountPasscode) {
if (!CleverTapAccountPasscode) {
throw new Error("Please provide a CleverTap Account Passcode");
}
this.api = new CleverTapAPI(CleverTapAccountId, CleverTapAccountPasscode);
if (!REGIONS.regionIsValid(CleverTapAccountRegion)) {
throw new Error("Please provide a valid CleverTap Account Region");
}
this.api = new CleverTapAPI(CleverTapAccountId, CleverTapAccountPasscode, CleverTapAccountRegion);
};
/**
upload(data, options, callback)
Sends an array of event and/or profile objects to CleverTap
Sends an array of event and/or profile objects to CleverTap

@@ -45,8 +50,8 @@ data: Array

Sample data:
Sample data:
var data = [
{"type":"event",
"identity":"6264372124",
"ts":Math.floor((new Date).getTime()/1000),
"evtName":"choseNewFavoriteFood",
"ts":Math.floor((new Date).getTime()/1000),
"evtName":"choseNewFavoriteFood",
"evtData":{

@@ -57,3 +62,3 @@ "value":"sushi"

{"type":"profile",
{"type":"profile",
"identity":"6264372124",

@@ -65,13 +70,13 @@ "profileData":{

"Email":"peter@foo.com",
},
},
},
];
];
Result format:
{
"status":<success, partial, fail>,
"processed":<count>,
"status":<success, partial, fail>,
"processed":<count>,
"unprocessed": [{"status":"fail", "code":<error code>, "error":<error msg>, "record":<record>}]
}
Sample result:

@@ -83,3 +88,3 @@ {

}
for data sizes > than the specified (or default) batchSize, responses will be an Array of response objects.

@@ -110,3 +115,3 @@

this.api.upload(data, options, (res) => {
this.api.upload(data, options, (res) => {
// if there is only one reponse return response object rather than array

@@ -116,7 +121,7 @@ try {

res = res[0];
}
}
} catch(e) {
// no-op
}
}
resolve(res);

@@ -128,4 +133,4 @@

});
});
});
};

@@ -137,6 +142,6 @@

Retrieve an individual user profile by ID.
Retrieve an individual user profile by ID.
Supported ID values are email, a custom identity value you have set on the profile via the SDKs or the Server API,
or the unique CleverTap objectID used by CleverTap to identify the user profile.
Supported ID values are email, a custom identity value you have set on the profile via the SDKs or the Server API,
or the unique CleverTap objectID used by CleverTap to identify the user profile.
The CleverTap objectID is available via the SDKs as well as displayed in the user profile on the CleverTap dashboard.

@@ -176,3 +181,3 @@

For more see https://support.clevertap.com/server/downloading-profiles-and-actions/#user-profile-by-id
For more see https://support.clevertap.com/server/downloading-profiles-and-actions/#user-profile-by-id

@@ -190,3 +195,3 @@ */

error = "profile requires email, identity or objectId";
}
}

@@ -203,3 +208,3 @@ return new Promise( (resolve, reject) => {

this.api.profile(options, (res) => {
this.api.profile(options, (res) => {

@@ -212,3 +217,3 @@ resolve(res);

});
});
});
};

@@ -228,3 +233,3 @@

Sample queries:
Sample queries:
var query = {

@@ -234,3 +239,3 @@ "event_name":"App Launched",

"to": 20151025
}
}

@@ -249,11 +254,11 @@ var query = {

Sample result:
[
{
"push_token" : "95f98af6ad9a5e714a56c5bf527a78cb1e3eda18d2f23bc8591437d0d8ae71a3" ,
"identity" : "5555555555" ,
[
{
"push_token" : "95f98af6ad9a5e714a56c5bf527a78cb1e3eda18d2f23bc8591437d0d8ae71a3" ,
"identity" : "5555555555" ,
"profileData": {"favoriteFood": "pizza"},
"platformInfo" : [
{ "platform" : "iOS" ,
"objectId" : "-1a063854f83a4c6484285039ecff87cb"} ,
{ "platform" : "Web" ,
"platformInfo" : [
{ "platform" : "iOS" ,
"objectId" : "-1a063854f83a4c6484285039ecff87cb"} ,
{ "platform" : "Web" ,
"objectId" : "a8ffcbc9-a747-4ee3-a791-c5e58ad03097"}

@@ -264,3 +269,3 @@ ]

For more see https://support.clevertap.com/server/downloading-profiles-and-actions/#user-profiles
For more see https://support.clevertap.com/server/downloading-profiles-and-actions/#user-profiles

@@ -287,3 +292,3 @@ */

this.api.profiles(query, options, (res) => {
this.api.profiles(query, options, (res) => {

@@ -296,3 +301,3 @@ resolve(res);

});
});
});
};

@@ -312,3 +317,3 @@

Sample queries:
Sample queries:
var query = {

@@ -318,3 +323,3 @@ "event_name":"App Launched",

"to": 20151025
}
}

@@ -333,25 +338,25 @@ var query = {

Sample result:
[
{
"profile": {
"objectId": "a8ffcbc9-a747-4ee3-a791-c5e58ad03097",
"platform": "Web",
"email": "peter@foo.com",
"profileData": { "favoriteColor" : "blue"},
"identity" : "5555555555",
[
{
"profile": {
"objectId": "a8ffcbc9-a747-4ee3-a791-c5e58ad03097",
"platform": "Web",
"email": "peter@foo.com",
"profileData": { "favoriteColor" : "blue"},
"identity" : "5555555555",
"id": 33
},
"ts": 20151023140416,
},
"ts": 20151023140416,
"event_props": { "value" : "pizza"}
},
{
"profile": {
"objectId": "a8ffcbc9-a747-4ee3-a791-c5e58ad03097",
"platform": "Web",
"email": "peter@foo.com",
"profileData": { "favoriteColor" : "blue"},
"identity": "5555555555",
},
{
"profile": {
"objectId": "a8ffcbc9-a747-4ee3-a791-c5e58ad03097",
"platform": "Web",
"email": "peter@foo.com",
"profileData": { "favoriteColor" : "blue"},
"identity": "5555555555",
"id": 33
},
"ts": 20151024121636,
},
"ts": 20151024121636,
"event_props" : { "value" : "pizza"}

@@ -361,3 +366,3 @@ }

For more see https://support.clevertap.com/server/downloading-profiles-and-actions/#user-actions
For more see https://support.clevertap.com/server/downloading-profiles-and-actions/#user-actions

@@ -384,3 +389,3 @@ */

this.api.events(query, options, (res) => {
this.api.events(query, options, (res) => {

@@ -398,3 +403,3 @@ resolve(res);

/**
Push Notifications

@@ -408,3 +413,3 @@

For info on required payloads and more in general see https://support.clevertap.com/server/send-notifications/push/
For info on required payloads and more in general see https://support.clevertap.com/server/send-notifications/push/

@@ -446,2 +451,4 @@ */

options.method = "POST";
return new Promise( (resolve, reject) => {

@@ -457,3 +464,3 @@ if (error) {

this.api.targets(options, (res) => {
this.api.targets(options, (res) => {

@@ -467,3 +474,3 @@ resolve(res);

});
};
};

@@ -530,11 +537,11 @@

if(!data || typeof(data) !== "object") {
error = `CleverTap.${type}: query must be an object: ${JSON.stringify(data)}`;
}
}
error = `CleverTap.${type}: query must be an object: ${JSON.stringify(data)}`;
}
}
if (type === "profiles") {
if(!data || typeof(data) !== "object") {
error = `CleverTap.${type}: query must be an object: ${JSON.stringify(data)}`;
}
}
error = `CleverTap.${type}: query must be an object: ${JSON.stringify(data)}`;
}
}

@@ -552,20 +559,20 @@ if (type === "upload") {

identity = record.identity || record.FBID || record.GPID || record.objectId;
identity = record.identity || record.FBID || record.GPID || record.objectId;
if(!identity) {
error = `upload record must contain an identity, FBID, GPID or objectId field: ${JSON.stringify(record)}`;
break;
}
error = `upload record must contain an identity, FBID, GPID or objectId field: ${JSON.stringify(record)}`;
break;
}
recordType = record.type;
if(validRecordTypes.indexOf(recordType) === -1) {
error = `CleverTap.${type}: record type must be 'profile' or 'event': ${JSON.stringify(record)}`;
error = `CleverTap.${type}: record type must be 'profile' or 'event': ${JSON.stringify(record)}`;
break;
}
}
if(recordType === "profile") {
profileData = record.profileData;
if(!profileData || typeof(profileData) !== "object") {
error = `CleverTap.${type}: record with type '${recordType}' must contain a 'profileData' object: ${JSON.stringify(record)}`;
error = `CleverTap.${type}: record with type '${recordType}' must contain a 'profileData' object: ${JSON.stringify(record)}`;
break;
}
}
}
}

@@ -575,20 +582,27 @@ if(recordType === "event") {

if(!evtData || typeof(evtData) !== "object") {
error = `CleverTap.${type}: record with type '${recordType}' must contain a 'evtData' object: ${JSON.stringify(record)}`;
error = `CleverTap.${type}: record with type '${recordType}' must contain a 'evtData' object: ${JSON.stringify(record)}`;
break;
}
}
}
}
}
}
}
}
return error;
};
var init = (CleverTapAccountId, CleverTapAccountPasscode) => {
return new CleverTap(CleverTapAccountId, CleverTapAccountPasscode);
const init = (CleverTapAccountId, CleverTapAccountPasscode, CleverTapAccountRegion) => {
if (!CleverTapAccountRegion) {
CleverTapAccountRegion = REGIONS.CLEVERTAP_REGIONS.EUROPE
console.log("CleverTap Account Region not provided; defaulting to Europe (eu1) region");
}
else if (!REGIONS.regionIsValid(CleverTapAccountRegion)) {
throw new Error(`the CleverTap Account Region provided: ${CleverTapAccountRegion} - is invalid`);
}
return new CleverTap(CleverTapAccountId, CleverTapAccountPasscode, CleverTapAccountRegion);
};
module.exports = {
"init":init
REGIONS: REGIONS.CLEVERTAP_REGIONS,
"init": init
};
{
"name": "clevertap",
"version": "1.1.1",
"version": "1.2.0",
"description": "CleverTap API library for node",

@@ -32,3 +32,3 @@ "main": "./lib/clevertap",

"engines": {
"node": ">=4.2.3"
"node": ">=12.13.1"
},

@@ -35,0 +35,0 @@ "devDependencies": {

# clevertap-node
[![npm version](https://badge.fury.io/js/clevertap.svg)](https://badge.fury.io/js/clevertap)
[![CI Status](http://img.shields.io/travis/CleverTap/clevertap-node.svg?style=flat)](https://travis-ci.org/CleverTap/clevertap-node)
[![CI Status](https://app.travis-ci.com/CleverTap/clevertap-node.svg?branch=master)](https://app.travis-ci.com/CleverTap/clevertap-node)

@@ -17,6 +18,12 @@ Fully async Node.js server module for accessing the [CleverTap](https://clevertap.com/) Server API

const CleverTap = require('clevertap');
/**
init the library with your CleverTap Account Id, CleverTap Account Passcode and CleverTap Account Region
Clevertap Account Regions:
EUROPE: 'eu1', // default for most accounts
INDIA: 'in1',
SINGAPORE: 'sg1',
US: 'us1'
*/
const clevertap = CleverTap.init(YOUR_CLEVERTAP_ACCOUNT_ID, YOUR_CLEVERTAP_ACCOUNT_PASSCODE, CleverTap.CLEVERTAP_REGIONS.EUROPE);
// init the library with your CleverTap Account Id and CleverTap Account Passcode
const clevertap = CleverTap.init(YOUR_CLEVERTAP_ACCOUNT_ID, YOUR_CLEVERTAP_ACCOUNT_PASSCODE);
// the library supports both callbacks and Promises

@@ -32,6 +39,6 @@

var query = {"event_name":"choseNewFavoriteFood",
"props":
"props":
[{"name":"value","operator":"contains", "value":"piz"}],
"from": 20150810,
"to": 20151025
"from": 20210101,
"to": 20210701
};

@@ -47,6 +54,4 @@

var query = {"event_name":"choseNewFavoriteFood",
"props":
[{"name":"value","operator":"contains", "value":"piz"}],
"from": 20150810,
"to": 20151025
"from": 20210101,
"to": 20210701
}

@@ -66,4 +71,4 @@

"event_name": "App Launched",
"from": 20160101,
"to": 20160317,
"from": 20210101,
"to": 20210701,
},

@@ -85,3 +90,4 @@ "content":{

"deep_link": "judepereira.com",
"foo": "bar_android"
"foo": "bar_android",
"wzrk_cid":"BRTesting"
}

@@ -91,2 +97,3 @@ }

"devices": [
"android",
"ios"

@@ -102,2 +109,70 @@ ],

//Estimate a target compaigns
var estimatePayload = {
"name": "green freedom",
"when": "now",
//This flag should be add in the the payload for target estimate api
"estimate_only": true,
"where": {
"event_name": "App Launched",
"from": 20210101,
"to": 20210701,
},
"content":{
"title":"Hello!",
"body":"Strictly Green Lantern fans only!",
"platform_specific": {
"ios": {
"deep_link": "judepereira.com",
"sound_file": "judepereira.wav",
"category": "reactive",
"badge_count": 1,
"foo": "bar_ios"
},
"android": {
"background_image": "http://judepereira.com/a.jpg",
"default_sound": true,
"deep_link": "judepereira.com",
"foo": "bar_android",
"wzrk_cid":"BRTesting"
}
}
},
"devices": [
"android",
"ios"
],
}
//callback style
clevertap.targets(clevertap.TARGET_ESTIMATE, estimatePayload, {"debug":1}, (res) => {console.log(res)} );
// or if you prefer Promises
clevertap.targets(clevertap.TARGET_ESTIMATE, estimatePayload, {"debug":1}).then( (res) => {console.log(res)} );
//List all target compaigns in a date range
var listPayload = {"from": 20210101, "to": 20210701}
//callback style
clevertap.targets(clevertap.TARGET_LIST, listPayload, {"debug":1}, (res) => {console.log(res)} );
// or if you prefer Promises
clevertap.targets(clevertap.TARGET_LIST, listPayload, {"debug":1}).then( (res) => {console.log(res)} );
//Stop a specific target compaign
var stopPayload = {"id": 1629904249}
//callback style
clevertap.targets(clevertap.TARGET_STOP, stopPayload, {"debug":1}, (res) => {console.log(res)} );
// or if you prefer Promises
clevertap.targets(clevertap.TARGET_STOP, createPayload, {"debug":1}).then( (res) => {console.log(res)} );
//Resule out a target compaign
var resultPayload = {"id": 1629904249}
//callback style
clevertap.targets(clevertap.TARGET_RESULT, resultPayload, {"debug":1}, (res) => {console.log(res)} );
// or if you prefer Promises
clevertap.targets(clevertap.TARGET_RESULT, resultPayload, {"debug":1}).then( (res) => {console.log(res)} );
```

@@ -104,0 +179,0 @@

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc