import {z} from 'zod' export type GoogleChromePolicyVersionsV1PolicyTargetKey = {additionalTargetKeys?: {[key: string]: string} | undefined, targetResource?: string | undefined}; export type GoogleChromePolicyVersionsV1ResolveRequest = {pageSize?: number | undefined, pageToken?: string | undefined, policySchemaFilter?: string | undefined, policyTargetKey?: GoogleChromePolicyVersionsV1PolicyTargetKey | undefined}; export type CreateApiV1CustomersCustomersIdPoliciesResolveArgs = {customersId: string, body: GoogleChromePolicyVersionsV1ResolveRequest}; export type CreateApiV1CustomersCustomersIdPoliciesResolveOptions = {baseUrl?: string | undefined, Oauth2?: string | undefined, Oauth2c?: string | undefined, fetch?: typeof fetch | undefined}; export const googleChromePolicyVersionsV1PolicyTargetKey = z.object({additionalTargetKeys: z.record(z.string(), z.string()).optional(), targetResource: z.string().optional()}); export const googleChromePolicyVersionsV1PolicyValue = z.object({policySchema: z.string().optional(), value: z.record(z.string(), z.unknown()).optional()}); export const googleChromePolicyVersionsV1ResolvedPolicy = z.object({addedSourceKey: googleChromePolicyVersionsV1PolicyTargetKey.optional(), sourceKey: googleChromePolicyVersionsV1PolicyTargetKey.optional(), targetKey: googleChromePolicyVersionsV1PolicyTargetKey.optional(), value: googleChromePolicyVersionsV1PolicyValue.optional()}); export const googleChromePolicyVersionsV1ResolveResponse = z.object({nextPageToken: z.string().optional(), resolvedPolicies: z.array(googleChromePolicyVersionsV1ResolvedPolicy).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 }; /** * Gets the resolved policy values for a list of policies that match a search query. * * POST /v1/customers/{customersId}/policies:resolve * * Also accepts auth: Oauth2 + Oauth2c */ export const createApiV1CustomersCustomersIdPoliciesResolve = async (args: CreateApiV1CustomersCustomersIdPoliciesResolveArgs, options?: CreateApiV1CustomersCustomersIdPoliciesResolveOptions) => { const {baseUrl = "https://chromepolicy.googleapis.com", fetch: fetchFn = fetch, Oauth2, Oauth2c} = 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}`) if (Oauth2c !== undefined) headers.set('authorization', `Bearer ${Oauth2c}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/customers/${encodeURIComponent(String(args.customersId))}/policies:resolve${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(googleChromePolicyVersionsV1ResolveResponse, await res.json()) };