export type EntityMerge = {primary_entity_token?: string | undefined, primary_external_entity_id?: string | undefined, secondary_entity_token?: string | undefined, secondary_external_entity_id?: string | undefined}; export type CreateApiEntitiesMergeArgs = {body: EntityMerge}; export type CreateApiEntitiesMergeOptions = {baseUrl?: string | undefined, oauth2?: string | undefined, fetch?: typeof fetch | undefined}; /** * Merge two entities * * POST /entities/merge * * Also accepts auth: basic */ export const createApiEntitiesMerge = async (args: CreateApiEntitiesMergeArgs, options?: CreateApiEntitiesMergeOptions) => { const {baseUrl = "https://sandbox.alloy.co/v1", fetch: fetchFn = fetch, oauth2} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") if (oauth2 !== undefined) headers.set('authorization', `Bearer ${oauth2}`) const url = `${baseUrl.replace(/\/+$/, '')}/entities/merge${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 };