@pagopa/selfcare-common-frontend 1.1.0 → 1.2.2

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.
Files changed (58) hide show
  1. package/CHANGELOG.md +9 -2
  2. package/README.md +85 -1
  3. package/build.info +2 -2
  4. package/components/EndingPage.js +1 -1
  5. package/components/EndingPage.js.map +1 -1
  6. package/components/ErrorBoundary/ErrorBoundary.js +6 -9
  7. package/components/ErrorBoundary/ErrorBoundary.js.map +1 -1
  8. package/components/FilterModal.d.ts +1 -1
  9. package/components/Footer/Footer.d.ts +2 -1
  10. package/components/Footer/Footer.js +9 -5
  11. package/components/Footer/Footer.js.map +1 -1
  12. package/components/SessionModal.js +1 -1
  13. package/components/SessionModal.js.map +1 -1
  14. package/components/TitleBox.d.ts +1 -2
  15. package/components/TitleBox.js.map +1 -1
  16. package/components/UnloadEventHandler.d.ts +8 -0
  17. package/components/UnloadEventHandler.js +33 -0
  18. package/components/UnloadEventHandler.js.map +1 -0
  19. package/components/UserNotifyHandle.d.ts +7 -0
  20. package/components/UserNotifyHandle.js +55 -0
  21. package/components/UserNotifyHandle.js.map +1 -0
  22. package/hooks/useErrorDispatcher.d.ts +1 -1
  23. package/hooks/useErrorDispatcher.js +1 -1
  24. package/hooks/useErrorDispatcher.js.map +1 -1
  25. package/hooks/useLoading.d.ts +1 -1
  26. package/hooks/useLoading.js +1 -1
  27. package/hooks/useLoading.js.map +1 -1
  28. package/hooks/useUnloadEventInterceptor.d.ts +17 -0
  29. package/hooks/useUnloadEventInterceptor.js +60 -0
  30. package/hooks/useUnloadEventInterceptor.js.map +1 -0
  31. package/hooks/useUserNotify.d.ts +3 -0
  32. package/hooks/useUserNotify.js +11 -0
  33. package/hooks/useUserNotify.js.map +1 -0
  34. package/index.d.ts +1 -0
  35. package/index.js +3 -1
  36. package/index.js.map +1 -1
  37. package/model/UserNotify.d.ts +23 -0
  38. package/model/UserNotify.js +3 -0
  39. package/model/UserNotify.js.map +1 -0
  40. package/package.json +14 -6
  41. package/redux/slices/appStateSlice.d.ts +45 -2
  42. package/redux/slices/appStateSlice.js +43 -0
  43. package/redux/slices/appStateSlice.js.map +1 -1
  44. package/redux/slices/userSlice.d.ts +3 -1
  45. package/redux/slices/userSlice.js.map +1 -1
  46. package/utils/api-utils.d.ts +16 -0
  47. package/utils/api-utils.js +63 -0
  48. package/utils/api-utils.js.map +1 -0
  49. package/utils/constants.d.ts +3 -0
  50. package/utils/constants.js +3 -0
  51. package/utils/constants.js.map +1 -1
  52. package/utils/fixSwagger20ArraySchemaDef.js +67 -0
  53. package/utils/routes-utils.d.ts +1 -0
  54. package/utils/routes-utils.js +1 -0
  55. package/utils/routes-utils.js.map +1 -1
  56. package/utils/storage-utils.d.ts +3 -0
  57. package/utils/storage-utils.js +3 -0
  58. package/utils/storage-utils.js.map +1 -1
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const react_redux_1 = require("react-redux");
4
+ const appStateSlice_1 = require("../redux/slices/appStateSlice");
5
+ /** @see {@link UserNotifyHandle} */
6
+ function default_1() {
7
+ const dispatch = (0, react_redux_1.useDispatch)();
8
+ return (notify) => dispatch(appStateSlice_1.appStateActions.addNotify(notify));
9
+ }
10
+ exports.default = default_1;
11
+ //# sourceMappingURL=useUserNotify.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useUserNotify.js","sourceRoot":"","sources":["../../src/lib/hooks/useUserNotify.ts"],"names":[],"mappings":";;AAAA,6CAA0C;AAE1C,iEAAgE;AAEhE,oCAAoC;AACpC;IACE,MAAM,QAAQ,GAAG,IAAA,yBAAW,GAAE,CAAC;IAC/B,OAAO,CAAC,MAAkB,EAAE,EAAE,CAAC,QAAQ,CAAC,+BAAe,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,CAAC;AAC7E,CAAC;AAHD,4BAGC"}
package/index.d.ts CHANGED
@@ -18,3 +18,4 @@ export { default as ErrorBoundary } from './components/ErrorBoundary/ErrorBounda
18
18
  export * from './components/ErrorBoundary/ErrorBoundary';
19
19
  export { default as LoadingOverlay } from './components/Loading/LoadingOverlay';
20
20
  export * from './components/Loading/LoadingOverlay';
21
+ export { default as EndingPage } from './components/EndingPage';
package/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.LoadingOverlay = exports.ErrorBoundary = exports.Toast = exports.TitleBox = exports.SessionModal = exports.FilterModal = exports.CustomPagination = exports.CustomAvatar = exports.Footer = exports.Header = void 0;
3
+ exports.EndingPage = exports.LoadingOverlay = exports.ErrorBoundary = exports.Toast = exports.TitleBox = exports.SessionModal = exports.FilterModal = exports.CustomPagination = exports.CustomAvatar = exports.Footer = exports.Header = void 0;
4
4
  const tslib_1 = require("tslib");
5
5
  var Header_1 = require("./components/Header/Header");
6
6
  Object.defineProperty(exports, "Header", { enumerable: true, get: function () { return (0, tslib_1.__importDefault)(Header_1).default; } });
