@cocreate/organizations 1.5.8 → 1.6.1

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,23 @@
1
+ ## [1.6.1](https://github.com/CoCreate-app/CoCreate-organizations/compare/v1.6.0...v1.6.1) (2022-09-29)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * config renameed to CoCreateConfig ([fc0ce1f](https://github.com/CoCreate-app/CoCreate-organizations/commit/fc0ce1f3d73ce6a98b3c1f40339c4da62b346377))
7
+
8
+ # [1.6.0](https://github.com/CoCreate-app/CoCreate-organizations/compare/v1.5.8...v1.6.0) (2022-09-28)
9
+
10
+
11
+ ### Bug Fixes
12
+
13
+ * broadcast params reduced to socket, message, data ([f90ea9c](https://github.com/CoCreate-app/CoCreate-organizations/commit/f90ea9cf92e9e5a03c66bf40d2525699102d11a7))
14
+
15
+
16
+ ### Features
17
+
18
+ * config is accessible from socket.config ([c64dacf](https://github.com/CoCreate-app/CoCreate-organizations/commit/c64dacf3ef279c61e682c099c8801ff18567fc30))
19
+ * create new org while offline ([dc4223c](https://github.com/CoCreate-app/CoCreate-organizations/commit/dc4223c2e60c9ede79c040508bdc635b26f69fe6))
20
+
1
21
  ## [1.5.8](https://github.com/CoCreate-app/CoCreate-organizations/compare/v1.5.7...v1.5.8) (2022-09-01)
2
22
 
3
23
 
@@ -46,7 +46,7 @@
46
46
  </form>
47
47
 
48
48
  <script>
49
- var config = {
49
+ var CoCreateConfig = {
50
50
  apiKey: 'c2b08663-06e3-440c-ef6f-13978b42883a',
51
51
  organization_id: '5de0387b12e200ea63204d6c'
52
52
  }
package/demo/index.html CHANGED
@@ -96,7 +96,7 @@
96
96
  </div>
97
97
 
98
98
  <script>
99
- var config = {
99
+ var CoCreateConfig = {
100
100
  apiKey: 'c2b08663-06e3-440c-ef6f-13978b42883a',
101
101
  organization_id: '5de0387b12e200ea63204d6c',
102
102
  host: 'ws.cocreate.app'
@@ -72,7 +72,7 @@
72
72
  </div>
73
73
 
74
74
  <script>
75
- var config = {
75
+ var CoCreateConfig = {
76
76
  apiKey: '2061acef-0451-4545-f754-60cf8160',
77
77
  securityKey: '073daff2-5142-4402-cf59-48e205ef',
78
78
  organization_id: '5ff747727005da1c272740ab'
@@ -110,7 +110,7 @@
110
110
 
111
111
 
112
112
  <script>
113
- var config = {
113
+ var CoCreateConfig = {
114
114
  apiKey: 'c2b08663-06e3-440c-ef6f-13978b42883a',
115
115
  organization_id: '5de0387b12e200ea63204d6c'
116
116
  }
@@ -115,7 +115,7 @@
115
115
 
116
116
 
117
117
  <script>
118
- var config = {
118
+ var CoCreateConfig = {
119
119
  apiKey: 'c2b08663-06e3-440c-ef6f-13978b42883a',
120
120
  organization_id: '5de0387b12e200ea63204d6c'
121
121
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cocreate/organizations",
3
- "version": "1.5.8",
3
+ "version": "1.6.1",
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
@@ -1,6 +1,7 @@
1
1
  import crud from '@cocreate/crud-client';
2
2
  // import input from '@cocreate/elements'
3
3
  import action from '@cocreate/actions';
4
+ import uuid from '@cocreate/uuid';
4
5
 
5
6
  const CoCreateOrganization = {
6
7
  init: function() {
@@ -19,7 +20,7 @@ const CoCreateOrganization = {
19
20
 
20
21
  let elements = form.querySelectorAll("[collection='organizations'][name]");
21
22
 
22
- let data = {};
23
+ let data = {data: {}};
23
24
  //. get form data
24
25
  elements.forEach(el => {
25
26
  let name = el.getAttribute('name');
@@ -28,13 +29,33 @@ const CoCreateOrganization = {
28
29
  if (el.getAttribute('data-type') == 'array') {
29
30
  value = [value];
30
31
  }
31
- data[name] = value;
32
+ data.data[name] = value;
32
33
  });
33
34
 
34
- crud.send('createOrg', {
35
- collection: 'organizations',
36
- data: data
37
- });
35
+ const socket = crud.socket.getSocket()
36
+ if (!socket || !socket.connected || window && !window.navigator.onLine) {
37
+ data.collection = 'organizations'
38
+ data.data['_id'] = ObjectId()
39
+ data.data['name'] = 'untitled'
40
+ window.localStorage.setItem('apiKey', uuid(32));
41
+ window.localStorage.setItem('organization_id', data['_id']);
42
+ crud.createDocument(data).then((response) => {
43
+ data.database = data.data['_id']
44
+ data.organization_id = data.data['_id']
45
+ crud.createDocument(data).then((response) => {
46
+
47
+ document.dispatchEvent(new CustomEvent('createOrg', {
48
+ detail: response
49
+ }));
50
+
51
+ })
52
+ })
53
+ } else {
54
+ crud.send('createOrg', {
55
+ collection: 'organizations',
56
+ data: data
57
+ });
58
+ }
38
59
  },
39
60
 
40
61
  setDocumentId: function(collection, id) {
@@ -106,6 +127,8 @@ const CoCreateOrganization = {
106
127
 
107
128
  };
108
129
 
130
+ const ObjectId = (rnd = r16 => Math.floor(r16).toString(16)) =>
131
+ rnd(Date.now()/1000) + ' '.repeat(16).replace(/./g, () => rnd(Math.random()*16));
109
132
 
110
133
  action.init({
111
134
  name: "createOrg",
package/src/server.js CHANGED
@@ -9,16 +9,16 @@ class CoCreateOrganization {
9
9
 
10
10
  init() {
11
11
  if (this.wsManager) {
12
- this.wsManager.on('createOrg', (socket, data, socketInfo) =>
13
- this.createOrg(socket, data, socketInfo)
12
+ this.wsManager.on('createOrg', (socket, data) =>
13
+ this.createOrg(socket, data)
14
14
  );
15
- this.wsManager.on('deleteOrg', (socket, data, socketInfo) =>
16
- this.deleteOrg(socket, data, socketInfo)
15
+ this.wsManager.on('deleteOrg', (socket, data) =>
16
+ this.deleteOrg(socket, data)
17
17
  );
18
18
  }
19
19
  }
20
20
 
21
- async createOrg(socket, data, socketInfo) {
21
+ async createOrg(socket, data) {
22
22
  const self = this;
23
23
  if(!data.data) return;
24
24
 
@@ -37,8 +37,8 @@ class CoCreateOrganization {
37
37
 
38
38
  const response = { ...data, document_id: orgId }
39
39
 
40
- self.wsManager.send(socket, 'createOrg', response, socketInfo);
41
- self.wsManager.broadcast(socket, data.namespace || data['organization_id'] , data.room, 'createDocument', response);
40
+ self.wsManager.send(socket, 'createOrg', response);
41
+ self.wsManager.broadcast(socket, 'createDocument', response);
42
42
 
43
43
  // add new org to platformDB
44
44
  if (data.organization_id != process.env.organization_id) {
@@ -53,7 +53,7 @@ class CoCreateOrganization {
53
53
  }
54
54
 
55
55
 
56
- async deleteOrg(socket, data, socketInfo) {
56
+ async deleteOrg(socket, data) {
57
57
  const self = this;
58
58
  if(!data.data) return;
59
59
  const organization_id = data.data.organization_id
@@ -74,10 +74,10 @@ class CoCreateOrganization {
74
74
  platformDB.deleteOne(query, function(error, result) {
75
75
  if (!error) {
76
76
  let response = { ...data }
77
- self.wsManager.send(socket, 'deleteOrg', response, socketInfo);
78
- self.wsManager.broadcast(socket, response.namespace || response['organization_id'], response.room, 'deleteDocument', response, socketInfo);
77
+ self.wsManager.send(socket, 'deleteOrg', response);
78
+ self.wsManager.broadcast(socket, 'deleteDocument', response);
79
79
  } else {
80
- self.wsManager.send(socket, 'ServerError', error, socketInfo);
80
+ self.wsManager.send(socket, 'ServerError', error);
81
81
  }
82
82
  })
83
83
  }