nylas 7.0.0-beta.2 → 7.0.0-beta.4

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 (100) hide show
  1. package/README.md +19 -10
  2. package/lib/cjs/apiClient.js +57 -32
  3. package/lib/cjs/models/attachments.js +2 -0
  4. package/lib/cjs/models/connectors.js +2 -0
  5. package/lib/cjs/models/contacts.js +2 -0
  6. package/lib/cjs/models/credentials.js +12 -0
  7. package/lib/cjs/models/drafts.js +2 -0
  8. package/lib/cjs/models/files.js +2 -0
  9. package/lib/cjs/models/folders.js +2 -0
  10. package/lib/cjs/models/freeBusy.js +11 -0
  11. package/lib/cjs/models/messages.js +11 -0
  12. package/lib/cjs/models/smartCompose.js +2 -0
  13. package/lib/cjs/models/threads.js +2 -0
  14. package/lib/cjs/models/webhooks.js +3 -0
  15. package/lib/cjs/nylas.js +16 -0
  16. package/lib/cjs/resources/attachments.js +57 -0
  17. package/lib/cjs/resources/auth.js +21 -16
  18. package/lib/cjs/resources/calendars.js +12 -0
  19. package/lib/cjs/resources/connectors.js +68 -0
  20. package/lib/cjs/resources/contacts.js +76 -0
  21. package/lib/cjs/resources/credentials.js +60 -0
  22. package/lib/cjs/resources/drafts.js +81 -0
  23. package/lib/cjs/resources/events.js +14 -0
  24. package/lib/cjs/resources/folders.js +72 -0
  25. package/lib/cjs/resources/grants.js +0 -11
  26. package/lib/cjs/resources/messages.js +128 -0
  27. package/lib/cjs/resources/redirectUris.js +1 -1
  28. package/lib/cjs/resources/resource.js +16 -0
  29. package/lib/cjs/resources/smartCompose.js +34 -0
  30. package/lib/cjs/resources/threads.js +54 -0
  31. package/lib/cjs/utils.js +17 -1
  32. package/lib/cjs/version.js +1 -1
  33. package/lib/esm/apiClient.js +57 -32
  34. package/lib/esm/models/attachments.js +1 -0
  35. package/lib/esm/models/connectors.js +1 -0
  36. package/lib/esm/models/contacts.js +1 -0
  37. package/lib/esm/models/credentials.js +9 -0
  38. package/lib/esm/models/drafts.js +1 -0
  39. package/lib/esm/models/files.js +1 -0
  40. package/lib/esm/models/folders.js +1 -0
  41. package/lib/esm/models/freeBusy.js +8 -0
  42. package/lib/esm/models/messages.js +8 -0
  43. package/lib/esm/models/smartCompose.js +1 -0
  44. package/lib/esm/models/threads.js +1 -0
  45. package/lib/esm/models/webhooks.js +3 -0
  46. package/lib/esm/nylas.js +16 -0
  47. package/lib/esm/resources/attachments.js +53 -0
  48. package/lib/esm/resources/auth.js +21 -16
  49. package/lib/esm/resources/calendars.js +12 -0
  50. package/lib/esm/resources/connectors.js +64 -0
  51. package/lib/esm/resources/contacts.js +72 -0
  52. package/lib/esm/resources/credentials.js +56 -0
  53. package/lib/esm/resources/drafts.js +77 -0
  54. package/lib/esm/resources/events.js +14 -0
  55. package/lib/esm/resources/folders.js +68 -0
  56. package/lib/esm/resources/grants.js +0 -11
  57. package/lib/esm/resources/messages.js +124 -0
  58. package/lib/esm/resources/redirectUris.js +1 -1
  59. package/lib/esm/resources/resource.js +16 -0
  60. package/lib/esm/resources/smartCompose.js +30 -0
  61. package/lib/esm/resources/threads.js +50 -0
  62. package/lib/esm/utils.js +15 -0
  63. package/lib/esm/version.js +1 -1
  64. package/lib/types/apiClient.d.ts +8 -1
  65. package/lib/types/models/attachments.d.ts +42 -0
  66. package/lib/types/models/auth.d.ts +5 -1
  67. package/lib/types/models/calendars.d.ts +1 -1
  68. package/lib/types/models/connectors.d.ts +123 -0
  69. package/lib/types/models/contacts.d.ts +148 -0
  70. package/lib/types/models/credentials.d.ts +151 -0
  71. package/lib/types/models/drafts.d.ts +92 -0
  72. package/lib/types/models/events.d.ts +14 -0
  73. package/lib/types/models/files.d.ts +17 -0
  74. package/lib/types/models/folders.d.ts +71 -0
  75. package/lib/types/models/freeBusy.d.ts +79 -0
  76. package/lib/types/models/messages.d.ts +271 -0
  77. package/lib/types/models/response.d.ts +6 -6
  78. package/lib/types/models/smartCompose.d.ts +18 -0
  79. package/lib/types/models/threads.d.ts +153 -0
  80. package/lib/types/models/webhooks.d.ts +80 -2
  81. package/lib/types/nylas.d.ts +40 -0
  82. package/lib/types/resources/attachments.d.ts +61 -0
  83. package/lib/types/resources/auth.d.ts +15 -11
  84. package/lib/types/resources/calendars.d.ts +18 -3
  85. package/lib/types/resources/connectors.d.ts +80 -0
  86. package/lib/types/resources/contacts.d.ts +92 -0
  87. package/lib/types/resources/credentials.d.ts +80 -0
  88. package/lib/types/resources/drafts.d.ts +87 -0
  89. package/lib/types/resources/events.d.ts +22 -3
  90. package/lib/types/resources/folders.d.ts +90 -0
  91. package/lib/types/resources/grants.d.ts +3 -14
  92. package/lib/types/resources/messages.d.ts +129 -0
  93. package/lib/types/resources/redirectUris.d.ts +2 -2
  94. package/lib/types/resources/resource.d.ts +4 -0
  95. package/lib/types/resources/smartCompose.d.ts +41 -0
  96. package/lib/types/resources/threads.d.ts +70 -0
  97. package/lib/types/resources/webhooks.d.ts +1 -1
  98. package/lib/types/utils.d.ts +2 -0
  99. package/lib/types/version.d.ts +1 -1
  100. package/package.json +5 -3
