From fc7c1187e827de7abc759da23ae0c0395797ca3a Mon Sep 17 00:00:00 2001 From: Trent Larson Date: Fri, 19 May 2023 13:28:52 -0600 Subject: [PATCH] allow to switch the server --- project.yaml | 1 - src/constants/app.ts | 11 ++++--- src/db/index.ts | 6 +++- src/db/tables/settings.ts | 1 + src/main.ts | 2 ++ src/test/index.ts | 3 +- src/views/AccountViewView.vue | 55 ++++++++++++++++++++++++++++++-- src/views/ContactAmountsView.vue | 11 +++---- src/views/ContactsView.vue | 24 ++++++-------- src/views/NewEditProjectView.vue | 8 ++--- src/views/ProjectViewView.vue | 9 ++++-- src/views/ProjectsView.vue | 5 +-- 12 files changed, 98 insertions(+), 38 deletions(-) diff --git a/project.yaml b/project.yaml index addf166..64601fa 100644 --- a/project.yaml +++ b/project.yaml @@ -7,7 +7,6 @@ - contacts v1 : - .1 remove 'copy' until it works - - .5 switch to prod server - .5 Add page to show seed. - 01 Provide a way to import the non-sensitive data. - 01 Provide way to share your contact info. diff --git a/src/constants/app.ts b/src/constants/app.ts index 60be120..94e0d5c 100644 --- a/src/constants/app.ts +++ b/src/constants/app.ts @@ -2,8 +2,11 @@ * Generic strings that could be used throughout the app. */ export enum AppString { - APP_NAME = "KickStart with Time", - VERSION = "0.1", - DEFAULT_ENDORSER_API_SERVER = "https://test.endorser.ch:8000", - //DEFAULT_ENDORSER_API_SERVER = "http://localhost:3000", + APP_NAME = "Kick-Start with Time", + + PROD_ENDORSER_API_SERVER = "https://endorser.ch:3000", + TEST_ENDORSER_API_SERVER = "https://test.endorser.ch:8000", + LOCAL_ENDORSER_API_SERVER = "http://localhost:3000", + + DEFAULT_ENDORSER_API_SERVER = TEST_ENDORSER_API_SERVER, } diff --git a/src/db/index.ts b/src/db/index.ts index 6806b60..bcb3806 100644 --- a/src/db/index.ts +++ b/src/db/index.ts @@ -7,6 +7,7 @@ import { Settings, SettingsSchema, } from "./tables/settings"; +import { AppString } from "@/constants/app"; // a separate DB because the seed is super-sensitive data type SensitiveTables = { @@ -57,5 +58,8 @@ db.version(1).stores(NonsensitiveSchemas); // initialize, a la https://dexie.org/docs/Tutorial/Design#the-populate-event db.on("populate", function () { // ensure there's an initial entry for settings - db.settings.add({ id: MASTER_SETTINGS_KEY }); + db.settings.add({ + id: MASTER_SETTINGS_KEY, + apiServer: AppString.DEFAULT_ENDORSER_API_SERVER, + }); }); diff --git a/src/db/tables/settings.ts b/src/db/tables/settings.ts index a2233ec..a7671c2 100644 --- a/src/db/tables/settings.ts +++ b/src/db/tables/settings.ts @@ -2,6 +2,7 @@ export type Settings = { id: number; // there's only one entry: MASTER_SETTINGS_KEY activeDid?: string; + apiServer?: string; firstName?: string; lastName?: string; showContactGivesInline?: boolean; diff --git a/src/main.ts b/src/main.ts index cdb751d..c3bec57 100644 --- a/src/main.ts +++ b/src/main.ts @@ -21,6 +21,7 @@ import { faEye, faEyeSlash, faFileLines, + faFloppyDisk, faFolderOpen, faHand, faHouseChimney, @@ -53,6 +54,7 @@ library.add( faEye, faEyeSlash, faFileLines, + faFloppyDisk, faFolderOpen, faHand, faHouseChimney, diff --git a/src/test/index.ts b/src/test/index.ts index 2403a9f..4f622b3 100644 --- a/src/test/index.ts +++ b/src/test/index.ts @@ -49,7 +49,8 @@ export async function testServerRegisterUser() { // Make the xhr request payload const payload = JSON.stringify({ jwtEncoded: vcJwt }); - const endorserApiServer = AppString.DEFAULT_ENDORSER_API_SERVER; + const endorserApiServer = + settings?.apiServer || AppString.TEST_ENDORSER_API_SERVER; const url = endorserApiServer + "/api/claim"; const headers = { "Content-Type": "application/json", diff --git a/src/views/AccountViewView.vue b/src/views/AccountViewView.vue index 9a9f87e..7a387a8 100644 --- a/src/views/AccountViewView.vue +++ b/src/views/AccountViewView.vue @@ -248,6 +248,40 @@ +
+ Claim Server + + + + + +
+
Switch Account @@ -302,7 +336,11 @@ interface RateLimits { @Component export default class AccountViewView extends Vue { + Constants = AppString; + activeDid = ""; + apiServer = ""; + apiServerInput = ""; derivationPath = ""; firstName = ""; lastName = ""; @@ -345,6 +383,8 @@ export default class AccountViewView extends Vue { await db.open(); const settings = await db.settings.get(MASTER_SETTINGS_KEY); this.activeDid = settings?.activeDid || ""; + this.apiServer = settings?.apiServer || ""; + this.apiServerInput = settings?.apiServer || ""; this.firstName = settings?.firstName || ""; this.lastName = settings?.lastName || ""; this.showContactGives = !!settings?.showContactGivesInline; @@ -433,8 +473,7 @@ export default class AccountViewView extends Vue { } async checkLimits() { - const endorserApiServer = AppString.DEFAULT_ENDORSER_API_SERVER; - const url = endorserApiServer + "/api/report/rateLimits"; + const url = this.apiServer + "/api/report/rateLimits"; await accountsDB.open(); const accounts = await accountsDB.accounts.toArray(); const account = R.find((acc) => acc.did === this.activeDid, accounts); @@ -491,6 +530,18 @@ export default class AccountViewView extends Vue { }; } + async onClickSaveApiServer() { + await db.open(); + db.settings.update(MASTER_SETTINGS_KEY, { + apiServer: this.apiServerInput, + }); + this.apiServer = this.apiServerInput; + } + + setApiServerInput(value) { + this.apiServerInput = value; + } + alertMessage = ""; alertTitle = ""; isAlertVisible = false; diff --git a/src/views/ContactAmountsView.vue b/src/views/ContactAmountsView.vue index e422c18..18a5df9 100644 --- a/src/views/ContactAmountsView.vue +++ b/src/views/ContactAmountsView.vue @@ -144,6 +144,7 @@ import { AxiosError } from "axios"; @Options({}) export default class ContactsView extends Vue { activeDid = ""; + apiServer = ""; contact: Contact | null = null; giveRecords: Array = []; @@ -155,6 +156,7 @@ export default class ContactsView extends Vue { const settings = await db.settings.get(MASTER_SETTINGS_KEY); this.activeDid = settings?.activeDid || ""; + this.apiServer = settings?.apiServer || ""; if (this.activeDid && this.contact) { this.loadGives(this.activeDid, this.contact); @@ -168,14 +170,12 @@ export default class ContactsView extends Vue { const account = R.find((acc) => acc.did === activeDid, accounts); const identity = JSON.parse(account?.identity || "undefined"); - const endorserApiServer = AppString.DEFAULT_ENDORSER_API_SERVER; - // load all the time I have given to them try { let result = []; const url = - endorserApiServer + + this.apiServer + "/api/v2/report/gives?agentDid=" + encodeURIComponent(identity.did) + "&recipientDid=" + @@ -201,7 +201,7 @@ export default class ContactsView extends Vue { } const url2 = - endorserApiServer + + this.apiServer + "/api/v2/report/gives?agentDid=" + encodeURIComponent(contact.did) + "&recipientDid=" + @@ -282,8 +282,7 @@ export default class ContactsView extends Vue { // Make the xhr request payload const payload = JSON.stringify({ jwtEncoded: vcJwt }); - const endorserApiServer = AppString.DEFAULT_ENDORSER_API_SERVER; - const url = endorserApiServer + "/api/v2/claim"; + const url = this.apiServer + "/api/v2/claim"; const token = await accessToken(identity); const headers = { "Content-Type": "application/json", diff --git a/src/views/ContactsView.vue b/src/views/ContactsView.vue index 508c598..c92e7d9 100644 --- a/src/views/ContactsView.vue +++ b/src/views/ContactsView.vue @@ -271,6 +271,7 @@ const Buffer = require("buffer/").Buffer; }) export default class ContactsView extends Vue { activeDid = ""; + apiServer = ""; contacts: Array = []; contactInput = ""; // { "did:...": concatenated-descriptions } entry for each contact @@ -296,6 +297,7 @@ export default class ContactsView extends Vue { await db.open(); const settings = await db.settings.get(MASTER_SETTINGS_KEY); this.activeDid = settings?.activeDid || ""; + this.apiServer = settings?.apiServer || ""; this.showGiveNumbers = !!settings?.showContactGivesInline; if (this.showGiveNumbers) { @@ -321,12 +323,10 @@ export default class ContactsView extends Vue { return; } - const endorserApiServer = AppString.DEFAULT_ENDORSER_API_SERVER; - // load all the time I have given try { const url = - endorserApiServer + + this.apiServer + "/api/v2/report/gives?agentDid=" + encodeURIComponent(identity.did); const token = await accessToken(identity); @@ -335,7 +335,7 @@ export default class ContactsView extends Vue { Authorization: "Bearer " + token, }; const resp = await this.axios.get(url, { headers }); - console.log("All gifts you've given:", resp.data); + //console.log("All gifts you've given:", resp.data); if (resp.status === 200) { const contactDescriptions: Record = {}; const contactConfirmed: Record = {}; @@ -381,7 +381,7 @@ export default class ContactsView extends Vue { // load all the time I have received try { const url = - endorserApiServer + + this.apiServer + "/api/v2/report/gives?recipientDid=" + encodeURIComponent(identity.did); const token = await accessToken(identity); @@ -390,7 +390,7 @@ export default class ContactsView extends Vue { Authorization: "Bearer " + token, }; const resp = await this.axios.get(url, { headers }); - console.log("All gifts you've recieved:", resp.data); + //console.log("All gifts you've recieved:", resp.data); if (resp.status === 200) { const contactDescriptions: Record = {}; const contactConfirmed: Record = {}; @@ -520,8 +520,7 @@ export default class ContactsView extends Vue { // Make the xhr request payload const payload = JSON.stringify({ jwtEncoded: vcJwt }); - const endorserApiServer = AppString.DEFAULT_ENDORSER_API_SERVER; - const url = endorserApiServer + "/api/v2/claim"; + const url = this.apiServer + "/api/v2/claim"; const token = await accessToken(identity); const headers = { "Content-Type": "application/json", @@ -561,9 +560,8 @@ export default class ContactsView extends Vue { } async setVisibility(contact: Contact, visibility: boolean) { - const endorserApiServer = AppString.DEFAULT_ENDORSER_API_SERVER; const url = - endorserApiServer + + this.apiServer + "/api/report/" + (visibility ? "canSeeMe" : "cannotSeeMe"); await accountsDB.open(); @@ -601,9 +599,8 @@ export default class ContactsView extends Vue { } async checkVisibility(contact: Contact) { - const endorserApiServer = AppString.DEFAULT_ENDORSER_API_SERVER; const url = - endorserApiServer + + this.apiServer + "/api/report/canDidExplicitlySeeMe?did=" + encodeURIComponent(contact.did); await accountsDB.open(); @@ -774,8 +771,7 @@ export default class ContactsView extends Vue { // Make the xhr request payload const payload = JSON.stringify({ jwtEncoded: vcJwt }); - const endorserApiServer = AppString.DEFAULT_ENDORSER_API_SERVER; - const url = endorserApiServer + "/api/v2/claim"; + const url = this.apiServer + "/api/v2/claim"; const token = await accessToken(identity); const headers = { "Content-Type": "application/json", diff --git a/src/views/NewEditProjectView.vue b/src/views/NewEditProjectView.vue index e2f16cd..9013cab 100644 --- a/src/views/NewEditProjectView.vue +++ b/src/views/NewEditProjectView.vue @@ -101,6 +101,7 @@ interface VerifiableCredential { }) export default class NewEditProjectView extends Vue { activeDid = ""; + apiServer = ""; projectName = ""; description = ""; errorMessage = ""; @@ -116,6 +117,7 @@ export default class NewEditProjectView extends Vue { await db.open(); const settings = await db.settings.get(MASTER_SETTINGS_KEY); this.activeDid = settings?.activeDid || ""; + this.apiServer = settings?.apiServer || ""; if (this.projectId) { await accountsDB.open(); @@ -132,9 +134,8 @@ export default class NewEditProjectView extends Vue { } async LoadProject(identity: IIdentifier) { - const endorserApiServer = AppString.DEFAULT_ENDORSER_API_SERVER; const url = - endorserApiServer + + this.apiServer + "/api/claim/byHandle/" + encodeURIComponent(this.projectId); const token = await accessToken(identity); @@ -191,8 +192,7 @@ export default class NewEditProjectView extends Vue { // Make the xhr request payload const payload = JSON.stringify({ jwtEncoded: vcJwt }); - const endorserApiServer = AppString.DEFAULT_ENDORSER_API_SERVER; - const url = endorserApiServer + "/api/v2/claim"; + const url = this.apiServer + "/api/v2/claim"; const token = await accessToken(identity); const headers = { "Content-Type": "application/json", diff --git a/src/views/ProjectViewView.vue b/src/views/ProjectViewView.vue index b9dca89..88eaf94 100644 --- a/src/views/ProjectViewView.vue +++ b/src/views/ProjectViewView.vue @@ -161,6 +161,7 @@ import { IIdentifier } from "@veramo/core"; components: {}, }) export default class ProjectViewView extends Vue { + apiServer = ""; expanded = false; name = ""; description = ""; @@ -188,9 +189,10 @@ export default class ProjectViewView extends Vue { } async LoadProject(identity: IIdentifier) { - const endorserApiServer = AppString.DEFAULT_ENDORSER_API_SERVER; - // eslint-disable-next-line prettier/prettier - const url = endorserApiServer + "/api/claim/byHandle/" + encodeURIComponent(this.projectId); + const url = + this.apiServer + + "/api/claim/byHandle/" + + encodeURIComponent(this.projectId); const token = await accessToken(identity); const headers = { "Content-Type": "application/json", @@ -232,6 +234,7 @@ export default class ProjectViewView extends Vue { await db.open(); const settings = await db.settings.get(MASTER_SETTINGS_KEY); const activeDid = settings?.activeDid || ""; + this.apiServer = settings?.apiServer || ""; await accountsDB.open(); const num_accounts = await accountsDB.accounts.count(); diff --git a/src/views/ProjectsView.vue b/src/views/ProjectsView.vue index a808725..fd41f51 100644 --- a/src/views/ProjectsView.vue +++ b/src/views/ProjectsView.vue @@ -114,6 +114,7 @@ import { IIdentifier } from "@veramo/core"; components: {}, }) export default class ProjectsView extends Vue { + apiServer = ""; projects: { handleId: string; name: string; description: string }[] = []; onClickLoadProject(id: string) { @@ -127,8 +128,7 @@ export default class ProjectsView extends Vue { } async LoadProjects(identity: IIdentifier) { - const endorserApiServer = AppString.DEFAULT_ENDORSER_API_SERVER; - const url = endorserApiServer + "/api/v2/report/plansByIssuer"; + const url = this.apiServer + "/api/v2/report/plansByIssuer"; const token = await accessToken(identity); const headers = { "Content-Type": "application/json", @@ -161,6 +161,7 @@ export default class ProjectsView extends Vue { await db.open(); const settings = await db.settings.get(MASTER_SETTINGS_KEY); const activeDid = settings?.activeDid || ""; + this.apiServer = settings?.apiServer || ""; await accountsDB.open(); const num_accounts = await accountsDB.accounts.count(); -- 2.30.2