(feat): better connection management, utility functions & tests
This commit is contained in:
parent
b8889812c5
commit
822dfea577
14 changed files with 448 additions and 39 deletions
55
dist/index.d.ts
vendored
55
dist/index.d.ts
vendored
|
|
@ -1,6 +1,6 @@
|
|||
import { type TransportClient, READY_STATE } from "@tensamin/ttp-core";
|
||||
import { createSchema } from "./schema";
|
||||
import type { ZodObject } from "zod";
|
||||
import type { z, ZodObject } from "zod";
|
||||
/**
|
||||
* @param redirectUrl The URL should point to the TAuth HTTP Server at http://hostname:port/callback
|
||||
*/
|
||||
|
|
@ -9,6 +9,7 @@ export declare class TAuthClient {
|
|||
identifier: string;
|
||||
privateKey: string;
|
||||
publicKey: string;
|
||||
saveSession: (userId: number, sessionId: number) => Promise<void> | void;
|
||||
redirectUrl: URL;
|
||||
schema: ReturnType<typeof createSchema>;
|
||||
httpServer: {
|
||||
|
|
@ -17,31 +18,43 @@ export declare class TAuthClient {
|
|||
};
|
||||
clientMap: Map<string, TransportClient<{
|
||||
identification: {
|
||||
request: ZodObject<{
|
||||
app_identifier: import("zod").ZodString;
|
||||
app_session_id: import("zod").ZodNumber;
|
||||
app_public_key: import("zod").ZodString;
|
||||
user_id: import("zod").ZodNumber;
|
||||
}, import("zod/v4/core").$strip>;
|
||||
response: ZodObject<{
|
||||
challenge: import("zod").ZodBase64;
|
||||
public_key: import("zod").ZodBase64;
|
||||
}, import("zod/v4/core").$strip>;
|
||||
request: z.ZodObject<{
|
||||
app_identifier: z.ZodString;
|
||||
app_session_id: z.ZodNumber;
|
||||
app_public_key: z.ZodString;
|
||||
user_id: z.ZodNumber;
|
||||
}, z.core.$strip>;
|
||||
response: z.ZodObject<{
|
||||
challenge: z.ZodBase64;
|
||||
public_key: z.ZodBase64;
|
||||
}, z.core.$strip>;
|
||||
};
|
||||
challenge_response: {
|
||||
request: ZodObject<{
|
||||
challenge: import("zod").ZodBase64;
|
||||
}, import("zod/v4/core").$strip>;
|
||||
response: ZodObject<{
|
||||
app_data: ZodObject<import("zod/v4/core").$ZodLooseShape, import("zod/v4/core").$strip>;
|
||||
}, import("zod/v4/core").$strip>;
|
||||
request: z.ZodObject<{
|
||||
challenge: z.ZodBase64;
|
||||
}, z.core.$strip>;
|
||||
response: z.ZodObject<{}, z.core.$strip>;
|
||||
};
|
||||
load_app_data: {
|
||||
request: z.ZodObject<{}, z.core.$strip>;
|
||||
response: z.ZodObject<{
|
||||
app_data: z.ZodString;
|
||||
}, z.core.$strip>;
|
||||
};
|
||||
save_app_data: {
|
||||
request: z.ZodObject<{
|
||||
app_data: z.ZodString;
|
||||
}, z.core.$strip>;
|
||||
response: z.ZodObject<{}, z.core.$strip>;
|
||||
};
|
||||
}>>;
|
||||
constructor({ frontendUrl, identifier, privateKey, publicKey, redirectUrl, appData, httpServer, htmlSuccessPage, }: {
|
||||
private appData;
|
||||
constructor({ frontendUrl, identifier, privateKey, publicKey, saveSession, redirectUrl, appData, httpServer, htmlSuccessPage, }: {
|
||||
frontendUrl: string;
|
||||
identifier: string;
|
||||
privateKey: string;
|
||||
publicKey: string;
|
||||
saveSession: (userId: number, sessionId: number) => Promise<void> | void;
|
||||
redirectUrl: string;
|
||||
appData: ZodObject;
|
||||
httpServer?: {
|
||||
|
|
@ -53,6 +66,9 @@ export declare class TAuthClient {
|
|||
generateChallenge(userId: number): Promise<string>;
|
||||
solveChallenge(userId: number, challenge: string): Promise<string>;
|
||||
createTTP(userId: number, sessionId: number, omikronUrl: string): void;
|
||||
loadData(userId: number, sessionId: number): Promise<Record<string, unknown>>;
|
||||
saveData(userId: number, sessionId: number, data: any): Promise<void>;
|
||||
private createTemporaryTTPConnection;
|
||||
generateLink(challenge?: string): string;
|
||||
}
|
||||
export declare function getFriendlyReadyState(stateIndex: number): keyof typeof READY_STATE;
|
||||
|
|
@ -60,3 +76,6 @@ export declare function generateKeyPair(): {
|
|||
private: string;
|
||||
public: string;
|
||||
};
|
||||
export * from "./crypto";
|
||||
export * from "./schema";
|
||||
export * from "./user";
|
||||
|
|
|
|||
Loading…
Reference in a new issue