splunk-events
Advanced tools
Comparing version 1.4.2 to 1.5.0
@@ -10,2 +10,6 @@ # Changelog | ||
## [1.5.0] - 2021-03-26 | ||
### Added | ||
- UMD and ESM build types. | ||
## [1.4.2] - 2021-03-09 | ||
@@ -12,0 +16,0 @@ ### Added |
@@ -1,8 +0,28 @@ | ||
"use strict"; | ||
var __assign = (this && this.__assign) || function () { | ||
__assign = Object.assign || function(t) { | ||
/*! | ||
* splunk-events v1.5.0 | ||
* Copyright (c) VTEX | ||
* Released under the MIT License. | ||
*/ | ||
'use strict'; | ||
/*! ***************************************************************************** | ||
Copyright (c) Microsoft Corporation. | ||
Permission to use, copy, modify, and/or distribute this software for any | ||
purpose with or without fee is hereby granted. | ||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH | ||
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY | ||
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, | ||
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM | ||
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR | ||
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR | ||
PERFORMANCE OF THIS SOFTWARE. | ||
***************************************************************************** */ | ||
var __assign = function() { | ||
__assign = Object.assign || function __assign(t) { | ||
for (var s, i = 1, n = arguments.length; i < n; i++) { | ||
s = arguments[i]; | ||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) | ||
t[p] = s[p]; | ||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p]; | ||
} | ||
@@ -13,5 +33,38 @@ return t; | ||
}; | ||
exports.__esModule = true; | ||
var debounce_1 = require("./debounce"); | ||
var request_1 = require("./request"); | ||
function debounce(func, wait) { | ||
if (wait === void 0) { wait = 100; } | ||
var timeout = null; | ||
var debounced = function () { | ||
if (timeout) { | ||
clearTimeout(timeout); | ||
timeout = null; | ||
} | ||
timeout = setTimeout(func, wait); | ||
}; | ||
debounced.clear = function () { | ||
if (!timeout) { | ||
return; | ||
} | ||
clearTimeout(timeout); | ||
timeout = null; | ||
}; | ||
return debounced; | ||
} | ||
function fetchRequest(context) { | ||
if ((typeof window !== 'undefined' && typeof window.fetch !== 'function') || | ||
(typeof global !== 'undefined' && | ||
typeof global.fetch !== 'function')) { | ||
console.log('Error, using fetchRequest without fetch object'); | ||
return Promise.resolve(null); | ||
} | ||
return fetch(context.url, __assign(__assign({}, context), { body: context.data })).then(function (response) { | ||
if (context.responseType === 'json') { | ||
return response.json(); | ||
} | ||
return response; | ||
}); | ||
} | ||
var SplunkEvents = /** @class */ (function () { | ||
@@ -92,3 +145,3 @@ function SplunkEvents() { | ||
headers: (_a = _this.headers) !== null && _a !== void 0 ? _a : {}, | ||
responseType: 'json' | ||
responseType: 'json', | ||
}) | ||
@@ -132,3 +185,4 @@ .then(function () { | ||
this.token = config.token; // required | ||
this.injectAdditionalInfo = (_c = (_b = config.injectAditionalInfo) !== null && _b !== void 0 ? _b : config.injectAdditionalInfo) !== null && _c !== void 0 ? _c : false; | ||
this.injectAdditionalInfo = | ||
(_c = (_b = config.injectAditionalInfo) !== null && _b !== void 0 ? _b : config.injectAdditionalInfo) !== null && _c !== void 0 ? _c : false; | ||
this.autoFlush = (_d = config.autoFlush) !== null && _d !== void 0 ? _d : true; | ||
@@ -141,4 +195,5 @@ this.autoRetryFlush = (_e = config.autoRetryFlush) !== null && _e !== void 0 ? _e : true; | ||
this.debounceTime = (_l = (_k = config.debounceTime) !== null && _k !== void 0 ? _k : this.debounceTime) !== null && _l !== void 0 ? _l : 2000; | ||
this.debouncedFlush = (_m = this.debouncedFlush) !== null && _m !== void 0 ? _m : debounce_1["default"](this.flush, this.debounceTime); | ||
this._requestImpl = (_p = (_o = config.request) !== null && _o !== void 0 ? _o : this._requestImpl) !== null && _p !== void 0 ? _p : request_1.fetchRequest; | ||
this.debouncedFlush = | ||
(_m = this.debouncedFlush) !== null && _m !== void 0 ? _m : debounce(this.flush, this.debounceTime); | ||
this._requestImpl = (_p = (_o = config.request) !== null && _o !== void 0 ? _o : this._requestImpl) !== null && _p !== void 0 ? _p : fetchRequest; | ||
this.injectTimestamp = (_q = config.injectTimestamp) !== null && _q !== void 0 ? _q : false; | ||
@@ -197,3 +252,3 @@ this.shouldParseEventData = (_r = config.shouldParseEventData) !== null && _r !== void 0 ? _r : true; | ||
return { | ||
additional_info: additionalInfo | ||
additional_info: additionalInfo, | ||
}; | ||
@@ -224,2 +279,4 @@ }; | ||
}()); | ||
exports["default"] = SplunkEvents; | ||
module.exports = SplunkEvents; | ||
//# sourceMappingURL=splunk-events.js.map |
{ | ||
"name": "splunk-events", | ||
"version": "1.4.2", | ||
"version": "1.5.0", | ||
"description": "Javascript lib to create Splunk Logs via HTTP", | ||
"main": "lib/splunk-events.js", | ||
"types": "lib/splunk-events.d.ts", | ||
"main": "lib/splunk-events.min.js", | ||
"cdn": "lib/splunk-events.umd.min.js", | ||
"module": "lib/splunk-events.esm.min.js", | ||
"browser": "src/splunk-events.ts", | ||
"types": "types/splunk-events.d.ts", | ||
"sideEffects": false, | ||
"scripts": { | ||
"test": "vtex-test-tools test", | ||
"build": "tsc -D --outDir lib ./src/splunk-events.ts", | ||
"build": "rimraf lib && rimraf types && rollup -c", | ||
"dev": "rollup -c --watch", | ||
"lint": "eslint --ext ts .", | ||
"prepublishOnly": "yarn test && yarn build" | ||
}, | ||
"files": [ | ||
"lib/", | ||
"types/", | ||
"src/" | ||
], | ||
"devDependencies": { | ||
@@ -20,2 +30,6 @@ "@vtex/prettier-config": "^0.1.4", | ||
"prettier": "^2.0.4", | ||
"rimraf": "^3.0.2", | ||
"rollup": "^2.42.4", | ||
"rollup-plugin-terser": "^7.0.2", | ||
"rollup-plugin-typescript2": "^0.30.0", | ||
"typescript": "^4.0.2" | ||
@@ -50,2 +64,5 @@ }, | ||
], | ||
"author": { | ||
"name": "VTEX" | ||
}, | ||
"license": "MIT", | ||
@@ -52,0 +69,0 @@ "repository": { |
147
README.md
@@ -5,14 +5,59 @@ # Splunk Events | ||
------- | ||
### Support | ||
## Table of Contents | ||
- [Support](#support) | ||
- [Installation](#installation) | ||
- [Installation from CDN](#installation-from-cdn) | ||
- [Examples](#examples) | ||
- [ES6 Example](#es6-example) | ||
- [CommonJS](#commonjs) | ||
- [API](#api) | ||
- [`config(params)`](#configparams) | ||
- [`log(event)`](#logeventlevel-type-workflowtype-workflowinstance-eventdata-account) | ||
- [`flush()`](#flush) | ||
- [Working on Node and old browsers](#working-on-node-and-old-browsers) | ||
- [Write your own fetcher](#write-your-own-fetcher) | ||
- [Using in VTEX IO](#using-in-vtex-io-node-app-example) | ||
- [Splunk Documentation](#splunk-documentation) | ||
- [Development](#development) | ||
- [Deploy](#deploy) | ||
## Support | ||
- Node (with axios as dependency) | ||
- Browser (IE8+, Firefox, Chrome, Safari and Opera) | ||
------- | ||
### Setup | ||
## Installation | ||
```npm install splunk-events``` or ```yarn add splunk-events``` | ||
This library is published in the NPM registry and can be installed using any compatible package manager. | ||
------- | ||
```bash | ||
npm install splunk-events --save | ||
# For yarn, use the command below. | ||
yarn add splunk-events | ||
``` | ||
### Installation from CDN | ||
This module has an UMD bundle available through JSDelivr and Unpkg CDNs. | ||
```html | ||
<!-- For UNPKG use the code below. --> | ||
<script src="https://unpkg.com/splunk-events"></script> | ||
<!-- For JSDelivr use the code below. --> | ||
<script src="https://cdn.jsdelivr.net/npm/splunk-events"></script> | ||
<script> | ||
// UMD module is exposed through the "SplunkEvents" global variable. | ||
console.log(window.SplunkEvents) | ||
</script> | ||
``` | ||
## Examples | ||
Here you can find some examples on how to start using this library. | ||
### ES6 Example | ||
@@ -38,4 +83,3 @@ | ||
------- | ||
### ES5 Example | ||
### CommonJS | ||
@@ -60,7 +104,6 @@ ```javascript | ||
------- | ||
### API | ||
## API | ||
### `config(params)` | ||
#### config(params) | ||
```javascript | ||
@@ -118,38 +161,37 @@ { | ||
#### logEvent(level, type, workflowType, workflowInstance, eventData, account) | ||
### `logEvent(level, type, workflowType, workflowInstance, eventData, account)` | ||
'level' is the criticality of the event ('Critical','Important','Debug'). | ||
`level` is the criticality of the event ('Critical','Important','Debug'). | ||
'type' is the type of the event ('Error','Warn','Info'). | ||
`type` is the type of the event ('Error','Warn','Info'). | ||
'workflowType' is an action or a flow's stage in the system. | ||
`workflowType` is an action or a flow's stage in the system. | ||
'workflowInstance' defines what id/element is being processed/executed/created in the workflowType. | ||
`workflowInstance` defines what id/element is being processed/executed/created in the workflowType. | ||
'eventData' is an object containing your custom data to send to Splunk. This object should be flat and properties with a 'null' or 'undefined' value will be **omitted**. | ||
`eventData` is an object containing your custom data to send to Splunk. This object should be flat and properties with a 'null' or 'undefined' value will be **omitted**. | ||
'account' is the `accountName` (e.g. 'dreamstore','gatewayqa','instoreqa'). | ||
`account` is the `accountName` (e.g. 'dreamstore','gatewayqa','instoreqa'). | ||
if 'injectAditionalInfo' is set to true, this function adds some default data to the event | ||
``` | ||
- User Agent | ||
- Browser Language | ||
- Screen Resolution | ||
- URI Host | ||
- URI Path | ||
- URI Protocol | ||
- URI Hash | ||
``` | ||
If `injectAditionalInfo` is set to true, this function adds some default data to the event | ||
#### flush() | ||
- User Agent (`navigator.userAgent`) | ||
- Browser Language (`navigator.browserLanguage` or `navigator.language`) | ||
- Screen Resolution (`window.screen.availWidth` and `window.screen.availHeight`) | ||
- URI Host (`window.location.hostname`) | ||
- URI Path (`window.location.pathname`) | ||
- URI Protocol (`window.location.protocol`) | ||
- URI Hash (`window.location.hash`) | ||
### `flush()` | ||
Immediately send all queued events to Splunk Server. | ||
This is not required when using the 'autoFlush' option. | ||
This is not required when using the `autoFlush` option. | ||
#### Working on Node and old browsers | ||
## Working on Node and old browsers | ||
By default this lib doesn't have any dependencies for the newer browsers (it tries to use Fetch API). | ||
But to make it work on old browsers and Node you must use axios (0.13+) as a dependency by installing it (```npm install --save axios```) and setting it on Splunk events config: | ||
But to make it work on old browsers and Node you must use axios (0.13+) as a dependency by installing it (`npm install --save axios`) and setting it on Splunk events config: | ||
@@ -170,3 +212,3 @@ ```javascript | ||
#### Write your own fetcher | ||
## Write your own fetcher | ||
@@ -201,5 +243,7 @@ Just like you can pass axios as a request config (see section above), you can write your own fetcher by just following the same signature that axios use (see axios API documentation: https://github.com/mzabriskie/axios#axios-api). | ||
``` | ||
------- | ||
### Using in VTEX IO (node app example) | ||
## Using in VTEX IO (node app example) | ||
Insert your splunk endpoint in your app policies (located at manifest.json) like so: | ||
```json | ||
@@ -218,6 +262,8 @@ { | ||
``` | ||
If your endpoint has a port, you don't need to add it here. The protocol neither. Just the host... | ||
If your endpoint has a port you don't need to add it here and neither the protocol, only the host. | ||
Then you have to create a new fetcher or tweak your if you already have one. | ||
This is to add headers so IO can properly proxy the request... | ||
This is to add headers so IO can properly proxy the request. | ||
```javascript | ||
@@ -240,5 +286,6 @@ function splunkCustomFetcher(context) { | ||
Finally you can configure your splunk cient like so: | ||
```javascript | ||
splunkEvents.config({ | ||
// add your endpoint with http protocol and no ports, let IO do the proxying, trust the headers... | ||
// add your endpoint with http protocol and no ports, let IO do the proxying, trust the headers. | ||
endpoint: `http://${SPLUNK_ENDPOINT}`, | ||
@@ -250,22 +297,26 @@ request: splunkCustomFetcher, | ||
------- | ||
### Splunk Documentation | ||
## Splunk Documentation | ||
http://dev.splunk.com/view/event-collector/SP-CAAAE6P | ||
### Development | ||
## Development | ||
After setting up the project with ```npm install``` or ```yarn```, you can run ```npm build``` and ```npm link``` to test it on another project (see examples on how to test it above). | ||
After setting up the project with `npm install` or `yarn`, you can run `npm build` and `npm link` to test it on another project (see examples on how to test it above). | ||
### Deploy | ||
To deploy this package to npm, install the releasy package with ```npm install -g releasy``` | ||
To deploy this package to npm, install the releasy package with `npm install -g releasy` | ||
Make sure you are logged with the correct user (use ```npm login``` command) | ||
Make sure you are logged with the correct user (use `npm login` command) | ||
Then choose between patch, minor and major version to release with the commands: | ||
* ```releasy patch --stable``` | ||
* ```releasy minor --stable``` | ||
* ```releasy major --stable``` | ||
* `releasy patch --stable` | ||
* `releasy minor --stable` | ||
* `releasy major --stable` | ||
After that, SplunkEvents.js will be generated with babel and uploaded to the npm registry with the new version. | ||
After that, several bundles will be generated with Rollup and uploaded to the npm registry with the new version. | ||
## License | ||
Released under [MIT License](./LICENSE). |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
195190
26
1585
314
11
7