Comparing version 1.1.0 to 1.2.0
@@ -27,2 +27,6 @@ (function() { | ||
modelKey: 'description' | ||
}), | ||
'readOnly': Attributes.Boolean({ | ||
modelKey: 'readOnly', | ||
jsonKey: 'read_only' | ||
}) | ||
@@ -29,0 +33,0 @@ }); |
@@ -118,2 +118,5 @@ (function() { | ||
DeltaStream.prototype.close = function() { | ||
clearTimeout(this.timeoutId); | ||
delete this.timeoutId; | ||
this.restartBackoff.reset(); | ||
if (this.request) { | ||
@@ -120,0 +123,0 @@ this.request.abort(); |
(function() { | ||
var Attributes, Contact, Draft, File, Message, Promise, _, | ||
bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }, | ||
extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }, | ||
@@ -22,2 +23,3 @@ hasProp = {}.hasOwnProperty; | ||
function Draft() { | ||
this.save = bind(this.save, this); | ||
return Draft.__super__.constructor.apply(this, arguments); | ||
@@ -28,24 +30,20 @@ } | ||
Draft.prototype.save = function(callback) { | ||
Draft.prototype.toJSON = function() { | ||
var json; | ||
json = Draft.__super__.toJSON.apply(this, arguments); | ||
json.file_ids = this.fileIds(); | ||
if (this.draft) { | ||
json.object = 'draft'; | ||
} | ||
return json; | ||
}; | ||
Draft.prototype.save = function(params, callback) { | ||
if (params == null) { | ||
params = {}; | ||
} | ||
if (callback == null) { | ||
callback = null; | ||
} | ||
return this.connection.request({ | ||
method: this.id ? 'PUT' : 'POST', | ||
body: this.toJSON(), | ||
path: this.id ? "/n/" + this.namespaceId + "/drafts/" + this.id : "/n/" + this.namespaceId + "/drafts" | ||
}).then((function(_this) { | ||
return function(json) { | ||
_this.fromJSON(json); | ||
if (callback) { | ||
callback(null, _this); | ||
} | ||
return Promise.resolve(_this); | ||
}; | ||
})(this))["catch"](function(err) { | ||
if (callback) { | ||
callback(err); | ||
} | ||
return Promise.reject(err); | ||
}); | ||
return this._save(params, callback); | ||
}; | ||
@@ -52,0 +50,0 @@ |
@@ -59,10 +59,31 @@ (function() { | ||
Event.prototype.save = function(callback) { | ||
Event.prototype.save = function(params, callback) { | ||
if (params == null) { | ||
params = {}; | ||
} | ||
if (callback == null) { | ||
callback = null; | ||
} | ||
return this._save(params, callback); | ||
}; | ||
Event.prototype.fromJSON = function(json) { | ||
Event.__super__.fromJSON.call(this, json); | ||
if (this.when != null) { | ||
this.start = this.when.start_time || new Date(this.when.start_date).getTime() / 1000.0 || this.when.time; | ||
this.end = this.when.end_time || new Date(this.when.end_date).getTime() / 1000.0 + (60 * 60 * 24 - 1) || this.when.time; | ||
delete this.when.object; | ||
} | ||
return this; | ||
}; | ||
Event.prototype.rsvp = function(status, comment, callback) { | ||
return this.connection.request({ | ||
method: this.id ? 'PUT' : 'POST', | ||
body: this.toJSON(), | ||
path: this.id ? "/n/" + this.namespaceId + "/events/" + this.id : "/n/" + this.namespaceId + "/events" | ||
method: 'POST', | ||
body: { | ||
'event_id': this.id, | ||
'status': status, | ||
'comment': comment | ||
}, | ||
path: "/n/" + this.namespaceId + "/send-rsvp" | ||
}).then((function(_this) { | ||
@@ -84,12 +105,2 @@ return function(json) { | ||
Event.prototype.fromJSON = function(json) { | ||
Event.__super__.fromJSON.call(this, json); | ||
if (this.when != null) { | ||
this.start = this.when.start_time || new Date(this.when.start_date).getTime() / 1000.0 || this.when.time; | ||
this.end = this.when.end_time || new Date(this.when.end_date).getTime() / 1000.0 + (60 * 60 * 24 - 1) || this.when.time; | ||
delete this.when.object; | ||
} | ||
return this; | ||
}; | ||
return Event; | ||
@@ -96,0 +107,0 @@ |
(function() { | ||
var Attributes, Contact, File, Message, RestfulModel, _, | ||
var Attributes, Contact, File, Folder, Label, Message, RestfulModel, _, | ||
bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }, | ||
extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }, | ||
@@ -16,2 +17,6 @@ hasProp = {}.hasOwnProperty; | ||
Label = require('./folder').Label; | ||
Folder = require('./folder').Folder; | ||
module.exports = Message = (function(superClass) { | ||
@@ -50,2 +55,6 @@ extend(Message, superClass); | ||
}), | ||
'starred': Attributes.Boolean({ | ||
queryable: true, | ||
modelKey: 'starred' | ||
}), | ||
'unread': Attributes.Boolean({ | ||
@@ -74,2 +83,10 @@ queryable: true, | ||
queryable: true | ||
}), | ||
'folder': Attributes.Object({ | ||
modelKey: 'folder', | ||
itemClass: Folder | ||
}), | ||
'labels': Attributes.Collection({ | ||
modelKey: 'labels', | ||
itemClass: Label | ||
}) | ||
@@ -79,2 +96,3 @@ }); | ||
function Message() { | ||
this.save = bind(this.save, this); | ||
Message.__super__.constructor.apply(this, arguments); | ||
@@ -89,12 +107,2 @@ this.body || (this.body = ""); | ||
Message.prototype.toJSON = function() { | ||
var json; | ||
json = Message.__super__.toJSON.apply(this, arguments); | ||
json.file_ids = this.fileIds(); | ||
if (this.draft) { | ||
json.object = 'draft'; | ||
} | ||
return json; | ||
}; | ||
Message.prototype.fromJSON = function(json) { | ||
@@ -138,2 +146,37 @@ var file, i, len, ref, ref1; | ||
Message.prototype.saveRequestBody = function() { | ||
var json, label; | ||
if (this.constructor.name === 'Draft') { | ||
return Message.__super__.saveRequestBody.apply(this, arguments); | ||
} | ||
json = {}; | ||
if (this.labels != null) { | ||
json['labels'] = (function() { | ||
var i, len, ref, results; | ||
ref = this.labels; | ||
results = []; | ||
for (i = 0, len = ref.length; i < len; i++) { | ||
label = ref[i]; | ||
results.push(label.id); | ||
} | ||
return results; | ||
}).call(this); | ||
} else if (this.folder != null) { | ||
json['folder'] = this.folder.id; | ||
} | ||
json['starred'] = this.starred; | ||
json['unread'] = this.unread; | ||
return json; | ||
}; | ||
Message.prototype.save = function(params, callback) { | ||
if (params == null) { | ||
params = {}; | ||
} | ||
if (callback == null) { | ||
callback = null; | ||
} | ||
return this._save(params, callback); | ||
}; | ||
return Message; | ||
@@ -140,0 +183,0 @@ |
(function() { | ||
var Attributes, Calendar, Contact, Delta, Draft, Event, File, Message, Namespace, RestfulModel, RestfulModelCollection, Tag, Thread, _, | ||
var Attributes, Calendar, Contact, Delta, Draft, Event, File, Folder, Label, Message, Namespace, RestfulModel, RestfulModelCollection, Tag, Thread, _, | ||
extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }, | ||
@@ -28,2 +28,6 @@ hasProp = {}.hasOwnProperty; | ||
Label = require('./folder').Label; | ||
Folder = require('./folder').Folder; | ||
Attributes = require('./attributes'); | ||
@@ -63,2 +67,4 @@ | ||
this.deltas = new Delta(this.connection, this.id); | ||
this.labels = new RestfulModelCollection(Label, this.connection, this.id); | ||
this.folders = new RestfulModelCollection(Folder, this.connection, this.id); | ||
this; | ||
@@ -76,2 +82,6 @@ } | ||
Namespace.prototype.folder = function() { | ||
return new Folder(this.connection, this.id); | ||
}; | ||
return Namespace; | ||
@@ -78,0 +88,0 @@ |
@@ -185,4 +185,7 @@ (function() { | ||
RestfulModelCollection.prototype["delete"] = function(itemOrId, callback) { | ||
RestfulModelCollection.prototype["delete"] = function(itemOrId, params, callback) { | ||
var id; | ||
if (params == null) { | ||
params = {}; | ||
} | ||
if (callback == null) { | ||
@@ -192,4 +195,9 @@ callback = null; | ||
id = (itemOrId != null ? itemOrId.id : void 0) != null ? itemOrId.id : itemOrId; | ||
if (_.isFunction(params)) { | ||
callback = params; | ||
params = {}; | ||
} | ||
return this.connection.request({ | ||
method: 'DELETE', | ||
qs: params, | ||
path: (this.path()) + "/" + id | ||
@@ -196,0 +204,0 @@ }).then(function() { |
(function() { | ||
var Attributes, Promise, RestfulModel; | ||
var Attributes, Promise, RestfulModel, _; | ||
@@ -8,2 +8,4 @@ Attributes = require('./attributes'); | ||
_ = require('underscore'); | ||
module.exports = RestfulModel = (function() { | ||
@@ -70,2 +72,6 @@ RestfulModel.attributes = { | ||
RestfulModel.prototype.saveRequestBody = function() { | ||
return this.toJSON(); | ||
}; | ||
RestfulModel.prototype.toString = function() { | ||
@@ -75,2 +81,34 @@ return JSON.stringify(this.toJSON()); | ||
RestfulModel.prototype._save = function(params, callback) { | ||
if (params == null) { | ||
params = {}; | ||
} | ||
if (callback == null) { | ||
callback = null; | ||
} | ||
if (_.isFunction(params)) { | ||
callback = params; | ||
params = {}; | ||
} | ||
return this.connection.request({ | ||
method: this.id ? 'PUT' : 'POST', | ||
body: this.saveRequestBody(), | ||
qs: params, | ||
path: this.id ? "/n/" + this.namespaceId + "/" + this.constructor.collectionName + "/" + this.id : "/n/" + this.namespaceId + "/" + this.constructor.collectionName | ||
}).then((function(_this) { | ||
return function(json) { | ||
_this.fromJSON(json); | ||
if (callback) { | ||
callback(null, _this); | ||
} | ||
return Promise.resolve(_this); | ||
}; | ||
})(this))["catch"](function(err) { | ||
if (callback) { | ||
callback(err); | ||
} | ||
return Promise.reject(err); | ||
}); | ||
}; | ||
return RestfulModel; | ||
@@ -77,0 +115,0 @@ |
(function() { | ||
var Attributes, Contact, RestfulModel, Tag, Thread, _, | ||
var Attributes, Contact, Folder, Label, RestfulModel, Tag, Thread, _, | ||
bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }, | ||
@@ -17,2 +17,6 @@ extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }, | ||
Label = require('./folder').Label; | ||
Folder = require('./folder').Folder; | ||
module.exports = Thread = (function(superClass) { | ||
@@ -23,2 +27,3 @@ extend(Thread, superClass); | ||
this.tagIds = bind(this.tagIds, this); | ||
this.save = bind(this.save, this); | ||
this.fromJSON = bind(this.fromJSON, this); | ||
@@ -41,2 +46,6 @@ return Thread.__super__.constructor.apply(this, arguments); | ||
}), | ||
'starred': Attributes.Boolean({ | ||
queryable: true, | ||
modelKey: 'starred' | ||
}), | ||
'tags': Attributes.Collection({ | ||
@@ -55,2 +64,10 @@ queryable: true, | ||
jsonKey: 'last_message_timestamp' | ||
}), | ||
'labels': Attributes.Collection({ | ||
modelKey: 'labels', | ||
itemClass: Label | ||
}), | ||
'folder': Attributes.Object({ | ||
modelKey: 'folder', | ||
itemClass: Folder | ||
}) | ||
@@ -65,2 +82,34 @@ }); | ||
Thread.prototype.saveRequestBody = function() { | ||
var json, label; | ||
json = {}; | ||
if (this.labels != null) { | ||
json['labels'] = (function() { | ||
var i, len, ref, results; | ||
ref = this.labels; | ||
results = []; | ||
for (i = 0, len = ref.length; i < len; i++) { | ||
label = ref[i]; | ||
results.push(label.id); | ||
} | ||
return results; | ||
}).call(this); | ||
} else if (this.folder != null) { | ||
json['folder'] = this.folder.id; | ||
} | ||
json['starred'] = this.starred; | ||
json['unread'] = this.unread; | ||
return json; | ||
}; | ||
Thread.prototype.save = function(params, callback) { | ||
if (params == null) { | ||
params = {}; | ||
} | ||
if (callback == null) { | ||
callback = null; | ||
} | ||
return this._save(params, callback); | ||
}; | ||
Thread.prototype.tagIds = function() { | ||
@@ -67,0 +116,0 @@ return _.map(this.tags, function(tag) { |
{ | ||
"name": "nylas", | ||
"version": "1.1.0", | ||
"version": "1.2.0", | ||
"description": "A NodeJS wrapper for the Nylas REST API for Email, Contacts and Calendar", | ||
@@ -5,0 +5,0 @@ "main": "lib/nylas.js", |
@@ -39,3 +39,3 @@ Nylas Node.js Bindings | ||
```javascript | ||
Nylas.with(accessToken).namespaces.list({}, function(namespaces){ | ||
Nylas.with(accessToken).namespaces.list({}, function(err, namespaces){ | ||
console.log(namespaces.length); | ||
@@ -153,3 +153,3 @@ }); | ||
namespace.threads.forEach({tag: 'unread', from: 'no-reply@sentry.com'}, function(thread) { | ||
namespace.threads.forEach({tag: 'unread', from: 'no-reply@sentry.com'}, function(err, thread) { | ||
console.log(thread.subject); | ||
@@ -168,2 +168,45 @@ }, function (err) { | ||
Folders and labels | ||
----- | ||
The new folders and labels API replaces the now deprecated Tags API. It allows you to apply Gmail labels to whole threads or individual messages and, for providers other than Gmail, to move threads and messages between folders. | ||
```javascript | ||
// List the labels for this account | ||
namespace.labels.list({}).then(function(labels) { | ||
console.log(label.displayName); | ||
console.log(label.id); | ||
}) | ||
// The same, with folders. | ||
namespace.folders.list({}).then(function(folders) { | ||
console.log(folder.displayName); | ||
console.log(folder.id); | ||
}) | ||
// Create a folder | ||
fld = ns.folders.build({ displayName: 'Reminders'}); | ||
fld.save(); | ||
// Add the 'Junk Email' label to a thread. | ||
var label = undefined; | ||
namespace.labels.list({}).then(function(labels) { | ||
for(var i = 0; i < labels.length; i++) { | ||
label = labels[i]; | ||
if (label.displayName == 'Junk Email') { | ||
break; | ||
} | ||
} | ||
ns.threads.list({}, function(err, threads) { | ||
var thread = threads[0]; | ||
thread.labels.push(label); | ||
thread.save(); | ||
}) | ||
// Note that Folders and Labels are absolutely identical from the standpoint of the SDK. | ||
// The only difference is that a message can have many labels but only a single folder. | ||
``` | ||
Creating and Sending Drafts | ||
@@ -209,3 +252,3 @@ ------ | ||
namespace.deltas.generateCursor(timestampMs, function(cursor) { | ||
namespace.deltas.generateCursor(timestampMs, function(error, cursor) { | ||
@@ -237,6 +280,34 @@ // Save inital cursor. | ||
Interacting with Events | ||
---- | ||
```javascript | ||
// Create an event and send an invite. | ||
// The Nylas API supports sending invites/updates to the event's participants. | ||
// To do this we need to set the 'notify_participants' parameter to true. | ||
var ev = namespace.events.build({ | ||
title: 'Out of time', | ||
calendarId: 'c4y597l3adg8mskfqxxns8hsj', | ||
when: {'start_time': 1437500000, 'end_time': 1437501600}, | ||
participants: [{email: 'karim@nylas.com', name: "Karim Hamidou"}] | ||
}); | ||
ev.save({'sendNotifications': true}, function(err, event) { | ||
console.log('Sent an invite to the participants'); | ||
}); | ||
// RSVP to an invite. Note that you can only RSVP to invites found in the | ||
// "Emailed events" calendar. | ||
ns.events.find('30xunbe3033d44kip9bnau5ph').then(function(ev) { | ||
ev.rsvp('maybe', 'I may attend this event').then(function(ev) { | ||
console.log('RSVP sent!'); | ||
}); | ||
}); | ||
``` | ||
Contributing | ||
---- | ||
We'd love your help making the Nylas Node.js bindings better. Join the Google Group for project updates and feature discussion. We also hang out in #nylas on irc.freenode.net, or you can email support@nylas.com. | ||
We'd love your help making the Nylas Node.js bindings better. Join the Google Group for project updates and feature discussion. We also hang out on the [Nylas community Slack channel](http://nylas-slack-invite.heroku.com/), or you can email support@nylas.com. | ||
@@ -247,2 +318,2 @@ Please sign the [Contributor License Agreement](https://www.nylas.com/cla.html) before submitting pull requests. (It's similar to other projects, like NodeJS or Meteor.) | ||
`npm test` | ||
`npm test` |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
153965
66
1793
314
1