import {z} from 'zod' export type AdaptekApiCommonConstantsEventHistoriesEventNotificationType = 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 58; export type AdaptekApiApplicationAdvisorAlertPreferencesCommandsUpsertAlertPreferenceCommand = {id?: number | undefined, eventTypeId?: AdaptekApiCommonConstantsEventHistoriesEventNotificationType | undefined, advisorId?: number | undefined, va?: boolean | undefined, sms?: boolean | undefined, email?: boolean | undefined, options?: (string | null) | undefined, options2?: (string | null) | undefined, createdUserId?: number | undefined}; export type CreateApiV1AdvisorsAdvisorIdAlertPreferencesArgs = {advisorId: number, body: AdaptekApiApplicationAdvisorAlertPreferencesCommandsUpsertAlertPreferenceCommand}; export type CreateApiV1AdvisorsAdvisorIdAlertPreferencesOptions = {baseUrl: string, oauth2?: string | undefined, fetch?: typeof fetch | undefined}; export const createApiV1AdvisorsAdvisorIdAlertPreferencesResponse = z.string(); 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 }; /** * Creates/updates an alert preference for an advisor * * POST /v1/Advisors/{advisorId}/AlertPreferences */ export const createApiV1AdvisorsAdvisorIdAlertPreferences = async (args: CreateApiV1AdvisorsAdvisorIdAlertPreferencesArgs, options: CreateApiV1AdvisorsAdvisorIdAlertPreferencesOptions) => { const {baseUrl, fetch: fetchFn = fetch, oauth2} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (oauth2 !== undefined) headers.set('authorization', `Bearer ${oauth2}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/Advisors/${encodeURIComponent(String(args.advisorId))}/AlertPreferences${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(createApiV1AdvisorsAdvisorIdAlertPreferencesResponse, await res.json()) };