UNPKG

@schibsted/sourcepoint

Version:

Package containing scripts used by Schibsteds' sites to integrate with Sourcepoint CMP

2 lines (1 loc) 1.5 kB
"use strict";var e=require("fs"),t=require("path"),n=require("url"),r="undefined"!=typeof document?document.currentScript:null;const i=n.fileURLToPath("undefined"==typeof document?require("url").pathToFileURL(__filename).href:r&&"SCRIPT"===r.tagName.toUpperCase()&&r.src||new URL("index.cjs",document.baseURI).href),s=t.dirname(i),o=t.resolve(s,"..",".."),c=t.resolve(o,"dist","templates"),u="5.5.9";function a(n,r,i){const s=e.readFileSync(t.resolve(c,i+".js"),"utf8"),o=e.readFileSync(t.resolve(c,i+"-with-messaging.js"),"utf8"),a=function(e){const t=(new Date).toISOString();return"/*! Copyright © "+(new Date).getFullYear()+" Schibsted. Generated by @schibsted/sourcepoint "+u+" ("+t+") */\n"+e}(function(e,t){const n=JSON.stringify(t);return e.replace(/['"]__CONFIGURATION_PLACEHOLDER__['"]/,n)}(r?s:o,"psi"===i?Object.assign({},n,{jsSdkVersion:u}):n));return r?function(e,t){let{baseEndpoint:n}=t;if(!n)throw new Error('"baseEndpoint" is not configured');const r="<script>\n"+e+"<\/script>";return r+'\n<link rel="preload" href="'+n+'/unified/wrapperMessagingWithoutDetection.js" as="script" crossorigin="crossorigin" fetchpriority="high">\n<script async src="'+n+'/unified/wrapperMessagingWithoutDetection.js" onload="document.dispatchEvent(new Event(\'cmp:loaded\'))"><\/script>'}(a,n):a}exports.psi=function(e,t){return void 0===t&&(t=!0),a(e,t,"psi")},exports.scc=function(e,t){return void 0===t&&(t=!0),a(e,t,"scc")},exports.tcf=function(e,t){return void 0===t&&(t=!0),a(e,t,"tcf")};