import {z} from 'zod' export type NetworkSettings = {ingressTrafficAllowed?: ('INGRESS_TRAFFIC_ALLOWED_UNSPECIFIED' | 'INGRESS_TRAFFIC_ALLOWED_ALL' | 'INGRESS_TRAFFIC_ALLOWED_INTERNAL_ONLY' | 'INGRESS_TRAFFIC_ALLOWED_INTERNAL_AND_LB') | undefined}; export type TrafficSplit = {allocations?: {[key: string]: number} | undefined, shardBy?: ('UNSPECIFIED' | 'COOKIE' | 'IP' | 'RANDOM') | undefined}; export type Service = {generatedCustomerMetadata?: {[key: string]: unknown} | undefined, id?: string | undefined, labels?: {[key: string]: string} | undefined, name?: string | undefined, networkSettings?: NetworkSettings | undefined, split?: TrafficSplit | undefined}; export type PatchApiV1ProjectsProjectsIdLocationsLocationsIdApplicationsApplicationsIdServicesServicesIdArgs = {projectsId: string, locationsId: string, applicationsId: string, servicesId: string, migrateTraffic?: boolean | undefined, updateMask?: unknown | undefined, body: Service}; export type PatchApiV1ProjectsProjectsIdLocationsLocationsIdApplicationsApplicationsIdServicesServicesIdOptions = {baseUrl?: string | undefined, Oauth2?: string | undefined, Oauth2c?: string | undefined, fetch?: typeof fetch | undefined}; export const status = z.object({code: z.number().int().optional(), details: z.array(z.record(z.string(), z.unknown())).optional(), message: z.string().optional()}); export const operation = z.object({done: z.boolean().optional(), error: status.optional(), metadata: z.record(z.string(), z.unknown()).optional(), name: z.string().optional(), response: z.record(z.string(), z.unknown()).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 }; /** * Updates the configuration of the specified service. * * PATCH /v1/projects/{projectsId}/locations/{locationsId}/applications/{applicationsId}/services/{servicesId} */ export const patchApiV1ProjectsProjectsIdLocationsLocationsIdApplicationsApplicationsIdServicesServicesId = async (args: PatchApiV1ProjectsProjectsIdLocationsLocationsIdApplicationsApplicationsIdServicesServicesIdArgs, options?: PatchApiV1ProjectsProjectsIdLocationsLocationsIdApplicationsApplicationsIdServicesServicesIdOptions) => { const {baseUrl = "https://appengine.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 (args.migrateTraffic != null) query.append("migrateTraffic", String(args.migrateTraffic)) if (args.updateMask != null) query.append("updateMask", String(args.updateMask)) if (Oauth2 !== undefined) headers.set('authorization', `Bearer ${Oauth2}`) if (Oauth2c !== undefined) headers.set('authorization', `Bearer ${Oauth2c}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/projects/${encodeURIComponent(String(args.projectsId))}/locations/${encodeURIComponent(String(args.locationsId))}/applications/${encodeURIComponent(String(args.applicationsId))}/services/${encodeURIComponent(String(args.servicesId))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PATCH", 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(operation, await res.json()) };