Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for custom authentication, connectors, and credentials APIs #497

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

### 7.0.0-beta.3 / TBD
* Added support for the free-busy endpoint
* Added support for native/custom authentication
* Added support for Connectors & Credentials APIs
* Fix `getAvailability` response type
* Fix path for destroying a redirect URI
* Fix model for updating an Event
Expand Down
2 changes: 1 addition & 1 deletion src/models/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ type AccessType = 'online' | 'offline';
/**
* Type for the different OAuth providers Nylas supports.
*/
export type Provider = 'google' | 'imap' | 'microsoft';
export type Provider = 'google' | 'imap' | 'microsoft' | 'virtual-calendar';

/**
* Configuration for generating a URL for OAuth 2.0 authentication.
Expand Down
143 changes: 143 additions & 0 deletions src/models/connectors.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
import { Provider } from './auth.js';
import { ListQueryParams } from './listQueryParams.js';

/**
* Interface representing the Nylas connector response.
*/
export interface Connector {
/**
* Custom name of the connector
*/
name: string;
/**
* The provider type
*/
provider: Provider;
/**
* Optional settings from provider
*/
settings?: Record<string, unknown>;
/**
* Default scopes for the connector
*/
scope?: string[];
}

/**
* Interface representing a Google connector creation request.
*/
export interface GoogleCreateConnectorSettings {
/**
* The Google Client ID
*/
clientId: string;
/**
* The Google Client Secret
*/
clientSecret: string;
/**
* The Google Pub/Sub topic name
*/
topicName?: string;
}

/**
* Interface representing a Microsoft connector creation request.
*/
export interface MicrosoftCreateConnectorSettings {
/**
* The Microsoft Client ID
*/
clientId: string;
/**
* The Microsoft Client Secret
*/
clientSecret: string;
/**
* The Microsoft tenant ID
*/
tenant?: string;
}

/**
* Interface representing the base Nylas connector creation request.
*/
interface BaseCreateConnectionRequest {
/**
* Custom name of the connector
*/
name: string;
/**
* The provider type
*/
provider: Provider;
}

/**
* Interface representing the base Nylas connector creation request.
*/
export interface GoogleCreateConnectorRequest
extends BaseCreateConnectionRequest {
/**
* The Google OAuth provider credentials and settings
*/
settings: GoogleCreateConnectorSettings;
/**
* The Google OAuth scopes
*/
scope?: string[];
}

export interface MicrosoftCreateConnectorRequest
extends BaseCreateConnectionRequest {
/**
* The Microsoft OAuth provider credentials and settings
*/
settings: MicrosoftCreateConnectorSettings;
/**
* The Microsoft OAuth scopes
*/
scope?: string[];
}

/**
* Interface representing the base Nylas connector creation request.
*/
export type ImapCreateConnectorRequest = BaseCreateConnectionRequest;

/**
* Interface representing the base Nylas connector creation request.
*/
export type VirtualCalendarsCreateConnectorRequest = BaseCreateConnectionRequest;

/**
* The type of the Nylas connector creation request.
*/
export type CreateConnectorRequest =
| GoogleCreateConnectorRequest
| MicrosoftCreateConnectorRequest
| ImapCreateConnectorRequest
| VirtualCalendarsCreateConnectorRequest;

/**
* Interface representing the base Nylas connector creation request.
*/
export interface UpdateConnectorRequest {
/**
* Custom name of the connector
*/
name?: string;
/**
* The OAuth provider credentials and settings
*/
settings?: Record<string, unknown>;
/**
* The OAuth scopes
*/
scope?: string[];
}

/**
* Interface of the query parameters for listing connectors.
*/
export type ListConnectorsQueryParams = ListQueryParams;
168 changes: 168 additions & 0 deletions src/models/credentials.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,168 @@
/**
* Interface representing a Nylas Credential object.
*/
export interface Credential {
/**
* Globally unique object identifier
*/
id: string;
/**
* Name of the credential
*/
name: string;
/**
* The type of credential
*/
credentialType?: CredentialType;
/**
* Hashed value of the credential that you created
*/
hashedData?: string;
/**
* Timestamp of when the credential was created
*/
createdAt?: number;
/**
* Timestamp of when the credential was updated
*/
updatedAt?: number;
}

