Skip to content

Commit

Permalink
login works!
Browse files Browse the repository at this point in the history
  • Loading branch information
Jazcash committed Apr 21, 2024
1 parent abaaa75 commit ffb18ca
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 15 deletions.
15 changes: 8 additions & 7 deletions electron.vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import vue from "@vitejs/plugin-vue";
import { defineConfig, externalizeDepsPlugin } from "electron-vite";
import path from "path";
import VueRouter from "unplugin-vue-router/vite";
import commonjs from "vite-plugin-commonjs";
import renderer from "vite-plugin-electron-renderer";

export default defineConfig({
Expand Down Expand Up @@ -47,10 +48,7 @@ export default defineConfig({
esbuildOptions: {
target: "esnext",
},
// exclude: [
// "tachyon-client", // only when using npm link
// "tachyon-protocol", // only when using npm link
// ],
include: ["tachyon-protocol"],
},
css: {
modules: false,
Expand All @@ -75,9 +73,12 @@ export default defineConfig({
ws: {
type: "esm",
},
// "tachyon-protocol": {
// type: "cjs",
// },
},
}),
commonjs({
filter: (id) => {
const fileRegex = /precompiled.*validations\.js$/;
return fileRegex.test(id);
},
}),
],
Expand Down
25 changes: 25 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@
"uuid": "^9.0.0",
"vite": "^4.0.4",
"vite-electron-plugin": "^0.7.4",
"vite-plugin-commonjs": "^0.10.1",
"vite-plugin-electron": "^0.11.1",
"vite-plugin-electron-renderer": "^0.14.5",
"vite-plugin-esmodule": "^1.4.4",
Expand All @@ -133,4 +134,4 @@
"@typescript-eslint/eslint-plugin": "$@typescript-eslint/eslint-plugin",
"eslint-plugin-unused-imports": "$eslint-plugin-unused-imports"
}
}
}
15 changes: 8 additions & 7 deletions src/renderer/utils/tachyon-client.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import { generateCodeVerifier, OAuth2Client, OAuth2Token } from "@badgateway/oauth2-client";
import { randomUUID } from "node:crypto";
import { Signal } from "jaz-ts-utils";
import { randomUUID } from "node:crypto";
import http from "node:http";
import { AddressInfo } from "node:net";
import { EndpointId, GenericRequestCommand, RequestData, ResponseCommand, ServiceId, SuccessResponseData, tachyonMeta } from "tachyon-protocol";
// @ts-ignore
import * as validators from "tachyon-protocol/validators";
import { SetOptional } from "type-fest";
import { ClientOptions, WebSocket } from "ws";
import http from "node:http";
import { AddressInfo } from "node:net";

export type AuthOptions = {
/** An OAuth 2 access token. If a previous token has been generated and stored, it can be passed here to be validated or refreshed, if necessary */
Expand Down Expand Up @@ -39,7 +41,6 @@ export class TachyonClient {

protected responseSignals: Map<string, Signal> = new Map();
protected oauthClient: OAuth2Client;
protected validators: any;

constructor(config: SetOptional<TachyonClientOptions, keyof typeof defaultTachyonClientOptions>) {
this.config = { ...defaultTachyonClientOptions, ...config };
Expand All @@ -54,7 +55,7 @@ export class TachyonClient {

public async init() {
// @ts-ignore
this.validators = await import("tachyon-protocol/validators");
//this.validators = await import("tachyon-protocol/validators");
}

public async connect(token: string): Promise<SuccessResponseData<"system", "connected">> {
Expand Down Expand Up @@ -89,7 +90,7 @@ export class TachyonClient {

const [serviceId, endpointId, commandType] = commandId.split("/");

const validator = this.validators[`${serviceId}_${endpointId}_${commandType}`];
const validator = validators[`${serviceId}_${endpointId}_${commandType}`];
const isValid = validator(response);
if (!isValid) {
console.error(`Command validation failed for ${commandId}`);
Expand Down Expand Up @@ -163,7 +164,7 @@ export class TachyonClient {
const commandId = `${serviceId}/${endpointId as string}/request`;
const messageId = randomUUID();
const request: GenericRequestCommand = { commandId, messageId };
const validator = this.validators[`${serviceId as string}_${endpointId as string}_request`];
const validator = validators[`${serviceId as string}_${endpointId as string}_request`];

if (data) {
Object.assign(request, data);
Expand Down

0 comments on commit ffb18ca

Please sign in to comment.