nylas 5.10.1 → 5.10.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.
@@ -10,6 +10,7 @@ export declare class Attribute {
10
10
  });
11
11
  toJSON(val: any): any;
12
12
  fromJSON(val: any, _parent: any): any;
13
+ saveRequestBody(val: any): any;
13
14
  }
14
15
  declare class AttributeObject extends Attribute {
15
16
  itemClass?: typeof RestfulModel;
@@ -19,8 +20,9 @@ declare class AttributeObject extends Attribute {
19
20
  itemClass?: typeof RestfulModel;
20
21
  readOnly?: boolean;
21
22
  });
22
- toJSON(val: any): any;
23
+ toJSON(val: any, saveRequestBody?: boolean): any;
23
24
  fromJSON(val: any, _parent: any): any;
25
+ saveRequestBody(val: any): any;
24
26
  }
25
27
  declare class AttributeNumber extends Attribute {
26
28
  toJSON(val: any): any;
@@ -54,8 +56,9 @@ declare class AttributeCollection extends Attribute {
54
56
  itemClass: typeof RestfulModel;
55
57
  readOnly?: boolean;
56
58
  });
57
- toJSON(vals: any): any[];
59
+ toJSON(vals: any, saveRequestBody?: boolean): any[];
58
60
  fromJSON(json: any, _parent: any): RestfulModel[];
61
+ saveRequestBody(val: any): any[] | undefined;
59
62
  }
