@bigbinary/neeto-commons-frontend 3.0.12 → 3.0.13
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.
- package/cjs/initializers/axios/index.js +6 -4
- package/cjs/initializers/axios/index.js.map +1 -1
- package/cjs/initializers/i18n.js +1 -1
- package/cjs/initializers/i18n.js.map +1 -1
- package/cjs/initializers/index.js +2 -2
- package/cjs/initializers/index.js.map +1 -1
- package/cjs/initializers/utils/utils.js.map +1 -0
- package/cjs/react-utils/useFetchNeetoApps/useFetchNeetoApps.js +3 -3
- package/cjs/react-utils/useFetchNeetoApps/useFetchNeetoApps.js.map +1 -1
- package/initializers/axios/index.js +4 -2
- package/initializers/axios/index.js.map +1 -1
- package/initializers/i18n.js +1 -1
- package/initializers/i18n.js.map +1 -1
- package/initializers/index.js +1 -1
- package/initializers/index.js.map +1 -1
- package/initializers/utils/utils.js.map +1 -0
- package/package.json +1 -1
- package/react-utils/useFetchNeetoApps/useFetchNeetoApps.js +1 -1
- package/react-utils/useFetchNeetoApps/useFetchNeetoApps.js.map +1 -1
- package/cjs/initializers/utils.js.map +0 -1
- package/initializers/utils.js.map +0 -1
- /package/cjs/initializers/{utils.js → utils/utils.js} +0 -0
- /package/initializers/{utils.js → utils/utils.js} +0 -0
|
@@ -10,10 +10,10 @@ var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
|
|
|
10
10
|
var _axios = _interopRequireDefault(require("axios"));
|
|
11
11
|
var _i18next = _interopRequireDefault(require("i18next"));
|
|
12
12
|
var _neetoCist = require("@bigbinary/neeto-cist");
|
|
13
|
-
var _reactUtils = require("@bigbinary/neeto-commons-frontend/react-utils");
|
|
14
|
-
var _utils = require("@bigbinary/neeto-commons-frontend/utils");
|
|
15
13
|
var _neetoui = require("@bigbinary/neetoui");
|
|
16
14
|
var _ramda = require("ramda");
|
|
15
|
+
var _useDisplayErrorPage = require("../../react-utils/useDisplayErrorPage");
|
|
16
|
+
var _axios2 = require("../../utils/axios");
|
|
17
17
|
var _paramsSerializer = _interopRequireDefault(require("./paramsSerializer"));
|
|
18
18
|
var _constants = require("../constants");
|
|
19
19
|
var shouldNot = function shouldNot(skip) {
|
|
@@ -95,13 +95,15 @@ var buildSuccessResponseHandler = function buildSuccessResponseHandler(skip) {
|
|
|
95
95
|
var handleUnauthorizedErrorResponse = function handleUnauthorizedErrorResponse(error) {
|
|
96
96
|
var _error$response2, _error$config2;
|
|
97
97
|
if (((_error$response2 = error.response) === null || _error$response2 === void 0 ? void 0 : _error$response2.status) !== 401) return error;
|
|
98
|
-
(0,
|
|
98
|
+
(0, _axios2.resetAuthTokens)();
|
|
99
99
|
var _ref2 = (_error$config2 = error.config) !== null && _error$config2 !== void 0 ? _error$config2 : {},
|
|
100
100
|
_ref2$redirectOnError = _ref2.redirectOnError,
|
|
101
101
|
redirectOnError = _ref2$redirectOnError === void 0 ? true : _ref2$redirectOnError;
|
|
102
102
|
if (redirectOnError) {
|
|
103
103
|
setTimeout(function () {
|
|
104
104
|
var redirectTo = window.location.pathname === "/login" ? "/login" : "/login?redirect_uri=".concat(encodeURIComponent(window.location.href));
|
|
105
|
+
|
|
106
|
+
// eslint-disable-next-line xss/no-location-href-assign
|
|
105
107
|
window.location.href = redirectTo;
|
|
106
108
|
}, 300);
|
|
107
109
|
}
|
|
@@ -140,7 +142,7 @@ var handle404ErrorResponse = function handle404ErrorResponse(error) {
|
|
|
140
142
|
if (status === 404 && show404ErrorPage || status === 403 && show403ErrorPage) {
|
|
141
143
|
var _error$request;
|
|
142
144
|
var fullUrl = ((_error$request = error.request) === null || _error$request === void 0 ? void 0 : _error$request.responseURL) || error.config.url;
|
|
143
|
-
|
|
145
|
+
_useDisplayErrorPage.useErrorDisplayStore.setState({
|
|
144
146
|
showErrorPage: true,
|
|
145
147
|
statusCode: status,
|
|
146
148
|
failedApiUrl: fullUrl,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["_axios","_interopRequireDefault","require","_i18next","_neetoCist","_reactUtils","_utils","_neetoui","_ramda","_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","showErrorToastr","_error$config3","_error$response3","_ref3","_ref3$showToastr","message","i18next","t","includes","isCancel","getUrlPathName","url","URL","_unused","handle404ErrorResponse","_error$config4","_error$response4","_ref4","_ref4$show404ErrorPag","show404ErrorPage","_ref4$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/axios/index.js"],"sourcesContent":["import axios from \"axios\";\nimport i18next from \"i18next\";\nimport { keysToCamelCase, matches, serializeKeysToSnakeCase } from \"neetocist\";\nimport { useErrorDisplayStore } from \"neetocommons/react-utils\";\nimport { resetAuthTokens } from \"neetocommons/utils\";\nimport { Toastr } from \"neetoui\";\nimport { evolve, omit } from \"ramda\";\n\nimport setParamsSerializer from \"./paramsSerializer\";\n\nimport { 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 window.location.href = redirectTo;\n }, 300);\n }\n\n return error;\n};\n\nconst showErrorToastr = error => {\n const { showToastr = true } = error.config ?? {};\n if (!showToastr) return error;\n\n if (error.message === \"Network Error\") {\n // @ts-ignore\n Toastr.error(i18next.t(\"neetoCommons.toastr.error.networkError\"));\n } else if (\n ![403, 404].includes(error.response?.status) &&\n !axios.isCancel(error)\n ) {\n // we already display a page in case of 403 & 404 and we don't want to show a toastr for cancelled requests.\n 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;AACA,IAAAG,WAAA,GAAAH,OAAA;AACA,IAAAI,MAAA,GAAAJ,OAAA;AACA,IAAAK,QAAA,GAAAL,OAAA;AACA,IAAAM,MAAA,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,I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EAAEsB,sBAAsB,CAACnH,IAAI,aAAJA,IAAI,uBAAJA,IAAI,CAAE6F,OAAO,CAAC;EAEnE,IAAI9F,SAAS,CAACC,IAAI,aAAJA,IAAI,uBAAJA,IAAI,CAAEG,QAAQ,CAAC,EAAEmH,uBAAuB,CAACtH,IAAI,aAAJA,IAAI,uBAAJA,IAAI,CAAEG,QAAQ,CAAC;AACxE,CAAC;AAEc,SAASqH,eAAeA,CAACxH,IAAI,EAAE;EAC5C,IAAI,EAACA,IAAI,aAAJA,IAAI,eAAJA,IAAI,CAAEyH,OAAO,GAAEhH,iBAAK,CAACC,QAAQ,CAAC+G,OAAO,GAAG,GAAG;EAEhD,IAAI,EAACzH,IAAI,aAAJA,IAAI,eAAJA,IAAI,CAAE0H,WAAW,GAAEpH,cAAc,EAAE;EAExC,IAAI,EAACN,IAAI,aAAJA,IAAI,eAAJA,IAAI,CAAE2H,gBAAgB,GAAE,IAAAC,4BAAmB,GAAE;EAElD,IAAI7H,SAAS,CAACC,IAAI,aAAJA,IAAI,uBAAJA,IAAI,CAAEkD,YAAY,CAAC,EAAEqE,kBAAkB,CAACvH,IAAI,aAAJA,IAAI,uBAAJA,IAAI,CAAEkD,YAAY,CAAC;AAC3E"}
|
|
1
|
+
{"version":3,"file":"index.js","names":["_axios","_interopRequireDefault","require","_i18next","_neetoCist","_neetoui","_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","showErrorToastr","_error$config3","_error$response3","_ref3","_ref3$showToastr","message","i18next","t","includes","isCancel","getUrlPathName","url","URL","_unused","handle404ErrorResponse","_error$config4","_error$response4","_ref4","_ref4$show404ErrorPag","show404ErrorPage","_ref4$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/axios/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 { 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 showErrorToastr = error => {\n const { showToastr = true } = error.config ?? {};\n if (!showToastr) return error;\n\n if (error.message === \"Network Error\") {\n // @ts-ignore\n Toastr.error(i18next.t(\"neetoCommons.toastr.error.networkError\"));\n } else if (\n ![403, 404].includes(error.response?.status) &&\n !axios.isCancel(error)\n ) {\n // we already display a page in case of 403 & 404 and we don't want to show a toastr for cancelled requests.\n 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;AACA,IAAAG,QAAA,GAAAH,OAAA;AACA,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;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,CAAC+G,OAAO,GAAG,GAAG;EAEhD,IAAI,EAACzH,IAAI,aAAJA,IAAI,eAAJA,IAAI,CAAE0H,WAAW,GAAEpH,cAAc,EAAE;EAExC,IAAI,EAACN,IAAI,aAAJA,IAAI,eAAJA,IAAI,CAAE2H,gBAAgB,GAAE,IAAAC,4BAAmB,GAAE;EAElD,IAAI7H,SAAS,CAACC,IAAI,aAAJA,IAAI,uBAAJA,IAAI,CAAEkD,YAAY,CAAC,EAAEqE,kBAAkB,CAACvH,IAAI,aAAJA,IAAI,uBAAJA,IAAI,CAAEkD,YAAY,CAAC;AAC3E"}
|
package/cjs/initializers/i18n.js
CHANGED
|
@@ -10,9 +10,9 @@ var _i18nextBrowserLanguagedetector = _interopRequireDefault(require("i18next-br
|
|
|
10
10
|
var _ramda = require("ramda");
|
|
11
11
|
var _reactI18next = require("react-i18next");
|
|
12
12
|
var _constants = require("./constants");
|
|
13
|
-
var _utils = require("./utils");
|
|
14
13
|
var _customFormatters = require("./utils/customFormatters");
|
|
15
14
|
var _customPostProcessors = require("./utils/customPostProcessors");
|
|
15
|
+
var _utils = require("./utils/utils");
|
|
16
16
|
var _en = _interopRequireDefault(require("../translations/en.json"));
|
|
17
17
|
// eslint-disable-next-line import/no-mutable-exports
|
|
18
18
|
var taxonomies = {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"i18n.js","names":["_i18next","_interopRequireDefault","require","_i18nextBrowserLanguagedetector","_ramda","_reactI18next","_constants","
|
|
1
|
+
{"version":3,"file":"i18n.js","names":["_i18next","_interopRequireDefault","require","_i18nextBrowserLanguagedetector","_ramda","_reactI18next","_constants","_customFormatters","_customPostProcessors","_utils","_en","taxonomies","exports","initializeI18n","hostTranslations","_window$globalProps","packageTranslations","preval","commonsTranslations","en","translation","commonsEn","resources","reduce","mergeDeepLeft","defaultTaxonomyKeys","Object","keys","taxonomyDefaultLabels","defaultTaxonomies","fromEntries","map","key","singular","plural","hostTaxonomies","window","globalProps","replaceNullValuesWithGetter","i18n","use","LanguageDetector","initReactI18next","sentenceCaseProcessor","init","fallbackLng","interpolation","defaultVariables","escapeValue","skipOnVariables","alwaysFormat","format","value","lng","options","newValue","LIST_FORMATS","includes","listFormatter","lowerCaseDynamicTextFormatter","postProcess","name","detection","order","caches","lookupQuerystring","lookupCookie","_default"],"sources":["../../../src/initializers/i18n.js"],"sourcesContent":["import i18n from \"i18next\";\nimport LanguageDetector from \"i18next-browser-languagedetector\";\nimport { mergeDeepLeft } from \"ramda\";\nimport { initReactI18next } from \"react-i18next\";\n\nimport { LIST_FORMATS } from \"./constants\";\nimport {\n listFormatter,\n lowerCaseDynamicTextFormatter,\n} from \"./utils/customFormatters\";\nimport { sentenceCaseProcessor } from \"./utils/customPostProcessors\";\nimport { replaceNullValuesWithGetter } from \"./utils/utils\";\n\nimport commonsEn from \"../translations/en.json\";\n\n// eslint-disable-next-line import/no-mutable-exports\nlet taxonomies = {};\n\nconst initializeI18n = hostTranslations => {\n // eslint-disable-next-line no-undef\n const packageTranslations = preval.require(\n \"../configs/scripts/getPkgTranslations.js\"\n );\n\n const commonsTranslations = { en: { translation: commonsEn } };\n\n const resources = [\n hostTranslations,\n commonsTranslations,\n packageTranslations,\n ].reduce(mergeDeepLeft);\n\n const defaultTaxonomyKeys = Object.keys(\n resources.en.translation.taxonomyDefaultLabels || {}\n );\n\n const defaultTaxonomies = Object.fromEntries(\n defaultTaxonomyKeys.map(key => [key, { singular: null, plural: null }])\n );\n\n const hostTaxonomies = window.globalProps?.taxonomies || {};\n\n taxonomies = replaceNullValuesWithGetter(\n mergeDeepLeft(hostTaxonomies, defaultTaxonomies)\n );\n\n i18n\n .use(LanguageDetector)\n .use(initReactI18next)\n .use(sentenceCaseProcessor)\n .init({\n resources,\n fallbackLng: \"en\",\n interpolation: {\n defaultVariables: { taxonomies },\n escapeValue: false,\n skipOnVariables: false,\n alwaysFormat: true,\n format: (value, format, lng, options) => {\n let newValue = value;\n\n if (LIST_FORMATS.includes(format)) {\n newValue = listFormatter({ value: newValue, format, lng, options });\n\n return newValue;\n }\n\n return lowerCaseDynamicTextFormatter(newValue, format);\n },\n },\n postProcess: [sentenceCaseProcessor.name],\n detection: {\n order: [\"querystring\", \"cookie\", \"navigator\", \"path\"],\n caches: [\"cookie\"],\n lookupQuerystring: \"lang\",\n lookupCookie: \"lang\",\n },\n });\n};\n\nexport { taxonomies };\n\nexport default initializeI18n;\n"],"mappings":";;;;;;;AAAA,IAAAA,QAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,+BAAA,GAAAF,sBAAA,CAAAC,OAAA;AACA,IAAAE,MAAA,GAAAF,OAAA;AACA,IAAAG,aAAA,GAAAH,OAAA;AAEA,IAAAI,UAAA,GAAAJ,OAAA;AACA,IAAAK,iBAAA,GAAAL,OAAA;AAIA,IAAAM,qBAAA,GAAAN,OAAA;AACA,IAAAO,MAAA,GAAAP,OAAA;AAEA,IAAAQ,GAAA,GAAAT,sBAAA,CAAAC,OAAA;AAEA;AACA,IAAIS,UAAU,GAAG,CAAC,CAAC;AAACC,OAAA,CAAAD,UAAA,GAAAA,UAAA;AAEpB,IAAME,cAAc,GAAG,SAAjBA,cAAcA,CAAGC,gBAAgB,EAAI;EAAA,IAAAC,mBAAA;EACzC;EACA,IAAMC,mBAAmB,GAAGC,MAAM,CAACf,OAAO,CACxC,0CAA0C,CAC3C;EAED,IAAMgB,mBAAmB,GAAG;IAAEC,EAAE,EAAE;MAAEC,WAAW,EAAEC;IAAU;EAAE,CAAC;EAE9D,IAAMC,SAAS,GAAG,CAChBR,gBAAgB,EAChBI,mBAAmB,EACnBF,mBAAmB,CACpB,CAACO,MAAM,CAACC,oBAAa,CAAC;EAEvB,IAAMC,mBAAmB,GAAGC,MAAM,CAACC,IAAI,CACrCL,SAAS,CAACH,EAAE,CAACC,WAAW,CAACQ,qBAAqB,IAAI,CAAC,CAAC,CACrD;EAED,IAAMC,iBAAiB,GAAGH,MAAM,CAACI,WAAW,CAC1CL,mBAAmB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ACzCC,SAAS,EAAE;MACTC,KAAK,EAAE,CAAC,aAAa,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,CAAC;MACrDC,MAAM,EAAE,CAAC,QAAQ,CAAC;MAClBC,iBAAiB,EAAE,MAAM;MACzBC,YAAY,EAAE;IAChB;EACF,CAAC,CAAC;AACN,CAAC;AAAC,IAAAC,QAAA,GAIatD,cAAc;AAAAD,OAAA,cAAAuD,QAAA"}
|
|
@@ -16,11 +16,11 @@ Object.defineProperty(exports, "taxonomies", {
|
|
|
16
16
|
Object.defineProperty(exports, "useDisplayErrorPage", {
|
|
17
17
|
enumerable: true,
|
|
18
18
|
get: function get() {
|
|
19
|
-
return
|
|
19
|
+
return _useDisplayErrorPage["default"];
|
|
20
20
|
}
|
|
21
21
|
});
|
|
22
22
|
var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
|
|
23
|
-
var
|
|
23
|
+
var _useDisplayErrorPage = _interopRequireDefault(require("../react-utils/useDisplayErrorPage"));
|
|
24
24
|
var _axios = _interopRequireDefault(require("./axios"));
|
|
25
25
|
var _globalProps = _interopRequireDefault(require("./globalProps"));
|
|
26
26
|
var _i18n = _interopRequireWildcard(require("./i18n"));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["
|
|
1
|
+
{"version":3,"file":"index.js","names":["_useDisplayErrorPage","_interopRequireDefault","require","_axios","_globalProps","_i18n","_interopRequireWildcard","_logger","_reactDevTools","_getRequireWildcardCache","nodeInterop","WeakMap","cacheBabelInterop","cacheNodeInterop","obj","__esModule","_typeof3","cache","has","get","newObj","hasPropertyDescriptor","Object","defineProperty","getOwnPropertyDescriptor","key","prototype","hasOwnProperty","call","desc","set","globalProps","exports","initializeApplication","_ref","translationResources","skip","initializeGlobalProps","window","_typeof2","axios","initializeAxios","i18n","initializeI18n","logger","initializeLogger","process","env","NODE_ENV","disableReactDevTools"],"sources":["../../../src/initializers/index.js"],"sourcesContent":["// TODO: kept for backward compatibility.\nimport useDisplayErrorPage from \"react-utils/useDisplayErrorPage\";\n\nimport initializeAxios from \"./axios\";\nimport initializeGlobalProps from \"./globalProps\";\nimport initializeI18n, { taxonomies } from \"./i18n\";\nimport initializeLogger from \"./logger\";\nimport disableReactDevTools from \"./reactDevTools\";\n\n// eslint-disable-next-line import/no-mutable-exports\nlet globalProps = {};\n\nexport { globalProps, useDisplayErrorPage, taxonomies };\n\nexport default function initializeApplication({ translationResources, skip }) {\n if (!skip?.globalProps) {\n initializeGlobalProps();\n // eslint-disable-next-line @bigbinary/neeto/no-globalProps-reassignment\n globalProps = window.globalProps;\n }\n\n if (typeof skip?.axios === \"object\" || !skip?.axios) {\n initializeAxios(skip?.axios);\n }\n\n if (!skip?.i18n) initializeI18n(translationResources);\n\n if (!skip?.logger) initializeLogger();\n\n if (process.env.NODE_ENV === \"production\") disableReactDevTools();\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AACA,IAAAA,oBAAA,GAAAC,sBAAA,CAAAC,OAAA;AAEA,IAAAC,MAAA,GAAAF,sBAAA,CAAAC,OAAA;AACA,IAAAE,YAAA,GAAAH,sBAAA,CAAAC,OAAA;AACA,IAAAG,KAAA,GAAAC,uBAAA,CAAAJ,OAAA;AACA,IAAAK,OAAA,GAAAN,sBAAA,CAAAC,OAAA;AACA,IAAAM,cAAA,GAAAP,sBAAA,CAAAC,OAAA;AAAmD,SAAAO,yBAAAC,WAAA,eAAAC,OAAA,kCAAAC,iBAAA,OAAAD,OAAA,QAAAE,gBAAA,OAAAF,OAAA,YAAAF,wBAAA,YAAAA,yBAAAC,WAAA,WAAAA,WAAA,GAAAG,gBAAA,GAAAD,iBAAA,KAAAF,WAAA;AAAA,SAAAJ,wBAAAQ,GAAA,EAAAJ,WAAA,SAAAA,WAAA,IAAAI,GAAA,IAAAA,GAAA,CAAAC,UAAA,WAAAD,GAAA,QAAAA,GAAA,aAAAE,QAAA,CAAAF,GAAA,yBAAAA,GAAA,uCAAAA,GAAA,UAA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JA,IAAI,CAAEI,KAAK,GAAE;IACnD,IAAAC,iBAAe,EAACL,IAAI,aAAJA,IAAI,uBAAJA,IAAI,CAAEI,KAAK,CAAC;EAC9B;EAEA,IAAI,EAACJ,IAAI,aAAJA,IAAI,eAAJA,IAAI,CAAEM,IAAI,GAAE,IAAAC,gBAAc,EAACR,oBAAoB,CAAC;EAErD,IAAI,EAACC,IAAI,aAAJA,IAAI,eAAJA,IAAI,CAAEQ,MAAM,GAAE,IAAAC,kBAAgB,GAAE;EAErC,IAAIC,OAAO,CAACC,GAAG,CAACC,QAAQ,KAAK,YAAY,EAAE,IAAAC,yBAAoB,GAAE;AACnE"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","names":["_i18next","_interopRequireDefault","require","getter","key","i18n","t","concat","replaceNullValuesWithGetter","inputObject","parentKey","arguments","length","undefined","result","_i","_Object$entries","Object","entries","_Object$entries$_i","_slicedToArray2","value","transKey","defineProperty","get","_typeof2","exports"],"sources":["../../../../src/initializers/utils/utils.js"],"sourcesContent":["import i18n from \"i18next\";\n\nconst getter = key => () => i18n.t(`taxonomyDefaultLabels.${key}`);\n\nexport const replaceNullValuesWithGetter = (inputObject, parentKey = \"\") => {\n const result = {};\n\n for (const [key, value] of Object.entries(inputObject)) {\n const transKey = parentKey ? `${parentKey}.${key}` : key;\n\n if (value === null) {\n Object.defineProperty(result, key, {\n get: getter(transKey),\n });\n } else if (typeof value === \"object\") {\n result[key] = replaceNullValuesWithGetter(value, transKey);\n } else {\n result[key] = value;\n }\n }\n\n return result;\n};\n"],"mappings":";;;;;;;;;AAAA,IAAAA,QAAA,GAAAC,sBAAA,CAAAC,OAAA;AAEA,IAAMC,MAAM,GAAG,SAATA,MAAMA,CAAGC,GAAG;EAAA,OAAI;IAAA,OAAMC,mBAAI,CAACC,CAAC,0BAAAC,MAAA,CAA0BH,GAAG,EAAG;EAAA;AAAA;AAE3D,IAAMI,2BAA2B,GAAG,SAA9BA,2BAA2BA,CAAIC,WAAW,EAAqB;EAAA,IAAnBC,SAAS,GAAAC,SAAA,CAAAC,MAAA,QAAAD,SAAA,QAAAE,SAAA,GAAAF,SAAA,MAAG,EAAE;EACrE,IAAMG,MAAM,GAAG,CAAC,CAAC;EAEjB,SAAAC,EAAA,MAAAC,eAAA,GAA2BC,MAAM,CAACC,OAAO,CAACT,WAAW,CAAC,EAAAM,EAAA,GAAAC,eAAA,CAAAJ,MAAA,EAAAG,EAAA,IAAE;IAAnD,IAAAI,kBAAA,OAAAC,eAAA,aAAAJ,eAAA,CAAAD,EAAA;MAAOX,GAAG,GAAAe,kBAAA;MAAEE,KAAK,GAAAF,kBAAA;IACpB,IAAMG,QAAQ,GAAGZ,SAAS,MAAAH,MAAA,CAAMG,SAAS,OAAAH,MAAA,CAAIH,GAAG,IAAKA,GAAG;IAExD,IAAIiB,KAAK,KAAK,IAAI,EAAE;MAClBJ,MAAM,CAACM,cAAc,CAACT,MAAM,EAAEV,GAAG,EAAE;QACjCoB,GAAG,EAAErB,MAAM,CAACmB,QAAQ;MACtB,CAAC,CAAC;IACJ,CAAC,MAAM,IAAI,IAAAG,QAAA,aAAOJ,KAAK,MAAK,QAAQ,EAAE;MACpCP,MAAM,CAACV,GAAG,CAAC,GAAGI,2BAA2B,CAACa,KAAK,EAAEC,QAAQ,CAAC;IAC5D,CAAC,MAAM;MACLR,MAAM,CAACV,GAAG,CAAC,GAAGiB,KAAK;IACrB;EACF;EAEA,OAAOP,MAAM;AACf,CAAC;AAACY,OAAA,CAAAlB,2BAAA,GAAAA,2BAAA"}
|
|
@@ -7,7 +7,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
7
7
|
exports["default"] = void 0;
|
|
8
8
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
9
9
|
var _neetoCist = require("@bigbinary/neeto-cist");
|
|
10
|
-
var
|
|
10
|
+
var _usePersistedQuery = _interopRequireDefault(require("../usePersistedQuery"));
|
|
11
11
|
var _neeto_apps = _interopRequireDefault(require("./apis/neeto_apps"));
|
|
12
12
|
var _constants = require("../constants");
|
|
13
13
|
var _query = require("../constants/query");
|
|
@@ -16,8 +16,8 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
|
|
|
16
16
|
var useFetchNeetoApps = function useFetchNeetoApps(options) {
|
|
17
17
|
var _globalProps$user;
|
|
18
18
|
var scopedQueryKey = "".concat(_query.QUERY_KEYS.NEETO_APPS_LIST, "-").concat((_globalProps$user = globalProps.user) === null || _globalProps$user === void 0 ? void 0 : _globalProps$user.id);
|
|
19
|
-
var neetoApps =
|
|
20
|
-
return (0,
|
|
19
|
+
var neetoApps = _usePersistedQuery["default"].getCache(scopedQueryKey);
|
|
20
|
+
return (0, _usePersistedQuery["default"])(scopedQueryKey, _neeto_apps["default"].fetch, _objectSpread({
|
|
21
21
|
staleTime: _constants.NEETO_APPS_LIST_STALE_TIME,
|
|
22
22
|
enabled: (0, _neetoCist.isNotPresent)(neetoApps === null || neetoApps === void 0 ? void 0 : neetoApps.data)
|
|
23
23
|
}, options));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useFetchNeetoApps.js","names":["_neetoCist","require","
|
|
1
|
+
{"version":3,"file":"useFetchNeetoApps.js","names":["_neetoCist","require","_usePersistedQuery","_interopRequireDefault","_neeto_apps","_constants","_query","ownKeys","object","enumerableOnly","keys","Object","getOwnPropertySymbols","symbols","filter","sym","getOwnPropertyDescriptor","enumerable","push","apply","_objectSpread","target","i","arguments","length","source","forEach","key","_defineProperty2","getOwnPropertyDescriptors","defineProperties","defineProperty","useFetchNeetoApps","options","_globalProps$user","scopedQueryKey","concat","QUERY_KEYS","NEETO_APPS_LIST","globalProps","user","id","neetoApps","usePersistedQuery","getCache","neetoAppsApi","fetch","staleTime","NEETO_APPS_LIST_STALE_TIME","enabled","isNotPresent","data","_default","exports"],"sources":["../../../../src/react-utils/useFetchNeetoApps/useFetchNeetoApps.js"],"sourcesContent":["import { isNotPresent } from \"neetocist\";\nimport usePersistedQuery from \"react-utils/usePersistedQuery\";\n\nimport neetoAppsApi from \"./apis/neeto_apps\";\n\nimport { NEETO_APPS_LIST_STALE_TIME } from \"../constants\";\nimport { QUERY_KEYS } from \"../constants/query\";\n\nconst useFetchNeetoApps = options => {\n const scopedQueryKey = `${QUERY_KEYS.NEETO_APPS_LIST}-${globalProps.user?.id}`;\n\n const neetoApps = usePersistedQuery.getCache(scopedQueryKey);\n\n return usePersistedQuery(scopedQueryKey, neetoAppsApi.fetch, {\n staleTime: NEETO_APPS_LIST_STALE_TIME,\n enabled: isNotPresent(neetoApps?.data),\n ...options,\n });\n};\n\nexport default useFetchNeetoApps;\n"],"mappings":";;;;;;;;AAAA,IAAAA,UAAA,GAAAC,OAAA;AACA,IAAAC,kBAAA,GAAAC,sBAAA,CAAAF,OAAA;AAEA,IAAAG,WAAA,GAAAD,sBAAA,CAAAF,OAAA;AAEA,IAAAI,UAAA,GAAAJ,OAAA;AACA,IAAAK,MAAA,GAAAL,OAAA;AAAgD,SAAAM,QAAAC,MAAA,EAAAC,cAAA,QAAAC,IAAA,GAAAC,MAAA,CAAAD,IAAA,CAAAF,MAAA,OAAAG,MAAA,CAAAC,qBAAA,QAAAC,OAAA,GAAAF,MAAA,CAAAC,qBAAA,CAAAJ,MAAA,GAAAC,cAAA,KAAAI,OAAA,GAAAA,OAAA,CAAAC,MAAA,WAAAC,GAAA,WAAAJ,MAAA,CAAAK,wBAAA,CAAAR,MAAA,EAAAO,GAAA,EAAAE,UAAA,OAAAP,IAAA,CAAAQ,IAAA,CAAAC,KAAA,CAAAT,IAAA,EAAAG,OAAA,YAAAH,IAAA;AAAA,SAAAU,cAAAC,MAAA,aAAAC,CAAA,MAAAA,CAAA,GAAAC,SAAA,CAAAC,MAAA,EAAAF,CAAA,UAAAG,MAAA,WAAAF,SAAA,CAAAD,CAAA,IAAAC,SAAA,CAAAD,CAAA,QAAAA,CAAA,OAAAf,OAAA,CAAAI,MAAA,CAAAc,MAAA,OAAAC,OAAA,WAAAC,GAAA,QAAAC,gBAAA,aAAAP,MAAA,EAAAM,GAAA,EAAAF,MAAA,CAAAE,GAAA,SAAAhB,MAAA,CAAAkB,yBAAA,GAAAlB,MAAA,CAAAmB,gBAAA,CAAAT,MAAA,EAAAV,MAAA,CAAAkB,yBAAA,CAAAJ,MAAA,KAAAlB,OAAA,CAAAI,MAAA,CAAAc,MAAA,GAAAC,OAAA,WAAAC,GAAA,IAAAhB,MAAA,CAAAoB,cAAA,CAAAV,MAAA,EAAAM,GAAA,EAAAhB,MAAA,CAAAK,wBAAA,CAAAS,MAAA,EAAAE,GAAA,iBAAAN,MAAA;AAEhD,IAAMW,iBAAiB,GAAG,SAApBA,iBAAiBA,CAAGC,OAAO,EAAI;EAAA,IAAAC,iBAAA;EACnC,IAAMC,cAAc,MAAAC,MAAA,CAAMC,iBAAU,CAACC,eAAe,OAAAF,MAAA,EAAAF,iBAAA,GAAIK,WAAW,CAACC,IAAI,cAAAN,iBAAA,uBAAhBA,iBAAA,CAAkBO,EAAE,CAAE;EAE9E,IAAMC,SAAS,GAAGC,6BAAiB,CAACC,QAAQ,CAACT,cAAc,CAAC;EAE5D,OAAO,IAAAQ,6BAAiB,EAACR,cAAc,EAAEU,sBAAY,CAACC,KAAK,EAAA1B,aAAA;IACzD2B,SAAS,EAAEC,qCAA0B;IACrCC,OAAO,EAAE,IAAAC,uBAAY,EAACR,SAAS,aAATA,SAAS,uBAATA,SAAS,CAAES,IAAI;EAAC,GACnClB,OAAO,EACV;AACJ,CAAC;AAAC,IAAAmB,QAAA,GAEapB,iBAAiB;AAAAqB,OAAA,cAAAD,QAAA"}
|
|
@@ -3,10 +3,10 @@ import _typeof from "@babel/runtime/helpers/typeof";
|
|
|
3
3
|
import axios from "axios";
|
|
4
4
|
import i18next from "i18next";
|
|
5
5
|
import { keysToCamelCase, matches, serializeKeysToSnakeCase } from "@bigbinary/neeto-cist";
|
|
6
|
-
import { useErrorDisplayStore } from "@bigbinary/neeto-commons-frontend/react-utils";
|
|
7
|
-
import { resetAuthTokens } from "@bigbinary/neeto-commons-frontend/utils";
|
|
8
6
|
import { Toastr } from "@bigbinary/neetoui";
|
|
9
7
|
import { evolve, omit } from "ramda";
|
|
8
|
+
import { useErrorDisplayStore } from "../../react-utils/useDisplayErrorPage";
|
|
9
|
+
import { resetAuthTokens } from "../../utils/axios";
|
|
10
10
|
import setParamsSerializer from "./paramsSerializer";
|
|
11
11
|
import { HEADERS_KEYS } from "../constants";
|
|
12
12
|
var shouldNot = function shouldNot(skip) {
|
|
@@ -95,6 +95,8 @@ var handleUnauthorizedErrorResponse = function handleUnauthorizedErrorResponse(e
|
|
|
95
95
|
if (redirectOnError) {
|
|
96
96
|
setTimeout(function () {
|
|
97
97
|
var redirectTo = window.location.pathname === "/login" ? "/login" : "/login?redirect_uri=".concat(encodeURIComponent(window.location.href));
|
|
98
|
+
|
|
99
|
+
// eslint-disable-next-line xss/no-location-href-assign
|
|
98
100
|
window.location.href = redirectTo;
|
|
99
101
|
}, 300);
|
|
100
102
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["axios","i18next","keysToCamelCase","matches","serializeKeysToSnakeCase","useErrorDisplayStore","resetAuthTokens","Toastr","evolve","omit","setParamsSerializer","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","showErrorToastr","_error$config3","_error$response3","_ref3","_ref3$showToastr","message","t","includes","isCancel","getUrlPathName","url","URL","_unused","handle404ErrorResponse","_error$config4","_error$response4","_ref4","_ref4$show404ErrorPag","show404ErrorPage","_ref4$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/axios/index.js"],"sourcesContent":["import axios from \"axios\";\nimport i18next from \"i18next\";\nimport { keysToCamelCase, matches, serializeKeysToSnakeCase } from \"neetocist\";\nimport { useErrorDisplayStore } from \"neetocommons/react-utils\";\nimport { resetAuthTokens } from \"neetocommons/utils\";\nimport { Toastr } from \"neetoui\";\nimport { evolve, omit } from \"ramda\";\n\nimport setParamsSerializer from \"./paramsSerializer\";\n\nimport { 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 window.location.href = redirectTo;\n }, 300);\n }\n\n return error;\n};\n\nconst showErrorToastr = error => {\n const { showToastr = true } = error.config ?? {};\n if (!showToastr) return error;\n\n if (error.message === \"Network Error\") {\n // @ts-ignore\n Toastr.error(i18next.t(\"neetoCommons.toastr.error.networkError\"));\n } else if (\n ![403, 404].includes(error.response?.status) &&\n !axios.isCancel(error)\n ) {\n // we already display a page in case of 403 & 404 and we don't want to show a toastr for cancelled requests.\n 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;AAC3D,SAASC,oBAAoB;AAC7B,SAASC,eAAe;AACxB,SAASC,MAAM;AACf,SAASC,MAAM,EAAEC,IAAI,QAAQ,OAAO;AAEpC,OAAOC,mBAAmB;AAE1B,SAASC,YAAY;AAErB,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;EACArB,KAAK,CAACsB,QAAQ,CAACC,OAAO,IAAAF,qBAAA,OAAAG,eAAA,CAAAH,qBAAA,EACnBV,YAAY,CAACc,MAAM,EAAG,kBAAkB,GAAAD,eAAA,CAAAH,qBAAA,EACxCV,YAAY,CAACe,WAAW,EAAG,kBAAkB,GAAAF,eAAA,CAAAH,qBAAA,EAC7CV,YAAY,CAACgB,UAAU,GAAAP,qBAAA,GAAGQ,QAAQ,CAChCC,aAAa,CA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AC;AAC3E"}
|
|
1
|
+
{"version":3,"file":"index.js","names":["axios","i18next","keysToCamelCase","matches","serializeKeysToSnakeCase","Toastr","evolve","omit","useErrorDisplayStore","resetAuthTokens","setParamsSerializer","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","showErrorToastr","_error$config3","_error$response3","_ref3","_ref3$showToastr","message","t","includes","isCancel","getUrlPathName","url","URL","_unused","handle404ErrorResponse","_error$config4","_error$response4","_ref4","_ref4$show404ErrorPag","show404ErrorPage","_ref4$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/axios/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 { 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 showErrorToastr = error => {\n const { showToastr = true } = error.config ?? {};\n if (!showToastr) return error;\n\n if (error.message === \"Network Error\") {\n // @ts-ignore\n Toastr.error(i18next.t(\"neetoCommons.toastr.error.networkError\"));\n } else if (\n ![403, 404].includes(error.response?.status) &&\n !axios.isCancel(error)\n ) {\n // we already display a page in case of 403 & 404 and we don't want to show a toastr for cancelled requests.\n 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;AAC3D,SAASC,MAAM;AACf,SAASC,MAAM,EAAEC,IAAI,QAAQ,OAAO;AACpC,SAASC,oBAAoB;AAC7B,SAASC,eAAe;AAExB,OAAOC,mBAAmB;AAE1B,SAASC,YAAY;AAErB,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;EAA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,CAAC,EAAEwG,uBAAuB,CAAC3G,IAAI,aAAJA,IAAI,uBAAJA,IAAI,CAAEG,QAAQ,CAAC;AACxE,CAAC;AAED,eAAe,SAAS0G,eAAeA,CAAC7G,IAAI,EAAE;EAC5C,IAAI,EAACA,IAAI,aAAJA,IAAI,eAAJA,IAAI,CAAE8G,OAAO,GAAE3H,KAAK,CAACsB,QAAQ,CAACqG,OAAO,GAAG,GAAG;EAEhD,IAAI,EAAC9G,IAAI,aAAJA,IAAI,eAAJA,IAAI,CAAE+G,WAAW,GAAEzG,cAAc,EAAE;EAExC,IAAI,EAACN,IAAI,aAAJA,IAAI,eAAJA,IAAI,CAAEgH,gBAAgB,GAAEnH,mBAAmB,EAAE;EAElD,IAAIE,SAAS,CAACC,IAAI,aAAJA,IAAI,uBAAJA,IAAI,CAAE6C,YAAY,CAAC,EAAE+D,kBAAkB,CAAC5G,IAAI,aAAJA,IAAI,uBAAJA,IAAI,CAAE6C,YAAY,CAAC;AAC3E"}
|
package/initializers/i18n.js
CHANGED
|
@@ -3,9 +3,9 @@ import LanguageDetector from "i18next-browser-languagedetector";
|
|
|
3
3
|
import { mergeDeepLeft } from "ramda";
|
|
4
4
|
import { initReactI18next } from "react-i18next";
|
|
5
5
|
import { LIST_FORMATS } from "./constants";
|
|
6
|
-
import { replaceNullValuesWithGetter } from "./utils";
|
|
7
6
|
import { listFormatter, lowerCaseDynamicTextFormatter } from "./utils/customFormatters";
|
|
8
7
|
import { sentenceCaseProcessor } from "./utils/customPostProcessors";
|
|
8
|
+
import { replaceNullValuesWithGetter } from "./utils/utils";
|
|
9
9
|
import commonsEn from "../translations/en.json";
|
|
10
10
|
|
|
11
11
|
// eslint-disable-next-line import/no-mutable-exports
|
package/initializers/i18n.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"i18n.js","names":["i18n","LanguageDetector","mergeDeepLeft","initReactI18next","LIST_FORMATS","
|
|
1
|
+
{"version":3,"file":"i18n.js","names":["i18n","LanguageDetector","mergeDeepLeft","initReactI18next","LIST_FORMATS","listFormatter","lowerCaseDynamicTextFormatter","sentenceCaseProcessor","replaceNullValuesWithGetter","commonsEn","taxonomies","initializeI18n","hostTranslations","_window$globalProps","packageTranslations","preval","require","commonsTranslations","en","translation","resources","reduce","defaultTaxonomyKeys","Object","keys","taxonomyDefaultLabels","defaultTaxonomies","fromEntries","map","key","singular","plural","hostTaxonomies","window","globalProps","use","init","fallbackLng","interpolation","defaultVariables","escapeValue","skipOnVariables","alwaysFormat","format","value","lng","options","newValue","includes","postProcess","name","detection","order","caches","lookupQuerystring","lookupCookie"],"sources":["../../src/initializers/i18n.js"],"sourcesContent":["import i18n from \"i18next\";\nimport LanguageDetector from \"i18next-browser-languagedetector\";\nimport { mergeDeepLeft } from \"ramda\";\nimport { initReactI18next } from \"react-i18next\";\n\nimport { LIST_FORMATS } from \"./constants\";\nimport {\n listFormatter,\n lowerCaseDynamicTextFormatter,\n} from \"./utils/customFormatters\";\nimport { sentenceCaseProcessor } from \"./utils/customPostProcessors\";\nimport { replaceNullValuesWithGetter } from \"./utils/utils\";\n\nimport commonsEn from \"../translations/en.json\";\n\n// eslint-disable-next-line import/no-mutable-exports\nlet taxonomies = {};\n\nconst initializeI18n = hostTranslations => {\n // eslint-disable-next-line no-undef\n const packageTranslations = preval.require(\n \"../configs/scripts/getPkgTranslations.js\"\n );\n\n const commonsTranslations = { en: { translation: commonsEn } };\n\n const resources = [\n hostTranslations,\n commonsTranslations,\n packageTranslations,\n ].reduce(mergeDeepLeft);\n\n const defaultTaxonomyKeys = Object.keys(\n resources.en.translation.taxonomyDefaultLabels || {}\n );\n\n const defaultTaxonomies = Object.fromEntries(\n defaultTaxonomyKeys.map(key => [key, { singular: null, plural: null }])\n );\n\n const hostTaxonomies = window.globalProps?.taxonomies || {};\n\n taxonomies = replaceNullValuesWithGetter(\n mergeDeepLeft(hostTaxonomies, defaultTaxonomies)\n );\n\n i18n\n .use(LanguageDetector)\n .use(initReactI18next)\n .use(sentenceCaseProcessor)\n .init({\n resources,\n fallbackLng: \"en\",\n interpolation: {\n defaultVariables: { taxonomies },\n escapeValue: false,\n skipOnVariables: false,\n alwaysFormat: true,\n format: (value, format, lng, options) => {\n let newValue = value;\n\n if (LIST_FORMATS.includes(format)) {\n newValue = listFormatter({ value: newValue, format, lng, options });\n\n return newValue;\n }\n\n return lowerCaseDynamicTextFormatter(newValue, format);\n },\n },\n postProcess: [sentenceCaseProcessor.name],\n detection: {\n order: [\"querystring\", \"cookie\", \"navigator\", \"path\"],\n caches: [\"cookie\"],\n lookupQuerystring: \"lang\",\n lookupCookie: \"lang\",\n },\n });\n};\n\nexport { taxonomies };\n\nexport default initializeI18n;\n"],"mappings":"AAAA,OAAOA,IAAI,MAAM,SAAS;AAC1B,OAAOC,gBAAgB,MAAM,kCAAkC;AAC/D,SAASC,aAAa,QAAQ,OAAO;AACrC,SAASC,gBAAgB,QAAQ,eAAe;AAEhD,SAASC,YAAY;AACrB,SACEC,aAAa,EACbC,6BAA6B;AAE/B,SAASC,qBAAqB;AAC9B,SAASC,2BAA2B;AAEpC,OAAOC,SAAS;;AAEhB;AACA,IAAIC,UAAU,GAAG,CAAC,CAAC;AAEnB,IAAMC,cAAc,GAAG,SAAjBA,cAAcA,CAAGC,gBAAgB,EAAI;EAAA,IAAAC,mBAAA;EACzC;EACA,IAAMC,mBAAmB,GAAGC,MAAM,CAACC,OAAO,CACxC,0CAA0C,CAC3C;EAED,IAAMC,mBAAmB,GAAG;IAAEC,EAAE,EAAE;MAAEC,WAAW,EAAEV;IAAU;EAAE,CAAC;EAE9D,IAAMW,SAAS,GAAG,CAChBR,gBAAgB,EAChBK,mBAAmB,EACnBH,mBAAmB,CACpB,CAACO,MAAM,CAACnB,aAAa,CAAC;EAEvB,IAAMoB,mBAAmB,GAAGC,MAAM,CAACC,IAAI,CACrCJ,SAAS,CAACF,EAAE,CAACC,WAAW,CAACM,qBAAqB,IAAI,CAAC,CAAC,CACrD;EAED,IAAMC,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,IAAI,CAAC;IACzCC,SAAS,EAAE;MACTC,KAAK,EAAE,CAAC,aAAa,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,CAAC;MACrDC,MAAM,EAAE,CAAC,QAAQ,CAAC;MAClBC,iBAAiB,EAAE,MAAM;MACzBC,YAAY,EAAE;IAChB;EACF,CAAC,CAAC;AACN,CAAC;AAED,SAAS7C,UAAU;AAEnB,eAAeC,cAAc"}
|
package/initializers/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import _typeof from "@babel/runtime/helpers/typeof";
|
|
2
2
|
// TODO: kept for backward compatibility.
|
|
3
|
-
import
|
|
3
|
+
import useDisplayErrorPage from "../react-utils/useDisplayErrorPage";
|
|
4
4
|
import initializeAxios from "./axios";
|
|
5
5
|
import initializeGlobalProps from "./globalProps";
|
|
6
6
|
import initializeI18n, { taxonomies } from "./i18n";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["useDisplayErrorPage","initializeAxios","initializeGlobalProps","initializeI18n","taxonomies","initializeLogger","disableReactDevTools","globalProps","initializeApplication","_ref","translationResources","skip","window","_typeof","axios","i18n","logger","process","env","NODE_ENV"],"sources":["../../src/initializers/index.js"],"sourcesContent":["// TODO: kept for backward compatibility.\nimport
|
|
1
|
+
{"version":3,"file":"index.js","names":["useDisplayErrorPage","initializeAxios","initializeGlobalProps","initializeI18n","taxonomies","initializeLogger","disableReactDevTools","globalProps","initializeApplication","_ref","translationResources","skip","window","_typeof","axios","i18n","logger","process","env","NODE_ENV"],"sources":["../../src/initializers/index.js"],"sourcesContent":["// TODO: kept for backward compatibility.\nimport useDisplayErrorPage from \"react-utils/useDisplayErrorPage\";\n\nimport initializeAxios from \"./axios\";\nimport initializeGlobalProps from \"./globalProps\";\nimport initializeI18n, { taxonomies } from \"./i18n\";\nimport initializeLogger from \"./logger\";\nimport disableReactDevTools from \"./reactDevTools\";\n\n// eslint-disable-next-line import/no-mutable-exports\nlet globalProps = {};\n\nexport { globalProps, useDisplayErrorPage, taxonomies };\n\nexport default function initializeApplication({ translationResources, skip }) {\n if (!skip?.globalProps) {\n initializeGlobalProps();\n // eslint-disable-next-line @bigbinary/neeto/no-globalProps-reassignment\n globalProps = window.globalProps;\n }\n\n if (typeof skip?.axios === \"object\" || !skip?.axios) {\n initializeAxios(skip?.axios);\n }\n\n if (!skip?.i18n) initializeI18n(translationResources);\n\n if (!skip?.logger) initializeLogger();\n\n if (process.env.NODE_ENV === \"production\") disableReactDevTools();\n}\n"],"mappings":";AAAA;AACA,OAAOA,mBAAmB;AAE1B,OAAOC,eAAe;AACtB,OAAOC,qBAAqB;AAC5B,OAAOC,cAAc,IAAIC,UAAU;AACnC,OAAOC,gBAAgB;AACvB,OAAOC,oBAAoB;;AAE3B;AACA,IAAIC,WAAW,GAAG,CAAC,CAAC;AAEpB,SAASA,WAAW,EAAEP,mBAAmB,EAAEI,UAAU;AAErD,eAAe,SAASI,qBAAqBA,CAAAC,IAAA,EAAiC;EAAA,IAA9BC,oBAAoB,GAAAD,IAAA,CAApBC,oBAAoB;IAAEC,IAAI,GAAAF,IAAA,CAAJE,IAAI;EACxE,IAAI,EAACA,IAAI,aAAJA,IAAI,eAAJA,IAAI,CAAEJ,WAAW,GAAE;IACtBL,qBAAqB,EAAE;IACvB;IACAK,WAAW,GAAGK,MAAM,CAACL,WAAW;EAClC;EAEA,IAAIM,OAAA,CAAOF,IAAI,aAAJA,IAAI,uBAAJA,IAAI,CAAEG,KAAK,MAAK,QAAQ,IAAI,EAACH,IAAI,aAAJA,IAAI,eAAJA,IAAI,CAAEG,KAAK,GAAE;IACnDb,eAAe,CAACU,IAAI,aAAJA,IAAI,uBAAJA,IAAI,CAAEG,KAAK,CAAC;EAC9B;EAEA,IAAI,EAACH,IAAI,aAAJA,IAAI,eAAJA,IAAI,CAAEI,IAAI,GAAEZ,cAAc,CAACO,oBAAoB,CAAC;EAErD,IAAI,EAACC,IAAI,aAAJA,IAAI,eAAJA,IAAI,CAAEK,MAAM,GAAEX,gBAAgB,EAAE;EAErC,IAAIY,OAAO,CAACC,GAAG,CAACC,QAAQ,KAAK,YAAY,EAAEb,oBAAoB,EAAE;AACnE"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","names":["i18n","getter","key","t","concat","replaceNullValuesWithGetter","inputObject","parentKey","arguments","length","undefined","result","_i","_Object$entries","Object","entries","_Object$entries$_i","_slicedToArray","value","transKey","defineProperty","get","_typeof"],"sources":["../../../src/initializers/utils/utils.js"],"sourcesContent":["import i18n from \"i18next\";\n\nconst getter = key => () => i18n.t(`taxonomyDefaultLabels.${key}`);\n\nexport const replaceNullValuesWithGetter = (inputObject, parentKey = \"\") => {\n const result = {};\n\n for (const [key, value] of Object.entries(inputObject)) {\n const transKey = parentKey ? `${parentKey}.${key}` : key;\n\n if (value === null) {\n Object.defineProperty(result, key, {\n get: getter(transKey),\n });\n } else if (typeof value === \"object\") {\n result[key] = replaceNullValuesWithGetter(value, transKey);\n } else {\n result[key] = value;\n }\n }\n\n return result;\n};\n"],"mappings":";;AAAA,OAAOA,IAAI,MAAM,SAAS;AAE1B,IAAMC,MAAM,GAAG,SAATA,MAAMA,CAAGC,GAAG;EAAA,OAAI;IAAA,OAAMF,IAAI,CAACG,CAAC,0BAAAC,MAAA,CAA0BF,GAAG,EAAG;EAAA;AAAA;AAElE,OAAO,IAAMG,2BAA2B,GAAG,SAA9BA,2BAA2BA,CAAIC,WAAW,EAAqB;EAAA,IAAnBC,SAAS,GAAAC,SAAA,CAAAC,MAAA,QAAAD,SAAA,QAAAE,SAAA,GAAAF,SAAA,MAAG,EAAE;EACrE,IAAMG,MAAM,GAAG,CAAC,CAAC;EAEjB,SAAAC,EAAA,MAAAC,eAAA,GAA2BC,MAAM,CAACC,OAAO,CAACT,WAAW,CAAC,EAAAM,EAAA,GAAAC,eAAA,CAAAJ,MAAA,EAAAG,EAAA,IAAE;IAAnD,IAAAI,kBAAA,GAAAC,cAAA,CAAAJ,eAAA,CAAAD,EAAA;MAAOV,GAAG,GAAAc,kBAAA;MAAEE,KAAK,GAAAF,kBAAA;IACpB,IAAMG,QAAQ,GAAGZ,SAAS,MAAAH,MAAA,CAAMG,SAAS,OAAAH,MAAA,CAAIF,GAAG,IAAKA,GAAG;IAExD,IAAIgB,KAAK,KAAK,IAAI,EAAE;MAClBJ,MAAM,CAACM,cAAc,CAACT,MAAM,EAAET,GAAG,EAAE;QACjCmB,GAAG,EAAEpB,MAAM,CAACkB,QAAQ;MACtB,CAAC,CAAC;IACJ,CAAC,MAAM,IAAIG,OAAA,CAAOJ,KAAK,MAAK,QAAQ,EAAE;MACpCP,MAAM,CAACT,GAAG,CAAC,GAAGG,2BAA2B,CAACa,KAAK,EAAEC,QAAQ,CAAC;IAC5D,CAAC,MAAM;MACLR,MAAM,CAACT,GAAG,CAAC,GAAGgB,KAAK;IACrB;EACF;EAEA,OAAOP,MAAM;AACf,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bigbinary/neeto-commons-frontend",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.13",
|
|
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>",
|
|
@@ -2,7 +2,7 @@ import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
|
2
2
|
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
3
3
|
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
4
4
|
import { isNotPresent } from "@bigbinary/neeto-cist";
|
|
5
|
-
import
|
|
5
|
+
import usePersistedQuery from "../usePersistedQuery";
|
|
6
6
|
import neetoAppsApi from "./apis/neeto_apps";
|
|
7
7
|
import { NEETO_APPS_LIST_STALE_TIME } from "../constants";
|
|
8
8
|
import { QUERY_KEYS } from "../constants/query";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useFetchNeetoApps.js","names":["isNotPresent","usePersistedQuery","neetoAppsApi","NEETO_APPS_LIST_STALE_TIME","QUERY_KEYS","useFetchNeetoApps","options","_globalProps$user","scopedQueryKey","concat","NEETO_APPS_LIST","globalProps","user","id","neetoApps","getCache","fetch","_objectSpread","staleTime","enabled","data"],"sources":["../../../src/react-utils/useFetchNeetoApps/useFetchNeetoApps.js"],"sourcesContent":["import { isNotPresent } from \"neetocist\";\nimport
|
|
1
|
+
{"version":3,"file":"useFetchNeetoApps.js","names":["isNotPresent","usePersistedQuery","neetoAppsApi","NEETO_APPS_LIST_STALE_TIME","QUERY_KEYS","useFetchNeetoApps","options","_globalProps$user","scopedQueryKey","concat","NEETO_APPS_LIST","globalProps","user","id","neetoApps","getCache","fetch","_objectSpread","staleTime","enabled","data"],"sources":["../../../src/react-utils/useFetchNeetoApps/useFetchNeetoApps.js"],"sourcesContent":["import { isNotPresent } from \"neetocist\";\nimport usePersistedQuery from \"react-utils/usePersistedQuery\";\n\nimport neetoAppsApi from \"./apis/neeto_apps\";\n\nimport { NEETO_APPS_LIST_STALE_TIME } from \"../constants\";\nimport { QUERY_KEYS } from \"../constants/query\";\n\nconst useFetchNeetoApps = options => {\n const scopedQueryKey = `${QUERY_KEYS.NEETO_APPS_LIST}-${globalProps.user?.id}`;\n\n const neetoApps = usePersistedQuery.getCache(scopedQueryKey);\n\n return usePersistedQuery(scopedQueryKey, neetoAppsApi.fetch, {\n staleTime: NEETO_APPS_LIST_STALE_TIME,\n enabled: isNotPresent(neetoApps?.data),\n ...options,\n });\n};\n\nexport default useFetchNeetoApps;\n"],"mappings":";;;AAAA,SAASA,YAAY;AACrB,OAAOC,iBAAiB;AAExB,OAAOC,YAAY;AAEnB,SAASC,0BAA0B;AACnC,SAASC,UAAU;AAEnB,IAAMC,iBAAiB,GAAG,SAApBA,iBAAiBA,CAAGC,OAAO,EAAI;EAAA,IAAAC,iBAAA;EACnC,IAAMC,cAAc,MAAAC,MAAA,CAAML,UAAU,CAACM,eAAe,OAAAD,MAAA,EAAAF,iBAAA,GAAII,WAAW,CAACC,IAAI,cAAAL,iBAAA,uBAAhBA,iBAAA,CAAkBM,EAAE,CAAE;EAE9E,IAAMC,SAAS,GAAGb,iBAAiB,CAACc,QAAQ,CAACP,cAAc,CAAC;EAE5D,OAAOP,iBAAiB,CAACO,cAAc,EAAEN,YAAY,CAACc,KAAK,EAAAC,aAAA;IACzDC,SAAS,EAAEf,0BAA0B;IACrCgB,OAAO,EAAEnB,YAAY,CAACc,SAAS,aAATA,SAAS,uBAATA,SAAS,CAAEM,IAAI;EAAC,GACnCd,OAAO,EACV;AACJ,CAAC;AAED,eAAeD,iBAAiB"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","names":["_i18next","_interopRequireDefault","require","getter","key","i18n","t","concat","replaceNullValuesWithGetter","inputObject","parentKey","arguments","length","undefined","result","_i","_Object$entries","Object","entries","_Object$entries$_i","_slicedToArray2","value","transKey","defineProperty","get","_typeof2","exports"],"sources":["../../../src/initializers/utils.js"],"sourcesContent":["import i18n from \"i18next\";\n\nconst getter = key => () => i18n.t(`taxonomyDefaultLabels.${key}`);\n\nexport const replaceNullValuesWithGetter = (inputObject, parentKey = \"\") => {\n const result = {};\n\n for (const [key, value] of Object.entries(inputObject)) {\n const transKey = parentKey ? `${parentKey}.${key}` : key;\n\n if (value === null) {\n Object.defineProperty(result, key, {\n get: getter(transKey),\n });\n } else if (typeof value === \"object\") {\n result[key] = replaceNullValuesWithGetter(value, transKey);\n } else {\n result[key] = value;\n }\n }\n\n return result;\n};\n"],"mappings":";;;;;;;;;AAAA,IAAAA,QAAA,GAAAC,sBAAA,CAAAC,OAAA;AAEA,IAAMC,MAAM,GAAG,SAATA,MAAMA,CAAGC,GAAG;EAAA,OAAI;IAAA,OAAMC,mBAAI,CAACC,CAAC,0BAAAC,MAAA,CAA0BH,GAAG,EAAG;EAAA;AAAA;AAE3D,IAAMI,2BAA2B,GAAG,SAA9BA,2BAA2BA,CAAIC,WAAW,EAAqB;EAAA,IAAnBC,SAAS,GAAAC,SAAA,CAAAC,MAAA,QAAAD,SAAA,QAAAE,SAAA,GAAAF,SAAA,MAAG,EAAE;EACrE,IAAMG,MAAM,GAAG,CAAC,CAAC;EAEjB,SAAAC,EAAA,MAAAC,eAAA,GAA2BC,MAAM,CAACC,OAAO,CAACT,WAAW,CAAC,EAAAM,EAAA,GAAAC,eAAA,CAAAJ,MAAA,EAAAG,EAAA,IAAE;IAAnD,IAAAI,kBAAA,OAAAC,eAAA,aAAAJ,eAAA,CAAAD,EAAA;MAAOX,GAAG,GAAAe,kBAAA;MAAEE,KAAK,GAAAF,kBAAA;IACpB,IAAMG,QAAQ,GAAGZ,SAAS,MAAAH,MAAA,CAAMG,SAAS,OAAAH,MAAA,CAAIH,GAAG,IAAKA,GAAG;IAExD,IAAIiB,KAAK,KAAK,IAAI,EAAE;MAClBJ,MAAM,CAACM,cAAc,CAACT,MAAM,EAAEV,GAAG,EAAE;QACjCoB,GAAG,EAAErB,MAAM,CAACmB,QAAQ;MACtB,CAAC,CAAC;IACJ,CAAC,MAAM,IAAI,IAAAG,QAAA,aAAOJ,KAAK,MAAK,QAAQ,EAAE;MACpCP,MAAM,CAACV,GAAG,CAAC,GAAGI,2BAA2B,CAACa,KAAK,EAAEC,QAAQ,CAAC;IAC5D,CAAC,MAAM;MACLR,MAAM,CAACV,GAAG,CAAC,GAAGiB,KAAK;IACrB;EACF;EAEA,OAAOP,MAAM;AACf,CAAC;AAACY,OAAA,CAAAlB,2BAAA,GAAAA,2BAAA"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","names":["i18n","getter","key","t","concat","replaceNullValuesWithGetter","inputObject","parentKey","arguments","length","undefined","result","_i","_Object$entries","Object","entries","_Object$entries$_i","_slicedToArray","value","transKey","defineProperty","get","_typeof"],"sources":["../../src/initializers/utils.js"],"sourcesContent":["import i18n from \"i18next\";\n\nconst getter = key => () => i18n.t(`taxonomyDefaultLabels.${key}`);\n\nexport const replaceNullValuesWithGetter = (inputObject, parentKey = \"\") => {\n const result = {};\n\n for (const [key, value] of Object.entries(inputObject)) {\n const transKey = parentKey ? `${parentKey}.${key}` : key;\n\n if (value === null) {\n Object.defineProperty(result, key, {\n get: getter(transKey),\n });\n } else if (typeof value === \"object\") {\n result[key] = replaceNullValuesWithGetter(value, transKey);\n } else {\n result[key] = value;\n }\n }\n\n return result;\n};\n"],"mappings":";;AAAA,OAAOA,IAAI,MAAM,SAAS;AAE1B,IAAMC,MAAM,GAAG,SAATA,MAAMA,CAAGC,GAAG;EAAA,OAAI;IAAA,OAAMF,IAAI,CAACG,CAAC,0BAAAC,MAAA,CAA0BF,GAAG,EAAG;EAAA;AAAA;AAElE,OAAO,IAAMG,2BAA2B,GAAG,SAA9BA,2BAA2BA,CAAIC,WAAW,EAAqB;EAAA,IAAnBC,SAAS,GAAAC,SAAA,CAAAC,MAAA,QAAAD,SAAA,QAAAE,SAAA,GAAAF,SAAA,MAAG,EAAE;EACrE,IAAMG,MAAM,GAAG,CAAC,CAAC;EAEjB,SAAAC,EAAA,MAAAC,eAAA,GAA2BC,MAAM,CAACC,OAAO,CAACT,WAAW,CAAC,EAAAM,EAAA,GAAAC,eAAA,CAAAJ,MAAA,EAAAG,EAAA,IAAE;IAAnD,IAAAI,kBAAA,GAAAC,cAAA,CAAAJ,eAAA,CAAAD,EAAA;MAAOV,GAAG,GAAAc,kBAAA;MAAEE,KAAK,GAAAF,kBAAA;IACpB,IAAMG,QAAQ,GAAGZ,SAAS,MAAAH,MAAA,CAAMG,SAAS,OAAAH,MAAA,CAAIF,GAAG,IAAKA,GAAG;IAExD,IAAIgB,KAAK,KAAK,IAAI,EAAE;MAClBJ,MAAM,CAACM,cAAc,CAACT,MAAM,EAAET,GAAG,EAAE;QACjCmB,GAAG,EAAEpB,MAAM,CAACkB,QAAQ;MACtB,CAAC,CAAC;IACJ,CAAC,MAAM,IAAIG,OAAA,CAAOJ,KAAK,MAAK,QAAQ,EAAE;MACpCP,MAAM,CAACT,GAAG,CAAC,GAAGG,2BAA2B,CAACa,KAAK,EAAEC,QAAQ,CAAC;IAC5D,CAAC,MAAM;MACLR,MAAM,CAACT,GAAG,CAAC,GAAGgB,KAAK;IACrB;EACF;EAEA,OAAOP,MAAM;AACf,CAAC"}
|
|
File without changes
|
|
File without changes
|