/**
* Interface representing additional data needed to create a credential for Microsoft Admin Consent
*/
export interface MicrosoftAdminConsentSettings {
clientId: string;
clientSecret: string;
[key: string]: string;
}

/**
* Interface representing additional data needed to create a credential for Google Service Account
*/
export interface GoogleServiceAccountCredential {
privateKeyId: string;
privateKey: string;
clientEmail: string;
[key: string]: string;
}

/**
* Interface representing additional data needed to create a credential for a Connector Override
*/
export type ConnectorOverrideCredential = Record<string, unknown>;

/**
* Type representing the data needed to create a credential
*/
export type CredentialData =
| MicrosoftAdminConsentSettings
| GoogleServiceAccountCredential
| ConnectorOverrideCredential;

/**
* Interface representing a request to create a Microsoft Admin Consent credential
*/
export interface CreateMicrosoftCredentialRequest {
/**
* Unique name of this credential
*/
name: string;
/**
* Type of credential for the admin consent flow
*/
credentialType: CredentialType.ADMINCONSENT;
/**
* Data that specifies some special data required for this credential
*/
credentialData: MicrosoftAdminConsentSettings;
}

/**
* Interface representing a request to create a Google Service Account credential
*/
export interface CreateGoogleCredentialRequest {
/**
* Unique name of this credential
*/
name: string;
/**
* Type of credential for the app permission flow
*/
credentialType: CredentialType.SERVICEACCOUNT;
/**
* Data that specifies some special data required for this credential
*/
credentialData: GoogleServiceAccountCredential;
}

/**
* Interface representing a request to create a Connector Override credential
*/
export interface CreateOverrideCredentialRequest {
/**
* Unique name of this credential
*/
name: string;
/**
* Type of credential to force the override of a connector's client values
*/
credentialType: CredentialType.CONNECTOR;
/**
* Data that specifies some special data required for this credential
*/
credentialData: ConnectorOverrideCredential;
}

/**
* Interface representing a request to create a credential
*/
export type CreateCredentialRequest =
| CreateMicrosoftCredentialRequest
| CreateGoogleCredentialRequest
| CreateOverrideCredentialRequest;

/**
* Interface representing a request to update a credential
*/
export interface UpdateCredentialRequest {
/**
* Unique name of this credential
*/
name?: string;
/**
* Data that specifies some special data required for this credential
*/
credentialData?: CredentialData;
}

/**
* Enum representing the type of credential
*/
export enum CredentialType {
ADMINCONSENT = 'adminconsent',
SERVICEACCOUNT = 'serviceaccount',
CONNECTOR = 'connector',
}

/**
* Interface representing the query parameters for listing credentials.
*/
export interface ListCredentialsQueryParams {
/**
* Limit the number of results
*/
limit?: number;
/**
* Offset the results by this number
*/
offset?: number;
/**
* Sort the results by field name
*/
sortBy?: 'createdAt' | 'updatedAt';
/**
* Order the results by ascending or descending
*/
orderBy?: 'desc' | 'asc';
}
6 changes: 6 additions & 0 deletions src/nylas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { Applications } from './resources/applications.js';
import { Messages } from './resources/messages.js';
import { Drafts } from './resources/drafts.js';
import { Threads } from './resources/threads.js';
import { Connectors } from './resources/connectors.js';

/**
* The entry point to the Node SDK
Expand All @@ -28,6 +29,10 @@ export default class Nylas {
* Access the Calendars API
*/
public calendars: Calendars;
/**
* Access the Connectors API
*/
public connectors: Connectors;
/**
* Access the Drafts API
*/
Expand Down Expand Up @@ -68,6 +73,7 @@ export default class Nylas {
this.applications = new Applications(this.apiClient);
this.auth = new Auth(this.apiClient);
this.calendars = new Calendars(this.apiClient);
this.connectors = new Connectors(this.apiClient);
this.drafts = new Drafts(this.apiClient);
this.events = new Events(this.apiClient);
this.messages = new Messages(this.apiClient);
Expand Down
Loading
Loading