@cocreate/indexeddb 1.1.2 → 1.2.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,17 @@
1
+ ## [1.2.1](https://github.com/CoCreate-app/CoCreate-indexeddb/compare/v1.2.0...v1.2.1) (2022-09-28)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * define database in generateDB ([919b3c8](https://github.com/CoCreate-app/CoCreate-indexeddb/commit/919b3c8a44b1489fde39b7d780da2f1824c7c4a8))
7
+
8
+ # [1.2.0](https://github.com/CoCreate-app/CoCreate-indexeddb/compare/v1.1.2...v1.2.0) (2022-09-28)
9
+
10
+
11
+ ### Features
12
+
13
+ * generateDB to apply minimum data required to indexeddb ([c98f808](https://github.com/CoCreate-app/CoCreate-indexeddb/commit/c98f8089ab9caf13602413b661e81fa2bfb2c966))
14
+
1
15
  ## [1.1.2](https://github.com/CoCreate-app/CoCreate-indexeddb/compare/v1.1.1...v1.1.2) (2022-09-22)
2
16
 
3
17
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cocreate/indexeddb",
3
- "version": "1.1.2",
3
+ "version": "1.2.1",
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",
@@ -62,8 +62,8 @@
62
62
  },
63
63
  "dependencies": {
64
64
  "@cocreate/docs": "^1.3.6",
65
- "@cocreate/filter": "^1.7.10",
65
+ "@cocreate/filter": "^1.8.1",
66
66
  "@cocreate/hosting": "^1.3.5",
67
- "@cocreate/utils": "^1.10.1"
67
+ "@cocreate/utils": "^1.10.2"
68
68
  }
69
69
  }
package/src/index.js CHANGED
@@ -671,6 +671,7 @@ const readDocuments = (data) => {
671
671
  };
672
672
  })
673
673
  }
674
+
674
675
  const sync = (action, data) => {
675
676
  return new Promise((resolve, reject) => {
676
677
  let openRequest = indexedDB.open(data.database);
@@ -708,6 +709,132 @@ const sync = (action, data) => {
708
709
  })
709
710
  }
710
711
 
712
+ async function generateDB(data) {
713
+ const organization_id = data.organization_id;
714
+ const apiKey = data.apiKey;
715
+
716
+ let user_id = ObjectId()
717
+ window.localStorage.setItem('user_id', user_id);
718
+
719
+ try {
720
+ // Create organization
721
+ let organization = {
722
+ database: organization_id,
723
+ collection: 'organizatons',
724
+ data: {
725
+ _id: organization_id,
726
+ name: 'untitled',
727
+ organization_id,
728
+ apiKey
729
+ }
730
+ }
731
+ await createDocument(organization);
732
+
733
+ // Create apiKey permission
734
+ if (organization_id && apiKey) {
735
+ let permissions = {
736
+ database: organization_id,
737
+ collection: 'permissions',
738
+ data: {
739
+ _id: ObjectId(),
740
+ organization_id,
741
+ type: "apikey",
742
+ key: apiKey,
743
+ hosts: [
744
+ "*"
745
+ ],
746
+ collections: {
747
+ "organizations": ["read"],
748
+ "files": ["read"]
749
+ },
750
+ documents: {
751
+ "someid": {
752
+ "permissions": [""],
753
+ "fieldNames": {
754
+ "name": ["read"]
755
+ }
756
+ }
757
+ },
758
+ "modules": {
759
+ "actions": [
760
+ "login",
761
+ "signin",
762
+ "userCurrentOrg",
763
+ "createUser",
764
+ "createOrg",
765
+ "runIndustry"
766
+ ],
767
+ "sendgrid": ["sendEmail"]
768
+ },
769
+ "admin": "true"
770
+ }
771
+ }
772
+
773
+ await createDocument(permissions);
774
+ }
775
+
776
+ // Create user
777
+ if (organization_id) {
778
+ let user = {
779
+ database: organization_id,
780
+ collection: 'users',
781
+ data: {
782
+ _id: user_id,
783
+ password: btoa('0000'),
784
+ connected_orgs: [organization_id],
785
+ current_org: organization_id,
786
+ organization_id: organization_id
787
+ }
788
+ }
789
+ await createDocument(user);
790
+ }
791
+
792
+ // Create role permission
793
+ if (user_id) {
794
+ let role = {
795
+ database: organization_id,
796
+ collection: 'permissions',
797
+ data: {
798
+ _id: ObjectId(),
799
+ organization_id,
800
+ "type": "role",
801
+ "name": "admin",
802
+ "collections": {
803
+ "*": ["*"]
804
+ },
805
+ "modules": {
806
+ "*": ""
807
+ },
808
+ "admin": "true",
809
+ "hosts": ["*"]
810
+ }
811
+ };
812
+
813
+ await createDocument(role);
814
+ let role_id = role.data._id;
815
+
816
+ // Create user permission
817
+ if (role_id) {
818
+ let data = {
819
+ database: organization_id,
820
+ collection: 'permissions',
821
+ data: {
822
+ _id: ObjectId(),
823
+ organization_id,
824
+ "type": "user_id",
825
+ "key": user_id,
826
+ "roles": [role_id]
827
+ }
828
+ };
829
+ await createDocument(data);
830
+ }
831
+ }
832
+ return true
833
+
834
+ } catch (error) {
835
+ console.log(error)
836
+ }
837
+ }
711
838
 
712
839
  const ObjectId = (rnd = r16 => Math.floor(r16).toString(16)) =>
713
840
  rnd(Date.now()/1000) + ' '.repeat(16).replace(/./g, () => rnd(Math.random()*16));
@@ -747,5 +874,6 @@ export {
747
874
  deleteDocument,
748
875
 
749
876
  sync,
750
- ObjectId
877
+ ObjectId,
878
+ generateDB
751
879
  };