nylas 6.2.2 → 6.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/config.d.ts CHANGED
@@ -9,6 +9,7 @@ export declare type NylasConfig = {
9
9
  };
10
10
  export declare type AuthenticateUrlConfig = {
11
11
  redirectURI: string;
12
+ redirectOnError?: boolean;
12
13
  loginHint?: string;
13
14
  state?: string;
14
15
  provider?: string;
@@ -64,10 +64,12 @@ export declare class CalendarConsecutiveAvailability extends Model implements Ca
64
64
  }
65
65
  export declare type CalendarAvailabilityProperties = {
66
66
  timeSlots: TimeSlotProperties[];
67
+ order?: string[];
67
68
  };
68
69
  export default class CalendarAvailability extends Model implements CalendarAvailabilityProperties {
69
70
  object: string;
70
71
  timeSlots: TimeSlot[];
72
+ order?: string[];
71
73
  static attributes: Record<string, Attribute>;
72
74
  constructor(props?: CalendarAvailabilityProperties);
73
75
  }
@@ -112,6 +112,9 @@ var CalendarAvailability = /** @class */ (function (_super) {
112
112
  jsonKey: 'time_slots',
113
113
  itemClass: free_busy_1.TimeSlot,
114
114
  }),
115
+ order: attributes_1.default.StringList({
116
+ modelKey: 'order',
117
+ }),
115
118
  };
116
119
  return CalendarAvailability;
117
120
  }(model_1.default));
@@ -67,8 +67,8 @@ var CalendarRestfulModelCollection = /** @class */ (function (_super) {
67
67
  callback(null, json);
68
68
  }
69
69
  var freeBusy = [];
70
- for (var _i = 0, _a = JSON.parse(json); _i < _a.length; _i++) {
71
- var fb = _a[_i];
70
+ for (var _i = 0, json_1 = json; _i < json_1.length; _i++) {
71
+ var fb = json_1[_i];
72
72
  freeBusy.push(new free_busy_1.default().fromJSON(fb));
73
73
  }
74
74
  return Promise.resolve(freeBusy);
@@ -7,6 +7,7 @@ export declare type DraftProperties = MessageProperties & {
7
7
  rawMime?: string;
8
8
  replyToMessageId?: string;
9
9
  version?: number;
10
+ fileIdsToAttach?: string[];
10
11
  };
11
12
  export default class Draft extends Message implements DraftProperties {
12
13
  rawMime?: string;
@@ -20,12 +20,14 @@ export declare type TimeSlotProperties = {
20
20
  status: string;
21
21
  startTime: number;
22
22
  endTime: number;
23
+ emails?: string[];
23
24
  };
24
25
  export declare class TimeSlot extends Model implements TimeSlotProperties {
25
26
  object: string;
26
27
  status: string;
27
28
  startTime: number;
28
29
  endTime: number;
30
+ emails?: string[];
29
31
  static attributes: Record<string, Attribute>;
30
32
  constructor(props?: TimeSlotProperties);
31
33
  }
@@ -66,6 +66,9 @@ var TimeSlot = /** @class */ (function (_super) {
66
66
  modelKey: 'endTime',
67
67
  jsonKey: 'end_time',
68
68
  }),
69
+ emails: attributes_1.default.StringList({
70
+ modelKey: 'emails',
71
+ }),
69
72
  };
70
73
  return TimeSlot;
71
74
  }(model_1.default));
