42 Commits

Author SHA1 Message Date
d97abc00e2 Fix version number
All checks were successful
Setup testing environment and test the code / build (push) Successful in 24s
Publish to NPM / build-and-publish (release) Successful in 26s
2026-04-17 16:27:31 +02:00
cada5487bf Merge remote-tracking branch 'origin/main'
Some checks failed
Setup testing environment and test the code / build (push) Successful in 33s
Publish to NPM / build-and-publish (release) Failing after 15s
# Conflicts:
#	package.json
2026-04-17 16:25:28 +02:00
2f9c65512b Added network permissions as constants and a permission calculator in permissions.ts 2026-04-17 16:25:03 +02:00
edd87375c3 Update package.json
Some checks failed
Setup testing environment and test the code / build (push) Has been cancelled
Publish to NPM / build-and-publish (release) Successful in 17s
2026-04-16 18:15:30 +02:00
b2d5b84435 Update package.json
Some checks failed
Setup testing environment and test the code / build (push) Has been cancelled
2026-04-16 18:13:06 +02:00
c460dc5385 Updated networkService.ts to use new /v2/ endpoint for uploading new network pictures
All checks were successful
Setup testing environment and test the code / build (push) Successful in 26s
Publish to NPM / build-and-publish (release) Successful in 37s
2026-04-16 16:55:48 +02:00
f54e76ab72 Updated extraMetadata to allow any type of data
All checks were successful
Setup testing environment and test the code / build (push) Successful in 26s
Publish to NPM / build-and-publish (release) Successful in 18s
2026-04-15 16:11:01 +02:00
fb1555338d Update WS
Some checks failed
Publish to NPM / build-and-publish (release) Successful in 27s
Setup testing environment and test the code / build (push) Has been cancelled
2026-04-14 16:44:27 +02:00
c98c917594 Update WS 2026-04-14 16:44:19 +02:00
cfb72d1772 Fixed types in getQuick functions
All checks were successful
Setup testing environment and test the code / build (push) Successful in 1m48s
Publish to NPM / build-and-publish (release) Successful in 27s
2026-04-14 16:05:09 +02:00
01d07d65d1 WebSocket Hotfix
All checks were successful
Setup testing environment and test the code / build (push) Successful in 1m9s
Publish to NPM / build-and-publish (release) Successful in 32s
2026-04-11 17:25:10 +02:00
c6ad01b710 Fix textChannelService.ts websocket
All checks were successful
Setup testing environment and test the code / build (push) Successful in 1m1s
Publish to NPM / build-and-publish (release) Successful in 30s
2026-04-11 17:14:39 +02:00
113cff5512 Fix textChannelService.ts websocket
Some checks failed
Setup testing environment and test the code / build (push) Failing after 1s
Publish to NPM / build-and-publish (release) Successful in 40s
2026-04-11 17:03:19 +02:00
2c91b73a60 Fix textChannelService.ts websocket
Some checks failed
Setup testing environment and test the code / build (push) Has been cancelled
2026-04-11 17:02:53 +02:00
866c8a1838 Removed dotenv
All checks were successful
Setup testing environment and test the code / build (push) Successful in 1m22s
Publish to NPM / build-and-publish (release) Successful in 29s
2026-04-10 21:17:16 +02:00
926a28b7f9 SessionManager hotfix
All checks were successful
Setup testing environment and test the code / build (push) Successful in 2m37s
Publish to NPM / build-and-publish (release) Successful in 1m44s
2026-04-10 19:18:13 +02:00
9d6a18dda4 Updated Attachment type
All checks were successful
Setup testing environment and test the code / build (push) Successful in 2m42s
Publish to NPM / build-and-publish (release) Successful in 2m47s
2026-04-10 09:18:16 +02:00
76f573023f WebSocket onNewConnId scope hotfix
All checks were successful
Setup testing environment and test the code / build (push) Successful in 1m10s
Publish to NPM / build-and-publish (release) Successful in 32s
2026-04-10 08:14:47 +02:00
b217123b99 Fix tests
All checks were successful
Setup testing environment and test the code / build (push) Successful in 1m9s
Publish to NPM / build-and-publish (release) Successful in 32s
2026-04-10 08:01:11 +02:00
59f7e10dd7 Race-condition fix
Some checks failed
Setup testing environment and test the code / build (push) Failing after 1m9s
2026-04-10 07:59:45 +02:00
56a0167120 WebSocket update
Some checks failed
Setup testing environment and test the code / build (push) Failing after 1m26s
Publish to NPM / build-and-publish (release) Successful in 29s
2026-04-10 07:38:52 +02:00
dc782003b0 Improve DX for message sending
Some checks failed
Setup testing environment and test the code / build (push) Failing after 0s
Publish to NPM / build-and-publish (release) Successful in 35s
2026-04-09 16:56:11 +02:00
2af9142d6c Improve DX for message sending
Some checks failed
Setup testing environment and test the code / build (push) Failing after 1m39s
Publish to NPM / build-and-publish (release) Failing after 33s
2026-04-09 16:53:08 +02:00
40905b225c Improve DX for message sending
Some checks failed
Setup testing environment and test the code / build (push) Has been cancelled
2026-04-09 16:52:55 +02:00
77e032fdb2 HotFix
All checks were successful
Setup testing environment and test the code / build (push) Successful in 59s
Publish to NPM / build-and-publish (release) Successful in 31s
2026-04-09 12:04:42 +02:00
96a5e5896b HotFix
All checks were successful
Setup testing environment and test the code / build (push) Successful in 1m13s
Publish to NPM / build-and-publish (release) Successful in 33s
2026-04-09 11:56:40 +02:00
14fe7ef41d HotFix 2026-04-09 11:56:29 +02:00
d04bd6a437 HotFix
All checks were successful
Setup testing environment and test the code / build (push) Successful in 57s
Publish to NPM / build-and-publish (release) Successful in 33s
2026-04-09 11:18:47 +02:00
0e553767b6 HotFix
Some checks failed
Publish to NPM / build-and-publish (release) Has been cancelled
Setup testing environment and test the code / build (push) Failing after 1m1s
2026-04-09 11:16:45 +02:00
b7af5497a4 Fix DM WebSocket
Some checks failed
Setup testing environment and test the code / build (push) Failing after 1m22s
Publish to NPM / build-and-publish (release) Successful in 30s
2026-04-09 11:12:41 +02:00
1cd629e3c1 loadSessions hotfix
All checks were successful
Setup testing environment and test the code / build (push) Successful in 1m20s
Publish to NPM / build-and-publish (release) Successful in 27s
2026-04-08 19:18:06 +02:00
7d50692ece Make storage async
All checks were successful
Setup testing environment and test the code / build (push) Successful in 1m4s
Publish to NPM / build-and-publish (release) Successful in 41s
2026-04-08 18:10:46 +02:00
d7422efcf0 Quick-fix
All checks were successful
Setup testing environment and test the code / build (push) Successful in 1m2s
2026-04-08 16:56:09 +02:00
1ccf534e04 Quick-fix
Some checks failed
Setup testing environment and test the code / build (push) Successful in 1m1s
Publish to NPM / build-and-publish (release) Failing after 29s
2026-04-08 16:48:11 +02:00
7ba341203d Quick-fix
All checks were successful
Setup testing environment and test the code / build (push) Successful in 1m6s
Publish to NPM / build-and-publish (release) Successful in 36s
2026-04-08 16:44:41 +02:00
54d466fb27 Quick-fix
All checks were successful
Setup testing environment and test the code / build (push) Successful in 1m30s
Publish to NPM / build-and-publish (release) Successful in 34s
2026-04-08 16:37:32 +02:00
07d30f7e83 Quick-fix
All checks were successful
Setup testing environment and test the code / build (push) Successful in 1m28s
2026-04-08 14:22:58 +02:00
cd806b7d17 Update package.json
Some checks failed
Setup testing environment and test the code / build (push) Has been cancelled
2026-04-08 13:59:00 +02:00
7daf542961 Update .gitea/workflows/publish.yml
Some checks failed
Setup testing environment and test the code / build (push) Has been cancelled
2026-04-08 13:55:29 +02:00
f911224847 Update .gitea/workflows/publish.yml
Some checks failed
Setup testing environment and test the code / build (push) Has been cancelled
2026-04-08 13:53:45 +02:00
c8d2de9f9d Merge remote-tracking branch 'origin/main'
Some checks failed
Setup testing environment and test the code / build (push) Has been cancelled
2026-04-08 13:51:47 +02:00
f8de78f3ab Type fixes 2026-04-08 13:51:43 +02:00
69 changed files with 371 additions and 263 deletions

