Merge pull request #2653 from Start9Labs/fix/ca-and-snek

fix ca trust test and snek high score
This commit is contained in:
Matt Hill
2024-06-25 10:58:38 -06:00
committed by GitHub
7 changed files with 31 additions and 10 deletions

12
web/package-lock.json generated
View File

@@ -1974,22 +1974,24 @@
}, },
"../sdk/dist": { "../sdk/dist": {
"name": "@start9labs/start-sdk", "name": "@start9labs/start-sdk",
"version": "0.3.6-alpha1", "version": "0.3.6-alpha5",
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"@iarna/toml": "^2.2.5",
"isomorphic-fetch": "^3.0.0", "isomorphic-fetch": "^3.0.0",
"ts-matches": "^5.4.1" "lodash": "^4.17.21",
"ts-matches": "^5.4.1",
"yaml": "^2.2.2"
}, },
"devDependencies": { "devDependencies": {
"@iarna/toml": "^2.2.5",
"@types/jest": "^29.4.0", "@types/jest": "^29.4.0",
"@types/lodash": "^4.17.5",
"jest": "^29.4.3", "jest": "^29.4.3",
"prettier": "^3.2.5", "prettier": "^3.2.5",
"ts-jest": "^29.0.5", "ts-jest": "^29.0.5",
"ts-node": "^10.9.1", "ts-node": "^10.9.1",
"tsx": "^4.7.1", "tsx": "^4.7.1",
"typescript": "^5.0.4", "typescript": "^5.0.4"
"yaml": "^2.2.2"
} }
}, },
"node_modules/@adobe/css-tools": { "node_modules/@adobe/css-tools": {

View File

@@ -39,7 +39,7 @@ export class SnekDirective {
try { try {
await this.embassyApi.setDbValue<number>( await this.embassyApi.setDbValue<number>(
['gaming', 'snake', 'high-score'], ['gaming', 'snake', 'highScore'],
data.highScore, data.highScore,
) )
} catch (e: any) { } catch (e: any) {

View File

@@ -42,7 +42,7 @@ export class CAWizardComponent {
private async testHttps() { private async testHttps() {
const url = `https://${this.document.location.host}${this.relativeUrl}` 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 this.caTrusted = true
}) })
} }

View File

@@ -12,7 +12,10 @@ export module RR {
export type WebsocketConfig<T> = Omit<WebSocketSubjectConfig<T>, 'url'> export type WebsocketConfig<T> = Omit<WebSocketSubjectConfig<T>, 'url'>
// server state // state
export type EchoReq = { message: string } // server.echo
export type EchoRes = string
export type ServerState = 'initializing' | 'error' | 'running' export type ServerState = 'initializing' | 'error' | 'running'

View File

@@ -17,7 +17,9 @@ export abstract class ApiService {
config: RR.WebsocketConfig<T>, config: RR.WebsocketConfig<T>,
): Observable<T> ): Observable<T>
// server state // state
abstract echo(params: RR.EchoReq, url: string): Promise<RR.EchoRes>
abstract getState(): Promise<RR.ServerState> abstract getState(): Promise<RR.ServerState>

View File

@@ -71,6 +71,10 @@ export class LiveApiService extends ApiService {
// state // state
async echo(params: RR.EchoReq, url: string): Promise<RR.EchoRes> {
return this.rpcRequest({ method: 'echo', params }, url)
}
async getState(): Promise<RR.ServerState> { async getState(): Promise<RR.ServerState> {
return this.rpcRequest({ method: 'state', params: {} }) return this.rpcRequest({ method: 'state', params: {} })
} }

View File

@@ -118,7 +118,17 @@ export class MockApiService extends ApiService {
} }
} }
// server state // state
async echo(params: RR.EchoReq, url: string): Promise<RR.EchoRes> {
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 private stateIndex = 0
async getState(): Promise<RR.ServerState> { async getState(): Promise<RR.ServerState> {