import {z} from 'zod' export type GoogleProtobufDuration = {seconds?: number | undefined, nanos?: number | undefined}; export type StreemInternalApiGroupReservationWaitMetrics = {average_call_length?: GoogleProtobufDuration | undefined, estimated_wait_time?: GoogleProtobufDuration | undefined, queue_position?: number | undefined}; export type StreemInternalApiSaveGroupAverageCallLengthRequest = {company_sid?: string | undefined, group_sid?: string | undefined, metrics?: StreemInternalApiGroupReservationWaitMetrics | undefined, update_type?: ('WAIT_TIME_UPDATE_TYPE_CREATED' | 'WAIT_TIME_UPDATE_TYPE_REQUEUED' | 'WAIT_TIME_UPDATE_TYPE_POLLING' | 'WAIT_TIME_UPDATE_TYPE_USER_AVAILABILITY_UPDATED' | 'WAIT_TIME_UPDATE_TYPE_GROUP_RESERVATION_UPDATED' | 'WAIT_TIME_UPDATE_TYPE_INVALID') | undefined}; export type CreateApiV1CompaniesCompanyCodeOrSidGroupsReservationMetricsArgs = {company_code_or_sid: string, body: StreemInternalApiSaveGroupAverageCallLengthRequest}; export type CreateApiV1CompaniesCompanyCodeOrSidGroupsReservationMetricsOptions = {baseUrl?: string | undefined, apiKey?: {username: string, password: string} | undefined, fetch?: typeof fetch | undefined}; export const googleProtobufDuration = z.object({seconds: z.number().int().optional(), nanos: z.number().int().optional()}); export const streemInternalApiGroupReservationWaitMetrics = z.object({average_call_length: googleProtobufDuration.optional(), estimated_wait_time: googleProtobufDuration.optional(), queue_position: z.number().int().optional()}); export const streemInternalApiSaveGroupAverageCallLengthResponse = z.object({metrics: streemInternalApiGroupReservationWaitMetrics.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 }; /** * POST /v1/companies/{company_code_or_sid}/groups/reservation-metrics * * Also accepts auth: bearer-auth */ export const createApiV1CompaniesCompanyCodeOrSidGroupsReservationMetrics = async (args: CreateApiV1CompaniesCompanyCodeOrSidGroupsReservationMetricsArgs, options?: CreateApiV1CompaniesCompanyCodeOrSidGroupsReservationMetricsOptions) => { const {baseUrl = "https://api.prod-us.streem.cloud", fetch: fetchFn = fetch, apiKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (apiKey !== undefined) headers.set('authorization', `Basic ${btoa(`${apiKey.username}:${apiKey.password}`)}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/companies/${encodeURIComponent(String(args.company_code_or_sid))}/groups/reservation-metrics${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(streemInternalApiSaveGroupAverageCallLengthResponse, await res.json()) };