@@ -32,4 +32,6 @@ Object.defineProperty(exports, "ErrorBoundary", { enumerable: true, get: functio
32
32
  var LoadingOverlay_1 = require("./components/Loading/LoadingOverlay");
33
33
  Object.defineProperty(exports, "LoadingOverlay", { enumerable: true, get: function () { return (0, tslib_1.__importDefault)(LoadingOverlay_1).default; } });
34
34
  (0, tslib_1.__exportStar)(require("./components/Loading/LoadingOverlay"), exports);
35
+ var EndingPage_1 = require("./components/EndingPage");
36
+ Object.defineProperty(exports, "EndingPage", { enumerable: true, get: function () { return (0, tslib_1.__importDefault)(EndingPage_1).default; } });
35
37
  //# sourceMappingURL=index.js.map
package/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/lib/index.ts"],"names":[],"mappings":";;;;AAAA,qDAA+D;AAAtD,8HAAA,OAAO,OAAU;AAC1B,0EAA2C;AAE3C,qDAA+D;AAAtD,8HAAA,OAAO,OAAU;AAC1B,0EAA2C;AAE3C,0DAAoE;AAA3D,0IAAA,OAAO,OAAgB;AAChC,yEAA0C;AAE1C,kEAA4E;AAAnE,kJAAA,OAAO,OAAoB;AACpC,6EAA8C;AAE9C,wDAAkE;AAAzD,wIAAA,OAAO,OAAe;AAC/B,wEAAyC;AAEzC,0DAAoE;AAA3D,0IAAA,OAAO,OAAgB;AAChC,yEAA0C;AAE1C,kDAA4D;AAAnD,kIAAA,OAAO,OAAY;AAC5B,qEAAsC;AAEtC,4CAAsD;AAA7C,4HAAA,OAAO,OAAS;AACzB,kEAAmC;AAEnC,0EAAoF;AAA3E,4IAAA,OAAO,OAAiB;AACjC,wFAAyD;AAEzD,sEAAgF;AAAvE,8IAAA,OAAO,OAAkB;AAClC,mFAAoD"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/lib/index.ts"],"names":[],"mappings":";;;;AAAA,qDAA+D;AAAtD,8HAAA,OAAO,OAAU;AAC1B,0EAA2C;AAE3C,qDAA+D;AAAtD,8HAAA,OAAO,OAAU;AAC1B,0EAA2C;AAE3C,0DAAoE;AAA3D,0IAAA,OAAO,OAAgB;AAChC,yEAA0C;AAE1C,kEAA4E;AAAnE,kJAAA,OAAO,OAAoB;AACpC,6EAA8C;AAE9C,wDAAkE;AAAzD,wIAAA,OAAO,OAAe;AAC/B,wEAAyC;AAEzC,0DAAoE;AAA3D,0IAAA,OAAO,OAAgB;AAChC,yEAA0C;AAE1C,kDAA4D;AAAnD,kIAAA,OAAO,OAAY;AAC5B,qEAAsC;AAEtC,4CAAsD;AAA7C,4HAAA,OAAO,OAAS;AACzB,kEAAmC;AAEnC,0EAAoF;AAA3E,4IAAA,OAAO,OAAiB;AACjC,wFAAyD;AAEzD,sEAAgF;AAAvE,8IAAA,OAAO,OAAkB;AAClC,mFAAoD;AAEpD,sDAAgE;AAAvD,sIAAA,OAAO,OAAc"}
@@ -0,0 +1,23 @@
1
+ /// <reference types="react" />
2
+ export declare type UserNotify = {
3
+ /** The identifier used to recognize the user notify: it cannot be possible to have the same error id at the same time */
4
+ id: string;
5
+ /** The title to show in the popup or toast */
6
+ title: string;
7
+ /** The body to show in the popup or toast */
8
+ message: React.ReactNode;
9
+ /** If component === 'Toast'. The logo to be rendered. As default a confirm logo will be used */
10
+ logo?: React.ElementType;
11
+ /** If component === 'Toast'. The color used for the left border */
12
+ leftBorderColor?: string;
13
+ /** If component === 'SessionModal'. If defined, it will render a confirm button which will execute this function */
14
+ onConfirm?: () => void;
15
+ /** If component === 'SessionModal'. If present, this string will rappresent the confirm button label */
16
+ confirmLabel?: string;
17
+ /** If defined, it will be executed when closing the popup */
18
+ onClose?: () => void;
19
+ /** If component === 'SessionModal'. The close button label */
20
+ closeLabel?: string;
21
+ /** Can render a SessionModal or Toast component */
22
+ component?: 'SessionModal' | 'Toast';
23
+ };
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=UserNotify.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"UserNotify.js","sourceRoot":"","sources":["../../src/lib/model/UserNotify.ts"],"names":[],"mappings":""}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@pagopa/selfcare-common-frontend",
3
3
  "description": "Shared React components for the pagopa selfcare project",
4
- "version": "1.1.0",
4
+ "version": "1.2.2",
5
5
  "license": "MIT",
6
6
  "repository": "https://github.com/pagopa/selfcare-common-frontend",
7
7
  "author": "https://www.pagopa.gov.it",
@@ -55,16 +55,16 @@
55
55
  "build": "yarn setTsConfigStart && react-scripts build",
56
56
  "clean:build": "rimraf build",
57
57
  "setTsConfigDist": "copyfiles tsconfigDist.json build && renamer --replace tsconfig.json build/tsconfigDist.json && copyfiles -u 1 build/tsconfig.json . && rimraf build/tsconfig.json",
58
- "cpDistStatic": "copyfiles -u 2 src/lib/index.css dist && copyfiles package.json README.md CHANGELOG.md dist",
58
+ "cpDistStatic": "copyfiles -u 2 src/lib/index.css src/lib/utils/fixSwagger20ArraySchemaDef.js dist && copyfiles package.json README.md CHANGELOG.md dist",
59
59
  "dist": "yarn setTsConfigDist && tsc && yarn cpDistStatic",
