From 0c188f6d10fe7380a3b6b757906304aeea28944a Mon Sep 17 00:00:00 2001 From: Matt Hill Date: Tue, 25 Jun 2024 10:54:09 -0600 Subject: [PATCH] fix ca trust test and snek high score --- web/package-lock.json | 12 +++++++----- web/projects/ui/src/app/app/snek/snek.directive.ts | 2 +- .../app/pages/login/ca-wizard/ca-wizard.component.ts | 2 +- web/projects/ui/src/app/services/api/api.types.ts | 5 ++++- .../ui/src/app/services/api/embassy-api.service.ts | 4 +++- .../src/app/services/api/embassy-live-api.service.ts | 4 ++++ .../src/app/services/api/embassy-mock-api.service.ts | 12 +++++++++++- 7 files changed, 31 insertions(+), 10 deletions(-) diff --git a/web/package-lock.json b/web/package-lock.json index 81b612ac1..ca5c8efe8 100644 --- a/web/package-lock.json +++ b/web/package-lock.json @@ -1974,22 +1974,24 @@ }, "../sdk/dist": { "name": "@start9labs/start-sdk", - "version": "0.3.6-alpha1", + "version": "0.3.6-alpha5", "license": "MIT", "dependencies": { + "@iarna/toml": "^2.2.5", "isomorphic-fetch": "^3.0.0", - "ts-matches": "^5.4.1" + "lodash": "^4.17.21", + "ts-matches": "^5.4.1", + "yaml": "^2.2.2" }, "devDependencies": { - "@iarna/toml": "^2.2.5", "@types/jest": "^29.4.0", + "@types/lodash": "^4.17.5", "jest": "^29.4.3", "prettier": "^3.2.5", "ts-jest": "^29.0.5", "ts-node": "^10.9.1", "tsx": "^4.7.1", - "typescript": "^5.0.4", - "yaml": "^2.2.2" + "typescript": "^5.0.4" } }, "node_modules/@adobe/css-tools": { diff --git a/web/projects/ui/src/app/app/snek/snek.directive.ts b/web/projects/ui/src/app/app/snek/snek.directive.ts index 255926792..db812ae4a 100644 --- a/web/projects/ui/src/app/app/snek/snek.directive.ts +++ b/web/projects/ui/src/app/app/snek/snek.directive.ts @@ -39,7 +39,7 @@ export class SnekDirective { try { await this.embassyApi.setDbValue( - ['gaming', 'snake', 'high-score'], + ['gaming', 'snake', 'highScore'], data.highScore, ) } catch (e: any) { diff --git a/web/projects/ui/src/app/pages/login/ca-wizard/ca-wizard.component.ts b/web/projects/ui/src/app/pages/login/ca-wizard/ca-wizard.component.ts index 2c0e9c7fe..fde1c968f 100644 --- a/web/projects/ui/src/app/pages/login/ca-wizard/ca-wizard.component.ts +++ b/web/projects/ui/src/app/pages/login/ca-wizard/ca-wizard.component.ts @@ -42,7 +42,7 @@ export class CAWizardComponent { private async testHttps() { const url = `https://${this.document.location.host}${this.relativeUrl}` - await this.api.getState().then(() => { + await this.api.echo({ message: 'ping' }, url).then(() => { this.caTrusted = true }) } diff --git a/web/projects/ui/src/app/services/api/api.types.ts b/web/projects/ui/src/app/services/api/api.types.ts index a5c52e9a2..0c7679754 100644 --- a/web/projects/ui/src/app/services/api/api.types.ts +++ b/web/projects/ui/src/app/services/api/api.types.ts @@ -12,7 +12,10 @@ export module RR { export type WebsocketConfig = Omit, 'url'> - // server state + // state + + export type EchoReq = { message: string } // server.echo + export type EchoRes = string export type ServerState = 'initializing' | 'error' | 'running' diff --git a/web/projects/ui/src/app/services/api/embassy-api.service.ts b/web/projects/ui/src/app/services/api/embassy-api.service.ts index d6bb11632..1d9c6f805 100644 --- a/web/projects/ui/src/app/services/api/embassy-api.service.ts +++ b/web/projects/ui/src/app/services/api/embassy-api.service.ts @@ -17,7 +17,9 @@ export abstract class ApiService { config: RR.WebsocketConfig, ): Observable - // server state + // state + + abstract echo(params: RR.EchoReq, url: string): Promise abstract getState(): Promise diff --git a/web/projects/ui/src/app/services/api/embassy-live-api.service.ts b/web/projects/ui/src/app/services/api/embassy-live-api.service.ts index 954a4475e..057c51013 100644 --- a/web/projects/ui/src/app/services/api/embassy-live-api.service.ts +++ b/web/projects/ui/src/app/services/api/embassy-live-api.service.ts @@ -71,6 +71,10 @@ export class LiveApiService extends ApiService { // state + async echo(params: RR.EchoReq, url: string): Promise { + return this.rpcRequest({ method: 'echo', params }, url) + } + async getState(): Promise { return this.rpcRequest({ method: 'state', params: {} }) } diff --git a/web/projects/ui/src/app/services/api/embassy-mock-api.service.ts b/web/projects/ui/src/app/services/api/embassy-mock-api.service.ts index 728b4ff35..98efee2ef 100644 --- a/web/projects/ui/src/app/services/api/embassy-mock-api.service.ts +++ b/web/projects/ui/src/app/services/api/embassy-mock-api.service.ts @@ -118,7 +118,17 @@ export class MockApiService extends ApiService { } } - // server state + // state + + async echo(params: RR.EchoReq, url: string): Promise { + if (url) { + const num = Math.floor(Math.random() * 10) + 1 + if (num > 8) return params.message + throw new Error() + } + await pauseFor(2000) + return params.message + } private stateIndex = 0 async getState(): Promise {