import {z} from 'zod' export type GetApiFinanceSalereportSummaryArgs = {'options.fromDate'?: string | undefined, 'options.toDate'?: string | undefined, 'options.distributors'?: Array | undefined, 'options.countryCodes'?: Array | undefined, 'options.countryIds'?: Array | undefined, 'options.countryId'?: number | undefined, 'options.readyOnly'?: boolean | undefined, 'options.artistId'?: number | undefined, 'options.artistIds'?: Array | undefined, 'options.releaseId'?: number | undefined, 'options.releaseIds'?: Array | undefined, 'options.trackId'?: number | undefined, 'options.trackIds'?: Array | undefined, 'options.payeeId'?: number | undefined, 'options.labelId'?: number | undefined, 'options.labelIds'?: Array | undefined, 'options.userStatementQueueId'?: number | undefined, 'options.storeId'?: number | undefined, 'options.storeIds'?: Array | undefined, 'options.serviceIds'?: Array | undefined, 'options.saleItemTypeId'?: number | undefined, 'options.statementDisplayTypeId'?: ('ExternalTrends' | 'ExternalDistribution' | 'InternalDistribution' | 'Mechanicals' | 'Royalty') | undefined, 'options.id'?: string | undefined, 'options.excludeIds'?: Array | undefined, 'options.excludeCountryId'?: number | undefined, 'options.groupBy'?: ('Label' | 'Artist' | 'Release' | 'Track' | 'DeliveryType' | 'DeliveryTypeGroup' | 'Service' | 'Country' | 'ItemType' | 'Date' | 'DateMonthly' | 'DateYearly' | 'DateDaily' | 'DateMonth' | 'Payee' | 'Total' | 'StatementDisplayType' | 'Store' | 'City' | 'Region' | 'Playlist') | undefined, 'options.subGroupBy'?: ('Label' | 'Artist' | 'Release' | 'Track' | 'DeliveryType' | 'DeliveryTypeGroup' | 'Service' | 'Country' | 'ItemType' | 'Date' | 'DateMonthly' | 'DateYearly' | 'DateDaily' | 'DateMonth' | 'Payee' | 'Total' | 'StatementDisplayType' | 'Store' | 'City' | 'Region' | 'Playlist') | undefined, 'options.subGroupPageSize'?: number | undefined, 'options.received'?: boolean | undefined, 'options.excludeResult'?: boolean | undefined, 'options.deliveryTypeIds'?: Array | undefined, 'options.deliveryTypeGroups'?: (Array<'Download' | 'Stream' | 'Physical' | 'Other' | 'Licensing' | 'DigitalPerformance'>) | undefined, 'options.cityId'?: number | undefined, 'options.cityIds'?: Array | undefined, 'options.regionId'?: number | undefined, 'options.regionIds'?: Array | undefined, 'options.playlistId'?: number | undefined, 'options.playlistIds'?: Array | undefined, 'options.selectAll'?: boolean | undefined, 'options.partOfPlaylist'?: boolean | undefined, 'options.yProperty'?: ('TotalNet' | 'TotalQuantity') | undefined, 'options.withDelta'?: boolean | undefined, 'options.processed'?: boolean | undefined, 'options.payeeStatus'?: ('Blocked' | 'Unblocked') | undefined, 'options.payeeType'?: ('VIP' | 'Standard') | undefined, 'options.statementDeliveredType'?: ('EmailSent' | 'EmailNotSent') | undefined, 'options.approved'?: boolean | undefined, 'options.userStatementId'?: number | undefined, 'options.contractId'?: number | undefined, 'options.totalNetFilter'?: ('EqualTo' | 'GreaterThan' | 'LessThan') | undefined, 'options.totalNet'?: number | undefined, 'options.isRoyaltyTokenPayee'?: boolean | undefined, 'options.isCrypto'?: boolean | undefined, 'options.getBalanceItemStatements'?: boolean | undefined, 'options.pageNumber'?: number | undefined, 'options.pageSize'?: number | undefined, 'options.orderByProperty'?: string | undefined, 'options.orderByDescending'?: boolean | undefined, 'options.searchText'?: string | undefined}; export type GetApiFinanceSalereportSummaryOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const statementGroup = z.object({year: z.number().int().optional(), month: z.number().int().optional(), totalGross: z.number().optional(), totalNet: z.number().optional(), status: z.enum(["MissingContent", "WaitingForApproval", "Approved", "Error", "NeedFx"]).optional()}); export const getApiFinanceSalereportSummaryResponse = z.array(statementGroup); 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 /finance/salereport/summary */ export const getApiFinanceSalereportSummary = async (args: GetApiFinanceSalereportSummaryArgs, options?: GetApiFinanceSalereportSummaryOptions) => { const {baseUrl = "http://api.revelator.com", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args['options.fromDate'] != null) query.append("options.fromDate", String(args['options.fromDate'])) if (args['options.toDate'] != null) query.append("options.toDate", String(args['options.toDate'])) for (const item of args['options.distributors'] ?? []) query.append("options.distributors", String(item)) for (const item of args['options.countryCodes'] ?? []) query.append("options.countryCodes", String(item)) for (const item of args['options.countryIds'] ?? []) query.append("options.countryIds", String(item)) if (args['options.countryId'] != null) query.append("options.countryId", String(args['options.countryId'])) if (args['options.readyOnly'] != null) query.append("options.readyOnly", String(args['options.readyOnly'])) if (args['options.artistId'] != null) query.append("options.artistId", String(args['options.artistId'])) for (const item of args['options.artistIds'] ?? []) query.append("options.artistIds", String(item)) if (args['options.releaseId'] != null) query.append("options.releaseId", String(args['options.releaseId'])) for (const item of args['options.releaseIds'] ?? []) query.append("options.releaseIds", String(item)) if (args['options.trackId'] != null) query.append("options.trackId", String(args['options.trackId'])) for (const item of args['options.trackIds'] ?? []) query.append("options.trackIds", String(item)) if (args['options.payeeId'] != null) query.append("options.payeeId", String(args['options.payeeId'])) if (args['options.labelId'] != null) query.append("options.labelId", String(args['options.labelId'])) for (const item of args['options.labelIds'] ?? []) query.append("options.labelIds", String(item)) if (args['options.userStatementQueueId'] != null) query.append("options.userStatementQueueId", String(args['options.userStatementQueueId'])) if (args['options.storeId'] != null) query.append("options.storeId", String(args['options.storeId'])) for (const item of args['options.storeIds'] ?? []) query.append("options.storeIds", String(item)) for (const item of args['options.serviceIds'] ?? []) query.append("options.serviceIds", String(item)) if (args['options.saleItemTypeId'] != null) query.append("options.saleItemTypeId", String(args['options.saleItemTypeId'])) if (args['options.statementDisplayTypeId'] != null) query.append("options.statementDisplayTypeId", String(args['options.statementDisplayTypeId'])) if (args['options.id'] != null) query.append("options.id", String(args['options.id'])) for (const item of args['options.excludeIds'] ?? []) query.append("options.excludeIds", String(item)) if (args['options.excludeCountryId'] != null) query.append("options.excludeCountryId", String(args['options.excludeCountryId'])) if (args['options.groupBy'] != null) query.append("options.groupBy", String(args['options.groupBy'])) if (args['options.subGroupBy'] != null) query.append("options.subGroupBy", String(args['options.subGroupBy'])) if (args['options.subGroupPageSize'] != null) query.append("options.subGroupPageSize", String(args['options.subGroupPageSize'])) if (args['options.received'] != null) query.append("options.received", String(args['options.received'])) if (args['options.excludeResult'] != null) query.append("options.excludeResult", String(args['options.excludeResult'])) for (const item of args['options.deliveryTypeIds'] ?? []) query.append("options.deliveryTypeIds", String(item)) for (const item of args['options.deliveryTypeGroups'] ?? []) query.append("options.deliveryTypeGroups", String(item)) if (args['options.cityId'] != null) query.append("options.cityId", String(args['options.cityId'])) for (const item of args['options.cityIds'] ?? []) query.append("options.cityIds", String(item)) if (args['options.regionId'] != null) query.append("options.regionId", String(args['options.regionId'])) for (const item of args['options.regionIds'] ?? []) query.append("options.regionIds", String(item)) if (args['options.playlistId'] != null) query.append("options.playlistId", String(args['options.playlistId'])) for (const item of args['options.playlistIds'] ?? []) query.append("options.playlistIds", String(item)) if (args['options.selectAll'] != null) query.append("options.selectAll", String(args['options.selectAll'])) if (args['options.partOfPlaylist'] != null) query.append("options.partOfPlaylist", String(args['options.partOfPlaylist'])) if (args['options.yProperty'] != null) query.append("options.yProperty", String(args['options.yProperty'])) if (args['options.withDelta'] != null) query.append("options.withDelta", String(args['options.withDelta'])) if (args['options.processed'] != null) query.append("options.processed", String(args['options.processed'])) if (args['options.payeeStatus'] != null) query.append("options.payeeStatus", String(args['options.payeeStatus'])) if (args['options.payeeType'] != null) query.append("options.payeeType", String(args['options.payeeType'])) if (args['options.statementDeliveredType'] != null) query.append("options.statementDeliveredType", String(args['options.statementDeliveredType'])) if (args['options.approved'] != null) query.append("options.approved", String(args['options.approved'])) if (args['options.userStatementId'] != null) query.append("options.userStatementId", String(args['options.userStatementId'])) if (args['options.contractId'] != null) query.append("options.contractId", String(args['options.contractId'])) if (args['options.totalNetFilter'] != null) query.append("options.totalNetFilter", String(args['options.totalNetFilter'])) if (args['options.totalNet'] != null) query.append("options.totalNet", String(args['options.totalNet'])) if (args['options.isRoyaltyTokenPayee'] != null) query.append("options.isRoyaltyTokenPayee", String(args['options.isRoyaltyTokenPayee'])) if (args['options.isCrypto'] != null) query.append("options.isCrypto", String(args['options.isCrypto'])) if (args['options.getBalanceItemStatements'] != null) query.append("options.getBalanceItemStatements", String(args['options.getBalanceItemStatements'])) if (args['options.pageNumber'] != null) query.append("options.pageNumber", String(args['options.pageNumber'])) if (args['options.pageSize'] != null) query.append("options.pageSize", String(args['options.pageSize'])) if (args['options.orderByProperty'] != null) query.append("options.orderByProperty", String(args['options.orderByProperty'])) if (args['options.orderByDescending'] != null) query.append("options.orderByDescending", String(args['options.orderByDescending'])) if (args['options.searchText'] != null) query.append("options.searchText", String(args['options.searchText'])) const url = `${baseUrl.replace(/\/+$/, '')}/finance/salereport/summary${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(getApiFinanceSalereportSummaryResponse, await res.json()) };