@cocreate/api 1.2.25 → 1.2.29

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/CHANGELOG.md CHANGED
@@ -1,3 +1,32 @@
1
+ ## [1.2.29](https://github.com/CoCreate-app/CoCreate-api/compare/v1.2.28...v1.2.29) (2022-02-16)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * update dependencies ([aea132d](https://github.com/CoCreate-app/CoCreate-api/commit/aea132d9e4102ee866f951de88a63c4d3e6cce14))
7
+
8
+ ## [1.2.28](https://github.com/CoCreate-app/CoCreate-api/compare/v1.2.27...v1.2.28) (2022-02-16)
9
+
10
+
11
+ ### Bug Fixes
12
+
13
+ * update action param to name ([c20f956](https://github.com/CoCreate-app/CoCreate-api/commit/c20f95664270d652c4e9f3205b461c5a64b39c62))
14
+ * update m_instance.id to m_instance.name ([38da5df](https://github.com/CoCreate-app/CoCreate-api/commit/38da5dfda83f2313463fb6f3e25e92f1a16bbf79))
15
+
16
+ ## [1.2.27](https://github.com/CoCreate-app/CoCreate-api/compare/v1.2.26...v1.2.27) (2022-02-11)
17
+
18
+
19
+ ### Bug Fixes
20
+
21
+ * define host will be used when creating socket ([e7c4a88](https://github.com/CoCreate-app/CoCreate-api/commit/e7c4a8846b1131c98150f923e76ab42ec8bfe821))
22
+
23
+ ## [1.2.26](https://github.com/CoCreate-app/CoCreate-api/compare/v1.2.25...v1.2.26) (2022-02-10)
24
+
25
+
26
+ ### Bug Fixes
27
+
28
+ * bump dependencies ([19c4eb9](https://github.com/CoCreate-app/CoCreate-api/commit/19c4eb979a2605716a2ba7d4702a23242e06a9d5))
29
+
1
30
  ## [1.2.25](https://github.com/CoCreate-app/CoCreate-api/compare/v1.2.24...v1.2.25) (2022-02-07)
2
31
 
3
32
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cocreate/api",
3
- "version": "1.2.25",
3
+ "version": "1.2.29",
4
4
  "description": "A simple api helper component in vanilla javascript used by JavaScript developers to create thirdparty api intergrations. CoCreate-api includes the client component and server side for api processing. Thirdparty apis can be accessible using HTML5 attributes and/or JavaScript API. ",
5
5
  "keywords": [
6
6
  "thirdparty-api-intergration",
@@ -62,12 +62,12 @@
62
62
  "webpack-log": "^3.0.1"
63
63
  },
64
64
  "dependencies": {
65
- "@cocreate/actions": "^1.3.30",
66
- "@cocreate/crud-client": "^1.4.45",
67
- "@cocreate/docs": "^1.2.67",
68
- "@cocreate/elements": "^1.6.8",
69
- "@cocreate/hosting": "^1.2.62",
70
- "@cocreate/render": "^1.5.4",
71
- "@cocreate/socket-client": "^1.4.20"
65
+ "@cocreate/actions": "^1.3.33",
66
+ "@cocreate/crud-client": "^1.4.47",
67
+ "@cocreate/docs": "^1.2.69",
68
+ "@cocreate/elements": "^1.6.11",
69
+ "@cocreate/hosting": "^1.2.64",
70
+ "@cocreate/render": "^1.5.7",
71
+ "@cocreate/socket-client": "^1.4.22"
72
72
  }
73
73
  }
package/src/client.js CHANGED
@@ -21,56 +21,46 @@ const CoCreateApi = {
21
21
  this.modules[name] = m_instance;
22
22
 
23
23
  socketApi.listen(name, (data) => {
24
- self.__responseProcess(name, data);
24
+ self.__response(name, data);
25
25
  });
26
26
 
27
- //. register actions
28
-
29
- if (Array.isArray(m_instance['actions'])) {
30
- m_instance['actions'].forEach((action) => {
31
- if (typeof m_instance[`action_${action}`] !== 'function') {
32
- m_instance[`action_${action}`] = function(element) {
33
- self.__commonAction(m_instance.id, action, element);
34
- };
35
- }
36
- CoCreateAction.init({
37
- action: action,
38
- endEvent: action,
39
- callback: (btn) => {
40
- m_instance[`action_${action}`](btn);
41
- },
42
- });
27
+ for (const [action, functions] of Object.entries(m_instance['actions'])){
28
+ if (typeof functions.request !== 'function') {
29
+ functions.request = self.__request;
30
+ }
31
+ CoCreateAction.init({
32
+ name: action,
33
+ endEvent: action,
34
+ callback: (element) => {
35
+ functions.request(m_instance.name, action, element);
36
+ },
43
37
  });
44
38
  }
45
39
  }
46
40
  },
47
-
48
- __responseProcess: function(id, data) {
49
- const {type, response} = data;
50
- const m_instance = this.modules[id];
51
-
52
- if (type && response && m_instance) {
53
-
54
- if ( typeof m_instance[`render_${type}`] === 'function') {
55
- m_instance[`render_${type}`](response);
56
- }
57
-
58
- this.render(type, response);
59
-
60
- document.dispatchEvent(new CustomEvent(type, {
61
- detail: {
62
- data: response
63
- }
64
- }));
65
- }
66
- },
67
-
68
- __commonAction: function(id, action, element) {
41
+
42
+ __request: function(id, action, element) {
69
43
  const form = element.closest("form") || document;
70
44
  let data = CoCreateApi.getFormData(id, action, form);
71
45
  CoCreateApi.send(id, action, data);
72
46
  },
73
-
47
+
48
+ __response: function(id, data) {
49
+ const {type, response} = data;
50
+ const m_instance = this.modules[id];
51
+ const functions = m_instance.actions[type]
52
+ if (typeof functions.response === 'function') {
53
+ functions.response(response);
54
+ }
55
+ else
56
+ this.render(type, response);
57
+
58
+ document.dispatchEvent(new CustomEvent(type, {
59
+ detail: {
60
+ data: response
61
+ }
62
+ }));
63
+ },
74
64
 
75
65
  getFormData: function(id, action, form){
76
66
  const mainAttr = id;
@@ -150,8 +140,9 @@ const CoCreateApi = {
150
140
 
151
141
  send : function(module, action, data){
152
142
  let request_data = this.getCommonParams(data || {});
153
- request_data = {...request_data, data};
154
- socketApi.send(module, {type: action, data: request_data});
143
+ data = {...request_data, type: action, data};
144
+ socketApi.send(module, data);
145
+ console.log('data', data)
155
146
  },
156
147
 
157
148
  render: function(action, data) {
@@ -163,8 +154,9 @@ const CoCreateApi = {
163
154
 
164
155
  getCommonParams: function(info) {
165
156
  return {
166
- "apiKey": info.apiKey || config.apiKey,
167
- "organization_id": info.organization_id || config.organization_Id,
157
+ "apiKey": info.apiKey || config.apiKey,
158
+ "organization_id": info.organization_id || config.organization_Id,
159
+ "host": info.host || config.host
168
160
  };
169
161
  }
170
162
  };
package/src/server.js CHANGED
@@ -1,54 +1,49 @@
1
1
  const crud = require('@cocreate/crud-client')
2
- const CoCreateSocketClient = require('@cocreate/socket-client')
3
- let socket = new CoCreateSocketClient("ws");
2
+ const socketClient = require('@cocreate/socket-client')
3
+ let socket = new socketClient("ws");
4
4
 
5
5
  crud.setSocket(socket);
6
6
 
7
7
  var api = ( ()=> {
8
8
  return {
9
- send_response : (wsManager,socket,obj,send_response) => {
10
- console.log("Response TO-> "+send_response)
9
+ send_response: (wsManager, socket, obj, send_response) => {
10
+ console.log(send_response, " Response Sent")
11
11
  wsManager.send(socket, send_response, obj)
12
12
  },
13
13
 
14
- handleError : (wsManager,socket, type, error,module_id)=>{
15
- const response = {
16
- 'object': 'error',
17
- 'data':error || error.response || error.response.data || error.response.body || error.message || error,
18
- };
19
- wsManager.send(socket, module_id, { type, response })
20
- //send_response(wsManager, socket, { type, response }, module_id);
14
+ handleError: (wsManager, socket, type, error, module_id)=>{
15
+ const response = {
16
+ 'object': 'error',
17
+ 'data':error || error.response || error.response.data || error.response.body || error.message || error,
18
+ };
19
+ wsManager.send(socket, module_id, { type, response })
21
20
  },
22
- getOrg : async (config, module) =>{
23
- console.log("config WS utils==== ",config)
21
+
22
+ getOrg: async (config, module) =>{
24
23
 
25
24
  socket.create({
26
25
  namespace: config["organization_id"],
27
26
  room: null,
28
- host: "server.cocreate.app:8088"
27
+ host: config["host"]
29
28
  })
30
- const event = "getOrg";
31
-
32
-
33
- console.log("Org_id => ",config["organization_id"])
34
-
35
- let org_row = await crud.readDocument({
29
+
30
+ let org = await crud.readDocument({
36
31
  collection: "organizations",
37
32
  name:"name",
38
33
  document_id: config["organization_id"],
39
- event,
40
34
  apiKey: config["apiKey"],
41
- organization_id: '5de0387b12e200ea63204d6c'
35
+ organization_id: config["organization_id"]
42
36
  });
43
37
 
44
38
  try{
45
- org_row = org_row["data"];
46
- }catch(e){
47
- console.log(module," Error GET ORG in : ",e);
39
+ org = org["data"];
40
+ }catch(e){
41
+ console.log(module," Error GET ORG in : ",e);
48
42
  return false;
49
- }
50
- return org_row;
43
+ }
44
+ return org;
51
45
  },
46
+
52
47
  getOrgInRoutesbyHostname : async (config, hostname) =>{
53
48
  var socket_config = {
54
49
  "config": {
@@ -59,63 +54,60 @@ var api = ( ()=> {
59
54
  "host": "server.cocreate.app:8088"
60
55
  };
61
56
 
62
- socket.create({
63
- namespace: socket_config.config.organization_Id,
64
- room: null,
65
- host: socket_config.host
66
- })
57
+ socket.create({
58
+ namespace: socket_config.config.organization_Id,
59
+ room: null,
60
+ host: socket_config.host
61
+ })
67
62
 
63
+ let data2 = await crud.readDocumentList({
64
+ collection: "organizations",
65
+ operator: {
66
+ filters: [{
67
+ name: 'domains',
68
+ operator: "$in",
69
+ value: [hostname]
70
+ }],
71
+ },
72
+ is_collection: false,
73
+ apiKey: config["config"]["apiKey"],
74
+ organization_id: config["config"]["organization_id"]
75
+ });
68
76
 
69
- let data2 = await crud.readDocumentList({
70
- collection: "organizations",
71
- operator: {
72
- filters: [{
73
- name: 'domains',
74
- operator: "$in",
75
- value: [hostname]
76
- }],
77
- // orders: [],
78
- // startIndex: 0,
79
- // search: { type: 'or', value: []}
80
- },
81
- is_collection: false,
82
- apiKey: config["config"]["apiKey"],
83
- organization_id: config["config"]["organization_id"]
84
- });
85
-
86
- //let data2 = await crud.listenAsync(eventGetOrg);
87
- console.log("data2 ===",data2)
88
-
89
- var org = data2["data"][0]
77
+ //let data2 = await crud.listenAsync(eventGetOrg);
78
+ console.log("data2 ===",data2)
90
79
 
91
- var socket_config = {
92
- "config": {
93
- "apiKey": org["apiKey"],
94
- // "securityKey": org["securityKey"],
95
- "organization_Id": org["_id"].toString(),
96
- },
97
- "prefix": "ws",
98
- "host": "server.cocreate.app:8088"
99
- }
100
- //other connection
80
+ var org = data2["data"][0]
81
+
82
+ var socket_config = {
83
+ "config": {
84
+ "apiKey": org["apiKey"],
85
+ "organization_Id": org["_id"].toString(),
86
+ },
87
+ "prefix": "ws",
88
+ "host": "server.cocreate.app:8088"
89
+ }
90
+
91
+ //other connection
101
92
  socket.create({
102
- namespace: socket_config.config.organization_Id,
93
+ namespace: socket_config.config.organization_Id,
103
94
  room: null,
104
95
  host: socket_config.host
105
96
  })
97
+
106
98
  // socket.setGlobalScope(socket_config.config.organization_id)
107
- let myOrg = await crud.readDocumentList({
108
- collection: "organizations",
109
- operator: {
110
- filters: [{
111
- name: '_id',
112
- operator: "$eq",
113
- value: [org["_id"].toString()]
114
- }],
115
- orders: [],
116
- startIndex: 0,
117
- search: { type: 'or', value: []}
118
- },
99
+ let myOrg = await crud.readDocumentList({
100
+ collection: "organizations",
101
+ operator: {
102
+ filters: [{
103
+ name: '_id',
104
+ operator: "$eq",
105
+ value: [org["_id"].toString()]
106
+ }],
107
+ orders: [],
108
+ startIndex: 0,
109
+ search: { type: 'or', value: []}
110
+ },
119
111
  is_collection: false,
120
112
  apiKey: org["apiKey"],
121
113
  organization_id: org["_id"]
@@ -124,7 +116,7 @@ var api = ( ()=> {
124
116
  return result;
125
117
  }
126
118
 
127
- } //
119
+ }
128
120
  })();
129
121
 
130
122
  module.exports = api;