60
60
  "clean:dist": "rimraf dist",
61
- "test": "yarn setTsConfigStart && react-scripts test --testPathIgnorePatterns src/lib/redux/__tests__/store -i",
62
- "test:coverage": "react-scripts test --testPathIgnorePatterns src/lib/redux/__tests__/store -i --coverage",
61
+ "test": "yarn setTsConfigStart && react-scripts test -i",
62
+ "test:coverage": "react-scripts test -i --coverage",
63
63
  "clean:coverage": "rimraf coverage",
64
64
  "lint-autofix": "yarn setTsConfigStart && eslint . -c .eslintrc.js --ext .ts,.tsx --fix",
65
65
  "lint": "yarn setTsConfigStart && eslint . -c .eslintrc.js --ext .ts,.tsx ",
66
66
  "prettify": "prettier --write \"./**/*.{ts,tsx}\"",
67
- "version": "auto-changelog -p --config .auto-changelog.json --tag-pattern \\d+\\.\\d+.\\d+$ --unreleased --unreleased --ignore-commit-pattern \"Bump version to\" --starting-version v1.0.0 && git add CHANGELOG.md"
67
+ "version": "auto-changelog -p --config .auto-changelog.json --tag-pattern \\d+\\.\\d+.\\d+$ --unreleased --ignore-commit-pattern \"Bump version to\" --starting-version v1.0.0 && git add CHANGELOG.md"
68
68
  },
69
69
  "eslintConfig": {
70
70
  "extends": [
@@ -112,7 +112,15 @@
112
112
  "coveragePathIgnorePatterns": [
113
113
  "src/index.tsx",
114
114
  "src/reportWebVitals.ts",
115
- "src/api/generated"
115
+ "src/api/generated",
116
+ "src/examples/*",
117
+ "src/AppExample.tsx",
118
+ "src/lib/utils/fixSwagger20ArraySchemaDef.js",
119
+ "src/lib/common-polyfill.ts",
120
+ "src/lib/index.ts",
121
+ "src/lib/components/icons/*",
122
+ "src/lib/model/*",
123
+ "src/store.ts"
116
124
  ]
117
125
  }
118
126
  }
@@ -1,5 +1,6 @@
1
1
  import { PayloadAction } from '@reduxjs/toolkit';
2
2
  import { ErrorInfo } from 'react';
3
+ import { UserNotify } from '../../model/UserNotify';
3
4
  export declare type AppError = {
4
5
  /** The identifier used to recognize the error: it cannot be possible to have the same error id at the same time */
5
6
  id: string;
@@ -31,6 +32,14 @@ interface AppStateState {
31
32
  };
32
33
  };
33
34
  errors: Array<AppError>;
35
+ userNotifies: Array<UserNotify>;
36
+ unloadEventConfiguration: {
37
+ enabled: boolean;
38
+ open: boolean;
39
+ title?: string;
40
+ description?: string;
41
+ exitAction?: () => void;
42
+ };
34
43
  }
35
44
  export declare const appStateSlice: import("@reduxjs/toolkit").Slice<AppStateState, {
36
45
  setLoading: (state: import("immer/dist/internal").WritableDraft<AppStateState>, action: PayloadAction<{
@@ -39,6 +48,15 @@ export declare const appStateSlice: import("@reduxjs/toolkit").Slice<AppStateSta
39
48
  }>) => void;
40
49
  addError: (state: import("immer/dist/internal").WritableDraft<AppStateState>, action: PayloadAction<AppError>) => void;
41
50
  removeError: (state: import("immer/dist/internal").WritableDraft<AppStateState>, action: PayloadAction<AppError>) => void;
51
+ addNotify: (state: import("immer/dist/internal").WritableDraft<AppStateState>, action: PayloadAction<UserNotify>) => void;
52
+ removeNotify: (state: import("immer/dist/internal").WritableDraft<AppStateState>, action: PayloadAction<UserNotify>) => void;
53
+ enableUnloadEventInterceptor: (state: import("immer/dist/internal").WritableDraft<AppStateState>, action: PayloadAction<{
54
+ title?: string;
55
+ description?: string;
56
+ }>) => void;
57
+ disableUnloadEventInterceptor: (state: import("immer/dist/internal").WritableDraft<AppStateState>) => void;
58
+ openUnloadEventNotify: (state: import("immer/dist/internal").WritableDraft<AppStateState>, action: PayloadAction<() => void>) => void;
59
+ closeUnloadEventNotify: (state: import("immer/dist/internal").WritableDraft<AppStateState>) => void;
42
60
  }, "appState">;
43
61
  export declare const appStateActions: import("@reduxjs/toolkit").CaseReducerActions<{
44
62
  setLoading: (state: import("immer/dist/internal").WritableDraft<AppStateState>, action: PayloadAction<{
@@ -47,10 +65,35 @@ export declare const appStateActions: import("@reduxjs/toolkit").CaseReducerActi
47
65
  }>) => void;
48
66
  addError: (state: import("immer/dist/internal").WritableDraft<AppStateState>, action: PayloadAction<AppError>) => void;
49
67
  removeError: (state: import("immer/dist/internal").WritableDraft<AppStateState>, action: PayloadAction<AppError>) => void;
68
+ addNotify: (state: import("immer/dist/internal").WritableDraft<AppStateState>, action: PayloadAction<UserNotify>) => void;
69
+ removeNotify: (state: import("immer/dist/internal").WritableDraft<AppStateState>, action: PayloadAction<UserNotify>) => void;
70
+ enableUnloadEventInterceptor: (state: import("immer/dist/internal").WritableDraft<AppStateState>, action: PayloadAction<{
71
+ title?: string;
72
+ description?: string;
73
+ }>) => void;
74
+ disableUnloadEventInterceptor: (state: import("immer/dist/internal").WritableDraft<AppStateState>) => void;
75
+ openUnloadEventNotify: (state: import("immer/dist/internal").WritableDraft<AppStateState>, action: PayloadAction<() => void>) => void;
76
+ closeUnloadEventNotify: (state: import("immer/dist/internal").WritableDraft<AppStateState>) => void;
50
77
  }>;
