Initial commit. Started laying down the foundations.

This commit is contained in:
2026-10-26 11:22:16 +01:00
commit 1fb7936be9
12 changed files with 6249 additions and 0 deletions

17
src/index.ts Normal file
View File

@@ -0,0 +1,17 @@
import {AuthApi, Configuration} from "./generated";
import {DatabaseAPI} from "./storage/database";
import {KeyringAPI} from "./storage/keyring";
import {KeyValueAPI} from "./storage/keyvalue";
import {AuthApiExtended} from "./services/auth";
export class ChateniumClient {
public auth: AuthApiExtended;
constructor(config: { baseUrl: string, storage: {database: DatabaseAPI, keyring: KeyringAPI, keyValue: KeyValueAPI} }) {
const apiConfig = new Configuration({
basePath: config.baseUrl+"/v3"
})
this.auth = new AuthApiExtended(apiConfig);
}
}

24
src/services/auth.ts Normal file
View File

@@ -0,0 +1,24 @@
import {AuthApi, Challenge, ChallengeDataOverride} from "../generated";
export class AuthChallenge {
private challenge?: Challenge;
constructor(private authApi: AuthApi) {}
/**
* Starts a new challenge for the provided endpoint
* @param action Each authenticated endpoint in v3/auth or v3/account has its own action name (Example: passwordless registration: AUTH:PLE)
* @param userId If the provided action points to an endpoint that modifies an existing user, provide it. For registration, don't.
* @param override For registration or account info changes, this provides the (new) user data
*/
async start(action: string, userId?: string, override?: ChallengeDataOverride): Promise<Challenge> {
const resp = await this.authApi.registerChallenge({
actionName: action,
override: override,
userId: userId,
})
this.challenge = resp.data;
return resp.data;
}
}

6
src/storage/database.ts Normal file
View File

@@ -0,0 +1,6 @@
export interface DatabaseAPI {
set(collection: string, key: string, value: any): void;
get(collection: string, key: string): Promise<string>;
delete(collection: string, key: string): void;
flush(): void;
}

6
src/storage/keyring.ts Normal file
View File

@@ -0,0 +1,6 @@
export interface KeyringAPI {
set(key: string, value: any): void;
get(key: string): Promise<string>;
getAll(): Promise<string[]>;
delete(key: string): void;
}

6
src/storage/keyvalue.ts Normal file
View File

@@ -0,0 +1,6 @@
export interface KeyValueAPI {
set(key: string, value: any): void;
get(key: string): Promise<string>;
delete(key: string): void;
flush(): void;
}