import {z} from 'zod' export type CreateApiV2OrganizationsCalendarsCreateArgs = {body: {name: string, slug?: string | undefined, description?: string | undefined, avatar_url?: string | undefined, tint_color?: string | undefined, launch_status?: ('launched' | 'coming-soon' | 'archived') | undefined, website?: (string | null) | undefined, instagram_handle?: (string | null) | undefined, twitter_handle?: (string | null) | undefined, youtube_handle?: (string | null) | undefined, tiktok_handle?: (string | null) | undefined, linkedin_handle?: (string | null) | undefined, location?: ({type: 'google', place_id: string} | {type: 'lookup', query: string}) | undefined}}; export type CreateApiV2OrganizationsCalendarsCreateOptions = {baseUrl?: string | undefined, apiKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const calendar = z.object({id: z.string(), launch_status: z.enum(["launched", "coming-soon", "archived"]), tint_color: z.string().nullable(), name: z.string(), slug: z.string().nullable(), avatar_url: z.string().nullable(), url: z.string(), description: z.string().nullable(), social_image_url: z.string().nullable(), cover_image_url: z.string().nullable(), is_personal: z.boolean(), location: z.object({city: z.string(), region: z.string().nullable(), country: z.string().nullable(), country_code: z.string().nullable(), timezone: z.string()}).nullable(), coordinate: z.object({longitude: z.number(), latitude: z.number()}).nullable(), instagram_handle: z.string().nullable(), twitter_handle: z.string().nullable(), youtube_handle: z.string().nullable(), tiktok_handle: z.string().nullable(), linkedin_handle: z.string().nullable(), website: z.string().nullable()}); export const validateResponse = async ( schema: { readonly '~standard': { readonly validate: (value: unknown) => ({ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }) | Promise<{ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }> } }, value: unknown ): Promise => { const result = await schema['~standard'].validate(value) if (result.issues !== undefined) { const detail = result.issues .map(({ message, path }) => path?.length ? `${path.map((segment) => String(typeof segment === 'object' ? segment.key : segment)).join('.')}: ${message}` : message ) .join('; ') throw new Error(`Response does not match the schema: ${detail}`, { cause: { issues: result.issues } }) } return result.value }; /** * Create Calendar * * POST /v2/organizations/calendars/create */ export const createApiV2OrganizationsCalendarsCreate = async (args: CreateApiV2OrganizationsCalendarsCreateArgs, options?: CreateApiV2OrganizationsCalendarsCreateOptions) => { const {baseUrl = "https://public-api.luma.com", fetch: fetchFn = fetch, apiKeyAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (apiKeyAuth !== undefined) headers.set("x-luma-api-key", apiKeyAuth) const url = `${baseUrl.replace(/\/+$/, '')}/v2/organizations/calendars/create${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(calendar, await res.json()) };