@cocreate/organizations 1.5.7 → 1.6.0

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.0](https://github.com/CoCreate-app/CoCreate-organizations/compare/v1.5.8...v1.6.0) (2022-09-28)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * broadcast params reduced to socket, message, data ([f90ea9c](https://github.com/CoCreate-app/CoCreate-organizations/commit/f90ea9cf92e9e5a03c66bf40d2525699102d11a7))
7
+
8
+
9
+ ### Features
10
+
11
+ * config is accessible from socket.config ([c64dacf](https://github.com/CoCreate-app/CoCreate-organizations/commit/c64dacf3ef279c61e682c099c8801ff18567fc30))
12
+ * create new org while offline ([dc4223c](https://github.com/CoCreate-app/CoCreate-organizations/commit/dc4223c2e60c9ede79c040508bdc635b26f69fe6))
13
+
14
+ ## [1.5.8](https://github.com/CoCreate-app/CoCreate-organizations/compare/v1.5.7...v1.5.8) (2022-09-01)
15
+
16
+
17
+ ### Bug Fixes
18
+
19
+ * bump all of [@cocreate](https://github.com/cocreate) dependencies ([3cfda8a](https://github.com/CoCreate-app/CoCreate-organizations/commit/3cfda8ae2f751cd470a224f44b980334ca4454c7))
20
+
1
21
  ## [1.5.7](https://github.com/CoCreate-app/CoCreate-organizations/compare/v1.5.6...v1.5.7) (2022-08-31)
2
22
 
3
23
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cocreate/organizations",
3
- "version": "1.5.7",
3
+ "version": "1.6.0",
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",
@@ -61,10 +61,10 @@
61
61
  "webpack-log": "^3.0.1"
62
62
  },
63
63
  "dependencies": {
64
- "@cocreate/actions": "^1.4.3",
65
- "@cocreate/crud-client": "^1.7.1",
66
- "@cocreate/docs": "^1.3.3",
67
- "@cocreate/elements": "^1.8.3",
64
+ "@cocreate/actions": "^1.5.0",
65
+ "@cocreate/crud-client": "^1.10.0",
66
+ "@cocreate/docs": "^1.3.5",
67
+ "@cocreate/elements": "^1.12.0",
68
68
  "mongodb": "^4.4.0"
69
69
  }
70
70
  }
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
  }