@@ -0,0 +1,53 @@
1
+ import { Resource } from './resource.js';
2
+ /**
3
+ * Nylas Attachments API
4
+ *
5
+ * The Nylas Attachments API allows you to retrieve metadata and download attachments.
6
+ */
7
+ export class Attachments extends Resource {
8
+ /**
9
+ * Returns an attachment by ID.
10
+ * @return The Attachment metadata
11
+ */
12
+ find({ identifier, attachmentId, queryParams, overrides, }) {
13
+ return super._find({
14
+ path: `/v3/grants/${identifier}/attachments/${attachmentId}`,
15
+ queryParams,
16
+ overrides,
17
+ });
18
+ }
19
+ /**
20
+ * Download the attachment data
21
+ *
22
+ * This method returns a NodeJS.ReadableStream which can be used to stream the attachment data.
23
+ * This is particularly useful for handling large attachments efficiently, as it avoids loading
24
+ * the entire file into memory. The stream can be piped to a file stream or used in any other way
25
+ * that Node.js streams are typically used.
26
+ *
27
+ * @param identifier Grant ID or email account to query
28
+ * @param attachmentId The id of the attachment to download.
29
+ * @param queryParams The query parameters to include in the request
30
+ * @returns {NodeJS.ReadableStream} The ReadableStream containing the file data.
31
+ */
32
+ download({ identifier, attachmentId, queryParams, overrides, }) {
33
+ return this._getStream({
34
+ path: `/v3/grants/${identifier}/attachments/${attachmentId}/download`,
35
+ queryParams,
36
+ overrides,
37
+ });
38
+ }
39
+ /**
40
+ * Download the attachment as a byte array
41
+ * @param identifier Grant ID or email account to query
42
+ * @param attachmentId The id of the attachment to download.
43
+ * @param queryParams The query parameters to include in the request
44
+ * @return The raw file data
45
+ */
46
+ downloadBytes({ identifier, attachmentId, queryParams, overrides, }) {
47
+ return super._getRaw({
48
+ path: `/v3/grants/${identifier}/attachments/${attachmentId}/download`,
49
+ queryParams,
50
+ overrides,
51
+ });
52
+ }
53
+ }
@@ -1,7 +1,6 @@
1
1
  import { v4 as uuid } from 'uuid';
