export type FilteringCondition = {field?: string | undefined, operator?: ('EQUAL' | 'NOT_EQUAL' | 'LESS' | 'GREATER' | 'LESS_OR_EQUAL' | 'GREATER_OR_EQUAL' | 'LIKE' | 'NOT_LIKE' | 'BETWEEN' | 'IN' | 'NOT_IN' | 'NOT' | 'IS_NULL' | 'IS_NOT_NULL' | 'IS_TRUE' | 'IS_FALSE' | 'IS_EMPTY' | 'IS_NOT_EMPTY' | 'CONTAINS') | undefined, parameters?: Array> | undefined}; export type FilteringLogic = {conditionalOperator?: ('AND' | 'OR') | undefined, expressions?: (Array) | undefined}; export type SortingParameter = {direction?: ('ASC' | 'DESC') | undefined, field?: string | undefined}; export type RequestParams = {filter?: (FilteringCondition | FilteringLogic) | undefined, page?: number | undefined, perPage?: number | undefined, sort?: Array | undefined}; export type GetApiGoalsArgs = {paramsIO: RequestParams, optionalFields?: Array | undefined}; export type GetApiGoalsOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; /** * Get all goals * * GET /goals */ export const getApiGoals = async (args: GetApiGoalsArgs, options?: GetApiGoalsOptions) => { const {baseUrl = "https://api.kameleoon.com", fetch: fetchFn = fetch, bearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "*/*") if (args.paramsIO != null) query.append("paramsIO", JSON.stringify(args.paramsIO)) for (const item of args.optionalFields ?? []) query.append("optionalFields", String(item)) if (bearerAuth !== undefined) headers.set('authorization', `Bearer ${bearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/goals${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "GET", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return res.blob() };