create-chayns-app 1.2.0-beta.0 → 1.2.0-beta.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 (25) hide show
  1. package/dist/index.cjs +55 -51
  2. package/package.json +2 -2
  3. package/templates/api-v5/internal/js/src/redux-modules/index.js +17 -0
  4. package/templates/api-v5/internal/js/src/redux-modules/loggerMiddleware.js +31 -0
  5. package/templates/api-v5/internal/js/src/utils/logger.js +31 -0
  6. package/templates/api-v5/internal/ts/src/redux-modules/index.ts +20 -0
  7. package/templates/api-v5/internal/ts/src/redux-modules/loggerMiddleware.ts +45 -0
  8. package/templates/api-v5/internal/ts/src/utils/logger.ts +31 -0
  9. package/templates/api-v5/page/src/index.jsx +1 -1
  10. package/templates/api-v5/page-module-redux/src/components/App.jsx +2 -2
  11. package/templates/api-v5/page-redux/src/index.jsx +1 -1
  12. package/templates/api-v5/page-ts/src/index.tsx +1 -1
  13. package/templates/api-v5/page-ts-module/src/components/AppWrapper.tsx +2 -2
  14. package/templates/api-v5/page-ts-module-redux/src/components/App.tsx +2 -2
  15. package/templates/api-v5/page-ts-module-redux/src/components/AppWrapper.tsx +2 -2
  16. package/templates/api-v5/page-ts-redux/src/index.tsx +1 -1
  17. package/templates/api-v5/shared/js/src/redux-modules/counter/slice.js +5 -0
  18. package/templates/api-v5/shared/js/src/redux-modules/index.js +6 -2
  19. package/templates/api-v5/shared/ts/src/hooks/redux.ts +5 -0
  20. package/templates/api-v5/shared/ts/src/redux-modules/counter/slice.ts +5 -0
  21. package/templates/api-v5/shared/ts/src/redux-modules/index.ts +7 -3
  22. package/templates/api-v5/shared/js/src/redux-modules/counter/selectors.js +0 -5
  23. package/templates/api-v5/shared/ts/src/redux-modules/counter/selectors.ts +0 -6
  24. /package/templates/api-v5/shared/js/src/constants/{server-urls.js → serverUrls.js} +0 -0
  25. /package/templates/api-v5/shared/ts/src/constants/{server-urls.ts → serverUrls.ts} +0 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-chayns-app",
3
- "version": "1.2.0-beta.0",
3
+ "version": "1.2.0-beta.2",
4
4
  "private": false,
5
5
  "description": "Create a new chayns® development project in one command.",
6
6
  "keywords": [
@@ -16,7 +16,7 @@
16
16
  },
17
17
  "repository": {
18
18
  "type": "git",
19
- "url": "https://github.com/TobitSoftware/create-chayns-app.git"
19
+ "url": "git+https://github.com/TobitSoftware/create-chayns-app.git"
20
20
  },
21
21
  "license": "MIT",
