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.4.1-alpha.4 to 0.5.1

6

lib/index.d.ts

@@ -7,2 +7,5 @@ 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;

@@ -12,4 +15,5 @@ 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 }?: {
export declare function flatten(obj: any, { separator, skipArrays }?: {
separator?: string | undefined;
skipArrays?: boolean | undefined;
}, path?: string[]): TableObject;

168

lib/index.es.js

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

/*! *****************************************************************************
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.4.1-alpha.2+4a5222c";
var version = "0.5.0";
var description = "Utility functions designed to outsource some processing logic from Server to JS";

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

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

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

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

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

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

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

else {
var customType = customMapping[jitsuType];
return customType !== null && customType !== void 0 ? customType : defaultSegmentType;
const customType = customMapping[jitsuType];
return customType ?? defaultSegmentType;
}
};
function removeProps(ev, props) {
var copy = __assign({}, ev);
props.forEach(function (p) { return delete copy[p]; });
const copy = { ...ev };
props.forEach(p => delete copy[p]);
return copy;
}
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;
const jitsuToSegment = (ev, { defaultSegmentType = "track", eventTypeMapping = {} } = {}) => {
if (ev.src_payload && ev.src === "ajs") {
return ev.src_payload;
}
var segmentEvent = {
let segmentEvent = {
type: getSegmentType(ev.event_type, eventTypeMapping, defaultSegmentType),
_metadata: {},
anonymousId: (_b = ev.user) === null || _b === void 0 ? void 0 : _b.anonymous_id,
anonymousId: ev.user?.anonymous_id,
context: {

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

title: ev.page_title,
url: ev.url
url: ev.url,
},
campaign: {
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
}
name: ev.utm?.name,
term: ev.utm?.term,
source: ev.utm?.source,
medium: ev.utm?.medium,
content: ev.utm?.content,
},
},

@@ -172,7 +134,20 @@ 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: ((_h = ev.user) === null || _h === void 0 ? void 0 : _h.id) || ((_j = ev.user) === null || _j === void 0 ? void 0 : _j.email)
userId: ev.user?.id || ev.user?.email,
};

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

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

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

alias: "aliases",
screen: "screens"
screen: "screens",
};
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 || {}));
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 || {}),
};
};

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

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

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

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

@@ -263,6 +265,2 @@ 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);
}

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

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

@@ -5,40 +5,4 @@ '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.4.1-alpha.2+4a5222c";
var version = "0.5.0";
var description = "Utility functions designed to outsource some processing logic from Server to JS";

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

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

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

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

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

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

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

else {
var customType = customMapping[jitsuType];
return customType !== null && customType !== void 0 ? customType : defaultSegmentType;
const customType = customMapping[jitsuType];
return customType ?? defaultSegmentType;
}
};
function removeProps(ev, props) {
var copy = __assign({}, ev);
props.forEach(function (p) { return delete copy[p]; });
const copy = { ...ev };
props.forEach(p => delete copy[p]);
return copy;
}
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;
const jitsuToSegment = (ev, { defaultSegmentType = "track", eventTypeMapping = {} } = {}) => {
if (ev.src_payload && ev.src === "ajs") {
return ev.src_payload;
}
var segmentEvent = {
let segmentEvent = {
type: getSegmentType(ev.event_type, eventTypeMapping, defaultSegmentType),
_metadata: {},
anonymousId: (_b = ev.user) === null || _b === void 0 ? void 0 : _b.anonymous_id,
anonymousId: ev.user?.anonymous_id,
context: {

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

title: ev.page_title,
url: ev.url
url: ev.url,
},
campaign: {
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
}
name: ev.utm?.name,
term: ev.utm?.term,
source: ev.utm?.source,
medium: ev.utm?.medium,
content: ev.utm?.content,
},
},

@@ -177,7 +139,20 @@ 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: ((_h = ev.user) === null || _h === void 0 ? void 0 : _h.id) || ((_j = ev.user) === null || _j === void 0 ? void 0 : _j.email)
userId: ev.user?.id || ev.user?.email,
};

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

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

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

alias: "aliases",
screen: "screens"
screen: "screens",
};
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 || {}));
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 || {}),
};
};

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

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

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

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

@@ -268,6 +270,2 @@ 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);
}

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

exports.removeEmptyFields = removeEmptyFields;
exports.removeProps = removeProps;
exports.segmentEventsTypes = segmentEventsTypes;
exports.segmentToTable = segmentToTable;
{
"name": "@jitsu/pipeline-helpers",
"version": "0.4.1-alpha.4+dead29f",
"version": "0.5.1",
"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": "dead29f98059ecf21a0576b0c64cdb7f71da46f7"
"gitHead": "361b010cd2aeafd332b4a827c47908ada60f3576"
}
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