export type ReferenceLineRequest = {lineText?: (string | null) | undefined, lineNumber: number}; export type ReferenceLinesRequest = {file: string, fileUrl?: (string | null) | undefined, preLines?: Array | undefined, postLines?: Array | undefined, referenceLine: ReferenceLineRequest}; export type FlagReference = {settingId: number, references: Array}; export type CodeReferenceRequest = {configId: string, repository: string, branch: string, commitUrl?: (string | null) | undefined, commitHash?: (string | null) | undefined, uploader?: (string | null) | undefined, activeBranches?: Array | undefined, flagReferences?: Array | undefined}; export type CreateApiV1CodeReferencesArgs = {body: CodeReferenceRequest}; export type CreateApiV1CodeReferencesOptions = {baseUrl?: string | undefined, Basic?: {username: string, password: string} | undefined, fetch?: typeof fetch | undefined}; /** * Upload References * * POST /v1/code-references */ export const createApiV1CodeReferences = async (args: CreateApiV1CodeReferencesArgs, options?: CreateApiV1CodeReferencesOptions) => { const {baseUrl = "https://api.configcat.com", fetch: fetchFn = fetch, Basic} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") if (Basic !== undefined) headers.set('authorization', `Basic ${btoa(`${Basic.username}:${Basic.password}`)}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/code-references${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 undefined };