@rws-framework/client 2.5.4 → 2.6.0

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/package.json CHANGED
@@ -1,99 +1,100 @@
1
1
  {
2
- "name": "@rws-framework/client",
3
- "private": false,
4
- "version": "2.5.4",
5
- "main": "src/index.ts",
6
- "scripts": {
7
- "docs": "typedoc --tsconfig ./tsconfig.json"
8
- },
9
- "bin": {
10
- "rws-client": "./console.js"
11
- },
12
- "repository": {
13
- "type": "git",
14
- "url": "git+https://github.com/papablack/rws-client.git"
15
- },
16
- "keywords": [
17
- "frontend",
18
- "rws",
19
- "client",
20
- "typescript"
21
- ],
22
- "author": "papablack",
23
- "license": "ISC",
24
- "bugs": {
25
- "url": "https://github.com/papablack/rws-client/issues"
26
- },
27
- "homepage": "https://github.com/papablack/rws-client#readme",
28
- "dependencies": {
29
- "@microsoft/fast-element": "^1.12.0",
30
- "@microsoft/fast-foundation": "^2.46.2",
31
- "@rws-framework/console": "^0.3.1",
32
- "@types/moment": "^2.13.0",
33
- "dragula": "^3.7.3",
34
- "he": "^1.2.0",
35
- "json5": "^2.2.3",
36
- "lodash": "^4.17.21",
37
- "moment": "^2.29.4",
38
- "partial-json-parser": "^1.0.0",
39
- "reflect-metadata": "^0.1.13",
40
- "resolve-url-loader": "^5.0.0",
41
- "sanitize-html": "^2.12.1",
42
- "sass": "^1.69.7",
43
- "scss-loading-animations": "^1.0.1",
44
- "socket.io-client": "^4.7.2",
45
- "ts-loader": "^9.4.4",
46
- "tsc-watch": "^6.0.4",
47
- "tslib": "^2.6.2",
48
- "upload": "^1.3.2",
49
- "url-router": "^13.0.0",
50
- "uuid": "^9.0.1",
51
- "v4": "^0.0.1"
52
- },
53
- "devDependencies": {
54
- "@types/dragula": "^3.7.4",
55
- "@types/eslint": "^6.0.0",
56
- "@types/express-fileupload": "^1.4.4",
57
- "@types/glob": "^8.1.0",
58
- "@types/he": "^1.2.3",
59
- "@types/sanitize-html": "^2.11.0",
60
- "@types/uuid": "^9.0.7",
61
- "@typescript-eslint/parser": "^5.0.0",
62
- "clean-webpack-plugin": "^4.0.0",
63
- "css-loader": "^6.8.1",
64
- "css-minimizer-webpack-plugin": "^5.0.1",
65
- "eslint": "^6.0.0",
66
- "file-loader": "^6.2.0",
67
- "html-webpack-plugin": "^5.5.3",
68
- "loader-utils": "^3.2.1",
69
- "mini-css-extract-plugin": "^2.7.6",
70
- "minimatch": "^9.0.4",
71
- "node-sass": "^9.0.0",
72
- "sass-loader": "^13.3.2",
73
- "source-map": "^0.7.4",
74
- "style-loader": "^3.3.3",
75
- "terser-webpack-plugin": "^5.3.9",
76
- "ts-loader": "^9.4.4",
77
- "ts-node": "^10.9.1",
78
- "tsconfig-paths": "^4.2.0",
79
- "tsconfig-paths-webpack-plugin": "^4.1.0",
80
- "typedoc": "^0.25.4",
81
- "typedoc-plugin-mermaid": "^1.10.0",
82
- "typedoc-plugin-not-exported": "^0.1.6",
83
- "typedoc-plugin-rename-defaults": "^0.7.0",
84
- "typedoc-theme-hierarchy": "^4.1.2",
85
- "typescript": "^5.1.6",
86
- "url-loader": "^4.1.1",
87
- "webpack": "^5.75.0",
88
- "webpack-bundle-analyzer": "^4.10.1",
89
- "webpack-cli": "^5.1.4",
90
- "webpack-dev-server": "^4.15.1",
91
- "webpack-node-externals": "^3.0.0"
92
- },
93
- "resolutions": {
94
- "lodash": "^4.17.21"
95
- },
96
- "overrides": {
97
- "lodash": "^4.17.21"
2
+ "name": "@rws-framework/client",
3
+ "private": false,
4
+ "version": "2.6.0",
5
+ "main": "src/index.ts",
6
+ "scripts": {
7
+ "docs": "typedoc --tsconfig ./tsconfig.json"
8
+ },
9
+ "bin": {
10
+ "rws-client": "./console.js"
11
+ },
12
+ "repository": {
13
+ "type": "git",
14
+ "url": "git+https://github.com/papablack/rws-client.git"
15
+ },
16
+ "keywords": [
17
+ "frontend",
18
+ "rws",
19
+ "client",
20
+ "typescript"
21
+ ],
22
+ "author": "papablack",
23
+ "license": "ISC",
24
+ "bugs": {
25
+ "url": "https://github.com/papablack/rws-client/issues"
26
+ },
27
+ "homepage": "https://github.com/papablack/rws-client#readme",
28
+ "dependencies": {
29
+ "@microsoft/fast-element": "^1.12.0",
30
+ "@microsoft/fast-foundation": "^2.46.2",
31
+ "@rws-framework/console": "^0.3.2",
32
+ "@types/moment": "^2.13.0",
33
+ "dragula": "^3.7.3",
34
+ "he": "^1.2.0",
35
+ "json5": "^2.2.3",
36
+ "lodash": "^4.17.21",
37
+ "moment": "^2.29.4",
38
+ "partial-json-parser": "^1.0.0",
39
+ "reflect-metadata": "^0.1.13",
40
+ "resolve-url-loader": "^5.0.0",
41
+ "sanitize-html": "^2.12.1",
42
+ "sass": "^1.69.7",
43
+ "scss-loading-animations": "^1.0.1",
44
+ "socket.io-client": "^4.7.2",
45
+ "ts-loader": "^9.4.4",
46
+ "tsc-watch": "^6.0.4",
47
+ "tslib": "^2.6.2",
48
+ "upload": "^1.3.2",
49
+ "url-router": "^13.0.0",
50
+ "uuid": "^9.0.1",
51
+ "v4": "^0.0.1"
52
+ },
53
+ "devDependencies": {
54
+ "@types/dragula": "^3.7.4",
55
+ "@types/eslint": "^6.0.0",
56
+ "@types/express-fileupload": "^1.4.4",
57
+ "@types/glob": "^8.1.0",
58
+ "@types/he": "^1.2.3",
59
+ "@types/sanitize-html": "^2.11.0",
60
+ "@types/uuid": "^9.0.7",
61
+ "@typescript-eslint/parser": "^5.0.0",
62
+ "clean-webpack-plugin": "^4.0.0",
63
+ "css-loader": "^6.8.1",
64
+ "css-minimizer-webpack-plugin": "^5.0.1",
65
+ "eslint": "^6.0.0",
66
+ "file-loader": "^6.2.0",
67
+ "html-webpack-plugin": "^5.5.3",
68
+ "loader-utils": "^3.2.1",
69
+ "mini-css-extract-plugin": "^2.7.6",
70
+ "minimatch": "^9.0.4",
71
+ "node-sass": "^9.0.0",
72
+ "sass-loader": "^13.3.2",
73
+ "source-map": "^0.7.4",
74
+ "style-loader": "^3.3.3",
75
+ "terser-webpack-plugin": "^5.3.9",
76
+ "ts-loader": "^9.4.4",
77
+ "ts-node": "^10.9.1",
78
+ "tsconfig-paths": "^4.2.0",
79
+ "tsconfig-paths-webpack-plugin": "^4.1.0",
80
+ "typedoc": "^0.25.4",
81
+ "typedoc-plugin-mermaid": "^1.10.0",
82
+ "typedoc-plugin-not-exported": "^0.1.6",
83
+ "typedoc-plugin-rename-defaults": "^0.7.0",
84
+ "typedoc-theme-hierarchy": "^4.1.2",
85
+ "typescript": "^5.1.6",
86
+ "url-loader": "^4.1.1",
87
+ "webpack": "^5.75.0",
88
+ "webpack-bundle-analyzer": "^4.10.1",
89
+ "webpack-cli": "^5.1.4",
90
+ "webpack-dev-server": "^4.15.1",
91
+ "webpack-node-externals": "^3.0.0"
92
+ },
93
+ "resolutions": {
94
+ "lodash": "^4.17.21"
95
+ },
96
+ "overrides": {
97
+ "lodash": "^4.17.21"
98
+ }
98
99
  }
99
- }
100
+
@@ -4,7 +4,7 @@ const webpack = require('webpack');
4
4
  const uglify = require('uglify-js')
