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

@jitsu/pipeline-helpers

Package Overview
Dependencies
Maintainers
4
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@jitsu/pipeline-helpers - npm Package Compare versions

Comparing version 0.6.0 to 0.7.0

6

lib/index.d.ts

@@ -7,5 +7,2 @@ import { DefaultJitsuEvent } from "@jitsu/types/event";

export declare const getSegmentType: (jitsuType: string, customMapping: Record<string, SegmentEventType>, defaultSegmentType: SegmentEventType) => SegmentEventType;
export declare function removeProps(ev: Record<string, string>, props: string[]): {
[x: string]: string;
};
export declare const jitsuToSegment: JitsuToSegmentMapper;

@@ -15,5 +12,4 @@ export declare const segmentToTable: (event: SegmentEvent, jitsuEvent?: DefaultJitsuEvent | undefined) => SegmentTableObject & JitsuDestinationHints<SegmentTableObject>;

export declare function removeEmptyFields<T>(obj: T): void;
export declare function flatten(obj: any, { separator, skipArrays }?: {
export declare function flatten(obj: any, { separator }?: {
separator?: string | undefined;
skipArrays?: boolean | undefined;
}, path?: string[]): TableObject;

168

lib/index.es.js

@@ -0,3 +1,39 @@

/*! *****************************************************************************
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];
}
return t;
};
return __assign.apply(this, arguments);
};
function __spreadArray(to, from, pack) {
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
if (ar || !(i in from)) {
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
ar[i] = from[i];
}
}
return to.concat(ar || Array.prototype.slice.call(from));
}
var name = "@jitsu/pipeline-helpers";
var version = "0.5.1";
var version = "0.4.1-alpha.2+4a5222c";
var description = "Utility functions designed to outsource some processing logic from Server to JS";

@@ -33,3 +69,3 @@ var author = "Jitsu Dev Team <dev@jitsu.com>";

};
var gitHead = "dead29f98059ecf21a0576b0c64cdb7f71da46f7";
var gitHead = "4a5222ce49da3cb6be58648c78b1111b39764fe1";
var pkg = {

@@ -54,3 +90,3 @@ name: name,

const segmentEventsTypes = {
var segmentEventsTypes = {
alias: true,

@@ -61,5 +97,5 @@ group: true,

screen: true,
track: true,
track: true
};
const getSegmentType = (jitsuType, customMapping, defaultSegmentType) => {
var getSegmentType = function (jitsuType, customMapping, defaultSegmentType) {
if (jitsuType === "user_identity" || jitsuType === "identify") {

@@ -75,19 +111,21 @@ return "identify";

else {
const customType = customMapping[jitsuType];
return customType ?? defaultSegmentType;
var customType = customMapping[jitsuType];
return customType !== null && customType !== void 0 ? customType : defaultSegmentType;
}
};
function removeProps(ev, props) {
const copy = { ...ev };
props.forEach(p => delete copy[p]);
var copy = __assign({}, ev);
props.forEach(function (p) { return delete copy[p]; });
return copy;
}
const jitsuToSegment = (ev, { defaultSegmentType = "track", eventTypeMapping = {} } = {}) => {
var jitsuToSegment = function (ev, _a) {
var _b, _c, _d, _e, _f, _g, _h, _j;
var _k = _a === void 0 ? {} : _a, _l = _k.defaultSegmentType, defaultSegmentType = _l === void 0 ? "track" : _l, _m = _k.eventTypeMapping, eventTypeMapping = _m === void 0 ? {} : _m;
if (ev.src_payload && ev.src === "ajs") {
return ev.src_payload;
}
let segmentEvent = {
var segmentEvent = {
type: getSegmentType(ev.event_type, eventTypeMapping, defaultSegmentType),
_metadata: {},
anonymousId: ev.user?.anonymous_id,
anonymousId: (_b = ev.user) === null || _b === void 0 ? void 0 : _b.anonymous_id,
context: {

@@ -102,11 +140,11 @@ ip: ev.source_ip,

title: ev.page_title,
url: ev.url,
url: ev.url
},
campaign: {
name: ev.utm?.name,
term: ev.utm?.term,
source: ev.utm?.source,
medium: ev.utm?.medium,
content: ev.utm?.content,
},
name: (_c = ev.utm) === null || _c === void 0 ? void 0 : _c.name,
term: (_d = ev.utm) === null || _d === void 0 ? void 0 : _d.term,
source: (_e = ev.utm) === null || _e === void 0 ? void 0 : _e.source,
medium: (_f = ev.utm) === null || _f === void 0 ? void 0 : _f.medium,
content: (_g = ev.utm) === null || _g === void 0 ? void 0 : _g.content
}
},

@@ -134,20 +172,7 @@ event: ev.event_type,

"utm",
"parsed_ua",
"location",
"eventn_ctx",
"api_key",
"app",
"doc_encoding",
"doc_host",
"ids",
"local_tz_offset",
"screen_resolution",
"src",
"vp_size",
"src_payload",
]), { skipArrays: true }),
])),
sentAt: ev.utc_time ? new Date(ev.utc_time) : new Date(),
timestamp: ev.utc_time ? new Date(ev.utc_time) : new Date(),
traits: flatten(removeProps(ev.user || {}, ["anonymous_id", "id"])),
userId: ev.user?.id || ev.user?.email,
userId: ((_h = ev.user) === null || _h === void 0 ? void 0 : _h.id) || ((_j = ev.user) === null || _j === void 0 ? void 0 : _j.email)
};

@@ -171,3 +196,3 @@ removeEmptyFields(segmentEvent);

}
const segmentTables = {
var segmentTables = {
track: "tracks",

@@ -178,36 +203,8 @@ page: "pages",

alias: "aliases",
screen: "screens",
screen: "screens"
};
const segmentToTable = (event, jitsuEvent) => {
const payloadObj = jitsuEvent?.src_payload?.obj || {};
return {
JITSU_TABLE_NAME: segmentTables[event.type] || "tracks",
__sql_type_timestamp: "timestamp",
__sql_type_sent_at: "timestamp",
anonymous_id: safeToString(event.anonymousId) || jitsuEvent?.src_payload?.anonymousId,
context_campaign_source: event.context?.campaign?.source,
context_ip: event.context?.ip,
context_library_name: jitsuEvent?.context?.library?.version || "jitsu-bridge",
context_library_version: pkg.version ,
context_locale: event.context?.locale || payloadObj.context?.locale,
context_page_path: event.context?.page?.path,
context_page_referrer: event.context?.page?.referrer,
context_page_search: event.context?.page?.search,
context_page_title: event.context?.page?.title,
context_page_url: event.context?.page?.url,
context_user_agent: event.context?.userAgent,
context_utm_source: event.context?.campaign?.source,
email: safeToString(event.traits?.email),
id: event.messageId,
name: safeToString(event.traits?.name),
path: event.context?.page?.path,
referrer: event.context?.page?.referrer,
search: event.context?.page?.search,
sent_at: safeToString(event.sentAt),
timestamp: payloadObj.timestamp || safeToString(event.timestamp),
title: event.context?.page?.title,
url: event.context?.page?.url,
user_id: safeToString(event.userId) || jitsuEvent?.src_payload?.userId,
...(event.properties || {}),
};
var segmentToTable = function (event, jitsuEvent) {
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10;
var payloadObj = ((_a = jitsuEvent === null || jitsuEvent === void 0 ? void 0 : jitsuEvent.src_payload) === null || _a === void 0 ? void 0 : _a.obj) || {};
return __assign({ JITSU_TABLE_NAME: segmentTables[event.type] || "tracks", __sql_type_timestamp: "timestamp", __sql_type_sent_at: "timestamp", anonymous_id: safeToString(event.anonymousId) || ((_b = jitsuEvent === null || jitsuEvent === void 0 ? void 0 : jitsuEvent.src_payload) === null || _b === void 0 ? void 0 : _b.anonymousId), context_campaign_source: (_d = (_c = event.context) === null || _c === void 0 ? void 0 : _c.campaign) === null || _d === void 0 ? void 0 : _d.source, context_ip: (_e = event.context) === null || _e === void 0 ? void 0 : _e.ip, context_library_name: ((_g = (_f = jitsuEvent === null || jitsuEvent === void 0 ? void 0 : jitsuEvent.context) === null || _f === void 0 ? void 0 : _f.library) === null || _g === void 0 ? void 0 : _g.version) || "jitsu-bridge", context_library_version: pkg.version , context_locale: ((_h = event.context) === null || _h === void 0 ? void 0 : _h.locale) || ((_j = payloadObj.context) === null || _j === void 0 ? void 0 : _j.locale), context_page_path: (_l = (_k = event.context) === null || _k === void 0 ? void 0 : _k.page) === null || _l === void 0 ? void 0 : _l.path, context_page_referrer: (_o = (_m = event.context) === null || _m === void 0 ? void 0 : _m.page) === null || _o === void 0 ? void 0 : _o.referrer, context_page_search: (_q = (_p = event.context) === null || _p === void 0 ? void 0 : _p.page) === null || _q === void 0 ? void 0 : _q.search, context_page_title: (_s = (_r = event.context) === null || _r === void 0 ? void 0 : _r.page) === null || _s === void 0 ? void 0 : _s.title, context_page_url: (_u = (_t = event.context) === null || _t === void 0 ? void 0 : _t.page) === null || _u === void 0 ? void 0 : _u.url, context_user_agent: (_v = event.context) === null || _v === void 0 ? void 0 : _v.userAgent, context_utm_source: (_x = (_w = event.context) === null || _w === void 0 ? void 0 : _w.campaign) === null || _x === void 0 ? void 0 : _x.source, email: safeToString((_y = event.traits) === null || _y === void 0 ? void 0 : _y.email), id: event.messageId, name: safeToString((_z = event.traits) === null || _z === void 0 ? void 0 : _z.name), path: (_1 = (_0 = event.context) === null || _0 === void 0 ? void 0 : _0.page) === null || _1 === void 0 ? void 0 : _1.path, referrer: (_3 = (_2 = event.context) === null || _2 === void 0 ? void 0 : _2.page) === null || _3 === void 0 ? void 0 : _3.referrer, search: (_5 = (_4 = event.context) === null || _4 === void 0 ? void 0 : _4.page) === null || _5 === void 0 ? void 0 : _5.search, sent_at: safeToString(event.sentAt), timestamp: payloadObj.timestamp || safeToString(event.timestamp), title: (_7 = (_6 = event.context) === null || _6 === void 0 ? void 0 : _6.page) === null || _7 === void 0 ? void 0 : _7.title, url: (_9 = (_8 = event.context) === null || _8 === void 0 ? void 0 : _8.page) === null || _9 === void 0 ? void 0 : _9.url, user_id: safeToString(event.userId) || ((_10 = jitsuEvent === null || jitsuEvent === void 0 ? void 0 : jitsuEvent.src_payload) === null || _10 === void 0 ? void 0 : _10.userId) }, (event.properties || {}));
};

@@ -228,3 +225,4 @@ function canonicalSqlTypeHint(hint) {

function removeEmptyFields(obj) {
for (const [key, val] of Object.entries(obj)) {
for (var _i = 0, _a = Object.entries(obj); _i < _a.length; _i++) {
var _b = _a[_i], key = _b[0], val = _b[1];
if (val !== null && typeof val === "object" && !Array.isArray(val)) {

@@ -238,24 +236,24 @@ removeEmptyFields(val);

}
function flatten(obj, { separator = "_", skipArrays = false } = {}, path = []) {
function flatten(obj, _a, path) {
var _b = _a === void 0 ? {} : _a, _c = _b.separator, separator = _c === void 0 ? "_" : _c;
if (path === void 0) { path = []; }
if (typeof obj !== "object") {
throw new Error(`Can't flatten an object, expected object, but got" ${typeof obj}`);
throw new Error("Can't flatten an object, expected object, but got\" ".concat(typeof obj));
}
if (obj === null) {
throw new Error(`Can't flatten null value`);
throw new Error("Can't flatten null value");
}
if (Array.isArray(obj)) {
if (!skipArrays) {
throw new Error(`Can't flatten array`);
}
else {
return {};
}
throw new Error("Can't flatten array");
}
const res = {};
for (const [key, value] of Object.entries(obj)) {
var res = {};
var _loop_1 = function (key, value) {
if (typeof value === "object") {
Object.entries(flatten(value, { separator, skipArrays }, [...path, key])).forEach(([subKey, subValue]) => (res[key + separator + subKey] = subValue));
Object.entries(flatten(value, { separator: separator }, __spreadArray(__spreadArray([], path, true), [key], false))).forEach(function (_a) {
var subKey = _a[0], subValue = _a[1];
return (res[key + separator + subKey] = subValue);
});
}
else if (typeof value == "function") {
throw new Error(`Can't flatten object with function as a value of ${key}. Path to node: ${path.join(".")}`);
throw new Error("Can't flatten object with function as a value of ".concat(key, ". Path to node: ").concat(path.join(".")));
}

@@ -265,2 +263,6 @@ else {

}
};
for (var _i = 0, _d = Object.entries(obj); _i < _d.length; _i++) {
var _e = _d[_i], key = _e[0], value = _e[1];
_loop_1(key, value);
}

@@ -270,2 +272,2 @@ return res;

export { canonicalSqlTypeHint, flatten, getSegmentType, jitsuToSegment, removeEmptyFields, removeProps, segmentEventsTypes, segmentToTable };
export { canonicalSqlTypeHint, flatten, getSegmentType, jitsuToSegment, removeEmptyFields, segmentEventsTypes, segmentToTable };

@@ -5,4 +5,40 @@ '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];
}
return t;
};
return __assign.apply(this, arguments);
};
function __spreadArray(to, from, pack) {
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
if (ar || !(i in from)) {
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
ar[i] = from[i];
}
}
return to.concat(ar || Array.prototype.slice.call(from));
}
var name = "@jitsu/pipeline-helpers";
var version = "0.5.1";
var version = "0.4.1-alpha.2+4a5222c";
var description = "Utility functions designed to outsource some processing logic from Server to JS";

@@ -38,3 +74,3 @@ var author = "Jitsu Dev Team <dev@jitsu.com>";

};
var gitHead = "dead29f98059ecf21a0576b0c64cdb7f71da46f7";
var gitHead = "4a5222ce49da3cb6be58648c78b1111b39764fe1";
var pkg = {

@@ -59,3 +95,3 @@ name: name,

const segmentEventsTypes = {
var segmentEventsTypes = {
alias: true,

@@ -66,5 +102,5 @@ group: true,

screen: true,
track: true,
track: true
};
const getSegmentType = (jitsuType, customMapping, defaultSegmentType) => {
var getSegmentType = function (jitsuType, customMapping, defaultSegmentType) {
if (jitsuType === "user_identity" || jitsuType === "identify") {

@@ -80,19 +116,21 @@ return "identify";

else {
const customType = customMapping[jitsuType];
return customType ?? defaultSegmentType;
var customType = customMapping[jitsuType];
return customType !== null && customType !== void 0 ? customType : defaultSegmentType;
}
};
function removeProps(ev, props) {
const copy = { ...ev };
props.forEach(p => delete copy[p]);
var copy = __assign({}, ev);
props.forEach(function (p) { return delete copy[p]; });
return copy;
}
const jitsuToSegment = (ev, { defaultSegmentType = "track", eventTypeMapping = {} } = {}) => {
var jitsuToSegment = function (ev, _a) {
var _b, _c, _d, _e, _f, _g, _h, _j;
var _k = _a === void 0 ? {} : _a, _l = _k.defaultSegmentType, defaultSegmentType = _l === void 0 ? "track" : _l, _m = _k.eventTypeMapping, eventTypeMapping = _m === void 0 ? {} : _m;
if (ev.src_payload && ev.src === "ajs") {
return ev.src_payload;
}
let segmentEvent = {
var segmentEvent = {
type: getSegmentType(ev.event_type, eventTypeMapping, defaultSegmentType),
_metadata: {},
anonymousId: ev.user?.anonymous_id,
anonymousId: (_b = ev.user) === null || _b === void 0 ? void 0 : _b.anonymous_id,
context: {

@@ -107,11 +145,11 @@ ip: ev.source_ip,

title: ev.page_title,
url: ev.url,
url: ev.url
},
campaign: {
name: ev.utm?.name,
term: ev.utm?.term,
source: ev.utm?.source,
medium: ev.utm?.medium,
content: ev.utm?.content,
},
name: (_c = ev.utm) === null || _c === void 0 ? void 0 : _c.name,
term: (_d = ev.utm) === null || _d === void 0 ? void 0 : _d.term,
source: (_e = ev.utm) === null || _e === void 0 ? void 0 : _e.source,
medium: (_f = ev.utm) === null || _f === void 0 ? void 0 : _f.medium,
content: (_g = ev.utm) === null || _g === void 0 ? void 0 : _g.content
}
},

@@ -139,20 +177,7 @@ event: ev.event_type,

"utm",
"parsed_ua",
"location",
"eventn_ctx",
"api_key",
"app",
"doc_encoding",
"doc_host",
"ids",
"local_tz_offset",
"screen_resolution",
"src",
"vp_size",
"src_payload",
]), { skipArrays: true }),
])),
sentAt: ev.utc_time ? new Date(ev.utc_time) : new Date(),
timestamp: ev.utc_time ? new Date(ev.utc_time) : new Date(),
traits: flatten(removeProps(ev.user || {}, ["anonymous_id", "id"])),
userId: ev.user?.id || ev.user?.email,
userId: ((_h = ev.user) === null || _h === void 0 ? void 0 : _h.id) || ((_j = ev.user) === null || _j === void 0 ? void 0 : _j.email)
};

@@ -176,3 +201,3 @@ removeEmptyFields(segmentEvent);

}
const segmentTables = {
var segmentTables = {
track: "tracks",

@@ -183,36 +208,8 @@ page: "pages",

alias: "aliases",
screen: "screens",
screen: "screens"
};
const segmentToTable = (event, jitsuEvent) => {
const payloadObj = jitsuEvent?.src_payload?.obj || {};
return {
JITSU_TABLE_NAME: segmentTables[event.type] || "tracks",
__sql_type_timestamp: "timestamp",
__sql_type_sent_at: "timestamp",
anonymous_id: safeToString(event.anonymousId) || jitsuEvent?.src_payload?.anonymousId,
context_campaign_source: event.context?.campaign?.source,
context_ip: event.context?.ip,
context_library_name: jitsuEvent?.context?.library?.version || "jitsu-bridge",
context_library_version: pkg.version ,
context_locale: event.context?.locale || payloadObj.context?.locale,
context_page_path: event.context?.page?.path,
context_page_referrer: event.context?.page?.referrer,
context_page_search: event.context?.page?.search,
context_page_title: event.context?.page?.title,
context_page_url: event.context?.page?.url,
context_user_agent: event.context?.userAgent,
context_utm_source: event.context?.campaign?.source,
email: safeToString(event.traits?.email),
id: event.messageId,
name: safeToString(event.traits?.name),
path: event.context?.page?.path,
referrer: event.context?.page?.referrer,
search: event.context?.page?.search,
sent_at: safeToString(event.sentAt),
timestamp: payloadObj.timestamp || safeToString(event.timestamp),
title: event.context?.page?.title,
url: event.context?.page?.url,
user_id: safeToString(event.userId) || jitsuEvent?.src_payload?.userId,
...(event.properties || {}),
};
var segmentToTable = function (event, jitsuEvent) {
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10;
var payloadObj = ((_a = jitsuEvent === null || jitsuEvent === void 0 ? void 0 : jitsuEvent.src_payload) === null || _a === void 0 ? void 0 : _a.obj) || {};
return __assign({ JITSU_TABLE_NAME: segmentTables[event.type] || "tracks", __sql_type_timestamp: "timestamp", __sql_type_sent_at: "timestamp", anonymous_id: safeToString(event.anonymousId) || ((_b = jitsuEvent === null || jitsuEvent === void 0 ? void 0 : jitsuEvent.src_payload) === null || _b === void 0 ? void 0 : _b.anonymousId), context_campaign_source: (_d = (_c = event.context) === null || _c === void 0 ? void 0 : _c.campaign) === null || _d === void 0 ? void 0 : _d.source, context_ip: (_e = event.context) === null || _e === void 0 ? void 0 : _e.ip, context_library_name: ((_g = (_f = jitsuEvent === null || jitsuEvent === void 0 ? void 0 : jitsuEvent.context) === null || _f === void 0 ? void 0 : _f.library) === null || _g === void 0 ? void 0 : _g.version) || "jitsu-bridge", context_library_version: pkg.version , context_locale: ((_h = event.context) === null || _h === void 0 ? void 0 : _h.locale) || ((_j = payloadObj.context) === null || _j === void 0 ? void 0 : _j.locale), context_page_path: (_l = (_k = event.context) === null || _k === void 0 ? void 0 : _k.page) === null || _l === void 0 ? void 0 : _l.path, context_page_referrer: (_o = (_m = event.context) === null || _m === void 0 ? void 0 : _m.page) === null || _o === void 0 ? void 0 : _o.referrer, context_page_search: (_q = (_p = event.context) === null || _p === void 0 ? void 0 : _p.page) === null || _q === void 0 ? void 0 : _q.search, context_page_title: (_s = (_r = event.context) === null || _r === void 0 ? void 0 : _r.page) === null || _s === void 0 ? void 0 : _s.title, context_page_url: (_u = (_t = event.context) === null || _t === void 0 ? void 0 : _t.page) === null || _u === void 0 ? void 0 : _u.url, context_user_agent: (_v = event.context) === null || _v === void 0 ? void 0 : _v.userAgent, context_utm_source: (_x = (_w = event.context) === null || _w === void 0 ? void 0 : _w.campaign) === null || _x === void 0 ? void 0 : _x.source, email: safeToString((_y = event.traits) === null || _y === void 0 ? void 0 : _y.email), id: event.messageId, name: safeToString((_z = event.traits) === null || _z === void 0 ? void 0 : _z.name), path: (_1 = (_0 = event.context) === null || _0 === void 0 ? void 0 : _0.page) === null || _1 === void 0 ? void 0 : _1.path, referrer: (_3 = (_2 = event.context) === null || _2 === void 0 ? void 0 : _2.page) === null || _3 === void 0 ? void 0 : _3.referrer, search: (_5 = (_4 = event.context) === null || _4 === void 0 ? void 0 : _4.page) === null || _5 === void 0 ? void 0 : _5.search, sent_at: safeToString(event.sentAt), timestamp: payloadObj.timestamp || safeToString(event.timestamp), title: (_7 = (_6 = event.context) === null || _6 === void 0 ? void 0 : _6.page) === null || _7 === void 0 ? void 0 : _7.title, url: (_9 = (_8 = event.context) === null || _8 === void 0 ? void 0 : _8.page) === null || _9 === void 0 ? void 0 : _9.url, user_id: safeToString(event.userId) || ((_10 = jitsuEvent === null || jitsuEvent === void 0 ? void 0 : jitsuEvent.src_payload) === null || _10 === void 0 ? void 0 : _10.userId) }, (event.properties || {}));
};

@@ -233,3 +230,4 @@ function canonicalSqlTypeHint(hint) {

function removeEmptyFields(obj) {
for (const [key, val] of Object.entries(obj)) {
for (var _i = 0, _a = Object.entries(obj); _i < _a.length; _i++) {
var _b = _a[_i], key = _b[0], val = _b[1];
if (val !== null && typeof val === "object" && !Array.isArray(val)) {

@@ -243,24 +241,24 @@ removeEmptyFields(val);

}
function flatten(obj, { separator = "_", skipArrays = false } = {}, path = []) {
function flatten(obj, _a, path) {
var _b = _a === void 0 ? {} : _a, _c = _b.separator, separator = _c === void 0 ? "_" : _c;
if (path === void 0) { path = []; }
if (typeof obj !== "object") {
throw new Error(`Can't flatten an object, expected object, but got" ${typeof obj}`);
throw new Error("Can't flatten an object, expected object, but got\" ".concat(typeof obj));
}
if (obj === null) {
throw new Error(`Can't flatten null value`);
throw new Error("Can't flatten null value");
}
if (Array.isArray(obj)) {
if (!skipArrays) {
throw new Error(`Can't flatten array`);
}
else {
return {};
}
throw new Error("Can't flatten array");
}
const res = {};
for (const [key, value] of Object.entries(obj)) {
var res = {};
var _loop_1 = function (key, value) {
if (typeof value === "object") {
Object.entries(flatten(value, { separator, skipArrays }, [...path, key])).forEach(([subKey, subValue]) => (res[key + separator + subKey] = subValue));
Object.entries(flatten(value, { separator: separator }, __spreadArray(__spreadArray([], path, true), [key], false))).forEach(function (_a) {
var subKey = _a[0], subValue = _a[1];
return (res[key + separator + subKey] = subValue);
});
}
else if (typeof value == "function") {
throw new Error(`Can't flatten object with function as a value of ${key}. Path to node: ${path.join(".")}`);
throw new Error("Can't flatten object with function as a value of ".concat(key, ". Path to node: ").concat(path.join(".")));
}

@@ -270,2 +268,6 @@ else {

}
};
for (var _i = 0, _d = Object.entries(obj); _i < _d.length; _i++) {
var _e = _d[_i], key = _e[0], value = _e[1];
_loop_1(key, value);
}

@@ -280,4 +282,3 @@ return res;

exports.removeEmptyFields = removeEmptyFields;
exports.removeProps = removeProps;
exports.segmentEventsTypes = segmentEventsTypes;
exports.segmentToTable = segmentToTable;
{
"name": "@jitsu/pipeline-helpers",
"version": "0.6.0",
"version": "0.7.0",
"description": "Utility functions designed to outsource some processing logic from Server to JS",

@@ -34,3 +34,3 @@ "author": "Jitsu Dev Team <dev@jitsu.com>",

},
"gitHead": "82fbe5d15fbd1308e6c571961f9d4f8cb3644591"
"gitHead": "ede64e6fc3d51e3f38315fde5633d385e0bc9178"
}
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