Merge pull request #6 from zeit/typescript

Use Typescript
This commit is contained in:
Naoyuki Kanezawa 2019-10-08 20:41:20 +09:00 committed by GitHub
commit 10282e46df
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 407 additions and 96 deletions

View File

@ -2,4 +2,6 @@ node_modules/*
docs/* docs/*
jsdoc2md/* jsdoc2md/*
coverage/* coverage/*
tests/* tests/*
*.d.ts
*.js

View File

@ -4,7 +4,12 @@
"node": true, "node": true,
"es6": true "es6": true
}, },
"parser": "@typescript-eslint/parser",
"parserOptions": { "parserOptions": {
"ecmaVersion": "2018" "ecmaVersion": "2018",
} "sourceType": "module"
},
"plugins": [
"@typescript-eslint"
]
} }

5
.gitignore vendored
View File

@ -73,4 +73,7 @@ typings/
.serverless .serverless
# Test files # Test files
run.js run.js
index.js
*.d.ts

View File

@ -16,12 +16,12 @@
* @exports CEF * @exports CEF
* @module SyslogPro * @module SyslogPro
*/ */
'use strict'; import moment from 'moment';
const moment = require('moment'); import * as os from 'os';
const os = require('os'); import * as dns from 'dns';
const dns = require('dns'); import * as fs from 'fs';
import * as tls from 'tls'; // eslint-disable-line no-unused-vars
let dnsPromises = dns.promises; let dnsPromises = dns.promises;
const fs = require('fs');
/** /**
* Format the ANSI foreground color code from a RGB hex code or ANSI color code * 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. * 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 * There is support for Syslog message formatting RFC-3164, RFC-5424 including
@ -99,7 +114,19 @@ function rgbToAnsi(hex,
* @version 0.0.0 * @version 0.0.0
* @since 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 * Construct a new Syslog transport object with user options
* @public * @public
@ -140,8 +167,7 @@ class Syslog {
* @param {CEF} [options.cef] - {@link module:SyslogPro~CEF|HP CEF * @param {CEF} [options.cef] - {@link module:SyslogPro~CEF|HP CEF
* (Common Event Format) formatting object} * (Common Event Format) formatting object}
*/ */
constructor(options) { constructor(options?: SyslogOptions) {
this.constructor__ = true;
if (!options) { if (!options) {
options = {}; options = {};
} }
@ -179,35 +205,35 @@ class Syslog {
this.format = options.format || 'none'; this.format = options.format || 'none';
} }
if (options.rfc3164) { if (options.rfc3164) {
if (options.rfc3164.constructor__) { if (options.rfc3164 instanceof RFC3164) {
/** @type {RFC3164} */ /** @type {RFC3164} */
this.rfc3164 = options.rfc3164; this.rfc3164 = options.rfc3164;
} else { } else {
this.rfc3164 = new RFC3164(options); this.rfc3164 = new RFC3164(options.rfc3164);
} }
} }
if (options.rfc5424) { if (options.rfc5424) {
if (options.rfc5424.constructor__) { if (options.rfc5424 instanceof RFC5424) {
/** @type {RFC5424} */ /** @type {RFC5424} */
this.rfc5424 = options.rfc5424; this.rfc5424 = options.rfc5424;
} else { } else {
this.rfc5424 = new RFC5424(options); this.rfc5424 = new RFC5424(options.rfc5424);
} }
} }
if (options.leef) { if (options.leef) {
if (options.leef.constructor__) { if (options.leef instanceof LEEF) {
/** @type {LEEF} */ /** @type {LEEF} */
this.leef = options.leef; this.leef = options.leef;
} else { } else {
this.leef = new LEEF(options); this.leef = new LEEF(options.leef);
} }
} }
if (options.cef) { if (options.cef) {
if (options.cef.constructor__) { if (options.cef instanceof CEF) {
/** @type {CEF} */ /** @type {CEF} */
this.cef = options.cef; this.cef = options.cef;
} else { } else {
this.cef = new CEF(options); this.cef = new CEF(options.cef);
} }
} }
if (this.format === 'rfc3164' && !this.rfc3164) { if (this.format === 'rfc3164' && !this.rfc3164) {
@ -325,7 +351,7 @@ class Syslog {
*/ */
async tlsMessage(msg) { async tlsMessage(msg) {
const tls = require('tls'); const tls = require('tls');
const tlsOptions = { const tlsOptions: tls.ConnectionOptions = {
host: this.target, host: this.target,
port: this.port, port: this.port,
}; };
@ -414,7 +440,16 @@ class Syslog {
/** /**
* The base class of RFC formartted syslog messages. * 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 * Sets the color to be used for messages at a set priority
* @public * @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 * 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 * fully configurable and ANSI foreground colors can be added. Both ANSI 8 and
@ -554,7 +608,12 @@ class RFC {
* @version 0.0.0 * @version 0.0.0
* @since 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 * Construct a new RFC3164 formatted Syslog object with user options
* @public * @public
@ -598,17 +657,11 @@ class RFC3164 extends RFC {
* Syslog server connection} that should be used to send messages directly * Syslog server connection} that should be used to send messages directly
* from this class. @see SyslogPro~Syslog * from this class. @see SyslogPro~Syslog
*/ */
constructor(options) { constructor(options?: RFC3164Options) {
super(); super();
/** @private @type {boolean} */
this.constructor__ = true;
options = options || {}; options = options || {};
this.hostname = options.hostname || os.hostname(); this.hostname = options.hostname || os.hostname();
if (options.applicationName) { this.applicationName = options.applicationName || '';
this.applicationName = options.applicationName;
} else {
this.applicationName = options.applacationName || '';
}
this.facility = options.facility || 23; this.facility = options.facility || 23;
if (options.color) { if (options.color) {
/** @type {boolean} */ /** @type {boolean} */
@ -623,11 +676,11 @@ class RFC3164 extends RFC {
this.extendedColor = false; this.extendedColor = false;
} }
if (options.server) { if (options.server) {
if (!options.server.constructor__) { if (options.server instanceof Syslog) {
/** @private @type {Syslog} */ /** @private @type {Syslog} */
this.server = new Syslog(options.server);
} else {
this.server = options.server; this.server = options.server;
} else {
this.server = new Syslog(options.server);
} }
} }
if (this.extendedColor) { 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 * A class to work with RFC5424 formatted syslog messages. The messaging is
* fully configurable and ANSI foreground * colors can be added. Both ANSI 8 * fully configurable and ANSI foreground * colors can be added. Both ANSI 8
@ -941,7 +1018,17 @@ class RFC3164 extends RFC {
* @version 0.0.0 * @version 0.0.0
* @since 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 * Construct a new RFC5424 formatted Syslog object with user options
* @public * @public
@ -992,17 +1079,11 @@ class RFC5424 extends RFC {
* Syslog server connection} that should be used to send messages directly * Syslog server connection} that should be used to send messages directly
* from this class. @see SyslogPro~Syslog * from this class. @see SyslogPro~Syslog
*/ */
constructor(options) { constructor(options?: RFC5424Options) {
super(); super();
/** @private @type {boolean} */
this.constructor__ = true;
options = options || {}; options = options || {};
this.hostname = options.hostname || os.hostname(); this.hostname = options.hostname || os.hostname();
if (options.applicationName) { this.applicationName = options.applicationName || '';
this.applicationName = options.applicationName;
} else {
this.applicationName = options.applacationName || '';
}
if (typeof options.timestamp === 'undefined' || options.timestamp) { if (typeof options.timestamp === 'undefined' || options.timestamp) {
/** @type {boolean} */ /** @type {boolean} */
this.timestamp = true; this.timestamp = true;
@ -1027,7 +1108,7 @@ class RFC5424 extends RFC {
} else { } else {
this.timestampMS = false; this.timestampMS = false;
} }
if (options.includeStructuredData || options.encludeStructuredData) { if (options.includeStructuredData) {
/** @type {boolean} */ /** @type {boolean} */
this.includeStructuredData = true; this.includeStructuredData = true;
} else { } else {
@ -1052,11 +1133,11 @@ class RFC5424 extends RFC {
this.extendedColor = false; this.extendedColor = false;
} }
if (options.server) { if (options.server) {
if (!options.server.constructor__) { if (options.server instanceof Syslog) {
/** @private @type {Syslog} */ /** @private @type {Syslog} */
this.server = new Syslog(options.server);
} else {
this.server = options.server; this.server = options.server;
} else {
this.server = new Syslog(options.server);
} }
} }
if (this.extendedColor) { 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 * 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 * of system messages are designed to work with security systems. Messages can
@ -1455,7 +1546,14 @@ class RFC5424 extends RFC {
* @version 0.0.0 * @version 0.0.0
* @since 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 * Construct a new LEEF formatting object with user options
* @public * @public
@ -1477,9 +1575,7 @@ class LEEF {
* Syslog server connection} that should be used to send messages directly * Syslog server connection} that should be used to send messages directly
* from this class. @see SyslogPro~Syslog * from this class. @see SyslogPro~Syslog
*/ */
constructor(options) { constructor(options?: LEEFOptions) {
/** @private @type {boolean} */
this.constructor__ = true;
options = options || {}; options = options || {};
/** @type {string} */ /** @type {string} */
this.vendor = options.vendor || 'unknown'; this.vendor = options.vendor || 'unknown';
@ -1542,7 +1638,7 @@ class LEEF {
calCountryOrRegion: null, calCountryOrRegion: null,
}; };
if (options.server) { if (options.server) {
if (options.server.constructor__) { if (options.server instanceof Syslog) {
/** @private @type {Syslog} */ /** @private @type {Syslog} */
this.server = options.server; this.server = options.server;
} else { } 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 * 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 * of system messages are designed to work with security systems. Messages can
@ -1605,7 +1712,15 @@ class LEEF {
* @version 0.0.0 * @version 0.0.0
* @since 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 * Construct a new CEF formatting object with user options
* @public * @public
@ -1626,9 +1741,7 @@ class CEF {
* Syslog server connection} that should be used to send messages directly * Syslog server connection} that should be used to send messages directly
* from this class. @see SyslogPro~Syslog * from this class. @see SyslogPro~Syslog
*/ */
constructor(options) { constructor(options?: CEFOptions) {
/** @private @type {boolean} */
this.constructor__ = true;
options = options || {}; options = options || {};
/** @type {string} */ /** @type {string} */
this.deviceVendor = options.deviceVendor || 'Unknown'; this.deviceVendor = options.deviceVendor || 'Unknown';
@ -1803,11 +1916,11 @@ class CEF {
sourceZoneURI: null, sourceZoneURI: null,
}; };
if (options.server) { if (options.server) {
if (options.server.constructor__) { if (options.server instanceof Syslog) {
/** @private @type {Syslog} */ /** @private @type {Syslog} */
this.server = options.server; this.server = options.server;
} else { } else {
this.server = new Syslog(options.server); this.server = new Syslog(options.server as SyslogOptions);
} }
} }
} }
@ -3017,7 +3130,8 @@ class CEF {
.toLowerCase()) { .toLowerCase()) {
if (Extensions[cefExts[ext][0]].len > 0 if (Extensions[cefExts[ext][0]].len > 0
&& typeof cefExts[ext][1] === 'string' && 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:'; let errMsg = 'FORMAT ERROR:';
errMsg += ' CEF Extention Key'; errMsg += ' CEF Extention Key';
errMsg += ' ' + cefExts[ext][0]; errMsg += ' ' + cefExts[ext][0];
@ -3078,11 +3192,4 @@ class CEF {
} }
} }
module.exports = { export const RgbToAnsi = rgbToAnsi;
RgbToAnsi: rgbToAnsi,
RFC3164: RFC3164,
RFC5424: RFC5424,
LEEF: LEEF,
CEF: CEF,
Syslog: Syslog,
};

198
package-lock.json generated
View File

@ -1,5 +1,5 @@
{ {
"name": "syslog-pro", "name": "@zeit/syslog-pro",
"version": "0.2.0", "version": "0.2.0",
"lockfileVersion": 1, "lockfileVersion": 1,
"requires": true, "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": { "abab": {
"version": "2.0.0", "version": "2.0.0",
"resolved": "https://registry.npmjs.org/abab/-/abab-2.0.0.tgz", "resolved": "https://registry.npmjs.org/abab/-/abab-2.0.0.tgz",
@ -2162,7 +2296,8 @@
"ansi-regex": { "ansi-regex": {
"version": "2.1.1", "version": "2.1.1",
"bundled": true, "bundled": true,
"dev": true "dev": true,
"optional": true
}, },
"aproba": { "aproba": {
"version": "1.2.0", "version": "1.2.0",
@ -2183,12 +2318,14 @@
"balanced-match": { "balanced-match": {
"version": "1.0.0", "version": "1.0.0",
"bundled": true, "bundled": true,
"dev": true "dev": true,
"optional": true
}, },
"brace-expansion": { "brace-expansion": {
"version": "1.1.11", "version": "1.1.11",
"bundled": true, "bundled": true,
"dev": true, "dev": true,
"optional": true,
"requires": { "requires": {
"balanced-match": "^1.0.0", "balanced-match": "^1.0.0",
"concat-map": "0.0.1" "concat-map": "0.0.1"
@ -2203,17 +2340,20 @@
"code-point-at": { "code-point-at": {
"version": "1.1.0", "version": "1.1.0",
"bundled": true, "bundled": true,
"dev": true "dev": true,
"optional": true
}, },
"concat-map": { "concat-map": {
"version": "0.0.1", "version": "0.0.1",
"bundled": true, "bundled": true,
"dev": true "dev": true,
"optional": true
}, },
"console-control-strings": { "console-control-strings": {
"version": "1.1.0", "version": "1.1.0",
"bundled": true, "bundled": true,
"dev": true "dev": true,
"optional": true
}, },
"core-util-is": { "core-util-is": {
"version": "1.0.2", "version": "1.0.2",
@ -2330,7 +2470,8 @@
"inherits": { "inherits": {
"version": "2.0.3", "version": "2.0.3",
"bundled": true, "bundled": true,
"dev": true "dev": true,
"optional": true
}, },
"ini": { "ini": {
"version": "1.3.5", "version": "1.3.5",
@ -2342,6 +2483,7 @@
"version": "1.0.0", "version": "1.0.0",
"bundled": true, "bundled": true,
"dev": true, "dev": true,
"optional": true,
"requires": { "requires": {
"number-is-nan": "^1.0.0" "number-is-nan": "^1.0.0"
} }
@ -2356,6 +2498,7 @@
"version": "3.0.4", "version": "3.0.4",
"bundled": true, "bundled": true,
"dev": true, "dev": true,
"optional": true,
"requires": { "requires": {
"brace-expansion": "^1.1.7" "brace-expansion": "^1.1.7"
} }
@ -2363,12 +2506,14 @@
"minimist": { "minimist": {
"version": "0.0.8", "version": "0.0.8",
"bundled": true, "bundled": true,
"dev": true "dev": true,
"optional": true
}, },
"minipass": { "minipass": {
"version": "2.2.4", "version": "2.2.4",
"bundled": true, "bundled": true,
"dev": true, "dev": true,
"optional": true,
"requires": { "requires": {
"safe-buffer": "^5.1.1", "safe-buffer": "^5.1.1",
"yallist": "^3.0.0" "yallist": "^3.0.0"
@ -2387,6 +2532,7 @@
"version": "0.5.1", "version": "0.5.1",
"bundled": true, "bundled": true,
"dev": true, "dev": true,
"optional": true,
"requires": { "requires": {
"minimist": "0.0.8" "minimist": "0.0.8"
} }
@ -2467,7 +2613,8 @@
"number-is-nan": { "number-is-nan": {
"version": "1.0.1", "version": "1.0.1",
"bundled": true, "bundled": true,
"dev": true "dev": true,
"optional": true
}, },
"object-assign": { "object-assign": {
"version": "4.1.1", "version": "4.1.1",
@ -2479,6 +2626,7 @@
"version": "1.4.0", "version": "1.4.0",
"bundled": true, "bundled": true,
"dev": true, "dev": true,
"optional": true,
"requires": { "requires": {
"wrappy": "1" "wrappy": "1"
} }
@ -2564,7 +2712,8 @@
"safe-buffer": { "safe-buffer": {
"version": "5.1.1", "version": "5.1.1",
"bundled": true, "bundled": true,
"dev": true "dev": true,
"optional": true
}, },
"safer-buffer": { "safer-buffer": {
"version": "2.1.2", "version": "2.1.2",
@ -2600,6 +2749,7 @@
"version": "1.0.2", "version": "1.0.2",
"bundled": true, "bundled": true,
"dev": true, "dev": true,
"optional": true,
"requires": { "requires": {
"code-point-at": "^1.0.0", "code-point-at": "^1.0.0",
"is-fullwidth-code-point": "^1.0.0", "is-fullwidth-code-point": "^1.0.0",
@ -2619,6 +2769,7 @@
"version": "3.0.1", "version": "3.0.1",
"bundled": true, "bundled": true,
"dev": true, "dev": true,
"optional": true,
"requires": { "requires": {
"ansi-regex": "^2.0.0" "ansi-regex": "^2.0.0"
} }
@ -2662,12 +2813,14 @@
"wrappy": { "wrappy": {
"version": "1.0.2", "version": "1.0.2",
"bundled": true, "bundled": true,
"dev": true "dev": true,
"optional": true
}, },
"yallist": { "yallist": {
"version": "3.0.2", "version": "3.0.2",
"bundled": true, "bundled": true,
"dev": true "dev": true,
"optional": true
} }
} }
}, },
@ -4186,6 +4339,12 @@
"integrity": "sha1-7dFMgk4sycHgsKG0K7UhBRakJDg=", "integrity": "sha1-7dFMgk4sycHgsKG0K7UhBRakJDg=",
"dev": true "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": { "log-driver": {
"version": "1.2.7", "version": "1.2.7",
"resolved": "https://registry.npmjs.org/log-driver/-/log-driver-1.2.7.tgz", "resolved": "https://registry.npmjs.org/log-driver/-/log-driver-1.2.7.tgz",
@ -6296,6 +6455,15 @@
"integrity": "sha512-4krF8scpejhaOgqzBEcGM7yDIEfi0/8+8zDRZhNZZ2kjmHJ4hv3zCbQWxoJGz1iw5U0Jl0nma13xzHXcncMavQ==", "integrity": "sha512-4krF8scpejhaOgqzBEcGM7yDIEfi0/8+8zDRZhNZZ2kjmHJ4hv3zCbQWxoJGz1iw5U0Jl0nma13xzHXcncMavQ==",
"dev": true "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": { "tunnel-agent": {
"version": "0.6.0", "version": "0.6.0",
"resolved": "https://registry.npmjs.org/tunnel-agent/-/tunnel-agent-0.6.0.tgz", "resolved": "https://registry.npmjs.org/tunnel-agent/-/tunnel-agent-0.6.0.tgz",
@ -6321,6 +6489,12 @@
"prelude-ls": "~1.1.2" "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": { "typical": {
"version": "2.6.1", "version": "2.6.1",
"resolved": "https://registry.npmjs.org/typical/-/typical-2.6.1.tgz", "resolved": "https://registry.npmjs.org/typical/-/typical-2.6.1.tgz",

View File

@ -42,14 +42,19 @@
"license": "MIT", "license": "MIT",
"repository": { "repository": {
"type": "git", "type": "git",
"url": "https://github.com/cyamato/SyslogPro.git" "url": "https://github.com/zeit/SyslogPro.git"
}, },
"directories": { "directories": {
"doc": "./docs", "doc": "./docs",
"example": "./example", "example": "./example",
"test": "./test" "test": "./test"
}, },
"files": [
"index.d.ts",
"index.js"
],
"main": "index.js", "main": "index.js",
"types": "index.d.ts",
"engines": { "engines": {
"node": ">=10.0.0" "node": ">=10.0.0"
}, },
@ -57,6 +62,9 @@
"moment": "^2.22.2" "moment": "^2.22.2"
}, },
"devDependencies": { "devDependencies": {
"@types/node": "12.7.11",
"@typescript-eslint/eslint-plugin": "2.3.3",
"@typescript-eslint/parser": "2.3.3",
"ajv": "^6.5.4", "ajv": "^6.5.4",
"coveralls": "^3.0.2", "coveralls": "^3.0.2",
"docco": "^0.8.0", "docco": "^0.8.0",
@ -65,15 +73,18 @@
"eslint-config-strongloop": "^2.1.0", "eslint-config-strongloop": "^2.1.0",
"jest": "^23.5.0", "jest": "^23.5.0",
"jsdoc": "^3.5.5", "jsdoc": "^3.5.5",
"jsdoc-to-markdown": "^4.0.1" "jsdoc-to-markdown": "^4.0.1",
"typescript": "3.6.3"
}, },
"scripts": { "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", "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", "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", "jsdoc": "jsdoc *.js -c ./jsdoc.json",
"readme": "jsdoc2md --template ./jsdoc2md/api.hbs --files *.js > ./docs/api.md", "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": { "jest": {
"collectCoverage": true, "collectCoverage": true,

View File

@ -898,25 +898,25 @@ describe('Base Syslog Class tests', () => {
let syslog = new SyslogPro.Syslog({ let syslog = new SyslogPro.Syslog({
format: 'cef' 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', () => { test('Syslog constructor with format leef but no object', () => {
let syslog = new SyslogPro.Syslog({ let syslog = new SyslogPro.Syslog({
format: 'leef' 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', () => { test('Syslog constructor with format rfc5424 but no object', () => {
let syslog = new SyslogPro.Syslog({ let syslog = new SyslogPro.Syslog({
format: 'rfc5424' 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', () => { test('Syslog constructor with format rfc3164 but no object', () => {
let syslog = new SyslogPro.Syslog({ let syslog = new SyslogPro.Syslog({
format: 'rfc3164' format: 'rfc3164'
}); });
expect(syslog.rfc3164.constructor__).toBe(true); expect(syslog.rfc3164 instanceof SyslogPro.RFC3164).toBe(true);
}); });
test('Syslog constructor with format objects', () => { test('Syslog constructor with format objects', () => {
let rfc3164 = new SyslogPro.RFC3164(); let rfc3164 = new SyslogPro.RFC3164();
@ -929,11 +929,10 @@ describe('Base Syslog Class tests', () => {
leef: leef, leef: leef,
cef: cef, cef: cef,
}); });
expect.assertions(4); expect(syslog.rfc3164 instanceof SyslogPro.RFC3164).toBe(true);
expect(syslog.rfc3164.constructor__).toBe(true); expect(syslog.rfc5424 instanceof SyslogPro.RFC5424).toBe(true);
expect(syslog.rfc5424.constructor__).toBe(true); expect(syslog.leef instanceof SyslogPro.LEEF).toBe(true);
expect(syslog.leef.constructor__).toBe(true); expect(syslog.cef instanceof SyslogPro.CEF).toBe(true);
expect(syslog.cef.constructor__).toBe(true);
}); });
test('Syslog constructor with format objects configs', () => { test('Syslog constructor with format objects configs', () => {
let rfc3164 = {}; let rfc3164 = {};
@ -947,10 +946,10 @@ describe('Base Syslog Class tests', () => {
cef: cef, cef: cef,
}); });
expect.assertions(4); expect.assertions(4);
expect(syslog.rfc3164.constructor__).toBe(true); expect(syslog.rfc3164 instanceof SyslogPro.RFC3164).toBe(true);
expect(syslog.rfc5424.constructor__).toBe(true); expect(syslog.rfc5424 instanceof SyslogPro.RFC5424).toBe(true);
expect(syslog.leef.constructor__).toBe(true); expect(syslog.leef instanceof SyslogPro.LEEF).toBe(true);
expect(syslog.cef.constructor__).toBe(true); expect(syslog.cef instanceof SyslogPro.CEF).toBe(true);
}); });
test('Syslog Send with Protocol selection Error', async () => { test('Syslog Send with Protocol selection Error', async () => {
let syslog = new SyslogPro.Syslog({ let syslog = new SyslogPro.Syslog({

10
tsconfig.json Normal file
View File

@ -0,0 +1,10 @@
{
"compilerOptions": {
"target": "es2018",
"module": "commonjs",
"declaration": true,
"esModuleInterop": true,
"strict": false,
"noImplicitAny": false
}
}