nylas 6.9.0 → 6.11.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 +5 -0
- package/lib/config.js +5 -0
- package/lib/models/LoggingInterface.d.ts +15 -0
- package/lib/models/LoggingInterface.js +2 -0
- package/lib/models/attributes.js +4 -6
- package/lib/models/draft.js +5 -1
- package/lib/models/event.js +3 -0
- package/lib/models/webhook-notification.d.ts +9 -0
- package/lib/models/webhook-notification.js +27 -0
- package/lib/nylas-connection.js +5 -4
- package/lib/nylas.d.ts +3 -0
- package/lib/nylas.js +14 -0
- package/package.json +2 -2
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
|
+
}
|
package/lib/models/attributes.js
CHANGED
|
@@ -86,12 +86,10 @@ var AttributeNumber = /** @class */ (function (_super) {
|
|
|
86
86
|
return val;
|
|
87
87
|
};
|
|
88
88
|
AttributeNumber.prototype.fromJSON = function (val) {
|
|
89
|
-
if (
|
|
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;
|
package/lib/models/draft.js
CHANGED
|
@@ -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
|
-
|
|
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 = {}; }
|
package/lib/models/event.js
CHANGED
|
@@ -148,6 +148,9 @@ var Event = /** @class */ (function (_super) {
|
|
|
148
148
|
if (this.id && json.participants) {
|
|
149
149
|
json.participants.forEach(function (participant) { return delete participant.status; });
|
|
150
150
|
}
|
|
151
|
+
if (this.visibility !== undefined && this.visibility === '') {
|
|
152
|
+
delete json.visibility;
|
|
153
|
+
}
|
|
151
154
|
return json;
|
|
152
155
|
};
|
|
153
156
|
Event.prototype.rsvp = function (status, comment, callback) {
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
1
2
|
import Model from './model';
|
|
2
3
|
import { Attribute } from './attributes';
|
|
3
4
|
export declare type LinkClickProperties = {
|
|
@@ -121,4 +122,12 @@ export default class WebhookNotification extends Model implements WebhookNotific
|
|
|
121
122
|
deltas: WebhookDelta[];
|
|
122
123
|
static attributes: Record<string, Attribute>;
|
|
123
124
|
constructor(props?: WebhookNotificationProperties);
|
|
125
|
+
/**
|
|
126
|
+
* Verify incoming webhook signature came from Nylas
|
|
127
|
+
* @param xNylasSignature The signature to verify
|
|
128
|
+
* @param rawBody The raw body from the payload
|
|
129
|
+
* @param clientSecret Overriding client secret of the app receiving the webhook
|
|
130
|
+
* @return true if the webhook signature was verified from Nylas
|
|
131
|
+
*/
|
|
132
|
+
static verifyWebhookSignature(xNylasSignature: string, rawBody: Buffer, clientSecret?: string): boolean;
|
|
124
133
|
}
|
|
@@ -15,9 +15,18 @@ var __extends = (this && this.__extends) || (function () {
|
|
|
15
15
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
16
16
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
17
17
|
};
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
|
|
22
|
+
result["default"] = mod;
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
18
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
var crypto_1 = __importDefault(require("crypto"));
|
|
19
27
|
var model_1 = __importDefault(require("./model"));
|
|
20
28
|
var attributes_1 = __importDefault(require("./attributes"));
|
|
29
|
+
var config = __importStar(require("../config"));
|
|
21
30
|
var LinkClick = /** @class */ (function (_super) {
|
|
22
31
|
__extends(LinkClick, _super);
|
|
23
32
|
function LinkClick(props) {
|
|
@@ -276,6 +285,24 @@ var WebhookNotification = /** @class */ (function (_super) {
|
|
|
276
285
|
_this.initAttributes(props);
|
|
277
286
|
return _this;
|
|
278
287
|
}
|
|
288
|
+
/**
|
|
289
|
+
* Verify incoming webhook signature came from Nylas
|
|
290
|
+
* @param xNylasSignature The signature to verify
|
|
291
|
+
* @param rawBody The raw body from the payload
|
|
292
|
+
* @param clientSecret Overriding client secret of the app receiving the webhook
|
|
293
|
+
* @return true if the webhook signature was verified from Nylas
|
|
294
|
+
*/
|
|
295
|
+
WebhookNotification.verifyWebhookSignature = function (xNylasSignature, rawBody, clientSecret) {
|
|
296
|
+
var clientSecretToUse = clientSecret || config.clientSecret;
|
|
297
|
+
if (!clientSecretToUse) {
|
|
298
|
+
throw new Error('Client secret is required to verify webhook signature');
|
|
299
|
+
}
|
|
300
|
+
var digest = crypto_1.default
|
|
301
|
+
.createHmac('sha256', clientSecretToUse)
|
|
302
|
+
.update(rawBody)
|
|
303
|
+
.digest('hex');
|
|
304
|
+
return digest === xNylasSignature;
|
|
305
|
+
};
|
|
279
306
|
WebhookNotification.attributes = {
|
|
280
307
|
deltas: attributes_1.default.Collection({
|
|
281
308
|
modelKey: 'deltas',
|
package/lib/nylas-connection.js
CHANGED
|
@@ -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
|
-
},
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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.
|
|
3
|
+
"version": "6.11.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",
|
|
@@ -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.
|
|
50
|
+
"node-fetch": "^2.6.12",
|
|
51
51
|
"uuid": "^8.3.2",
|
|
52
52
|
"websocket": "^1.0.34"
|
|
53
53
|
},
|