@nylas/react 3.2.15 โ†’ 3.2.17

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/README.md CHANGED
@@ -1,46 +1,94 @@
1
- # Nylas React Components
1
+ <div align="center">
2
+ <a href="https://www.nylas.com/">
3
+ <img width="100%" alt="Nylas" src="https://github.com/user-attachments/assets/137517ae-244d-47a5-8ca7-b12984971fc4" />
4
+ </a>
2
5
 
3
- React components for Nylas Scheduler
6
+ <h1>Nylas React Components</h1>
4
7
 
5
- ![npm](https://img.shields.io/npm/v/@nylas/react)
8
+ <p>
9
+ <strong>Scheduler components and OAuth connection hooks for React</strong>
10
+ </p>
6
11
 
7
- ## Requirements
12
+ <p>
13
+ <a href="https://www.npmjs.com/package/@nylas/react"><img src="https://img.shields.io/npm/v/@nylas/react" alt="npm version" /></a>
14
+ <a href="https://www.npmjs.com/package/@nylas/react"><img src="https://img.shields.io/npm/dm/@nylas/react" alt="downloads" /></a>
15
+ <a href="https://www.typescriptlang.org/"><img src="https://img.shields.io/badge/TypeScript-Ready-blue.svg" alt="TypeScript" /></a>
16
+ <a href="LICENSE.md"><img src="https://img.shields.io/badge/license-MIT-blue.svg" alt="license" /></a>
17
+ </p>
8
18
 
9
- - [Node.js](https://nodejs.org/en/) v20 or higher
10
- - [React.js](https://react.dev/) v18 or higher
19
+ <p>
20
+ <a href="https://developer.nylas.com/docs/v3/scheduler/">๐Ÿ“– Scheduler guide</a> ยท
21
+ <a href="https://developer.nylas.com/docs/api/v3/scheduler/">๐Ÿ“š API Reference</a> ยท
22
+ <a href="https://dashboard-v3.nylas.com/register">๐Ÿš€ Sign up</a> ยท
23
+ <a href="https://github.com/orgs/nylas-samples/repositories">๐Ÿ’ก Samples</a> ยท
24
+ <a href="https://forums.nylas.com">๐Ÿ’ฌ Forum</a>
25
+ </p>
26
+ </div>
27
+
28
+ <br />
29
+
30
+ `@nylas/react` gives you Nylas Scheduler as React components, so you can drop a booking page or a full scheduling-page editor into your app instead of building availability logic, timezone handling, and booking forms yourself. It also ships a `useNylasConnect` hook and a `NylasConnectButton` for the OAuth flow that connects a user's calendar.
31
+
32
+ This repository is for contributors and anyone installing from source. If you just want to use the library in your app, head to the [**Scheduler guide**](https://developer.nylas.com/docs/v3/scheduler/) on developer.nylas.com.
11
33
 
12
- ## Installation
34
+ ## Get started
13
35
 
14
- Install Nylas React Components via npm:
36
+ 1. [Sign up for a free Nylas account](https://dashboard-v3.nylas.com/register) and grab your client ID from the [Nylas Dashboard](https://dashboard-v3.nylas.com/).
37
+ 2. Register your app's callback URI under **Hosted Authentication**, so the connection flow is allowed to run.
38
+ 3. Install the package and render your first component โ€” see below.
39
+
40
+ The [Scheduler quickstart](https://developer.nylas.com/docs/v3/getting-started/scheduler/) walks through a working setup end to end, with the finished code in [quickstart-scheduler-react](https://github.com/nylas-samples/quickstart-scheduler-react).
41
+
42
+ ## โš™๏ธ Install
15
43
 
16
44
  ```bash
17
45
  npm install @nylas/react@latest
46
+ # or
47
+ yarn add @nylas/react@latest
18
48
  ```
19
49
 
20
- or yarn
50
+ ### Requirements
51
+
52
+ - [Node.js](https://nodejs.org/en/) v20 or higher
53
+ - [React](https://react.dev/) 18 or 19
54
+
55
+ The package ships its own TypeScript types, and exposes three subpaths so you only bundle what you use:
56
+
57
+ | Import from | Contains |
58
+ | --- | --- |
59
+ | `@nylas/react` | Everything below except the Connect symbols |
60
+ | `@nylas/react/elements` | Scheduler and booking components |
61
+ | `@nylas/react/utils` | `NylasIdentityRequestWrapper`, and the `LANGUAGE_CODE` type |
62
+ | `@nylas/react/connect` | `useNylasConnect`, `NylasConnectButton`, and re-exports of `@nylas/connect` |
63
+
64
+ > **Note:** `useNylasConnect` and `NylasConnectButton` are available **only** from `@nylas/react/connect`, not from the package root.
65
+
66
+ To install from source:
21
67
 
22
68
  ```bash
23
- yarn add @nylas/react@latest
69
+ git clone https://github.com/nylas/javascript.git
70
+ cd javascript
71
+ pnpm install
24
72
  ```
25
73
 
26
- ## Exports overview
74
+ ## โšก๏ธ Usage
75
+
76
+ ### Scheduler components
27
77
 
28
- - **Elements**
29
- - `NylasSchedulerEditor`, `NylasScheduling`, `NylasSchedulingMethod`
30
- - Import from `@nylas/react` or `@nylas/react/elements`
78
+ Three components are the entry points:
31
79
 
32
- - **Connect**
33
- - `useNylasConnect`, `NylasConnectButton`
34
- - Import from `@nylas/react` or `@nylas/react/connect`
80
+ - **`NylasScheduling`** โ€” the booking page your end users see.
81
+ - **`NylasSchedulerEditor`** โ€” the editor where your users build and configure scheduling pages.
82
+ - **`NylasSchedulingMethod`** โ€” picks a scheduling method.
35
83
 
36
- ## Getting Started
84
+ Around 50 further components (`NylasAvailabilityPicker`, `NylasBookingForm`, `NylasBufferTime`, `NylasCancellationPolicy`, `NylasTimeslotPicker`, and so on) are exported as the building blocks those two compose, alongside `NylasNotetakerConfig` and a set of form primitives and icons. Most apps only need the entry points.
85
+
86
+ ### Scheduler Editor
37
87
 
38
88
  The following example adds the Nylas Scheduler Editor and Scheduling components to your React app.
39
89
 
40
90
  > โš ๏ธ **Important:** Make sure to replace the `NYLAS_CLIENT_ID` with your Nylas Client ID. Your Nylas Client ID can be found in your app's Overview page on the [Nylas Dashboard](https://dashboard-v3.nylas.com).
41
91
 
42
- ### Adding the Components
43
-
44
92
  ```jsx
45
93
  import { BrowserRouter, Route, Routes } from "react-router-dom";
46
94
  import { NylasSchedulerEditor, NylasScheduling } from "@nylas/react";
@@ -101,11 +149,11 @@ function App() {
101
149
  export default App;
102
150
  ```
103
151
 
104
- ### Start a local development server
152
+ ### Local development server
105
153
 
106
154
  To create a Scheduling Page from the Scheduler Editor, you'll need a working Scheduler UI. To do this, run a local server to host your Scheduler Editor and Scheduling Pages.
107
155
 
108
- Navigate the root directory of your project and run the following command.
156
+ Navigate to the root directory of your project and run the following command.
109
157
 
110
158
  ```text
111
159
  npm run dev -- --port <PORT>
@@ -113,20 +161,17 @@ npm run dev -- --port <PORT>
113
161
 
114
162
  After you run the command, open your browser to `http://localhost:<PORT>/scheduler-editor` to see your Scheduler Editor and create your first Scheduling Page.
115
163
 
116
-
117
- ## Nylas Connect Hook
164
+ ### useNylasConnect hook
118
165
 
119
166
  The `useNylasConnect` hook provides a simple way to add OAuth authentication to your React app using Nylas Connect.
120
167
 
121
- ### Basic Usage
122
-
123
168
  ```jsx
124
- import { useNylasConnect } from '@nylas/react';
169
+ import { useNylasConnect } from "@nylas/react/connect";
125
170
 
126
171
  function LoginButton() {
127
172
  const { isConnected, connect, logout, grant, isLoading } = useNylasConnect({
128
- clientId: 'your-nylas-client-id',
129
- redirectUri: 'http://localhost:3000/callback'
173
+ clientId: "your-nylas-client-id",
174
+ redirectUri: "http://localhost:3000/callback",
130
175
  });
131
176
 
132
177
  if (isLoading) return <div>Loading...</div>;
@@ -141,42 +186,45 @@ function LoginButton() {
141
186
  }
142
187
 
143
188
  return (
144
- <button onClick={() => connect({ method: 'popup' })}>
145
- Connect Account
146
- </button>
189
+ <button onClick={() => connect({ method: "popup" })}>Connect Account</button>
147
190
  );
148
191
  }
149
192
  ```
150
193
 
194
+ #### Configuration
151
195
 
152
- ### Configuration
196
+ `UseNylasConnectConfig` extends `ConnectConfig` from [`@nylas/connect`](https://github.com/nylas/javascript/tree/main/packages/nylas-connect), so every option there โ€” `apiUrl`, `defaultScopes`, `persistTokens`, `logLevel`, `codeExchange`, `identityProviderToken`, and the rest โ€” is accepted here too. The most common, plus the four the hook adds of its own:
153
197
 
154
198
  | Option | Type | Default | Description |
155
- |--------|------|---------|-------------|
156
- | `clientId` | `string` | - | Your Nylas Client ID |
157
- | `redirectUri` | `string` | - | OAuth callback URL |
158
- | `autoHandleCallback` | `boolean` | `true` | Automatically handle OAuth callback |
159
- | `autoRefreshInterval` | `number` | - | Auto-refresh session interval (ms) |
160
- | `retryAttempts` | `number` | `0` | Number of retry attempts for failed operations |
161
- | `enableAutoRecovery` | `boolean` | `false` | Enable automatic error recovery |
199
+ | --- | --- | --- | --- |
200
+ | `clientId` | `string` | `NYLAS_CLIENT_ID` | Your Nylas Client ID |
201
+ | `redirectUri` | `string` | `NYLAS_REDIRECT_URI` | OAuth callback URL |
202
+ | `autoHandleCallback` | `boolean` | `true` | Automatically handle the OAuth callback |
203
+ | `autoRefreshInterval` | `number` | disabled | Auto-refresh session interval, in ms |
204
+ | `initialLoadingState` | `boolean` | `true` | Loading state the hook mounts with |
205
+ | `retryAttempts` | `number` | `0` | Retry attempts for failed operations |
206
+ | `enableAutoRecovery` | `boolean` | `false` | Automatic recovery from network errors |
162
207
 
163
- ### Hook Return Values
164
-
165
- The hook returns an object with the following properties:
208
+ #### Return values
166
209
 
167
210
  **State:**
168
- - `isConnected` - Whether user is authenticated
169
- - `grant` - Current user's grant information
170
- - `isLoading` - Loading state for operations
171
- - `error` - Current error, if any
211
+
212
+ - `isConnected` โ€” whether the user is authenticated
213
+ - `grant` โ€” the current user's `GrantInfo`, or `null`
214
+ - `isLoading` โ€” loading state for operations
215
+ - `error` โ€” current error, if any
172
216
 
173
217
  **Actions:**
174
- - `connect(options)` - Start OAuth flow
175
- - `logout(grantId?)` - Sign out user
176
- - `refreshSession()` - Refresh current session
177
- - `subscribe(callback)` - Listen to connection events
178
218
 
179
- ### Environment Setup
219
+ - `connect(options)` โ€” start the OAuth flow
220
+ - `logout(grantId?)` โ€” sign the user out
221
+ - `refreshSession()` โ€” refresh the current session
222
+ - `subscribe(callback)` โ€” listen to connection events
223
+ - `setLogLevel(level)` โ€” change log verbosity at runtime
224
+
225
+ The underlying client is also returned as `connectClient`, for anything the hook doesn't wrap.
226
+
227
+ #### Environment setup
180
228
 
181
229
  For security, use environment variables for your configuration:
182
230
 
@@ -189,22 +237,18 @@ VITE_NYLAS_REDIRECT_URI=http://localhost:3000/callback
189
237
  ```jsx
190
238
  const { isConnected, connect } = useNylasConnect({
191
239
  clientId: import.meta.env.VITE_NYLAS_CLIENT_ID,
192
- redirectUri: import.meta.env.VITE_NYLAS_REDIRECT_URI
240
+ redirectUri: import.meta.env.VITE_NYLAS_REDIRECT_URI,
193
241
  });
194
242
  ```
195
243
 
244
+ Next.js uses `NEXT_PUBLIC_` instead of `VITE_`.
196
245
 
197
-
198
-
199
-
200
- ## Nylas Connect Button
246
+ ### NylasConnectButton
201
247
 
202
248
  The `NylasConnectButton` component provides a simple way to add email provider authentication to your React application.
203
249
 
204
- ### Basic Usage
205
-
206
250
  ```jsx
207
- import { NylasConnectButton } from "@nylas/react";
251
+ import { NylasConnectButton } from "@nylas/react/connect";
208
252
 
209
253
  function App() {
210
254
  return (
@@ -222,12 +266,23 @@ function App() {
222
266
  }
223
267
  ```
224
268
 
225
- ### External Identity Provider Integration
269
+ Beyond `clientId` and `redirectUri`, the props fall into four groups:
270
+
271
+ | Group | Props |
272
+ | --- | --- |
273
+ | Connection | `apiUrl`, `defaultScopes`, `persistTokens`, `method`, `provider`, `scopes`, `loginHint`, `popupWidth`, `popupHeight` |
274
+ | Appearance | `text`, `children`, `variant` (`primary` \| `outline`), `size` (`sm` \| `md` \| `lg`), `className`, `style`, `disabled`, `unstyled`, `cssVars` |
275
+ | Callbacks | `onStart`, `onSuccess`, `onError`, `onCancel` |
276
+ | Advanced | `identityProviderToken`, `codeExchange` |
277
+
278
+ `unstyled` drops the default styling entirely; `cssVars` re-themes it without doing so, accepting `--nylas-btn-bg`, `--nylas-btn-fg`, `--nylas-btn-border`, and `--nylas-btn-bg-hover`.
279
+
280
+ ### External identity providers
226
281
 
227
282
  For applications that use external identity providers (via JWKS), you can pass identity provider tokens during authentication:
228
283
 
229
284
  ```jsx
230
- import { NylasConnectButton } from "@nylas/react";
285
+ import { NylasConnectButton } from "@nylas/react/connect";
231
286
 
232
287
  function App() {
233
288
  // Function to retrieve JWT token from your external identity provider
@@ -253,12 +308,14 @@ function App() {
253
308
  }
254
309
  ```
255
310
 
256
- ### Custom Backend Code Exchange
311
+ Returning `null` continues without IDP claims; throwing fails authentication. Per-provider setup guides for Auth0, Clerk, Google, and WorkOS: [external identity providers](https://developer.nylas.com/docs/v3/auth/nylas-connect-react/use-external-idp/).
312
+
313
+ ### Custom code exchange
257
314
 
258
315
  For enhanced security, you can handle the OAuth code exchange on your backend:
259
316
 
260
317
  ```jsx
261
- import { NylasConnectButton } from "@nylas/react";
318
+ import { NylasConnectButton } from "@nylas/react/connect";
262
319
 
263
320
  function App() {
264
321
  const handleCodeExchange = async (params) => {
@@ -309,12 +366,64 @@ function App() {
309
366
  }
310
367
  ```
311
368
 
312
- ## Links
369
+ ### Error handling
370
+
371
+ The hook surfaces failures on `error` rather than throwing, so render from it directly. `NylasConnectButton` reports them through `onError`, and `onCancel` fires separately when the user closes the popup.
372
+
373
+ ```jsx
374
+ const { error, connect } = useNylasConnect({ clientId, redirectUri });
375
+
376
+ if (error) return <p role="alert">Couldn't connect: {error.message}</p>;
377
+ ```
378
+
379
+ Every error extends `NylasConnectError` and sets a distinct `name` โ€” `PopupError` for a blocked or closed popup, `ConfigError` for a missing `clientId`, `OAuthError` when the provider rejects the request. All of them are re-exported from `@nylas/react/connect`.
380
+
381
+ ## ๐Ÿ’ก Examples
382
+
383
+ - [quickstart-scheduler-react](https://github.com/nylas-samples/quickstart-scheduler-react) โ€” the finished code for the Scheduler quickstart.
384
+ - [nylas-samples](https://github.com/orgs/nylas-samples/repositories) โ€” full sample apps and product quickstarts.
385
+
386
+ ## ๐Ÿค– AI agents
387
+
388
+ [nylas/skills](https://github.com/nylas/skills) drops Nylas into Claude Code, Cursor, Codex, and other agents that support the skills format:
389
+
390
+ ```bash
391
+ npx skills add nylas/skills
392
+ /plugin marketplace add nylas/skills # Claude Code
393
+ ```
394
+
395
+ ## ๐Ÿ“š Reference
396
+
397
+ - **Scheduler guide:** [developer.nylas.com/docs/v3/scheduler](https://developer.nylas.com/docs/v3/scheduler/)
398
+ - **Scheduler quickstart:** [developer.nylas.com/docs/v3/getting-started/scheduler](https://developer.nylas.com/docs/v3/getting-started/scheduler/)
399
+ - **Scheduler API reference:** [developer.nylas.com/docs/api/v3/scheduler](https://developer.nylas.com/docs/api/v3/scheduler/)
400
+ - **React connect guide:** [developer.nylas.com/docs/v3/auth/nylas-connect-react](https://developer.nylas.com/docs/v3/auth/nylas-connect-react/)
401
+ - **`useNylasConnect` reference:** [every option and return value](https://developer.nylas.com/docs/v3/auth/nylas-connect-react/usenylasconnect/)
402
+ - **`NylasConnectButton` reference:** [every prop](https://developer.nylas.com/docs/v3/auth/nylas-connect-react/nylasconnectbutton/)
403
+ - **Identity provider guides:** [Auth0, Clerk, Google, WorkOS](https://developer.nylas.com/docs/v3/auth/nylas-connect-react/use-external-idp/)
404
+ - **Developer forum:** [forums.nylas.com](https://forums.nylas.com/)
405
+ - **Changelog:** [CHANGELOG.md](CHANGELOG.md)
406
+
407
+ ## โœจ Upgrading
408
+
409
+ See [`CHANGELOG.md`](CHANGELOG.md) for per-release notes.
410
+
411
+ ## ๐Ÿ’™ Contributing
412
+
413
+ Issues, ideas, and pull requests welcome โ€” see [CONTRIBUTING.md](../../CONTRIBUTING.md). Before opening a large change, please open an issue or post in the [forum](https://forums.nylas.com) so we can sanity-check the direction.
414
+
415
+ ## ๐Ÿ”’ Security
416
+
417
+ Found a vulnerability? Please **don't** open a public issue. Report it through our [Vulnerability Disclosure Policy](https://www.nylas.com/security/vulnerability-disclosure-policy/).
418
+
419
+ ## ๐Ÿ”— Other Nylas SDKs
313
420
 
314
- A complete walkthrough for setting up Scheduler can be found at [https://developer.nylas.com/docs/v3/getting-started/scheduler/](https://developer.nylas.com/docs/v3/getting-started/scheduler/), with the complete code available on [GitHub](https://github.com/nylas-samples/quickstart-scheduler-react).
421
+ - [@nylas/connect](https://github.com/nylas/javascript/tree/main/packages/nylas-connect) ยท `npm install @nylas/connect`
422
+ - [nylas-nodejs](https://github.com/nylas/nylas-nodejs) ยท `npm install nylas`
423
+ - [nylas-python](https://github.com/nylas/nylas-python) ยท `pip install nylas`
424
+ - [nylas-ruby](https://github.com/nylas/nylas-ruby) ยท `gem install nylas`
425
+ - [nylas-java](https://github.com/nylas/nylas-java) ยท Maven / Gradle (Kotlin too)
315
426
 
316
- ### Further reading:
427
+ ## ๐Ÿ“ License
317
428
 
318
- - [Scheduler documentation](https://developer.nylas.com/docs/v3/scheduler/)
319
- - [Scheduler API reference](https://developer.nylas.com/docs/api/v3/scheduler/)
320
- - [Developer Forums](https://forums.nylas.com/)
429
+ MIT โ€” see [LICENSE.md](LICENSE.md).