{"version":3,"sources":["api/base/api-base.ts"],"names":["ApiBase","constructor","basePath","this","checkError","response","Promise","get","pathAndQuery","jsonResponse","fetch","undefined","post","bodyData","init","getRequestInit","put","delete","requestInit","await","json","method","mode","cache","credentials","headers","Content-Type","body","JSON","stringify"],"mappings":"MAAsBA,QAIlBC,YAAoBC,GAAAC,KAAAD,SAAAA,CAAoB,CAE9BE,WAAWC,GACjB,OAAO,IAAIC,QAAiB,IAAM,CAAA,CAAI,CAC1C,CAOOC,UAAUC,EAAsBC,EAAwB,CAAA,GAC3D,OAAaN,KAAKO,MAAMF,EAAcG,KAAAA,EAAWF,CAAY,CACjE,CAQOG,WAAWJ,EAAsBK,EAAgBJ,EAAwB,CAAA,GAC5E,IAAMK,EAAOX,KAAKY,eAAe,OAAQF,CAAQ,EACjD,OAAaV,KAAKO,MAAMF,EAAcM,EAAML,CAAY,CAC5D,CAQOO,UAAUR,EAAsBK,EAAgBJ,EAAwB,CAAA,GAC3E,IAAMK,EAAOX,KAAKY,eAAe,MAAOF,CAAQ,EAChD,OAAaV,KAAKO,MAAMF,EAAcM,EAAML,CAAY,CAC5D,CAQOQ,aAAaT,EAAsBK,EAAgBJ,EAAwB,CAAA,GAC9E,IAAMK,EAAOX,KAAKY,eAAe,SAAUF,CAAQ,EACnD,OAAaV,KAAKO,MAAMF,EAAcM,EAAML,CAAY,CAC5D,CAEOC,YAAYF,EAAsBU,EAA0BT,GAC/D,IAAMJ,EAAWc,MAAMT,MAAM,GAAGP,KAAKD,SAAWM,EAAgBU,CAAW,EAE3E,OAAKC,MAAMhB,KAAKC,WAAWC,CAAQ,EAI/BI,EAEaJ,EAASe,KAAI,EAGvBf,EARI,IASf,CAEQU,eAAeM,EAAgBR,GAGnC,MAAO,CACHQ,OAAQA,EACRC,KAAM,OACNC,MAAO,WACPC,YAAa,cACbC,QAAS,CACLC,eAAgB,kB,EAEpBC,KAVSd,EAAWe,KAAKC,UAAUhB,CAAQ,EAAI,I,CAYvD,C,QAhFkBb,O","file":"api-base.js","sourcesContent":["export abstract class ApiBase {\n //basePath = \"/startup/api/v1\"; - portal\n //basePath = \"/api\"; - app\n\n constructor(private basePath: string) { }\n\n protected checkError(response: Response): Promise{\n return new Promise(() => true);\n };\n\n /**\n * Make a GET request with supplied path and query to portal API.\n * @param pathAndQuery - should only contain the path after v1. ex. /user/search\n * @param jsonResponse - when true, returns the result of parsing the response body text as JSON; otherwise the Response object is returned.\n */\n public async get(pathAndQuery: string, jsonResponse: boolean = true) {\n return await this.fetch(pathAndQuery, undefined, jsonResponse);\n }\n\n /**\n * Make a POST request with supplied path and query to portal API.\n * @param pathAndQuery - should only contain the path after v1. ex. /user/search\n * @param bodyData - An optional object or an array with data to include in body as Json\n * @param jsonResponse - when true, returns the result of parsing the response body text as JSON; otherwise the Response object is returned.\n */\n public async post(pathAndQuery: string, bodyData?: any, jsonResponse: boolean = true) {\n const init = this.getRequestInit(\"POST\", bodyData);\n return await this.fetch(pathAndQuery, init, jsonResponse);\n }\n\n /**\n * Make a PUT request with supplied path and query to portal API.\n * @param pathAndQuery - should only contain the path after v1. ex. /user/search\n * @param bodyData - An optional object or an array with data to include in body as Json\n * @param jsonResponse - when true, returns the result of parsing the response body text as JSON; otherwise the Response object is returned.\n */\n public async put(pathAndQuery: string, bodyData?: any, jsonResponse: boolean = true) {\n const init = this.getRequestInit(\"PUT\", bodyData);\n return await this.fetch(pathAndQuery, init, jsonResponse);\n }\n \n /**\n * Make a DELETE request with supplied path and query to portal API.\n * @param pathAndQuery - should only contain the path after v1. ex. /user/search\n * @param bodyData - An optional object or an array with data to include in body as Json\n * @param jsonResponse - when true, returns the result of parsing the response body text as JSON; otherwise the Response object is returned.\n */\n public async delete(pathAndQuery: string, bodyData?: any, jsonResponse: boolean = true) {\n const init = this.getRequestInit(\"DELETE\", bodyData);\n return await this.fetch(pathAndQuery, init, jsonResponse);\n }\n\n public async fetch(pathAndQuery: string, requestInit: RequestInit, jsonResponse: boolean) : Promise {\n const response = await fetch(`${this.basePath}${pathAndQuery}`, requestInit);\n\n if (!await this.checkError(response)) {\n return null;\n }\n\n if (jsonResponse)\n {\n return await response.json();\n }\n\n return response;\n }\n\n private getRequestInit(method: string, bodyData?: any) {\n const body = bodyData ? JSON.stringify(bodyData) : null;\n\n return {\n method: method,\n mode: \"cors\",\n cache: \"no-cache\",\n credentials: \"same-origin\",\n headers: {\n \"Content-Type\": \"application/json\"\n },\n body: body\n } as RequestInit;\n }\n}"]}