import {z} from 'zod' export type ApiOpsApiClientOwnerDTO = {type?: ('CONSUMER' | 'APPLICATION') | undefined, key?: string | undefined}; export type SecretVersionRequest = {materialType?: ('LOCAL_SECRET' | 'SECRET_REFERENCE') | undefined, generate?: boolean | undefined, value?: string | undefined, reference?: string | undefined, label?: string | undefined, validFrom?: string | undefined, expiresAt?: string | undefined, graceWindowSeconds?: number | undefined, storageMode?: ('ENCRYPTED' | 'HASHED') | undefined}; export type ApiOpsApiClientCreateDTO = {owner?: ApiOpsApiClientOwnerDTO | undefined, organizationCode?: string | undefined, description?: string | undefined, clientId?: string | undefined, validFrom?: string | undefined, expiresAt?: string | undefined, allowedGrantTypes?: Array | undefined, tokenEndpointAuthMethod?: string | undefined, redirectUris?: Array | undefined, tokenIssuanceProfile?: string | undefined, tokenNeverExpires?: boolean | undefined, tokenExpiresInAmount?: number | undefined, tokenExpiresInUnit?: ('MILLI_SECONDS' | 'SECONDS' | 'MINUTES' | 'HOURS' | 'DAYS' | 'WEEKS' | 'MONTHS' | 'YEARS') | undefined, refreshTokenAllowed?: boolean | undefined, refreshTokenCount?: number | undefined, refreshTokenExpiresInAmount?: number | undefined, refreshTokenExpiresInUnit?: ('MILLI_SECONDS' | 'SECONDS' | 'MINUTES' | 'HOURS' | 'DAYS' | 'WEEKS' | 'MONTHS' | 'YEARS') | undefined, jwtSignatureAlgorithm?: string | undefined, secret?: SecretVersionRequest | undefined, version?: number | undefined}; export type UpdateApiApiopsProjectsProjectNameApiClientsApiClientKeyArgs = {projectName: string, apiClientKey: string, body: ApiOpsApiClientCreateDTO}; export type UpdateApiApiopsProjectsProjectNameApiClientsApiClientKeyOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const apiOpsApiClientOwnerDTO = z.object({type: z.enum(["CONSUMER", "APPLICATION"]).optional(), key: z.string().optional()}); export const apiOpsResponseApiClientSecretVersion = z.object({versionId: z.string().optional(), label: z.string().optional(), status: z.enum(["PENDING_ACTIVATION", "ACTIVE", "GRACE", "REVOKED"]).optional(), materialType: z.string().optional(), storageMode: z.enum(["ENCRYPTED", "HASHED"]).optional(), recoveryState: z.enum(["AVAILABLE", "UNAVAILABLE", "SHREDDED"]).optional(), validFrom: z.string().optional(), expiresAt: z.string().optional(), graceUntil: z.string().optional(), createdAt: z.string().optional(), revokedAt: z.string().optional(), revokedReason: z.string().optional(), version: z.number().int().optional()}); export const apiOpsResponseApiClient = z.object({apiClientKey: z.string().optional(), clientId: z.string().optional(), description: z.string().optional(), owner: apiOpsApiClientOwnerDTO.optional(), organizationCode: z.string().optional(), operationalState: z.enum(["DRAFT", "ACTIVE", "SUSPENDED", "REVOKED"]).optional(), readiness: z.enum(["READY", "PENDING_SECRET", "UNRESOLVED_DEPENDENCY"]).optional(), validFrom: z.string().optional(), expiresAt: z.string().optional(), allowedGrantTypes: z.array(z.string()).optional(), tokenEndpointAuthMethod: z.string().optional(), redirectUris: z.array(z.string()).optional(), tokenIssuanceProfile: z.string().optional(), tokenNeverExpires: z.boolean().optional(), tokenExpiresInAmount: z.number().int().optional(), tokenExpiresInUnit: z.enum(["MILLI_SECONDS", "SECONDS", "MINUTES", "HOURS", "DAYS", "WEEKS", "MONTHS", "YEARS"]).optional(), refreshTokenAllowed: z.boolean().optional(), refreshTokenCount: z.number().int().optional(), refreshTokenExpiresInAmount: z.number().int().optional(), refreshTokenExpiresInUnit: z.enum(["MILLI_SECONDS", "SECONDS", "MINUTES", "HOURS", "DAYS", "WEEKS", "MONTHS", "YEARS"]).optional(), jwtSignatureAlgorithm: z.string().optional(), revokedAt: z.string().optional(), revokedBy: z.string().optional(), revokedReason: z.string().optional(), lifecycleRevision: z.number().int().optional(), version: z.number().int().optional(), secretVersions: z.array(apiOpsResponseApiClientSecretVersion).optional()}); export const environment = z.object({name: z.string().optional(), acknowledged: z.boolean().optional(), detail: z.string().optional()}); export const apiOpsRuntimeDeploymentDTO = z.object({state: z.enum(["IN_SYNC", "DEGRADED"]).optional(), environments: z.array(environment).optional()}); export const apiOpsResponseApiClientMutation = z.object({apiClient: apiOpsResponseApiClient.optional(), runtimeDeployment: apiOpsRuntimeDeploymentDTO.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 }; /** * Update an API client * * PUT /apiops/projects/{projectName}/api-clients/{apiClientKey} */ export const updateApiApiopsProjectsProjectNameApiClientsApiClientKey = async (args: UpdateApiApiopsProjectsProjectNameApiClientsApiClientKeyArgs, options?: UpdateApiApiopsProjectsProjectNameApiClientsApiClientKeyOptions) => { const {baseUrl = "http://167.86.118.166:32080", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") const url = `${baseUrl.replace(/\/+$/, '')}/apiops/projects/${encodeURIComponent(String(args.projectName))}/api-clients/${encodeURIComponent(String(args.apiClientKey))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PUT", 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(apiOpsResponseApiClientMutation, await res.json()) };