nylas 6.3.2 → 6.4.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.
@@ -147,6 +147,9 @@ var Draft = /** @class */ (function (_super) {
147
147
  }), rawMime: attributes_1.default.String({
148
148
  modelKey: 'rawMime',
149
149
  readOnly: true,
150
+ }), fileIdsToAttach: attributes_1.default.StringList({
151
+ modelKey: 'fileIdsToAttach',
152
+ readOnly: true,
150
153
  }) });
151
154
  return Draft;
152
155
  }(message_1.default));
@@ -23,6 +23,7 @@ export declare type EventProperties = {
23
23
  when: WhenProperties;
24
24
  iCalUID?: string;
25
25
  messageId?: string;
26
+ eventCollectionId?: string | number;
26
27
  title?: string;
27
28
  description?: string;
28
29
  owner?: string;
@@ -37,8 +38,10 @@ export declare type EventProperties = {
37
38
  };
38
39
  masterEventId?: string;
39
40
  originalStartTime?: number;
41
+ capacity?: number;
40
42
  conferencing?: EventConferencingProperties;
41
43
  notifications?: EventNotificationProperties[];
44
+ roundRobinOrder?: string[];
42
45
  metadata?: object;
43
46
  jobStatusId?: string;
44
47
  };
@@ -47,6 +50,7 @@ export default class Event extends RestfulModel {
47
50
  when: When;
48
51
  iCalUID?: string;
49
52
  messageId?: string;
53
+ eventCollectionId?: string | number;
50
54
  title?: string;
51
55
  description?: string;
52
56
  owner?: string;
@@ -61,8 +65,11 @@ export default class Event extends RestfulModel {
61
65
  };
62
66
  masterEventId?: string;
63
67
  originalStartTime?: number;
68
+ capacity?: number;
64
69
  conferencing?: EventConferencing;
70
+ reminderMinutes?: string;
65
71
  notifications?: EventNotification[];
72
+ roundRobinOrder?: string[];
66
73
  metadata?: object;
67
74
  jobStatusId?: string;
68
75
  static collectionName: string;
@@ -77,4 +84,5 @@ export default class Event extends RestfulModel {
77
84
  saveRequestBody(): Record<string, unknown>;
78
85
  rsvp(status: string, comment: string, callback?: (error: Error | null, data?: Event) => void): Promise<Event>;
79
86
  generateICS(options?: ICSOptions): Promise<string>;
87
+ private validate;
80
88
  }
@@ -135,11 +135,7 @@ var Event = /** @class */ (function (_super) {
135
135
  };
136
136
  Event.prototype.save = function (params, callback) {
137
137
  if (params === void 0) { params = {}; }
138
- if (this.conferencing &&
139
- this.conferencing.details &&
140
- this.conferencing.autocreate) {
141
- return Promise.reject(new Error("Cannot set both 'details' and 'autocreate' in conferencing object."));
142
- }
138
+ this.validate();
143
139
  return _super.prototype.save.call(this, params, callback);
144
140
  };
145
141
  Event.prototype.saveRequestBody = function () {
@@ -196,6 +192,19 @@ var Event = /** @class */ (function (_super) {
196
192
  return response.ics;
197
193
  });
198
194
  };
195
+ Event.prototype.validate = function () {
196
+ if (this.conferencing &&
197
+ this.conferencing.details &&
198
+ this.conferencing.autocreate) {
199
+ throw new Error("Cannot set both 'details' and 'autocreate' in conferencing object.");
200
+ }
201
+ if (this.capacity &&
202
+ this.capacity != -1 &&
203
+ this.participants &&
204
+ this.participants.length > this.capacity) {
205
+ throw new Error('The number of participants in the event exceeds the set capacity.');
206
+ }
207
+ };
199
208
  Event.collectionName = 'events';
200
209
  Event.attributes = __assign(__assign({}, restful_model_1.default.attributes), { calendarId: attributes_1.default.String({
201
210
  modelKey: 'calendarId',
@@ -208,6 +217,9 @@ var Event = /** @class */ (function (_super) {
208
217
  modelKey: 'messageId',
209
218
  jsonKey: 'message_id',
210
219
  readOnly: true,
220
+ }), eventCollectionId: attributes_1.default.String({
221
+ modelKey: 'eventCollectionId',
222
+ jsonKey: 'event_collection_id',
211
223
  }), title: attributes_1.default.String({
212
224
  modelKey: 'title',
213
225
  }), description: attributes_1.default.String({
@@ -241,12 +253,20 @@ var Event = /** @class */ (function (_super) {
241
253
  modelKey: 'originalStartTime',
242
254
  jsonKey: 'original_start_time',
243
255
  readOnly: true,
256
+ }), capacity: attributes_1.default.Number({
257
+ modelKey: 'capacity',
244
258
  }), conferencing: attributes_1.default.Object({
245
259
  modelKey: 'conferencing',
246
260
  itemClass: event_conferencing_1.default,
261
+ }), reminderMinutes: attributes_1.default.String({
262
+ modelKey: 'reminderMinutes',
263
+ jsonKey: 'reminder_minutes',
247
264
  }), notifications: attributes_1.default.Collection({
248
265
  modelKey: 'notifications',
249
266
  itemClass: event_notification_1.default,
267
+ }), roundRobinOrder: attributes_1.default.StringList({
268
+ modelKey: 'roundRobinOrder',
269
+ jsonKey: 'round_robin_order',
250
270
  }), metadata: attributes_1.default.Object({
251
271
  modelKey: 'metadata',
252
272
  }), jobStatusId: attributes_1.default.String({
@@ -16,11 +16,24 @@ export declare class FreeBusyCalendar extends Model implements FreeBusyCalendarP
16
16
  static attributes: Record<string, Attribute>;
17
17
  constructor(props?: FreeBusyCalendarProperties);
18
18
  }
19
+ export declare type TimeSlotCapacityProperties = {
20
+ eventId: string;
21
+ currentCapacity: number;
22
+ maxCapacity: number;
23
+ };
24
+ export declare class TimeSlotCapacity extends Model implements TimeSlotCapacityProperties {
25
+ eventId: string;
26
+ currentCapacity: number;
27
+ maxCapacity: number;
28
+ static attributes: Record<string, Attribute>;
29
+ constructor(props?: TimeSlotCapacityProperties);
30
+ }
19
31
  export declare type TimeSlotProperties = {
20
32
  status: string;
21
33
  startTime: number;
22
34
  endTime: number;
23
35
  emails?: string[];
36
+ capacity?: TimeSlotCapacityProperties;
24
37
  };
25
38
  export declare class TimeSlot extends Model implements TimeSlotProperties {
26
39
  object: string;
@@ -28,6 +41,7 @@ export declare class TimeSlot extends Model implements TimeSlotProperties {
28
41
  startTime: number;
29
42
  endTime: number;
30
43
  emails?: string[];
44
+ capacity?: TimeSlotCapacity;
31
45
  static attributes: Record<string, Attribute>;
32
46
  constructor(props?: TimeSlotProperties);
33
47
  }
@@ -40,6 +40,33 @@ var FreeBusyCalendar = /** @class */ (function (_super) {
40
40
  return FreeBusyCalendar;
41
41
  }(model_1.default));
42
42
  exports.FreeBusyCalendar = FreeBusyCalendar;
43
+ var TimeSlotCapacity = /** @class */ (function (_super) {
44
+ __extends(TimeSlotCapacity, _super);
45
+ function TimeSlotCapacity(props) {
46
+ var _this = _super.call(this) || this;
47
+ _this.eventId = '';
48
+ _this.currentCapacity = 0;
49
+ _this.maxCapacity = 0;
50
+ _this.initAttributes(props);
51
+ return _this;
52
+ }
53
+ TimeSlotCapacity.attributes = {
54
+ eventId: attributes_1.default.String({
55
+ modelKey: 'eventId',
56
+ jsonKey: 'event_id',
57
+ }),
58
+ currentCapacity: attributes_1.default.Number({
59
+ modelKey: 'currentCapacity',
60
+ jsonKey: 'current_capacity',
61
+ }),
62
+ maxCapacity: attributes_1.default.Number({
63
+ modelKey: 'maxCapacity',
64
+ jsonKey: 'max_capacity',
65
+ }),
66
+ };
67
+ return TimeSlotCapacity;
68
+ }(model_1.default));
69
+ exports.TimeSlotCapacity = TimeSlotCapacity;
43
70
  var TimeSlot = /** @class */ (function (_super) {
44
71
  __extends(TimeSlot, _super);
45
72
  function TimeSlot(props) {
@@ -69,6 +96,10 @@ var TimeSlot = /** @class */ (function (_super) {
69
96
  emails: attributes_1.default.StringList({
70
97
  modelKey: 'emails',
71
98
  }),
99
+ capacity: attributes_1.default.Object({
100
+ modelKey: 'capacity',
101
+ itemClass: TimeSlotCapacity,
102
+ }),
72
103
  };
73
104
  return TimeSlot;
74
105
  }(model_1.default));
@@ -1,4 +1,4 @@
1
- import RestfulModel from './restful-model';
1
+ import RestfulModel, { SaveCallback } from './restful-model';
2
2
  import { Attribute } from './attributes';
3
3
  import File, { FileProperties } from './file';
4
4
  import Event, { EventProperties } from './event';
@@ -53,4 +53,5 @@ export default class Message extends RestfulModel implements MessageProperties {
53
53
  fileIds(): (string | undefined)[];
54
54
  getRaw(): Promise<string>;
55
55
  saveRequestBody(): Record<string, unknown>;
56
+ save(params?: {} | SaveCallback, callback?: SaveCallback): Promise<this>;
56
57
  }
@@ -106,6 +106,14 @@ var Message = /** @class */ (function (_super) {
106
106
  json['metadata'] = this.metadata;
107
107
  return json;
108
108
  };
109
+ Message.prototype.save = function (params, callback) {
110
+ if (params === void 0) { params = {}; }
111
+ // A Message can only be updated
112
+ if (this.constructor.name === 'Message' && !this.id) {
113
+ throw new Error('Cannot create a message. Please create and send a draft instead.');
114
+ }
115
+ return _super.prototype.save.call(this, params, callback);
116
+ };
109
117
  Message.collectionName = 'messages';
110
118
  Message.attributes = __assign(__assign({}, restful_model_1.default.attributes), { subject: attributes_1.default.String({
111
119
  modelKey: 'subject',
@@ -153,6 +153,7 @@ export declare type SchedulerConfigProperties = {
153
153
  };
154
154
  event?: {
155
155
  duration?: number;
156
+ capacity?: number;
156
157
  location?: string;
157
158
  title?: string;
158
159
  };
@@ -176,6 +177,7 @@ export declare class SchedulerConfig extends Model implements SchedulerConfigPro
176
177
  };
177
178
  event?: {
178
179
  duration?: number;
180
+ capacity?: number;
179
181
  location?: string;
180
182
  title?: string;
181
183
  };
@@ -193,30 +193,22 @@ var NylasConnection = /** @class */ (function () {
193
193
  console.warn(warning);
194
194
  }
195
195
  if (response.status > 299) {
196
- return response
197
- .clone()
198
- .json()
199
- .then(function (body) {
200
- var error = new nylas_api_error_1.default(response.status, body.type, body.message);
201
- if (body.missing_fields) {
202
- error.missingFields = body.missing_fields;
203
- }
204
- if (body.server_error) {
205
- error.serverError = body.server_error;
206
- }
207
- return reject(error);
208
- })
209
- .catch(function () {
210
- return response
211
- .text()
212
- .then(function (text) {
213
- var error = new nylas_api_error_1.default(response.status, response.statusText, text);
196
+ return response.text().then(function (body) {
197
+ try {
198
+ var parsedApiError = JSON.parse(body);
199
+ var error = new nylas_api_error_1.default(response.status, parsedApiError.type, parsedApiError.message);
200
+ if (parsedApiError.missing_fields) {
201
+ error.missingFields = parsedApiError.missing_fields;
202
+ }
203
+ if (parsedApiError.server_error) {
204
+ error.serverError = parsedApiError.server_error;
205
+ }
214
206
  return reject(error);
215
- })
216
- .catch(function () {
217
- var error = new nylas_api_error_1.default(response.status, response.statusText, 'Error encountered during request, unable to extract error message.');
207
+ }
208
+ catch (e) {
209
+ var error = new nylas_api_error_1.default(response.status, response.statusText, body);
218
210
  return reject(error);
219
- });
211
+ }
220
212
  });
221
213
  }
222
214
  else {
@@ -244,12 +236,14 @@ var NylasConnection = /** @class */ (function () {
244
236
  return resolve(response.text());
245
237
  }
246
238
  else {
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); });
239
+ return response.text().then(function (text) {
240
+ try {
241
+ return resolve(JSON.parse(text));
242
+ }
243
+ catch (e) {
244
+ return resolve(text);
245
+ }
246
+ });
253
247
  }
254
248
  }
255
249
  })
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nylas",
3
- "version": "6.3.2",
3
+ "version": "6.4.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",