import {z} from 'zod' export type GetApiV1NamespacesTenantMetaNamespaceScmCredentialsUuidArgs = {'tenant_meta.namespace': string, uuid: string, 'get_parameters.mask'?: string | undefined}; export type GetApiV1NamespacesTenantMetaNamespaceScmCredentialsUuidOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const v1IndexData = z.object({data: z.array(z.string()).optional(), search_score: z.number().optional(), tenant: z.string().optional(), will_be_deleted_at: z.string().optional()}); export const googleprotobufAny = z.object({"@type": z.string().optional()}).and(z.record(z.string(), z.unknown())); export const v1Meta = z.object({annotations: z.record(z.string(), z.string()).optional(), create_time: z.string().optional(), created_by: z.string().optional(), description: z.string().optional(), index_data: v1IndexData.optional(), kind: z.string().optional(), name: z.string(), parent_kind: z.string().optional(), parent_uuid: z.string().optional(), references: z.record(z.string(), googleprotobufAny).optional(), tags: z.array(z.string()).optional(), update_time: z.string().optional(), updated_by: z.string().optional(), upsert_time: z.string().optional(), version: z.string().optional()}); export const v1PlatformSource = z.enum(["PLATFORM_SOURCE_UNSPECIFIED", "PLATFORM_SOURCE_GITHUB", "PLATFORM_SOURCE_GITLAB", "PLATFORM_SOURCE_GITSERVER", "PLATFORM_SOURCE_BITBUCKET", "PLATFORM_SOURCE_BINARY", "PLATFORM_SOURCE_HUGGING_FACE", "PLATFORM_SOURCE_AZURE", "PLATFORM_SOURCE_ARCHIVE", "PLATFORM_SOURCE_EXTERNAL_AI_SERVICE", "PLATFORM_SOURCE_GITHUB_ENTERPRISE"]); export const specSCMCredentialStatusState = z.enum(["STATE_UNSPECIFIED", "STATE_SUCCESS", "STATE_FAIL"]); export const specSCMCredentialStatus = z.object({error_message: z.string().optional(), last_tested_at: z.string().optional(), state: specSCMCredentialStatusState.optional()}); export const v1SCMCredentialSpec = z.object({access_token: z.string(), description: z.string().optional(), platform_source: v1PlatformSource, scm_credential_status: specSCMCredentialStatus.optional(), target_url: z.string()}); export const v1TenantMeta = z.object({namespace: z.string()}); export const v1SCMCredential = z.object({meta: v1Meta, propagate: z.boolean().optional(), spec: v1SCMCredentialSpec, tenant_meta: v1TenantMeta, uuid: 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 }; /** * GetSCMCredential fetches the SCM credential identified by UUID. * * GET /v1/namespaces/{tenant_meta.namespace}/scm-credentials/{uuid} */ export const getApiV1NamespacesTenantMetaNamespaceScmCredentialsUuid = async (args: GetApiV1NamespacesTenantMetaNamespaceScmCredentialsUuidArgs, options?: GetApiV1NamespacesTenantMetaNamespaceScmCredentialsUuidOptions) => { const {baseUrl = "https://api.endorlabs.com", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args['get_parameters.mask'] != null) query.append("get_parameters.mask", String(args['get_parameters.mask'])) const url = `${baseUrl.replace(/\/+$/, '')}/v1/namespaces/${encodeURIComponent(String(args['tenant_meta.namespace']))}/scm-credentials/${encodeURIComponent(String(args.uuid))}${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(v1SCMCredential, await res.json()) };