@cocreate/api 1.2.30 → 1.2.33
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 +21 -0
- package/CoCreate.config.js +1 -1
- package/demo/index.html +1 -1
- package/docs/index.html +1 -1
- package/package.json +1 -1
- package/src/client.js +14 -14
- package/src/server.js +12 -23
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,24 @@
|
|
|
1
|
+
## [1.2.33](https://github.com/CoCreate-app/CoCreate-api/compare/v1.2.32...v1.2.33) (2022-05-06)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* update config organization_Id to organization_id ([da12a15](https://github.com/CoCreate-app/CoCreate-api/commit/da12a15f26ec015d1bfdd45ff3ff43cd8433427a))
|
|
7
|
+
|
|
8
|
+
## [1.2.32](https://github.com/CoCreate-app/CoCreate-api/compare/v1.2.31...v1.2.32) (2022-03-06)
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Bug Fixes
|
|
12
|
+
|
|
13
|
+
* use redocument ot get org if org_id is known ([7ef0d5c](https://github.com/CoCreate-app/CoCreate-api/commit/7ef0d5c3dd1ced316c83173bd3e8a0f02e6949b7))
|
|
14
|
+
|
|
15
|
+
## [1.2.31](https://github.com/CoCreate-app/CoCreate-api/compare/v1.2.30...v1.2.31) (2022-02-27)
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
### Bug Fixes
|
|
19
|
+
|
|
20
|
+
* update param module to component ([45edeb7](https://github.com/CoCreate-app/CoCreate-api/commit/45edeb7e4701d0510b1875f8a63dd7156338618c))
|
|
21
|
+
|
|
1
22
|
## [1.2.30](https://github.com/CoCreate-app/CoCreate-api/compare/v1.2.29...v1.2.30) (2022-02-24)
|
|
2
23
|
|
|
3
24
|
|
package/CoCreate.config.js
CHANGED
package/demo/index.html
CHANGED
package/docs/index.html
CHANGED
|
@@ -102,7 +102,7 @@
|
|
|
102
102
|
<pre><code class="language-javascript">
|
|
103
103
|
var config = {
|
|
104
104
|
apiKey: 'c2b08663-06e3-440c-ef6f-13978b42883a',
|
|
105
|
-
|
|
105
|
+
organization_id: '5de0387b12e200ea63204d6c',
|
|
106
106
|
host: 'localhost:8081'
|
|
107
107
|
}
|
|
108
108
|
</code></pre>
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cocreate/api",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.33",
|
|
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
|
-
|
|
10
|
+
components: { },
|
|
11
11
|
|
|
12
|
-
init: function({name,
|
|
13
|
-
this.register(name,
|
|
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,
|
|
18
|
+
register: function(name, component) {
|
|
19
19
|
const self = this;
|
|
20
|
-
if (typeof this.
|
|
21
|
-
this.
|
|
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(
|
|
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(
|
|
35
|
+
functions.request(component.name, action, element);
|
|
36
36
|
},
|
|
37
37
|
});
|
|
38
38
|
}
|
|
@@ -47,8 +47,8 @@ const CoCreateApi = {
|
|
|
47
47
|
|
|
48
48
|
__response: function(id, data) {
|
|
49
49
|
const {action, response} = data;
|
|
50
|
-
const
|
|
51
|
-
const functions =
|
|
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
|
}
|
|
@@ -138,10 +138,10 @@ const CoCreateApi = {
|
|
|
138
138
|
return newObject;
|
|
139
139
|
},
|
|
140
140
|
|
|
141
|
-
send : function(
|
|
141
|
+
send : function(component, action, data){
|
|
142
142
|
let request_data = this.getCommonParams(data || {});
|
|
143
143
|
data = {...request_data, action, data};
|
|
144
|
-
socketApi.send(
|
|
144
|
+
socketApi.send(component, data);
|
|
145
145
|
},
|
|
146
146
|
|
|
147
147
|
render: function(action, data) {
|
|
@@ -154,7 +154,7 @@ const CoCreateApi = {
|
|
|
154
154
|
getCommonParams: function(info) {
|
|
155
155
|
return {
|
|
156
156
|
"apiKey": info.apiKey || config.apiKey,
|
|
157
|
-
"organization_id": info.organization_id || config.
|
|
157
|
+
"organization_id": info.organization_id || config.organization_id,
|
|
158
158
|
"host": info.host || config.host
|
|
159
159
|
};
|
|
160
160
|
}
|
package/src/server.js
CHANGED
|
@@ -10,15 +10,15 @@ var api = ( ()=> {
|
|
|
10
10
|
wsManager.send(socket, send_response, obj)
|
|
11
11
|
},
|
|
12
12
|
|
|
13
|
-
handleError: (wsManager, socket, action, error,
|
|
13
|
+
handleError: (wsManager, socket, action, error, component) => {
|
|
14
14
|
const response = {
|
|
15
15
|
'object': 'error',
|
|
16
16
|
'data':error || error.response || error.response.data || error.response.body || error.message || error,
|
|
17
17
|
};
|
|
18
|
-
wsManager.send(socket,
|
|
18
|
+
wsManager.send(socket, component, { action, response })
|
|
19
19
|
},
|
|
20
20
|
|
|
21
|
-
getOrg: async (config,
|
|
21
|
+
getOrg: async (config, component) => {
|
|
22
22
|
|
|
23
23
|
socket.create({
|
|
24
24
|
namespace: config["organization_id"],
|
|
@@ -36,7 +36,7 @@ var api = ( ()=> {
|
|
|
36
36
|
try{
|
|
37
37
|
org = org["data"];
|
|
38
38
|
}catch(e){
|
|
39
|
-
console.log(
|
|
39
|
+
console.log(component," Error GET ORG in : ",e);
|
|
40
40
|
return false;
|
|
41
41
|
}
|
|
42
42
|
return org;
|
|
@@ -46,14 +46,14 @@ var api = ( ()=> {
|
|
|
46
46
|
var socket_config = {
|
|
47
47
|
"config": {
|
|
48
48
|
"apiKey": config["config"]["apiKey"],
|
|
49
|
-
"
|
|
49
|
+
"organization_id": config["config"]["organization_id"],
|
|
50
50
|
},
|
|
51
51
|
"prefix": "ws",
|
|
52
52
|
"host": "server.cocreate.app:8088"
|
|
53
53
|
};
|
|
54
54
|
|
|
55
55
|
socket.create({
|
|
56
|
-
namespace: socket_config.config.
|
|
56
|
+
namespace: socket_config.config.organization_id,
|
|
57
57
|
room: null,
|
|
58
58
|
host: socket_config.host
|
|
59
59
|
})
|
|
@@ -80,7 +80,7 @@ var api = ( ()=> {
|
|
|
80
80
|
var socket_config = {
|
|
81
81
|
"config": {
|
|
82
82
|
"apiKey": org["apiKey"],
|
|
83
|
-
"
|
|
83
|
+
"organization_id": org["_id"].toString(),
|
|
84
84
|
},
|
|
85
85
|
"prefix": "ws",
|
|
86
86
|
"host": "server.cocreate.app:8088"
|
|
@@ -88,27 +88,16 @@ var api = ( ()=> {
|
|
|
88
88
|
|
|
89
89
|
//other connection
|
|
90
90
|
socket.create({
|
|
91
|
-
namespace: socket_config.config.
|
|
91
|
+
namespace: socket_config.config.organization_id,
|
|
92
92
|
room: null,
|
|
93
93
|
host: socket_config.host
|
|
94
94
|
})
|
|
95
95
|
|
|
96
|
-
|
|
97
|
-
let myOrg = await crud.readDocumentList({
|
|
96
|
+
let myOrg = await crud.readDocument({
|
|
98
97
|
collection: "organizations",
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
operator: "$eq",
|
|
103
|
-
value: [org["_id"].toString()]
|
|
104
|
-
}],
|
|
105
|
-
orders: [],
|
|
106
|
-
startIndex: 0,
|
|
107
|
-
search: { type: 'or', value: []}
|
|
108
|
-
},
|
|
109
|
-
is_collection: false,
|
|
110
|
-
apiKey: org["apiKey"],
|
|
111
|
-
organization_id: org["_id"]
|
|
98
|
+
document_id: org["_id"],
|
|
99
|
+
apiKey: org["apiKey"],
|
|
100
|
+
organization_id: org["_id"]
|
|
112
101
|
});
|
|
113
102
|
let result = {'row':myOrg,'socket_config':socket_config};
|
|
114
103
|
return result;
|