import {z} from 'zod' export type GetApiNetworksDomainsTrackingDomainIdArgs = {domainId: number}; export type GetApiNetworksDomainsTrackingDomainIdOptions = {baseUrl?: string | undefined, APIKey?: string | undefined, fetch?: typeof fetch | undefined}; export const trackingDomain = z.object({network_tracking_domain_id: z.number().int().optional(), network_id: z.number().int().optional(), url: z.string().optional(), is_primary_domain: z.boolean().optional(), domain_status: z.enum(["active", "deleted"]).optional(), is_ssl_enabled: z.boolean().optional(), is_unassignable: z.boolean().optional(), public_notes: z.string().optional(), time_created: z.number().int().optional(), time_saved: z.number().int().optional(), ownership: z.string().optional(), html_static_redirect: z.string().optional(), url_redirect: 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 }; /** * Get Tracking Domain * * GET /networks/domains/tracking/{domainId} */ export const getApiNetworksDomainsTrackingDomainId = async (args: GetApiNetworksDomainsTrackingDomainIdArgs, options?: GetApiNetworksDomainsTrackingDomainIdOptions) => { const {baseUrl = "https://api.eflow.team/v1", fetch: fetchFn = fetch, APIKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (APIKey !== undefined) headers.set("X-Eflow-Api-Key", APIKey) const url = `${baseUrl.replace(/\/+$/, '')}/networks/domains/tracking/${encodeURIComponent(String(args.domainId))}${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(trackingDomain, await res.json()) };