import {z} from 'zod' export type GetApiServiceConfigArgs = {_filter?: string | undefined, _order_by?: string | undefined, _offset?: number | undefined, _limit?: number | undefined, _page_token?: string | undefined, _fields?: string | undefined}; export type GetApiServiceConfigOptions = {baseUrl: string, BearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const apiPageInfo = z.object({offset: z.number().int().optional(), page_token: z.string().optional(), size: z.number().int().optional()}); 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 atlasntpNtpService = z.object({acl_override: z.boolean().optional(), cfg_details_override: z.boolean().optional(), created_at: z.string().optional(), deleted_at: z.string().optional(), id: z.string().optional(), identity_account_id: z.string().optional(), ntp_config: atlasntpNtpConfig.optional(), ntp_keys_override: z.boolean().optional(), ophids: z.array(z.string()).optional(), pool_id: z.string().optional(), service_id: z.string().optional(), updated_at: z.string().optional()}); export const atlasntpListServiceConfigResponse = z.object({page: apiPageInfo.optional(), results: z.array(atlasntpNtpService).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 }; /** * Lists all NTP service configuration records that belong to an account * * GET /service/config */ export const getApiServiceConfig = async (args: GetApiServiceConfigArgs, options: GetApiServiceConfigOptions) => { const {baseUrl, fetch: fetchFn = fetch, BearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args._filter != null) query.append("_filter", String(args._filter)) if (args._order_by != null) query.append("_order_by", String(args._order_by)) if (args._offset != null) query.append("_offset", String(args._offset)) if (args._limit != null) query.append("_limit", String(args._limit)) if (args._page_token != null) query.append("_page_token", String(args._page_token)) if (args._fields != null) query.append("_fields", String(args._fields)) if (BearerAuth !== undefined) headers.set("Authorization", BearerAuth) const url = `${baseUrl.replace(/\/+$/, '')}/service/config${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(atlasntpListServiceConfigResponse, await res.json()) };