diff --git a/.eslintignore b/.eslintignore index 2ee0ee7..13aa93b 100644 --- a/.eslintignore +++ b/.eslintignore @@ -2,4 +2,6 @@ node_modules/* docs/* jsdoc2md/* coverage/* -tests/* \ No newline at end of file +tests/* +*.d.ts +*.js diff --git a/.eslintrc.json b/.eslintrc.json index ef901a8..8afc986 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -4,7 +4,12 @@ "node": true, "es6": true }, + "parser": "@typescript-eslint/parser", "parserOptions": { - "ecmaVersion": "2018" - } + "ecmaVersion": "2018", + "sourceType": "module" + }, + "plugins": [ + "@typescript-eslint" + ] } diff --git a/.gitignore b/.gitignore index da6b134..d7cfcd8 100644 --- a/.gitignore +++ b/.gitignore @@ -73,4 +73,7 @@ typings/ .serverless # Test files -run.js \ No newline at end of file +run.js + +index.js +*.d.ts diff --git a/index.js b/index.ts similarity index 96% rename from index.js rename to index.ts index 6fdcbe5..a74c76f 100644 --- a/index.js +++ b/index.ts @@ -16,12 +16,12 @@ * @exports CEF * @module SyslogPro */ -'use strict'; -const moment = require('moment'); -const os = require('os'); -const dns = require('dns'); +import moment from 'moment'; +import * as os from 'os'; +import * as dns from 'dns'; +import * as fs from 'fs'; +import * as tls from 'tls'; // eslint-disable-line no-unused-vars let dnsPromises = dns.promises; -const fs = require('fs'); /** * Format the ANSI foreground color code from a RGB hex code or ANSI color code @@ -88,6 +88,21 @@ function rgbToAnsi(hex, } } +type SyslogOptions = { + cef?: CEF | CEFOptions; + format?: string; + leef?: LEEF | LEEFOptions; + port?: number; + protocol?: string; + rfc3164?: RFC3164 | RFC3164Options; + rfc5424?: RFC5424 | RFC5424Options; + target?: string; + tcpTimeout?: number; + tlsServerCerts?: string | string[]; + tlsClientCert?: string; + tlsClientKey?: string; +}; + /** * A class to work with syslog messages using UDP, TCP, or TLS transport. * There is support for Syslog message formatting RFC-3164, RFC-5424 including @@ -99,7 +114,19 @@ function rgbToAnsi(hex, * @version 0.0.0 * @since 0.0.0 */ -class Syslog { +export class Syslog { + cef: any; + format: string; + leef: any; + port: number; + protocol: string; + rfc3164: any; + rfc5424: any; + target: string; + tcpTimeout: number; + tlsServerCerts: string | string[]; + tlsClientCert: string; + tlsClientKey: string; /** * Construct a new Syslog transport object with user options * @public @@ -140,8 +167,7 @@ class Syslog { * @param {CEF} [options.cef] - {@link module:SyslogPro~CEF|HP CEF * (Common Event Format) formatting object} */ - constructor(options) { - this.constructor__ = true; + constructor(options?: SyslogOptions) { if (!options) { options = {}; } @@ -179,35 +205,35 @@ class Syslog { this.format = options.format || 'none'; } if (options.rfc3164) { - if (options.rfc3164.constructor__) { + if (options.rfc3164 instanceof RFC3164) { /** @type {RFC3164} */ this.rfc3164 = options.rfc3164; } else { - this.rfc3164 = new RFC3164(options); + this.rfc3164 = new RFC3164(options.rfc3164); } } if (options.rfc5424) { - if (options.rfc5424.constructor__) { + if (options.rfc5424 instanceof RFC5424) { /** @type {RFC5424} */ this.rfc5424 = options.rfc5424; } else { - this.rfc5424 = new RFC5424(options); + this.rfc5424 = new RFC5424(options.rfc5424); } } if (options.leef) { - if (options.leef.constructor__) { + if (options.leef instanceof LEEF) { /** @type {LEEF} */ this.leef = options.leef; } else { - this.leef = new LEEF(options); + this.leef = new LEEF(options.leef); } } if (options.cef) { - if (options.cef.constructor__) { + if (options.cef instanceof CEF) { /** @type {CEF} */ this.cef = options.cef; } else { - this.cef = new CEF(options); + this.cef = new CEF(options.cef); } } if (this.format === 'rfc3164' && !this.rfc3164) { @@ -325,7 +351,7 @@ class Syslog { */ async tlsMessage(msg) { const tls = require('tls'); - const tlsOptions = { + const tlsOptions: tls.ConnectionOptions = { host: this.target, port: this.port, }; @@ -414,7 +440,16 @@ class Syslog { /** * The base class of RFC formartted syslog messages. */ -class RFC { +export class RFC { + alertColor: number; + criticalColor: number; + emergencyColor: number; + errorColor: number; + extendedColor: boolean; + debugColor: number; + informationalColor: number; + noticeColor: number; + warningColor: number; /** * Sets the color to be used for messages at a set priority * @public @@ -538,6 +573,25 @@ class RFC { } } +type RFC3164Options = { + applicationName?: string; + color?: boolean; + colors?: { + alertColor?: number; + criticalColor?: number; + emergencyColor?: number; + errorColor?: number; + debugColor?: number; + informationalColor?: number; + noticeColor?: number; + warningColor?: number; + }; + extendedColor?: boolean; + facility?: number; + hostname?: string; + server?: Syslog | SyslogOptions; +}; + /** * A class to work with RFC3164 formatted syslog messages. The messaging is * fully configurable and ANSI foreground colors can be added. Both ANSI 8 and @@ -554,7 +608,12 @@ class RFC { * @version 0.0.0 * @since 0.0.0 */ -class RFC3164 extends RFC { +export class RFC3164 extends RFC { + applicationName: string; + color: boolean; + facility: number; + hostname: string; + server: Syslog; /** * Construct a new RFC3164 formatted Syslog object with user options * @public @@ -598,17 +657,11 @@ class RFC3164 extends RFC { * Syslog server connection} that should be used to send messages directly * from this class. @see SyslogPro~Syslog */ - constructor(options) { + constructor(options?: RFC3164Options) { super(); - /** @private @type {boolean} */ - this.constructor__ = true; options = options || {}; this.hostname = options.hostname || os.hostname(); - if (options.applicationName) { - this.applicationName = options.applicationName; - } else { - this.applicationName = options.applacationName || ''; - } + this.applicationName = options.applicationName || ''; this.facility = options.facility || 23; if (options.color) { /** @type {boolean} */ @@ -623,11 +676,11 @@ class RFC3164 extends RFC { this.extendedColor = false; } if (options.server) { - if (!options.server.constructor__) { + if (options.server instanceof Syslog) { /** @private @type {Syslog} */ - this.server = new Syslog(options.server); - } else { this.server = options.server; + } else { + this.server = new Syslog(options.server); } } if (this.extendedColor) { @@ -925,6 +978,30 @@ class RFC3164 extends RFC { } } +type RFC5424Options = { + applicationName?: string; + color?: boolean; + colors?: { + alertColor?: number; + criticalColor?: number; + emergencyColor?: number; + errorColor?: number; + debugColor?: number; + informationalColor?: number; + noticeColor?: number; + warningColor?: number; + }; + extendedColor?: boolean; + hostname?: string; + includeStructuredData?: boolean; + server?: Syslog | SyslogOptions; + timestamp?: boolean; + timestampMS?: boolean; + timestampTZ?: boolean; + timestampUTC?: boolean; + utf8BOM?: boolean; +}; + /** * A class to work with RFC5424 formatted syslog messages. The messaging is * fully configurable and ANSI foreground * colors can be added. Both ANSI 8 @@ -941,7 +1018,17 @@ class RFC3164 extends RFC { * @version 0.0.0 * @since 0.0.0 */ -class RFC5424 extends RFC { +export class RFC5424 extends RFC { + applicationName: string; + color: boolean; + hostname: string; + includeStructuredData: boolean; + server: Syslog; + timestamp: boolean; + timestampMS: boolean; + timestampTZ: boolean; + timestampUTC: boolean; + utf8BOM: boolean; /** * Construct a new RFC5424 formatted Syslog object with user options * @public @@ -992,17 +1079,11 @@ class RFC5424 extends RFC { * Syslog server connection} that should be used to send messages directly * from this class. @see SyslogPro~Syslog */ - constructor(options) { + constructor(options?: RFC5424Options) { super(); - /** @private @type {boolean} */ - this.constructor__ = true; options = options || {}; this.hostname = options.hostname || os.hostname(); - if (options.applicationName) { - this.applicationName = options.applicationName; - } else { - this.applicationName = options.applacationName || ''; - } + this.applicationName = options.applicationName || ''; if (typeof options.timestamp === 'undefined' || options.timestamp) { /** @type {boolean} */ this.timestamp = true; @@ -1027,7 +1108,7 @@ class RFC5424 extends RFC { } else { this.timestampMS = false; } - if (options.includeStructuredData || options.encludeStructuredData) { + if (options.includeStructuredData) { /** @type {boolean} */ this.includeStructuredData = true; } else { @@ -1052,11 +1133,11 @@ class RFC5424 extends RFC { this.extendedColor = false; } if (options.server) { - if (!options.server.constructor__) { + if (options.server instanceof Syslog) { /** @private @type {Syslog} */ - this.server = new Syslog(options.server); - } else { this.server = options.server; + } else { + this.server = new Syslog(options.server); } } if (this.extendedColor) { @@ -1440,6 +1521,16 @@ class RFC5424 extends RFC { } } +type LEEFOptions = { + attributes?: any; + eventId?: string; + product?: string; + server?: Syslog | SyslogOptions; + syslogHeader?: boolean; + vendor?: string; + version?: string; +}; + /** * A class to work with IBM LEEF (Log Event Extended Format) messages this form * of system messages are designed to work with security systems. Messages can @@ -1455,7 +1546,14 @@ class RFC5424 extends RFC { * @version 0.0.0 * @since 0.0.0 */ -class LEEF { +export class LEEF { + attributes: any; + eventId: string; + product: string; + server: Syslog; + syslogHeader: boolean; + vendor: string; + version: string; /** * Construct a new LEEF formatting object with user options * @public @@ -1477,9 +1575,7 @@ class LEEF { * Syslog server connection} that should be used to send messages directly * from this class. @see SyslogPro~Syslog */ - constructor(options) { - /** @private @type {boolean} */ - this.constructor__ = true; + constructor(options?: LEEFOptions) { options = options || {}; /** @type {string} */ this.vendor = options.vendor || 'unknown'; @@ -1542,7 +1638,7 @@ class LEEF { calCountryOrRegion: null, }; if (options.server) { - if (options.server.constructor__) { + if (options.server instanceof Syslog) { /** @private @type {Syslog} */ this.server = options.server; } else { @@ -1590,6 +1686,17 @@ class LEEF { } } +type CEFOptions = { + deviceEventClassId?: string; + deviceProduct?: string; + deviceVendor?: string; + deviceVersion?: string; + extensions?: any; + name?: string; + server?: Syslog | SyslogOptions; + severity?: string; +}; + /** * A class to work with HP CEF (Common Event Format) messages. This form * of system messages are designed to work with security systems. Messages can @@ -1605,7 +1712,15 @@ class LEEF { * @version 0.0.0 * @since 0.0.0 */ -class CEF { +export class CEF { + deviceEventClassId: string; + deviceProduct: string; + deviceVendor: string; + deviceVersion: string; + extensions: any; + name: string; + server: Syslog; + severity: string; /** * Construct a new CEF formatting object with user options * @public @@ -1626,9 +1741,7 @@ class CEF { * Syslog server connection} that should be used to send messages directly * from this class. @see SyslogPro~Syslog */ - constructor(options) { - /** @private @type {boolean} */ - this.constructor__ = true; + constructor(options?: CEFOptions) { options = options || {}; /** @type {string} */ this.deviceVendor = options.deviceVendor || 'Unknown'; @@ -1803,11 +1916,11 @@ class CEF { sourceZoneURI: null, }; if (options.server) { - if (options.server.constructor__) { + if (options.server instanceof Syslog) { /** @private @type {Syslog} */ this.server = options.server; } else { - this.server = new Syslog(options.server); + this.server = new Syslog(options.server as SyslogOptions); } } } @@ -3017,7 +3130,8 @@ class CEF { .toLowerCase()) { if (Extensions[cefExts[ext][0]].len > 0 && typeof cefExts[ext][1] === 'string' - && cefExts[ext][1].length > Extensions[cefExts[ext][0]].len){ + && (cefExts[ext][1] as string).length + > Extensions[cefExts[ext][0]].len){ let errMsg = 'FORMAT ERROR:'; errMsg += ' CEF Extention Key'; errMsg += ' ' + cefExts[ext][0]; @@ -3078,11 +3192,4 @@ class CEF { } } -module.exports = { - RgbToAnsi: rgbToAnsi, - RFC3164: RFC3164, - RFC5424: RFC5424, - LEEF: LEEF, - CEF: CEF, - Syslog: Syslog, -}; +export const RgbToAnsi = rgbToAnsi; diff --git a/package-lock.json b/package-lock.json index db272e2..d94cb73 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,5 +1,5 @@ { - "name": "syslog-pro", + "name": "@zeit/syslog-pro", "version": "0.2.0", "lockfileVersion": 1, "requires": true, @@ -32,6 +32,140 @@ } } }, + "@types/eslint-visitor-keys": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/@types/eslint-visitor-keys/-/eslint-visitor-keys-1.0.0.tgz", + "integrity": "sha512-OCutwjDZ4aFS6PB1UZ988C4YgwlBHJd6wCeQqaLdmadZ/7e+w79+hbMUFC1QXDNCmdyoRfAFdm0RypzwR+Qpag==", + "dev": true + }, + "@types/json-schema": { + "version": "7.0.3", + "resolved": "https://registry.npmjs.org/@types/json-schema/-/json-schema-7.0.3.tgz", + "integrity": "sha512-Il2DtDVRGDcqjDtE+rF8iqg1CArehSK84HZJCT7AMITlyXRBpuPhqGLDQMowraqqu1coEaimg4ZOqggt6L6L+A==", + "dev": true + }, + "@types/node": { + "version": "12.7.11", + "resolved": "https://registry.npmjs.org/@types/node/-/node-12.7.11.tgz", + "integrity": "sha512-Otxmr2rrZLKRYIybtdG/sgeO+tHY20GxeDjcGmUnmmlCWyEnv2a2x1ZXBo3BTec4OiTXMQCiazB8NMBf0iRlFw==", + "dev": true + }, + "@typescript-eslint/eslint-plugin": { + "version": "2.3.3", + "resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-2.3.3.tgz", + "integrity": "sha512-12cCbwu5PbQudkq2xCIS/QhB7hCMrsNPXK+vJtqy/zFqtzVkPRGy12O5Yy0gUK086f3VHV/P4a4R4CjMW853pA==", + "dev": true, + "requires": { + "@typescript-eslint/experimental-utils": "2.3.3", + "eslint-utils": "^1.4.2", + "functional-red-black-tree": "^1.0.1", + "regexpp": "^2.0.1", + "tsutils": "^3.17.1" + }, + "dependencies": { + "eslint-utils": { + "version": "1.4.2", + "resolved": "https://registry.npmjs.org/eslint-utils/-/eslint-utils-1.4.2.tgz", + "integrity": "sha512-eAZS2sEUMlIeCjBeubdj45dmBHQwPHWyBcT1VSYB7o9x9WRRqKxyUoiXlRjyAwzN7YEzHJlYg0NmzDRWx6GP4Q==", + "dev": true, + "requires": { + "eslint-visitor-keys": "^1.0.0" + } + } + } + }, + "@typescript-eslint/experimental-utils": { + "version": "2.3.3", + "resolved": "https://registry.npmjs.org/@typescript-eslint/experimental-utils/-/experimental-utils-2.3.3.tgz", + "integrity": "sha512-MQ4jKPMTU1ty4TigJCRKFPye2qyQdH8jzIIkceaHgecKFmkNS1hXPqKiZ+mOehkz6+HcN5Nuvwm+frmWZR9tdg==", + "dev": true, + "requires": { + "@types/json-schema": "^7.0.3", + "@typescript-eslint/typescript-estree": "2.3.3", + "eslint-scope": "^5.0.0" + }, + "dependencies": { + "eslint-scope": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/eslint-scope/-/eslint-scope-5.0.0.tgz", + "integrity": "sha512-oYrhJW7S0bxAFDvWqzvMPRm6pcgcnWc4QnofCAqRTRfQC0JcwenzGglTtsLyIuuWFfkqDG9vz67cnttSd53djw==", + "dev": true, + "requires": { + "esrecurse": "^4.1.0", + "estraverse": "^4.1.1" + } + } + } + }, + "@typescript-eslint/parser": { + "version": "2.3.3", + "resolved": "https://registry.npmjs.org/@typescript-eslint/parser/-/parser-2.3.3.tgz", + "integrity": "sha512-+cV53HuYFeeyrNW8x/rgPmbVrzzp/rpRmwbJnNtwn4K8mroL1BdjxwQh7X9cUHp9rm4BBiEWmD3cSBjKG7d5mw==", + "dev": true, + "requires": { + "@types/eslint-visitor-keys": "^1.0.0", + "@typescript-eslint/experimental-utils": "2.3.3", + "@typescript-eslint/typescript-estree": "2.3.3", + "eslint-visitor-keys": "^1.1.0" + }, + "dependencies": { + "eslint-visitor-keys": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/eslint-visitor-keys/-/eslint-visitor-keys-1.1.0.tgz", + "integrity": "sha512-8y9YjtM1JBJU/A9Kc+SbaOV4y29sSWckBwMHa+FGtVj5gN/sbnKDf6xJUl+8g7FAij9LVaP8C24DUiH/f/2Z9A==", + "dev": true + } + } + }, + "@typescript-eslint/typescript-estree": { + "version": "2.3.3", + "resolved": "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-2.3.3.tgz", + "integrity": "sha512-GkACs12Xp8d/STunNv/iSMYJFQrkrax9vuPZySlgSzoJJtw1cp6tbEw4qsLskQv6vloLrkFJHcTJ0a/yCB5cIA==", + "dev": true, + "requires": { + "glob": "^7.1.4", + "is-glob": "^4.0.1", + "lodash.unescape": "4.0.1", + "semver": "^6.3.0" + }, + "dependencies": { + "glob": { + "version": "7.1.4", + "resolved": "https://registry.npmjs.org/glob/-/glob-7.1.4.tgz", + "integrity": "sha512-hkLPepehmnKk41pUGm3sYxoFs/umurYfYJCerbXEyFIWcAzvpipAgVkBqqT9RBKMGjnq6kMuyYwha6csxbiM1A==", + "dev": true, + "requires": { + "fs.realpath": "^1.0.0", + "inflight": "^1.0.4", + "inherits": "2", + "minimatch": "^3.0.4", + "once": "^1.3.0", + "path-is-absolute": "^1.0.0" + } + }, + "is-extglob": { + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/is-extglob/-/is-extglob-2.1.1.tgz", + "integrity": "sha1-qIwCU1eR8C7TfHahueqXc8gz+MI=", + "dev": true + }, + "is-glob": { + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/is-glob/-/is-glob-4.0.1.tgz", + "integrity": "sha512-5G0tKtBTFImOqDnLB2hG6Bp2qcKEFduo4tZu9MT/H6NQv/ghhy30o55ufafxJ/LdH79LLs2Kfrn85TLKyA7BUg==", + "dev": true, + "requires": { + "is-extglob": "^2.1.1" + } + }, + "semver": { + "version": "6.3.0", + "resolved": "https://registry.npmjs.org/semver/-/semver-6.3.0.tgz", + "integrity": "sha512-b39TBaTSfV6yBrapU89p5fKekE2m/NwnDocOVruQFS1/veMgdzuPcnOM34M6CwxW8jH/lxEa5rBoDeUwu5HHTw==", + "dev": true + } + } + }, "abab": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/abab/-/abab-2.0.0.tgz", @@ -2162,7 +2296,8 @@ "ansi-regex": { "version": "2.1.1", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "aproba": { "version": "1.2.0", @@ -2183,12 +2318,14 @@ "balanced-match": { "version": "1.0.0", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "brace-expansion": { "version": "1.1.11", "bundled": true, "dev": true, + "optional": true, "requires": { "balanced-match": "^1.0.0", "concat-map": "0.0.1" @@ -2203,17 +2340,20 @@ "code-point-at": { "version": "1.1.0", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "concat-map": { "version": "0.0.1", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "console-control-strings": { "version": "1.1.0", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "core-util-is": { "version": "1.0.2", @@ -2330,7 +2470,8 @@ "inherits": { "version": "2.0.3", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "ini": { "version": "1.3.5", @@ -2342,6 +2483,7 @@ "version": "1.0.0", "bundled": true, "dev": true, + "optional": true, "requires": { "number-is-nan": "^1.0.0" } @@ -2356,6 +2498,7 @@ "version": "3.0.4", "bundled": true, "dev": true, + "optional": true, "requires": { "brace-expansion": "^1.1.7" } @@ -2363,12 +2506,14 @@ "minimist": { "version": "0.0.8", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "minipass": { "version": "2.2.4", "bundled": true, "dev": true, + "optional": true, "requires": { "safe-buffer": "^5.1.1", "yallist": "^3.0.0" @@ -2387,6 +2532,7 @@ "version": "0.5.1", "bundled": true, "dev": true, + "optional": true, "requires": { "minimist": "0.0.8" } @@ -2467,7 +2613,8 @@ "number-is-nan": { "version": "1.0.1", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "object-assign": { "version": "4.1.1", @@ -2479,6 +2626,7 @@ "version": "1.4.0", "bundled": true, "dev": true, + "optional": true, "requires": { "wrappy": "1" } @@ -2564,7 +2712,8 @@ "safe-buffer": { "version": "5.1.1", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "safer-buffer": { "version": "2.1.2", @@ -2600,6 +2749,7 @@ "version": "1.0.2", "bundled": true, "dev": true, + "optional": true, "requires": { "code-point-at": "^1.0.0", "is-fullwidth-code-point": "^1.0.0", @@ -2619,6 +2769,7 @@ "version": "3.0.1", "bundled": true, "dev": true, + "optional": true, "requires": { "ansi-regex": "^2.0.0" } @@ -2662,12 +2813,14 @@ "wrappy": { "version": "1.0.2", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "yallist": { "version": "3.0.2", "bundled": true, - "dev": true + "dev": true, + "optional": true } } }, @@ -4186,6 +4339,12 @@ "integrity": "sha1-7dFMgk4sycHgsKG0K7UhBRakJDg=", "dev": true }, + "lodash.unescape": { + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/lodash.unescape/-/lodash.unescape-4.0.1.tgz", + "integrity": "sha1-vyJJiGzlFM2hEvrpIYzcBlIR/Jw=", + "dev": true + }, "log-driver": { "version": "1.2.7", "resolved": "https://registry.npmjs.org/log-driver/-/log-driver-1.2.7.tgz", @@ -6296,6 +6455,15 @@ "integrity": "sha512-4krF8scpejhaOgqzBEcGM7yDIEfi0/8+8zDRZhNZZ2kjmHJ4hv3zCbQWxoJGz1iw5U0Jl0nma13xzHXcncMavQ==", "dev": true }, + "tsutils": { + "version": "3.17.1", + "resolved": "https://registry.npmjs.org/tsutils/-/tsutils-3.17.1.tgz", + "integrity": "sha512-kzeQ5B8H3w60nFY2g8cJIuH7JDpsALXySGtwGJ0p2LSjLgay3NdIpqq5SoOBe46bKDW2iq25irHCr8wjomUS2g==", + "dev": true, + "requires": { + "tslib": "^1.8.1" + } + }, "tunnel-agent": { "version": "0.6.0", "resolved": "https://registry.npmjs.org/tunnel-agent/-/tunnel-agent-0.6.0.tgz", @@ -6321,6 +6489,12 @@ "prelude-ls": "~1.1.2" } }, + "typescript": { + "version": "3.6.3", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-3.6.3.tgz", + "integrity": "sha512-N7bceJL1CtRQ2RiG0AQME13ksR7DiuQh/QehubYcghzv20tnh+MQnQIuJddTmsbqYj+dztchykemz0zFzlvdQw==", + "dev": true + }, "typical": { "version": "2.6.1", "resolved": "https://registry.npmjs.org/typical/-/typical-2.6.1.tgz", diff --git a/package.json b/package.json index 956d107..4e8d4b4 100644 --- a/package.json +++ b/package.json @@ -42,14 +42,19 @@ "license": "MIT", "repository": { "type": "git", - "url": "https://github.com/cyamato/SyslogPro.git" + "url": "https://github.com/zeit/SyslogPro.git" }, "directories": { "doc": "./docs", "example": "./example", "test": "./test" }, + "files": [ + "index.d.ts", + "index.js" + ], "main": "index.js", + "types": "index.d.ts", "engines": { "node": ">=10.0.0" }, @@ -57,6 +62,9 @@ "moment": "^2.22.2" }, "devDependencies": { + "@types/node": "12.7.11", + "@typescript-eslint/eslint-plugin": "2.3.3", + "@typescript-eslint/parser": "2.3.3", "ajv": "^6.5.4", "coveralls": "^3.0.2", "docco": "^0.8.0", @@ -65,15 +73,18 @@ "eslint-config-strongloop": "^2.1.0", "jest": "^23.5.0", "jsdoc": "^3.5.5", - "jsdoc-to-markdown": "^4.0.1" + "jsdoc-to-markdown": "^4.0.1", + "typescript": "3.6.3" }, "scripts": { - "pretest": "eslint .", + "build": "tsc", + "pretest": "eslint '*.ts' && npm run build", "test": "jest --colors --expand --logHeapUsage --runInBand && cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js", "docs": "jsdoc *.js -c ./jsdoc.json; jsdoc2md --template ./jsdoc2md/api.hbs --files *.js > ./docs/api.md; docco --output ./docs/docco --layout plain-markdown *.js && mv ./docs/docco/index.html ./docs/docco/README.md; docco --output ./docs/docco *.js", "jsdoc": "jsdoc *.js -c ./jsdoc.json", "readme": "jsdoc2md --template ./jsdoc2md/api.hbs --files *.js > ./docs/api.md", - "docco": "docco --output ./docs/docco --layout plain-markdown *.js && mv ./docs/docco/index.html ./docs/docco/README.md; docco --output ./docs/docco *.js" + "docco": "docco --output ./docs/docco --layout plain-markdown *.js && mv ./docs/docco/index.html ./docs/docco/README.md; docco --output ./docs/docco *.js", + "prepublishOnly": "npm run build" }, "jest": { "collectCoverage": true, diff --git a/tests/syslog.test.js b/tests/syslog.test.js index 53c1eed..536430d 100644 --- a/tests/syslog.test.js +++ b/tests/syslog.test.js @@ -898,25 +898,25 @@ describe('Base Syslog Class tests', () => { let syslog = new SyslogPro.Syslog({ format: 'cef' }); - expect(syslog.cef.constructor__).toBe(true); + expect(syslog.cef instanceof SyslogPro.CEF).toBe(true); }); test('Syslog constructor with format leef but no object', () => { let syslog = new SyslogPro.Syslog({ format: 'leef' }); - expect(syslog.leef.constructor__).toBe(true); + expect(syslog.leef instanceof SyslogPro.LEEF).toBe(true); }); test('Syslog constructor with format rfc5424 but no object', () => { let syslog = new SyslogPro.Syslog({ format: 'rfc5424' }); - expect(syslog.rfc5424.constructor__).toBe(true); + expect(syslog.rfc5424 instanceof SyslogPro.RFC5424).toBe(true); }); test('Syslog constructor with format rfc3164 but no object', () => { let syslog = new SyslogPro.Syslog({ format: 'rfc3164' }); - expect(syslog.rfc3164.constructor__).toBe(true); + expect(syslog.rfc3164 instanceof SyslogPro.RFC3164).toBe(true); }); test('Syslog constructor with format objects', () => { let rfc3164 = new SyslogPro.RFC3164(); @@ -929,11 +929,10 @@ describe('Base Syslog Class tests', () => { leef: leef, cef: cef, }); - expect.assertions(4); - expect(syslog.rfc3164.constructor__).toBe(true); - expect(syslog.rfc5424.constructor__).toBe(true); - expect(syslog.leef.constructor__).toBe(true); - expect(syslog.cef.constructor__).toBe(true); + expect(syslog.rfc3164 instanceof SyslogPro.RFC3164).toBe(true); + expect(syslog.rfc5424 instanceof SyslogPro.RFC5424).toBe(true); + expect(syslog.leef instanceof SyslogPro.LEEF).toBe(true); + expect(syslog.cef instanceof SyslogPro.CEF).toBe(true); }); test('Syslog constructor with format objects configs', () => { let rfc3164 = {}; @@ -947,10 +946,10 @@ describe('Base Syslog Class tests', () => { cef: cef, }); expect.assertions(4); - expect(syslog.rfc3164.constructor__).toBe(true); - expect(syslog.rfc5424.constructor__).toBe(true); - expect(syslog.leef.constructor__).toBe(true); - expect(syslog.cef.constructor__).toBe(true); + expect(syslog.rfc3164 instanceof SyslogPro.RFC3164).toBe(true); + expect(syslog.rfc5424 instanceof SyslogPro.RFC5424).toBe(true); + expect(syslog.leef instanceof SyslogPro.LEEF).toBe(true); + expect(syslog.cef instanceof SyslogPro.CEF).toBe(true); }); test('Syslog Send with Protocol selection Error', async () => { let syslog = new SyslogPro.Syslog({ diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 0000000..f91f60a --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,10 @@ +{ + "compilerOptions": { + "target": "es2018", + "module": "commonjs", + "declaration": true, + "esModuleInterop": true, + "strict": false, + "noImplicitAny": false + } +}