@cocreate/indexeddb 1.1.1 → 1.2.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,17 @@
1
+ # [1.2.0](https://github.com/CoCreate-app/CoCreate-indexeddb/compare/v1.1.2...v1.2.0) (2022-09-28)
2
+
3
+
4
+ ### Features
5
+
6
+ * generateDB to apply minimum data required to indexeddb ([c98f808](https://github.com/CoCreate-app/CoCreate-indexeddb/commit/c98f8089ab9caf13602413b661e81fa2bfb2c966))
7
+
8
+ ## [1.1.2](https://github.com/CoCreate-app/CoCreate-indexeddb/compare/v1.1.1...v1.1.2) (2022-09-22)
9
+
10
+
11
+ ### Bug Fixes
12
+
13
+ * deploy cdn ([5bd660a](https://github.com/CoCreate-app/CoCreate-indexeddb/commit/5bd660ab3c61c677fd4fa21ae54870bb037cfb24))
14
+
1
15
  ## [1.1.1](https://github.com/CoCreate-app/CoCreate-indexeddb/compare/v1.1.0...v1.1.1) (2022-09-21)
2
16
 
3
17
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cocreate/indexeddb",
3
- "version": "1.1.1",
3
+ "version": "1.2.0",
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,127 @@ 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
+ collection: 'organizatons',
723
+ data: {
724
+ _id: organization_id,
725
+ name: 'untitled',
726
+ organization_id,
727
+ apiKey
728
+ }
729
+ }
730
+ await createDocument(organization);
731
+
732
+ // Create apiKey permission
733
+ if (organization_id && apiKey) {
734
+ let permissions = {
735
+ collection: 'permissions',
736
+ data: {
737
+ _id: ObjectId(),
738
+ organization_id,
739
+ type: "apikey",
740
+ key: apiKey,
741
+ hosts: [
742
+ "*"
743
+ ],
744
+ collections: {
745
+ "organizations": ["read"],
746
+ "files": ["read"]
747
+ },
748
+ documents: {
749
+ "someid": {
750
+ "permissions": [""],
751
+ "fieldNames": {
752
+ "name": ["read"]
753
+ }
754
+ }
755
+ },
756
+ "modules": {
757
+ "actions": [
758
+ "login",
759
+ "signin",
760
+ "userCurrentOrg",
761
+ "createUser",
762
+ "createOrg",
763
+ "runIndustry"
764
+ ],
765
+ "sendgrid": ["sendEmail"]
766
+ },
767
+ "admin": "true"
768
+ }
769
+ }
770
+
771
+ await createDocument(permissions);
772
+ }
773
+
774
+ // Create user
775
+ if (organization_id) {
776
+ let user = {
777
+ collection: 'users',
778
+ data: {
779
+ _id: user_id,
780
+ password: btoa('0000'),
781
+ connected_orgs: [organization_id],
782
+ current_org: organization_id,
783
+ organization_id: organization_id
784
+ }
785
+ }
786
+ await createDocument(user);
787
+ }
788
+
789
+ // Create role permission
790
+ if (user_id) {
791
+ let role = {
792
+ collection: 'permissions',
793
+ data: {
794
+ _id: ObjectId(),
795
+ organization_id,
796
+ "type": "role",
797
+ "name": "admin",
798
+ "collections": {
799
+ "*": ["*"]
800
+ },
801
+ "modules": {
802
+ "*": ""
803
+ },
804
+ "admin": "true",
805
+ "hosts": ["*"]
806
+ }
807
+ };
808
+
809
+ await createDocument(role);
810
+ let role_id = role.data._id;
811
+
812
+ // Create user permission
813
+ if (role_id) {
814
+ let data = {
815
+ collection: 'permissions',
816
+ data: {
817
+ _id: ObjectId(),
818
+ organization_id,
819
+ "type": "user_id",
820
+ "key": user_id,
821
+ "roles": [role_id]
822
+ }
823
+ };
824
+ await createDocument(data);
825
+ }
826
+ }
827
+ return true
828
+
829
+ } catch (error) {
830
+ console.log(error)
831
+ }
832
+ }
711
833
 
712
834
  const ObjectId = (rnd = r16 => Math.floor(r16).toString(16)) =>
713
835
  rnd(Date.now()/1000) + ' '.repeat(16).replace(/./g, () => rnd(Math.random()*16));
@@ -747,5 +869,6 @@ export {
747
869
  deleteDocument,
748
870
 
749
871
  sync,
750
- ObjectId
872
+ ObjectId,
873
+ generateDB
751
874
  };