@cocreate/users 1.22.9 → 1.22.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.
package/src/server.js CHANGED
@@ -1,128 +1,128 @@
1
- class CoCreateUser {
2
- constructor(crud) {
3
- this.wsManager = crud.wsManager
4
- this.crud = crud
5
- this.init()
6
- }
7
-
8
- init() {
9
- if (this.wsManager) {
10
- this.wsManager.on('signUp', (socket, data) => this.signUp(socket, data));
11
- this.wsManager.on('signIn', (socket, data) => this.signIn(socket, data))
12
- this.wsManager.on('userStatus', (socket, data) => this.userStatus(socket, data))
13
- }
14
- }
15
-
16
- async signUp(socket, data) {
17
- const self = this;
18
- try {
19
-
20
- if (data.user) {
21
- const response = await this.crud.createDocument(data.user)
22
- this.wsManager.broadcast(socket, 'createDocument', response);
23
- }
24
-
25
- if (data.userKey) {
26
- const response = await this.crud.createDocument(data.userKey)
27
- this.wsManager.broadcast(socket, 'createDocument', response);
28
- }
29
-
30
- self.wsManager.send(socket, 'signUp', data);
31
-
32
- } catch (error) {
33
- console.log('createDocument error', error);
34
- }
35
- }
36
-
37
-
38
- /**
39
- data = {
40
- namespace: string,
41
- collection: string,
42
- data: object,
43
- eId: string,
44
- key: string,
45
- organization_id: string
46
- }
47
- **/
48
- async signIn(socket, data) {
49
- const self = this;
50
- try {
51
- this.crud.readDocument(data).then(async (data) => {
52
- let response = {
53
- success: false,
54
- message: "signIn failed",
55
- status: "failed",
56
- userStatus: 'off',
57
- uid: data.uid
58
- }
59
-
60
- if (data.document[0] && data.document[0]._id && self.wsManager.authenticate) {
61
- const user_id = data.document[0].key
62
- const token = await self.wsManager.authenticate.generateToken({ user_id });
63
-
64
- if (token && token != 'null') {
65
- response = {
66
- success: true,
67
- message: "signIn successful",
68
- status: "success",
69
- userStatus: 'on',
70
- user_id,
71
- token,
72
- uid: data.uid
73
- };
74
-
75
- // if (data.organization_id != process.env.organization_id) {
76
- // let Data = { organization_id: process.env.organization_id }
77
- // Data.document['_id'] = data.document[0]._id
78
- // Data.document['lastsignIn'] = data.document[0].lastsignIn
79
- // Data.document['organization_id'] = process.env.organization_id
80
- // crud.updateDocument(Data)
81
- // }
82
- }
83
- }
84
- self.wsManager.send(socket, 'signIn', response)
85
- self.wsManager.broadcast(socket, 'updateUserStatus', {
86
- user_id: response.user_id,
87
- userStatus: response.userStatus,
88
- organization_id: response.organization_id
89
- })
90
- })
91
-
92
- } catch (error) {
93
- console.log('signIn failed', error);
94
- }
95
- }
96
-
97
-
98
- /**
99
- * status: 'on/off/idle'
100
- */
101
- async userStatus(socket, data) {
102
- const self = this;
103
- try {
104
- if (!data.user_id || !data.userStatus)
105
- return
106
- data.collection = 'users'
107
- data['document'] = {
108
- _id: data.user_id,
109
- userStatus: data.userStatus
110
- }
111
-
112
- this.crud.updateDocument(data).then((data) => {
113
- // self.wsManager.broadcast(socket, 'updateUserStatus', data)
114
- self.wsManager.broadcast(socket, 'updateUserStatus', {
115
- user_id: data.user_id,
116
- userStatus: data.userStatus,
117
- organization_id: data.organization_id || socket.config.organization_id
118
- })
119
-
120
- })
121
-
122
- } catch (error) {
123
- console.log('userStatus error')
124
- }
125
- }
126
- }
127
-
1
+ class CoCreateUser {
2
+ constructor(crud) {
3
+ this.wsManager = crud.wsManager
4
+ this.crud = crud
5
+ this.init()
6
+ }
7
+
8
+ init() {
9
+ if (this.wsManager) {
10
+ this.wsManager.on('signUp', (socket, data) => this.signUp(socket, data));
11
+ this.wsManager.on('signIn', (socket, data) => this.signIn(socket, data))
12
+ this.wsManager.on('userStatus', (socket, data) => this.userStatus(socket, data))
13
+ }
14
+ }
15
+
16
+ async signUp(socket, data) {
17
+ const self = this;
18
+ try {
19
+
20
+ if (data.user) {
21
+ const response = await this.crud.createDocument(data.user)
22
+ this.wsManager.broadcast(socket, 'createDocument', response);
23
+ }
24
+
25
+ if (data.userKey) {
26
+ const response = await this.crud.createDocument(data.userKey)
27
+ this.wsManager.broadcast(socket, 'createDocument', response);
28
+ }
29
+
30
+ self.wsManager.send(socket, 'signUp', data);
31
+
32
+ } catch (error) {
33
+ console.log('createDocument error', error);
34
+ }
35
+ }
36
+
37
+
38
+ /**
39
+ data = {
40
+ namespace: string,
41
+ collection: string,
42
+ data: object,
43
+ eId: string,
44
+ key: string,
45
+ organization_id: string
46
+ }
47
+ **/
48
+ async signIn(socket, data) {
49
+ const self = this;
50
+ try {
51
+ this.crud.readDocument(data).then(async (data) => {
52
+ let response = {
53
+ success: false,
54
+ message: "signIn failed",
55
+ status: "failed",
56
+ userStatus: 'off',
57
+ uid: data.uid
58
+ }
59
+
60
+ if (data.document[0] && data.document[0]._id && self.wsManager.authenticate) {
61
+ const user_id = data.document[0].key
62
+ const token = await self.wsManager.authenticate.generateToken({ user_id });
63
+
64
+ if (token && token != 'null') {
65
+ response = {
66
+ success: true,
67
+ message: "signIn successful",
68
+ status: "success",
69
+ userStatus: 'on',
70
+ user_id,
71
+ token,
72
+ uid: data.uid
73
+ };
74
+
75
+ // if (data.organization_id != process.env.organization_id) {
76
+ // let Data = { organization_id: process.env.organization_id }
77
+ // Data.document['_id'] = data.document[0]._id
78
+ // Data.document['lastsignIn'] = data.document[0].lastsignIn
79
+ // Data.document['organization_id'] = process.env.organization_id
80
+ // crud.updateDocument(Data)
81
+ // }
82
+ }
83
+ }
84
+ self.wsManager.send(socket, 'signIn', response)
85
+ self.wsManager.broadcast(socket, 'updateUserStatus', {
86
+ user_id: response.user_id,
87
+ userStatus: response.userStatus,
88
+ organization_id: response.organization_id
89
+ })
90
+ })
91
+
92
+ } catch (error) {
93
+ console.log('signIn failed', error);
94
+ }
95
+ }
96
+
97
+
98
+ /**
99
+ * status: 'on/off/idle'
100
+ */
101
+ async userStatus(socket, data) {
102
+ const self = this;
103
+ try {
104
+ if (!data.user_id || !data.userStatus)
105
+ return
106
+ data.collection = 'users'
107
+ data['document'] = {
108
+ _id: data.user_id,
109
+ userStatus: data.userStatus
110
+ }
111
+
112
+ this.crud.updateDocument(data).then((data) => {
113
+ // self.wsManager.broadcast(socket, 'updateUserStatus', data)
114
+ self.wsManager.broadcast(socket, 'updateUserStatus', {
115
+ user_id: data.user_id,
116
+ userStatus: data.userStatus,
117
+ organization_id: data.organization_id || socket.config.organization_id
118
+ })
119
+
120
+ })
121
+
122
+ } catch (error) {
123
+ console.log('userStatus error')
124
+ }
125
+ }
126
+ }
127
+
128
128
  module.exports = CoCreateUser;