51
78
  export declare const appStateReducer: import("redux").Reducer<AppStateState, import("redux").AnyAction>;
52
79
  export declare const appStateSelectors: {
53
- selectLoading: (state: any) => any;
54
- selectErrors: (state: any) => any;
80
+ selectLoading: (state: {
81
+ appState: AppStateState;
82
+ }) => boolean;
83
+ selectErrors: (state: {
84
+ appState: AppStateState;
85
+ }) => AppError[];
86
+ selectNotifies: (state: {
87
+ appState: AppStateState;
88
+ }) => UserNotify[];
89
+ selectUnloadEventConfiguration: (state: {
90
+ appState: AppStateState;
91
+ }) => {
92
+ enabled: boolean;
93
+ open: boolean;
94
+ title?: string | undefined;
95
+ description?: string | undefined;
96
+ exitAction?: (() => void) | undefined;
97
+ };
55
98
  };
56
99
  export {};
@@ -8,6 +8,18 @@ const initialState = {
8
8
  tasks: {},
9
9
  },
10
10
  errors: [],
11
+ userNotifies: [],
12
+ unloadEventConfiguration: {
13
+ enabled: false,
14
+ open: false,
15
+ },
16
+ };
17
+ const keepOnPage = (e) => {
18
+ const message = "Warning!\n\nNavigating away from this page will delete your text if you haven't already saved it.";
19
+ e.preventDefault();
20
+ // eslint-disable-next-line functional/immutable-data
21
+ e.returnValue = message;
22
+ return message;
11
23
  };
12
24
  /* eslint-disable functional/immutable-data */
13
25
  exports.appStateSlice = (0, toolkit_1.createSlice)({
@@ -25,11 +37,40 @@ exports.appStateSlice = (0, toolkit_1.createSlice)({
25
37
  }
26
38
  },
27
39
  addError: (state, action) => {
40
+ if (!action.payload.component) {
41
+ action.payload.component = 'SessionModal';
42
+ }
28
43
  state.errors.push(action.payload);
29
44
  },
30
45
  removeError: (state, action) => {
31
46
  state.errors = state.errors.filter((e) => e.id !== action.payload.id);
32
47
  },
48
+ addNotify: (state, action) => {
49
+ state.userNotifies.push(action.payload);
50
+ },
51
+ removeNotify: (state, action) => {
52
+ state.userNotifies = state.userNotifies.filter((e) => e.id !== action.payload.id);
53
+ },
54
+ enableUnloadEventInterceptor: (state, action) => {
55
+ state.unloadEventConfiguration.open = false;
56
+ state.unloadEventConfiguration.enabled = true;
57
+ state.unloadEventConfiguration.title = action.payload.title;
58
+ state.unloadEventConfiguration.description = action.payload.description;
59
+ window.addEventListener('beforeunload', keepOnPage);
60
+ },
61
+ disableUnloadEventInterceptor: (state) => {
62
+ state.unloadEventConfiguration.open = false;
63
+ state.unloadEventConfiguration.enabled = false;
64
+ window.removeEventListener('beforeunload', keepOnPage);
65
+ },
66
+ openUnloadEventNotify: (state, action) => {
67
+ state.unloadEventConfiguration.open = true;
68
+ state.unloadEventConfiguration.exitAction = action.payload;
69
+ },
70
+ closeUnloadEventNotify: (state) => {
71
+ state.unloadEventConfiguration.open = false;
72
+ state.unloadEventConfiguration.exitAction = undefined;
73
+ },
33
74
  },
34
75
  });
35
76
  exports.appStateActions = exports.appStateSlice.actions;
@@ -37,5 +78,7 @@ exports.appStateReducer = exports.appStateSlice.reducer;
37
78
  exports.appStateSelectors = {
38
79
  selectLoading: (state) => state.appState.loading.result,
39
80
  selectErrors: (state) => state.appState.errors,
81
+ selectNotifies: (state) => state.appState.userNotifies,
82
+ selectUnloadEventConfiguration: (state) => state.appState.unloadEventConfiguration,
40
83
  };
41
84
  //# sourceMappingURL=appStateSlice.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"appStateSlice.js","sourceRoot":"","sources":["../../../src/lib/redux/slices/appStateSlice.ts"],"names":[],"mappings":";;;AAAA,8CAA8D;AAmC9D,MAAM,YAAY,GAAkB;IAClC,OAAO,EAAE;QACP,MAAM,EAAE,KAAK;QACb,KAAK,EAAE,EAAE;KACV;IACD,MAAM,EAAE,EAAE;CACX,CAAC;AAEF,8CAA8C;AACjC,QAAA,aAAa,GAAG,IAAA,qBAAW,EAAC;IACvC,IAAI,EAAE,UAAU;IAChB,YAAY;IACZ,QAAQ,EAAE;QACR,UAAU,EAAE,CAAC,KAAK,EAAE,MAAyD,EAAE,EAAE;YAC/E,IAAI,MAAM,CAAC,OAAO,CAAC,OAAO,EAAE;gBAC1B,KAAK,CAAC,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC;gBAC5B,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC;aACjD;iBAAM;gBACL,OAAO,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;gBAChD,KAAK,CAAC,OAAO,CAAC,MAAM,GAAG,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC;aACpE;QACH,CAAC;QACD,QAAQ,EAAE,CAAC,KAAK,EAAE,MAA+B,EAAE,EAAE;YACnD,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;QACpC,CAAC;QACD,WAAW,EAAE,CAAC,KAAK,EAAE,MAA+B,EAAE,EAAE;YACtD,KAAK,CAAC,MAAM,GAAG,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CA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EAAE,CAAC,KAAkC,EAAE,EAAE,CAAC,KAAK,CAAC,QAAQ,CAAC,MAAM;IAC3E,cAAc,EAAE,CAAC,KAAkC,EAAE,EAAE,CAAC,KAAK,CAAC,QAAQ,CAAC,YAAY;IACnF,8BAA8B,EAAE,CAAC,KAAkC,EAAE,EAAE,CAAC,KAAK,CAAC,QAAQ,CAAC,wBAAwB;CAChH,CAAC"}
