UNPKG

salsify-experiences-sdk

Version:

SDK to be used by commerce websites to implement product experiences.

2 lines 28 kB
(()=>{"use strict";var t={9306:(t,e,n)=>{var r=n(4901),o=n(6823),i=TypeError;t.exports=function(t){if(r(t))return t;throw new i(o(t)+" is not a function")}},8551:(t,e,n)=>{var r=n(34),o=String,i=TypeError;t.exports=function(t){if(r(t))return t;throw new i(o(t)+" is not an object")}},9617:(t,e,n)=>{var r=n(5397),o=n(5610),i=n(6198),s=function(t){return function(e,n,s){var a=r(e),c=i(a);if(0===c)return!t&&-1;var u,l=o(s,c);if(t&&n!=n){for(;c>l;)if((u=a[l++])!=u)return!0}else for(;c>l;l++)if((t||l in a)&&a[l]===n)return t||l||0;return!t&&-1}};t.exports={includes:s(!0),indexOf:s(!1)}},7680:(t,e,n)=>{var r=n(9504);t.exports=r([].slice)},4576:(t,e,n)=>{var r=n(9504),o=r({}.toString),i=r("".slice);t.exports=function(t){return i(o(t),8,-1)}},7740:(t,e,n)=>{var r=n(9297),o=n(5031),i=n(7347),s=n(4913);t.exports=function(t,e,n){for(var a=o(e),c=s.f,u=i.f,l=0;l<a.length;l++){var h=a[l];r(t,h)||n&&r(n,h)||c(t,h,u(e,h))}}},6699:(t,e,n)=>{var r=n(3724),o=n(4913),i=n(6980);t.exports=r?function(t,e,n){return o.f(t,e,i(1,n))}:function(t,e,n){return t[e]=n,t}},6980:t=>{t.exports=function(t,e){return{enumerable:!(1&t),configurable:!(2&t),writable:!(4&t),value:e}}},2106:(t,e,n)=>{var r=n(283),o=n(4913);t.exports=function(t,e,n){return n.get&&r(n.get,e,{getter:!0}),n.set&&r(n.set,e,{setter:!0}),o.f(t,e,n)}},6840:(t,e,n)=>{var r=n(4901),o=n(4913),i=n(283),s=n(9433);t.exports=function(t,e,n,a){a||(a={});var c=a.enumerable,u=void 0!==a.name?a.name:e;if(r(n)&&i(n,u,a),a.global)c?t[e]=n:s(e,n);else{try{a.unsafe?t[e]&&(c=!0):delete t[e]}catch(t){}c?t[e]=n:o.f(t,e,{value:n,enumerable:!1,configurable:!a.nonConfigurable,writable:!a.nonWritable})}return t}},9433:(t,e,n)=>{var r=n(4475),o=Object.defineProperty;t.exports=function(t,e){try{o(r,t,{value:e,configurable:!0,writable:!0})}catch(n){r[t]=e}return e}},3724:(t,e,n)=>{var r=n(9039);t.exports=!r((function(){return 7!==Object.defineProperty({},1,{get:function(){return 7}})[1]}))},4055:(t,e,n)=>{var r=n(4475),o=n(34),i=r.document,s=o(i)&&o(i.createElement);t.exports=function(t){return s?i.createElement(t):{}}},6763:t=>{t.exports="function"==typeof Bun&&Bun&&"string"==typeof Bun.version},8119:(t,e,n)=>{var r=n(9392);t.exports=/(?:ipad|iphone|ipod).*applewebkit/i.test(r)},9088:(t,e,n)=>{var r=n(4475),o=n(4576);t.exports="process"===o(r.process)},9392:t=>{t.exports="undefined"!=typeof navigator&&String(navigator.userAgent)||""},7388:(t,e,n)=>{var r,o,i=n(4475),s=n(9392),a=i.process,c=i.Deno,u=a&&a.versions||c&&c.version,l=u&&u.v8;l&&(o=(r=l.split("."))[0]>0&&r[0]<4?1:+(r[0]+r[1])),!o&&s&&(!(r=s.match(/Edge\/(\d+)/))||r[1]>=74)&&(r=s.match(/Chrome\/(\d+)/))&&(o=+r[1]),t.exports=o},8727:t=>{t.exports=["constructor","hasOwnProperty","isPrototypeOf","propertyIsEnumerable","toLocaleString","toString","valueOf"]},6518:(t,e,n)=>{var r=n(4475),o=n(7347).f,i=n(6699),s=n(6840),a=n(9433),c=n(7740),u=n(2796);t.exports=function(t,e){var n,l,h,g,d,p=t.target,f=t.global,v=t.stat;if(n=f?r:v?r[p]||a(p,{}):r[p]&&r[p].prototype)for(l in e){if(g=e[l],h=t.dontCallGetSet?(d=o(n,l))&&d.value:n[l],!u(f?l:p+(v?".":"#")+l,t.forced)&&void 0!==h){if(typeof g==typeof h)continue;c(g,h)}(t.sham||h&&h.sham)&&i(g,"sham",!0),s(n,l,g,t)}}},9039:t=>{t.exports=function(t){try{return!!t()}catch(t){return!0}}},8745:(t,e,n)=>{var r=n(616),o=Function.prototype,i=o.apply,s=o.call;t.exports="object"==typeof Reflect&&Reflect.apply||(r?s.bind(i):function(){return s.apply(i,arguments)})},6080:(t,e,n)=>{var r=n(7476),o=n(9306),i=n(616),s=r(r.bind);t.exports=function(t,e){return o(t),void 0===e?t:i?s(t,e):function(){return t.apply(e,arguments)}}},616:(t,e,n)=>{var r=n(9039);t.exports=!r((function(){var t=function(){}.bind();return"function"!=typeof t||t.hasOwnProperty("prototype")}))},9565:(t,e,n)=>{var r=n(616),o=Function.prototype.call;t.exports=r?o.bind(o):function(){return o.apply(o,arguments)}},350:(t,e,n)=>{var r=n(3724),o=n(9297),i=Function.prototype,s=r&&Object.getOwnPropertyDescriptor,a=o(i,"name"),c=a&&"something"===function(){}.name,u=a&&(!r||r&&s(i,"name").configurable);t.exports={EXISTS:a,PROPER:c,CONFIGURABLE:u}},7476:(t,e,n)=>{var r=n(4576),o=n(9504);t.exports=function(t){if("Function"===r(t))return o(t)}},9504:(t,e,n)=>{var r=n(616),o=Function.prototype,i=o.call,s=r&&o.bind.bind(i,i);t.exports=r?s:function(t){return function(){return i.apply(t,arguments)}}},7751:(t,e,n)=>{var r=n(4475),o=n(4901);t.exports=function(t,e){return arguments.length<2?(n=r[t],o(n)?n:void 0):r[t]&&r[t][e];var n}},5966:(t,e,n)=>{var r=n(9306),o=n(4117);t.exports=function(t,e){var n=t[e];return o(n)?void 0:r(n)}},4475:function(t,e,n){var r=function(t){return t&&t.Math===Math&&t};t.exports=r("object"==typeof globalThis&&globalThis)||r("object"==typeof window&&window)||r("object"==typeof self&&self)||r("object"==typeof n.g&&n.g)||r("object"==typeof this&&this)||function(){return this}()||Function("return this")()},9297:(t,e,n)=>{var r=n(9504),o=n(8981),i=r({}.hasOwnProperty);t.exports=Object.hasOwn||function(t,e){return i(o(t),e)}},421:t=>{t.exports={}},397:(t,e,n)=>{var r=n(7751);t.exports=r("document","documentElement")},5917:(t,e,n)=>{var r=n(3724),o=n(9039),i=n(4055);t.exports=!r&&!o((function(){return 7!==Object.defineProperty(i("div"),"a",{get:function(){return 7}}).a}))},7055:(t,e,n)=>{var r=n(9504),o=n(9039),i=n(4576),s=Object,a=r("".split);t.exports=o((function(){return!s("z").propertyIsEnumerable(0)}))?function(t){return"String"===i(t)?a(t,""):s(t)}:s},3706:(t,e,n)=>{var r=n(9504),o=n(4901),i=n(7629),s=r(Function.toString);o(i.inspectSource)||(i.inspectSource=function(t){return s(t)}),t.exports=i.inspectSource},1181:(t,e,n)=>{var r,o,i,s=n(8622),a=n(4475),c=n(34),u=n(6699),l=n(9297),h=n(7629),g=n(6119),d=n(421),p="Object already initialized",f=a.TypeError,v=a.WeakMap;if(s||h.state){var y=h.state||(h.state=new v);y.get=y.get,y.has=y.has,y.set=y.set,r=function(t,e){if(y.has(t))throw new f(p);return e.facade=t,y.set(t,e),e},o=function(t){return y.get(t)||{}},i=function(t){return y.has(t)}}else{var m=g("state");d[m]=!0,r=function(t,e){if(l(t,m))throw new f(p);return e.facade=t,u(t,m,e),e},o=function(t){return l(t,m)?t[m]:{}},i=function(t){return l(t,m)}}t.exports={set:r,get:o,has:i,enforce:function(t){return i(t)?o(t):r(t,{})},getterFor:function(t){return function(e){var n;if(!c(e)||(n=o(e)).type!==t)throw new f("Incompatible receiver, "+t+" required");return n}}}},4901:t=>{var e="object"==typeof document&&document.all;t.exports=void 0===e&&void 0!==e?function(t){return"function"==typeof t||t===e}:function(t){return"function"==typeof t}},2796:(t,e,n)=>{var r=n(9039),o=n(4901),i=/#|\.prototype\./,s=function(t,e){var n=c[a(t)];return n===l||n!==u&&(o(e)?r(e):!!e)},a=s.normalize=function(t){return String(t).replace(i,".").toLowerCase()},c=s.data={},u=s.NATIVE="N",l=s.POLYFILL="P";t.exports=s},4117:t=>{t.exports=function(t){return null==t}},34:(t,e,n)=>{var r=n(4901);t.exports=function(t){return"object"==typeof t?null!==t:r(t)}},6395:t=>{t.exports=!1},757:(t,e,n)=>{var r=n(7751),o=n(4901),i=n(1625),s=n(7040),a=Object;t.exports=s?function(t){return"symbol"==typeof t}:function(t){var e=r("Symbol");return o(e)&&i(e.prototype,a(t))}},6198:(t,e,n)=>{var r=n(8014);t.exports=function(t){return r(t.length)}},283:(t,e,n)=>{var r=n(9504),o=n(9039),i=n(4901),s=n(9297),a=n(3724),c=n(350).CONFIGURABLE,u=n(3706),l=n(1181),h=l.enforce,g=l.get,d=String,p=Object.defineProperty,f=r("".slice),v=r("".replace),y=r([].join),m=a&&!o((function(){return 8!==p((function(){}),"length",{value:8}).length})),b=String(String).split("String"),w=t.exports=function(t,e,n){"Symbol("===f(d(e),0,7)&&(e="["+v(d(e),/^Symbol\(([^)]*)\).*$/,"$1")+"]"),n&&n.getter&&(e="get "+e),n&&n.setter&&(e="set "+e),(!s(t,"name")||c&&t.name!==e)&&(a?p(t,"name",{value:e,configurable:!0}):t.name=e),m&&n&&s(n,"arity")&&t.length!==n.arity&&p(t,"length",{value:n.arity});try{n&&s(n,"constructor")&&n.constructor?a&&p(t,"prototype",{writable:!1}):t.prototype&&(t.prototype=void 0)}catch(t){}var r=h(t);return s(r,"source")||(r.source=y(b,"string"==typeof e?e:"")),t};Function.prototype.toString=w((function(){return i(this)&&g(this).source||u(this)}),"toString")},741:t=>{var e=Math.ceil,n=Math.floor;t.exports=Math.trunc||function(t){var r=+t;return(r>0?n:e)(r)}},4913:(t,e,n)=>{var r=n(3724),o=n(5917),i=n(8686),s=n(8551),a=n(6969),c=TypeError,u=Object.defineProperty,l=Object.getOwnPropertyDescriptor,h="enumerable",g="configurable",d="writable";e.f=r?i?function(t,e,n){if(s(t),e=a(e),s(n),"function"==typeof t&&"prototype"===e&&"value"in n&&d in n&&!n[d]){var r=l(t,e);r&&r[d]&&(t[e]=n.value,n={configurable:g in n?n[g]:r[g],enumerable:h in n?n[h]:r[h],writable:!1})}return u(t,e,n)}:u:function(t,e,n){if(s(t),e=a(e),s(n),o)try{return u(t,e,n)}catch(t){}if("get"in n||"set"in n)throw new c("Accessors not supported");return"value"in n&&(t[e]=n.value),t}},7347:(t,e,n)=>{var r=n(3724),o=n(9565),i=n(8773),s=n(6980),a=n(5397),c=n(6969),u=n(9297),l=n(5917),h=Object.getOwnPropertyDescriptor;e.f=r?h:function(t,e){if(t=a(t),e=c(e),l)try{return h(t,e)}catch(t){}if(u(t,e))return s(!o(i.f,t,e),t[e])}},8480:(t,e,n)=>{var r=n(1828),o=n(8727).concat("length","prototype");e.f=Object.getOwnPropertyNames||function(t){return r(t,o)}},3717:(t,e)=>{e.f=Object.getOwnPropertySymbols},1625:(t,e,n)=>{var r=n(9504);t.exports=r({}.isPrototypeOf)},1828:(t,e,n)=>{var r=n(9504),o=n(9297),i=n(5397),s=n(9617).indexOf,a=n(421),c=r([].push);t.exports=function(t,e){var n,r=i(t),u=0,l=[];for(n in r)!o(a,n)&&o(r,n)&&c(l,n);for(;e.length>u;)o(r,n=e[u++])&&(~s(l,n)||c(l,n));return l}},8773:(t,e)=>{var n={}.propertyIsEnumerable,r=Object.getOwnPropertyDescriptor,o=r&&!n.call({1:2},1);e.f=o?function(t){var e=r(this,t);return!!e&&e.enumerable}:n},4270:(t,e,n)=>{var r=n(9565),o=n(4901),i=n(34),s=TypeError;t.exports=function(t,e){var n,a;if("string"===e&&o(n=t.toString)&&!i(a=r(n,t)))return a;if(o(n=t.valueOf)&&!i(a=r(n,t)))return a;if("string"!==e&&o(n=t.toString)&&!i(a=r(n,t)))return a;throw new s("Can't convert object to primitive value")}},5031:(t,e,n)=>{var r=n(7751),o=n(9504),i=n(8480),s=n(3717),a=n(8551),c=o([].concat);t.exports=r("Reflect","ownKeys")||function(t){var e=i.f(a(t)),n=s.f;return n?c(e,n(t)):e}},7979:(t,e,n)=>{var r=n(8551);t.exports=function(){var t=r(this),e="";return t.hasIndices&&(e+="d"),t.global&&(e+="g"),t.ignoreCase&&(e+="i"),t.multiline&&(e+="m"),t.dotAll&&(e+="s"),t.unicode&&(e+="u"),t.unicodeSets&&(e+="v"),t.sticky&&(e+="y"),e}},7750:(t,e,n)=>{var r=n(4117),o=TypeError;t.exports=function(t){if(r(t))throw new o("Can't call method on "+t);return t}},9472:(t,e,n)=>{var r,o=n(4475),i=n(8745),s=n(4901),a=n(6763),c=n(9392),u=n(7680),l=n(2812),h=o.Function,g=/MSIE .\./.test(c)||a&&((r=o.Bun.version.split(".")).length<3||"0"===r[0]&&(r[1]<3||"3"===r[1]&&"0"===r[2]));t.exports=function(t,e){var n=e?2:1;return g?function(r,o){var a=l(arguments.length,1)>n,c=s(r)?r:h(r),g=a?u(arguments,n):[],d=a?function(){i(c,this,g)}:c;return e?t(d,o):t(d)}:t}},6119:(t,e,n)=>{var r=n(5745),o=n(3392),i=r("keys");t.exports=function(t){return i[t]||(i[t]=o(t))}},7629:(t,e,n)=>{var r=n(6395),o=n(4475),i=n(9433),s="__core-js_shared__",a=t.exports=o[s]||i(s,{});(a.versions||(a.versions=[])).push({version:"3.37.1",mode:r?"pure":"global",copyright:"© 2014-2024 Denis Pushkarev (zloirock.ru)",license:"https://github.com/zloirock/core-js/blob/v3.37.1/LICENSE",source:"https://github.com/zloirock/core-js"})},5745:(t,e,n)=>{var r=n(7629);t.exports=function(t,e){return r[t]||(r[t]=e||{})}},4495:(t,e,n)=>{var r=n(7388),o=n(9039),i=n(4475).String;t.exports=!!Object.getOwnPropertySymbols&&!o((function(){var t=Symbol("symbol detection");return!i(t)||!(Object(t)instanceof Symbol)||!Symbol.sham&&r&&r<41}))},9225:(t,e,n)=>{var r,o,i,s,a=n(4475),c=n(8745),u=n(6080),l=n(4901),h=n(9297),g=n(9039),d=n(397),p=n(7680),f=n(4055),v=n(2812),y=n(8119),m=n(9088),b=a.setImmediate,w=a.clearImmediate,x=a.process,S=a.Dispatch,C=a.Function,E=a.MessageChannel,I=a.String,O=0,P={},j="onreadystatechange";g((function(){r=a.location}));var T=function(t){if(h(P,t)){var e=P[t];delete P[t],e()}},k=function(t){return function(){T(t)}},A=function(t){T(t.data)},M=function(t){a.postMessage(I(t),r.protocol+"//"+r.host)};b&&w||(b=function(t){v(arguments.length,1);var e=l(t)?t:C(t),n=p(arguments,1);return P[++O]=function(){c(e,void 0,n)},o(O),O},w=function(t){delete P[t]},m?o=function(t){x.nextTick(k(t))}:S&&S.now?o=function(t){S.now(k(t))}:E&&!y?(s=(i=new E).port2,i.port1.onmessage=A,o=u(s.postMessage,s)):a.addEventListener&&l(a.postMessage)&&!a.importScripts&&r&&"file:"!==r.protocol&&!g(M)?(o=M,a.addEventListener("message",A,!1)):o=j in f("script")?function(t){d.appendChild(f("script"))[j]=function(){d.removeChild(this),T(t)}}:function(t){setTimeout(k(t),0)}),t.exports={set:b,clear:w}},5610:(t,e,n)=>{var r=n(1291),o=Math.max,i=Math.min;t.exports=function(t,e){var n=r(t);return n<0?o(n+e,0):i(n,e)}},5397:(t,e,n)=>{var r=n(7055),o=n(7750);t.exports=function(t){return r(o(t))}},1291:(t,e,n)=>{var r=n(741);t.exports=function(t){var e=+t;return e!=e||0===e?0:r(e)}},8014:(t,e,n)=>{var r=n(1291),o=Math.min;t.exports=function(t){var e=r(t);return e>0?o(e,9007199254740991):0}},8981:(t,e,n)=>{var r=n(7750),o=Object;t.exports=function(t){return o(r(t))}},2777:(t,e,n)=>{var r=n(9565),o=n(34),i=n(757),s=n(5966),a=n(4270),c=n(8227),u=TypeError,l=c("toPrimitive");t.exports=function(t,e){if(!o(t)||i(t))return t;var n,c=s(t,l);if(c){if(void 0===e&&(e="default"),n=r(c,t,e),!o(n)||i(n))return n;throw new u("Can't convert object to primitive value")}return void 0===e&&(e="number"),a(t,e)}},6969:(t,e,n)=>{var r=n(2777),o=n(757);t.exports=function(t){var e=r(t,"string");return o(e)?e:e+""}},6823:t=>{var e=String;t.exports=function(t){try{return e(t)}catch(t){return"Object"}}},3392:(t,e,n)=>{var r=n(9504),o=0,i=Math.random(),s=r(1..toString);t.exports=function(t){return"Symbol("+(void 0===t?"":t)+")_"+s(++o+i,36)}},7040:(t,e,n)=>{var r=n(4495);t.exports=r&&!Symbol.sham&&"symbol"==typeof Symbol.iterator},8686:(t,e,n)=>{var r=n(3724),o=n(9039);t.exports=r&&o((function(){return 42!==Object.defineProperty((function(){}),"prototype",{value:42,writable:!1}).prototype}))},2812:t=>{var e=TypeError;t.exports=function(t,n){if(t<n)throw new e("Not enough arguments");return t}},8622:(t,e,n)=>{var r=n(4475),o=n(4901),i=r.WeakMap;t.exports=o(i)&&/native code/.test(String(i))},8227:(t,e,n)=>{var r=n(4475),o=n(5745),i=n(9297),s=n(3392),a=n(4495),c=n(7040),u=r.Symbol,l=o("wks"),h=c?u.for||u:u&&u.withoutSetter||s;t.exports=function(t){return i(l,t)||(l[t]=a&&i(u,t)?u[t]:h("Symbol."+t)),l[t]}},9479:(t,e,n)=>{var r=n(4475),o=n(3724),i=n(2106),s=n(7979),a=n(9039),c=r.RegExp,u=c.prototype;o&&a((function(){var t=!0;try{c(".","d")}catch(e){t=!1}var e={},n="",r=t?"dgimsy":"gimsy",o=function(t,r){Object.defineProperty(e,t,{get:function(){return n+=r,!0}})},i={dotAll:"s",global:"g",ignoreCase:"i",multiline:"m",sticky:"y"};for(var s in t&&(i.hasIndices="d"),i)o(s,i[s]);return Object.getOwnPropertyDescriptor(u,"flags").get.call(e)!==r||n!==r}))&&i(u,"flags",{configurable:!0,get:s})},6368:(t,e,n)=>{var r=n(6518),o=n(4475),i=n(9225).clear;r({global:!0,bind:!0,enumerable:!0,forced:o.clearImmediate!==i},{clearImmediate:i})},9848:(t,e,n)=>{n(6368),n(9309)},9309:(t,e,n)=>{var r=n(6518),o=n(4475),i=n(9225).set,s=n(9472),a=o.setImmediate?s(i,!1):i;r({global:!0,bind:!0,enumerable:!0,forced:o.setImmediate!==a},{setImmediate:a})}},e={};function n(r){var o=e[r];if(void 0!==o)return o.exports;var i=e[r]={exports:{}};return t[r].call(i.exports,i,i.exports,n),i.exports}n.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||new Function("return this")()}catch(t){if("object"==typeof window)return window}}(),n(9479),n(9848);let r=function(t){return t.ContentLength="content-length",t}({});function o(){return"object"==typeof window&&"object"==typeof document}class i{#t=new Map;#e;constructor(t){this.#e=t}async getConfig(t){return this.#t.has(t)?this.#t.get(t):this.#n(t)}async#n(t){const e=`${t}/config.json`;let n,o;try{n=await(i=e,fetch(i,{method:"GET"}))}catch(t){const n=t instanceof Error?t.message:void 0;return void this.#e.log("error",{errorContext:"per-product config",errorType:"fetch",errorMessage:`Error fetching ${e}: ${n}`})}var i;if("0"===n.headers.get(r.ContentLength))return this.#r(t,void 0);try{o=await n.json()}catch(n){const r=n instanceof Error?n.message:void 0;return this.#e.log("error",{errorContext:"per-product config",errorType:"parse",errorMessage:`Error parsing ${e}: ${r}`}),this.#r(t,void 0)}return function(t,e,n){const r={errorType:"validation",errorContext:"per-product config"};return"object"!=typeof t||null===t?(e?.log("error",{...r,errorMessage:`${n} does not contain an object`}),!1):"content"in t?Array.isArray(t.content)?0===t.content.length?(e?.log("error",{...r,errorMessage:`'content' array in ${n} has length 0`}),!1):!(!t.content.every((t=>function(t,e,n){const r={errorType:"validation",errorContext:"per-product config"};return"object"!=typeof t||null===t?(e?.log("error",{...r,errorMessage:`'content' in ${n} contains a source that is not an object`}),!1):"source"in t?"string"!=typeof t.source&&null!==t.source?(e?.log("error",{...r,errorMessage:`'content' in ${n} contains a source with an invalid 'source' value`}),!1):"weight"in t?"number"==typeof t.weight||(e?.log("error",{...r,errorMessage:`'content' in ${n} contains a source with an invalid 'weight' value`}),!1):(e?.log("error",{...r,errorMessage:`'content' in ${n} contains a source that is missing a 'weight' key`}),!1):(e?.log("error",{...r,errorMessage:`'content' in ${n} contains a source that is missing a 'source' key`}),!1)}(t,e,n)))||Math.abs(1-t.content.reduce(((t,e)=>t+e.weight),0))>.001&&(e?.log("error",{...r,errorMessage:`sum of source weights in 'content' in ${n} does not equal 1`}),1)):(e?.log("error",{...r,errorMessage:`'content' in ${n} is not an array`}),!1):(e?.log("error",{...r,errorMessage:`${n} does not contain a 'content' key`}),!1)}(o,this.#e,e)?this.#r(t,o):this.#r(t,void 0)}#r(t,e){return this.#t.set(t,e),e}}const s="salsify-ec-iframe",a="https://salsify-ecdn.com",c="https://staging.salsify-ecdn.com",u=/^https:\/\/.+.test\.salsify\.com/,l="index.html";let h=!1;function g(t){return t.origin===a||t.origin===c||u.test(t.origin)}class d{#o;#i=new Map;#s;#a;#c;#e;#u;constructor(t,e,n,r){this.#a=t,this.#c=e,this.#e=n,this.#u=r,this.#o=new i(n)}async exists(t,e){e=this.#l(e);const n=this.#h(t,e),r=await this.#o.getConfig(n),o=this.#g(r,n,t),i=r?.content??null,s=await this.#d(r?.content,n),a=!!o&&await this.#p(n,o);return this.#s={idType:e,productId:t,content:i,allContentExists:s,source:o,sourceExists:a},this.#e.log("ec_exists",this.#s),a}async renderIframe(t,e,n){if(!o())throw new Error("Can only render EC iframe in a browser runtime context.");this.#u?.beforeRender&&this.#u.beforeRender(e,n),n=this.#l(n);const r=this.#h(e,n),i=await this.#o.getConfig(r),a=this.#g(i,r,e);if(null!==a){c=this.#e,h||(window.addEventListener("message",(t=>{if(!g(t))return;if(t.data.messageType&&"heightUpdateRequest"!==t.data.messageType)return;const e=`#${s}`,n=document.querySelector(e);n?n.height=t.data.height:c.log("error",{errorContext:"iframeResizeListener",errorType:"dom",errorMessage:`Could not find iframe with selector ${e}`})})),h=!0);const e=this.#f();e.src=this.#v(r,a),e.title="Salsify Enhanced Content",t.appendChild(e)}var c;const u=i?.content??null,l=await this.#d(i?.content,r),d=!!a&&await this.#p(r,a);this.#s={idType:n,productId:e,content:u,allContentExists:l,source:a,sourceExists:d},this.#e.log("ec_render_iframe",this.#s),this.#u?.afterRender?.(e,n)}updateLanguageCode(t){this.#a={...this.#a,languageCode:t},this.#e.log("ec_update_language_code",{languageCode:t})}get lastRenderConfig(){return this.#s}#l(t){if(t)return t;if(this.#a.enhancedContent.idType)return this.#a.enhancedContent.idType;throw new Error("No ID type specified.")}#f(){const t=document.createElement("iframe");return t.id=s,t.height="0",t.width="100%",t.style.border="0",t.scrolling="no",t}#y(){return this.#a.cdnRoot&&u.test(this.#a.cdnRoot)?this.#a.cdnRoot:this.#a.staging?c:a}#h(t,e){return`${this.#y()}/sdk/${this.#a.clientId}/${this.#a.languageCode}/BTF/${e}/${t}`}#v(t){return`${t}/${arguments.length>1&&void 0!==arguments[1]?arguments[1]:l}`}#g(t,e,n){if(t&&this.#a.tracking){const{content:e}=t,{sessionId:r}=this.#c;if(r)return function(t){const e=JSON.stringify(t.content),n=function(t,e){let n,r,o;const i=3&t.length,s=t.length-i;let a=0;const c=3432918353,u=461845907;for(r=0;r<s;)n=255&t.charCodeAt(r)|(255&t.charCodeAt(++r))<<8|(255&t.charCodeAt(++r))<<16|(255&t.charCodeAt(++r))<<24,++r,n=(65535&n)*c+(((n>>>16)*c&65535)<<16)&4294967295,n=n<<15|n>>>17,n=(65535&n)*u+(((n>>>16)*u&65535)<<16)&4294967295,a^=n,a=a<<13|a>>>19,o=5*(65535&a)+((5*(a>>>16)&65535)<<16)&4294967295,a=27492+(65535&o)+((58964+(o>>>16)&65535)<<16);switch(n=0,i){case 3:n^=(255&t.charCodeAt(r+2))<<16;case 2:n^=(255&t.charCodeAt(r+1))<<8;case 1:n^=255&t.charCodeAt(r),n=(65535&n)*c+(((n>>>16)*c&65535)<<16)&4294967295,n=n<<15|n>>>17,n=(65535&n)*u+(((n>>>16)*u&65535)<<16)&4294967295,a^=n}return a^=t.length,a^=a>>>16,a=2246822507*(65535&a)+((2246822507*(a>>>16)&65535)<<16)&4294967295,a^=a>>>13,a=3266489909*(65535&a)+((3266489909*(a>>>16)&65535)<<16)&4294967295,a^=a>>>16,a>>>0}(`${t.productId}${e}${t.sessionId}`)/4294967295;let r=0;const o=t.content.map((t=>r+=t.weight)).findIndex((t=>t>=n));return t.content[o]}({productId:n,content:e,sessionId:r}).source}return l}async#p(t,e){const n=`${t}/${e}`;if(!this.#i.has(n)){const i=this.#v(t,e);let s;try{s=await(o=i,fetch(o,{method:"HEAD"}))}catch(t){const e=t instanceof Error?t.message:void 0;return this.#e.log("error",{errorContext:"exists",errorType:"fetch",errorMessage:`Error on HEAD request of ${i}: ${e}`}),!1}this.#i.set(n,"0"!==s.headers.get(r.ContentLength))}var o;return this.#i.get(n)||!1}async#d(t,e){if(!t)return!1;let n=!1;for(const r of t)if(r.source&&(n=!0,!await this.#p(e,r.source)))return!1;return n}}const p={errorType:"validation",errorContext:"event"};class f{#e;constructor(t){this.#e=t}handle(t,e){this.#e.log(this.eventName,{...t,...e})}handleValidationError(t){throw this.#e.log("error",{...p,errorMessage:t}),new Error(t)}}class v extends f{eventName="navigation";handle(t){super.handle(t)}}const y=new RegExp(/^[A-Z]{3}$/);class m extends f{eventName="add_to_cart";handle(t,e){const n=this.#m(t);n?this.handleValidationError(n):super.handle(t,e)}#m(t){if(t.currency&&!y.test(t.currency))return`Invalid 3-character alphabetic ISO-4217 currency code: ${t.currency}. See: https://www.iso.org/iso-4217-currency-codes.html.`}}class b{#e;#u;#b;constructor(t,e,n){this.#e=t,this.#u=e,this.#b=n}navigation(t){this.#u?.beforeNavigation?.(t),new v(this.#e).handle(t),this.#u?.onNavigation?.(t)}addToCart(t){new m(this.#e).handle(t,{lastEcRenderConfig:this.#b?.lastRenderConfig})}}function w(t){const e=document.cookie.split("; ");for(const n of e){const[e,r]=n.split("=");if(e===t)return r}}function x(t,e){let n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"Mon, 01 Feb 2027 16:55:43 GMT",r=arguments.length>3&&void 0!==arguments[3]?arguments[3]:"315576000";const o=window.location.hostname;document.cookie=`${t}=${e};Path=/;Domain=${o};Expires=${n};Max-Age=${r}`}class S{#w=0;#x=null;clear(){this.#x&&(clearTimeout(this.#x),this.#w=0,this.#x=null)}start(t){this.#x&&clearTimeout(this.#x),this.#x=this.#S(t)}#S(t){return setTimeout((()=>{t(),this.#w++,this.#x=this.#S(t)}),Math.min(5e3*Math.pow(this.#w+1,2),3e5))}}class C{#c;#a;#C;#E=[];#x;constructor(t,e){this.#c=t,this.#a=e,this.#C=this.#a.staging?"https://retail-client-events-service-staging.internal.salsify.com/events":"https://retail-client-events-service.internal.salsify.com/events"}log(t,e,n){const r={code:"sdk_"+t,properties:e,context:n,timestamp:Date.now()/1e3};this.#I([r])}async#I(t){const e=[...this.#E.splice(0),...t];if(!e.length)return;const n={app:"sxp_sdk",channel:this.#c.clientId,csid:this.#c.sessionId,pagesessionid:this.#c.pageSessionId,jsSource:this.#c.jsSource,timestamp:Date.now()/1e3,logs:e};let r;try{r=await(o=this.#C,i=n,fetch(o,{method:"POST",body:JSON.stringify(i),headers:{"content-type":"text/plain"}}))}catch(t){return void this.#O(e)}var o,i;r.ok?this.#x?.clear():this.#O(e)}#O(t){this.#E.length>=1e3||(this.#E.push(...t.splice(0,1e3-this.#E.length)),this.#x||(this.#x=new S),this.#x.start((()=>this.#I(this.#E.splice(0)))))}}const E="1.0.3";class I{#c;#a;#P;constructor(t,e){this.#c=t,this.#a=e,this.#P=new C(this.#c,this.#a)}log(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};const n={version:E};o()?n.page={url:window.location.href,title:window.document.title,scrollPosition:window.scrollY}:n.serverSide=!0,"undefined"!=typeof localStorage&&localStorage?.sxp_sdk_debug?console.log("SXP SDK:",{clientId:this.#c.clientId,sessionId:this.#c.sessionId,pageSessionId:this.#c.pageSessionId,code:t,properties:e,context:n}):this.#P.log(t,e,n)}}class O{#e;#b;#j=0;#T=Date.now();#k;#A;#x;constructor(t,e){this.#e=t,this.#b=e,this.#k=this.#M.bind(this),this.#A=this.sendEvent.bind(this),this.#x=new S}start(){document.addEventListener("visibilitychange",this.#k),window.addEventListener("beforeunload",this.#A),this.#x.start(this.sendEvent.bind(this))}stop(){document.removeEventListener("visibilitychange",this.#k),window.removeEventListener("beforeunload",this.#A),this.#x.clear()}restart(){this.stop(),this.#j=0,this.#T=Date.now(),this.start()}sendEvent(){const t=Date.now();this.#j+=(t-this.#T)/1e3,this.#T=t,this.#e.log("time_on_page",{timeOnPage:this.#j,lastEcRenderConfig:this.#b?.lastRenderConfig})}#M(){"visible"===document.visibilityState?this.#T=Date.now():(this.sendEvent(),this.#x.clear())}}const P="salsify_session_id",j={languageCode:"en-US",tracking:!0},T={idType:"SDKID"},k=new class{#R=!1;#a;#b;#$;#c;#D=!1;#L;#_;constructor(t){this.#_=t}init(t){if(this.#R)throw new Error("Salsify Experiences SDK has already been initialized.");const e={...T,...t.enhancedContent};this.#a={...j,...t,enhancedContent:e},this.#c={url:o()?window.location.href:void 0,sessionId:this.#N(this.#a.tracking),pageSessionId:o()?crypto.randomUUID?.():void 0,tracking:this.#a.tracking,clientId:this.#a.clientId,languageCode:this.#a.languageCode,enhancedContent:this.#a.enhancedContent,version:E,jsSource:this.#_},o()&&(t=>{window.addEventListener("message",(e=>{var n;e.source&&g(e)&&"contextRequest"===e.data.messageType&&(e.ports.length?e.ports.forEach((e=>{e.postMessage(t)})):(n=e.source,"MessagePort"in window&&n instanceof MessagePort||"ServiceWorker"in window&&n instanceof ServiceWorker||!n.postMessage?e.source.postMessage(t):e.source.postMessage(t,e.origin)))}))})(this.#c);const n=(r=this.#c,i=this.#a,new I(r,i));var r,i;n.log("init",this.#a),this.#b=new d(this.#a,this.#c,n,{beforeRender:this.#F.bind(this),afterRender:this.#q.bind(this)}),o()&&(this.#L=new O(n,this.#b),this.#L.start()),this.#$=new b(n,{beforeNavigation:this.#z.bind(this)},this.#b),this.#R=!0}get initialized(){return this.#R}get enhancedContent(){if(!this.#b)throw new Error("Salsify Experiences SDK has not been initialized.");return this.#b}get events(){if(!this.#$)throw new Error("Salsify Experiences SDK has not been initialized.");return this.#$}#U(){let t=w(P);return t||(t=crypto.randomUUID?.(),t&&x(P,t)),t}#H(){var t;w(t=P)&&x(t,"","Thu, 01 Jan 1970 00:00:00 UTC","0")}#G(){this.#c&&(this.#c.pageSessionId=crypto.randomUUID?.(),this.#D=!1)}#F(){o()&&(this.#c&&(this.#c.url=window.location.href),this.#D&&this.#G())}#q(){o()&&(this.#D=!0)}#z(){o()&&(this.#c&&(this.#c.url=window.location.href),this.#D&&(this.#L?.sendEvent(),this.#L?.restart(),this.#G()))}#N(t){if(o())return t?this.#U():(this.#H(),"NOT_TRACKED")}}("bundle");if(!o())throw Error("It looks like you're attempting to use the Salisfy Experiences SDK bundle outside of a browser environment. Please use the NPM module instead: https://www.npmjs.com/package/salsify-experiences-sdk");window.salsifyExperiencesSdk=k,window.salsifyExperiencesSdkLoaded&&window.salsifyExperiencesSdkLoaded(k)})(); //# sourceMappingURL=salsify.js.map