@walkeros/web-destination-heap 3.4.0-next-1776749829492

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.
@@ -0,0 +1,222 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __export = (target, all) => {
3
+ for (var name in all)
4
+ __defProp(target, name, { get: all[name], enumerable: true });
5
+ };
6
+
7
+ // src/examples/env.ts
8
+ var env_exports = {};
9
+ __export(env_exports, {
10
+ init: () => init,
11
+ push: () => push,
12
+ simulation: () => simulation
13
+ });
14
+ var noop = (() => {
15
+ });
16
+ function createMockHeap() {
17
+ return {
18
+ load: noop,
19
+ track: noop,
20
+ identify: noop,
21
+ resetIdentity: noop,
22
+ addUserProperties: noop,
23
+ addEventProperties: noop,
24
+ clearEventProperties: noop,
25
+ startTracking: noop,
26
+ stopTracking: noop
27
+ };
28
+ }
29
+ var init = {
30
+ window: {
31
+ heap: createMockHeap()
32
+ }
33
+ };
34
+ var push = {
35
+ window: {
36
+ heap: createMockHeap()
37
+ }
38
+ };
39
+ var simulation = [
40
+ "call:window.heap.track",
41
+ "call:window.heap.identify",
42
+ "call:window.heap.resetIdentity",
43
+ "call:window.heap.addUserProperties",
44
+ "call:window.heap.addEventProperties",
45
+ "call:window.heap.clearEventProperties",
46
+ "call:window.heap.startTracking",
47
+ "call:window.heap.stopTracking"
48
+ ];
49
+
50
+ // src/examples/step.ts
51
+ var step_exports = {};
52
+ __export(step_exports, {
53
+ consentGrantStartTracking: () => consentGrantStartTracking,
54
+ consentRevokeStopTracking: () => consentRevokeStopTracking,
55
+ defaultEventForwarding: () => defaultEventForwarding,
56
+ destinationLevelIdentify: () => destinationLevelIdentify,
57
+ destinationLevelInclude: () => destinationLevelInclude,
58
+ eventWithUserProperties: () => eventWithUserProperties,
59
+ globalEventProperties: () => globalEventProperties,
60
+ userLoginIdentify: () => userLoginIdentify,
61
+ userLogoutReset: () => userLogoutReset
62
+ });
63
+
64
+ // ../../../core/dist/index.mjs
65
+ var e = Object.defineProperty;
66
+ var c = {};
67
+ ((t, n) => {
68
+ for (var o in n) e(t, o, { get: n[o], enumerable: true });
69
+ })(c, { Level: () => u });
70
+ var u = ((e2) => (e2[e2.ERROR = 0] = "ERROR", e2[e2.WARN = 1] = "WARN", e2[e2.INFO = 2] = "INFO", e2[e2.DEBUG = 3] = "DEBUG", e2))(u || {});
71
+ var W = { merge: true, shallow: true, extend: true };
72
+ function L(e2, t = {}, n = {}) {
73
+ n = { ...W, ...n };
74
+ const o = Object.entries(t).reduce((t2, [o2, r]) => {
75
+ const i = e2[o2];
76
+ return n.merge && Array.isArray(i) && Array.isArray(r) ? t2[o2] = r.reduce((e3, t3) => e3.includes(t3) ? e3 : [...e3, t3], [...i]) : (n.extend || o2 in e2) && (t2[o2] = r), t2;
77
+ }, {});
78
+ return n.shallow ? { ...e2, ...o } : (Object.assign(e2, o), e2);
79
+ }
80
+ function fe(e2 = {}) {
81
+ var _a;
82
+ const t = e2.timestamp || (/* @__PURE__ */ new Date()).setHours(0, 13, 37, 0), n = e2.group || "gr0up", o = e2.count || 1, r = L({ 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}-${o}`, trigger: "test", entity: "entity", action: "action", timestamp: t, timing: 3.14, group: n, count: o, version: { source: "3.4.0-next-1776749829492", tagging: 1 }, source: { type: "web", id: "https://localhost:80", previous_id: "http://remotehost:9001" } }, e2, { merge: false });
83
+ if (e2.name) {
84
+ const [t2, n2] = (_a = e2.name.split(" ")) != null ? _a : [];
85
+ t2 && n2 && (r.entity = t2, r.action = n2);
86
+ }
87
+ return r;
88
+ }
89
+ function le(e2 = "entity action", t = {}) {
90
+ const n = t.timestamp || (/* @__PURE__ */ new Date()).setHours(0, 13, 37, 0), o = { data: { id: "ers", name: "Everyday Ruck Snack", color: "black", size: "l", price: 420 } }, r = { data: { id: "cc", name: "Cool Cap", size: "one size", price: 42 } };
91
+ return fe({ ...{ "cart view": { data: { currency: "EUR", value: 2 * o.data.price }, context: { shopping: ["cart", 0] }, globals: { pagegroup: "shop" }, nested: [{ entity: "product", data: { ...o.data, quantity: 2 }, context: { shopping: ["cart", 0] }, nested: [] }], trigger: "load" }, "checkout view": { data: { step: "payment", currency: "EUR", value: o.data.price + r.data.price }, context: { shopping: ["checkout", 0] }, globals: { pagegroup: "shop" }, nested: [{ entity: "product", ...o, context: { shopping: ["checkout", 0] }, nested: [] }, { entity: "product", ...r, 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", ...o, context: { shopping: ["complete", 0] }, nested: [] }, { entity: "product", ...r, 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": { ...o, context: { shopping: ["intent", 0] }, globals: { pagegroup: "shop" }, nested: [], trigger: "click" }, "product view": { ...o, context: { shopping: ["detail", 0] }, globals: { pagegroup: "shop" }, nested: [], trigger: "load" }, "product visible": { data: { ...o.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 });
92
+ }
93
+
94
+ // src/examples/step.ts
95
+ var defaultEventForwarding = {
96
+ in: le("product view", { timestamp: 1700000100 }),
97
+ out: [["heap.track", "product view", {}]]
98
+ };
99
+ var destinationLevelInclude = {
100
+ in: le("order complete", { timestamp: 1700000101 }),
101
+ mapping: {
102
+ name: "purchase",
103
+ data: {
104
+ map: {
105
+ order_id: "data.id",
106
+ total: "data.total",
107
+ currency: { key: "data.currency", value: "EUR" }
108
+ }
109
+ }
110
+ },
111
+ out: [
112
+ [
113
+ "heap.track",
114
+ "purchase",
115
+ { order_id: "0rd3r1d", total: 555, currency: "EUR" }
116
+ ]
117
+ ]
118
+ };
119
+ var destinationLevelIdentify = {
120
+ in: le("page view", { timestamp: 1700000102 }),
121
+ settings: {
122
+ identify: "user.id"
123
+ },
124
+ out: [
125
+ ["heap.identify", "us3r"],
126
+ ["heap.track", "page view", {}]
127
+ ]
128
+ };
129
+ var userLoginIdentify = {
130
+ in: le("user login", {
131
+ timestamp: 1700000103,
132
+ data: {
133
+ email: "user@example.com",
134
+ plan: "premium",
135
+ company: "Acme"
136
+ }
137
+ }),
138
+ mapping: {
139
+ skip: true,
140
+ settings: {
141
+ identify: "data.email",
142
+ userProperties: {
143
+ map: {
144
+ plan: "data.plan",
145
+ company: "data.company"
146
+ }
147
+ }
148
+ }
149
+ },
150
+ out: [
151
+ ["heap.identify", "user@example.com"],
152
+ ["heap.addUserProperties", { plan: "premium", company: "Acme" }]
153
+ ]
154
+ };
155
+ var userLogoutReset = {
156
+ in: le("user logout", { timestamp: 1700000104 }),
157
+ mapping: {
158
+ skip: true,
159
+ settings: {
160
+ reset: true
161
+ }
162
+ },
163
+ out: [["heap.resetIdentity"]]
164
+ };
165
+ var eventWithUserProperties = {
166
+ in: le("order complete", {
167
+ timestamp: 1700000105,
168
+ data: {
169
+ id: "0rd3r1d",
170
+ total: 555,
171
+ currency: "EUR"
172
+ }
173
+ }),
174
+ mapping: {
175
+ settings: {
176
+ userProperties: {
177
+ map: {
178
+ last_order_value: "data.total",
179
+ last_order_currency: "data.currency"
180
+ }
181
+ }
182
+ }
183
+ },
184
+ out: [
185
+ [
186
+ "heap.addUserProperties",
187
+ { last_order_value: 555, last_order_currency: "EUR" }
188
+ ],
189
+ ["heap.track", "order complete", {}]
190
+ ]
191
+ };
192
+ var globalEventProperties = {
193
+ in: le("page view", {
194
+ timestamp: 1700000106,
195
+ data: { category: "docs" }
196
+ }),
197
+ mapping: {
198
+ skip: true,
199
+ settings: {
200
+ eventProperties: {
201
+ map: {
202
+ page_category: "data.category"
203
+ }
204
+ }
205
+ }
206
+ },
207
+ out: [["heap.addEventProperties", { page_category: "docs" }]]
208
+ };
209
+ var consentRevokeStopTracking = {
210
+ command: "consent",
211
+ in: { analytics: false },
212
+ out: [["heap.stopTracking"]]
213
+ };
214
+ var consentGrantStartTracking = {
215
+ command: "consent",
216
+ in: { analytics: true },
217
+ out: [["heap.startTracking"]]
218
+ };
219
+ export {
220
+ env_exports as env,
221
+ step_exports as step
222
+ };
@@ -0,0 +1 @@
1
+ "use strict";var Destination=(()=>{var e=Object.defineProperty,t=Object.getOwnPropertyDescriptor,n=Object.getOwnPropertyNames,r=Object.prototype.hasOwnProperty,o={};((t,n)=>{for(var r in n)e(t,r,{get:n[r],enumerable:!0})})(o,{DestinationHeap:()=>h,default:()=>k,destinationHeap:()=>j});var i=Object.defineProperty;((e,t)=>{for(var n in t)i(e,n,{get:t[n],enumerable:!0})})({},{Level:()=>s});var a,s=((a=s||{})[a.ERROR=0]="ERROR",a[a.WARN=1]="WARN",a[a.INFO=2]="INFO",a[a.DEBUG=3]="DEBUG",a);function c(e){return Array.isArray(e)}function l(e){return void 0!==e}function u(e){return"object"==typeof e&&null!==e&&!c(e)&&"[object Object]"===Object.prototype.toString.call(e)}function d(e){return"string"==typeof e}function f(e,t="",n){const r=t.split(".");let o=e;for(let e=0;e<r.length;e++){const t=r[e];if("*"===t&&c(o)){const t=r.slice(e+1).join("."),i=[];for(const e of o){const r=f(e,t,n);i.push(r)}return i}if(o=o instanceof Object?o[t]:void 0,void 0===o)break}return l(o)?o:n}function p(e){return function(e){return"boolean"==typeof e}(e)||d(e)||function(e){return"number"==typeof e&&!Number.isNaN(e)}(e)||!l(e)||c(e)&&e.every(p)||u(e)&&Object.values(e).every(p)}function v(e){return p(e)?e:void 0}function y(e,t,n){return async function(...r){try{return await e(...r)}catch(e){if(!t)return;return await t(e)}finally{await(null==n?void 0:n())}}}async function w(e,t={},n={}){var r;if(!l(e))return;const o=u(e)&&e.consent||n.consent||(null==(r=n.collector)?void 0:r.consent),i=c(t)?t:[t];for(const t of i){const r=await y(b)(e,t,{...n,consent:o});if(l(r))return r}}async function b(e,t,n={}){const{collector:r,consent:o}=n;return(c(t)?t:[t]).reduce(async(t,i)=>{const a=await t;if(a)return a;const s=d(i)?{key:i}:i;if(!Object.keys(s).length)return;const{condition:u,consent:p,fn:g,key:h,loop:P,map:m,set:j,validate:O,value:k}=s;if(u&&!await y(u)(e,i,r))return;if(p&&!function(e,t={},n={}){const r={...t,...n},o={};let i=!e||0===Object.keys(e).length;return Object.keys(r).forEach(t=>{r[t]&&(o[t]=!0,e&&e[t]&&(i=!0))}),!!i&&o}(p,o))return k;let E=l(k)?k:e;if(g&&(E=await y(g)(e,i,n)),h&&(E=f(e,h,k)),P){const[t,r]=P,o="this"===t?[e]:await w(e,t,n);c(o)&&(E=(await Promise.all(o.map(e=>w(e,r,n)))).filter(l))}else m?E=await Object.entries(m).reduce(async(t,[r,o])=>{const i=await t,a=await w(e,o,n);return l(a)&&(i[r]=a),i},Promise.resolve({})):j&&(E=await Promise.all(j.map(t=>b(e,t,n))));O&&!await y(O)(E)&&(E=void 0);const N=v(E);return l(N)?N:v(k)},Promise.resolve(void 0))}function g(e){return{window:"undefined"!=typeof window?window:globalThis.window,document:"undefined"!=typeof document?document:globalThis.document,...e}}var h={};function P(e){var t;if(null==(t=null==e?void 0:e.window)?void 0:t.heap)return e.window.heap;const{window:n}=g(e);return n.heap}function m(e){const t={};if(!u(e))return t;for(const[n,r]of Object.entries(e))"string"!=typeof r&&"number"!=typeof r&&"boolean"!=typeof r||(t[n]=r);return t}var j={type:"heap",config:{},init({config:e,env:t}){var n,r,o;const i=e.settings;if(!(null==i?void 0:i.appId))return!1;if(null==(n=null==t?void 0:t.window)?void 0:n.heap)return e;const{window:a,document:s}=g(t),c=a,l=s,u={disableTextCapture:null==(r=i.disableTextCapture)||r,disablePageviewAutocapture:null==(o=i.disablePageviewAutocapture)||o,...void 0!==i.disableSessionReplay&&{disableSessionReplay:i.disableSessionReplay},...void 0!==i.secureCookie&&{secureCookie:i.secureCookie},...void 0!==i.ingestServer&&{ingestServer:i.ingestServer},...i.heapConfig};if(!c.heap){const e={load:(t,n)=>{e.appid=t,e.config=null!=n?n:{}},track:()=>{},identify:()=>{},resetIdentity:()=>{},addUserProperties:()=>{},addEventProperties:()=>{},clearEventProperties:()=>{},startTracking:()=>{},stopTracking:()=>{},q:[]},t=["addEventProperties","addUserProperties","clearEventProperties","identify","resetIdentity","track","startTracking","stopTracking"];for(const n of t){const t=(...t)=>{e.q=e.q||[],e.q.push([n,...t])};e[n]=t}c.heap=e}e.loadScript&&function(e,t){const n=t.createElement("script");n.type="text/javascript",n.async=!0,n.src=`https://cdn.heapanalytics.com/js/heap-${e}.js`;const r=t.getElementsByTagName("script")[0];r&&r.parentNode?r.parentNode.insertBefore(n,r):t.head.appendChild(n)}(i.appId,l);const d=c.heap;return d.appid||d.load(i.appId,u),e},async push(e,{config:t,data:n,env:r,rule:o,collector:i}){var a,s;const c=P(r);if(!c)return;const l=t.settings||{},f=(null==o?void 0:o.settings)||{};if(void 0!==f.reset){("boolean"==typeof f.reset?f.reset:await w(e,f.reset,{collector:i}))&&c.resetIdentity()}const p=null!=(a=f.identify)?a:l.identify;if(void 0!==p){const t=await w(e,p,{collector:i});d(t)&&t.length>0&&c.identify(t)}const v=null!=(s=f.userProperties)?s:l.userProperties;if(void 0!==v){const t=await w(e,v,{collector:i});u(t)&&c.addUserProperties(m(t))}if(void 0!==f.eventProperties){const t=await w(e,f.eventProperties,{collector:i});u(t)&&c.addEventProperties(m(t))}if(void 0!==f.clearEventProperties){("boolean"==typeof f.clearEventProperties?f.clearEventProperties:await w(e,f.clearEventProperties,{collector:i}))&&c.clearEventProperties()}if(!0!==(null==o?void 0:o.skip)){const t=d(null==o?void 0:o.name)?o.name:e.name,r=m(n);c.track(t,r)}},on(e,t){var n;if("consent"!==e||!t.data)return;const r=P(t.env);if(!r)return;const o=null==(n=t.config)?void 0:n.consent;if(!o||0===Object.keys(o).length)return;const i=t.data;Object.keys(o).every(e=>!0===i[e])?r.startTracking():r.stopTracking()}};var O,k=j;return O=o,((o,i,a,s)=>{if(i&&"object"==typeof i||"function"==typeof i)for(let c of n(i))r.call(o,c)||c===a||e(o,c,{get:()=>i[c],enumerable:!(s=t(i,c))||s.enumerable});return o})(e({},"__esModule",{value:!0}),O)})();
@@ -0,0 +1,120 @@
1
+ import { Destination as Destination$1, Mapping as Mapping$1 } from '@walkeros/core';
2
+ import { DestinationWeb } from '@walkeros/web-core';
3
+
4
+ /** Property value types accepted by Heap SDK methods. */
5
+ type HeapPropertyValue = string | number | boolean;
6
+ /** Options accepted by heap.load() as the second argument. */
7
+ interface HeapConfig {
8
+ disableTextCapture?: boolean;
9
+ disablePageviewAutocapture?: boolean;
10
+ disableSessionReplay?: boolean;
11
+ secureCookie?: boolean;
12
+ compressCookies?: boolean;
13
+ clearEventPropertiesOnNewUser?: boolean;
14
+ ingestServer?: string;
15
+ trackingServer?: string;
16
+ eventPropertiesStorageMedium?: string;
17
+ metadataStorageMedium?: string;
18
+ [key: string]: unknown;
19
+ }
20
+ /**
21
+ * Heap SDK surface — the subset of window.heap methods this destination uses.
22
+ * Mirrors the snippet-provided command queue so tests can mock each method.
23
+ */
24
+ interface HeapSDK {
25
+ load: (appId: string, config?: HeapConfig) => void;
26
+ track: (event: string, properties?: Record<string, HeapPropertyValue>) => void;
27
+ identify: (identity: string) => void;
28
+ resetIdentity: () => void;
29
+ addUserProperties: (properties: Record<string, HeapPropertyValue>) => void;
30
+ addEventProperties: (properties: Record<string, HeapPropertyValue>) => void;
31
+ clearEventProperties: () => void;
32
+ startTracking: () => void;
33
+ stopTracking: () => void;
34
+ appid?: string;
35
+ config?: HeapConfig;
36
+ q?: unknown[][];
37
+ }
38
+ /**
39
+ * Settings (destination-level).
40
+ *
41
+ * appId is required (Heap Project Settings → App ID).
42
+ * identify/userProperties resolve every push to keep identity sticky.
43
+ */
44
+ interface Settings {
45
+ /** Heap App ID (required). Find it in Project > Settings > App ID. */
46
+ appId: string;
47
+ /** Disable Heap auto text capture. Default: true. */
48
+ disableTextCapture?: boolean;
49
+ /** Disable Heap automatic pageview tracking. Default: true (walkerOS handles pageviews). */
50
+ disablePageviewAutocapture?: boolean;
51
+ /** Disable Heap session replay. */
52
+ disableSessionReplay?: boolean;
53
+ /** SSL-only cookies. */
54
+ secureCookie?: boolean;
55
+ /** Custom server endpoint (first-party proxy). */
56
+ ingestServer?: string;
57
+ /** Destination-level identity mapping. Resolves to a string for heap.identify(). */
58
+ identify?: Mapping$1.Value;
59
+ /** Destination-level user properties mapping. Resolves to object for heap.addUserProperties(). */
60
+ userProperties?: Mapping$1.Value;
61
+ /** Additional heap.load() config passthrough. */
62
+ heapConfig?: HeapConfig;
63
+ }
64
+ type InitSettings = Partial<Settings>;
65
+ /**
66
+ * Mapping (rule.settings) — per-event overrides.
67
+ *
68
+ * identify — resolves to string for heap.identify()
69
+ * reset — truthy triggers heap.resetIdentity()
70
+ * userProperties — resolves to object for heap.addUserProperties()
71
+ * eventProperties — resolves to object for heap.addEventProperties() (persistent)
72
+ * clearEventProperties — truthy triggers heap.clearEventProperties()
73
+ */
74
+ interface Mapping {
75
+ identify?: Mapping$1.Value;
76
+ reset?: boolean | Mapping$1.Value;
77
+ userProperties?: Mapping$1.Value;
78
+ eventProperties?: Mapping$1.Value;
79
+ clearEventProperties?: boolean | Mapping$1.Value;
80
+ }
81
+ /**
82
+ * Env — optional override for the Heap SDK. Production leaves this
83
+ * undefined and the destination creates the snippet's command queue on
84
+ * window.heap. Tests provide a mock via env.window.heap = { ... }.
85
+ */
86
+ interface Env extends DestinationWeb.Env {
87
+ window: {
88
+ heap: HeapSDK;
89
+ };
90
+ }
91
+ declare global {
92
+ interface Window {
93
+ heap?: HeapSDK;
94
+ }
95
+ }
96
+ type Types = Destination$1.Types<Settings, Mapping, Env, InitSettings>;
97
+ type Destination = DestinationWeb.Destination<Types>;
98
+ type Config = DestinationWeb.Config<Types>;
99
+ type Rule = Mapping$1.Rule<Mapping>;
100
+ type Rules = Mapping$1.Rules<Rule>;
101
+
102
+ type index_Config = Config;
103
+ type index_Destination = Destination;
104
+ type index_Env = Env;
105
+ type index_HeapConfig = HeapConfig;
106
+ type index_HeapPropertyValue = HeapPropertyValue;
107
+ type index_HeapSDK = HeapSDK;
108
+ type index_InitSettings = InitSettings;
109
+ type index_Mapping = Mapping;
110
+ type index_Rule = Rule;
111
+ type index_Rules = Rules;
112
+ type index_Settings = Settings;
113
+ type index_Types = Types;
114
+ declare namespace index {
115
+ export type { index_Config as Config, index_Destination as Destination, index_Env as Env, index_HeapConfig as HeapConfig, index_HeapPropertyValue as HeapPropertyValue, index_HeapSDK as HeapSDK, index_InitSettings as InitSettings, index_Mapping as Mapping, index_Rule as Rule, index_Rules as Rules, index_Settings as Settings, index_Types as Types };
116
+ }
117
+
118
+ declare const destinationHeap: Destination;
119
+
120
+ export { index as DestinationHeap, destinationHeap as default, destinationHeap };
@@ -0,0 +1,120 @@
1
+ import { Destination as Destination$1, Mapping as Mapping$1 } from '@walkeros/core';
2
+ import { DestinationWeb } from '@walkeros/web-core';
3
+
4
+ /** Property value types accepted by Heap SDK methods. */
5
+ type HeapPropertyValue = string | number | boolean;
6
+ /** Options accepted by heap.load() as the second argument. */
7
+ interface HeapConfig {
8
+ disableTextCapture?: boolean;
9
+ disablePageviewAutocapture?: boolean;
10
+ disableSessionReplay?: boolean;
11
+ secureCookie?: boolean;
12
+ compressCookies?: boolean;
13
+ clearEventPropertiesOnNewUser?: boolean;
14
+ ingestServer?: string;
15
+ trackingServer?: string;
16
+ eventPropertiesStorageMedium?: string;
17
+ metadataStorageMedium?: string;
18
+ [key: string]: unknown;
19
+ }
20
+ /**
21
+ * Heap SDK surface — the subset of window.heap methods this destination uses.
22
+ * Mirrors the snippet-provided command queue so tests can mock each method.
23
+ */
24
+ interface HeapSDK {
25
+ load: (appId: string, config?: HeapConfig) => void;
26
+ track: (event: string, properties?: Record<string, HeapPropertyValue>) => void;
27
+ identify: (identity: string) => void;
28
+ resetIdentity: () => void;
29
+ addUserProperties: (properties: Record<string, HeapPropertyValue>) => void;
30
+ addEventProperties: (properties: Record<string, HeapPropertyValue>) => void;
31
+ clearEventProperties: () => void;
32
+ startTracking: () => void;
33
+ stopTracking: () => void;
34
+ appid?: string;
35
+ config?: HeapConfig;
36
+ q?: unknown[][];
37
+ }
38
+ /**
39
+ * Settings (destination-level).
40
+ *
41
+ * appId is required (Heap Project Settings → App ID).
42
+ * identify/userProperties resolve every push to keep identity sticky.
43
+ */
44
+ interface Settings {
45
+ /** Heap App ID (required). Find it in Project > Settings > App ID. */
46
+ appId: string;
47
+ /** Disable Heap auto text capture. Default: true. */
48
+ disableTextCapture?: boolean;
49
+ /** Disable Heap automatic pageview tracking. Default: true (walkerOS handles pageviews). */
50
+ disablePageviewAutocapture?: boolean;
51
+ /** Disable Heap session replay. */
52
+ disableSessionReplay?: boolean;
53
+ /** SSL-only cookies. */
54
+ secureCookie?: boolean;
55
+ /** Custom server endpoint (first-party proxy). */
56
+ ingestServer?: string;
57
+ /** Destination-level identity mapping. Resolves to a string for heap.identify(). */
58
+ identify?: Mapping$1.Value;
59
+ /** Destination-level user properties mapping. Resolves to object for heap.addUserProperties(). */
60
+ userProperties?: Mapping$1.Value;
61
+ /** Additional heap.load() config passthrough. */
62
+ heapConfig?: HeapConfig;
63
+ }
64
+ type InitSettings = Partial<Settings>;
65
+ /**
66
+ * Mapping (rule.settings) — per-event overrides.
67
+ *
68
+ * identify — resolves to string for heap.identify()
69
+ * reset — truthy triggers heap.resetIdentity()
70
+ * userProperties — resolves to object for heap.addUserProperties()
71
+ * eventProperties — resolves to object for heap.addEventProperties() (persistent)
72
+ * clearEventProperties — truthy triggers heap.clearEventProperties()
73
+ */
74
+ interface Mapping {
75
+ identify?: Mapping$1.Value;
76
+ reset?: boolean | Mapping$1.Value;
77
+ userProperties?: Mapping$1.Value;
78
+ eventProperties?: Mapping$1.Value;
79
+ clearEventProperties?: boolean | Mapping$1.Value;
80
+ }
81
+ /**
82
+ * Env — optional override for the Heap SDK. Production leaves this
83
+ * undefined and the destination creates the snippet's command queue on
84
+ * window.heap. Tests provide a mock via env.window.heap = { ... }.
85
+ */
86
+ interface Env extends DestinationWeb.Env {
87
+ window: {
88
+ heap: HeapSDK;
89
+ };
90
+ }
91
+ declare global {
92
+ interface Window {
93
+ heap?: HeapSDK;
94
+ }
95
+ }
96
+ type Types = Destination$1.Types<Settings, Mapping, Env, InitSettings>;
97
+ type Destination = DestinationWeb.Destination<Types>;
98
+ type Config = DestinationWeb.Config<Types>;
99
+ type Rule = Mapping$1.Rule<Mapping>;
100
+ type Rules = Mapping$1.Rules<Rule>;
101
+
102
+ type index_Config = Config;
103
+ type index_Destination = Destination;
104
+ type index_Env = Env;
105
+ type index_HeapConfig = HeapConfig;
106
+ type index_HeapPropertyValue = HeapPropertyValue;
107
+ type index_HeapSDK = HeapSDK;
108
+ type index_InitSettings = InitSettings;
109
+ type index_Mapping = Mapping;
110
+ type index_Rule = Rule;
111
+ type index_Rules = Rules;
112
+ type index_Settings = Settings;
113
+ type index_Types = Types;
114
+ declare namespace index {
115
+ export type { index_Config as Config, index_Destination as Destination, index_Env as Env, index_HeapConfig as HeapConfig, index_HeapPropertyValue as HeapPropertyValue, index_HeapSDK as HeapSDK, index_InitSettings as InitSettings, index_Mapping as Mapping, index_Rule as Rule, index_Rules as Rules, index_Settings as Settings, index_Types as Types };
116
+ }
117
+
118
+ declare const destinationHeap: Destination;
119
+
120
+ export { index as DestinationHeap, destinationHeap as default, destinationHeap };
@@ -0,0 +1 @@
1
+ "use strict";function _array_like_to_array(e,r){(null==r||r>e.length)&&(r=e.length);for(var t=0,n=new Array(r);t<r;t++)n[t]=e[t];return n}function _array_with_holes(e){if(Array.isArray(e))return e}function _array_without_holes(e){if(Array.isArray(e))return _array_like_to_array(e)}function asyncGeneratorStep(e,r,t,n,o,a,i){try{var c=e[a](i),l=c.value}catch(e){return void t(e)}c.done?r(l):Promise.resolve(l).then(n,o)}function _async_to_generator(e){return function(){var r=this,t=arguments;return new Promise(function(n,o){var a=e.apply(r,t);function i(e){asyncGeneratorStep(a,n,o,i,c,"next",e)}function c(e){asyncGeneratorStep(a,n,o,i,c,"throw",e)}i(void 0)})}}function _define_property(e,r,t){return r in e?Object.defineProperty(e,r,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[r]=t,e}function _instanceof(e,r){return null!=r&&"undefined"!=typeof Symbol&&r[Symbol.hasInstance]?!!r[Symbol.hasInstance](e):e instanceof r}function _iterable_to_array(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}function _iterable_to_array_limit(e,r){var t=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=t){var n,o,a=[],i=!0,c=!1;try{for(t=t.call(e);!(i=(n=t.next()).done)&&(a.push(n.value),!r||a.length!==r);i=!0);}catch(e){c=!0,o=e}finally{try{i||null==t.return||t.return()}finally{if(c)throw o}}return a}}function _non_iterable_rest(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function _non_iterable_spread(){throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function _object_spread(e){for(var r=1;r<arguments.length;r++){var t=null!=arguments[r]?arguments[r]:{},n=Object.keys(t);"function"==typeof Object.getOwnPropertySymbols&&(n=n.concat(Object.getOwnPropertySymbols(t).filter(function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),n.forEach(function(r){_define_property(e,r,t[r])})}return e}function ownKeys(e,r){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);r&&(n=n.filter(function(r){return Object.getOwnPropertyDescriptor(e,r).enumerable})),t.push.apply(t,n)}return t}function _object_spread_props(e,r){return r=null!=r?r:{},Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):ownKeys(Object(r)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}),e}function _sliced_to_array(e,r){return _array_with_holes(e)||_iterable_to_array_limit(e,r)||_unsupported_iterable_to_array(e,r)||_non_iterable_rest()}function _to_consumable_array(e){return _array_without_holes(e)||_iterable_to_array(e)||_unsupported_iterable_to_array(e)||_non_iterable_spread()}function _type_of(e){return e&&"undefined"!=typeof Symbol&&e.constructor===Symbol?"symbol":typeof e}function _unsupported_iterable_to_array(e,r){if(e){if("string"==typeof e)return _array_like_to_array(e,r);var t=Object.prototype.toString.call(e).slice(8,-1);return"Object"===t&&e.constructor&&(t=e.constructor.name),"Map"===t||"Set"===t?Array.from(t):"Arguments"===t||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t)?_array_like_to_array(e,r):void 0}}function _ts_generator(e,r){var t,n,o,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]},i=Object.create(("function"==typeof Iterator?Iterator:Object).prototype),c=Object.defineProperty;return c(i,"next",{value:l(0)}),c(i,"throw",{value:l(1)}),c(i,"return",{value:l(2)}),"function"==typeof Symbol&&c(i,Symbol.iterator,{value:function(){return this}}),i;function l(c){return function(l){return function(c){if(t)throw new TypeError("Generator is already executing.");for(;i&&(i=0,c[0]&&(a=0)),a;)try{if(t=1,n&&(o=2&c[0]?n.return:c[0]?n.throw||((o=n.return)&&o.call(n),0):n.next)&&!(o=o.call(n,c[1])).done)return o;switch(n=0,o&&(c=[2&c[0],o.value]),c[0]){case 0:case 1:o=c;break;case 4:return a.label++,{value:c[1],done:!1};case 5:a.label++,n=c[1],c=[0];continue;case 7:c=a.ops.pop(),a.trys.pop();continue;default:if(!(o=a.trys,(o=o.length>0&&o[o.length-1])||6!==c[0]&&2!==c[0])){a=0;continue}if(3===c[0]&&(!o||c[1]>o[0]&&c[1]<o[3])){a.label=c[1];break}if(6===c[0]&&a.label<o[1]){a.label=o[1],o=c;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(c);break}o[2]&&a.ops.pop(),a.trys.pop();continue}c=r.call(e,a)}catch(e){c=[6,e],n=0}finally{t=o=0}if(5&c[0])throw c[1];return{value:c[0]?c[1]:void 0,done:!0}}([c,l])}}}var Destination=function(){var e=function(e){return Array.isArray(e)},r=function(e){return void 0!==e},t=function(r){return"object"==(void 0===r?"undefined":_type_of(r))&&null!==r&&!e(r)&&"[object Object]"===Object.prototype.toString.call(r)},n=function(e){return"string"==typeof e},o=function(e){return g(e)?e:void 0},a=function(e,r,t){return function(){for(var n=arguments.length,o=new Array(n),a=0;a<n;a++)o[a]=arguments[a];return _async_to_generator(function(){var n;return _ts_generator(this,function(a){switch(a.label){case 0:return a.trys.push([0,2,4,6]),[4,e.apply(void 0,_to_consumable_array(o))];case 1:case 3:return[2,a.sent()];case 2:return n=a.sent(),r?[4,r(n)]:[2];case 4:return[4,null==t?void 0:t()];case 5:return a.sent(),[7];case 6:return[2]}})})()}},i=function(n){return _async_to_generator(function(n){var o,i,c,l,u,s,f,y,p,d,v,b,_,h=arguments;return _ts_generator(this,function(g){switch(g.label){case 0:if(o=h.length>1&&void 0!==h[1]?h[1]:{},i=h.length>2&&void 0!==h[2]?h[2]:{},!r(n))return[2];l=t(n)&&n.consent||i.consent||(null===(c=i.collector)||void 0===c?void 0:c.consent),u=e(o)?o:[o],s=!0,f=!1,y=void 0,g.label=1;case 1:g.trys.push([1,6,7,8]),p=u[Symbol.iterator](),g.label=2;case 2:return(s=(d=p.next()).done)?[3,5]:(v=d.value,[4,a(m)(n,v,_object_spread_props(_object_spread({},i),{consent:l}))]);case 3:if(b=g.sent(),r(b))return[2,b];g.label=4;case 4:return s=!0,[3,2];case 5:return[3,8];case 6:return _=g.sent(),f=!0,y=_,[3,8];case 7:try{s||null==p.return||p.return()}finally{if(f)throw y}return[7];case 8:return[2]}})}).apply(this,arguments)},c=function(e){return _object_spread({window:"undefined"!=typeof window?window:globalThis.window,document:"undefined"!=typeof document?document:globalThis.document},e)},l=function(e){var r;return(null==e||null===(r=e.window)||void 0===r?void 0:r.heap)?e.window.heap:c(e).window.heap},u=function(e){var r={};if(!t(e))return r;var n=!0,o=!1,a=void 0;try{for(var i,c=Object.entries(e)[Symbol.iterator]();!(n=(i=c.next()).done);n=!0){var l=_sliced_to_array(i.value,2),u=l[0],s=l[1];"string"!=typeof s&&"number"!=typeof s&&"boolean"!=typeof s||(r[u]=s)}}catch(e){o=!0,a=e}finally{try{n||null==c.return||c.return()}finally{if(o)throw a}}return r},s=Object.defineProperty,f=Object.getOwnPropertyDescriptor,y=Object.getOwnPropertyNames,p=Object.prototype.hasOwnProperty,d={};!function(e,r){for(var t in r)s(e,t,{get:r[t],enumerable:!0})}(d,{DestinationHeap:function(){return j},default:function(){return P},destinationHeap:function(){return O}});var v=Object.defineProperty;!function(e,r){for(var t in r)v(e,t,{get:r[t],enumerable:!0})}({},{Level:function(){return _}});var b,_=((b=_||{})[b.ERROR=0]="ERROR",b[b.WARN=1]="WARN",b[b.INFO=2]="INFO",b[b.DEBUG=3]="DEBUG",b);function h(t){for(var n=arguments.length>2?arguments[2]:void 0,o=(arguments.length>1&&void 0!==arguments[1]?arguments[1]:"").split("."),a=t,i=0;i<o.length;i++){var c=o[i];if("*"===c&&e(a)){var l=o.slice(i+1).join("."),u=[],s=!0,f=!1,y=void 0;try{for(var p,d=a[Symbol.iterator]();!(s=(p=d.next()).done);s=!0){var v=h(p.value,l,n);u.push(v)}}catch(e){f=!0,y=e}finally{try{s||null==d.return||d.return()}finally{if(f)throw y}}return u}if(void 0===(a=_instanceof(a,Object)?a[c]:void 0))break}return r(a)?a:n}function g(o){return function(e){return"boolean"==typeof e}(o)||n(o)||function(e){return"number"==typeof e&&!Number.isNaN(e)}(o)||!r(o)||e(o)&&o.every(g)||t(o)&&Object.values(o).every(g)}function m(t,c){return _async_to_generator(function(t,c){var l,u,s,f=arguments;return _ts_generator(this,function(y){return u=(l=f.length>2&&void 0!==f[2]?f[2]:{}).collector,s=l.consent,[2,(e(c)?c:[c]).reduce(function(c,f){return _async_to_generator(function(){var y,p,d,v,b,_,g,w,j,O,P,S,k,E,A,I,T,x,N,R,D;return _ts_generator(this,function(C){switch(C.label){case 0:return[4,c];case 1:return(y=C.sent())?[2,y]:(p=n(f)?{key:f}:f,Object.keys(p).length?(d=p.condition,v=p.consent,b=p.fn,_=p.key,g=p.loop,w=p.map,j=p.set,O=p.validate,P=p.value,(S=d)?[4,a(d)(t,f,u)]:[3,3]):[2]);case 2:S=!C.sent(),C.label=3;case 3:return S?[2]:v&&!function(e){var r=_object_spread({},arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},arguments.length>2&&void 0!==arguments[2]?arguments[2]:{}),t={},n=!e||0===Object.keys(e).length;return Object.keys(r).forEach(function(o){r[o]&&(t[o]=!0,e&&e[o]&&(n=!0))}),!!n&&t}(v,s)?[2,P]:(k=r(P)?P:t,b?[4,a(b)(t,f,l)]:[3,5]);case 4:k=C.sent(),C.label=5;case 5:return _&&(k=h(t,_,P)),g?(E=_sliced_to_array(g,2),A=E[0],I=E[1],"this"!==A?[3,6]:(x=[t],[3,8])):[3,11];case 6:return[4,i(t,A,l)];case 7:x=C.sent(),C.label=8;case 8:return e(T=x)?[4,Promise.all(T.map(function(e){return i(e,I,l)}))]:[3,10];case 9:k=C.sent().filter(r),C.label=10;case 10:return[3,17];case 11:return w?[4,Object.entries(w).reduce(function(e,n){var o=_sliced_to_array(n,2),a=o[0],c=o[1];return _async_to_generator(function(){var n,o;return _ts_generator(this,function(u){switch(u.label){case 0:return[4,e];case 1:return n=u.sent(),[4,i(t,c,l)];case 2:return o=u.sent(),[2,(r(o)&&(n[a]=o),n)]}})})()},Promise.resolve({}))]:[3,13];case 12:return k=C.sent(),[3,16];case 13:return(N=j)?[4,Promise.all(j.map(function(e){return m(t,e,l)}))]:[3,15];case 14:N=k=C.sent(),C.label=15;case 15:C.label=16;case 16:C.label=17;case 17:return(R=O)?[4,a(O)(k)]:[3,19];case 18:R=!C.sent(),C.label=19;case 19:return R&&(k=void 0),D=o(k),[2,r(D)?D:o(P)]}})})()},Promise.resolve(void 0))]})}).apply(this,arguments)}var w,j={},O={type:"heap",config:{},init:function(e){var r,t,n,o=e.config,a=e.env,i=o.settings;if(!(null==i?void 0:i.appId))return!1;if(null==a||null===(n=a.window)||void 0===n?void 0:n.heap)return o;var l=c(a),u=l.window,s=l.document,f=_object_spread({disableTextCapture:null===(r=i.disableTextCapture)||void 0===r||r,disablePageviewAutocapture:null===(t=i.disablePageviewAutocapture)||void 0===t||t},void 0!==i.disableSessionReplay&&{disableSessionReplay:i.disableSessionReplay},void 0!==i.secureCookie&&{secureCookie:i.secureCookie},void 0!==i.ingestServer&&{ingestServer:i.ingestServer},i.heapConfig);if(!u.heap){var y={load:function(e,r){y.appid=e,y.config=null!=r?r:{}},track:function(){},identify:function(){},resetIdentity:function(){},addUserProperties:function(){},addEventProperties:function(){},clearEventProperties:function(){},startTracking:function(){},stopTracking:function(){},q:[]},p=!0,d=!1,v=void 0;try{for(var b,_=function(){var e=b.value;y[e]=function(){for(var r=arguments.length,t=new Array(r),n=0;n<r;n++)t[n]=arguments[n];y.q=y.q||[],y.q.push([e].concat(_to_consumable_array(t)))}},h=["addEventProperties","addUserProperties","clearEventProperties","identify","resetIdentity","track","startTracking","stopTracking"][Symbol.iterator]();!(p=(b=h.next()).done);p=!0)_()}catch(e){d=!0,v=e}finally{try{p||null==h.return||h.return()}finally{if(d)throw v}}u.heap=y}o.loadScript&&function(e,r){var t=r.createElement("script");t.type="text/javascript",t.async=!0,t.src="https://cdn.heapanalytics.com/js/heap-".concat(e,".js");var n=r.getElementsByTagName("script")[0];n&&n.parentNode?n.parentNode.insertBefore(t,n):r.head.appendChild(t)}(i.appId,s);var g=u.heap;return g.appid||g.load(i.appId,f),o},push:function(e,r){return _async_to_generator(function(e,r){var o,a,c,s,f,y,p,d,v,b,_,h,g,m,w,j,O,P,S;return _ts_generator(this,function(k){switch(k.label){case 0:return o=r.config,a=r.data,c=r.env,s=r.rule,f=r.collector,(d=l(c))?(v=o.settings||{},void 0===(b=(null==s?void 0:s.settings)||{}).reset?[3,4]:"boolean"!=typeof b.reset?[3,1]:(_=b.reset,[3,3])):[2];case 1:return[4,i(e,b.reset,{collector:f})];case 2:_=k.sent(),k.label=3;case 3:_&&d.resetIdentity(),k.label=4;case 4:return void 0===(h=null!==(y=b.identify)&&void 0!==y?y:v.identify)?[3,6]:[4,i(e,h,{collector:f})];case 5:g=k.sent(),n(g)&&g.length>0&&d.identify(g),k.label=6;case 6:return void 0===(m=null!==(p=b.userProperties)&&void 0!==p?p:v.userProperties)?[3,8]:[4,i(e,m,{collector:f})];case 7:w=k.sent(),t(w)&&d.addUserProperties(u(w)),k.label=8;case 8:return void 0===b.eventProperties?[3,10]:[4,i(e,b.eventProperties,{collector:f})];case 9:j=k.sent(),t(j)&&d.addEventProperties(u(j)),k.label=10;case 10:return void 0===b.clearEventProperties?[3,14]:"boolean"!=typeof b.clearEventProperties?[3,11]:(O=b.clearEventProperties,[3,13]);case 11:return[4,i(e,b.clearEventProperties,{collector:f})];case 12:O=k.sent(),k.label=13;case 13:O&&d.clearEventProperties(),k.label=14;case 14:return!0!==(null==s?void 0:s.skip)&&(P=n(null==s?void 0:s.name)?s.name:e.name,S=u(a),d.track(P,S)),[2]}})}).apply(this,arguments)},on:function(e,r){var t;if("consent"===e&&r.data){var n=l(r.env);if(n){var o=null===(t=r.config)||void 0===t?void 0:t.consent;if(o&&0!==Object.keys(o).length){var a=r.data;Object.keys(o).every(function(e){return!0===a[e]})?n.startTracking():n.stopTracking()}}}}},P=O;return w=d,function(e,r,t,n){if(r&&"object"===(void 0===r?"undefined":_type_of(r))||"function"==typeof r){var o=!0,a=!1,i=void 0;try{for(var c,l=function(){var o=c.value;p.call(e,o)||o===t||s(e,o,{get:function(){return r[o]},enumerable:!(n=f(r,o))||n.enumerable})},u=y(r)[Symbol.iterator]();!(o=(c=u.next()).done);o=!0)l()}catch(e){a=!0,i=e}finally{try{o||null==u.return||u.return()}finally{if(a)throw i}}}return e}(s({},"__esModule",{value:!0}),w)}();
package/dist/index.js ADDED
@@ -0,0 +1 @@
1
+ "use strict";var e,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,r=Object.getOwnPropertyNames,o=Object.prototype.hasOwnProperty,i={};((e,n)=>{for(var r in n)t(e,r,{get:n[r],enumerable:!0})})(i,{DestinationHeap:()=>h,default:()=>k,destinationHeap:()=>O}),module.exports=(e=i,((e,i,a,s)=>{if(i&&"object"==typeof i||"function"==typeof i)for(let c of r(i))o.call(e,c)||c===a||t(e,c,{get:()=>i[c],enumerable:!(s=n(i,c))||s.enumerable});return e})(t({},"__esModule",{value:!0}),e));var a=Object.defineProperty;((e,t)=>{for(var n in t)a(e,n,{get:t[n],enumerable:!0})})({},{Level:()=>c});var s,c=((s=c||{})[s.ERROR=0]="ERROR",s[s.WARN=1]="WARN",s[s.INFO=2]="INFO",s[s.DEBUG=3]="DEBUG",s);function l(e){return Array.isArray(e)}function u(e){return void 0!==e}function p(e){return"object"==typeof e&&null!==e&&!l(e)&&"[object Object]"===Object.prototype.toString.call(e)}function f(e){return"string"==typeof e}function d(e,t="",n){const r=t.split(".");let o=e;for(let e=0;e<r.length;e++){const t=r[e];if("*"===t&&l(o)){const t=r.slice(e+1).join("."),i=[];for(const e of o){const r=d(e,t,n);i.push(r)}return i}if(o=o instanceof Object?o[t]:void 0,void 0===o)break}return u(o)?o:n}function v(e){return function(e){return"boolean"==typeof e}(e)||f(e)||function(e){return"number"==typeof e&&!Number.isNaN(e)}(e)||!u(e)||l(e)&&e.every(v)||p(e)&&Object.values(e).every(v)}function y(e){return v(e)?e:void 0}function b(e,t,n){return async function(...r){try{return await e(...r)}catch(e){if(!t)return;return await t(e)}finally{await(null==n?void 0:n())}}}async function g(e,t={},n={}){var r;if(!u(e))return;const o=p(e)&&e.consent||n.consent||(null==(r=n.collector)?void 0:r.consent),i=l(t)?t:[t];for(const t of i){const r=await b(w)(e,t,{...n,consent:o});if(u(r))return r}}async function w(e,t,n={}){const{collector:r,consent:o}=n;return(l(t)?t:[t]).reduce(async(t,i)=>{const a=await t;if(a)return a;const s=f(i)?{key:i}:i;if(!Object.keys(s).length)return;const{condition:c,consent:p,fn:v,key:P,loop:h,map:m,set:j,validate:O,value:k}=s;if(c&&!await b(c)(e,i,r))return;if(p&&!function(e,t={},n={}){const r={...t,...n},o={};let i=!e||0===Object.keys(e).length;return Object.keys(r).forEach(t=>{r[t]&&(o[t]=!0,e&&e[t]&&(i=!0))}),!!i&&o}(p,o))return k;let E=u(k)?k:e;if(v&&(E=await b(v)(e,i,n)),P&&(E=d(e,P,k)),h){const[t,r]=h,o="this"===t?[e]:await g(e,t,n);l(o)&&(E=(await Promise.all(o.map(e=>g(e,r,n)))).filter(u))}else m?E=await Object.entries(m).reduce(async(t,[r,o])=>{const i=await t,a=await g(e,o,n);return u(a)&&(i[r]=a),i},Promise.resolve({})):j&&(E=await Promise.all(j.map(t=>w(e,t,n))));O&&!await b(O)(E)&&(E=void 0);const N=y(E);return u(N)?N:y(k)},Promise.resolve(void 0))}var P=require("@walkeros/web-core"),h={};function m(e){var t;if(null==(t=null==e?void 0:e.window)?void 0:t.heap)return e.window.heap;const{window:n}=(0,P.getEnv)(e);return n.heap}function j(e){const t={};if(!p(e))return t;for(const[n,r]of Object.entries(e))"string"!=typeof r&&"number"!=typeof r&&"boolean"!=typeof r||(t[n]=r);return t}var O={type:"heap",config:{},init({config:e,env:t}){var n,r,o;const i=e.settings;if(!(null==i?void 0:i.appId))return!1;if(null==(n=null==t?void 0:t.window)?void 0:n.heap)return e;const{window:a,document:s}=(0,P.getEnv)(t),c=a,l=s,u={disableTextCapture:null==(r=i.disableTextCapture)||r,disablePageviewAutocapture:null==(o=i.disablePageviewAutocapture)||o,...void 0!==i.disableSessionReplay&&{disableSessionReplay:i.disableSessionReplay},...void 0!==i.secureCookie&&{secureCookie:i.secureCookie},...void 0!==i.ingestServer&&{ingestServer:i.ingestServer},...i.heapConfig};if(!c.heap){const e={load:(t,n)=>{e.appid=t,e.config=null!=n?n:{}},track:()=>{},identify:()=>{},resetIdentity:()=>{},addUserProperties:()=>{},addEventProperties:()=>{},clearEventProperties:()=>{},startTracking:()=>{},stopTracking:()=>{},q:[]},t=["addEventProperties","addUserProperties","clearEventProperties","identify","resetIdentity","track","startTracking","stopTracking"];for(const n of t){const t=(...t)=>{e.q=e.q||[],e.q.push([n,...t])};e[n]=t}c.heap=e}e.loadScript&&function(e,t){const n=t.createElement("script");n.type="text/javascript",n.async=!0,n.src=`https://cdn.heapanalytics.com/js/heap-${e}.js`;const r=t.getElementsByTagName("script")[0];r&&r.parentNode?r.parentNode.insertBefore(n,r):t.head.appendChild(n)}(i.appId,l);const p=c.heap;return p.appid||p.load(i.appId,u),e},async push(e,{config:t,data:n,env:r,rule:o,collector:i}){var a,s;const c=m(r);if(!c)return;const l=t.settings||{},u=(null==o?void 0:o.settings)||{};if(void 0!==u.reset){("boolean"==typeof u.reset?u.reset:await g(e,u.reset,{collector:i}))&&c.resetIdentity()}const d=null!=(a=u.identify)?a:l.identify;if(void 0!==d){const t=await g(e,d,{collector:i});f(t)&&t.length>0&&c.identify(t)}const v=null!=(s=u.userProperties)?s:l.userProperties;if(void 0!==v){const t=await g(e,v,{collector:i});p(t)&&c.addUserProperties(j(t))}if(void 0!==u.eventProperties){const t=await g(e,u.eventProperties,{collector:i});p(t)&&c.addEventProperties(j(t))}if(void 0!==u.clearEventProperties){("boolean"==typeof u.clearEventProperties?u.clearEventProperties:await g(e,u.clearEventProperties,{collector:i}))&&c.clearEventProperties()}if(!0!==(null==o?void 0:o.skip)){const t=f(null==o?void 0:o.name)?o.name:e.name,r=j(n);c.track(t,r)}},on(e,t){var n;if("consent"!==e||!t.data)return;const r=m(t.env);if(!r)return;const o=null==(n=t.config)?void 0:n.consent;if(!o||0===Object.keys(o).length)return;const i=t.data;Object.keys(o).every(e=>!0===i[e])?r.startTracking():r.stopTracking()}};var k=O;//# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts","../src/types/index.ts"],"sourcesContent":["import type { DestinationWeb } from '@walkeros/web-core';\nimport { getMappingValue, isObject, isString } from '@walkeros/core';\nimport { getEnv } from '@walkeros/web-core';\nimport type {\n Destination,\n Env,\n HeapConfig,\n HeapPropertyValue,\n HeapSDK,\n Mapping,\n Settings,\n} from './types';\n\n// Types export\nexport * as DestinationHeap from './types';\n\n/**\n * Resolve the Heap SDK: prefer the caller-provided mock (tests) via\n * env.window.heap, otherwise fall back to the global window.heap the\n * init function established (real snippet command queue).\n */\nfunction getHeap(env: Env | undefined): HeapSDK | undefined {\n if (env?.window?.heap) return env.window.heap;\n const { window } = getEnv(env as DestinationWeb.Env | undefined);\n return (window as Window).heap;\n}\n\n/**\n * Coerce a resolved object into a flat { key: primitive } map suitable\n * for Heap's property APIs. Drops non-primitive values.\n */\nfunction toHeapProperties(value: unknown): Record<string, HeapPropertyValue> {\n const out: Record<string, HeapPropertyValue> = {};\n if (!isObject(value)) return out;\n for (const [key, val] of Object.entries(value)) {\n if (\n typeof val === 'string' ||\n typeof val === 'number' ||\n typeof val === 'boolean'\n ) {\n out[key] = val;\n }\n }\n return out;\n}\n\nexport const destinationHeap: Destination = {\n type: 'heap',\n\n config: {},\n\n init({ config, env }) {\n const settings = config.settings;\n if (!settings?.appId) return false;\n\n // In tests a mock is provided via env.window.heap and there's nothing\n // for us to bootstrap. In production we install the Heap snippet's\n // command queue and call heap.load().\n if (env?.window?.heap) return config;\n\n const { window, document } = getEnv(env as DestinationWeb.Env | undefined);\n const w = window as Window;\n const doc = document as Document;\n\n const heapConfig: HeapConfig = {\n disableTextCapture: settings.disableTextCapture ?? true,\n disablePageviewAutocapture: settings.disablePageviewAutocapture ?? true,\n ...(settings.disableSessionReplay !== undefined && {\n disableSessionReplay: settings.disableSessionReplay,\n }),\n ...(settings.secureCookie !== undefined && {\n secureCookie: settings.secureCookie,\n }),\n ...(settings.ingestServer !== undefined && {\n ingestServer: settings.ingestServer,\n }),\n ...settings.heapConfig,\n };\n\n // Install the Heap snippet's command queue if not already present.\n if (!w.heap) {\n const heap: HeapSDK = {\n load: (appId: string, cfg?: HeapConfig) => {\n heap.appid = appId;\n heap.config = cfg ?? {};\n },\n track: (() => undefined) as HeapSDK['track'],\n identify: (() => undefined) as HeapSDK['identify'],\n resetIdentity: () => undefined,\n addUserProperties: (() => undefined) as HeapSDK['addUserProperties'],\n addEventProperties: (() => undefined) as HeapSDK['addEventProperties'],\n clearEventProperties: () => undefined,\n startTracking: () => undefined,\n stopTracking: () => undefined,\n q: [],\n };\n\n // Queue all calls until the real snippet boots and replaces these.\n const methods: Array<keyof HeapSDK> = [\n 'addEventProperties',\n 'addUserProperties',\n 'clearEventProperties',\n 'identify',\n 'resetIdentity',\n 'track',\n 'startTracking',\n 'stopTracking',\n ];\n for (const method of methods) {\n const queue = (...args: unknown[]) => {\n heap.q = heap.q || [];\n heap.q.push([method, ...args]);\n };\n (heap as unknown as Record<string, (...args: unknown[]) => void>)[\n method as string\n ] = queue;\n }\n\n w.heap = heap;\n }\n\n // Load real snippet script unless disabled.\n if (config.loadScript) addScript(settings.appId, doc);\n\n const heap = w.heap as HeapSDK;\n if (!heap.appid) heap.load(settings.appId, heapConfig);\n\n return config;\n },\n\n async push(event, { config, data, env, rule, collector }) {\n const heap = getHeap(env as Env | undefined);\n if (!heap) return;\n\n const settings = (config.settings || {}) as Partial<Settings>;\n const mappingSettings = (rule?.settings || {}) as Mapping;\n\n // 1. Reset identity first — subsequent identify/userProperties\n // operate on the fresh anonymous user.\n if (mappingSettings.reset !== undefined) {\n const resolved =\n typeof mappingSettings.reset === 'boolean'\n ? mappingSettings.reset\n : await getMappingValue(event, mappingSettings.reset, { collector });\n if (resolved) heap.resetIdentity();\n }\n\n // 2. Identify — rule-level wins over destination-level.\n const identifyMapping = mappingSettings.identify ?? settings.identify;\n if (identifyMapping !== undefined) {\n const resolved = await getMappingValue(event, identifyMapping, {\n collector,\n });\n if (isString(resolved) && resolved.length > 0) {\n heap.identify(resolved);\n }\n }\n\n // 3. User properties — rule-level wins over destination-level.\n const userPropsMapping =\n mappingSettings.userProperties ?? settings.userProperties;\n if (userPropsMapping !== undefined) {\n const resolved = await getMappingValue(event, userPropsMapping, {\n collector,\n });\n if (isObject(resolved)) {\n heap.addUserProperties(toHeapProperties(resolved));\n }\n }\n\n // 4. Persistent event properties.\n if (mappingSettings.eventProperties !== undefined) {\n const resolved = await getMappingValue(\n event,\n mappingSettings.eventProperties,\n { collector },\n );\n if (isObject(resolved)) {\n heap.addEventProperties(toHeapProperties(resolved));\n }\n }\n\n // 5. Clear persistent event properties.\n if (mappingSettings.clearEventProperties !== undefined) {\n const resolved =\n typeof mappingSettings.clearEventProperties === 'boolean'\n ? mappingSettings.clearEventProperties\n : await getMappingValue(event, mappingSettings.clearEventProperties, {\n collector,\n });\n if (resolved) heap.clearEventProperties();\n }\n\n // 6. Default track — unless rule.skip is set.\n if (rule?.skip !== true) {\n const eventName = isString(rule?.name) ? rule.name : event.name;\n const properties = toHeapProperties(data);\n heap.track(eventName, properties);\n }\n },\n\n on(type, context) {\n if (type !== 'consent' || !context.data) return;\n\n const heap = getHeap(context.env as Env | undefined);\n if (!heap) return;\n\n const required = context.config?.consent;\n if (!required || Object.keys(required).length === 0) return;\n\n const consent = context.data as Record<string, boolean>;\n const allGranted = Object.keys(required).every(\n (key) => consent[key] === true,\n );\n\n if (allGranted) heap.startTracking();\n else heap.stopTracking();\n },\n};\n\nfunction addScript(appId: string, doc: Document) {\n const script = doc.createElement('script');\n script.type = 'text/javascript';\n script.async = true;\n script.src = `https://cdn.heapanalytics.com/js/heap-${appId}.js`;\n const firstScript = doc.getElementsByTagName('script')[0];\n if (firstScript && firstScript.parentNode) {\n firstScript.parentNode.insertBefore(script, firstScript);\n } else {\n doc.head.appendChild(script);\n }\n}\n\nexport default destinationHeap;\n","import type {\n Mapping as WalkerOSMapping,\n Destination as CoreDestination,\n} from '@walkeros/core';\nimport type { DestinationWeb } from '@walkeros/web-core';\n\n/** Property value types accepted by Heap SDK methods. */\nexport type HeapPropertyValue = string | number | boolean;\n\n/** Options accepted by heap.load() as the second argument. */\nexport interface HeapConfig {\n disableTextCapture?: boolean;\n disablePageviewAutocapture?: boolean;\n disableSessionReplay?: boolean;\n secureCookie?: boolean;\n compressCookies?: boolean;\n clearEventPropertiesOnNewUser?: boolean;\n ingestServer?: string;\n trackingServer?: string;\n eventPropertiesStorageMedium?: string;\n metadataStorageMedium?: string;\n [key: string]: unknown;\n}\n\n/**\n * Heap SDK surface — the subset of window.heap methods this destination uses.\n * Mirrors the snippet-provided command queue so tests can mock each method.\n */\nexport interface HeapSDK {\n load: (appId: string, config?: HeapConfig) => void;\n track: (\n event: string,\n properties?: Record<string, HeapPropertyValue>,\n ) => void;\n identify: (identity: string) => void;\n resetIdentity: () => void;\n addUserProperties: (properties: Record<string, HeapPropertyValue>) => void;\n addEventProperties: (properties: Record<string, HeapPropertyValue>) => void;\n clearEventProperties: () => void;\n startTracking: () => void;\n stopTracking: () => void;\n appid?: string;\n config?: HeapConfig;\n q?: unknown[][];\n}\n\n/**\n * Settings (destination-level).\n *\n * appId is required (Heap Project Settings → App ID).\n * identify/userProperties resolve every push to keep identity sticky.\n */\nexport interface Settings {\n /** Heap App ID (required). Find it in Project > Settings > App ID. */\n appId: string;\n /** Disable Heap auto text capture. Default: true. */\n disableTextCapture?: boolean;\n /** Disable Heap automatic pageview tracking. Default: true (walkerOS handles pageviews). */\n disablePageviewAutocapture?: boolean;\n /** Disable Heap session replay. */\n disableSessionReplay?: boolean;\n /** SSL-only cookies. */\n secureCookie?: boolean;\n /** Custom server endpoint (first-party proxy). */\n ingestServer?: string;\n /** Destination-level identity mapping. Resolves to a string for heap.identify(). */\n identify?: WalkerOSMapping.Value;\n /** Destination-level user properties mapping. Resolves to object for heap.addUserProperties(). */\n userProperties?: WalkerOSMapping.Value;\n /** Additional heap.load() config passthrough. */\n heapConfig?: HeapConfig;\n}\n\nexport type InitSettings = Partial<Settings>;\n\n/**\n * Mapping (rule.settings) — per-event overrides.\n *\n * identify — resolves to string for heap.identify()\n * reset — truthy triggers heap.resetIdentity()\n * userProperties — resolves to object for heap.addUserProperties()\n * eventProperties — resolves to object for heap.addEventProperties() (persistent)\n * clearEventProperties — truthy triggers heap.clearEventProperties()\n */\nexport interface Mapping {\n identify?: WalkerOSMapping.Value;\n reset?: boolean | WalkerOSMapping.Value;\n userProperties?: WalkerOSMapping.Value;\n eventProperties?: WalkerOSMapping.Value;\n clearEventProperties?: boolean | WalkerOSMapping.Value;\n}\n\n/**\n * Env — optional override for the Heap SDK. Production leaves this\n * undefined and the destination creates the snippet's command queue on\n * window.heap. Tests provide a mock via env.window.heap = { ... }.\n */\nexport interface Env extends DestinationWeb.Env {\n window: {\n heap: HeapSDK;\n };\n}\n\ndeclare global {\n interface Window {\n heap?: HeapSDK;\n }\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"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;A;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEA,sBAAuB;;;ACFvB;;;ADqBA,SAAS,QAAQ,KAA2C;AArB5D;AAsBE,OAAI,gCAAK,WAAL,mBAAa,KAAM,QAAO,IAAI,OAAO;AACzC,QAAM,EAAE,OAAO,QAAI,wBAAO,GAAqC;AAC/D,SAAQ,OAAkB;AAC5B;AAMA,SAAS,iBAAiB,OAAmD;AAC3E,QAAM,MAAyC,CAAC;AAChD,MAAI,CAAC,EAAS,KAAK,EAAG,QAAO;AAC7B,aAAW,CAAC,KAAK,GAAG,KAAK,OAAO,QAAQ,KAAK,GAAG;AAC9C,QACE,OAAO,QAAQ,YACf,OAAO,QAAQ,YACf,OAAO,QAAQ,WACf;AACA,UAAI,GAAG,IAAI;AAAA,IACb;AAAA,EACF;AACA,SAAO;AACT;AAEO,IAAM,kBAA+B;AAAA,EAC1C,MAAM;AAAA,EAEN,QAAQ,CAAC;AAAA,EAET,KAAK,EAAE,QAAQ,IAAI,GAAG;AAnDxB;AAoDI,UAAM,WAAW,OAAO;AACxB,QAAI,EAAC,qCAAU,OAAO,QAAO;AAK7B,SAAI,gCAAK,WAAL,mBAAa,KAAM,QAAO;AAE9B,UAAM,EAAE,QAAQ,SAAS,QAAI,wBAAO,GAAqC;AACzE,UAAM,IAAI;AACV,UAAM,MAAM;AAEZ,UAAM,aAAyB;AAAA,MAC7B,qBAAoB,cAAS,uBAAT,YAA+B;AAAA,MACnD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O",t[t.DEBUG=3]="DEBUG",t);function r(e){return Array.isArray(e)}function o(e){return void 0!==e}function i(e){return"object"==typeof e&&null!==e&&!r(e)&&"[object Object]"===Object.prototype.toString.call(e)}function a(e){return"string"==typeof e}function s(e,t="",n){const i=t.split(".");let a=e;for(let e=0;e<i.length;e++){const t=i[e];if("*"===t&&r(a)){const t=i.slice(e+1).join("."),r=[];for(const e of a){const o=s(e,t,n);r.push(o)}return r}if(a=a instanceof Object?a[t]:void 0,void 0===a)break}return o(a)?a:n}function c(e){return function(e){return"boolean"==typeof e}(e)||a(e)||function(e){return"number"==typeof e&&!Number.isNaN(e)}(e)||!o(e)||r(e)&&e.every(c)||i(e)&&Object.values(e).every(c)}function l(e){return c(e)?e:void 0}function u(e,t,n){return async function(...r){try{return await e(...r)}catch(e){if(!t)return;return await t(e)}finally{await(null==n?void 0:n())}}}async function p(e,t={},n={}){var a;if(!o(e))return;const s=i(e)&&e.consent||n.consent||(null==(a=n.collector)?void 0:a.consent),c=r(t)?t:[t];for(const t of c){const r=await u(d)(e,t,{...n,consent:s});if(o(r))return r}}async function d(e,t,n={}){const{collector:i,consent:c}=n;return(r(t)?t:[t]).reduce(async(t,f)=>{const v=await t;if(v)return v;const y=a(f)?{key:f}:f;if(!Object.keys(y).length)return;const{condition:w,consent:b,fn:g,key:h,loop:P,map:k,set:m,validate:j,value:E}=y;if(w&&!await u(w)(e,f,i))return;if(b&&!function(e,t={},n={}){const r={...t,...n},o={};let i=!e||0===Object.keys(e).length;return Object.keys(r).forEach(t=>{r[t]&&(o[t]=!0,e&&e[t]&&(i=!0))}),!!i&&o}(b,c))return E;let O=o(E)?E:e;if(g&&(O=await u(g)(e,f,n)),h&&(O=s(e,h,E)),P){const[t,i]=P,a="this"===t?[e]:await p(e,t,n);r(a)&&(O=(await Promise.all(a.map(e=>p(e,i,n)))).filter(o))}else k?O=await Object.entries(k).reduce(async(t,[r,i])=>{const a=await t,s=await p(e,i,n);return o(s)&&(a[r]=s),a},Promise.resolve({})):m&&(O=await Promise.all(m.map(t=>d(e,t,n))));j&&!await u(j)(O)&&(O=void 0);const R=l(O);return o(R)?R:l(E)},Promise.resolve(void 0))}import{getEnv as f}from"@walkeros/web-core";var v={};function y(e){var t;if(null==(t=null==e?void 0:e.window)?void 0:t.heap)return e.window.heap;const{window:n}=f(e);return n.heap}function w(e){const t={};if(!i(e))return t;for(const[n,r]of Object.entries(e))"string"!=typeof r&&"number"!=typeof r&&"boolean"!=typeof r||(t[n]=r);return t}var b={type:"heap",config:{},init({config:e,env:t}){var n,r,o;const i=e.settings;if(!(null==i?void 0:i.appId))return!1;if(null==(n=null==t?void 0:t.window)?void 0:n.heap)return e;const{window:a,document:s}=f(t),c=a,l=s,u={disableTextCapture:null==(r=i.disableTextCapture)||r,disablePageviewAutocapture:null==(o=i.disablePageviewAutocapture)||o,...void 0!==i.disableSessionReplay&&{disableSessionReplay:i.disableSessionReplay},...void 0!==i.secureCookie&&{secureCookie:i.secureCookie},...void 0!==i.ingestServer&&{ingestServer:i.ingestServer},...i.heapConfig};if(!c.heap){const e={load:(t,n)=>{e.appid=t,e.config=null!=n?n:{}},track:()=>{},identify:()=>{},resetIdentity:()=>{},addUserProperties:()=>{},addEventProperties:()=>{},clearEventProperties:()=>{},startTracking:()=>{},stopTracking:()=>{},q:[]},t=["addEventProperties","addUserProperties","clearEventProperties","identify","resetIdentity","track","startTracking","stopTracking"];for(const n of t){const t=(...t)=>{e.q=e.q||[],e.q.push([n,...t])};e[n]=t}c.heap=e}e.loadScript&&function(e,t){const n=t.createElement("script");n.type="text/javascript",n.async=!0,n.src=`https://cdn.heapanalytics.com/js/heap-${e}.js`;const r=t.getElementsByTagName("script")[0];r&&r.parentNode?r.parentNode.insertBefore(n,r):t.head.appendChild(n)}(i.appId,l);const p=c.heap;return p.appid||p.load(i.appId,u),e},async push(e,{config:t,data:n,env:r,rule:o,collector:s}){var c,l;const u=y(r);if(!u)return;const d=t.settings||{},f=(null==o?void 0:o.settings)||{};if(void 0!==f.reset){("boolean"==typeof f.reset?f.reset:await p(e,f.reset,{collector:s}))&&u.resetIdentity()}const v=null!=(c=f.identify)?c:d.identify;if(void 0!==v){const t=await p(e,v,{collector:s});a(t)&&t.length>0&&u.identify(t)}const b=null!=(l=f.userProperties)?l:d.userProperties;if(void 0!==b){const t=await p(e,b,{collector:s});i(t)&&u.addUserProperties(w(t))}if(void 0!==f.eventProperties){const t=await p(e,f.eventProperties,{collector:s});i(t)&&u.addEventProperties(w(t))}if(void 0!==f.clearEventProperties){("boolean"==typeof f.clearEventProperties?f.clearEventProperties:await p(e,f.clearEventProperties,{collector:s}))&&u.clearEventProperties()}if(!0!==(null==o?void 0:o.skip)){const t=a(null==o?void 0:o.name)?o.name:e.name,r=w(n);u.track(t,r)}},on(e,t){var n;if("consent"!==e||!t.data)return;const r=y(t.env);if(!r)return;const o=null==(n=t.config)?void 0:n.consent;if(!o||0===Object.keys(o).length)return;const i=t.data;Object.keys(o).every(e=>!0===i[e])?r.startTracking():r.stopTracking()}};var g=b;export{v as DestinationHeap,g as default,b as destinationHeap};//# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts","../src/types/index.ts"],"sourcesContent":["import type { DestinationWeb } from '@walkeros/web-core';\nimport { getMappingValue, isObject, isString } from '@walkeros/core';\nimport { getEnv } from '@walkeros/web-core';\nimport type {\n Destination,\n Env,\n HeapConfig,\n HeapPropertyValue,\n HeapSDK,\n Mapping,\n Settings,\n} from './types';\n\n// Types export\nexport * as DestinationHeap from './types';\n\n/**\n * Resolve the Heap SDK: prefer the caller-provided mock (tests) via\n * env.window.heap, otherwise fall back to the global window.heap the\n * init function established (real snippet command queue).\n */\nfunction getHeap(env: Env | undefined): HeapSDK | undefined {\n if (env?.window?.heap) return env.window.heap;\n const { window } = getEnv(env as DestinationWeb.Env | undefined);\n return (window as Window).heap;\n}\n\n/**\n * Coerce a resolved object into a flat { key: primitive } map suitable\n * for Heap's property APIs. Drops non-primitive values.\n */\nfunction toHeapProperties(value: unknown): Record<string, HeapPropertyValue> {\n const out: Record<string, HeapPropertyValue> = {};\n if (!isObject(value)) return out;\n for (const [key, val] of Object.entries(value)) {\n if (\n typeof val === 'string' ||\n typeof val === 'number' ||\n typeof val === 'boolean'\n ) {\n out[key] = val;\n }\n }\n return out;\n}\n\nexport const destinationHeap: Destination = {\n type: 'heap',\n\n config: {},\n\n init({ config, env }) {\n const settings = config.settings;\n if (!settings?.appId) return false;\n\n // In tests a mock is provided via env.window.heap and there's nothing\n // for us to bootstrap. In production we install the Heap snippet's\n // command queue and call heap.load().\n if (env?.window?.heap) return config;\n\n const { window, document } = getEnv(env as DestinationWeb.Env | undefined);\n const w = window as Window;\n const doc = document as Document;\n\n const heapConfig: HeapConfig = {\n disableTextCapture: settings.disableTextCapture ?? true,\n disablePageviewAutocapture: settings.disablePageviewAutocapture ?? true,\n ...(settings.disableSessionReplay !== undefined && {\n disableSessionReplay: settings.disableSessionReplay,\n }),\n ...(settings.secureCookie !== undefined && {\n secureCookie: settings.secureCookie,\n }),\n ...(settings.ingestServer !== undefined && {\n ingestServer: settings.ingestServer,\n }),\n ...settings.heapConfig,\n };\n\n // Install the Heap snippet's command queue if not already present.\n if (!w.heap) {\n const heap: HeapSDK = {\n load: (appId: string, cfg?: HeapConfig) => {\n heap.appid = appId;\n heap.config = cfg ?? {};\n },\n track: (() => undefined) as HeapSDK['track'],\n identify: (() => undefined) as HeapSDK['identify'],\n resetIdentity: () => undefined,\n addUserProperties: (() => undefined) as HeapSDK['addUserProperties'],\n addEventProperties: (() => undefined) as HeapSDK['addEventProperties'],\n clearEventProperties: () => undefined,\n startTracking: () => undefined,\n stopTracking: () => undefined,\n q: [],\n };\n\n // Queue all calls until the real snippet boots and replaces these.\n const methods: Array<keyof HeapSDK> = [\n 'addEventProperties',\n 'addUserProperties',\n 'clearEventProperties',\n 'identify',\n 'resetIdentity',\n 'track',\n 'startTracking',\n 'stopTracking',\n ];\n for (const method of methods) {\n const queue = (...args: unknown[]) => {\n heap.q = heap.q || [];\n heap.q.push([method, ...args]);\n };\n (heap as unknown as Record<string, (...args: unknown[]) => void>)[\n method as string\n ] = queue;\n }\n\n w.heap = heap;\n }\n\n // Load real snippet script unless disabled.\n if (config.loadScript) addScript(settings.appId, doc);\n\n const heap = w.heap as HeapSDK;\n if (!heap.appid) heap.load(settings.appId, heapConfig);\n\n return config;\n },\n\n async push(event, { config, data, env, rule, collector }) {\n const heap = getHeap(env as Env | undefined);\n if (!heap) return;\n\n const settings = (config.settings || {}) as Partial<Settings>;\n const mappingSettings = (rule?.settings || {}) as Mapping;\n\n // 1. Reset identity first — subsequent identify/userProperties\n // operate on the fresh anonymous user.\n if (mappingSettings.reset !== undefined) {\n const resolved =\n typeof mappingSettings.reset === 'boolean'\n ? mappingSettings.reset\n : await getMappingValue(event, mappingSettings.reset, { collector });\n if (resolved) heap.resetIdentity();\n }\n\n // 2. Identify — rule-level wins over destination-level.\n const identifyMapping = mappingSettings.identify ?? settings.identify;\n if (identifyMapping !== undefined) {\n const resolved = await getMappingValue(event, identifyMapping, {\n collector,\n });\n if (isString(resolved) && resolved.length > 0) {\n heap.identify(resolved);\n }\n }\n\n // 3. User properties — rule-level wins over destination-level.\n const userPropsMapping =\n mappingSettings.userProperties ?? settings.userProperties;\n if (userPropsMapping !== undefined) {\n const resolved = await getMappingValue(event, userPropsMapping, {\n collector,\n });\n if (isObject(resolved)) {\n heap.addUserProperties(toHeapProperties(resolved));\n }\n }\n\n // 4. Persistent event properties.\n if (mappingSettings.eventProperties !== undefined) {\n const resolved = await getMappingValue(\n event,\n mappingSettings.eventProperties,\n { collector },\n );\n if (isObject(resolved)) {\n heap.addEventProperties(toHeapProperties(resolved));\n }\n }\n\n // 5. Clear persistent event properties.\n if (mappingSettings.clearEventProperties !== undefined) {\n const resolved =\n typeof mappingSettings.clearEventProperties === 'boolean'\n ? mappingSettings.clearEventProperties\n : await getMappingValue(event, mappingSettings.clearEventProperties, {\n collector,\n });\n if (resolved) heap.clearEventProperties();\n }\n\n // 6. Default track — unless rule.skip is set.\n if (rule?.skip !== true) {\n const eventName = isString(rule?.name) ? rule.name : event.name;\n const properties = toHeapProperties(data);\n heap.track(eventName, properties);\n }\n },\n\n on(type, context) {\n if (type !== 'consent' || !context.data) return;\n\n const heap = getHeap(context.env as Env | undefined);\n if (!heap) return;\n\n const required = context.config?.consent;\n if (!required || Object.keys(required).length === 0) return;\n\n const consent = context.data as Record<string, boolean>;\n const allGranted = Object.keys(required).every(\n (key) => consent[key] === true,\n );\n\n if (allGranted) heap.startTracking();\n else heap.stopTracking();\n },\n};\n\nfunction addScript(appId: string, doc: Document) {\n const script = doc.createElement('script');\n script.type = 'text/javascript';\n script.async = true;\n script.src = `https://cdn.heapanalytics.com/js/heap-${appId}.js`;\n const firstScript = doc.getElementsByTagName('script')[0];\n if (firstScript && firstScript.parentNode) {\n firstScript.parentNode.insertBefore(script, firstScript);\n } else {\n doc.head.appendChild(script);\n }\n}\n\nexport default destinationHeap;\n","import type {\n Mapping as WalkerOSMapping,\n Destination as CoreDestination,\n} from '@walkeros/core';\nimport type { DestinationWeb } from '@walkeros/web-core';\n\n/** Property value types accepted by Heap SDK methods. */\nexport type HeapPropertyValue = string | number | boolean;\n\n/** Options accepted by heap.load() as the second argument. */\nexport interface HeapConfig {\n disableTextCapture?: boolean;\n disablePageviewAutocapture?: boolean;\n disableSessionReplay?: boolean;\n secureCookie?: boolean;\n compressCookies?: boolean;\n clearEventPropertiesOnNewUser?: boolean;\n ingestServer?: string;\n trackingServer?: string;\n eventPropertiesStorageMedium?: string;\n metadataStorageMedium?: string;\n [key: string]: unknown;\n}\n\n/**\n * Heap SDK surface — the subset of window.heap methods this destination uses.\n * Mirrors the snippet-provided command queue so tests can mock each method.\n */\nexport interface HeapSDK {\n load: (appId: string, config?: HeapConfig) => void;\n track: (\n event: string,\n properties?: Record<string, HeapPropertyValue>,\n ) => void;\n identify: (identity: string) => void;\n resetIdentity: () => void;\n addUserProperties: (properties: Record<string, HeapPropertyValue>) => void;\n addEventProperties: (properties: Record<string, HeapPropertyValue>) => void;\n clearEventProperties: () => void;\n startTracking: () => void;\n stopTracking: () => void;\n appid?: string;\n config?: HeapConfig;\n q?: unknown[][];\n}\n\n/**\n * Settings (destination-level).\n *\n * appId is required (Heap Project Settings → App ID).\n * identify/userProperties resolve every push to keep identity sticky.\n */\nexport interface Settings {\n /** Heap App ID (required). Find it in Project > Settings > App ID. */\n appId: string;\n /** Disable Heap auto text capture. Default: true. */\n disableTextCapture?: boolean;\n /** Disable Heap automatic pageview tracking. Default: true (walkerOS handles pageviews). */\n disablePageviewAutocapture?: boolean;\n /** Disable Heap session replay. */\n disableSessionReplay?: boolean;\n /** SSL-only cookies. */\n secureCookie?: boolean;\n /** Custom server endpoint (first-party proxy). */\n ingestServer?: string;\n /** Destination-level identity mapping. Resolves to a string for heap.identify(). */\n identify?: WalkerOSMapping.Value;\n /** Destination-level user properties mapping. Resolves to object for heap.addUserProperties(). */\n userProperties?: WalkerOSMapping.Value;\n /** Additional heap.load() config passthrough. */\n heapConfig?: HeapConfig;\n}\n\nexport type InitSettings = Partial<Settings>;\n\n/**\n * Mapping (rule.settings) — per-event overrides.\n *\n * identify — resolves to string for heap.identify()\n * reset — truthy triggers heap.resetIdentity()\n * userProperties — resolves to object for heap.addUserProperties()\n * eventProperties — resolves to object for heap.addEventProperties() (persistent)\n * clearEventProperties — truthy triggers heap.clearEventProperties()\n */\nexport interface Mapping {\n identify?: WalkerOSMapping.Value;\n reset?: boolean | WalkerOSMapping.Value;\n userProperties?: WalkerOSMapping.Value;\n eventProperties?: WalkerOSMapping.Value;\n clearEventProperties?: boolean | WalkerOSMapping.Value;\n}\n\n/**\n * Env — optional override for the Heap SDK. Production leaves this\n * undefined and the destination creates the snippet's command queue on\n * window.heap. Tests provide a mock via env.window.heap = { ... }.\n */\nexport interface Env extends DestinationWeb.Env {\n window: {\n heap: HeapSDK;\n };\n}\n\ndeclare global {\n interface Window {\n heap?: HeapSDK;\n }\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"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEA,SAAS,cAAc;;;ACFvB;;;ADqBA,SAAS,QAAQ,KAA2C;AArB5D;AAsBE,OAAI,gCAAK,WAAL,mBAAa,KAAM,QAAO,IAAI,OAAO;AACzC,QAAM,EAAE,OAAO,IAAI,OAAO,GAAqC;AAC/D,SAAQ,OAAkB;AAC5B;AAMA,SAAS,iBAAiB,OAAmD;AAC3E,QAAM,MAAyC,CAAC;AAChD,MAAI,CAAC,EAAS,KAAK,EAAG,QAAO;AAC7B,aAAW,CAAC,KAAK,GAAG,KAAK,OAAO,QAAQ,KAAK,GAAG;AAC9C,QACE,OAAO,QAAQ,YACf,OAAO,QAAQ,YACf,OAAO,QAAQ,WACf;AACA,UAAI,GAAG,IAAI;AAAA,IACb;AAAA,EACF;AACA,SAAO;AACT;AAEO,IAAM,kBAA+B;AAAA,EAC1C,MAAM;AAAA,EAEN,QAAQ,CAAC;AAAA,EAET,KAAK,EAAE,QAAQ,IAAI,GAAG;AAnDxB;AAoDI,UAAM,WAAW,OAAO;AACxB,QAAI,EAAC,qCAAU,OAAO,QAAO;AAK7B,SAAI,gCAAK,WAAL,mBAAa,KAAM,QAAO;AAE9B,UAAM,EAAE,QAAQ,SAAS,IAAI,OAAO,GAAqC;AACzE,UAAM,IAAI;AACV,UAAM,MAAM;AAEZ,UAAM,aAAyB;AAAA,MAC7B,qBAAoB,cAAS,uBAAT,YAA+B;AAAA,MACnD,6BAA4B,cAAS,+BAAT,YAAuC;AAAA,MACnE,GAA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