60
63
  declare const Attributes: {
61
64
  Number(__0: {
@@ -38,6 +38,12 @@ var Attribute = /** @class */ (function () {
38
38
  Attribute.prototype.fromJSON = function (val, _parent) {
39
39
  return val || null;
40
40
  };
41
+ Attribute.prototype.saveRequestBody = function (val) {
42
+ if (this.readOnly) {
43
+ return;
44
+ }
45
+ return this.toJSON(val);
46
+ };
41
47
  return Attribute;
42
48
  }());
43
49
  exports.Attribute = Attribute;
@@ -49,11 +55,14 @@ var AttributeObject = /** @class */ (function (_super) {
49
55
  _this.itemClass = itemClass;
50
56
  return _this;
51
57
  }
52
- AttributeObject.prototype.toJSON = function (val) {
58
+ AttributeObject.prototype.toJSON = function (val, saveRequestBody) {
53
59
  if (!val) {
54
60
  return val;
55
61
  }
56
- if (val.toJSON != null) {
62
+ if (saveRequestBody === true && val.saveRequestBody != null) {
63
+ return val.saveRequestBody();
64
+ }
65
+ else if (val.toJSON != null) {
57
66
  return val.toJSON();
58
67
  }
59
68
  return val;
@@ -64,6 +73,12 @@ var AttributeObject = /** @class */ (function (_super) {
64
73
  }
65
74
  return new this.itemClass(_parent.connection, val);
66
75
  };
76
+ AttributeObject.prototype.saveRequestBody = function (val) {
77
+ if (this.readOnly) {
78
+ return;
79
+ }
80
+ return this.toJSON(val, true);
81
+ };
67
82
  return AttributeObject;
68
83
  }(Attribute));
69
84
  var AttributeNumber = /** @class */ (function (_super) {
@@ -175,14 +190,17 @@ var AttributeCollection = /** @class */ (function (_super) {
175
190
  _this.itemClass = itemClass;
176
191
  return _this;
177
192
  }
178
- AttributeCollection.prototype.toJSON = function (vals) {
193
+ AttributeCollection.prototype.toJSON = function (vals, saveRequestBody) {
179
194
  if (!vals) {
180
195
  return [];
181
196
  }
182
197
  var json = [];
183
198
  for (var _i = 0, vals_1 = vals; _i < vals_1.length; _i++) {
184
199
  var val = vals_1[_i];
185
- if (val.toJSON != null) {
200
+ if (saveRequestBody === true && val.saveRequestBody != null) {
201
+ json.push(val.saveRequestBody());
202
+ }
203
+ else if (val.toJSON != null) {
186
204
  json.push(val.toJSON());
187
205
  }
188
206
  else {
@@ -203,6 +221,12 @@ var AttributeCollection = /** @class */ (function (_super) {
203
221
  }
204
222
  return objs;
205
223
  };
224
+ AttributeCollection.prototype.saveRequestBody = function (val) {
225
+ if (this.readOnly) {
226
+ return;
227
+ }
228
+ return this.toJSON(val, true);
229
+ };
206
230
  return AttributeCollection;
207
231
  }(Attribute));
208
232
  var Attributes = {
@@ -9,8 +9,10 @@ export default class Component extends RestfulModel {
9
9
  publicAccountId?: string;
10
10
  publicTokenId?: string;
11
11
  publicApplicationId?: string;
12
+ accessToken?: string;
12
13
  createdAt?: Date;
13
14
  updatedAt?: Date;
14
15
  saveEndpoint(): string;
15
16
  save(params?: {} | SaveCallback, callback?: SaveCallback): Promise<this>;
17
+ saveRequestBody(): any;
16
18
  }
@@ -41,6 +41,16 @@ var Component = /** @class */ (function (_super) {
41
41
  if (params === void 0) { params = {}; }
42
42
  return this._save(params, callback);
43
43
  };
44
+ Component.prototype.saveRequestBody = function () {
45
+ var json = _super.prototype.saveRequestBody.call(this);
46
+ if (this.id) {
47
+ // Cannot cannot send these values after creation
48
+ delete json.access_token;
49
+ delete json.public_application_id;
50
+ delete json.type;
51
+ }
52
+ return json;
53
+ };
44
54
  return Component;
45
55
  }(restful_model_1.default));
46
56
  exports.default = Component;
@@ -67,6 +77,9 @@ Component.attributes = __assign(__assign({}, restful_model_1.default.attributes)
67
77
  }), publicApplicationId: attributes_1.default.String({
68
78
  modelKey: 'publicApplicationId',
69
79
  jsonKey: 'public_application_id',
80
+ }), accessToken: attributes_1.default.String({
81
+ modelKey: 'accessToken',
82
+ jsonKey: 'access_token',
70
83
  }), createdAt: attributes_1.default.Date({
71
84
  modelKey: 'createdAt',
72
85
  jsonKey: 'created_at',
@@ -43,5 +43,6 @@ EventParticipant.attributes = {
43
43
  }),
44
44
  status: attributes_1.default.String({
45
45
  modelKey: 'status',
46
+ readOnly: true,
46
47
  }),
47
48
  };
@@ -43,5 +43,6 @@ export default class Event extends RestfulModel {
43
43
  [key: string]: any;
44
44
  };
45
45
  save(params?: {} | SaveCallback, callback?: SaveCallback): Promise<this>;
46
+ saveRequestBody(): any;
46
47
  rsvp(status: string, comment: string, callback?: (error: Error | null, data?: Event) => void): Promise<this>;
47
48
  }
@@ -126,6 +126,13 @@ var Event = /** @class */ (function (_super) {
126
126
  }
127
127
  return this._save(params, callback);
128
128
  };
129
+ Event.prototype.saveRequestBody = function () {
130
+ var json = _super.prototype.saveRequestBody.call(this);
131
+ if (json.when && json.when.object) {
132
+ delete json.when.object;
133
+ }
134
+ return json;
135
+ };
129
136
  Event.prototype.rsvp = function (status, comment, callback) {
130
137
  var _this = this;
131
138
  return this.connection
@@ -37,8 +37,11 @@ var RestfulModel = /** @class */ (function () {
37
37
  var json = {};
38
38
  var attributes = this.attributes();
39
39
  for (var attrName in attributes) {
40
- if (!attributes[attrName].readOnly || enforceReadOnly !== true) {
41
- var attr = attributes[attrName];
40
+ var attr = attributes[attrName];
41
+ if (enforceReadOnly === true) {
42
+ json[attr.jsonKey] = attr.saveRequestBody(this[attrName]);
43
+ }
44
+ else {
42
45
  json[attr.jsonKey] = attr.toJSON(this[attrName]);
43
46
  }
44
47
  }
@@ -54,7 +54,7 @@ export default class Scheduler extends RestfulModel {
54
54
  name_field_hidden: boolean;
55
55
  opening_hours: Array<{
56
56
  account_id?: string;
57
- days?: string;
57
+ days?: string[];
58
58
  end?: string;
59
59
  start?: string;
60
60
  }>;
@@ -72,7 +72,7 @@ export default class Scheduler extends RestfulModel {
72
72
  title?: string;
73
73
  };
74
74
  expire_after?: {
75
- date?: number;
75
+ date?: Date;
76
76
  uses?: number;
77
77
  };
78
78
  locale?: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nylas",
3
- "version": "5.10.1",
3
+ "version": "5.10.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",