5
5
  const HtmlWebpackPlugin = require('html-webpack-plugin');
6
6
  const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
7
-
7
+ const chalk = require('chalk');
8
8
  const RWSAfterPlugin = require('./webpack/rws_after_plugin');
9
9
  const tools = require('./_tools');
10
10
  const { _DEFAULT_CONFIG } = require('./cfg/_default.cfg');
@@ -18,25 +18,24 @@ const JsMinimizerPlugin = require('terser-webpack-plugin');
18
18
  const json5 = require('json5');
19
19
  const { rwsPath } = require('@rws-framework/console');
20
20
 
21
-
22
- const RWSWebpackWrapper = (config) => {
23
- const BuildConfigurator = new RWSConfigBuilder(RWSPath.findPackageDir(process.cwd()) + '/.rws.json', _DEFAULT_CONFIG);
21
+ const RWSWebpackWrapper = (config) => {
22
+ const BuildConfigurator = new RWSConfigBuilder(RWSPath.findPackageDir(process.cwd()) + '/.rws.json', {..._DEFAULT_CONFIG, ...config});
24
23
 
25
24
  config.packageDir = RWSPath.findPackageDir(process.cwd());
26
25
 
27
26
  const executionDir = RWSPath.relativize(BuildConfigurator.get('executionDir') || config.executionDir || process.cwd(), config.packageDir);
28
27
 
29
- const isDev = BuildConfigurator.get('dev') || config.dev;
30
- const isHotReload = BuildConfigurator.get('hot') || config.hot;
31
- const isReport = BuildConfigurator.get('report') || config.report;
28
+ const isDev = BuildConfigurator.get('dev', config.dev);
29
+ const isHotReload = BuildConfigurator.get('hot', config.hot);
30
+ const isReport = BuildConfigurator.get('report', config.report);
31
+ const isParted = BuildConfigurator.get('parted', config.parted || false);
32
32
 
33
- const isParted = BuildConfigurator.get('parted') || config.parted;
34
- const partedPrefix = BuildConfigurator.get('partedPrefix') || config.partedPrefix;
35
- const partedDirUrlPrefix = BuildConfigurator.get('partedDirUrlPrefix') || config.partedDirUrlPrefix;
33
+ const partedPrefix = BuildConfigurator.get('partedPrefix', config.partedPrefix);
34
+ const partedDirUrlPrefix = BuildConfigurator.get('partedDirUrlPrefix', config.partedDirUrlPrefix);
36
35
 
37
- const partedComponentsLocations = BuildConfigurator.get('partedComponentsLocations') || config.partedComponentsLocations;
38
- const customServiceLocations = BuildConfigurator.get('customServiceLocations') || config.customServiceLocations;
39
- const outputDir = RWSPath.relativize(BuildConfigurator.get('outputDir') || config.outputDir, config.packageDir);
36
+ const partedComponentsLocations = BuildConfigurator.get('partedComponentsLocations', config.partedComponentsLocations);
37
+ const customServiceLocations = BuildConfigurator.get('customServiceLocations', config.customServiceLocations);
38
+ const outputDir = RWSPath.relativize(BuildConfigurator.get('outputDir', config.outputDir), config.packageDir);
40
39
 
41
40
  const outputFileName = BuildConfigurator.get('outputFileName') || config.outputFileName;
42
41
  const publicDir = BuildConfigurator.get('publicDir') || config.publicDir;
@@ -44,9 +43,27 @@ const RWSWebpackWrapper = (config) => {
44
43
 
45
44
  const publicIndex = BuildConfigurator.get('publicIndex') || config.publicIndex;
46
45
 
47
-
48
- const tsConfigPath = rwsPath.relativize(BuildConfigurator.get('tsConfigPath') || config.tsConfigPath, executionDir);
49
-
46
+
47
+ const tsConfigPath = rwsPath.relativize(BuildConfigurator.get('tsConfigPath') || config.tsConfigPath, executionDir);
48
+
49
+
50
+ RWSPath.removeDirectory(outputDir, true);
51
+
52
+ console.log(chalk.green('Build started with'))
53
+ console.log({
54
+ executionDir,
55
+ tsConfigPath,
56
+ outputDir,
57
+ dev: isDev,
58
+ publicDir,
59
+ parted: isParted,
60
+ partedPrefix,
61
+ partedDirUrlPrefix
62
+ });
63
+
64
+
65
+ //AFTER OPTION DEFINITIONS
66
+
50
67
  let WEBPACK_PLUGINS = [
51
68
  new webpack.DefinePlugin({
52
69
  'process.env._RWS_DEFAULTS': JSON.stringify(BuildConfigurator.exportDefaultConfig()),
@@ -55,21 +72,6 @@ const RWSWebpackWrapper = (config) => {
55
72
  new webpack.ContextReplacementPlugin(/moment[\/\\]locale$/, /en-gb/)
56
73
  ];
57
74
 
58
- // if(isParted){
59
- // WEBPACK_PLUGINS.push(new webpack.BannerPlugin({
60
- // banner: `if(!window.RWS_PARTS_LOADED){
61
- // const script = document.createElement('script');
62
- // script.src = '${partedDirUrlPrefix}/${partedPrefix}.vendors.js';
63
- // script.type = 'text/javascript';
64
- // document.body.appendChild(script);
65
- // window.RWS_PARTS_LOADED = true;
66
- // }`.replace('\n', ''),
67
- // raw: true,
68
- // entryOnly: true,
69
- // // include: 'client'
70
- // }));
71
- // }
72
-
73
75
  const WEBPACK_AFTER_ACTIONS = config.actions || [];
74
76
 
75
77
  const aliases = config.aliases = {};
@@ -87,7 +89,7 @@ const RWSWebpackWrapper = (config) => {
87
89
  }));
88
90
  }
89
91
 
90
- WEBPACK_PLUGINS = [...WEBPACK_PLUGINS, new webpack.optimize.ModuleConcatenationPlugin(), ...overridePlugins];
92
+ WEBPACK_PLUGINS = [...WEBPACK_PLUGINS, ...overridePlugins];
91
93
 
92
94
 
93
95
  if (isReport) {
@@ -106,18 +108,18 @@ const RWSWebpackWrapper = (config) => {
106
108
 
107
109
  const assetsToCopy = BuildConfigurator.get('copyAssets') || config.copyAssets;
108
110
 
109
- if (!!assetsToCopy) {
111
+ if (!!assetsToCopy) {
110
112
  WEBPACK_AFTER_ACTIONS.push({
111
113
  type: 'copy',
112
114
  actionHandler: assetsToCopy
113
115
  });
114
116
  }
115
117
 
116
- if (WEBPACK_AFTER_ACTIONS.length) {
118
+ if (WEBPACK_AFTER_ACTIONS.length) {
117
119
  WEBPACK_PLUGINS.push(new RWSAfterPlugin({ actions: WEBPACK_AFTER_ACTIONS }));
118
120
  }
119
121
 
120
- const splitInfoJson = config.outputDir + '/rws_chunks_info.json'
122
+ const rwsInfoJson = outputDir + '/rws_info.json'
121
123
  const automatedEntries = {};
122
124
 
123
125
  const foundRWSUserClasses = tools.findComponentFilesWithText(executionDir, '@RWSView', ['dist', 'node_modules', '@rws-framework/client']);
@@ -137,20 +139,11 @@ const RWSWebpackWrapper = (config) => {
137
139
  });
138
140
  }
139
141
 
140
- const optimConfig = {
141
- minimize: true,
142
- minimizer: isDev ? [
143
- new TerserPlugin({
144
- terserOptions: {
145
- mangle: false, //@error breaks FAST view stuff if enabled for all assets
146
- output: {
147
- comments: false
148
- },
149
- },
150
- extractComments: false,
151
- parallel: true,
152
- })
153
- ] : [
142
+ const optimConfig = {};
143
+
144
+ if(!isDev){
145
+ optimConfig.minimize = true;
146
+ optimConfig.minimizer = [
154
147
  new TerserPlugin({
155
148
  terserOptions: {
156
149
  keep_classnames: true, // Prevent mangling of class names
@@ -167,10 +160,13 @@ const RWSWebpackWrapper = (config) => {
167
160
  parallel: true,
168
161
  }),
169
162
  new CssMinimizerPlugin(),
170
- ],
171
- };
163
+ ];
164
+ }
165
+
172
166
 
173
167
  if (isParted) {
168
+ WEBPACK_PLUGINS.push(new webpack.BannerPlugin(tools.getPartedModeVendorsBannerParams(partedDirUrlPrefix, partedPrefix)));
169
+
174
170
  if (partedComponentsLocations) {
175
171
  partedComponentsLocations.forEach((componentDir) => {
176
172
  RWSComponents = [...RWSComponents, ...(tools.findComponentFilesWithText(path.resolve(componentDir), '@RWSView', ['dist', 'node_modules', '@rws-framework/client']))];
@@ -188,7 +184,8 @@ const RWSWebpackWrapper = (config) => {
188
184
  automatedEntries[fileInfo.sanitName] = fileInfo.filePath;
189
185
  });
190
186
 
191
- fs.writeFileSync(splitInfoJson, JSON.stringify(Object.keys(automatedEntries), null, 2));
187
+ fs.writeFileSync(rwsInfoJson, JSON.stringify({ components: Object.keys(automatedEntries) }, null, 2));
188
+
192
189
  optimConfig.splitChunks = {
193
190
  cacheGroups: {
194
191
  vendor: {
@@ -215,18 +212,14 @@ const RWSWebpackWrapper = (config) => {
215
212
  }
216
213
  }
217
214
  };
218
- } else {
219
- if (fs.existsSync(splitInfoJson)) {
220
- fs.unlinkSync(splitInfoJson);
221
- }
222
215
  }
223
216
 
224
217
  const tsValidated = tools.setupTsConfig(tsConfigPath, executionDir);
225
218
 
226
- if(!tsValidated){
219
+ if (!tsValidated) {
227
220
  throw new Error('RWS Webpack build failed.');
228
221
  }
229
-
222
+
230
223
  const cfgExport = {
231
224
  entry: {
232
225
  client: config.entry,
@@ -245,31 +238,26 @@ const RWSWebpackWrapper = (config) => {
245
238
  modules: modules_setup,
246
239
  alias: {
247
240
  ...aliases
248
- },
249
- plugins: [
250
- // new TsconfigPathsPlugin({configFile: config.tsConfigPath})
251
- ]
241
+ }
252
242
  },
253
243
  module: {
254
- rules: [
244
+ rules: [
255
245
  {
256
246
  test: /\.html$/,
257
247
  use: [
258
- path.resolve(__dirname, './webpack/rws_fast_html_loader.js')
248
+ path.resolve(__dirname, './webpack/loaders/rws_fast_html_loader.js')
259
249
  ],
260
250
  },
261
251
  {
262
252
  test: /\.css$/,
263
253
  use: [
264
- 'css-loader',
265
- // path.resolve(__dirname, './webpack/rws_fast_css_loader.js')
254
+ 'css-loader',
266
255
  ],
267
256
  },
268
257
  {
269
258
  test: /\.scss$/,
270
- use: [
271
- // 'css-loader',
272
- path.resolve(__dirname, './webpack/rws_fast_scss_loader.js'),
259
+ use: [
260
+ path.resolve(__dirname, './webpack/loaders/rws_fast_scss_loader.js'),
273
261
  ],
274
262
  },
275
263
  {
@@ -279,12 +267,12 @@ const RWSWebpackWrapper = (config) => {
279
267
  loader: 'ts-loader',
280
268
  options: {
281
269
  allowTsInNodeModules: true,
282
- configFile: path.resolve(tsConfigPath)
270
+ configFile: path.resolve(tsConfigPath)
283
271
  }
284
272
  },
285
273
  {
286
- loader: path.resolve(__dirname, './webpack/rws_fast_ts_loader.js'),
287
- }
274
+ loader: path.resolve(__dirname, './webpack/loaders/rws_fast_ts_loader.js'),
275
+ }
288
276
  ],
289
277
  exclude: /node_modules\/(?!\@rws-framework\/client)/,
290
278
  }
@@ -294,6 +282,15 @@ const RWSWebpackWrapper = (config) => {
294
282
  optimization: optimConfig,
295
283
  }
296
284
 
285
+ // if(isDev){
286
+ cfgExport.module.rules.push({
287
+ test: /\.js$/,
288
+ use: [
289
+ path.resolve(__dirname, './webpack/loaders/rws_uncomments_loader.js'),
290
+ ],
291
+ })
292
+ // }
293
+
297
294
  if (isHotReload) {
298
295
  cfgExport.devServer = {
299
296
  hot: true,
@@ -0,0 +1,46 @@
1
+ import RWSWindow, { RWSWindowComponentRegister } from "../interfaces/RWSWindow";
2
+ import { RWSClientInstance } from "../client";
3
+ import RWSViewComponent, { IWithCompose } from "../components/_component";
4
+ type RWSInfoType = { components: string[] };
5
+
6
+ async function loadPartedComponents(this: RWSClientInstance): Promise<void> {
7
+ this.assignClientToBrowser();
8
+
9
+ const componentParts: RWSInfoType = await this.apiService.get<RWSInfoType>(this.appConfig.get('partedDirUrlPrefix') + '/rws_info.json');
10
+
11
+ componentParts.components.forEach((componentName: string, key: number) => {
12
+ const partUrl = `${this.appConfig.get('partedDirUrlPrefix')}/${this.appConfig.get('partedPrefix')}.${componentName}.js`;
13
+
14
+ const script: HTMLScriptElement = document.createElement('script');
15
+ script.src = partUrl;
16
+ script.async = true;
17
+ script.type = 'text/javascript';
18
+ document.body.appendChild(script);
19
+
20
+ console.log(`Appended ${componentParts.components[key]} component (${partUrl})`);
21
+ });
22
+ }
23
+
24
+ function defineAllComponents() {
25
+ const richWindowComponents: RWSWindowComponentRegister = (window as Window & RWSWindow).RWS.components;
26
+
27
+ Object.keys(richWindowComponents).map(key => richWindowComponents[key].component).forEach((el: IWithCompose<RWSViewComponent>) => {
28
+ el.define(el as any, el.definition);
29
+ });
30
+ }
31
+
32
+ function getBinds(this: RWSClientInstance){
33
+ return {
34
+ loadPartedComponents: loadPartedComponents.bind(this)
35
+ };
36
+ }
37
+
38
+ export default getBinds;
39
+
40
+ const ComponentHelperStatic = {
41
+ defineAllComponents: defineAllComponents
42
+ }
43
+
44
+ export {
45
+ ComponentHelperStatic
46
+ }
@@ -0,0 +1,120 @@
1
+ import { IRWSConfig, IRWSUser } from "../index";
2
+ import { RWSClientInstance } from "../client";
3
+ import startClient from '../run';
4
+
5
+ type RWSInfoType = { components: string[] };
6
+
7
+ function getUser(this: RWSClientInstance): IRWSUser {
8
+
9
+ const localSaved = localStorage.getItem('the_rws_user');
10
+
11
+ if (localSaved) {
12
+ this.setUser(JSON.parse(localSaved) as IRWSUser);
13
+ }
14
+
15
+ return this.user;
16
+ }
17
+
18
+ function setUser(this: RWSClientInstance, user: IRWSUser): RWSClientInstance {
19
+ if (!user || !user?.jwt_token) {
20
+ console.warn('[RWS Client Warning]', 'Passed user is not valid', user);
21
+ return this;
22
+ }
23
+
24
+ this.user = user;
25
+
26
+ this.apiService.setToken(this.user.jwt_token);
27
+ this.wsService.setUser(this.user);
28
+
29
+ localStorage.setItem('the_rws_user', JSON.stringify(this.user));
30
+
31
+ return this;
32
+ }
33
+
34
+ function pushDataToServiceWorker(this: RWSClientInstance, type: string, data: any, asset_type: string = 'data_push'): void {
35
+ let tries = 0;
36
+
37
+ const doIt: () => void = () => {
38
+ try {
39
+ this.swService.sendDataToServiceWorker(type, data, asset_type);
40
+ } catch (e) {
41
+ if (tries < 3) {
42
+ setTimeout(() => { doIt(); }, 300);
43
+ tries++;
44
+ }
45
+ }
46
+ };
47
+
48
+ doIt();
49
+ }
50
+
51
+ function pushUserToServiceWorker(this: RWSClientInstance, userData: any) {
52
+ this.setUser(userData);
53
+ this.pushDataToServiceWorker('SET_USER', userData, 'logged_user');
54
+ }
55
+
56
+ function get(this: RWSClientInstance, key: string): any | null
57
+ {
58
+ if(Object.keys(this.customServices).includes(key)){
59
+ return this.customServices[key];
60
+ }
61
+
62
+ if(Object.keys(this.defaultServices).includes(key)){
63
+ return this.defaultServices[key];
64
+ }
65
+
66
+ return null;
67
+ }
68
+
69
+ async function setup(this: RWSClientInstance, config: IRWSConfig = {}): Promise<IRWSConfig> {
70
+ if (this.isSetup) {
71
+ return this.config;
72
+ }
73
+
74
+ this.config = { ...this.config, ...config };
75
+ this.appConfig.mergeConfig(this.config);
76
+
77
+ if (this.appConfig.get('parted')) {
78
+ await this.loadPartedComponents();
79
+ }
80
+
81
+
82
+ this.isSetup = true;
83
+ return this.config;
84
+ }
85
+
86
+ async function start(this: RWSClientInstance, config: IRWSConfig = {}): Promise<RWSClientInstance> {
87
+ this.config = { ...this.config, ...config };
88
+
89
+ if (!this.isSetup) {
90
+ this.config = await this.setup(this.config);
91
+ }
92
+
93
+ if (Object.keys(config).length) {
94
+ this.appConfig.mergeConfig(this.config);
95
+ }
96
+
97
+ if (this.config.user && !this.config.dontPushToSW) {
98
+ this.pushUserToServiceWorker(this.user);
99
+ }
100
+
101
+ await startClient(this.appConfig, this.wsService, this.notifyService, this.routingService);
102
+
103
+ await this.initCallback();
104
+
105
+ return this;
106
+ }
107
+
108
+ function getBinds(this: RWSClientInstance) {
109
+ return {
110
+ start: start.bind(this),
111
+ setup: setup.bind(this),
112
+ get: get.bind(this),
113
+ setUser: setUser.bind(this),
114
+ getUser: getUser.bind(this),
115
+ pushDataToServiceWorker: pushDataToServiceWorker.bind(this),
116
+ pushUserToServiceWorker: pushUserToServiceWorker.bind(this)
117
+ };
118
+ }
119
+
120
+ export default getBinds;
@@ -0,0 +1,28 @@
1
+ import { loadRWSRichWindow } from "../interfaces/RWSWindow";
2
+ import { RWSClientInstance } from "../client";
3
+ type RWSInfoType = { components: string[] };
4
+
5
+ async function loadServices(this: RWSClientInstance){
6
+ const richWindow = loadRWSRichWindow();
7
+
8
+ for (const serviceKey of Object.keys(richWindow.RWS._registered)){
9
+ const currentService = this._container.get(richWindow.RWS._registered[serviceKey]);
10
+
11
+ if(currentService.isInClient() && !Object.keys(this.customServices).includes(serviceKey)){
12
+ this.customServices[serviceKey] = currentService;
13
+ }
14
+
15
+ if(currentService.isDefault() && !Object.keys(this.defaultServices).includes(serviceKey)){
16
+ this.defaultServices[serviceKey] = currentService;
17
+ }
18
+ }
19
+ }
20
+
21
+
22
+ function getBinds(this: RWSClientInstance){
23
+ return {
24
+ loadServices: loadServices.bind(this),
25
+ };
26
+ }
27
+
28
+ export default getBinds;