@cocreate/api 1.2.27 → 1.2.30
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 +24 -0
- package/CoCreate.config.js +1 -1
- package/package.json +8 -8
- package/src/client.js +35 -45
- package/src/server.js +18 -19
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,27 @@
|
|
|
1
|
+
## [1.2.30](https://github.com/CoCreate-app/CoCreate-api/compare/v1.2.29...v1.2.30) (2022-02-24)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* CoCreate.config replace CoCreate.app with * ([62ecf98](https://github.com/CoCreate-app/CoCreate-api/commit/62ecf980e1e0efdc237d0015fd041ebaceb954eb))
|
|
7
|
+
* removed name param from getOrg crud function ([4d868b5](https://github.com/CoCreate-app/CoCreate-api/commit/4d868b58982d4fb635f6d040073fad23dc225533))
|
|
8
|
+
* update param type to action ([3ee6cd7](https://github.com/CoCreate-app/CoCreate-api/commit/3ee6cd7c6f2f67b0d26c49c0b202554e828633b4))
|
|
9
|
+
|
|
10
|
+
## [1.2.29](https://github.com/CoCreate-app/CoCreate-api/compare/v1.2.28...v1.2.29) (2022-02-16)
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
### Bug Fixes
|
|
14
|
+
|
|
15
|
+
* update dependencies ([aea132d](https://github.com/CoCreate-app/CoCreate-api/commit/aea132d9e4102ee866f951de88a63c4d3e6cce14))
|
|
16
|
+
|
|
17
|
+
## [1.2.28](https://github.com/CoCreate-app/CoCreate-api/compare/v1.2.27...v1.2.28) (2022-02-16)
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
### Bug Fixes
|
|
21
|
+
|
|
22
|
+
* update action param to name ([c20f956](https://github.com/CoCreate-app/CoCreate-api/commit/c20f95664270d652c4e9f3205b461c5a64b39c62))
|
|
23
|
+
* update m_instance.id to m_instance.name ([38da5df](https://github.com/CoCreate-app/CoCreate-api/commit/38da5dfda83f2313463fb6f3e25e92f1a16bbf79))
|
|
24
|
+
|
|
1
25
|
## [1.2.27](https://github.com/CoCreate-app/CoCreate-api/compare/v1.2.26...v1.2.27) (2022-02-11)
|
|
2
26
|
|
|
3
27
|
|
package/CoCreate.config.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cocreate/api",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.30",
|
|
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.
|
|
66
|
-
"@cocreate/crud-client": "^1.4.
|
|
67
|
-
"@cocreate/docs": "^1.2.
|
|
68
|
-
"@cocreate/elements": "^1.6.
|
|
69
|
-
"@cocreate/hosting": "^1.2.
|
|
70
|
-
"@cocreate/render": "^1.5.
|
|
71
|
-
"@cocreate/socket-client": "^1.4.
|
|
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.
|
|
24
|
+
self.__response(name, data);
|
|
25
25
|
});
|
|
26
26
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
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
|
-
|
|
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 {action, response} = data;
|
|
50
|
+
const m_instance = this.modules[id];
|
|
51
|
+
const functions = m_instance.actions[action]
|
|
52
|
+
if (typeof functions.response === 'function') {
|
|
53
|
+
functions.response(response);
|
|
54
|
+
}
|
|
55
|
+
else
|
|
56
|
+
this.render(action, response);
|
|
57
|
+
|
|
58
|
+
document.dispatchEvent(new CustomEvent(action, {
|
|
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,8 @@ const CoCreateApi = {
|
|
|
150
140
|
|
|
151
141
|
send : function(module, action, data){
|
|
152
142
|
let request_data = this.getCommonParams(data || {});
|
|
153
|
-
|
|
154
|
-
socketApi.send(module,
|
|
143
|
+
data = {...request_data, action, data};
|
|
144
|
+
socketApi.send(module, data);
|
|
155
145
|
},
|
|
156
146
|
|
|
157
147
|
render: function(action, data) {
|
|
@@ -163,9 +153,9 @@ const CoCreateApi = {
|
|
|
163
153
|
|
|
164
154
|
getCommonParams: function(info) {
|
|
165
155
|
return {
|
|
166
|
-
"apiKey":
|
|
167
|
-
"organization_id":
|
|
168
|
-
"host":
|
|
156
|
+
"apiKey": info.apiKey || config.apiKey,
|
|
157
|
+
"organization_id": info.organization_id || config.organization_Id,
|
|
158
|
+
"host": info.host || config.host
|
|
169
159
|
};
|
|
170
160
|
}
|
|
171
161
|
};
|
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
|
-
|
|
13
|
+
handleError: (wsManager, socket, action, error, module_id) => {
|
|
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, {
|
|
18
|
+
wsManager.send(socket, module_id, { action, response })
|
|
20
19
|
},
|
|
21
20
|
|
|
22
|
-
getOrg: async (config, module) =>{
|
|
21
|
+
getOrg: async (config, module) => {
|
|
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"]
|
|
@@ -44,7 +42,7 @@ var api = ( ()=> {
|
|
|
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"],
|
|
@@ -74,20 +72,21 @@ var api = ( ()=> {
|
|
|
74
72
|
organization_id: config["config"]["organization_id"]
|
|
75
73
|
});
|
|
76
74
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
var org = data2["data"][0]
|
|
75
|
+
//let data2 = await crud.listenAsync(eventGetOrg);
|
|
76
|
+
// console.log("data2 ===", data2)
|
|
81
77
|
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
78
|
+
var org = data2["data"][0]
|
|
79
|
+
|
|
80
|
+
var socket_config = {
|
|
81
|
+
"config": {
|
|
82
|
+
"apiKey": org["apiKey"],
|
|
83
|
+
"organization_Id": org["_id"].toString(),
|
|
84
|
+
},
|
|
85
|
+
"prefix": "ws",
|
|
86
|
+
"host": "server.cocreate.app:8088"
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
//other connection
|
|
91
90
|
socket.create({
|
|
92
91
|
namespace: socket_config.config.organization_Id,
|
|
93
92
|
room: null,
|