@schibsted/sps-sdk 3.0.0 → 3.0.1-CBT-18546.1
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/dist/cjs/public-script-versions.d.ts +4 -0
- package/dist/cjs/public-script-versions.js +9 -0
- package/dist/cjs/public-script-versions.js.map +1 -0
- package/dist/cjs/utils/pulseProxy.js +3 -4
- package/dist/cjs/utils/pulseProxy.js.map +1 -1
- package/dist/esm/public-script-versions.d.ts +4 -0
- package/dist/esm/public-script-versions.js +6 -0
- package/dist/esm/public-script-versions.js.map +1 -0
- package/dist/esm/utils/pulseProxy.js +3 -4
- package/dist/esm/utils/pulseProxy.js.map +1 -1
- package/dist/public-scripts/pulse-tracker-proxy.v1.0.0.min.js +1 -0
- package/dist/public-scripts/sps-pulse-helpers.v1.0.0.min.js +1 -0
- package/package.json +3 -3
- package/dist/public-scripts/pulse-tracker-proxy.v0.1.0.min.js +0 -1
- package/dist/public-scripts/sps-pulse-helpers.v0.2.0.min.js +0 -1
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PUBLIC_SCRIPT_VERSIONS = void 0;
|
|
4
|
+
// Generated from public-script-versions.json — do not edit manually
|
|
5
|
+
exports.PUBLIC_SCRIPT_VERSIONS = {
|
|
6
|
+
"sps-pulse-helpers": "1.0.0",
|
|
7
|
+
"pulse-tracker-proxy": "1.0.0"
|
|
8
|
+
};
|
|
9
|
+
//# sourceMappingURL=public-script-versions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"public-script-versions.js","sourceRoot":"","sources":["../../src/public-script-versions.ts"],"names":[],"mappings":";;;AAAA,oEAAoE;AACvD,QAAA,sBAAsB,GAAG;IACpC,mBAAmB,EAAE,OAAO;IAC5B,qBAAqB,EAAE,OAAO;CACtB,CAAC"}
|
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.injectPulseProxyScripts = void 0;
|
|
4
|
-
const
|
|
5
|
-
const PULSE_TRACKER_PROXY_VERSION = "0.1.0";
|
|
4
|
+
const public_script_versions_1 = require("../public-script-versions.js");
|
|
6
5
|
const injectPulseProxyScripts = (root, { pulseOrigin, publication, placementType, cdnUrl, offerData, experiment, }) => {
|
|
7
|
-
const HELPERS_SRC = `${cdnUrl}/public-scripts/sps-pulse-helpers.v${
|
|
8
|
-
const PROXY_SRC = `${cdnUrl}/public-scripts/pulse-tracker-proxy.v${
|
|
6
|
+
const HELPERS_SRC = `${cdnUrl}/public-scripts/sps-pulse-helpers.v${public_script_versions_1.PUBLIC_SCRIPT_VERSIONS["sps-pulse-helpers"]}.min.js`;
|
|
7
|
+
const PROXY_SRC = `${cdnUrl}/public-scripts/pulse-tracker-proxy.v${public_script_versions_1.PUBLIC_SCRIPT_VERSIONS["pulse-tracker-proxy"]}.min.js`;
|
|
9
8
|
const configScript = document.createElement("script");
|
|
10
9
|
configScript.type = "application/json";
|
|
11
10
|
configScript.setAttribute("data-sps-pulse-config", "true");
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pulseProxy.js","sourceRoot":"","sources":["../../../src/utils/pulseProxy.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"pulseProxy.js","sourceRoot":"","sources":["../../../src/utils/pulseProxy.ts"],"names":[],"mappings":";;;AAGA,sEAAmE;AA6B5D,MAAM,uBAAuB,GAAG,CACrC,IAAiB,EACjB,EACE,WAAW,EACX,WAAW,EACX,aAAa,EACb,MAAM,EACN,SAAS,EACT,UAAU,GACa,EACzB,EAAE;IACF,MAAM,WAAW,GAAG,GAAG,MAAM,sCAAsC,+CAAsB,CAAC,mBAAmB,CAAC,SAAS,CAAC;IACxH,MAAM,SAAS,GAAG,GAAG,MAAM,wCAAwC,+CAAsB,CAAC,qBAAqB,CAAC,SAAS,CAAC;IAE1H,MAAM,YAAY,GAAG,QAAQ,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAC;IACtD,YAAY,CAAC,IAAI,GAAG,kBAAkB,CAAC;IACvC,YAAY,CAAC,YAAY,CAAC,uBAAuB,EAAE,MAAM,CAAC,CAAC;IAC3D,YAAY,CAAC,WAAW,GAAG,IAAI,CAAC,SAAS,CAAC;QACxC,WAAW;QACX,WAAW;QACX,aAAa;QACb,SAAS;QACT,GAAG,CAAC,UAAU,IAAI,EAAE,UAAU,EAAE,CAAC;KAClC,CAAC,CAAC;IAEH,MAAM,aAAa,GAAG,QAAQ,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAC;IACvD,aAAa,CAAC,GAAG,GAAG,WAAW,CAAC;IAEhC,MAAM,WAAW,GAAG,QAAQ,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAC;IACrD,WAAW,CAAC,GAAG,GAAG,SAAS,CAAC;IAE5B,IAAI,CAAC,WAAW,CAAC,YAAY,CAAC,CAAC;IAC/B,IAAI,CAAC,WAAW,CAAC,WAAW,CAAC,CAAC;IAC9B,IAAI,CAAC,WAAW,CAAC,aAAa,CAAC,CAAC;AAClC,CAAC,CAAC;AAlCW,QAAA,uBAAuB,2BAkClC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"public-script-versions.js","sourceRoot":"","sources":["../../src/public-script-versions.ts"],"names":[],"mappings":"AAAA,oEAAoE;AACpE,MAAM,CAAC,MAAM,sBAAsB,GAAG;IACpC,mBAAmB,EAAE,OAAO;IAC5B,qBAAqB,EAAE,OAAO;CACtB,CAAC"}
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
const PULSE_TRACKER_PROXY_VERSION = "0.1.0";
|
|
1
|
+
import { PUBLIC_SCRIPT_VERSIONS } from "../public-script-versions.js";
|
|
3
2
|
export const injectPulseProxyScripts = (root, { pulseOrigin, publication, placementType, cdnUrl, offerData, experiment, }) => {
|
|
4
|
-
const HELPERS_SRC = `${cdnUrl}/public-scripts/sps-pulse-helpers.v${
|
|
5
|
-
const PROXY_SRC = `${cdnUrl}/public-scripts/pulse-tracker-proxy.v${
|
|
3
|
+
const HELPERS_SRC = `${cdnUrl}/public-scripts/sps-pulse-helpers.v${PUBLIC_SCRIPT_VERSIONS["sps-pulse-helpers"]}.min.js`;
|
|
4
|
+
const PROXY_SRC = `${cdnUrl}/public-scripts/pulse-tracker-proxy.v${PUBLIC_SCRIPT_VERSIONS["pulse-tracker-proxy"]}.min.js`;
|
|
6
5
|
const configScript = document.createElement("script");
|
|
7
6
|
configScript.type = "application/json";
|
|
8
7
|
configScript.setAttribute("data-sps-pulse-config", "true");
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pulseProxy.js","sourceRoot":"","sources":["../../../src/utils/pulseProxy.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"pulseProxy.js","sourceRoot":"","sources":["../../../src/utils/pulseProxy.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,sBAAsB,EAAE,MAAM,2BAA2B,CAAC;AA6BnE,MAAM,CAAC,MAAM,uBAAuB,GAAG,CACrC,IAAiB,EACjB,EACE,WAAW,EACX,WAAW,EACX,aAAa,EACb,MAAM,EACN,SAAS,EACT,UAAU,GACa,EACzB,EAAE;IACF,MAAM,WAAW,GAAG,GAAG,MAAM,sCAAsC,sBAAsB,CAAC,mBAAmB,CAAC,SAAS,CAAC;IACxH,MAAM,SAAS,GAAG,GAAG,MAAM,wCAAwC,sBAAsB,CAAC,qBAAqB,CAAC,SAAS,CAAC;IAE1H,MAAM,YAAY,GAAG,QAAQ,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAC;IACtD,YAAY,CAAC,IAAI,GAAG,kBAAkB,CAAC;IACvC,YAAY,CAAC,YAAY,CAAC,uBAAuB,EAAE,MAAM,CAAC,CAAC;IAC3D,YAAY,CAAC,WAAW,GAAG,IAAI,CAAC,SAAS,CAAC;QACxC,WAAW;QACX,WAAW;QACX,aAAa;QACb,SAAS;QACT,GAAG,CAAC,UAAU,IAAI,EAAE,UAAU,EAAE,CAAC;KAClC,CAAC,CAAC;IAEH,MAAM,aAAa,GAAG,QAAQ,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAC;IACvD,aAAa,CAAC,GAAG,GAAG,WAAW,CAAC;IAEhC,MAAM,WAAW,GAAG,QAAQ,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAC;IACrD,WAAW,CAAC,GAAG,GAAG,SAAS,CAAC;IAE5B,IAAI,CAAC,WAAW,CAAC,YAAY,CAAC,CAAC;IAC/B,IAAI,CAAC,WAAW,CAAC,WAAW,CAAC,CAAC;IAC9B,IAAI,CAAC,WAAW,CAAC,aAAa,CAAC,CAAC;AAClC,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var PulseTrackerProxyBundle=(()=>{var g=Object.defineProperty;var _=Object.getOwnPropertyDescriptor;var I=Object.getOwnPropertyNames;var M=Object.prototype.hasOwnProperty;var O=(e,r,t,o)=>{if(r&&typeof r=="object"||typeof r=="function")for(let a of I(r))!M.call(e,a)&&a!==t&&g(e,a,{get:()=>r[a],enumerable:!(o=_(r,a))||o.enumerable});return e};var U=e=>O(g({},"__esModule",{value:!0}),e);var C={};var l="pulse-tracker-proxy",x=`${l}:request`,H=`${l}:ack`,T=`${l}:invoke`,w=`${l}:return`,u=`${l}:return-error`,f=["trackAnonymousViewUIElement","trackEngagementAudio","trackEngagementForm","trackEngagementHealthUIElement","trackEngagementOffer","trackEngagementTeaser","trackEngagementUIElement","trackEngagementVideo","trackEngagementVideoAd","trackEngagementWidget","trackCompletedHealthAction","trackImpressionAdSlot","trackImpressionForm","trackImpressionHealthUIElement","trackImpressionOffer","trackImpressionPlayer","trackImpressionTeaser","trackImpressionUIElement","trackImpressionWidget","trackLeaveArticle","trackLeaveAudioPage","trackLeaveError","trackLeaveFrontpage","trackLeaveLandingpage","trackLeaveListing","trackLeaveLockedArticle","trackLeaveLockedAudio","trackLeaveLockedAudioPage","trackLeaveLockedVideo","trackLeaveLockedVideoPage","trackLeavePage","trackLeaveVideoPage","trackLeaveWeather","trackViewArticle","trackViewAudio","trackViewAudioPage","trackViewError","trackViewFrontpage","trackViewHealthPage","trackViewLandingpage","trackViewListing","trackViewLockedArticle","trackViewLockedAudio","trackViewLockedAudioPage","trackViewLockedVideo","trackViewLockedVideoPage","trackViewPage","trackViewTitle","trackViewVideo","trackViewVideoPage","trackViewWeather","trackLegacyViewArticle","trackLegacyViewLoginPoster","trackLegacyViewSalesPoster","trackLegacyViewListing","trackLegacyViewFrontpage","trackLegacyViewPage","trackLegacyViewUIElement","trackLegacyClickUIElement"];function P(e){return e!==null&&typeof e=="object"&&"type"in e&&typeof e.type=="string"&&e.type.startsWith(l)}async function h(e,r,t){return await new Promise((o,a)=>{let s=e.document.createElement("script");s.src=`//sdk.pulse.schibsted.com/versioned/${t}/pulse.min.js`,s.async=!0,s.onload=o,s.onerror=()=>{a(new Error(`Failed to load autotracker script from src: ${s.src}`))},e.document.head.appendChild(s)}),new Promise((o,a)=>{if(!e.pulse){a(new Error("Pulse autotracker did not load correctly!"));return}e.pulse("init",r),e.pulse(s=>{o(s)})})}function d(e,{target:r,timeout:t,debug:o=()=>{}}){return new Promise((a,s)=>{let i=new MessageChannel,n=t?setTimeout(()=>{i.port1.close(),s(new Error(`Message of type ${e.type} timed out`))},t):void 0,p=c=>{if(o("[Pulse Tracker Proxy] Received the response on the MessageChannel",c),!P(c.data)){o("[Pulse Tracker Proxy] Response was not a valid Proxy Message",c.data);return}c.data.type===u&&(o("[Pulse Tracker Proxy] Received an return error response",c.data.error),clearTimeout(n),i.port1.close(),s(new Error(c.data.error))),o("[Pulse Tracker Proxy] Received a valid response",c.data),clearTimeout(n),i.port1.close(),a(c.data)};i.port1.onmessage=p,o("[Pulse Tracker Proxy] Sending message to target window",e),r.postMessage(e,"*",[i.port2])})}var A="2.0.0-rc.4";function y(e){let r="tracker"in e&&typeof e.tracker=="object"?e.tracker:{};return{...e,tracker:{...r,proxyVersion:A}}}var m=class{constructor(r,t){this.target=r,this.debug=t}track(...r){this.debug("[Pulse Tracker Proxy] Calling `track`",r);let[t,o,...a]=r,s=[t,y(o),...a];return this.invoke({method:"track",args:s})}async invoke(r){this.debug("[Pulse Tracker Proxy] Invoking remote function",r);let t=await d({type:T,payload:r},{target:this.target});if(!P(t))throw this.debug("[Pulse Tracker Proxy] Invalid response from proxy",t),new Error("Invalid response from proxy");if(t.type===u)throw this.debug("[Pulse Tracker Proxy] Error response from proxy",t.error),new Error(t.error);if(t.type===w)return this.debug("[Pulse Tracker Proxy] Successful response from proxy",t.payload),t.payload;throw this.debug("[Pulse Tracker Proxy] Unhandled response from proxy",t),new Error("Unexpected response from proxy")}};var $=Object.fromEntries(f.map(e=>[e,function(...r){this.debug("[Pulse Tracker Proxy] Calling `track`",r);let[t,...o]=r,a=[y(t),...o];return this.invoke({method:e,args:a})}]));function Y(){return class extends m{constructor(e,r){super(e,r),r("[Pulse TPaaS Proxy] Initialized"),Object.assign(this,$)}}}var L=Y();function V({provider:e,autotrackerVersion:r="3",window:t=globalThis.window,target:o=t.parent,timeout:a=5e3,retries:s=3,retryTimeout:i=1e3,debug:n=()=>{}}={}){if(n("[Pulse Tracker Proxy] Checking if `pulseEventHandler` is provided in the current window..."),t.pulseEventHandler)return n(`[Pulse Tracker Proxy] \`pulseEventHandler\` found in the current window. Assuming it is the app webview. Loading autotracker version ${r}...`),e?h(t,e,r):(n("[Pulse Tracker Proxy] `provider` is not set - cannot create pulse tracker."),Promise.reject("`provider` is not set - cannot create pulse tracker."));if(n("[Pulse Tracker Proxy] `pulseEventHandler` not found in the current window - not a mobile app webview."),n("[Pulse Tracker Proxy] Trying to establish connection...",{target:o,timeout:a,retries:s}),!o)return Promise.reject(new Error("Target window not provided. Possibly window.parent is not available."));let p,c=!1,R=new Promise((k,E)=>{p=setTimeout(()=>{c=!0,n("[Pulse Tracker Proxy] Ack timeout. Sorry, target seems to not support the proxy."),E(new Error(`Pulse tracker proxy not found within ${a} ms`))},a)}),v=(async()=>{for(let k=0;k<s;k++){if(c)throw n("[Pulse Tracker Proxy] Configured timeout has passed before the next attempt"),new Error("Configured timeout has passed before the next attempt.");try{n(`[Pulse Tracker Proxy] Sending request to target window (attempt: ${k+1})...`),await d({type:x},{target:o,timeout:i})}catch(E){n(`[Pulse Tracker Proxy] Ack Request failed: ${E}`);continue}return clearTimeout(p),n(`[Pulse Tracker Proxy] Ack Request successful (attempt: ${k+1})`),new L(o,n)}throw clearTimeout(p),n("[Pulse Tracker Proxy] Retries exhausted. Target did not respond. Failing."),new Error("Failed to establish connection with pulse tracker proxy")})();return Promise.race([R,v])}var S;window.getPulseTrackerProxy=(S=window.getPulseTrackerProxy)!=null?S:V;return U(C);})();
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var SpsPulseHelpersBundle=(()=>{var A=Object.defineProperty;var U=Object.getOwnPropertyDescriptor;var $=Object.getOwnPropertyNames;var G=Object.prototype.hasOwnProperty;var N=(r,e,t,o)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of $(e))!G.call(r,n)&&n!==t&&A(r,n,{get:()=>e[n],enumerable:!(o=U(e,n))||o.enumerable});return r};var W=r=>N(A({},"__esModule",{value:!0}),r);var q={};var k="pulse-tracker-proxy",Y=`${k}:request`,K=`${k}:ack`,V=`${k}:invoke`,O=`${k}:return`,f=`${k}:return-error`,I=["trackAnonymousViewUIElement","trackEngagementAudio","trackEngagementForm","trackEngagementHealthUIElement","trackEngagementOffer","trackEngagementTeaser","trackEngagementUIElement","trackEngagementVideo","trackEngagementVideoAd","trackEngagementWidget","trackCompletedHealthAction","trackImpressionAdSlot","trackImpressionForm","trackImpressionHealthUIElement","trackImpressionOffer","trackImpressionPlayer","trackImpressionTeaser","trackImpressionUIElement","trackImpressionWidget","trackLeaveArticle","trackLeaveAudioPage","trackLeaveError","trackLeaveFrontpage","trackLeaveLandingpage","trackLeaveListing","trackLeaveLockedArticle","trackLeaveLockedAudio","trackLeaveLockedAudioPage","trackLeaveLockedVideo","trackLeaveLockedVideoPage","trackLeavePage","trackLeaveVideoPage","trackLeaveWeather","trackViewArticle","trackViewAudio","trackViewAudioPage","trackViewError","trackViewFrontpage","trackViewHealthPage","trackViewLandingpage","trackViewListing","trackViewLockedArticle","trackViewLockedAudio","trackViewLockedAudioPage","trackViewLockedVideo","trackViewLockedVideoPage","trackViewPage","trackViewTitle","trackViewVideo","trackViewVideoPage","trackViewWeather","trackLegacyViewArticle","trackLegacyViewLoginPoster","trackLegacyViewSalesPoster","trackLegacyViewListing","trackLegacyViewFrontpage","trackLegacyViewPage","trackLegacyViewUIElement","trackLegacyClickUIElement"];function y(r){return r!==null&&typeof r=="object"&&"type"in r&&typeof r.type=="string"&&r.type.startsWith(k)}function T(r,{target:e,timeout:t,debug:o=()=>{}}){return new Promise((n,i)=>{let s=new MessageChannel,p=t?setTimeout(()=>{s.port1.close(),i(new Error(`Message of type ${r.type} timed out`))},t):void 0,u=a=>{if(o("[Pulse Tracker Proxy] Received the response on the MessageChannel",a),!y(a.data)){o("[Pulse Tracker Proxy] Response was not a valid Proxy Message",a.data);return}a.data.type===f&&(o("[Pulse Tracker Proxy] Received an return error response",a.data.error),clearTimeout(p),s.port1.close(),i(new Error(a.data.error))),o("[Pulse Tracker Proxy] Received a valid response",a.data),clearTimeout(p),s.port1.close(),n(a.data)};s.port1.onmessage=u,o("[Pulse Tracker Proxy] Sending message to target window",r),e.postMessage(r,"*",[s.port2])})}var _="2.0.0-rc.4";function x(r){let e="tracker"in r&&typeof r.tracker=="object"?r.tracker:{};return{...r,tracker:{...e,proxyVersion:_}}}var E=class{constructor(e,t){this.target=e,this.debug=t}track(...e){this.debug("[Pulse Tracker Proxy] Calling `track`",e);let[t,o,...n]=e,i=[t,x(o),...n];return this.invoke({method:"track",args:i})}async invoke(e){this.debug("[Pulse Tracker Proxy] Invoking remote function",e);let t=await T({type:V,payload:e},{target:this.target});if(!y(t))throw this.debug("[Pulse Tracker Proxy] Invalid response from proxy",t),new Error("Invalid response from proxy");if(t.type===f)throw this.debug("[Pulse Tracker Proxy] Error response from proxy",t.error),new Error(t.error);if(t.type===O)return this.debug("[Pulse Tracker Proxy] Successful response from proxy",t.payload),t.payload;throw this.debug("[Pulse Tracker Proxy] Unhandled response from proxy",t),new Error("Unexpected response from proxy")}};var F=Object.fromEntries(I.map(r=>[r,function(...e){this.debug("[Pulse Tracker Proxy] Calling `track`",e);let[t,...o]=e,n=[x(t),...o];return this.invoke({method:r,args:n})}]));function D(){return class extends E{constructor(r,e){super(r,e),e("[Pulse TPaaS Proxy] Initialized"),Object.assign(this,F)}}}var j=D();function R(r,e,t,o){let i="",s=0;function p(a){return(a.textContent||"").trim().replace(/\s+/g," ").slice(0,200)||""}function u(a){var P,m,c,g;try{let l=a.target,d=(P=l==null?void 0:l.closest)==null?void 0:P.call(l,"a");if(!d)return;let w=d.getAttribute("data-track-id")||d.textContent||"link",h=p(d),S=`a|${w}|${h}`,L=Date.now();if(S===i&&L-s<400)return;i=S,s=L;let v=d.getAttribute("data-intent");r.trackLegacyClickUIElement({object:{id:w,elementType:"Button",name:h,containerName:"Page",custom:{...t,...e}},target:{url:(g=(c=(m=d.getAttribute("href"))==null?void 0:m.split("?"))==null?void 0:c[0])!=null?g:""},...v?{intent:v}:{},...o?{experiments:[{id:o,name:o,platform:"SPS",variant:t.offer_test_group}]}:{}})}catch{}}return document.addEventListener("click",u,!0),()=>document.removeEventListener("click",u,!0)}var b=!1,M=!1,C="script[data-sps-pulse-config='true']";async function H(){if(console.log("[SPS-Pulse-Helpers] boot initiated"),b)return;b=!0;let r=null;try{let e=document.querySelector(C);if(!e){console.warn(`[SPS-Pulse-Helpers] Config script tag not found with selector ${C}`);return}r=JSON.parse(e.textContent)}catch(e){console.warn("[SPS-Pulse-Helpers] Failed to parse config from script tag",e);return}try{let e=window.getPulseTrackerProxy;if(!e||typeof e!="function"){console.warn("[SPS-Pulse-Helpers] PulseTrackerProxy not available");return}let{placementType:t,publication:o,pulseOrigin:n,offerData:i,experiment:s}=r,p=await e({provider:o});R(p,n,i,s);let u=window.frameElement,a=window.parent.IntersectionObserver;if(!u||!a){console.warn("[SPS-Pulse-Helpers] No iframe or IntersectionObserver available. Pulse View event will not be fired.");return}let P=new a(m=>{var l;let c=m[0],g=(l=c==null?void 0:c.intersectionRatio)!=null?l:0;if(c!=null&&c.isIntersecting&&g>=1/3){if(P.disconnect(),M)return;M=!0,p.trackLegacyViewUIElement({object:{id:t,elementType:t,name:t,placement:{},custom:{...i,...n}},...s?{experiments:[{id:s,name:s,platform:"SPS",variant:i.offer_test_group}]}:{}})}},{root:null,threshold:[0,1/3]});P.observe(u)}catch(e){console.warn("[SPS-Pulse-Helpers] boot failed",e)}}H();return W(q);})();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@schibsted/sps-sdk",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.1-CBT-18546.1",
|
|
4
4
|
"description": "SPS SDK for node.js",
|
|
5
5
|
"engines": {
|
|
6
6
|
"node": ">=18.0.0"
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
"dist"
|
|
30
30
|
],
|
|
31
31
|
"scripts": {
|
|
32
|
-
"build": "npm run build:clean && npm run build:esm && npm run build:cjs && npm run build:public-scripts",
|
|
32
|
+
"build": "npm run build:clean && node scripts/generate-versions-ts.js && npm run build:esm && npm run build:cjs && npm run build:public-scripts",
|
|
33
33
|
"build:clean": "rm -rf dist/cjs dist/esm",
|
|
34
34
|
"build:esm": "tsc -p tsconfig.esm.json && tsc-alias -p tsconfig.esm.json",
|
|
35
35
|
"build:cjs": "tsc -p tsconfig.cjs.json && tsc-alias -p tsconfig.cjs.json && echo '{\"type\":\"commonjs\"}' > dist/cjs/package.json",
|
|
@@ -47,7 +47,7 @@
|
|
|
47
47
|
"@semantic-release/changelog": "^6.0.3",
|
|
48
48
|
"@semantic-release/git": "^10.0.1",
|
|
49
49
|
"@snoam/mono-ma-shared-configs": "^1.1.0",
|
|
50
|
-
"@
|
|
50
|
+
"@schibsted/pulse-tracker-proxy": "^2.0.0-rc.4",
|
|
51
51
|
"@types/jest": "30.0.0",
|
|
52
52
|
"@types/node": "^24.0.3",
|
|
53
53
|
"conventional-changelog-conventionalcommits": "^9.1.0",
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";var PulseTrackerProxyBundle=(()=>{var x=Object.defineProperty;var A=Object.getOwnPropertyDescriptor;var g=Object.getOwnPropertyNames;var v=Object.prototype.hasOwnProperty;var O=(r,o)=>{for(var e in o)x(r,e,{get:o[e],enumerable:!0})},$=(r,o,e,t)=>{if(o&&typeof o=="object"||typeof o=="function")for(let s of g(o))!v.call(r,s)&&s!==e&&x(r,s,{get:()=>o[s],enumerable:!(t=A(o,s))||t.enumerable});return r};var G=r=>$(x({},"__esModule",{value:!0}),r);var N={};var T={};O(T,{getPulseTrackerProxy:()=>C});var p="pulse-tracker-proxy",f=`${p}:request`,b=`${p}:ack`,k=`${p}:invoke`,h=`${p}:return`,P=`${p}:return-error`;function d(r){return r!==null&&typeof r=="object"&&"type"in r&&typeof r.type=="string"&&r.type.startsWith(p)}async function w(r,o,e){return await new Promise((t,s)=>{let n=r.document.createElement("script");n.src=`//sdk.pulse.schibsted.com/versioned/${e}/pulse.min.js`,n.async=!0,n.onload=t,n.onerror=()=>{s(new Error(`Failed to load autotracker script from src: ${n.src}`))},r.document.head.appendChild(n)}),new Promise((t,s)=>{if(!r.pulse){s(new Error("Pulse autotracker did not load correctly!"));return}r.pulse("init",o),r.pulse(n=>{t(n)})})}function y(r,{target:o,timeout:e,debug:t=()=>{}}){return new Promise((s,n)=>{let c=new MessageChannel,a=e?setTimeout(()=>{c.port1.close(),n(new Error(`Message of type ${r.type} timed out`))},e):void 0,u=i=>{if(t("[Pulse Tracker Proxy] Received the response on the MessageChannel",i),!d(i.data)){t("[Pulse Tracker Proxy] Response was not a valid Proxy Message",i.data);return}i.data.type===P&&(t("[Pulse Tracker Proxy] Received an return error response",i.data.error),clearTimeout(a),c.port1.close(),n(new Error(i.data.error))),t("[Pulse Tracker Proxy] Received a valid response",i.data),clearTimeout(a),c.port1.close(),s(i.data)};c.port1.onmessage=u,t("[Pulse Tracker Proxy] Sending message to target window",r),o.postMessage(r,"*",[c.port2])})}var R={PROXY_VERSION:"1.0.0",GIT_COMMIT:"e2afeb92"};function I(r){let o="tracker"in r&&typeof r.tracker=="object"?r.tracker:{};return{...r,tracker:{...o,proxyVersion:R.PROXY_VERSION}}}var E=class{constructor(o,e){this.target=o,this.debug=e}track(...o){this.debug("[Pulse Tracker Proxy] Calling `track`",o);let[e,t,...s]=o,n=[e,I(t),...s];return this.invoke({method:"track",args:n})}async invoke(o){this.debug("[Pulse Tracker Proxy] Invoking remote function",o);let e=await y({type:k,payload:o},{target:this.target});if(!d(e))throw this.debug("[Pulse Tracker Proxy] Invalid response from proxy",e),new Error("Invalid response from proxy");if(e.type===P)throw this.debug("[Pulse Tracker Proxy] Error response from proxy",e.error),new Error(e.error);if(e.type===h)return this.debug("[Pulse Tracker Proxy] Successful response from proxy",e.payload),e.payload;throw this.debug("[Pulse Tracker Proxy] Unhandled response from proxy",e),new Error("Unexpected response from proxy")}};function C({provider:r,autotrackerVersion:o="3",window:e=globalThis.window,target:t=e.parent,timeout:s=5e3,retries:n=3,retryTimeout:c=1e3,debug:a=()=>{}}={}){if(a("[Pulse Tracker Proxy] Checking if `pulseEventHandler` is provided in the current window..."),e.pulseEventHandler)return a(`[Pulse Tracker Proxy] \`pulseEventHandler\` found in the current window. Assuming it is the app webview. Loading autotracker version ${o}...`),r?w(e,r,o):(a("[Pulse Tracker Proxy] `provider` is not set - cannot create pulse tracker."),Promise.reject("`provider` is not set - cannot create pulse tracker."));if(a("[Pulse Tracker Proxy] `pulseEventHandler` not found in the current window - not a mobile app webview."),a("[Pulse Tracker Proxy] Trying to establish connection...",{target:t,timeout:s,retries:n}),!t)return Promise.reject(new Error("Target window not provided. Possibly window.parent is not available."));let u,i=!1,_=new Promise((l,m)=>{u=setTimeout(()=>{i=!0,a("[Pulse Tracker Proxy] Ack timeout. Sorry, target seems to not support the proxy."),m(new Error(`Pulse tracker proxy not found within ${s} ms`))},s)}),M=(async()=>{for(let l=0;l<n;l++){if(i)throw a("[Pulse Tracker Proxy] Configured timeout has passed before the next attempt"),new Error("Configured timeout has passed before the next attempt.");try{a(`[Pulse Tracker Proxy] Sending request to target window (attempt: ${l+1})...`),await y({type:f},{target:t,timeout:c})}catch(m){a(`[Pulse Tracker Proxy] Ack Request failed: ${m}`);continue}return clearTimeout(u),a(`[Pulse Tracker Proxy] Ack Request successful (attempt: ${l+1})`),new E(t,a)}throw clearTimeout(u),a("[Pulse Tracker Proxy] Retries exhausted. Target did not respond. Failing."),new Error("Failed to establish connection with pulse tracker proxy")})();return Promise.race([_,M])}var S;window.PulseTrackerProxy=(S=window.PulseTrackerProxy)!=null?S:T;return G(N);})();
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";var SpsPulseHelpersBundle=(()=>{var S=Object.defineProperty;var I=Object.getOwnPropertyDescriptor;var C=Object.getOwnPropertyNames;var h=Object.prototype.hasOwnProperty;var H=(t,e,i,a)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of C(e))!h.call(t,n)&&n!==i&&S(t,n,{get:()=>e[n],enumerable:!(a=I(e,n))||a.enumerable});return t};var D=t=>H(S({},"__esModule",{value:!0}),t);var L={};function w(t,e,i,a){let u="",l=0;function s(p){return(p.textContent||"").trim().replace(/\s+/g," ").slice(0,200)||""}function g(p){var f,P,r;try{let c=p.target,o=(f=c==null?void 0:c.closest)==null?void 0:f.call(c,"a");if(!o)return;let m=o.getAttribute("data-track-id")||o.textContent||"link",d=s(o),b=`a|${m}|${d}`,v=Date.now();if(b===u&&v-l<400)return;u=b,l=v;let E=o.getAttribute("data-intent"),y={object:{type:"UIElement",name:d,elementType:"Button",id:m,contentId:m,"spt:custom":{...i,...e}},action:"Click",target:{url:(P=o.getAttribute("href"))==null?void 0:P.split("?")[0]}};E&&(y.intent=E),a&&(y.experiments=[{name:a,platform:"SPS",variant:i.offer_test_group}]),(r=t==null?void 0:t.track)==null||r.call(t,"engagementEvent",y)}catch{}}return document.addEventListener("click",g,!0),()=>document.removeEventListener("click",g,!0)}var T=!1,x=!1,O="script[data-sps-pulse-config='true']";async function k(){if(console.log("[SPS-Pulse-Helpers] boot initiated"),T)return;T=!0;let t=null;try{let e=document.querySelector(O);if(!e){console.warn(`[SPS-Pulse-Helpers] Config script tag not found with selector ${O}`);return}t=JSON.parse(e.textContent)}catch(e){console.warn("[SPS-Pulse-Helpers] Failed to parse config from script tag",e);return}try{let e=window.PulseTrackerProxy;if(!e||typeof e.getPulseTrackerProxy!="function"){console.warn("[SPS-Pulse-Helpers] PulseTrackerProxy not available");return}let{placementType:i,publication:a,pulseOrigin:n,offerData:u,experiment:l}=t,s=await e.getPulseTrackerProxy({provider:a});w(s,n,u,l);let g=window.frameElement,p=window.parent.IntersectionObserver;if(!g||!p){console.warn("[SPS-Pulse-Helpers] No iframe or IntersectionObserver available. Pulse View event will not be fired.");return}let f=new p(P=>{var o,m;let r=P[0],c=(o=r==null?void 0:r.intersectionRatio)!=null?o:0;if(r!=null&&r.isIntersecting&&c>=1/3){if(f.disconnect(),x)return;x=!0;let d={object:{type:"UIElement",elementType:i,id:i,contentId:i,"spt:custom":{...u,...n}}};l&&(d.experiments=[{id:l,name:l,platform:"SPS",variant:u.offer_test_group}]),(m=s==null?void 0:s.track)==null||m.call(s,"trackerEvent",d)}},{root:null,threshold:[0,1/3]});f.observe(g)}catch(e){console.warn("[SPS-Pulse-Helpers] boot failed",e)}}k();return D(L);})();
|