The NylasConnect
class is the core of the Nylas Connect library. It provides methods for OAuth authentication, token management, and grant creation and management.
import { NylasConnect } from "@nylas/connect";
const nylasConnect = new NylasConnect({ clientId: process.env.NYLAS_CLIENT_ID!, redirectUri: process.env.NYLAS_REDIRECT_URI!, apiUrl: process.env.NYLAS_API_URL || "https://api.us.nylas.com", environment: "production", persistTokens: true, debug: false, logLevel: "error",});
// Set up authentication state monitoringnylasConnect.onConnectStateChange((state) => { console.log("Auth state changed:", state);
switch (state.type) { case "connected": // Handle successful connection break; case "disconnected": // Handle disconnection break; case "error": // Handle authentication errors console.error("Auth error:", state.error); break; }});
ConnectConfig
Section titled “ConnectConfig”The NylasConnect
constructor accepts a ConnectConfig
object with the following options.
Property
Toggle details
Methods
Section titled “Methods”The NylasConnect
class includes the following methods. Click on any method name to view its detailed documentation.
Authentication methods
Section titled “Authentication methods”Method
Toggle details
Callback methods
Section titled “Callback methods”Grant management methods
Section titled “Grant management methods”Method
Toggle details
Utility methods
Section titled “Utility methods”Property types
Section titled “Property types”ConnectError
Section titled “ConnectError”ConnectError
extends the standard Error
interface and adds fields for better error handling.
Property | Type | Description |
---|---|---|
code | string | An error code for programmatic error handling. |
description | string? | A human-readable description of the error. |
docsUrl | string? | A link to relevant documentation. |
fix | string? | A suggested solution for resolving the error. |
originalError | Error? | The original error, if the ConnectError wraps another error. |
Environment
Section titled “Environment”Name | Environment |
Description | Your project’s deployment environment. |
Enum | development | staging | production |
ProviderScopes
Section titled “ProviderScopes”Default scope settings for different providers.
type ProviderScopes = { google?: GoogleScope[]; microsoft?: MicrosoftScope[]; yahoo?: YahooScope[]; imap?: never; // IMAP doesn't support scopes icloud?: string[]; // iCloud uses custom scopes};
const nylasConnect = new NylasConnect({ clientId: "<NYLAS_CLIENT_ID>", redirectUri: "https://yourapp.com/callback", defaultScopes: { google: ["https://www.googleapis.com/auth/gmail.readonly"], microsoft: ["https://graph.microsoft.com/Mail.Read"], },});