@@ -0,0 +1,9 @@
1
+ import RestfulModelCollection from './restful-model-collection';
2
+ import JobStatus from './job-status';
3
+ import NylasConnection from '../nylas-connection';
4
+ export default class JobStatusRestfulModelCollection extends RestfulModelCollection<JobStatus> {
5
+ connection: NylasConnection;
6
+ modelClass: typeof JobStatus;
7
+ constructor(connection: NylasConnection);
8
+ protected createModel(json: Record<string, unknown>): JobStatus;
9
+ }
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+ var __extends = (this && this.__extends) || (function () {
3
+ var extendStatics = function (d, b) {
4
+ extendStatics = Object.setPrototypeOf ||
5
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
+ function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
7
+ return extendStatics(d, b);
8
+ };
9
+ return function (d, b) {
10
+ extendStatics(d, b);
11
+ function __() { this.constructor = d; }
12
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
13
+ };
14
+ })();
15
+ var __importDefault = (this && this.__importDefault) || function (mod) {
16
+ return (mod && mod.__esModule) ? mod : { "default": mod };
17
+ };
18
+ Object.defineProperty(exports, "__esModule", { value: true });
19
+ var restful_model_collection_1 = __importDefault(require("./restful-model-collection"));
20
+ var job_status_1 = __importDefault(require("./job-status"));
21
+ var outbox_job_status_1 = __importDefault(require("./outbox-job-status"));
22
+ var JobStatusRestfulModelCollection = /** @class */ (function (_super) {
23
+ __extends(JobStatusRestfulModelCollection, _super);
24
+ function JobStatusRestfulModelCollection(connection) {
25
+ var _this = _super.call(this, job_status_1.default, connection) || this;
26
+ _this.connection = connection;
27
+ _this.modelClass = job_status_1.default;
28
+ return _this;
29
+ }
30
+ JobStatusRestfulModelCollection.prototype.createModel = function (json) {
31
+ if (json['object'] && json['object'] === 'message') {
32
+ return new outbox_job_status_1.default(this.connection).fromJSON(json);
33
+ }
34
+ return new this.modelClass(this.connection).fromJSON(json);
35
+ };
36
+ return JobStatusRestfulModelCollection;
37
+ }(restful_model_collection_1.default));
38
+ exports.default = JobStatusRestfulModelCollection;
@@ -51,6 +51,12 @@ var MessageRestfulModelCollection = /** @class */ (function (_super) {
51
51
  };
52
52
  delete options.view;
53
53
  }
54
+ // If only one message ID was passed in, use the normal find function
55
+ if (messageIds.length == 1) {
56
+ return this.find(messageIds[0], options).then(function (message) {
57
+ return [message];
58
+ });
59
+ }
54
60
  return this.range(__assign({ path: this.path() + "/" + messageIds.join() }, options));
55
61
  };
56
62
  /**
@@ -5,6 +5,7 @@ export default class ModelCollection<T extends Model> {
5
5
  connection: NylasConnection;
6
6
  modelClass: any;
7
7
  _path: string;
8
+ baseUrl?: string;
8
9
  constructor(modelClass: any, connection: NylasConnection, path: string);
9
10
  forEach(params: Record<string, unknown> | undefined, eachCallback: (item: T) => void, completeCallback?: (err?: Error | null | undefined) => void): void;
10
11
  list(params?: Record<string, unknown>, callback?: (error: Error | null, obj?: T[]) => void): Promise<T[]>;
@@ -157,6 +157,7 @@ var ModelCollection = /** @class */ (function () {
157
157
  method: 'GET',
158
158
  path: path,
159
159
  qs: __assign(__assign({}, params), { offset: offset, limit: limit }),
160
+ baseUrl: this.baseUrl,
160
161
  });
161
162
  }
162
163
  return this.getModelCollection(params, offset, limit, path);
@@ -172,6 +173,7 @@ var ModelCollection = /** @class */ (function () {
172
173
  method: 'GET',
173
174
  path: this.path() + "/" + id,
174
175
  qs: params,
176
+ baseUrl: this.baseUrl,
175
177
  })
