import {z} from 'zod' export type PlaylistType = 'Multimedia' | 'Slideshow' | 'Template' | 'Marquee'; export type SourceType = 'Audio' | 'Command' | 'Flash' | 'Gadget' | 'Image' | 'Pdf' | 'PlaceExchange' | 'Playlist' | 'PowerPoint' | 'Rss' | 'Svg' | 'Template' | 'Text' | 'Twitter' | 'Url' | 'Video' | 'VistarMedia' | 'WebPage' | 'YouTube' | 'VistarMediaEx' | 'DataTable' | 'AdBreak'; export type Media = {name?: (string | null) | undefined, group_id?: (string | null) | undefined, tags?: (string | null) | undefined, advertiser_id?: (string | null) | undefined, is_shared?: (boolean | null) | undefined, start_date?: (string | null) | undefined, end_date?: (string | null) | undefined, id?: (string | null) | undefined, group_name?: (string | null) | undefined, mime_type?: (string | null) | undefined, file_size?: number | undefined, file_name?: (string | null) | undefined, file_url?: (string | null) | undefined, thumbnail_url?: (string | null) | undefined, uploaded_on?: (string | null) | undefined, uploaded_by_id?: (string | null) | undefined, sha_512?: (string | null) | undefined, width?: (number | null) | undefined, height?: (number | null) | undefined, is_approved?: (boolean | null) | undefined, approved_on?: (string | null) | undefined, declined_on?: (string | null) | undefined, declined_reason?: (string | null) | undefined}; export type LoopPolicyType = 'Default' | 'OverSaturate2x' | 'OverSaturate3x' | 'OverSaturate4x' | 'OverSaturate5x' | 'Random' | 'UnderSaturate2x' | 'UnderSaturate3x' | 'UnderSaturate4x' | 'UnderSaturate5x' | 'Prefill' | 'Postfill' | 'Spreadfill'; export type ConditionType = 'AfterDate' | 'AfterTime' | 'Always' | 'BeaconActive' | 'BeforeDate' | 'BeforeTime' | 'Command' | 'DateRange' | 'DayOfMonth' | 'DaysOfWeek' | 'DeviceByGroup' | 'DeviceByNestedGroup' | 'DeviceByName' | 'DeviceByTag' | 'DeviceByOrg' | 'Everywhere' | 'GeoLocation' | 'GpsWithinRadius' | 'KeyEvent' | 'MonthOfYear' | 'Motion' | 'Never' | 'Nowhere' | 'PctAdult' | 'PctChild' | 'PctFemale' | 'PctMale' | 'PctSenior' | 'PctYoung' | 'PctYoungAdult' | 'PlaylistByName' | 'PlaylistByTag' | 'SendCommand' | 'SpecificDevice' | 'SpecificPlaylist' | 'SpecificTemplate' | 'SpecificZone' | 'TemplateByName' | 'TemplateByTag' | 'TimeRange' | 'TopicSet' | 'TotalViewersGreaterThan' | 'TotalViewersLessThan' | 'TouchEvent' | 'WeekOfMonth' | 'WeekOfYear'; export type ConditionOperator = 'And' | 'Or' | 'AndNot' | 'OrNot'; export type Condition = {type?: ConditionType | undefined, operator?: ConditionOperator | undefined, value_1?: (string | null) | undefined, value_2?: (string | null) | undefined, value_3?: (string | null) | undefined, value_4?: (string | null) | undefined}; export type Source = {id?: (string | null) | undefined, name?: (string | null) | undefined, type?: SourceType | undefined, sequence?: (number | null) | undefined, media_id?: (string | null) | undefined, template_id?: (string | null) | undefined, playlist_id?: (string | null) | undefined, value?: (string | null) | undefined, interval?: (number | null) | undefined, media?: Media | undefined, loop_policy_type?: LoopPolicyType | undefined, conditions?: (Array | null) | undefined}; export type Playlist = {id?: (string | null) | undefined, name?: (string | null) | undefined, group_name?: (string | null) | undefined, group_id?: (string | null) | undefined, tags?: (string | null) | undefined, type?: PlaylistType | undefined, duration?: (number | null) | undefined, calculated_duration?: (number | null) | undefined, is_random_start?: (boolean | null) | undefined, created_on?: (string | null) | undefined, created_by_id?: (string | null) | undefined, modified_on?: (string | null) | undefined, modified_by_id?: (string | null) | undefined, sources?: (Array | null) | undefined}; export type CreateApiPlaylistsArgs = {body: Playlist}; export type CreateApiPlaylistsOptions = {baseUrl?: string | undefined, Bearer?: string | undefined, fetch?: typeof fetch | undefined}; export const playlistType = z.enum(["Multimedia", "Slideshow", "Template", "Marquee"]); export const sourceType = z.enum(["Audio", "Command", "Flash", "Gadget", "Image", "Pdf", "PlaceExchange", "Playlist", "PowerPoint", "Rss", "Svg", "Template", "Text", "Twitter", "Url", "Video", "VistarMedia", "WebPage", "YouTube", "VistarMediaEx", "DataTable", "AdBreak"]); export const media = z.object({name: z.string().nullable().optional(), group_id: z.string().nullable().optional(), tags: z.string().nullable().optional(), advertiser_id: z.string().nullable().optional(), is_shared: z.boolean().nullable().optional(), start_date: z.string().nullable().optional(), end_date: z.string().nullable().optional(), id: z.string().nullable().optional(), group_name: z.string().nullable().optional(), mime_type: z.string().nullable().optional(), file_size: z.number().int().optional(), file_name: z.string().nullable().optional(), file_url: z.string().nullable().optional(), thumbnail_url: z.string().nullable().optional(), uploaded_on: z.string().nullable().optional(), uploaded_by_id: z.string().nullable().optional(), sha_512: z.string().nullable().optional(), width: z.number().int().nullable().optional(), height: z.number().int().nullable().optional(), is_approved: z.boolean().nullable().optional(), approved_on: z.string().nullable().optional(), declined_on: z.string().nullable().optional(), declined_reason: z.string().nullable().optional()}); export const loopPolicyType = z.enum(["Default", "OverSaturate2x", "OverSaturate3x", "OverSaturate4x", "OverSaturate5x", "Random", "UnderSaturate2x", "UnderSaturate3x", "UnderSaturate4x", "UnderSaturate5x", "Prefill", "Postfill", "Spreadfill"]); export const conditionType = z.enum(["AfterDate", "AfterTime", "Always", "BeaconActive", "BeforeDate", "BeforeTime", "Command", "DateRange", "DayOfMonth", "DaysOfWeek", "DeviceByGroup", "DeviceByNestedGroup", "DeviceByName", "DeviceByTag", "DeviceByOrg", "Everywhere", "GeoLocation", "GpsWithinRadius", "KeyEvent", "MonthOfYear", "Motion", "Never", "Nowhere", "PctAdult", "PctChild", "PctFemale", "PctMale", "PctSenior", "PctYoung", "PctYoungAdult", "PlaylistByName", "PlaylistByTag", "SendCommand", "SpecificDevice", "SpecificPlaylist", "SpecificTemplate", "SpecificZone", "TemplateByName", "TemplateByTag", "TimeRange", "TopicSet", "TotalViewersGreaterThan", "TotalViewersLessThan", "TouchEvent", "WeekOfMonth", "WeekOfYear"]); export const conditionOperator = z.enum(["And", "Or", "AndNot", "OrNot"]); export const condition = z.object({type: conditionType.optional(), operator: conditionOperator.optional(), value_1: z.string().nullable().optional(), value_2: z.string().nullable().optional(), value_3: z.string().nullable().optional(), value_4: z.string().nullable().optional()}); export const source = z.object({id: z.string().nullable().optional(), name: z.string().nullable().optional(), type: sourceType.optional(), sequence: z.number().int().nullable().optional(), media_id: z.string().nullable().optional(), template_id: z.string().nullable().optional(), playlist_id: z.string().nullable().optional(), value: z.string().nullable().optional(), interval: z.number().int().nullable().optional(), media: media.optional(), loop_policy_type: loopPolicyType.optional(), conditions: z.array(condition).nullable().optional()}); export const playlist = z.object({id: z.string().nullable().optional(), name: z.string().nullable().optional(), group_name: z.string().nullable().optional(), group_id: z.string().nullable().optional(), tags: z.string().nullable().optional(), type: playlistType.optional(), duration: z.number().int().nullable().optional(), calculated_duration: z.number().int().nullable().optional(), is_random_start: z.boolean().nullable().optional(), created_on: z.string().nullable().optional(), created_by_id: z.string().nullable().optional(), modified_on: z.string().nullable().optional(), modified_by_id: z.string().nullable().optional(), sources: z.array(source).nullable().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 new playlist. * * POST /playlists * * Also accepts auth: ApiKeyInHeader, ApiKeyInQuery */ export const createApiPlaylists = async (args: CreateApiPlaylistsArgs, options?: CreateApiPlaylistsOptions) => { const {baseUrl = "https://api.reveldigital.com", fetch: fetchFn = fetch, Bearer} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (Bearer !== undefined) headers.set('authorization', `Bearer ${Bearer}`) const url = `${baseUrl.replace(/\/+$/, '')}/playlists${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(playlist, await res.json()) };