Skip to content

Commit 6d301b7

Browse files
committed
fix: dev workflow, types
1 parent b44d2d2 commit 6d301b7

19 files changed

Lines changed: 1461 additions & 1210 deletions

app.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ app.use((req, res, next) => {
2020
// add routes
2121
app.use("/api", apiController);
2222

23-
if (process.env.APP_ENV === "production") {
23+
if (process.env.NODE_ENV === "production") {
2424
app.use(express.static("client/dist"));
2525
app.get("*", (req, res) => {
2626
res.sendFile(path.join(__dirname, "../client/dist", "index.html"));

client/app.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ const callDuration = document.getElementById('call-duration')!;
4545
async function initChat() {
4646
try {
4747
setupStatus.textContent = 'Initializing secure keys...';
48-
chat = createChatInstance();
48+
chat = createChatInstance({ baseUrl: process.env.CHATE2EE_API_URL || 'http://localhost:3001' });
4949
await chat.init();
5050

5151
const keys = chat.getKeyPair();

client/vite.config.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { defineConfig, loadEnv } from 'vite';
2+
3+
export default defineConfig(({ mode }) => {
4+
const env = loadEnv(mode, process.cwd(), '');
5+
return {
6+
define: {
7+
'process.env.CHATE2EE_API_URL': JSON.stringify(env.CHATE2EE_API_URL ?? ''),
8+
},
9+
};
10+
});

package-lock.json

Lines changed: 1360 additions & 1116 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,13 @@
44
"description": "",
55
"main": "index.js",
66
"scripts": {
7-
"dev": "concurrently \"npm run client\" \"npm run server\"",
8-
"build-client": "cd client && npm run build",
9-
"build": "tsc && npm run build-client",
10-
"client": "cd client && npm run dev",
11-
"server": "cross-env NODE_ENV=development nodemon --watch \"./**\" --ext \"ts,json\" --ignore \"./client\" --ignore \"./service\" --exec \"ts-node index.ts\"",
12-
"serve": "node ./dist/index",
7+
"dev": "concurrently \"npm run client:dev\" \"npm run serve:dev\"",
8+
"build": "npm run client:build",
9+
"client:dev": "cd client && npm run dev",
10+
"client:build": "cd client && npm run build",
11+
"serve:dev": "cross-env NODE_ENV=development nodemon --ext ts,json --ignore client --ignore service --exec ts-node index.ts",
12+
"serve": "cross-env NODE_ENV=production ts-node index.ts",
1313
"test": "cross-env NODE_ENV=test jest",
14-
"postinstall": "npm run build-service-sdk && cd client && npm install",
15-
"docker_start": "cross-env NODE_ENV=production node ./dist/index",
1614
"build-service-sdk": "cd service && npm install && npm run build"
1715
},
1816
"author": "",

service/README.md

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,10 @@ Create an instance and initialize it to generate encryption keys and prepare the
2727
```javascript
2828
import { createChatInstance } from '@chat-e2ee/service';
2929

30-
31-
const chat = createChatInstance();
30+
const chat = createChatInstance({
31+
baseUrl: 'https://your-api.example.com',
32+
settings: { disableLog: true },
33+
});
3234
await chat.init();
3335
```
3436

@@ -70,9 +72,26 @@ chat.on('chat-message', async (msg) => {
7072
### `setConfig(config: Partial<ConfigType>)`
7173
Global configuration for the SDK.
7274
- `settings.disableLog`: Boolean to toggle console logging (Default: `false`).
75+
- `baseUrl`: Base URL of the chat-e2ee backend API (Default: `'http://localhost:3001'`).
76+
77+
```javascript
78+
import { setConfig } from '@chat-e2ee/service';
7379

74-
### `createChatInstance(): IChatE2EE`
75-
Factory function to create a new chat session instance.
80+
setConfig({
81+
baseUrl: 'https://your-api.example.com',
82+
settings: { disableLog: true },
83+
});
84+
```
85+
86+
### `createChatInstance(config?: Partial<ConfigType>): IChatE2EE`
87+
Factory function to create a new chat session instance. Accepts an optional config to set `baseUrl` and `settings` inline, as an alternative to calling `setConfig()` separately.
88+
89+
```javascript
90+
const chat = createChatInstance({
91+
baseUrl: 'https://your-api.example.com',
92+
settings: { disableLog: true },
93+
});
94+
```
7695

7796
---
7897

service/package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
"author": "Mukesh",
77
"license": "ISC",
88
"types": "dist/types/sdk.d.ts",
9+
"exports": {
10+
".": "./src/sdk.ts"
11+
},
912
"devDependencies": {
1013
"@types/jest": "29.5.14",
1114
"@types/node": "^25.0.3",
@@ -15,8 +18,6 @@
1518
},
1619
"scripts": {
1720
"build": "node build.js --production",
18-
"build:dev": "node build.js",
19-
"watch": "node build.js --watch",
2021
"publish-sdk": "npm publish",
2122
"test": "jest"
2223
},

service/src/configContext.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ import { Logger } from './utils/logger';
44
let chate2eeConfig: configType = {
55
settings: {
66
disableLog: false // true - Disable Logs; false - Enable Logs
7-
}
7+
},
8+
baseUrl: 'http://localhost:3001',
89
};
910

1011
export const setConfig: SetConfigType = (config) => {

service/src/cryptoAES.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@ export class AesGcmEncryption {
5353
}
5454

5555
public async encryptData(data: ArrayBuffer) {
56+
if(!this.aesKeyLocal) {
57+
throw new Error('Local AES key not generated.')
58+
};
5659
// Generate an Initialization Vector (IV) for AES-GCM (12 bytes)
5760
const iv = crypto.getRandomValues(new Uint8Array(12));
5861
// Encrypt the frame data using AES-GCM

service/src/deleteLink.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import makeRequest from './makeRequest';
22

3-
const deleteLink = async ({ channelID }) => {
3+
const deleteLink = async ({ channelID }: { channelID?: string }) => {
44
return makeRequest(`/chat-link/${channelID}`, {
55
method: 'DELETE'
66
});

0 commit comments

Comments
 (0)