@cocreate/api 1.2.29 → 1.2.32

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,26 @@
1
+ ## [1.2.32](https://github.com/CoCreate-app/CoCreate-api/compare/v1.2.31...v1.2.32) (2022-03-06)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * use redocument ot get org if org_id is known ([7ef0d5c](https://github.com/CoCreate-app/CoCreate-api/commit/7ef0d5c3dd1ced316c83173bd3e8a0f02e6949b7))
7
+
8
+ ## [1.2.31](https://github.com/CoCreate-app/CoCreate-api/compare/v1.2.30...v1.2.31) (2022-02-27)
9
+
10
+
11
+ ### Bug Fixes
12
+
13
+ * update param module to component ([45edeb7](https://github.com/CoCreate-app/CoCreate-api/commit/45edeb7e4701d0510b1875f8a63dd7156338618c))
14
+
15
+ ## [1.2.30](https://github.com/CoCreate-app/CoCreate-api/compare/v1.2.29...v1.2.30) (2022-02-24)
16
+
17
+
18
+ ### Bug Fixes
19
+
20
+ * CoCreate.config replace CoCreate.app with * ([62ecf98](https://github.com/CoCreate-app/CoCreate-api/commit/62ecf980e1e0efdc237d0015fd041ebaceb954eb))
21
+ * removed name param from getOrg crud function ([4d868b5](https://github.com/CoCreate-app/CoCreate-api/commit/4d868b58982d4fb635f6d040073fad23dc225533))
22
+ * update param type to action ([3ee6cd7](https://github.com/CoCreate-app/CoCreate-api/commit/3ee6cd7c6f2f67b0d26c49c0b202554e828633b4))
23
+
1
24
  ## [1.2.29](https://github.com/CoCreate-app/CoCreate-api/compare/v1.2.28...v1.2.29) (2022-02-16)
2
25
 
3
26
 
@@ -14,7 +14,7 @@ module.exports = {
14
14
  "name": "index.html",
15
15
  "path": "/docs/api/index.html",
16
16
  "domains": [
17
- "cocreate.app",
17
+ "*",
18
18
  "general.cocreate.app"
19
19
  ],
20
20
  "directory": "/docs/api",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cocreate/api",
3
- "version": "1.2.29",
3
+ "version": "1.2.32",
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",
package/src/client.js CHANGED
@@ -7,24 +7,24 @@ import CoCreateElements from '@cocreate/elements';
7
7
  let socketApi = new CoCreateSocket('api');
8
8
 
9
9
  const CoCreateApi = {
10
- modules: { },
10
+ components: { },
11
11
 
12
- init: function({name, module}) {
13
- this.register(name, module);
12
+ init: function({name, component}) {
13
+ this.register(name || component.name, component);
14
14
  if (!socketApi.sockets.size)
15
15
  socketApi.create(window.config);
16
16
  },
17
17
 
18
- register: function(name, m_instance) {
18
+ register: function(name, component) {
19
19
  const self = this;
20
- if (typeof this.modules[name] === 'undefined') {
21
- this.modules[name] = m_instance;
22
-
20
+ if (typeof this.components[name] === 'undefined') {
21
+ this.components[name] = component;
22
+
23
23
  socketApi.listen(name, (data) => {
24
24
  self.__response(name, data);
25
25
  });
26
26
 
27
- for (const [action, functions] of Object.entries(m_instance['actions'])){
27
+ for (const [action, functions] of Object.entries(component['actions'])){
28
28
  if (typeof functions.request !== 'function') {
29
29
  functions.request = self.__request;
30
30
  }
@@ -32,7 +32,7 @@ const CoCreateApi = {
32
32
  name: action,
33
33
  endEvent: action,
34
34
  callback: (element) => {
35
- functions.request(m_instance.name, action, element);
35
+ functions.request(component.name, action, element);
36
36
  },
37
37
  });
38
38
  }
@@ -46,16 +46,16 @@ const CoCreateApi = {
46
46
  },
47
47
 
48
48
  __response: function(id, data) {
49
- const {type, response} = data;
50
- const m_instance = this.modules[id];
51
- const functions = m_instance.actions[type]
49
+ const {action, response} = data;
50
+ const component = this.components[id];
51
+ const functions = component.actions[action]
52
52
  if (typeof functions.response === 'function') {
53
53
  functions.response(response);
54
54
  }
55
55
  else
56
- this.render(type, response);
56
+ this.render(action, response);
57
57
 
58
- document.dispatchEvent(new CustomEvent(type, {
58
+ document.dispatchEvent(new CustomEvent(action, {
59
59
  detail: {
60
60
  data: response
61
61
  }
@@ -138,11 +138,10 @@ const CoCreateApi = {
138
138
  return newObject;
139
139
  },
140
140
 
141
- send : function(module, action, data){
141
+ send : function(component, action, data){
142
142
  let request_data = this.getCommonParams(data || {});
143
- data = {...request_data, type: action, data};
144
- socketApi.send(module, data);
145
- console.log('data', data)
143
+ data = {...request_data, action, data};
144
+ socketApi.send(component, data);
146
145
  },
147
146
 
148
147
  render: function(action, data) {
package/src/server.js CHANGED
@@ -7,19 +7,18 @@ crud.setSocket(socket);
7
7
  var api = ( ()=> {
8
8
  return {
9
9
  send_response: (wsManager, socket, obj, send_response) => {
10
- console.log(send_response, " Response Sent")
11
10
  wsManager.send(socket, send_response, obj)
12
11
  },
13
12
 
14
- handleError: (wsManager, socket, type, error, module_id)=>{
13
+ handleError: (wsManager, socket, action, error, component) => {
15
14
  const response = {
16
15
  'object': 'error',
17
16
  'data':error || error.response || error.response.data || error.response.body || error.message || error,
18
17
  };
19
- wsManager.send(socket, module_id, { type, response })
18
+ wsManager.send(socket, component, { action, response })
20
19
  },
21
20
 
22
- getOrg: async (config, module) =>{
21
+ getOrg: async (config, component) => {
23
22
 
24
23
  socket.create({
25
24
  namespace: config["organization_id"],
@@ -29,7 +28,6 @@ var api = ( ()=> {
29
28
 
30
29
  let org = await crud.readDocument({
31
30
  collection: "organizations",
32
- name:"name",
33
31
  document_id: config["organization_id"],
34
32
  apiKey: config["apiKey"],
35
33
  organization_id: config["organization_id"]
@@ -38,13 +36,13 @@ var api = ( ()=> {
38
36
  try{
39
37
  org = org["data"];
40
38
  }catch(e){
41
- console.log(module," Error GET ORG in : ",e);
39
+ console.log(component," Error GET ORG in : ",e);
42
40
  return false;
43
41
  }
44
42
  return org;
45
43
  },
46
44
 
47
- getOrgInRoutesbyHostname : async (config, hostname) =>{
45
+ getOrgInRoutesbyHostname : async (config, hostname) => {
48
46
  var socket_config = {
49
47
  "config": {
50
48
  "apiKey": config["config"]["apiKey"],
@@ -75,7 +73,7 @@ var api = ( ()=> {
75
73
  });
76
74
 
77
75
  //let data2 = await crud.listenAsync(eventGetOrg);
78
- console.log("data2 ===",data2)
76
+ // console.log("data2 ===", data2)
79
77
 
80
78
  var org = data2["data"][0]
81
79
 
@@ -95,22 +93,11 @@ var api = ( ()=> {
95
93
  host: socket_config.host
96
94
  })
97
95
 
98
- // socket.setGlobalScope(socket_config.config.organization_id)
99
- let myOrg = await crud.readDocumentList({
96
+ let myOrg = await crud.readDocument({
100
97
  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
- },
111
- is_collection: false,
112
- apiKey: org["apiKey"],
113
- organization_id: org["_id"]
98
+ document_id: org["_id"],
99
+ apiKey: org["apiKey"],
100
+ organization_id: org["_id"]
114
101
  });
115
102
  let result = {'row':myOrg,'socket_config':socket_config};
116
103
  return result;