import {z} from 'zod' export type GetApiServicesCoordinateLocationsLocationIdLinkAlertArgs = {'X-ST-Units'?: string | undefined, 'Accept-Language'?: string | undefined, locationId: string, Authorization: unknown, postalCode?: string | undefined, subscriptionId?: string | undefined}; export type GetApiServicesCoordinateLocationsLocationIdLinkAlertOptions = {baseUrl?: string | undefined, Bearer?: string | undefined, fetch?: typeof fetch | undefined}; export const error: z.ZodType = z.object({code: z.string().optional(), message: z.string().optional(), target: z.string().optional(), details: z.array(z.lazy(() => error)).optional()}); export const errorResponse = z.object({requestId: z.string().optional(), error: error.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 }; /** * Redirect to condent provider's alert detail link. If no query given, coordinate of the location ID is used. Otherwise the coordinate of subscription will be used. * * GET /services/coordinate/locations/{locationId}/link/alert */ export const getApiServicesCoordinateLocationsLocationIdLinkAlert = async (args: GetApiServicesCoordinateLocationsLocationIdLinkAlertArgs, options?: GetApiServicesCoordinateLocationsLocationIdLinkAlertOptions) => { const {baseUrl = "https://api.smartthings.com/v1", fetch: fetchFn = fetch, Bearer} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args['X-ST-Units'] != null) headers.set("X-ST-Units", String(args['X-ST-Units'])) if (args['Accept-Language'] != null) headers.set("Accept-Language", String(args['Accept-Language'])) if (args.Authorization != null) headers.set("Authorization", String(args.Authorization)) if (args.postalCode != null) query.append("postalCode", String(args.postalCode)) if (args.subscriptionId != null) query.append("subscriptionId", String(args.subscriptionId)) if (Bearer !== undefined) headers.set('authorization', `Bearer ${Bearer}`) const url = `${baseUrl.replace(/\/+$/, '')}/services/coordinate/locations/${encodeURIComponent(String(args.locationId))}/link/alert${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(errorResponse, await res.json()) };