nylas 6.3.1 → 6.4.1

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.
@@ -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;
@@ -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,10 @@ export default class Event extends RestfulModel {
61
65
  };
62
66
  masterEventId?: string;
63
67
  originalStartTime?: number;
68
+ capacity?: number;
64
69
  conferencing?: EventConferencing;
65
70
  notifications?: EventNotification[];
71
+ roundRobinOrder?: string[];
66
72
  metadata?: object;
67
73
  jobStatusId?: string;
68
74
  static collectionName: string;
@@ -77,4 +83,5 @@ export default class Event extends RestfulModel {
77
83
  saveRequestBody(): Record<string, unknown>;
78
84
  rsvp(status: string, comment: string, callback?: (error: Error | null, data?: Event) => void): Promise<Event>;
79
85
  generateICS(options?: ICSOptions): Promise<string>;
86
+ private validate;
80
87
  }
@@ -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,17 @@ 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,
247
261
  }), notifications: attributes_1.default.Collection({
248
262
  modelKey: 'notifications',
249
263
  itemClass: event_notification_1.default,
264
+ }), roundRobinOrder: attributes_1.default.StringList({
265
+ modelKey: 'roundRobinOrder',
266
+ jsonKey: 'round_robin_order',
250
267
  }), metadata: attributes_1.default.Object({
251
268
  modelKey: 'metadata',
252
269
  }), 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));
@@ -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) {
@@ -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>;
@@ -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.1",
3
+ "version": "6.4.1",
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",