export type MerqTimestamp = string | string | string; export type SecurityMetrics = {eff_ts: MerqTimestamp, id: string, lineage?: Record | undefined, metric: string, prov_ts: MerqTimestamp, source?: string | undefined, value: string | number | number | boolean | Array | Record}; export type CreateApiSecurityTypeDataArgs = {type: string, body: Array}; export type CreateApiSecurityTypeDataOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; /** * Insert new security metrics * * POST /security/{type}/data */ export const createApiSecurityTypeData = async (args: CreateApiSecurityTypeDataArgs, options?: CreateApiSecurityTypeDataOptions) => { const {baseUrl = "https://api.merqube.com", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") const url = `${baseUrl.replace(/\/+$/, '')}/security/${encodeURIComponent(String(args.type))}/data${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 };