export type FormRequest = {formInstanceId?: string | undefined, formDefinitionId?: string | undefined, formDefinitionKey?: string | undefined, taskId?: string | undefined, processInstanceId?: string | undefined, processDefinitionId?: string | undefined, scopeId?: string | undefined, scopeType?: string | undefined, scopeDefinitionId?: string | undefined, outcome?: string | undefined, tenantId?: string | undefined, parentDeploymentId?: string | undefined, variables?: {[key: string]: Record} | undefined}; export type CreateApiFormFormInstancesArgs = {body: FormRequest}; export type CreateApiFormFormInstancesOptions = {baseUrl?: string | undefined, basicAuth?: {username: string, password: string} | undefined, fetch?: typeof fetch | undefined}; /** * Store a form instance * * POST /form/form-instances */ export const createApiFormFormInstances = async (args: CreateApiFormFormInstancesArgs, options?: CreateApiFormFormInstancesOptions) => { const {baseUrl = "http://localhost:8090/form-api", fetch: fetchFn = fetch, basicAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") if (basicAuth !== undefined) headers.set('authorization', `Basic ${btoa(`${basicAuth.username}:${basicAuth.password}`)}`) const url = `${baseUrl.replace(/\/+$/, '')}/form/form-instances${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 };