nylas 7.0.0-beta.2 → 7.0.0-beta.3

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.
Files changed (72) hide show
  1. package/README.md +19 -10
  2. package/lib/cjs/apiClient.js +7 -0
  3. package/lib/cjs/models/connectors.js +2 -0
  4. package/lib/cjs/models/credentials.js +12 -0
  5. package/lib/cjs/models/drafts.js +2 -0
  6. package/lib/cjs/models/files.js +2 -0
  7. package/lib/cjs/models/freeBusy.js +11 -0
  8. package/lib/cjs/models/messages.js +11 -0
  9. package/lib/cjs/models/smartCompose.js +2 -0
  10. package/lib/cjs/models/threads.js +2 -0
  11. package/lib/cjs/models/webhooks.js +3 -0
  12. package/lib/cjs/nylas.js +8 -0
  13. package/lib/cjs/resources/auth.js +8 -6
  14. package/lib/cjs/resources/calendars.js +12 -0
  15. package/lib/cjs/resources/connectors.js +68 -0
  16. package/lib/cjs/resources/credentials.js +60 -0
  17. package/lib/cjs/resources/drafts.js +81 -0
  18. package/lib/cjs/resources/grants.js +2 -2
  19. package/lib/cjs/resources/messages.js +121 -0
  20. package/lib/cjs/resources/redirectUris.js +1 -1
  21. package/lib/cjs/resources/smartCompose.js +34 -0
  22. package/lib/cjs/resources/threads.js +54 -0
  23. package/lib/cjs/utils.js +17 -1
  24. package/lib/cjs/version.js +1 -1
  25. package/lib/esm/apiClient.js +7 -0
  26. package/lib/esm/models/connectors.js +1 -0
  27. package/lib/esm/models/credentials.js +9 -0
  28. package/lib/esm/models/drafts.js +1 -0
  29. package/lib/esm/models/files.js +1 -0
  30. package/lib/esm/models/freeBusy.js +8 -0
  31. package/lib/esm/models/messages.js +8 -0
  32. package/lib/esm/models/smartCompose.js +1 -0
  33. package/lib/esm/models/threads.js +1 -0
  34. package/lib/esm/models/webhooks.js +3 -0
  35. package/lib/esm/nylas.js +8 -0
  36. package/lib/esm/resources/auth.js +8 -6
  37. package/lib/esm/resources/calendars.js +12 -0
  38. package/lib/esm/resources/connectors.js +64 -0
  39. package/lib/esm/resources/credentials.js +56 -0
  40. package/lib/esm/resources/drafts.js +77 -0
  41. package/lib/esm/resources/grants.js +2 -2
  42. package/lib/esm/resources/messages.js +117 -0
  43. package/lib/esm/resources/redirectUris.js +1 -1
  44. package/lib/esm/resources/smartCompose.js +30 -0
  45. package/lib/esm/resources/threads.js +50 -0
  46. package/lib/esm/utils.js +15 -0
  47. package/lib/esm/version.js +1 -1
  48. package/lib/types/apiClient.d.ts +3 -1
  49. package/lib/types/models/auth.d.ts +1 -1
  50. package/lib/types/models/calendars.d.ts +1 -1
  51. package/lib/types/models/connectors.d.ts +127 -0
  52. package/lib/types/models/credentials.d.ts +151 -0
  53. package/lib/types/models/drafts.d.ts +92 -0
  54. package/lib/types/models/files.d.ts +17 -0
  55. package/lib/types/models/freeBusy.d.ts +79 -0
  56. package/lib/types/models/messages.d.ts +271 -0
  57. package/lib/types/models/smartCompose.d.ts +18 -0
  58. package/lib/types/models/threads.d.ts +153 -0
  59. package/lib/types/models/webhooks.d.ts +80 -2
  60. package/lib/types/nylas.d.ts +20 -0
  61. package/lib/types/resources/calendars.d.ts +16 -1
  62. package/lib/types/resources/connectors.d.ts +80 -0
  63. package/lib/types/resources/credentials.d.ts +80 -0
  64. package/lib/types/resources/drafts.d.ts +87 -0
  65. package/lib/types/resources/grants.d.ts +1 -1
  66. package/lib/types/resources/messages.d.ts +129 -0
  67. package/lib/types/resources/smartCompose.d.ts +41 -0
  68. package/lib/types/resources/threads.d.ts +70 -0
  69. package/lib/types/resources/webhooks.d.ts +1 -1
  70. package/lib/types/utils.d.ts +2 -0
  71. package/lib/types/version.d.ts +1 -1
  72. package/package.json +5 -3
