import {z} from 'zod' export type AtlasntpNtpAccessControlRules = {acl?: string | undefined, created_at?: string | undefined, deleted_at?: string | undefined, id?: unknown | undefined, kod?: boolean | undefined, limited?: boolean | undefined, nomodify?: boolean | undefined, nopeer?: boolean | undefined, noquery?: boolean | undefined, notrap?: boolean | undefined, updated_at?: string | undefined}; export type AtlasntpNtpConfigDetails = {address?: string | undefined, authentication?: boolean | undefined, authentication_key_type?: string | undefined, authentication_key_value?: string | undefined, burst?: boolean | undefined, created_at?: string | undefined, deleted_at?: string | undefined, iburst?: boolean | undefined, id?: unknown | undefined, is_pool?: boolean | undefined, preferred?: boolean | undefined, updated_at?: string | undefined, upstream_key_num?: number | undefined}; export type AtlasntpNtpKeys = {comments?: string | undefined, created_at?: string | undefined, deleted_at?: string | undefined, id?: unknown | undefined, identity_account_id?: string | undefined, key_num?: number | undefined, type?: string | undefined, updated_at?: string | undefined, upstream?: boolean | undefined, value?: string | undefined}; export type AtlasntpNtpConfig = {avg?: number | undefined, created_at?: string | undefined, deleted_at?: string | undefined, id?: string | undefined, min?: number | undefined, monitor?: number | undefined, ntp_access_control_rules?: Array | undefined, ntp_config_details?: Array | undefined, ntp_keys?: Array | undefined, previous_config_id?: string | undefined, updated_at?: string | undefined, version?: unknown | undefined}; export type AtlasntpSetAccountConfigRequest = {ntp_config?: AtlasntpNtpConfig | undefined}; export type CreateApiAccountConfigArgs = {body: AtlasntpSetAccountConfigRequest}; export type CreateApiAccountConfigOptions = {baseUrl: string, BearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const atlasntpNtpAccessControlRules = z.object({acl: z.string().optional(), created_at: z.string().optional(), deleted_at: z.string().optional(), id: z.string().optional(), kod: z.boolean().optional(), limited: z.boolean().optional(), nomodify: z.boolean().optional(), nopeer: z.boolean().optional(), noquery: z.boolean().optional(), notrap: z.boolean().optional(), updated_at: z.string().optional()}); export const atlasntpNtpConfigDetails = z.object({address: z.string().optional(), authentication: z.boolean().optional(), authentication_key_type: z.string().optional(), authentication_key_value: z.string().optional(), burst: z.boolean().optional(), created_at: z.string().optional(), deleted_at: z.string().optional(), iburst: z.boolean().optional(), id: z.string().optional(), is_pool: z.boolean().optional(), preferred: z.boolean().optional(), updated_at: z.string().optional(), upstream_key_num: z.number().int().optional()}); export const atlasntpNtpKeys = z.object({comments: z.string().optional(), created_at: z.string().optional(), deleted_at: z.string().optional(), id: z.string().optional(), identity_account_id: z.string().optional(), key_num: z.number().int().optional(), type: z.string().optional(), updated_at: z.string().optional(), upstream: z.boolean().optional(), value: z.string().optional()}); export const atlasntpNtpConfig = z.object({avg: z.number().int().optional(), created_at: z.string().optional(), deleted_at: z.string().optional(), id: z.string().optional(), min: z.number().int().optional(), monitor: z.number().int().optional(), ntp_access_control_rules: z.array(atlasntpNtpAccessControlRules).optional(), ntp_config_details: z.array(atlasntpNtpConfigDetails).optional(), ntp_keys: z.array(atlasntpNtpKeys).optional(), previous_config_id: z.string().optional(), updated_at: z.string().optional(), version: z.string().optional()}); export const atlasntpNtpAccountConfig = z.object({created_at: z.string().optional(), id: z.string().optional(), identity_account_id: z.string().optional(), ntp_config: atlasntpNtpConfig.optional(), updated_at: z.string().optional()}); export const atlasntpSetAccountConfigResponse = z.object({account_config: atlasntpNtpAccountConfig.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 }; /** * Creates or updates the global default NTP configuration of the account. * * POST /account/config */ export const createApiAccountConfig = async (args: CreateApiAccountConfigArgs, options: CreateApiAccountConfigOptions) => { const {baseUrl, fetch: fetchFn = fetch, BearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (BearerAuth !== undefined) headers.set("Authorization", BearerAuth) const url = `${baseUrl.replace(/\/+$/, '')}/account/config${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(atlasntpSetAccountConfigResponse, await res.json()) };