4 Commits

Author SHA1 Message Date
Noel Maróti
137976d2d7 Created wrapper proxies for DM and Contacts. Rest is WIP 2026-11-07 13:44:30 +01:00
Noel Maróti
3c553ceb71 Wired up all generated API handlers 2026-11-07 13:44:17 +01:00
Noel Maróti
7e0c3f3684 Removed storage interfaces - no longer necessary 2026-11-07 13:44:00 +01:00
Noel Maróti
279f3a1c70 Updated SDK version 2026-11-07 13:43:47 +01:00
8 changed files with 120 additions and 29 deletions

4
package-lock.json generated
View File

@@ -1,12 +1,12 @@
{
"name": "chatenium-sdk-typescript",
"version": "1.0.0",
"version": "2.0.0-beta.1",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "chatenium-sdk-typescript",
"version": "1.0.0",
"version": "2.0.0-beta.1",
"license": "GPL-3.0-or-later",
"dependencies": {
"@openapitools/openapi-generator-cli": "^2.42.0"

View File

@@ -1,6 +1,6 @@
{
"name": "chatenium-sdk-typescript",
"version": "1.0.0",
"version": "2.0.0-beta.1",
"description": "A TypeScript SDK for interacting with Chatenium API",
"main": "index.js",
"types": "./dist/index.d.ts",

View File

@@ -1,16 +1,72 @@
import {AuthApi, Configuration} from "./generated";
import {DatabaseAPI} from "./storage/database";
import {KeyringAPI} from "./storage/keyring";
import {KeyValueAPI} from "./storage/keyvalue";
import {
AuthApi,
AccountApi,
Configuration,
ContactsApi,
DirectMessagingApi,
FileTransferApi,
CascadeApi, ThreadApi, ThreadMessage, ThreadMessagesApi, PicturesCreatorApi, PicturesApi, PictureCommentsApi,
PictureAlbumApi, CascadeInviteApi, RanksApi
} from "./generated";
export class ChateniumClient {
public auth: AuthApi;
public account: AccountApi;
public contacts: ContactsApi;
public directMessaging: DirectMessagingApi;
public fileTransfers: FileTransferApi;
public cascades: CascadeApi;
public threads: ThreadApi;
public threadMessages: ThreadMessagesApi;
public pictureCreator: PicturesCreatorApi;
public pictures: PicturesApi;
public pictureComments: PictureCommentsApi;
public pictureAlbums: PictureAlbumApi;
public cascadeInvites: CascadeInviteApi;
public cascadeRanks: RanksApi;
constructor(config: { baseUrl: string, storage: {database: DatabaseAPI, keyring: KeyringAPI, keyValue: KeyValueAPI} }) {
const apiConfig = new Configuration({
basePath: config.baseUrl+"/v3"
private apiConfig: Configuration;
constructor(config: { baseUrl: string }) {
this.apiConfig = new Configuration({
basePath: config.baseUrl+"/v3",
})
this.auth = new AuthApi(apiConfig);
this.auth = new AuthApi(this.apiConfig);
this.account = new AccountApi(this.apiConfig);
this.contacts = new ContactsApi(this.apiConfig);
this.directMessaging = new DirectMessagingApi(this.apiConfig);
this.fileTransfers = new FileTransferApi(this.apiConfig);
this.cascades = new CascadeApi(this.apiConfig);
this.threads = new ThreadApi(this.apiConfig);
this.pictureCreator = new PicturesCreatorApi(this.apiConfig);
this.threadMessages = new ThreadMessagesApi(this.apiConfig);
this.pictures = new PicturesApi(this.apiConfig);
this.pictureComments = new PictureCommentsApi(this.apiConfig);
this.pictureAlbums = new PictureAlbumApi(this.apiConfig);
this.cascadeInvites = new CascadeInviteApi(this.apiConfig);
this.cascadeRanks = new RanksApi(this.apiConfig);
}
addHeader(name: string, value: string) {
this.apiConfig.baseOptions.headers[name] = value;
this.refreshHandlers();
}
refreshHandlers() {
this.auth = new AuthApi(this.apiConfig);
this.account = new AccountApi(this.apiConfig);
this.contacts = new ContactsApi(this.apiConfig);
this.directMessaging = new DirectMessagingApi(this.apiConfig);
this.fileTransfers = new FileTransferApi(this.apiConfig);
this.cascades = new CascadeApi(this.apiConfig);
this.threads = new ThreadApi(this.apiConfig);
this.pictureCreator = new PicturesCreatorApi(this.apiConfig);
this.threadMessages = new ThreadMessagesApi(this.apiConfig);
this.pictures = new PicturesApi(this.apiConfig);
this.pictureComments = new PictureCommentsApi(this.apiConfig);
this.pictureAlbums = new PictureAlbumApi(this.apiConfig);
this.cascadeInvites = new CascadeInviteApi(this.apiConfig);
this.cascadeRanks = new RanksApi(this.apiConfig);
}
}

32
src/services/contact.ts Normal file
View File

@@ -0,0 +1,32 @@
import {Contact, ContactsApi} from "../generated";
const EXCLUDED_METHODS = ['getContacts', 'newContact'] as const;
type ExcludedMethods = typeof EXCLUDED_METHODS[number];
const excludeSet = new Set<string>(EXCLUDED_METHODS);
type OmitContactIdArg<T> = T extends (first: any, ...args: infer Rest) => infer R
? (...args: Rest) => R
: T;
type WrappedDMHandler<T> = {
[K in keyof T]: K extends ExcludedMethods
? T[K]
: T[K] extends (...args: any[]) => any
? OmitContactIdArg<T[K]>
: T[K];
};
function createContactWrapper<TFirst>(
instance: ContactsApi,
boundArg: TFirst
): WrappedDMHandler<ContactsApi> {
return new Proxy(instance, {
get(target, prop, receiver) {
const value = Reflect.get(target, prop, receiver);
if (typeof value === 'function' && !excludeSet.has(prop as string)) {
return (...args: any[]) => value.call(target, boundArg, ...args);
}
return value;
}
}) as unknown as WrappedDMHandler<ContactsApi>;
}

21
src/services/dm.ts Normal file
View File

@@ -0,0 +1,21 @@
import {DirectMessagingApi} from "../generated";
type OmitContactIdArg<T> = T extends (first: any, ...args: infer Rest) => infer R
? (...args: Rest) => R
: T;
type WrappedDMHandler<T> = {
[K in keyof T]: T[K] extends (...args: any[]) => any ? OmitContactIdArg<T[K]> : T[K];
};
export function createDMHandler<TFirst>(instance: DirectMessagingApi, contactId: TFirst): WrappedDMHandler<DirectMessagingApi> {
return new Proxy(instance, {
get(target, prop, receiver) {
const value = Reflect.get(target, prop, receiver);
if (typeof value === 'function') {
return (...args: any[]) => value.call(target, contactId, ...args);
}
return value;
}
}) as unknown as WrappedDMHandler<DirectMessagingApi>;
}

View File

@@ -1,6 +0,0 @@
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;
}

View File

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

View File

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