import {z} from 'zod' export type CertificateRawData = {privateKey?: string | undefined, publicCertificate?: string | undefined}; export type ManagedCertificate = {lastRenewalTime?: unknown | undefined, status?: ('MANAGEMENT_STATUS_UNSPECIFIED' | 'OK' | 'PENDING' | 'FAILED_RETRYING_NOT_VISIBLE' | 'FAILED_PERMANENT' | 'FAILED_RETRYING_CAA_FORBIDDEN' | 'FAILED_RETRYING_CAA_CHECKING') | undefined}; export type AuthorizedCertificate = {certificateRawData?: CertificateRawData | undefined, displayName?: string | undefined, domainMappingsCount?: number | undefined, domainNames?: Array | undefined, expireTime?: unknown | undefined, id?: string | undefined, managedCertificate?: ManagedCertificate | undefined, name?: string | undefined, visibleDomainMappings?: Array | undefined}; export type CreateApiV1ProjectsProjectsIdLocationsLocationsIdApplicationsApplicationsIdAuthorizedCertificatesArgs = {projectsId: string, locationsId: string, applicationsId: string, body: AuthorizedCertificate}; export type CreateApiV1ProjectsProjectsIdLocationsLocationsIdApplicationsApplicationsIdAuthorizedCertificatesOptions = {baseUrl?: string | undefined, Oauth2?: string | undefined, Oauth2c?: string | undefined, fetch?: typeof fetch | undefined}; export const certificateRawData = z.object({privateKey: z.string().optional(), publicCertificate: z.string().optional()}); export const managedCertificate = z.object({lastRenewalTime: z.string().optional(), status: z.enum(["MANAGEMENT_STATUS_UNSPECIFIED", "OK", "PENDING", "FAILED_RETRYING_NOT_VISIBLE", "FAILED_PERMANENT", "FAILED_RETRYING_CAA_FORBIDDEN", "FAILED_RETRYING_CAA_CHECKING"]).optional()}); export const authorizedCertificate = z.object({certificateRawData: certificateRawData.optional(), displayName: z.string().optional(), domainMappingsCount: z.number().int().optional(), domainNames: z.array(z.string()).optional(), expireTime: z.string().optional(), id: z.string().optional(), managedCertificate: managedCertificate.optional(), name: z.string().optional(), visibleDomainMappings: z.array(z.string()).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 }; /** * Uploads the specified SSL certificate. * * POST /v1/projects/{projectsId}/locations/{locationsId}/applications/{applicationsId}/authorizedCertificates */ export const createApiV1ProjectsProjectsIdLocationsLocationsIdApplicationsApplicationsIdAuthorizedCertificates = async (args: CreateApiV1ProjectsProjectsIdLocationsLocationsIdApplicationsApplicationsIdAuthorizedCertificatesArgs, options?: CreateApiV1ProjectsProjectsIdLocationsLocationsIdApplicationsApplicationsIdAuthorizedCertificatesOptions) => { 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 (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))}/authorizedCertificates${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(authorizedCertificate, await res.json()) };