@bigbinary/neeto-commons-frontend 3.4.4 → 3.4.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -5,8 +5,6 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
value: true
|
|
6
6
|
});
|
|
7
7
|
exports["default"] = initializeAxios;
|
|
8
|
-
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
|
|
9
|
-
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
|
|
10
8
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
11
9
|
var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
|
|
12
10
|
var _axios = _interopRequireDefault(require("axios"));
|
|
@@ -14,10 +12,12 @@ var _i18next = _interopRequireDefault(require("i18next"));
|
|
|
14
12
|
var _neetoCist = require("@bigbinary/neeto-cist");
|
|
15
13
|
var _Toastr = _interopRequireDefault(require("@bigbinary/neetoui/Toastr"));
|
|
16
14
|
var _ramda = require("ramda");
|
|
15
|
+
var _reactToastify = require("react-toastify");
|
|
17
16
|
var _useDisplayErrorPage = require("../../react-utils/useDisplayErrorPage");
|
|
18
17
|
var _axios2 = require("../../utils/axios");
|
|
19
18
|
var _paramsSerializer = _interopRequireDefault(require("./paramsSerializer"));
|
|
20
19
|
var _constants = require("../constants");
|
|
20
|
+
var checkOnlineInterval = null;
|
|
21
21
|
var shouldNot = function shouldNot(skip) {
|
|
22
22
|
return (0, _typeof2["default"])(skip) === "object" || !skip;
|
|
23
23
|
};
|
|
@@ -111,49 +111,51 @@ var handleUnauthorizedErrorResponse = function handleUnauthorizedErrorResponse(e
|
|
|
111
111
|
}
|
|
112
112
|
return error;
|
|
113
113
|
};
|
|
114
|
-
var
|
|
115
|
-
return
|
|
116
|
-
};
|
|
117
|
-
var
|
|
118
|
-
var
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
}();
|
|
114
|
+
var isOnline = function isOnline() {
|
|
115
|
+
return window.navigator.onLine;
|
|
116
|
+
};
|
|
117
|
+
var showOfflineToastr = function showOfflineToastr() {
|
|
118
|
+
var toastId = _Toastr["default"].error(_i18next["default"].t("neetoCommons.toastr.error.networkError"));
|
|
119
|
+
if (toastId) {
|
|
120
|
+
var dismissToastInterval = setInterval(function () {
|
|
121
|
+
if (!isOnline()) return;
|
|
122
|
+
_reactToastify.toast.dismiss(toastId);
|
|
123
|
+
clearInterval(dismissToastInterval);
|
|
124
|
+
checkOnlineInterval = null;
|
|
125
|
+
}, 1000);
|
|
126
|
+
}
|
|
127
|
+
};
|
|
128
|
+
var handleNetworkError = function handleNetworkError(error) {
|
|
129
|
+
if (isOnline()) {
|
|
130
|
+
_Toastr["default"].error(_i18next["default"].t("generic.error"));
|
|
131
|
+
return error;
|
|
132
|
+
}
|
|
133
|
+
if (checkOnlineInterval) return error;
|
|
134
|
+
var startTime = Date.now();
|
|
135
|
+
checkOnlineInterval = setInterval(function () {
|
|
136
|
+
var elapsedTime = Date.now() - startTime;
|
|
137
|
+
if (isOnline()) {
|
|
138
|
+
clearInterval(checkOnlineInterval);
|
|
139
|
+
checkOnlineInterval = null;
|
|
140
|
+
} else if (elapsedTime >= _constants.MAXIMUM_OFFLINE_DURATION) {
|
|
141
|
+
clearInterval(checkOnlineInterval);
|
|
142
|
+
showOfflineToastr();
|
|
143
|
+
}
|
|
144
|
+
}, 1000);
|
|
145
|
+
return error;
|
|
146
|
+
};
|
|
148
147
|
var showErrorToastr = function showErrorToastr(error) {
|
|
149
148
|
var _error$config3, _error$response3;
|
|
150
|
-
var
|
|
151
|
-
|
|
152
|
-
showToastr =
|
|
149
|
+
var _ref3 = (_error$config3 = error.config) !== null && _error$config3 !== void 0 ? _error$config3 : {},
|
|
150
|
+
_ref3$showToastr = _ref3.showToastr,
|
|
151
|
+
showToastr = _ref3$showToastr === void 0 ? true : _ref3$showToastr;
|
|
153
152
|
if (!showToastr) return error;
|
|
154
|
-
var
|
|
155
|
-
status =
|
|
153
|
+
var _ref4 = (_error$response3 = error.response) !== null && _error$response3 !== void 0 ? _error$response3 : {},
|
|
154
|
+
status = _ref4.status;
|
|
156
155
|
if (error.message === "Network Error") return handleNetworkError(error);
|
|
156
|
+
if (error.code === "ECONNABORTED") {
|
|
157
|
+
return error;
|
|
158
|
+
}
|
|
157
159
|
if (![403, 404, 520].includes(status) && !_axios["default"].isCancel(error)) {
|
|
158
160
|
// we already display a page in case of 403 & 404 and we don't want to show a toastr for cancelled requests.
|
|
159
161
|
// We handle cloudflare error differently for production and other environments.
|
|
@@ -175,11 +177,11 @@ var getUrlPathName = function getUrlPathName(url) {
|
|
|
175
177
|
};
|
|
176
178
|
var handle404ErrorResponse = function handle404ErrorResponse(error) {
|
|
177
179
|
var _error$config4, _error$response4;
|
|
178
|
-
var
|
|
179
|
-
|
|
180
|
-
show404ErrorPage =
|
|
181
|
-
|
|
182
|
-
show403ErrorPage =
|
|
180
|
+
var _ref5 = (_error$config4 = error.config) !== null && _error$config4 !== void 0 ? _error$config4 : {},
|
|
181
|
+
_ref5$show404ErrorPag = _ref5.show404ErrorPage,
|
|
182
|
+
show404ErrorPage = _ref5$show404ErrorPag === void 0 ? true : _ref5$show404ErrorPag,
|
|
183
|
+
_ref5$show403ErrorPag = _ref5.show403ErrorPage,
|
|
184
|
+
show403ErrorPage = _ref5$show403ErrorPag === void 0 ? true : _ref5$show403ErrorPag;
|
|
183
185
|
var status = (_error$response4 = error.response) === null || _error$response4 === void 0 ? void 0 : _error$response4.status;
|
|
184
186
|
if (status === 404 && show404ErrorPage || status === 403 && show403ErrorPage) {
|
|
185
187
|
var _error$request;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["_axios","_interopRequireDefault","require","_i18next","_neetoCist","_Toastr","_ramda","_useDisplayErrorPage","_axios2","_paramsSerializer","_constants","shouldNot","skip","_typeof2","shouldShowToastr","response","notice","noticeCode","setAuthHeaders","_document$querySelect","_axios$defaults$heade","axios","defaults","headers","_defineProperty2","HEADERS_KEYS","accept","contentType","xCsrfToken","document","querySelector","getAttribute","createPipe","functions","data","reduce","acc","fn","transformResponseKeysToCamelCase","_response$config$tran","config","transformResponseCase","keysToCamelCase","transformErrorKeysToCamelCase","error","_error$config","_error$response","_ref","_ref$transformRespons","showSuccessToastr","_response$config$show","showToastr","matches","showThumbsUpToastr","Toastr","success","icon","className","pullDataFromResponse","_response$config$incl","includeMetadataInResponse","buildSuccessResponseHandler","interceptors","transformCase","push","handleUnauthorizedErrorResponse","_error$response2","_error$config2","status","resetAuthTokens","_ref2","_ref2$redirectOnError","redirectOnError","setTimeout","redirectTo","window","location","pathname","concat","encodeURIComponent","href","isUserOffline","navigator","onLine","handleNetworkError","_ref3","_asyncToGenerator2","_regenerator","mark","_callee","errorMessage","wrap","_callee$","_context","prev","next","i18next","t","Promise","resolve","MAXIMUM_OFFLINE_DURATION","abrupt","stop","_x","apply","arguments","showErrorToastr","_error$config3","_error$response3","_ref4","_ref4$showToastr","_ref5","message","includes","isCancel","globalProps","railsEnv","getUrlPathName","url","URL","_unused","handle404ErrorResponse","_error$config4","_error$response4","_ref6","_ref6$show404ErrorPag","show404ErrorPage","_ref6$show403ErrorPag","show403ErrorPage","_error$request","fullUrl","request","responseURL","useErrorDisplayStore","setState","showErrorPage","statusCode","failedApiUrl","failedApiPath","buildErrorResponseHandler","logoutOn401","reject","bind","cleanupCredentialsForCrossOrigin","hostname","evolve","omit","transformDataToSnakeCase","_request$transformReq","transformRequestCase","serializeKeysToSnakeCase","params","addRequestInterceptors","cleanCredentialsForCrossOrigin","use","addResponseInterceptors","registerIntercepts","initializeAxios","baseURL","authHeaders","paramsSerializer","setParamsSerializer"],"sources":["../../../../src/initializers/axiosInitializer/index.js"],"sourcesContent":["import axios from \"axios\";\nimport i18next from \"i18next\";\nimport { keysToCamelCase, matches, serializeKeysToSnakeCase } from \"neetocist\";\nimport { Toastr } from \"neetoui\";\nimport { evolve, omit } from \"ramda\";\nimport { useErrorDisplayStore } from \"react-utils/useDisplayErrorPage\";\nimport { resetAuthTokens } from \"utils/axios\";\n\nimport setParamsSerializer from \"./paramsSerializer\";\n\nimport { MAXIMUM_OFFLINE_DURATION, HEADERS_KEYS } from \"../constants\";\n\nconst shouldNot = skip => typeof skip === \"object\" || !skip;\n\nconst shouldShowToastr = response =>\n typeof response === \"string\" ||\n (typeof response === \"object\" && (response?.notice || response?.noticeCode));\n\nconst setAuthHeaders = () => {\n // @ts-ignore\n axios.defaults.headers = {\n [HEADERS_KEYS.accept]: \"application/json\",\n [HEADERS_KEYS.contentType]: \"application/json\",\n [HEADERS_KEYS.xCsrfToken]: document\n .querySelector('[name=\"csrf-token\"]')\n ?.getAttribute(\"content\"),\n };\n};\n\n// pipe function from ramda doesn't accept array of functions.\n// We can't use spread operator too. So this is a workaround.\nconst createPipe = functions => data =>\n functions.reduce((acc, fn) => fn(acc), data);\n\nconst transformResponseKeysToCamelCase = response => {\n const { transformResponseCase = true } = response.config;\n\n if (response.data && transformResponseCase) {\n response.data = keysToCamelCase(response.data);\n }\n\n return response;\n};\n\nconst transformErrorKeysToCamelCase = error => {\n const { transformResponseCase = true } = error.config ?? {};\n\n if (error.response?.data && transformResponseCase) {\n error.response.data = keysToCamelCase(error.response.data);\n }\n\n return error;\n};\n\nconst showSuccessToastr = response => {\n const { showToastr = true } = response.config;\n if (!showToastr) return response;\n\n if (matches({ showThumbsUpToastr: true }, response.data)) {\n // @ts-ignore\n Toastr.success(\"\", { icon: \"👍\", className: \"w-20\" });\n } else if (matches({ noticeCode: \"thumbs_up\" }, response.data)) {\n // @ts-ignore\n Toastr.success(\"\", { icon: \"👍\", className: \"w-20\" });\n } else if (shouldShowToastr(response.data)) {\n Toastr.success(response.data);\n }\n\n return response;\n};\n\nconst pullDataFromResponse = response => {\n const { includeMetadataInResponse = false } = response.config;\n\n return includeMetadataInResponse ? response : response.data;\n};\n\nconst buildSuccessResponseHandler = skip => {\n const interceptors = [];\n if (!skip?.transformCase) interceptors.push(transformResponseKeysToCamelCase);\n\n if (!skip?.showToastr) interceptors.push(showSuccessToastr);\n\n if (!skip?.pullDataFromResponse) interceptors.push(pullDataFromResponse);\n\n return createPipe(interceptors);\n};\n\nconst handleUnauthorizedErrorResponse = error => {\n if (error.response?.status !== 401) return error;\n\n resetAuthTokens();\n\n const { redirectOnError = true } = error.config ?? {};\n if (redirectOnError) {\n setTimeout(() => {\n const redirectTo =\n window.location.pathname === \"/login\"\n ? \"/login\"\n : `/login?redirect_uri=${encodeURIComponent(window.location.href)}`;\n\n // eslint-disable-next-line xss/no-location-href-assign\n window.location.href = redirectTo;\n }, 300);\n }\n\n return error;\n};\n\nconst isUserOffline = () => !window.navigator.onLine;\n\nconst handleNetworkError = async error => {\n const errorMessage = i18next.t(\"neetoCommons.toastr.error.networkError\");\n if (isUserOffline()) {\n await new Promise(resolve => setTimeout(resolve, MAXIMUM_OFFLINE_DURATION));\n\n if (isUserOffline()) Toastr.error(errorMessage);\n\n return error;\n }\n Toastr.error(errorMessage);\n\n return error;\n};\n\nconst showErrorToastr = error => {\n const { showToastr = true } = error.config ?? {};\n if (!showToastr) return error;\n\n const { status } = error.response ?? {};\n\n if (error.message === \"Network Error\") return handleNetworkError(error);\n\n if (![403, 404, 520].includes(status) && !axios.isCancel(error)) {\n // we already display a page in case of 403 & 404 and we don't want to show a toastr for cancelled requests.\n // We handle cloudflare error differently for production and other environments.\n Toastr.error(error);\n }\n\n if (status === 520) {\n if (globalProps.railsEnv === \"production\") {\n Toastr.error(i18next.t(\"generic.error\"));\n } else Toastr.error(error);\n }\n\n return error;\n};\n\nconst getUrlPathName = url => {\n try {\n return new URL(url).pathname;\n } catch {\n return url;\n }\n};\n\nconst handle404ErrorResponse = error => {\n const { show404ErrorPage = true, show403ErrorPage = true } =\n error.config ?? {};\n\n const status = error.response?.status;\n if (\n (status === 404 && show404ErrorPage) ||\n (status === 403 && show403ErrorPage)\n ) {\n const fullUrl = error.request?.responseURL || error.config.url;\n useErrorDisplayStore.setState({\n showErrorPage: true,\n statusCode: status,\n failedApiUrl: fullUrl,\n failedApiPath: getUrlPathName(fullUrl),\n });\n }\n\n return error;\n};\n\nconst buildErrorResponseHandler = skip => {\n const interceptors = [];\n if (!skip?.transformCase) interceptors.push(transformErrorKeysToCamelCase);\n\n if (!skip?.show404ErrorPage) interceptors.push(handle404ErrorResponse);\n\n if (!skip?.logoutOn401) interceptors.push(handleUnauthorizedErrorResponse);\n\n if (!skip?.showToastr) interceptors.push(showErrorToastr);\n\n interceptors.push(Promise.reject.bind(Promise));\n\n return createPipe(interceptors);\n};\n\nconst cleanupCredentialsForCrossOrigin = request => {\n if (!request.url.includes(\"://\")) return request;\n\n if (request.url.includes(window.location.hostname)) return request;\n\n return evolve({ headers: omit([HEADERS_KEYS.xCsrfToken]) })(request);\n};\n\nconst transformDataToSnakeCase = request => {\n const { transformRequestCase = true } = request;\n\n if (!transformRequestCase) return request;\n\n return evolve(\n { data: serializeKeysToSnakeCase, params: serializeKeysToSnakeCase },\n request\n );\n};\n\nconst addRequestInterceptors = skip => {\n if (!skip?.cleanCredentialsForCrossOrigin) {\n axios.interceptors.request.use(cleanupCredentialsForCrossOrigin);\n }\n\n if (!skip?.transformCase) {\n axios.interceptors.request.use(transformDataToSnakeCase);\n }\n};\n\nconst addResponseInterceptors = skip => {\n axios.interceptors.response.use(\n buildSuccessResponseHandler(skip),\n buildErrorResponseHandler(skip)\n );\n};\n\nconst registerIntercepts = skip => {\n if (shouldNot(skip?.request)) addRequestInterceptors(skip?.request);\n\n if (shouldNot(skip?.response)) addResponseInterceptors(skip?.response);\n};\n\nexport default function initializeAxios(skip) {\n if (!skip?.baseURL) axios.defaults.baseURL = \"/\";\n\n if (!skip?.authHeaders) setAuthHeaders();\n\n if (!skip?.paramsSerializer) setParamsSerializer();\n\n if (shouldNot(skip?.interceptors)) registerIntercepts(skip?.interceptors);\n}\n"],"mappings":";;;;;;;;;;;AAAA,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,QAAA,GAAAF,sBAAA,CAAAC,OAAA;AACA,IAAAE,UAAA,GAAAF,OAAA;AAA+E,IAAAG,OAAA,GAAAJ,sBAAA,CAAAC,OAAA;AAE/E,IAAAI,MAAA,GAAAJ,OAAA;AACA,IAAAK,oBAAA,GAAAL,OAAA;AACA,IAAAM,OAAA,GAAAN,OAAA;AAEA,IAAAO,iBAAA,GAAAR,sBAAA,CAAAC,OAAA;AAEA,IAAAQ,UAAA,GAAAR,OAAA;AAEA,IAAMS,SAAS,GAAG,SAAZA,SAASA,CAAGC,IAAI;EAAA,OAAI,IAAAC,QAAA,aAAOD,IAAI,MAAK,QAAQ,IAAI,CAACA,IAAI;AAAA;AAE3D,IAAME,gBAAgB,GAAG,SAAnBA,gBAAgBA,CAAGC,QAAQ;EAAA,OAC/B,OAAOA,QAAQ,KAAK,QAAQ,IAC3B,IAAAF,QAAA,aAAOE,QAAQ,MAAK,QAAQ,KAAK,CAAAA,QAAQ,aAARA,QAAQ,uBAARA,QAAQ,CAAEC,MAAM,MAAID,QAAQ,aAARA,QAAQ,uBAARA,QAAQ,CAAEE,UAAU,EAAE;AAAA;AAE9E,IAAMC,cAAc,GAAG,SAAjBA,cAAcA,CAAA,EAAS;EAAA,IAAAC,qBAAA,EAAAC,qBAAA;EAC3B;EACAC,iBAAK,CAACC,QAAQ,CAACC,OAAO,IAAAH,qBAAA,WAAAI,gBAAA,aAAAJ,qB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,iBAAK,CAACC,QAAQ,CAACwI,OAAO,GAAG,GAAG;EAEhD,IAAI,EAAClJ,IAAI,aAAJA,IAAI,eAAJA,IAAI,CAAEmJ,WAAW,GAAE7I,cAAc,EAAE;EAExC,IAAI,EAACN,IAAI,aAAJA,IAAI,eAAJA,IAAI,CAAEoJ,gBAAgB,GAAE,IAAAC,4BAAmB,GAAE;EAElD,IAAItJ,SAAS,CAACC,IAAI,aAAJA,IAAI,uBAAJA,IAAI,CAAEkD,YAAY,CAAC,EAAE8F,kBAAkB,CAAChJ,IAAI,aAAJA,IAAI,uBAAJA,IAAI,CAAEkD,YAAY,CAAC;AAC3E"}
|
|
1
|
+
{"version":3,"file":"index.js","names":["_axios","_interopRequireDefault","require","_i18next","_neetoCist","_Toastr","_ramda","_reactToastify","_useDisplayErrorPage","_axios2","_paramsSerializer","_constants","checkOnlineInterval","shouldNot","skip","_typeof2","shouldShowToastr","response","notice","noticeCode","setAuthHeaders","_document$querySelect","_axios$defaults$heade","axios","defaults","headers","_defineProperty2","HEADERS_KEYS","accept","contentType","xCsrfToken","document","querySelector","getAttribute","createPipe","functions","data","reduce","acc","fn","transformResponseKeysToCamelCase","_response$config$tran","config","transformResponseCase","keysToCamelCase","transformErrorKeysToCamelCase","error","_error$config","_error$response","_ref","_ref$transformRespons","showSuccessToastr","_response$config$show","showToastr","matches","showThumbsUpToastr","Toastr","success","icon","className","pullDataFromResponse","_response$config$incl","includeMetadataInResponse","buildSuccessResponseHandler","interceptors","transformCase","push","handleUnauthorizedErrorResponse","_error$response2","_error$config2","status","resetAuthTokens","_ref2","_ref2$redirectOnError","redirectOnError","setTimeout","redirectTo","window","location","pathname","concat","encodeURIComponent","href","isOnline","navigator","onLine","showOfflineToastr","toastId","i18next","t","dismissToastInterval","setInterval","toast","dismiss","clearInterval","handleNetworkError","startTime","Date","now","elapsedTime","MAXIMUM_OFFLINE_DURATION","showErrorToastr","_error$config3","_error$response3","_ref3","_ref3$showToastr","_ref4","message","code","includes","isCancel","globalProps","railsEnv","getUrlPathName","url","URL","_unused","handle404ErrorResponse","_error$config4","_error$response4","_ref5","_ref5$show404ErrorPag","show404ErrorPage","_ref5$show403ErrorPag","show403ErrorPage","_error$request","fullUrl","request","responseURL","useErrorDisplayStore","setState","showErrorPage","statusCode","failedApiUrl","failedApiPath","buildErrorResponseHandler","logoutOn401","Promise","reject","bind","cleanupCredentialsForCrossOrigin","hostname","evolve","omit","transformDataToSnakeCase","_request$transformReq","transformRequestCase","serializeKeysToSnakeCase","params","addRequestInterceptors","cleanCredentialsForCrossOrigin","use","addResponseInterceptors","registerIntercepts","initializeAxios","baseURL","authHeaders","paramsSerializer","setParamsSerializer"],"sources":["../../../../src/initializers/axiosInitializer/index.js"],"sourcesContent":["import axios from \"axios\";\nimport i18next from \"i18next\";\nimport { keysToCamelCase, matches, serializeKeysToSnakeCase } from \"neetocist\";\nimport { Toastr } from \"neetoui\";\nimport { evolve, omit } from \"ramda\";\nimport { toast } from \"react-toastify\";\nimport { useErrorDisplayStore } from \"react-utils/useDisplayErrorPage\";\nimport { resetAuthTokens } from \"utils/axios\";\n\nimport setParamsSerializer from \"./paramsSerializer\";\n\nimport { HEADERS_KEYS, MAXIMUM_OFFLINE_DURATION } from \"../constants\";\n\nlet checkOnlineInterval = null;\n\nconst shouldNot = skip => typeof skip === \"object\" || !skip;\n\nconst shouldShowToastr = response =>\n typeof response === \"string\" ||\n (typeof response === \"object\" && (response?.notice || response?.noticeCode));\n\nconst setAuthHeaders = () => {\n // @ts-ignore\n axios.defaults.headers = {\n [HEADERS_KEYS.accept]: \"application/json\",\n [HEADERS_KEYS.contentType]: \"application/json\",\n [HEADERS_KEYS.xCsrfToken]: document\n .querySelector('[name=\"csrf-token\"]')\n ?.getAttribute(\"content\"),\n };\n};\n\n// pipe function from ramda doesn't accept array of functions.\n// We can't use spread operator too. So this is a workaround.\nconst createPipe = functions => data =>\n functions.reduce((acc, fn) => fn(acc), data);\n\nconst transformResponseKeysToCamelCase = response => {\n const { transformResponseCase = true } = response.config;\n\n if (response.data && transformResponseCase) {\n response.data = keysToCamelCase(response.data);\n }\n\n return response;\n};\n\nconst transformErrorKeysToCamelCase = error => {\n const { transformResponseCase = true } = error.config ?? {};\n\n if (error.response?.data && transformResponseCase) {\n error.response.data = keysToCamelCase(error.response.data);\n }\n\n return error;\n};\n\nconst showSuccessToastr = response => {\n const { showToastr = true } = response.config;\n if (!showToastr) return response;\n\n if (matches({ showThumbsUpToastr: true }, response.data)) {\n // @ts-ignore\n Toastr.success(\"\", { icon: \"👍\", className: \"w-20\" });\n } else if (matches({ noticeCode: \"thumbs_up\" }, response.data)) {\n // @ts-ignore\n Toastr.success(\"\", { icon: \"👍\", className: \"w-20\" });\n } else if (shouldShowToastr(response.data)) {\n Toastr.success(response.data);\n }\n\n return response;\n};\n\nconst pullDataFromResponse = response => {\n const { includeMetadataInResponse = false } = response.config;\n\n return includeMetadataInResponse ? response : response.data;\n};\n\nconst buildSuccessResponseHandler = skip => {\n const interceptors = [];\n if (!skip?.transformCase) interceptors.push(transformResponseKeysToCamelCase);\n\n if (!skip?.showToastr) interceptors.push(showSuccessToastr);\n\n if (!skip?.pullDataFromResponse) interceptors.push(pullDataFromResponse);\n\n return createPipe(interceptors);\n};\n\nconst handleUnauthorizedErrorResponse = error => {\n if (error.response?.status !== 401) return error;\n\n resetAuthTokens();\n\n const { redirectOnError = true } = error.config ?? {};\n if (redirectOnError) {\n setTimeout(() => {\n const redirectTo =\n window.location.pathname === \"/login\"\n ? \"/login\"\n : `/login?redirect_uri=${encodeURIComponent(window.location.href)}`;\n\n // eslint-disable-next-line xss/no-location-href-assign\n window.location.href = redirectTo;\n }, 300);\n }\n\n return error;\n};\n\nconst isOnline = () => window.navigator.onLine;\n\nconst showOfflineToastr = () => {\n const toastId = Toastr.error(\n i18next.t(\"neetoCommons.toastr.error.networkError\")\n );\n\n if (toastId) {\n const dismissToastInterval = setInterval(() => {\n if (!isOnline()) return;\n\n toast.dismiss(toastId);\n clearInterval(dismissToastInterval);\n checkOnlineInterval = null;\n }, 1000);\n }\n};\n\nconst handleNetworkError = error => {\n if (isOnline()) {\n Toastr.error(i18next.t(\"generic.error\"));\n\n return error;\n }\n\n if (checkOnlineInterval) return error;\n\n const startTime = Date.now();\n\n checkOnlineInterval = setInterval(() => {\n const elapsedTime = Date.now() - startTime;\n\n if (isOnline()) {\n clearInterval(checkOnlineInterval);\n checkOnlineInterval = null;\n } else if (elapsedTime >= MAXIMUM_OFFLINE_DURATION) {\n clearInterval(checkOnlineInterval);\n showOfflineToastr();\n }\n }, 1000);\n\n return error;\n};\n\nconst showErrorToastr = error => {\n const { showToastr = true } = error.config ?? {};\n if (!showToastr) return error;\n\n const { status } = error.response ?? {};\n\n if (error.message === \"Network Error\") return handleNetworkError(error);\n\n if (error.code === \"ECONNABORTED\") {\n return error;\n }\n\n if (![403, 404, 520].includes(status) && !axios.isCancel(error)) {\n // we already display a page in case of 403 & 404 and we don't want to show a toastr for cancelled requests.\n // We handle cloudflare error differently for production and other environments.\n Toastr.error(error);\n }\n\n if (status === 520) {\n if (globalProps.railsEnv === \"production\") {\n Toastr.error(i18next.t(\"generic.error\"));\n } else Toastr.error(error);\n }\n\n return error;\n};\n\nconst getUrlPathName = url => {\n try {\n return new URL(url).pathname;\n } catch {\n return url;\n }\n};\n\nconst handle404ErrorResponse = error => {\n const { show404ErrorPage = true, show403ErrorPage = true } =\n error.config ?? {};\n\n const status = error.response?.status;\n if (\n (status === 404 && show404ErrorPage) ||\n (status === 403 && show403ErrorPage)\n ) {\n const fullUrl = error.request?.responseURL || error.config.url;\n useErrorDisplayStore.setState({\n showErrorPage: true,\n statusCode: status,\n failedApiUrl: fullUrl,\n failedApiPath: getUrlPathName(fullUrl),\n });\n }\n\n return error;\n};\n\nconst buildErrorResponseHandler = skip => {\n const interceptors = [];\n if (!skip?.transformCase) interceptors.push(transformErrorKeysToCamelCase);\n\n if (!skip?.show404ErrorPage) interceptors.push(handle404ErrorResponse);\n\n if (!skip?.logoutOn401) interceptors.push(handleUnauthorizedErrorResponse);\n\n if (!skip?.showToastr) interceptors.push(showErrorToastr);\n\n interceptors.push(Promise.reject.bind(Promise));\n\n return createPipe(interceptors);\n};\n\nconst cleanupCredentialsForCrossOrigin = request => {\n if (!request.url.includes(\"://\")) return request;\n\n if (request.url.includes(window.location.hostname)) return request;\n\n return evolve({ headers: omit([HEADERS_KEYS.xCsrfToken]) })(request);\n};\n\nconst transformDataToSnakeCase = request => {\n const { transformRequestCase = true } = request;\n\n if (!transformRequestCase) return request;\n\n return evolve(\n { data: serializeKeysToSnakeCase, params: serializeKeysToSnakeCase },\n request\n );\n};\n\nconst addRequestInterceptors = skip => {\n if (!skip?.cleanCredentialsForCrossOrigin) {\n axios.interceptors.request.use(cleanupCredentialsForCrossOrigin);\n }\n\n if (!skip?.transformCase) {\n axios.interceptors.request.use(transformDataToSnakeCase);\n }\n};\n\nconst addResponseInterceptors = skip => {\n axios.interceptors.response.use(\n buildSuccessResponseHandler(skip),\n buildErrorResponseHandler(skip)\n );\n};\n\nconst registerIntercepts = skip => {\n if (shouldNot(skip?.request)) addRequestInterceptors(skip?.request);\n\n if (shouldNot(skip?.response)) addResponseInterceptors(skip?.response);\n};\n\nexport default function initializeAxios(skip) {\n if (!skip?.baseURL) axios.defaults.baseURL = \"/\";\n\n if (!skip?.authHeaders) setAuthHeaders();\n\n if (!skip?.paramsSerializer) setParamsSerializer();\n\n if (shouldNot(skip?.interceptors)) registerIntercepts(skip?.interceptors);\n}\n"],"mappings":";;;;;;;;;AAAA,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,QAAA,GAAAF,sBAAA,CAAAC,OAAA;AACA,IAAAE,UAAA,GAAAF,OAAA;AAA+E,IAAAG,OAAA,GAAAJ,sBAAA,CAAAC,OAAA;AAE/E,IAAAI,MAAA,GAAAJ,OAAA;AACA,IAAAK,cAAA,GAAAL,OAAA;AACA,IAAAM,oBAAA,GAAAN,OAAA;AACA,IAAAO,OAA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D,YAAY,CAAC,EAAEyF,kBAAkB,CAAC3I,IAAI,aAAJA,IAAI,uBAAJA,IAAI,CAAEkD,YAAY,CAAC;AAC3E"}
|
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
|
|
2
1
|
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
3
2
|
import _typeof from "@babel/runtime/helpers/typeof";
|
|
4
|
-
import _regeneratorRuntime from "@babel/runtime/regenerator";
|
|
5
3
|
import axios from "axios";
|
|
6
4
|
import i18next from "i18next";
|
|
7
5
|
import { keysToCamelCase, matches, serializeKeysToSnakeCase } from "@bigbinary/neeto-cist";
|
|
8
6
|
import Toastr from "@bigbinary/neetoui/Toastr";
|
|
9
7
|
import { evolve, omit } from "ramda";
|
|
8
|
+
import { toast } from "react-toastify";
|
|
10
9
|
import { useErrorDisplayStore } from "../../react-utils/useDisplayErrorPage";
|
|
11
10
|
import { resetAuthTokens } from "../../utils/axios";
|
|
12
11
|
import setParamsSerializer from "./paramsSerializer";
|
|
13
|
-
import {
|
|
12
|
+
import { HEADERS_KEYS, MAXIMUM_OFFLINE_DURATION } from "../constants";
|
|
13
|
+
var checkOnlineInterval = null;
|
|
14
14
|
var shouldNot = function shouldNot(skip) {
|
|
15
15
|
return _typeof(skip) === "object" || !skip;
|
|
16
16
|
};
|
|
@@ -104,49 +104,51 @@ var handleUnauthorizedErrorResponse = function handleUnauthorizedErrorResponse(e
|
|
|
104
104
|
}
|
|
105
105
|
return error;
|
|
106
106
|
};
|
|
107
|
-
var
|
|
108
|
-
return
|
|
109
|
-
};
|
|
110
|
-
var
|
|
111
|
-
var
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
}();
|
|
107
|
+
var isOnline = function isOnline() {
|
|
108
|
+
return window.navigator.onLine;
|
|
109
|
+
};
|
|
110
|
+
var showOfflineToastr = function showOfflineToastr() {
|
|
111
|
+
var toastId = Toastr.error(i18next.t("neetoCommons.toastr.error.networkError"));
|
|
112
|
+
if (toastId) {
|
|
113
|
+
var dismissToastInterval = setInterval(function () {
|
|
114
|
+
if (!isOnline()) return;
|
|
115
|
+
toast.dismiss(toastId);
|
|
116
|
+
clearInterval(dismissToastInterval);
|
|
117
|
+
checkOnlineInterval = null;
|
|
118
|
+
}, 1000);
|
|
119
|
+
}
|
|
120
|
+
};
|
|
121
|
+
var handleNetworkError = function handleNetworkError(error) {
|
|
122
|
+
if (isOnline()) {
|
|
123
|
+
Toastr.error(i18next.t("generic.error"));
|
|
124
|
+
return error;
|
|
125
|
+
}
|
|
126
|
+
if (checkOnlineInterval) return error;
|
|
127
|
+
var startTime = Date.now();
|
|
128
|
+
checkOnlineInterval = setInterval(function () {
|
|
129
|
+
var elapsedTime = Date.now() - startTime;
|
|
130
|
+
if (isOnline()) {
|
|
131
|
+
clearInterval(checkOnlineInterval);
|
|
132
|
+
checkOnlineInterval = null;
|
|
133
|
+
} else if (elapsedTime >= MAXIMUM_OFFLINE_DURATION) {
|
|
134
|
+
clearInterval(checkOnlineInterval);
|
|
135
|
+
showOfflineToastr();
|
|
136
|
+
}
|
|
137
|
+
}, 1000);
|
|
138
|
+
return error;
|
|
139
|
+
};
|
|
141
140
|
var showErrorToastr = function showErrorToastr(error) {
|
|
142
141
|
var _error$config3, _error$response3;
|
|
143
|
-
var
|
|
144
|
-
|
|
145
|
-
showToastr =
|
|
142
|
+
var _ref3 = (_error$config3 = error.config) !== null && _error$config3 !== void 0 ? _error$config3 : {},
|
|
143
|
+
_ref3$showToastr = _ref3.showToastr,
|
|
144
|
+
showToastr = _ref3$showToastr === void 0 ? true : _ref3$showToastr;
|
|
146
145
|
if (!showToastr) return error;
|
|
147
|
-
var
|
|
148
|
-
status =
|
|
146
|
+
var _ref4 = (_error$response3 = error.response) !== null && _error$response3 !== void 0 ? _error$response3 : {},
|
|
147
|
+
status = _ref4.status;
|
|
149
148
|
if (error.message === "Network Error") return handleNetworkError(error);
|
|
149
|
+
if (error.code === "ECONNABORTED") {
|
|
150
|
+
return error;
|
|
151
|
+
}
|
|
150
152
|
if (![403, 404, 520].includes(status) && !axios.isCancel(error)) {
|
|
151
153
|
// we already display a page in case of 403 & 404 and we don't want to show a toastr for cancelled requests.
|
|
152
154
|
// We handle cloudflare error differently for production and other environments.
|
|
@@ -168,11 +170,11 @@ var getUrlPathName = function getUrlPathName(url) {
|
|
|
168
170
|
};
|
|
169
171
|
var handle404ErrorResponse = function handle404ErrorResponse(error) {
|
|
170
172
|
var _error$config4, _error$response4;
|
|
171
|
-
var
|
|
172
|
-
|
|
173
|
-
show404ErrorPage =
|
|
174
|
-
|
|
175
|
-
show403ErrorPage =
|
|
173
|
+
var _ref5 = (_error$config4 = error.config) !== null && _error$config4 !== void 0 ? _error$config4 : {},
|
|
174
|
+
_ref5$show404ErrorPag = _ref5.show404ErrorPage,
|
|
175
|
+
show404ErrorPage = _ref5$show404ErrorPag === void 0 ? true : _ref5$show404ErrorPag,
|
|
176
|
+
_ref5$show403ErrorPag = _ref5.show403ErrorPage,
|
|
177
|
+
show403ErrorPage = _ref5$show403ErrorPag === void 0 ? true : _ref5$show403ErrorPag;
|
|
176
178
|
var status = (_error$response4 = error.response) === null || _error$response4 === void 0 ? void 0 : _error$response4.status;
|
|
177
179
|
if (status === 404 && show404ErrorPage || status === 403 && show403ErrorPage) {
|
|
178
180
|
var _error$request;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["axios","i18next","keysToCamelCase","matches","serializeKeysToSnakeCase","Toastr","evolve","omit","useErrorDisplayStore","resetAuthTokens","setParamsSerializer","MAXIMUM_OFFLINE_DURATION","HEADERS_KEYS","shouldNot","skip","_typeof","shouldShowToastr","response","notice","noticeCode","setAuthHeaders","_document$querySelect","_axios$defaults$heade","defaults","headers","_defineProperty","accept","contentType","xCsrfToken","document","querySelector","getAttribute","createPipe","functions","data","reduce","acc","fn","transformResponseKeysToCamelCase","_response$config$tran","config","transformResponseCase","transformErrorKeysToCamelCase","error","_error$config","_error$response","_ref","_ref$transformRespons","showSuccessToastr","_response$config$show","showToastr","showThumbsUpToastr","success","icon","className","pullDataFromResponse","_response$config$incl","includeMetadataInResponse","buildSuccessResponseHandler","interceptors","transformCase","push","handleUnauthorizedErrorResponse","_error$response2","_error$config2","status","_ref2","_ref2$redirectOnError","redirectOnError","setTimeout","redirectTo","window","location","pathname","concat","encodeURIComponent","href","isUserOffline","navigator","onLine","handleNetworkError","_ref3","_asyncToGenerator","_regeneratorRuntime","mark","_callee","errorMessage","wrap","_callee$","_context","prev","next","t","Promise","resolve","abrupt","stop","_x","apply","arguments","showErrorToastr","_error$config3","_error$response3","_ref4","_ref4$showToastr","_ref5","message","includes","isCancel","globalProps","railsEnv","getUrlPathName","url","URL","_unused","handle404ErrorResponse","_error$config4","_error$response4","_ref6","_ref6$show404ErrorPag","show404ErrorPage","_ref6$show403ErrorPag","show403ErrorPage","_error$request","fullUrl","request","responseURL","setState","showErrorPage","statusCode","failedApiUrl","failedApiPath","buildErrorResponseHandler","logoutOn401","reject","bind","cleanupCredentialsForCrossOrigin","hostname","transformDataToSnakeCase","_request$transformReq","transformRequestCase","params","addRequestInterceptors","cleanCredentialsForCrossOrigin","use","addResponseInterceptors","registerIntercepts","initializeAxios","baseURL","authHeaders","paramsSerializer"],"sources":["../../../src/initializers/axiosInitializer/index.js"],"sourcesContent":["import axios from \"axios\";\nimport i18next from \"i18next\";\nimport { keysToCamelCase, matches, serializeKeysToSnakeCase } from \"neetocist\";\nimport { Toastr } from \"neetoui\";\nimport { evolve, omit } from \"ramda\";\nimport { useErrorDisplayStore } from \"react-utils/useDisplayErrorPage\";\nimport { resetAuthTokens } from \"utils/axios\";\n\nimport setParamsSerializer from \"./paramsSerializer\";\n\nimport { MAXIMUM_OFFLINE_DURATION, HEADERS_KEYS } from \"../constants\";\n\nconst shouldNot = skip => typeof skip === \"object\" || !skip;\n\nconst shouldShowToastr = response =>\n typeof response === \"string\" ||\n (typeof response === \"object\" && (response?.notice || response?.noticeCode));\n\nconst setAuthHeaders = () => {\n // @ts-ignore\n axios.defaults.headers = {\n [HEADERS_KEYS.accept]: \"application/json\",\n [HEADERS_KEYS.contentType]: \"application/json\",\n [HEADERS_KEYS.xCsrfToken]: document\n .querySelector('[name=\"csrf-token\"]')\n ?.getAttribute(\"content\"),\n };\n};\n\n// pipe function from ramda doesn't accept array of functions.\n// We can't use spread operator too. So this is a workaround.\nconst createPipe = functions => data =>\n functions.reduce((acc, fn) => fn(acc), data);\n\nconst transformResponseKeysToCamelCase = response => {\n const { transformResponseCase = true } = response.config;\n\n if (response.data && transformResponseCase) {\n response.data = keysToCamelCase(response.data);\n }\n\n return response;\n};\n\nconst transformErrorKeysToCamelCase = error => {\n const { transformResponseCase = true } = error.config ?? {};\n\n if (error.response?.data && transformResponseCase) {\n error.response.data = keysToCamelCase(error.response.data);\n }\n\n return error;\n};\n\nconst showSuccessToastr = response => {\n const { showToastr = true } = response.config;\n if (!showToastr) return response;\n\n if (matches({ showThumbsUpToastr: true }, response.data)) {\n // @ts-ignore\n Toastr.success(\"\", { icon: \"👍\", className: \"w-20\" });\n } else if (matches({ noticeCode: \"thumbs_up\" }, response.data)) {\n // @ts-ignore\n Toastr.success(\"\", { icon: \"👍\", className: \"w-20\" });\n } else if (shouldShowToastr(response.data)) {\n Toastr.success(response.data);\n }\n\n return response;\n};\n\nconst pullDataFromResponse = response => {\n const { includeMetadataInResponse = false } = response.config;\n\n return includeMetadataInResponse ? response : response.data;\n};\n\nconst buildSuccessResponseHandler = skip => {\n const interceptors = [];\n if (!skip?.transformCase) interceptors.push(transformResponseKeysToCamelCase);\n\n if (!skip?.showToastr) interceptors.push(showSuccessToastr);\n\n if (!skip?.pullDataFromResponse) interceptors.push(pullDataFromResponse);\n\n return createPipe(interceptors);\n};\n\nconst handleUnauthorizedErrorResponse = error => {\n if (error.response?.status !== 401) return error;\n\n resetAuthTokens();\n\n const { redirectOnError = true } = error.config ?? {};\n if (redirectOnError) {\n setTimeout(() => {\n const redirectTo =\n window.location.pathname === \"/login\"\n ? \"/login\"\n : `/login?redirect_uri=${encodeURIComponent(window.location.href)}`;\n\n // eslint-disable-next-line xss/no-location-href-assign\n window.location.href = redirectTo;\n }, 300);\n }\n\n return error;\n};\n\nconst isUserOffline = () => !window.navigator.onLine;\n\nconst handleNetworkError = async error => {\n const errorMessage = i18next.t(\"neetoCommons.toastr.error.networkError\");\n if (isUserOffline()) {\n await new Promise(resolve => setTimeout(resolve, MAXIMUM_OFFLINE_DURATION));\n\n if (isUserOffline()) Toastr.error(errorMessage);\n\n return error;\n }\n Toastr.error(errorMessage);\n\n return error;\n};\n\nconst showErrorToastr = error => {\n const { showToastr = true } = error.config ?? {};\n if (!showToastr) return error;\n\n const { status } = error.response ?? {};\n\n if (error.message === \"Network Error\") return handleNetworkError(error);\n\n if (![403, 404, 520].includes(status) && !axios.isCancel(error)) {\n // we already display a page in case of 403 & 404 and we don't want to show a toastr for cancelled requests.\n // We handle cloudflare error differently for production and other environments.\n Toastr.error(error);\n }\n\n if (status === 520) {\n if (globalProps.railsEnv === \"production\") {\n Toastr.error(i18next.t(\"generic.error\"));\n } else Toastr.error(error);\n }\n\n return error;\n};\n\nconst getUrlPathName = url => {\n try {\n return new URL(url).pathname;\n } catch {\n return url;\n }\n};\n\nconst handle404ErrorResponse = error => {\n const { show404ErrorPage = true, show403ErrorPage = true } =\n error.config ?? {};\n\n const status = error.response?.status;\n if (\n (status === 404 && show404ErrorPage) ||\n (status === 403 && show403ErrorPage)\n ) {\n const fullUrl = error.request?.responseURL || error.config.url;\n useErrorDisplayStore.setState({\n showErrorPage: true,\n statusCode: status,\n failedApiUrl: fullUrl,\n failedApiPath: getUrlPathName(fullUrl),\n });\n }\n\n return error;\n};\n\nconst buildErrorResponseHandler = skip => {\n const interceptors = [];\n if (!skip?.transformCase) interceptors.push(transformErrorKeysToCamelCase);\n\n if (!skip?.show404ErrorPage) interceptors.push(handle404ErrorResponse);\n\n if (!skip?.logoutOn401) interceptors.push(handleUnauthorizedErrorResponse);\n\n if (!skip?.showToastr) interceptors.push(showErrorToastr);\n\n interceptors.push(Promise.reject.bind(Promise));\n\n return createPipe(interceptors);\n};\n\nconst cleanupCredentialsForCrossOrigin = request => {\n if (!request.url.includes(\"://\")) return request;\n\n if (request.url.includes(window.location.hostname)) return request;\n\n return evolve({ headers: omit([HEADERS_KEYS.xCsrfToken]) })(request);\n};\n\nconst transformDataToSnakeCase = request => {\n const { transformRequestCase = true } = request;\n\n if (!transformRequestCase) return request;\n\n return evolve(\n { data: serializeKeysToSnakeCase, params: serializeKeysToSnakeCase },\n request\n );\n};\n\nconst addRequestInterceptors = skip => {\n if (!skip?.cleanCredentialsForCrossOrigin) {\n axios.interceptors.request.use(cleanupCredentialsForCrossOrigin);\n }\n\n if (!skip?.transformCase) {\n axios.interceptors.request.use(transformDataToSnakeCase);\n }\n};\n\nconst addResponseInterceptors = skip => {\n axios.interceptors.response.use(\n buildSuccessResponseHandler(skip),\n buildErrorResponseHandler(skip)\n );\n};\n\nconst registerIntercepts = skip => {\n if (shouldNot(skip?.request)) addRequestInterceptors(skip?.request);\n\n if (shouldNot(skip?.response)) addResponseInterceptors(skip?.response);\n};\n\nexport default function initializeAxios(skip) {\n if (!skip?.baseURL) axios.defaults.baseURL = \"/\";\n\n if (!skip?.authHeaders) setAuthHeaders();\n\n if (!skip?.paramsSerializer) setParamsSerializer();\n\n if (shouldNot(skip?.interceptors)) registerIntercepts(skip?.interceptors);\n}\n"],"mappings":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Toastr","evolve","omit","toast","useErrorDisplayStore","resetAuthTokens","setParamsSerializer","HEADERS_KEYS","MAXIMUM_OFFLINE_DURATION","checkOnlineInterval","shouldNot","skip","_typeof","shouldShowToastr","response","notice","noticeCode","setAuthHeaders","_document$querySelect","_axios$defaults$heade","defaults","headers","_defineProperty","accept","contentType","xCsrfToken","document","querySelector","getAttribute","createPipe","functions","data","reduce","acc","fn","transformResponseKeysToCamelCase","_response$config$tran","config","transformResponseCase","transformErrorKeysToCamelCase","error","_error$config","_error$response","_ref","_ref$transformRespons","showSuccessToastr","_response$config$show","showToastr","showThumbsUpToastr","success","icon","className","pullDataFromResponse","_response$config$incl","includeMetadataInResponse","buildSuccessResponseHandler","interceptors","transformCase","push","handleUnauthorizedErrorResponse","_error$response2","_error$config2","status","_ref2","_ref2$redirectOnError","redirectOnError","setTimeout","redirectTo","window","location","pathname","concat","encodeURIComponent","href","isOnline","navigator","onLine","showOfflineToastr","toastId","t","dismissToastInterval","setInterval","dismiss","clearInterval","handleNetworkError","startTime","Date","now","elapsedTime","showErrorToastr","_error$config3","_error$response3","_ref3","_ref3$showToastr","_ref4","message","code","includes","isCancel","globalProps","railsEnv","getUrlPathName","url","URL","_unused","handle404ErrorResponse","_error$config4","_error$response4","_ref5","_ref5$show404ErrorPag","show404ErrorPage","_ref5$show403ErrorPag","show403ErrorPage","_error$request","fullUrl","request","responseURL","setState","showErrorPage","statusCode","failedApiUrl","failedApiPath","buildErrorResponseHandler","logoutOn401","Promise","reject","bind","cleanupCredentialsForCrossOrigin","hostname","transformDataToSnakeCase","_request$transformReq","transformRequestCase","params","addRequestInterceptors","cleanCredentialsForCrossOrigin","use","addResponseInterceptors","registerIntercepts","initializeAxios","baseURL","authHeaders","paramsSerializer"],"sources":["../../../src/initializers/axiosInitializer/index.js"],"sourcesContent":["import axios from \"axios\";\nimport i18next from \"i18next\";\nimport { keysToCamelCase, matches, serializeKeysToSnakeCase } from \"neetocist\";\nimport { Toastr } from \"neetoui\";\nimport { evolve, omit } from \"ramda\";\nimport { toast } from \"react-toastify\";\nimport { useErrorDisplayStore } from \"react-utils/useDisplayErrorPage\";\nimport { resetAuthTokens } from \"utils/axios\";\n\nimport setParamsSerializer from \"./paramsSerializer\";\n\nimport { HEADERS_KEYS, MAXIMUM_OFFLINE_DURATION } from \"../constants\";\n\nlet checkOnlineInterval = null;\n\nconst shouldNot = skip => typeof skip === \"object\" || !skip;\n\nconst shouldShowToastr = response =>\n typeof response === \"string\" ||\n (typeof response === \"object\" && (response?.notice || response?.noticeCode));\n\nconst setAuthHeaders = () => {\n // @ts-ignore\n axios.defaults.headers = {\n [HEADERS_KEYS.accept]: \"application/json\",\n [HEADERS_KEYS.contentType]: \"application/json\",\n [HEADERS_KEYS.xCsrfToken]: document\n .querySelector('[name=\"csrf-token\"]')\n ?.getAttribute(\"content\"),\n };\n};\n\n// pipe function from ramda doesn't accept array of functions.\n// We can't use spread operator too. So this is a workaround.\nconst createPipe = functions => data =>\n functions.reduce((acc, fn) => fn(acc), data);\n\nconst transformResponseKeysToCamelCase = response => {\n const { transformResponseCase = true } = response.config;\n\n if (response.data && transformResponseCase) {\n response.data = keysToCamelCase(response.data);\n }\n\n return response;\n};\n\nconst transformErrorKeysToCamelCase = error => {\n const { transformResponseCase = true } = error.config ?? {};\n\n if (error.response?.data && transformResponseCase) {\n error.response.data = keysToCamelCase(error.response.data);\n }\n\n return error;\n};\n\nconst showSuccessToastr = response => {\n const { showToastr = true } = response.config;\n if (!showToastr) return response;\n\n if (matches({ showThumbsUpToastr: true }, response.data)) {\n // @ts-ignore\n Toastr.success(\"\", { icon: \"👍\", className: \"w-20\" });\n } else if (matches({ noticeCode: \"thumbs_up\" }, response.data)) {\n // @ts-ignore\n Toastr.success(\"\", { icon: \"👍\", className: \"w-20\" });\n } else if (shouldShowToastr(response.data)) {\n Toastr.success(response.data);\n }\n\n return response;\n};\n\nconst pullDataFromResponse = response => {\n const { includeMetadataInResponse = false } = response.config;\n\n return includeMetadataInResponse ? response : response.data;\n};\n\nconst buildSuccessResponseHandler = skip => {\n const interceptors = [];\n if (!skip?.transformCase) interceptors.push(transformResponseKeysToCamelCase);\n\n if (!skip?.showToastr) interceptors.push(showSuccessToastr);\n\n if (!skip?.pullDataFromResponse) interceptors.push(pullDataFromResponse);\n\n return createPipe(interceptors);\n};\n\nconst handleUnauthorizedErrorResponse = error => {\n if (error.response?.status !== 401) return error;\n\n resetAuthTokens();\n\n const { redirectOnError = true } = error.config ?? {};\n if (redirectOnError) {\n setTimeout(() => {\n const redirectTo =\n window.location.pathname === \"/login\"\n ? \"/login\"\n : `/login?redirect_uri=${encodeURIComponent(window.location.href)}`;\n\n // eslint-disable-next-line xss/no-location-href-assign\n window.location.href = redirectTo;\n }, 300);\n }\n\n return error;\n};\n\nconst isOnline = () => window.navigator.onLine;\n\nconst showOfflineToastr = () => {\n const toastId = Toastr.error(\n i18next.t(\"neetoCommons.toastr.error.networkError\")\n );\n\n if (toastId) {\n const dismissToastInterval = setInterval(() => {\n if (!isOnline()) return;\n\n toast.dismiss(toastId);\n clearInterval(dismissToastInterval);\n checkOnlineInterval = null;\n }, 1000);\n }\n};\n\nconst handleNetworkError = error => {\n if (isOnline()) {\n Toastr.error(i18next.t(\"generic.error\"));\n\n return error;\n }\n\n if (checkOnlineInterval) return error;\n\n const startTime = Date.now();\n\n checkOnlineInterval = setInterval(() => {\n const elapsedTime = Date.now() - startTime;\n\n if (isOnline()) {\n clearInterval(checkOnlineInterval);\n checkOnlineInterval = null;\n } else if (elapsedTime >= MAXIMUM_OFFLINE_DURATION) {\n clearInterval(checkOnlineInterval);\n showOfflineToastr();\n }\n }, 1000);\n\n return error;\n};\n\nconst showErrorToastr = error => {\n const { showToastr = true } = error.config ?? {};\n if (!showToastr) return error;\n\n const { status } = error.response ?? {};\n\n if (error.message === \"Network Error\") return handleNetworkError(error);\n\n if (error.code === \"ECONNABORTED\") {\n return error;\n }\n\n if (![403, 404, 520].includes(status) && !axios.isCancel(error)) {\n // we already display a page in case of 403 & 404 and we don't want to show a toastr for cancelled requests.\n // We handle cloudflare error differently for production and other environments.\n Toastr.error(error);\n }\n\n if (status === 520) {\n if (globalProps.railsEnv === \"production\") {\n Toastr.error(i18next.t(\"generic.error\"));\n } else Toastr.error(error);\n }\n\n return error;\n};\n\nconst getUrlPathName = url => {\n try {\n return new URL(url).pathname;\n } catch {\n return url;\n }\n};\n\nconst handle404ErrorResponse = error => {\n const { show404ErrorPage = true, show403ErrorPage = true } =\n error.config ?? {};\n\n const status = error.response?.status;\n if (\n (status === 404 && show404ErrorPage) ||\n (status === 403 && show403ErrorPage)\n ) {\n const fullUrl = error.request?.responseURL || error.config.url;\n useErrorDisplayStore.setState({\n showErrorPage: true,\n statusCode: status,\n failedApiUrl: fullUrl,\n failedApiPath: getUrlPathName(fullUrl),\n });\n }\n\n return error;\n};\n\nconst buildErrorResponseHandler = skip => {\n const interceptors = [];\n if (!skip?.transformCase) interceptors.push(transformErrorKeysToCamelCase);\n\n if (!skip?.show404ErrorPage) interceptors.push(handle404ErrorResponse);\n\n if (!skip?.logoutOn401) interceptors.push(handleUnauthorizedErrorResponse);\n\n if (!skip?.showToastr) interceptors.push(showErrorToastr);\n\n interceptors.push(Promise.reject.bind(Promise));\n\n return createPipe(interceptors);\n};\n\nconst cleanupCredentialsForCrossOrigin = request => {\n if (!request.url.includes(\"://\")) return request;\n\n if (request.url.includes(window.location.hostname)) return request;\n\n return evolve({ headers: omit([HEADERS_KEYS.xCsrfToken]) })(request);\n};\n\nconst transformDataToSnakeCase = request => {\n const { transformRequestCase = true } = request;\n\n if (!transformRequestCase) return request;\n\n return evolve(\n { data: serializeKeysToSnakeCase, params: serializeKeysToSnakeCase },\n request\n );\n};\n\nconst addRequestInterceptors = skip => {\n if (!skip?.cleanCredentialsForCrossOrigin) {\n axios.interceptors.request.use(cleanupCredentialsForCrossOrigin);\n }\n\n if (!skip?.transformCase) {\n axios.interceptors.request.use(transformDataToSnakeCase);\n }\n};\n\nconst addResponseInterceptors = skip => {\n axios.interceptors.response.use(\n buildSuccessResponseHandler(skip),\n buildErrorResponseHandler(skip)\n );\n};\n\nconst registerIntercepts = skip => {\n if (shouldNot(skip?.request)) addRequestInterceptors(skip?.request);\n\n if (shouldNot(skip?.response)) addResponseInterceptors(skip?.response);\n};\n\nexport default function initializeAxios(skip) {\n if (!skip?.baseURL) axios.defaults.baseURL = \"/\";\n\n if (!skip?.authHeaders) setAuthHeaders();\n\n if (!skip?.paramsSerializer) setParamsSerializer();\n\n if (shouldNot(skip?.interceptors)) registerIntercepts(skip?.interceptors);\n}\n"],"mappings":";;AAAA,OAAOA,KAAK,MAAM,OAAO;AACzB,OAAOC,OAAO,MAAM,SAAS;AAC7B,SAASC,eAAe,EAAEC,OAAO,EAAEC,wBAAwB;AAAoB,OAAAC,MAAA;AAE/E,SAASC,MAAM,EAAEC,IAAI,QAAQ,OAAO;AACpC,SAASC,KAAK,QAAQ,gBAAgB;AACtC,SAASC,oBAAoB;AAC7B,SAASC,eAAe;AAExB,OAAOC,mBAAmB;AAE1B,SAASC,YAAY,EAAEC,wBAAwB;AAE/C,IAAIC,mBAAmB,GAAG,IAAI;AAE9B,IAAMC,SAAS,GAAG,SAAZA,SAASA,CAAGC,IAAI;EAAA,OAAIC,OAAA,CAAOD,IAAI,MAAK,QAAQ,IAAI,CAACA,IAAI;AAAA;AAE3D,IAAME,gBAAgB,GAAG,SAAnBA,gBAAgBA,CAAGC,QAAQ;EAAA,OAC/B,OAAOA,QAAQ,KAAK,QAAQ,IAC3BF,OAAA,CAAOE,QAAQ,MAAK,QAAQ,KAAK,CAAAA,QAAQ,aAARA,QAAQ,uBAARA,QAAQ,CAAEC,MAAM,MAAID,QAAQ,aAARA,QAAQ,uBAARA,QAAQ,CAAEE,UAAU,EAAE;AAAA;AAE9E,IAAMC,cAAc,GAAG,SAAjBA,cAAcA,CAAA,EAAS;EAAA,IAAAC,qBAAA,EAAAC,qBAAA;EAC3B;EACAxB,KAAK,CAACyB,QAAQ,CAACC,O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AQ,CAAC,EAAE0H,uBAAuB,CAAC7H,IAAI,aAAJA,IAAI,uBAAJA,IAAI,CAAEG,QAAQ,CAAC;AACxE,CAAC;AAED,eAAe,SAAS4H,eAAeA,CAAC/H,IAAI,EAAE;EAC5C,IAAI,EAACA,IAAI,aAAJA,IAAI,eAAJA,IAAI,CAAEgI,OAAO,GAAEhJ,KAAK,CAACyB,QAAQ,CAACuH,OAAO,GAAG,GAAG;EAEhD,IAAI,EAAChI,IAAI,aAAJA,IAAI,eAAJA,IAAI,CAAEiI,WAAW,GAAE3H,cAAc,EAAE;EAExC,IAAI,EAACN,IAAI,aAAJA,IAAI,eAAJA,IAAI,CAAEkI,gBAAgB,GAAEvI,mBAAmB,EAAE;EAElD,IAAII,SAAS,CAACC,IAAI,aAAJA,IAAI,uBAAJA,IAAI,CAAE6C,YAAY,CAAC,EAAEiF,kBAAkB,CAAC9H,IAAI,aAAJA,IAAI,uBAAJA,IAAI,CAAE6C,YAAY,CAAC;AAC3E"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bigbinary/neeto-commons-frontend",
|
|
3
|
-
"version": "3.4.
|
|
3
|
+
"version": "3.4.5",
|
|
4
4
|
"description": "A package encapsulating common code across neeto projects including initializers, utility functions, common components and hooks and so on.",
|
|
5
5
|
"repository": "git@github.com:bigbinary/neeto-commons-frontend.git",
|
|
6
6
|
"author": "Amaljith K <amaljith.k@bigbinary.com>",
|