diff --git a/dist/index.d.ts b/dist/index.d.ts index 5a80261..6814120 100644 --- a/dist/index.d.ts +++ b/dist/index.d.ts @@ -71,7 +71,7 @@ export declare class TAuthClient { }); generateChallenge(userId: number): Promise; solveChallenge(userId: number, challenge: string): Promise; - createTTP(userId: number, sessionId: number, omikronUrl: string): void; + createTTP(userId: number, sessionId: number, omikronUrl: string): Promise>; loadData(userId: number, sessionId: number): Promise>; saveData(userId: number, sessionId: number, data: any): Promise; private createTemporaryTTPConnection; diff --git a/dist/index.html b/dist/index.html new file mode 100644 index 0000000..2903413 --- /dev/null +++ b/dist/index.html @@ -0,0 +1,459 @@ + + + + + + + Login successful + + + + +
+

Login successful

+

You can close this page now.

+
+ + + diff --git a/dist/index.js b/dist/index.js index c6d51f8..07045eb 100644 --- a/dist/index.js +++ b/dist/index.js @@ -76,7 +76,8 @@ export class TAuthClient { if ((await this.solveChallenge(userId, originalChallenge)) === potentialChallenge) { await this.saveSession(userId, potentialSessionId); - return new Response(htmlSuccessPage || (await readFile("./index.html")), { + return new Response(htmlSuccessPage || + (await readFile(new URL("./index.html", import.meta.url), "utf8")), { headers: { "Content-Type": "text/html", }, @@ -126,15 +127,13 @@ export class TAuthClient { } createTTP(userId, sessionId, omikronUrl) { console.log(`[tauth] Creating TTP client for user ${userId} with session ${sessionId} at ${omikronUrl}`); - this.clientMap.set(`${userId}:${sessionId}`, createTransportClient(this.schema, { + const client = createTransportClient(this.schema, { url: omikronUrl, onReadyStateChange: (stateIndex) => { const state = getFriendlyReadyState(stateIndex); console.log(state); if (state === "OPEN") { - this.clientMap - .get(`${userId}:${sessionId}`) - ?.send("identification", { + this.clientMap.get(`${userId}:${sessionId}`)?.send("identification", { app_identifier: this.identifier, app_session_id: sessionId, app_public_key: this.publicKey, @@ -142,8 +141,10 @@ export class TAuthClient { }); } }, - })); - this.clientMap.get(`${userId}:${sessionId}`)?.connect(); + }); + this.clientMap.set(`${userId}:${sessionId}`, client); + client.connect(); + return Promise.resolve(client); } async loadData(userId, sessionId) { const connection = await this.createTemporaryTTPConnection(userId, sessionId); diff --git a/package.json b/package.json index 68ef575..e3fe420 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@tensamin/tauth-sdk", - "version": "0.0.3", + "version": "0.0.4", "type": "module", "main": "./dist/index.js", "types": "./dist/index.d.ts", @@ -15,7 +15,7 @@ } }, "scripts": { - "build": "bun run test && tsc -p tsconfig.build.json", + "build": "bun run test && tsc -p tsconfig.build.json && cp src/index.html dist/index.html", "test": "bun test" }, "devDependencies": { diff --git a/src/index.html b/src/index.html index b7e8811..2903413 100644 --- a/src/index.html +++ b/src/index.html @@ -1,4 +1,11 @@ - Login successful

Login successful

You can close this page now.

\ No newline at end of file + + + + +
+

Login successful

+

You can close this page now.

+
+ + + diff --git a/src/index.ts b/src/index.ts index 22cd520..a78603c 100644 --- a/src/index.ts +++ b/src/index.ts @@ -120,7 +120,8 @@ export class TAuthClient { await this.saveSession(userId, potentialSessionId); return new Response( - htmlSuccessPage || (await readFile("./index.html")), + htmlSuccessPage || + (await readFile(new URL("./index.html", import.meta.url), "utf8")), { headers: { "Content-Type": "text/html", @@ -192,33 +193,35 @@ export class TAuthClient { return await decrypt(sharedSecret, challenge); } - createTTP(userId: number, sessionId: number, omikronUrl: string) { + createTTP( + userId: number, + sessionId: number, + omikronUrl: string, + ): Promise> { console.log( `[tauth] Creating TTP client for user ${userId} with session ${sessionId} at ${omikronUrl}`, ); - this.clientMap.set( - `${userId}:${sessionId}`, - createTransportClient(this.schema, { - url: omikronUrl, - onReadyStateChange: (stateIndex) => { - const state = getFriendlyReadyState(stateIndex); - console.log(state); - if (state === "OPEN") { - this.clientMap - .get(`${userId}:${sessionId}`) - ?.send("identification", { - app_identifier: this.identifier, - app_session_id: sessionId, - app_public_key: this.publicKey, - user_id: userId, - }); - } - }, - }), - ); + const client = createTransportClient(this.schema, { + url: omikronUrl, + onReadyStateChange: (stateIndex) => { + const state = getFriendlyReadyState(stateIndex); + console.log(state); + if (state === "OPEN") { + this.clientMap.get(`${userId}:${sessionId}`)?.send("identification", { + app_identifier: this.identifier, + app_session_id: sessionId, + app_public_key: this.publicKey, + user_id: userId, + }); + } + }, + }); - this.clientMap.get(`${userId}:${sessionId}`)?.connect(); + this.clientMap.set(`${userId}:${sessionId}`, client); + client.connect(); + + return Promise.resolve(client); } async loadData(userId: number, sessionId: number) {