package/README.md CHANGED
@@ -4,18 +4,22 @@
4
4
 
5
5
  # Nylas Node.js SDK
6
6
 
7
+ [![npm](https://img.shields.io/npm/v/nylas%2Fbeta?label=npm%40beta)
8
+ ](https://www.npmjs.com/package/nylas/v/beta@)
7
9
  [![codecov](https://codecov.io/gh/nylas/nylas-nodejs/branch/main/graph/badge.svg?token=94IMGU4F09)](https://codecov.io/gh/nylas/nylas-nodejs)
8
10
 
9
- This is the GitHub repository for the Nylas Node SDK and this repo is primarily for anyone who wants to make contributions to the SDK or install it from source. If you are looking to use Node to access the Nylas Email, Calendar, or Contacts API you should refer to our official [Node SDK Quickstart Guide](https://developer.nylas.com/docs/developer-tools/sdk/node-sdk/).
11
+ This is the GitHub repository for the Nylas Node SDK. This repo is primarily for anyone who wants to make contributions to the SDK, or install it from source. If you are looking to use Node to access the Nylas Email, Calendar, or Contacts API you should refer to our official [Node SDK Quickstart Guide](https://developer.nylas.com/docs/developer-tools/sdk/node-sdk/).
10
12
 
11
13
  The Nylas Communications Platform provides REST APIs for [Email](https://developer.nylas.com/docs/connectivity/email/), [Calendar](https://developer.nylas.com/docs/connectivity/calendar/), and [Contacts](https://developer.nylas.com/docs/connectivity/contacts/), and the Node SDK is the quickest way to build your integration using JavaScript.
12
14
 
13
15
  Here are some resources to help you get started:
14
16
 
15
- - [Nylas SDK Tutorials](https://developer.nylas.com/docs/the-basics/tutorials/nodejs/)
16
- - [Quickstart](https://developer.nylas.com/docs/the-basics/quickstart/)
17
+ - [Sign up for your free Nylas account](https://dashboard.nylas.com/register)
18
+ - [Sign up for the Nylas v3 Beta program to access the v3 Dashboard](https://info.nylas.com/apiv3betasignup.html?utm_source=github&utm_medium=devrel-surfaces&utm_campaign=&utm_content=node-sdk-upgrade)
19
+ - [Nylas API v3 Quickstart Guide](https://developer.nylas.com/docs/v3-beta/v3-quickstart/)
20
+ - [Nylas SDK Reference](https://nylas-nodejs-sdk-reference.pages.dev/)
17
21
  - [Nylas API Reference](https://developer.nylas.com/docs/api/)
18
-
22
+ - [Nylas Samples repo for code samples and example applications](https://github.com/orgs/nylas-samples/repositories?q=&type=all&language=javascript)
19
23
 
20
24
  ## ⚙️ Install
21
25
 
@@ -23,12 +27,12 @@ Here are some resources to help you get started:
23
27
 
24
28
  ### Set up using npm
25
29
 
26
- To run the Nylas Node SDK, you will first need to have [Node](https://nodejs.org/en/download/) and [npm](https://www.npmjs.com/get-npm) installed on your machine.
30
+ To run the Nylas Node SDK, first install [Node](https://nodejs.org/en/download/) and [npm](https://www.npmjs.com/get-npm) on your machine.
27
31
 
28
32
  Then, head to the nearest command line and run the following:
29
33
  `npm install nylas@beta`
30
34
 
31
- Alternatively, if you prefer to use [Yarn](https://yarnpkg.com/en/), you can install the Nylas Node SDK with `yarn add nylas`
35
+ Alternatively, you can use [Yarn](https://yarnpkg.com/en/) to install the Nylas Node SDK by running the `yarn add nylas` command.
32
36
 
33
37
  ### Build from source
34
38
 
@@ -50,7 +54,7 @@ For code examples that demonstrate how to use this SDK, take a look at our [Node
50
54
 
51
55
  ### 🚀 Making Your First Request
52
56
 
53
- Every resource (i.e., messages, events, contacts) is accessed via an instance of `Nylas`. The `Nylas` object must be initialized with your Nylas API key, and you can provide other additional configurations such as the Nylas API url and the timeout.
57
+ You access Nylas resources (messages, calendars, events, contacts) through an instance of `Nylas`. The `Nylas` object must be initialized with your Nylas API key, and you can provide other additional configurations such as the Nylas API url and the timeout.
54
58
 
55
59
  ```typescript
56
60
  import Nylas from "nylas";
@@ -61,6 +65,7 @@ const nylas = new Nylas({
61
65
  ```
62
66
 
63
67
  Once initialized you can use the object to make requests for a given account's resources, for example to list all the calendars for a given account:
68
+
64
69
  ```typescript
65
70
  nylas.calendars.list({ identifier: "GRANT_ID" }).then(calendars => {
66
71
  console.log(calendars);
@@ -71,12 +76,16 @@ nylas.calendars.list({ identifier: "GRANT_ID" }).then(calendars => {
71
76
 
72
77
  Nylas maintains a [reference guide for the Node SDK](https://nylas-nodejs-sdk-reference.pages.dev/) to help you get familiar with the available methods and classes.
73
78
 
79
+ ## ✨ Upgrading from 6.x
80
+
81
+ See [UPGRADE.md](UPGRADE.md) for instructions on upgrading from 6.x to 7.x.
82
+
83
+ **Note**: The Node SDK v7.x is not compatible with the Nylas API earlier than v3-beta.
84
+
74
85
  ## 💙 Contributing
75
86
 
76
87
  Please refer to [Contributing](Contributing.md) for information about how to make contributions to this project. We welcome questions, bug reports, and pull requests.
77
88
 
78
89
  ## 📝 License
79
90
 
80
- This project is licensed under the terms of the MIT license. Please refer to [LICENSE](LICENSE.txt) for the full terms.
81
-
82
-
91
+ This project is licensed under the terms of the MIT license. Please refer to [LICENSE](LICENSE.txt) for the full terms.
@@ -55,6 +55,13 @@ class APIClient {
55
55
  requestOptions.body = JSON.stringify((0, utils_js_1.objKeysToSnakeCase)(optionParams.body));
56
56
  requestOptions.headers['Content-Type'] = 'application/json';
57
57
  }
58
+ if (optionParams.form) {
59
+ requestOptions.body = optionParams.form;
60
+ requestOptions.headers = {
61
+ ...requestOptions.headers,
62
+ ...optionParams.form.getHeaders(),
63
+ };
64
+ }
58
65
  return requestOptions;
59
66
  }
60
67
  newRequest(options) {
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CredentialType = void 0;
4
+ /**
5
+ * Enum representing the type of credential
6
+ */
7
+ var CredentialType;
8
+ (function (CredentialType) {
9
+ CredentialType["ADMINCONSENT"] = "adminconsent";
10
+ CredentialType["SERVICEACCOUNT"] = "serviceaccount";
11
+ CredentialType["CONNECTOR"] = "connector";
12
+ })(CredentialType = exports.CredentialType || (exports.CredentialType = {}));
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.FreeBusyType = void 0;
4
+ /**
5
+ * Enum representing the type of free/busy information returned for a calendar.
6
+ */
7
+ var FreeBusyType;
8
+ (function (FreeBusyType) {
9
+ FreeBusyType["FREE_BUSY"] = "free_busy";
10
+ FreeBusyType["ERROR"] = "error";
11
+ })(FreeBusyType = exports.FreeBusyType || (exports.FreeBusyType = {}));
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MessageFields = void 0;
4
+ /**
5
+ * Enum representing the message fields that can be included in a response.
6
+ */
7
+ var MessageFields;
8
+ (function (MessageFields) {
9
+ MessageFields["STANDARD"] = "standard";
10
+ MessageFields["INCLUDE_HEADERS"] = "include_headers";
11
+ })(MessageFields = exports.MessageFields || (exports.MessageFields = {}));
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,6 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.WebhookTriggers = void 0;
4
+ /**
5
+ * Enum representing the available webhook triggers.
6
+ */
4
7
  var WebhookTriggers;
5
8
  (function (WebhookTriggers) {
6
9
  WebhookTriggers["CalendarCreated"] = "calendar.created";
package/lib/cjs/nylas.js CHANGED
@@ -7,6 +7,10 @@ const events_js_1 = require("./resources/events.js");
7
7
  const auth_js_1 = require("./resources/auth.js");
8
8
  const webhooks_js_1 = require("./resources/webhooks.js");
9
9
  const applications_js_1 = require("./resources/applications.js");
10
+ const messages_js_1 = require("./resources/messages.js");
11
+ const drafts_js_1 = require("./resources/drafts.js");
12
+ const threads_js_1 = require("./resources/threads.js");
13
+ const connectors_js_1 = require("./resources/connectors.js");
10
14
  /**
11
15
  * The entry point to the Node SDK
12
16
  *
@@ -26,7 +30,11 @@ class Nylas {
26
30
  this.applications = new applications_js_1.Applications(this.apiClient);
27
31
  this.auth = new auth_js_1.Auth(this.apiClient);
28
32
  this.calendars = new calendars_js_1.Calendars(this.apiClient);
33
+ this.connectors = new connectors_js_1.Connectors(this.apiClient);
34
+ this.drafts = new drafts_js_1.Drafts(this.apiClient);
29
35
  this.events = new events_js_1.Events(this.apiClient);
36
+ this.messages = new messages_js_1.Messages(this.apiClient);
37
+ this.threads = new threads_js_1.Threads(this.apiClient);
30
38
  this.webhooks = new webhooks_js_1.Webhooks(this.apiClient);
31
39
  return this;
32
40
  }
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Auth = void 0;
4
4
  const uuid_1 = require("uuid");
5
- const sha256_1 = require("sha256");
5
+ const node_crypto_1 = require("node:crypto");
6
6
  const resource_js_1 = require("./resource.js");
7
7
  const grants_js_1 = require("./grants.js");
8
8
  /**
@@ -74,7 +74,7 @@ class Auth extends resource_js_1.Resource {
74
74
  url.searchParams.set('code_challenge_method', 's256');
75
75
  const secret = (0, uuid_1.v4)();
76
76
  const secretHash = this.hashPKCESecret(secret);
77
- url.searchParams.set('code_challenge', secret);
77
+ url.searchParams.set('code_challenge', secretHash);
78
78
  // Return the url with secret & hashed secret
79
79
  return { secret, secretHash, url: url.toString() };
80
80
  }
@@ -138,16 +138,18 @@ class Auth extends resource_js_1.Resource {
138
138
  if (config.prompt) {
139
139
  url.searchParams.set('prompt', config.prompt);
140
140
  }
141
- if (config.metadata) {
142
- url.searchParams.set('metadata', config.metadata);
143
- }
144
141
  if (config.state) {
145
142
  url.searchParams.set('state', config.state);
146
143
  }
147
144
  return url;
148
145
  }
149
146
  hashPKCESecret(secret) {
150
- return Buffer.from((0, sha256_1.default)(secret)).toString('base64');
147
+ const hash = (0, node_crypto_1.createHash)('sha256')
148
+ .update(secret)
149
+ .digest('hex');
150
+ return Buffer.from(hash)
151
+ .toString('base64')
152
+ .replace(/=+$/, '');
151
153
  }
152
154
  }
153
155
  exports.Auth = Auth;
@@ -74,5 +74,17 @@ class Calendars extends resource_js_1.Resource {
74
74
  overrides,
75
75
  });
76
76
  }
77
+ /**
78
+ * Get the free/busy schedule for a list of email addresses
79
+ * @return The free/busy response
80
+ */
81
+ getFreeBusy({ identifier, requestBody, overrides, }) {
82
+ return this.apiClient.request({
83
+ method: 'POST',
84
+ path: `/v3/grants/${identifier}/calendars/free-busy`,
85
+ body: requestBody,
86
+ overrides,
87
+ });
88
+ }
77
89
  }
78
90
  exports.Calendars = Calendars;
@@ -0,0 +1,68 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Connectors = void 0;
4
+ const resource_js_1 = require("./resource.js");
5
+ const credentials_js_1 = require("./credentials.js");
6
+ class Connectors extends resource_js_1.Resource {
7
+ /**
8
+ * @param apiClient client The configured Nylas API client
9
+ */
10
+ constructor(apiClient) {
11
+ super(apiClient);
12
+ this.credentials = new credentials_js_1.Credentials(apiClient);
13
+ }
14
+ /**
15
+ * Return all connectors
16
+ * @return A list of connectors
17
+ */
18
+ list({ queryParams, overrides, }) {
19
+ return super._list({
20
+ queryParams,
21
+ overrides,
22
+ path: `/v3/connectors`,
23
+ });
24
+ }
25
+ /**
26
+ * Return a connector
27
+ * @return The connector
28
+ */
29
+ find({ provider, overrides, }) {
30
+ return super._find({
31
+ path: `/v3/connectors/${provider}`,
32
+ overrides,
33
+ });
34
+ }
35
+ /**
36
+ * Create a connector
37
+ * @return The created connector
38
+ */
39
+ create({ requestBody, overrides, }) {
40
+ return super._create({
41
+ path: `/v3/connectors`,
42
+ requestBody,
43
+ overrides,
44
+ });
45
+ }
46
+ /**
47
+ * Update a connector
48
+ * @return The updated connector
49
+ */
50
+ update({ provider, requestBody, overrides, }) {
51
+ return super._update({
52
+ path: `/v3/connectors/${provider}`,
53
+ requestBody,
54
+ overrides,
55
+ });
56
+ }
57
+ /**
58
+ * Delete a connector
59
+ * @return The deleted connector
60
+ */
61
+ destroy({ provider, overrides, }) {
62
+ return super._destroy({
63
+ path: `/v3/connectors/${provider}`,
64
+ overrides,
65
+ });
66
+ }
67
+ }
68
+ exports.Connectors = Connectors;
@@ -0,0 +1,60 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Credentials = void 0;
4
+ const resource_js_1 = require("./resource.js");
5
+ class Credentials extends resource_js_1.Resource {
6
+ /**
7
+ * Return all credentials
8
+ * @return A list of credentials
9
+ */
10
+ list({ provider, queryParams, overrides, }) {
11
+ return super._list({
12
+ queryParams,
13
+ overrides,
14
+ path: `/v3/credentials/${provider}/creds`,
15
+ });
16
+ }
17
+ /**
18
+ * Return a credential
19
+ * @return The credential
20
+ */
21
+ find({ provider, credentialsId, overrides, }) {
22
+ return super._find({
23
+ path: `/v3/credentials/${provider}/creds/${credentialsId}`,
24
+ overrides,
25
+ });
26
+ }
27
+ /**
28
+ * Create a credential
29
+ * @return The created credential
30
+ */
31
+ create({ provider, requestBody, overrides, }) {
32
+ return super._create({
33
+ path: `/v3/credentials/${provider}/creds`,
34
+ requestBody,
35
+ overrides,
36
+ });
37
+ }
38
+ /**
39
+ * Update a credential
40
+ * @return The updated credential
41
+ */
42
+ update({ provider, credentialsId, requestBody, overrides, }) {
43
+ return super._update({
44
+ path: `/v3/credentials/${provider}/creds/${credentialsId}}`,
45
+ requestBody,
46
+ overrides,
47
+ });
48
+ }
49
+ /**
50
+ * Delete a credential
51
+ * @return The deleted credential
52
+ */
53
+ destroy({ provider, credentialsId, overrides, }) {
54
+ return super._destroy({
55
+ path: `/v3/credentials/${provider}/creds/${credentialsId}}`,
56
+ overrides,
57
+ });
58
+ }
59
+ }
60
+ exports.Credentials = Credentials;
@@ -0,0 +1,81 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Drafts = void 0;
4
+ const resource_js_1 = require("./resource.js");
5
+ const messages_js_1 = require("./messages.js");
6
+ /**
7
+ * Nylas Drafts API
8
+ *
9
+ * The Nylas Drafts API allows you to list, find, update, delete, and send drafts on user accounts.
10
+ */
11
+ class Drafts extends resource_js_1.Resource {
12
+ /**
13
+ * Return all Drafts
14
+ * @return A list of drafts
15
+ */
16
+ list({ identifier, queryParams, overrides, }) {
17
+ return super._list({
18
+ queryParams,
19
+ overrides,
20
+ path: `/v3/grants/${identifier}/drafts`,
21
+ });
22
+ }
23
+ /**
24
+ * Return a Draft
25
+ * @return The draft
26
+ */
27
+ find({ identifier, draftId, overrides, }) {
28
+ return super._find({
29
+ path: `/v3/grants/${identifier}/drafts/${draftId}`,
30
+ overrides,
31
+ });
32
+ }
33
+ /**
34
+ * Return a Draft
35
+ * @return The draft
36
+ */
37
+ create({ identifier, requestBody, overrides, }) {
38
+ const form = messages_js_1.Messages._buildFormRequest(requestBody);
39
+ return this.apiClient.request({
40
+ method: 'POST',
41
+ path: `/v3/grants/${identifier}/drafts`,
42
+ form,
43
+ overrides,
44
+ });
45
+ }
46
+ /**
47
+ * Update a Draft
48
+ * @return The updated draft
49
+ */
50
+ update({ identifier, draftId, requestBody, overrides, }) {
51
+ const form = messages_js_1.Messages._buildFormRequest(requestBody);
52
+ return this.apiClient.request({
53
+ method: 'PUT',
54
+ path: `/v3/grants/${identifier}/drafts/${draftId}`,
55
+ form,
56
+ overrides,
57
+ });
58
+ }
59
+ /**
60
+ * Delete a Draft
61
+ * @return The deleted draft
62
+ */
63
+ destroy({ identifier, draftId, overrides, }) {
64
+ return super._destroy({
65
+ path: `/v3/grants/${identifier}/drafts/${draftId}`,
66
+ overrides,
67
+ });
68
+ }
69
+ /**
70
+ * Send a Draft
71
+ * @return The sent draft
72
+ */
73
+ send({ identifier, draftId, overrides, }) {
74
+ return super._create({
75
+ path: `/v3/grants/${identifier}/drafts/${draftId}`,
76
+ requestBody: {},
77
+ overrides,
78
+ });
79
+ }
80
+ }
81
+ exports.Drafts = Drafts;
@@ -30,12 +30,12 @@ class Grants extends resource_js_1.Resource {
30
30
  });
31
31
  }
32
32
  /**
33
- * Create a Grant
33
+ * Create a Grant via Custom Authentication
34
34
  * @return The created Grant
35
35
  */
36
36
  create({ requestBody, overrides, }) {
37
37
  return super._create({
38
- path: `/v3/grants`,
38
+ path: `/v3/connect/custom`,
39
39
  requestBody,
40
40
  overrides,
41
41
  });
@@ -0,0 +1,121 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Messages = void 0;
4
+ const resource_js_1 = require("./resource.js");
5
+ const FormData = require("form-data");
6
+ const utils_js_1 = require("../utils.js");
7
+ const smartCompose_js_1 = require("./smartCompose.js");
8
+ /**
9
+ * Nylas Messages API
10
+ *
11
+ * The Nylas Messages API allows you to list, find, update, delete, schedule, and send messages on user accounts.
12
+ */
13
+ class Messages extends resource_js_1.Resource {
14
+ constructor(apiClient) {
15
+ super(apiClient);
16
+ this.smartCompose = new smartCompose_js_1.SmartCompose(apiClient);
17
+ }
18
+ /**
19
+ * Return all Messages
20
+ * @return A list of messages
21
+ */
22
+ list({ identifier, queryParams, overrides, }) {
23
+ return super._list({
24
+ queryParams,
25
+ overrides,
26
+ path: `/v3/grants/${identifier}/messages`,
27
+ });
28
+ }
29
+ /**
30
+ * Return a Message
31
+ * @return The message
32
+ */
33
+ find({ identifier, messageId, overrides, }) {
34
+ return super._find({
35
+ path: `/v3/grants/${identifier}/messages/${messageId}`,
36
+ overrides,
37
+ });
38
+ }
39
+ /**
40
+ * Update a Message
41
+ * @return The updated message
42
+ */
43
+ update({ identifier, messageId, requestBody, overrides, }) {
44
+ return super._update({
45
+ path: `/v3/grants/${identifier}/messages/${messageId}`,
46
+ requestBody,
47
+ overrides,
48
+ });
49
+ }
50
+ /**
51
+ * Delete a Message
52
+ * @return The deleted message
53
+ */
54
+ destroy({ identifier, messageId, overrides, }) {
55
+ return super._destroy({
56
+ path: `/v3/grants/${identifier}/messages/${messageId}`,
57
+ overrides,
58
+ });
59
+ }
60
+ /**
61
+ * Send an email
62
+ * @return The sent message
63
+ */
64
+ send({ identifier, requestBody, overrides, }) {
65
+ const form = Messages._buildFormRequest(requestBody);
66
+ return this.apiClient.request({
67
+ method: 'POST',
68
+ path: `/v3/grants/${identifier}/messages/send`,
69
+ form,
70
+ overrides,
71
+ });
72
+ }
73
+ /**
74
+ * Retrieve your scheduled messages
75
+ * @return A list of scheduled messages
76
+ */
77
+ listScheduledMessages({ identifier, overrides, }) {
78
+ return super._find({
79
+ path: `/v3/grants/${identifier}/messages/schedules`,
80
+ overrides,
81
+ });
82
+ }
83
+ /**
84
+ * Retrieve a scheduled message
85
+ * @return The scheduled message
86
+ */
87
+ findScheduledMessage({ identifier, scheduleId, overrides, }) {
88
+ return super._find({
89
+ path: `/v3/grants/${identifier}/messages/schedules/${scheduleId}`,
90
+ overrides,
91
+ });
92
+ }
93
+ /**
94
+ * Stop a scheduled message
95
+ * @return The confirmation of the stopped scheduled message
96
+ */
97
+ stopScheduledMessage({ identifier, scheduleId, overrides, }) {
98
+ return super._destroy({
99
+ path: `/v3/grants/${identifier}/messages/schedules/${scheduleId}`,
100
+ overrides,
101
+ });
102
+ }
103
+ static _buildFormRequest(requestBody) {
104
+ const form = new FormData();
105
+ // Split out the message payload from the attachments
106
+ const messagePayload = {
107
+ ...requestBody,
108
+ attachments: undefined,
109
+ };
110
+ form.append('message', JSON.stringify((0, utils_js_1.objKeysToSnakeCase)(messagePayload)));
111
+ // Add a separate form field for each attachment
112
+ requestBody.attachments?.forEach((attachment, index) => {
113
+ form.append(`file${index}`, attachment.content, {
114
+ filename: attachment.filename,
115
+ contentType: attachment.contentType,
116
+ });
117
+ });
118
+ return form;
119
+ }
120
+ }
121
+ exports.Messages = Messages;
@@ -57,7 +57,7 @@ class RedirectUris extends resource_js_1.Resource {
57
57
  destroy({ redirectUriId, overrides, }) {
58
58
  return super._destroy({
59
59
  overrides,
60
- path: `/v1/redirect_uris/${redirectUriId}`,
60
+ path: `/v3/applications/redirect-uris/${redirectUriId}`,
61
61
  });
62
62
  }
63
63
  }
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SmartCompose = void 0;
4
+ const resource_js_1 = require("./resource.js");
5
+ /**
6
+ * A collection of Smart Compose related API endpoints.
7
+ *
8
+ * These endpoints allow for the generation of message suggestions.
9
+ */
10
+ class SmartCompose extends resource_js_1.Resource {
11
+ /**
12
+ * Compose a message
13
+ * @return The generated message
14
+ */
15
+ composeMessage({ identifier, requestBody, overrides, }) {
16
+ return super._create({
17
+ path: `/v3/grants/${identifier}/messages/smart-compose`,
18
+ requestBody,
19
+ overrides,
20
+ });
21
+ }
22
+ /**
23
+ * Compose a message reply
24
+ * @return The generated message reply
25
+ */
26
+ composeMessageReply({ identifier, messageId, requestBody, overrides, }) {
27
+ return super._create({
28
+ path: `/v3/grants/${identifier}/messages/${messageId}/smart-compose`,
29
+ requestBody,
30
+ overrides,
31
+ });
32
+ }
33
+ }
34
+ exports.SmartCompose = SmartCompose;