Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,8 @@ jobs:
- name: Check code formatting
run: npm run format:check

- name: Build TypeScript
run: npm run build

- name: Run tests
run: npm test
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
node_modules/

# TypeScript compiled output (source of truth is in src/)
dist/
*.key
*.cert
*.output
Expand Down
3 changes: 3 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ build
dist
*.min.js

# TypeScript compiled output
dist/

# Logs
*.log
wpm2.output
Expand Down
4 changes: 2 additions & 2 deletions configure.sh
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ fi

if [ -z "$CLIENT_NAME" ];
then
node configure.js
node dist/configure.js
else
WICKRIO_BOT_NAME=$CLIENT_NAME node configure.js
WICKRIO_BOT_NAME=$CLIENT_NAME node dist/configure.js
fi
26 changes: 0 additions & 26 deletions logger.js

This file was deleted.

1,981 changes: 354 additions & 1,627 deletions package-lock.json

Large diffs are not rendered by default.

14 changes: 11 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,37 @@
"name": "wickrio_web_interface",
"version": "6.60",
"description": "WickrIO Node.JS API Web Interface",
"main": "web_interface.js",
"main": "dist/web_interface.js",
"author": "Paul Cushman (pcushman@wickr.com)",
"license": "ISC",
"dependencies": {
"express": "^4.17.1",
"helmet": "^3.20.0",
"morgan": "^1.10.1",
"multer": "^1.4.5-lts.1",
"wickrio-bot-api": "^7.1.8"
"wickrio-bot-api": "^7.1.9"
},
"devDependencies": {
"@types/express": "^5.0.6",
"@types/morgan": "^1.9.10",
"@types/multer": "^2.0.0",
"@types/node": "^25.2.3",
"prettier": "^3.8.1",
"supertest": "^7.2.2",
"typescript": "^5.9.3",
"vitest": "^4.0.18"
},
"scripts": {
"start": "nohup wpm2 start --no-metrics ./wpm.json >>wpm2.output 2>&1 & echo $! > $(cat pidLocation.json)",
"stop": "kill $(cat $(cat pidLocation.json))",
"restart": "kill $(cat $(cat pidLocation.json)) && nohup wpm2 start --no-metrics ./wpm.json >>wpm2.output 2>&1 & echo $! > $(cat pidLocation.json)",
"build": "tsc",
"build:watch": "tsc --watch",
"format": "prettier --write .",
"format:check": "prettier --check .",
"test": "vitest run",
"test:watch": "vitest"
"test:watch": "vitest",
"clean": "rm -rf ./dist"
},
"repository": {
"type": "git",
Expand Down
2 changes: 1 addition & 1 deletion processes.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"apps": [{
"name": "WickrIO-Web-Interface",
"args": [],
"script": "node web_interface.js",
"script": "node dist/web_interface.js",
"exec_interpreter": "none",
"autorestart": false,
"watch": [
Expand Down
24 changes: 14 additions & 10 deletions configure.js → src/configure.ts
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
const WickrIOBotAPI = require('wickrio-bot-api')
const util = require('util')
import WickrIOBotAPI from 'wickrio-bot-api'

require('dotenv').config({
path: `.env.configure`,
})

var wickrIOConfigure
let wickrIOConfigure: InstanceType<typeof WickrIOBotAPI.WickrIOConfigure>

process.stdin.resume() //so the program will not close instantly

function exitHandler(options, err) {
function exitHandler(options: { exit?: boolean; pid?: boolean }, err?: unknown): void {
try {
if (err) {
process.kill(process.pid)
Expand All @@ -20,8 +19,8 @@ function exitHandler(options, err) {
} else if (options.pid) {
process.kill(process.pid)
}
} catch (err) {
console.log(err)
} catch (e) {
console.log(e)
}
}

Expand All @@ -38,14 +37,19 @@ process.on(
exitHandler.bind(null, {
exit: true,
reason: 'uncaughtException',
})
} as { exit: boolean; pid?: boolean })
)

main()

async function main() {
const tokens = require('./configTokens.json')
var fullName = process.cwd() + '/processes.json'
async function main(): Promise<void> {
const tokens = require('../configTokens.json') as {
supportAdministrators: boolean
supportVerification: boolean
integration: string
tokens: WickrIOBotAPI.WickrIOConfigureTokens[]
}
const fullName = process.cwd() + '/processes.json'
wickrIOConfigure = new WickrIOBotAPI.WickrIOConfigure(
tokens.tokens,
fullName,
Expand Down
33 changes: 33 additions & 0 deletions src/logger.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import util from 'util'
import WickrIOBotAPI from 'wickrio-bot-api'

const logger = WickrIOBotAPI.logger as {
info: (...args: unknown[]) => void
error: (...args: unknown[]) => void
warn: (...args: unknown[]) => void
debug: (...args: unknown[]) => void
}

function redactSensitiveInfo(args: unknown[]): unknown[] {
return args.map(arg => {
if (typeof arg === 'string' && arg.includes('"message"')) {
return '<redacted>'
}
if (typeof arg === 'object' && arg !== null && 'message' in arg) {
return '<redacted>'
}
return arg
})
}

console.log = function (...args: unknown[]): void {
const redactedArgs = redactSensitiveInfo(args)
logger.info(util.format.apply(null, redactedArgs as [string, ...unknown[]]))
}

console.error = function (...args: unknown[]): void {
const redactedArgs = redactSensitiveInfo(args)
logger.error(util.format.apply(null, redactedArgs as [string, ...unknown[]]))
}

export = logger
5 changes: 5 additions & 0 deletions src/types/helmet.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
declare module 'helmet' {
import { RequestHandler } from 'express'
function helmet(options?: Record<string, unknown>): RequestHandler
export = helmet
}
48 changes: 48 additions & 0 deletions src/types/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
export interface TokenValue {
value: string
}

export interface Tokens {
WICKRIO_BOT_NAME: TokenValue
BOT_PORT: TokenValue
BOT_API_KEY: TokenValue
BOT_API_AUTH_TOKEN: TokenValue
HTTPS_CHOICE: TokenValue
SSL_KEY_LOCATION?: TokenValue
SSL_CRT_LOCATION?: TokenValue
}

export interface UserEntry {
name: string
}

export interface RoomRequest {
title: string
description: string
members: UserEntry[]
masters: UserEntry[]
ttl?: number | string
bor?: number | string
}

export interface GroupConvoRequest {
members: UserEntry[]
ttl?: number | string
bor?: number | string
}

export interface AttachmentInfo {
url?: string
filename?: string
displayname?: string
}

export interface MessageBody {
users?: UserEntry[]
vgroupid?: string
message?: string
attachment?: AttachmentInfo
ttl?: number | string
bor?: number | string
messagemeta?: Record<string, unknown>
}
52 changes: 52 additions & 0 deletions src/types/wickrio-bot-api.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
declare module 'wickrio-bot-api' {
import { WickrIOAddon } from 'wickrio_addon'

interface ApiServiceInstance {
WickrIOAPI: WickrIOAddon
}

class WickrIOBot {
apiService(): ApiServiceInstance
start(botName: string): Promise<boolean>
close(): Promise<boolean>
setAdminOnly(value: boolean): boolean
processesJsonToProcessEnv(): void
}

interface WickrIOConfigureTokens {
token: string
pattern: string
type: string
description: string
message: string
required: boolean
default: string
list?: WickrIOConfigureTokens[]
}

class WickrIOConfigure {
constructor(
tokens: WickrIOConfigureTokens[],
fullName: string,
supportAdministrators: boolean,
supportVerification: boolean
)
configureYourBot(integration: string): Promise<void>
}

const logger: {
info: (...args: unknown[]) => void
error: (...args: unknown[]) => void
warn: (...args: unknown[]) => void
debug: (...args: unknown[]) => void
}

export {
WickrIOBot,
WickrIOConfigure,
WickrIOConfigureTokens,
WickrIOAddon,
ApiServiceInstance,
logger,
}
}
Loading