2
- import sha256 from 'sha256';
2
+ import { createHash } from 'node:crypto';
3
3
  import { Resource } from './resource.js';
4
- import { Grants } from './grants.js';
5
4
  /**
6
5
  * A collection of authentication related API endpoints
7
6
  *
@@ -9,14 +8,6 @@ import { Grants } from './grants.js';
9
8
  * Also contains the Grants API and collection of provider API endpoints.
10
9
  */
11
10
  export class Auth extends Resource {
12
- /**
13
- * @param apiClient The configured Nylas API client
14
- */
15
- constructor(apiClient) {
16
- super(apiClient);
17
- this.apiClient = apiClient;
18
- this.grants = new Grants(apiClient);
19
- }
20
11
  /**
21
12
  * Build the URL for authenticating users to your application with OAuth 2.0
22
13
  * @param config The configuration for building the URL
@@ -71,7 +62,7 @@ export class Auth extends Resource {
71
62
  url.searchParams.set('code_challenge_method', 's256');
72
63
  const secret = uuid();
73
64
  const secretHash = this.hashPKCESecret(secret);
74
- url.searchParams.set('code_challenge', secret);
65
+ url.searchParams.set('code_challenge', secretHash);
75
66
  // Return the url with secret & hashed secret
76
67
  return { secret, secretHash, url: url.toString() };
77
68
  }
@@ -87,6 +78,18 @@ export class Auth extends Resource {
87
78
  url.searchParams.set('credential_id', config.credentialId);
88
79
  return url.toString();
89
80
  }
81
+ /**
82
+ * Create a grant via Custom Authentication
83
+ * @return The created grant
84
+ */
85
+ customAuthentication({ requestBody, overrides, }) {
86
+ return this.apiClient.request({
87
+ method: 'POST',
88
+ path: `/v3/connect/custom`,
89
+ body: requestBody,
90
+ overrides,
91
+ });
92
+ }
90
93
  /**
91
94
  * Revoke a token (and the grant attached to the token)
92
95
  * @param token The token to revoke
@@ -110,7 +113,7 @@ export class Auth extends Resource {
110
113
  async detectProvider(params) {
111
114
  return this.apiClient.request({
112
115
  method: 'POST',
113
- path: `/v3/grants/providers/detect`,
116
+ path: `/v3/providers/detect`,
114
117
  queryParams: params,
115
118
  });
116
119
  }
@@ -135,15 +138,17 @@ export class Auth extends Resource {
135
138
  if (config.prompt) {
136
139
  url.searchParams.set('prompt', config.prompt);
137
140
  }
138
- if (config.metadata) {
139
- url.searchParams.set('metadata', config.metadata);
140
- }
141
141
  if (config.state) {
142
142
  url.searchParams.set('state', config.state);
143
143
  }
144
144
  return url;
145
145
  }
146
146
  hashPKCESecret(secret) {
147
- return Buffer.from(sha256(secret)).toString('base64');
147
+ const hash = createHash('sha256')
148
+ .update(secret)
149
+ .digest('hex');
150
+ return Buffer.from(hash)
151
+ .toString('base64')
152
+ .replace(/=+$/, '');
148
153
  }
149
154
  }
@@ -71,4 +71,16 @@ export class Calendars extends Resource {
71
71
  overrides,
72
72
  });
73
73
  }
74
+ /**
75
+ * Get the free/busy schedule for a list of email addresses
76
+ * @return The free/busy response
77
+ */
78
+ getFreeBusy({ identifier, requestBody, overrides, }) {
79
+ return this.apiClient.request({
80
+ method: 'POST',
81
+ path: `/v3/grants/${identifier}/calendars/free-busy`,
82
+ body: requestBody,
83
+ overrides,
84
+ });
85
+ }
74
86
  }
