nylas 6.6.0 → 6.7.0

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
@@ -7,6 +7,10 @@ export declare type NylasConfig = {
7
7
  clientSecret: string;
8
8
  apiServer?: string;
9
9
  };
10
+ export declare enum ResponseType {
11
+ CODE = "code",
12
+ TOKEN = "token"
13
+ }
10
14
  export declare type AuthenticateUrlConfig = {
11
15
  redirectURI: string;
12
16
  redirectOnError?: boolean;
@@ -14,4 +18,5 @@ export declare type AuthenticateUrlConfig = {
14
18
  state?: string;
15
19
  provider?: string;
16
20
  scopes?: string[];
21
+ responseType?: ResponseType;
17
22
  };
package/lib/config.js CHANGED
@@ -10,3 +10,8 @@ function setClientSecret(newClientSecret) {
10
10
  exports.clientSecret = newClientSecret;
11
11
  }
12
12
  exports.setClientSecret = setClientSecret;
13
+ var ResponseType;
14
+ (function (ResponseType) {
15
+ ResponseType["CODE"] = "code";
16
+ ResponseType["TOKEN"] = "token";
17
+ })(ResponseType = exports.ResponseType || (exports.ResponseType = {}));
@@ -12,7 +12,7 @@ export declare type CalendarProperties = {
12
12
  isPrimary?: boolean;
13
13
  jobStatusId?: string;
14
14
  metadata?: object;
15
- color?: number;
15
+ hexColor?: string;
16
16
  };
17
17
  export default class Calendar extends RestfulModel implements CalendarProperties {
18
18
  name: string;
@@ -23,7 +23,7 @@ export default class Calendar extends RestfulModel implements CalendarProperties
23
23
  isPrimary?: boolean;
24
24
  jobStatusId?: string;
25
25
  metadata?: object;
26
- color?: number;
26
+ hexColor?: string;
27
27
  static collectionName: string;
28
28
  static attributes: Record<string, Attribute>;
29
29
  constructor(connection: NylasConnection, props?: CalendarProperties);
@@ -87,8 +87,9 @@ var Calendar = /** @class */ (function (_super) {
87
87
  readOnly: true,
88
88
  }), metadata: attributes_1.default.Object({
89
89
  modelKey: 'metadata',
90
- }), color: attributes_1.default.Number({
91
- modelKey: 'color',
90
+ }), hexColor: attributes_1.default.String({
91
+ modelKey: 'hexColor',
92
+ jsonKey: 'hex_color',
92
93
  readOnly: true,
93
94
  }) });
94
95
  return Calendar;