22
22
  "author": {
@@ -0,0 +1,17 @@
1
+ import { configureStore, combineReducers } from '@reduxjs/toolkit';
2
+ import { counterReducer } from './counter/slice';
3
+ import { loggerMiddleware } from './loggerMiddleware';
4
+
5
+ const rootReducer = combineReducers({
6
+ counter: counterReducer,
7
+ });
8
+
9
+ export const createStore = (preloadedState) => configureStore({
10
+ reducer: rootReducer,
11
+ middleware: (getDefaultMiddleware) => getDefaultMiddleware().concat(loggerMiddleware),
12
+ preloadedState,
13
+ });
14
+
15
+ const store = createStore();
16
+
17
+ export default store;
@@ -0,0 +1,31 @@
1
+ import logger from "../utils/logger";
2
+
3
+ export const loggerMiddleware = () => (next) => (action) => {
4
+ try {
5
+ const metaAction = action;
6
+ if (metaAction.meta.requestStatus === 'rejected') {
7
+ if (metaAction.meta.aborted || metaAction.meta.condition) {
8
+ return next(action);
9
+ }
10
+ if (process.env.NODE_ENV === 'development') {
11
+ // eslint-disable-next-line no-console
12
+ console.log('redux action error', action);
13
+ }
14
+ logger.error({
15
+ message: 'redux action error',
16
+ customText: metaAction.type,
17
+ data: { arg: metaAction.meta.arg },
18
+ section: 'redux-modules/loggerMiddleware',
19
+ }, metaAction.error);
20
+ }
21
+ return next(action);
22
+ } catch (ex) {
23
+ logger.error({
24
+ message: 'error in store',
25
+ data: {
26
+ action,
27
+ }
28
+ }, ex);
29
+ }
30
+ return undefined;
31
+ };
@@ -0,0 +1,31 @@
1
+ import { getCurrentPage, getSite, getUser } from 'chayns-api';
2
+ import { ChaynsLogger } from 'chayns-logger';
3
+
4
+ const logger = new ChaynsLogger({
5
+ // TODO: create and insert your applicationUid
6
+ applicationUid: '<applicationUid>',
7
+ overrideOnError: true,
8
+ overrideConsoleError: process.env.NODE_ENV !== 'development',
9
+ useDevServer: process.env.NODE_ENV === 'development' || ['qa', 'development'].includes(process.env.BUILD_ENV),
10
+ version: process.env.BUILD_VERSION,
11
+ throttleTime: 1000,
12
+ middleware: (payload) => {
13
+ try {
14
+ const currentPage = getCurrentPage();
15
+ // eslint-disable-next-line no-param-reassign
16
+ payload.siteId ??= currentPage.siteId;
17
+ // eslint-disable-next-line no-param-reassign
18
+ payload.customNumber ??= currentPage.id;
19
+ // eslint-disable-next-line no-param-reassign
20
+ payload.personId ??= getUser()?.personId;
21
+ // eslint-disable-next-line no-param-reassign
22
+ payload.locationId ??= getSite().locationId;
23
+ } catch {
24
+ //
25
+ }
26
+
27
+ return true;
28
+ },
29
+ });
30
+
31
+ export default logger;
@@ -0,0 +1,20 @@
1
+ import { configureStore, combineReducers } from '@reduxjs/toolkit';
2
+ import { counterReducer } from './counter/slice';
3
+ import { loggerMiddleware } from './loggerMiddleware';
4
+
5
+ const rootReducer = combineReducers({
6
+ counter: counterReducer,
7
+ });
8
+
9
+ export const createStore = (preloadedState?: RootState) => configureStore({
10
+ reducer: rootReducer,
11
+ middleware: (getDefaultMiddleware) => getDefaultMiddleware().concat(loggerMiddleware),
12
+ preloadedState,
13
+ });
14
+
15
+ const store = createStore();
16
+
17
+ export type RootState = ReturnType<typeof rootReducer>;
18
+ export type AppDispatch = ReturnType<typeof createStore>["dispatch"];
19
+
20
+ export default store;
@@ -0,0 +1,45 @@
1
+ import { Middleware } from "@reduxjs/toolkit";
2
+ import logger from "../utils/logger";
3
+
4
+ type MetaAction = {
5
+ type: string;
6
+ payload: unknown;
7
+ meta: {
8
+ arg: unknown;
9
+ requestId: string;
10
+ requestStatus: 'pending' | 'rejected' | 'fulfilled';
11
+ aborted?: boolean;
12
+ condition?: boolean;
13
+ },
14
+ error?: Error;
15
+ }
16
+
17
+ export const loggerMiddleware: Middleware = () => (next) => (action) => {
18
+ try {
19
+ const metaAction = action as MetaAction;
20
+ if (metaAction.meta.requestStatus === 'rejected') {
21
+ if (metaAction.meta.aborted || metaAction.meta.condition) {
22
+ return next(action);
23
+ }
24
+ if (process.env.NODE_ENV === 'development') {
25
+ // eslint-disable-next-line no-console
26
+ console.log('redux action error', action);
27
+ }
28
+ logger.error({
29
+ message: 'redux action error',
30
+ customText: metaAction.type,
31
+ data: { arg: metaAction.meta.arg },
32
+ section: 'redux-modules/loggerMiddleware',
33
+ }, metaAction.error);
34
+ }
35
+ return next(action);
36
+ } catch (ex) {
37
+ logger.error({
38
+ message: 'error in store',
39
+ data: {
40
+ action,
41
+ }
42
+ }, ex as Error);
43
+ }
44
+ return undefined;
45
+ };
@@ -0,0 +1,31 @@
1
+ import { getCurrentPage, getSite, getUser } from 'chayns-api';
2
+ import { ChaynsLogger } from 'chayns-logger';
3
+
4
+ const logger = new ChaynsLogger({
5
+ // TODO: create and insert your applicationUid
6
+ applicationUid: '<applicationUid>',
7
+ overrideOnError: true,
8
+ overrideConsoleError: process.env.NODE_ENV !== 'development',
9
+ useDevServer: process.env.NODE_ENV === 'development' || ['qa', 'development'].includes(process.env.BUILD_ENV),
10
+ version: process.env.BUILD_VERSION,
11
+ throttleTime: 1000,
12
+ middleware: (payload) => {
13
+ try {
14
+ const currentPage = getCurrentPage();
15
+ // eslint-disable-next-line no-param-reassign
16
+ payload.siteId ??= currentPage.siteId;
17
+ // eslint-disable-next-line no-param-reassign
18
+ payload.customNumber ??= currentPage.id;
19
+ // eslint-disable-next-line no-param-reassign
20
+ payload.personId ??= getUser()?.personId;
21
+ // eslint-disable-next-line no-param-reassign
22
+ payload.locationId ??= getSite().locationId;
23
+ } catch {
24
+ //
25
+ }
26
+
27
+ return true;
28
+ },
29
+ });
30
+
31
+ export default logger;
@@ -1,7 +1,7 @@
1
1
  import React from 'react';
2
2
  import { createRoot } from 'react-dom/client';
3
3
  import AppWrapper from './components/AppWrapper';
4
-
4
+ {{ logger-import }}
5
5
  try {
6
6
  const root = createRoot(document.querySelector('#root'));
7
7
  root.render(<AppWrapper />);
@@ -2,11 +2,11 @@ import React, { useState } from 'react';
2
2
  import { WaitUntil } from 'chayns-api';
3
3
  import { SmallWaitCursor } from '@chayns-components/core';
4
4
  import { useSelector } from 'react-redux';
5
- import { selectCount } from '../redux-modules/counter/counterSelectors';
5
+ import { selectCounterValue } from '../redux-modules/counter/slice';
6
6
  import './app.scss';
7
7
 
8
8
  const App = () => {
9
- const counter = useSelector(selectCount);
9
+ const counter = useSelector(selectCounterValue);
10
10
 
11
11
  const [taskList] = useState(() => [
12
12
  // first level tasks are executed one after the other
@@ -1,7 +1,7 @@
1
1
  import React from 'react';
2
2
  import { createRoot } from 'react-dom/client';
3
3
  import AppWrapper from './components/AppWrapper';
4
-
4
+ {{ logger-import }}
5
5
  try {
6
6
  const root = createRoot(document.querySelector('#root'));
7
7
  root.render(<AppWrapper />);
@@ -1,7 +1,7 @@
1
1
  import React from 'react';
2
2
  import { createRoot } from 'react-dom/client';
3
3
  import AppWrapper from './components/AppWrapper';
4
-
4
+ {{ logger-import }}
5
5
  try {
6
6
  const root = createRoot(document.querySelector('#root') as Element);
7
7
  root.render(<AppWrapper />);
@@ -1,9 +1,9 @@
1
- import React, { FC, ComponentProps } from 'react';
1
+ import React, { ComponentPropsWithoutRef } from 'react';
2
2
  import { ChaynsProvider, withCompatMode } from 'chayns-api';
3
3
  import { PageProvider } from '@chayns-components/core';
4
4
  import App from './App';
5
5
 
6
- const AppWrapper: FC<ComponentProps<typeof ChaynsProvider>> = (props) => (
6
+ const AppWrapper = (props: ComponentPropsWithoutRef<typeof ChaynsProvider>) => (
7
7
  <div className="{{ package-name-underscore }}">
8
8
  {/* eslint-disable-next-line react/jsx-props-no-spreading */}
9
9
  <ChaynsProvider {...props}>
@@ -2,11 +2,11 @@ import React, { useState } from 'react';
2
2
  import { WaitUntil } from 'chayns-api';
3
3
  import { SmallWaitCursor } from '@chayns-components/core';
4
4
  import { useSelector } from 'react-redux';
5
- import { selectCount } from '../redux-modules/counter/counterSelectors';
5
+ import { selectCounterValue } from '../redux-modules/counter/slice';
6
6
  import './app.scss';
7
7
 
8
8
  const App = () => {
9
- const counter = useSelector(selectCount);
9
+ const counter = useSelector(selectCounterValue);
10
10
 
11
11
  const [taskList] = useState(() => [
12
12
  // first level tasks are executed one after the other
@@ -1,11 +1,11 @@
1
- import React, { FC, ComponentProps } from 'react';
1
+ import React, { ComponentPropsWithoutRef } from 'react';
2
2
  import { Provider } from 'react-redux';
3
3
  import { ChaynsProvider, withCompatMode } from 'chayns-api';
4
4
  import { PageProvider } from '@chayns-components/core';
5
5
  import App from './App';
6
6
  import store from '../redux-modules';
7
7
 
8
- const AppWrapper: FC<ComponentProps<typeof ChaynsProvider>> = (props) => (
8
+ const AppWrapper = (props: ComponentPropsWithoutRef<typeof ChaynsProvider>) => (
9
9
  <div className="{{ package-name-underscore }}">
10
10
  {/* eslint-disable-next-line react/jsx-props-no-spreading */}
11
11
  <ChaynsProvider {...props}>
@@ -1,7 +1,7 @@
1
1
  import React from 'react';
2
2
  import { createRoot } from 'react-dom/client';
3
3
  import AppWrapper from './components/AppWrapper';
4
-
4
+ {{ logger-import }}
5
5
  try {
6
6
  const root = createRoot(document.querySelector('#root') as Element);
7
7
  root.render(<AppWrapper />);
@@ -16,8 +16,13 @@ const slice = createSlice({
16
16
  state.value += payload;
17
17
  },
18
18
  },
19
+ selectors: {
20
+ selectCounterState: (state) => state,
21
+ selectCounterValue: (state) => state.value,
22
+ },
19
23
  });
20
24
 
21
25
  export const { increment, decrement, incrementByAmount } = slice.actions;
26
+ export const { selectCounterState, selectCounterValue } = slice.selectors;
22
27
  export const counterReducer = slice.reducer;
23
28
  export const counterSliceName = slice.name;
@@ -5,7 +5,11 @@ const rootReducer = combineReducers({
5
5
  counter: counterReducer,
6
6
  });
7
7
 
8
- const Store = configureStore({
8
+ export const createStore = (preloadedState) => configureStore({
9
9
  reducer: rootReducer,
10
+ preloadedState,
10
11
  });
11
- export default Store;
12
+
13
+ const store = createStore();
14
+
15
+ export default store;
@@ -0,0 +1,5 @@
1
+ import { useDispatch, useSelector } from 'react-redux';
2
+ import type { RootState, AppDispatch } from '../redux-modules';
3
+
4
+ export const useAppDispatch = useDispatch.withTypes<AppDispatch>();
5
+ export const useAppSelector = useSelector.withTypes<RootState>();
@@ -16,8 +16,13 @@ const counterSlice = createSlice({
16
16
  state.value += payload;
17
17
  },
18
18
  },
19
+ selectors: {
20
+ selectCounterState: (state) => state,
21
+ selectCounterValue: (state) => state.value,
22
+ },
19
23
  });
20
24
 
21
25
  export const { increment, decrement, incrementByAmount } = counterSlice.actions;
26
+ export const { selectCounterState, selectCounterValue } = counterSlice.selectors;
22
27
  export const counterReducer = counterSlice.reducer;
23
28
  export const counterSliceName = counterSlice.name;
@@ -5,10 +5,14 @@ const rootReducer = combineReducers({
5
5
  counter: counterReducer,
6
6
  });
7
7
 
8
- const Store = configureStore({
8
+ export const createStore = (preloadedState?: RootState) => configureStore({
9
9
  reducer: rootReducer,
10
+ preloadedState,
10
11
  });
11
12
 
13
+ const store = createStore();
14
+
12
15
  export type RootState = ReturnType<typeof rootReducer>;
13
- export type AppDispatch = typeof Store.dispatch;
14
- export default Store;
16
+ export type AppDispatch = ReturnType<typeof createStore>["dispatch"];
17
+
18
+ export default store;
@@ -1,5 +0,0 @@
1
- import { counterSliceName } from './slice';
2
-
3
- export const selectCounterState = (state) => state[counterSliceName];
4
-
5
- export const selectCounterValue = (state) => selectCounterState(state).value;
@@ -1,6 +0,0 @@
1
- import { counterSliceName } from './slice';
2
- import { RootState } from '../index';
3
-
4
- export const selectCounterState = (state: RootState) => state[counterSliceName];
5
-
6
- export const selectCounterValue = (state: RootState) => selectCounterState(state).value;