export type BulkSetApprovalSchema = {object_ids: Array, object_type: 'assets' | 'collections' | 'saved_searches', status: 'APPROVED' | 'NOT_APPROVED'}; export type CreateApiV1ApprovalsBulkArgs = {'Auth-Token': string, 'App-ID': string, body: BulkSetApprovalSchema}; export type CreateApiV1ApprovalsBulkOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; /** * Create a job for bulk request & set approval * * POST /v1/approvals/bulk/ */ export const createApiV1ApprovalsBulk = async (args: CreateApiV1ApprovalsBulkArgs, options: CreateApiV1ApprovalsBulkOptions) => { const {baseUrl, fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") if (args['Auth-Token'] != null) headers.set("Auth-Token", String(args['Auth-Token'])) if (args['App-ID'] != null) headers.set("App-ID", String(args['App-ID'])) const url = `${baseUrl.replace(/\/+$/, '')}/v1/approvals/bulk/${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 };