@playpilot/tpi 8.19.1-beta.5 → 8.19.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.
@@ -1,3 +1,3 @@
1
- (function(){"use strict";function m(){var e;return(e=window.PlayPilotLinkInjections)==null?void 0:e.token}const j="https://partner-api.playpilot.tech/1.0",q="https://cdn.jsdelivr.net/npm/@playpilot/tpi@8.19.1-beta.5",h={};async function u(e,{headers:t={},method:n="GET",body:i=null}={}){const o=!_()&&n==="GET";if(o&&e in h)return h[e];const c=n==="GET"?{}:{"Content-Type":"application/json"},l=await fetch(j+e,{method:n,headers:new Headers({...c,...t}),body:i?JSON.stringify(i):null});if(!(l!=null&&l.ok))throw l;const s=await l.text();let a=s;try{s&&(a=JSON.parse(s))}catch{}return o&&(h[e]=a),a}const w="EncryptedToken",y="articleReplacementEditToken",I="playpilot-editorial-mode";async function A({href:e=window.location.href,throwError:t=!1}={}){try{const n=m();if(!n)throw new Error("No token was provided");const i=k(e);if(!i)throw new Error("Could not be authenticated");return await u(`/external-pages/edit-authorization?api-token=${n}`,{method:"POST",body:{private_token:i}}),C(i),!0}catch(n){if(console.error(n),t)throw n}finally{O()}return!1}function k(e=""){var i,o;const t=(i=window==null?void 0:window.PlayPilotLinkInjections)==null?void 0:i.editorial_token;if(t)return t;if(e){const c=new URL(e).searchParams.get(y);if(c)return decodeURI(c)}return((o=("; "+document.cookie).split(`; ${w}=`).pop())==null?void 0:o.split(";")[0])||""}function C(e){const t=new Date;t.setTime(t.getTime()+30*24*60*60*1e3);const i="expires="+t.toUTCString();document.cookie=w+"="+e+";"+i+";path=/"}function _(){var t;const e=(t=window==null?void 0:window.PlayPilotLinkInjections)==null?void 0:t.editorial_token;return new URLSearchParams(window.location.search).get(I)==="true"||!!e}function O(){const e=new URL(window.location.href);e.searchParams.delete(y),window.history.replaceState({},"",e)}async function M(){const e=m();if(!e)throw new Error("No token was provided");try{return await await u(`/domains/config?api-token=${e}`)||null}catch{return null}}function N(e){let t=0;for(let n=0;n<e.length;n++){const i=e.charCodeAt(n);t=t*31+i>>>0}return t.toString(16)}function R(e=5){const t="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";let n="";for(;n.length<e;)n+=t[Math.floor(Math.random()*t.length)];return n}const P={English:"en-US",Swedish:"sv-SE",Danish:"da-DK"};function U(){var i,o;const e=(i=window.PlayPilotLinkInjections)==null?void 0:i.language,t=Object.values(P);if(e){if(t.includes(e))return e;console.warn(`PlayPilot Link Injections: ${e} is not an accepted language`)}const n=(o=document.querySelector("html"))==null?void 0:o.getAttribute("lang");if(n){if(t.includes(n))return n;const c=t.find(l=>l.toLowerCase().startsWith(n+"-"));if(c)return c}return P.English}function v(e,t=""){const n=[],i=[e];for(;i.length>0;){const o=i.pop();if(n.includes(o)||t&&o.matches(t)||/^(A|BUTTON|SCRIPT|NOSCRIPT|STYLE|IFRAME|FIGCAPTION|TIME|LABEL|BLOCKQUOTE|H1)$/.test(o.tagName)||o.offsetWidth<=1)continue;const c=Array.from(o.childNodes).some(a=>{var r;return a.nodeType===Node.TEXT_NODE&&((r=a.nodeValue)==null?void 0:r.trim())!==""});if(c&&o.tagName==="LI"){const a=o.closest("ul, ol");a&&!n.includes(a)&&n.push(a);continue}const l=o.tagName==="P"&&!!o.textContent;if(c||l){n.push(o);continue}const s=Array.from(o.children);for(let a=s.length-1;a>=0;a--)i.push(s[a])}return n}function T(){var t;const e=(t=window.PlayPilotLinkInjections)==null?void 0:t.selector;if(e){const n=e.replace(/(:)/g,"\\$1"),i=document.querySelector(n);if(i)return i}return document.querySelector("article")||document.querySelector("main")||document.body}function $(e){return e.map(t=>t.innerText).join(`
1
+ (function(){"use strict";function m(){var e;return(e=window.PlayPilotLinkInjections)==null?void 0:e.token}const j="https://partner-api.playpilot.tech/1.0",q="https://cdn.jsdelivr.net/npm/@playpilot/tpi@8.19.1",h={};async function u(e,{headers:t={},method:n="GET",body:i=null}={}){const o=!_()&&n==="GET";if(o&&e in h)return h[e];const c=n==="GET"?{}:{"Content-Type":"application/json"},l=await fetch(j+e,{method:n,headers:new Headers({...c,...t}),body:i?JSON.stringify(i):null});if(!(l!=null&&l.ok))throw l;const s=await l.text();let a=s;try{s&&(a=JSON.parse(s))}catch{}return o&&(h[e]=a),a}const w="EncryptedToken",y="articleReplacementEditToken",I="playpilot-editorial-mode";async function A({href:e=window.location.href,throwError:t=!1}={}){try{const n=m();if(!n)throw new Error("No token was provided");const i=k(e);if(!i)throw new Error("Could not be authenticated");return await u(`/external-pages/edit-authorization?api-token=${n}`,{method:"POST",body:{private_token:i}}),C(i),!0}catch(n){if(console.error(n),t)throw n}finally{O()}return!1}function k(e=""){var i,o;const t=(i=window==null?void 0:window.PlayPilotLinkInjections)==null?void 0:i.editorial_token;if(t)return t;if(e){const c=new URL(e).searchParams.get(y);if(c)return decodeURI(c)}return((o=("; "+document.cookie).split(`; ${w}=`).pop())==null?void 0:o.split(";")[0])||""}function C(e){const t=new Date;t.setTime(t.getTime()+30*24*60*60*1e3);const i="expires="+t.toUTCString();document.cookie=w+"="+e+";"+i+";path=/"}function _(){var t;const e=(t=window==null?void 0:window.PlayPilotLinkInjections)==null?void 0:t.editorial_token;return new URLSearchParams(window.location.search).get(I)==="true"||!!e}function O(){const e=new URL(window.location.href);e.searchParams.delete(y),window.history.replaceState({},"",e)}async function M(){const e=m();if(!e)throw new Error("No token was provided");try{return await await u(`/domains/config?api-token=${e}`)||null}catch{return null}}function N(e){let t=0;for(let n=0;n<e.length;n++){const i=e.charCodeAt(n);t=t*31+i>>>0}return t.toString(16)}function R(e=5){const t="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";let n="";for(;n.length<e;)n+=t[Math.floor(Math.random()*t.length)];return n}const P={English:"en-US",Swedish:"sv-SE",Danish:"da-DK"};function U(){var i,o;const e=(i=window.PlayPilotLinkInjections)==null?void 0:i.language,t=Object.values(P);if(e){if(t.includes(e))return e;console.warn(`PlayPilot Link Injections: ${e} is not an accepted language`)}const n=(o=document.querySelector("html"))==null?void 0:o.getAttribute("lang");if(n){if(t.includes(n))return n;const c=t.find(l=>l.toLowerCase().startsWith(n+"-"));if(c)return c}return P.English}function v(e,t=""){const n=[],i=[e];for(;i.length>0;){const o=i.pop();if(n.includes(o)||t&&o.matches(t)||/^(A|BUTTON|SCRIPT|NOSCRIPT|STYLE|IFRAME|FIGCAPTION|TIME|LABEL|BLOCKQUOTE|H1)$/.test(o.tagName)||o.offsetWidth<=1)continue;const c=Array.from(o.childNodes).some(a=>{var r;return a.nodeType===Node.TEXT_NODE&&((r=a.nodeValue)==null?void 0:r.trim())!==""});if(c&&o.tagName==="LI"){const a=o.closest("ul, ol");a&&!n.includes(a)&&n.push(a);continue}const l=o.tagName==="P"&&!!o.textContent;if(c||l){n.push(o);continue}const s=Array.from(o.children);for(let a=s.length-1;a>=0;a--)i.push(s[a])}return n}function T(){var t;const e=(t=window.PlayPilotLinkInjections)==null?void 0:t.selector;if(e){const n=e.replace(/(:)/g,"\\$1"),i=document.querySelector(n);if(i)return i}return document.querySelector("article")||document.querySelector("main")||document.body}function $(e){return e.map(t=>t.innerText).join(`
2
2
 
3
- `)}function S(e=(t=>(t=window.PlayPilotLinkInjections)==null?void 0:t.config)()||null){const n=T(),i=v(n,(e==null?void 0:e.exclude_elements_selector)||""),o=$(i);return{parentElement:n,elements:i,pageText:o}}function E(){const e=T();return{content_heading:D(e),content_modified_time:z(e),content_published_time:B(e)}}function D(e){const t=e.querySelector("h1")||document.querySelector("h1");return(t==null?void 0:t.innerText.trim())||null}function z(e){const t=document.querySelector('meta[property*="modified_time"]')||document.querySelector('meta[name*="modified_time"]')||e.querySelector('[itemprop="dateModified"]')||document.querySelector('[itemprop="dateModified"]')||null,n=x().dateModified||(t==null?void 0:t.getAttribute("content"))||(t==null?void 0:t.getAttribute("datetime"))||(t==null?void 0:t.innerText);return n?g(n):null}function B(e){const t=document.querySelector('meta[property*="published_time"]')||document.querySelector('meta[name*="published_time"]')||e.querySelector('[itemprop="datePublished"]')||document.querySelector('[itemprop="datePublished"]')||e.querySelector("time")||document.querySelector("time")||e.querySelector("[datetime]")||document.querySelector("[datetime]")||null,n=x().datePublished||(t==null?void 0:t.getAttribute("content"))||(t==null?void 0:t.getAttribute("datetime"))||(t==null?void 0:t.innerText);return n?g(n):null}function g(e){try{return new Date(e).toISOString()}catch{return null}}function x(){const t=Array.from(document.querySelectorAll('[type="application/ld+json"]')).find(n=>n.textContent.includes("dateModified")||n.textContent.includes("datePublished"));if(!t)return{};try{return JSON.parse(t.textContent||"")}catch{return{}}}function b(){const e=location.pathname.replace(/\/+/g,"/");return location.protocol+"//"+location.host+e}function G(e){return!!(e.exclude_urls_pattern&&b().match(new RegExp(e.exclude_urls_pattern)))}let p=null;async function d({url:e=b(),params:t={},method:n="GET"}={}){const i=m(),o=_()?await A():!1,c=U();if(!i)throw new Error("No token was provided");const l=`/external-pages/?api-token=${i}&include_title_details=true${o?"&editorial_mode_enabled=true":""}&language=${c}`;let s;if(n==="POST"){const{pageText:a}=S();t.run_ai&&(t.hash=N(a||""),t.page_text=a),t.url=e,t.metadata=E(),s=await u(l,{method:"POST",body:t})}else s=await u(l+`&url=${e}`,{method:"GET"});return window.PlayPilotLinkInjections.last_successful_fetch=s,s}async function H({requireCompletedResult:e=!1,runAiWhenRelevant:t=!1,pollInterval:n=3e3,maxTries:i=600,onpoll:o=()=>null}={}){let c=0;p&&clearTimeout(p);const l=async(s,a)=>{let r;try{try{r=await d()}catch(f){throw console.error(f),(f==null?void 0:f.status)===404&&(r=await d({method:"POST"}),r.ai_enabled&&(r=await d({params:{run_ai:!0},method:"POST"}))),new Error}const{pageText:V}=S();if(r&&t&&(r=await F(V,r)),e&&r.ai_enabled&&r.ai_running)throw new Error;r.manual_injections=L(r.manual_injections||[]),r.ai_injections=L(r.ai_injections||[]),s(r);return}catch{if(c++,c>=i){i>1&&console.error("Max poll limit exceeded. Please return later."),s();return}r&&o(r),p=setTimeout(()=>l(s),n)}};return new Promise(l)}async function F(e,t){if(!e||!t.ai_enabled||t.ai_running)return t;const n=E().content_modified_time,i=t.content_modified_time?g(t.content_modified_time):null,o=n&&i===n;return t.ai_last_run&&o||new Date(n||0)<=new Date(i||0)?t:await d({params:{run_ai:!0},method:"POST"})}function L(e){return e.map(t=>({...t,key:J(t.sid)}))}function J(e){return e+"-"+R()}function K(e){window.PlayPilotLinkInjections&&(window.PlayPilotLinkInjections.consents=e)}function W(){const e=navigator.userAgent.toLowerCase();return/bot|crawl|spider|google|baidu|bing|msn|teoma|slurp|yandex|facebookexternalhit|facebot/i.test(e)}window.PlayPilotLinkInjections||(window.PlayPilotLinkInjections={token:"",editorial_token:"",selector:"",after_article_selector:"",after_article_insert_position:"",language:null,region:null,organization_sid:null,domain_sid:null,last_successful_fetch:null,tracked_events:[],queued_tracking_events:[],split_test_identifiers:{},evaluated_link_injections:[],initial_link_injections_promise:null,time_at_initialize:0,ads:[],video_playtimes:{},require_consent:!0,no_affiliate:!1,consents:{ads:!1,pixels:!1,tracking:!1,split_tests:!1,affiliate:!1},config:{},app:null,async initialize(e={token:"",selector:"",after_article_selector:"",after_article_insert_position:"",language:null,region:null,organization_sid:null,domain_sid:null,editorial_token:"",require_consent:!0,no_affiliate:!1}){if(!e.token){console.error("An API token is required.");return}this.token=e.token,this.editorial_token=e.editorial_token,this.selector=e.selector,this.after_article_selector=e.after_article_selector,this.after_article_insert_position=e.after_article_insert_position,this.language=e.language,this.region=e.region,this.organization_sid=e.organization_sid,this.domain_sid=e.domain_sid,this.require_consent=e.require_consent,this.no_affiliate=e.no_affiliate,this.time_at_initialize=Date.now(),this.require_consent===!1&&K({ads:!0,pixels:!0,tracking:!0,split_tests:!0,affiliate:!0}),this.config=await M()||{},!G(this.config)&&(this.initial_link_injections_promise=H({maxTries:1,runAiWhenRelevant:!W()}),this.mount())},destroy(){var e;(e=window.PlayPilotMount)==null||e.destroy(),delete window.PlayPilotLinkInjections},mount(){const e=_()||k(),t=document.createElement("script");t.id="playpilot-mount",t.src=`${q}/dist/${e?"editorial.":""}mount.js`,t.onload=()=>{var n;return(n=window.PlayPilotMount)==null?void 0:n.mount()},document.body.appendChild(t)}})})();
3
+ `)}function S(e=(t=>(t=window.PlayPilotLinkInjections)==null?void 0:t.config)()||null){const n=T(),i=v(n,(e==null?void 0:e.exclude_elements_selector)||""),o=$(i);return{parentElement:n,elements:i,pageText:o}}function E(){const e=T();return{content_heading:D(e),content_modified_time:z(e),content_published_time:B(e)}}function D(e){const t=e.querySelector("h1")||document.querySelector("h1");return(t==null?void 0:t.innerText.trim())||null}function z(e){const t=document.querySelector('meta[property*="modified_time"]')||document.querySelector('meta[name*="modified_time"]')||e.querySelector('[itemprop="dateModified"]')||document.querySelector('[itemprop="dateModified"]')||null,n=x().dateModified||(t==null?void 0:t.getAttribute("content"))||(t==null?void 0:t.getAttribute("datetime"))||(t==null?void 0:t.innerText);return n?g(n):null}function B(e){const t=document.querySelector('meta[property*="published_time"]')||document.querySelector('meta[name*="published_time"]')||e.querySelector('[itemprop="datePublished"]')||document.querySelector('[itemprop="datePublished"]')||e.querySelector("time")||document.querySelector("time")||e.querySelector("[datetime]")||document.querySelector("[datetime]")||null,n=x().datePublished||(t==null?void 0:t.getAttribute("content"))||(t==null?void 0:t.getAttribute("datetime"))||(t==null?void 0:t.innerText);return n?g(n):null}function g(e){try{return new Date(e).toISOString()}catch{return null}}function x(){const t=Array.from(document.querySelectorAll('[type="application/ld+json"]')).find(n=>n.textContent.includes("dateModified")||n.textContent.includes("datePublished"));if(!t)return{};try{return JSON.parse(t.textContent||"")}catch{return{}}}function L(){const e=location.pathname.replace(/\/+/g,"/");return location.protocol+"//"+location.host+e}function G(e){return!!(e.exclude_urls_pattern&&L().match(new RegExp(e.exclude_urls_pattern)))}let p=null;async function d({url:e=L(),params:t={},method:n="GET"}={}){const i=m(),o=_()?await A():!1,c=U();if(!i)throw new Error("No token was provided");const l=`/external-pages/?api-token=${i}&include_title_details=true${o?"&editorial_mode_enabled=true":""}&language=${c}`;let s;if(n==="POST"){const{pageText:a}=S();t.run_ai&&(t.hash=N(a||""),t.page_text=a),t.url=e,t.metadata=E(),s=await u(l,{method:"POST",body:t})}else s=await u(l+`&url=${e}`,{method:"GET"});return window.PlayPilotLinkInjections.last_successful_fetch=s,s}async function H({requireCompletedResult:e=!1,runAiWhenRelevant:t=!1,pollInterval:n=3e3,maxTries:i=600,onpoll:o=()=>null}={}){let c=0;p&&clearTimeout(p);const l=async(s,a)=>{let r;try{try{r=await d()}catch(f){throw console.error(f),(f==null?void 0:f.status)===404&&(r=await d({method:"POST"}),r.ai_enabled&&(r=await d({params:{run_ai:!0},method:"POST"}))),new Error}const{pageText:V}=S();if(r&&t&&(r=await F(V,r)),e&&r.ai_enabled&&r.ai_running)throw new Error;r.manual_injections=b(r.manual_injections||[]),r.ai_injections=b(r.ai_injections||[]),s(r);return}catch{if(c++,c>=i){i>1&&console.error("Max poll limit exceeded. Please return later."),s();return}r&&o(r),p=setTimeout(()=>l(s),n)}};return new Promise(l)}async function F(e,t){if(!e||!t.ai_enabled||t.ai_running)return t;const n=E().content_modified_time,i=t.content_modified_time?g(t.content_modified_time):null,o=n&&i===n;return t.ai_last_run&&o||new Date(n||0)<=new Date(i||0)?t:await d({params:{run_ai:!0},method:"POST"})}function b(e){return e.map(t=>({...t,key:J(t.sid)}))}function J(e){return e+"-"+R()}function K(e){window.PlayPilotLinkInjections&&(window.PlayPilotLinkInjections.consents=e)}function W(){const e=navigator.userAgent.toLowerCase();return/bot|crawl|spider|google|baidu|bing|msn|teoma|slurp|yandex|facebookexternalhit|facebot/i.test(e)}window.PlayPilotLinkInjections||(window.PlayPilotLinkInjections={token:"",editorial_token:"",selector:"",after_article_selector:"",after_article_insert_position:"",language:null,region:null,organization_sid:null,domain_sid:null,last_successful_fetch:null,tracked_events:[],queued_tracking_events:[],split_test_identifiers:{},evaluated_link_injections:[],initial_link_injections_promise:null,time_at_initialize:0,ads:[],video_playtimes:{},require_consent:!0,no_affiliate:!1,consents:{ads:!1,pixels:!1,tracking:!1,split_tests:!1,affiliate:!1},config:{},app:null,async initialize(e={token:"",selector:"",after_article_selector:"",after_article_insert_position:"",language:null,region:null,organization_sid:null,domain_sid:null,editorial_token:"",require_consent:!0,no_affiliate:!1}){if(!e.token){console.error("An API token is required.");return}this.token=e.token,this.editorial_token=e.editorial_token,this.selector=e.selector,this.after_article_selector=e.after_article_selector,this.after_article_insert_position=e.after_article_insert_position,this.language=e.language,this.region=e.region,this.organization_sid=e.organization_sid,this.domain_sid=e.domain_sid,this.require_consent=e.require_consent,this.no_affiliate=e.no_affiliate,this.time_at_initialize=Date.now(),this.require_consent===!1&&K({ads:!0,pixels:!0,tracking:!0,split_tests:!0,affiliate:!0}),this.config=await M()||{},!G(this.config)&&(this.initial_link_injections_promise=H({maxTries:1,runAiWhenRelevant:!W()}),this.mount())},destroy(){var e;(e=window.PlayPilotMount)==null||e.destroy(),delete window.PlayPilotLinkInjections},mount(){const e=_()||k(),t=document.createElement("script");t.id="playpilot-mount",t.src=`${q}/dist/${e?"editorial.":""}mount.js`,t.onload=()=>{var n;return(n=window.PlayPilotMount)==null?void 0:n.mount()},document.body.appendChild(t)}})})();