nylas 6.2.0-canary.0 → 6.2.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.
@@ -1,5 +1,5 @@
1
1
  import Model from './model';
2
- import RestfulModel from './restful-model';
2
+ declare type AnyModel = new (...args: any[]) => Model;
3
3
  export declare abstract class Attribute {
4
4
  modelKey: string;
5
5
  jsonKey: string;
@@ -18,7 +18,7 @@ declare class AttributeObject extends Attribute {
18
18
  constructor({ modelKey, jsonKey, itemClass, readOnly, }: {
19
19
  modelKey: string;
20
20
  jsonKey?: string;
21
- itemClass?: typeof Model | typeof RestfulModel;
21
+ itemClass?: AnyModel;
22
22
  readOnly?: boolean;
23
23
  });
24
24
  toJSON(val: any, saveRequestBody?: boolean): unknown;
@@ -58,12 +58,12 @@ declare class AttributeCollection extends Attribute {
58
58
  constructor({ modelKey, jsonKey, itemClass, readOnly, }: {
59
59
  modelKey: string;
60
60
  jsonKey?: string;
61
- itemClass: typeof Model | typeof RestfulModel;
61
+ itemClass: AnyModel;
62
62
  readOnly?: boolean;
63
63
  });
64
- toJSON(vals: any, saveRequestBody?: boolean): unknown[];
65
- fromJSON(json: unknown[], _parent: any): typeof Model[] | typeof RestfulModel[] | unknown[];
66
- saveRequestBody(val: any): unknown;
64
+ toJSON(vals: any, saveRequestBody?: boolean): AnyModel[];
65
+ fromJSON(json: unknown[], _parent: any): AnyModel[];
66
+ saveRequestBody(val: any): AnyModel[] | undefined;
67
67
  }
68
68
  declare class AttributeEnum extends Attribute {
69
69
  itemClass: any;
@@ -121,7 +121,7 @@ declare const Attributes: {
121
121
  Collection(__0: {
122
122
  modelKey: string;
123
123
  jsonKey?: string | undefined;
124
- itemClass: typeof Model | typeof RestfulModel;
124
+ itemClass: AnyModel;
125
125
  readOnly?: boolean | undefined;
126
126
  }): AttributeCollection;
127
127
  Boolean(__0: {
@@ -132,7 +132,7 @@ declare const Attributes: {
132
132
  Object(__0: {
133
133
  modelKey: string;
134
134
  jsonKey?: string | undefined;
135
- itemClass?: typeof Model | typeof RestfulModel | undefined;
135
+ itemClass?: AnyModel | undefined;
136
136
  readOnly?: boolean | undefined;
137
137
  }): AttributeObject;
138
138
  Enum(__0: {
@@ -19,15 +19,11 @@ var __spreadArrays = (this && this.__spreadArrays) || function () {
19
19
  r[k] = a[j];
20
20
  return r;
21
21
  };
22
- var __importDefault = (this && this.__importDefault) || function (mod) {
23
- return (mod && mod.__esModule) ? mod : { "default": mod };
24
- };
25
22
  Object.defineProperty(exports, "__esModule", { value: true });
26
- var restful_model_1 = __importDefault(require("./restful-model"));
27
- // The Attribute class represents a single model attribute, like 'namespace_id'
28
- // Subclasses of Attribute like AttributeDateTime know how to covert between
29
- // the JSON representation of that type and the javascript representation.
30
- // The Attribute class also exposes convenience methods for generating Matchers.
23
+ function isRestfulModel(cls) {
24
+ // A 'RestfulModel' has 'endpointName' and 'collectionName' unlike 'Model'
25
+ return cls.endpointName !== undefined && cls.collectionName !== undefined;
26
+ }
31
27
  var Attribute = /** @class */ (function () {
32
28
  function Attribute(_a) {
33
29
  var modelKey = _a.modelKey, jsonKey = _a.jsonKey, readOnly = _a.readOnly;
@@ -68,8 +64,8 @@ var AttributeObject = /** @class */ (function (_super) {
68
64
  if (!val || !this.itemClass) {
69
65
  return val;
70
66
  }
71
- if (this.itemClass.prototype instanceof restful_model_1.default) {
72
- return new this.itemClass(_parent.connection).fromJSON(val);
67
+ if (isRestfulModel(this.itemClass)) {
68
+ return new this.itemClass(_parent.connection, val).fromJSON(val);
73
69
  }
74
70
  return new this.itemClass(val).fromJSON(val);
75
71
  };
@@ -239,8 +235,8 @@ var AttributeCollection = /** @class */ (function (_super) {
239
235
  for (var _i = 0, json_1 = json; _i < json_1.length; _i++) {
240
236
  var objJSON = json_1[_i];
241
237
  var obj = void 0;
242
- if (this.itemClass.prototype instanceof restful_model_1.default) {
243
- obj = new this.itemClass(_parent.connection).fromJSON(objJSON);
238
+ if (isRestfulModel(this.itemClass)) {
239
+ obj = new this.itemClass(_parent.connection, objJSON).fromJSON(objJSON);
244
240
  }
245
241
  else {
246
242
  obj = new this.itemClass(objJSON).fromJSON(objJSON);
@@ -12,9 +12,11 @@ export default class Draft extends Message implements DraftProperties {
12
12
  rawMime?: string;
13
13
  replyToMessageId?: string;
14
14
  version?: number;
15
+ fileIdsToAttach?: string[];
15
16
  static collectionName: string;
16
17
  static attributes: Record<string, Attribute>;
17
18
  constructor(connection: NylasConnection, props?: DraftProperties);
19
+ fileIds(): (string | undefined)[];
18
20
  toJSON(enforceReadOnly?: boolean): Record<string, any>;
19
21
  save(params?: {} | SaveCallback, callback?: SaveCallback): Promise<this>;
20
22
  saveRequestBody(): Record<string, unknown>;
@@ -36,12 +36,19 @@ var Draft = /** @class */ (function (_super) {
36
36
  _this.initAttributes(props);
37
37
  return _this;
38
38
  }
39
+ Draft.prototype.fileIds = function () {
40
+ var fileIds = _super.prototype.fileIds.call(this);
41
+ if (this.fileIdsToAttach) {
42
+ fileIds = Array.from(new Set(fileIds.concat(this.fileIdsToAttach)));
43
+ }
44
+ return fileIds;
45
+ };
39
46
  Draft.prototype.toJSON = function (enforceReadOnly) {
40
47
  if (this.rawMime) {
41
48
  throw Error('toJSON() cannot be called for raw MIME drafts');
42
49
  }
43
50
  var json = _super.prototype.toJSON.call(this, enforceReadOnly);
44
- json.file_ids = _super.prototype.fileIds.call(this);
51
+ json.file_ids = this.fileIds();
45
52
  return json;
46
53
  };
47
54
  Draft.prototype.save = function (params, callback) {
@@ -33,6 +33,7 @@ export declare type ManagementAccountProperties = {
33
33
  namespaceId: string;
34
34
  provider: string;
35
35
  syncState: string;
36
+ authenticationType: string;
36
37
  trial: boolean;
37
38
  metadata?: object;
38
39
  };
@@ -45,6 +46,7 @@ export default class ManagementAccount extends ManagementModel implements Manage
45
46
  namespaceId: string;
46
47
  provider: string;
47
48
  syncState: string;
49
+ authenticationType: string;
48
50
  trial: boolean;
49
51
  metadata?: object;
50
52
  static collectionName: string;
@@ -91,6 +91,7 @@ var ManagementAccount = /** @class */ (function (_super) {
91
91
  _this.namespaceId = '';
92
92
  _this.provider = '';
93
93
  _this.syncState = '';
94
+ _this.authenticationType = '';
94
95
  _this.trial = false;
95
96
  _this.initAttributes(props);
96
97
  return _this;
@@ -173,6 +174,9 @@ var ManagementAccount = /** @class */ (function (_super) {
173
174
  }), syncState: attributes_1.default.String({
174
175
  modelKey: 'syncState',
175
176
  jsonKey: 'sync_state',
177
+ }), authenticationType: attributes_1.default.String({
178
+ modelKey: 'authenticationType',
179
+ jsonKey: 'authentication_type',
176
180
  }), trial: attributes_1.default.Boolean({
177
181
  modelKey: 'trial',
178
182
  }), metadata: attributes_1.default.Object({
@@ -0,0 +1,26 @@
1
+ import RestfulModelCollection from './restful-model-collection';
2
+ import Message from './message';
3
+ import NylasConnection from '../nylas-connection';
4
+ export default class MessageRestfulModelCollection extends RestfulModelCollection<Message> {
5
+ connection: NylasConnection;
6
+ modelClass: typeof Message;
7
+ constructor(connection: NylasConnection);
8
+ /**
9
+ * Return Multiple Messages by a list of Message IDs.
10
+ * @param messageIds The list of message ids to find.
11
+ * @param options Additional options including: view, offset, limit, and callback
12
+ * @returns The list of messages.
13
+ */
14
+ findMultiple(messageIds: string[], options?: {
15
+ view?: string;
16
+ offset?: number;
17
+ limit?: number;
18
+ callback?: (error: Error | null, results?: Message[]) => void;
19
+ }): Promise<Message[]>;
20
+ /**
21
+ * Return raw message contents
22
+ * @param messageId The message to fetch content of
23
+ * @returns The raw message contents
24
+ */
25
+ findRaw(messageId: string): Promise<string>;
26
+ }
@@ -0,0 +1,74 @@
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 __assign = (this && this.__assign) || function () {
16
+ __assign = Object.assign || function(t) {
17
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
18
+ s = arguments[i];
19
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
20
+ t[p] = s[p];
21
+ }
22
+ return t;
23
+ };
24
+ return __assign.apply(this, arguments);
25
+ };
26
+ var __importDefault = (this && this.__importDefault) || function (mod) {
27
+ return (mod && mod.__esModule) ? mod : { "default": mod };
28
+ };
29
+ Object.defineProperty(exports, "__esModule", { value: true });
30
+ var restful_model_collection_1 = __importDefault(require("./restful-model-collection"));
31
+ var message_1 = __importDefault(require("./message"));
32
+ var MessageRestfulModelCollection = /** @class */ (function (_super) {
33
+ __extends(MessageRestfulModelCollection, _super);
34
+ function MessageRestfulModelCollection(connection) {
35
+ var _this = _super.call(this, message_1.default, connection) || this;
36
+ _this.connection = connection;
37
+ _this.modelClass = message_1.default;
38
+ return _this;
39
+ }
40
+ /**
41
+ * Return Multiple Messages by a list of Message IDs.
42
+ * @param messageIds The list of message ids to find.
43
+ * @param options Additional options including: view, offset, limit, and callback
44
+ * @returns The list of messages.
45
+ */
46
+ MessageRestfulModelCollection.prototype.findMultiple = function (messageIds, options) {
47
+ if (options && options.view) {
48
+ // view is a parameter, so move it into a params object
49
+ options.params = {
50
+ view: options.view,
51
+ };
52
+ delete options.view;
53
+ }
54
+ return this.range(__assign({ path: this.path() + "/" + messageIds.join() }, options));
55
+ };
56
+ /**
57
+ * Return raw message contents
58
+ * @param messageId The message to fetch content of
59
+ * @returns The raw message contents
60
+ */
61
+ MessageRestfulModelCollection.prototype.findRaw = function (messageId) {
62
+ return this.connection
63
+ .request({
64
+ method: 'GET',
65
+ headers: {
66
+ Accept: 'message/rfc822',
67
+ },
68
+ path: this.path() + "/" + messageId,
69
+ })
70
+ .catch(function (err) { return Promise.reject(err); });
71
+ };
72
+ return MessageRestfulModelCollection;
73
+ }(restful_model_collection_1.default));
74
+ exports.default = MessageRestfulModelCollection;
@@ -0,0 +1,21 @@
1
+ import OutboxMessage, { OutboxMessageProperties } from './outbox-message';
2
+ import Model from './model';
3
+ import { Attribute } from './attributes';
4
+ import NylasConnection from '../nylas-connection';
5
+ export declare type OutboxJobStatusProperties = {
6
+ jobStatusId: string;
7
+ accountId: string;
8
+ status: string;
9
+ originalData?: OutboxMessageProperties;
10
+ };
11
+ export default class OutboxJobStatus extends Model implements OutboxJobStatusProperties {
12
+ jobStatusId: string;
13
+ status: string;
14
+ accountId: string;
15
+ originalData?: OutboxMessage;
16
+ private _connection?;
17
+ static attributes: Record<string, Attribute>;
18
+ constructor(props?: OutboxJobStatusProperties);
19
+ get connection(): NylasConnection | undefined;
20
+ fromJSON(json: Record<string, unknown>, connection?: NylasConnection): this;
21
+ }
@@ -0,0 +1,70 @@
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 outbox_message_1 = __importDefault(require("./outbox-message"));
20
+ var model_1 = __importDefault(require("./model"));
21
+ var attributes_1 = __importDefault(require("./attributes"));
22
+ var OutboxJobStatus = /** @class */ (function (_super) {
23
+ __extends(OutboxJobStatus, _super);
24
+ function OutboxJobStatus(props) {
25
+ var _this = _super.call(this) || this;
26
+ _this.jobStatusId = '';
27
+ _this.status = '';
28
+ _this.accountId = '';
29
+ _this.initAttributes(props);
30
+ return _this;
31
+ }
32
+ Object.defineProperty(OutboxJobStatus.prototype, "connection", {
33
+ get: function () {
34
+ return this._connection;
35
+ },
36
+ enumerable: true,
37
+ configurable: true
38
+ });
39
+ OutboxJobStatus.prototype.fromJSON = function (json, connection) {
40
+ // Allow a connection object to be passed in to instantiate a Calendar sub object
41
+ if (connection) {
42
+ this._connection = connection;
43
+ }
44
+ return _super.prototype.fromJSON.call(this, json);
45
+ };
46
+ OutboxJobStatus.attributes = {
47
+ jobStatusId: attributes_1.default.String({
48
+ modelKey: 'jobStatusId',
49
+ jsonKey: 'job_status_id',
50
+ readOnly: true,
51
+ }),
52
+ status: attributes_1.default.String({
53
+ modelKey: 'status',
54
+ readOnly: true,
55
+ }),
56
+ accountId: attributes_1.default.String({
57
+ modelKey: 'accountId',
58
+ jsonKey: 'account_id',
59
+ readOnly: true,
60
+ }),
61
+ originalData: attributes_1.default.Object({
62
+ modelKey: 'originalData',
63
+ jsonKey: 'original_data',
64
+ itemClass: outbox_message_1.default,
65
+ readOnly: true,
66
+ }),
67
+ };
68
+ return OutboxJobStatus;
69
+ }(model_1.default));
70
+ exports.default = OutboxJobStatus;
@@ -0,0 +1,16 @@
1
+ import Draft, { DraftProperties } from './draft';
2
+ import { Attribute } from './attributes';
3
+ import NylasConnection from '../nylas-connection';
4
+ export declare type OutboxMessageProperties = DraftProperties & {
5
+ sendAt: Date;
6
+ retryLimitDatetime?: Date;
7
+ originalSendAt?: Date;
8
+ };
9
+ export default class OutboxMessage extends Draft implements OutboxMessageProperties {
10
+ sendAt: Date;
11
+ retryLimitDatetime?: Date;
12
+ originalSendAt?: Date;
13
+ static collectionName: string;
14
+ static attributes: Record<string, Attribute>;
15
+ constructor(connection: NylasConnection, props?: OutboxMessageProperties);
16
+ }
@@ -0,0 +1,54 @@
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 __assign = (this && this.__assign) || function () {
16
+ __assign = Object.assign || function(t) {
17
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
18
+ s = arguments[i];
19
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
20
+ t[p] = s[p];
21
+ }
22
+ return t;
23
+ };
24
+ return __assign.apply(this, arguments);
25
+ };
26
+ var __importDefault = (this && this.__importDefault) || function (mod) {
27
+ return (mod && mod.__esModule) ? mod : { "default": mod };
28
+ };
29
+ Object.defineProperty(exports, "__esModule", { value: true });
30
+ var draft_1 = __importDefault(require("./draft"));
31
+ var attributes_1 = __importDefault(require("./attributes"));
32
+ var OutboxMessage = /** @class */ (function (_super) {
33
+ __extends(OutboxMessage, _super);
34
+ function OutboxMessage(connection, props) {
35
+ var _this = _super.call(this, connection, props) || this;
36
+ _this.sendAt = new Date();
37
+ _this.initAttributes(props);
38
+ return _this;
39
+ }
40
+ OutboxMessage.collectionName = '/v2/outbox';
41
+ OutboxMessage.attributes = __assign(__assign({}, draft_1.default.attributes), { sendAt: attributes_1.default.DateTime({
42
+ modelKey: 'sendAt',
43
+ jsonKey: 'send_at',
44
+ }), retryLimitDatetime: attributes_1.default.DateTime({
45
+ modelKey: 'retryLimitDatetime',
46
+ jsonKey: 'retry_limit_datetime',
47
+ }), originalSendAt: attributes_1.default.DateTime({
48
+ modelKey: 'originalSendAt',
49
+ jsonKey: 'original_send_at',
50
+ readOnly: true,
51
+ }) });
52
+ return OutboxMessage;
53
+ }(draft_1.default));
54
+ exports.default = OutboxMessage;
@@ -0,0 +1,35 @@
1
+ import NylasConnection from '../nylas-connection';
2
+ import Draft, { SendCallback } from './draft';
3
+ import OutboxJobStatus from './outbox-job-status';
4
+ import Model from './model';
5
+ import { Attribute } from './attributes';
6
+ declare type SendParams = {
7
+ sendAt: Date | number;
8
+ retryLimitDatetime?: Date | number;
9
+ tracking?: Record<string, any>;
10
+ callback?: SendCallback;
11
+ };
12
+ declare type UpdateParams = {
13
+ updatedMessage?: Draft;
14
+ sendAt?: Date | number;
15
+ retryLimitDatetime?: Date | number;
16
+ };
17
+ export declare class SendGridVerifiedStatus extends Model {
18
+ domainVerified?: boolean;
19
+ senderVerified?: boolean;
20
+ static attributes: Record<string, Attribute>;
21
+ }
22
+ export default class Outbox {
23
+ connection: NylasConnection;
24
+ private path;
25
+ constructor(connection: NylasConnection);
26
+ send(draft: Draft, options: SendParams): Promise<OutboxJobStatus>;
27
+ update(jobStatusId: string, options: UpdateParams): Promise<OutboxJobStatus>;
28
+ delete(jobStatusId: string): Promise<void>;
29
+ sendGridVerificationStatus(): Promise<SendGridVerifiedStatus>;
30
+ deleteSendGridSubUser(email: string): Promise<void>;
31
+ private request;
32
+ private static validateAndFormatDateTime;
33
+ private static dateToEpoch;
34
+ }
35
+ export {};
@@ -0,0 +1,158 @@
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_connection_1 = require("../nylas-connection");
20
+ var outbox_job_status_1 = __importDefault(require("./outbox-job-status"));
21
+ var model_1 = __importDefault(require("./model"));
22
+ var attributes_1 = __importDefault(require("./attributes"));
23
+ var SendGridVerifiedStatus = /** @class */ (function (_super) {
24
+ __extends(SendGridVerifiedStatus, _super);
25
+ function SendGridVerifiedStatus() {
26
+ return _super !== null && _super.apply(this, arguments) || this;
27
+ }
28
+ SendGridVerifiedStatus.attributes = {
29
+ domainVerified: attributes_1.default.Boolean({
30
+ modelKey: 'domainVerified',
31
+ jsonKey: 'domain_verified',
32
+ }),
33
+ senderVerified: attributes_1.default.Boolean({
34
+ modelKey: 'senderVerified',
35
+ jsonKey: 'sender_verified',
36
+ }),
37
+ };
38
+ return SendGridVerifiedStatus;
39
+ }(model_1.default));
40
+ exports.SendGridVerifiedStatus = SendGridVerifiedStatus;
41
+ var Outbox = /** @class */ (function () {
42
+ function Outbox(connection) {
43
+ this.path = '/v2/outbox';
44
+ this.connection = connection;
45
+ }
46
+ Outbox.prototype.send = function (draft, options) {
47
+ var _this = this;
48
+ var body = draft.saveRequestBody();
49
+ if (options.tracking) {
50
+ body['tracking'] = options.tracking;
51
+ }
52
+ var _a = Outbox.validateAndFormatDateTime(options.sendAt, options.retryLimitDatetime), sendAt = _a[0], retryLimitDatetime = _a[1];
53
+ body['send_at'] = sendAt;
54
+ body['retry_limit_datetime'] = retryLimitDatetime;
55
+ return this.request({
56
+ method: 'POST',
57
+ path: '',
58
+ body: body,
59
+ })
60
+ .then(function (json) {
61
+ var message = new outbox_job_status_1.default().fromJSON(json, _this.connection);
62
+ if (options.callback) {
63
+ options.callback(null, message);
64
+ }
65
+ return Promise.resolve(message);
66
+ })
67
+ .catch(function (err) {
68
+ if (options.callback) {
69
+ options.callback(err);
70
+ }
71
+ return Promise.reject(err);
72
+ });
73
+ };
74
+ Outbox.prototype.update = function (jobStatusId, options) {
75
+ var _this = this;
76
+ var body = {};
77
+ if (options.updatedMessage) {
78
+ body = options.updatedMessage.saveRequestBody();
79
+ }
80
+ var _a = Outbox.validateAndFormatDateTime(options.sendAt, options.retryLimitDatetime), sendAt = _a[0], retryLimitDatetime = _a[1];
81
+ body['send_at'] = sendAt;
82
+ body['retry_limit_datetime'] = retryLimitDatetime;
83
+ return this.request({
84
+ method: 'PATCH',
85
+ path: "/" + jobStatusId,
86
+ body: body,
87
+ }).then(function (json) {
88
+ var message = new outbox_job_status_1.default().fromJSON(json, _this.connection);
89
+ return Promise.resolve(message);
90
+ });
91
+ };
92
+ Outbox.prototype.delete = function (jobStatusId) {
93
+ return this.request({
94
+ method: 'DELETE',
95
+ path: "/" + jobStatusId,
96
+ });
97
+ };
98
+ Outbox.prototype.sendGridVerificationStatus = function () {
99
+ return this.request({
100
+ method: 'GET',
101
+ path: "/onboard/verified_status",
102
+ }).then(function (json) {
103
+ if (json.results) {
104
+ json = json.results;
105
+ }
106
+ var verifiedStatus = new SendGridVerifiedStatus().fromJSON(json);
107
+ return Promise.resolve(verifiedStatus);
108
+ });
109
+ };
110
+ Outbox.prototype.deleteSendGridSubUser = function (email) {
111
+ return this.request({
112
+ method: 'DELETE',
113
+ path: "/onboard/subuser",
114
+ body: { email: email },
115
+ });
116
+ };
117
+ Outbox.prototype.request = function (options) {
118
+ var header;
119
+ if (options.body) {
120
+ header = {
121
+ 'Content-Type': 'application/json',
122
+ };
123
+ }
124
+ return this.connection.request({
125
+ method: options.method,
126
+ path: "" + this.path + options.path,
127
+ body: options.body,
128
+ headers: header,
129
+ authMethod: nylas_connection_1.AuthMethod.BEARER,
130
+ });
131
+ };
132
+ Outbox.validateAndFormatDateTime = function (sendAt, retryLimitDatetime) {
133
+ var sendAtEpoch = sendAt instanceof Date ? Outbox.dateToEpoch(sendAt) : sendAt;
134
+ var retryLimitDatetimeEpoch = retryLimitDatetime instanceof Date
135
+ ? Outbox.dateToEpoch(retryLimitDatetime)
136
+ : retryLimitDatetime;
137
+ if (sendAtEpoch && sendAtEpoch !== 0) {
138
+ if (sendAtEpoch < Outbox.dateToEpoch(new Date())) {
139
+ throw new Error('Cannot set message to be sent at a time before the current time.');
140
+ }
141
+ }
142
+ if (retryLimitDatetimeEpoch && retryLimitDatetimeEpoch !== 0) {
143
+ var validSendAt = sendAtEpoch;
144
+ if (!validSendAt || validSendAt === 0) {
145
+ validSendAt = Outbox.dateToEpoch(new Date());
146
+ }
147
+ if (retryLimitDatetimeEpoch < validSendAt) {
148
+ throw new Error('Cannot set message to stop retrying before time to send at.');
149
+ }
150
+ }
151
+ return [sendAtEpoch, retryLimitDatetimeEpoch];
152
+ };
153
+ Outbox.dateToEpoch = function (date) {
154
+ return Math.floor(date.getTime() / 1000.0);
155
+ };
156
+ return Outbox;
157
+ }());
158
+ exports.default = Outbox;
@@ -34,6 +34,7 @@ export declare type SchedulerAppearanceProperties = {
34
34
  showAutoschedule?: boolean;
35
35
  showNylasBranding?: boolean;
36
36
  showTimezoneOptions?: boolean;
37
+ showWeekView?: boolean;
37
38
  submitText?: string;
38
39
  thankYouRedirect?: string;
39
40
  thankYouText?: string;
@@ -47,6 +48,7 @@ export declare class SchedulerAppearance extends Model implements SchedulerAppea
47
48
  showAutoschedule?: boolean;
48
49
  showNylasBranding?: boolean;
49
50
  showTimezoneOptions?: boolean;
51
+ showWeekView?: boolean;
50
52
  submitText?: string;
51
53
  thankYouRedirect?: string;
52
54
  thankYouText?: string;
@@ -78,13 +80,13 @@ export declare class SchedulerBookingAdditionalFields extends Model implements S
78
80
  }
79
81
  export declare type SchedulerBookingOpeningHoursProperties = {
80
82
  accountId?: string;
81
- days?: string;
83
+ days?: string[];
82
84
  end?: string;
83
85
  start?: string;
84
86
  };
85
87
  export declare class SchedulerBookingOpeningHours extends Model implements SchedulerBookingOpeningHoursProperties {
86
88
  accountId?: string;
87
- days?: string;
89
+ days?: string[];
88
90
  end?: string;
89
91
  start?: string;
90
92
  static attributes: Record<string, Attribute>;
@@ -92,6 +94,7 @@ export declare class SchedulerBookingOpeningHours extends Model implements Sched
92
94
  }
93
95
  export declare type SchedulerBookingProperties = {
94
96
  additionalFields?: SchedulerBookingAdditionalFieldsProperties[];
97
+ additionalGuestsHidden?: boolean;
95
98
  availableDaysInFuture?: number;
96
99
  calendarInviteToGuests?: boolean;
97
100
  cancellationPolicy?: string;
@@ -107,6 +110,7 @@ export declare type SchedulerBookingProperties = {
107
110
  };
108
111
  export declare class SchedulerBooking extends Model implements SchedulerBookingProperties {
109
112
  additionalFields?: SchedulerBookingAdditionalFields[];
113
+ additionalGuestsHidden?: boolean;
110
114
  availableDaysInFuture?: number;
111
115
  calendarInviteToGuests?: boolean;
112
116
  cancellationPolicy?: string;
@@ -179,6 +183,7 @@ export declare class SchedulerConfig extends Model implements SchedulerConfigPro
179
183
  date?: number;
180
184
  uses?: number;
181
185
  };
186
+ disableEmails?: boolean;
182
187
  locale?: string;
183
188
  localeForGuests?: string;
184
189
  reminders?: SchedulerRemindersProperties[];
@@ -108,6 +108,10 @@ var SchedulerAppearance = /** @class */ (function (_super) {
108
108
  modelKey: 'showTimezoneOptions',
109
109
  jsonKey: 'show_timezone_options',
110
110
  }),
111
+ showWeekView: attributes_1.default.Boolean({
112
+ modelKey: 'showWeekView',
113
+ jsonKey: 'show_week_view',
114
+ }),
111
115
  submitText: attributes_1.default.String({
112
116
  modelKey: 'submitText',
113
117
  jsonKey: 'submit_text',
@@ -178,7 +182,7 @@ var SchedulerBookingOpeningHours = /** @class */ (function (_super) {
178
182
  modelKey: 'accountId',
179
183
  jsonKey: 'account_id',
180
184
  }),
181
- days: attributes_1.default.String({
185
+ days: attributes_1.default.StringList({
182
186
  modelKey: 'days',
183
187
  }),
184
188
  end: attributes_1.default.String({
@@ -204,6 +208,10 @@ var SchedulerBooking = /** @class */ (function (_super) {
204
208
  jsonKey: 'additional_fields',
205
209
  itemClass: SchedulerBookingAdditionalFields,
206
210
  }),
211
+ additionalGuestsHidden: attributes_1.default.Boolean({
212
+ modelKey: 'additionalGuestsHidden',
213
+ jsonKey: 'additional_guests_hidden',
214
+ }),
207
215
  availableDaysInFuture: attributes_1.default.Number({
208
216
  modelKey: 'availableDaysInFuture',
209
217
  jsonKey: 'available_days_in_future',
@@ -316,6 +324,10 @@ var SchedulerConfig = /** @class */ (function (_super) {
316
324
  modelKey: 'expireAfter',
317
325
  jsonKey: 'expire_after',
318
326
  }),
327
+ disableEmails: attributes_1.default.Boolean({
328
+ modelKey: 'disableEmails',
329
+ jsonKey: 'disable_emails',
330
+ }),
319
331
  locale: attributes_1.default.String({
320
332
  modelKey: 'locale',
321
333
  }),
@@ -0,0 +1,108 @@
1
+ import Model from './model';
2
+ import { Attribute } from './attributes';
3
+ export declare type LinkClickProperties = {
4
+ id: number;
5
+ ip: string;
6
+ userAgent: string;
7
+ timestamp: Date;
8
+ linkIndex?: number;
9
+ };
10
+ export declare class LinkClick extends Model implements LinkClickProperties {
11
+ id: number;
12
+ ip: string;
13
+ userAgent: string;
14
+ timestamp: Date;
15
+ linkIndex?: number;
16
+ static attributes: Record<string, Attribute>;
17
+ constructor(props?: LinkClickCountProperties);
18
+ }
19
+ export declare type LinkClickCountProperties = {
20
+ url: string;
21
+ count: number;
22
+ };
23
+ export declare class LinkClickCount extends Model implements LinkClickCountProperties {
24
+ url: string;
25
+ count: number;
26
+ static attributes: Record<string, Attribute>;
27
+ constructor(props?: LinkClickCountProperties);
28
+ }
29
+ export declare type MessageTrackingDataProperties = {
30
+ messageId: string;
31
+ payload: string;
32
+ senderAppId: number;
33
+ threadId?: string;
34
+ replyToMessageId?: string;
35
+ timestamp?: Date;
36
+ count?: number;
37
+ fromSelf?: boolean;
38
+ recents?: LinkClickProperties[];
39
+ linkData?: LinkClickCountProperties[];
40
+ };
41
+ export declare class MessageTrackingData extends Model implements MessageTrackingDataProperties {
42
+ messageId: string;
43
+ payload: string;
44
+ senderAppId: number;
45
+ replyToMessageId?: string;
46
+ timestamp?: Date;
47
+ threadId?: string;
48
+ fromSelf?: boolean;
49
+ count?: number;
50
+ linkData?: LinkClickCount[];
51
+ recents?: LinkClick[];
52
+ static attributes: Record<string, Attribute>;
53
+ constructor(props?: MessageTrackingDataProperties);
54
+ }
55
+ export declare type WebhookObjectAttributesProperties = {
56
+ action?: string;
57
+ jobStatusId?: string;
58
+ threadId?: string;
59
+ receivedDate?: Date;
60
+ };
61
+ export declare class WebhookObjectAttributes extends Model implements WebhookObjectAttributesProperties {
62
+ action?: string;
63
+ jobStatusId?: string;
64
+ threadId?: string;
65
+ receivedDate?: Date;
66
+ static attributes: Record<string, Attribute>;
67
+ constructor(props?: WebhookObjectAttributesProperties);
68
+ }
69
+ export declare type WebhookObjectDataProperties = {
70
+ id: string;
71
+ accountId: string;
72
+ namespaceId: string;
73
+ object: string;
74
+ metadata?: MessageTrackingDataProperties;
75
+ objectAttributes?: WebhookObjectAttributesProperties;
76
+ };
77
+ export declare class WebhookObjectData extends Model implements WebhookObjectDataProperties {
78
+ id: string;
79
+ accountId: string;
80
+ namespaceId: string;
81
+ object: string;
82
+ metadata?: MessageTrackingData;
83
+ objectAttributes?: WebhookObjectAttributes;
84
+ static attributes: Record<string, Attribute>;
85
+ constructor(props?: WebhookObjectDataProperties);
86
+ }
87
+ export declare type WebhookDeltaProperties = {
88
+ object: string;
89
+ type: string;
90
+ date: Date;
91
+ objectData: WebhookObjectDataProperties;
92
+ };
93
+ export declare class WebhookDelta extends Model implements WebhookDeltaProperties {
94
+ date: Date;
95
+ object: string;
96
+ type: string;
97
+ objectData: WebhookObjectData;
98
+ static attributes: Record<string, Attribute>;
99
+ constructor(props?: WebhookDeltaProperties);
100
+ }
101
+ export declare type WebhookNotificationProperties = {
102
+ deltas: WebhookDeltaProperties[];
103
+ };
104
+ export default class WebhookNotification extends Model implements WebhookNotificationProperties {
105
+ deltas: WebhookDelta[];
106
+ static attributes: Record<string, Attribute>;
107
+ constructor(props?: WebhookNotificationProperties);
108
+ }
@@ -0,0 +1,239 @@
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 model_1 = __importDefault(require("./model"));
20
+ var attributes_1 = __importDefault(require("./attributes"));
21
+ var LinkClick = /** @class */ (function (_super) {
22
+ __extends(LinkClick, _super);
23
+ function LinkClick(props) {
24
+ var _this = _super.call(this) || this;
25
+ _this.id = 0;
26
+ _this.ip = '';
27
+ _this.userAgent = '';
28
+ _this.timestamp = new Date();
29
+ _this.initAttributes(props);
30
+ return _this;
31
+ }
32
+ LinkClick.attributes = {
33
+ id: attributes_1.default.Number({
34
+ modelKey: 'id',
35
+ }),
36
+ ip: attributes_1.default.String({
37
+ modelKey: 'ip',
38
+ }),
39
+ userAgent: attributes_1.default.String({
40
+ modelKey: 'userAgent',
41
+ jsonKey: 'user_agent',
42
+ }),
43
+ timestamp: attributes_1.default.DateTime({
44
+ modelKey: 'timestamp',
45
+ }),
46
+ linkIndex: attributes_1.default.Number({
47
+ modelKey: 'linkIndex',
48
+ jsonKey: 'link_index',
49
+ }),
50
+ };
51
+ return LinkClick;
52
+ }(model_1.default));
53
+ exports.LinkClick = LinkClick;
54
+ var LinkClickCount = /** @class */ (function (_super) {
55
+ __extends(LinkClickCount, _super);
56
+ function LinkClickCount(props) {
57
+ var _this = _super.call(this) || this;
58
+ _this.url = '';
59
+ _this.count = 0;
60
+ _this.initAttributes(props);
61
+ return _this;
62
+ }
63
+ LinkClickCount.attributes = {
64
+ url: attributes_1.default.String({
65
+ modelKey: 'url',
66
+ }),
67
+ count: attributes_1.default.Number({
68
+ modelKey: 'count',
69
+ }),
70
+ };
71
+ return LinkClickCount;
72
+ }(model_1.default));
73
+ exports.LinkClickCount = LinkClickCount;
74
+ var MessageTrackingData = /** @class */ (function (_super) {
75
+ __extends(MessageTrackingData, _super);
76
+ function MessageTrackingData(props) {
77
+ var _this = _super.call(this) || this;
78
+ _this.messageId = '';
79
+ _this.payload = '';
80
+ _this.senderAppId = 0;
81
+ _this.initAttributes(props);
82
+ return _this;
83
+ }
84
+ MessageTrackingData.attributes = {
85
+ messageId: attributes_1.default.String({
86
+ modelKey: 'messageId',
87
+ jsonKey: 'message_id',
88
+ }),
89
+ payload: attributes_1.default.String({
90
+ modelKey: 'payload',
91
+ }),
92
+ senderAppId: attributes_1.default.Number({
93
+ modelKey: 'senderAppId',
94
+ jsonKey: 'sender_app_id',
95
+ }),
96
+ replyToMessageId: attributes_1.default.String({
97
+ modelKey: 'replyToMessageId',
98
+ jsonKey: 'reply_to_message_id',
99
+ }),
100
+ timestamp: attributes_1.default.DateTime({
101
+ modelKey: 'timestamp',
102
+ }),
103
+ threadId: attributes_1.default.String({
104
+ modelKey: 'threadId',
105
+ jsonKey: 'thread_id',
106
+ }),
107
+ fromSelf: attributes_1.default.Boolean({
108
+ modelKey: 'fromSelf',
109
+ jsonKey: 'from_self',
110
+ }),
111
+ count: attributes_1.default.Number({
112
+ modelKey: 'count',
113
+ }),
114
+ linkData: attributes_1.default.Collection({
115
+ modelKey: 'linkData',
116
+ jsonKey: 'link_data',
117
+ itemClass: LinkClickCount,
118
+ }),
119
+ recents: attributes_1.default.Collection({
120
+ modelKey: 'recents',
121
+ itemClass: LinkClick,
122
+ }),
123
+ };
124
+ return MessageTrackingData;
125
+ }(model_1.default));
126
+ exports.MessageTrackingData = MessageTrackingData;
127
+ var WebhookObjectAttributes = /** @class */ (function (_super) {
128
+ __extends(WebhookObjectAttributes, _super);
129
+ function WebhookObjectAttributes(props) {
130
+ var _this = _super.call(this) || this;
131
+ _this.initAttributes(props);
132
+ return _this;
133
+ }
134
+ WebhookObjectAttributes.attributes = {
135
+ action: attributes_1.default.String({
136
+ modelKey: 'action',
137
+ }),
138
+ jobStatusId: attributes_1.default.String({
139
+ modelKey: 'jobStatusId',
140
+ jsonKey: 'job_status_id',
141
+ }),
142
+ threadId: attributes_1.default.String({
143
+ modelKey: 'threadId',
144
+ jsonKey: 'thread_id',
145
+ }),
146
+ receivedDate: attributes_1.default.DateTime({
147
+ modelKey: 'receivedDate',
148
+ jsonKey: 'received_date',
149
+ }),
150
+ };
151
+ return WebhookObjectAttributes;
152
+ }(model_1.default));
153
+ exports.WebhookObjectAttributes = WebhookObjectAttributes;
154
+ var WebhookObjectData = /** @class */ (function (_super) {
155
+ __extends(WebhookObjectData, _super);
156
+ function WebhookObjectData(props) {
157
+ var _this = _super.call(this) || this;
158
+ _this.id = '';
159
+ _this.accountId = '';
160
+ _this.namespaceId = '';
161
+ _this.object = '';
162
+ _this.initAttributes(props);
163
+ return _this;
164
+ }
165
+ WebhookObjectData.attributes = {
166
+ id: attributes_1.default.String({
167
+ modelKey: 'id',
168
+ }),
169
+ accountId: attributes_1.default.String({
170
+ modelKey: 'accountId',
171
+ jsonKey: 'account_id',
172
+ }),
173
+ namespaceId: attributes_1.default.String({
174
+ modelKey: 'namespaceId',
175
+ jsonKey: 'namespace_id',
176
+ }),
177
+ object: attributes_1.default.String({
178
+ modelKey: 'object',
179
+ }),
180
+ metadata: attributes_1.default.Object({
181
+ modelKey: 'metadata',
182
+ itemClass: MessageTrackingData,
183
+ }),
184
+ objectAttributes: attributes_1.default.Object({
185
+ modelKey: 'objectAttributes',
186
+ jsonKey: 'attributes',
187
+ itemClass: WebhookObjectAttributes,
188
+ }),
189
+ };
190
+ return WebhookObjectData;
191
+ }(model_1.default));
192
+ exports.WebhookObjectData = WebhookObjectData;
193
+ var WebhookDelta = /** @class */ (function (_super) {
194
+ __extends(WebhookDelta, _super);
195
+ function WebhookDelta(props) {
196
+ var _this = _super.call(this) || this;
197
+ _this.date = new Date();
198
+ _this.object = '';
199
+ _this.type = '';
200
+ _this.objectData = new WebhookObjectData();
201
+ _this.initAttributes(props);
202
+ return _this;
203
+ }
204
+ WebhookDelta.attributes = {
205
+ date: attributes_1.default.DateTime({
206
+ modelKey: 'date',
207
+ }),
208
+ object: attributes_1.default.String({
209
+ modelKey: 'object',
210
+ }),
211
+ type: attributes_1.default.String({
212
+ modelKey: 'type',
213
+ }),
214
+ objectData: attributes_1.default.Object({
215
+ modelKey: 'objectData',
216
+ jsonKey: 'object_data',
217
+ itemClass: WebhookObjectData,
218
+ }),
219
+ };
220
+ return WebhookDelta;
221
+ }(model_1.default));
222
+ exports.WebhookDelta = WebhookDelta;
223
+ var WebhookNotification = /** @class */ (function (_super) {
224
+ __extends(WebhookNotification, _super);
225
+ function WebhookNotification(props) {
226
+ var _this = _super.call(this) || this;
227
+ _this.deltas = [];
228
+ _this.initAttributes(props);
229
+ return _this;
230
+ }
231
+ WebhookNotification.attributes = {
232
+ deltas: attributes_1.default.Collection({
233
+ modelKey: 'deltas',
234
+ itemClass: WebhookDelta,
235
+ }),
236
+ };
237
+ return WebhookNotification;
238
+ }(model_1.default));
239
+ exports.default = WebhookNotification;
@@ -2,6 +2,29 @@ import ManagementModel from './management-model';
2
2
  import { Attribute } from './attributes';
3
3
  import { SaveCallback } from './restful-model';
4
4
  import NylasConnection from '../nylas-connection';
5
+ export declare enum WebhookTriggers {
6
+ AccountConnected = "account.connected",
7
+ AccountRunning = "account.running",
8
+ AccountStopped = "account.stopped",
9
+ AccountInvalid = "account.invalid",
10
+ AccountSyncError = "account.sync_error",
11
+ MessageCreated = "message.created",
12
+ MessageOpened = "message.opened",
13
+ MessageUpdated = "message.updated",
14
+ MessageLinkClicked = "message.link_clicked",
15
+ ThreadReplied = "thread.replied",
16
+ ContactCreated = "contact.created",
17
+ ContactUpdated = "contact.updated",
18
+ ContactDeleted = "contact.deleted",
19
+ CalendarCreated = "calendar.created",
20
+ CalendarUpdated = "calendar.updated",
21
+ CalendarDeleted = "calendar.deleted",
22
+ EventCreated = "event.created",
23
+ EventUpdated = "event.updated",
24
+ EventDeleted = "event.deleted",
25
+ JobSuccessful = "job.successful",
26
+ JobFailed = "job.failed"
27
+ }
5
28
  export declare type WebhookProperties = {
6
29
  callbackUrl: string;
7
30
  state: string;
@@ -18,6 +18,30 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
18
18
  Object.defineProperty(exports, "__esModule", { value: true });
19
19
  var management_model_1 = __importDefault(require("./management-model"));
20
20
  var attributes_1 = __importDefault(require("./attributes"));
21
+ var WebhookTriggers;
22
+ (function (WebhookTriggers) {
23
+ WebhookTriggers["AccountConnected"] = "account.connected";
24
+ WebhookTriggers["AccountRunning"] = "account.running";
25
+ WebhookTriggers["AccountStopped"] = "account.stopped";
26
+ WebhookTriggers["AccountInvalid"] = "account.invalid";
27
+ WebhookTriggers["AccountSyncError"] = "account.sync_error";
28
+ WebhookTriggers["MessageCreated"] = "message.created";
29
+ WebhookTriggers["MessageOpened"] = "message.opened";
30
+ WebhookTriggers["MessageUpdated"] = "message.updated";
31
+ WebhookTriggers["MessageLinkClicked"] = "message.link_clicked";
32
+ WebhookTriggers["ThreadReplied"] = "thread.replied";
33
+ WebhookTriggers["ContactCreated"] = "contact.created";
34
+ WebhookTriggers["ContactUpdated"] = "contact.updated";
35
+ WebhookTriggers["ContactDeleted"] = "contact.deleted";
36
+ WebhookTriggers["CalendarCreated"] = "calendar.created";
37
+ WebhookTriggers["CalendarUpdated"] = "calendar.updated";
38
+ WebhookTriggers["CalendarDeleted"] = "calendar.deleted";
39
+ WebhookTriggers["EventCreated"] = "event.created";
40
+ WebhookTriggers["EventUpdated"] = "event.updated";
41
+ WebhookTriggers["EventDeleted"] = "event.deleted";
42
+ WebhookTriggers["JobSuccessful"] = "job.successful";
43
+ WebhookTriggers["JobFailed"] = "job.failed";
44
+ })(WebhookTriggers = exports.WebhookTriggers || (exports.WebhookTriggers = {}));
21
45
  var Webhook = /** @class */ (function (_super) {
22
46
  __extends(Webhook, _super);
23
47
  function Webhook(connection, clientId, props) {
@@ -7,7 +7,6 @@ import ContactRestfulModelCollection from './models/contact-restful-model-collec
7
7
  import RestfulModelInstance from './models/restful-model-instance';
8
8
  import Account from './models/account';
9
9
  import Thread from './models/thread';
10
- import Message from './models/message';
11
10
  import Draft from './models/draft';
12
11
  import File from './models/file';
13
12
  import Event from './models/event';
@@ -18,7 +17,13 @@ import { AppendOptions } from 'form-data';
18
17
  import Neural from './models/neural';
19
18
  import ComponentRestfulModelCollection from './models/component-restful-model-collection';
20
19
  import SchedulerRestfulModelCollection from './models/scheduler-restful-model-collection';
20
+ import MessageRestfulModelCollection from './models/message-restful-model-collection';
21
21
  import DeltaCollection from './models/delta-collection';
22
+ import Outbox from './models/outbox';
23
+ export declare enum AuthMethod {
24
+ BASIC = 0,
25
+ BEARER = 1
26
+ }
22
27
  export declare type RequestOptions = {
23
28
  path: string;
24
29
  method?: string;
@@ -30,6 +35,7 @@ export declare type RequestOptions = {
30
35
  body?: any;
31
36
  baseUrl?: string;
32
37
  url?: URL;
38
+ authMethod?: AuthMethod;
33
39
  };
34
40
  export declare type FormDataType = {
35
41
  value: unknown;
@@ -40,7 +46,7 @@ export default class NylasConnection {
40
46
  clientId: string | null | undefined;
41
47
  threads: RestfulModelCollection<Thread>;
42
48
  contacts: ContactRestfulModelCollection;
43
- messages: RestfulModelCollection<Message>;
49
+ messages: MessageRestfulModelCollection;
44
50
  drafts: RestfulModelCollection<Draft>;
45
51
  files: RestfulModelCollection<File>;
46
52
  calendars: CalendarRestfulModelCollection;
@@ -53,6 +59,7 @@ export default class NylasConnection {
53
59
  account: RestfulModelInstance<Account>;
54
60
  component: ComponentRestfulModelCollection;
55
61
  scheduler: SchedulerRestfulModelCollection;
62
+ outbox: Outbox;
56
63
  neural: Neural;
57
64
  constructor(accessToken: string | null | undefined, { clientId }: {
58
65
  clientId: string | null | undefined;
@@ -31,7 +31,6 @@ var contact_restful_model_collection_1 = __importDefault(require("./models/conta
31
31
  var restful_model_instance_1 = __importDefault(require("./models/restful-model-instance"));
32
32
  var account_1 = __importDefault(require("./models/account"));
33
33
  var thread_1 = __importDefault(require("./models/thread"));
34
- var message_1 = __importDefault(require("./models/message"));
35
34
  var draft_1 = __importDefault(require("./models/draft"));
36
35
  var file_1 = __importDefault(require("./models/file"));
37
36
  var event_1 = __importDefault(require("./models/event"));
@@ -43,16 +42,23 @@ var neural_1 = __importDefault(require("./models/neural"));
43
42
  var nylas_api_error_1 = __importDefault(require("./models/nylas-api-error"));
44
43
  var component_restful_model_collection_1 = __importDefault(require("./models/component-restful-model-collection"));
45
44
  var scheduler_restful_model_collection_1 = __importDefault(require("./models/scheduler-restful-model-collection"));
45
+ var message_restful_model_collection_1 = __importDefault(require("./models/message-restful-model-collection"));
46
46
  var delta_collection_1 = __importDefault(require("./models/delta-collection"));
47
+ var outbox_1 = __importDefault(require("./models/outbox"));
47
48
  var PACKAGE_JSON = require('../package.json');
48
49
  var SDK_VERSION = PACKAGE_JSON.version;
49
- var SUPPORTED_API_VERSION = '2.3';
50
+ var SUPPORTED_API_VERSION = '2.5';
51
+ var AuthMethod;
52
+ (function (AuthMethod) {
53
+ AuthMethod[AuthMethod["BASIC"] = 0] = "BASIC";
54
+ AuthMethod[AuthMethod["BEARER"] = 1] = "BEARER";
55
+ })(AuthMethod = exports.AuthMethod || (exports.AuthMethod = {}));
50
56
  var NylasConnection = /** @class */ (function () {
51
57
  function NylasConnection(accessToken, _a) {
52
58
  var clientId = _a.clientId;
53
59
  this.threads = new restful_model_collection_1.default(thread_1.default, this);
54
60
  this.contacts = new contact_restful_model_collection_1.default(this);
55
- this.messages = new restful_model_collection_1.default(message_1.default, this);
61
+ this.messages = new message_restful_model_collection_1.default(this);
56
62
  this.drafts = new restful_model_collection_1.default(draft_1.default, this);
57
63
  this.files = new restful_model_collection_1.default(file_1.default, this);
58
64
  this.calendars = new calendar_restful_model_collection_1.default(this);
@@ -65,6 +71,7 @@ var NylasConnection = /** @class */ (function () {
65
71
  this.account = new restful_model_instance_1.default(account_1.default, this);
66
72
  this.component = new component_restful_model_collection_1.default(this);
67
73
  this.scheduler = new scheduler_restful_model_collection_1.default(this);
74
+ this.outbox = new outbox_1.default(this);
68
75
  this.neural = new neural_1.default(this);
69
76
  this.accessToken = accessToken;
70
77
  this.clientId = clientId;
@@ -107,8 +114,13 @@ var NylasConnection = /** @class */ (function () {
107
114
  ? config.clientSecret
108
115
  : this.accessToken;
109
116
  if (user) {
110
- headers['authorization'] =
111
- 'Basic ' + Buffer.from(user + ":", 'utf8').toString('base64');
117
+ if (options.authMethod === AuthMethod.BEARER) {
118
+ headers['authorization'] = "Bearer " + user;
119
+ }
120
+ else {
121
+ headers['authorization'] =
122
+ 'Basic ' + Buffer.from(user + ":", 'utf8').toString('base64');
123
+ }
112
124
  }
113
125
  if (!headers['User-Agent']) {
114
126
  headers['User-Agent'] = "Nylas Node SDK v" + SDK_VERSION;
@@ -181,7 +193,9 @@ var NylasConnection = /** @class */ (function () {
181
193
  console.warn(warning);
182
194
  }
183
195
  if (response.status > 299) {
184
- return response.json().then(function (body) {
196
+ return response
197
+ .json()
198
+ .then(function (body) {
185
199
  var error = new nylas_api_error_1.default(response.status, body.type, body.message);
186
200
  if (body.missing_fields) {
187
201
  error.missingFields = body.missing_fields;
@@ -190,6 +204,18 @@ var NylasConnection = /** @class */ (function () {
190
204
  error.serverError = body.server_error;
191
205
  }
192
206
  return reject(error);
207
+ })
208
+ .catch(function () {
209
+ return response
210
+ .text()
211
+ .then(function (text) {
212
+ var error = new nylas_api_error_1.default(response.status, response.statusText, text);
213
+ return reject(error);
214
+ })
215
+ .catch(function () {
216
+ var error = new nylas_api_error_1.default(response.status, response.statusText, 'Error encountered during request, unable to extract error message.');
217
+ return reject(error);
218
+ });
193
219
  });
194
220
  }
195
221
  else {
@@ -209,6 +235,10 @@ var NylasConnection = /** @class */ (function () {
209
235
  return reject(e);
210
236
  });
211
237
  }
238
+ else if (response.headers.get('content-length') &&
239
+ Number(response.headers.get('content-length')) == 0) {
240
+ return resolve();
241
+ }
212
242
  else if (response.headers.get('Content-Type') === 'message/rfc822') {
213
243
  return resolve(response.text());
214
244
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nylas",
3
- "version": "6.2.0-canary.0",
3
+ "version": "6.2.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",