Skip to content
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
23 changes: 23 additions & 0 deletions src/models/scheduler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -459,3 +459,26 @@ export interface FindBookingQueryParams {
export type ConfirmBookingQueryParams = FindBookingQueryParams;
export type RescheduleBookingQueryParams = FindBookingQueryParams;
export type DestroyBookingQueryParams = FindBookingQueryParams;

export interface SchedulerAvailabilityTimeSlot {
emails: string[];
startTime: number;
endTime: number;
eventId?: string;
masterId?: string;
calendarId?: string;
}

export interface SchedulerAvailabilityResponse {
order?: string[];
timeSlots: SchedulerAvailabilityTimeSlot[];
}

export interface GetSchedulerAvailabilityQueryParams {
startTime: number;
endTime: number;
configurationId?: string;
slug?: string;
clientId?: string;
bookingId?: string;
}
35 changes: 35 additions & 0 deletions src/resources/availability.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { Overrides } from '../config.js';
import { NylasResponse } from '../models/response.js';
import {
SchedulerAvailabilityResponse,
GetSchedulerAvailabilityQueryParams,
} from '../models/scheduler.js';
import { Resource } from './resource.js';
import { makePathParams } from '../utils.js';

/**
* The parameters for the {@link SchedulerAvailability.get} method
* @property queryParams The query parameters to include in the request
*/
export interface GetSchedulerAvailabilityParams {
queryParams: GetSchedulerAvailabilityQueryParams;
}

export class SchedulerAvailability extends Resource {
/**
* Get availability for a scheduling configuration
* @return The availability response with time slots
*/
public get({
queryParams,
overrides,
}: GetSchedulerAvailabilityParams & Overrides): Promise<
NylasResponse<SchedulerAvailabilityResponse>
> {
return super._find({
path: makePathParams('/v3/scheduling/availability', {}),
queryParams,
overrides,
});
}
}
3 changes: 3 additions & 0 deletions src/resources/scheduler.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
import { Configurations } from './configurations.js';
import { Sessions } from './sessions.js';
import { Bookings } from './bookings.js';
import { SchedulerAvailability } from './availability.js';
import APIClient from '../apiClient.js';

export class Scheduler {
public configurations: Configurations;
public bookings: Bookings;
public sessions: Sessions;
public availability: SchedulerAvailability;

constructor(apiClient: APIClient) {
this.configurations = new Configurations(apiClient);
this.bookings = new Bookings(apiClient);
this.sessions = new Sessions(apiClient);
this.availability = new SchedulerAvailability(apiClient);
}
}
2 changes: 1 addition & 1 deletion tests/resources/attachments.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ describe('Attachments', () => {

// Mock Web ReadableStream (native in Node 18+)
const mockStream = new ReadableStream({
start(controller) {
start(controller: ReadableStreamDefaultController<Uint8Array>): void {
controller.enqueue(new Uint8Array([1, 2, 3]));
controller.close();
},
Expand Down
136 changes: 136 additions & 0 deletions tests/resources/availability.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
import APIClient from '../../src/apiClient';
import { SchedulerAvailability } from '../../src/resources/availability';
jest.mock('../../src/apiClient');

describe('SchedulerAvailability', () => {
let apiClient: jest.Mocked<APIClient>;
let availability: SchedulerAvailability;

beforeAll(() => {
apiClient = new APIClient({
apiKey: 'apiKey',
apiUri: 'https://test.api.nylas.com',
timeout: 30,
headers: {},
}) as jest.Mocked<APIClient>;

availability = new SchedulerAvailability(apiClient);
apiClient.request.mockResolvedValue({});
});

describe('get', () => {
it('should call apiClient.request with configurationId', async () => {
await availability.get({
queryParams: {
startTime: 1659367800,
endTime: 1659369600,
configurationId: 'configuration123',
},
overrides: {
apiUri: 'https://test.api.nylas.com',
headers: { override: 'foobar' },
},
});

expect(apiClient.request).toHaveBeenCalledWith({
method: 'GET',
path: '/v3/scheduling/availability',
queryParams: {
startTime: 1659367800,
endTime: 1659369600,
configurationId: 'configuration123',
},
overrides: {
apiUri: 'https://test.api.nylas.com',
headers: { override: 'foobar' },
},
});
});

it('should call apiClient.request with slug', async () => {
await availability.get({
queryParams: {
startTime: 1659367800,
endTime: 1659369600,
slug: 'my-schedule',
},
});

expect(apiClient.request).toHaveBeenCalledWith({
method: 'GET',
path: '/v3/scheduling/availability',
queryParams: {
startTime: 1659367800,
endTime: 1659369600,
slug: 'my-schedule',
},
overrides: undefined,
});
});

it('should call apiClient.request with clientId', async () => {
await availability.get({
queryParams: {
startTime: 1659367800,
endTime: 1659369600,
clientId: 'client123',
},
});

expect(apiClient.request).toHaveBeenCalledWith({
method: 'GET',
path: '/v3/scheduling/availability',
queryParams: {
startTime: 1659367800,
endTime: 1659369600,
clientId: 'client123',
},
overrides: undefined,
});
});

it('should call apiClient.request with bookingId for reschedule availability', async () => {
await availability.get({
queryParams: {
startTime: 1659367800,
endTime: 1659369600,
configurationId: 'configuration123',
bookingId: 'booking456',
},
});

expect(apiClient.request).toHaveBeenCalledWith({
method: 'GET',
path: '/v3/scheduling/availability',
queryParams: {
startTime: 1659367800,
endTime: 1659369600,
configurationId: 'configuration123',
bookingId: 'booking456',
},
overrides: undefined,
});
});

it('should URL-encode special characters in query params', async () => {
await availability.get({
queryParams: {
startTime: 1659367800,
endTime: 1659369600,
slug: 'my schedule/special',
},
});

expect(apiClient.request).toHaveBeenCalledWith({
method: 'GET',
path: '/v3/scheduling/availability',
queryParams: {
startTime: 1659367800,
endTime: 1659369600,
slug: 'my schedule/special',
},
overrides: undefined,
});
});
});
});
Loading