export type Def0 = {privacyPolicy?: ({version?: string | undefined, url: string}) | undefined, gpc?: number | undefined}; export type Def1 = {sessionToken?: string | undefined, subject: {verifiedId?: string | undefined, anonymousId?: string | undefined}, compliance?: Def0 | undefined, actions: Array<{target: string, vendor: string, action: string, jurisdiction?: string | undefined}>, attributes: {[key: string]: unknown}, origin?: string | undefined, jurisdiction?: string | undefined}; export type CreateApiV2ConsentsArgs = {'x-country-code-override'?: string | undefined, 'x-region-code-override'?: string | undefined, body: Def1}; export type CreateApiV2ConsentsOptions = {baseUrl?: string | undefined, ucApiKey?: string | undefined, fetch?: typeof fetch | undefined}; /** * Create and insert a consent * * POST /v2/consents */ export const createApiV2Consents = async (args: CreateApiV2ConsentsArgs, options?: CreateApiV2ConsentsOptions) => { const {baseUrl = "https://uc.api.osano.com", fetch: fetchFn = fetch, ucApiKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") if (args['x-country-code-override'] != null) headers.set("x-country-code-override", String(args['x-country-code-override'])) if (args['x-region-code-override'] != null) headers.set("x-region-code-override", String(args['x-region-code-override'])) if (ucApiKey !== undefined) headers.set("x-uc-api-key", ucApiKey) const url = `${baseUrl.replace(/\/+$/, '')}/v2/consents${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 };