Skip to content

Commit

Permalink
Merge branch 'v7.0.0-beta' into AV-817-3-0-beta-node-sdk-beta-test-co…
Browse files Browse the repository at this point in the history
…verage
  • Loading branch information
mrashed-dev authored Oct 16, 2023
2 parents 797682c + f21c496 commit 24e272c
Show file tree
Hide file tree
Showing 3 changed files with 121 additions and 3 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
# Changelog

### 7.0.0-beta.3 / TBD
* Added support for the free-busy endpoint
* Fix `getAvailability` response type
* Fix path for destroying a redirect URI
* Fix model for updating an Event
* Fix model for updating an Event

### 7.0.0-beta.2 / 2023-08-21
* Fix issue with getting the current Nylas SDK package version
Expand Down
84 changes: 84 additions & 0 deletions src/models/freeBusy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
/**
* Interface representation of a Nylas free-busy time slot object.
*/
export interface FreeBusyTimeSlot {
/**
* Unix timestamp for the start of the slot.
*/
startTime: number;
/**
* Unix timestamp for the end of the slot.
*/
endTime: number;
/**
* The status of the time slot.
*/
status: string;
}

/**
* Class representation of a Nylas get free-busy request
*/
export interface GetFreeBusyRequest {
/**
* Unix timestamp representing the start of the time block for assessing the account's free/busy schedule.
*/
startTime: number;
/**
* Unix timestamp representing the end of the time block for assessing the account's free/busy schedule.
*/
endTime: number;
/**
* A list of email addresses to check the free/busy schedules for.
*/
emails: string[];
}

/**
* Enum representing the type of free/busy information returned for a calendar.
*/
export enum FreeBusyType {
FREE_BUSY = 'free_busy',
ERROR = 'error',
}

/**
* Union type of the possible Nylas get free busy response.
*/
export type GetFreeBusyResponse = FreeBusy | FreeBusyError;

/**
* This interface represents a successful free-busy response.
*/
export interface FreeBusy {
/**
* The participant's email address.
*/
email: string;
/**
* A list of busy time slots.
*/
timeSlots: FreeBusyTimeSlot[];
/**
* The type of the response.
*/
object: FreeBusyType.FREE_BUSY;
}

/**
* This interface represents a failed free-busy response.
*/
export interface FreeBusyError {
/**
* The participant's email address.
*/
email: string;
/**
* Description of the error fetching data for this participant.
*/
error: string;
/**
* The type of the response.
*/
object: FreeBusyType.ERROR;
}
36 changes: 34 additions & 2 deletions src/resources/calendars.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
GetAvailabilityRequest,
GetAvailabilityResponse,
} from '../models/availability.js';
import { GetFreeBusyRequest, GetFreeBusyResponse } from '../models/freeBusy.js';

/**
* The parameters for the {@link Calendars.find} method
Expand Down Expand Up @@ -75,6 +76,16 @@ interface GetAvailabilityParams {
requestBody: GetAvailabilityRequest;
}

/**
* The parameters for the {@link Calendars.getFreeBusy} method
* @property identifier The identifier of the grant to act upon
* @property requestBody The free busy request
*/
interface GetFreeBusyParams {
identifier: string;
requestBody: GetFreeBusyRequest;
}

/**
* Nylas Calendar API
*
Expand Down Expand Up @@ -170,12 +181,33 @@ export class Calendars extends Resource {
public getAvailability({
requestBody,
overrides,
}: GetAvailabilityParams & Overrides): Promise<GetAvailabilityResponse> {
return this.apiClient.request<GetAvailabilityResponse>({
}: GetAvailabilityParams & Overrides): Promise<
NylasResponse<GetAvailabilityResponse>
> {
return this.apiClient.request<NylasResponse<GetAvailabilityResponse>>({
method: 'POST',
path: `/v3/calendars/availability`,
body: requestBody,
overrides,
});
}

/**
* Get the free/busy schedule for a list of email addresses
* @return The free/busy response
*/
public getFreeBusy({
identifier,
requestBody,
overrides,
}: GetFreeBusyParams & Overrides): Promise<
NylasResponse<GetFreeBusyResponse[]>
> {
return this.apiClient.request<NylasResponse<GetFreeBusyResponse[]>>({
method: 'POST',
path: `/v3/grants/${identifier}/calendars/free-busy`,
body: requestBody,
overrides,
});
}
}

0 comments on commit 24e272c

Please sign in to comment.