View File

@@ -22,8 +22,9 @@ jobs:
- name: Build TypeScript
run: npm run build
- name: Add NPM token
run: echo "//registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }}" > .npmrc
- name: Publish to NPM
run: npm publish --access public
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
run: npm publish --access public

View File

@@ -45,13 +45,11 @@ jobs:
with:
node-version: '24'
- name: Create .env file
run: |
echo "API_URL=http://api:3000" >> .env
echo "CDN_URL=http://cdn:4000" >> .env
echo "WS_URL=ws://api:3000" >> .env
- name: Run Vitest
env:
API_URL: http://api:3000
CDN_URL: http://cdn:4000
WS_URL: ws://api:3000
run: |
npm install
npm test --experimental-websocket

3
.gitignore vendored
View File

@@ -13,4 +13,5 @@ yarn-error.log*
.DS_Store
.env
.env.*
!.env.example
!.env.example
/dist

6
README.md Normal file
View File

@@ -0,0 +1,6 @@
# Chatenium SDK For TypeScript
A library for interacting with the Chatenium API.
## Quick Start
```aiignore
npm install @chatenium/chatenium-sdk
```

8
package-lock.json generated
View File

@@ -1,12 +1,12 @@
{
"name": "chatenium-sdk",
"version": "1.0.0",
"name": "@chatenium/chatenium-sdk",
"version": "1.0.8",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "chatenium-sdk",
"version": "1.0.0",
"name": "@chatenium/chatenium-sdk",
"version": "1.0.8",
"dependencies": {
"@faker-js/faker": "^10.4.0",
"axios": "^1.14.0",

View File

@@ -1,8 +1,28 @@
{
"name": "chatenium-sdk",
"version": "1.0.0",
"name": "@chatenium/chatenium-sdk",
"version": "1.2.0",
"description": "A library for interacting with the Chatenium API",
"type": "module",
"main": "dist/index.js",
"module": "dist/index.js",
"types": "dist/index.d.ts",
"exports": {
".": {
"types": "./dist/index.d.ts",
"import": "./dist/index.js",
"default": "./dist/index.js"
},
"./core/*": "./dist/core/*.js",
"./services/*": "./dist/services/*.js",
"./domain/*": "./dist/domain/*.js",
"./mocks/*": "./dist/mocks/*.js",
"./storage/*": "./dist/storage/*.js"
},
"files": [
"dist",
"README.md",
"LICENSE"
],
"scripts": {
"build": "tsc",
"test": "vitest run",
@@ -15,11 +35,10 @@
"typescript": "^5.5.3",
"vitest": "^4.1.2"
},
"private": true,
"private": false,
"dependencies": {
"@faker-js/faker": "^10.4.0",
"axios": "^1.14.0",
"dotenv": "^17.4.0",
"msw": "^2.12.14",
"uuid": "^13.0.0"
}

View File

@@ -4,17 +4,13 @@ export interface SDKConfig {
wsUrl: string;
}
declare const process: any;
const isNode =
typeof process !== 'undefined' &&
typeof process.versions !== 'undefined' &&
typeof process.versions.node !== 'undefined';
if (isNode) {
try {
require('dotenv').config();
} catch { }
}
const getEnv = (key: string): string | undefined => {
if (!isNode) return undefined;
return process.env?.[key];

View File

@@ -1,5 +1,5 @@
import axios, {AxiosInstance} from 'axios';
import {environment} from "./environment";
import {environment} from './environment.js';
export const getClient = (cdn: boolean) => {
const env = environment.get();

32
src/core/permissions.ts Normal file
View File

@@ -0,0 +1,32 @@
export const permissions = {
createAndEditCategories: 2,
deleteCategories: 4,
createAndEditChannels: 8,
deleteChannels: 16,
deleteAnyMessage: 32,
pinMessages: 64,
createAndEditRanks: 128,
deleteRanks: 256,
changeNetworkNamePictureAndVisibility: 512,
createEmojis: 1024,
deleteEmojis: 2048,
manageEmbed: 4096,
createWebhooks: 8192,
deleteWebhooks: 16384,
createInvites: 32768,
deleteInvites: 65536,
sendMessages: 131072,
seeChannels: 262144,
banMembers: 524288,
kickMembers: 1048576,
unAndAssignRanksToMember: 2097152,
}
/**
* Determines whether the set of permissions includes the permission. Note that network owners have regular permissions just like the other members, so if the userid matches with the network's creator ID, then the permission is automatically granted. This logic is not included in this function.
* @param permissions
* @param permission
*/
export function permissionGranted(permissions: number, permission: number): Boolean {
return (permissions & permission) === permission;
}

View File

@@ -4,12 +4,12 @@ import {
WSMakeTokenReq,
WSMakeTokenResp,
WSMessagePayload
} from "../domain/websocket.schema";
import {getClient} from "./http";
import {CreateNetworkReq, Network} from "../domain/networkService.schema";
} from '../domain/websocket.schema.js';
import {getClient} from './http.js';
import {CreateNetworkReq, Network} from '../domain/networkService.schema.js';
import {isAxiosError} from "axios";
import {GenericErrorBody} from "../domain/http.schema";
import {environment} from "./environment";
import {GenericErrorBody} from '../domain/http.schema.js';
import {environment} from './environment.js';
export class WebSocketHandler {
private static instance: WebSocketHandler;
@@ -43,6 +43,13 @@ export class WebSocketHandler {
this.connection = new WebSocket(`${environment.get().wsUrl}/v2/ws?userid=${userid}&access_token=${resp.data.token}`)
console.log("Connected to websocket successfully")
this.startListening()
this.connection.onclose = () => {
console.error("The WebSocket connection was closed unexpectedly. Reconnecting...")
setTimeout(() => {
this.connect(userid, token)
}, 3000)
}
return
} catch (e) {
console.log(e)
@@ -64,9 +71,10 @@ export class WebSocketHandler {
if (payl.action == "connectionId") {
console.log("ConnectionID received")
const data: WSConnIdPayload = JSON.parse(payl.data);
this.connectionId = data.connId;
this.listeners.forEach(listener => {
console.log(data.connId, listener)
listener.onNewConnId(data.connId)
this.connectionId = data.connId;
})
} else {
this.listeners.forEach(listener => {
@@ -78,6 +86,10 @@ export class WebSocketHandler {
}
public registerService(service: WSListenerPipe) {
console.log("Registering service", service)
if (this.connId) {
service.onNewConnId(this.connId)
}
this.listeners.add(service);
}

View File

@@ -17,6 +17,7 @@ export interface JoinWebsocketRoomReq {
channelId: string
networkId: string
categoryId: string
disableAutoRemove: boolean
}
export interface StreamRegistry {

View File

@@ -24,4 +24,5 @@ export interface Attachment {
path: string
height: number
width: number
extraMetaData: Record<string, any> // Used by clients
}

View File

@@ -1,4 +1,4 @@
import {Attachment, TimeStamp} from "./common.schema";
import {Attachment, TimeStamp} from './common.schema.js';
export interface GetMessageReq {
from: number
@@ -58,6 +58,7 @@ export interface JoinWsRoomReq {
connId: string
chatid: string
userid: string
disableAutoRemove: boolean
}
// Response schemas

View File

@@ -41,5 +41,5 @@ export interface FileData {
}
export interface FileUploadProgressListener {
fileProgressUpdate: (fileId: string, allChunks: number, chunksDone: number) => void
fileProgressUpdate: (tempMsgId: string, fileId: string, allChunks: number, chunksDone: number) => void
}

View File

@@ -1,5 +1,5 @@
// Request schemas
import {PublicUserData, RGB, TimeStamp} from "./common.schema";
import {PublicUserData, RGB, TimeStamp} from './common.schema.js';
export interface GetInvitesReq {
networkId: string
@@ -208,9 +208,11 @@ export interface GetMembersReq {
}
export interface UploadNewPictureReq {
picId: string
userid: string
networkId: string
data: string
isImage: boolean
monogramColors: RGB | null
}
export interface ChangeVisibilityReq {
@@ -255,6 +257,7 @@ export interface JoinWebSocketRoomReq {
userid: string
connId: string
networkId: string
disableAutoRemove: boolean
}
export interface GetFromInviteReq {

View File

@@ -1,4 +1,4 @@
import {PublicUserData, TimeStamp} from "./common.schema";
import {PublicUserData, TimeStamp} from './common.schema.js';
// Request schemas
export interface GetReq {

View File

@@ -1,5 +1,5 @@
import {PublicUserData} from "./common.schema";
import {GIF} from "./userService.schema";
import {PublicUserData} from './common.schema.js';
import {GIF, PersonalUserData} from './userService.schema.js';
export interface Session {
userData: PersonalUserData

View File

@@ -1,4 +1,4 @@
import {Attachment, PublicUserData, TimeStamp} from "./common.schema";
import {Attachment, PublicUserData, TimeStamp} from './common.schema.js';
export interface GetMessageReq {
from: number
@@ -78,6 +78,7 @@ export interface JoinWsRoomReq {
networkId: string
categoryId: string
userid: string
disableAutoRemove: boolean
}
// Response schemas

View File

@@ -1,4 +1,4 @@
import {TimeStamp} from "./common.schema";
import {TimeStamp} from './common.schema.js';
export interface ChangeUsernameReq {
newUsername: string;

View File

@@ -5,8 +5,8 @@ import {
OtpSendCodeReq,
OtpVerifyCodeReq, PleVerifyCodeReq, PleVerifyCodeResp, RegisterReq, SignInSuccessResp,
UserDataValidationResp, VerifyPasswordResetReq
} from "../../domain/authService.schema";
import {GenericSuccessBody} from "../../domain/http.schema";
} from '../../domain/authService.schema.js';
import {GenericSuccessBody} from '../../domain/http.schema.js';
export const networkHandlers = [
http.get('*/user/authOptions', () => {

View File

@@ -1,6 +1,6 @@
import {http, HttpResponse} from "msw";
import {GetRTCAccessResp} from "../../domain/callService.schema";
import {StreamRegistry} from "../../domain/broadcastChannelService.schema";
import {GetRTCAccessResp} from '../../domain/callService.schema.js';
import {StreamRegistry} from '../../domain/broadcastChannelService.schema.js';
export const brcChanHandlers = [
http.get('*/network/channel/rtmpData', () => {

View File

@@ -1,5 +1,5 @@
import {http, HttpResponse} from "msw";
import {GetRTCAccessResp} from "../../domain/callService.schema";
import {GetRTCAccessResp} from '../../domain/callService.schema.js';
export const callHandlers = [
http.post('*/v2/chat/getRTCAccess', () => {

View File

@@ -1,5 +1,5 @@
import {http, HttpResponse} from "msw";
import {Chat, GetAvailabilityResp, StartNewReq} from "../../domain/chatService.schema";
import {Chat, GetAvailabilityResp, StartNewReq} from '../../domain/chatService.schema.js';
export const chatHandlers = [
http.get('*/chat/get', () => {

View File

@@ -1,7 +1,7 @@
import {http, HttpResponse} from "msw";
import {Chat} from "../../domain/chatService.schema";
import {FinishMessageReq, GetMessagePosResp, Message, PinnedMessage} from "../../domain/dmService.schema";
import {CreateNetworkReq, Network} from "../../domain/networkService.schema";
import {Chat} from '../../domain/chatService.schema.js';
import {FinishMessageReq, GetMessagePosResp, Message, PinnedMessage} from '../../domain/dmService.schema.js';
import {CreateNetworkReq, Network} from '../../domain/networkService.schema.js';
export const dmHandlers = [
http.get('*/chat/dm/messages', () => {
@@ -28,4 +28,8 @@ export const dmHandlers = [
message: body.message,
})
}),
http.post('*/v2/chat/dm/joinWebSocketRoom', async () => {
return HttpResponse.json()
}),
]

View File

@@ -1,6 +1,6 @@
import {http, HttpResponse} from "msw";
import {GetRTCAccessResp} from "../../domain/callService.schema";
import {RegisterUploadResp} from "../../domain/fileUploadService.schema";
import {GetRTCAccessResp} from '../../domain/callService.schema.js';
import {RegisterUploadResp} from '../../domain/fileUploadService.schema.js';
export const fileUploadHandlers = [
http.post('*/chat/cdnRegisterUpload', () => {

View File

@@ -5,8 +5,8 @@ import {
Network,
NetworkCategory,
NetworkInvite, POW
} from "../../domain/networkService.schema";
import {PublicUserData} from "../../domain/common.schema";
} from '../../domain/networkService.schema.js';
import {PublicUserData} from '../../domain/common.schema.js';
export const authHandlers = [
http.get('*/network/invites', () => {

View File

@@ -1,6 +1,6 @@
import {http, HttpResponse} from "msw";
import {CreateNetworkReq, Network, NetworkInvite} from "../../domain/networkService.schema";
import {Album, Comment, CreateAlbumReq, GetResp} from "../../domain/pictureService.schema";
import {CreateNetworkReq, Network, NetworkInvite} from '../../domain/networkService.schema.js';
import {Album, Comment, CreateAlbumReq, GetResp} from '../../domain/pictureService.schema.js';
export const pictureHandlers = [
http.get('*/picture/pictures', () => {

View File

@@ -1,6 +1,6 @@
import {http, HttpResponse} from "msw";
import {GetResp} from "../../domain/pictureService.schema";
import {Session} from "../../domain/userService.schema";
import {GetResp} from '../../domain/pictureService.schema.js';
import {Session} from '../../domain/userService.schema.js';
export const userHandler = [
http.post('*/user/getSessions', () => {

View File

@@ -1,12 +1,12 @@
import {networkHandlers} from "./handlers/auth.http";
import {authHandlers} from "./handlers/network.http";
import {pictureHandlers} from "./handlers/picture.http";
import {callHandlers} from "./handlers/call.http";
import {fileUploadHandlers} from "./handlers/fUpl.http";
import {chatHandlers} from "./handlers/chat.http";
import {dmHandlers} from "./handlers/dm.http";
import {userHandler} from "./handlers/user.http";
import {brcChanHandlers} from "./handlers/brcChan.http";
import {networkHandlers} from './handlers/auth.http.js';
import {authHandlers} from './handlers/network.http.js';
import {pictureHandlers} from './handlers/picture.http.js';
import {callHandlers} from './handlers/call.http.js';
import {fileUploadHandlers} from './handlers/fUpl.http.js';
import {chatHandlers} from './handlers/chat.http.js';
import {dmHandlers} from './handlers/dm.http.js';
import {userHandler} from './handlers/user.http.js';
import {brcChanHandlers} from './handlers/brcChan.http.js';
export const allHandlers = [
...authHandlers,

View File

@@ -1,4 +1,4 @@
import {setupServer} from "msw/node";
import {allHandlers} from "./index";
import {allHandlers} from './index.js';
export const mockServer = setupServer(...allHandlers)

View File

@@ -1,4 +1,4 @@
import {DatabaseAPI} from "../../storage/database";
import {DatabaseAPI} from '../../storage/database.js';
export class DatabaseMock implements DatabaseAPI {
database: { [collection: string]: { [key: string]: string } } = {};

View File

@@ -1,4 +1,4 @@
import {KeyringAPI} from "../../storage/keyring";
import {KeyringAPI} from '../../storage/keyring.js';
export class KeyringMock implements KeyringAPI {
ring: { [key: string]: string } = {};
@@ -7,15 +7,15 @@ export class KeyringMock implements KeyringAPI {
this.ring[key] = value;
}
get(key: string): string {
return this.ring[key];
get(key: string): Promise<string> {
return Promise.resolve(this.ring[key]);
}
getAll(): Promise<string[]> {
return Promise.resolve(Object.keys(this.ring));
}
delete(key: string) {
delete this.ring[key];
}
flush() {
this.ring = {};
}
}

View File

@@ -1,6 +1,6 @@
import {describe, expect, it} from "vitest";
import {AuthService} from "./authService";
import {VerificationTypeEmail} from "../domain/authService.schema";
import {AuthService} from './authService.js';
import {VerificationTypeEmail} from '../domain/authService.schema.js';
import {faker} from "@faker-js/faker/locale/en";
describe("AuthService", () => {

View File

@@ -1,4 +1,4 @@
import {getClient} from "../core/http";
import {getClient} from '../core/http.js';
import {
AuthMethods, FinishPleAccountReq,
LoginPasswordAuthReq, LoginWithApple, LoginWithGoogleReq, OtpPleCodeSendTestingResp,
@@ -6,9 +6,9 @@ import {
OtpVerifyCodeReq, PleSendCodeReq,
PleVerifyCodeReq, PleVerifyCodeResp, RegisterReq, ResetPasswordReq, ResetPasswordResp,
SignInSuccessResp, UserDataValidationResp, VerifyPasswordResetReq
} from "../domain/authService.schema";
} from '../domain/authService.schema.js';
import {isAxiosError} from "axios";
import {GenericErrorBody, GenericSuccessBody} from "../domain/http.schema";
import {GenericErrorBody, GenericSuccessBody} from '../domain/http.schema.js';
export class AuthService {
/**

View File

@@ -1,5 +1,5 @@
import {describe, expect, it} from "vitest";
import {BroadcastChannelService} from "./broadcastChannelService";
import {BroadcastChannelService} from './broadcastChannelService.js';
describe("BroadcastChannelService", () => {
const service = new BroadcastChannelService("", "", "", "", "", () => {})

View File

@@ -1,15 +1,15 @@
import {AxiosInstance, isAxiosError} from "axios";
import {getClient} from "../core/http";
import {MessageListener} from "../domain/websocket.schema";
import {WebSocketHandler} from "../core/webSocketHandler";
import {AcceptInviteReq} from "../domain/networkService.schema";
import {GenericErrorBody} from "../domain/http.schema";
import {getClient} from '../core/http.js';
import {MessageListener} from '../domain/websocket.schema.js';
import {WebSocketHandler} from '../core/webSocketHandler.js';
import {AcceptInviteReq} from '../domain/networkService.schema.js';
import {GenericErrorBody} from '../domain/http.schema.js';
import {
CreateServerReq,
GetRTMPDataReq,
JoinWebsocketRoomReq,
StreamRegistry
} from "../domain/broadcastChannelService.schema";
} from '../domain/broadcastChannelService.schema.js';
export class BroadcastChannelService {
userid: string
@@ -31,7 +31,7 @@ export class BroadcastChannelService {
})
WebSocketHandler.getInstance().registerService({
identifier: channelId,
onNewConnId: this.onNewConnId,
onNewConnId: newConnId => this.onNewConnId(newConnId),
onNewMessage: wsMessageListener,
})
}
@@ -81,6 +81,7 @@ export class BroadcastChannelService {
networkId: this.networkId,
connId: WebSocketHandler.getInstance().connId,
categoryId: this.categoryId,
disableAutoRemove: true
});
return
} catch (e) {

View File

@@ -1,5 +1,5 @@
import {describe, expect, it} from "vitest";
import {CallService} from "./callService";
import {CallService} from './callService.js';
describe("CallService", () => {
const handler = new CallService("", "")

View File

@@ -1,8 +1,8 @@
import {getClient} from "../core/http";
import {OtpPleCodeSendTestingResp, OtpSendCodeReq} from "../domain/authService.schema";
import {getClient} from '../core/http.js';
import {OtpPleCodeSendTestingResp, OtpSendCodeReq} from '../domain/authService.schema.js';
import {isAxiosError} from "axios";
import {GenericErrorBody} from "../domain/http.schema";
import {GetRTCAccessReq, GetRTCAccessResp, InviteToCallReq} from "../domain/callService.schema";
import {GenericErrorBody} from '../domain/http.schema.js';
import {GetRTCAccessReq, GetRTCAccessResp, InviteToCallReq} from '../domain/callService.schema.js';
export class CallService {
userid: string;

View File

@@ -1,6 +1,6 @@
import {describe, expect, it} from "vitest";
import {ChatService} from "./chatService";
import {DatabaseMock} from "../mocks/storage/database";
import {ChatService} from './chatService.js';
import {DatabaseMock} from '../mocks/storage/database.js';
import {faker} from "@faker-js/faker/locale/en";
describe("ChatService", () => {

View File

@@ -1,18 +1,18 @@
import {DatabaseAPI} from "../storage/database";
import {MessageListener} from "../domain/websocket.schema";
import {getClient} from "../core/http";
import {WebSocketHandler} from "../core/webSocketHandler";
import {DatabaseAPI} from '../storage/database.js';
import {MessageListener} from '../domain/websocket.schema.js';
import {getClient} from '../core/http.js';
import {WebSocketHandler} from '../core/webSocketHandler.js';
import {AxiosInstance, isAxiosError} from "axios";
import {NetworkInvite} from "../domain/networkService.schema";
import {GenericErrorBody} from "../domain/http.schema";
import {NetworkInvite} from '../domain/networkService.schema.js';
import {GenericErrorBody} from '../domain/http.schema.js';
import {
Chat,
GetAvailabilityReq,
GetAvailabilityResp,
StartNewReq,
ToggleChatMuteReq
} from "../domain/chatService.schema";
import {Message} from "../domain/dmService.schema";
} from '../domain/chatService.schema.js';
import {Message} from '../domain/dmService.schema.js';
/**
* ChatService is an exception because it's one instance for all chats because it's unnecessary to create a new instance for each chat
@@ -32,7 +32,7 @@ export class ChatService {
})
WebSocketHandler.getInstance().registerService({
identifier: userid,
onNewConnId: this.onNewConnId,
onNewConnId: newConnId => this.onNewConnId(newConnId),
onNewMessage: wsMessageListener,
})
}
@@ -58,8 +58,8 @@ export class ChatService {
}
}
getQuick(): Message[] {
const chats = this.database.get("chats", this.userid)
async getQuick(): Promise<Chat[]> {
const chats = await this.database.get("chats", this.userid)
if (chats) {
return JSON.parse(chats)
} else {

View File

@@ -1,6 +1,6 @@
import {describe, expect, it} from "vitest";
import {DMService} from "./dmService";
import {DatabaseMock} from "../mocks/storage/database";
import {DMService} from './dmService.js';
import {DatabaseMock} from '../mocks/storage/database.js';
import {faker} from "@faker-js/faker/locale/en";
describe("DmService", () => {
@@ -23,7 +23,7 @@ describe("DmService", () => {
it('should send a new message', async () => {
const message = faker.internet.displayName()
const newMessage = await service.sendMessage(message)
const newMessage = await service.sendMessage("", message)
expect(newMessage.message).toBe(message)
});
})

View File

@@ -1,8 +1,8 @@
import {DatabaseAPI} from "../storage/database";
import {DatabaseAPI} from '../storage/database.js';
import {AxiosInstance, isAxiosError} from "axios";
import {MessageListener} from "../domain/websocket.schema";
import {getClient} from "../core/http";
import {WebSocketHandler} from "../core/webSocketHandler";
import {MessageListener} from '../domain/websocket.schema.js';
import {getClient} from '../core/http.js';
import {WebSocketHandler} from '../core/webSocketHandler.js';
import {
DeleteMessagesReq,
EditMessageReq,
@@ -10,11 +10,11 @@ import {
GetMessagePosResp, JoinWsRoomReq,
Message, PinMessageReq,
PinnedMessage, ReadMessagesReq, UnpinMessageReq
} from "../domain/dmService.schema";
import {NetworkInvite} from "../domain/networkService.schema";
import {GenericErrorBody} from "../domain/http.schema";
import {FileData, FileUploadProgressListener} from "../domain/fileUploadService.schema";
import {FileUploadService} from "./fileUploadService";
} from '../domain/dmService.schema.js';
import {NetworkInvite} from '../domain/networkService.schema.js';
import {GenericErrorBody} from '../domain/http.schema.js';
import {FileData, FileUploadProgressListener} from '../domain/fileUploadService.schema.js';
import {FileUploadService} from './fileUploadService.js';
export class DMService {
userid: string;
@@ -36,14 +36,15 @@ export class DMService {
})
WebSocketHandler.getInstance().registerService({
identifier: chatid,
onNewConnId: this.onNewConnId,
onNewConnId: newConnId => this.onNewConnId(newConnId),
onNewMessage: wsMessageListener,
})
}
private onNewConnId(newConnId: string) {
console.log("NetworkService: New connection id")
console.log("DmService: New connection id")
this.client.defaults.headers["X-WS-ID"] = newConnId;
this.joinWebSocketRoom().then()
}
/**
@@ -65,8 +66,8 @@ export class DMService {
}
}
getQuick(): Message[] {
const messages = this.database.get("messages", this.chatid)
async getQuick(): Promise<Message[]> {
const messages = await this.database.get("messages", this.chatid)
if (messages) {
return JSON.parse(messages)
} else {
@@ -129,17 +130,18 @@ export class DMService {
/**
* Sends a new message to the chat
* @param tempMsgId
* @param message
* @param replyTo
* @param replyToMessage
* @param attachments
* @param progressListener
*/
async sendMessage(message: string, replyTo: string | null = null, replyToMessage: string | null = null, attachments: FileData[] | null = null, progressListener: FileUploadProgressListener | null = null): Promise<Message> {
async sendMessage(tempMsgId: string, message: string, replyTo: string | null = null, replyToMessage: string | null = null, attachments: FileData[] | null = null, progressListener: FileUploadProgressListener | null = null): Promise<Message> {
let uploadId = ""
if (attachments) {
const uploader = new FileUploadService(this.token)
uploadId = await uploader.uploadFiles(this.chatid, this.userid, attachments, progressListener!)
uploadId = await uploader.uploadFiles(tempMsgId, this.chatid, this.userid, attachments, progressListener!)
}
try {
const resp = await this.client.post<Message>("chat/dm/finishMessage", <FinishMessageReq>{
@@ -244,10 +246,11 @@ export class DMService {
*/
async joinWebSocketRoom(): Promise<void> {
try {
const resp = await this.client.patch("chat/dm/joinWebSocketRoom", <JoinWsRoomReq>{
await this.client.post("v2/chat/dm/joinWebSocketRoom", <JoinWsRoomReq>{
chatid: this.chatid,
userid: this.userid,
connId: WebSocketHandler.getInstance().connId,
disableAutoRemove: true
});
return
} catch (e) {

View File

@@ -1,17 +1,17 @@
import {DatabaseAPI} from "../storage/database";
import {DatabaseAPI} from '../storage/database.js';
import {AxiosInstance, isAxiosError} from "axios";
import {MessageListener} from "../domain/websocket.schema";
import {getClient} from "../core/http";
import {WebSocketHandler} from "../core/webSocketHandler";
import {CreateNetworkReq, Network} from "../domain/networkService.schema";
import {GenericErrorBody} from "../domain/http.schema";
import {MessageListener} from '../domain/websocket.schema.js';
import {getClient} from '../core/http.js';
import {WebSocketHandler} from '../core/webSocketHandler.js';
import {CreateNetworkReq, Network} from '../domain/networkService.schema.js';
import {GenericErrorBody} from '../domain/http.schema.js';
import {
AcceptFileTransferReq, DeclineFileTransferReq, FileTransferSendAnswerRTCReq,
FileTransferSendICERTCReq, FileTransferSendOfferRTCReq,
StartNewFileTransferReq,
StartNewFileTransferResp,
TransferableFileMetadata
} from "../domain/fileTransferService.schema";
} from '../domain/fileTransferService.schema.js';
export class FileTransferService {
userid: string;

View File

@@ -1,10 +1,12 @@
import {describe, expect, it} from "vitest";
import {FileUploadService} from "./fileUploadService";
import {FileUploadService} from './fileUploadService.js';
describe("fileUploadService", () => {
it('should upload files', async () => {
const service = new FileUploadService("");
const uploadId = await service.uploadFiles("", "", [])
const uploadId = await service.uploadFiles("","", "", [], {
fileProgressUpdate: () => {}
})
expect(uploadId).toBe("MockUploadId")
});
})

View File

@@ -4,11 +4,11 @@ import {
FileUploadRegistration, FinishUploadReq,
RegisterUploadReq,
RegisterUploadResp
} from "../domain/fileUploadService.schema";
} from '../domain/fileUploadService.schema.js';
import {AxiosInstance, isAxiosError} from "axios";
import {getClient} from "../core/http";
import {InviteToCallReq} from "../domain/callService.schema";
import {GenericErrorBody} from "../domain/http.schema";
import {getClient} from '../core/http.js';
import {InviteToCallReq} from '../domain/callService.schema.js';
import {GenericErrorBody} from '../domain/http.schema.js';
import {v4 as uuidv4} from 'uuid';
export class FileUploadService {
@@ -39,12 +39,13 @@ export class FileUploadService {
/**
* Automatically registers the upload, calculates chunksize and uploads each chunk and returns with an uploadId that must be provided when sending the message
* @param tempMsgId
* @param roomId chatid or channelId
* @param userid
* @param files
* @param listener
*/
async uploadFiles(roomId: string, userid: string, files: FileData[], listener: FileUploadProgressListener): Promise<string> {
async uploadFiles(tempMsgId: string, roomId: string, userid: string, files: FileData[], listener: FileUploadProgressListener): Promise<string> {
let registrations: FileUploadRegistration[] = [];
files.forEach(file => {
@@ -63,7 +64,7 @@ export class FileUploadService {
files: registrations,
});
for (let filesUploaded = 0; filesUploaded < files.length; filesUploaded++) {
await this.uploadFile(resp.data.uploadId, roomId, userid, files[filesUploaded], registrations[filesUploaded], listener)
await this.uploadFile(tempMsgId, resp.data.uploadId, roomId, userid, files[filesUploaded], registrations[filesUploaded], listener)
}
await this.finishUpload(roomId, userid, resp.data.uploadId)
return resp.data.uploadId
@@ -93,7 +94,7 @@ export class FileUploadService {
}
}
private async uploadFile(uploadId: string, roomId: string, userid: string, file: FileData, registration: FileUploadRegistration, listener: FileUploadProgressListener): Promise<void> {
private async uploadFile(tempMsgId: string, uploadId: string, roomId: string, userid: string, file: FileData, registration: FileUploadRegistration, listener: FileUploadProgressListener): Promise<void> {
const chunkSize = this.calculateChunkSize(file.data.size);
const totalChunks = Math.ceil(file.data.size / chunkSize);
@@ -105,7 +106,7 @@ export class FileUploadService {
const chunk = new Uint8Array(arrayBuffer.slice(start, end));
const base64 = this.uint8ToBase64(chunk);
await this.uploadChunk(uploadId, roomId, userid, registration.fileId, base64);
listener.fileProgressUpdate(file.fileId, totalChunks, i)
listener.fileProgressUpdate(tempMsgId, file.fileId, totalChunks, i)
}
}

View File

@@ -1,9 +1,9 @@
import {describe, expect, it} from "vitest";
import {NetworkService} from "./networkService";
import {DatabaseMock} from "../mocks/storage/database";
import {NetworkService} from './networkService.js';
import {DatabaseMock} from '../mocks/storage/database.js';
import {faker} from "@faker-js/faker/locale/en";
import {getClient} from "../core/http";
import {environment, SDKConfig} from "../core/environment";
import {getClient} from '../core/http.js';
import {environment, SDKConfig} from '../core/environment.js';
describe("NetworkService", () => {
const service = new NetworkService("", "", "", new DatabaseMock(), (action, data) => {})

View File

@@ -1,7 +1,7 @@
import {DatabaseAPI} from "../storage/database";
import {getClient} from "../core/http";
import {DatabaseAPI} from '../storage/database.js';
import {getClient} from '../core/http.js';
import {AxiosInstance, isAxiosError} from "axios";
import {GenericErrorBody} from "../domain/http.schema";
import {GenericErrorBody} from '../domain/http.schema.js';
import {
AcceptInviteReq, AssignRankToMemberReq, BanMemberReq, ChangeVisibilityReq, CreateCategoryReq, CreateChannelReq,
CreateInviteReq,
@@ -15,11 +15,11 @@ import {
NetworkInvite, NetworkRank, OverwriteChannelPermissionReq, OverwritePermissionReq, PermissionUpdate, POW,
RemoveRankFromMemberReq, ToggleCategoryMuteReq, ToggleChannelNetworkMuteReq, ToggleNetworkMuteReq,
UnbanMemberReq, UploadNewPictureReq
} from "../domain/networkService.schema";
import {PublicUserData, RGB} from "../domain/common.schema";
import {WebSocketHandler} from "../core/webSocketHandler";
import {MessageListener} from "../domain/websocket.schema";
import {Message} from "../domain/dmService.schema";
} from '../domain/networkService.schema.js';
import {PublicUserData, RGB} from '../domain/common.schema.js';
import {WebSocketHandler} from '../core/webSocketHandler.js';
import {MessageListener} from '../domain/websocket.schema.js';
import {Message} from '../domain/dmService.schema.js';
export class NetworkService {
userid: string;
@@ -39,7 +39,7 @@ export class NetworkService {
})
WebSocketHandler.getInstance().registerService({
identifier: networkId,
onNewConnId: this.onNewConnId,
onNewConnId: newConnId => this.onNewConnId(newConnId),
onNewMessage: wsMessageListener,
})
}
@@ -108,8 +108,8 @@ export class NetworkService {
}
}
getQuick(): Message[] {
const networks = this.database.get("networks", this.userid)
async getQuick(): Promise<Network[]> {
const networks = await this.database.get("networks", this.userid)
if (networks) {
return JSON.parse(networks)
} else {
@@ -711,14 +711,18 @@ export class NetworkService {
/**
* Uploads a new network picture
* @param picId
* @param isImage
* @param image
* @param colors
*/
async uploadNewPic(picId: string): Promise<void> {
async uploadNewPic(isImage: boolean, image: string | null, colors: RGB | null): Promise<void> {
try {
await this.client.patch<PublicUserData[]>("network/uploadNewPic", <UploadNewPictureReq>{
await this.client.patch<PublicUserData[]>("v2/network/uploadNewPic", <UploadNewPictureReq>{
userid: this.userid,
networkId: this.networkId,
picId: picId,
data: image,
isImage: isImage,
monogramColors: colors
});
return
} catch (e) {
@@ -863,6 +867,7 @@ export class NetworkService {
userid: this.userid,
networkId: this.networkId,
connId: connId,
disableAutoRemove: true
});
return
} catch (e) {

View File

@@ -1,6 +1,6 @@
import {describe, expect, it} from "vitest";
import {PictureService} from "./pictureService";
import {DatabaseMock} from "../mocks/storage/database";
import {PictureService} from './pictureService.js';
import {DatabaseMock} from '../mocks/storage/database.js';
import {faker} from "@faker-js/faker/locale/en";
describe("PictureService", () => {

View File

@@ -1,8 +1,8 @@
import {DatabaseAPI} from "../storage/database";
import {DatabaseAPI} from '../storage/database.js';
import {AxiosInstance, isAxiosError} from "axios";
import {getClient} from "../core/http";
import {NetworkInvite} from "../domain/networkService.schema";
import {GenericErrorBody} from "../domain/http.schema";
import {getClient} from '../core/http.js';
import {NetworkInvite} from '../domain/networkService.schema.js';
import {GenericErrorBody} from '../domain/http.schema.js';
import {
Album, ChangePictureVisibilityReq, Comment,
CreateAlbumReq,
@@ -10,9 +10,9 @@ import {
DiscoveryResp, EditPictureTitleReq,
FinalizeUploadReq,
GetResp, PostCommentReq, ToggleFollowReq, TogglePictureLikeReq, UploadImageReq
} from "../domain/pictureService.schema";
import {environment} from "../core/environment";
import {Message} from "../domain/dmService.schema";
} from '../domain/pictureService.schema.js';
import {environment} from '../core/environment.js';
import {Message} from '../domain/dmService.schema.js';
export class PictureService {
userid: string;
@@ -54,8 +54,8 @@ export class PictureService {
}
}
getQuick(): Message[] {
const pictures = this.database.get("pictures", this.uploaderId)
async getQuick(): Promise<Message[]> {
const pictures = await this.database.get("pictures", this.uploaderId)
if (pictures) {
return JSON.parse(pictures)
} else {

View File

@@ -1,11 +1,11 @@
import {PublicUserData} from "../domain/common.schema";
import {DatabaseAPI} from "../storage/database";
import {KeyringAPI} from "../storage/keyring";
import {KeyValueAPI} from "../storage/keyvalue";
import {Session, ValidateSessionReq, ValidateSessionResp} from "../domain/sessionManager.schema";
import {PublicUserData} from '../domain/common.schema.js';
import {DatabaseAPI} from '../storage/database.js';
import {KeyringAPI} from '../storage/keyring.js';
import {KeyValueAPI} from '../storage/keyvalue.js';
import {Session, ValidateSessionReq, ValidateSessionResp} from '../domain/sessionManager.schema.js';
import {AxiosInstance} from "axios";
import {getClient} from "../core/http";
import {PersonalUserData} from "../domain/userService.schema";
import {getClient} from '../core/http.js';
import {PersonalUserData} from '../domain/userService.schema.js';
export class SessionManager {
client: AxiosInstance;
@@ -33,18 +33,26 @@ export class SessionManager {
/**
* Loads all saved sessions
*/
loadSessions(): Session[] {
const tokens = this.keyring.getAll()
async loadSessions(): Promise<Session[]> {
const tokens = await this.keyring.getAll()
const sessions: Session[] = []
tokens.forEach(token => {
const userData = this.database.get("sessions", token.split(".")[0])
if (userData) {
sessions.push({
token: token,
userData: JSON.parse(userData)
})
for (const tokenKey of tokens) {
try {
const token = await this.keyring.get(tokenKey)
const userData = await this.database.get("sessions", tokenKey)
if (userData && userData.trim().length > 0) {
sessions.push({
token: token,
userData: JSON.parse(userData)
})
}
} catch (e) {
console.error(`Failed to parse session for ${tokenKey}:`, e)
continue
}
})
}
return sessions
}
@@ -52,8 +60,8 @@ export class SessionManager {
/**
* Gets the preferred user set by the client
*/
getPreferredUser(): string {
return this.KeyValue.get("preferredUser") ?? ""
async getPreferredUser(): Promise<string> {
return await this.KeyValue.get("preferredUser") ?? ""
}
/**
@@ -67,9 +75,14 @@ export class SessionManager {
/**
* Loads the preferred session by the client
*/
loadPreferredSession() {
const sessions = this.loadSessions()
let preferredUser = this.getPreferredUser()
async loadPreferredSession() {
const sessions = await this.loadSessions()
if (sessions.length == 0) {
throw new Error("No sessions found")
}
let preferredUser = await this.getPreferredUser()
if (preferredUser == "") {
preferredUser = sessions[0].userData.userid
this.setPreferredUser(sessions[0].userData.userid)

View File

@@ -1,8 +1,8 @@
import {DatabaseAPI} from "../storage/database";
import {DatabaseAPI} from '../storage/database.js';
import {AxiosInstance, isAxiosError} from "axios";
import {MessageListener} from "../domain/websocket.schema";
import {getClient} from "../core/http";
import {WebSocketHandler} from "../core/webSocketHandler";
import {MessageListener} from '../domain/websocket.schema.js';
import {getClient} from '../core/http.js';
import {WebSocketHandler} from '../core/webSocketHandler.js';
import {
DeleteMessagesReq,
EditMessageReq,
@@ -10,11 +10,11 @@ import {
GetMessagePosResp, JoinWsRoomReq,
Message, PinMessageReq,
PinnedMessage, ReadMessagesReq, UnpinMessageReq
} from "../domain/textChannelService.schema";
import {NetworkInvite} from "../domain/networkService.schema";
import {GenericErrorBody} from "../domain/http.schema";
import {FileData, FileUploadProgressListener} from "../domain/fileUploadService.schema";
import {FileUploadService} from "./fileUploadService";
} from '../domain/textChannelService.schema.js';
import {NetworkInvite} from '../domain/networkService.schema.js';
import {GenericErrorBody} from '../domain/http.schema.js';
import {FileData, FileUploadProgressListener} from '../domain/fileUploadService.schema.js';
import {FileUploadService} from './fileUploadService.js';
export class TextChannelServiceService {
userid: string;
@@ -40,7 +40,7 @@ export class TextChannelServiceService {
})
WebSocketHandler.getInstance().registerService({
identifier: channelId,
onNewConnId: this.onNewConnId,
onNewConnId: newConnId => this.onNewConnId(newConnId),
onNewMessage: wsMessageListener,
})
}
@@ -48,6 +48,7 @@ export class TextChannelServiceService {
private onNewConnId(newConnId: string) {
console.log("NetworkService: New connection id")
this.client.defaults.headers["X-WS-ID"] = newConnId;
this.joinWebSocketRoom().then()
}
/**
@@ -71,8 +72,8 @@ export class TextChannelServiceService {
}
}
getQuick(): Message[] {
const messages = this.database.get("networkmessages", this.channelId)
async getQuick(): Promise<Message[]> {
const messages = await this.database.get("networkmessages", this.channelId)
if (messages) {
return JSON.parse(messages)
} else {
@@ -137,17 +138,18 @@ export class TextChannelServiceService {
/**
* Sends a new message to the chat
* @param tempMsgId
* @param message
* @param replyTo
* @param replyToMessage
* @param attachments
* @param progressListener
*/
async sendMessage(message: string, replyTo: string | null = null, replyToMessage: string | null = null, attachments: FileData[] | null = null, progressListener: FileUploadProgressListener | null = null): Promise<Message> {
async sendMessage(tempMsgId: string, message: string, replyTo: string | null = null, replyToMessage: string | null = null, attachments: FileData[] | null = null, progressListener: FileUploadProgressListener | null = null): Promise<Message> {
let uploadId = ""
if (attachments) {
const uploader = new FileUploadService(this.token)
uploadId = await uploader.uploadFiles(this.channelId, this.userid, attachments, progressListener!)
uploadId = await uploader.uploadFiles(tempMsgId, this.channelId, this.userid, attachments, progressListener!)
}
try {
const resp = await this.client.post<Message>("network/channel/finishMessage", <FinishMessageReq>{
@@ -262,12 +264,13 @@ export class TextChannelServiceService {
*/
async joinWebSocketRoom(): Promise<void> {
try {
const resp = await this.client.patch("network/channel/joinWebSocketRoom", <JoinWsRoomReq>{
const resp = await this.client.post("v2/network/channel/joinWebSocketRoom", <JoinWsRoomReq>{
networkId: this.networkId,
channelId: this.channelId,
categoryId: this.categoryId,
userid: this.userid,
connId: WebSocketHandler.getInstance().connId,
disableAutoRemove: true
});
return
} catch (e) {

View File

@@ -1,6 +1,6 @@
import {describe, expect, it} from "vitest";
import {UserService} from "./userService";
import {DatabaseMock} from "../mocks/storage/database";
import {UserService} from './userService.js';
import {DatabaseMock} from '../mocks/storage/database.js';
describe("UserService", () => {
const service = new UserService("", "", new DatabaseMock())

View File

@@ -1,10 +1,10 @@
import {DatabaseAPI} from "../storage/database";
import {DatabaseAPI} from '../storage/database.js';
import {AxiosInstance, isAxiosError} from "axios";
import {MessageListener} from "../domain/websocket.schema";
import {getClient} from "../core/http";
import {WebSocketHandler} from "../core/webSocketHandler";
import {DeleteCategoryReq} from "../domain/networkService.schema";
import {GenericErrorBody} from "../domain/http.schema";
import {MessageListener} from '../domain/websocket.schema.js';
import {getClient} from '../core/http.js';
import {WebSocketHandler} from '../core/webSocketHandler.js';
import {DeleteCategoryReq} from '../domain/networkService.schema.js';
import {GenericErrorBody} from '../domain/http.schema.js';
import {
ChangeDisplayNameReq,
ChangeEmailReq,
@@ -12,9 +12,9 @@ import {
ChangeUsernameReq, CurrNewCodeTestingResp, DeleteReq, GetSessionsReq, GIF, RegisterFCMTokenReq, Session,
ToggleGifSaveReq, UploadNewPfpCdnReq, UploadNewPfpCdnResp,
UploadNewPfpReq, VerifyMailChangeReq, VerifyPhoneChange
} from "../domain/userService.schema";
import {RGB} from "../domain/common.schema";
import {OtpPleCodeSendTestingResp} from "../domain/authService.schema";
} from '../domain/userService.schema.js';
import {RGB} from '../domain/common.schema.js';
import {OtpPleCodeSendTestingResp} from '../domain/authService.schema.js';
export class UserService {
userid: string;

View File

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

View File

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

View File

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

View File

@@ -1,5 +1,5 @@
import {beforeAll, afterEach, afterAll, vi} from 'vitest';
import {mockServer} from "./mocks/node";
import {mockServer} from './mocks/node.js';
beforeAll(() => mockServer.listen({onUnhandledRequest: 'error'}));
afterEach(() => mockServer.resetHandlers());

View File

@@ -1,6 +1,6 @@
import {describe, expect, it} from "vitest";
import {AuthService} from "../src/services/authService";
import {VerificationTypeEmail} from "../src/domain/authService.schema";
import {AuthService} from '../src/services/authService.js';
import {VerificationTypeEmail} from '../src/domain/authService.schema.js';
describe("AuthService", () => {
it("should return authMethods", async () => {

View File

@@ -1,5 +1,5 @@
import {describe, expect, it} from "vitest";
import {BroadcastChannelService} from "../src/services/broadcastChannelService";
import {BroadcastChannelService} from '../src/services/broadcastChannelService.js';
const BRC_CHAN_SERVICE_TESTING_NETWORK_ID = "000000000000000000000000"
const BRC_CHAN_SERVICE_TESTING_USER_ID = "000000000000000000000000"

View File

@@ -1,6 +1,6 @@
import {describe, expect, it} from "vitest";
import {DatabaseMock} from "../src/mocks/storage/database";
import {ChatService} from "../src/services/chatService";
import {DatabaseMock} from '../src/mocks/storage/database.js';
import {ChatService} from '../src/services/chatService.js';
describe("ChatService Integration Testing", () => {
const CHAT_SERVICE_TESTING_USER_ID = "000000000000000000000000"

View File

@@ -1,7 +1,7 @@
import {describe, expect, it} from "vitest";
import {DMService} from "../src/services/dmService";
import {ChatService} from "../src/services/chatService";
import {DatabaseMock} from "../src/mocks/storage/database";
import {DMService} from '../src/services/dmService.js';
import {ChatService} from '../src/services/chatService.js';
import {DatabaseMock} from '../src/mocks/storage/database.js';
import {faker} from "@faker-js/faker/locale/en";
describe("DmService Integration Testing", () => {
@@ -38,7 +38,7 @@ describe("DmService Integration Testing", () => {
it('should send a message', async () => {
const message = faker.lorem.paragraph()
const newMessage = await service.sendMessage(message)
const newMessage = await service.sendMessage("", message)
expect(newMessage.message).toBe(message)
});

View File

@@ -1,8 +1,8 @@
import {describe, it} from "vitest";
import {FileUploadService} from "../src/services/fileUploadService";
import {environment, SDKConfig} from "../src/core/environment";
import {getClient} from "../src/core/http";
import {FileData} from "../src/domain/fileUploadService.schema";
import {FileUploadService} from '../src/services/fileUploadService.js';
import {environment, SDKConfig} from '../src/core/environment.js';
import {getClient} from '../src/core/http.js';
import {FileData} from '../src/domain/fileUploadService.schema.js';
import axios from "axios";
import {v4 as uuidv4} from 'uuid';
@@ -18,6 +18,7 @@ describe("FileUploadService Integration Testing", () => {
const service = new FileUploadService(FILE_UPL_SERVICE_TESTING_TOKEN);
await service.uploadFiles(
"",
FILE_UPL_SERVICE_TESTING_CHAT_ID,
FILE_UPL_SERVICE_TESTING_USER_ID,
[

View File

@@ -1,12 +1,12 @@
import {describe, expect, it} from "vitest";
import {NetworkService} from "../src/services/networkService";
import {DatabaseMock} from "../src/mocks/storage/database";
import {environment, SDKConfig} from "../src/core/environment";
import {getClient} from "../src/core/http";
import {NetworkService} from '../src/services/networkService.js';
import {DatabaseMock} from '../src/mocks/storage/database.js';
import {environment, SDKConfig} from '../src/core/environment.js';
import {getClient} from '../src/core/http.js';
import {faker} from "@faker-js/faker/locale/en";
import {AuthService} from "../src/services/authService";
import {RGB} from "../src/domain/common.schema";
import {NetworkPermissions, PermissionUpdate} from "../src/domain/networkService.schema";
import {AuthService} from '../src/services/authService.js';
import {RGB} from '../src/domain/common.schema.js';
import {NetworkPermissions, PermissionUpdate} from '../src/domain/networkService.schema.js';
const NETWORK_SERVICE_TESTING_NETWORK_ID = "000000000000000000000000"
const NETWORK_SERVICE_TESTING_USER_ID = "000000000000000000000000"

View File

@@ -1,9 +1,9 @@
import {describe, expect, it} from "vitest";
import {environment, SDKConfig} from "../src/core/environment";
import {NetworkService} from "../src/services/networkService";
import {DatabaseMock} from "../src/mocks/storage/database";
import {getClient} from "../src/core/http";
import {PictureService} from "../src/services/pictureService";
import {environment, SDKConfig} from '../src/core/environment.js';
import {NetworkService} from '../src/services/networkService.js';
import {DatabaseMock} from '../src/mocks/storage/database.js';
import {getClient} from '../src/core/http.js';
import {PictureService} from '../src/services/pictureService.js';
import {faker} from "@faker-js/faker/locale/en";
const PICTURE_SERVICE_TESTING_TOKEN = "testingToken"

View File

@@ -1,9 +1,9 @@
import {describe, expect, it} from "vitest";
import {DMService} from "../src/services/dmService";
import {ChatService} from "../src/services/chatService";
import {DatabaseMock} from "../src/mocks/storage/database";
import {DMService} from '../src/services/dmService.js';
import {ChatService} from '../src/services/chatService.js';
import {DatabaseMock} from '../src/mocks/storage/database.js';
import {faker} from "@faker-js/faker/locale/en";
import {TextChannelServiceService} from "../src/services/textChannelService";
import {TextChannelServiceService} from '../src/services/textChannelService.js';
describe("DmService Integration Testing", () => {
const TXT_CHAN_SERVICE_TESTING_CHANNEL_ID = "222222222222222222222222"
@@ -43,7 +43,7 @@ describe("DmService Integration Testing", () => {
it('should send a message', async () => {
const message = faker.lorem.paragraph()
const newMessage = await service.sendMessage(message)
const newMessage = await service.sendMessage("", message)
expect(newMessage.message).toBe(message)
});

View File

@@ -1,7 +1,7 @@
import {describe, expect, it} from "vitest";
import {UserService} from "../src/services/userService";
import {DatabaseMock} from "../src/mocks/storage/database";
import {RGB} from "../src/domain/common.schema"
import {UserService} from '../src/services/userService.js';
import {DatabaseMock} from '../src/mocks/storage/database.js';
import {RGB} from '../src/domain/common.schema.js'
const USER_SERVICE_TESTING_USER_ID = "000000000000000000000000"
const USER_SERVICE_TESTING_TOKEN = "testingToken"

View File

@@ -1,6 +1,6 @@
import {beforeAll, beforeEach} from 'vitest';
import {environment, SDKConfig} from "../src/core/environment";
import {getClient} from "../src/core/http";
import {environment, SDKConfig} from '../src/core/environment.js';
import {getClient} from '../src/core/http.js';
beforeEach(async () => {
await getClient(false).post("v2/reset")

View File

@@ -1,5 +1,5 @@
import {describe, it} from "vitest";
import {WebSocketHandler} from "../src/core/webSocketHandler";
import {WebSocketHandler} from '../src/core/webSocketHandler.js';
const WEBSOCKET_HANDLER_TESTING_USER_ID = "000000000000000000000000"
const WEBSOCKET_HANDLER_TESTING_USER_TOKEN = "testingToken"

View File

@@ -1,12 +1,15 @@
{
"compilerOptions": {
"target": "es2016",
"module": "commonjs",
"module": "NodeNext",
"moduleResolution": "nodenext",
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"declaration": true,
"strict": true,
"skipLibCheck": true,
"outDir": "dist"
"outDir": "dist",
"verbatimModuleSyntax": false,
},
"include": ["src"]
}