import {z} from 'zod' export type GetApiApiEnterprisesEnterpriseIdAnalyticsTrendsByTrackSqlArgs = {enterpriseId: number, 'filter.countryIds'?: Array | undefined, 'filter.distributorIds'?: Array | undefined, 'filter.excludeDistributorIds'?: Array | undefined, 'filter.excludeTikTok'?: boolean | undefined, 'filter.releaseIds'?: Array | undefined, 'filter.trackIds'?: Array | undefined, 'filter.artistIds'?: Array | undefined, 'filter.labelIds'?: Array | undefined, 'filter.dateGranularity'?: string | undefined, 'filter.onlyNew'?: boolean | undefined, 'filter.orderByProperty'?: string | undefined, 'filter.orderByDescending'?: boolean | undefined, 'filter.pageSize'?: number | undefined, 'filter.pageNumber'?: number | undefined, 'filter.fromDate'?: string | undefined, 'filter.toDate'?: string | undefined}; export type GetApiApiEnterprisesEnterpriseIdAnalyticsTrendsByTrackSqlOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const analyticsTrendsResultTotalsDTO = z.object({streamsCount: z.number().int().optional(), downloadsCount: z.number().int().optional()}); export const analyticsTrendsResultItemByTrackDTO = z.object({releaseId: z.number().int().optional(), releaseName: z.string().optional(), releaseVersion: z.string().optional(), trackImageId: z.string().optional(), trackId: z.number().int().optional(), trackName: z.string().optional(), trackVersion: z.string().optional(), artistId: z.number().int().optional(), artistName: z.string().optional()}); export const analyticsTrendsResultItemDTOAnalyticsTrendsResultItemByTrackDTO = z.object({streamsCount: z.number().int().optional(), downloadsCount: z.number().int().optional(), eventDate: z.string().optional(), metadata: analyticsTrendsResultItemByTrackDTO.optional()}); export const analyticsTrendsPagedAnalyticsTrendsResultItemByTrackDTO = z.object({totals: analyticsTrendsResultTotalsDTO.optional(), fromDate: z.string().optional(), toDate: z.string().optional(), totalItemsCount: z.number().int().optional(), pageNumber: z.number().int().optional(), pageSize: z.number().int().optional(), items: z.array(analyticsTrendsResultItemDTOAnalyticsTrendsResultItemByTrackDTO).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 }; /** * GET /api/enterprises/{enterpriseId}/analytics/trends/byTrackSql */ export const getApiApiEnterprisesEnterpriseIdAnalyticsTrendsByTrackSql = async (args: GetApiApiEnterprisesEnterpriseIdAnalyticsTrendsByTrackSqlArgs, options?: GetApiApiEnterprisesEnterpriseIdAnalyticsTrendsByTrackSqlOptions) => { const {baseUrl = "http://api.revelator.com", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") for (const item of args['filter.countryIds'] ?? []) query.append("filter.countryIds", String(item)) for (const item of args['filter.distributorIds'] ?? []) query.append("filter.distributorIds", String(item)) for (const item of args['filter.excludeDistributorIds'] ?? []) query.append("filter.excludeDistributorIds", String(item)) if (args['filter.excludeTikTok'] != null) query.append("filter.excludeTikTok", String(args['filter.excludeTikTok'])) for (const item of args['filter.releaseIds'] ?? []) query.append("filter.releaseIds", String(item)) for (const item of args['filter.trackIds'] ?? []) query.append("filter.trackIds", String(item)) for (const item of args['filter.artistIds'] ?? []) query.append("filter.artistIds", String(item)) for (const item of args['filter.labelIds'] ?? []) query.append("filter.labelIds", String(item)) if (args['filter.dateGranularity'] != null) query.append("filter.dateGranularity", String(args['filter.dateGranularity'])) if (args['filter.onlyNew'] != null) query.append("filter.onlyNew", String(args['filter.onlyNew'])) if (args['filter.orderByProperty'] != null) query.append("filter.orderByProperty", String(args['filter.orderByProperty'])) if (args['filter.orderByDescending'] != null) query.append("filter.orderByDescending", String(args['filter.orderByDescending'])) if (args['filter.pageSize'] != null) query.append("filter.pageSize", String(args['filter.pageSize'])) if (args['filter.pageNumber'] != null) query.append("filter.pageNumber", String(args['filter.pageNumber'])) if (args['filter.fromDate'] != null) query.append("filter.fromDate", String(args['filter.fromDate'])) if (args['filter.toDate'] != null) query.append("filter.toDate", String(args['filter.toDate'])) const url = `${baseUrl.replace(/\/+$/, '')}/api/enterprises/${encodeURIComponent(String(args.enterpriseId))}/analytics/trends/byTrackSql${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(analyticsTrendsPagedAnalyticsTrendsResultItemByTrackDTO, await res.json()) };