import {z} from 'zod' export type GetApiV1ProjectsProjectIdRcsSendersSenderIdTestNumbersTestNumberCapabilitiesArgs = {projectId: string, senderId: string, testNumber: string}; export type GetApiV1ProjectsProjectIdRcsSendersSenderIdTestNumbersTestNumberCapabilitiesOptions = {baseUrl?: string | undefined, BasicAuth?: {username: string, password: string} | undefined, BearerAuth?: string | undefined, OAuth2Production?: string | undefined, fetch?: typeof fetch | undefined}; export const rcsTestNumberCapabilitiesFeaturesEnum = z.enum(["ACTION_COMPOSE", "ACTION_CREATE_CALENDAR_EVENT", "ACTION_DIAL", "ACTION_OPEN_URL", "ACTION_OPEN_URL_IN_WEBVIEW", "ACTION_SHARE_LOCATION", "ACTION_VIEW_LOCATION", "REVOCATION", "RICHCARD_CAROUSEL", "RICHCARD_STANDALONE", "FEATURE_UNSPECIFIED", "UNRECOGNIZED"]); export const rcsTestNumberCapabilitiesDto = z.object({features: z.array(rcsTestNumberCapabilitiesFeaturesEnum)}); 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 test number capabilities of sender for project * * GET /v1/projects/{projectId}/rcs/senders/{senderId}/testNumbers/{testNumber}/capabilities */ export const getApiV1ProjectsProjectIdRcsSendersSenderIdTestNumbersTestNumberCapabilities = async (args: GetApiV1ProjectsProjectIdRcsSendersSenderIdTestNumbersTestNumberCapabilitiesArgs, options?: GetApiV1ProjectsProjectIdRcsSendersSenderIdTestNumbersTestNumberCapabilitiesOptions) => { const {baseUrl = "https://provisioning.api.sinch.com", fetch: fetchFn = fetch, BasicAuth, BearerAuth, OAuth2Production} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (BasicAuth !== undefined) headers.set('authorization', `Basic ${btoa(`${BasicAuth.username}:${BasicAuth.password}`)}`) if (BearerAuth !== undefined) headers.set('authorization', `Bearer ${BearerAuth}`) if (OAuth2Production !== undefined) headers.set('authorization', `Bearer ${OAuth2Production}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/projects/${encodeURIComponent(String(args.projectId))}/rcs/senders/${encodeURIComponent(String(args.senderId))}/testNumbers/${encodeURIComponent(String(args.testNumber))}/capabilities${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(rcsTestNumberCapabilitiesDto, await res.json()) };