import {z} from 'zod' export type GetApiV1CustomersCustomersIdPolicySchemasArgs = {customersId: string, filter?: string | undefined, pageSize?: number | undefined, pageToken?: string | undefined}; export type GetApiV1CustomersCustomersIdPolicySchemasOptions = {baseUrl?: string | undefined, Oauth2?: string | undefined, Oauth2c?: string | undefined, fetch?: typeof fetch | undefined}; export const googleChromePolicyVersionsV1AdditionalTargetKeyName = z.object({key: z.string().optional(), keyDescription: z.string().optional()}); export const proto2EnumValueDescriptorProto = z.object({name: z.string().optional(), number: z.number().int().optional()}); export const proto2EnumDescriptorProto = z.object({name: z.string().optional(), value: z.array(proto2EnumValueDescriptorProto).optional(), visibility: z.enum(["VISIBILITY_UNSET", "VISIBILITY_LOCAL", "VISIBILITY_EXPORT"]).optional()}); export const proto2FieldDescriptorProto = z.object({defaultValue: z.string().optional(), jsonName: z.string().optional(), label: z.enum(["LABEL_OPTIONAL", "LABEL_REPEATED", "LABEL_REQUIRED"]).optional(), name: z.string().optional(), number: z.number().int().optional(), oneofIndex: z.number().int().optional(), proto3Optional: z.boolean().optional(), type: z.enum(["TYPE_DOUBLE", "TYPE_FLOAT", "TYPE_INT64", "TYPE_UINT64", "TYPE_INT32", "TYPE_FIXED64", "TYPE_FIXED32", "TYPE_BOOL", "TYPE_STRING", "TYPE_GROUP", "TYPE_MESSAGE", "TYPE_BYTES", "TYPE_UINT32", "TYPE_ENUM", "TYPE_SFIXED32", "TYPE_SFIXED64", "TYPE_SINT32", "TYPE_SINT64"]).optional(), typeName: z.string().optional()}); export const proto2OneofDescriptorProto = z.object({name: z.string().optional()}); export const proto2DescriptorProto: z.ZodType = z.object({enumType: z.array(proto2EnumDescriptorProto).optional(), field: z.array(proto2FieldDescriptorProto).optional(), name: z.string().optional(), nestedType: z.array(z.lazy(() => proto2DescriptorProto)).optional(), oneofDecl: z.array(proto2OneofDescriptorProto).optional(), visibility: z.enum(["VISIBILITY_UNSET", "VISIBILITY_LOCAL", "VISIBILITY_EXPORT"]).optional()}); export const proto2FileDescriptorProto = z.object({editionDeprecated: z.string().optional(), enumType: z.array(proto2EnumDescriptorProto).optional(), messageType: z.array(proto2DescriptorProto).optional(), name: z.string().optional(), optionDependency: z.array(z.string()).optional(), package: z.string().optional(), syntax: z.string().optional()}); export const googleChromePolicyVersionsV1NumericRangeConstraint = z.object({maximum: z.string().optional(), minimum: z.string().optional()}); export const googleChromePolicyVersionsV1UploadedFileConstraints = z.object({sizeLimitBytes: z.string().optional(), supportedContentTypes: z.array(z.enum(["CONTENT_TYPE_UNSPECIFIED", "CONTENT_TYPE_PLAIN_TEXT", "CONTENT_TYPE_HTML", "CONTENT_TYPE_IMAGE_JPEG", "CONTENT_TYPE_IMAGE_GIF", "CONTENT_TYPE_IMAGE_PNG", "CONTENT_TYPE_JSON", "CONTENT_TYPE_ZIP", "CONTENT_TYPE_GZIP", "CONTENT_TYPE_CSV", "CONTENT_TYPE_YAML", "CONTENT_TYPE_IMAGE_WEBP"])).optional()}); export const googleChromePolicyVersionsV1FieldConstraints = z.object({numericRangeConstraint: googleChromePolicyVersionsV1NumericRangeConstraint.optional(), uploadedFileConstraints: googleChromePolicyVersionsV1UploadedFileConstraints.optional()}); export const googleChromePolicyVersionsV1PolicySchemaFieldDependencies = z.object({sourceField: z.string().optional(), sourceFieldValue: z.string().optional()}); export const googleChromePolicyVersionsV1PolicySchemaFieldKnownValueDescription = z.object({description: z.string().optional(), fieldDependencies: z.array(googleChromePolicyVersionsV1PolicySchemaFieldDependencies).optional(), value: z.string().optional()}); export const googleChromePolicyVersionsV1PolicySchemaRequiredItems = z.object({fieldConditions: z.array(z.string()).optional(), requiredFields: z.array(z.string()).optional()}); export const googleChromePolicyVersionsV1PolicySchemaFieldDescription: z.ZodType = z.object({defaultValue: z.unknown(), description: z.string().optional(), field: z.string().optional(), fieldConstraints: googleChromePolicyVersionsV1FieldConstraints.optional(), fieldDependencies: z.array(googleChromePolicyVersionsV1PolicySchemaFieldDependencies).optional(), fieldDescription: z.string().optional(), inputConstraint: z.string().optional(), knownValueDescriptions: z.array(googleChromePolicyVersionsV1PolicySchemaFieldKnownValueDescription).optional(), name: z.string().optional(), nestedFieldDescriptions: z.array(z.lazy(() => googleChromePolicyVersionsV1PolicySchemaFieldDescription)).optional(), requiredItems: z.array(googleChromePolicyVersionsV1PolicySchemaRequiredItems).optional()}); export const googleChromePolicyVersionsV1PolicySchemaNoticeDescription = z.object({acknowledgementRequired: z.boolean().optional(), field: z.string().optional(), noticeMessage: z.string().optional(), noticeValue: z.string().optional()}); export const googleTypeDate = z.object({day: z.number().int().optional(), month: z.number().int().optional(), year: z.number().int().optional()}); export const googleChromePolicyVersionsV1PolicyApiLifecycle = z.object({deprecatedInFavorOf: z.array(z.string()).optional(), description: z.string().optional(), endSupport: googleTypeDate.optional(), policyApiLifecycleStage: z.enum(["API_UNSPECIFIED", "API_PREVIEW", "API_DEVELOPMENT", "API_CURRENT", "API_DEPRECATED"]).optional(), scheduledToDeprecatePolicies: z.array(z.string()).optional()}); export const googleChromePolicyVersionsV1PolicySchema = z.object({accessRestrictions: z.array(z.string()).optional(), additionalTargetKeyNames: z.array(googleChromePolicyVersionsV1AdditionalTargetKeyName).optional(), categoryTitle: z.string().optional(), definition: proto2FileDescriptorProto.optional(), fieldDescriptions: z.array(googleChromePolicyVersionsV1PolicySchemaFieldDescription).optional(), name: z.string().optional(), notices: z.array(googleChromePolicyVersionsV1PolicySchemaNoticeDescription).optional(), policyApiLifecycle: googleChromePolicyVersionsV1PolicyApiLifecycle.optional(), policyDescription: z.string().optional(), schemaName: z.string().optional(), supportUri: z.string().optional(), supportedPlatforms: z.array(z.enum(["PLATFORM_UNSPECIFIED", "CHROME_OS", "CHROME_BROWSER", "CHROME_BROWSER_FOR_ANDROID", "CHROME_BROWSER_FOR_IOS"])).optional(), validTargetResources: z.array(z.enum(["TARGET_RESOURCE_UNSPECIFIED", "ORG_UNIT", "GROUP"])).optional()}); export const googleChromePolicyVersionsV1ListPolicySchemasResponse = z.object({nextPageToken: z.string().optional(), policySchemas: z.array(googleChromePolicyVersionsV1PolicySchema).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 a list of policy schemas that match a specified filter value for a given customer. * * GET /v1/customers/{customersId}/policySchemas * * Also accepts auth: Oauth2 + Oauth2c */ export const getApiV1CustomersCustomersIdPolicySchemas = async (args: GetApiV1CustomersCustomersIdPolicySchemasArgs, options?: GetApiV1CustomersCustomersIdPolicySchemasOptions) => { const {baseUrl = "https://chromepolicy.googleapis.com", fetch: fetchFn = fetch, Oauth2, Oauth2c} = 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.pageSize != null) query.append("pageSize", String(args.pageSize)) if (args.pageToken != null) query.append("pageToken", String(args.pageToken)) 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))}/policySchemas${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(googleChromePolicyVersionsV1ListPolicySchemasResponse, await res.json()) };