nylas 6.10.0 → 6.11.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.
package/lib/config.d.ts CHANGED
@@ -1,10 +1,13 @@
1
1
  import { WebhookTriggers } from './models/webhook';
2
+ import LoggingInterface from './models/LoggingInterface';
2
3
  export declare let apiServer: string | null;
3
4
  export declare function setApiServer(newApiServer: string | null): void;
4
5
  export declare let clientSecret: string;
5
6
  export declare function setClientSecret(newClientSecret: string): void;
6
7
  export declare let timeout: number;
7
8
  export declare function setTimeout(newTimeout: number): void;
9
+ export declare let logger: LoggingInterface | undefined;
10
+ export declare function setLogger(newLogger?: LoggingInterface): void;
8
11
  export declare type NylasConfig = {
9
12
  /** Nylas application client ID */
10
13
  clientId: string;
@@ -14,6 +17,8 @@ export declare type NylasConfig = {
14
17
  apiServer?: string;
15
18
  /** Timeout for outgoing API calls, in milliseconds */
16
19
  timeout?: number;
20
+ /** Logger to redirect log messages to your application. */
21
+ logger?: LoggingInterface;
17
22
  };
18
23
  export declare enum ResponseType {
19
24
  CODE = "code",
package/lib/config.js CHANGED
@@ -17,6 +17,11 @@ function setTimeout(newTimeout) {
17
17
  exports.timeout = newTimeout;
18
18
  }
19
19
  exports.setTimeout = setTimeout;
20
+ exports.logger = undefined;
21
+ function setLogger(newLogger) {
22
+ exports.logger = newLogger;
23
+ }
24
+ exports.setLogger = setLogger;
20
25
  var ResponseType;
21
26
  (function (ResponseType) {
22
27
  ResponseType["CODE"] = "code";
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Logging interface to redirect log messages to your application.
3
+ */
4
+ export default interface LoggingInterface {
5
+ /**
6
+ * Log a warning message.
7
+ * @param message The message to log.
8
+ */
9
+ warn(message: string): void;
10
+ /**
11
+ * Log an error message.
12
+ * @param message The error message to log.
13
+ */
14
+ error(message: string): void;
15
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -86,12 +86,10 @@ var AttributeNumber = /** @class */ (function (_super) {
86
86
  return val;
87
87
  };
88
88
  AttributeNumber.prototype.fromJSON = function (val) {
89
- if (!isNaN(Number(val))) {
90
- return Number(val);
91
- }
92
- else {
89
+ if (val === null || isNaN(Number(val))) {
93
90
  return null;
94
91
  }
92
+ return Number(val);
95
93
  };
96
94
  return AttributeNumber;
97
95
  }(Attribute));
@@ -109,8 +107,8 @@ var AttributeNumberList = /** @class */ (function (_super) {
109
107
  }
110
108
  var nums = [];
111
109
  for (var num in json) {
112
- if (!isNaN(Number(num))) {
113
- nums.push(Number(num));
110
+ if (!isNaN(Number(json[num]))) {
111
+ nums.push(Number(json[num]));
114
112
  }
115
113
  }
116
114
  return nums;
@@ -66,7 +66,11 @@ var Draft = /** @class */ (function (_super) {
66
66
  if (this.rawMime) {
67
67
  throw Error('saveRequestBody() cannot be called for raw MIME drafts');
68
68
  }
69
- return _super.prototype.saveRequestBody.call(this);
69
+ var json = _super.prototype.saveRequestBody.call(this);
70
+ if (this.replyToMessageId !== undefined && this.replyToMessageId === '') {
71
+ delete json.reply_to_message_id;
72
+ }
73
+ return json;
70
74
  };
71
75
  Draft.prototype.deleteRequestBody = function (params) {
72
76
  if (params === void 0) { params = {}; }
@@ -86,8 +86,9 @@ export default class Event extends RestfulModel {
86
86
  organizerEmail?: string;
87
87
  organizerName?: string;
88
88
  hideParticipants?: boolean;
89
- visibility?: string;
90
89
  customerEventId?: string;
90
+ private _visibility?;
91
+ private visibilityIsDirty;
91
92
  static collectionName: string;
92
93
  static attributes: Record<string, Attribute>;
93
94
  constructor(connection: NylasConnection, props?: EventProperties);
@@ -95,10 +96,13 @@ export default class Event extends RestfulModel {
95
96
  set start(val: string | number | undefined);
96
97
  get end(): string | number | undefined;
97
98
  set end(val: string | number | undefined);
99
+ get visibility(): string | undefined;
100
+ set visibility(val: string | undefined);
98
101
  deleteRequestQueryString(params?: Record<string, unknown>): Record<string, unknown>;
99
102
  save(params?: {} | SaveCallback, callback?: SaveCallback): Promise<this>;
100
103
  saveRequestBody(): Record<string, unknown>;
101
- rsvp(status: string, comment: string, callback?: (error: Error | null, data?: Event) => void): Promise<Event>;
104
+ rsvp(status: string, comment?: string, callback?: (error: Error | null, data?: Event) => void): Promise<Event>;
102
105
  generateICS(options?: ICSOptions): Promise<string>;
106
+ fromJSON(json: Record<string, unknown>): this;
103
107
  private validate;
104
108
  }
@@ -49,7 +49,9 @@ var Event = /** @class */ (function (_super) {
49
49
  var _this = _super.call(this, connection, props) || this;
50
50
  _this.calendarId = '';
51
51
  _this.when = new when_1.default();
52
+ _this.visibilityIsDirty = false;
52
53
  _this.initAttributes(props);
54
+ _this.visibilityIsDirty = false;
53
55
  return _this;
54
56
  }
55
57
  Object.defineProperty(Event.prototype, "start", {
@@ -126,6 +128,19 @@ var Event = /** @class */ (function (_super) {
126
128
  enumerable: true,
127
129
  configurable: true
128
130
  });
131
+ Object.defineProperty(Event.prototype, "visibility", {
132
+ get: function () {
133
+ return this._visibility;
134
+ },
135
+ set: function (val) {
136
+ if (val !== this._visibility) {
137
+ this.visibilityIsDirty = true;
138
+ }
139
+ this._visibility = val;
140
+ },
141
+ enumerable: true,
142
+ configurable: true
143
+ });
129
144
  Event.prototype.deleteRequestQueryString = function (params) {
130
145
  if (params === void 0) { params = {}; }
131
146
  var qs = {};
@@ -148,6 +163,10 @@ var Event = /** @class */ (function (_super) {
148
163
  if (this.id && json.participants) {
149
164
  json.participants.forEach(function (participant) { return delete participant.status; });
150
165
  }
166
+ if ((this.visibility !== undefined && this.visibility === '') ||
167
+ !this.visibilityIsDirty) {
168
+ delete json.visibility;
169
+ }
151
170
  return json;
152
171
  };
153
172
  Event.prototype.rsvp = function (status, comment, callback) {
@@ -197,6 +216,11 @@ var Event = /** @class */ (function (_super) {
197
216
  return response.ics;
198
217
  });
199
218
  };
219
+ Event.prototype.fromJSON = function (json) {
220
+ var model = _super.prototype.fromJSON.call(this, json);
221
+ model.visibilityIsDirty = false;
222
+ return model;
223
+ };
200
224
  Event.prototype.validate = function () {
201
225
  if (this.conferencing &&
202
226
  this.conferencing.details &&
@@ -298,7 +322,8 @@ var Event = /** @class */ (function (_super) {
298
322
  modelKey: 'hideParticipants',
299
323
  jsonKey: 'hide_participants',
300
324
  }), visibility: attributes_1.default.String({
301
- modelKey: 'visibility',
325
+ modelKey: '_visibility',
326
+ jsonKey: 'visibility',
302
327
  }), customerEventId: attributes_1.default.String({
303
328
  modelKey: 'customerEventId',
304
329
  jsonKey: 'customer_event_id',
@@ -48,6 +48,7 @@ var delta_collection_1 = __importDefault(require("./models/delta-collection"));
48
48
  var outbox_1 = __importDefault(require("./models/outbox"));
49
49
  var job_status_restful_model_collection_1 = __importDefault(require("./models/job-status-restful-model-collection"));
50
50
  var rate_limit_error_1 = __importDefault(require("./models/rate-limit-error"));
51
+ var config_1 = require("./config");
51
52
  var PACKAGE_JSON = require('../package.json');
52
53
  var SDK_VERSION = PACKAGE_JSON.version;
53
54
  var SUPPORTED_API_VERSION = '2.5';
@@ -189,7 +190,7 @@ var NylasConnection = /** @class */ (function () {
189
190
  controller = new abort_controller_1.default();
190
191
  timeout = setTimeout(function () {
191
192
  controller.abort();
192
- }, 150);
193
+ }, config.timeout);
193
194
  }
194
195
  return new Promise(function (resolve, reject) {
195
196
  return node_fetch_1.default(req, { signal: controller === null || controller === void 0 ? void 0 : controller.signal })
@@ -201,7 +202,7 @@ var NylasConnection = /** @class */ (function () {
201
202
  var apiVersion = response.headers.get('nylas-api-version');
202
203
  var warning = _this.getWarningForVersion(SUPPORTED_API_VERSION, apiVersion);
203
204
  if (warning) {
204
- console.warn(warning);
205
+ config_1.logger === null || config_1.logger === void 0 ? void 0 : config_1.logger.warn(warning);
205
206
  }
206
207
  if (response.status > 299) {
207
208
  return response.text().then(function (body) {
@@ -266,10 +267,10 @@ var NylasConnection = /** @class */ (function () {
266
267
  })
267
268
  .catch(function (err) {
268
269
  if (err && err.name && err.name === 'AbortError') {
269
- console.warn('Request timed out');
270
+ config_1.logger === null || config_1.logger === void 0 ? void 0 : config_1.logger.warn('Request timed out');
270
271
  return reject(err);
271
272
  }
272
- console.error("Error encountered during request:\n" + err.stack);
273
+ config_1.logger === null || config_1.logger === void 0 ? void 0 : config_1.logger.error("Error encountered during request:\n" + err.stack);
273
274
  return reject(err);
274
275
  })
275
276
  .then(function () {
package/lib/nylas.d.ts CHANGED
@@ -8,6 +8,7 @@ import Webhook from './models/webhook';
8
8
  import { AuthenticateUrlConfig, NylasConfig } from './config';
9
9
  import AccessToken from './models/access-token';
10
10
  import ApplicationDetails, { ApplicationDetailsProperties } from './models/application-details';
11
+ import LoggingInterface from './models/LoggingInterface';
11
12
  declare class Nylas {
12
13
  static clientId: string;
13
14
  static get clientSecret(): string;
@@ -16,6 +17,8 @@ declare class Nylas {
16
17
  static set apiServer(newApiServer: string | null);
17
18
  static get timeout(): number;
18
19
  static set timeout(timeout: number);
20
+ static get logger(): LoggingInterface | undefined;
21
+ static set logger(timeout: LoggingInterface | undefined);
19
22
  static accounts: ManagementModelCollection<ManagementAccount> | RestfulModelCollection<Account>;
20
23
  static connect: Connect;
21
24
  static webhooks: ManagementModelCollection<Webhook>;
package/lib/nylas.js CHANGED
@@ -57,6 +57,17 @@ var Nylas = /** @class */ (function () {
57
57
  enumerable: true,
58
58
  configurable: true
59
59
  });
60
+ Object.defineProperty(Nylas, "logger", {
61
+ get: function () {
62
+ return config.logger;
63
+ },
64
+ // Logger to redirect log messages to your application
65
+ set: function (timeout) {
66
+ config.setLogger(timeout);
67
+ },
68
+ enumerable: true,
69
+ configurable: true
70
+ });
60
71
  Nylas.config = function (config) {
61
72
  if (config.apiServer && config.apiServer.indexOf('://') === -1) {
62
73
  throw new Error('Please specify a fully qualified URL for the API Server.');
@@ -74,6 +85,9 @@ var Nylas = /** @class */ (function () {
74
85
  this.apiServer = 'https://api.nylas.com';
75
86
  }
76
87
  this.timeout = config.timeout || 0;
88
+ if (config.logger) {
89
+ this.logger = config.logger;
90
+ }
77
91
  var conn = new nylas_connection_1.default(this.clientSecret, {
78
92
  clientId: this.clientId,
79
93
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nylas",
3
- "version": "6.10.0",
3
+ "version": "6.11.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",
@@ -47,7 +47,7 @@
47
47
  "backoff": "^2.5.0",
48
48
  "form-data": "^4.0.0",
49
49
  "JSONStream": "^1.3.5",
50
- "node-fetch": "^2.6.1",
50
+ "node-fetch": "^2.6.12",
51
51
  "uuid": "^8.3.2",
52
52
  "websocket": "^1.0.34"
53
53
  },