176
178
  .then(function (json) {
177
179
  var model = _this.createModel(json);
@@ -185,6 +187,7 @@ var ModelCollection = /** @class */ (function () {
185
187
  method: 'GET',
186
188
  path: path,
187
189
  qs: __assign(__assign({}, params), { offset: offset, limit: limit }),
190
+ baseUrl: this.baseUrl,
188
191
  })
189
192
  .then(function (jsonArray) {
190
193
  var models = jsonArray.map(function (json) {
@@ -1,21 +1,20 @@
1
1
  import OutboxMessage, { OutboxMessageProperties } from './outbox-message';
2
- import Model from './model';
3
2
  import { Attribute } from './attributes';
4
3
  import NylasConnection from '../nylas-connection';
5
- export declare type OutboxJobStatusProperties = {
6
- jobStatusId: string;
7
- accountId: string;
8
- status: string;
4
+ import JobStatus, { JobStatusProperties } from './job-status';
5
+ export declare type OutboxJobStatusProperties = JobStatusProperties & {
6
+ messageId?: string;
7
+ threadId?: string;
8
+ sendAt?: Date;
9
+ originalSendAt?: Date;
9
10
  originalData?: OutboxMessageProperties;
10
11
  };
11
- export default class OutboxJobStatus extends Model implements OutboxJobStatusProperties {
12
- jobStatusId: string;
13
- status: string;
14
- accountId: string;
12
+ export default class OutboxJobStatus extends JobStatus implements OutboxJobStatusProperties {
13
+ messageId?: string;
14
+ threadId?: string;
15
+ sendAt?: Date;
16
+ originalSendAt?: Date;
15
17
  originalData?: OutboxMessage;
16
- private _connection?;
17
18
  static attributes: Record<string, Attribute>;
18
- constructor(props?: OutboxJobStatusProperties);
19
- get connection(): NylasConnection | undefined;
20
- fromJSON(json: Record<string, unknown>, connection?: NylasConnection): this;
19
+ constructor(connection: NylasConnection, props?: OutboxJobStatusProperties);
21
20
  }
@@ -12,59 +12,53 @@ var __extends = (this && this.__extends) || (function () {
12
12
  d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
13
13
  };
14
14
  })();
15
+ var __assign = (this && this.__assign) || function () {
16
+ __assign = Object.assign || function(t) {
17
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
18
+ s = arguments[i];
19
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
20
+ t[p] = s[p];
21
+ }
22
+ return t;
23
+ };
24
+ return __assign.apply(this, arguments);
25
+ };
15
26
  var __importDefault = (this && this.__importDefault) || function (mod) {
16
27
  return (mod && mod.__esModule) ? mod : { "default": mod };
17
28
  };
18
29
  Object.defineProperty(exports, "__esModule", { value: true });
19
30
  var outbox_message_1 = __importDefault(require("./outbox-message"));
20
- var model_1 = __importDefault(require("./model"));
21
31
  var attributes_1 = __importDefault(require("./attributes"));
32
+ var job_status_1 = __importDefault(require("./job-status"));
22
33
  var OutboxJobStatus = /** @class */ (function (_super) {
23
34
  __extends(OutboxJobStatus, _super);
24
- function OutboxJobStatus(props) {
25
- var _this = _super.call(this) || this;
26
- _this.jobStatusId = '';
27
- _this.status = '';
28
- _this.accountId = '';
35
+ function OutboxJobStatus(connection, props) {
36
+ var _this = _super.call(this, connection, props) || this;
29
37
  _this.initAttributes(props);
30
38
  return _this;
31
39
  }
32
- Object.defineProperty(OutboxJobStatus.prototype, "connection", {
33
- get: function () {
34
- return this._connection;
35
- },
36
- enumerable: true,
37
- configurable: true
38
- });
39
- OutboxJobStatus.prototype.fromJSON = function (json, connection) {
40
- // Allow a connection object to be passed in to instantiate a Calendar sub object
41
- if (connection) {
42
- this._connection = connection;
43
- }
44
- return _super.prototype.fromJSON.call(this, json);
45
- };
46
- OutboxJobStatus.attributes = {
47
- jobStatusId: attributes_1.default.String({
48
- modelKey: 'jobStatusId',
49
- jsonKey: 'job_status_id',
40
+ OutboxJobStatus.attributes = __assign(__assign({}, job_status_1.default.attributes), { messageId: attributes_1.default.String({
41
+ modelKey: 'messageId',
42
+ jsonKey: 'message_id',
43
+ readOnly: true,
44
+ }), threadId: attributes_1.default.String({
45
+ modelKey: 'threadId',
46
+ jsonKey: 'thread_id',
50
47
  readOnly: true,
51
- }),
52
- status: attributes_1.default.String({
53
- modelKey: 'status',
48
+ }), sendAt: attributes_1.default.DateTime({
49
+ modelKey: 'sendAt',
50
+ jsonKey: 'send_at',
54
51
  readOnly: true,
55
- }),
56
- accountId: attributes_1.default.String({
57
- modelKey: 'accountId',
58
- jsonKey: 'account_id',
52
+ }), originalSendAt: attributes_1.default.DateTime({
53
+ modelKey: 'originalSendAt',
54
+ jsonKey: 'original_send_at',
59
55
  readOnly: true,
60
- }),
61
- originalData: attributes_1.default.Object({
56
+ }), originalData: attributes_1.default.Object({
62
57
  modelKey: 'originalData',
63
58
  jsonKey: 'original_data',
64
59
  itemClass: outbox_message_1.default,
65
60
  readOnly: true,
66
- }),
67
- };
61
+ }) });
68
62
  return OutboxJobStatus;
69
- }(model_1.default));
63
+ }(job_status_1.default));
70
64
  exports.default = OutboxJobStatus;
@@ -58,7 +58,7 @@ var Outbox = /** @class */ (function () {
58
58
  body: body,
59
59
  })
60
60
  .then(function (json) {
61
- var message = new outbox_job_status_1.default().fromJSON(json, _this.connection);
61
+ var message = new outbox_job_status_1.default(_this.connection).fromJSON(json);
62
62
  if (options.callback) {
63
63
  options.callback(null, message);
64
64
  }
@@ -85,7 +85,7 @@ var Outbox = /** @class */ (function () {
85
85
  path: "/" + jobStatusId,
86
86
  body: body,
87
87
  }).then(function (json) {
88
- var message = new outbox_job_status_1.default().fromJSON(json, _this.connection);
88
+ var message = new outbox_job_status_1.default(_this.connection).fromJSON(json);
89
89
  return Promise.resolve(message);
90
90
  });
91
91
  };
@@ -4,7 +4,6 @@ import ModelCollection from './model-collection';
4
4
  export declare type GetCallback = (error: Error | null, result?: RestfulModel) => void;
5
5
  export default class RestfulModelCollection<T extends RestfulModel> extends ModelCollection<any> {
6
6
  modelClass: typeof RestfulModel;
7
- baseUrl?: string;
8
7
  constructor(modelClass: typeof RestfulModel, connection: NylasConnection);
9
8
  count(params?: Record<string, unknown>, callback?: (err: Error | null, num?: number) => void): Promise<number>;
10
9
  first(params?: Record<string, unknown>, callback?: (error: Error | null, model?: T) => void): Promise<T>;
@@ -14,6 +14,7 @@ export declare type ProviderAvailability = {
14
14
  export default class SchedulerRestfulModelCollection extends RestfulModelCollection<Scheduler> {
15
15
  connection: NylasConnection;
16
16
  modelClass: typeof Scheduler;
17
+ baseUrl: string;
17
18
  constructor(connection: NylasConnection);
18
19
  getGoogleAvailability(): Promise<ProviderAvailability>;
19
20
  getOffice365Availability(): Promise<ProviderAvailability>;
@@ -10,7 +10,6 @@ import Thread from './models/thread';
10
10
  import Draft from './models/draft';
11
11
  import File from './models/file';
12
12
  import Event from './models/event';
13
- import JobStatus from './models/job-status';
14
13
  import Resource from './models/resource';
15
14
  import Folder, { Label } from './models/folder';
16
15
  import { AppendOptions } from 'form-data';
@@ -20,6 +19,7 @@ import SchedulerRestfulModelCollection from './models/scheduler-restful-model-co
20
19
  import MessageRestfulModelCollection from './models/message-restful-model-collection';
21
20
  import DeltaCollection from './models/delta-collection';
22
21
  import Outbox from './models/outbox';
22
+ import JobStatusRestfulModelCollection from './models/job-status-restful-model-collection';
23
23
  export declare enum AuthMethod {
24
24
  BASIC = 0,
25
25
  BEARER = 1
@@ -50,7 +50,7 @@ export default class NylasConnection {
50
50
  drafts: RestfulModelCollection<Draft>;
51
51
  files: RestfulModelCollection<File>;
52
52
  calendars: CalendarRestfulModelCollection;
53
- jobStatuses: RestfulModelCollection<JobStatus>;
53
+ jobStatuses: JobStatusRestfulModelCollection;
54
54
  events: RestfulModelCollection<Event>;
55
55
  resources: RestfulModelCollection<Resource>;
56
56
  deltas: DeltaCollection;
@@ -34,7 +34,6 @@ var thread_1 = __importDefault(require("./models/thread"));
34
34
  var draft_1 = __importDefault(require("./models/draft"));
35
35
  var file_1 = __importDefault(require("./models/file"));
36
36
  var event_1 = __importDefault(require("./models/event"));
37
- var job_status_1 = __importDefault(require("./models/job-status"));
38
37
  var resource_1 = __importDefault(require("./models/resource"));
39
38
  var folder_1 = __importStar(require("./models/folder"));
40
39
  var form_data_1 = __importDefault(require("form-data"));
@@ -45,6 +44,7 @@ var scheduler_restful_model_collection_1 = __importDefault(require("./models/sch
45
44
  var message_restful_model_collection_1 = __importDefault(require("./models/message-restful-model-collection"));
46
45
  var delta_collection_1 = __importDefault(require("./models/delta-collection"));
47
46
  var outbox_1 = __importDefault(require("./models/outbox"));
47
+ var job_status_restful_model_collection_1 = __importDefault(require("./models/job-status-restful-model-collection"));
48
48
  var PACKAGE_JSON = require('../package.json');
49
49
  var SDK_VERSION = PACKAGE_JSON.version;
50
50
  var SUPPORTED_API_VERSION = '2.5';
@@ -62,7 +62,7 @@ var NylasConnection = /** @class */ (function () {
62
62
  this.drafts = new restful_model_collection_1.default(draft_1.default, this);
63
63
  this.files = new restful_model_collection_1.default(file_1.default, this);
64
64
  this.calendars = new calendar_restful_model_collection_1.default(this);
65
- this.jobStatuses = new restful_model_collection_1.default(job_status_1.default, this);
65
+ this.jobStatuses = new job_status_restful_model_collection_1.default(this);
66
66
  this.events = new restful_model_collection_1.default(event_1.default, this);
67
67
  this.resources = new restful_model_collection_1.default(resource_1.default, this);
68
68
  this.deltas = new delta_collection_1.default(this);
@@ -194,6 +194,7 @@ var NylasConnection = /** @class */ (function () {
194
194
  }
195
195
  if (response.status > 299) {
196
196
  return response
197
+ .clone()
197
198
  .json()
198
199
  .then(function (body) {
199
200
  var error = new nylas_api_error_1.default(response.status, body.type, body.message);
@@ -237,13 +238,18 @@ var NylasConnection = /** @class */ (function () {
237
238
  }
238
239
  else if (response.headers.get('content-length') &&
239
240
  Number(response.headers.get('content-length')) == 0) {
240
- return resolve();
241
+ return resolve(undefined);
241
242
  }
242
243
  else if (response.headers.get('Content-Type') === 'message/rfc822') {
243
244
  return resolve(response.text());
244
245
  }
245
246
  else {
246
- return resolve(response.json());
247
+ return response
248
+ .clone()
249
+ .json()
250
+ .catch(function () { return response.text(); })
251
+ .then(function (data) { return resolve(data); })
252
+ .catch(function () { return resolve(undefined); });
247
253
  }
248
254
  }
249
255
  })
package/lib/nylas.d.ts CHANGED
@@ -23,5 +23,10 @@ declare class Nylas {
23
23
  static application(options?: ApplicationDetailsProperties): Promise<ApplicationDetails>;
24
24
  static exchangeCodeForToken(code: string, callback?: (error: Error | null, accessToken?: string) => void): Promise<AccessToken>;
25
25
  static urlForAuthentication(options: AuthenticateUrlConfig): string;
26
+ /**
27
+ * Revoke a single access token
28
+ * @param accessToken The access token to revoke
29
+ */
30
+ static revoke(accessToken: string): Promise<void>;
26
31
  }
27
32
  export = Nylas;
package/lib/nylas.js CHANGED
@@ -163,8 +163,23 @@ var Nylas = /** @class */ (function () {
163
163
  if (options.provider != null) {
164
164
  url += "&provider=" + options.provider;
165
165
  }
166
+ if (options.redirectOnError) {
167
+ url += '&redirect_on_error=true';
168
+ }
166
169
  return url;
167
170
  };
171
+ /**
172
+ * Revoke a single access token
173
+ * @param accessToken The access token to revoke
174
+ */
175
+ Nylas.revoke = function (accessToken) {
176
+ return Nylas.with(accessToken)
177
+ .request({
178
+ method: 'POST',
179
+ path: '/oauth/revoke',
180
+ })
181
+ .catch(function (err) { return Promise.reject(err); });
182
+ };
168
183
  Nylas.clientId = '';
169
184
  return Nylas;
170
185
  }());
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nylas",
3
- "version": "6.2.2",
3
+ "version": "6.3.2",
4
4
  "description": "A NodeJS wrapper for the Nylas REST API for email, contacts, and calendar.",
5
5
  "main": "lib/nylas.js",
6
6
  "types": "lib/nylas.d.ts",