\n \n \n \n {{ errorMessage }}\n \n \n
\n\n\n\n","import { render } from \"./ajax-error-toast.vue?vue&type=template&id=1f60e4a5\"\nimport script from \"./ajax-error-toast.vue?vue&type=script&lang=js\"\nexport * from \"./ajax-error-toast.vue?vue&type=script&lang=js\"\n\nimport exportComponent from \"../../../node_modules/vue-loader/dist/exportHelper.js\"\nconst __exports__ = /*#__PURE__*/exportComponent(script, [['render',render]])\n\nexport default __exports__","\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\n// runtime helper for setting properties on components\n// in a tree-shakable way\nexports.default = (sfc, props) => {\n const target = sfc.__vccOpts || sfc;\n for (const [key, val] of props) {\n target[key] = val;\n }\n return target;\n};\n","import { objectKeysToCamelCase } from './transform-object-keys'\nimport { urlWithParams } from './url-params'\n\nconst STATUS_ERROR = 'error'\nconst GET_VERB = 'GET'\nconst POST_VERB = 'POST'\nconst PATCH_VERB = 'PATCH'\nconst PUT_VERB = 'PUT'\nconst DELETE_VERB = 'DELETE'\nconst PARAMS_IN_BODY_METHODS = [POST_VERB, PATCH_VERB, PUT_VERB, DELETE_VERB]\n\nfunction get(options) {\n return ajaxBase({...options, method: GET_VERB})\n}\n\nfunction post(options) {\n return ajaxBase({...options, method: POST_VERB})\n}\n\nfunction patch(options) {\n return ajaxBase({...options, method: PATCH_VERB})\n}\n\nfunction put(options) {\n return ajaxBase({...options, method: PUT_VERB})\n}\n\nconst errorTypes = {\n FETCH_FAILED: 'fetchFailed',\n NOT_OK_HTTP_STATUS: 'nonOkHttpStatus'\n}\n\nasync function ajaxBase({url, params, method, headers, data: requestData, acceptContentType='application/json',\n successHandler, errorHandler = null, throwOnFailure = false, camelCaseResponse = true}) {\n // If we're doing a GET, encode the params in the URL. Otherwise, we'll encode into the request body\n const parameterizedUrl = (method === GET_VERB) ? urlWithParams(url, params || {}) : url\n\n // By default, do not set the `body` parameter. For GET and other methods that do not accept a body,\n // even setting `body: null` can cause errors in some browsers.\n const maybeBody = {}\n\n // by default, communicate with the server via json\n let contentType = 'application/json;charset=UTF-8'\n\n if (PARAMS_IN_BODY_METHODS.includes(method)) {\n if (requestData === undefined) {\n // We need to do send as URL encoded data, since we accept arbitrary params.\n maybeBody.body = new URLSearchParams(params).toString()\n contentType = 'application/x-www-form-urlencoded'\n } else {\n // Need to JSON.stringify the bodyData here or it will be serialized\n // as [object Object] by default\n maybeBody.body = JSON.stringify(requestData)\n }\n }\n\n let response = null\n try {\n response = await fetch(parameterizedUrl, {\n method,\n headers: {\n ...headers,\n ...maybeCsrfToken(),\n 'Accept': acceptContentType,\n 'Content-Type': contentType,\n credentials: 'same-origin'\n },\n ...maybeBody\n })\n } catch (e) {\n if (throwOnFailure) {\n throw e\n } else {\n document.dispatchEvent(new CustomEvent('agra:ajax-error', {detail: {errorType: errorTypes.FETCH_FAILED}}))\n return\n }\n }\n\n // Check that HTTP status is OK\n if (!response.ok) {\n let errorBody\n try {\n errorBody = await response.json()\n } catch {\n // couldn't parse JSON\n errorBody = {error: `Response status was ${response.status}`}\n }\n\n if (throwOnFailure) {\n throw errorBody\n } else {\n document.dispatchEvent(new CustomEvent('agra:ajax-error', {\n detail: {\n errorType: errorTypes.NOT_OK_HTTP_STATUS,\n httpStatusCode: response.status,\n message: errorBody.message\n }\n }))\n return\n }\n }\n\n // Parse the response body\n if (response.status === 204) {\n // No response body to parse. Call the provided success handler function and we're done.\n if (successHandler) {\n successHandler(null)\n }\n return\n }\n\n // Parse body as JSON if that's the expected response\n const jsonRegexContentType = /json/i\n if (jsonRegexContentType.test(acceptContentType)) {\n const jsonResponse = await response.json()\n\n const transformedResponse = camelCaseResponse ? objectKeysToCamelCase(jsonResponse) : jsonResponse\n\n if (Array.isArray(jsonResponse)) {\n // Send the array data to the provided success handler function\n if (successHandler) {\n successHandler(transformedResponse)\n }\n return\n }\n\n // If we get here, we can assume that the JSON data is a hash. Extract common fields from it.\n const { status, message, data, ...rest } = transformedResponse\n\n // If the response has \"status\": \"error\", that's a 'business logic' error that the caller should handle.\n // Send it to the provided error handler function. If we were not provided an error handler function,\n // throw an exception.\n if (status === STATUS_ERROR) {\n if (errorHandler) {\n errorHandler({ message, info: rest })\n return\n } else {\n let error = new Error(message)\n error.info = rest\n throw error\n }\n }\n\n // Send the body, minus the 'status', to the provided success handler function\n if (successHandler) {\n successHandler({ message, data, ...rest })\n }\n } else {\n // Send the body as unparsed text to the provided success handler function\n const bodyText = await response.text()\n if (successHandler) {\n successHandler(bodyText)\n }\n }\n}\n\nfunction maybeCsrfToken() {\n const tokenElement = document.querySelector('meta[name=\"csrf-token\"]')\n if (tokenElement) {\n return {\n 'X-CSRF-Token': tokenElement.getAttribute('content')\n }\n }\n else {\n return {}\n }\n}\n\nexport default {\n get,\n post,\n // We inline the delete method here because `delete` is a JS keyword\n delete: options => {\n return ajaxBase({...options, method: DELETE_VERB})\n },\n put,\n patch,\n\n errorTypes\n}\n"],"names":["urlWithParams","baseUrl","searchParamsMap","urlObj","URL","window","location","origin","urlSearchParams","searchParams","Object","entries","forEach","k","v","stringValue","JSON","stringify","append","sort","toString","urlParamsWithNamespace","paramsMap","namespace","newParamsMap","props","kind","type","String","required","default","showFixedTopRight","Boolean","showOnMount","data","show","mounted","this","showToast","methods","removeToast","setTimeout","_createBlock","_Transition","name","appear","_withCtx","$data","_createElementBlock","key","class","_normalizeClass","$props","_createElementVNode","_renderSlot","_ctx","$slots","undefined","_createCommentVNode","_","makeObjectTransformer","transformWithFunction","transformObjectKeys","sourceObject","transformedObject","Array","isArray","value","isPlainObject","objectKeysToCamelCase","camelCase","objectKeysToSnakeCase","snakeCase","components","Toast","messageForNonOkHttpStatus","inject","t","active","errorDetail","errorType","computed","errorMessage","ajax","errorTypes","FETCH_FAILED","i18n","NOT_OK_HTTP_STATUS","httpStatusCode","message","document","addEventListener","evt","detail","_component_toast","_createTextVNode","_toDisplayString","$options","exports","sfc","target","__vccOpts","val","POST_VERB","PATCH_VERB","DELETE_VERB","PARAMS_IN_BODY_METHODS","async","ajaxBase","url","params","method","headers","requestData","acceptContentType","successHandler","errorHandler","throwOnFailure","camelCaseResponse","parameterizedUrl","maybeBody","contentType","includes","body","URLSearchParams","response","fetch","maybeCsrfToken","credentials","e","dispatchEvent","CustomEvent","ok","errorBody","json","error","status","test","jsonResponse","transformedResponse","rest","info","Error","bodyText","text","tokenElement","querySelector","getAttribute","get","options","post","delete","put","patch"],"sourceRoot":""}