Fix @xmpp typing.

This commit is contained in:
John Livingston 2021-12-08 12:29:21 +01:00
parent 0e45f9a197
commit 2c72f3bf2f
No known key found for this signature in database
GPG Key ID: B17B5640CE66CDBC
4 changed files with 202 additions and 27 deletions

View File

@ -1,8 +1,8 @@
/* eslint-disable no-void */
import { logger } from '../logger'
import { XMPP, XMPPXmlFunction, XMPPStanza, XMPPAddress } from './types'
const { component, xml } = require('@xmpp/component')
import type { XMPPStanza } from './types'
import { component, xml, Component } from '@xmpp/component'
import type { JID } from '@xmpp/jid'
interface ComponentConnectionConfig {
service: string
@ -11,22 +11,21 @@ interface ComponentConnectionConfig {
}
abstract class ComponentBot {
protected xmpp?: XMPP
protected address?: XMPPAddress
protected xmpp?: Component
protected address?: JID
protected xml = xml
constructor (
public readonly botName: string,
protected readonly connectionConfig: ComponentConnectionConfig
) {}
protected xml: XMPPXmlFunction = (...args) => xml(...args)
public async connect (): Promise<void> {
this.xmpp = component({
service: this.connectionConfig.service,
domain: this.connectionConfig.domain,
password: this.connectionConfig.password
}) as XMPP
})
this.xmpp.on('error', (err: any) => {
logger.error(err)
@ -49,14 +48,14 @@ abstract class ComponentBot {
}
})
this.xmpp.on('online', (address: XMPPAddress) => {
this.xmpp.on('online', (address) => {
logger.debug('Online with address' + address.toString())
this.address = address
void this.onOnline()
})
this.xmpp.start()
await this.xmpp.start()
}
public async stop (): Promise<any> {

View File

@ -1,21 +1,7 @@
import { EventEmitter } from 'events'
export interface XMPP extends EventEmitter {
send: (xml: any) => any
start: () => any
stop: () => Promise<any>
}
export interface XMPPAddress {
toString: () => string
}
import type { Element } from '@xmpp/xml'
export type XMPPStanzaType = 'message' | 'iq' | 'presence'
export interface XMPPStanza {
attrs: any
is: (type: XMPPStanzaType) => boolean
toString: () => string
export interface XMPPStanza extends Element {
name: XMPPStanzaType
}
export type XMPPXmlFunction = (type: string, attrs: object, content?: any) => any

189
package-lock.json generated
View File

@ -175,6 +175,15 @@
"integrity": "sha512-/yBMcem+fbvhSREH+s14YJi18sp7J9jpuhYByADT2rypfajMZZN4WQ6zBGgBKp53NKmqI36wFYDb3yaMPurITw==",
"dev": true
},
"@types/accepts": {
"version": "1.3.5",
"resolved": "https://registry.npmjs.org/@types/accepts/-/accepts-1.3.5.tgz",
"integrity": "sha512-jOdnI/3qTpHABjM5cx1Hc0sKsPoYCp+DP/GJRGtDlPd7fiV9oXGGIcjW/ZOxLIvjGz8MA+uMZI9metHlgqbgwQ==",
"dev": true,
"requires": {
"@types/node": "*"
}
},
"@types/async": {
"version": "3.2.9",
"resolved": "https://registry.npmjs.org/@types/async/-/async-3.2.9.tgz",
@ -211,6 +220,24 @@
"@types/node": "*"
}
},
"@types/content-disposition": {
"version": "0.5.4",
"resolved": "https://registry.npmjs.org/@types/content-disposition/-/content-disposition-0.5.4.tgz",
"integrity": "sha512-0mPF08jn9zYI0n0Q/Pnz7C4kThdSt+6LD4amsrYDDpgBfrVWa3TcCOxKX1zkGgYniGagRv8heN2cbh+CAn+uuQ==",
"dev": true
},
"@types/cookies": {
"version": "0.7.7",
"resolved": "https://registry.npmjs.org/@types/cookies/-/cookies-0.7.7.tgz",
"integrity": "sha512-h7BcvPUogWbKCzBR2lY4oqaZbO3jXZksexYJVFvkrFeLgbZjQkU4x8pRq6eg2MHXQhY0McQdqmmsxRWlVAHooA==",
"dev": true,
"requires": {
"@types/connect": "*",
"@types/express": "*",
"@types/keygrip": "*",
"@types/node": "*"
}
},
"@types/express": {
"version": "4.17.13",
"resolved": "https://registry.npmjs.org/@types/express/-/express-4.17.13.tgz",
@ -254,11 +281,23 @@
"form-data": "^2.5.0"
}
},
"@types/http-assert": {
"version": "1.5.3",
"resolved": "https://registry.npmjs.org/@types/http-assert/-/http-assert-1.5.3.tgz",
"integrity": "sha512-FyAOrDuQmBi8/or3ns4rwPno7/9tJTijVW6aQQjK02+kOQ8zmoNg2XJtAuQhvQcy1ASJq38wirX5//9J1EqoUA==",
"dev": true
},
"@types/http-cache-semantics": {
"version": "4.0.0",
"resolved": "https://registry.npmjs.org/@types/http-cache-semantics/-/http-cache-semantics-4.0.0.tgz",
"integrity": "sha512-c3Xy026kOF7QOTn00hbIllV1dLR9hG9NkSrLQgCVs8NF6sBU+VGWjD3wLPhmh1TYAc7ugCFsvHYMN4VcBN1U1A=="
},
"@types/http-errors": {
"version": "1.8.1",
"resolved": "https://registry.npmjs.org/@types/http-errors/-/http-errors-1.8.1.tgz",
"integrity": "sha512-e+2rjEwK6KDaNOm5Aa9wNGgyS9oSZU/4pfSMMPYNOfjvFI0WVXm29+ITRFr6aKDvvKo7uU1jV68MW4ScsfDi7Q==",
"dev": true
},
"@types/json-schema": {
"version": "7.0.9",
"resolved": "https://registry.npmjs.org/@types/json-schema/-/json-schema-7.0.9.tgz",
@ -271,6 +310,12 @@
"integrity": "sha1-7ihweulOEdK4J7y+UnC86n8+ce4=",
"dev": true
},
"@types/keygrip": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/@types/keygrip/-/keygrip-1.0.2.tgz",
"integrity": "sha512-GJhpTepz2udxGexqos8wgaBx4I/zWIDPh/KOGEwAqtuGDkOUJu5eFvwmdBX4AmB8Odsr+9pHCQqiAqDL/yKMKw==",
"dev": true
},
"@types/keyv": {
"version": "3.1.1",
"resolved": "https://registry.npmjs.org/@types/keyv/-/keyv-3.1.1.tgz",
@ -279,6 +324,37 @@
"@types/node": "*"
}
},
"@types/koa": {
"version": "2.13.4",
"resolved": "https://registry.npmjs.org/@types/koa/-/koa-2.13.4.tgz",
"integrity": "sha512-dfHYMfU+z/vKtQB7NUrthdAEiSvnLebvBjwHtfFmpZmB7em2N3WVQdHgnFq+xvyVgxW5jKDmjWfLD3lw4g4uTw==",
"dev": true,
"requires": {
"@types/accepts": "*",
"@types/content-disposition": "*",
"@types/cookies": "*",
"@types/http-assert": "*",
"@types/http-errors": "*",
"@types/keygrip": "*",
"@types/koa-compose": "*",
"@types/node": "*"
}
},
"@types/koa-compose": {
"version": "3.2.5",
"resolved": "https://registry.npmjs.org/@types/koa-compose/-/koa-compose-3.2.5.tgz",
"integrity": "sha512-B8nG/OoE1ORZqCkBVsup/AKcvjdgoHnfi4pZMn5UwAPCbhk/96xyv284eBYW8JlQbQ7zDmnpFr68I/40mFoIBQ==",
"dev": true,
"requires": {
"@types/koa": "*"
}
},
"@types/ltx": {
"version": "3.0.1",
"resolved": "https://registry.npmjs.org/@types/ltx/-/ltx-3.0.1.tgz",
"integrity": "sha512-X+1EoqEcSZ45MYJmg0rfMvEyQPGydLT00HJcPant+5J3+OM0N+ZVL6BdZ1Iy4K3dA+JBGe1WP7PvTM/GtxN/XA==",
"dev": true
},
"@types/mime": {
"version": "1.3.2",
"resolved": "https://registry.npmjs.org/@types/mime/-/mime-1.3.2.tgz",
@ -353,6 +429,119 @@
"winston": "*"
}
},
"@types/xmpp__component": {
"version": "0.13.0",
"resolved": "https://registry.npmjs.org/@types/xmpp__component/-/xmpp__component-0.13.0.tgz",
"integrity": "sha512-4vKLiicgkZwW8bKofmmy0BJpw3MuOW73c5hVPhUtgBPDTh9hj7wQezhpOLX3AhQFto97YpLg2GwWzhnwfSl1BA==",
"dev": true,
"requires": {
"@types/xmpp__component-core": "*",
"@types/xmpp__iq": "*",
"@types/xmpp__middleware": "*",
"@types/xmpp__reconnect": "*"
}
},
"@types/xmpp__component-core": {
"version": "0.13.0",
"resolved": "https://registry.npmjs.org/@types/xmpp__component-core/-/xmpp__component-core-0.13.0.tgz",
"integrity": "sha512-K9l6SLG91kTcchW/Nt5TL9Kfe5aWDyDcHWvoFgnwvGoF4g0K737HdZMzD0DN1TP7Gb2g/JNCiK245BuDYegAbw==",
"dev": true,
"requires": {
"@types/xmpp__connection-tcp": "*",
"@types/xmpp__jid": "*",
"@types/xmpp__xml": "*"
}
},
"@types/xmpp__connection": {
"version": "0.13.0",
"resolved": "https://registry.npmjs.org/@types/xmpp__connection/-/xmpp__connection-0.13.0.tgz",
"integrity": "sha512-YsvLhgOfxY3TbDTeTT0ZrToqh3IsA0nKnXk/NxTES2O6wTxn9lQDRBYNgB6lkq+D50nA8nmT3d53acb0f4Rycw==",
"dev": true,
"requires": {
"@types/xmpp__error": "*",
"@types/xmpp__events": "*",
"@types/xmpp__jid": "*",
"@types/xmpp__xml": "*"
}
},
"@types/xmpp__connection-tcp": {
"version": "0.13.0",
"resolved": "https://registry.npmjs.org/@types/xmpp__connection-tcp/-/xmpp__connection-tcp-0.13.0.tgz",
"integrity": "sha512-yHvAWck6JVs0H/E2tnoUVOsFPylLj1TX4ARdm1/jFRqOPWynw36B/RU0UW1KNSC8dKA6VAhl0mTICnGUZVtcug==",
"dev": true,
"requires": {
"@types/xmpp__connection": "*",
"@types/xmpp__xml": "*"
}
},
"@types/xmpp__error": {
"version": "0.13.0",
"resolved": "https://registry.npmjs.org/@types/xmpp__error/-/xmpp__error-0.13.0.tgz",
"integrity": "sha512-W+tM0UDj3toruhdjhn/VK1mtjOF+YMz+FdxgkMVi6lwCXA/uDW79elW6WbeM8zhiM92ZoVPSgD2zt9YXmrkiZQ==",
"dev": true,
"requires": {
"@types/xmpp__xml": "*"
}
},
"@types/xmpp__events": {
"version": "0.13.0",
"resolved": "https://registry.npmjs.org/@types/xmpp__events/-/xmpp__events-0.13.0.tgz",
"integrity": "sha512-somi0EF9BwaBPmDQk6r1hE6dtXXjv2ztSNk/hStcfGVY9NfD9ErcopWgzzbGdeQg2/WcMNlVwfYXQfIm6w3w+A==",
"dev": true,
"requires": {
"@types/node": "*"
}
},
"@types/xmpp__iq": {
"version": "0.13.0",
"resolved": "https://registry.npmjs.org/@types/xmpp__iq/-/xmpp__iq-0.13.0.tgz",
"integrity": "sha512-jy3aTixRMi8uqiIfhbkIxeWB62NTFGXKdZsYOwlgLNQ9BUimnbGR8BmZGSic5meUTPUaEEpCx/xp3AnVYADICQ==",
"dev": true,
"requires": {
"@types/koa-compose": "*",
"@types/xmpp__events": "*",
"@types/xmpp__middleware": "*",
"@types/xmpp__xml": "*"
}
},
"@types/xmpp__jid": {
"version": "1.3.2",
"resolved": "https://registry.npmjs.org/@types/xmpp__jid/-/xmpp__jid-1.3.2.tgz",
"integrity": "sha512-zh5mdcBY1zNzI9XxXZxsuq/XGd6YeSwZzwQJpV5NQEtZUiSJ1+YW19+w2pELLrlV2hoMOcSf8PfPwB9ocPwIDg==",
"dev": true
},
"@types/xmpp__middleware": {
"version": "0.13.0",
"resolved": "https://registry.npmjs.org/@types/xmpp__middleware/-/xmpp__middleware-0.13.0.tgz",
"integrity": "sha512-bgwIFdl5khKt/UQY4f6Ca7pEIUGQPCN3CvZ4ZuYSwp5PY9EpH32Tj/akUwfWMuMqGsybvdTeuq7ewT1ic7hsZQ==",
"dev": true,
"requires": {
"@types/koa-compose": "*",
"@types/xmpp__connection": "*",
"@types/xmpp__error": "*",
"@types/xmpp__jid": "*",
"@types/xmpp__xml": "*"
}
},
"@types/xmpp__reconnect": {
"version": "0.13.0",
"resolved": "https://registry.npmjs.org/@types/xmpp__reconnect/-/xmpp__reconnect-0.13.0.tgz",
"integrity": "sha512-MGuq9Dl24iU/t1nuGp/5yUsv4yAvQk5DOARw/iPXpAjB5hCBCzzvsN2ttkw8vAVsQ5DSbpgPWI33GQ2xF2MaSQ==",
"dev": true,
"requires": {
"@types/xmpp__connection": "*",
"@types/xmpp__events": "*"
}
},
"@types/xmpp__xml": {
"version": "0.13.1",
"resolved": "https://registry.npmjs.org/@types/xmpp__xml/-/xmpp__xml-0.13.1.tgz",
"integrity": "sha512-pxRGht/JVPhIwvcFkqv3fsXc1V/qj/C+vkTD75S1whpaNslJJbmA4hphOcbynvIegKdQHxfa56d22sOtHWjDsg==",
"dev": true,
"requires": {
"@types/ltx": "*"
}
},
"@typescript-eslint/eslint-plugin": {
"version": "4.29.0",
"resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-4.29.0.tgz",

View File

@ -49,6 +49,7 @@
"@types/got": "^9.6.12",
"@types/node": "^16.11.6",
"@types/winston": "^2.4.4",
"@types/xmpp__component": "^0.13.0",
"@typescript-eslint/eslint-plugin": "^4.29.0",
"@typescript-eslint/parser": "^4.29.0",
"eslint": "^7.32.0",