@cocreate/api 1.18.0 → 1.18.2

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,17 @@
1
+ ## [1.18.2](https://github.com/CoCreate-app/CoCreate-api/compare/v1.18.1...v1.18.2) (2023-12-09)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * options ([b84440d](https://github.com/CoCreate-app/CoCreate-api/commit/b84440dc78ac217bf3676be975fb4ad6febe1fd9))
7
+
8
+ ## [1.18.1](https://github.com/CoCreate-app/CoCreate-api/compare/v1.18.0...v1.18.1) (2023-12-01)
9
+
10
+
11
+ ### Bug Fixes
12
+
13
+ * added constructor ([cfd4f49](https://github.com/CoCreate-app/CoCreate-api/commit/cfd4f4960b48f48a4ef3b4bc75272cb192800480))
14
+
1
15
  # [1.18.0](https://github.com/CoCreate-app/CoCreate-api/compare/v1.17.0...v1.18.0) (2023-11-25)
2
16
 
3
17
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cocreate/api",
3
- "version": "1.18.0",
3
+ "version": "1.18.2",
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
@@ -11,7 +11,7 @@ const CoCreateApi = {
11
11
 
12
12
  init: function ({ name, endPoints, options }) {
13
13
  this.register({ name, endPoints, options });
14
- if (options.socket !== false && !socket.sockets.size)
14
+ if (options && options.socket !== false && !socket.sockets.size)
15
15
  socket.create({ prefix: 'api' });
16
16
  },
17
17
 
package/src/server.js CHANGED
@@ -1,102 +1,60 @@
1
- const CRUD = require('@cocreate/crud-client')
2
- const socketClient = require('@cocreate/socket-client')
3
- let socket = new socketClient("ws");
4
-
5
- CRUD.setSocket(socket);
6
-
7
- var api = (() => {
8
- return {
9
- getOrg: async (config, component) => {
10
-
11
- socket.create({
12
- namespace: config["organization_id"],
13
- room: null,
14
- host: config["host"]
15
- })
16
-
17
- let org = await CRUD.send({
18
- method: 'object.read',
19
- array: "organizations",
20
- key: config["key"],
21
- organization_id: config["organization_id"],
22
- object: {
23
- _id: config["organization_id"]
24
- }
1
+ class CoCreateApi {
2
+ constructor(crud) {
3
+ this.wsManager = crud.wsManager
4
+ this.crud = crud
5
+ this.init()
6
+ }
25
7
 
26
- });
8
+ async getOrganization(config, component) {
27
9
 
28
- if (!org || !org.object && !org.object[0]) {
29
- console.log(component, " Error GET ORG in : ", e);
30
- return false;
10
+ let org = await CRUD.send({
11
+ method: 'object.read',
12
+ array: "organizations",
13
+ key: config["key"],
14
+ organization_id: config["organization_id"],
15
+ object: {
16
+ _id: config["organization_id"]
31
17
  }
32
18
 
33
- return org.object[0];
34
- },
35
-
36
- getOrgInRoutesbyHostname: async (config, hostname) => {
37
- var socket_config = {
38
- "config": {
39
- "key": config["config"]["key"],
40
- "organization_id": config["config"]["organization_id"],
41
- },
42
- "prefix": "ws",
43
- "host": "server.cocreate.app:8088"
44
- };
45
-
46
- socket.create({
47
- namespace: socket_config.config.organization_id,
48
- room: null,
49
- host: socket_config.host
50
- })
19
+ });
51
20
 
52
- let data2 = await CRUD.send({
53
- method: 'object.read',
54
- array: "organizations",
55
- object: {
56
- $filter: {
57
- query: [{
58
- key: 'host',
59
- operator: "$in",
60
- value: [hostname]
61
- }],
62
- },
63
- },
64
- key: config["config"]["key"],
65
- organization_id: config["config"]["organization_id"]
66
- });
67
-
68
- var org = data2.object[0]
21
+ if (!org || !org.object && !org.object[0]) {
22
+ console.log(component, " Error GET ORG in : ", e);
23
+ return false;
24
+ }
69
25
 
70
- var socket_config = {
71
- "config": {
72
- "key": org["key"],
73
- "organization_id": org["_id"].toString(),
74
- },
75
- "prefix": "ws",
76
- "host": "server.cocreate.app:8088"
77
- }
26
+ return org.object[0];
27
+ }
78
28
 
79
- //other connection
80
- socket.create({
81
- namespace: socket_config.config.organization_id,
82
- room: null,
83
- host: socket_config.host
84
- })
29
+ async getApiKey(organization_id, name) {
30
+ this.organizations[organization_id] = this.getOrganization(organization_id, name)
31
+ this.organizations[organization_id] = await this.organizations[organization_id]
32
+ return this.organizations[organization_id]
33
+ }
85
34
 
86
- let myOrg = await CRUD.send({
87
- method: 'object.read',
88
- array: "organizations",
89
- key: org["key"],
90
- organization_id: org["_id"],
91
- object: {
92
- _id: org["_id"]
93
- }
94
- });
95
- let result = { 'row': myOrg, 'socket_config': socket_config };
96
- return result;
35
+ async getOrganizationNew(organization_id, name) {
36
+ let organization = await this.crud.send({
37
+ method: 'object.read',
38
+ database: organization_id,
39
+ array: 'organizations',
40
+ object: [{ _id: organization_id }],
41
+ organization_id
42
+ })
43
+
44
+ if (organization
45
+ && organization.object
46
+ && organization.object[0]) {
47
+ if (organization.object[0].apis && organization.object[0].apis[name]) {
48
+ return organization.object[0].apis && organization.object[0].apis[name]
49
+ } else
50
+ return { [this.name]: false, error: 'An apikey could not be found' }
51
+ } else {
52
+ return { serverOrganization: false, error: 'An organization could not be found' }
97
53
  }
98
54
 
99
55
  }
100
- })();
101
56
 
102
- module.exports = api;
57
+ }
58
+
59
+
60
+ module.exports = CoCreateApi;