import {z} from 'zod' export type GetApiApiPlaylistDeezerListsArgs = {offset?: number | undefined, limit?: number | undefined, 'tagIds[]'?: Array | undefined, 'curatorIds[]'?: Array | undefined, 'excludedCuratorListIds[]'?: Array | undefined, sortColumn?: ('active_ratio' | 'fdiff_month' | 'fdiff_percent_month' | 'fdiff_percent_week' | 'fdiff_week' | 'followers' | 'last_updated' | 'num_track') | undefined, sortOrderDesc?: boolean | undefined, code2?: string | undefined, indie?: boolean | undefined, editorial?: boolean | undefined, majorCurator?: boolean | undefined, topPlaylist?: boolean | undefined, descriptionSearch?: string | undefined, 'userListIds[]'?: Array | undefined}; export type GetApiApiPlaylistDeezerListsOptions = {baseUrl?: string | undefined, BearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const getApiApiPlaylistDeezerListsResponse = z.object({obj: z.array(z.object({position: z.number().int().gte(0).optional(), id: z.union([z.number().int().gte(0), z.string()]), name: z.string().nullable().optional(), image_url: z.string().nullable().optional(), description: z.string().nullable().optional(), active_ratio: z.number().nullable().optional(), num_track: z.union([z.number().int(), z.string()]).nullable().optional(), last_updated: z.union([z.string(), z.number()]).nullable().optional(), owner_id: z.union([z.number().int(), z.string()]).nullable().optional(), owner_name: z.string().nullable().optional(), code2: z.string().nullable().optional(), editorial: z.boolean().optional(), genre: z.string().nullable().optional(), followers: z.number().int().gte(0).nullable().optional(), fdiff_week: z.number().int().nullable().optional(), fdiff_percent_week: z.number().nullable().optional(), fdiff_month: z.number().int().nullable().optional(), fdiff_percent_month: z.number().nullable().optional(), playlist_id: z.union([z.number().int().gte(0), z.string()]).nullable().optional(), user_id: z.string().nullable().optional(), catalog: z.string().nullable().optional(), personalized: z.boolean().optional(), playlist_updated: z.union([z.string(), z.number()]).nullable().optional(), tag_ids: z.array(z.number().int().gte(0)).nullable().optional(), suspicion_score: z.number().nullable().optional(), submithub_url: z.string().nullable().optional(), groover_url: z.string().nullable().optional(), score_100: z.number().nullable().optional(), views: z.number().int().gte(0).nullable().optional(), vdiff_week: z.number().int().nullable().optional(), vdiff_percent_week: z.number().nullable().optional(), vdiff_month: z.number().int().nullable().optional(), vdiff_percent_month: z.number().nullable().optional(), youtube_last_updated: z.string().nullable().optional(), permalink: z.string().nullable().optional(), artist_permalink: z.string().nullable().optional(), soundcloud_artist_name: z.string().nullable().optional(), monthly_diff: z.unknown(), monthly_diff_percent: z.unknown(), latest: z.unknown(), soundcloud_updated: z.union([z.string(), z.number()]).nullable().optional(), with_storefronts: z.boolean().optional(), code2s: z.array(z.string()).optional(), chart: z.boolean().optional(), radio: z.boolean().optional(), music_brand_curator: z.boolean().optional(), non_music_brand_curator: z.boolean().optional(), editorial_brand: z.boolean().optional(), indie_curator: z.boolean().optional(), personality_artist_curator: z.boolean().optional(), curator_id: z.union([z.number().int().gte(0), z.string()]).nullable().optional(), chart_ranks: z.array(z.unknown()).optional(), rank: z.number().int().nullable().optional(), moods: z.array(z.object({id: z.number().int().gte(0), name: z.string().nullable().optional()})).nullable().optional(), activities: z.array(z.object({id: z.number().int().gte(0), name: z.string().nullable().optional()})).nullable().optional(), mood_smart_ordered: z.array(z.unknown()).nullable().optional(), activity_smart_ordered: z.array(z.unknown()).nullable().optional()})), offset: z.number().int().gte(0), total: z.number().int().gte(0)}); 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 }; /** * List Deezer Playlists * * GET /api/playlist/deezer/lists */ export const getApiApiPlaylistDeezerLists = async (args: GetApiApiPlaylistDeezerListsArgs, options?: GetApiApiPlaylistDeezerListsOptions) => { const {baseUrl = "https://api.chartmetric.com", fetch: fetchFn = fetch, BearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.offset != null) query.append("offset", String(args.offset)) if (args.limit != null) query.append("limit", String(args.limit)) for (const item of args['tagIds[]'] ?? []) query.append("tagIds[]", String(item)) for (const item of args['curatorIds[]'] ?? []) query.append("curatorIds[]", String(item)) for (const item of args['excludedCuratorListIds[]'] ?? []) query.append("excludedCuratorListIds[]", String(item)) if (args.sortColumn != null) query.append("sortColumn", String(args.sortColumn)) if (args.sortOrderDesc != null) query.append("sortOrderDesc", String(args.sortOrderDesc)) if (args.code2 != null) query.append("code2", String(args.code2)) if (args.indie != null) query.append("indie", String(args.indie)) if (args.editorial != null) query.append("editorial", String(args.editorial)) if (args.majorCurator != null) query.append("majorCurator", String(args.majorCurator)) if (args.topPlaylist != null) query.append("topPlaylist", String(args.topPlaylist)) if (args.descriptionSearch != null) query.append("descriptionSearch", String(args.descriptionSearch)) for (const item of args['userListIds[]'] ?? []) query.append("userListIds[]", String(item)) if (BearerAuth !== undefined) headers.set('authorization', `Bearer ${BearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/playlist/deezer/lists${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "GET", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(getApiApiPlaylistDeezerListsResponse, await res.json()) };