UNPKG

2.28 kBTypeScriptView Raw
1import { calendar_v3 } from "googleapis";
2import { OAuth2Client, JWT, Compute, UserRefreshClient } from "google-auth-library";
3import moment from "moment-timezone";
4/** Slot deciding strategies */
5export declare type Strategy = "linear" | "heavy-firsts" | "heavy-lasts" | "heavy-centers" | "heavy-mornings" | "heavy-afternoons" | "heavy-evenings" | "heavy-mondays" | "heavy-tuesdays" | "heavy-wednesdays" | "heavy-fridays" | "heavy-saturday" | "heavy-sundays";
6/**
7 * Get a random element from this array, strategy-weighted
8 */
9export declare const weightedItemFromArray: (params: GetEventsParams & GetSlotsParams, arr: Slot[], strategies: Strategy[]) => Slot;
10export interface GetEventsParams {
11 user?: {
12 accessToken: string;
13 refreshToken: string;
14 };
15 from: moment.MomentInput;
16 to: moment.MomentInput;
17 calendar?: calendar_v3.Calendar;
18 calendarId?: string;
19 auth?: string | OAuth2Client | JWT | Compute | UserRefreshClient;
20}
21export interface GetSlotsParams {
22 log?: boolean;
23 slotDuration?: number;
24 slots?: number;
25 padding?: number;
26 url?: string;
27 strategies?: Strategy[];
28 weight?: number;
29 days?: number[];
30 daily?: {
31 timezone: string;
32 from?: [number, number?, number?];
33 to?: [number, number?, number?];
34 };
35 slotFilter?: (slot: Slot) => boolean;
36 logger?: (...args: any[]) => void;
37}
38export interface Slot {
39 start: Date;
40 end: Date;
41}
42/**
43 * Find a user's events from a single calendar
44 * Defaults to their primary calendar
45 */
46export declare const getEventsFromSingleCalendar: ({ user, from, to, calendar, calendarId, auth, }: GetEventsParams) => Promise<calendar_v3.Schema$Event[]>;
47/**
48 * Get a list of user's events from all calendars
49 */
50export declare const getEventsFromAllCalendars: (params: Pick<GetEventsParams, "user" | "auth" | "from" | "to" | "calendar">) => Promise<calendar_v3.Schema$Event[]>;
51/**
52 * Get calendar events from a webcal ICS URL
53 */
54export declare const getEventsFromWebcal: (url: string) => Promise<{
55 start: {
56 dateTime: string;
57 };
58 end: {
59 dateTime: string;
60 };
61}[]>;
62/**
63 * List all free slots for a user
64 */
65export declare const getSlots: (params: GetEventsParams & GetSlotsParams) => Promise<Slot[]>;