@@ -0,0 +1,64 @@
1
+ import { Resource } from './resource.js';
2
+ import { Credentials } from './credentials.js';
3
+ export class Connectors extends Resource {
4
+ /**
5
+ * @param apiClient client The configured Nylas API client
6
+ */
7
+ constructor(apiClient) {
8
+ super(apiClient);
9
+ this.credentials = new Credentials(apiClient);
10
+ }
11
+ /**
12
+ * Return all connectors
13
+ * @return A list of connectors
14
+ */
15
+ list({ queryParams, overrides, }) {
16
+ return super._list({
17
+ queryParams,
18
+ overrides,
19
+ path: `/v3/connectors`,
20
+ });
21
+ }
22
+ /**
23
+ * Return a connector
24
+ * @return The connector
25
+ */
26
+ find({ provider, overrides, }) {
27
+ return super._find({
28
+ path: `/v3/connectors/${provider}`,
29
+ overrides,
30
+ });
31
+ }
32
+ /**
33
+ * Create a connector
34
+ * @return The created connector
35
+ */
36
+ create({ requestBody, overrides, }) {
37
+ return super._create({
38
+ path: `/v3/connectors`,
39
+ requestBody,
40
+ overrides,
41
+ });
42
+ }
43
+ /**
44
+ * Update a connector
45
+ * @return The updated connector
46
+ */
47
+ update({ provider, requestBody, overrides, }) {
48
+ return super._update({
49
+ path: `/v3/connectors/${provider}`,
50
+ requestBody,
51
+ overrides,
52
+ });
53
+ }
54
+ /**
55
+ * Delete a connector
56
+ * @return The deleted connector
57
+ */
58
+ destroy({ provider, overrides, }) {
59
+ return super._destroy({
60
+ path: `/v3/connectors/${provider}`,
61
+ overrides,
62
+ });
63
+ }
64
+ }
@@ -0,0 +1,72 @@
1
+ import { Resource } from './resource.js';
2
+ /**
3
+ * Nylas Contacts API
4
+ *
5
+ * The Nylas Contacts API allows you to create, update, and delete contacts.
6
+ */
7
+ export class Contacts extends Resource {
8
+ /**
9
+ * Return all Contacts
10
+ * @return The list of Contacts
11
+ */
12
+ list({ identifier, queryParams, overrides, }) {
13
+ return super._list({
14
+ queryParams,
15
+ path: `/v3/grants/${identifier}/contacts`,
16
+ overrides,
17
+ });
18
+ }
19
+ /**
20
+ * Return a Contact
21
+ * @return The Contact
22
+ */
23
+ find({ identifier, contactId, queryParams, overrides, }) {
24
+ return super._find({
25
+ path: `/v3/grants/${identifier}/contacts/${contactId}`,
26
+ queryParams,
27
+ overrides,
28
+ });
29
+ }
30
+ /**
31
+ * Create a Contact
32
+ * @return The created Contact
33
+ */
34
+ create({ identifier, requestBody, overrides, }) {
35
+ return super._create({
36
+ path: `/v3/grants/${identifier}/contacts`,
37
+ requestBody,
38
+ overrides,
39
+ });
40
+ }
41
+ /**
42
+ * Update a Contact
43
+ * @return The updated Contact
44
+ */
45
+ update({ identifier, contactId, requestBody, overrides, }) {
46
+ return super._update({
47
+ path: `/v3/grants/${identifier}/contacts/${contactId}`,
48
+ requestBody,
49
+ overrides,
50
+ });
51
+ }
52
+ /**
53
+ * Delete a Contact
54
+ * @return The deletion response
55
+ */
56
+ destroy({ identifier, contactId, overrides, }) {
57
+ return super._destroy({
58
+ path: `/v3/grants/${identifier}/contacts/${contactId}`,
59
+ overrides,
60
+ });
61
+ }
62
+ /**
63
+ * Return a Contact Group
64
+ * @return The list of Contact Groups
65
+ */
66
+ groups({ identifier, overrides, }) {
67
+ return super._list({
68
+ path: `/v3/grants/${identifier}/contacts/groups`,
69
+ overrides,
70
+ });
71
+ }
72
+ }
@@ -0,0 +1,56 @@
1
+ import { Resource } from './resource.js';
2
+ export class Credentials extends Resource {
3
+ /**
4
+ * Return all credentials
5
+ * @return A list of credentials
6
+ */
7
+ list({ provider, queryParams, overrides, }) {
8
+ return super._list({
9
+ queryParams,
10
+ overrides,
11
+ path: `/v3/credentials/${provider}/creds`,
12
+ });
13
+ }
14
+ /**
15
+ * Return a credential
16
+ * @return The credential
17
+ */
18
+ find({ provider, credentialsId, overrides, }) {
19
+ return super._find({
20
+ path: `/v3/credentials/${provider}/creds/${credentialsId}`,
21
+ overrides,
22
+ });
23
+ }
24
+ /**
25
+ * Create a credential
26
+ * @return The created credential
27
+ */
28
+ create({ provider, requestBody, overrides, }) {
29
+ return super._create({
30
+ path: `/v3/credentials/${provider}/creds`,
31
+ requestBody,
32
+ overrides,
33
+ });
34
+ }
35
+ /**
36
+ * Update a credential
37
+ * @return The updated credential
38
+ */
39
+ update({ provider, credentialsId, requestBody, overrides, }) {
40
+ return super._update({
41
+ path: `/v3/credentials/${provider}/creds/${credentialsId}}`,
42
+ requestBody,
43
+ overrides,
44
+ });
45
+ }
46
+ /**
47
+ * Delete a credential
48
+ * @return The deleted credential
49
+ */
50
+ destroy({ provider, credentialsId, overrides, }) {
51
+ return super._destroy({
52
+ path: `/v3/credentials/${provider}/creds/${credentialsId}}`,
53
+ overrides,
54
+ });
55
+ }
56
+ }
@@ -0,0 +1,77 @@
1
+ import { Resource } from './resource.js';
2
+ import { Messages } from './messages.js';
3
+ /**
4
+ * Nylas Drafts API
5
+ *
6
+ * The Nylas Drafts API allows you to list, find, update, delete, and send drafts on user accounts.
7
+ */
8
+ export class Drafts extends Resource {
9
+ /**
10
+ * Return all Drafts
11
+ * @return A list of drafts
12
+ */
13
+ list({ identifier, queryParams, overrides, }) {
14
+ return super._list({
15
+ queryParams,
16
+ overrides,
17
+ path: `/v3/grants/${identifier}/drafts`,
18
+ });
19
+ }
20
+ /**
21
+ * Return a Draft
22
+ * @return The draft
23
+ */
24
+ find({ identifier, draftId, overrides, }) {
25
+ return super._find({
26
+ path: `/v3/grants/${identifier}/drafts/${draftId}`,
27
+ overrides,
28
+ });
29
+ }
30
+ /**
31
+ * Return a Draft
32
+ * @return The draft
33
+ */
34
+ create({ identifier, requestBody, overrides, }) {
35
+ const form = Messages._buildFormRequest(requestBody);
36
+ return this.apiClient.request({
37
+ method: 'POST',
38
+ path: `/v3/grants/${identifier}/drafts`,
39
+ form,
40
+ overrides,
41
+ });
42
+ }
43
+ /**
44
+ * Update a Draft
45
+ * @return The updated draft
46
+ */
47
+ update({ identifier, draftId, requestBody, overrides, }) {
48
+ const form = Messages._buildFormRequest(requestBody);
49
+ return this.apiClient.request({
50
+ method: 'PUT',
51
+ path: `/v3/grants/${identifier}/drafts/${draftId}`,
52
+ form,
53
+ overrides,
54
+ });
55
+ }
56
+ /**
57
+ * Delete a Draft
58
+ * @return The deleted draft
59
+ */
60
+ destroy({ identifier, draftId, overrides, }) {
61
+ return super._destroy({
62
+ path: `/v3/grants/${identifier}/drafts/${draftId}`,
63
+ overrides,
64
+ });
65
+ }
66
+ /**
67
+ * Send a Draft
68
+ * @return The sent draft
69
+ */
70
+ send({ identifier, draftId, overrides, }) {
71
+ return super._create({
72
+ path: `/v3/grants/${identifier}/drafts/${draftId}`,
73
+ requestBody: {},
74
+ overrides,
75
+ });
76
+ }
77
+ }
@@ -62,4 +62,18 @@ export class Events extends Resource {
62
62
  overrides,
63
63
  });
