nylas 7.7.4 → 7.8.0-canary.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/cjs/apiClient.js +16 -3
- package/lib/cjs/models/error.js +12 -4
- package/lib/cjs/version.js +1 -1
- package/lib/esm/apiClient.js +16 -3
- package/lib/esm/models/error.js +12 -4
- package/lib/esm/version.js +1 -1
- package/lib/types/models/error.d.ts +27 -3
- package/lib/types/models/response.d.ts +9 -0
- package/lib/types/version.d.ts +1 -1
- package/package.json +1 -1
package/lib/cjs/apiClient.js
CHANGED
|
@@ -87,15 +87,21 @@ class APIClient {
|
|
|
87
87
|
// Check if the request is an authentication request
|
|
88
88
|
const isAuthRequest = options.path.includes('connect/token') ||
|
|
89
89
|
options.path.includes('connect/revoke');
|
|
90
|
+
const headers = response?.headers?.entries
|
|
91
|
+
? Object.fromEntries(response.headers.entries())
|
|
92
|
+
: {};
|
|
93
|
+
const flowId = headers['x-flow-id'];
|
|
94
|
+
const requestId = headers['x-request-id'];
|
|
90
95
|
if (isAuthRequest) {
|
|
91
|
-
error = new error_js_1.NylasOAuthError(camelCaseError, response.status);
|
|
96
|
+
error = new error_js_1.NylasOAuthError(camelCaseError, response.status, requestId, flowId, headers);
|
|
92
97
|
}
|
|
93
98
|
else {
|
|
94
|
-
error = new error_js_1.NylasApiError(camelCaseError, response.status);
|
|
99
|
+
error = new error_js_1.NylasApiError(camelCaseError, response.status, requestId, flowId, headers);
|
|
95
100
|
}
|
|
96
101
|
}
|
|
97
102
|
catch (e) {
|
|
98
|
-
|
|
103
|
+
const flowId = response?.headers?.get('x-flow-id') || undefined;
|
|
104
|
+
throw new Error(`Received an error but could not parse response from the server${flowId ? ` with flow ID ${flowId}` : ''}: ${text}`);
|
|
99
105
|
}
|
|
100
106
|
throw error;
|
|
101
107
|
}
|
|
@@ -137,9 +143,16 @@ class APIClient {
|
|
|
137
143
|
});
|
|
138
144
|
}
|
|
139
145
|
async requestWithResponse(response) {
|
|
146
|
+
const headers = response?.headers?.entries
|
|
147
|
+
? Object.fromEntries(response.headers.entries())
|
|
148
|
+
: {};
|
|
149
|
+
const flowId = headers['x-flow-id'];
|
|
140
150
|
const text = await response.text();
|
|
141
151
|
try {
|
|
142
152
|
const responseJSON = JSON.parse(text);
|
|
153
|
+
// Inject the flow ID and headers into the response
|
|
154
|
+
responseJSON.flowId = flowId;
|
|
155
|
+
responseJSON.headers = headers;
|
|
143
156
|
return (0, utils_js_1.objKeysToCamelCase)(responseJSON, ['metadata']);
|
|
144
157
|
}
|
|
145
158
|
catch (e) {
|
package/lib/cjs/models/error.js
CHANGED
|
@@ -17,10 +17,12 @@ exports.AbstractNylasSdkError = AbstractNylasSdkError;
|
|
|
17
17
|
* Class representation of a general Nylas API error.
|
|
18
18
|
*/
|
|
19
19
|
class NylasApiError extends AbstractNylasApiError {
|
|
20
|
-
constructor(apiError, statusCode) {
|
|
20
|
+
constructor(apiError, statusCode, requestId, flowId, headers) {
|
|
21
21
|
super(apiError.error.message);
|
|
22
22
|
this.type = apiError.error.type;
|
|
23
|
-
this.requestId =
|
|
23
|
+
this.requestId = requestId;
|
|
24
|
+
this.flowId = flowId;
|
|
25
|
+
this.headers = headers;
|
|
24
26
|
this.providerError = apiError.error.providerError;
|
|
25
27
|
this.statusCode = statusCode;
|
|
26
28
|
}
|
|
@@ -30,13 +32,16 @@ exports.NylasApiError = NylasApiError;
|
|
|
30
32
|
* Class representing an OAuth error returned by the Nylas API.
|
|
31
33
|
*/
|
|
32
34
|
class NylasOAuthError extends AbstractNylasApiError {
|
|
33
|
-
constructor(apiError, statusCode) {
|
|
35
|
+
constructor(apiError, statusCode, requestId, flowId, headers) {
|
|
34
36
|
super(apiError.errorDescription);
|
|
35
37
|
this.error = apiError.error;
|
|
36
38
|
this.errorCode = apiError.errorCode;
|
|
37
39
|
this.errorDescription = apiError.errorDescription;
|
|
38
40
|
this.errorUri = apiError.errorUri;
|
|
39
41
|
this.statusCode = statusCode;
|
|
42
|
+
this.requestId = requestId;
|
|
43
|
+
this.flowId = flowId;
|
|
44
|
+
this.headers = headers;
|
|
40
45
|
}
|
|
41
46
|
}
|
|
42
47
|
exports.NylasOAuthError = NylasOAuthError;
|
|
@@ -44,10 +49,13 @@ exports.NylasOAuthError = NylasOAuthError;
|
|
|
44
49
|
* Error thrown when the Nylas SDK times out before receiving a response from the server
|
|
45
50
|
*/
|
|
46
51
|
class NylasSdkTimeoutError extends AbstractNylasSdkError {
|
|
47
|
-
constructor(url, timeout) {
|
|
52
|
+
constructor(url, timeout, requestId, flowId, headers) {
|
|
48
53
|
super('Nylas SDK timed out before receiving a response from the server.');
|
|
49
54
|
this.url = url;
|
|
50
55
|
this.timeout = timeout;
|
|
56
|
+
this.requestId = requestId;
|
|
57
|
+
this.flowId = flowId;
|
|
58
|
+
this.headers = headers;
|
|
51
59
|
}
|
|
52
60
|
}
|
|
53
61
|
exports.NylasSdkTimeoutError = NylasSdkTimeoutError;
|
package/lib/cjs/version.js
CHANGED
package/lib/esm/apiClient.js
CHANGED
|
@@ -85,15 +85,21 @@ export default class APIClient {
|
|
|
85
85
|
// Check if the request is an authentication request
|
|
86
86
|
const isAuthRequest = options.path.includes('connect/token') ||
|
|
87
87
|
options.path.includes('connect/revoke');
|
|
88
|
+
const headers = response?.headers?.entries
|
|
89
|
+
? Object.fromEntries(response.headers.entries())
|
|
90
|
+
: {};
|
|
91
|
+
const flowId = headers['x-flow-id'];
|
|
92
|
+
const requestId = headers['x-request-id'];
|
|
88
93
|
if (isAuthRequest) {
|
|
89
|
-
error = new NylasOAuthError(camelCaseError, response.status);
|
|
94
|
+
error = new NylasOAuthError(camelCaseError, response.status, requestId, flowId, headers);
|
|
90
95
|
}
|
|
91
96
|
else {
|
|
92
|
-
error = new NylasApiError(camelCaseError, response.status);
|
|
97
|
+
error = new NylasApiError(camelCaseError, response.status, requestId, flowId, headers);
|
|
93
98
|
}
|
|
94
99
|
}
|
|
95
100
|
catch (e) {
|
|
96
|
-
|
|
101
|
+
const flowId = response?.headers?.get('x-flow-id') || undefined;
|
|
102
|
+
throw new Error(`Received an error but could not parse response from the server${flowId ? ` with flow ID ${flowId}` : ''}: ${text}`);
|
|
97
103
|
}
|
|
98
104
|
throw error;
|
|
99
105
|
}
|
|
@@ -135,9 +141,16 @@ export default class APIClient {
|
|
|
135
141
|
});
|
|
136
142
|
}
|
|
137
143
|
async requestWithResponse(response) {
|
|
144
|
+
const headers = response?.headers?.entries
|
|
145
|
+
? Object.fromEntries(response.headers.entries())
|
|
146
|
+
: {};
|
|
147
|
+
const flowId = headers['x-flow-id'];
|
|
138
148
|
const text = await response.text();
|
|
139
149
|
try {
|
|
140
150
|
const responseJSON = JSON.parse(text);
|
|
151
|
+
// Inject the flow ID and headers into the response
|
|
152
|
+
responseJSON.flowId = flowId;
|
|
153
|
+
responseJSON.headers = headers;
|
|
141
154
|
return objKeysToCamelCase(responseJSON, ['metadata']);
|
|
142
155
|
}
|
|
143
156
|
catch (e) {
|
package/lib/esm/models/error.js
CHANGED
|
@@ -12,10 +12,12 @@ export class AbstractNylasSdkError extends Error {
|
|
|
12
12
|
* Class representation of a general Nylas API error.
|
|
13
13
|
*/
|
|
14
14
|
export class NylasApiError extends AbstractNylasApiError {
|
|
15
|
-
constructor(apiError, statusCode) {
|
|
15
|
+
constructor(apiError, statusCode, requestId, flowId, headers) {
|
|
16
16
|
super(apiError.error.message);
|
|
17
17
|
this.type = apiError.error.type;
|
|
18
|
-
this.requestId =
|
|
18
|
+
this.requestId = requestId;
|
|
19
|
+
this.flowId = flowId;
|
|
20
|
+
this.headers = headers;
|
|
19
21
|
this.providerError = apiError.error.providerError;
|
|
20
22
|
this.statusCode = statusCode;
|
|
21
23
|
}
|
|
@@ -24,22 +26,28 @@ export class NylasApiError extends AbstractNylasApiError {
|
|
|
24
26
|
* Class representing an OAuth error returned by the Nylas API.
|
|
25
27
|
*/
|
|
26
28
|
export class NylasOAuthError extends AbstractNylasApiError {
|
|
27
|
-
constructor(apiError, statusCode) {
|
|
29
|
+
constructor(apiError, statusCode, requestId, flowId, headers) {
|
|
28
30
|
super(apiError.errorDescription);
|
|
29
31
|
this.error = apiError.error;
|
|
30
32
|
this.errorCode = apiError.errorCode;
|
|
31
33
|
this.errorDescription = apiError.errorDescription;
|
|
32
34
|
this.errorUri = apiError.errorUri;
|
|
33
35
|
this.statusCode = statusCode;
|
|
36
|
+
this.requestId = requestId;
|
|
37
|
+
this.flowId = flowId;
|
|
38
|
+
this.headers = headers;
|
|
34
39
|
}
|
|
35
40
|
}
|
|
36
41
|
/**
|
|
37
42
|
* Error thrown when the Nylas SDK times out before receiving a response from the server
|
|
38
43
|
*/
|
|
39
44
|
export class NylasSdkTimeoutError extends AbstractNylasSdkError {
|
|
40
|
-
constructor(url, timeout) {
|
|
45
|
+
constructor(url, timeout, requestId, flowId, headers) {
|
|
41
46
|
super('Nylas SDK timed out before receiving a response from the server.');
|
|
42
47
|
this.url = url;
|
|
43
48
|
this.timeout = timeout;
|
|
49
|
+
this.requestId = requestId;
|
|
50
|
+
this.flowId = flowId;
|
|
51
|
+
this.headers = headers;
|
|
44
52
|
}
|
|
45
53
|
}
|
package/lib/esm/version.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// This file is generated by scripts/exportVersion.js
|
|
2
|
-
export const SDK_VERSION = '7.
|
|
2
|
+
export const SDK_VERSION = '7.8.0-canary.1';
|
|
@@ -10,6 +10,15 @@ export declare abstract class AbstractNylasApiError extends Error {
|
|
|
10
10
|
* The HTTP status code of the error response.
|
|
11
11
|
*/
|
|
12
12
|
statusCode?: number;
|
|
13
|
+
/**
|
|
14
|
+
* The flow ID
|
|
15
|
+
* Provide this to Nylas support to help trace requests and responses
|
|
16
|
+
*/
|
|
17
|
+
flowId?: string | null;
|
|
18
|
+
/**
|
|
19
|
+
* The response headers
|
|
20
|
+
*/
|
|
21
|
+
headers?: Record<string, string>;
|
|
13
22
|
}
|
|
14
23
|
/**
|
|
15
24
|
* Base class for all Nylas SDK errors.
|
|
@@ -28,7 +37,7 @@ export declare class NylasApiError extends AbstractNylasApiError implements Nyla
|
|
|
28
37
|
* Provider Error.
|
|
29
38
|
*/
|
|
30
39
|
providerError: any;
|
|
31
|
-
constructor(apiError: NylasApiErrorResponse, statusCode?: number);
|
|
40
|
+
constructor(apiError: NylasApiErrorResponse, statusCode?: number, requestId?: string, flowId?: string, headers?: Record<string, string>);
|
|
32
41
|
}
|
|
33
42
|
/**
|
|
34
43
|
* Class representing an OAuth error returned by the Nylas API.
|
|
@@ -50,7 +59,7 @@ export declare class NylasOAuthError extends AbstractNylasApiError implements Ny
|
|
|
50
59
|
* URL to the related documentation and troubleshooting regarding this error.
|
|
51
60
|
*/
|
|
52
61
|
errorUri: string;
|
|
53
|
-
constructor(apiError: NylasOAuthErrorResponse, statusCode?: number);
|
|
62
|
+
constructor(apiError: NylasOAuthErrorResponse, statusCode?: number, requestId?: string, flowId?: string, headers?: Record<string, string>);
|
|
54
63
|
}
|
|
55
64
|
/**
|
|
56
65
|
* Error thrown when the Nylas SDK times out before receiving a response from the server
|
|
@@ -64,7 +73,20 @@ export declare class NylasSdkTimeoutError extends AbstractNylasSdkError {
|
|
|
64
73
|
* The timeout value set in the Nylas SDK, in seconds
|
|
65
74
|
*/
|
|
66
75
|
timeout: number;
|
|
67
|
-
|
|
76
|
+
/**
|
|
77
|
+
* The request ID
|
|
78
|
+
*/
|
|
79
|
+
requestId?: string;
|
|
80
|
+
/**
|
|
81
|
+
* The flow ID
|
|
82
|
+
* Provide this to Nylas support to help trace requests and responses
|
|
83
|
+
*/
|
|
84
|
+
flowId?: string;
|
|
85
|
+
/**
|
|
86
|
+
* The response headers
|
|
87
|
+
*/
|
|
88
|
+
headers?: Record<string, string>;
|
|
89
|
+
constructor(url: string, timeout: number, requestId?: string, flowId?: string, headers?: Record<string, string>);
|
|
68
90
|
}
|
|
69
91
|
/**
|
|
70
92
|
* Interface representing the error response from the Nylas API.
|
|
@@ -72,6 +94,8 @@ export declare class NylasSdkTimeoutError extends AbstractNylasSdkError {
|
|
|
72
94
|
export interface NylasApiErrorResponse {
|
|
73
95
|
requestId: string;
|
|
74
96
|
error: NylasApiErrorResponseData;
|
|
97
|
+
flowId?: string;
|
|
98
|
+
headers?: Record<string, string>;
|
|
75
99
|
}
|
|
76
100
|
/**
|
|
77
101
|
* Interface representing the error data within the response object.
|
|
@@ -16,6 +16,15 @@ export interface NylasResponse<T> {
|
|
|
16
16
|
* The request ID
|
|
17
17
|
*/
|
|
18
18
|
requestId: string;
|
|
19
|
+
/**
|
|
20
|
+
* The flow ID
|
|
21
|
+
* Provide this t
|
|
22
|
+
*/
|
|
23
|
+
flowId?: string;
|
|
24
|
+
/**
|
|
25
|
+
* The response headers
|
|
26
|
+
*/
|
|
27
|
+
headers?: Record<string, string>;
|
|
19
28
|
}
|
|
20
29
|
/**
|
|
21
30
|
* Interface representation of a Nylas response object that contains a list of objects.
|
package/lib/types/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const SDK_VERSION = "7.
|
|
1
|
+
export declare const SDK_VERSION = "7.8.0-canary.1";
|