import {z} from 'zod' export type StartAt = unknown; export type EndAt = unknown; export type Limit = number; export type Offset = number; export type Sort = unknown; export type GetApiNetworkServicesV1LocationAnalyticsSitesInsightsArgs = {'start-at': StartAt, 'end-at': EndAt, limit?: Limit | undefined, offset?: Offset | undefined, sort?: Sort | undefined}; export type GetApiNetworkServicesV1LocationAnalyticsSitesInsightsOptions = {baseUrl?: string | undefined, OAuth2?: string | undefined, fetch?: typeof fetch | undefined}; export const laSitesInsightsForAPI = z.object({id: z.string(), type: z.string(), siteId: z.string().optional(), siteName: z.string().optional(), newVisitorCount: z.number().int().optional(), recurringVisitorCount: z.number().int().optional(), totalVisitorCount: z.number().int().optional(), passerbyCount: z.number().int().optional(), visitDuration: z.number().int().optional()}); export const laSitesInsightsResponseForAPI = z.object({items: z.array(laSitesInsightsForAPI).optional(), offset: z.number().int().optional(), count: z.number().int().optional(), total: z.number().int().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 the insights for each site of a tenant for a given time range. * * GET /network-services/v1/location-analytics/sites/insights */ export const getApiNetworkServicesV1LocationAnalyticsSitesInsights = async (args: GetApiNetworkServicesV1LocationAnalyticsSitesInsightsArgs, options?: GetApiNetworkServicesV1LocationAnalyticsSitesInsightsOptions) => { const {baseUrl = "https://sso.common.cloud.hpe.com", fetch: fetchFn = fetch, OAuth2} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args['start-at'] != null) query.append("start-at", String(args['start-at'])) if (args['end-at'] != null) query.append("end-at", String(args['end-at'])) if (args.limit != null) query.append("limit", String(args.limit)) if (args.offset != null) query.append("offset", String(args.offset)) if (args.sort != null) query.append("sort", String(args.sort)) if (OAuth2 !== undefined) headers.set('authorization', `Bearer ${OAuth2}`) const url = `${baseUrl.replace(/\/+$/, '')}/network-services/v1/location-analytics/sites/insights${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(laSitesInsightsResponseForAPI, await res.json()) };