import {z} from 'zod' export type GetApiFulfillmentsLocationsIdArgs = {id: string}; export type GetApiFulfillmentsLocationsIdOptions = {baseUrl?: string | undefined, BearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const fulfillmentsLocationAttributes = z.object({id: z.number().int().optional(), public_id: z.string().nullable().optional(), workspace_id: z.number().int().optional(), name: z.string().optional(), address_name: z.string().optional(), email_address: z.string().optional(), phone_number: z.string().nullable().optional(), sort_order: z.number().int().nullable().optional(), archived: z.boolean().optional(), external_app: z.boolean().nullable().optional(), created_at: z.string().nullable().optional(), updated_at: z.string().nullable().optional(), address: z.object({address_one: z.string().nullable().optional(), address_two: z.string().nullable().optional(), city: z.string().nullable().optional(), region: z.string().nullable().optional(), country: z.string().nullable().optional(), postal_code: z.string().nullable().optional()}).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 }; /** * Fetch Location * * GET /fulfillments/locations/{id} * * Also accepts auth: OAuth2 */ export const getApiFulfillmentsLocationsId = async (args: GetApiFulfillmentsLocationsIdArgs, options?: GetApiFulfillmentsLocationsIdOptions) => { const {baseUrl = "https://myworkspace.myclickfunnels.com/api/v2", fetch: fetchFn = fetch, BearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (BearerAuth !== undefined) headers.set('authorization', `Bearer ${BearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/fulfillments/locations/${encodeURIComponent(String(args.id))}${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(fulfillmentsLocationAttributes, await res.json()) };