import {z} from 'zod' export type GetApiAccountsAidCustomersSettingsArgs = {aid: unknown}; export type GetApiAccountsAidCustomersSettingsOptions = {baseUrl?: string | undefined, JWT?: string | undefined, fetch?: typeof fetch | undefined}; export const customersMfaSettings = z.object({enabled: z.boolean(), login: z.object({challenge_type: z.literal("oob"), oob_channel: z.enum(["sms", "email"])}), login_recovery: z.object({challenge_type: z.literal("oob"), oob_channel: z.enum(["sms", "email"])})}); export const autoTokenType = z.object({type: z.enum(["SHA256", "HMAC-SHA256"])}); export const customersSettings = z.object({users: z.object({head: z.object({enabled: z.boolean()}).optional(), phone_number_validation: z.object({allow_duplicates: z.boolean()}).optional(), customer_id_format: z.enum(["uuid", "sequence"]), mfa: customersMfaSettings.optional(), verifications: z.object({phone_number: z.literal("sms").optional()}).optional()}).optional(), auto_tokens: z.object({phone_number: z.array(autoTokenType).optional(), email: z.array(autoTokenType).optional()}).optional(), tokens: z.object({event_expiry: z.array(z.object({status: z.string(), time_to_live: z.number().int()})).optional()}).optional(), attributes: z.array(z.object({name: z.string(), type: z.enum(["string", "integer", "real", "boolean", "phonenumber", "email", "date", "date-time"]), multiple_values: z.boolean().optional(), private: z.boolean().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 }; /** * aid_customers_atributes_get * * GET /accounts/{aid}/customers/settings */ export const getApiAccountsAidCustomersSettings = async (args: GetApiAccountsAidCustomersSettingsArgs, options?: GetApiAccountsAidCustomersSettingsOptions) => { const {baseUrl = "https://api.dintero.com/v1", fetch: fetchFn = fetch, JWT} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (JWT !== undefined) headers.set('authorization', `Bearer ${JWT}`) const url = `${baseUrl.replace(/\/+$/, '')}/accounts/${encodeURIComponent(String(args.aid))}/customers/settings${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(customersSettings, await res.json()) };