Browse Source

add DB export

kb/add-usage-guide
Trent Larson 2 years ago
parent
commit
c7fa6823bc
  1. 9
      package-lock.json
  2. 1
      package.json
  3. 3
      project.yaml
  4. 2
      src/db/index.ts
  5. 42
      src/views/AccountViewView.vue

9
package-lock.json

@ -26,6 +26,7 @@
"class-transformer": "^0.5.1", "class-transformer": "^0.5.1",
"core-js": "^3.26.1", "core-js": "^3.26.1",
"dexie": "^3.2.2", "dexie": "^3.2.2",
"dexie-export-import": "^4.0.6",
"did-jwt": "^6.9.0", "did-jwt": "^6.9.0",
"ethereum-cryptography": "^1.1.2", "ethereum-cryptography": "^1.1.2",
"ethereumjs-util": "^7.1.5", "ethereumjs-util": "^7.1.5",
@ -12187,6 +12188,14 @@
"node": ">=6.0" "node": ">=6.0"
} }
}, },
"node_modules/dexie-export-import": {
"version": "4.0.6",
"resolved": "https://registry.npmjs.org/dexie-export-import/-/dexie-export-import-4.0.6.tgz",
"integrity": "sha512-WFTSm/XB4MNHBZVQJTrWjWvqur7vfpx1mWEWMuTUB9zdW3FTXvkpm7SvsUX55r6y6wmJ3libwA5eRCbVUKmuTw==",
"peerDependencies": {
"dexie": "^2.0.4 || ^3.0.0 || ^4.0.1-alpha.5"
}
},
"node_modules/did-jwt": { "node_modules/did-jwt": {
"version": "6.9.0", "version": "6.9.0",
"resolved": "https://registry.npmjs.org/did-jwt/-/did-jwt-6.9.0.tgz", "resolved": "https://registry.npmjs.org/did-jwt/-/did-jwt-6.9.0.tgz",

1
package.json

@ -26,6 +26,7 @@
"class-transformer": "^0.5.1", "class-transformer": "^0.5.1",
"core-js": "^3.26.1", "core-js": "^3.26.1",
"dexie": "^3.2.2", "dexie": "^3.2.2",
"dexie-export-import": "^4.0.6",
"did-jwt": "^6.9.0", "did-jwt": "^6.9.0",
"ethereum-cryptography": "^1.1.2", "ethereum-cryptography": "^1.1.2",
"ethereumjs-util": "^7.1.5", "ethereumjs-util": "^7.1.5",

3
project.yaml

@ -16,6 +16,9 @@
- .2 show error to user when adding a duplicate contact - .2 show error to user when adding a duplicate contact
- parse input more robustly (with CSV lib and not commas) - parse input more robustly (with CSV lib and not commas)
- refactor alerts:
- They show at the top and can be missed, eg. account bakcup download
- commit screen - commit screen
- discover screen - discover screen

2
src/db/index.ts

@ -27,7 +27,7 @@ type NonsensitiveTables = {
* https://9to5answer.com/how-to-bypass-warning-unexpected-any-specify-a-different-type-typescript-eslint-no-explicit-any * https://9to5answer.com/how-to-bypass-warning-unexpected-any-specify-a-different-type-typescript-eslint-no-explicit-any
*/ */
export type SensitiveDexie<T extends unknown = SensitiveTables> = BaseDexie & T; export type SensitiveDexie<T extends unknown = SensitiveTables> = BaseDexie & T;
export const accountsDB = new BaseDexie("KickStartSensitive") as SensitiveDexie; export const accountsDB = new BaseDexie("KickStartAccounts") as SensitiveDexie;
const SensitiveSchemas = Object.assign({}, AccountsSchema); const SensitiveSchemas = Object.assign({}, AccountsSchema);
export type NonsensitiveDexie<T extends unknown = NonsensitiveTables> = export type NonsensitiveDexie<T extends unknown = NonsensitiveTables> =

42
src/views/AccountViewView.vue

@ -122,29 +122,34 @@
<router-link <router-link
:to="{ name: 'new-edit-account' }" :to="{ name: 'new-edit-account' }"
class="block text-center text-lg font-bold uppercase bg-blue-600 text-white px-2 py-3 rounded-md mb-8" class="block text-center text-lg font-bold uppercase bg-blue-600 text-white px-2 py-3 rounded-md mb-8"
>Edit Identity</router-link
> >
Edit Identity
</router-link>
<h3 class="text-sm uppercase font-semibold mb-3">Contact Actions</h3> <h3 class="text-sm uppercase font-semibold mb-3">Contact Actions</h3>
<a <a
href="contact-scan.html" href="contact-scan.html"
class="block w-full text-center text-md uppercase bg-slate-500 text-white px-1.5 py-2 rounded-md mb-6" class="block w-full text-center text-md uppercase bg-slate-500 text-white px-1.5 py-2 rounded-md mb-6"
>Scan New Contact</a
> >
Scan New Contact
</a>
<h3 class="text-sm uppercase font-semibold mb-3">Identity Actions</h3> <h3 class="text-sm uppercase font-semibold mb-3">Data</h3>
<a <a
href="" href=""
class="block w-full text-center text-md uppercase bg-slate-500 text-white px-1.5 py-2 rounded-md mb-2" class="block w-full text-center text-md uppercase bg-slate-500 text-white px-1.5 py-2 rounded-md mb-2"
>Backup Seed</a
> >
Backup Identifier Seed
</a>
<a <a
href=""
class="block w-full text-center text-md uppercase bg-slate-500 text-white px-1.5 py-2 rounded-md mb-6" class="block w-full text-center text-md uppercase bg-slate-500 text-white px-1.5 py-2 rounded-md mb-6"
>Backup Other Data</a @click="exportDatabase()"
> >
Download Settings & Contacts (excluding Identifier Data)
</a>
<a ref="downloadLink" />
<!-- QR code popup --> <!-- QR code popup -->
<dialog id="dlgQR" class="backdrop:bg-black/75 rounded-md"> <dialog id="dlgQR" class="backdrop:bg-black/75 rounded-md">
@ -198,6 +203,7 @@
</template> </template>
<script lang="ts"> <script lang="ts">
import "dexie-export-import";
import { Options, Vue } from "vue-class-component"; import { Options, Vue } from "vue-class-component";
import { useClipboard } from "@vueuse/core"; import { useClipboard } from "@vueuse/core";
import { db, accountsDB } from "@/db"; import { db, accountsDB } from "@/db";
@ -299,6 +305,30 @@ export default class AccountViewView extends Vue {
}; };
} }
public async exportDatabase() {
try {
const blob = await db.export({ prettyJson: true });
const url = URL.createObjectURL(blob);
console.log("typeof", typeof this.$refs.downloadLink);
const downloadAnchor = this.$refs.downloadLink as HTMLAnchorElement;
downloadAnchor.href = url;
downloadAnchor.download = db.name + "-backup.json";
downloadAnchor.click();
URL.revokeObjectURL(url);
this.alertTitle = "Download Started";
this.alertMessage = "See your downloads directory for the backup.";
this.isAlertVisible = true;
} catch (error) {
this.alertTitle = "Export Error";
this.alertMessage = "See console logs for more info.";
this.isAlertVisible = true;
console.error("Export Error:", error);
}
}
alertMessage = ""; alertMessage = "";
alertTitle = ""; alertTitle = "";
isAlertVisible = false; isAlertVisible = false;

Loading…
Cancel
Save