nylas 7.0.0-beta.0 → 7.0.0-beta.2

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 (204) hide show
  1. package/README.md +27 -19
  2. package/lib/cjs/apiClient.js +114 -0
  3. package/lib/cjs/config.js +32 -0
  4. package/lib/cjs/models/applicationDetails.js +2 -0
  5. package/lib/cjs/models/auth.js +2 -0
  6. package/lib/cjs/models/availability.js +11 -0
  7. package/lib/cjs/models/calendars.js +2 -0
  8. package/lib/cjs/models/error.js +53 -0
  9. package/lib/cjs/models/events.js +2 -0
  10. package/lib/cjs/models/grants.js +2 -0
  11. package/lib/cjs/models/listQueryParams.js +2 -0
  12. package/lib/cjs/models/redirectUri.js +2 -0
  13. package/lib/cjs/models/response.js +2 -0
  14. package/lib/cjs/models/webhooks.js +18 -0
  15. package/lib/cjs/nylas.js +34 -0
  16. package/lib/cjs/package.json +3 -0
  17. package/lib/cjs/resources/applications.js +30 -0
  18. package/lib/cjs/resources/auth.js +153 -0
  19. package/lib/cjs/resources/calendars.js +78 -0
  20. package/lib/cjs/resources/events.js +69 -0
  21. package/lib/cjs/resources/grants.js +65 -0
  22. package/lib/cjs/resources/redirectUris.js +64 -0
  23. package/lib/cjs/resources/resource.js +111 -0
  24. package/lib/cjs/resources/webhooks.js +98 -0
  25. package/lib/cjs/utils.js +58 -0
  26. package/lib/cjs/version.js +5 -0
  27. package/lib/esm/apiClient.js +111 -0
  28. package/lib/esm/config.js +29 -0
  29. package/lib/esm/models/applicationDetails.js +1 -0
  30. package/lib/esm/models/auth.js +1 -0
  31. package/lib/esm/models/availability.js +8 -0
  32. package/lib/esm/models/calendars.js +1 -0
  33. package/lib/esm/models/error.js +45 -0
  34. package/lib/esm/models/events.js +1 -0
  35. package/lib/esm/models/grants.js +1 -0
  36. package/lib/esm/models/listQueryParams.js +1 -0
  37. package/lib/esm/models/redirectUri.js +1 -0
  38. package/lib/esm/models/response.js +1 -0
  39. package/lib/esm/models/webhooks.js +15 -0
  40. package/lib/esm/nylas.js +31 -0
  41. package/lib/esm/package.json +3 -0
  42. package/lib/esm/resources/applications.js +26 -0
  43. package/lib/esm/resources/auth.js +149 -0
  44. package/lib/esm/resources/calendars.js +74 -0
  45. package/lib/esm/resources/events.js +65 -0
  46. package/lib/esm/resources/grants.js +61 -0
  47. package/lib/esm/resources/redirectUris.js +60 -0
  48. package/lib/esm/resources/resource.js +107 -0
  49. package/lib/esm/resources/webhooks.js +94 -0
  50. package/lib/esm/utils.js +53 -0
  51. package/lib/esm/version.js +2 -0
  52. package/lib/types/apiClient.d.ts +65 -0
  53. package/lib/types/config.d.ts +50 -0
  54. package/lib/types/models/applicationDetails.d.ts +93 -0
  55. package/lib/types/models/auth.d.ts +196 -0
  56. package/lib/types/models/availability.d.ts +159 -0
  57. package/lib/types/models/calendars.d.ts +121 -0
  58. package/lib/types/models/error.d.ts +104 -0
  59. package/lib/types/models/events.d.ts +494 -0
  60. package/lib/types/models/grants.d.ts +134 -0
  61. package/lib/types/models/listQueryParams.d.ts +4 -0
  62. package/lib/types/models/redirectUri.d.ts +71 -0
  63. package/lib/types/models/response.d.ts +40 -0
  64. package/lib/types/models/webhooks.d.ts +45 -0
  65. package/lib/types/nylas.d.ts +44 -0
  66. package/lib/types/resources/applications.d.ts +26 -0
  67. package/lib/types/resources/auth.d.ts +66 -0
  68. package/lib/types/resources/calendars.d.ts +97 -0
  69. package/lib/types/resources/events.d.ts +87 -0
  70. package/lib/types/resources/grants.d.ts +63 -0
  71. package/lib/types/resources/redirectUris.d.ts +63 -0
  72. package/lib/types/resources/resource.d.ts +55 -0
  73. package/lib/types/resources/webhooks.d.ts +79 -0
  74. package/lib/types/utils.d.ts +22 -0
  75. package/lib/types/version.d.ts +1 -0
  76. package/package.json +33 -42
  77. package/lib/config.d.ts +0 -70
  78. package/lib/config.js +0 -68
  79. package/lib/models/access-token.d.ts +0 -18
  80. package/lib/models/access-token.js +0 -56
  81. package/lib/models/account.d.ts +0 -27
  82. package/lib/models/account.js +0 -73
  83. package/lib/models/application-details.d.ts +0 -14
  84. package/lib/models/application-details.js +0 -47
  85. package/lib/models/attributes.d.ts +0 -151
  86. package/lib/models/attributes.js +0 -382
  87. package/lib/models/calendar-availability.d.ts +0 -76
  88. package/lib/models/calendar-availability.js +0 -121
  89. package/lib/models/calendar-restful-model-collection.d.ts +0 -17
  90. package/lib/models/calendar-restful-model-collection.js +0 -181
  91. package/lib/models/calendar.d.ts +0 -31
  92. package/lib/models/calendar.js +0 -93
  93. package/lib/models/component-restful-model-collection.d.ts +0 -9
  94. package/lib/models/component-restful-model-collection.js +0 -34
  95. package/lib/models/component.d.ts +0 -37
  96. package/lib/models/component.js +0 -91
  97. package/lib/models/connect.d.ts +0 -73
  98. package/lib/models/connect.js +0 -193
  99. package/lib/models/contact-restful-model-collection.d.ts +0 -9
  100. package/lib/models/contact-restful-model-collection.js +0 -60
  101. package/lib/models/contact.d.ts +0 -129
  102. package/lib/models/contact.js +0 -289
  103. package/lib/models/delta-collection.d.ts +0 -17
  104. package/lib/models/delta-collection.js +0 -139
  105. package/lib/models/delta-stream.d.ts +0 -32
  106. package/lib/models/delta-stream.js +0 -250
  107. package/lib/models/delta.d.ts +0 -28
  108. package/lib/models/delta.js +0 -88
  109. package/lib/models/deltas.d.ts +0 -17
  110. package/lib/models/deltas.js +0 -49
  111. package/lib/models/draft.d.ts +0 -27
  112. package/lib/models/draft.js +0 -156
  113. package/lib/models/email-participant.d.ts +0 -13
  114. package/lib/models/email-participant.js +0 -46
  115. package/lib/models/event-conferencing.d.ts +0 -34
  116. package/lib/models/event-conferencing.js +0 -71
  117. package/lib/models/event-notification.d.ts +0 -27
  118. package/lib/models/event-notification.js +0 -62
  119. package/lib/models/event-participant.d.ts +0 -19
  120. package/lib/models/event-participant.js +0 -56
  121. package/lib/models/event.d.ts +0 -96
  122. package/lib/models/event.js +0 -297
  123. package/lib/models/file.d.ts +0 -29
  124. package/lib/models/file.js +0 -136
  125. package/lib/models/folder.d.ts +0 -21
  126. package/lib/models/folder.js +0 -69
  127. package/lib/models/free-busy.d.ts +0 -58
  128. package/lib/models/free-busy.js +0 -132
  129. package/lib/models/job-status-restful-model-collection.d.ts +0 -9
  130. package/lib/models/job-status-restful-model-collection.js +0 -38
  131. package/lib/models/job-status.d.ts +0 -24
  132. package/lib/models/job-status.js +0 -68
  133. package/lib/models/management-account.d.ts +0 -63
  134. package/lib/models/management-account.js +0 -187
  135. package/lib/models/management-model-collection.d.ts +0 -10
  136. package/lib/models/management-model-collection.js +0 -39
  137. package/lib/models/management-model.d.ts +0 -6
  138. package/lib/models/management-model.js +0 -29
  139. package/lib/models/message-restful-model-collection.d.ts +0 -26
  140. package/lib/models/message-restful-model-collection.js +0 -80
  141. package/lib/models/message.d.ts +0 -57
  142. package/lib/models/message.js +0 -173
  143. package/lib/models/model-collection.d.ts +0 -25
  144. package/lib/models/model-collection.js +0 -201
  145. package/lib/models/model.d.ts +0 -12
  146. package/lib/models/model.js +0 -64
  147. package/lib/models/neural-categorizer.d.ts +0 -28
  148. package/lib/models/neural-categorizer.js +0 -139
  149. package/lib/models/neural-clean-conversation.d.ts +0 -16
  150. package/lib/models/neural-clean-conversation.js +0 -114
  151. package/lib/models/neural-ocr.d.ts +0 -14
  152. package/lib/models/neural-ocr.js +0 -50
  153. package/lib/models/neural-sentiment-analysis.d.ts +0 -20
  154. package/lib/models/neural-sentiment-analysis.js +0 -56
  155. package/lib/models/neural-signature-contact.d.ts +0 -43
  156. package/lib/models/neural-signature-contact.js +0 -142
  157. package/lib/models/neural-signature-extraction.d.ts +0 -17
  158. package/lib/models/neural-signature-extraction.js +0 -54
  159. package/lib/models/neural.d.ts +0 -36
  160. package/lib/models/neural.js +0 -163
  161. package/lib/models/nylas-api-error.d.ts +0 -26
  162. package/lib/models/nylas-api-error.js +0 -61
  163. package/lib/models/outbox-job-status.d.ts +0 -20
  164. package/lib/models/outbox-job-status.js +0 -64
  165. package/lib/models/outbox-message.d.ts +0 -16
  166. package/lib/models/outbox-message.js +0 -54
  167. package/lib/models/outbox.d.ts +0 -35
  168. package/lib/models/outbox.js +0 -158
  169. package/lib/models/resource.d.ts +0 -22
  170. package/lib/models/resource.js +0 -66
  171. package/lib/models/restful-model-collection.d.ts +0 -15
  172. package/lib/models/restful-model-collection.js +0 -169
  173. package/lib/models/restful-model-instance.d.ts +0 -9
  174. package/lib/models/restful-model-instance.js +0 -37
  175. package/lib/models/restful-model.d.ts +0 -36
  176. package/lib/models/restful-model.js +0 -146
  177. package/lib/models/scheduler-booking-request.d.ts +0 -64
  178. package/lib/models/scheduler-booking-request.js +0 -148
  179. package/lib/models/scheduler-restful-model-collection.d.ts +0 -26
  180. package/lib/models/scheduler-restful-model-collection.js +0 -133
  181. package/lib/models/scheduler-time-slot.d.ts +0 -20
  182. package/lib/models/scheduler-time-slot.js +0 -53
  183. package/lib/models/scheduler.d.ts +0 -226
  184. package/lib/models/scheduler.js +0 -446
  185. package/lib/models/thread.d.ts +0 -49
  186. package/lib/models/thread.js +0 -127
  187. package/lib/models/webhook-notification.d.ts +0 -108
  188. package/lib/models/webhook-notification.js +0 -239
  189. package/lib/models/webhook.d.ts +0 -50
  190. package/lib/models/webhook.js +0 -101
  191. package/lib/models/when.d.ts +0 -23
  192. package/lib/models/when.js +0 -65
  193. package/lib/nylas-connection.d.ts +0 -71
  194. package/lib/nylas-connection.js +0 -258
  195. package/lib/nylas.d.ts +0 -57
  196. package/lib/nylas.js +0 -210
  197. package/lib/server-bindings/express-binding.d.ts +0 -18
  198. package/lib/server-bindings/express-binding.js +0 -163
  199. package/lib/server-bindings/server-binding.d.ts +0 -65
  200. package/lib/server-bindings/server-binding.js +0 -87
  201. package/lib/services/routes.d.ts +0 -26
  202. package/lib/services/routes.js +0 -95
  203. package/lib/services/tunnel.d.ts +0 -29
  204. package/lib/services/tunnel.js +0 -112
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,15 @@
1
+ export var WebhookTriggers;
2
+ (function (WebhookTriggers) {
3
+ WebhookTriggers["CalendarCreated"] = "calendar.created";
4
+ WebhookTriggers["CalendarUpdated"] = "calendar.updated";
5
+ WebhookTriggers["CalendarDeleted"] = "calendar.deleted";
6
+ WebhookTriggers["EventCreated"] = "event.created";
7
+ WebhookTriggers["EventUpdated"] = "event.updated";
8
+ WebhookTriggers["EventDeleted"] = "event.deleted";
9
+ WebhookTriggers["GrantCreated"] = "grant.created";
10
+ WebhookTriggers["GrantUpdated"] = "grant.updated";
11
+ WebhookTriggers["GrantDeleted"] = "grant.deleted";
12
+ WebhookTriggers["GrantExpired"] = "grant.expired";
13
+ WebhookTriggers["MessageSendSuccess"] = "message.send_success";
14
+ WebhookTriggers["MessageSendFailed"] = "message.send_failed";
15
+ })(WebhookTriggers || (WebhookTriggers = {}));
@@ -0,0 +1,31 @@
1
+ import APIClient from './apiClient.js';
2
+ import { DEFAULT_SERVER_URL } from './config.js';
3
+ import { Calendars } from './resources/calendars.js';
4
+ import { Events } from './resources/events.js';
5
+ import { Auth } from './resources/auth.js';
6
+ import { Webhooks } from './resources/webhooks.js';
7
+ import { Applications } from './resources/applications.js';
8
+ /**
9
+ * The entry point to the Node SDK
10
+ *
11
+ * A Nylas instance holds a configured http client pointing to a base URL and is intended to be reused and shared
12
+ * across threads and time.
13
+ */
14
+ export default class Nylas {
15
+ /**
16
+ * @param config Configuration options for the Nylas SDK
17
+ */
18
+ constructor(config) {
19
+ this.apiClient = new APIClient({
20
+ apiKey: config.apiKey,
21
+ apiUri: config.apiUri || DEFAULT_SERVER_URL,
22
+ timeout: config.timeout || 30,
23
+ });
24
+ this.applications = new Applications(this.apiClient);
25
+ this.auth = new Auth(this.apiClient);
26
+ this.calendars = new Calendars(this.apiClient);
27
+ this.events = new Events(this.apiClient);
28
+ this.webhooks = new Webhooks(this.apiClient);
29
+ return this;
30
+ }
31
+ }
@@ -0,0 +1,3 @@
1
+ {
2
+ "type": "module"
3
+ }
@@ -0,0 +1,26 @@
1
+ import { Resource } from './resource.js';
2
+ import { RedirectUris } from './redirectUris.js';
3
+ /**
4
+ * Nylas Applications API
5
+ *
6
+ * This endpoint allows for getting application details as well as redirect URI operations.
7
+ */
8
+ export class Applications extends Resource {
9
+ /**
10
+ * @param apiClient client The configured Nylas API client
11
+ */
12
+ constructor(apiClient) {
13
+ super(apiClient);
14
+ this.redirectUris = new RedirectUris(apiClient);
15
+ }
16
+ /**
17
+ * Get application details
18
+ * @returns The application details
19
+ */
20
+ getDetails({ overrides } = {}) {
21
+ return super._find({
22
+ path: `/v3/applications`,
23
+ overrides,
24
+ });
25
+ }
26
+ }
@@ -0,0 +1,149 @@
1
+ import { v4 as uuid } from 'uuid';
2
+ import sha256 from 'sha256';
3
+ import { Resource } from './resource.js';
4
+ import { Grants } from './grants.js';
5
+ /**
6
+ * A collection of authentication related API endpoints
7
+ *
8
+ * These endpoints allow for various functionality related to authentication.
9
+ * Also contains the Grants API and collection of provider API endpoints.
10
+ */
11
+ 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
+ /**
21
+ * Build the URL for authenticating users to your application with OAuth 2.0
22
+ * @param config The configuration for building the URL
23
+ * @return The URL for hosted authentication
24
+ */
25
+ urlForOAuth2(config) {
26
+ return this.urlAuthBuilder(config).toString();
27
+ }
28
+ /**
29
+ * Exchange an authorization code for an access token
30
+ * @param request The request parameters for the code exchange
31
+ * @return Information about the Nylas application
32
+ */
33
+ exchangeCodeForToken(request) {
34
+ const body = {
35
+ ...request,
36
+ grantType: 'authorization_code',
37
+ };
38
+ if (request.codeVerifier) {
39
+ body.codeVerifier = request.codeVerifier;
40
+ }
41
+ return this.apiClient.request({
42
+ method: 'POST',
43
+ path: `/v3/connect/token`,
44
+ body,
45
+ });
46
+ }
47
+ /**
48
+ * Refresh an access token
49
+ * @param request The refresh token request
50
+ * @return The response containing the new access token
51
+ */
52
+ refreshAccessToken(request) {
53
+ return this.apiClient.request({
54
+ method: 'POST',
55
+ path: `/v3/connect/token`,
56
+ body: {
57
+ ...request,
58
+ grantType: 'refresh_token',
59
+ },
60
+ });
61
+ }
62
+ /**
63
+ * Build the URL for authenticating users to your application with OAuth 2.0 and PKCE
64
+ * IMPORTANT: YOU WILL NEED TO STORE THE 'secret' returned to use it inside the CodeExchange flow
65
+ * @param config The configuration for building the URL
66
+ * @return The URL for hosted authentication
67
+ */
68
+ urlForOAuth2PKCE(config) {
69
+ const url = this.urlAuthBuilder(config);
70
+ // Add code challenge to URL generation
71
+ url.searchParams.set('code_challenge_method', 's256');
72
+ const secret = uuid();
73
+ const secretHash = this.hashPKCESecret(secret);
74
+ url.searchParams.set('code_challenge', secret);
75
+ // Return the url with secret & hashed secret
76
+ return { secret, secretHash, url: url.toString() };
77
+ }
78
+ /**
79
+ * Build the URL for admin consent authentication for Microsoft
80
+ * @param config The configuration for building the URL
81
+ * @return The URL for admin consent authentication
82
+ */
83
+ urlForAdminConsent(config) {
84
+ const configWithProvider = { ...config, provider: 'microsoft' };
85
+ const url = this.urlAuthBuilder(configWithProvider);
86
+ url.searchParams.set('response_type', 'adminconsent');
87
+ url.searchParams.set('credential_id', config.credentialId);
88
+ return url.toString();
89
+ }
90
+ /**
91
+ * Revoke a token (and the grant attached to the token)
92
+ * @param token The token to revoke
93
+ * @return True if the token was revoked successfully
94
+ */
95
+ async revoke(token) {
96
+ await this.apiClient.request({
97
+ method: 'POST',
98
+ path: `/v3/connect/revoke`,
99
+ queryParams: {
100
+ token,
101
+ },
102
+ });
103
+ return true;
104
+ }
105
+ /**
106
+ * Detect provider from email address
107
+ * @param params The parameters to include in the request
108
+ * @return The detected provider, if found
109
+ */
110
+ async detectProvider(params) {
111
+ return this.apiClient.request({
112
+ method: 'POST',
113
+ path: `/v3/grants/providers/detect`,
114
+ queryParams: params,
115
+ });
116
+ }
117
+ urlAuthBuilder(config) {
118
+ const url = new URL(`${this.apiClient.serverUrl}/v3/connect/auth`);
119
+ url.searchParams.set('client_id', config.clientId);
120
+ url.searchParams.set('redirect_uri', config.redirectUri);
121
+ url.searchParams.set('access_type', config.accessType ? config.accessType : 'online');
122
+ url.searchParams.set('response_type', 'code');
123
+ if (config.provider) {
124
+ url.searchParams.set('provider', config.provider);
125
+ }
126
+ if (config.loginHint) {
127
+ url.searchParams.set('login_hint', config.loginHint);
128
+ if (config.includeGrantScopes) {
129
+ url.searchParams.set('include_grant_scopes', config.includeGrantScopes.toString());
130
+ }
131
+ }
132
+ if (config.scope) {
133
+ url.searchParams.set('scope', config.scope.join(' '));
134
+ }
135
+ if (config.prompt) {
136
+ url.searchParams.set('prompt', config.prompt);
137
+ }
138
+ if (config.metadata) {
139
+ url.searchParams.set('metadata', config.metadata);
140
+ }
141
+ if (config.state) {
142
+ url.searchParams.set('state', config.state);
143
+ }
144
+ return url;
145
+ }
146
+ hashPKCESecret(secret) {
147
+ return Buffer.from(sha256(secret)).toString('base64');
148
+ }
149
+ }
@@ -0,0 +1,74 @@
1
+ import { Resource } from './resource.js';
2
+ /**
3
+ * Nylas Calendar API
4
+ *
5
+ * The Nylas calendar API allows you to create new calendars or manage existing ones.
6
+ * A calendar can be accessed by one, or several people, and can contain events.
7
+ */
8
+ export class Calendars extends Resource {
9
+ /**
10
+ * Return all Calendars
11
+ * @return A list of calendars
12
+ */
13
+ list({ identifier, queryParams, overrides, }) {
14
+ return super._list({
15
+ queryParams,
16
+ overrides,
17
+ path: `/v3/grants/${identifier}/calendars`,
18
+ });
19
+ }
20
+ /**
21
+ * Return a Calendar
22
+ * @return The calendar
23
+ */
24
+ find({ identifier, calendarId, overrides, }) {
25
+ return super._find({
26
+ path: `/v3/grants/${identifier}/calendars/${calendarId}`,
27
+ overrides,
28
+ });
29
+ }
30
+ /**
31
+ * Create a Calendar
32
+ * @return The created calendar
33
+ */
34
+ create({ identifier, requestBody, overrides, }) {
35
+ return super._create({
36
+ path: `/v3/grants/${identifier}/calendars`,
37
+ requestBody,
38
+ overrides,
39
+ });
40
+ }
41
+ /**
42
+ * Update a Calendar
43
+ * @return The updated Calendar
44
+ */
45
+ update({ calendarId, identifier, requestBody, overrides, }) {
46
+ return super._update({
47
+ path: `/v3/grants/${identifier}/calendars/${calendarId}`,
48
+ requestBody,
49
+ overrides,
50
+ });
51
+ }
52
+ /**
53
+ * Delete a Calendar
54
+ * @return The deleted Calendar
55
+ */
56
+ destroy({ identifier, calendarId, overrides, }) {
57
+ return super._destroy({
58
+ path: `/v3/grants/${identifier}/calendars/${calendarId}`,
59
+ overrides,
60
+ });
61
+ }
62
+ /**
63
+ * Get Availability for a given account / accounts
64
+ * @return The availability response
65
+ */
66
+ getAvailability({ requestBody, overrides, }) {
67
+ return this.apiClient.request({
68
+ method: 'POST',
69
+ path: `/v3/calendars/availability`,
70
+ body: requestBody,
71
+ overrides,
72
+ });
73
+ }
74
+ }
@@ -0,0 +1,65 @@
1
+ import { Resource } from './resource.js';
2
+ /**
3
+ * Nylas Events API
4
+ *
5
+ * The Nylas Events API allows you to create, update, and delete events on user calendars.
6
+ */
7
+ export class Events extends Resource {
8
+ /**
9
+ * Return all Events
10
+ * @return The list of Events
11
+ */
12
+ list({ identifier, queryParams, overrides, }) {
13
+ return super._list({
14
+ queryParams,
15
+ path: `/v3/grants/${identifier}/events`,
16
+ overrides,
17
+ });
18
+ }
19
+ /**
20
+ * Return an Event
21
+ * @return The Event
22
+ */
23
+ find({ identifier, eventId, queryParams, overrides, }) {
24
+ return super._find({
25
+ path: `/v3/grants/${identifier}/events/${eventId}`,
26
+ queryParams,
27
+ overrides,
28
+ });
29
+ }
30
+ /**
31
+ * Create an Event
32
+ * @return The created Event
33
+ */
34
+ create({ identifier, requestBody, queryParams, overrides, }) {
35
+ return super._create({
36
+ path: `/v3/grants/${identifier}/events`,
37
+ queryParams,
38
+ requestBody,
39
+ overrides,
40
+ });
41
+ }
42
+ /**
43
+ * Update an Event
44
+ * @return The updated Event
45
+ */
46
+ update({ identifier, eventId, requestBody, queryParams, overrides, }) {
47
+ return super._update({
48
+ path: `/v3/grants/${identifier}/events/${eventId}`,
49
+ queryParams,
50
+ requestBody,
51
+ overrides,
52
+ });
53
+ }
54
+ /**
55
+ * Delete an Event
56
+ * @return The deletion response
57
+ */
58
+ destroy({ identifier, eventId, queryParams, overrides, }) {
59
+ return super._destroy({
60
+ path: `/v3/grants/${identifier}/events/${eventId}`,
61
+ queryParams,
62
+ overrides,
63
+ });
64
+ }
65
+ }
@@ -0,0 +1,61 @@
1
+ import { Resource } from './resource.js';
2
+ /**
3
+ * Nylas Grants API
4
+ *
5
+ * The Nylas Grants API allows for the management of grants.
6
+ */
7
+ export class Grants extends Resource {
8
+ /**
9
+ * Return all Grants
10
+ * @return The list of Grants
11
+ */
12
+ async list({ overrides } = {}, queryParams) {
13
+ return super._list({
14
+ queryParams,
15
+ path: `/v3/grants`,
16
+ overrides,
17
+ });
18
+ }
19
+ /**
20
+ * Return a Grant
21
+ * @return The Grant
22
+ */
23
+ find({ grantId, overrides, }) {
24
+ return super._find({
25
+ path: `/v3/grants/${grantId}`,
26
+ overrides,
27
+ });
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
+ /**
41
+ * Update a Grant
42
+ * @return The updated Grant
43
+ */
44
+ update({ grantId, requestBody, overrides, }) {
45
+ return super._updatePatch({
46
+ path: `/v3/grants/${grantId}`,
47
+ requestBody,
48
+ overrides,
49
+ });
50
+ }
51
+ /**
52
+ * Delete a Grant
53
+ * @return The deletion response
54
+ */
55
+ destroy({ grantId, overrides, }) {
56
+ return super._destroy({
57
+ path: `/v3/grants/${grantId}`,
58
+ overrides,
59
+ });
60
+ }
61
+ }
@@ -0,0 +1,60 @@
1
+ import { Resource } from './resource.js';
2
+ /**
3
+ * A collection of redirect URI related API endpoints.
4
+ *
5
+ * These endpoints allows for the management of redirect URIs.
6
+ */
7
+ export class RedirectUris extends Resource {
8
+ /**
9
+ * Return all Redirect URIs
10
+ * @return The list of Redirect URIs
11
+ */
12
+ list({ overrides } = {}) {
13
+ return super._list({
14
+ overrides,
15
+ path: '/v3/applications/redirect-uris',
16
+ });
17
+ }
18
+ /**
19
+ * Return a Redirect URI
20
+ * @return The Redirect URI
21
+ */
22
+ find({ redirectUriId, overrides, }) {
23
+ return super._find({
24
+ overrides,
25
+ path: `/v3/applications/redirect-uris/${redirectUriId}`,
26
+ });
27
+ }
28
+ /**
29
+ * Create a Redirect URI
30
+ * @return The created Redirect URI
31
+ */
32
+ create({ requestBody, overrides, }) {
33
+ return super._create({
34
+ overrides,
35
+ path: '/v3/applications/redirect-uris',
36
+ requestBody,
37
+ });
38
+ }
39
+ /**
40
+ * Update a Redirect URI
41
+ * @return The updated Redirect URI
42
+ */
43
+ update({ redirectUriId, requestBody, overrides, }) {
44
+ return super._update({
45
+ overrides,
46
+ path: `/v3/applications/redirect-uris/${redirectUriId}`,
47
+ requestBody,
48
+ });
49
+ }
50
+ /**
51
+ * Delete a Redirect URI
52
+ * @return The deleted Redirect URI
53
+ */
54
+ destroy({ redirectUriId, overrides, }) {
55
+ return super._destroy({
56
+ overrides,
57
+ path: `/v1/redirect_uris/${redirectUriId}`,
58
+ });
59
+ }
60
+ }
@@ -0,0 +1,107 @@
1
+ /**
2
+ * Base class for Nylas API resources
3
+ *
4
+ * @ignore No public constructor or functions
5
+ */
6
+ export class Resource {
7
+ /**
8
+ * @param apiClient client The configured Nylas API client
9
+ */
10
+ constructor(apiClient) {
11
+ this.apiClient = apiClient;
12
+ }
13
+ async fetchList({ queryParams, path, overrides, }) {
14
+ const res = await this.apiClient.request({
15
+ method: 'GET',
16
+ path,
17
+ queryParams,
18
+ overrides,
19
+ });
20
+ if (queryParams?.limit) {
21
+ let entriesRemaining = queryParams.limit;
22
+ while (res.data.length != queryParams.limit) {
23
+ entriesRemaining = queryParams.limit - res.data.length;
24
+ if (!res.nextCursor) {
25
+ break;
26
+ }
27
+ const nextRes = await this.apiClient.request({
28
+ method: 'GET',
29
+ path,
30
+ queryParams: {
31
+ ...queryParams,
32
+ limit: entriesRemaining,
33
+ pageToken: res.nextCursor,
34
+ },
35
+ overrides,
36
+ });
37
+ res.data = res.data.concat(nextRes.data);
38
+ res.requestId = nextRes.requestId;
39
+ res.nextCursor = nextRes.nextCursor;
40
+ }
41
+ }
42
+ return res;
43
+ }
44
+ async *listIterator(listParams) {
45
+ const first = await this.fetchList(listParams);
46
+ yield first;
47
+ let pageToken = first.nextCursor;
48
+ while (pageToken) {
49
+ const res = await this.fetchList({
50
+ ...listParams,
51
+ queryParams: pageToken
52
+ ? {
53
+ ...listParams.queryParams,
54
+ pageToken,
55
+ }
56
+ : listParams.queryParams,
57
+ });
58
+ yield res;
59
+ pageToken = res.nextCursor;
60
+ }
61
+ return undefined;
62
+ }
63
+ _list(listParams) {
64
+ const iterator = this.listIterator(listParams);
65
+ const first = iterator.next().then(res => ({
66
+ ...res.value,
67
+ next: iterator.next.bind(iterator),
68
+ }));
69
+ return Object.assign(first, {
70
+ [Symbol.asyncIterator]: this.listIterator.bind(this, listParams),
71
+ });
72
+ }
73
+ _find({ path, queryParams, overrides, }) {
74
+ return this.apiClient.request({
75
+ method: 'GET',
76
+ path,
77
+ queryParams,
78
+ overrides,
79
+ });
80
+ }
81
+ payloadRequest(method, { path, queryParams, requestBody, overrides }) {
82
+ return this.apiClient.request({
83
+ method,
84
+ path,
85
+ queryParams,
86
+ body: requestBody,
87
+ overrides,
88
+ });
89
+ }
90
+ _create(params) {
91
+ return this.payloadRequest('POST', params);
92
+ }
93
+ _update(params) {
94
+ return this.payloadRequest('PUT', params);
95
+ }
96
+ _updatePatch(params) {
97
+ return this.payloadRequest('PATCH', params);
98
+ }
99
+ _destroy({ path, queryParams, overrides, }) {
100
+ return this.apiClient.request({
101
+ method: 'DELETE',
102
+ path,
103
+ queryParams,
104
+ overrides,
105
+ });
106
+ }
107
+ }
@@ -0,0 +1,94 @@
1
+ import { Resource } from './resource.js';
2
+ /**
3
+ * Nylas Webhooks API
4
+ *
5
+ * The Nylas Webhooks API allows your application to receive notifications in real-time when certain events occur.
6
+ */
7
+ export class Webhooks extends Resource {
8
+ /**
9
+ * List all webhook destinations for the application
10
+ * @returns The list of webhook destinations
11
+ */
12
+ list({ overrides } = {}) {
13
+ return super._list({
14
+ overrides,
15
+ path: `/v3/webhooks`,
16
+ });
17
+ }
18
+ /**
19
+ * Return a webhook destination
20
+ * @return The webhook destination
21
+ */
22
+ find({ webhookId, overrides, }) {
23
+ return super._find({
24
+ path: `/v3/webhooks/${webhookId}`,
25
+ overrides,
26
+ });
27
+ }
28
+ /**
29
+ * Create a webhook destination
30
+ * @returns The created webhook destination
31
+ */
32
+ create({ requestBody, overrides, }) {
33
+ return super._create({
34
+ path: `/v3/webhooks`,
35
+ requestBody,
36
+ overrides,
37
+ });
38
+ }
39
+ /**
40
+ * Update a webhook destination
41
+ * @returns The updated webhook destination
42
+ */
43
+ update({ webhookId, requestBody, overrides, }) {
44
+ return super._update({
45
+ path: `/v3/webhooks/${webhookId}`,
46
+ requestBody,
47
+ overrides,
48
+ });
49
+ }
50
+ /**
51
+ * Delete a webhook destination
52
+ * @returns The deletion response
53
+ */
54
+ destroy({ webhookId, overrides, }) {
55
+ return super._destroy({
56
+ path: `/v3/webhooks/${webhookId}`,
57
+ overrides,
58
+ });
59
+ }
60
+ /**
61
+ * Update the webhook secret value for a destination
62
+ * @returns The updated webhook destination with the webhook secret
63
+ */
64
+ rotateSecret({ webhookId, overrides, }) {
65
+ return super._update({
66
+ path: `/v3/webhooks/${webhookId}/rotate-secret`,
67
+ requestBody: {},
68
+ overrides,
69
+ });
70
+ }
71
+ /**
72
+ * Get the current list of IP addresses that Nylas sends webhooks from
73
+ * @returns The list of IP addresses that Nylas sends webhooks from
74
+ */
75
+ ipAddresses({ overrides } = {}) {
76
+ return super._find({
77
+ path: `/v3/webhooks/ip-addresses`,
78
+ overrides,
79
+ });
80
+ }
81
+ /**
82
+ * Extract the challenge parameter from a URL
83
+ * @param url The URL sent by Nylas containing the challenge parameter
84
+ * @returns The challenge parameter
85
+ */
86
+ extractChallengeParameter(url) {
87
+ const urlObject = new URL(url);
88
+ const challengeParameter = urlObject.searchParams.get('challenge');
89
+ if (!challengeParameter) {
90
+ throw new Error('Invalid URL or no challenge parameter found.');
91
+ }
92
+ return challengeParameter;
93
+ }
94
+ }