nylas 7.2.0 → 7.2.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/nylas.js +1 -1
- package/lib/cjs/resources/drafts.js +34 -10
- package/lib/cjs/resources/messages.js +17 -5
- package/lib/cjs/utils.js +18 -3
- package/lib/cjs/version.js +1 -1
- package/lib/esm/nylas.js +1 -1
- package/lib/esm/resources/drafts.js +34 -10
- package/lib/esm/resources/messages.js +17 -5
- package/lib/esm/utils.js +18 -3
- package/lib/esm/version.js +1 -1
- package/lib/types/models/availability.d.ts +1 -1
- package/lib/types/resources/messages.d.ts +1 -0
- package/lib/types/version.d.ts +1 -1
- package/package.json +1 -1
package/lib/cjs/nylas.js
CHANGED
|
@@ -44,7 +44,7 @@ class Nylas {
|
|
|
44
44
|
this.apiClient = new apiClient_js_1.default({
|
|
45
45
|
apiKey: config.apiKey,
|
|
46
46
|
apiUri: config.apiUri || config_js_1.DEFAULT_SERVER_URL,
|
|
47
|
-
timeout: config.timeout ||
|
|
47
|
+
timeout: config.timeout || 90,
|
|
48
48
|
});
|
|
49
49
|
this.applications = new applications_js_1.Applications(this.apiClient);
|
|
50
50
|
this.auth = new auth_js_1.Auth(this.apiClient);
|
|
@@ -35,11 +35,23 @@ class Drafts extends resource_js_1.Resource {
|
|
|
35
35
|
* @return The draft
|
|
36
36
|
*/
|
|
37
37
|
create({ identifier, requestBody, overrides, }) {
|
|
38
|
-
const
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
38
|
+
const path = `/v3/grants/${identifier}/drafts`;
|
|
39
|
+
// Use form data only if the attachment size is greater than 3mb
|
|
40
|
+
const attachmentSize = requestBody.attachments?.reduce(function (_, attachment) {
|
|
41
|
+
return attachment.size || 0;
|
|
42
|
+
}, 0) || 0;
|
|
43
|
+
if (attachmentSize >= messages_js_1.Messages.MAXIMUM_JSON_ATTACHMENT_SIZE) {
|
|
44
|
+
const form = messages_js_1.Messages._buildFormRequest(requestBody);
|
|
45
|
+
return this.apiClient.request({
|
|
46
|
+
method: 'POST',
|
|
47
|
+
path,
|
|
48
|
+
form,
|
|
49
|
+
overrides,
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
return super._create({
|
|
53
|
+
path,
|
|
54
|
+
requestBody,
|
|
43
55
|
overrides,
|
|
44
56
|
});
|
|
45
57
|
}
|
|
@@ -48,11 +60,23 @@ class Drafts extends resource_js_1.Resource {
|
|
|
48
60
|
* @return The updated draft
|
|
49
61
|
*/
|
|
50
62
|
update({ identifier, draftId, requestBody, overrides, }) {
|
|
51
|
-
const
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
63
|
+
const path = `/v3/grants/${identifier}/drafts/${draftId}`;
|
|
64
|
+
// Use form data only if the attachment size is greater than 3mb
|
|
65
|
+
const attachmentSize = requestBody.attachments?.reduce(function (_, attachment) {
|
|
66
|
+
return attachment.size || 0;
|
|
67
|
+
}, 0) || 0;
|
|
68
|
+
if (attachmentSize >= messages_js_1.Messages.MAXIMUM_JSON_ATTACHMENT_SIZE) {
|
|
69
|
+
const form = messages_js_1.Messages._buildFormRequest(requestBody);
|
|
70
|
+
return this.apiClient.request({
|
|
71
|
+
method: 'PUT',
|
|
72
|
+
path,
|
|
73
|
+
form,
|
|
74
|
+
overrides,
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
return super._update({
|
|
78
|
+
path,
|
|
79
|
+
requestBody,
|
|
56
80
|
overrides,
|
|
57
81
|
});
|
|
58
82
|
}
|
|
@@ -63,13 +63,23 @@ class Messages extends resource_js_1.Resource {
|
|
|
63
63
|
* @return The sent message
|
|
64
64
|
*/
|
|
65
65
|
send({ identifier, requestBody, overrides, }) {
|
|
66
|
-
const
|
|
67
|
-
|
|
66
|
+
const path = `/v3/grants/${identifier}/messages/send`;
|
|
67
|
+
const requestOptions = {
|
|
68
68
|
method: 'POST',
|
|
69
|
-
path
|
|
70
|
-
form,
|
|
69
|
+
path,
|
|
71
70
|
overrides,
|
|
72
|
-
}
|
|
71
|
+
};
|
|
72
|
+
// Use form data only if the attachment size is greater than 3mb
|
|
73
|
+
const attachmentSize = requestBody.attachments?.reduce(function (_, attachment) {
|
|
74
|
+
return attachment.size || 0;
|
|
75
|
+
}, 0) || 0;
|
|
76
|
+
if (attachmentSize >= Messages.MAXIMUM_JSON_ATTACHMENT_SIZE) {
|
|
77
|
+
requestOptions.form = Messages._buildFormRequest(requestBody);
|
|
78
|
+
}
|
|
79
|
+
else {
|
|
80
|
+
requestOptions.body = requestBody;
|
|
81
|
+
}
|
|
82
|
+
return this.apiClient.request(requestOptions);
|
|
73
83
|
}
|
|
74
84
|
/**
|
|
75
85
|
* Retrieve your scheduled messages
|
|
@@ -127,3 +137,5 @@ class Messages extends resource_js_1.Resource {
|
|
|
127
137
|
}
|
|
128
138
|
}
|
|
129
139
|
exports.Messages = Messages;
|
|
140
|
+
// The maximum size of an attachment that can be sent using json
|
|
141
|
+
Messages.MAXIMUM_JSON_ATTACHMENT_SIZE = 3 * 1024 * 1024;
|
package/lib/cjs/utils.js
CHANGED
|
@@ -18,6 +18,21 @@ function createFileRequestBuilder(filePath) {
|
|
|
18
18
|
};
|
|
19
19
|
}
|
|
20
20
|
exports.createFileRequestBuilder = createFileRequestBuilder;
|
|
21
|
+
/**
|
|
22
|
+
* Applies the casing function and ensures numeric parts are preceded by underscores in snake_case.
|
|
23
|
+
* @param casingFunction The original casing function.
|
|
24
|
+
* @param input The string to convert.
|
|
25
|
+
* @returns The converted string.
|
|
26
|
+
*/
|
|
27
|
+
function applyCasing(casingFunction, input) {
|
|
28
|
+
const transformed = casingFunction(input);
|
|
29
|
+
if (casingFunction === change_case_1.snakeCase) {
|
|
30
|
+
return transformed.replace(/(\d+)/g, '_$1');
|
|
31
|
+
}
|
|
32
|
+
else {
|
|
33
|
+
return transformed.replace(/_+(\d+)/g, (match, p1) => p1);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
21
36
|
/**
|
|
22
37
|
* A utility function that recursively converts all keys in an object to a given case.
|
|
23
38
|
* @param obj The object to convert
|
|
@@ -33,7 +48,7 @@ function convertCase(obj, casingFunction, excludeKeys) {
|
|
|
33
48
|
newObj[key] = obj[key];
|
|
34
49
|
}
|
|
35
50
|
else if (Array.isArray(obj[key])) {
|
|
36
|
-
newObj[casingFunction
|
|
51
|
+
newObj[applyCasing(casingFunction, key)] = obj[key].map(item => {
|
|
37
52
|
if (typeof item === 'object') {
|
|
38
53
|
return convertCase(item, casingFunction);
|
|
39
54
|
}
|
|
@@ -43,10 +58,10 @@ function convertCase(obj, casingFunction, excludeKeys) {
|
|
|
43
58
|
});
|
|
44
59
|
}
|
|
45
60
|
else if (typeof obj[key] === 'object' && obj[key] !== null) {
|
|
46
|
-
newObj[casingFunction
|
|
61
|
+
newObj[applyCasing(casingFunction, key)] = convertCase(obj[key], casingFunction);
|
|
47
62
|
}
|
|
48
63
|
else {
|
|
49
|
-
newObj[casingFunction
|
|
64
|
+
newObj[applyCasing(casingFunction, key)] = obj[key];
|
|
50
65
|
}
|
|
51
66
|
}
|
|
52
67
|
return newObj;
|
package/lib/cjs/version.js
CHANGED
package/lib/esm/nylas.js
CHANGED
|
@@ -28,7 +28,7 @@ export default class Nylas {
|
|
|
28
28
|
this.apiClient = new APIClient({
|
|
29
29
|
apiKey: config.apiKey,
|
|
30
30
|
apiUri: config.apiUri || DEFAULT_SERVER_URL,
|
|
31
|
-
timeout: config.timeout ||
|
|
31
|
+
timeout: config.timeout || 90,
|
|
32
32
|
});
|
|
33
33
|
this.applications = new Applications(this.apiClient);
|
|
34
34
|
this.auth = new Auth(this.apiClient);
|
|
@@ -32,11 +32,23 @@ export class Drafts extends Resource {
|
|
|
32
32
|
* @return The draft
|
|
33
33
|
*/
|
|
34
34
|
create({ identifier, requestBody, overrides, }) {
|
|
35
|
-
const
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
35
|
+
const path = `/v3/grants/${identifier}/drafts`;
|
|
36
|
+
// Use form data only if the attachment size is greater than 3mb
|
|
37
|
+
const attachmentSize = requestBody.attachments?.reduce(function (_, attachment) {
|
|
38
|
+
return attachment.size || 0;
|
|
39
|
+
}, 0) || 0;
|
|
40
|
+
if (attachmentSize >= Messages.MAXIMUM_JSON_ATTACHMENT_SIZE) {
|
|
41
|
+
const form = Messages._buildFormRequest(requestBody);
|
|
42
|
+
return this.apiClient.request({
|
|
43
|
+
method: 'POST',
|
|
44
|
+
path,
|
|
45
|
+
form,
|
|
46
|
+
overrides,
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
return super._create({
|
|
50
|
+
path,
|
|
51
|
+
requestBody,
|
|
40
52
|
overrides,
|
|
41
53
|
});
|
|
42
54
|
}
|
|
@@ -45,11 +57,23 @@ export class Drafts extends Resource {
|
|
|
45
57
|
* @return The updated draft
|
|
46
58
|
*/
|
|
47
59
|
update({ identifier, draftId, requestBody, overrides, }) {
|
|
48
|
-
const
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
60
|
+
const path = `/v3/grants/${identifier}/drafts/${draftId}`;
|
|
61
|
+
// Use form data only if the attachment size is greater than 3mb
|
|
62
|
+
const attachmentSize = requestBody.attachments?.reduce(function (_, attachment) {
|
|
63
|
+
return attachment.size || 0;
|
|
64
|
+
}, 0) || 0;
|
|
65
|
+
if (attachmentSize >= Messages.MAXIMUM_JSON_ATTACHMENT_SIZE) {
|
|
66
|
+
const form = Messages._buildFormRequest(requestBody);
|
|
67
|
+
return this.apiClient.request({
|
|
68
|
+
method: 'PUT',
|
|
69
|
+
path,
|
|
70
|
+
form,
|
|
71
|
+
overrides,
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
return super._update({
|
|
75
|
+
path,
|
|
76
|
+
requestBody,
|
|
53
77
|
overrides,
|
|
54
78
|
});
|
|
55
79
|
}
|
|
@@ -60,13 +60,23 @@ export class Messages extends Resource {
|
|
|
60
60
|
* @return The sent message
|
|
61
61
|
*/
|
|
62
62
|
send({ identifier, requestBody, overrides, }) {
|
|
63
|
-
const
|
|
64
|
-
|
|
63
|
+
const path = `/v3/grants/${identifier}/messages/send`;
|
|
64
|
+
const requestOptions = {
|
|
65
65
|
method: 'POST',
|
|
66
|
-
path
|
|
67
|
-
form,
|
|
66
|
+
path,
|
|
68
67
|
overrides,
|
|
69
|
-
}
|
|
68
|
+
};
|
|
69
|
+
// Use form data only if the attachment size is greater than 3mb
|
|
70
|
+
const attachmentSize = requestBody.attachments?.reduce(function (_, attachment) {
|
|
71
|
+
return attachment.size || 0;
|
|
72
|
+
}, 0) || 0;
|
|
73
|
+
if (attachmentSize >= Messages.MAXIMUM_JSON_ATTACHMENT_SIZE) {
|
|
74
|
+
requestOptions.form = Messages._buildFormRequest(requestBody);
|
|
75
|
+
}
|
|
76
|
+
else {
|
|
77
|
+
requestOptions.body = requestBody;
|
|
78
|
+
}
|
|
79
|
+
return this.apiClient.request(requestOptions);
|
|
70
80
|
}
|
|
71
81
|
/**
|
|
72
82
|
* Retrieve your scheduled messages
|
|
@@ -123,3 +133,5 @@ export class Messages extends Resource {
|
|
|
123
133
|
return form;
|
|
124
134
|
}
|
|
125
135
|
}
|
|
136
|
+
// The maximum size of an attachment that can be sent using json
|
|
137
|
+
Messages.MAXIMUM_JSON_ATTACHMENT_SIZE = 3 * 1024 * 1024;
|
package/lib/esm/utils.js
CHANGED
|
@@ -14,6 +14,21 @@ export function createFileRequestBuilder(filePath) {
|
|
|
14
14
|
size: stats.size,
|
|
15
15
|
};
|
|
16
16
|
}
|
|
17
|
+
/**
|
|
18
|
+
* Applies the casing function and ensures numeric parts are preceded by underscores in snake_case.
|
|
19
|
+
* @param casingFunction The original casing function.
|
|
20
|
+
* @param input The string to convert.
|
|
21
|
+
* @returns The converted string.
|
|
22
|
+
*/
|
|
23
|
+
function applyCasing(casingFunction, input) {
|
|
24
|
+
const transformed = casingFunction(input);
|
|
25
|
+
if (casingFunction === snakeCase) {
|
|
26
|
+
return transformed.replace(/(\d+)/g, '_$1');
|
|
27
|
+
}
|
|
28
|
+
else {
|
|
29
|
+
return transformed.replace(/_+(\d+)/g, (match, p1) => p1);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
17
32
|
/**
|
|
18
33
|
* A utility function that recursively converts all keys in an object to a given case.
|
|
19
34
|
* @param obj The object to convert
|
|
@@ -29,7 +44,7 @@ function convertCase(obj, casingFunction, excludeKeys) {
|
|
|
29
44
|
newObj[key] = obj[key];
|
|
30
45
|
}
|
|
31
46
|
else if (Array.isArray(obj[key])) {
|
|
32
|
-
newObj[casingFunction
|
|
47
|
+
newObj[applyCasing(casingFunction, key)] = obj[key].map(item => {
|
|
33
48
|
if (typeof item === 'object') {
|
|
34
49
|
return convertCase(item, casingFunction);
|
|
35
50
|
}
|
|
@@ -39,10 +54,10 @@ function convertCase(obj, casingFunction, excludeKeys) {
|
|
|
39
54
|
});
|
|
40
55
|
}
|
|
41
56
|
else if (typeof obj[key] === 'object' && obj[key] !== null) {
|
|
42
|
-
newObj[casingFunction
|
|
57
|
+
newObj[applyCasing(casingFunction, key)] = convertCase(obj[key], casingFunction);
|
|
43
58
|
}
|
|
44
59
|
else {
|
|
45
|
-
newObj[casingFunction
|
|
60
|
+
newObj[applyCasing(casingFunction, key)] = obj[key];
|
|
46
61
|
}
|
|
47
62
|
}
|
|
48
63
|
return newObj;
|
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.
|
|
2
|
+
export const SDK_VERSION = '7.2.1';
|
|
@@ -52,7 +52,7 @@ export interface GetAvailabilityRequest {
|
|
|
52
52
|
/**
|
|
53
53
|
* When set to true, the availability time slots will start at 30 minutes past or on the hour.
|
|
54
54
|
* For example, a free slot starting at 16:10 is considered available only from 16:30.
|
|
55
|
-
* @deprecated Use
|
|
55
|
+
* @deprecated Use {@link roundTo} instead.
|
|
56
56
|
*/
|
|
57
57
|
roundTo30Minutes?: boolean;
|
|
58
58
|
}
|
|
@@ -84,6 +84,7 @@ export type StopScheduledMessageParams = FindScheduledMessageParams;
|
|
|
84
84
|
*/
|
|
85
85
|
export declare class Messages extends Resource {
|
|
86
86
|
smartCompose: SmartCompose;
|
|
87
|
+
static MAXIMUM_JSON_ATTACHMENT_SIZE: number;
|
|
87
88
|
constructor(apiClient: APIClient);
|
|
88
89
|
/**
|
|
89
90
|
* Return all Messages
|
package/lib/types/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const SDK_VERSION = "7.2.
|
|
1
|
+
export declare const SDK_VERSION = "7.2.1";
|