@gudhub/core 1.1.77 → 1.1.78

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.
@@ -239,6 +239,11 @@ export class AppProcessor {
239
239
  this.updateAppsListInStorage(received_app_list);
240
240
  this.applistReceived = true;
241
241
  app_list = received_app_list;
242
+
243
+ // Here we get default user's app
244
+ // We do it here to do it only once
245
+ // We do it because we need to initialize WebSockets, which we do in getApp method
246
+ this.getApp(this.storage.getUser().app_init);
242
247
  }
243
248
 
244
249
  return app_list;
@@ -5,19 +5,75 @@ export class Auth {
5
5
  }
6
6
 
7
7
  async login({ username, password } = {}) {
8
- let user = await this.req.axiosRequest({
9
- method: 'POST',
10
- url: `${this.req.root}/auth/login`,
11
- form: {
12
- username,
13
- password,
14
- },
15
- });
8
+ const user = await this.loginApi(username, password);
9
+ this.storage.updateUser(user);
10
+ return user;
11
+ }
12
+
13
+ async logout(token) {
14
+ const response = await this.logoutApi(token);
15
+ return response;
16
+ }
17
+
18
+ async signup(user) {
19
+ const newUser = await this.signupApi(user);
20
+ return newUser;
21
+ }
22
+
23
+ async updateToken(auth_key) {
24
+ const user = await this.updateTokenApi(auth_key);
25
+ return user;
26
+ }
27
+
28
+ async updateUser(userData) {
29
+ const user = await this.updateUserApi(userData);
30
+ this.storage.updateUser(user);
31
+ return user;
32
+ }
33
+
34
+ async updateAvatar(imageData) {
35
+ const user = await this.avatarUploadApi(imageData);
16
36
  this.storage.updateUser(user);
17
37
  return user;
18
38
  }
19
39
 
