@lizzythelizard/whatsapp-mcp 0.1.3 → 0.1.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/auth.d.ts.map +1 -1
- package/dist/auth.js +1 -0
- package/dist/auth.js.map +1 -1
- package/dist/index.js +32 -9
- package/dist/index.js.map +1 -1
- package/dist/store.d.ts +23 -9
- package/dist/store.d.ts.map +1 -1
- package/dist/store.js +16 -10
- package/dist/store.js.map +1 -1
- package/dist/sync.d.ts +6 -2
- package/dist/sync.d.ts.map +1 -1
- package/dist/sync.js +61 -2
- package/dist/sync.js.map +1 -1
- package/dist/tools.d.ts +4 -1
- package/dist/tools.d.ts.map +1 -1
- package/dist/tools.js +69 -60
- package/dist/tools.js.map +1 -1
- package/package.json +59 -45
- package/.github/dependabot.yml +0 -20
- package/.github/workflows/auto-merge.yml +0 -19
- package/.github/workflows/ci.yml +0 -75
- package/.vscode/extensions.json +0 -7
- package/.vscode/settings.json +0 -12
- package/AGENTS.md +0 -42
- package/Dockerfile +0 -25
- package/dist/syncManager.d.ts +0 -29
- package/dist/syncManager.d.ts.map +0 -1
- package/dist/syncManager.js +0 -79
- package/dist/syncManager.js.map +0 -1
- package/eslint.config.mjs +0 -32
- package/src/auth.test.ts +0 -138
- package/src/auth.ts +0 -58
- package/src/index.ts +0 -45
- package/src/store.test.ts +0 -353
- package/src/store.ts +0 -182
- package/src/sync.test.ts +0 -304
- package/src/sync.ts +0 -170
- package/src/tools.test.ts +0 -254
- package/src/tools.ts +0 -132
- package/tsconfig.json +0 -19
- package/tsconfig.test.json +0 -7
- package/vitest.config.ts +0 -7
package/package.json
CHANGED
|
@@ -1,45 +1,59 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@lizzythelizard/whatsapp-mcp",
|
|
3
|
-
"version": "0.1.
|
|
4
|
-
"description": "MCP server for WhatsApp integration",
|
|
5
|
-
"type": "module",
|
|
6
|
-
"main": "dist/index.js",
|
|
7
|
-
"
|
|
8
|
-
"
|
|
9
|
-
|
|
10
|
-
"
|
|
11
|
-
"
|
|
12
|
-
},
|
|
13
|
-
"
|
|
14
|
-
"
|
|
15
|
-
"
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
"
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
"whatsapp"
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
"
|
|
31
|
-
"
|
|
32
|
-
"
|
|
33
|
-
"
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
"
|
|
39
|
-
"
|
|
40
|
-
"
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
1
|
+
{
|
|
2
|
+
"name": "@lizzythelizard/whatsapp-mcp",
|
|
3
|
+
"version": "0.1.5",
|
|
4
|
+
"description": "MCP server for WhatsApp integration",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "dist/index.js",
|
|
7
|
+
"files": [
|
|
8
|
+
"dist"
|
|
9
|
+
],
|
|
10
|
+
"engines": {
|
|
11
|
+
"node": ">=20"
|
|
12
|
+
},
|
|
13
|
+
"repository": {
|
|
14
|
+
"type": "git",
|
|
15
|
+
"url": "git+https://github.com/lizzyTheLizard/whatsapp-mcp.git"
|
|
16
|
+
},
|
|
17
|
+
"bugs": {
|
|
18
|
+
"url": "https://github.com/lizzyTheLizard/whatsapp-mcp/issues"
|
|
19
|
+
},
|
|
20
|
+
"homepage": "https://github.com/lizzyTheLizard/whatsapp-mcp#readme",
|
|
21
|
+
"publishConfig": {
|
|
22
|
+
"access": "public"
|
|
23
|
+
},
|
|
24
|
+
"bin": {
|
|
25
|
+
"whatsapp-mcp": "dist/index.js"
|
|
26
|
+
},
|
|
27
|
+
"scripts": {
|
|
28
|
+
"build": "tsc",
|
|
29
|
+
"start": "node dist/index.js",
|
|
30
|
+
"dev": "tsx watch src/index.ts",
|
|
31
|
+
"test": "vitest run",
|
|
32
|
+
"test:watch": "vitest",
|
|
33
|
+
"lint": "eslint src/",
|
|
34
|
+
"lint:fix": "eslint src/ --fix",
|
|
35
|
+
"typecheck": "tsc --noEmit"
|
|
36
|
+
},
|
|
37
|
+
"keywords": [
|
|
38
|
+
"mcp",
|
|
39
|
+
"whatsapp",
|
|
40
|
+
"model-context-protocol"
|
|
41
|
+
],
|
|
42
|
+
"license": "MIT",
|
|
43
|
+
"dependencies": {
|
|
44
|
+
"@modelcontextprotocol/sdk": "^1.29.0",
|
|
45
|
+
"@stylistic/eslint-plugin": "^5.10.0",
|
|
46
|
+
"@whiskeysockets/baileys": "^7.0.0-rc13",
|
|
47
|
+
"zod": "^4.4.3"
|
|
48
|
+
},
|
|
49
|
+
"devDependencies": {
|
|
50
|
+
"@eslint/js": "^10.0.1",
|
|
51
|
+
"@types/node": "^26.0.1",
|
|
52
|
+
"@typescript-eslint/eslint-plugin": "^8.62.0",
|
|
53
|
+
"eslint": "^10.5.0",
|
|
54
|
+
"tsx": "^4.22.4",
|
|
55
|
+
"typescript": "^6.0.3",
|
|
56
|
+
"typescript-eslint": "^8.62.0",
|
|
57
|
+
"vitest": "^4.1.9"
|
|
58
|
+
}
|
|
59
|
+
}
|
package/.github/dependabot.yml
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
version: 2
|
|
2
|
-
updates:
|
|
3
|
-
- package-ecosystem: "npm"
|
|
4
|
-
directory: "/"
|
|
5
|
-
schedule:
|
|
6
|
-
interval: "weekly"
|
|
7
|
-
day: "monday"
|
|
8
|
-
open-pull-requests-limit: 10
|
|
9
|
-
|
|
10
|
-
- package-ecosystem: "docker"
|
|
11
|
-
directory: "/"
|
|
12
|
-
schedule:
|
|
13
|
-
interval: "weekly"
|
|
14
|
-
day: "monday"
|
|
15
|
-
|
|
16
|
-
- package-ecosystem: "github-actions"
|
|
17
|
-
directory: "/"
|
|
18
|
-
schedule:
|
|
19
|
-
interval: "weekly"
|
|
20
|
-
day: "monday"
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
name: Dependabot Auto-Merge
|
|
2
|
-
|
|
3
|
-
on:
|
|
4
|
-
pull_request_target:
|
|
5
|
-
|
|
6
|
-
permissions:
|
|
7
|
-
contents: write
|
|
8
|
-
pull-requests: write
|
|
9
|
-
|
|
10
|
-
jobs:
|
|
11
|
-
auto-merge:
|
|
12
|
-
if: github.actor == 'dependabot[bot]'
|
|
13
|
-
runs-on: ubuntu-latest
|
|
14
|
-
steps:
|
|
15
|
-
- name: Auto-merge Dependabot PRs
|
|
16
|
-
run: gh pr merge --auto --merge "$PR_URL"
|
|
17
|
-
env:
|
|
18
|
-
PR_URL: ${{ github.event.pull_request.html_url }}
|
|
19
|
-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
package/.github/workflows/ci.yml
DELETED
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
name: CI
|
|
2
|
-
|
|
3
|
-
on:
|
|
4
|
-
pull_request:
|
|
5
|
-
branches: [main]
|
|
6
|
-
push:
|
|
7
|
-
branches: [main]
|
|
8
|
-
|
|
9
|
-
env:
|
|
10
|
-
DOCKER_IMAGE: ${{ secrets.DOCKER_USERNAME }}/whatsapp-mcp
|
|
11
|
-
|
|
12
|
-
jobs:
|
|
13
|
-
checks:
|
|
14
|
-
runs-on: ubuntu-latest
|
|
15
|
-
steps:
|
|
16
|
-
- uses: actions/checkout@v7
|
|
17
|
-
- uses: actions/setup-node@v6
|
|
18
|
-
with:
|
|
19
|
-
node-version: 24
|
|
20
|
-
cache: npm
|
|
21
|
-
- run: npm ci
|
|
22
|
-
- run: npm run build
|
|
23
|
-
- run: npm run lint
|
|
24
|
-
- run: npm run typecheck
|
|
25
|
-
- run: npm test
|
|
26
|
-
- name: Check version can be published
|
|
27
|
-
run: npm publish --dry-run
|
|
28
|
-
|
|
29
|
-
docker:
|
|
30
|
-
runs-on: ubuntu-latest
|
|
31
|
-
needs: [checks]
|
|
32
|
-
permissions:
|
|
33
|
-
contents: read
|
|
34
|
-
packages: write
|
|
35
|
-
steps:
|
|
36
|
-
- uses: actions/checkout@v7
|
|
37
|
-
- uses: docker/setup-buildx-action@v4
|
|
38
|
-
- name: Log in to Docker Hub
|
|
39
|
-
if: github.ref == 'refs/heads/main'
|
|
40
|
-
uses: docker/login-action@v4
|
|
41
|
-
with:
|
|
42
|
-
username: ${{ secrets.DOCKER_USERNAME }}
|
|
43
|
-
password: ${{ secrets.DOCKER_PASSWORD }}
|
|
44
|
-
- name: Extract metadata
|
|
45
|
-
id: meta
|
|
46
|
-
uses: docker/metadata-action@v6
|
|
47
|
-
with:
|
|
48
|
-
images: ${{ env.DOCKER_IMAGE }}
|
|
49
|
-
tags: |
|
|
50
|
-
type=sha,prefix=
|
|
51
|
-
type=raw,value=latest,enable=${{ github.ref == 'refs/heads/main' }}
|
|
52
|
-
- name: Build and push
|
|
53
|
-
uses: docker/build-push-action@v7
|
|
54
|
-
with:
|
|
55
|
-
context: .
|
|
56
|
-
push: ${{ github.ref == 'refs/heads/main' }}
|
|
57
|
-
tags: ${{ steps.meta.outputs.tags }}
|
|
58
|
-
labels: ${{ steps.meta.outputs.labels }}
|
|
59
|
-
cache-from: type=gha
|
|
60
|
-
cache-to: type=gha,mode=max
|
|
61
|
-
|
|
62
|
-
npm-publish:
|
|
63
|
-
runs-on: ubuntu-latest
|
|
64
|
-
needs: [checks]
|
|
65
|
-
if: github.ref == 'refs/heads/main'
|
|
66
|
-
steps:
|
|
67
|
-
- uses: actions/checkout@v7
|
|
68
|
-
- uses: actions/setup-node@v6
|
|
69
|
-
with:
|
|
70
|
-
node-version: 24
|
|
71
|
-
cache: npm
|
|
72
|
-
registry-url: "https://registry.npmjs.org"
|
|
73
|
-
- run: npm ci
|
|
74
|
-
- run: npm run build
|
|
75
|
-
- run: npm publish
|
package/.vscode/extensions.json
DELETED
package/.vscode/settings.json
DELETED
package/AGENTS.md
DELETED
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
# AGENTS.md
|
|
2
|
-
|
|
3
|
-
This file helps AI agents understand how to work with this project.
|
|
4
|
-
|
|
5
|
-
## Project Overview
|
|
6
|
-
|
|
7
|
-
A WhatsApp MCP (Model Context Protocol) server that exposes WhatsApp functionality as tools for AI assistants.
|
|
8
|
-
|
|
9
|
-
## Key Conventions
|
|
10
|
-
|
|
11
|
-
- TypeScript with ESM (`"type": "module"`)
|
|
12
|
-
- Source code lives in `src/`, tests in `tests/`
|
|
13
|
-
- Use `zod` for input validation
|
|
14
|
-
- Follow existing tool patterns when adding new tools
|
|
15
|
-
|
|
16
|
-
## Common Commands
|
|
17
|
-
|
|
18
|
-
- `npm run dev` — start dev server with auto-reload
|
|
19
|
-
- `npm test` — run test suite
|
|
20
|
-
- `npm run build` — compile to JavaScript
|
|
21
|
-
- `npm run lint` — check code quality
|
|
22
|
-
- `npm run typecheck` — run TypeScript type checking
|
|
23
|
-
|
|
24
|
-
## Architecture
|
|
25
|
-
|
|
26
|
-
The MCP server uses `@modelcontextprotocol/sdk` with stdio transport. Tools are registered in `src/index.ts` via `server.setRequestHandler`. Each tool has:
|
|
27
|
-
|
|
28
|
-
1. A `zod` schema for input validation
|
|
29
|
-
2. A definition in `ListToolsRequestSchema`
|
|
30
|
-
3. A handler in `CallToolRequestSchema`
|
|
31
|
-
|
|
32
|
-
## Adding a New Tool
|
|
33
|
-
|
|
34
|
-
1. Define a Zod schema for the tool's input
|
|
35
|
-
2. Add the tool definition to `ListToolsRequestSchema`
|
|
36
|
-
3. Add a case to the switch in `CallToolRequestSchema`
|
|
37
|
-
|
|
38
|
-
## Testing
|
|
39
|
-
|
|
40
|
-
- Write tests in `tests/` matching the source structure
|
|
41
|
-
- Use `vitest` with `describe`/`it`/`expect`
|
|
42
|
-
- Test input schemas and handler logic separately
|
package/Dockerfile
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
FROM node:26-alpine AS build
|
|
2
|
-
|
|
3
|
-
WORKDIR /app
|
|
4
|
-
|
|
5
|
-
COPY package*.json ./
|
|
6
|
-
RUN npm ci
|
|
7
|
-
|
|
8
|
-
COPY tsconfig.json ./
|
|
9
|
-
COPY src/ ./src/
|
|
10
|
-
RUN npm run build
|
|
11
|
-
|
|
12
|
-
FROM node:26-alpine AS production
|
|
13
|
-
|
|
14
|
-
WORKDIR /app
|
|
15
|
-
|
|
16
|
-
RUN addgroup -S appgroup && adduser -S appuser -G appgroup
|
|
17
|
-
|
|
18
|
-
COPY package*.json ./
|
|
19
|
-
RUN npm ci --omit=dev
|
|
20
|
-
|
|
21
|
-
COPY --from=build /app/dist ./dist
|
|
22
|
-
|
|
23
|
-
USER appuser
|
|
24
|
-
|
|
25
|
-
CMD ["node", "dist/index.js"]
|
package/dist/syncManager.d.ts
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { UserSession } from '@/app/shared/auth/auth';
|
|
2
|
-
import { SyncHandler } from './sync';
|
|
3
|
-
import { Mutex } from 'async-mutex';
|
|
4
|
-
export type RunningSyncStatus = {
|
|
5
|
-
state: 'connecting';
|
|
6
|
-
} | {
|
|
7
|
-
state: 'qr';
|
|
8
|
-
data: string;
|
|
9
|
-
} | {
|
|
10
|
-
state: 'initialsync';
|
|
11
|
-
} | {
|
|
12
|
-
state: 'ready';
|
|
13
|
-
} | {
|
|
14
|
-
state: 'failed';
|
|
15
|
-
data: string;
|
|
16
|
-
};
|
|
17
|
-
interface RunningSync {
|
|
18
|
-
status: RunningSyncStatus;
|
|
19
|
-
timeout: NodeJS.Timeout;
|
|
20
|
-
handler: SyncHandler;
|
|
21
|
-
}
|
|
22
|
-
declare global {
|
|
23
|
-
var runningSyncs: Map<string, RunningSync> | undefined;
|
|
24
|
-
var mutex: Mutex | undefined;
|
|
25
|
-
}
|
|
26
|
-
export declare function getRunningSyncData(user: UserSession): RunningSyncStatus;
|
|
27
|
-
export declare function triggerWhatsappSync(user: UserSession): Promise<void>;
|
|
28
|
-
export {};
|
|
29
|
-
//# sourceMappingURL=syncManager.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"syncManager.d.ts","sourceRoot":"","sources":["../src/syncManager.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAA;AAIpD,OAAO,EAAa,WAAW,EAAE,MAAM,QAAQ,CAAA;AAC/C,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAA;AAEnC,MAAM,MAAM,iBAAiB,GAAG;IAAE,KAAK,EAAE,YAAY,CAAA;CAAE,GACnD;IAAE,KAAK,EAAE,IAAI,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GAC7B;IAAE,KAAK,EAAE,aAAa,CAAA;CAAE,GACxB;IAAE,KAAK,EAAE,OAAO,CAAA;CAAE,GAClB;IAAE,KAAK,EAAE,QAAQ,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,CAAA;AAErC,UAAU,WAAW;IACnB,MAAM,EAAE,iBAAiB,CAAA;IACzB,OAAO,EAAE,MAAM,CAAC,OAAO,CAAA;IACvB,OAAO,EAAE,WAAW,CAAA;CACrB;AAED,OAAO,CAAC,MAAM,CAAC;IACb,IAAI,YAAY,EAAE,GAAG,CAAC,MAAM,EAAE,WAAW,CAAC,GAAG,SAAS,CAAA;IACtD,IAAI,KAAK,EAAE,KAAK,GAAG,SAAS,CAAA;CAC7B;AAED,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,WAAW,GAAG,iBAAiB,CAEvE;AAED,wBAAsB,mBAAmB,CAAC,IAAI,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC,CAwB1E"}
|
package/dist/syncManager.js
DELETED
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
'use server';
|
|
2
|
-
import { logger } from '@/app/shared/logger';
|
|
3
|
-
import { transactional } from '@/app/shared/_external/db/access';
|
|
4
|
-
import { logEvent } from '@/app/shared/_data/Event';
|
|
5
|
-
import { startSync } from './sync';
|
|
6
|
-
import { Mutex } from 'async-mutex';
|
|
7
|
-
export function getRunningSyncData(user) {
|
|
8
|
-
return getSync(user).status;
|
|
9
|
-
}
|
|
10
|
-
export async function triggerWhatsappSync(user) {
|
|
11
|
-
globalThis.mutex ??= new Mutex();
|
|
12
|
-
await globalThis.mutex.runExclusive(async () => {
|
|
13
|
-
globalThis.runningSyncs ??= new Map();
|
|
14
|
-
const existing = globalThis.runningSyncs.get(user.email);
|
|
15
|
-
if (existing) {
|
|
16
|
-
clearTimeout(existing.timeout);
|
|
17
|
-
existing.timeout = setTimeout(() => { existing.handler.close(); }, 5 * 1000);
|
|
18
|
-
return;
|
|
19
|
-
}
|
|
20
|
-
logger.debug(`Start whatsapp sync for ${user.email}`);
|
|
21
|
-
const handler = await startSync(user.email);
|
|
22
|
-
handler.onQrCode((qr) => { qrCallback(user, qr); });
|
|
23
|
-
handler.onAuth(() => { authCallback(user); });
|
|
24
|
-
handler.onReady(() => { readyCallback(user); });
|
|
25
|
-
handler.onFinished((error) => { finishedCallback(user, error); });
|
|
26
|
-
handler.start();
|
|
27
|
-
const runningSync = {
|
|
28
|
-
status: { state: 'connecting' },
|
|
29
|
-
timeout: setTimeout(() => { closeSync(user); }, 5 * 1000),
|
|
30
|
-
handler,
|
|
31
|
-
};
|
|
32
|
-
globalThis.runningSyncs.set(user.email, runningSync);
|
|
33
|
-
});
|
|
34
|
-
}
|
|
35
|
-
function qrCallback(user, qr) {
|
|
36
|
-
const message = `WhatsApp authentication requires QR code for user ${user.email}`;
|
|
37
|
-
logger.info(message);
|
|
38
|
-
void transactional(async (c) => { await logEvent(c, 'INFO', message); });
|
|
39
|
-
const runningSync = getSync(user);
|
|
40
|
-
runningSync.status = { state: 'qr', data: qr };
|
|
41
|
-
}
|
|
42
|
-
function authCallback(user) {
|
|
43
|
-
const message = `WhatsApp authentication successful for user ${user.email}`;
|
|
44
|
-
logger.info(message);
|
|
45
|
-
void transactional(async (c) => { await logEvent(c, 'INFO', message); });
|
|
46
|
-
const runningSync = getSync(user);
|
|
47
|
-
runningSync.status = { state: 'initialsync' };
|
|
48
|
-
}
|
|
49
|
-
function readyCallback(user) {
|
|
50
|
-
logger.debug(`WhatsApp is ready for user ${user.email}`);
|
|
51
|
-
const runningSync = getSync(user);
|
|
52
|
-
runningSync.status = { state: 'ready' };
|
|
53
|
-
}
|
|
54
|
-
function finishedCallback(user, error) {
|
|
55
|
-
if (!error) {
|
|
56
|
-
logger.debug('Closing WhatsApp sync handler after successful completion');
|
|
57
|
-
globalThis.runningSyncs?.delete(user.email);
|
|
58
|
-
return;
|
|
59
|
-
}
|
|
60
|
-
const errorMessage = error instanceof Error ? error.message : 'Unknown error';
|
|
61
|
-
const message = `WhatsApp sync failed for user ${user.email}: ${errorMessage}`;
|
|
62
|
-
logger.error(message, error);
|
|
63
|
-
void transactional(async (c) => { await logEvent(c, 'ERROR', message); });
|
|
64
|
-
const runningSync = getSync(user);
|
|
65
|
-
runningSync.status = { state: 'failed', data: message };
|
|
66
|
-
}
|
|
67
|
-
function closeSync(user) {
|
|
68
|
-
logger.info('WhatsApp sync timeout reached, closing sync handler');
|
|
69
|
-
const runningSync = getSync(user);
|
|
70
|
-
globalThis.runningSyncs?.delete(user.email);
|
|
71
|
-
runningSync.handler.close();
|
|
72
|
-
}
|
|
73
|
-
function getSync(user) {
|
|
74
|
-
const runningSync = globalThis.runningSyncs?.get(user.email);
|
|
75
|
-
if (!runningSync)
|
|
76
|
-
throw new Error(`No running WhatsApp sync found for user ${user.email}`);
|
|
77
|
-
return runningSync;
|
|
78
|
-
}
|
|
79
|
-
//# sourceMappingURL=syncManager.js.map
|
package/dist/syncManager.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"syncManager.js","sourceRoot":"","sources":["../src/syncManager.ts"],"names":[],"mappings":"AAAA,YAAY,CAAA;AAEZ,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAA;AAC5C,OAAO,EA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EAAE,IAAI,EAAE,OAAO,EAAE,CAAA;AACzD,CAAC;AAED,SAAS,SAAS,CAAC,IAAiB;IAClC,MAAM,CAAC,IAAI,CAAC,qDAAqD,CAAC,CAAA;IAClE,MAAM,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;IACjC,UAAU,CAAC,YAAY,EAAE,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;IAC3C,WAAW,CAAC,OAAO,CAAC,KAAK,EAAE,CAAA;AAC7B,CAAC;AAED,SAAS,OAAO,CAAC,IAAiB;IAChC,MAAM,WAAW,GAAG,UAAU,CAAC,YAAY,EAAE,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;IAC5D,IAAI,CAAC,WAAW;QAAE,MAAM,IAAI,KAAK,CAAC,2CAA2C,IAAI,CAAC,KAAK,EAAE,CAAC,CAAA;IAC1F,OAAO,WAAW,CAAA;AACpB,CAAC"}
|
package/eslint.config.mjs
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import eslint from '@eslint/js'
|
|
2
|
-
import tseslint from 'typescript-eslint'
|
|
3
|
-
import { defineConfig, globalIgnores } from 'eslint/config'
|
|
4
|
-
import stylistic from '@stylistic/eslint-plugin'
|
|
5
|
-
|
|
6
|
-
export default defineConfig([
|
|
7
|
-
eslint.configs.recommended,
|
|
8
|
-
tseslint.configs.recommendedTypeChecked,
|
|
9
|
-
tseslint.configs.strictTypeChecked,
|
|
10
|
-
tseslint.configs.stylisticTypeChecked,
|
|
11
|
-
stylistic.configs.recommended,
|
|
12
|
-
globalIgnores(['node_modules/**', 'dist/**']),
|
|
13
|
-
{
|
|
14
|
-
languageOptions: {
|
|
15
|
-
parserOptions: {
|
|
16
|
-
tsconfigRootDir: import.meta.dirname,
|
|
17
|
-
projectService: {
|
|
18
|
-
allowDefaultProject: ['src/*.test.ts'],
|
|
19
|
-
},
|
|
20
|
-
},
|
|
21
|
-
},
|
|
22
|
-
rules: {
|
|
23
|
-
'@typescript-eslint/no-extraneous-class': ['off'],
|
|
24
|
-
'@typescript-eslint/no-unused-vars': ['warn', { argsIgnorePattern: '^_' }],
|
|
25
|
-
'@stylistic/max-statements-per-line': ['error', { max: 2 }],
|
|
26
|
-
},
|
|
27
|
-
},
|
|
28
|
-
{
|
|
29
|
-
files: ['**/*.js', '**/*.cjs', '**/*.mjs'],
|
|
30
|
-
extends: [tseslint.configs.disableTypeChecked],
|
|
31
|
-
},
|
|
32
|
-
])
|
package/src/auth.test.ts
DELETED
|
@@ -1,138 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect } from 'vitest'
|
|
2
|
-
import { createExportableAuth } from './auth.js'
|
|
3
|
-
|
|
4
|
-
describe('createExportableAuth', () => {
|
|
5
|
-
it('returns fresh auth with initAuthCreds when called without argument', () => {
|
|
6
|
-
const auth = createExportableAuth()
|
|
7
|
-
expect(auth.creds).toBeDefined()
|
|
8
|
-
expect(auth.keys).toBeDefined()
|
|
9
|
-
expect(typeof auth.toAuthState).toBe('function')
|
|
10
|
-
})
|
|
11
|
-
|
|
12
|
-
it('restores creds and keys from a JSON string', () => {
|
|
13
|
-
const original = createExportableAuth()
|
|
14
|
-
const json = original.toAuthState()
|
|
15
|
-
const restored = createExportableAuth(json)
|
|
16
|
-
expect(restored.creds.registrationId).toBe(original.creds.registrationId)
|
|
17
|
-
expect(restored.creds.noiseKey.public).toEqual(original.creds.noiseKey.public)
|
|
18
|
-
})
|
|
19
|
-
|
|
20
|
-
it('roundtrips through toAuthState and back', async () => {
|
|
21
|
-
const auth = createExportableAuth()
|
|
22
|
-
await auth.keys.set({ 'sender-key': { 'test@test:1': new Uint8Array([1, 2, 3]) } })
|
|
23
|
-
const json = auth.toAuthState()
|
|
24
|
-
const imported = createExportableAuth(json)
|
|
25
|
-
const retrieved = await imported.keys.get('sender-key', ['test@test:1'])
|
|
26
|
-
expect(retrieved['test@test:1']).toBeDefined()
|
|
27
|
-
expect(new Uint8Array(retrieved['test@test:1'])).toEqual(new Uint8Array([1, 2, 3]))
|
|
28
|
-
})
|
|
29
|
-
|
|
30
|
-
it('preserves Uint8Array values through export and import', async () => {
|
|
31
|
-
const auth = createExportableAuth()
|
|
32
|
-
const original = new Uint8Array([255, 254, 253])
|
|
33
|
-
await auth.keys.set({ 'sender-key': { 'test-id': original } })
|
|
34
|
-
const json = auth.toAuthState()
|
|
35
|
-
const imported = createExportableAuth(json)
|
|
36
|
-
const retrieved = await imported.keys.get('sender-key', ['test-id'])
|
|
37
|
-
expect(new Uint8Array(retrieved['test-id'])).toEqual(original)
|
|
38
|
-
})
|
|
39
|
-
|
|
40
|
-
it('handles undefined input and returns fresh auth', () => {
|
|
41
|
-
const auth = createExportableAuth(undefined)
|
|
42
|
-
expect(auth.creds).toBeDefined()
|
|
43
|
-
expect(auth.creds.registrationId).toBeGreaterThan(0)
|
|
44
|
-
})
|
|
45
|
-
|
|
46
|
-
it('throws on invalid JSON string', () => {
|
|
47
|
-
expect(() => createExportableAuth('not valid json')).toThrow()
|
|
48
|
-
})
|
|
49
|
-
|
|
50
|
-
it('handles empty JSON object (no creds)', () => {
|
|
51
|
-
const auth = createExportableAuth('{}')
|
|
52
|
-
expect(typeof auth.toAuthState).toBe('function')
|
|
53
|
-
expect(auth.toAuthState()).toBe('{}')
|
|
54
|
-
})
|
|
55
|
-
})
|
|
56
|
-
|
|
57
|
-
describe('keys store (set/get)', () => {
|
|
58
|
-
it('stores and retrieves session values', async () => {
|
|
59
|
-
const auth = createExportableAuth()
|
|
60
|
-
const value = new Uint8Array([10, 20, 30])
|
|
61
|
-
await auth.keys.set({ session: { 'session-id': value } })
|
|
62
|
-
const result = await auth.keys.get('session', ['session-id'])
|
|
63
|
-
expect(result['session-id']).toBeDefined()
|
|
64
|
-
expect(new Uint8Array(result['session-id'])).toEqual(value)
|
|
65
|
-
})
|
|
66
|
-
|
|
67
|
-
it('stores and retrieves string values (lid-mapping)', async () => {
|
|
68
|
-
const auth = createExportableAuth()
|
|
69
|
-
await auth.keys.set({ 'lid-mapping': { test: 'mapped-value' } })
|
|
70
|
-
const result = await auth.keys.get('lid-mapping', ['test'])
|
|
71
|
-
expect(result.test).toBe('mapped-value')
|
|
72
|
-
})
|
|
73
|
-
|
|
74
|
-
it('stores and retrieves string array values (device-list)', async () => {
|
|
75
|
-
const auth = createExportableAuth()
|
|
76
|
-
await auth.keys.set({ 'device-list': { test: ['dev1', 'dev2'] } })
|
|
77
|
-
const result = await auth.keys.get('device-list', ['test'])
|
|
78
|
-
expect(result.test).toEqual(['dev1', 'dev2'])
|
|
79
|
-
})
|
|
80
|
-
|
|
81
|
-
it('returns empty object for missing keys', async () => {
|
|
82
|
-
const auth = createExportableAuth()
|
|
83
|
-
const result = await auth.keys.get('session', ['nonexistent'])
|
|
84
|
-
expect(result).toEqual({})
|
|
85
|
-
})
|
|
86
|
-
|
|
87
|
-
it('overwrites existing values on successive sets', async () => {
|
|
88
|
-
const auth = createExportableAuth()
|
|
89
|
-
await auth.keys.set({ session: { s1: new Uint8Array([1]) } })
|
|
90
|
-
await auth.keys.set({ session: { s1: new Uint8Array([2]) } })
|
|
91
|
-
const result = await auth.keys.get('session', ['s1'])
|
|
92
|
-
expect(new Uint8Array(result.s1)).toEqual(new Uint8Array([2]))
|
|
93
|
-
})
|
|
94
|
-
|
|
95
|
-
it('deletes key when value is set to null', async () => {
|
|
96
|
-
const auth = createExportableAuth()
|
|
97
|
-
await auth.keys.set({ session: { s1: new Uint8Array([1]) } })
|
|
98
|
-
await auth.keys.set({ session: { s1: null } })
|
|
99
|
-
const result = await auth.keys.get('session', ['s1'])
|
|
100
|
-
expect(result).toEqual({})
|
|
101
|
-
})
|
|
102
|
-
|
|
103
|
-
it('retrieves multiple ids in a single get call', async () => {
|
|
104
|
-
const auth = createExportableAuth()
|
|
105
|
-
await auth.keys.set({ 'lid-mapping': { id1: 'val1', id2: 'val2' } })
|
|
106
|
-
const result = await auth.keys.get('lid-mapping', ['id1', 'id2'])
|
|
107
|
-
expect(result.id1).toBe('val1')
|
|
108
|
-
expect(result.id2).toBe('val2')
|
|
109
|
-
})
|
|
110
|
-
|
|
111
|
-
it('handles app-state-sync-key with correct protobuf conversion', async () => {
|
|
112
|
-
const auth = createExportableAuth()
|
|
113
|
-
const keyData = {
|
|
114
|
-
keyData: new Uint8Array([1, 2, 3]),
|
|
115
|
-
timestamp: 1234567890,
|
|
116
|
-
}
|
|
117
|
-
await auth.keys.set({ 'app-state-sync-key': { key1: keyData } })
|
|
118
|
-
const result = await auth.keys.get('app-state-sync-key', ['key1'])
|
|
119
|
-
expect(result.key1).toBeDefined()
|
|
120
|
-
expect(result.key1.keyData).toBeDefined()
|
|
121
|
-
expect(Number(result.key1.timestamp)).toBe(1234567890)
|
|
122
|
-
})
|
|
123
|
-
|
|
124
|
-
it('stores and retrieves sender-key-memory (boolean map)', async () => {
|
|
125
|
-
const auth = createExportableAuth()
|
|
126
|
-
await auth.keys.set({ 'sender-key-memory': { jid1: { user1: true } } })
|
|
127
|
-
const result = await auth.keys.get('sender-key-memory', ['jid1'])
|
|
128
|
-
expect(result.jid1.user1).toBe(true)
|
|
129
|
-
})
|
|
130
|
-
|
|
131
|
-
it('stores and retrieves tctoken', async () => {
|
|
132
|
-
const auth = createExportableAuth()
|
|
133
|
-
await auth.keys.set({ tctoken: { default: { token: Buffer.from('token-data'), timestamp: '123' } } })
|
|
134
|
-
const result = await auth.keys.get('tctoken', ['default'])
|
|
135
|
-
expect(result.default.token).toBeDefined()
|
|
136
|
-
expect(result.default.timestamp).toBe('123')
|
|
137
|
-
})
|
|
138
|
-
})
|
package/src/auth.ts
DELETED
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
import { AuthenticationCreds, BufferJSON, initAuthCreds, SignalDataTypeMap, proto, SignalDataSet, AuthenticationState } from '@whiskeysockets/baileys'
|
|
2
|
-
|
|
3
|
-
export interface ExportableAuthState extends AuthenticationState {
|
|
4
|
-
toAuthState: () => string
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
interface AuthStateInput { creds: AuthenticationCreds, keys: Record<string, string> }
|
|
8
|
-
|
|
9
|
-
export function createExportableAuth(input?: string): ExportableAuthState {
|
|
10
|
-
const { creds, keys } = fromString<AuthStateInput>(input) ?? { creds: initAuthCreds(), keys: {} }
|
|
11
|
-
return {
|
|
12
|
-
creds,
|
|
13
|
-
keys: { get: (t, ids) => getKey(t, ids, keys), set: (data) => { setKey(data, keys) } },
|
|
14
|
-
toAuthState: () => toString({ creds, keys }),
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-parameters
|
|
19
|
-
function fromString<T>(str: string | undefined): T | undefined {
|
|
20
|
-
if (!str) return undefined
|
|
21
|
-
return JSON.parse(str, BufferJSON.reviver) as T
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
function toString(data: unknown): string {
|
|
25
|
-
return JSON.stringify(data, BufferJSON.replacer)
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
function getKey<T extends keyof SignalDataTypeMap>(type: T, ids: string[], keys: Record<string, string>): Record<string, SignalDataTypeMap[T]> {
|
|
29
|
-
return ids.reduce<Record<string, SignalDataTypeMap[T]>>((acc, id) => {
|
|
30
|
-
const value = fromString<SignalDataTypeMap[T]>(keys[`${type}-${id}`])
|
|
31
|
-
if (!value) return acc
|
|
32
|
-
if (type === 'app-state-sync-key') {
|
|
33
|
-
const typedValue = value as SignalDataTypeMap['app-state-sync-key']
|
|
34
|
-
const converted = proto.Message.AppStateSyncKeyData.fromObject(typedValue)
|
|
35
|
-
const typeResult = converted as unknown as SignalDataTypeMap[T]
|
|
36
|
-
acc[id] = typeResult
|
|
37
|
-
}
|
|
38
|
-
else {
|
|
39
|
-
acc[id] = value
|
|
40
|
-
}
|
|
41
|
-
return acc
|
|
42
|
-
}, {})
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
function setKey(data: SignalDataSet, keys: Record<string, string>): void {
|
|
46
|
-
for (const category in data) {
|
|
47
|
-
const dataCategory = data[category as keyof SignalDataTypeMap]
|
|
48
|
-
for (const id in dataCategory) {
|
|
49
|
-
const value = dataCategory[id]
|
|
50
|
-
if (!value)
|
|
51
|
-
// eslint-disable-next-line @typescript-eslint/no-dynamic-delete
|
|
52
|
-
delete keys[`${category}-${id}`]
|
|
53
|
-
else {
|
|
54
|
-
keys[`${category}-${id}`] = JSON.stringify(value, BufferJSON.replacer)
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
}
|