@fluxo-dev/state 0.0.5 → 0.0.8
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/.babelrc +12 -0
- package/.eslintrc.json +18 -0
- package/jest.config.ts +11 -0
- package/package.json +1 -4
- package/project.json +43 -0
- package/src/{index.d.ts → index.ts} +2 -1
- package/src/lib/constants/local-storage.ts +4 -0
- package/src/lib/fluxo-client/fluxoClientSlice.ts +27 -0
- package/src/lib/fluxo-client-configuration.ts +10 -0
- package/src/lib/layout/layoutSlice.ts +67 -0
- package/src/lib/route-rule/route-rule-slice.ts +25 -0
- package/src/lib/store.ts +29 -0
- package/src/lib/user/userActions.ts +28 -0
- package/src/lib/user/userSlice.ts +82 -0
- package/tsconfig.json +25 -0
- package/tsconfig.lib.json +23 -0
- package/tsconfig.spec.json +20 -0
- package/index.esm.d.ts +0 -1
- package/index.esm.js +0 -36581
- package/src/lib/constants/local-storage.d.ts +0 -4
- package/src/lib/fluxo-client/fluxoClientSlice.d.ts +0 -7
- package/src/lib/fluxo-client-configuration.d.ts +0 -9
- package/src/lib/layout/layoutSlice.d.ts +0 -14
- package/src/lib/route-rule/route-rule-slice.d.ts +0 -6
- package/src/lib/store.d.ts +0 -17
- package/src/lib/user/userActions.d.ts +0 -22
- package/src/lib/user/userSlice.d.ts +0 -12
package/.babelrc
ADDED
package/.eslintrc.json
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extends": ["plugin:@nx/react", "../../../.eslintrc.json"],
|
|
3
|
+
"ignorePatterns": ["!**/*"],
|
|
4
|
+
"overrides": [
|
|
5
|
+
{
|
|
6
|
+
"files": ["*.ts", "*.tsx", "*.js", "*.jsx"],
|
|
7
|
+
"rules": {}
|
|
8
|
+
},
|
|
9
|
+
{
|
|
10
|
+
"files": ["*.ts", "*.tsx"],
|
|
11
|
+
"rules": {}
|
|
12
|
+
},
|
|
13
|
+
{
|
|
14
|
+
"files": ["*.js", "*.jsx"],
|
|
15
|
+
"rules": {}
|
|
16
|
+
}
|
|
17
|
+
]
|
|
18
|
+
}
|
package/jest.config.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/* eslint-disable */
|
|
2
|
+
export default {
|
|
3
|
+
displayName: 'shared-state',
|
|
4
|
+
preset: '../../../jest.preset.js',
|
|
5
|
+
transform: {
|
|
6
|
+
'^(?!.*\\.(js|jsx|ts|tsx|css|json)$)': '@nx/react/plugins/jest',
|
|
7
|
+
'^.+\\.[tj]sx?$': ['babel-jest', { presets: ['@nx/react/babel'] }],
|
|
8
|
+
},
|
|
9
|
+
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx'],
|
|
10
|
+
coverageDirectory: '../../../coverage/libs/shared/state',
|
|
11
|
+
};
|
package/package.json
CHANGED
package/project.json
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "shared-state",
|
|
3
|
+
"$schema": "../../../node_modules/nx/schemas/project-schema.json",
|
|
4
|
+
"sourceRoot": "libs/shared/state/src",
|
|
5
|
+
"projectType": "library",
|
|
6
|
+
"tags": ["scope:shared-state"],
|
|
7
|
+
"targets": {
|
|
8
|
+
"build": {
|
|
9
|
+
"executor": "@nx/rollup:rollup",
|
|
10
|
+
"outputs": ["{options.outputPath}"],
|
|
11
|
+
"options": {
|
|
12
|
+
"outputPath": "dist/libs/shared/state",
|
|
13
|
+
"tsConfig": "libs/shared/state/tsconfig.lib.json",
|
|
14
|
+
"project": "libs/shared/state/package.json",
|
|
15
|
+
"entryFile": "libs/shared/state/src/index.ts",
|
|
16
|
+
"external": ["react/jsx-runtime"],
|
|
17
|
+
"rollupConfig": "@nx/react/plugins/bundle-rollup",
|
|
18
|
+
"compiler": "babel",
|
|
19
|
+
"assets": [
|
|
20
|
+
{
|
|
21
|
+
"glob": "libs/shared/state/README.md",
|
|
22
|
+
"input": ".",
|
|
23
|
+
"output": "."
|
|
24
|
+
}
|
|
25
|
+
]
|
|
26
|
+
}
|
|
27
|
+
},
|
|
28
|
+
"lint": {
|
|
29
|
+
"executor": "@nx/eslint:lint",
|
|
30
|
+
"outputs": ["{options.outputFile}"],
|
|
31
|
+
"options": {
|
|
32
|
+
"lintFilePatterns": ["libs/shared/state/**/*.{ts,tsx,js,jsx}"]
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
"test": {
|
|
36
|
+
"executor": "@nx/jest:jest",
|
|
37
|
+
"outputs": ["{workspaceRoot}/coverage/{projectRoot}"],
|
|
38
|
+
"options": {
|
|
39
|
+
"jestConfig": "libs/shared/state/jest.config.ts"
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
export * from './lib/fluxo-client/fluxoClientSlice'
|
|
1
|
+
export * from './lib/fluxo-client/fluxoClientSlice'
|
|
2
2
|
export * from './lib/store';
|
|
3
3
|
export * from './lib/fluxo-client-configuration';
|
|
4
|
+
|
|
4
5
|
export * from './lib/fluxo-client/fluxoClientSlice';
|
|
5
6
|
export * from './lib/layout/layoutSlice';
|
|
6
7
|
export * from './lib/user/userActions';
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { createSlice } from '@reduxjs/toolkit';
|
|
2
|
+
import {FluxoClientConfiguration} from "../fluxo-client-configuration";
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
export interface IFluxoClientSliceState {
|
|
6
|
+
fluxoClientConfig: FluxoClientConfiguration | null;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
const initialState: IFluxoClientSliceState = {
|
|
10
|
+
fluxoClientConfig: null,
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
const fluxoClientSlice = createSlice({
|
|
14
|
+
name: 'fluxoClient',
|
|
15
|
+
initialState,
|
|
16
|
+
reducers: {
|
|
17
|
+
setFluxoClientConfiguration(state, action) {
|
|
18
|
+
state.fluxoClientConfig = action.payload
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
})
|
|
22
|
+
|
|
23
|
+
export const {
|
|
24
|
+
setFluxoClientConfiguration
|
|
25
|
+
} = fluxoClientSlice.actions;
|
|
26
|
+
|
|
27
|
+
export default fluxoClientSlice.reducer
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import {createSlice, PayloadAction} from '@reduxjs/toolkit'
|
|
2
|
+
|
|
3
|
+
const initialState: {loading: boolean, searchPanelOpened: boolean, userIdle: boolean, navbarOpened: boolean, configuration: any, appMenu: any[], sysFeatures: any, jitAppFeatures: any} = {
|
|
4
|
+
loading: false,
|
|
5
|
+
searchPanelOpened: false,
|
|
6
|
+
userIdle: false,
|
|
7
|
+
navbarOpened: false,
|
|
8
|
+
configuration: {},
|
|
9
|
+
appMenu: [],
|
|
10
|
+
sysFeatures: {},
|
|
11
|
+
jitAppFeatures: {}
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const layoutSlice = createSlice({
|
|
15
|
+
name: 'layout',
|
|
16
|
+
initialState,
|
|
17
|
+
reducers: {
|
|
18
|
+
openSearchPanel(state, action) {
|
|
19
|
+
state.searchPanelOpened = true
|
|
20
|
+
},
|
|
21
|
+
closeSearchPanel(state, action) {
|
|
22
|
+
state.searchPanelOpened = false
|
|
23
|
+
},
|
|
24
|
+
openNavbar(state, action) {
|
|
25
|
+
state.navbarOpened = true
|
|
26
|
+
},
|
|
27
|
+
closeNavbar(state, action) {
|
|
28
|
+
state.navbarOpened = false
|
|
29
|
+
},
|
|
30
|
+
setUserIdle(state, action) {
|
|
31
|
+
state.userIdle = true
|
|
32
|
+
},
|
|
33
|
+
unsetUserIdle(state, action) {
|
|
34
|
+
state.userIdle = false
|
|
35
|
+
},
|
|
36
|
+
setConfiguration(state, action: PayloadAction<any[]>) {
|
|
37
|
+
state.configuration = action.payload;
|
|
38
|
+
},
|
|
39
|
+
setSysFeatures(state, action: PayloadAction<any[]>) {
|
|
40
|
+
state.sysFeatures = action.payload;
|
|
41
|
+
},
|
|
42
|
+
setJitAppsFeatures(state, action: PayloadAction<any[]>) {
|
|
43
|
+
state.jitAppFeatures = action.payload;
|
|
44
|
+
},
|
|
45
|
+
setAppMenu(state, action: PayloadAction<any[]>) {
|
|
46
|
+
state.appMenu = action.payload;
|
|
47
|
+
}
|
|
48
|
+
},
|
|
49
|
+
})
|
|
50
|
+
|
|
51
|
+
export const {
|
|
52
|
+
openSearchPanel,
|
|
53
|
+
closeSearchPanel,
|
|
54
|
+
setUserIdle,
|
|
55
|
+
unsetUserIdle,
|
|
56
|
+
openNavbar,
|
|
57
|
+
closeNavbar,
|
|
58
|
+
setConfiguration,
|
|
59
|
+
setSysFeatures,
|
|
60
|
+
setJitAppsFeatures,
|
|
61
|
+
setAppMenu,
|
|
62
|
+
} = layoutSlice.actions;
|
|
63
|
+
|
|
64
|
+
export default layoutSlice.reducer
|
|
65
|
+
|
|
66
|
+
export class toggleUserIdle {
|
|
67
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { createSlice } from '@reduxjs/toolkit';
|
|
2
|
+
|
|
3
|
+
export interface IFluxoRouteRuleSliceState {
|
|
4
|
+
routeRules: any[] | null;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
const initialState: IFluxoRouteRuleSliceState = {
|
|
8
|
+
routeRules: null,
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
const fluxoRouteSlice = createSlice({
|
|
12
|
+
name: 'fluxoRouteRule',
|
|
13
|
+
initialState,
|
|
14
|
+
reducers: {
|
|
15
|
+
setRouteRules(state, action) {
|
|
16
|
+
state.routeRules = action.payload
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
})
|
|
20
|
+
|
|
21
|
+
export const {
|
|
22
|
+
setRouteRules
|
|
23
|
+
} = fluxoRouteSlice.actions;
|
|
24
|
+
|
|
25
|
+
export default fluxoRouteSlice.reducer
|
package/src/lib/store.ts
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { configureStore } from '@reduxjs/toolkit'
|
|
2
|
+
import userReducer from './user/userSlice'
|
|
3
|
+
import layoutReducer from './layout/layoutSlice'
|
|
4
|
+
import fluxoClientReducer from './fluxo-client/fluxoClientSlice'
|
|
5
|
+
import fluxoRouteRuleReducer from './route-rule/route-rule-slice';
|
|
6
|
+
import {TypedUseSelectorHook, useDispatch, useSelector} from "react-redux";
|
|
7
|
+
|
|
8
|
+
export interface IFluxoRootState {
|
|
9
|
+
user: ReturnType<typeof userReducer>;
|
|
10
|
+
layout: ReturnType<typeof layoutReducer>;
|
|
11
|
+
client: ReturnType<typeof fluxoClientReducer>;
|
|
12
|
+
routeRules: ReturnType<typeof fluxoRouteRuleReducer>;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export const store = configureStore<IFluxoRootState>({
|
|
16
|
+
reducer: {
|
|
17
|
+
user: userReducer,
|
|
18
|
+
layout: layoutReducer,
|
|
19
|
+
client: fluxoClientReducer,
|
|
20
|
+
routeRules: fluxoRouteRuleReducer,
|
|
21
|
+
},
|
|
22
|
+
})
|
|
23
|
+
|
|
24
|
+
type AppDispatch = typeof store.dispatch
|
|
25
|
+
type RootState = ReturnType<typeof store.getState>
|
|
26
|
+
|
|
27
|
+
// Use throughout your app instead of plain `useDispatch` and `useSelector`
|
|
28
|
+
export const useAppDispatch : () => AppDispatch = useDispatch
|
|
29
|
+
export const useAppSelector : TypedUseSelectorHook<RootState> = useSelector
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import {createAsyncThunk} from "@reduxjs/toolkit";
|
|
2
|
+
|
|
3
|
+
export const userLogin = createAsyncThunk<any, { id: string } & Partial<any>, { rejectValue: any}>(
|
|
4
|
+
'user/login',
|
|
5
|
+
async ({ data }, { rejectWithValue, getState }) => {
|
|
6
|
+
try {
|
|
7
|
+
return data
|
|
8
|
+
} catch (error: any) {
|
|
9
|
+
// return custom error message from API if any
|
|
10
|
+
if (error.response && error.response.data.message) {
|
|
11
|
+
return rejectWithValue(error.response.data.message)
|
|
12
|
+
} else {
|
|
13
|
+
return rejectWithValue(error.message)
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
)
|
|
18
|
+
|
|
19
|
+
export const userLogout = createAsyncThunk(
|
|
20
|
+
'user/logout',
|
|
21
|
+
async () => {
|
|
22
|
+
try {
|
|
23
|
+
return true;
|
|
24
|
+
} catch (error: any) {
|
|
25
|
+
return true;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
)
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import {createSlice, PayloadAction} from '@reduxjs/toolkit'
|
|
2
|
+
import {userLogin, userLogout} from "./userActions";
|
|
3
|
+
import {LocalStorageConstants} from "../constants/local-storage";
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
interface UserState {
|
|
7
|
+
loading: boolean;
|
|
8
|
+
userInfo: any;
|
|
9
|
+
accessToken: string | null;
|
|
10
|
+
error: boolean;
|
|
11
|
+
success: boolean;
|
|
12
|
+
loggedIn: boolean;
|
|
13
|
+
userPermissions: any[];
|
|
14
|
+
roles: string[];
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const initialState: UserState = {
|
|
18
|
+
loading: false,
|
|
19
|
+
userInfo: JSON.parse(localStorage.getItem(LocalStorageConstants.userData) ?? '{}'), // for user object
|
|
20
|
+
accessToken: localStorage.getItem(LocalStorageConstants.accessToken ?? ''), // for storing the JWT
|
|
21
|
+
error: false,
|
|
22
|
+
success: false,
|
|
23
|
+
loggedIn: false,
|
|
24
|
+
userPermissions: [],
|
|
25
|
+
roles: []
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const userSlice = createSlice({
|
|
29
|
+
name: 'user',
|
|
30
|
+
initialState,
|
|
31
|
+
reducers: {
|
|
32
|
+
autoLoginSucceded: (state, action) => {
|
|
33
|
+
state.loading = false;
|
|
34
|
+
state.userInfo = JSON.parse(action.payload);
|
|
35
|
+
state.loggedIn = true;
|
|
36
|
+
state.error = false;
|
|
37
|
+
state.success = true;
|
|
38
|
+
state.roles = [JSON.parse(action.payload)["http://schemas.microsoft.com/ws/2008/06/identity/claims/role"]];
|
|
39
|
+
},
|
|
40
|
+
setUserPermissions(state, action: PayloadAction<any[]>) {
|
|
41
|
+
state.userPermissions = action.payload;
|
|
42
|
+
},
|
|
43
|
+
},
|
|
44
|
+
extraReducers: (builder) => {
|
|
45
|
+
builder.addCase(userLogin.pending, (state, action) => {
|
|
46
|
+
state.loggedIn = false;
|
|
47
|
+
state.loading = true
|
|
48
|
+
state.error = false
|
|
49
|
+
})
|
|
50
|
+
|
|
51
|
+
builder.addCase(userLogin.fulfilled, (state, action) => {
|
|
52
|
+
state.loading = false
|
|
53
|
+
state.loggedIn = true;
|
|
54
|
+
state.userInfo = action.payload.userData
|
|
55
|
+
state.accessToken = action.payload.token
|
|
56
|
+
state.roles = action.payload.role
|
|
57
|
+
})
|
|
58
|
+
|
|
59
|
+
builder.addCase(userLogin.rejected, (state, action) => {
|
|
60
|
+
state.loading = false
|
|
61
|
+
state.loggedIn = false;
|
|
62
|
+
state.error = true;//(action.payload as any).error as any
|
|
63
|
+
state.roles = []
|
|
64
|
+
})
|
|
65
|
+
|
|
66
|
+
builder.addCase(userLogout.fulfilled, (state, action) => {
|
|
67
|
+
state.loading = false
|
|
68
|
+
state.loggedIn = false;
|
|
69
|
+
state.error = false;
|
|
70
|
+
state.userInfo = JSON.parse('{}');
|
|
71
|
+
state.accessToken = '';
|
|
72
|
+
state.roles = []
|
|
73
|
+
})
|
|
74
|
+
},
|
|
75
|
+
})
|
|
76
|
+
|
|
77
|
+
export const {
|
|
78
|
+
autoLoginSucceded,
|
|
79
|
+
setUserPermissions
|
|
80
|
+
} = userSlice.actions;
|
|
81
|
+
|
|
82
|
+
export default userSlice.reducer
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extends": "../../../tsconfig.base.json",
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
"jsx": "react-jsx",
|
|
5
|
+
"allowJs": true,
|
|
6
|
+
"esModuleInterop": true,
|
|
7
|
+
"allowSyntheticDefaultImports": true,
|
|
8
|
+
"forceConsistentCasingInFileNames": true,
|
|
9
|
+
"strict": true,
|
|
10
|
+
"noImplicitOverride": true,
|
|
11
|
+
"noPropertyAccessFromIndexSignature": true,
|
|
12
|
+
"noImplicitReturns": true,
|
|
13
|
+
"noFallthroughCasesInSwitch": true
|
|
14
|
+
},
|
|
15
|
+
"files": [],
|
|
16
|
+
"include": [],
|
|
17
|
+
"references": [
|
|
18
|
+
{
|
|
19
|
+
"path": "./tsconfig.lib.json"
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
"path": "./tsconfig.spec.json"
|
|
23
|
+
}
|
|
24
|
+
]
|
|
25
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extends": "./tsconfig.json",
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
"outDir": "../../../dist/out-tsc",
|
|
5
|
+
"types": ["node"]
|
|
6
|
+
},
|
|
7
|
+
"files": [
|
|
8
|
+
"../../../node_modules/@nx/react/typings/cssmodule.d.ts",
|
|
9
|
+
"../../../node_modules/@nx/react/typings/image.d.ts"
|
|
10
|
+
],
|
|
11
|
+
"exclude": [
|
|
12
|
+
"jest.config.ts",
|
|
13
|
+
"**/*.spec.ts",
|
|
14
|
+
"**/*.test.ts",
|
|
15
|
+
"**/*.spec.tsx",
|
|
16
|
+
"**/*.test.tsx",
|
|
17
|
+
"**/*.spec.js",
|
|
18
|
+
"**/*.test.js",
|
|
19
|
+
"**/*.spec.jsx",
|
|
20
|
+
"**/*.test.jsx"
|
|
21
|
+
],
|
|
22
|
+
"include": ["**/*.js", "**/*.jsx", "**/*.ts", "**/*.tsx"]
|
|
23
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extends": "./tsconfig.json",
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
"outDir": "../../../dist/out-tsc",
|
|
5
|
+
"module": "commonjs",
|
|
6
|
+
"types": ["jest", "node"]
|
|
7
|
+
},
|
|
8
|
+
"include": [
|
|
9
|
+
"jest.config.ts",
|
|
10
|
+
"**/*.test.ts",
|
|
11
|
+
"**/*.spec.ts",
|
|
12
|
+
"**/*.test.tsx",
|
|
13
|
+
"**/*.spec.tsx",
|
|
14
|
+
"**/*.test.js",
|
|
15
|
+
"**/*.spec.js",
|
|
16
|
+
"**/*.test.jsx",
|
|
17
|
+
"**/*.spec.jsx",
|
|
18
|
+
"**/*.d.ts"
|
|
19
|
+
]
|
|
20
|
+
}
|
package/index.esm.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "./src/index";
|