20
- logout(token) {
40
+ async getUsersList(keyword) {
41
+ const usersList = await this.getUsersListApi(keyword);
42
+ return usersList;
43
+ }
44
+
45
+ async loginApi(username, password) {
46
+ try {
47
+ const user = await this.req.axiosRequest({
48
+ method: 'POST',
49
+ url: `${this.req.root}/auth/login`,
50
+ form: {
51
+ username,
52
+ password,
53
+ },
54
+ });
55
+ return user;
56
+ } catch (error) {
57
+ console.log(error);
58
+ }
59
+ }
60
+
61
+ async updateTokenApi(auth_key) {
62
+ try {
63
+ const user = await this.req.axiosRequest({
64
+ method: 'POST',
65
+ url: `${this.req.root}/auth/login`,
66
+ form: {
67
+ auth_key,
68
+ },
69
+ });
70
+ return user;
71
+ } catch (error) {
72
+ console.log(error);
73
+ }
74
+ }
75
+
76
+ logoutApi(token) {
21
77
  return this.req.post({
22
78
  url: "/auth/logout",
23
79
  form: {
@@ -26,7 +82,7 @@ export class Auth {
26
82
  });
27
83
  }
28
84
 
29
- signup(user) {
85
+ signupApi(user) {
30
86
  return this.req.axiosRequest({
31
87
  method: 'POST',
32
88
  url: `${this.req.root}/auth/singup`,
@@ -34,7 +90,7 @@ export class Auth {
34
90
  });
35
91
  }
36
92
 
37
- getUsersList(keyword) {
93
+ getUsersListApi(keyword) {
38
94
  return this.req.get({
39
95
  url: "/auth/userlist",
40
96
  params: {
@@ -52,16 +108,6 @@ export class Auth {
52
108
  });
53
109
  }
54
110
 
55
- updateToken(auth_key) {
56
- return this.req.axiosRequest({
57
- method: 'POST',
58
- url: `${this.req.root}/auth/login`,
59
- form: {
60
- auth_key,
61
- },
62
- });
63
- }
64
-
65
111
  avatarUploadApi(image) {
66
112
  return this.req.post({
67
113
  url: "/auth/avatar-upload",
@@ -130,15 +176,4 @@ export class Auth {
130
176
  return accesstoken;
131
177
  }
132
178
 
133
- async updateUser(userData) {
134
- const user = await this.updateUserApi(userData);
135
- this.storage.updateUser(user);
136
- return user;
137
- }
138
-
139
- async updateAvatar(imageData) {
140
- const user = await this.avatarUploadApi(imageData);
141
- this.storage.updateUser(user);
142
- return user;
143
- }
144
179
  }
@@ -273,6 +273,19 @@ export default async function createAngularModuleInstance(gudhub, module_id, mod
273
273
  }
274
274
  });
275
275
  },
276
+
277
+ //*************** ON MESSAGE ****************//
278
+
279
+ onMessage: function(appId, userId, response) {
280
+ return new Promise(async (resolve) => {
281
+ const onMessageFunction = importedClass.onMessage;
282
+ if(onMessageFunction) {
283
+ const result = await onMessageFunction(appId, userId, response);
284
+ resolve(result);
285
+ }
286
+ resolve(null);
287
+ })
288
+ },
276
289
  }
277
290
 
278
291
  // We need these methods in browser environment only
@@ -165,6 +165,19 @@ export default async function createClassInstance(gudhub, module_id, js_url, css
165
165
  });
166
166
  },
167
167
 
168
+ //*************** ON MESSAGE ****************//
169
+
170
+ onMessage: function(appId, userId, response) {
171
+ return new Promise(async (resolve) => {
172
+ const onMessageFunction = importedClass.onMessage;
173
+ if(onMessageFunction) {
174
+ const result = await onMessageFunction(appId, userId, response);
175
+ resolve(result);
176
+ }
177
+ resolve(null);
178
+ })
179
+ },
180
+
168
181
  //*************** EXTEND CONTROLLER ****************//
169
182
 
170
183
  extendController: function (actionScope) {
@@ -27,7 +27,7 @@ export class Interpritate {
27
27
  }
28
28
 
29
29
  for(var i = 0; i < currentIntrpr.length; i++) {
30
- if(currentIntrpr[i].settings.condition_filter && currentIntrpr[i].settings.filters_list.length > 0) {
30
+ if(currentIntrpr[i].settings && currentIntrpr[i].settings.condition_filter && currentIntrpr[i].settings.filters_list.length > 0) {
31
31
  const item = await gudhub.getItem(appId, itemId);
32
32
  if(item) {
33
33
  const filteredItems = gudhub.filter([item], currentIntrpr[i].settings.filters_list);
@@ -918,6 +918,15 @@ export default function generateModulesList(async_modules_path, file_server_url,
918
918
  type: 'gh_element',
919
919
  technology: 'class'
920
920
  },
921
+ {
922
+ data_type: 'conversations',
923
+ name: 'Conversations',
924
+ icon: 'timeline',
925
+ js: 'https://gudhub.com/modules/conversation/dist/main.js',
926
+ css: 'https://gudhub.com/modules/conversation/dist/style.css',
927
+ type: 'gh_element',
928
+ technology: 'class'
929
+ },
921
930
  /* AUTOMATION MODULES */
922
931
  /*
923
932
  We have next types for automations:
@@ -0,0 +1,42 @@
1
+ export class WebSocketEmitter {
2
+
3
+ constructor(gudhub) {
4
+ this.gudhub = gudhub;
5
+ }
6
+
7
+ async emitToUser(user_id, data) {
8
+
9
+ const message = {
10
+ user_id,
11
+ data: typeof data === 'object' ? JSON.stringify(data) : data
12
+ }
13
+
14
+ const response = await this.gudhub.req.post({
15
+ url: '/ws/emit-to-user',
16
+ form: message
17
+ });
18
+
19
+ return response;
20
+
21
+ }
22
+
23
+ async broadcastToAppSubscribers(app_id, data_type, data) {
24
+
25
+ const message = {
26
+ app_id,
27
+ data: JSON.stringify({
28
+ data_type,
29
+ data
30
+ })
31
+ }
32
+
33
+ const response = await this.gudhub.req.post({
34
+ url: '/ws/broadcast-to-app-subscribers',
35
+ form: message
36
+ });
37
+
38
+ return response;
39
+
40
+ }
41
+
42
+ }
@@ -52,6 +52,17 @@ export function WebsocketHandler(gudhub, message) {
52
52
  gudhub.documentManager.emitDocumentInsert(message.response);
53
53
  console.log('/api/new/document/insert-one - ', message);
54
54
  break;
55
+ case '/ws/emit-to-user':
56
+ console.log('/ws/emit-to-user - ', message);
57
+ break;
58
+ case '/ws/broadcast-to-app-subscribers':
59
+ console.log('/ws/broadcast-to-app-subscribers - ', message);
60
+ const response = JSON.parse(message.response);
61
+ if(!response.data_type) return;
62
+ gudhub.ghconstructor.getInstance(response.data_type).then(instance => {
63
+ instance.onMessage(message.app_id, message.user_id, response);
64
+ });
65
+ break;
55
66
  default:
56
67
  console.warn("WEBSOCKETS is not process this API:", message.api);
57
68
  }
package/GUDHUB/gudhub.js CHANGED
@@ -17,6 +17,7 @@ import { IS_WEB } from "./consts.js";
17
17
  import { WebsocketHandler } from './WebSocket/WebsocketHandler.js';
18
18
  import { GroupSharing } from './Utils/sharing/GroupSharing.js';
19
19
  import { Sharing } from './Utils/sharing/Sharing.js';
20
+ import { WebSocketEmitter } from './WebSocket/WebSocketEmitter.js';
20
21
 
21
22
  export class GudHub {
22
23
  constructor(
@@ -76,6 +77,7 @@ export class GudHub {
76
77
  );
77
78
  this.fileManager = new FileManager(this.storage, this.pipeService, this.req, this.appProcessor);
78
79
  this.documentManager = new DocumentManager(this.req, this.pipeService);
80
+ this.websocketsemitter = new WebSocketEmitter(this);
79
81
 
80
82
  if (options.initWebsocket) {
81
83
  const gudhub = this;
@@ -148,6 +150,16 @@ export class GudHub {
148
150
  );
149
151
  }
150
152
 
153
+ //************************* WEBSOCKETS EMITTER ****************************//
154
+
155
+ emitToUser(user_id, data) {
156
+ return this.websocketsemitter.emitToUser(user_id, data);
157
+ }
158
+
159
+ broadcastToAppSubscribers(app_id, data_type, data) {
160
+ return this.websocketsemitter.broadcastToAppSubscribers(app_id, data_type, data);
161
+ }
162
+
151
163
  /******************* INTERPRITATE *******************/
152
164
 
153
165
  getInterpretation(value, field, dataType, source, itemId, appId, containerId) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gudhub/core",
3
- "version": "1.1.77",
3
+ "version": "1.1.78",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {