@walkeros/web-destination-api 0.4.2 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +119 -75
- package/dist/dev.js +1 -1
- package/dist/dev.mjs +1 -1
- package/dist/examples/index.js +6 -6
- package/dist/examples/index.mjs +6 -6
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/examples/index.js
CHANGED
|
@@ -63,18 +63,18 @@ var c = {};
|
|
|
63
63
|
for (var r in n) e(t, r, { get: n[r], enumerable: true });
|
|
64
64
|
})(c, { Level: () => a });
|
|
65
65
|
var a = ((e2) => (e2[e2.ERROR = 0] = "ERROR", e2[e2.INFO = 1] = "INFO", e2[e2.DEBUG = 2] = "DEBUG", e2))(a || {});
|
|
66
|
-
var
|
|
67
|
-
function
|
|
68
|
-
n = { ...
|
|
66
|
+
var E = { merge: true, shallow: true, extend: true };
|
|
67
|
+
function S(e2, t = {}, n = {}) {
|
|
68
|
+
n = { ...E, ...n };
|
|
69
69
|
const r = Object.entries(t).reduce((t2, [r2, o]) => {
|
|
70
70
|
const i = e2[r2];
|
|
71
71
|
return n.merge && Array.isArray(i) && Array.isArray(o) ? t2[r2] = o.reduce((e3, t3) => e3.includes(t3) ? e3 : [...e3, t3], [...i]) : (n.extend || r2 in e2) && (t2[r2] = o), t2;
|
|
72
72
|
}, {});
|
|
73
73
|
return n.shallow ? { ...e2, ...r } : (Object.assign(e2, r), e2);
|
|
74
74
|
}
|
|
75
|
-
function
|
|
75
|
+
function W(e2 = {}) {
|
|
76
76
|
var _a;
|
|
77
|
-
const t = e2.timestamp || (/* @__PURE__ */ new Date()).setHours(0, 13, 37, 0), n = e2.group || "gr0up", r = e2.count || 1, o =
|
|
77
|
+
const t = e2.timestamp || (/* @__PURE__ */ new Date()).setHours(0, 13, 37, 0), n = e2.group || "gr0up", r = e2.count || 1, o = S({ name: "entity action", data: { string: "foo", number: 1, boolean: true, array: [0, "text", false], not: void 0 }, context: { dev: ["test", 1] }, globals: { lang: "elb" }, custom: { completely: "random" }, user: { id: "us3r", device: "c00k13", session: "s3ss10n" }, nested: [{ entity: "child", data: { is: "subordinated" }, nested: [], context: { element: ["child", 0] } }], consent: { functional: true }, id: `${t}-${n}-${r}`, trigger: "test", entity: "entity", action: "action", timestamp: t, timing: 3.14, group: n, count: r, version: { source: "0.5.0", tagging: 1 }, source: { type: "web", id: "https://localhost:80", previous_id: "http://remotehost:9001" } }, e2, { merge: false });
|
|
78
78
|
if (e2.name) {
|
|
79
79
|
const [t2, n2] = (_a = e2.name.split(" ")) != null ? _a : [];
|
|
80
80
|
t2 && n2 && (o.entity = t2, o.action = n2);
|
|
@@ -83,7 +83,7 @@ function z(e2 = {}) {
|
|
|
83
83
|
}
|
|
84
84
|
function B(e2 = "entity action", t = {}) {
|
|
85
85
|
const n = t.timestamp || (/* @__PURE__ */ new Date()).setHours(0, 13, 37, 0), r = { data: { id: "ers", name: "Everyday Ruck Snack", color: "black", size: "l", price: 420 } }, o = { data: { id: "cc", name: "Cool Cap", size: "one size", price: 42 } };
|
|
86
|
-
return
|
|
86
|
+
return W({ ...{ "cart view": { data: { currency: "EUR", value: 2 * r.data.price }, context: { shopping: ["cart", 0] }, globals: { pagegroup: "shop" }, nested: [{ entity: "product", data: { ...r.data, quantity: 2 }, context: { shopping: ["cart", 0] }, nested: [] }], trigger: "load" }, "checkout view": { data: { step: "payment", currency: "EUR", value: r.data.price + o.data.price }, context: { shopping: ["checkout", 0] }, globals: { pagegroup: "shop" }, nested: [{ entity: "product", ...r, context: { shopping: ["checkout", 0] }, nested: [] }, { entity: "product", ...o, context: { shopping: ["checkout", 0] }, nested: [] }], trigger: "load" }, "order complete": { data: { id: "0rd3r1d", currency: "EUR", shipping: 5.22, taxes: 73.76, total: 555 }, context: { shopping: ["complete", 0] }, globals: { pagegroup: "shop" }, nested: [{ entity: "product", ...r, context: { shopping: ["complete", 0] }, nested: [] }, { entity: "product", ...o, context: { shopping: ["complete", 0] }, nested: [] }, { entity: "gift", data: { name: "Surprise" }, context: { shopping: ["complete", 0] }, nested: [] }], trigger: "load" }, "page view": { data: { domain: "www.example.com", title: "walkerOS documentation", referrer: "https://www.walkeros.io/", search: "?foo=bar", hash: "#hash", id: "/docs/" }, globals: { pagegroup: "docs" }, trigger: "load" }, "product add": { ...r, context: { shopping: ["intent", 0] }, globals: { pagegroup: "shop" }, nested: [], trigger: "click" }, "product view": { ...r, context: { shopping: ["detail", 0] }, globals: { pagegroup: "shop" }, nested: [], trigger: "load" }, "product visible": { data: { ...r.data, position: 3, promo: true }, context: { shopping: ["discover", 0] }, globals: { pagegroup: "shop" }, nested: [], trigger: "load" }, "promotion visible": { data: { name: "Setting up tracking easily", position: "hero" }, context: { ab_test: ["engagement", 0] }, globals: { pagegroup: "homepage" }, trigger: "visible" }, "session start": { data: { id: "s3ss10n", start: n, isNew: true, count: 1, runs: 1, isStart: true, storage: true, referrer: "", device: "c00k13" }, user: { id: "us3r", device: "c00k13", session: "s3ss10n", hash: "h4sh", address: "street number", email: "user@example.com", phone: "+49 123 456 789", userAgent: "Mozilla...", browser: "Chrome", browserVersion: "90", deviceType: "desktop", language: "de-DE", country: "DE", region: "HH", city: "Hamburg", zip: "20354", timezone: "Berlin", os: "walkerOS", osVersion: "1.0", screenSize: "1337x420", ip: "127.0.0.0", internal: true, custom: "value" } } }[e2], ...t, name: e2 });
|
|
87
87
|
}
|
|
88
88
|
|
|
89
89
|
// src/examples/events.ts
|
package/dist/examples/index.mjs
CHANGED
|
@@ -41,18 +41,18 @@ var c = {};
|
|
|
41
41
|
for (var r in n) e(t, r, { get: n[r], enumerable: true });
|
|
42
42
|
})(c, { Level: () => a });
|
|
43
43
|
var a = ((e2) => (e2[e2.ERROR = 0] = "ERROR", e2[e2.INFO = 1] = "INFO", e2[e2.DEBUG = 2] = "DEBUG", e2))(a || {});
|
|
44
|
-
var
|
|
45
|
-
function
|
|
46
|
-
n = { ...
|
|
44
|
+
var E = { merge: true, shallow: true, extend: true };
|
|
45
|
+
function S(e2, t = {}, n = {}) {
|
|
46
|
+
n = { ...E, ...n };
|
|
47
47
|
const r = Object.entries(t).reduce((t2, [r2, o]) => {
|
|
48
48
|
const i = e2[r2];
|
|
49
49
|
return n.merge && Array.isArray(i) && Array.isArray(o) ? t2[r2] = o.reduce((e3, t3) => e3.includes(t3) ? e3 : [...e3, t3], [...i]) : (n.extend || r2 in e2) && (t2[r2] = o), t2;
|
|
50
50
|
}, {});
|
|
51
51
|
return n.shallow ? { ...e2, ...r } : (Object.assign(e2, r), e2);
|
|
52
52
|
}
|
|
53
|
-
function
|
|
53
|
+
function W(e2 = {}) {
|
|
54
54
|
var _a;
|
|
55
|
-
const t = e2.timestamp || (/* @__PURE__ */ new Date()).setHours(0, 13, 37, 0), n = e2.group || "gr0up", r = e2.count || 1, o =
|
|
55
|
+
const t = e2.timestamp || (/* @__PURE__ */ new Date()).setHours(0, 13, 37, 0), n = e2.group || "gr0up", r = e2.count || 1, o = S({ name: "entity action", data: { string: "foo", number: 1, boolean: true, array: [0, "text", false], not: void 0 }, context: { dev: ["test", 1] }, globals: { lang: "elb" }, custom: { completely: "random" }, user: { id: "us3r", device: "c00k13", session: "s3ss10n" }, nested: [{ entity: "child", data: { is: "subordinated" }, nested: [], context: { element: ["child", 0] } }], consent: { functional: true }, id: `${t}-${n}-${r}`, trigger: "test", entity: "entity", action: "action", timestamp: t, timing: 3.14, group: n, count: r, version: { source: "0.5.0", tagging: 1 }, source: { type: "web", id: "https://localhost:80", previous_id: "http://remotehost:9001" } }, e2, { merge: false });
|
|
56
56
|
if (e2.name) {
|
|
57
57
|
const [t2, n2] = (_a = e2.name.split(" ")) != null ? _a : [];
|
|
58
58
|
t2 && n2 && (o.entity = t2, o.action = n2);
|
|
@@ -61,7 +61,7 @@ function z(e2 = {}) {
|
|
|
61
61
|
}
|
|
62
62
|
function B(e2 = "entity action", t = {}) {
|
|
63
63
|
const n = t.timestamp || (/* @__PURE__ */ new Date()).setHours(0, 13, 37, 0), r = { data: { id: "ers", name: "Everyday Ruck Snack", color: "black", size: "l", price: 420 } }, o = { data: { id: "cc", name: "Cool Cap", size: "one size", price: 42 } };
|
|
64
|
-
return
|
|
64
|
+
return W({ ...{ "cart view": { data: { currency: "EUR", value: 2 * r.data.price }, context: { shopping: ["cart", 0] }, globals: { pagegroup: "shop" }, nested: [{ entity: "product", data: { ...r.data, quantity: 2 }, context: { shopping: ["cart", 0] }, nested: [] }], trigger: "load" }, "checkout view": { data: { step: "payment", currency: "EUR", value: r.data.price + o.data.price }, context: { shopping: ["checkout", 0] }, globals: { pagegroup: "shop" }, nested: [{ entity: "product", ...r, context: { shopping: ["checkout", 0] }, nested: [] }, { entity: "product", ...o, context: { shopping: ["checkout", 0] }, nested: [] }], trigger: "load" }, "order complete": { data: { id: "0rd3r1d", currency: "EUR", shipping: 5.22, taxes: 73.76, total: 555 }, context: { shopping: ["complete", 0] }, globals: { pagegroup: "shop" }, nested: [{ entity: "product", ...r, context: { shopping: ["complete", 0] }, nested: [] }, { entity: "product", ...o, context: { shopping: ["complete", 0] }, nested: [] }, { entity: "gift", data: { name: "Surprise" }, context: { shopping: ["complete", 0] }, nested: [] }], trigger: "load" }, "page view": { data: { domain: "www.example.com", title: "walkerOS documentation", referrer: "https://www.walkeros.io/", search: "?foo=bar", hash: "#hash", id: "/docs/" }, globals: { pagegroup: "docs" }, trigger: "load" }, "product add": { ...r, context: { shopping: ["intent", 0] }, globals: { pagegroup: "shop" }, nested: [], trigger: "click" }, "product view": { ...r, context: { shopping: ["detail", 0] }, globals: { pagegroup: "shop" }, nested: [], trigger: "load" }, "product visible": { data: { ...r.data, position: 3, promo: true }, context: { shopping: ["discover", 0] }, globals: { pagegroup: "shop" }, nested: [], trigger: "load" }, "promotion visible": { data: { name: "Setting up tracking easily", position: "hero" }, context: { ab_test: ["engagement", 0] }, globals: { pagegroup: "homepage" }, trigger: "visible" }, "session start": { data: { id: "s3ss10n", start: n, isNew: true, count: 1, runs: 1, isStart: true, storage: true, referrer: "", device: "c00k13" }, user: { id: "us3r", device: "c00k13", session: "s3ss10n", hash: "h4sh", address: "street number", email: "user@example.com", phone: "+49 123 456 789", userAgent: "Mozilla...", browser: "Chrome", browserVersion: "90", deviceType: "desktop", language: "de-DE", country: "DE", region: "HH", city: "Hamburg", zip: "20354", timezone: "Berlin", os: "walkerOS", osVersion: "1.0", screenSize: "1337x420", ip: "127.0.0.0", internal: true, custom: "value" } } }[e2], ...t, name: e2 });
|
|
65
65
|
}
|
|
66
66
|
|
|
67
67
|
// src/examples/events.ts
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/types/index.ts","../src/index.ts"],"sourcesContent":["import type {\n Mapping as WalkerOSMapping,\n SendDataValue,\n SendHeaders,\n Destination as CoreDestination,\n} from '@walkeros/core';\nimport type { DestinationWeb, sendWeb } from '@walkeros/web-core';\nimport type { SendWebTransport } from '@walkeros/web-core';\n\nexport interface Settings {\n url: string;\n headers?: SendHeaders;\n method?: string;\n transform?: Transform;\n transport?: SendWebTransport;\n}\n\n// InitSettings: user input (all optional)\nexport type InitSettings = Partial<Settings>;\n\nexport interface Mapping {}\n\nexport interface Env extends DestinationWeb.Env {\n sendWeb?: typeof sendWeb;\n}\n\nexport type Types = CoreDestination.Types<Settings, Mapping, Env, InitSettings>;\n\nexport type Destination = DestinationWeb.Destination<Types>;\nexport type Config = DestinationWeb.Config<Types>;\n\nexport type Rule = WalkerOSMapping.Rule<Mapping>;\nexport type Rules = WalkerOSMapping.Rules<Rule>;\n\nexport type Transform = (\n data?: unknown,\n config?: Config,\n mapping?: WalkerOSMapping.Rule<Mapping>,\n) => SendDataValue;\n","import type { Settings, Destination, Env } from './types';\nimport { isDefined } from '@walkeros/core';\nimport { getEnv, sendWeb } from '@walkeros/web-core';\n\n// Types\nexport * as DestinationAPI from './types';\n\nexport const destinationAPI: Destination = {\n type: 'api',\n\n config: {},\n\n push(event, { config, mapping, data, env, logger }) {\n const { settings } = config;\n const {\n url,\n headers,\n method,\n transform,\n transport = 'fetch',\n } = settings || {};\n\n if (!url) logger.throw('Config settings url missing');\n\n const eventData = isDefined(data) ? data : event;\n const body = transform\n ? transform(eventData, config, mapping) // Transform event data\n : JSON.stringify(eventData);\n\n const sendWebFn = (env as Env)?.sendWeb || sendWeb;\n sendWebFn(url!, body, { headers, method, transport });\n },\n};\n\nexport default destinationAPI;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;ACOO,IAAM,iBAA8B;AAAA,EACzC,MAAM;AAAA,EAEN,QAAQ,CAAC;AAAA,EAET,KAAK,OAAO,EAAE,QAAQ,SAAS,MAAM,KAAK,OAAO,GAAG;AAClD,UAAM,EAAE,SAAS,IAAI;AACrB,UAAM;AAAA,MACJ;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA,YAAY;AAAA,IACd,IAAI,YAAY,CAAC;AAEjB,QAAI,CAAC,IAAK,QAAO,MAAM,6BAA6B;AAEpD,UAAM,YAAY,EAAU,IAAI,IAAI,OAAO;AAC3C,UAAM,OAAO,YACT,UAAU,WAAW,QAAQ,OAAO,IACpC,KAAK,UAAU,SAAS;AAE5B,UAAM,aAAa,2BAAa,
|
|
1
|
+
{"version":3,"sources":["../src/types/index.ts","../src/index.ts"],"sourcesContent":["import type {\n Mapping as WalkerOSMapping,\n SendDataValue,\n SendHeaders,\n Destination as CoreDestination,\n} from '@walkeros/core';\nimport type { DestinationWeb, sendWeb } from '@walkeros/web-core';\nimport type { SendWebTransport } from '@walkeros/web-core';\n\nexport interface Settings {\n url: string;\n headers?: SendHeaders;\n method?: string;\n transform?: Transform;\n transport?: SendWebTransport;\n}\n\n// InitSettings: user input (all optional)\nexport type InitSettings = Partial<Settings>;\n\nexport interface Mapping {}\n\nexport interface Env extends DestinationWeb.Env {\n sendWeb?: typeof sendWeb;\n}\n\nexport type Types = CoreDestination.Types<Settings, Mapping, Env, InitSettings>;\n\nexport type Destination = DestinationWeb.Destination<Types>;\nexport type Config = DestinationWeb.Config<Types>;\n\nexport type Rule = WalkerOSMapping.Rule<Mapping>;\nexport type Rules = WalkerOSMapping.Rules<Rule>;\n\nexport type Transform = (\n data?: unknown,\n config?: Config,\n mapping?: WalkerOSMapping.Rule<Mapping>,\n) => SendDataValue;\n","import type { Settings, Destination, Env } from './types';\nimport { isDefined } from '@walkeros/core';\nimport { getEnv, sendWeb } from '@walkeros/web-core';\n\n// Types\nexport * as DestinationAPI from './types';\n\nexport const destinationAPI: Destination = {\n type: 'api',\n\n config: {},\n\n push(event, { config, mapping, data, env, logger }) {\n const { settings } = config;\n const {\n url,\n headers,\n method,\n transform,\n transport = 'fetch',\n } = settings || {};\n\n if (!url) logger.throw('Config settings url missing');\n\n const eventData = isDefined(data) ? data : event;\n const body = transform\n ? transform(eventData, config, mapping) // Transform event data\n : JSON.stringify(eventData);\n\n const sendWebFn = (env as Env)?.sendWeb || sendWeb;\n sendWebFn(url!, body, { headers, method, transport });\n },\n};\n\nexport default destinationAPI;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;ACOO,IAAM,iBAA8B;AAAA,EACzC,MAAM;AAAA,EAEN,QAAQ,CAAC;AAAA,EAET,KAAK,OAAO,EAAE,QAAQ,SAAS,MAAM,KAAK,OAAO,GAAG;AAClD,UAAM,EAAE,SAAS,IAAI;AACrB,UAAM;AAAA,MACJ;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA,YAAY;AAAA,IACd,IAAI,YAAY,CAAC;AAEjB,QAAI,CAAC,IAAK,QAAO,MAAM,6BAA6B;AAEpD,UAAM,YAAY,EAAU,IAAI,IAAI,OAAO;AAC3C,UAAM,OAAO,YACT,UAAU,WAAW,QAAQ,OAAO,IACpC,KAAK,UAAU,SAAS;AAE5B,UAAM,aAAa,2BAAa,YAAWA;AAC3C,cAAU,KAAM,MAAM,EAAE,SAAS,QAAQ,UAAU,CAAC;AAAA,EACtD;AACF;AAEA,IAAO,gBAAQ;","names":["S"]}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@walkeros/web-destination-api",
|
|
3
3
|
"description": "Web API destination for walkerOS",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.5.0",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"main": "./dist/index.js",
|
|
7
7
|
"module": "./dist/index.mjs",
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
"update": "npx npm-check-updates -u && npm update"
|
|
36
36
|
},
|
|
37
37
|
"dependencies": {
|
|
38
|
-
"@walkeros/web-core": "0.
|
|
38
|
+
"@walkeros/web-core": "0.5.0"
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {},
|
|
41
41
|
"repository": {
|