nylas 6.8.0 → 6.9.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 +7 -0
- package/lib/config.js +5 -0
- package/lib/models/nylas-api-error.js +1 -0
- package/lib/models/restful-model-collection.d.ts +1 -1
- package/lib/models/when.d.ts +6 -0
- package/lib/models/when.js +11 -0
- package/lib/nylas-connection.js +21 -4
- package/lib/nylas.d.ts +2 -0
- package/lib/nylas.js +12 -0
- package/package.json +1 -1
package/lib/config.d.ts
CHANGED
|
@@ -3,10 +3,17 @@ export declare let apiServer: string | null;
|
|
|
3
3
|
export declare function setApiServer(newApiServer: string | null): void;
|
|
4
4
|
export declare let clientSecret: string;
|
|
5
5
|
export declare function setClientSecret(newClientSecret: string): void;
|
|
6
|
+
export declare let timeout: number;
|
|
7
|
+
export declare function setTimeout(newTimeout: number): void;
|
|
6
8
|
export declare type NylasConfig = {
|
|
9
|
+
/** Nylas application client ID */
|
|
7
10
|
clientId: string;
|
|
11
|
+
/** Nylas application client secret */
|
|
8
12
|
clientSecret: string;
|
|
13
|
+
/** API Server base URL */
|
|
9
14
|
apiServer?: string;
|
|
15
|
+
/** Timeout for outgoing API calls, in milliseconds */
|
|
16
|
+
timeout?: number;
|
|
10
17
|
};
|
|
11
18
|
export declare enum ResponseType {
|
|
12
19
|
CODE = "code",
|
package/lib/config.js
CHANGED
|
@@ -12,6 +12,11 @@ function setClientSecret(newClientSecret) {
|
|
|
12
12
|
exports.clientSecret = newClientSecret;
|
|
13
13
|
}
|
|
14
14
|
exports.setClientSecret = setClientSecret;
|
|
15
|
+
exports.timeout = 0;
|
|
16
|
+
function setTimeout(newTimeout) {
|
|
17
|
+
exports.timeout = newTimeout;
|
|
18
|
+
}
|
|
19
|
+
exports.setTimeout = setTimeout;
|
|
15
20
|
var ResponseType;
|
|
16
21
|
(function (ResponseType) {
|
|
17
22
|
ResponseType["CODE"] = "code";
|
|
@@ -2,7 +2,7 @@ import NylasConnection from '../nylas-connection';
|
|
|
2
2
|
import RestfulModel from './restful-model';
|
|
3
3
|
import ModelCollection from './model-collection';
|
|
4
4
|
export declare type GetCallback = (error: Error | null, result?: RestfulModel) => void;
|
|
5
|
-
export default class RestfulModelCollection<T extends RestfulModel> extends ModelCollection<
|
|
5
|
+
export default class RestfulModelCollection<T extends RestfulModel> extends ModelCollection<T> {
|
|
6
6
|
modelClass: typeof RestfulModel;
|
|
7
7
|
constructor(modelClass: typeof RestfulModel, connection: NylasConnection);
|
|
8
8
|
count(params?: Record<string, unknown>, callback?: (err: Error | null, num?: number) => void): Promise<number>;
|
package/lib/models/when.d.ts
CHANGED
|
@@ -3,7 +3,10 @@ import { Attribute } from './attributes';
|
|
|
3
3
|
export declare type WhenProperties = {
|
|
4
4
|
startTime?: number;
|
|
5
5
|
endTime?: number;
|
|
6
|
+
startTimezone?: string;
|
|
7
|
+
endTimezone?: string;
|
|
6
8
|
time?: number;
|
|
9
|
+
timezone?: string;
|
|
7
10
|
startDate?: string;
|
|
8
11
|
endDate?: string;
|
|
9
12
|
date?: string;
|
|
@@ -12,7 +15,10 @@ export declare type WhenProperties = {
|
|
|
12
15
|
export default class When extends Model implements WhenProperties {
|
|
13
16
|
startTime?: number;
|
|
14
17
|
endTime?: number;
|
|
18
|
+
startTimezone?: string;
|
|
19
|
+
endTimezone?: string;
|
|
15
20
|
time?: number;
|
|
21
|
+
timezone?: string;
|
|
16
22
|
startDate?: string;
|
|
17
23
|
endDate?: string;
|
|
18
24
|
date?: string;
|
package/lib/models/when.js
CHANGED
|
@@ -41,9 +41,20 @@ var When = /** @class */ (function (_super) {
|
|
|
41
41
|
modelKey: 'endTime',
|
|
42
42
|
jsonKey: 'end_time',
|
|
43
43
|
}),
|
|
44
|
+
startTimezone: attributes_1.default.String({
|
|
45
|
+
modelKey: 'startTimezone',
|
|
46
|
+
jsonKey: 'start_timezone',
|
|
47
|
+
}),
|
|
48
|
+
endTimezone: attributes_1.default.String({
|
|
49
|
+
modelKey: 'endTimezone',
|
|
50
|
+
jsonKey: 'end_timezone',
|
|
51
|
+
}),
|
|
44
52
|
time: attributes_1.default.Number({
|
|
45
53
|
modelKey: 'time',
|
|
46
54
|
}),
|
|
55
|
+
timezone: attributes_1.default.String({
|
|
56
|
+
modelKey: 'timezone',
|
|
57
|
+
}),
|
|
47
58
|
startDate: attributes_1.default.String({
|
|
48
59
|
modelKey: 'startDate',
|
|
49
60
|
jsonKey: 'start_date',
|
package/lib/nylas-connection.js
CHANGED
|
@@ -10,6 +10,9 @@ var __assign = (this && this.__assign) || function () {
|
|
|
10
10
|
};
|
|
11
11
|
return __assign.apply(this, arguments);
|
|
12
12
|
};
|
|
13
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
14
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
15
|
+
};
|
|
13
16
|
var __importStar = (this && this.__importStar) || function (mod) {
|
|
14
17
|
if (mod && mod.__esModule) return mod;
|
|
15
18
|
var result = {};
|
|
@@ -17,12 +20,11 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
17
20
|
result["default"] = mod;
|
|
18
21
|
return result;
|
|
19
22
|
};
|
|
20
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
21
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
22
|
-
};
|
|
23
23
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
24
24
|
// TODO since node 10 URL is global
|
|
25
25
|
var url_1 = require("url");
|
|
26
|
+
// TODO since node 15 AbortController is global
|
|
27
|
+
var abort_controller_1 = __importDefault(require("abort-controller"));
|
|
26
28
|
var node_fetch_1 = __importStar(require("node-fetch"));
|
|
27
29
|
var config = __importStar(require("./config"));
|
|
28
30
|
var restful_model_collection_1 = __importDefault(require("./models/restful-model-collection"));
|
|
@@ -181,8 +183,16 @@ var NylasConnection = /** @class */ (function () {
|
|
|
181
183
|
NylasConnection.prototype.request = function (options) {
|
|
182
184
|
var _this = this;
|
|
183
185
|
var req = this.newRequest(options);
|
|
186
|
+
var controller;
|
|
187
|
+
var timeout;
|
|
188
|
+
if (config.timeout && config.timeout !== 0) {
|
|
189
|
+
controller = new abort_controller_1.default();
|
|
190
|
+
timeout = setTimeout(function () {
|
|
191
|
+
controller.abort();
|
|
192
|
+
}, 150);
|
|
193
|
+
}
|
|
184
194
|
return new Promise(function (resolve, reject) {
|
|
185
|
-
return node_fetch_1.default(req)
|
|
195
|
+
return node_fetch_1.default(req, { signal: controller === null || controller === void 0 ? void 0 : controller.signal })
|
|
186
196
|
.then(function (response) {
|
|
187
197
|
if (typeof response === 'undefined') {
|
|
188
198
|
return reject(new Error('No response'));
|
|
@@ -255,8 +265,15 @@ var NylasConnection = /** @class */ (function () {
|
|
|
255
265
|
}
|
|
256
266
|
})
|
|
257
267
|
.catch(function (err) {
|
|
268
|
+
if (err && err.name && err.name === 'AbortError') {
|
|
269
|
+
console.warn('Request timed out');
|
|
270
|
+
return reject(err);
|
|
271
|
+
}
|
|
258
272
|
console.error("Error encountered during request:\n" + err.stack);
|
|
259
273
|
return reject(err);
|
|
274
|
+
})
|
|
275
|
+
.then(function () {
|
|
276
|
+
clearTimeout(timeout);
|
|
260
277
|
});
|
|
261
278
|
});
|
|
262
279
|
};
|
package/lib/nylas.d.ts
CHANGED
|
@@ -14,6 +14,8 @@ declare class Nylas {
|
|
|
14
14
|
static set clientSecret(newClientSecret: string);
|
|
15
15
|
static get apiServer(): string | null;
|
|
16
16
|
static set apiServer(newApiServer: string | null);
|
|
17
|
+
static get timeout(): number;
|
|
18
|
+
static set timeout(timeout: number);
|
|
17
19
|
static accounts: ManagementModelCollection<ManagementAccount> | RestfulModelCollection<Account>;
|
|
18
20
|
static connect: Connect;
|
|
19
21
|
static webhooks: ManagementModelCollection<Webhook>;
|
package/lib/nylas.js
CHANGED
|
@@ -46,6 +46,17 @@ var Nylas = /** @class */ (function () {
|
|
|
46
46
|
enumerable: true,
|
|
47
47
|
configurable: true
|
|
48
48
|
});
|
|
49
|
+
Object.defineProperty(Nylas, "timeout", {
|
|
50
|
+
get: function () {
|
|
51
|
+
return config.timeout;
|
|
52
|
+
},
|
|
53
|
+
// Timeout for outgoing API calls, in milliseconds
|
|
54
|
+
set: function (timeout) {
|
|
55
|
+
config.setTimeout(timeout);
|
|
56
|
+
},
|
|
57
|
+
enumerable: true,
|
|
58
|
+
configurable: true
|
|
59
|
+
});
|
|
49
60
|
Nylas.config = function (config) {
|
|
50
61
|
if (config.apiServer && config.apiServer.indexOf('://') === -1) {
|
|
51
62
|
throw new Error('Please specify a fully qualified URL for the API Server.');
|
|
@@ -62,6 +73,7 @@ var Nylas = /** @class */ (function () {
|
|
|
62
73
|
else {
|
|
63
74
|
this.apiServer = 'https://api.nylas.com';
|
|
64
75
|
}
|
|
76
|
+
this.timeout = config.timeout || 0;
|
|
65
77
|
var conn = new nylas_connection_1.default(this.clientSecret, {
|
|
66
78
|
clientId: this.clientId,
|
|
67
79
|
});
|