import {z} from 'zod' export type GetApiAnalyticsMonthlyActiveEventCreatorsWithMoreThanXEventsArgs = {startDate: string, endDate: string, timezoneOffset: number}; export type GetApiAnalyticsMonthlyActiveEventCreatorsWithMoreThanXEventsOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; export const getApiAnalyticsMonthlyActiveEventCreatorsWithMoreThanXEventsResponse = z.array(z.object({count: z.number().int().optional(), date: 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 }; /** * Gets the daily count of monthly active event creators over a date range with more than x events * * GET /analytics/monthly-active-event-creators-with-more-than-x-events */ export const getApiAnalyticsMonthlyActiveEventCreatorsWithMoreThanXEvents = async (args: GetApiAnalyticsMonthlyActiveEventCreatorsWithMoreThanXEventsArgs, options: GetApiAnalyticsMonthlyActiveEventCreatorsWithMoreThanXEventsOptions) => { const {baseUrl, fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.startDate != null) query.append("startDate", String(args.startDate)) if (args.endDate != null) query.append("endDate", String(args.endDate)) if (args.timezoneOffset != null) query.append("timezoneOffset", String(args.timezoneOffset)) const url = `${baseUrl.replace(/\/+$/, '')}/analytics/monthly-active-event-creators-with-more-than-x-events${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(getApiAnalyticsMonthlyActiveEventCreatorsWithMoreThanXEventsResponse, await res.json()) };