Join our webinar on Wednesday, June 26, at 1pm EDTHow Chia Mitigates Risk in the Crypto Industry.Register
Socket
Socket
Sign inDemoInstall

usergrid

Package Overview
Dependencies
6
Maintainers
1
Versions
15
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.10.2 to 0.10.3

.project

5

changelog.md
##Change log
###0.10.3
- Added set / get token methods to accomodate session storage
- Added createUserActivity method to make creating activities for logged in user easier
###0.10.2

@@ -4,0 +9,0 @@

209

lib/usergrid.js

@@ -25,3 +25,3 @@ /**

var Usergrid = {};
Usergrid.SDK_VERSION = '0.10.02';
Usergrid.SDK_VERSION = '0.10.03';

@@ -91,3 +91,3 @@ //authentication type constants

} else if (this.authType === AUTH_APP_USER) {
qs['access_token'] = this.token;
qs['access_token'] = self.getToken();
}

@@ -148,6 +148,6 @@

/**
/*
* Main function for creating new entities - should be called directly.
*
* options object: options {client:client, data:{'type':'collection_type', 'key':'value'}, uuid:uuid}}
* options object: options {data:{'type':'collection_type', 'key':'value'}, uuid:uuid}}
*

@@ -173,3 +173,3 @@ * @method createEntity

/**
/*
* Main function for creating new collections - should be called directly.

@@ -194,3 +194,53 @@ *

/**
/*
* Function for creating new activities for the current user - should be called directly.
*
* //user can be any of the following: "me", a uuid, a username
* Note: the "me" alias will reference the currently logged in user (e.g. 'users/me/activties')
*
* //build a json object that looks like this:
* var options =
* {
* "actor" : {
* "displayName" :"myusername",
* "uuid" : "myuserid",
* "username" : "myusername",
* "email" : "myemail",
* "picture": "http://path/to/picture",
* "image" : {
* "duration" : 0,
* "height" : 80,
* "url" : "http://www.gravatar.com/avatar/",
* "width" : 80
* },
* },
* "verb" : "post",
* "content" : "My cool message",
* "lat" : 48.856614,
* "lon" : 2.352222
* }
*
* @method createEntity
* @public
* @params {string} user // "me", a uuid, or a username
* @params {object} options
* @param {function} callback
* @return {callback} callback(err, data)
*/
Usergrid.Client.prototype.createUserActivity = function (user, options, callback) {
options.type = 'users/'+user+'/activities';
var options = {
client:this,
data:options
}
var entity = new Usergrid.Entity(options);
entity.save(function(err, data) {
if (typeof(callback) === 'function') {
callback(err, entity);
}
});
}
/*
* A private method to get call timing of last call

@@ -208,2 +258,28 @@ */