@@ -11,6 +11,8 @@ export declare const userActions: import("@reduxjs/toolkit").CaseReducerActions<
11
11
  }>;
12
12
  export declare const userReducer: import("redux").Reducer<UserState, import("redux").AnyAction>;
13
13
  export declare const userSelectors: {
14
- selectLoggedUser: (state: any) => any;
14
+ selectLoggedUser: (state: {
15
+ user: UserState;
16
+ }) => User | undefined;
15
17
  };
16
18
  export {};
@@ -1 +1 @@
1
- {"version":3,"file":"userSlice.js","sourceRoot":"","sources":["../../../src/lib/redux/slices/userSlice.ts"],"names":[],"mappings":";;;AAAA,8CAA8D;AAO9D,MAAM,YAAY,GAAc,EAAE,CAAC;AAEnC,8CAA8C;AACjC,QAAA,SAAS,GAAG,IAAA,qBAAW,EAAC;IACnC,IAAI,EAAE,MAAM;IACZ,YAAY;IACZ,QAAQ,EAAE;QACR,aAAa,EAAE,CAAC,KAAK,EAAE,MAA2B,EAAE,EAAE;YACpD,KAAK,CAAC,MAAM,GAAG,MAAM,CAAC,OAAO,CAAC;QAChC,CAAC;KACF;CACF,CAAC,CAAC;AAEU,QAAA,WAAW,GAAG,iBAAS,CAAC,OAAO,CAAC;AAChC,QAAA,WAAW,GAAG,iBAAS,CAAC,OAAO,CAAC;AAEhC,QAAA,aAAa,GAAG;IAC3B,gBAAgB,EAAE,CAAC,KAAU,EAAE,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM;CACpD,CAAC"}
1
+ {"version":3,"file":"userSlice.js","sourceRoot":"","sources":["../../../src/lib/redux/slices/userSlice.ts"],"names":[],"mappings":";;;AAAA,8CAA8D;AAO9D,MAAM,YAAY,GAAc,EAAE,CAAC;AAEnC,8CAA8C;AACjC,QAAA,SAAS,GAAG,IAAA,qBAAW,EAAC;IACnC,IAAI,EAAE,MAAM;IACZ,YAAY;IACZ,QAAQ,EAAE;QACR,aAAa,EAAE,CAAC,KAAK,EAAE,MAA2B,EAAE,EAAE;YACpD,KAAK,CAAC,MAAM,GAAG,MAAM,CAAC,OAAO,CAAC;QAChC,CAAC;KACF;CACF,CAAC,CAAC;AAEU,QAAA,WAAW,GAAG,iBAAS,CAAC,OAAO,CAAC;AAChC,QAAA,WAAW,GAAG,iBAAS,CAAC,OAAO,CAAC;AAEhC,QAAA,aAAa,GAAG;IAC3B,gBAAgB,EAAE,CAAC,KAA0B,EAAE,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM;CACpE,CAAC"}
@@ -0,0 +1,16 @@
1
+ import { ApiRequestType, IResponseType, TypeofApiResponse } from '@pagopa/ts-commons/lib/requests';
2
+ import * as t from 'io-ts';
3
+ import { EnhancedStore } from '@reduxjs/toolkit';
4
+ /** To show an error popup to inform of the not valid session */
5
+ export declare const onRedirectToLogin: (store: EnhancedStore) => {
6
+ payload: import("../redux/slices/appStateSlice").AppError;
7
+ type: string;
8
+ };
9
+ /** Return the implementation of fetch configured with a timeout */
10
+ export declare const buildFetchApi: (timeoutMs?: number) => (input: string | Request, init?: RequestInit | undefined) => Promise<Response>;
11
+ /** Extract the response of a @pagopa/openapi-codegen-ts generated client rest invocation having status code successHttpStatus.
12
+ If notValidTokenHttpStatus is not null and the returned status is equal to notValidTokenHttpStatus, it will call the onRedirectToLogin function and will schedule the redirect towards logout path.
13
+ If notAuthorizedTokenHttpStatus is not null and the returned status is equal to notAuthorizedTokenHttpStatus, it will throw an Error with message "Operation not allowed".
14
+ If emptyResponseHttpStatus is not null and the returned status is equal to emptyResponseHttpStatus, it will return a promise that resolve to null value.
15
+ Other statuses will return will throw a generic error. */
16
+ export declare const extractResponse: <R>(response: t.Validation<TypeofApiResponse<ApiRequestType<any, any, any, IResponseType<any, any, any>>>>, successHttpStatus: number, onRedirectToLogin: () => void, notValidTokenHttpStatus?: number | null, notAuthorizedTokenHttpStatus?: number | null, emptyResponseHttpStatus?: number | null) => Promise<R>;
@@ -0,0 +1,63 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.extractResponse = exports.buildFetchApi = exports.onRedirectToLogin = void 0;
4
+ const Either_1 = require("fp-ts/lib/Either");
5
+ const ts_commons_1 = require("@pagopa/ts-commons");
6
+ const fetch_1 = require("@pagopa/ts-commons/lib/fetch");
7
+ const env_1 = require("../config/env");
8
+ const appStateSlice_1 = require("../redux/slices/appStateSlice");
9
+ /** To show an error popup to inform of the not valid session */
10
+ const onRedirectToLogin = (store) => store.dispatch(appStateSlice_1.appStateActions.addError({
11
+ id: 'tokenNotValid',
12
+ error: new Error(),
13
+ techDescription: 'token expired or not valid',
14
+ toNotify: false,
15
+ blocking: false,
16
+ displayableTitle: 'Sessione scaduta',
17
+ displayableDescription: 'Stai per essere rediretto alla pagina di login...',
18
+ }));
19
+ exports.onRedirectToLogin = onRedirectToLogin;
20
+ /** Return the implementation of fetch configured with a timeout */
21
+ const buildFetchApi = (timeoutMs = 300000) => {
22
+ // Must be an https endpoint so we use an https agent
23
+ const abortableFetch = (0, fetch_1.AbortableFetch)(ts_commons_1.agent.getHttpFetch(process.env));
24
+ const fetchWithTimeout = (0, fetch_1.toFetch)((0, fetch_1.setFetchTimeout)(timeoutMs, abortableFetch));
25
+ // tslint:disable-next-line: no-any
26
+ return fetch;
27
+ };
28
+ exports.buildFetchApi = buildFetchApi;
29
+ /** Extract the response of a @pagopa/openapi-codegen-ts generated client rest invocation having status code successHttpStatus.
30
+ If notValidTokenHttpStatus is not null and the returned status is equal to notValidTokenHttpStatus, it will call the onRedirectToLogin function and will schedule the redirect towards logout path.
31
+ If notAuthorizedTokenHttpStatus is not null and the returned status is equal to notAuthorizedTokenHttpStatus, it will throw an Error with message "Operation not allowed".
32
+ If emptyResponseHttpStatus is not null and the returned status is equal to emptyResponseHttpStatus, it will return a promise that resolve to null value.
33
+ Other statuses will return will throw a generic error. */
34
+ const extractResponse = async (response, successHttpStatus, onRedirectToLogin, notValidTokenHttpStatus = 401, notAuthorizedTokenHttpStatus = 403, emptyResponseHttpStatus = 404) => {
35
+ if ((0, Either_1.isRight)(response)) {
36
+ if (response.right.status === successHttpStatus) {
37
+ return response.right.value;
38
+ }
39
+ else if (notValidTokenHttpStatus && response.right.status === notValidTokenHttpStatus) {
40
+ onRedirectToLogin();
41
+ window.setTimeout(() => window.location.assign(env_1.CONFIG.URL_FE.LOGOUT), 2000);
42
+ return new Promise(() => null);
43
+ }
44
+ else if (notAuthorizedTokenHttpStatus &&
45
+ response.right.status === notAuthorizedTokenHttpStatus) {
46
+ throw new Error(`Operation not allowed!`);
47
+ }
48
+ else if (emptyResponseHttpStatus && response.right.status === emptyResponseHttpStatus) {
49
+ return new Promise((resolve) => resolve(null));
50
+ }
51
+ else {
52
+ console.error(JSON.stringify(response.right));
53
+ throw new Error(`Unexpected HTTP status! Expected ${successHttpStatus} obtained ${response.right.status}`);
54
+ }
55
+ }
56
+ else {
57
+ console.error('Something gone wrong while fetching data');
58
+ console.error(JSON.stringify(response.left));
59
+ throw (0, Either_1.toError)(response.left);
60
+ }
61
+ };
62
+ exports.extractResponse = extractResponse;
63
+ //# sourceMappingURL=api-utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"api-utils.js","sourceRoot":"","sources":["../../src/lib/utils/api-utils.ts"],"names":[],"mappings":";;;AACA,6CAAoD;AAEpD,mDAA2C;AAC3C,wDAAwF;AAGxF,uCAAuC;AACvC,iEAAgE;AAEhE,gEAAgE;AACzD,MAAM,iBAAiB,GAAG,CAAC,KAAoB,EAAE,EAAE,CACxD,KAAK,CAAC,QAAQ,CACZ,+BAAe,CAAC,QAAQ,CAAC;IACvB,EAAE,EAAE,eAAe;IACnB,KAAK,EAAE,IAAI,KAAK,EAAE;IAClB,eAAe,EAA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,QAAQ,CAAC,KAAK,CAAC,MAAM,KAAK,4BAA4B,EACtD;YACA,MAAM,IAAI,KAAK,CAAC,wBAAwB,CAAC,CAAC;SAC3C;aAAM,IAAI,uBAAuB,IAAI,QAAQ,CAAC,KAAK,CAAC,MAAM,KAAK,uBAAuB,EAAE;YACvF,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,IAAoB,CAAC,CAAC,CAAC;SAChE;aAAM;YACL,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC;YAC9C,MAAM,IAAI,KAAK,CACb,oCAAoC,iBAAiB,aAAa,QAAQ,CAAC,KAAK,CAAC,MAAM,EAAE,CAC1F,CAAC;SACH;KACF;SAAM;QACL,OAAO,CAAC,KAAK,CAAC,0CAA0C,CAAC,CAAC;QAC1D,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC;QAC7C,MAAM,IAAA,gBAAO,EAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;KAC9B;AACH,CAAC,CAAC;AAnCW,QAAA,eAAe,mBAmC1B"}
@@ -1,7 +1,10 @@
1
1
  import { UserRole } from '../model/Party';
