import {z} from 'zod' export type MetadataLabels = {[key: string]: string}; export type CustomDomainMetadata = {createdAt?: string | undefined, updatedAt?: string | undefined, createdBy?: string | undefined, updatedBy?: string | undefined, displayName?: string | undefined, labels?: MetadataLabels | undefined, name?: string | undefined, sharedFromWorkspace?: string | undefined, workspace?: string | undefined}; export type CustomDomainSpec = {cnameRecords?: string | undefined, domainType?: ('previews' | 'applications') | undefined, fallbackPreviewId?: string | undefined, lastVerifiedAt?: string | undefined, region?: string | undefined, status?: ('pending' | 'verified' | 'failed') | undefined, subjectAlternativeNames?: Array<{[key: string]: unknown}> | undefined, txtRecords?: {[key: string]: string} | undefined, verificationError?: string | undefined}; export type CustomDomain = {metadata: CustomDomainMetadata, spec: CustomDomainSpec}; export type CreateApiApplicationsApplicationNameCustomdomainsArgs = {applicationName: string, body: CustomDomain}; export type CreateApiApplicationsApplicationNameCustomdomainsOptions = {baseUrl?: string | undefined, OAuth2?: string | undefined, fetch?: typeof fetch | undefined}; export const metadataLabels = z.record(z.string(), z.string()); export const customDomainMetadata = z.object({createdAt: z.string().optional(), updatedAt: z.string().optional(), createdBy: z.string().optional(), updatedBy: z.string().optional(), displayName: z.string().optional(), labels: metadataLabels.optional(), name: z.string().optional(), sharedFromWorkspace: z.string().optional(), workspace: z.string().optional()}); export const customDomainSpec = z.object({cnameRecords: z.string().optional(), domainType: z.enum(["previews", "applications"]).optional(), fallbackPreviewId: z.string().optional(), lastVerifiedAt: z.string().optional(), region: z.string().optional(), status: z.enum(["pending", "verified", "failed"]).optional(), subjectAlternativeNames: z.array(z.record(z.string(), z.unknown())).optional(), txtRecords: z.record(z.string(), z.string()).optional(), verificationError: z.string().optional()}); export const customDomain = z.object({metadata: customDomainMetadata, spec: customDomainSpec}); 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 }; /** * Create application custom domain * * POST /applications/{applicationName}/customdomains * * Also accepts auth: ApiKeyAuth */ export const createApiApplicationsApplicationNameCustomdomains = async (args: CreateApiApplicationsApplicationNameCustomdomainsArgs, options?: CreateApiApplicationsApplicationNameCustomdomainsOptions) => { const {baseUrl = "https://api.blaxel.ai/v0", fetch: fetchFn = fetch, OAuth2} = 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}`) const url = `${baseUrl.replace(/\/+$/, '')}/applications/${encodeURIComponent(String(args.applicationName))}/customdomains${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(customDomain, await res.json()) };