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

Create a webhook should return secret #485

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
82 changes: 80 additions & 2 deletions src/models/webhooks.ts
Original file line number Diff line number Diff line change
@@ -1,40 +1,118 @@
/**
* Interface representing a Nylas Webhook object.
*/
export interface Webhook {
/**
* Globally unique object identifier.
*/
id: string;
description?: string;
/**
* List of events that triggers the webhook.
*/
triggerTypes: WebhookTriggers[];
/**
* The url to send webhooks to.
*/
callbackUrl: string;
/**
* The status of the new destination.
*/
status: 'active' | 'failing' | 'failed' | 'pause';
notificationEmailAddress?: string;
/**
* The time the status field was last updated, represented as a Unix timestamp in seconds.
*/
statusUpdatedAt: number;
/**
* The time the status field was created, represented as a Unix timestamp in seconds
*/
createdAt: number;
/**
* The time the status field was last updated, represented as a Unix timestamp in seconds.
*/
updatedAt: number;
/**
* A human-readable description of the webhook destination.
*/
description?: string;
/**
* The email addresses that Nylas notifies when a webhook is down for a while.
*/
notificationEmailAddress?: string;
}

/**
* Class representing a Nylas webhook with secret.
*/
export interface WebhookWithSecret extends Webhook {
/**
* A secret value used to encode the X-Nylas-Signature header on webhook requests.
*/
webhookSecret: string;
}

/**
* Class representing a Nylas webhook delete response.
*/
export interface WebhookDeleteResponse {
/**
* ID of the request.
*/
requestId: string;
/**
* Object containing the webhook deletion status.
*/
data?: {
/**
* The status of the webhook deletion.
*/
status: 'success';
};
}

/**
* Class representing the response for getting a list of webhook ip addresses.
*/
export interface WebhookIpAddressesResponse {
/**
* The IP addresses that Nylas send you webhook from.
*/
ipAddresses: string[];
/**
* UNIX timestamp when Nylas updated the list of IP addresses.
*/
updatedAt: number;
}

/**
* Class representation of a Nylas create webhook request.
*/
export interface CreateWebhookRequest {
/**
* List of events that triggers the webhook.
*/
triggerTypes: WebhookTriggers[];
/**
* The url to send webhooks to.
*/
callbackUrl: string;
/**
* A human-readable description of the webhook destination.
*/
description?: string;
/**
* The email addresses that Nylas notifies when a webhook is down for a while.
*/
notificationEmailAddress?: string;
}

/**
* Class representation of a Nylas update webhook request.
*/
export type UpdateWebhookRequest = Partial<CreateWebhookRequest>;

/**
* Enum representing the available webhook triggers.
*/
export enum WebhookTriggers {
CalendarCreated = 'calendar.created',
CalendarUpdated = 'calendar.updated',
Expand Down
4 changes: 3 additions & 1 deletion src/resources/webhooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,9 @@ export class Webhooks extends Resource {
public create({
requestBody,
overrides,
}: CreateWebhookParams & Overrides): Promise<NylasResponse<Webhook>> {
}: CreateWebhookParams & Overrides): Promise<
NylasResponse<WebhookWithSecret>
> {
return super._create({
path: `/v3/webhooks`,
requestBody,
Expand Down
Loading