64
64
  }
65
+ /**
66
+ * Send RSVP. Allows users to respond to events they have been added to as an attendee.
67
+ * You cannot send RSVP as an event owner/organizer.
68
+ * You cannot directly update events as an invitee, since you are not the owner/organizer.
69
+ * @return The send-rsvp response
70
+ */
71
+ sendRsvp({ identifier, eventId, requestBody, queryParams, overrides, }) {
72
+ return super._create({
73
+ path: `/v3/grants/${identifier}/events/${eventId}/send-rsvp`,
74
+ queryParams,
75
+ requestBody,
76
+ overrides,
77
+ });
78
+ }
65
79
  }
@@ -0,0 +1,68 @@
1
+ import { Resource } from './resource.js';
2
+ /**
3
+ * Nylas Folder API
4
+ *
5
+ * Email providers use folders to store and organize email messages. Examples of common system folders include Inbox, Sent, Drafts, etc.
6
+ *
7
+ * If your team is migrating from Nylas APIv2, there were previously two separate endpoints for interacting with Folders (Microsoft) and Labels (Google).
8
+ * In Nylas API v3, these endpoints are consolidated under Folders.
9
+ *
10
+ * To simplify the developer experience, Nylas uses the same folders commands to manage both folders and labels, using the folder_id key to refer to the folder's ID on the provider.
11
+ * The API also exposes provider-specific fields such as background_color (Google only).
12
+ *
13
+ * Depending on the provider (Google, some IMAP providers, etc.), a message can be contained in more than one folder.
14
+ */
15
+ export class Folders extends Resource {
16
+ /**
17
+ * Return all Folders
18
+ * @return A list of folders
19
+ */
20
+ list({ identifier, overrides, }) {
21
+ return super._list({
22
+ overrides,
23
+ path: `/v3/grants/${identifier}/folders`,
24
+ });
25
+ }
26
+ /**
27
+ * Return a Folder
28
+ * @return The folder
29
+ */
30
+ find({ identifier, folderId, overrides, }) {
31
+ return super._find({
32
+ path: `/v3/grants/${identifier}/folders/${folderId}`,
33
+ overrides,
34
+ });
35
+ }
36
+ /**
37
+ * Create a Folder
38
+ * @return The created folder
39
+ */
40
+ create({ identifier, requestBody, overrides, }) {
41
+ return super._create({
42
+ path: `/v3/grants/${identifier}/folders`,
43
+ requestBody,
44
+ overrides,
45
+ });
46
+ }
47
+ /**
48
+ * Update a Folder
49
+ * @return The updated Folder
50
+ */
51
+ update({ identifier, folderId, requestBody, overrides, }) {
52
+ return super._update({
53
+ path: `/v3/grants/${identifier}/folders/${folderId}`,
54
+ requestBody,
55
+ overrides,
56
+ });
57
+ }
58
+ /**
59
+ * Delete a Folder
60
+ * @return The deleted Folder
61
+ */
62
+ destroy({ identifier, folderId, overrides, }) {
63
+ return super._destroy({
64
+ path: `/v3/grants/${identifier}/folders/${folderId}`,
65
+ overrides,
66
+ });
67
+ }
68
+ }
@@ -26,17 +26,6 @@ export class Grants extends Resource {
26
26
  overrides,
27
27
  });
