@common-stack/frontend-stack-react 4.0.1-alpha.11

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 (56) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +50 -0
  3. package/lib/backend/env.d.ts +1 -0
  4. package/lib/backend/middlewares/cache.d.ts +2 -0
  5. package/lib/backend/middlewares/container.d.ts +4 -0
  6. package/lib/backend/middlewares/container.js +72 -0
  7. package/lib/backend/middlewares/container.js.map +1 -0
  8. package/lib/backend/middlewares/cors.d.ts +6 -0
  9. package/lib/backend/middlewares/cors.js +20 -0
  10. package/lib/backend/middlewares/cors.js.map +1 -0
  11. package/lib/backend/middlewares/error.d.ts +2 -0
  12. package/lib/backend/middlewares/error.js +40 -0
  13. package/lib/backend/middlewares/error.js.map +1 -0
  14. package/lib/backend/modules/index.d.ts +2 -0
  15. package/lib/backend/modules/modules.d.ts +3 -0
  16. package/lib/backend/request.d.ts +2 -0
  17. package/lib/config/base-apollo-cache.d.ts +16 -0
  18. package/lib/config/base-apollo-cache.js +35 -0
  19. package/lib/config/base-apollo-cache.js.map +1 -0
  20. package/lib/config/base-apollo-client.d.ts +19 -0
  21. package/lib/config/base-apollo-client.js +109 -0
  22. package/lib/config/base-apollo-client.js.map +1 -0
  23. package/lib/config/base-redux-config.d.ts +23 -0
  24. package/lib/config/base-redux-config.js +41 -0
  25. package/lib/config/base-redux-config.js.map +1 -0
  26. package/lib/config/browser-env-config.d.ts +7 -0
  27. package/lib/config/browser-env-config.js +8 -0
  28. package/lib/config/browser-env-config.js.map +1 -0
  29. package/lib/config/client.service.d.ts +9 -0
  30. package/lib/config/client.service.js +72 -0
  31. package/lib/config/client.service.js.map +1 -0
  32. package/lib/config/env-config.d.ts +19 -0
  33. package/lib/config/env-config.js +21 -0
  34. package/lib/config/env-config.js.map +1 -0
  35. package/lib/config/epic-config.d.ts +3 -0
  36. package/lib/config/epic-config.js +6 -0
  37. package/lib/config/epic-config.js.map +1 -0
  38. package/lib/config/i18n.d.ts +2 -0
  39. package/lib/config/index.d.ts +3 -0
  40. package/lib/config/public-config.d.ts +3 -0
  41. package/lib/config/redis-config.server.d.ts +1 -0
  42. package/lib/config/redis-config.server.js +8 -0
  43. package/lib/config/redis-config.server.js.map +1 -0
  44. package/lib/config/redux-config.d.ts +29 -0
  45. package/lib/config/redux-config.js +73 -0
  46. package/lib/config/redux-config.js.map +1 -0
  47. package/lib/index.d.ts +6 -0
  48. package/lib/index.js +1 -0
  49. package/lib/index.js.map +1 -0
  50. package/lib/load-context.server.d.ts +10 -0
  51. package/lib/load-context.server.js +15 -0
  52. package/lib/load-context.server.js.map +1 -0
  53. package/lib/utils/index.d.ts +10 -0
  54. package/lib/utils/index.js +29 -0
  55. package/lib/utils/index.js.map +1 -0
  56. package/package.json +54 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License