@@ -296,7 +296,6 @@ var Event = /** @class */ (function (_super) {
296
296
  readOnly: true,
297
297
  }), visibility: attributes_1.default.String({
298
298
  modelKey: 'visibility',
299
- readOnly: true,
300
299
  }), customerEventId: attributes_1.default.String({
301
300
  modelKey: 'customerEventId',
302
301
  jsonKey: 'customer_event_id',
@@ -0,0 +1,26 @@
1
+ import NylasApiError from './nylas-api-error';
2
+ import { Headers } from 'node-fetch';
3
+ /**
4
+ * This error class represents a 429 error response, with details on the rate limit
5
+ */
6
+ export default class RateLimitError extends NylasApiError {
7
+ static RATE_LIMIT_STATUS_CODE: number;
8
+ static RATE_LIMIT_LIMIT_HEADER: string;
9
+ static RATE_LIMIT_RESET_HEADER: string;
10
+ /**
11
+ * The rate limit
12
+ */
13
+ rateLimit?: number;
14
+ /**
15
+ * The rate limit expiration time, in seconds
16
+ */
17
+ rateLimitReset?: number;
18
+ constructor(type: string, message: string, rateLimit?: number, rateLimitReset?: number);
19
+ /**
20
+ * Parses an API response and generates a 429 error with details filled in
21
+ * @param parsedApiError The response parsed as a JSON
22
+ * @param headers The response headers
23
+ * @return The error with the rate limit details filled in
24
+ */
25
+ static parseErrorResponse(parsedApiError: Record<string, string>, headers: Headers): RateLimitError;
26
+ }
@@ -0,0 +1,47 @@
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 nylas_api_error_1 = __importDefault(require("./nylas-api-error"));
20
+ /**
21
+ * This error class represents a 429 error response, with details on the rate limit
22
+ */
23
+ var RateLimitError = /** @class */ (function (_super) {
24
+ __extends(RateLimitError, _super);
25
+ function RateLimitError(type, message, rateLimit, rateLimitReset) {
26
+ var _this = _super.call(this, RateLimitError.RATE_LIMIT_STATUS_CODE, type, message) || this;
27
+ _this.rateLimit = rateLimit;
28
+ _this.rateLimitReset = rateLimitReset;
29
+ return _this;
30
+ }
31
+ /**
32
+ * Parses an API response and generates a 429 error with details filled in
33
+ * @param parsedApiError The response parsed as a JSON
34
+ * @param headers The response headers
35
+ * @return The error with the rate limit details filled in
36
+ */
37
+ RateLimitError.parseErrorResponse = function (parsedApiError, headers) {
38
+ var rateLimit = Number(headers.get(this.RATE_LIMIT_LIMIT_HEADER)) || undefined;
39
+ var rateLimitReset = Number(headers.get(this.RATE_LIMIT_RESET_HEADER)) || undefined;
40
+ return new RateLimitError(parsedApiError.type, parsedApiError.message, rateLimit, rateLimitReset);
41
+ };
42
+ RateLimitError.RATE_LIMIT_STATUS_CODE = 429;
43
+ RateLimitError.RATE_LIMIT_LIMIT_HEADER = 'X-RateLimit-Limit';
44
+ RateLimitError.RATE_LIMIT_RESET_HEADER = 'X-RateLimit-Reset';
45
+ return RateLimitError;
46
+ }(nylas_api_error_1.default));
47
+ exports.default = RateLimitError;
@@ -76,6 +76,8 @@ export declare class WebhookObjectAttributes extends Model implements WebhookObj
76
76
  extras?: WebhookObjectExtrasProperties;
77
77
  threadId?: string;
78
78
  receivedDate?: Date;
79
+ calendarId?: string;
80
+ createdBeforeAccountConnection?: boolean;
79
81
  static attributes: Record<string, Attribute>;
80
82
  constructor(props?: WebhookObjectAttributesProperties);
81
83
  }
@@ -84,7 +86,7 @@ export declare type WebhookObjectDataProperties = {
84
86
  accountId: string;
85
87
  namespaceId: string;
86
88
  object: string;
87
- metadata?: MessageTrackingDataProperties;
89
+ metadata?: MessageTrackingDataProperties | Record<string, unknown>;
88
90
  objectAttributes?: WebhookObjectAttributesProperties;
89
91
  };
90
92
  export declare class WebhookObjectData extends Model implements WebhookObjectDataProperties {
@@ -92,10 +94,11 @@ export declare class WebhookObjectData extends Model implements WebhookObjectDat
92
94
  accountId: string;
93
95
  namespaceId: string;
94
96
  object: string;
95
- metadata?: MessageTrackingData;
97
+ metadata?: MessageTrackingData | Record<string, unknown>;
96
98
  objectAttributes?: WebhookObjectAttributes;
97
99
  static attributes: Record<string, Attribute>;
98
100
  constructor(props?: WebhookObjectDataProperties);
101
+ fromJSON(json: Record<string, unknown>): this;
99
102
  }
100
103
  export declare type WebhookDeltaProperties = {
101
104
  object: string;
@@ -168,10 +168,18 @@ var WebhookObjectAttributes = /** @class */ (function (_super) {
168
168
  modelKey: 'threadId',
169
169
  jsonKey: 'thread_id',
170
170
  }),
171
+ calendarId: attributes_1.default.String({
172
+ modelKey: 'calendarId',
173
+ jsonKey: 'calendar_id',
174
+ }),
171
175
  receivedDate: attributes_1.default.DateTime({
172
176
  modelKey: 'receivedDate',
173
177
  jsonKey: 'received_date',
174
178
  }),
179
+ createdBeforeAccountConnection: attributes_1.default.Boolean({
180
+ modelKey: 'createdBeforeAccountConnection',
181
+ jsonKey: 'created_before_account_connection',
182
+ }),
175
183
  extras: attributes_1.default.Object({
176
184
  modelKey: 'extras',
177
185
  itemClass: WebhookObjectExtras,
@@ -189,8 +197,20 @@ var WebhookObjectData = /** @class */ (function (_super) {
189
197
  _this.namespaceId = '';
190
198
  _this.object = '';
191
199
  _this.initAttributes(props);
200
+ if (_this.metadata &&
201
+ (_this.object === 'message' || _this.object === 'thread')) {
202
+ _this.metadata = new MessageTrackingData(_this.metadata);
203
+ }
192
204
  return _this;
193
205
  }
206
+ WebhookObjectData.prototype.fromJSON = function (json) {
207
+ var notification = _super.prototype.fromJSON.call(this, json);
208
+ if (notification.metadata &&
209
+ (notification.object === 'message' || notification.object === 'thread')) {
210
+ notification.metadata = new MessageTrackingData().fromJSON(json['metadata']);
211
+ }
212
+ return notification;
213
+ };
194
214
  WebhookObjectData.attributes = {
195
215
  id: attributes_1.default.String({
196
216
  modelKey: 'id',
@@ -208,7 +228,6 @@ var WebhookObjectData = /** @class */ (function (_super) {
208
228
  }),
209
229
  metadata: attributes_1.default.Object({
210
230
  modelKey: 'metadata',
211
- itemClass: MessageTrackingData,
212
231
  }),
213
232
  objectAttributes: attributes_1.default.Object({
214
233
  modelKey: 'objectAttributes',
@@ -45,6 +45,7 @@ var message_restful_model_collection_1 = __importDefault(require("./models/messa
45
45
  var delta_collection_1 = __importDefault(require("./models/delta-collection"));
46
46
  var outbox_1 = __importDefault(require("./models/outbox"));
47
47
  var job_status_restful_model_collection_1 = __importDefault(require("./models/job-status-restful-model-collection"));
48
+ var rate_limit_error_1 = __importDefault(require("./models/rate-limit-error"));
48
49
  var PACKAGE_JSON = require('../package.json');
49
50
  var SDK_VERSION = PACKAGE_JSON.version;
50
51
  var SUPPORTED_API_VERSION = '2.5';
@@ -196,7 +197,13 @@ var NylasConnection = /** @class */ (function () {
196
197
  return response.text().then(function (body) {
197
198
  try {
198
199
  var parsedApiError = JSON.parse(body);
199
- var error = new nylas_api_error_1.default(response.status, parsedApiError.type, parsedApiError.message);
200
+ var error = void 0;
201
+ if (response.status === rate_limit_error_1.default.RATE_LIMIT_STATUS_CODE) {
202
+ error = rate_limit_error_1.default.parseErrorResponse(parsedApiError, response.headers);
203
+ }
204
+ else {
205
+ error = new nylas_api_error_1.default(response.status, parsedApiError.type, parsedApiError.message);
206
+ }
200
207
  if (parsedApiError.missing_fields) {
201
208
  error.missingFields = parsedApiError.missing_fields;
202
209
  }
package/lib/nylas.js CHANGED
@@ -20,6 +20,7 @@ var connect_1 = __importDefault(require("./models/connect"));
20
20
  var restful_model_collection_1 = __importDefault(require("./models/restful-model-collection"));
21
21
  var management_model_collection_1 = __importDefault(require("./models/management-model-collection"));
22
22
  var webhook_1 = __importDefault(require("./models/webhook"));
23
+ var config_1 = require("./config");
23
24
  var access_token_1 = __importDefault(require("./models/access-token"));
24
25
  var application_details_1 = __importDefault(require("./models/application-details"));
25
26
  var Nylas = /** @class */ (function () {
@@ -153,7 +154,7 @@ var Nylas = /** @class */ (function () {
153
154
  if (!options.loginHint) {
154
155
  options.loginHint = '';
155
156
  }
156
- var url = this.apiServer + "/oauth/authorize?client_id=" + this.clientId + "&response_type=code&login_hint=" + options.loginHint + "&redirect_uri=" + options.redirectURI;
157
+ var url = this.apiServer + "/oauth/authorize?client_id=" + this.clientId + "&response_type=" + (options.responseType || config_1.ResponseType.CODE) + "&login_hint=" + options.loginHint + "&redirect_uri=" + options.redirectURI;
157
158
  if (options.state != null) {
158
159
  url += "&state=" + options.state;
159
160
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nylas",
3
- "version": "6.6.0",
3
+ "version": "6.7.0",
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",