28
28
  }
29
- /**
30
- * Create a Grant
31
- * @return The created Grant
32
- */
33
- create({ requestBody, overrides, }) {
34
- return super._create({
35
- path: `/v3/grants`,
36
- requestBody,
37
- overrides,
38
- });
39
- }
40
29
  /**
41
30
  * Update a Grant
42
31
  * @return The updated Grant
@@ -0,0 +1,124 @@
1
+ import { Resource } from './resource.js';
2
+ import * as FormData from 'form-data';
3
+ import { objKeysToSnakeCase } from '../utils.js';
4
+ import { SmartCompose } from './smartCompose.js';
5
+ /**
6
+ * Nylas Messages API
7
+ *
8
+ * The Nylas Messages API allows you to list, find, update, delete, schedule, and send messages on user accounts.
9
+ */
10
+ export class Messages extends Resource {
11
+ constructor(apiClient) {
12
+ super(apiClient);
13
+ this.smartCompose = new SmartCompose(apiClient);
14
+ }
15
+ /**
16
+ * Return all Messages
17
+ * @return A list of messages
18
+ */
19
+ list({ identifier, queryParams, overrides, }) {
20
+ return super._list({
21
+ queryParams,
22
+ overrides,
23
+ path: `/v3/grants/${identifier}/messages`,
24
+ });
25
+ }
26
+ /**
27
+ * Return a Message
28
+ * @return The message
29
+ */
30
+ find({ identifier, messageId, overrides, }) {
31
+ return super._find({
32
+ path: `/v3/grants/${identifier}/messages/${messageId}`,
33
+ overrides,
34
+ });
35
+ }
36
+ /**
37
+ * Update a Message
38
+ * @return The updated message
39
+ */
40
+ update({ identifier, messageId, requestBody, overrides, }) {
41
+ return super._update({
42
+ path: `/v3/grants/${identifier}/messages/${messageId}`,
43
+ requestBody,
44
+ overrides,
45
+ });
46
+ }
47
+ /**
48
+ * Delete a Message
49
+ * @return The deleted message
50
+ */
51
+ destroy({ identifier, messageId, overrides, }) {
52
+ return super._destroy({
53
+ path: `/v3/grants/${identifier}/messages/${messageId}`,
54
+ overrides,
55
+ });
56
+ }
57
+ /**
58
+ * Send an email
59
+ * @return The sent message
60
+ */
61
+ send({ identifier, requestBody, overrides, }) {
62
+ const form = Messages._buildFormRequest(requestBody);
63
+ return this.apiClient.request({
64
+ method: 'POST',
65
+ path: `/v3/grants/${identifier}/messages/send`,
66
+ form,
67
+ overrides,
68
+ });
69
+ }
70
+ /**
71
+ * Retrieve your scheduled messages
72
+ * @return A list of scheduled messages
73
+ */
74
+ listScheduledMessages({ identifier, overrides, }) {
75
+ return super._find({
76
+ path: `/v3/grants/${identifier}/messages/schedules`,
77
+ overrides,
78
+ });
79
+ }
80
+ /**
81
+ * Retrieve a scheduled message
82
+ * @return The scheduled message
83
+ */
84
+ findScheduledMessage({ identifier, scheduleId, overrides, }) {
85
+ return super._find({
86
+ path: `/v3/grants/${identifier}/messages/schedules/${scheduleId}`,
87
+ overrides,
88
+ });
89
+ }
90
+ /**
91
+ * Stop a scheduled message
92
+ * @return The confirmation of the stopped scheduled message
93
+ */
94
+ stopScheduledMessage({ identifier, scheduleId, overrides, }) {
95
+ return super._destroy({
96
+ path: `/v3/grants/${identifier}/messages/schedules/${scheduleId}`,
97
+ overrides,
98
+ });
99
+ }
100
+ static _buildFormRequest(requestBody) {
101
+ let form;
102
+ // FormData imports are funky, cjs needs to use .default, es6 doesn't
103
+ if (typeof FormData.default !== 'undefined') {
104
+ form = new FormData.default();
105
+ }
106
+ else {
107
+ form = new FormData();
108
+ }
109
+ // Split out the message payload from the attachments
110
+ const messagePayload = {
111
+ ...requestBody,
112
+ attachments: undefined,
113
+ };
114
+ form.append('message', JSON.stringify(objKeysToSnakeCase(messagePayload)));
115
+ // Add a separate form field for each attachment
116
+ requestBody.attachments?.forEach((attachment, index) => {
117
+ form.append(`file${index}`, attachment.content, {
118
+ filename: attachment.filename,
119
+ contentType: attachment.contentType,
120
+ });
121
+ });
122
+ return form;
123
+ }
124
+ }
@@ -54,7 +54,7 @@ export class RedirectUris extends Resource {
54
54
  destroy({ redirectUriId, overrides, }) {
55
55
  return super._destroy({
56
56
  overrides,
57
- path: `/v1/redirect_uris/${redirectUriId}`,
57
+ path: `/v3/applications/redirect-uris/${redirectUriId}`,
58
58
  });
59
59
  }
60
60
  }
@@ -104,4 +104,20 @@ export class Resource {
104
104
  overrides,
105
105
  });
106
106
  }
107
+ _getRaw({ path, queryParams, overrides, }) {
108
+ return this.apiClient.requestRaw({
109
+ method: 'GET',
110
+ path,
111
+ queryParams,
112
+ overrides,
113
+ });
114
+ }
115
+ _getStream({ path, queryParams, overrides, }) {
116
+ return this.apiClient.requestStream({
117
+ method: 'GET',
118
+ path,
119
+ queryParams,
120
+ overrides,
121
+ });
122
+ }
107
123
  }