2
+ /** The key used to store in the session storage the loggedUser in selfcare projects */
2
3
  export declare const STORAGE_KEY_USER = "user";
4
+ /** The key used to store in the session storage the logged user token in selfcare projects */
3
5
  export declare const STORAGE_KEY_TOKEN = "token";
4
6
  export declare const LOADING_TASK_LOGIN_CHECK = "LOGIN_CHECK";
7
+ /** The short and long labels used for the roles of selfcare's projects */
5
8
  export declare const roleLabels: {
6
9
  [key in UserRole]: {
7
10
  shortLabel: string;
@@ -1,9 +1,12 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.roleLabels = exports.LOADING_TASK_LOGIN_CHECK = exports.STORAGE_KEY_TOKEN = exports.STORAGE_KEY_USER = void 0;
4
+ /** The key used to store in the session storage the loggedUser in selfcare projects */
4
5
  exports.STORAGE_KEY_USER = 'user';
6
+ /** The key used to store in the session storage the logged user token in selfcare projects */
5
7
  exports.STORAGE_KEY_TOKEN = 'token';
6
8
  exports.LOADING_TASK_LOGIN_CHECK = 'LOGIN_CHECK';
9
+ /** The short and long labels used for the roles of selfcare's projects */
7
10
  exports.roleLabels = {
8
11
  ADMIN: { shortLabel: 'Ref. Amministrativo', longLabel: 'Referente Amministrativo' },
9
12
  LIMITED: { shortLabel: 'Ref. Operativo', longLabel: 'Referente Operativo' },
@@ -1 +1 @@
1
- {"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/lib/utils/constants.ts"],"names":[],"mappings":";;;AAEa,QAAA,gBAAgB,GAAG,MAAM,CAAC;AAC1B,QAAA,iBAAiB,GAAG,OAAO,CAAC;AAE5B,QAAA,wBAAwB,GAAG,aAAa,CAAC;AAEzC,QAAA,UAAU,GAAqE;IAC1F,KAAK,EAAE,EAAE,UAAU,EAAE,qBAAqB,EAAE,SAAS,EAAE,0BAA0B,EAAE;IACnF,OAAO,EAAE,EAAE,UAAU,EAAE,gBAAgB,EAAE,SAAS,EAAE,qBAAqB,EAAE;CAC5E,CAAC"}
1
+ {"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/lib/utils/constants.ts"],"names":[],"mappings":";;;AAEA,uFAAuF;AAC1E,QAAA,gBAAgB,GAAG,MAAM,CAAC;AACvC,8FAA8F;AACjF,QAAA,iBAAiB,GAAG,OAAO,CAAC;AAE5B,QAAA,wBAAwB,GAAG,aAAa,CAAC;AAEtD,0EAA0E;AAC7D,QAAA,UAAU,GAAqE;IAC1F,KAAK,EAAE,EAAE,UAAU,EAAE,qBAAqB,EAAE,SAAS,EAAE,0BAA0B,EAAE;IACnF,OAAO,EAAE,EAAE,UAAU,EAAE,gBAAgB,EAAE,SAAS,EAAE,qBAAqB,EAAE;CAC5E,CAAC"}
@@ -0,0 +1,67 @@
1
+ const fs = require('fs');
2
+ const regexReplace = require('regex-replace');
3
+
4
+ console.log(`Fixing Swagger 2.0 schema array definition in ${process.argv[2]}`);
5
+
6
+ const filePath = process.argv[2];
7
+
8
+ const patternRef =
9
+ /"schema"\s*:\s*\{[^{]+\{\s*"\$ref"\s*:\s*"#\/definitions\/([^"]+)"[^,]+,\s+"type"\s*:\s*"array"[^}]+}((?:\n|.)*"definitions"\s*:\s*\{)/gm;
10
+ const patternRef2 =
11
+ /"schema"\s*:\s*\{\s*"type"\s*:\s*"array"[^{]+\{\s*"\$ref"\s*:\s*"#\/definitions\/([^"]+)"[^}]*}[^}]*}((?:\n|.)*"definitions"\s*:\s*\{)/gm;
12
+ const replaceRef =
13
+ '"schema":{"$ref":"#/definitions/$1Array"}$2"$1Array":{"type": "array", "items": {"$ref": "#/definitions/$1"}},';
14
+
15
+ async function fixArrayDef(patternRef, replaceRef) {
16
+ regexReplace(patternRef, replaceRef, filePath).then((r) => {
17
+ fs.readFile(filePath, 'utf8', function (err, doc) {
18
+ if (doc.match(patternRef)) {
19
+ fixArrayDef(patternRef, replaceRef);
20
+ }
21
+ });
22
+ });
23
+ }
24
+
25
+ const patternNativeArrayType = (nativeType) =>
26
+ new RegExp(
27
+ `"schema"\\s*:\\s*\\{[^{]+\\{\\s*"type"\\s*:\\s*"${nativeType}"[^,]+,\\s+"type"\\s*:\\s*"array"[^}]+}`,
28
+ 'gm'
29
+ );
30
+ const replaceNativeArrayType = (nativeType) =>
31
+ `"schema":{"$ref":"#/definitions/${nativeType.toUpperCase()}Array"}`;
32
+
33
+ const patternNativeTypeRef = /"definitions"\s*:\s*\{/gm;
34
+ const replaceNativeArrayTypeRef = (nativeType) =>
35
+ `"definitions" : {"${nativeType.toUpperCase()}Array":{"type": "array", "items": {"type": "${nativeType}"}},`;
36
+
37
+ async function fixArrayNativeDef(nativeType) {
38
+ await regexReplace(
39
+ patternNativeArrayType(nativeType),
40
+ replaceNativeArrayType(nativeType),
41
+ filePath
42
+ );
43
+
44
+ await regexReplace(patternNativeTypeRef, replaceNativeArrayTypeRef(nativeType), filePath);
45
+ }
46
+
47
+ const patternNativeType = (nativeType) =>
48
+ new RegExp(`"schema"\\s*:\\s*\\{\\s*"type"\\s*:\\s*"${nativeType}"\\s*}`, 'gm');
49
+ const replaceNativeType = (nativeType) =>
50
+ `"schema":{"$ref":"#/definitions/${nativeType.toUpperCase()}Wrapper"}`;
51
+ const replaceNativeTypeRef = (nativeType) =>
52
+ `"definitions" : {"${nativeType.toUpperCase()}Wrapper":{"type": "${nativeType}"},`;
53
+
54
+ async function fixNativeDef(nativeType) {
55
+ await regexReplace(patternNativeType(nativeType), replaceNativeType(nativeType), filePath);
56
+
57
+ await regexReplace(patternNativeTypeRef, replaceNativeTypeRef(nativeType), filePath);
58
+ }
59
+
60
+ async function exec() {
61
+ await fixArrayDef(patternRef, replaceRef);
62
+ await fixArrayDef(patternRef2, replaceRef);
63
+ await fixArrayNativeDef('string');
64
+ await fixNativeDef('string');
65
+ }
66
+
67
+ exec();
@@ -1,3 +1,4 @@
1
+ /** It will resolve the path variables in path using the provided map */
1
2
  export declare const resolvePathVariables: (path: string, pathVariables: {
2
3
  [key: string]: string;
3
4
  }) => string;
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.resolvePathVariables = void 0;
4
+ /** It will resolve the path variables in path using the provided map */
4
5
  const resolvePathVariables = (path, pathVariables) => Object.keys(pathVariables).reduce((result, key) => result.replace(`:${key}`, pathVariables[key]), path);
5
6
  exports.resolvePathVariables = resolvePathVariables;
6
7
  //# sourceMappingURL=routes-utils.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"routes-utils.js","sourceRoot":"","sources":["../../src/lib/utils/routes-utils.tsx"],"names":[],"mappings":";;;AAAO,MAAM,oBAAoB,GAAG,CAAC,IAAY,EAAE,aAAwC,EAAE,EAAE,CAC7F,MAAM,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC,MAAM,CAC/B,CAAC,MAAM,EAAE,GAAG,EAAE,EAAE,CAAC,MAAM,CAAC,OAAO,CAAC,IAAI,GAAG,EAAE,EAAE,aAAa,CAAC,GAAG,CAAC,CAAC,EAC9D,IAAI,CACL,CAAC;AAJS,QAAA,oBAAoB,wBAI7B"}
1
+ {"version":3,"file":"routes-utils.js","sourceRoot":"","sources":["../../src/lib/utils/routes-utils.tsx"],"names":[],"mappings":";;;AAAA,wEAAwE;AACjE,MAAM,oBAAoB,GAAG,CAAC,IAAY,EAAE,aAAwC,EAAE,EAAE,CAC7F,MAAM,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC,MAAM,CAC/B,CAAC,MAAM,EAAE,GAAG,EAAE,EAAE,CAAC,MAAM,CAAC,OAAO,CAAC,IAAI,GAAG,EAAE,EAAE,aAAa,CAAC,GAAG,CAAC,CAAC,EAC9D,IAAI,CACL,CAAC;AAJS,QAAA,oBAAoB,wBAI7B"}
@@ -1,6 +1,9 @@
1
1
  declare type StorageValue = string | number | object;
2
2
  declare type StorageValueType = 'string' | 'number' | 'object';
3
+ /** It will delete a key from the local session storage */
3
4
  export declare function storageDelete(key: string): void;
5
+ /** It will store a key/value pair in the local session storage */
4
6
  export declare function storageWrite(key: string, value: StorageValue, type: StorageValueType): void;
7
+ /** It will read a key from the local session storage */
5
8
  export declare function storageRead(key: string, type: StorageValueType): any;
6
9
  export {};
@@ -1,10 +1,12 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.storageRead = exports.storageWrite = exports.storageDelete = void 0;
4
+ /** It will delete a key from the local session storage */
4
5
  function storageDelete(key) {
5
6
  window.sessionStorage.removeItem(key);
6
7
  }
7
8
  exports.storageDelete = storageDelete;
9
+ /** It will store a key/value pair in the local session storage */
8
10
  function storageWrite(key, value, type) {
9
11
  const stringifyFn = {
10
12
  string: () => value,
@@ -15,6 +17,7 @@ function storageWrite(key, value, type) {
15
17
  window.sessionStorage.setItem(key, stringified);
16
18
  }
17
19
  exports.storageWrite = storageWrite;
20
+ /** It will read a key from the local session storage */
18
21
  function storageRead(key, type) {
19
22
  const value = window.sessionStorage.getItem(key);
20
23
  if (value === null) {
@@ -1 +1 @@
1
- {"version":3,"file":"storage-utils.js","sourceRoot":"","sources":["../../src/lib/utils/storage-utils.ts"],"names":[],"mappings":";;;AAIA,SAAgB,aAAa,CAAC,GAAW;IACvC,MAAM,CAAC,cAAc,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC;AACxC,CAAC;AAFD,sCAEC;AAED,SAAgB,YAAY,CAAC,GAAW,EAAE,KAAmB,EAAE,IAAsB;IACnF,MAAM,WAAW,GAAgD;QAC/D,MAAM,EAAE,GAAG,EAAE,CAAC,KAAe;QAC7B,MAAM,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC;QAC3B,MAAM,EAAE,GAAG,EAAE,CAAC,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC;KACpC,CAAC;IAEF,MAAM,WAAW,GAAG,WAAW,CAAC,IAAI,CAAC,EAAE,CAAC;IAExC,MAAM,CAAC,cAAc,CAAC,OAAO,CAAC,GAAG,EAAE,WAAW,CAAC,CAAC;AAClD,CAAC;AAVD,oCAUC;AAED,SAAgB,WAAW,CAAC,GAAW,EAAE,IAAsB;IAC7D,MAAM,KAAK,GAAkB,MAAM,CAAC,cAAc,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;IAEhE,IAAI,KAAK,KAAK,IAAI,EAAE;QAClB,OAAO;KACR;IAED,MAAM,OAAO,GAAG;QACd,MAAM,EAAE,GAAG,EAAE,CAAC,KAAK;QACnB,MAAM,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC;QAC3B,MAAM,EAAE,GAAG,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC;KAChC,CAAC;IAEF,OAAO,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC;AACzB,CAAC;AAdD,kCAcC"}
1
+ {"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