import {z} from 'zod' export type CreateApiApiTeamArgs = {body: {name: string, sport_id: number, league_id: number, type_id?: number | undefined, parent_id?: (number | null) | undefined, division_id?: number | undefined, capacity?: (number | null) | undefined, alias?: (string | null) | undefined, logo?: (string | null) | undefined, cover?: (string | null) | undefined, synopsis?: string | undefined, email?: (string | null) | undefined, inactive?: boolean | undefined, exclude_from_social_scan?: boolean | undefined, website_url?: (string | null) | undefined, markets?: (Array<{id?: number | undefined, pivot?: ({class?: string | undefined}) | undefined}> | null) | undefined, organizations?: Array | undefined, agencies?: Array> | undefined, hashtags?: Array> | undefined, rejected_brands?: Array> | undefined, locations?: (Array<{location_id?: number | undefined, label_id?: number | undefined}>) | undefined, twitter_handle?: (string | null) | undefined, facebook_handle?: (string | null) | undefined, instagram_handle?: (string | null) | undefined, tiktok_handle?: (string | null) | undefined, youtube_handle?: (string | null) | undefined, twitch_handle?: (string | null) | undefined}}; export type CreateApiApiTeamOptions = {baseUrl: string, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const property = z.object({id: z.number().int().optional(), parent_id: z.number().int().optional(), type_id: z.number().int().optional(), uuid: z.number().int().optional(), division_id: z.number().int().optional(), sport_id: z.number().int().optional(), name: z.string().optional(), synopsis: z.string().optional(), alias: z.string().optional(), logo: z.string().optional(), cover: z.string().optional(), is_continuous: z.number().int().optional(), league_level_property: z.number().int().optional(), no_of_employees: z.number().int().optional(), email: z.string().optional(), website_url: z.string().optional(), linkedin_url: z.string().optional(), linkedin_id_url: z.string().optional(), facebook_url: z.string().optional(), twitter_url: z.string().optional(), instagram_url: z.string().optional(), twitch_url: z.string().optional(), tiktok_url: z.string().optional(), youtube_url: z.string().optional(), exclude_from_social_scan: z.number().int().optional(), inactive: z.number().int().optional(), market: z.string().optional(), state: z.string().optional(), city: z.string().optional(), geolocation: z.string().optional(), corporate_phone: z.string().optional(), linkedin_employees: z.string().optional(), targeted_prospects_feed_url: z.string().optional(), top_sponsorship_headlines_feed_url: z.string().optional(), headlines_feed_url: z.string().optional(), capacity: z.string().optional(), venue_uuid: z.string().optional(), created_at: z.string().optional(), updated_at: z.string().optional(), deleted_at: z.string().optional()}); 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 a property * * POST /api/team */ export const createApiApiTeam = async (args: CreateApiApiTeamArgs, options: CreateApiApiTeamOptions) => { const {baseUrl, fetch: fetchFn = fetch, bearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (bearerAuth !== undefined) headers.set('authorization', `Bearer ${bearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/team${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(property, await res.json()) };