2
+
3
+ Copyright (c) 2017 CDMBase LLC.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,50 @@
1
+ # React Package
2
+ React components and containers
3
+
4
+ What does it include:
5
+ ---
6
+ 1. exported react pure components
7
+ 2. exported react containers
8
+ 3. Typescript 2.0.0 => ES6
9
+ 4. unit testing with jest
10
+
11
+ Purpose:
12
+ ---
13
+ This package can be installable in front-end webserver
14
+
15
+ Useful commands:
16
+ ---
17
+ npm run build - build the library files
18
+ npm run test - run tests once
19
+ npm run test:watch - run tests in watchmode (Useful for development)
20
+
21
+ Files explained:
22
+ ---
23
+ src - directory is used for typescript code that is part of the project
24
+ index.ts - Index file of the package. Consists of exported components and containers
25
+ index.spec.ts - Tests file for main
26
+ components - All pure components which don't depend on backend data or external state such as redux
27
+ index.ts - References all the exported components
28
+ containers - Components with data to render. Tightly coupled with redux.
29
+ index.ts - References all the exported containers
30
+ package.json - file is used to describe the library and packages that are required added under peer-dependencies section
31
+ tsconfig.json - configuration file for the library compilation
32
+ webpack.config.js - configuration file of the compilation automation process for the library
33
+
34
+
35
+ Tutorials:
36
+ ---
37
+ [react-jest-enzymes test](https://www.youtube.com/watch?v=bMmntkVM4wQ)
38
+
39
+ [testing react with enzyme tutorial](http://codeheaven.io/testing-react-components-with-enzyme/)
40
+
41
+ [react-redux-typescript-guide](https://github.com/piotrwitek/react-redux-typescript-guide)
42
+
43
+ Performance:
44
+ ---
45
+ [Redux FAQ: Connecting multiple components](http://redux.js.org/docs/FAQ.html#react-multiple-components)
46
+
47
+ [React/Redux Links: Performance articles](https://github.com/markerikson/react-redux-links/blob/master/react-performance.md)
48
+
49
+ [React/Redux: Component re-rendering too often?](http://redux.js.org/docs/faq/ReactRedux.html#react-rendering-too-often)
50
+
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,2 @@
1
+ export declare const cacheMiddleware: (req: any, res: any, next: any) => void;
2
+ export declare const cacheMiddlewareSync: (req: any, res: any, next: any) => Promise<any>;
@@ -0,0 +1,4 @@
1
+ export declare const TYPES: {
2
+ HttpRequest: symbol;
3
+ };
4
+ export declare const containerMiddleware: (req: any, res: any, next: any) => Promise<void>;
@@ -0,0 +1,72 @@
1
+ import {v4}from'uuid';import {ClientTypes}from'@common-stack/core';import {merge}from'lodash-es';import {ScopedContainer}from'@common-stack/client-core/lib/connector/ScopedContainer.js';import {createReduxStore}from'../../config/redux-config.js';import {logger}from'@cdm-logger/server';import {UtilityClass}from'../../utils/index.js';import modules from'virtual-modules';import {createApolloClient}from'../../config/base-apollo-client.js';import {config}from'../../config/env-config.js';const TYPES = {
2
+ HttpRequest: Symbol.for('HttpRequest'),
3
+ };
4
+ const utility = new UtilityClass(modules);
5
+ ScopedContainer.registerGlobalDependencies((container) => {
6
+ container.bind(ClientTypes.Logger).toConstantValue(logger);
7
+ container.bind(ClientTypes.UtilityClass).toConstantValue(utility);
8
+ });
9
+ const containerMiddleware = async (req, res, next) => {
10
+ const requestId = v4(); // Generate a unique identifier for the request
11
+ if (config.LOG_LEVEL === 'debug' || config.LOG_LEVEL === 'trace') {
12
+ console.time(`Request ${requestId} Duration`); // Start timing the request
13
+ }
14
+ logger.debug(`Express req started - ID: ${requestId} , URL: ${req.url}`); // Log when request starts with unique ID
15
+ const container = modules.createContainers({}, requestId);
16
+ const clientState = modules.getStateParams({
17
+ // resolverContex: () => services,
18
+ scopeId: requestId,
19
+ requestResponsePair: {
20
+ req,
21
+ res,
22
+ },
23
+ });
24
+ const { apolloClient } = createApolloClient({
25
+ httpGraphqlURL: config.GRAPHQL_URL,
26
+ httpLocalGraphqlURL: config.LOCAL_GRAPHQL_URL,
27
+ isDev: process.env.NODE_ENV === 'development',
28
+ isDebug: __DEBUGGING__,
29
+ isSSR: __SSR__,
30
+ scope: typeof window !== 'undefined' ? 'browser' : 'server',
31
+ clientState,
32
+ getDataIdFromObject: (result) => modules.getDataIdFromObject(result),
33
+ initialState: typeof window !== 'undefined' ? window?.__APOLLO_STATE__ : undefined,
34
+ logger,
35
+ });
36
+ container.bind(TYPES.HttpRequest).toConstantValue(req);
37
+ let count = 1;
38
+ container
39
+ .bind(ClientTypes.ApolloClientFactory)
40
+ .toDynamicValue((context) => () => {
41
+ count = count + 1;
42
+ console.log('---COUNT__________', count);
43
+ return apolloClient;
44
+ })
45
+ .inRequestScope();
46
+ const services = merge({}, ...modules.createServiceFunc.map((serviceFunc) => serviceFunc(container)));
47
+ const resolvers = modules.getApolloResolvers(() => services);
48
+ apolloClient.setResolvers(resolvers);
49
+ const { store } = createReduxStore(apolloClient, services, container);
50
+ req.container = container;
51
+ req.apolloClient = container.get(ClientTypes.ApolloClientFactory)();
52
+ req.logger = logger;
53
+ req.store = store;
54
+ req.services = services;
55
+ res.on('finish', () => {
56
+ logger.debug(`Express req Finished! - ID: ${requestId}`); // Log when request finishes with unique ID
57
+ if (config.LOG_LEVEL === 'debug' || config.LOG_LEVEL === 'trace') {
58
+ console.timeEnd(`Request ${requestId} Duration`); // End timing and log the duration
59
+ }
60
+ try {
61
+ // req.services.organizationContextService.dispose();
62
+ // req.services.configurationService.dispose();
63
+ ScopedContainer.remove(requestId);
64
+ req.apollClient = null;
65
+ req.services = null;
66
+ }
67
+ catch (error) {
68
+ console.error(`Error during container cleanup - ID: ${requestId}`, error);
69
+ }
70
+ });
71
+ next();
72
+ };export{TYPES,containerMiddleware};//# sourceMappingURL=container.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"container.js","sources":["../../../src/backend/middlewares/container.ts"],"sourcesContent":[null],"names":["uuidv4"],"mappings":"ueAea,MAAA,KAAK,GAAG;AACjB,IAAA,WAAW,EAAE,MAAM,CAAC,GAAG,CAAC,aAAa,CAAC;EACxC;AAEF,MAAM,OAAO,GAAG,IAAI,YAAY,CAAC,OAAO,CAAC,CAAC;AAE1C,eAAe,CAAC,0BAA0B,CAAC,CAAC,SAAS,KAAI;AACrD,IAAA,SAAS,CAAC,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC,eAAe,CAAC,MAAM,CAAC,CAAC;AAC3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A,GAAG,CAAC,EAAE,CAAC,QAAQ,EAAE,MAAK;QAClB,MAAM,CAAC,KAAK,CAAC,CAAA,4BAAA,EAA+B,SAAS,CAAE,CAAA,CAAC,CAAC;AACzD,QAAA,IAAI,MAAM,CAAC,SAAS,KAAK,OAAO,IAAI,MAAM,CAAC,SAAS,KAAK,OAAO,EAAE;YAC9D,OAAO,CAAC,OAAO,CAAC,CAAA,QAAA,EAAW,SAAS,CAAW,SAAA,CAAA,CAAC,CAAC;SACpD;AAED,QAAA,IAAI;;;AAGA,YAAA,eAAe,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;AAClC,YAAA,GAAG,CAAC,WAAW,GAAG,IAAI,CAAC;AACvB,YAAA,GAAG,CAAC,QAAQ,GAAG,IAAI,CAAC;SACvB;QAAC,OAAO,KAAK,EAAE;YACZ,OAAO,CAAC,KAAK,CAAC,CAAA,qCAAA,EAAwC,SAAS,CAAE,CAAA,EAAE,KAAK,CAAC,CAAC;SAC7E;AACL,KAAC,CAAC,CAAC;AAEH,IAAA,IAAI,EAAE,CAAC;AACX"}
@@ -0,0 +1,6 @@
1
+ import cors from 'cors';
2
+ export declare const corsMiddleware: (req: cors.CorsRequest, res: {
3
+ statusCode?: number;
4
+ setHeader(key: string, value: string): any;
5
+ end(): any;
6
+ }, next: (err?: any) => any) => void;
@@ -0,0 +1,20 @@
1
+ import cors from'cors';import {logger}from'@cdm-logger/server';import {config}from'../../config/env-config.js';import'../../config/client.service.js';import'../../config/redux-config.js';/* eslint-disable jest/require-hook */
2
+ const { CLIENT_URL, BACKEND_URL, LOCAL_GRAPHQL_URL } = config;
3
+ const corsWhitelist = [CLIENT_URL, BACKEND_URL, LOCAL_GRAPHQL_URL];
4
+ logger.info('corsWhitelist (%j)', corsWhitelist);
5
+ const corsOptions = {
6
+ origin: (origin, callback) => {
7
+ if (origin && corsWhitelist.indexOf(origin) !== -1) {
8
+ callback(null, true);
9
+ }
10
+ else {
11
+ // TODO: only throw when in debug mode
12
+ logger.error('url (%s) is not in the whitelist', origin);
13
+ // callback(new Error('Not allowed by CORS'))
14
+ logger.warn('allowing all origins temporarily, you need to disable it.');
15
+ callback(null, true);
16
+ }
17
+ },
18
+ credentials: true,
19
+ };
20
+ const corsMiddleware = cors(corsOptions);export{corsMiddleware};//# sourceMappingURL=cors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cors.js","sources":["../../../src/backend/middlewares/cors.ts"],"sourcesContent":[null],"names":[],"mappings":"2LAAA;AAKA,MAAM,EAAE,UAAU,EAAE,WAAW,EAAE,iBAAiB,EAAE,GAAG,MAAM,CAAC;AAE9D,MAAM,aAAa,GAAG,CAAC,UAAU,EAAE,WAAW,EAAE,iBAAiB,CAAC,CAAC;AACnE,MAAM,CAAC,IAAI,CAAC,oBAAoB,EAAE,aAAa,CAAC,CAAC;AAEjD,MAAM,WAAW,GAAqB;AAClC,IAAA,MAAM,EAAE,CAAC,MAAM,EAAE,QAAQ,KAAI;AACzB,QAAA,IAAI,MAAM,IAAI,aAAa,CAAC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE;AAChD,YAAA,QAAQ,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;SACxB;aAAM;;AAEH,YAAA,MAAM,CAAC,KAAK,CAAC,kCAAkC,EAAE,MAAM,CAAC,CAAC;;AAEzD,YAAA,MAAM,CAAC,IAAI,CAAC,2DAA2D,CAAC,CAAC;AACzE,YAAA,QAAQ,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;SACxB;KACJ;AACD,IAAA,WAAW,EAAE,IAAI;CACpB,CAAC;MAEW,cAAc,GAAG,IAAI,CAAC,WAAW"}
@@ -0,0 +1,2 @@
1
+ /// <reference path="../../../../../typings/index.d.ts" />
2
+ export declare const errorMiddleware: (e: any, req: any, res: any, next: any) => void;
@@ -0,0 +1,40 @@
1
+ import*as path from'path';import*as fs from'fs';import*as url from'url';import {logger}from'@cdm-logger/server';/// <reference path='../../../../../typings/index.d.ts' />
2
+ let assetMap;
3
+ const stripCircular = (from, seen) => {
4
+ const to = Array.isArray(from) ? [] : {};
5
+ seen = seen || [];
6
+ seen.push(from);
7
+ Object.getOwnPropertyNames(from).forEach(key => {
8
+ if (!from[key] || (typeof from[key] !== 'object' && !Array.isArray(from[key]))) {
9
+ to[key] = from[key];
10
+ }
11
+ else if (seen.indexOf(from[key]) < 0) {
12
+ to[key] = stripCircular(from[key], seen.slice(0));
13
+ }
14
+ else {
15
+ to[key] = '[Circular]';
16
+ }
17
+ });
18
+ return to;
19
+ };
20
+ const { pathname } = url.parse(__BACKEND_URL__);
21
+ const errorMiddleware = (e, req, res, next) => {
22
+ if (req.path === pathname) {
23
+ const stack = e.stack.toString().replace(/[\n]/g, '\\n');
24
+ res.status(200).send(`[{"data": {}, "errors":[{"message": "${stack}"}]}]`);
25
+ }
26
+ else {
27
+ logger.error(e);
28
+ if (__DEV__ || !assetMap) {
29
+ assetMap = JSON.parse(fs.readFileSync(path.join(__FRONTEND_BUILD_DIR__, 'assets.json')).toString());
30
+ }
31
+ const serverErrorScript = `<script charset="UTF-8">window.__SERVER_ERROR__=${JSON.stringify(stripCircular(e))};</script>`;
32
+ const vendorScript = assetMap['vendor.js']
33
+ ? `<script src="/${assetMap['vendor.js']}" charSet="utf-8"></script>`
34
+ : '';
35
+ res.status(200).send(`<html>${serverErrorScript}<body><div id="content"></div>
36
+ ${vendorScript}
37
+ <script src="/${assetMap['index.js']}" charSet="utf-8"></script>
38
+ </body></html>`);
39
+ }
40
+ };export{errorMiddleware};//# sourceMappingURL=error.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"error.js","sources":["../../../src/backend/middlewares/error.ts"],"sourcesContent":[null],"names":[],"mappings":"gHAAA;AAQA,IAAI,QAAQ,CAAC;AAEb,MAAM,aAAa,GAAG,CAAC,IAAI,EAAE,IAAU,KAAI;AACvC,IAAA,MAAM,EAAE,GAAG,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,E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AAA,CAAC,CAAC;KAC9E;SAAM;AACH,QAAA,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;AAEhB,QAAA,IAAI,OAAO,IAAI,CAAC,QAAQ,EAAE;YACtB,QAAQ,GAAG,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,YAAY,CAAC,IAAI,CAAC,IAAI,CAAC,sBAAsB,EAAE,aAAa,CAAC,CAAC,CAAC,QAAQ,EAAE,CAAC,CAAC;SACvG;AAED,QAAA,MAAM,iBAAiB,GAAG,CAAmD,gDAAA,EAAA,IAAI,CAAC,SAAS,CACvF,aAAa,CAAC,CAAC,CAAC,CACnB,YAAY,CAAC;AACd,QAAA,MAAM,YAAY,GAAG,QAAQ,CAAC,WAAW,CAAC;AACtC,cAAE,CAAiB,cAAA,EAAA,QAAQ,CAAC,WAAW,CAAC,CAA6B,2BAAA,CAAA;cACnE,EAAE,CAAC;QAET,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAChB,CAAA,MAAA,EAAS,iBAAiB,CAAA;UAChC,YAAY,CAAA;4BACM,QAAQ,CAAC,UAAU,CAAC,CAAA;AACrB,0BAAA,CAAA,CACd,CAAC;KACL;AACL"}
@@ -0,0 +1,2 @@
1
+ import modules from './modules';
2
+ export default modules;
@@ -0,0 +1,3 @@
1
+ import { Feature } from '@common-stack/server-core';
2
+ declare const _default: Feature<import("@common-stack/server-core").ConfigurationScope>;
3
+ export default _default;
@@ -0,0 +1,2 @@
1
+ import { Request } from 'node-fetch';
2
+ export declare const createFetchRequest: Request;
@@ -0,0 +1,16 @@
1
+ import { InMemoryCache } from '@apollo/client/cache';
2
+ import { CdmLogger } from '@cdm-logger/core';
3
+ interface CreateCacheParams {
4
+ getDataIdFromObject: (x?: any) => string;
5
+ clientState: any;
6
+ initialState?: any;
7
+ logger: CdmLogger.ILogger;
8
+ }
9
+ export declare const createCache: ({ getDataIdFromObject, clientState }: CreateCacheParams) => InMemoryCache;
10
+ export declare const initializeCache: ({ cache, initialState, clientState, logger }: {
11
+ cache: InMemoryCache;
12
+ initialState?: any;
13
+ clientState: any;
14
+ logger: CdmLogger.ILogger;
15
+ }) => void;
16
+ export {};
@@ -0,0 +1,35 @@
1
+ import {InMemoryCache}from'@apollo/client/cache';// cache.ts
2
+ const createCache = ({ getDataIdFromObject, clientState }) => {
3
+ const cache = new InMemoryCache({
4
+ dataIdFromObject: getDataIdFromObject,
5
+ possibleTypes: clientState.possibleTypes,
6
+ typePolicies: clientState.typePolicies,
7
+ });
8
+ return cache;
9
+ };
10
+ const initializeCache = ({ cache, initialState, clientState, logger }) => {
11
+ if (initialState) {
12
+ try {
13
+ cache.restore(initialState);
14
+ logger.debug('Cache restored with initial state');
15
+ }
16
+ catch (err) {
17
+ logger.error('Error restoring cache', err);
18
+ }
19
+ }
20
+ else {
21
+ clientState.defaults?.forEach((x) => {
22
+ try {
23
+ if (x.type === 'query') {
24
+ cache.writeQuery({ query: x.query, data: x.data });
25
+ }
26
+ else if (x.type === 'fragment') {
27
+ cache.writeFragment({ id: x.id, fragment: x.fragment, data: x.data });
28
+ }
29
+ }
30
+ catch (err) {
31
+ logger.error('Error writing to cache', err);
32
+ }
33
+ });
34
+ }
35
+ };export{createCache,initializeCache};//# sourceMappingURL=base-apollo-cache.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"base-apollo-cache.js","sources":["../../src/config/base-apollo-cache.ts"],"sourcesContent":[null],"names":[],"mappings":"iDAAA;AAWa,MAAA,WAAW,GAAG,CAAC,EAAE,mBAAmB,EAAE,WAAW,EAAqB,KAAmB;AAClG,IAAA,MAAM,KAAK,GAAG,IAAI,aAAa,CAAC;AAC5B,QAAA,gBAAgB,EAAE,mBAAmB;QACrC,aAAa,EAAE,WAAW,CAAC,aAAa;QACxC,YAAY,EAAE,WAAW,CAAC,YAAY;AACzC,KAAA,CAAC,CAAC;AAEH,IAAA,OAAO,KAAK,CAAC;AACjB,EAAE;AAEK,MAAM,eAAe,GAAG,CAAC,EAAE,KAAK,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,EAA6F,KAAI;IACvK,IAAI,YAAY,EAAE;AACd,QAAA,IAAI;AACA,YAAA,KAAK,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC;AAC5B,YAAA,MAAM,CAAC,KAAK,CAAC,mCAAmC,CAAC,CAAC;SACrD;QAAC,OAAO,GAAG,EAAE;AACV,YAAA,MAAM,CAAC,KAAK,CAAC,uBAAuB,EAAE,GAAG,CAAC,CAAC;SAC9C;KACJ;SAAM;QACH,WAAW,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC,CAAC,KAAI;AAChC,YAAA,IAAI;AACA,gBAAA,IAAI,CAAC,CAAC,IAAI,KAAK,OAAO,EAAE;AACpB,oBAAA,KAAK,CAAC,UAAU,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC;iBACtD;AAAM,qBAAA,IAAI,CAAC,CAAC,IAAI,KAAK,UAAU,EAAE;oBAC9B,KAAK,CAAC,aAAa,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC,EAAE,EAAE,QAAQ,EAAE,CAAC,CAAC,QAAQ,EAAE,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC;iBACzE;aACJ;YAAC,OAAO,GAAG,EAAE;AACV,gBAAA,MAAM,CAAC,KAAK,CAAC,wBAAwB,EAAE,GAAG,CAAC,CAAC;aAC/C;AACL,SAAC,CAAC,CAAC;KACN;AACL"}
@@ -0,0 +1,19 @@
1
+ import { ApolloClient, NormalizedCacheObject, InMemoryCache } from '@apollo/client/index.js';
2
+ import { CdmLogger } from '@cdm-logger/core';
3
+ interface IApolloClientParams {
4
+ initialState?: any;
5
+ scope: 'browser' | 'server' | 'native';
6
+ getDataIdFromObject: (x?: any) => string;
7
+ clientState: any;
8
+ isDebug: boolean;
9
+ isDev: boolean;
10
+ isSSR: boolean;
11
+ httpGraphqlURL: string;
12
+ httpLocalGraphqlURL: string;
13
+ logger: CdmLogger.ILogger;
14
+ }
15
+ export declare const createApolloClient: ({ scope, isDev, isDebug, isSSR, getDataIdFromObject, clientState, httpGraphqlURL, httpLocalGraphqlURL, initialState, logger, }: IApolloClientParams) => {
16
+ apolloClient: ApolloClient<NormalizedCacheObject>;
17
+ cache: InMemoryCache;
18
+ };
19
+ export {};
@@ -0,0 +1,109 @@
1
+ import {isBoolean,merge}from'lodash-es';import {ApolloLink,ApolloClient}from'@apollo/client/index.js';import {HttpLink}from'@apollo/client/link/http';import {BatchHttpLink}from'@apollo/client/link/batch-http';import {onError}from'@apollo/client/link/error';import {GraphQLWsLink}from'@apollo/client/link/subscriptions';import {getOperationAST}from'graphql';import {invariant}from'ts-invariant';import {RetryLink}from'@apollo/client/link/retry';import {createClient}from'graphql-ws';import fetch from'cross-fetch';import {createCache,initializeCache}from'./base-apollo-cache.js';// apolloClient.ts
2
+ const schema = `
3
+ # Add your schema here
4
+ `;
5
+ const errorLink = onError(({ graphQLErrors, networkError }) => {
6
+ if (graphQLErrors) {
7
+ graphQLErrors.map(({ message, locations, path }) => invariant.warn(`[GraphQL error]: Message: ${message}, Location: ${locations}, Path: ${path}`));
8
+ }
9
+ if (networkError) {
10
+ invariant.warn(`[Network error]: ${networkError}`);
11
+ }
12
+ });
13
+ const createApolloClient = ({ scope, isDev, isDebug, isSSR, getDataIdFromObject, clientState, httpGraphqlURL, httpLocalGraphqlURL, initialState, logger, }) => {
14
+ const isBrowser = scope === 'browser';
15
+ const isServer = scope === 'server';
16
+ const cache = createCache({ getDataIdFromObject, clientState, logger });
17
+ logger.debug('Created new Apollo memory cache');
18
+ const retryLink = new RetryLink({
19
+ attempts: async (count, operation, error) => {
20
+ const promises = (clientState.retryLinkAttemptFuncs || []).map((func) => func(count, operation, error));
21
+ try {
22
+ const result = await Promise.all(promises);
23
+ return !!result.find((item) => item && isBoolean(item));
24
+ }
25
+ catch (e) {
26
+ logger.trace('Error occurred in retryLink Attempt condition', e);
27
+ throw e;
28
+ }
29
+ },
30
+ });
31
+ let link;
32
+ if (isBrowser) {
33
+ const connectionParams = async () => {
34
+ const param = {};
35
+ for (const connectionParam of clientState.connectionParams) {
36
+ const result = await connectionParam();
37
+ merge(param, await result());
38
+ }
39
+ return param;
40
+ };
41
+ const wsLink = new GraphQLWsLink(createClient({
42
+ url: httpGraphqlURL.replace(/^http/, 'ws'),
43
+ retryAttempts: 10,
44
+ lazy: true,
45
+ // reconnect: true,
46
+ // timeout: 30000,
47
+ shouldRetry: () => true,
48
+ keepAlive: 10000,
49
+ connectionParams,
50
+ on: {
51
+ connected: (socket) => logger.debug('WebSocket connected'),
52
+ error: async (error) => {
53
+ logger.error(error, '[WS connectionCallback error] %j');
54
+ const promises = (clientState.connectionCallbackFuncs || []).map((func) => func(wsLink, error, {}));
55
+ try {
56
+ await Promise.all(promises);
57
+ }
58
+ catch (err) {
59
+ logger.trace('Error occurred in connectionCallback condition', err);
60
+ throw err;
61
+ }
62
+ },
63
+ ping: () => logger.trace('Pinged Server'),
64
+ pong: () => logger.trace('Pong received'),
65
+ },
66
+ }));
67
+ link = ApolloLink.split(({ query, operationName }) => {
68
+ if (operationName.endsWith('_WS')) {
69
+ return true;
70
+ }
71
+ const operationAST = getOperationAST(query, operationName);
72
+ return !!operationAST && operationAST.operation === 'subscription';
73
+ }, wsLink, new HttpLink({ uri: httpGraphqlURL, credentials: 'include', fetch }));
74
+ }
75
+ else if (isServer) {
76
+ link = new BatchHttpLink({
77
+ uri: httpLocalGraphqlURL,
78
+ fetch,
79
+ batchInterval: 2000,
80
+ batchMax: 100,
81
+ credentials: 'include',
82
+ });
83
+ }
84
+ else {
85
+ link = new HttpLink({ uri: httpLocalGraphqlURL, fetch, credentials: 'include' });
86
+ }
87
+ const links = [errorLink, retryLink, ...(clientState.preLinks || []), link];
88
+ const params = {
89
+ queryDeduplication: true,
90
+ typeDefs: schema.concat(clientState.typeDefs || ''),
91
+ resolvers: clientState.resolvers,
92
+ link: ApolloLink.from(links),
93
+ cache,
94
+ credentials: 'include',
95
+ connectToDevTools: isBrowser && (isDev || isDebug),
96
+ };
97
+ if (isSSR) {
98
+ if (isBrowser) {
99
+ params.ssrForceFetchDelay = 100;
100
+ }
101
+ else if (isServer) {
102
+ params.ssrMode = true;
103
+ }
104
+ }
105
+ const apolloClient = new ApolloClient(params);
106
+ logger.debug('Created new Apollo client');
107
+ initializeCache({ cache, initialState, clientState, logger });
108
+ return { apolloClient, cache };
109
+ };export{createApolloClient};//# sourceMappingURL=base-apollo-client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"base-apollo-client.js","sources":["../../src/config/base-apollo-client.ts"],"sourcesContent":[null],"names":[],"mappings":"kkBAAA;AAqBA,MAAM,MAAM,GAAG,CAAA;;CAEd,CAAC;AAeF,MAAM,SAAS,GAAG,OAAO,CAAC,CAAC,EAAE,aAAa,EAAE,YAAY,EAAE,KAAI;IAC1D,IAAI,aAAa,EAAE;QACf,aAAa,CAAC,GAAG,CAAC,CAAC,EAAE,OAAO,EAAE,SAAS,EAAE,IAAI,EAAE,KAC3C,SAAS,CAAC,IAAI,CAAC,CAAA,0BAAA,EAA6B,OAAO,CAAA,YAAA,EAAe,SAAS,CAAA,QAAA,EAAW,IAAI,CAAA,CAAE,CAAC,CAChG,CAAC;KACL;IACD,IAAI,YAAY,EAAE;AACd,QAAA,SAAS,CAAC,IAAI,CAAC,oBAAoB,YAAY,CAAA,CAAE,CAAC,CAAC;KACtD;AACL,CAAC,CAAC,CAAC;AAEU,MAAA,kBAAkB,GAAG,CAAC,EAC/B,KAAK,EACL,KAAK,EACL,OAAO,EACP,KAAK,EACL,mBAAmB,EACnB,WAAW,EACX,cAAc,EACd,mBAAmB,EACnB,YAAY,EACZ,MAAM,GACY,KAAiF;AACnG,IAAA,MAAM,SAAS,GAAG,KAAK,KAAK,SAAS,CAAC;AACtC,IAAA,MAAM,QAAQ,GAAG,KAAK,KAAK,QAAQ,CAAC;AAEpC,IAA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;AAED,IAAA,MAAM,YAAY,GAAG,IAAI,YAAY,CAAM,MAAM,CAAC,CAAC;AACnD,IAAA,MAAM,CAAC,KAAK,CAAC,2BAA2B,CAAC,CAAC;IAE1C,eAAe,CAAC,EAAE,KAAK,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,EAAE,CAAC,CAAC;AAE9D,IAAA,OAAO,EAAE,YAAY,EAAE,KAAK,EAAE,CAAC;AACnC"}
@@ -0,0 +1,23 @@
1
+ import { Middleware, StoreEnhancer } from 'redux';
2
+ import { EpicMiddleware, Epic } from 'redux-observable';
3
+ import { PersistConfig } from 'redux-persist';
4
+ interface IReduxStore<S = any> {
5
+ scope: 'browser' | 'server' | 'native' | 'ElectronMain';
6
+ isDebug: boolean;
7
+ isDev: boolean;
8
+ reducers: any;
9
+ enhancers?: StoreEnhancer[];
10
+ rootEpic: Epic<any, any, any, any>;
11
+ epicMiddleware?: EpicMiddleware<any, any, S, any>;
12
+ preMiddleware?: Middleware[];
13
+ postMiddleware?: Middleware[];
14
+ middleware?: Middleware[];
15
+ initialState?: any;
16
+ persistConfig?: PersistConfig<any>;
17
+ }
18
+ /**
19
+ * Add any reducers required for this app dirctly in to
20
+ * `combineReducers`
21
+ */
22
+ export declare const createReduxStore: ({ scope, isDebug, isDev, reducers, rootEpic, enhancers, epicMiddleware, preMiddleware, postMiddleware, middleware, initialState, persistConfig, }: IReduxStore<any>) => import("@reduxjs/toolkit").Store<any, import("@reduxjs/toolkit").UnknownAction, unknown>;
23
+ export {};
@@ -0,0 +1,41 @@
1
+ import {combineReducers,configureStore}from'@reduxjs/toolkit';import {persistReducer,FLUSH,REHYDRATE,PAUSE,PERSIST,PURGE,REGISTER}from'redux-persist';// version 11/12/2021
2
+ /* eslint-disable @typescript-eslint/explicit-module-boundary-types */
3
+ /* eslint-disable @typescript-eslint/no-explicit-any */
4
+ /* eslint-disable @typescript-eslint/no-var-requires */
5
+ /* eslint-disable global-require */
6
+ /* eslint-disable no-underscore-dangle */
7
+ /**
8
+ * Add any reducers required for this app dirctly in to
9
+ * `combineReducers`
10
+ */
11
+ const createReduxStore = ({ scope, isDebug, isDev, reducers, rootEpic, enhancers = [], epicMiddleware, preMiddleware = [], postMiddleware = [], middleware = [], initialState, persistConfig, }) => {
12
+ const isBrowser = scope === 'browser';
13
+ const isElectronMain = scope === 'ElectronMain';
14
+ const rootReducer = combineReducers(reducers);
15
+ const persistedReducer = persistConfig && isBrowser ? persistReducer(persistConfig, rootReducer) : rootReducer;
16
+ /**
17
+ * Add middleware that required for this app.
18
+ */
19
+ // Configure middlewares
20
+ const middlewares = [
21
+ ...preMiddleware,
22
+ ...(epicMiddleware ? [epicMiddleware] : []),
23
+ ...middleware,
24
+ ...postMiddleware,
25
+ ];
26
+ const store = configureStore({
27
+ reducer: persistedReducer,
28
+ middleware: (getDefaultMiddleware) => getDefaultMiddleware({
29
+ serializableCheck: {
30
+ ignoredActions: [FLUSH, REHYDRATE, PAUSE, PERSIST, PURGE, REGISTER],
31
+ },
32
+ }).concat(...middlewares),
33
+ devTools: isDev || isDebug,
34
+ preloadedState: initialState,
35
+ enhancers: (getDefaultEnhancers) => getDefaultEnhancers().concat(...enhancers),
36
+ });
37
+ if ((isBrowser || isElectronMain || __SSR__) && epicMiddleware && rootEpic) {
38
+ epicMiddleware.run(rootEpic);
39
+ }
40
+ return store;
41
+ };export{createReduxStore};//# sourceMappingURL=base-redux-config.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"base-redux-config.js","sources":["../../src/config/base-redux-config.ts"],"sourcesContent":[null],"names":[],"mappings":"sJAAA;AACA;AACA;AACA;AACA;AACA;AAoBA;;;AAGG;AACU,MAAA,gBAAgB,GAAG,CAAC,EAC7B,KAAK,EACL,OAAO,EACP,KAAK,EACL,QAAQ,EACR,QAAQ,EACR,SAAS,GAAG,EAAE,EACd,cAAc,EACd,aAAa,GAAG,EAAE,EAClB,cAAc,GAAG,EAAE,EACnB,UAAU,GAAG,EAAE,EACf,YAAY,EACZ,a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
2
+ GA_ID: string;
3
+ GRAPHQL_URL: string;
4
+ LOCAL_GRAPHQL_URL: string;
5
+ GRAPHQL_SUBSCRIPTION_URL: string;
6
+ LOG_LEVEL: string;
7
+ } & import("envalid").CleanedEnvAccessors>;
@@ -0,0 +1,8 @@
1
+ import {cleanEnv,str}from'envalid';import {getEnvironment}from'@common-stack/core';const env = getEnvironment();
2
+ const config = cleanEnv(env, {
3
+ GA_ID: str({ devDefault: 'G-xxxxxxx' }),
4
+ GRAPHQL_URL: str({ devDefault: __GRAPHQL_URL__ }),
5
+ LOCAL_GRAPHQL_URL: str({ default: __GRAPHQL_URL__ }),
6
+ GRAPHQL_SUBSCRIPTION_URL: str({ default: env?.GRAPHQL_URL?.replace(/^http/, 'ws') }),
7
+ LOG_LEVEL: str({ devDefault: 'debug' }),
8
+ });export{config};//# sourceMappingURL=browser-env-config.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"browser-env-config.js","sources":["../../src/config/browser-env-config.ts"],"sourcesContent":[null],"names":[],"mappings":"mFAGA,MAAM,GAAG,GAAG,cAAc,EAAE,CAAC;AAEhB,MAAA,MAAM,GAAG,QAAQ,CAAC,GAAG,EAAE;IAChC,KAAK,EAAE,GAAG,CAAC,EAAE,UAAU,EAAE,WAAW,EAAE,CAAC;IACvC,WAAW,EAAE,GAAG,CAAC,EAAE,UAAU,EAAE,eAAe,EAAE,CAAC;IACjD,iBAAiB,EAAE,GAAG,CAAC,EAAE,OAAO,EAAE,eAAe,EAAE,CAAC;AACpD,IAAA,wBAAwB,EAAE,GAAG,CAAC,EAAE,OAAO,EAAE,GAAG,EAAE,WAAW,EAAE,OAAO,CAAC,OAAO,EAAE,IAAI,CAAC,EAAE,CAAC;IACpF,SAAS,EAAE,GAAG,CAAC,EAAE,UAAU,EAAE,OAAO,EAAE,CAAC;AAC1C,CAAA"}
@@ -0,0 +1,9 @@
1
+ import 'reflect-metadata';
2
+ import { Container } from 'inversify';
3
+ import { ApolloClient, NormalizedCacheObject } from '@apollo/client/index.js';
4
+ export declare const createClientContainer: (req?: any, res?: any) => {
5
+ container: Container;
6
+ apolloClient: ApolloClient<NormalizedCacheObject>;
7
+ serviceFunc: () => any;
8
+ logger: import("@cdm-logger/core/lib/interface").ILogger;
9
+ };
@@ -0,0 +1,72 @@
1
+ import'reflect-metadata';import {ClientTypes}from'@common-stack/client-core';import {ScopedContainer}from'@common-stack/client-core/lib/connector/ScopedContainer.js';import {merge}from'lodash-es';import modules from'virtual-module';import {UtilityClass,logger}from'../utils/index.js';import {createApolloClient}from'./base-apollo-client.js';import {config}from'./browser-env-config.js';const utility = new UtilityClass(modules);
2
+ ScopedContainer.registerGlobalDependencies((container) => {
3
+ container.bind(ClientTypes.Logger).toConstantValue(logger);
4
+ container.bind(ClientTypes.UtilityClass).toConstantValue(utility);
5
+ });
6
+ const createClientContainer = (req, res) => {
7
+ logger.debug('Calling CreateClientContainer');
8
+ const container = modules.createContainers({});
9
+ container
10
+ .bind(ClientTypes.ApolloClient)
11
+ .toDynamicValue((context) => new Error('Too early to bind ApolloClient'))
12
+ .inRequestScope();
13
+ container
14
+ .bind(ClientTypes.ApolloClientFactory)
15
+ .toDynamicValue((context) => () => {
16
+ const newClient = container.get(ClientTypes.ApolloClient);
17
+ return newClient;
18
+ });
19
+ const services = merge({ container: container }, ...modules.createServiceFunc.map((serviceFunc) => serviceFunc(container)));
20
+ const clientState = modules.getStateParams({
21
+ resolverContex: () => services,
22
+ // container: container,
23
+ requestResponsePair: {
24
+ req,
25
+ res,
26
+ },
27
+ });
28
+ const { apolloClient, cache } = createApolloClient({
29
+ httpGraphqlURL: config.GRAPHQL_URL,
30
+ httpLocalGraphqlURL: config.LOCAL_GRAPHQL_URL,
31
+ isDev: process.env.NODE_ENV === 'development',
32
+ isDebug: __DEBUGGING__,
33
+ isSSR: __SSR__,
34
+ scope: typeof window !== 'undefined' ? 'browser' : 'server',
35
+ clientState,
36
+ getDataIdFromObject: (result) => modules.getDataIdFromObject(result),
37
+ initialState: typeof window !== 'undefined' ? window?.__APOLLO_STATE__ : undefined,
38
+ logger,
39
+ });
40
+ if (!container.isBound(ClientTypes.InMemoryCache)) {
41
+ container
42
+ .bind(ClientTypes.InMemoryCache)
43
+ .toDynamicValue((context) => cache)
44
+ .inRequestScope();
45
+ }
46
+ container
47
+ .rebind(ClientTypes.ApolloClient)
48
+ .toDynamicValue((context) => apolloClient)
49
+ .inRequestScope();
50
+ // const services = serviceFunc();
51
+ const serviceFunc = () => services;
52
+ apolloClient.container = services;
53
+ const clientService = {
54
+ container: container,
55
+ apolloClient,
56
+ serviceFunc,
57
+ logger,
58
+ };
59
+ // @ts-ignore
60
+ if (import.meta.hot) {
61
+ //@ts-ignore
62
+ import.meta.hot.dispose(() => {
63
+ // Force Apollo to fetch the latest data from the server
64
+ delete window.__APOLLO_STATE__;
65
+ });
66
+ }
67
+ if (typeof window !== 'undefined') {
68
+ //@ts-ignore
69
+ window.__CLIENT_SERVICE__ = clientService;
70
+ }
71
+ return clientService;
72
+ };export{createClientContainer};//# sourceMappingURL=client.service.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.service.js","sources":["../../src/config/client.service.ts"],"sourcesContent":[null],"names":[],"mappings":"kYAgBA,MAAM,OAAO,GAAG,IAAI,YAAY,CAAC,OAAO,CAAC,CAAC;AAE1C,eAAe,CAAC,0BAA0B,CAAC,CAAC,SAAS,KAAI;AACrD,IAAA,SAAS,CAAC,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC,eAAe,CAAC,MAAM,CAAC,CAAC;AAC3D,IAAA,SAAS,CAAC,IAAI,CAAC,WAAW,CAAC,YAAY,CAAC,CAAC,eAAe,CAAC,OAAO,CAAC,CAAC;AACtE,CAAC,CAAC,CAAC;MAEU,qBAAqB,GAAG,CAAC,GAAS,EAAE,GAAS,KAAI;AAC1D,IAAA,MAAM,CAAC,KAAK,CAAC,+BAA+B,CAAC,CAAC;IAE9C,MAAM,SAAS,GAAG,OAAO,CAAC,gBAAgB,C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: string;
9
+ LOG_LEVEL: string;
10
+ REDIS_CLUSTER_URL: string;
11
+ REDIS_URL: string;
12
+ REDIS_CLUSTER_ENABLED: boolean;
13
+ REDIS_SENTINEL_ENABLED: boolean;
14
+ APP_NAME: string;
15
+ CLIENT_URL: string;
16
+ CONNECTION_ID: string;
17
+ NAMESPACE: string;
18
+ ZIPKIN_URL: string;
19
+ } & import("envalid").CleanedEnvAccessors>;
@@ -0,0 +1,21 @@
1
+ import'reflect-metadata';import {cleanEnv,str,json,bool}from'envalid';const config = cleanEnv(process.env, {
2
+ SENTRY_DSN_FRONTEND: str({ default: 'https://64defc5ee0bd467aa28888f9860f18ee@sentry.io/2158332' }),
3
+ NODE_ENV: str({ default: 'production', choices: ['production', 'staging', 'development', 'test'] }),
4
+ BACKEND_URL: str({ devDefault: __BACKEND_URL__ }),
5
+ LOCAL_BACKEND_URL: str({ devDefault: __BACKEND_URL__ }),
6
+ LOCAL_GRAPHQL_URL: str({ default: __GRAPHQL_URL__, desc: 'Graphql Server URL within LAN' }),
7
+ GRAPHQL_URL: str({ devDefault: __GRAPHQL_URL__, desc: 'Graphql Server Public URL' }),
8
+ LOG_LEVEL: str({ devDefault: 'trace' }),
9
+ REDIS_CLUSTER_URL: json({
10
+ devDefault: '[{"port":6379,"host":"localhost"}]',
11
+ example: '[{"port":6379,"host":"localhost"}]',
12
+ }),
13
+ REDIS_URL: str({ devDefault: 'localhost' }),
14
+ REDIS_CLUSTER_ENABLED: bool({ devDefault: false }),
15
+ REDIS_SENTINEL_ENABLED: bool({ devDefault: true }),
16
+ APP_NAME: str({ devDefault: 'AdminiIde' }),
17
+ CLIENT_URL: str({ devDefault: __BACKEND_URL__ }),
18
+ CONNECTION_ID: str({ devDefault: 'CONNECTION_ID' }),
19
+ NAMESPACE: str({ default: 'default' }),
20
+ ZIPKIN_URL: str(),
21
+ });export{config};//# sourceMappingURL=env-config.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"env-config.js","sources":["../../src/config/env-config.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GAAG,CAAC,EAAE,OAAO,EAAE,SAAS,EAAE,CAAC;IACtC,UAAU,EAAE,GAAG,EAAE;AACpB,CAAA"}
@@ -0,0 +1,3 @@
1
+ import { BehaviorSubject } from 'rxjs';
2
+ export declare const epic$: BehaviorSubject<any>;
3
+ export declare const rootEpic: (action$: any, ...rest: any[]) => import("rxjs").Observable<any>;
@@ -0,0 +1,6 @@
1
+ import {combineEpics,ofType}from'redux-observable';import {BehaviorSubject}from'rxjs';import {mergeMap,takeUntil}from'rxjs/operators/index.js';import modules from'virtual-module';const epic$ = new BehaviorSubject(combineEpics(...modules.epics));
2
+ // Since we're using mergeMap, by default any new
3
+ // epic that comes in will be merged into the previous
4
+ // one, unless an EPIC_END action is dispatched first,
5
+ // which would cause the old one(s) to be unsubscribed
6
+ const rootEpic = (action$, ...rest) => epic$.pipe(mergeMap((epic) => epic(action$, ...rest).pipe(takeUntil(action$.pipe(ofType('EPIC_END'))))));export{epic$,rootEpic};//# sourceMappingURL=epic-config.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"epic-config.js","sources":["../../src/config/epic-config.ts"],"sourcesContent":[null],"names":[],"mappings":"mLAMO,MAAM,KAAK,GAAG,IAAI,eAAe,CAAC,YAAY,CAAC,GAAG,OAAO,CAAC,KAAK,CAAC,EAAE;AACzE;AACA;AACA;AACA;MACa,QAAQ,GAAG,CAAC,OAAO,EAAE,GAAG,IAAI,KACrC,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,IAAI,KAAK,IAAI,CAAC,OAAO,EAAE,GAAG,IAAI,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC"}
@@ -0,0 +1,2 @@
1
+ import i18n from 'i18next';
2
+ export default i18n;
@@ -0,0 +1,3 @@
1
+ export * from './env-config';
2
+ export * from './client.service';
3
+ export * from './redux-config';
@@ -0,0 +1,3 @@
1
+ /// <reference path="../../../../typings/index.d.ts" />
2
+ declare const env: any;
3
+ export default env;
@@ -0,0 +1 @@
1
+ export declare function getRedisClient(): any;
@@ -0,0 +1,8 @@
1
+ import Redis from'ioredis';import {config}from'./env-config.js';let redisClient;
2
+ function getRedisClient() {
3
+ if (!redisClient) {
4
+ // Initialize Redis client if it doesn't exist
5
+ redisClient = new Redis(config.REDIS_URL);
6
+ }
7
+ return redisClient;
8
+ }export{getRedisClient};//# sourceMappingURL=redis-config.server.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"redis-config.server.js","sources":["../../src/config/redis-config.server.ts"],"sourcesContent":[null],"names":[],"mappings":"gEAGA,IAAI,WAAW,CAAC;SAEA,cAAc,GAAA;IAC1B,IAAI,CAAC,WAAW,EAAE;;QAEd,WAAW,GAAG,IAAI,KAAK,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;KAC7C;AACD,IAAA,OAAO,WAAW,CAAC;AACvB"}
@@ -0,0 +1,29 @@
1
+ /// <reference types="redux-persist/types/stateReconciler/autoMergeLevel2" />
2
+ /// <reference types="redux-persist/types/types" />
3
+ /// <reference types="redux-persist" />
4
+ import "reflect-metadata";
5
+ import autoMergeLevel2 from 'redux-persist/lib/stateReconciler/autoMergeLevel2';
6
+ export declare const epicMiddlewareFunc: (apolloClient: any, services: any, container: any) => import("redux-observable").EpicMiddleware<import("redux").Action<any>, import("redux").Action<any>, void, {
7
+ apolloClient: any;
8
+ routes: any;
9
+ services: any;
10
+ container: any;
11
+ logger: import("@cdm-logger/core/lib/interface").ILogger;
12
+ config: {
13
+ loadRoot: boolean;
14
+ };
15
+ }>;
16
+ export declare const persistConfig: {
17
+ key: string;
18
+ storage: import("redux-persist").WebStorage;
19
+ stateReconciler: typeof autoMergeLevel2;
20
+ transforms: any;
21
+ blacklist: string[];
22
+ };
23
+ /**
24
+ * Add any reducers required for this app dirctly in to
25
+ * `combineReducers`
26
+ */
27
+ export declare const createReduxStore: (apolloClient: any, services: any, container: any) => {
28
+ store: any;
29
+ };
@@ -0,0 +1,73 @@
1
+ import'reflect-metadata';import storage from'redux-persist/lib/storage';import {combineReducers}from'@reduxjs/toolkit';import autoMergeLevel2 from'redux-persist/lib/stateReconciler/autoMergeLevel2';import {createEpicMiddleware}from'redux-observable';import {createRouterReducer}from'@common-stack/remix-router-redux';import {persistReducer}from'redux-persist';import {REDUX_PERSIST_KEY}from'@common-stack/client-core';import {createReduxStore as createReduxStore$1}from'./base-redux-config.js';import {logger}from'../utils/index.js';import modules from'virtual-modules';import {rootEpic}from'./epic-config.js';const epicMiddlewareFunc = (apolloClient, services, container) => createEpicMiddleware({
2
+ dependencies: {
3
+ apolloClient,
4
+ routes: modules.getConfiguredRoutes(),
5
+ services,
6
+ container,
7
+ logger,
8
+ config: {
9
+ loadRoot: false,
10
+ }
11
+ },
12
+ });
13
+ const persistConfig = {
14
+ key: REDUX_PERSIST_KEY,
15
+ storage,
16
+ stateReconciler: autoMergeLevel2,
17
+ transforms: modules.reduxPersistStateTransformers,
18
+ blacklist: ['router']
19
+ };
20
+ /**
21
+ * Add any reducers required for this app dirctly in to
22
+ * `combineReducers`
23
+ */
24
+ const createReduxStore = (apolloClient, services, container) => {
25
+ const reducers = {
26
+ router: createRouterReducer({}),
27
+ ...modules.reducers,
28
+ };
29
+ let store;
30
+ // @ts-ignore
31
+ if (import.meta.hot && import.meta.hot.data && import.meta.hot.data.store) {
32
+ // console.log('Restoring Redux store:', JSON.stringify(import.meta.hot.data.store.getState()));
33
+ // @ts-ignore
34
+ store = import.meta.hot.data.store;
35
+ // replace the reducers always as we don't have ablity to find
36
+ // new reducer added through our `modules`
37
+ store.replaceReducer(persistReducer(persistConfig, combineReducers(reducers)));
38
+ }
39
+ else {
40
+ let initialState = {};
41
+ let middlewares = [];
42
+ if (__CLIENT__ && typeof window !== 'undefined') {
43
+ initialState = { ...window.__PRELOADED_STATE__ }; // #952 TODO we need cookie to have id_token for SSR to work properly
44
+ delete window.__PRELOADED_STATE__; // Delete it once we have it stored in a variable
45
+ // it doesn't work, since __remixRouter is not created yet.
46
+ // middlewares = [createRouterMiddleware({ router: window.__remixRouter } as any)];
47
+ }
48
+ store = createReduxStore$1({
49
+ scope: __CLIENT__ && typeof window !== 'undefined' ? 'browser' : 'server',
50
+ isDebug: true,
51
+ isDev: process.env.NODE_ENV === 'development',
52
+ initialState,
53
+ persistConfig,
54
+ middleware: middlewares,
55
+ epicMiddleware: epicMiddlewareFunc(apolloClient, services, container),
56
+ rootEpic: rootEpic,
57
+ reducers,
58
+ });
59
+ }
60
+ if (container.isBound('ReduxStore')) {
61
+ container
62
+ .rebind('ReduxStore')
63
+ .toDynamicValue(() => store)
64
+ .inRequestScope();
65
+ }
66
+ else {
67
+ container
68
+ .bind('ReduxStore')
69
+ .toDynamicValue(() => store)
70
+ .inRequestScope();
71
+ }
72
+ return { store };
73
+ };export{createReduxStore,epicMiddlewareFunc,persistConfig};//# sourceMappingURL=redux-config.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"redux-config.js","sources":["../../src/config/redux-config.ts"],"sourcesContent":[null],"names":["createBaseReduxStore"],"mappings":"kmBAkBO,MAAM,kBAAkB,GAAG,CAAC,YAAiB,EAAE,QAAa,EAAE,SAAc,KAC/E,oBAAoB,CAAC;AACjB,IAAA,YAAY,EAAE;QACV,YAAY;AACZ,QAAA,MAAM,EAAE,OAAO,CAAC,mBAAmB,EAAE;QACrC,QAAQ;QACR,SAAS;QACT,MAAM;AACN,QAAA,MAAM,EAAE;AACJ,YAAA,QAAQ,EAAE,KAAK;AAClB,SAAA;AACJ,KAAA;AACJ,CAAA,EAAE;AAEM,MAAA,aAAa,GAAG;AACzB,IAAA,GAAG,EAAE,iBAAiB;IACtB,OAAO;AACP,IAAA,eAAe,EAAE,eAAe;IAChC,UAAU,EAAE,OAAO,CAAC,6BAA6B;IACjD,SAAS,EAAE,CAAC,QAAQ,CAAC;EACvB;AAEF;;;AAGG;AACU,MAAA,gBAAgB,GAAG,CAAC,YAAiB,EAAE,QAAa,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C,YAAY,CAAC,EAAE;QACjC,SAAS;aACJ,MAAM,CAAC,YAAY,CAAC;AACpB,aAAA,cAAc,CAAC,MAAM,KAAK,CAAC;AAC3B,aAAA,cAAc,EAAE,CAAC;KACzB;SAAM;QACH,SAAS;aACJ,IAAI,CAAC,YAAY,CAAC;AAClB,aAAA,cAAc,CAAC,MAAM,KAAK,CAAC;AAC3B,aAAA,cAAc,EAAE,CAAC;KACzB;IACD,OAAO,EAAE,KAAK,EAAE,CAAC;AACrB"}
package/lib/index.d.ts ADDED
@@ -0,0 +1,6 @@
1
+ export * from './utils';
2
+ export * from './config';
3
+ export * from './backend/middlewares/cors';
4
+ export * from './backend/middlewares/container';
5
+ export * from './backend/middlewares/error';
6
+ export * from './load-context.server';
package/lib/index.js ADDED
@@ -0,0 +1 @@
1
+ export{UtilityClass,logger}from'./utils/index.js';export{config}from'./config/env-config.js';export{createClientContainer}from'./config/client.service.js';export{createReduxStore,epicMiddlewareFunc,persistConfig}from'./config/redux-config.js';export{corsMiddleware}from'./backend/middlewares/cors.js';export{TYPES,containerMiddleware}from'./backend/middlewares/container.js';export{errorMiddleware}from'./backend/middlewares/error.js';export{loadContext}from'./load-context.server.js';//# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":""}
@@ -0,0 +1,10 @@
1
+ import 'reflect-metadata';
2
+ export declare const loadContext: (req: Request, res: Response) => Promise<{
3
+ modules: any;
4
+ routeConfig: any;
5
+ store: any;
6
+ container: any;
7
+ apolloClient: any;
8
+ services: any;
9
+ redisClient: any;
10
+ }>;
@@ -0,0 +1,15 @@
1
+ import'reflect-metadata';import modules from'virtual-module';import {getRedisClient}from'./config/redis-config.server.js';/* eslint-disable @typescript-eslint/ban-ts-comment */
2
+ const routeConfig = modules.getConfiguredRoutes();
3
+ const redisClient = getRedisClient();
4
+ const loadContext = async (req, res) => {
5
+ const { container, store, apolloClient, services } = req;
6
+ return {
7
+ modules: modules,
8
+ routeConfig,
9
+ store,
10
+ container,
11
+ apolloClient,
12
+ services,
13
+ redisClient,
14
+ };
15
+ };export{loadContext};//# sourceMappingURL=load-context.server.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"load-context.server.js","sources":["../src/load-context.server.ts"],"sourcesContent":[null],"names":["feature"],"mappings":"0HAAA;AAOA,MAAM,WAAW,GAAGA,OAAO,CAAC,mBAAmB,EAAE,CAAC;AAClD,MAAM,WAAW,GAAG,cAAc,EAAE,CAAC;AACxB,MAAA,WAAW,GAAG,OAAO,GAAY,EAAE,GAAa,KAAI;IAC7D,MAAM,EAAE,SAAS,EAAE,KAAK,EAAE,YAAY,EAAE,QAAQ,EAAE,GAAQ,GAAG,CAAC;IAE9D,OAAO;AACH,QAAA,OAAO,EAAEA,OAAO;QAChB,WAAW;QACX,KAAK;QACL,SAAS;QACT,YAAY;QACZ,QAAQ;QACR,WAAW;KACd,CAAC;AACN"}
@@ -0,0 +1,10 @@
1
+ import modules from 'virtual-module';
2
+ export declare class UtilityClass {
3
+ private modules;
4
+ private cache;
5
+ constructor(modules: any);
6
+ getCacheKey(storeObj: any): string;
7
+ }
8
+ declare const logger: import("@cdm-logger/core/lib/interface").ILogger;
9
+ export default modules;
10
+ export { logger };
@@ -0,0 +1,29 @@
1
+ import {ClientLogger}from'@cdm-logger/client';export{default}from'virtual-module';class UtilityClass {
2
+ modules;
3
+ cache = { key: null, modules: null };
4
+ constructor(modules) {
5
+ this.modules = modules;
6
+ // Setup HMR to invalidate cache when modules change
7
+ // @ts-ignore
8
+ if (import.meta.hot) {
9
+ // @ts-ignore
10
+ import.meta.hot.accept('./module', (newModules) => {
11
+ this.modules = newModules.default;
12
+ this.cache.key = null; // Invalidate cache
13
+ this.cache.modules = null;
14
+ });
15
+ }
16
+ }
17
+ getCacheKey(storeObj) {
18
+ // Check if the modules reference has changed or cache is invalidated
19
+ if (this.cache.modules !== this.modules) {
20
+ // Modules have changed, recalculate the cache key
21
+ this.cache.modules = this.modules;
22
+ this.cache.key = this.modules.getDataIdFromObject(storeObj);
23
+ }
24
+ return this.cache.key;
25
+ }
26
+ }
27
+ const logger = ClientLogger.create(process.env.APP_NAME || 'Fullstack-Pro', {
28
+ level: process.env.LOG_LEVEL || 'info',
29
+ });export{UtilityClass,logger};//# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sources":["../../src/utils/index.ts"],"sourcesContent":[null],"names":[],"mappings":"wFAKa,YAAY,CAAA;AAGD,IAAA,OAAA,CAAA;IAFZ,KAAK,GAAyC,EAAE,GAAG,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;AAEnF,IAAA,WAAA,CAAoB,OAAO,EAAA;QAAP,IAAO,CAAA,OAAA,GAAP,OAAO,CAAA;;;AAGvB,QAAA,IAAI,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE;;AAEjB,YAAA,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,UAAU,EAAE,CAAC,UAAU,KAAI;AAC9C,gBAAA,IAAI,CAAC,OAAO,GAAG,UAAU,CAAC,OAAO,CAAC;gBAClC,IAAI,CAAC,KAAK,CAAC,GAAG,GAAG,IAAI,CAAC;AACtB,gBAAA,IAAI,CAAC,KAAK,CAAC,OAAO,GAAG,IAAI,CAAC;AAC9B,aAAC,CAAC,CAAC;SACN;KACJ;AAEM,IAAA,WAAW,CAAC,QAAQ,EAAA;;QAEvB,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,KAAK,IAAI,CAAC,OAAO,EAAE;;YAErC,IAAI,CAAC,KAAK,CAAC,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC;AAClC,YAAA,IAAI,CAAC,KAAK,CAAC,GAAG,GAAG,IAAI,CAAC,OAAO,CAAC,mBAAmB,CAAC,QAAQ,CAAC,CAAC;SAC/D;AACD,QAAA,OAAO,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC;KACzB;AACJ,CAAA;AAED,MAAM,MAAM,GAAG,YAAY,CAAC,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,QAAQ,IAAI,eAAe,EAAE;AACxE,IAAA,KAAK,EAAG,OAAO,CAAC,GAAG,CAAC,SAAiB,IAAI,MAAM;AAClD,CAAA"}
package/package.json ADDED
@@ -0,0 +1,54 @@
1
+ {
2
+ "name": "@common-stack/frontend-stack-react",
3
+ "version": "4.0.1-alpha.11",
4
+ "description": "Client Module for react app",
5
+ "homepage": "https://github.com/cdmbase/fullstack-pro#readme",
6
+ "bugs": {
7
+ "url": "https://github.com/cdmbase/fullstack-pro/issues"
8
+ },
9
+ "repository": {
10
+ "type": "git",
11
+ "url": "git+https://github.com/cdmbase/fullstack-pro.git"
12
+ },
13
+ "license": "ISC",
14
+ "author": "CDMBase LLC",
15
+ "main": "lib/index.js",
16
+ "module": "lib/index.js",
17
+ "type": "module",
18
+ "typings": "lib/index.d.ts",
19
+ "scripts": {
20
+ "build": "npm run build:clean && npm run build:lib",
21
+ "build:clean": "rimraf lib",
22
+ "build:lib": "rollup -c rollup.config.mjs",
23
+ "build:lib:watch": "npm run build:lib -- --watch",
24
+ "jest": "./node_modules/.bin/jest",
25
+ "prepublish": "npm run build",
26
+ "test": "jest",
27
+ "test:debug": "npm test -- --runInBand",
28
+ "test:watch": "npm test -- --watch",
29
+ "watch": "npm run build:lib:watch"
30
+ },
31
+ "dependencies": {
32
+ "@common-stack/client-react": "4.0.1-alpha.11",
33
+ "@common-stack/core": "4.0.1-alpha.11"
34
+ },
35
+ "devDependencies": {
36
+ "jest-fetch-mock": "^3.0.3",
37
+ "vite": "^5.2.12"
38
+ },
39
+ "peerDependencies": {
40
+ "@apollo/client": ">=3.0.0",
41
+ "@remix-run/react": "^2.9.2",
42
+ "react": ">=16.8.6",
43
+ "react-dom": ">=16.8.6",
44
+ "react-router": ">=6.0.0",
45
+ "redux": ">=4.0.1"
46
+ },
47
+ "publishConfig": {
48
+ "access": "public"
49
+ },
50
+ "typescript": {
51
+ "definition": "lib/index.d.ts"
52
+ },
53
+ "gitHead": "6cf439a9ad8f608c93c119d38ce474feca88998b"
54
+ }