@cocreate/api 1.2.27 → 1.2.28
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 +8 -0
- package/package.json +1 -1
- package/src/client.js +36 -45
- package/src/server.js +15 -14
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,11 @@
|
|
|
1
|
+
## [1.2.28](https://github.com/CoCreate-app/CoCreate-api/compare/v1.2.27...v1.2.28) (2022-02-16)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* update action param to name ([c20f956](https://github.com/CoCreate-app/CoCreate-api/commit/c20f95664270d652c4e9f3205b461c5a64b39c62))
|
|
7
|
+
* update m_instance.id to m_instance.name ([38da5df](https://github.com/CoCreate-app/CoCreate-api/commit/38da5dfda83f2313463fb6f3e25e92f1a16bbf79))
|
|
8
|
+
|
|
1
9
|
## [1.2.27](https://github.com/CoCreate-app/CoCreate-api/compare/v1.2.26...v1.2.27) (2022-02-11)
|
|
2
10
|
|
|
3
11
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cocreate/api",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.28",
|
|
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
|
@@ -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 {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
|
-
|
|
154
|
-
socketApi.send(module,
|
|
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,9 +154,9 @@ const CoCreateApi = {
|
|
|
163
154
|
|
|
164
155
|
getCommonParams: function(info) {
|
|
165
156
|
return {
|
|
166
|
-
"apiKey":
|
|
167
|
-
"organization_id":
|
|
168
|
-
"host":
|
|
157
|
+
"apiKey": info.apiKey || config.apiKey,
|
|
158
|
+
"organization_id": info.organization_id || config.organization_Id,
|
|
159
|
+
"host": info.host || config.host
|
|
169
160
|
};
|
|
170
161
|
}
|
|
171
162
|
};
|
package/src/server.js
CHANGED
|
@@ -11,7 +11,7 @@ var api = ( ()=> {
|
|
|
11
11
|
wsManager.send(socket, send_response, obj)
|
|
12
12
|
},
|
|
13
13
|
|
|
14
|
-
|
|
14
|
+
handleError: (wsManager, socket, type, error, module_id)=>{
|
|
15
15
|
const response = {
|
|
16
16
|
'object': 'error',
|
|
17
17
|
'data':error || error.response || error.response.data || error.response.body || error.message || error,
|
|
@@ -74,20 +74,21 @@ var api = ( ()=> {
|
|
|
74
74
|
organization_id: config["config"]["organization_id"]
|
|
75
75
|
});
|
|
76
76
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
var org = data2["data"][0]
|
|
77
|
+
//let data2 = await crud.listenAsync(eventGetOrg);
|
|
78
|
+
console.log("data2 ===",data2)
|
|
81
79
|
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
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
|
|
91
92
|
socket.create({
|
|
92
93
|
namespace: socket_config.config.organization_Id,
|
|
93
94
|
room: null,
|