Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

snowplow-tracker-core

Package Overview
Dependencies
Maintainers
1
Versions
35
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

snowplow-tracker-core - npm Package Compare versions

Comparing version 0.6.1 to 0.7.0-alpha.1

.tscache/default/hashes/contexts.ts-077b5fab88d89b67b246a9febf469e8f

35

lib/base64.js

@@ -26,2 +26,37 @@ "use strict";

exports.base64encode = base64encode;
function base64decode(encodedData) {
var decodeUTF8string = function (str) {
return decodeURIComponent(str.split('').map(function (c) {
return '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2);
}).join(''));
};
var b64 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
var o1, o2, o3, h1, h2, h3, h4, bits, i = 0, ac = 0, dec = '', tmpArr = [];
if (!encodedData) {
return encodedData;
}
encodedData += '';
do {
h1 = b64.indexOf(encodedData.charAt(i++));
h2 = b64.indexOf(encodedData.charAt(i++));
h3 = b64.indexOf(encodedData.charAt(i++));
h4 = b64.indexOf(encodedData.charAt(i++));
bits = h1 << 18 | h2 << 12 | h3 << 6 | h4;
o1 = bits >> 16 & 0xff;
o2 = bits >> 8 & 0xff;
o3 = bits & 0xff;
if (h3 === 64) {
tmpArr[ac++] = String.fromCharCode(o1);
}
else if (h4 === 64) {
tmpArr[ac++] = String.fromCharCode(o1, o2);
}
else {
tmpArr[ac++] = String.fromCharCode(o1, o2, o3);
}
} while (i < encodedData.length);
dec = tmpArr.join('');
return decodeUTF8string(dec.replace(/\0+$/, ''));
}
exports.base64decode = base64decode;
//# sourceMappingURL=base64.js.map

@@ -86,1 +86,69 @@ /*

export function base64decode(encodedData:string): string {
// discuss at: http://locutus.io/php/base64_decode/
// original by: Tyler Akins (http://rumkin.com)
// improved by: Thunder.m
// improved by: Kevin van Zonneveld (http://kvz.io)
// improved by: Kevin van Zonneveld (http://kvz.io)
// input by: Aman Gupta
// input by: Brett Zamir (http://brett-zamir.me)
// bugfixed by: Onno Marsman (https://twitter.com/onnomarsman)
// bugfixed by: Pellentesque Malesuada
// bugfixed by: Kevin van Zonneveld (http://kvz.io)
// improved by: Indigo744
// example 1: base64_decode('S2V2aW4gdmFuIFpvbm5ldmVsZA==')
// returns 1: 'Kevin van Zonneveld'
// example 2: base64_decode('YQ==')
// returns 2: 'a'
// example 3: base64_decode('4pyTIMOgIGxhIG1vZGU=')
// returns 3: '✓ à la mode'
// decodeUTF8string()
// Internal function to decode properly UTF8 string
// Adapted from Solution #1 at https://developer.mozilla.org/en-US/docs/Web/API/WindowBase64/Base64_encoding_and_decoding
var decodeUTF8string = function (str) {
// Going backwards: from bytestream, to percent-encoding, to original string.
return decodeURIComponent(str.split('').map(function (c) {
return '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2)
}).join(''))
};
var b64 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
var o1, o2, o3, h1, h2, h3, h4, bits, i = 0,
ac = 0,
dec = '',
tmpArr: Array<string> = [];
if (!encodedData) {
return encodedData;
}
encodedData += '';
do {
// unpack four hexets into three octets using index points in b64
h1 = b64.indexOf(encodedData.charAt(i++));
h2 = b64.indexOf(encodedData.charAt(i++));
h3 = b64.indexOf(encodedData.charAt(i++));
h4 = b64.indexOf(encodedData.charAt(i++));
bits = h1 << 18 | h2 << 12 | h3 << 6 | h4;
o1 = bits >> 16 & 0xff;
o2 = bits >> 8 & 0xff;
o3 = bits & 0xff;
if (h3 === 64) {
tmpArr[ac++] = String.fromCharCode(o1);
} else if (h4 === 64) {
tmpArr[ac++] = String.fromCharCode(o1, o2);
} else {
tmpArr[ac++] = String.fromCharCode(o1, o2, o3);
}
} while (i < encodedData.length);
dec = tmpArr.join('');
return decodeUTF8string(dec.replace(/\0+$/, ''));
}

26

lib/core.js

@@ -5,2 +5,3 @@ "use strict";

var payload = require("./payload");
var contexts_1 = require("./contexts");
function getTimestamp(tstamp) {

@@ -25,2 +26,6 @@ if (tstamp == null) {

var payloadPairs = {};
var contextModule = contexts_1.contextModule();
function getAllContexts(event) {
return contextModule.getApplicableContexts(event);
}
function addPayloadPair(key, value) {

@@ -47,2 +52,11 @@ payloadPairs[key] = value;

}
function attachGlobalContexts(sb, contexts) {
var globalContexts = getAllContexts(sb);
if (contexts && contexts.length) {
return contexts.concat(globalContexts);
}
else {
return globalContexts;
}
}
function track(sb, context, tstamp) {

@@ -53,3 +67,4 @@ sb.addDict(payloadPairs);

sb.add(timestamp.type, timestamp.value.toString());
var wrappedContexts = completeContexts(context);
var allContexts = attachGlobalContexts(sb, context);
var wrappedContexts = completeContexts(allContexts);
if (wrappedContexts !== undefined) {

@@ -355,2 +370,11 @@ sb.addJson('cx', 'co', wrappedContexts);

}, context ? context.concat([documentJson]) : [documentJson], tstamp);
},
addGlobalContexts: function (contexts) {
contextModule.addGlobalContexts(contexts);
},
clearGlobalContexts: function () {
contextModule.clearAllContexts();
},
removeGlobalContexts: function (contexts) {
contextModule.removeGlobalContexts(contexts);
}

@@ -357,0 +381,0 @@ };

@@ -20,4 +20,6 @@ /*

import {PayloadData} from "./payload";
import {
contextModule as contextConstructor
} from "./contexts";
/**

@@ -32,3 +34,2 @@ * Interface common for any Self-Describing JSON such as custom context or

/**

@@ -82,3 +83,14 @@ * Algebraic datatype representing possible timestamp type choice

let contextModule = contextConstructor();
/**
* Gets all global contexts to be added to events
*
* @param event
*/
function getAllContexts(event: PayloadData) : Array<SelfDescribingJson> {
return contextModule.getApplicableContexts(event);
}
/**
* Set a persistent key-value pair to be added to every payload

@@ -127,2 +139,17 @@ *

/**
* Adds all global contexts to a contexts array
*
* @param sb PayloadData
* @param contexts Array<SelfDescribingJson>
*/
function attachGlobalContexts(sb: PayloadData, contexts?: Array<SelfDescribingJson>): Array<SelfDescribingJson> | undefined{
var globalContexts = getAllContexts(sb);
if (contexts && contexts.length) {
return contexts.concat(globalContexts);
} else {
return globalContexts;
}
}
/**
* Gets called by every trackXXX method

@@ -140,5 +167,6 @@ * Adds context and payloadPairs name-value pairs to the payload

sb.add('eid', uuid.v4());
var timestamp = getTimestamp(tstamp);
var timestamp = getTimestamp(tstamp);
sb.add(timestamp.type, timestamp.value.toString());
var wrappedContexts = completeContexts(context);
var allContexts = attachGlobalContexts(sb, context);
var wrappedContexts = completeContexts(allContexts);
if (wrappedContexts !== undefined) {

@@ -320,3 +348,3 @@ sb.addJson('cx', 'co', wrappedContexts);

* @param pageUrl Current page URL
* @param pageTitle The user-defined page title to attach to this page view
* @param pageTitle The user-defined page title to attach to this page view
* @param referrer URL users came from

@@ -965,4 +993,16 @@ * @param context Custom contexts relating to the event

}, context ? context.concat([documentJson]) : [documentJson], tstamp);
},
addGlobalContexts: function(contexts: Array<Object>) {
contextModule.addGlobalContexts(contexts);
},
clearGlobalContexts: function() {
contextModule.clearAllContexts();
},
removeGlobalContexts: function(contexts: Array<Object>) {
contextModule.removeGlobalContexts(contexts);
}
};
}

@@ -11,2 +11,19 @@ "use strict";

}
function base64urldecode(data) {
if (!data) {
return data;
}
var padding = 4 - data.length % 4;
switch (padding) {
case 2:
data += "==";
break;
case 3:
data += "=";
break;
}
var b64Data = data.replace(/-/g, '+').replace(/_/g, '/');
return base64.base64decode(b64Data);
}
exports.base64urldecode = base64urldecode;
function isNonEmptyJson(property) {

@@ -13,0 +30,0 @@ if (!isJson(property)) {

@@ -42,2 +42,21 @@ /*

export function base64urldecode(data: string): string {
if (!data) {
return data;
}
var padding = 4 - data.length % 4;
switch (padding) {
case 2:
data += "==";
break;
case 3:
data += "=";
break;
}
var b64Data = data.replace(/-/g, '+').replace(/_/g, '/');
return base64.base64decode(b64Data);
}
/**

@@ -44,0 +63,0 @@ * Is property a non-empty JSON?

declare module 'snowplow-tracker/lib/base64' {
export function base64encode(data: string): string;
export function base64decode(encodedData: string): string;

@@ -12,2 +13,3 @@ }

}
export function base64urldecode(data: string): string;
export function isNonEmptyJson(property: any): boolean;

@@ -18,2 +20,39 @@ export function isJson(property: Object): boolean;

}
declare module 'snowplow-tracker/lib/contexts' {
import { PayloadData } from 'snowplow-tracker/lib/payload';
import { SelfDescribingJson } from 'snowplow-tracker/lib/core';
export type ContextGenerator = (payload: SelfDescribingJson, eventType: string, schema: string) => SelfDescribingJson;
export type ContextPrimitive = SelfDescribingJson | ContextGenerator;
export type ContextFilter = (payload: SelfDescribingJson, eventType: string, schema: string) => boolean;
export type FilterContextProvider = [ContextFilter, ContextPrimitive];
export interface RuleSet {
accept?: string[] | string;
reject?: string[] | string;
}
export type PathContextProvider = [RuleSet, ContextPrimitive];
export type ConditionalContextProvider = FilterContextProvider | PathContextProvider;
export function getSchemaParts(input: string): Array<string> | undefined;
export function isValidMatcher(input: any): boolean;
export function isStringArray(input: any): boolean;
export function isValidRuleSetArg(input: any): boolean;
export function isSelfDescribingJson(input: any): boolean;
export function isEventJson(input: any): boolean;
export function isObject(input: any): boolean;
export function isRuleSet(input: any): boolean;
export function isContextGenerator(input: any): boolean;
export function isContextFilter(input: any): boolean;
export function isContextPrimitive(input: any): boolean;
export function isFilterContextProvider(input: any): boolean;
export function isPathContextProvider(input: any): boolean;
export function isConditionalContextProvider(input: any): boolean;
export function matchSchemaAgainstRule(rule: string, schema: string): boolean;
export function matchSchemaAgainstRuleSet(ruleSet: RuleSet, schema: string): boolean;
export function contextModule(): {
addGlobalContexts: (contexts: any[]) => void;
clearAllContexts: () => void;
removeGlobalContexts: (contexts: any[]) => void;
getApplicableContexts: (event: PayloadData) => SelfDescribingJson[];
};
}
declare module 'snowplow-tracker/lib/core' {

@@ -70,2 +109,5 @@ import * as payload from 'snowplow-tracker/lib/payload';

trackConsentGranted: (id: string, version: string, name?: string | undefined, description?: string | undefined, expiry?: string | undefined, context?: SelfDescribingJson[] | undefined, tstamp?: number | TrueTimestamp | DeviceTimestamp | undefined) => payload.PayloadData;
addGlobalContexts: (contexts: Object[]) => void;
clearGlobalContexts: () => void;
removeGlobalContexts: (contexts: Object[]) => void;
};

@@ -72,0 +114,0 @@

15

package.json
{
"name": "snowplow-tracker-core",
"version": "0.6.1",
"version": "0.7.0-alpha.1",
"devDependencies": {
"@types/es6-shim": "0.31.34",
"@types/node": "^9.6.7",
"@types/uuid": "^2.0.29",
"dts-generator": "^2.0.0",
"grunt": "0.4.5",
"grunt-ts": "5.5.1",
"intern": "3.3.2",
"dts-generator": "^2.0.0",
"grunt-ts": "5.5.1",
"typescript": "2.2.2",
"@types/node": "^9.6.7",
"@types/es6-shim": "0.31.34",
"@types/uuid": "^2.0.29"
"lodash": "^4.17.11",
"typescript": "2.2.2"
},

@@ -14,0 +15,0 @@ "dependencies": {

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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