import {z} from 'zod' export type GetApiV1CustomerProfilesCustomerProfileSidChannelEndpointAssignmentsArgs = {CustomerProfileSid: string, ChannelEndpointSid?: string | undefined, ChannelEndpointSids?: string | undefined, PageSize?: number | undefined, Page?: number | undefined, PageToken?: string | undefined}; export type GetApiV1CustomerProfilesCustomerProfileSidChannelEndpointAssignmentsOptions = {baseUrl?: string | undefined, accountSidAuthToken?: {username: string, password: string} | undefined, fetch?: typeof fetch | undefined}; export const trusthubV1CustomerProfileCustomerProfileChannelEndpointAssignment = z.object({sid: z.string().min(34).max(34).nullable().optional(), customer_profile_sid: z.string().min(34).max(34).nullable().optional(), account_sid: z.string().min(34).max(34).nullable().optional(), channel_endpoint_type: z.string().nullable().optional(), channel_endpoint_sid: z.string().min(34).max(34).nullable().optional(), date_created: z.string().nullable().optional(), url: z.string().nullable().optional()}); export const getApiV1CustomerProfilesCustomerProfileSidChannelEndpointAssignmentsResponse = z.object({results: z.array(trusthubV1CustomerProfileCustomerProfileChannelEndpointAssignment).optional(), meta: z.object({first_page_url: z.string().optional(), key: z.string().optional(), next_page_url: z.string().nullable().optional(), page: z.number().int().optional(), page_size: z.number().int().optional(), previous_page_url: z.string().nullable().optional(), url: z.string().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 }; /** * Retrieve a list of all Assigned Items for an account. * * GET /v1/CustomerProfiles/{CustomerProfileSid}/ChannelEndpointAssignments */ export const getApiV1CustomerProfilesCustomerProfileSidChannelEndpointAssignments = async (args: GetApiV1CustomerProfilesCustomerProfileSidChannelEndpointAssignmentsArgs, options?: GetApiV1CustomerProfilesCustomerProfileSidChannelEndpointAssignmentsOptions) => { const {baseUrl = "https://trusthub.twilio.com", fetch: fetchFn = fetch, accountSidAuthToken} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.ChannelEndpointSid != null) query.append("ChannelEndpointSid", String(args.ChannelEndpointSid)) if (args.ChannelEndpointSids != null) query.append("ChannelEndpointSids", String(args.ChannelEndpointSids)) if (args.PageSize != null) query.append("PageSize", String(args.PageSize)) if (args.Page != null) query.append("Page", String(args.Page)) if (args.PageToken != null) query.append("PageToken", String(args.PageToken)) if (accountSidAuthToken !== undefined) headers.set('authorization', `Basic ${btoa(`${accountSidAuthToken.username}:${accountSidAuthToken.password}`)}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/CustomerProfiles/${encodeURIComponent(String(args.CustomerProfileSid))}/ChannelEndpointAssignments${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(getApiV1CustomerProfilesCustomerProfileSidChannelEndpointAssignmentsResponse, await res.json()) };