snowplow-tracker-core
Advanced tools
Comparing version 0.7.0-alpha.2 to 0.7.0-alpha.3
@@ -12,5 +12,7 @@ "use strict"; | ||
var payload_1 = require("./payload"); | ||
var base64url_1 = require("base64url"); | ||
var isEqual = require("lodash/isEqual"); | ||
var has = require("lodash/has"); | ||
var get = require("lodash/get"); | ||
var isPlainObject = require("lodash/isPlainObject"); | ||
function getSchemaParts(input) { | ||
@@ -68,12 +70,8 @@ var re = new RegExp('^iglu:([a-zA-Z0-9-_]+|\.)\/([a-zA-Z0-9-_]+|\.)\/([a-zA-Z0-9-_]+|\.)\/([0-9]+-[0-9]+-[0-9]|\.)$'); | ||
exports.isEventJson = isEventJson; | ||
function isObject(input) { | ||
return input && typeof input === 'object' && input.constructor === Object; | ||
} | ||
exports.isObject = isObject; | ||
function isRuleSet(input) { | ||
var methodCount = 0; | ||
if (isObject(input)) { | ||
var ruleCount = 0; | ||
if (isPlainObject(input)) { | ||
if (has(input, 'accept')) { | ||
if (isValidRuleSetArg(input['accept'])) { | ||
methodCount += 1; | ||
ruleCount += 1; | ||
} | ||
@@ -86,3 +84,3 @@ else { | ||
if (isValidRuleSetArg(input['reject'])) { | ||
methodCount += 1; | ||
ruleCount += 1; | ||
} | ||
@@ -93,3 +91,3 @@ else { | ||
} | ||
return methodCount > 0; | ||
return ruleCount > 0 && ruleCount <= 2; | ||
} | ||
@@ -202,3 +200,3 @@ return false; | ||
if (has(decodedEvent, 'ue_px')) { | ||
decodedEvent['ue_px'] = JSON.parse(payload_1.base64urldecode(get(decodedEvent, ['ue_px']))); | ||
decodedEvent['ue_px'] = JSON.parse(base64url_1.base64url.base64urldecode(get(decodedEvent, ['ue_px']))); | ||
} | ||
@@ -205,0 +203,0 @@ return decodedEvent; |
@@ -1,6 +0,8 @@ | ||
import {PayloadData, base64urldecode, isNonEmptyJson} from "./payload"; | ||
import {SelfDescribingJson} from "./core"; | ||
import { PayloadData, isNonEmptyJson } from "./payload"; | ||
import { SelfDescribingJson } from "./core"; | ||
import { base64url } from "base64url"; | ||
import isEqual = require('lodash/isEqual'); | ||
import has = require('lodash/has'); | ||
import get = require('lodash/get'); | ||
import isPlainObject = require('lodash/isPlainObject'); | ||
@@ -72,12 +74,8 @@ /** | ||
export function isObject(input: any) : boolean { | ||
return input && typeof input === 'object' && input.constructor === Object; | ||
} | ||
export function isRuleSet(input: any) : boolean { | ||
let methodCount = 0; | ||
if (isObject(input)) { | ||
let ruleCount = 0; | ||
if (isPlainObject(input)) { | ||
if (has(input, 'accept')) { | ||
if (isValidRuleSetArg(input['accept'])) { | ||
methodCount += 1; | ||
ruleCount += 1; | ||
} else { | ||
@@ -89,3 +87,3 @@ return false; | ||
if (isValidRuleSetArg(input['reject'])) { | ||
methodCount += 1; | ||
ruleCount += 1; | ||
} else { | ||
@@ -95,3 +93,5 @@ return false; | ||
} | ||
return methodCount > 0; // if 'reject' or 'accept' exists, we have a valid ruleset | ||
// if either 'reject' or 'accept' or both exists, | ||
// we have a valid ruleset | ||
return ruleCount > 0 && ruleCount <= 2; | ||
} | ||
@@ -187,7 +187,7 @@ return false; | ||
// Warning: below is a design decision, good to know for understanding this functionality. | ||
// Returns the "useful" schema, basically what would someone want to use to discern events. | ||
// Returns the "useful" schema, i.e. what would someone want to use to identify events. | ||
// The idea being that you can determine the event type from 'e', so getting the schema from | ||
// 'ue_px.schema'/'ue_pr.schema' would be redundant - it'll return the unstructured event schema. | ||
// Instead the schema nested inside the unstructured event is more useful! | ||
// This doesn't decode ue_px, it works because it's called by code that has already decoded it | ||
function getUsefulSchema(sb: SelfDescribingJson): string { | ||
@@ -207,3 +207,3 @@ if (typeof get(sb, 'ue_px.data.schema') === 'string') { | ||
if (has(decodedEvent, 'ue_px')) { | ||
decodedEvent['ue_px'] = JSON.parse(base64urldecode(get(decodedEvent, ['ue_px']))); | ||
decodedEvent['ue_px'] = JSON.parse(base64url.base64urldecode(get(decodedEvent, ['ue_px']))); | ||
} | ||
@@ -210,0 +210,0 @@ return decodedEvent; |
@@ -11,19 +11,2 @@ "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) { | ||
@@ -30,0 +13,0 @@ if (!isJson(property)) { |
@@ -42,21 +42,2 @@ /* | ||
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); | ||
} | ||
/** | ||
@@ -63,0 +44,0 @@ * Is property a non-empty JSON? |
@@ -13,3 +13,2 @@ declare module 'snowplow-tracker/lib/base64' { | ||
} | ||
export function base64urldecode(data: string): string; | ||
export function isNonEmptyJson(property: any): boolean; | ||
@@ -39,3 +38,2 @@ export function isJson(property: Object): boolean; | ||
export function isEventJson(input: any): boolean; | ||
export function isObject(input: any): boolean; | ||
export function isRuleSet(input: any): boolean; | ||
@@ -42,0 +40,0 @@ export function isContextGenerator(input: any): boolean; |
{ | ||
"name": "snowplow-tracker-core", | ||
"version": "0.7.0-alpha.2", | ||
"version": "0.7.0-alpha.3", | ||
"devDependencies": { | ||
"@types/es6-shim": "0.31.34", | ||
"@types/node": "^9.6.7", | ||
"@types/uuid": "^2.0.29", | ||
"dts-generator": "^2.0.0", | ||
@@ -12,6 +11,8 @@ "grunt": "0.4.5", | ||
"intern": "3.3.2", | ||
"lodash": "^4.17.11", | ||
"typescript": "2.2.2" | ||
}, | ||
"dependencies": { | ||
"@types/uuid": "^2.0.29", | ||
"base64url": "^3.0.0", | ||
"lodash": "^4.17.11", | ||
"uuid": "2.0.3" | ||
@@ -18,0 +19,0 @@ }, |
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
7
134723
4
2375
+ Added@types/uuid@^2.0.29
+ Addedbase64url@^3.0.0
+ Addedlodash@^4.17.11
+ Added@types/node@22.12.0(transitive)
+ Added@types/uuid@2.0.35(transitive)
+ Addedbase64url@3.0.1(transitive)
+ Addedlodash@4.17.21(transitive)
+ Addedundici-types@6.20.0(transitive)