@cocreate/indexeddb 1.4.7 → 1.4.9

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,18 @@
1
+ ## [1.4.9](https://github.com/CoCreate-app/CoCreate-indexeddb/compare/v1.4.8...v1.4.9) (2022-12-04)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * bump @cocreate/utils ([efd06ae](https://github.com/CoCreate-app/CoCreate-indexeddb/commit/efd06ae0f6ec539889379db5e864d754d3c0b6d0))
7
+ * utils.ObjectId ([87949d6](https://github.com/CoCreate-app/CoCreate-indexeddb/commit/87949d6ef3eb98351d168fcb4fcda287e52d845c))
8
+
9
+ ## [1.4.8](https://github.com/CoCreate-app/CoCreate-indexeddb/compare/v1.4.7...v1.4.8) (2022-12-02)
10
+
11
+
12
+ ### Bug Fixes
13
+
14
+ * docs ([37137e8](https://github.com/CoCreate-app/CoCreate-indexeddb/commit/37137e89b4b12befe83f43cf22eecd106f5aa5d7))
15
+
1
16
  ## [1.4.7](https://github.com/CoCreate-app/CoCreate-indexeddb/compare/v1.4.6...v1.4.7) (2022-12-02)
2
17
 
3
18
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cocreate/indexeddb",
3
- "version": "1.4.7",
3
+ "version": "1.4.9",
4
4
  "description": "A simple indexeddb component in vanilla javascript. Easily configured using HTML5 data-attributes and/or JavaScript API.",
5
5
  "keywords": [
6
6
  "indexeddb",
@@ -61,8 +61,8 @@
61
61
  "webpack-log": "^3.0.1"
62
62
  },
63
63
  "dependencies": {
64
- "@cocreate/docs": "^1.4.10",
65
- "@cocreate/hosting": "^1.6.8",
66
- "@cocreate/utils": "^1.13.0"
64
+ "@cocreate/docs": "^1.4.12",
65
+ "@cocreate/hosting": "^1.6.10",
66
+ "@cocreate/utils": "^1.13.1"
67
67
  }
68
68
  }
package/src/index.js CHANGED
@@ -4,7 +4,7 @@
4
4
  *
5
5
  * SPDX-License-Identifier: MIT
6
6
  ********************************************************************************/
7
- import {dotNotationToObject, searchData, sortData, queryData} from '@cocreate/utils'
7
+ import {ObjectId, dotNotationToObject, searchData, sortData, queryData} from '@cocreate/utils'
8
8
 
9
9
  function createDatabase(data){
10
10
  return Database('createDatabase', data)
@@ -991,12 +991,10 @@ async function readDocs(data, database, collection, objectStore, isIndex, direct
991
991
  });
992
992
  }
993
993
 
994
- async function generateDB(data) {
994
+ function generateDB(data) {
995
995
  const organization_id = data.organization_id;
996
996
  const apiKey = data.apiKey;
997
-
998
- let user_id = ObjectId()
999
- window.localStorage.setItem('user_id', user_id);
997
+ const user_id = data.user_id;
1000
998
 
1001
999
  try {
1002
1000
  // Create organization
@@ -1006,11 +1004,11 @@ async function generateDB(data) {
1006
1004
  document: {
1007
1005
  _id: organization_id,
1008
1006
  name: 'untitled',
1009
- organization_id,
1010
- apiKey
1007
+ apiKey,
1008
+ organization_id
1011
1009
  }
1012
1010
  }
1013
- await createDocument(organization);
1011
+ createDocument(organization);
1014
1012
 
1015
1013
  // Create apiKey permission
1016
1014
  if (organization_id && apiKey) {
@@ -1019,7 +1017,6 @@ async function generateDB(data) {
1019
1017
  collection: 'permissions',
1020
1018
  document: {
1021
1019
  _id: ObjectId(),
1022
- organization_id,
1023
1020
  type: "apikey",
1024
1021
  key: apiKey,
1025
1022
  hosts: [
@@ -1047,11 +1044,12 @@ async function generateDB(data) {
1047
1044
  ],
1048
1045
  "sendgrid": ["sendEmail"]
1049
1046
  },
1050
- "admin": "true"
1047
+ "admin": "true",
1048
+ organization_id,
1051
1049
  }
1052
1050
  }
1053
1051
 
1054
- await createDocument(permissions);
1052
+ createDocument(permissions);
1055
1053
  }
1056
1054
 
1057
1055
  // Create user
@@ -1064,10 +1062,10 @@ async function generateDB(data) {
1064
1062
  password: btoa('0000'),
1065
1063
  connected_orgs: [organization_id],
1066
1064
  current_org: organization_id,
1067
- organization_id: organization_id
1065
+ organization_id
1068
1066
  }
1069
1067
  }
1070
- await createDocument(user);
1068
+ createDocument(user);
1071
1069
  }
1072
1070
 
1073
1071
  // Create role permission
@@ -1077,7 +1075,6 @@ async function generateDB(data) {
1077
1075
  collection: 'permissions',
1078
1076
  document: {
1079
1077
  _id: ObjectId(),
1080
- organization_id,
1081
1078
  "type": "role",
1082
1079
  "name": "admin",
1083
1080
  "collections": {
@@ -1087,16 +1084,17 @@ async function generateDB(data) {
1087
1084
  "*": ""
1088
1085
  },
1089
1086
  "admin": "true",
1090
- "hosts": ["*"]
1087
+ "hosts": ["*"],
1088
+ organization_id,
1091
1089
  }
1092
1090
  };
1093
1091
 
1094
- await createDocument(role);
1095
- let role_id = role.data._id;
1092
+ createDocument(role);
1093
+ let role_id = role.document._id;
1096
1094
 
1097
1095
  // Create user permission
1098
1096
  if (role_id) {
1099
- let data = {
1097
+ let userPermission = {
1100
1098
  database: organization_id,
1101
1099
  collection: 'permissions',
1102
1100
  document: {
@@ -1107,7 +1105,7 @@ async function generateDB(data) {
1107
1105
  "roles": [role_id]
1108
1106
  }
1109
1107
  };
1110
- await createDocument(data);
1108
+ createDocument(userPermission);
1111
1109
  }
1112
1110
  }
1113
1111
  return true
@@ -1152,9 +1150,6 @@ function createData(data, array, type) {
1152
1150
  }
1153
1151
 
1154
1152
 
1155
- const ObjectId = (rnd = r16 => Math.floor(r16).toString(16)) =>
1156
- rnd(Date.now()/1000) + ' '.repeat(16).replace(/./g, () => rnd(Math.random()*16));
1157
-
1158
1153
  function init() {
1159
1154
  // Check for support.
1160
1155
  if (!('indexedDB' in window)) {
@@ -1166,6 +1161,7 @@ function init() {
1166
1161
  init();
1167
1162
 
1168
1163
  export default {
1164
+ ObjectId,
1169
1165
  getDatabase,
1170
1166
  createDatabase,
1171
1167
  readDatabase,
@@ -1187,6 +1183,5 @@ export default {
1187
1183
  updateDocument,
1188
1184
  deleteDocument,
1189
1185
 
1190
- ObjectId,
1191
1186
  generateDB
1192
1187
  };