Socket
Socket
Sign inDemoInstall

@segment/analytics.js-core

Package Overview
Dependencies
Maintainers
149
Versions
69
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@segment/analytics.js-core - npm Package Compare versions

Comparing version 3.13.2 to 3.13.3

4

HISTORY.md

@@ -0,1 +1,5 @@

# 3.13.3 / 2020-05-26
- feat: add destination middleware
# 3.13.2 / 2020-05-21

@@ -2,0 +6,0 @@

@@ -17,2 +17,4 @@ 'use strict';

.IntegrationMiddlewareChain;
var DestinationMiddlewareChain = require('./middleware')
.DestinationMiddlewareChain;
var Page = require('segmentio-facade').Page;

@@ -54,2 +56,3 @@ var Track = require('segmentio-facade').Track;

this._integrationMiddlewares = new IntegrationMiddlewareChain();
this._destinationMiddlewares = {};
this._integrations = {};

@@ -116,2 +119,3 @@ this._readied = false;

* Define a new `IntegrationMiddleware`
* DEPRECATED
*

@@ -128,2 +132,28 @@ * @param {Function} Middleware

/**
* Define a new `DestinationMiddleware`
* Destination Middleware is chained after integration middleware
*
* @param {String} integrationName
* @param {Array} Middlewares
* @return {Analytics}
*/
Analytics.prototype.addDestinationMiddleware = function(
integrationName,
middlewares
) {
var self = this;
middlewares.forEach(function(middleware) {
if (!self._destinationMiddlewares[integrationName]) {
self._destinationMiddlewares[
integrationName
] = new DestinationMiddlewareChain();
}
self._destinationMiddlewares[integrationName].add(middleware);
});
return self;
};
/**
* Initialize with the given integration `settings` and `options`.

@@ -798,8 +828,39 @@ *

metrics.increment('analytics_js.integration.invoke', {
method: method,
integration_name: integration.name
});
// apply destination middlewares
// Apply any integration middlewares that exist, then invoke the integration with the result.
if (self._destinationMiddlewares[integration.name]) {
self._destinationMiddlewares[integration.name].applyMiddlewares(
facadeCopy,
integration.name,
function(result) {
// A nullified payload should not be sent to an integration.
if (result === null) {
self.log(
'Payload to destination "%s" was null and dropped by a middleware.',
name
);
return;
}
integration.invoke.call(integration, method, result);
// Check if the payload is still a Facade. If not, convert it to one.
if (!(result instanceof Facade)) {
result = new Facade(result);
}
metrics.increment('analytics_js.integration.invoke', {
method: method,
integration_name: integration.name
});
integration.invoke.call(integration, method, result);
}
);
} else {
metrics.increment('analytics_js.integration.invoke', {
method: method,
integration_name: integration.name
});
integration.invoke.call(integration, method, result);
}
}

@@ -806,0 +867,0 @@ );

@@ -37,2 +37,16 @@ 'use strict';

module.exports.DestinationMiddlewareChain = function DestinationMiddlewareChain() {
var apply = middlewareChain(this);
this.applyMiddlewares = function(facade, integration, callback) {
return apply(
function(mw, payload, next) {
mw({ payload: payload, integration: integration, next: next });
},
facade,
callback
);
};
};
// Chain is essentially a linked list of middlewares to run in order.

@@ -39,0 +53,0 @@ function middlewareChain(dest) {

2

package.json
{
"name": "@segment/analytics.js-core",
"author": "Segment <friends@segment.com>",
"version": "3.13.2",
"version": "3.13.3",
"description": "The hassle-free way to integrate analytics into any web application.",

@@ -6,0 +6,0 @@ "keywords": [

Sorry, the diff of this file is too big to display

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc