import {z} from 'zod' export type ContextContextType = 'CONTEXT_TYPE_UNSPECIFIED' | 'CONTEXT_TYPE_MAIN' | 'CONTEXT_TYPE_EXTERNAL' | 'CONTEXT_TYPE_CI_RUN' | 'CONTEXT_TYPE_SBOM' | 'CONTEXT_TYPE_REF'; export type V1Context = {id: string, tags?: Array | undefined, type: ContextContextType, will_be_deleted_at?: string | undefined}; export type V1IndexData = {data?: Array | undefined, search_score?: number | undefined, tenant?: string | undefined, will_be_deleted_at?: string | undefined}; export type GoogleprotobufAny = {'@type'?: string | undefined} | {[key: string]: unknown}; export type V1Meta = {annotations?: {[key: string]: string} | undefined, create_time?: string | undefined, created_by?: string | undefined, description?: string | undefined, index_data?: V1IndexData | undefined, kind?: string | undefined, name: string, parent_kind?: string | undefined, parent_uuid?: string | undefined, references?: {[key: string]: GoogleprotobufAny} | undefined, tags?: Array | undefined, update_time?: string | undefined, updated_by?: string | undefined, upsert_time?: string | undefined, version?: string | undefined}; export type V1LicenseMappingInfo = 'LICENSE_MAPPING_INFO_UNSPECIFIED' | 'LICENSE_MAPPING_INFO_NOT_OSS' | 'LICENSE_MAPPING_INFO_IN_CODE' | 'LICENSE_MAPPING_INFO_UNKNOWN' | 'LICENSE_MAPPING_INFO_NOT_INCOMPLETE' | 'LICENSE_MAPPING_INFO_PRIVATE' | 'LICENSE_MAPPING_INFO_EXACT' | 'LICENSE_MAPPING_INFO_UNLICENSED'; export type PackageLicenseInfoLicenseInfoMapping = {confidence?: number | undefined, mapping_info?: V1LicenseMappingInfo | undefined, notes?: string | undefined, source?: string | undefined}; export type V1PackageLicenseInfo = {additional_files?: {[key: string]: number} | undefined, confidence?: number | undefined, copyrights?: Array | undefined, file_location?: number | undefined, file_name?: string | undefined, hash?: string | undefined, license_description: string, llm?: string | undefined, mapping_info?: PackageLicenseInfoLicenseInfoMapping | undefined, matched_text?: string | undefined, notices_file?: boolean | undefined, spdx_expr?: string | undefined, spdx_id?: string | undefined, type?: string | undefined, url?: string | undefined}; export type V1Version = {metadata?: {[key: string]: string} | undefined, ref: string, sha?: string | undefined}; export type V1PackageLicenseSpec = {all_licenses?: Array | undefined, code_licenses?: Array | undefined, copyrights?: {[key: string]: string} | undefined, declared_code_licenses?: Array | undefined, license_text?: {[key: string]: string} | undefined, package_manager_licenses?: Array | undefined, project_uuid?: string | undefined, version?: V1Version | undefined}; export type PackageLicenseServiceCreatePackageLicenseBody = {context: V1Context, meta: V1Meta, spec: V1PackageLicenseSpec, tenant_meta: Record, uuid?: string | undefined}; export type CreateApiV1NamespacesTenantMetaNamespacePackageLicensesArgs = {'tenant_meta.namespace': string, body: PackageLicenseServiceCreatePackageLicenseBody}; export type CreateApiV1NamespacesTenantMetaNamespacePackageLicensesOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const contextContextType = z.enum(["CONTEXT_TYPE_UNSPECIFIED", "CONTEXT_TYPE_MAIN", "CONTEXT_TYPE_EXTERNAL", "CONTEXT_TYPE_CI_RUN", "CONTEXT_TYPE_SBOM", "CONTEXT_TYPE_REF"]); export const v1Context = z.object({id: z.string(), tags: z.array(z.string()).optional(), type: contextContextType, will_be_deleted_at: z.string().optional()}); 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 v1LicenseMappingInfo = z.enum(["LICENSE_MAPPING_INFO_UNSPECIFIED", "LICENSE_MAPPING_INFO_NOT_OSS", "LICENSE_MAPPING_INFO_IN_CODE", "LICENSE_MAPPING_INFO_UNKNOWN", "LICENSE_MAPPING_INFO_NOT_INCOMPLETE", "LICENSE_MAPPING_INFO_PRIVATE", "LICENSE_MAPPING_INFO_EXACT", "LICENSE_MAPPING_INFO_UNLICENSED"]); export const packageLicenseInfoLicenseInfoMapping = z.object({confidence: z.number().optional(), mapping_info: v1LicenseMappingInfo.optional(), notes: z.string().optional(), source: z.string().optional()}); export const v1PackageLicenseInfo = z.object({additional_files: z.record(z.string(), z.number().int()).optional(), confidence: z.number().optional(), copyrights: z.array(z.string()).optional(), file_location: z.number().int().optional(), file_name: z.string().optional(), hash: z.string().optional(), license_description: z.string(), llm: z.string().optional(), mapping_info: packageLicenseInfoLicenseInfoMapping.optional(), matched_text: z.string().optional(), notices_file: z.boolean().optional(), spdx_expr: z.string().optional(), spdx_id: z.string().optional(), type: z.string().optional(), url: z.string().optional()}); export const v1Version = z.object({metadata: z.record(z.string(), z.string()).optional(), ref: z.string(), sha: z.string().optional()}); export const v1PackageLicenseSpec = z.object({all_licenses: z.array(v1PackageLicenseInfo).optional(), code_licenses: z.array(v1PackageLicenseInfo).optional(), copyrights: z.record(z.string(), z.string()).optional(), declared_code_licenses: z.array(v1PackageLicenseInfo).optional(), license_text: z.record(z.string(), z.string()).optional(), package_manager_licenses: z.array(v1PackageLicenseInfo).optional(), project_uuid: z.string().optional(), version: v1Version.optional()}); export const v1TenantMeta = z.object({namespace: z.string()}); export const v1PackageLicense = z.object({context: v1Context, meta: v1Meta, spec: v1PackageLicenseSpec, 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 }; /** * CreatePackageLicense * * POST /v1/namespaces/{tenant_meta.namespace}/package-licenses */ export const createApiV1NamespacesTenantMetaNamespacePackageLicenses = async (args: CreateApiV1NamespacesTenantMetaNamespacePackageLicensesArgs, options?: CreateApiV1NamespacesTenantMetaNamespacePackageLicensesOptions) => { const {baseUrl = "https://api.endorlabs.com", 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(/\/+$/, '')}/v1/namespaces/${encodeURIComponent(String(args['tenant_meta.namespace']))}/package-licenses${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(v1PackageLicense, await res.json()) };