package/webpack.config.js CHANGED
@@ -1,84 +1,84 @@
1
- const path = require("path")
2
- const TerserPlugin = require("terser-webpack-plugin")
3
- const MiniCssExtractPlugin = require("mini-css-extract-plugin")
4
- let isProduction = process.env.NODE_ENV === "production"
5
- const { CleanWebpackPlugin } = require("clean-webpack-plugin")
6
-
7
- module.exports = {
8
- entry: {
9
- "CoCreate-users": "./src/index.js",
10
- },
11
- output: {
12
- path: path.resolve(__dirname, "dist"),
13
- filename: isProduction ? "[name].min.js" : "[name].js",
14
- libraryTarget: "umd",
15
- libraryExport: "default",
16
- library: ["CoCreate", "users"],
17
- globalObject: "this",
18
- },
19
-
20
- plugins: [
21
- new CleanWebpackPlugin(),
22
- new MiniCssExtractPlugin({
23
- filename: "[name].css",
24
- }),
25
- ],
26
- // Default mode for Webpack is production.
27
- // Depending on mode Webpack will apply different things
28
- // on final bundle. For now we don't need production's JavaScript
29
- // minifying and other thing so let's set mode to development
30
- mode: isProduction ? "production" : "development",
31
- module: {
32
- rules: [
33
- {
34
- test: /.js$/,
35
- exclude: /(node_modules)/,
36
- use: {
37
- loader: "babel-loader",
38
- options: {
39
- plugins: ["@babel/plugin-transform-modules-commonjs"],
40
- },
41
- },
42
- },
43
- {
44
- test: /.css$/i,
45
- use: [
46
- { loader: "style-loader", options: { injectType: "linkTag" } },
47
- "file-loader",
48
- ],
49
- },
50
- ],
51
- },
52
-
53
- // add source map
54
- ...(isProduction ? {} : { devtool: "eval-source-map" }),
55
-
56
- optimization: {
57
- minimize: true,
58
- minimizer: [
59
- new TerserPlugin({
60
- extractComments: true,
61
- // cache: true,
62
- parallel: true,
63
- // sourceMap: true, // Must be set to true if using source-maps in production
64
- terserOptions: {
65
- // https://github.com/webpack-contrib/terser-webpack-plugin#terseroptions
66
- // extractComments: 'all',
67
- compress: {
68
- drop_console: true,
69
- },
70
- },
71
- }),
72
- ],
73
- splitChunks: {
74
- chunks: "all",
75
- minSize: 200,
76
- // maxSize: 99999,
77
- //minChunks: 1,
78
-
79
- cacheGroups: {
80
- defaultVendors: false,
81
- },
82
- },
83
- },
84
- }
1
+ const path = require("path")
2
+ const TerserPlugin = require("terser-webpack-plugin")
3
+ const MiniCssExtractPlugin = require("mini-css-extract-plugin")
4
+ let isProduction = process.env.NODE_ENV === "production"
5
+ const { CleanWebpackPlugin } = require("clean-webpack-plugin")
6
+
7
+ module.exports = {
8
+ entry: {
9
+ "CoCreate-users": "./src/index.js",
10
+ },
11
+ output: {
12
+ path: path.resolve(__dirname, "dist"),
13
+ filename: isProduction ? "[name].min.js" : "[name].js",
14
+ libraryTarget: "umd",
15
+ libraryExport: "default",
16
+ library: ["CoCreate", "users"],
17
+ globalObject: "this",
18
+ },
19
+
20
+ plugins: [
21
+ new CleanWebpackPlugin(),
22
+ new MiniCssExtractPlugin({
23
+ filename: "[name].css",
24
+ }),
25
+ ],
26
+ // Default mode for Webpack is production.
27
+ // Depending on mode Webpack will apply different things
28
+ // on final bundle. For now we don't need production's JavaScript
29
+ // minifying and other thing so let's set mode to development
30
+ mode: isProduction ? "production" : "development",
31
+ module: {
32
+ rules: [
33
+ {
34
+ test: /.js$/,
35
+ exclude: /(node_modules)/,
36
+ use: {
37
+ loader: "babel-loader",
38
+ options: {
39
+ plugins: ["@babel/plugin-transform-modules-commonjs"],
40
+ },
41
+ },
42
+ },
43
+ {
44
+ test: /.css$/i,
45
+ use: [
46
+ { loader: "style-loader", options: { injectType: "linkTag" } },
47
+ "file-loader",
48
+ ],
49
+ },
50
+ ],
51
+ },
52
+
53
+ // add source map
54
+ ...(isProduction ? {} : { devtool: "eval-source-map" }),
55
+
56
+ optimization: {
57
+ minimize: true,
58
+ minimizer: [
59
+ new TerserPlugin({
60
+ extractComments: true,
61
+ // cache: true,
62
+ parallel: true,
63
+ // sourceMap: true, // Must be set to true if using source-maps in production
64
+ terserOptions: {
65
+ // https://github.com/webpack-contrib/terser-webpack-plugin#terseroptions
66
+ // extractComments: 'all',
67
+ compress: {
68
+ drop_console: true,
69
+ },
70
+ },
71
+ }),
72
+ ],
73
+ splitChunks: {
74
+ chunks: "all",
75
+ minSize: 200,
76
+ // maxSize: 99999,
77
+ //minChunks: 1,
78
+
79
+ cacheGroups: {
80
+ defaultVendors: false,
81
+ },
82
+ },
83
+ },
84
+ }