/*
* A public method to store the OAuth token for later use - uses localstorage if available
*
* @method setToken
* @public
* @params {string} token
* @return none
*/
Usergrid.Client.prototype.setToken = function (token) {
this.token = token;
}
/*
* A public method to get the OAuth token
*
* @method getToken
* @public
* @return {string} token
*/
Usergrid.Client.prototype.getToken = function () {
if (this.token) {
return this.token;
}
return null;
}
/*
* A public method to log in an app user - stores the token for later use

@@ -235,3 +311,3 @@ *

user = new Usergrid.Entity('users', data.user);
self.token = data.access_token;
self.setToken(data.access_token);
}

@@ -269,3 +345,3 @@ if (typeof(callback) === 'function') {

user = new Usergrid.Entity('users', data.user);
self.token = data.access_token;
self.setToken(data.access_token);
}

@@ -287,3 +363,3 @@ if (typeof(callback) === 'function') {

Usergrid.Client.prototype.getLoggedInUser = function (callback) {
if (!this.token) {
if (!this.getToken()) {
callback(true, null, null);

@@ -305,3 +381,7 @@ } else {

} else {
var user = new Usergrid.Entity('users', data.user);
var options = {
client:self,
data:data.entities[0]
}
var user = new Usergrid.Entity(options);
if (typeof(callback) === 'function') {

@@ -315,3 +395,3 @@ callback(err, data, user);

/**
/*
* A public method to test if a user is logged in - does not guarantee that the token is still valid,

@@ -325,3 +405,3 @@ * but rather that one exists

Usergrid.Client.prototype.isLoggedIn = function () {
if (this.token) {
if (this.getToken()) {
return true;

@@ -332,3 +412,3 @@ }

/**
/*
* A public method to log out an app user - clears all user fields from client

@@ -341,3 +421,3 @@ *

Usergrid.Client.prototype.logout = function () {
this.token = null;
this.setToken(null);
}

@@ -382,3 +462,3 @@

/**
/*
* A class to Model a Usergrid Entity.

@@ -395,3 +475,3 @@ * Set the type of entity in the 'data' json object

/**
/*
* gets a specific field or the entire data object. If null or no argument

@@ -412,3 +492,3 @@ * passed, will return all data, else, will return a specific field

/**
/*
* adds a specific key value pair or object to the Entity's data

@@ -439,3 +519,3 @@ * is additive - will not overwrite existing values unless they

/**
/*
* Saves the entity back to the database

@@ -519,3 +599,3 @@ *

/**
/*
* refreshes the entity by making a GET call back to the database

@@ -583,3 +663,3 @@ *

/**
/*
* deletes the entity from the database - will only delete

@@ -626,3 +706,3 @@ * if the object has a valid uuid

/**
/*
* The Collection class models Usergrid Collections. It essentially

@@ -651,50 +731,7 @@ * acts as a container for holding Entity objects, while providing

var self = this;
//get list of collections, see if this one exists
var callOptions = {
method:'GET',
endpoint:''
};
this._client.request(callOptions, function (err, data) {
if (err && self._client.logging) {
console.log('error getting collections - check options passed to client');
if (typeof(callback) === 'function') {
return callback(err, data);
}
} else {
//store collection list
var collections = data.entities[0].metadata.collections;
if ( collections.hasOwnProperty(self._type) ) {
//collection exists, so just fetch
self.fetch(function(err) {
if (typeof(callback) === 'function') {
return callback(err, data);
}
});
} else {
//collection doesn't exist, post first
self._client.request(
{
method:'POST',
endpoint:self._type,
json:{},
qs:self.qs
},
function (err, data) {
if (err && self._client.logging) {
console.log('error: collection not created');
}
if (typeof(callback) === 'function') {
callback(err, data);
}
}
);
}
}
});
//populate the collection
this.fetch(callback);
}
/**
/*
* Populates the collection from the server

@@ -756,3 +793,3 @@ *

/**
/*
* Adds a new Entity to the collection (saves, then adds to the local object)

@@ -782,3 +819,3 @@ *

/**
/*
* Removes the Entity from the collection, then destroys the object on the server

@@ -808,3 +845,3 @@ *

/**
/*
* Looks up an Entity by UUID

@@ -821,4 +858,4 @@ *

data: {
type: this._type,
uuid:uuid
type: this._type,
uuid:uuid
},

@@ -831,3 +868,3 @@ client: this._client

/**
/*
* Returns the first Entity of the Entity list - does not affect the iterator

@@ -846,3 +883,3 @@ *

/**
/*
* Returns the last Entity of the Entity list - does not affect the iterator

@@ -861,3 +898,3 @@ *

/**
/*
* Entity iteration -Checks to see if there is a "next" entity

@@ -880,3 +917,3 @@ * in the list. The first time this method is called on an entity

/**
/*
* Entity iteration - Gets the "next" entity in the list. The first

@@ -899,3 +936,3 @@ * time this method is called on an entity list, or after the method

/**
/*
* Entity iteration - Checks to see if there is a "previous"

@@ -916,3 +953,3 @@ * entity in the list.

/**
/*
* Entity iteration - Gets the "previous" entity in the list.

@@ -932,3 +969,3 @@ *

/**
/*
* Entity iteration - Resets the iterator back to the beginning

@@ -944,3 +981,3 @@ * of the list

/**
/*
* Method to save off the cursor just returned by the last API call

@@ -959,3 +996,3 @@ *

/**
/*
* Resets the paging pointer (back to original page)

@@ -973,3 +1010,3 @@ *

/**
/*
* Paging - checks to see if there is a next page od data

@@ -984,3 +1021,3 @@ *

/**
/*
* Paging - advances the cursor and gets the next

@@ -1005,3 +1042,3 @@ * page of data from the API. Stores returned entities

/**
/*
* Paging - checks to see if there is a previous page od data

@@ -1016,3 +1053,3 @@ *

/**
/*
* Paging - reverts the cursor and gets the previous

@@ -1036,3 +1073,3 @@ * page of data from the API. Stores returned entities

/**
/*
* Tests if the string is a uuid

@@ -1039,0 +1076,0 @@ *

{
"name": "usergrid",
"version": "0.10.2",
"version": "0.10.3",
"description": "A Node.js module for making API calls to App Services (Usergrid) from within Node.js",

@@ -5,0 +5,0 @@ "main": "./lib/usergrid.js",

##Version
Current Version: **0.10.2**
Current Version: **0.10.3**

@@ -123,3 +123,3 @@ See change log:

endpoint:'users/fred',
body:{ newkey:'newvalue' }
body:{ newkey:'newvalue' }
};

@@ -449,3 +449,3 @@ client.request(options, function (err, data) {

###To log a user in
Up to this point, we have shown how you can use the client secret / client id combination to authenticate your calls against the API. For a server-side Node.js app, this may be all you need. However, if you do find that your app requires that you authenticate an individual user, you have several options.
Up to this point, we have shown how you can use the client secret / client id combination to authenticate your calls against the API. For a server-side Node.js app, this may be all you need. However, if you do find that your app requires that you authenticate an individual user, you have several options.

@@ -456,3 +456,3 @@ The first is to use client-side authentication with Ajax. If you want to opt for this method, take a look at our Javascript SDK. The syntax for usage is the same as this Node.js module, so it will be easy to pick up:

The other method is to log the user in server-side. When you log a user in, the API will return an OAuth token for you to use for calls to the API on the user's behalf. Once that token is returned, you can either make a new client just for the user, or change the auth method on the existing client. These methods are described below:
The other method is to log the user in server-side. When you log a user in, the API will return an OAuth token for you to use for calls to the API on the user's behalf. Once that token is returned, you can either make a new client just for the user, or change the auth method on the existing client. These methods are described below:

@@ -521,7 +521,7 @@

To recap, once a user has been logged in, and an OAuth token has been acquired, use one of the two methods to make calls to the API:
To recap, once a user has been logged in, and an OAuth token has been acquired, use one of the two methods to make calls to the API:
1. Use the same client object and change auth types before each call
1. Use the same client object and change auth types before each call
2. Grab the token and make a new client object specifically for user calls.
2. Grab the token and make a new client object specifically for user calls.

@@ -528,0 +528,0 @@ Either method will work.

SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc