@cocreate/organizations 1.13.1 → 1.13.3

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,19 @@
1
+ ## [1.13.3](https://github.com/CoCreate-app/CoCreate-organizations/compare/v1.13.2...v1.13.3) (2023-05-11)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * minor bugs ([66f84c0](https://github.com/CoCreate-app/CoCreate-organizations/commit/66f84c009616d1cc929e82b05117807cf44ef875))
7
+ * removed deleteOrgs and deleteOrg. now handeled by delete documents ([ab17992](https://github.com/CoCreate-app/CoCreate-organizations/commit/ab1799247711262bfdf82f2b763ead6ff34103e7))
8
+
9
+ ## [1.13.2](https://github.com/CoCreate-app/CoCreate-organizations/compare/v1.13.1...v1.13.2) (2023-05-10)
10
+
11
+
12
+ ### Bug Fixes
13
+
14
+ * apikey renamed to key ([1de6e5f](https://github.com/CoCreate-app/CoCreate-organizations/commit/1de6e5fa2105b9b7a3185c08577eebbb30cd3a67))
15
+ * apikey renamed to key ([7a67ebd](https://github.com/CoCreate-app/CoCreate-organizations/commit/7a67ebd3da8be66259632ede4ebb492455bc94bf))
16
+
1
17
  ## [1.13.1](https://github.com/CoCreate-app/CoCreate-organizations/compare/v1.13.0...v1.13.1) (2023-05-10)
2
18
 
3
19
 
@@ -1,7 +1,7 @@
1
1
  module.exports = {
2
2
  "config": {
3
3
  "organization_id": "5ff747727005da1c272740ab",
4
- "apiKey": "2061acef-0451-4545-f754-60cf8160",
4
+ "key": "2061acef-0451-4545-f754-60cf8160",
5
5
  "host": "general.cocreate.app"
6
6
  },
7
7
  "sources": [
@@ -28,10 +28,10 @@
28
28
 
29
29
 
30
30
  <!-- API key -->
31
- <input type="hidden" id="apiKey"
31
+ <input type="hidden" id="key"
32
32
  collection="organizations"
33
33
  document_id=""
34
- name="apiKey"
34
+ name="key"
35
35
  placeholder="API Key"
36
36
  uuid="32" readonly>
37
37
 
package/demo/index.html CHANGED
@@ -54,10 +54,10 @@
54
54
  placeholder="OrganizationId">
55
55
 
56
56
  <!-- API key -->
57
- <input type="hidden" id="apiKey"
57
+ <input type="hidden" id="key"
58
58
  collection="organizations"
59
59
  document_id=""
60
- name="apiKey"
60
+ name="key"
61
61
  placeholder="API Key"
62
62
  uuid="32" readonly>
63
63
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cocreate/organizations",
3
- "version": "1.13.1",
3
+ "version": "1.13.3",
4
4
  "description": "A simple organizations component in vanilla javascript. Easily configured using HTML5 attributes and/or JavaScript API.",
5
5
  "keywords": [
6
6
  "organizations",
package/src/client.js CHANGED
@@ -9,92 +9,38 @@ const CoCreateOrganization = {
9
9
  let formEl = btn.closest("form");
10
10
  if (!formEl) return;
11
11
 
12
- let organization = {
13
- collection: 'organizations',
14
- document: [{
15
- _id: crud.socket.config.organization_id,
16
- key: crud.socket.config.key
17
- }]
18
- }
19
- let user = {
20
- collection: 'users',
21
- document: [{
22
- _id: crud.socket.config.user_id
23
- }]
24
- }
25
-
26
- form.setDocumentId(formEl, organization)
27
- form.setDocumentId(formEl, user)
28
-
29
- organization = form.getData(formEl, 'organizations')
30
- user = form.getData(formEl, 'users')
12
+ let organization = form.getData(formEl, 'organizations')
13
+ let user = form.getData(formEl, 'users')
31
14
 
15
+ let response
32
16
  let documents = await indexeddb.generateDB(organization, user)
33
17
 
34
- let response = await crud.socket.send('createOrg', {
35
- documents,
36
- broadcastBrowser: false
37
- });
18
+ if (documents) {
19
+ if(!organization || !organization.document || !organization.document[0]) return
20
+ let org = organization.document[0]
21
+ let organization_id = org._id
22
+ let key = org.key
23
+
24
+ if (!crud.socket.status) {
25
+ crud.socket.status = true
26
+ crud.socket.create({organization_id, key})
27
+ }
28
+
29
+ form.setDocumentId(formEl, organization)
30
+ form.setDocumentId(formEl, user)
31
+
32
+ response = await crud.socket.send('createOrg', {
33
+ documents,
34
+ broadcastBrowser: false,
35
+ organization_id,
36
+ key
37
+ });
38
+ }
38
39
 
39
40
  document.dispatchEvent(new CustomEvent('createdOrg', {
40
41
  detail: response
41
42
  }));
42
-
43
- },
44
-
45
- deleteOrg: async function(btn) {
46
- const { collection, document_id } = crud.getAttributes(btn);
47
- const organization_id = document_id;
48
-
49
- if (crud.checkValue(collection) && crud.checkValue(document_id)) {
50
-
51
- crud.socket.send('deleteOrg', {
52
- collection,
53
- document_id,
54
- data: {
55
- organization_id,
56
- },
57
- 'metadata': 'deleteOrg-action'
58
- }).then(response => {
59
-
60
- // ToDo: replace with custom event
61
- document.dispatchEvent(new CustomEvent('deletedOrg', {
62
- detail: {}
63
- }));
64
- })
65
- }
66
- },
67
-
68
- deleteOrgs: async function(btn) {
69
- const collection = btn.getAttribute('collection');
70
- if (crud.checkValue(collection)) {
71
- const dataTemplateid = btn.getAttribute('template_id');
72
- if (!dataTemplateid) return;
73
-
74
- const selectedEls = document.querySelectorAll(`.selected[templateid="${dataTemplateid}"]`);
75
-
76
- selectedEls.forEach((el) => {
77
- const document_id = el.getAttribute('document_id');
78
- const organization_id = document_id;
79
-
80
- if (crud.checkValue(document_id)) {
81
- crud.socket.send('deleteOrg', {
82
- collection,
83
- document_id,
84
- data: {
85
- organization_id,
86
- },
87
- 'metadata': 'deleteOrgs-action'
88
- })
89
- }
90
- });
91
-
92
- document.dispatchEvent(new CustomEvent('deletedOrgs', {
93
- detail: {}
94
- }));
95
- }
96
43
  }
97
-
98
44
  };
99
45
 
100
46
  action.init({
@@ -105,20 +51,4 @@ action.init({
105
51
  },
106
52
  });
107
53
 
108
- action.init({
109
- name: "deleteOrg",
110
- endEvent: "deletedOrg",
111
- callback: (btn, data) => {
112
- CoCreateOrganization.deleteOrg(btn);
113
- },
114
- });
115
-
116
- action.init({
117
- name: "deleteOrgs",
118
- endEvent: "deletedOrgs",
119
- callback: (btn, data) => {
120
- CoCreateOrganization.deleteOrgs(btn);
121
- },
122
- });
123
-
124
54
  export default CoCreateOrganization;
package/src/server.js CHANGED
@@ -10,9 +10,6 @@ class CoCreateOrganization {
10
10
  this.wsManager.on('createOrg', (socket, data) =>
11
11
  this.createOrg(socket, data)
12
12
  );
13
- this.wsManager.on('deleteOrg', (socket, data) =>
14
- this.deleteOrg(socket, data)
15
- );
16
13
  }
17
14
  }
18
15
 
@@ -36,41 +33,6 @@ class CoCreateOrganization {
36
33
  }
37
34
  }
38
35
 
39
-
40
- async deleteOrg(socket, data) {
41
- const self = this;
42
- const organization_id = data.data.organization_id
43
- if (!organization_id || organization_id == process.env.organization_id) return;
44
- if (data.organization_id != process.env.organization_id) return;
45
-
46
- try {
47
- this.crud.deleteDatabase(data).then((response) => {
48
- if (response === true){
49
- process.emit('deleteOrg', organization_id)
50
- self.wsManager.send(socket, 'deleteOrg', data);
51
-
52
- // delete org from platformDB
53
- const request = {
54
- database: process.env.organization_id,
55
- collection: 'organization',
56
- document: {
57
- _id: organization_id
58
- },
59
- organization_id: process.env.organization_id
60
- };
61
-
62
- self.crud.deleteDocument(request).then((data) => {
63
- self.wsManager.broadcast(socket, 'deleteDocument', data)
64
- })
65
- }
66
-
67
- })
68
-
69
- }catch(error){
70
- console.log('deleteOrg error', error);
71
- }
72
- }
73
-
74
36
  }
75
37
 
76
38
  module.exports = CoCreateOrganization;