@cocreate/organizations 1.21.6 → 1.22.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 +7 -0
- package/package.json +1 -1
- package/src/client.js +34 -29
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
# [1.22.0](https://github.com/CoCreate-app/CoCreate-organizations/compare/v1.21.6...v1.22.0) (2023-10-16)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Features
|
|
5
|
+
|
|
6
|
+
* get() retuns promise to limit request to one ([67d59b3](https://github.com/CoCreate-app/CoCreate-organizations/commit/67d59b38bbaa6e80727a1f2327e0ef60896565d2))
|
|
7
|
+
|
|
1
8
|
## [1.21.6](https://github.com/CoCreate-app/CoCreate-organizations/compare/v1.21.5...v1.21.6) (2023-10-14)
|
|
2
9
|
|
|
3
10
|
|
package/package.json
CHANGED
package/src/client.js
CHANGED
|
@@ -10,10 +10,6 @@ async function generateDB(organization = { object: {} }, user = { object: {} })
|
|
|
10
10
|
const apikey = organization.object.key || uuid.generate();
|
|
11
11
|
const user_id = user.object._id || Crud.ObjectId();
|
|
12
12
|
|
|
13
|
-
let hasApiKey = await Crud.send({ method: 'read.object', database: organization_id, array: 'keys', organization_id })
|
|
14
|
-
if (hasApiKey && hasApiKey.object && hasApiKey.object[0])
|
|
15
|
-
return
|
|
16
|
-
|
|
17
13
|
try {
|
|
18
14
|
// Create organization
|
|
19
15
|
organization.method = 'create.object'
|
|
@@ -23,7 +19,7 @@ async function generateDB(organization = { object: {} }, user = { object: {} })
|
|
|
23
19
|
organization.object._id = organization_id
|
|
24
20
|
organization.object.name = organization.object.name || 'untitiled'
|
|
25
21
|
organization.organization_id = organization_id
|
|
26
|
-
|
|
22
|
+
Indexeddb.send(organization);
|
|
27
23
|
|
|
28
24
|
// Create user
|
|
29
25
|
user.method = 'create.object'
|
|
@@ -34,7 +30,7 @@ async function generateDB(organization = { object: {} }, user = { object: {} })
|
|
|
34
30
|
user.object.firstname = user.object.firstname || 'untitiled'
|
|
35
31
|
user.object.lastname = user.object.lastname || 'untitiled'
|
|
36
32
|
user.organization_id = organization_id
|
|
37
|
-
|
|
33
|
+
Indexeddb.send(user);
|
|
38
34
|
|
|
39
35
|
// Create default key
|
|
40
36
|
let key = {
|
|
@@ -54,7 +50,7 @@ async function generateDB(organization = { object: {} }, user = { object: {} })
|
|
|
54
50
|
},
|
|
55
51
|
organization_id
|
|
56
52
|
}
|
|
57
|
-
|
|
53
|
+
Indexeddb.send(key);
|
|
58
54
|
|
|
59
55
|
// Create role
|
|
60
56
|
let role_id = Crud.ObjectId();
|
|
@@ -71,7 +67,7 @@ async function generateDB(organization = { object: {} }, user = { object: {} })
|
|
|
71
67
|
},
|
|
72
68
|
organization_id
|
|
73
69
|
};
|
|
74
|
-
|
|
70
|
+
Indexeddb.send(role);
|
|
75
71
|
|
|
76
72
|
// Create user key
|
|
77
73
|
let userKey = {
|
|
@@ -90,7 +86,7 @@ async function generateDB(organization = { object: {} }, user = { object: {} })
|
|
|
90
86
|
},
|
|
91
87
|
organization_id
|
|
92
88
|
};
|
|
93
|
-
|
|
89
|
+
Indexeddb.send(userKey);
|
|
94
90
|
|
|
95
91
|
return { organization: organization.object, apikey, user: user.object, role: role.object, userKey: userKey.object }
|
|
96
92
|
|
|
@@ -144,35 +140,44 @@ async function getOrganizationFromServiceWorker() {
|
|
|
144
140
|
});
|
|
145
141
|
}
|
|
146
142
|
|
|
147
|
-
|
|
143
|
+
let organizationPromise = null;
|
|
144
|
+
async function createOrganizationPromise() {
|
|
148
145
|
let createOrganization = document.querySelector('[actions*="createOrganization"]')
|
|
146
|
+
if (createOrganization)
|
|
147
|
+
return Crud.socket.organization = 'canceled'
|
|
149
148
|
|
|
150
149
|
if (Crud.socket.organization == 'canceled' || Crud.socket.organization == 'pending') return
|
|
151
150
|
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
151
|
+
const organization_id = prompt("An organization_id could not be found, if you already have an organization_id input it now.\n\nOr leave blank and click 'OK' to create a new organization");
|
|
152
|
+
|
|
153
|
+
if (organization_id === null)
|
|
154
|
+
return Crud.socket.organization = 'canceled'
|
|
155
|
+
|
|
156
|
+
Crud.socket.organization = 'pending'
|
|
157
|
+
if (Indexeddb) {
|
|
158
|
+
try {
|
|
159
|
+
let org = { object: {} }
|
|
160
|
+
if (organization_id)
|
|
161
|
+
org.object._id = organization_id
|
|
162
|
+
let { organization, apikey, user } = await generateDB(org)
|
|
163
|
+
if (organization && apikey && user) {
|
|
164
|
+
Crud.socket.apikey = apikey
|
|
165
|
+
Crud.socket.user_id = user._id
|
|
166
|
+
Config.set('organization_id', organization._id)
|
|
167
|
+
Config.set('apikey', apikey)
|
|
168
|
+
Config.set('user_id', user._id)
|
|
169
|
+
Crud.socket.organization = true
|
|
170
|
+
return organization._id
|
|
169
171
|
}
|
|
172
|
+
} catch (error) {
|
|
173
|
+
console.error('Failed to load the script:', error);
|
|
170
174
|
}
|
|
171
|
-
} else {
|
|
172
|
-
Crud.socket.organization = 'canceled'
|
|
173
175
|
}
|
|
174
176
|
}
|
|
175
177
|
|
|
178
|
+
async function createOrganization() {
|
|
179
|
+
return organizationPromise || (organizationPromise = createOrganizationPromise());
|
|
180
|
+
}
|
|
176
181
|
|
|
177
182
|
async function create(btn) {
|
|
178
183
|
let formEl = btn.closest("form");
|