@builder.io/sdk 2.0.6 → 2.0.7
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/CHANGELOG.md +18 -0
- package/dist/index.browser.js +2726 -1
- package/dist/index.browser.js.map +1 -1
- package/dist/index.cjs.js +29 -31
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.d.ts +7 -7
- package/dist/index.esm.js +22 -26
- package/dist/index.esm.js.map +1 -1
- package/dist/index.umd.js +31 -30
- package/dist/index.umd.js.map +1 -1
- package/dist/package.json +13 -9
- package/dist/src/builder.class.d.ts +862 -862
- package/dist/src/classes/animator.class.d.ts +26 -26
- package/dist/src/classes/cookies.class.d.ts +15 -15
- package/dist/src/classes/observable.class.d.ts +27 -27
- package/dist/src/classes/promise.class.d.ts +17 -17
- package/dist/src/classes/query-string.class.d.ts +9 -9
- package/dist/src/classes/query-string.class.test.d.ts +1 -1
- package/dist/src/constants/builder.d.ts +2 -2
- package/dist/src/functions/assign.function.d.ts +1 -1
- package/dist/src/functions/fetch.function.d.ts +28 -28
- package/dist/src/functions/finder.function.d.ts +10 -10
- package/dist/src/functions/get-top-level-domain.d.ts +6 -6
- package/dist/src/functions/next-tick.function.d.ts +2 -1
- package/dist/src/functions/omit.function.d.ts +1 -1
- package/dist/src/functions/server-only-require.function.d.ts +3 -3
- package/dist/src/functions/throttle.function.d.ts +1 -1
- package/dist/src/functions/to-error.d.ts +13 -13
- package/dist/src/functions/uuid.d.ts +8 -8
- package/dist/src/types/api-version.d.ts +2 -2
- package/dist/src/types/content.d.ts +31 -31
- package/dist/src/types/element.d.ts +60 -60
- package/dist/src/url.d.ts +9 -9
- package/dist/src/url.test.d.ts +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +13 -9
- package/project.json +4 -0
package/dist/index.browser.js
CHANGED
|
@@ -1,2 +1,2727 @@
|
|
|
1
|
-
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define("@builder.io/sdk",["exports"],t):t(e.BuilderIO={})}(this,function(exports){"use strict";var __assign=function(){return(__assign=Object.assign||function(e){for(var t,i=1,n=arguments.length;i<n;i++)for(var r in t=arguments[i])Object.prototype.hasOwnProperty.call(t,r)&&(e[r]=t[r]);return e}).apply(this,arguments)};!function(){if("undefined"==typeof window||"function"==typeof window.CustomEvent)return!1;window.CustomEvent=function(e,t){t=t||{bubbles:!1,cancelable:!1,detail:null};var i=document.createEvent("CustomEvent");return i.initCustomEvent(e,t.bubbles,t.cancelable,t.detail),i}}();var isSafari="undefined"!=typeof window&&/^((?!chrome|android).)*safari/i.test(window.navigator.userAgent);function nextTick(e){if("function"==typeof setImmediate&&"undefined"==typeof window)return setImmediate(e);if(isSafari||"undefined"==typeof MutationObserver)setTimeout(e);else{var t=0,i=new MutationObserver(function(){return e()}),n=document.createTextNode("");i.observe(n,{characterData:!0}),n.data=String(t=++t)}}var PROPERTY_NAME_DENY_LIST=Object.freeze(["__proto__","prototype","constructor"]),QueryString=function(){function e(){}return e.parseDeep=function(e){var t=this.parse(e);return this.deepen(t)},e.stringifyDeep=function(e){var t=this.flatten(e);return this.stringify(t)},e.parse=function(e){for(var t={},i=("?"===e[0]?e.substr(1):e).split("&"),n=0;n<i.length;n++){var r=i[n].split("=");try{t[decodeURIComponent(r[0])]=decodeURIComponent(r[1]||"")}catch(e){}}return t},e.stringify=function(e){var t="";for(var i in e)if(e.hasOwnProperty(i)){var n=e[i];t&&(t+="&"),t+=encodeURIComponent(i)+"="+encodeURIComponent(n)}return t},e.deepen=function(e){var t={};for(var i in e){for(var n=t,r=i.split("."),o=r.pop(),s=0,a=r;s<a.length;s++){var u=a[s];assertAllowedPropertyName(u),n=n[u]=n[u]||{}}n[o]=e[i]}return t},e.flatten=function(e,t,i){for(var n in void 0===i&&(i={}),e){var r=e[n],o=t?t+"."+n:n;r&&"object"==typeof r?this.flatten(r,o,i):i[o]=r}return i},e}();function assertAllowedPropertyName(e){if(PROPERTY_NAME_DENY_LIST.indexOf(e)>=0)throw new Error('Property name "'.concat(e,'" is not allowed'))}var version="2.0.5",Subscription=function(){function e(e,t){this.listeners=e,this.listener=t,this.unsubscribed=!1,this.otherSubscriptions=[]}return Object.defineProperty(e.prototype,"closed",{get:function(){return this.unsubscribed},enumerable:!1,configurable:!0}),e.prototype.add=function(e){this.otherSubscriptions.push(e)},e.prototype.unsubscribe=function(){if(!this.unsubscribed){if(this.listener&&this.listeners){var e=this.listeners.indexOf(this.listener);e>-1&&this.listeners.splice(e,1)}this.otherSubscriptions.forEach(function(e){return e.unsubscribe()}),this.unsubscribed=!0}},e}(),BehaviorSubject=function(){function e(e){var t=this;this.value=e,this.listeners=[],this.errorListeners=[],this.then=function(){for(var e,i=[],n=0;n<arguments.length;n++)i[n]=arguments[n];return(e=t.toPromise()).then.apply(e,i)}}return e.prototype.next=function(e){this.value=e;for(var t=0,i=this.listeners;t<i.length;t++){(0,i[t])(e)}},e.prototype.map=function(t){var i=new e(t(this.value));return this.subscribe(function(e){i.next(t(e))}),this.catch(function(e){i.error(e)}),i},e.prototype.catch=function(e){return this.errorListeners.push(e),new Subscription(this.errorListeners,e)},e.prototype.error=function(e){for(var t=0,i=this.errorListeners;t<i.length;t++){(0,i[t])(e)}},e.prototype.subscribe=function(e,t){return this.listeners.push(e),t&&this.errorListeners.push(t),new Subscription(this.listeners,e)},e.prototype.toPromise=function(){var e=this;return new Promise(function(t,i){var n=e.subscribe(function(e){t(e),n.unsubscribe()},function(e){i(e),n.unsubscribe()})})},e.prototype.promise=function(){return this.toPromise()},e}(),State={Pending:"Pending",Fulfilled:"Fulfilled",Rejected:"Rejected"};function isFunction(e){return e&&"function"==typeof e}function isObject(e){return e&&"object"==typeof e}var TinyPromise=function(){function e(e){this._state=State.Pending,this._handlers=[],this._value=null,e(this._resolve.bind(this),this._reject.bind(this))}return e.prototype._resolve=function(t){var i=this;if(t instanceof e)t.then(this._resolve.bind(this),this._reject.bind(this));else if(isObject(t)||isFunction(t)){var n=!1;try{var r=t.then;isFunction(r)?r.call(t,function(e){n||i._resolve(e),n=!0},function(e){n||i._reject(e),n=!0}):this._fulfill(t)}catch(e){n||this._reject(e)}}else this._fulfill(t)},e.prototype._fulfill=function(e){var t=this;this._state=State.Fulfilled,this._value=e,this._handlers.forEach(function(e){return t._callHandler(e)})},e.prototype._reject=function(e){var t=this;this._state=State.Rejected,this._value=e,this._handlers.forEach(function(e){return t._callHandler(e)})},e.prototype._isPending=function(){return this._state===State.Pending},e.prototype._isFulfilled=function(){return this._state===State.Fulfilled},e.prototype._isRejected=function(){return this._state===State.Rejected},e.prototype._addHandler=function(e,t){this._handlers.push({onFulfilled:e,onRejected:t})},e.prototype._callHandler=function(e){this._isFulfilled()&&isFunction(e.onFulfilled)?e.onFulfilled(this._value):this._isRejected()&&isFunction(e.onRejected)&&e.onRejected(this._value)},e.prototype.then=function(t,i){var n=this;switch(this._state){case State.Pending:return new e(function(e,r){n._addHandler(function(i){nextTick(function(){try{isFunction(t)?e(t(i)):e(i)}catch(e){r(e)}})},function(t){nextTick(function(){try{isFunction(i)?e(i(t)):r(t)}catch(e){r(e)}})})});case State.Fulfilled:return new e(function(e,i){nextTick(function(){try{isFunction(t)?e(t(n._value)):e(n._value)}catch(e){i(e)}})});case State.Rejected:return new e(function(e,t){nextTick(function(){try{isFunction(i)?e(i(n._value)):t(n._value)}catch(e){t(e)}})})}},e}(),Promise$1="undefined"!=typeof Promise?Promise:TinyPromise,serverOnlyRequire;try{serverOnlyRequire=eval("require")}catch(e){serverOnlyRequire=function(){return null}}var serverOnlyRequire$1=serverOnlyRequire;function promiseResolve(e){return new Promise$1(function(t){return t(e)})}function tinyFetch(e,t){return void 0===t&&(t={}),new Promise$1(function(i,n){var r=new XMLHttpRequest;if(r.open(t.method||"get",e,!0),t.headers)for(var o in t.headers)r.setRequestHeader(o,t.headers[o]);function s(){var e=[],t=[],i={},n=void 0;return r.getAllResponseHeaders().replace(/^(.*?):[^\S\n]*([\s\S]*?)$/gm,function(r,o,s){var a=o;return e.push(a=a.toLowerCase()),t.push([a,s]),n=i[a],i[a]=n?"".concat(n,",").concat(s):s,""}),{ok:2==(r.status/100|0),status:r.status,statusText:r.statusText,url:r.responseURL,clone:s,text:function(){return promiseResolve(r.responseText)},json:function(){return promiseResolve(r.responseText).then(JSON.parse)},blob:function(){return promiseResolve(new Blob([r.response]))},headers:{keys:function(){return e},entries:function(){return t},get:function(e){return i[e.toLowerCase()]},has:function(e){return e.toLowerCase()in i}}}}r.withCredentials="include"===t.credentials,r.onload=function(){i(s())},r.onerror=n,r.send(t.body)})}function getFetch(){var e=void 0;if(globalThis.fetch)null!=e||(e=globalThis.fetch);else if("undefined"==typeof window)try{null!=e||(e=serverOnlyRequire$1("node-fetch"))}catch(e){console.warn("node-fetch is not installed. consider polyfilling fetch or installing node-fetch."),console.warn(e)}return null!=e?e:tinyFetch}function assign(e){for(var t=[],i=1;i<arguments.length;i++)t[i-1]=arguments[i];for(var n=Object(e),r=1;r<arguments.length;r++){var o=arguments[r];if(null!=o)for(var s in o)Object.prototype.hasOwnProperty.call(o,s)&&(n[s]=o[s])}return n}function throttle(e,t,i){var n,r,o;void 0===i&&(i={});var s=null,a=0,u=function(){a=!1===i.leading?0:Date.now(),s=null,o=e.apply(n,r),s||(n=r=null)};return function(){var c=Date.now();a||!1!==i.leading||(a=c);var l=t-(c-a);return n=this,r=arguments,l<=0||l>t?(s&&(clearTimeout(s),s=null),a=c,o=e.apply(n,r),s||(n=r=null)):s||!1===i.trailing||(s=setTimeout(u,l)),o}}var camelCaseToKebabCase=function(e){return e?e.replace(/([A-Z])/g,function(e){return"-".concat(e[0].toLowerCase())}):""},Animator=function(){function e(){}return e.prototype.bindAnimations=function(e){for(var t=0,i=e;t<i.length;t++){var n=i[t];switch(n.trigger){case"pageLoad":this.triggerAnimation(n);break;case"hover":this.bindHoverAnimation(n);break;case"scrollInView":this.bindScrollInViewAnimation(n)}}},e.prototype.warnElementNotPresent=function(e){console.warn("Cannot animate element: element with ID ".concat(e," not found!"))},e.prototype.augmentAnimation=function(e,t){for(var i=this.getAllStylesUsed(e),n=getComputedStyle(t),r=0,o=[e.steps[0].styles,e.steps[e.steps.length-1].styles];r<o.length;r++)for(var s=o[r],a=0,u=i;a<u.length;a++){var c=u[a];c in s||(s[c]=n[c])}},e.prototype.getAllStylesUsed=function(e){for(var t=[],i=0,n=e.steps;i<n.length;i++){var r=n[i];for(var o in r.styles)-1===t.indexOf(o)&&t.push(o)}return t},e.prototype.triggerAnimation=function(e){var t=this,i=Array.prototype.slice.call(document.getElementsByClassName(e.elementId||e.id||""));i.length?Array.from(i).forEach(function(i){t.augmentAnimation(e,i),i.style.transition="none",i.style.transitionDelay="0",assign(i.style,e.steps[0].styles),setTimeout(function(){i.style.transition="all ".concat(e.duration,"s ").concat(camelCaseToKebabCase(e.easing)),e.delay&&(i.style.transitionDelay=e.delay+"s"),assign(i.style,e.steps[1].styles),setTimeout(function(){i.style.transition="",i.style.transitionDelay=""},1e3*(e.delay||0)+1e3*e.duration+100)})}):this.warnElementNotPresent(e.elementId||e.id||"")},e.prototype.bindHoverAnimation=function(e){var t=this,i=Array.prototype.slice.call(document.getElementsByClassName(e.elementId||e.id||""));i.length?Array.from(i).forEach(function(i){t.augmentAnimation(e,i);var n=e.steps[0].styles,r=e.steps[1].styles;function o(){assign(i.style,n)}o(),i.addEventListener("mouseenter",function(){assign(i.style,r)}),i.addEventListener("mouseleave",o),setTimeout(function(){i.style.transition="all ".concat(e.duration,"s ").concat(camelCaseToKebabCase(e.easing)),e.delay&&(i.style.transitionDelay=e.delay+"s")})}):this.warnElementNotPresent(e.elementId||e.id||"")},e.prototype.bindScrollInViewAnimation=function(e){var t=this,i=Array.prototype.slice.call(document.getElementsByClassName(e.elementId||e.id||""));i.length?Array.from(i).forEach(function(i){t.augmentAnimation(e,i);var n=!1,r=!1;function o(){!n&&a(i)?(n=!0,r=!0,setTimeout(function(){assign(i.style,e.steps[1].styles),e.repeat||document.removeEventListener("scroll",s),setTimeout(function(){r=!1,e.repeat||(i.style.transition="",i.style.transitionDelay="")},1e3*(e.duration+(e.delay||0))+100)})):e.repeat&&n&&!r&&!a(i)&&(n=!1,assign(i.style,e.steps[0].styles))}var s=throttle(o,200,{leading:!1});function a(t){var i=t.getBoundingClientRect(),n=window.innerHeight,r=(e.thresholdPercent||0)/100*n;return i.bottom>r&&i.top<n-r}var u=e.steps[0].styles;assign(i.style,u),setTimeout(function(){i.style.transition="all ".concat(e.duration,"s ").concat(camelCaseToKebabCase(e.easing)),e.delay&&(i.style.transitionDelay=e.delay+"s")}),document.addEventListener("scroll",s,{capture:!0,passive:!0}),o()}):this.warnElementNotPresent(e.elementId||e.id||"")},e}();function getTopLevelDomain(e){var t=e.split(".");return t.length>2?t.slice(1).join("."):e}var fieldContentRegExp=/^[\u0009\u0020-\u007e\u0080-\u00ff]+$/,Cookies=function(){function e(e,t){this.request=e,this.response=t}return e.prototype.get=function(e){var t=this.request.headers.cookie;if(t){var i=t.match(getPattern(e));if(i)return i[1]}},e.prototype.set=function(e,t,i){var n=this.response,r=this.request,o=n.getHeader("Set-Cookie")||[],s=void 0!==this.secure?!!this.secure:"https"===r.protocol||r.connection.encrypted,a=new Cookie(e,t,i);if("string"==typeof o&&(o=[o]),!s&&i&&i.secure)throw new Error("Cannot send secure cookie over unencrypted connection");return a.secure=s,i&&"secure"in i&&(a.secure=!!i.secure),a.domain=r.headers.host&&getTopLevelDomain(r.headers.host),pushCookie(o,a),n.setHeader.call(n,"Set-Cookie",o),this},e}(),Cookie=function(){function e(e,t,i){if(this.path="/",this.domain=void 0,this.httpOnly=!0,this.sameSite=!1,this.secure=!1,this.overwrite=!1,this.name="",this.value="",!fieldContentRegExp.test(e))throw new TypeError("argument name is invalid");if(t&&!fieldContentRegExp.test(t))throw new TypeError("argument value is invalid");t||(this.expires=new Date(0)),this.name=e,this.value=t||"",i.expires&&(this.expires=i.expires),i.secure&&(this.secure=i.secure)}return e.prototype.toString=function(){return"".concat(this.name,"=").concat(this.value)},e.prototype.toHeader=function(){var e=this.toString();return this.maxAge&&(this.expires=new Date(Date.now()+this.maxAge)),this.path&&(e+="; path=".concat(this.path)),this.expires&&(e+="; expires=".concat(this.expires.toUTCString())),this.domain&&(e+="; domain=".concat(this.domain)),e+="; SameSite=".concat(!0===this.sameSite?"strict":"None"),this.secure&&(e+="; secure"),this.httpOnly&&(e+="; httponly"),e},e}();function getPattern(e){return new RegExp("(?:^|;) *".concat(e.replace(/[-[\]{}()*+?.,\\^$|#\s]/g,"\\$&"),"=([^;]*)"))}function pushCookie(e,t){if(t.overwrite)for(var i=e.length-1;i>=0;i--)0===e[i].indexOf("".concat(t.name,"="))&&e.splice(i,1);e.push(t.toHeader())}function omit(e){for(var t=[],i=1;i<arguments.length;i++)t[i-1]=arguments[i];for(var n=Object.assign({},e),r=0,o=t;r<o.length;r++){delete n[o[r]]}return n}function uuidv4(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(e){var t=16*Math.random()|0;return("x"==e?t:3&t|8).toString(16)})}function uuid(){return uuidv4().replace(/-/g,"")}function emptyUrl(){return{query:null,port:null,auth:null,hash:null,host:null,hostname:null,href:null,path:null,pathname:null,protocol:null,search:null,slashes:null}}function parse(e){var t,i=emptyUrl();return""===e||"/"===e[0]?(t=new URL(e,"http://0.0.0.0/"),i.href=t.href,i.href=i.href.slice(14)):(t=new URL(e),i.href=t.href,i.port=""===t.port?null:t.port,i.hash=""===t.hash?null:t.hash,i.host=t.host,i.hostname=t.hostname,i.href=t.href,i.pathname=t.pathname,i.protocol=t.protocol,i.slashes="/"===e[t.protocol.length]),i.search=t.search,i.query=t.search.slice(1),i.path="".concat(t.pathname).concat(t.search),i.pathname=t.pathname,i}function pad(e,t){for(;e.length<t;)e="0"+e;return e}function fold(e,t){var i,n;if(0===t.length)return e;for(i=0,n=t.length;i<n;i++)e=(e<<5)-e+t.charCodeAt(i),e|=0;return e<0?-2*e:e}function foldObject(e,t,i){return Object.keys(t).sort().reduce(function(e,n){return foldValue(e,t[n],n,i)},e)}function foldValue(e,t,i,n){var r=fold(fold(fold(e,i),toString(t)),typeof t);if(null===t)return fold(r,"null");if(void 0===t)return fold(r,"undefined");if("object"==typeof t||"function"==typeof t){if(-1!==n.indexOf(t))return fold(r,"[Circular]"+i);n.push(t);var o=foldObject(r,t,n);if(!("valueOf"in t)||"function"!=typeof t.valueOf)return o;try{return fold(o,String(t.valueOf()))}catch(e){return fold(o,"[valueOf exception]"+(e.stack||e.message))}}return fold(r,t.toString())}function toString(e){return Object.prototype.toString.call(e)}function sum(e){return pad(foldValue(0,e,"",[]).toString(16),8)}var hashSum=sum;function toError(e){return e instanceof Error?e:new Error(String(e))}var DEFAULT_API_VERSION="v3";function datePlusMinutes(e){return void 0===e&&(e=30),new Date(Date.now()+6e4*e)}var isPositiveNumber=function(e){return"number"==typeof e&&!isNaN(e)&&e>=0},isReactNative="object"==typeof navigator&&"ReactNative"===navigator.product,validEnvList=["production","qa","test","development","dev","cdn-qa","cloud","fast","cdn2","cdn-prod"];function getQueryParam(e,t){for(var i=(e.split("?")[1]||"").split("&"),n=0;n<i.length;n++){var r=i[n].split("=");if(decodeURIComponent(r[0])===t)return decodeURIComponent(r[1])}return null}var urlParser={parse:function(e){var t=document.createElement("a");t.href=e;for(var i={},n=0,r=["username","password","host","hostname","port","protocol","origin","pathname","search","hash"];n<r.length;n++){var o=r[n];i[o]=t[o]}return!i.pathname&&""!==i.pathname||"string"!=typeof i.pathname||0===i.pathname.indexOf("/")||(i.pathname="/"+i.pathname),i}},parse$1=isReactNative?function(){return emptyUrl()}:"object"==typeof window?urlParser.parse:parse;function setCookie(e,t,i){try{var n="";i&&(n="; expires="+i.toUTCString());var r=!isBrowser||"https:"===location.protocol;document.cookie=e+"="+(t||"")+n+"; path=/"+"; domain=".concat(getTopLevelDomain(location.hostname))+(r?";secure ; SameSite=None":"")}catch(e){console.warn("Could not set cookie",e)}}function getCookie(e){try{return decodeURIComponent(document.cookie.replace(new RegExp("(?:(?:^|.*;)\\s*"+encodeURIComponent(e).replace(/[\-\.\+\*]/g,"\\$&")+"\\s*\\=\\s*([^;]*).*$)|^.*$"),"$1"))||null}catch(e){console.warn("Could not get cookie",e)}}function size(e){return Object.keys(e).length}function find(e,t){for(var i=e,n=i.length>>>0,r=arguments[1],o=0;o<n;o++){var s=i[o];if(t.call(r,s,o,i))return s}}var sessionStorageKey="builderSessionId",localStorageKey="builderVisitorId",isBrowser="undefined"!=typeof window&&!isReactNative,isIframe=isBrowser&&window.top!==window.self;function BuilderComponent(e){return void 0===e&&(e={}),Builder.Component(e)}var Builder=function(){function e(t,i,n,r,o,s){void 0===t&&(t=null),void 0===r&&(r=!1),void 0===o&&(o=null);var a=this;if(this.request=i,this.response=n,this.eventsQueue=[],this.throttledClearEventsQueue=throttle(function(){a.processEventsQueue(),a.setCookie(sessionStorageKey,a.sessionId,datePlusMinutes(30))},5),this.env="production",this.sessionId=this.getSessionId(),this.targetContent=!0,this.contentPerRequest=1,this.allowCustomFonts=!0,this.cookies=null,this.cachebust=!1,this.overrideParams="",this.noCache=!1,this.preview=!1,this.apiVersion$=new BehaviorSubject(void 0),this.canTrack$=new BehaviorSubject(!this.browserTrackingDisabled),this.apiKey$=new BehaviorSubject(null),this.authToken$=new BehaviorSubject(null),this.userAttributesChanged=new BehaviorSubject(null),this.editingMode$=new BehaviorSubject(isIframe),this.editingModel$=new BehaviorSubject(null),this.userAgent="object"==typeof navigator&&navigator.userAgent||"",this.trackingHooks=[],this.visitorId=this.getVisitorId(),this.autoTrack=!!e.isBrowser&&!(this.isDevelopmentEnv||e.isBrowser&&-1!==location.search.indexOf("builder.preview=")),this.trackingUserAttributes={},this.blockContentLoading="",this.observersByKey={},this.noEditorUpdates={},this.overrides={},this.queryOptions={},this.getContentQueue=null,this.priorContentQueue=null,this.testCookiePrefix="builder.tests",this.cookieQueue=[],e.isBrowser&&!r&&e.singletonInstance)return e.singletonInstance;this.request&&this.response&&(this.setUserAgent(this.request.headers["user-agent"]||""),this.cookies=new Cookies(this.request,this.response)),t&&(this.apiKey=t),s&&(this.apiVersion=s),o&&(this.authToken=o),isBrowser&&(this.bindMessageListeners(),e.isEditing&&parent.postMessage({type:"builder.animatorOptions",data:{options:{version:2}}},"*")),isIframe&&this.messageFrameLoaded(),this.canTrack$.subscribe(function(e){if(e){if("undefined"!=typeof sessionStorage)try{sessionStorage.getItem(sessionStorageKey)||sessionStorage.setItem(sessionStorageKey,a.sessionId)}catch(e){console.debug("Session storage error",e)}a.eventsQueue.length&&a.throttledClearEventsQueue(),a.cookieQueue.length&&(a.cookieQueue.forEach(function(e){a.setCookie(e[0],e[1])}),a.cookieQueue.length=0)}}),isBrowser&&(this.setTestsFromUrl(),this.getOverridesFromQueryString())}return e.register=function(t,i){var n=this.registry[t];if(n||(n=this.registry[t]=[]),n.push(i),e.isBrowser){var r={type:"builder.register",data:{type:t,info:i}};try{parent.postMessage(r,"*"),parent!==window&&window.postMessage(r,"*")}catch(e){console.debug("Could not postmessage",e)}}this.registryChange.next(this.registry)},e.registerEditor=function(t){if(e.isBrowser){window.postMessage({type:"builder.registerEditor",data:omit(t,"component")},"*");var i=location.hostname;e.isTrustedHost(i)||console.error("Builder.registerEditor() called in the wrong environment! You cannot load custom editors from your app, they must be loaded through the Builder.io app itself. Follow the readme here for more details: https://github.com/builderio/builder/tree/master/plugins/cloudinary or contact chat us in our Spectrum community for help: https://spectrum.chat/builder")}this.editors.push(t)},e.registerPlugin=function(e){this.plugins.push(e)},e.registerAction=function(e){this.actions.push(e)},e.registerTrustedHost=function(e){this.trustedHosts.push(e)},e.setServerContext=function(e){this.serverContext=e},e.isTrustedHost=function(e){return this.trustedHosts.findIndex(function(t){return t===e||e.endsWith(".".concat(t))})>-1},e.runAction=function(e){if(!("string"==typeof e?find(this.actions,function(t){return t.name===e}):e))throw new Error("Action not found: ".concat(e))},e.fields=function(e,t){var i;null===(i=window.parent)||void 0===i||i.postMessage({type:"builder.fields",data:{name:e,fields:t}},"*")},e.set=function(t){e.register("editor.settings",t)},e.import=function(t){if(e.isBrowser){var i=window.System;if(i)return i.import("https://cdn.builder.io/systemjs/".concat(t));console.warn("System.js not available. Please include System.js when using Builder.import")}else console.warn("Builder.import used on the server - this should only be used in the browser")},Object.defineProperty(e,"editingPage",{get:function(){return this._editingPage},set:function(e){this._editingPage=e,isBrowser&&isIframe&&(e?document.body.classList.add("builder-editing-page"):document.body.classList.remove("builder-editing-page"))},enumerable:!1,configurable:!0}),e.prepareComponentSpecToSend=function(e){return __assign(__assign(__assign({},e),e.inputs&&{inputs:e.inputs.map(function(e){for(var t,i=0,n=["onChange","showIf"];i<n.length;i++){var r=n[i];if(e[r]&&"function"==typeof e[r]){var o=e[r];e=__assign(__assign({},e),((t={})[r]="return (".concat(o.toString(),").apply(this, arguments)"),t))}}return e})}),{hooks:Object.keys(e.hooks||{}).reduce(function(t,i){var n=e.hooks&&e.hooks[i];return n?(t[i]="string"==typeof n?n:"return (".concat(n.toString(),").apply(this, arguments)"),t):t},{}),class:void 0})},e.registerBlock=function(e,t){this.registerComponent(e,t)},e.registerComponent=function(e,t){var i,n=__assign(__assign({class:e},e.builderOptions),t);if(this.addComponent(n),t.models&&this.singletonInstance.editingModel?isBrowser&&t.models.includes(this.singletonInstance.editingModel):isBrowser){var r=this.prepareComponentSpecToSend(n);null===(i=window.parent)||void 0===i||i.postMessage({type:"builder.registerComponent",data:r},"*")}},e.addComponent=function(e){var t=find(this.components,function(t){return t.name===e.name});if(t){if(t.class&&!e.class)return;this.components.splice(this.components.indexOf(t),1,e)}else this.components.push(e)},e.component=function(e){var t=this;return void 0===e&&(e={}),function(i){var n,r=__assign(__assign({},e),{class:i});r.name||(r.name=i.name),t.addComponent(r);var o=t.prepareComponentSpecToSend(r);return isBrowser&&(null===(n=window.parent)||void 0===n||n.postMessage({type:"builder.registerComponent",data:o},"*")),i}},Object.defineProperty(e,"Component",{get:function(){return this.component},enumerable:!1,configurable:!0}),e.prototype.processEventsQueue=function(){if(this.eventsQueue.length){var t=this.eventsQueue;this.eventsQueue=[];for(var i=__assign(__assign({},e.overrideUserAttributes),this.trackingUserAttributes),n=0,r=t;n<r.length;n++){var o=r[n];o.data.metadata||(o.data.metadata={}),o.data.metadata.user||(o.data.metadata.user={}),Object.assign(o.data.metadata.user,i,o.data.metadata.user)}var s=this.host;getFetch()("".concat(s,"/api/v1/track"),{method:"POST",body:JSON.stringify({events:t}),headers:{"content-type":"application/json"},mode:"cors"}).catch(function(){})}},Object.defineProperty(e.prototype,"browserTrackingDisabled",{get:function(){return e.isBrowser&&Boolean(window.builderNoTrack||!navigator.cookieEnabled)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"canTrack",{get:function(){return this.canTrack$.value},set:function(e){this.canTrack!==e&&this.canTrack$.next(e)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"apiVersion",{get:function(){return this.apiVersion$.value},set:function(e){this.apiVersion!==e&&this.apiVersion$.next(e)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"editingMode",{get:function(){return this.editingMode$.value},set:function(e){e!==this.editingMode&&this.editingMode$.next(e)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"editingModel",{get:function(){return this.editingModel$.value},set:function(e){e!==this.editingModel&&this.editingModel$.next(e)},enumerable:!1,configurable:!0}),e.prototype.findParentElement=function(e,t,i){if(void 0===i&&(i=!0),!(e instanceof HTMLElement))return null;var n=i?e:e.parentElement;do{if(!n)return null;if(t(n))return n}while(n=n.parentElement);return null},e.prototype.findBuilderParent=function(e){return this.findParentElement(e,function(e){var t=e.getAttribute("builder-id")||e.id;return Boolean(t&&0===t.indexOf("builder-"))})},e.prototype.setUserAgent=function(e){this.userAgent=e||""},e.prototype.setTrackingHook=function(e){this.trackingHooks.push(e)},e.prototype.track=function(t,i,n){if(void 0===i&&(i={}),!isIframe&&isBrowser&&!e.isPreviewing){var r=this.apiKey;if(r){for(var o=JSON.parse(JSON.stringify({type:t,data:__assign(__assign({},omit(i,"meta")),{metadata:__assign(__assign({sdkVersion:e.VERSION,url:location.href},i.meta),i.metadata),ownerId:r,userAttributes:this.getUserAttributes(),sessionId:this.sessionId,visitorId:this.visitorId})})),s=0,a=this.trackingHooks;s<a.length;s++){var u=(0,a[s])(o,n||{});u&&(o=u)}this.eventsQueue.push(o),this.canTrack&&this.throttledClearEventsQueue()}else console.error('Builder integration error: Looks like the Builder SDK has not been initialized properly (your API key has not been set). Make sure you are calling `builder.init("«YOUR-API-KEY»");` as early as possible in your application\'s code.')}},e.prototype.getSessionId=function(){var t=this,i=null;try{e.isBrowser&&"undefined"!=typeof sessionStorage&&(i=this.getCookie(sessionStorageKey))}catch(e){console.debug("Session storage error",e)}return i||(i=uuid()),e.isBrowser&&setTimeout(function(){try{t.canTrack&&t.setCookie(sessionStorageKey,i,datePlusMinutes(30))}catch(e){console.debug("Cookie setting error",e)}}),i},e.prototype.getVisitorId=function(){var t=this;if(this.visitorId)return this.visitorId;var i=null;try{e.isBrowser&&"undefined"!=typeof localStorage&&(i=localStorage.getItem(localStorageKey))}catch(e){console.debug("Local storage error",e)}return i||(i=uuid()),this.visitorId=i,e.isBrowser&&setTimeout(function(){try{t.canTrack&&"undefined"!=typeof localStorage&&i&&localStorage.setItem(localStorageKey,i)}catch(e){console.debug("Session storage error",e)}}),i},e.prototype.trackImpression=function(t,i,n,r){isIframe||!isBrowser||e.isPreviewing||this.track("impression",{contentId:t,variationId:i!==t?i:void 0,metadata:n},r)},e.prototype.trackConversion=function(t,i,n,r,o){if(!isIframe&&isBrowser&&!e.isPreviewing){var s="object"==typeof i?i:r,a="string"==typeof i?i:void 0;this.track("conversion",{amount:t,variationId:n,meta:s,contentId:a},o)}},Object.defineProperty(e.prototype,"isDevelopmentEnv",{get:function(){return e.isIframe||e.isBrowser&&("localhost"===location.hostname||""!==location.port)||"production"!==this.env},enumerable:!1,configurable:!0}),e.prototype.trackInteraction=function(t,i,n,r,o){if(void 0===n&&(n=!1),!isIframe&&isBrowser&&!e.isPreviewing){var s=r&&r.target,a=s&&this.findBuilderParent(s),u={};if(r){var c=r.clientX,l=r.clientY;if(s){var d=c-(g=s.getBoundingClientRect()).left,h=l-g.top,p=m(d/g.width),f=m(h/g.height);u.targetOffset={x:p,y:f}}if(a){var g;d=c-(g=a.getBoundingClientRect()).left,h=l-g.top,p=m(d/g.width),f=m(h/g.height);u.builderTargetOffset={x:p,y:f}}}var v=a&&(a.getAttribute("builder-id")||a.id);v&&a&&(u.builderElementIndex=[].slice.call(document.getElementsByClassName(v)).indexOf(a)),this.track("click",{contentId:t,metadata:u,variationId:i!==t?i:void 0,unique:!n,targetBuilderElement:v||void 0},o)}function m(e){return Math.round(1e3*e)/1e3}},e.prototype.component=function(t){return void 0===t&&(t={}),e.component(t)},Object.defineProperty(e.prototype,"apiKey",{get:function(){return this.apiKey$.value},set:function(e){this.apiKey$.next(e)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"authToken",{get:function(){return this.authToken$.value},set:function(e){this.authToken$.next(e)},enumerable:!1,configurable:!0}),e.prototype.modifySearch=function(e){return e.replace(/(^|&|\?)(builder_.*?)=/gi,function(e,t,i){return t+i.replace(/_/g,".")+"="})},e.prototype.setTestsFromUrl=function(){var e=this.getLocation().search,t=QueryString.parseDeep(this.modifySearch(e||"").substr(1)),i=t.builder&&t.builder.tests;if(i&&"object"==typeof i)for(var n in i)i.hasOwnProperty(n)&&this.setTestCookie(n,i[n])},e.prototype.resetOverrides=function(){e.overrideUserAttributes={},this.cachebust=!1,this.noCache=!1,this.preview=!1,this.editingModel=null,this.overrides={},this.env="production",this.userAgent="",this.request=void 0,this.response=void 0},e.prototype.getOverridesFromQueryString=function(){var t=this.getLocation(),i=QueryString.parseDeep(this.modifySearch(t.search||"").substr(1)),n=i.builder;if(n){var r=n.userAttributes,o=n.overrides,s=n.env,a=(n.host,n.api),u=n.cachebust,c=n.noCache,l=n.preview,d=n.editing,h=n.frameEditing,p=n.options,f=n.params;if(r&&this.setUserAttributes(r),p&&(this.queryOptions=__assign(__assign(__assign({},p.locale&&{locale:p.locale}),p.includeRefs&&{includeRefs:p.includeRefs}),p.enrich&&{enrich:p.enrich})),o&&(this.overrides=o),validEnvList.indexOf(s||a)>-1&&(this.env=s||a),e.isEditing){var g=h||d||l;g&&"true"!==g&&(this.editingModel=g)}u&&(this.cachebust=!0),c&&(this.noCache=!0),l&&(this.preview=!0),i&&(this.overrideParams=f)}},e.prototype.messageFrameLoaded=function(){var e;null===(e=window.parent)||void 0===e||e.postMessage({type:"builder.loaded",data:{value:!0}},"*")},e.prototype.bindMessageListeners=function(){var t=this;isBrowser&&addEventListener("message",function(i){var n,r,o,s,a,u=parse$1(i.origin),c=-1===["builder.register","builder.registerComponent"].indexOf(null===(n=i.data)||void 0===n?void 0:n.type),l=u.hostname&&e.isTrustedHost(u.hostname);if(!c||l){var d=i.data;if(d)switch(d.type){case"builder.ping":null===(r=window.parent)||void 0===r||r.postMessage({type:"builder.pong",data:{}},"*");break;case"builder.register":if(i.source===window)break;var h=d.data;if(!h)break;var p=h.type,f=h.info,g=e.registry[p];g||(g=e.registry[p]=[]),g.push(f),e.registryChange.next(e.registry);break;case"builder.settingsChange":if(i.source===window)break;var v=d.data;if(!v)break;Object.assign(e.settings,v),e.settingsChange.next(e.settings);break;case"builder.registerEditor":if(i.source===window)break;var m=d.data;if(!m)break;var y=!!m.component;e.editors.every(function(t,i){return m.name!==t.name||!(t.component&&!y)&&(e.editors[i]=t,!1)});break;case"builder.triggerAnimation":e.animator.triggerAnimation(d.data);break;case"builder.contentUpdate":var b=d.data.key||d.data.alias||d.data.entry||d.data.modelName,w=d.data.data,k=t.observersByKey[b];k&&!t.noEditorUpdates[b]&&k.next([w]);break;case"builder.getComponents":null===(o=window.parent)||void 0===o||o.postMessage({type:"builder.components",data:e.components.map(function(t){return e.prepareComponentSpecToSend(t)})},"*");break;case"builder.editingModel":t.editingModel=d.data.model;break;case"builder.registerComponent":var C=d.data;e.addComponent(C);break;case"builder.blockContentLoading":"string"==typeof d.data.model&&(t.blockContentLoading=d.data.model);break;case"builder.editingMode":d.data?(t.editingMode=!0,document.body.classList.add("builder-editing")):(t.editingMode=!1,document.body.classList.remove("builder-editing"));break;case"builder.editingPageMode":var S=d.data;e.editingPage=S;break;case"builder.overrideUserAttributes":var _=d.data;assign(e.overrideUserAttributes,_),t.flushGetContentQueue(!0);break;case"builder.overrideTestGroup":var x=d.data,T=x.variationId,I=x.contentId;T&&I&&(t.setTestCookie(I,T),t.flushGetContentQueue(!0));break;case"builder.evaluate":var P=d.data.text,B=d.data.arguments||[],O=d.data.id,E=new Function(P),A=void 0,j=null;try{A=E.apply(t,B)}catch(e){j=toError(e)}j?null===(s=window.parent)||void 0===s||s.postMessage({type:"builder.evaluateError",data:{id:O,error:j.message}},"*"):A&&"function"==typeof A.then?A.then(function(e){var t;null===(t=window.parent)||void 0===t||t.postMessage({type:"builder.evaluateResult",data:{id:O,result:e}},"*")}).catch(console.error):null===(a=window.parent)||void 0===a||a.postMessage({type:"builder.evaluateResult",data:{result:A,id:O}},"*")}}})},Object.defineProperty(e.prototype,"defaultCanTrack",{get:function(){return Boolean(e.isBrowser&&navigator.userAgent.trim()&&!navigator.userAgent.match(/bot|crawler|spider|robot|crawling|prerender|google|baidu|bing|msn|duckduckbot|teoma|slurp|yandex|phantom|headless|selenium|puppeteer/i)&&!this.browserTrackingDisabled)},enumerable:!1,configurable:!0}),e.prototype.init=function(e,t,i,n,r,o){return void 0===t&&(t=this.defaultCanTrack),i&&(this.request=i),n&&(this.response=n),this.canTrack=t,this.apiKey=e,r&&(this.authToken=r),o&&(this.apiVersion=o),this},Object.defineProperty(e.prototype,"previewingModel",{get:function(){var e=this.getLocation().search;return QueryString.parse((e||"").substr(1))["builder.preview"]},enumerable:!1,configurable:!0}),e.prototype.getLocation=function(){var e,t={};return this.request?t=parse$1(null!==(e=this.request.url)&&void 0!==e?e:""):"object"==typeof location&&(t=parse$1(location.href)),""===t.pathname&&(t.pathname="/"),t},e.prototype.getUserAttributes=function(t){void 0===t&&(t=this.userAgent||"");var i={Android:function(){return t.match(/Android/i)},BlackBerry:function(){return t.match(/BlackBerry/i)},iOS:function(){return t.match(/iPhone|iPod/i)},Opera:function(){return t.match(/Opera Mini/i)},Windows:function(){return t.match(/IEMobile/i)||t.match(/WPDesktop/i)},any:function(){return i.Android()||i.BlackBerry()||i.iOS()||i.Opera()||i.Windows()}},n=t.match(/Tablet|iPad/i),r=this.getLocation();return __assign({urlPath:r.pathname,host:r.host||r.hostname,device:n?"tablet":i.any()?"mobile":"desktop"},e.overrideUserAttributes)},e.prototype.setUserAttributes=function(t){assign(e.overrideUserAttributes,t),this.userAttributesChanged.next(t)},e.prototype.setTrackingUserAttributes=function(e){assign(this.trackingUserAttributes,e)},e.prototype.get=function(t,i){void 0===i&&(i={});var n=this;return e.isBrowser?(i.apiKey&&!this.apiKey&&(this.apiKey=i.apiKey),i.authToken&&!this.authToken&&(this.authToken=i.authToken),i.apiVersion&&!this.apiVersion&&(this.apiVersion=i.apiVersion)):(n=new e(i.apiKey||this.apiKey,i.req,i.res,void 0,i.authToken||this.authToken,i.apiVersion||this.apiVersion)).setUserAttributes(this.getUserAttributes()),n.queueGetContent(t,i).map(function(t){var i=t&&t[0];if(e.isStatic)return i;var n=i&&i.data;return n?(void 0!==n.blocksString&&(n.blocks=JSON.parse(n.blocksString),delete n.blocksString),{data:n,id:i.id,variationId:i.testVariationId||i.variationId||null,testVariationId:i.testVariationId||i.variationId||null,testVariationName:i.testVariationName||null,lastUpdated:i.lastUpdated||null}):null})},e.prototype.queueGetContent=function(t,i){var n=this;void 0===i&&(i={});var r=i.key||i.alias||t,o=this.editingModel===t,s=this.observersByKey[r];"DEMO"!==this.apiKey||this.overrides[r]||i.initialContent||(i.initialContent=[]);var a=i.initialContent;if(s&&(!s.value||i.cache))return s.value&&nextTick(function(){s.next(s.value)}),s;if(o&&e.isBrowser&&parent.postMessage({type:"builder.updateContent",data:{options:i}},"*"),!a)if(this.getContentQueue||(this.getContentQueue=[]),this.getContentQueue.push(__assign(__assign({},i),{model:t,key:r})),this.getContentQueue&&this.getContentQueue.length>=this.contentPerRequest){var u=this.getContentQueue.slice();this.getContentQueue=[],nextTick(function(){n.flushGetContentQueue(!1,u)})}else nextTick(function(){n.flushGetContentQueue()});var c=new BehaviorSubject(null);return this.observersByKey[r]=c,i.noEditorUpdates&&(this.noEditorUpdates[r]=!0),a&&nextTick(function(){c.next(a)}),c},e.prototype.requestUrl=function(e,t){return getFetch()(e,__assign({next:__assign({revalidate:1},null==t?void 0:t.next)},t)).then(function(e){return e.json()})},Object.defineProperty(e.prototype,"host",{get:function(){switch(this.env){case"qa":return"https://qa.builder.io";case"test":return"https://builder-io-test.web.app";case"fast":return"https://fast.builder.io";case"cloud":return"https://cloud.builder.io";case"cdn2":return"https://cdn2.builder.io";case"cdn-qa":return"https://cdn-qa.builder.io";case"development":case"dev":return"http://localhost:5000";case"cdn-prod":return"https://cdn.builder.io";default:return e.overrideHost||"https://cdn.builder.io"}},enumerable:!1,configurable:!0}),e.prototype.flushGetContentQueue=function(t,i){var n=this;if(void 0===t&&(t=!1),!this.apiKey)throw new Error("Fetching content failed, expected apiKey to be defined instead got: ".concat(this.apiKey));if(this.apiVersion){if(!["v1","v3"].includes(this.apiVersion))throw new Error("Invalid apiVersion: expected 'v1' or 'v3', received '".concat(this.apiVersion,"'"))}else this.apiVersion=DEFAULT_API_VERSION;if(t||this.getContentQueue){var r=i||(t?this.priorContentQueue:this.getContentQueue)||[];this.getOverridesFromQueryString();var o=__assign(__assign({omit:r[0].omit||"meta.componentsUsed",apiKey:this.apiKey},r[0].options),this.queryOptions);r[0].locale&&(o.locale=r[0].locale),r[0].fields&&(o.fields=r[0].fields),r[0].format&&(o.format=r[0].format);var s="undefined"!=typeof location?QueryString.parseDeep(location.search.substr(1)):{},a=r&&r[0].userAttributes?r[0].userAttributes:this.targetContent?this.getUserAttributes():{urlPath:this.getLocation().pathname};if(r.find(function(e){return!!e.includeUrl})){var u=this.getLocation();u.origin&&(o.url="".concat(u.origin).concat(u.pathname).concat(u.search))}var c=null==i?void 0:i.find(function(e){return e.url});if((null==c?void 0:c.url)&&(a.urlPath=c.url.split("?")[0]),o.userAttributes=a,t||i||(this.priorContentQueue=r,this.getContentQueue=null),(this.cachebust||isIframe||s.cachebust||s["builder.cachebust"]||"production"!==this.env)&&(o.cachebust=!0),e.isEditing&&(o.isEditing=!0),(this.noCache||"production"!==this.env)&&(o.noCache=!0),size(this.overrides))for(var l in this.overrides)this.overrides.hasOwnProperty(l)&&(o["overrides.".concat(l)]=this.overrides[l]);for(var d=0,h=r;d<h.length;d++){var p=h[d];p.format&&(o.format=p.format),p.static&&(o.static=p.static),p.cachebust&&(o.cachebust=p.cachebust),isPositiveNumber(p.cacheSeconds)&&(o.cacheSeconds=p.cacheSeconds),isPositiveNumber(p.staleCacheSeconds)&&(o.staleCacheSeconds=p.staleCacheSeconds);for(var f=0,g=["prerender","extractCss","limit","offset","query","preview","model","entry","rev","static"];f<g.length;f++){var v=p[l=g[f]];void 0!==v&&(o.options=o.options||{},o.options[p.key]=o.options[p.key]||{},o.options[p.key][l]=JSON.stringify(v))}}this.preview&&(o.preview="true");var m=Object.keys(o).length>0,y=this.host,b=r.map(function(e){return encodeURIComponent(e.key)}).join(",");if(this.overrideParams)assign(o,omit(QueryString.parse(this.overrideParams),"apiKey"));var w=QueryString.stringifyDeep(o),k=o.format,C={headers:{},next:{revalidate:1}};this.authToken&&(C.headers=__assign(__assign({},C.headers),{Authorization:"Bearer ".concat(this.authToken)}));var S="solid"===k||"react"===k?"codegen":"query",_="query"===S?this.apiVersion:"v1",x="".concat(y,"/api/").concat(_,"/").concat(S,"/").concat(this.apiKey,"/").concat(b)+(o&&m?"?".concat(w):"");return getFetch()(x,C).then(function(e){return e.json()}).then(function(t){for(var i=0,o=r;i<o.length;i++){var s=o[i],a=s.key;if(s.model!==n.blockContentLoading||s.noEditorUpdates){n.editingModel===s.model&&e.isEditing&&parent.postMessage({type:"builder.updateContent",data:{options:s}},"*");var u=n.observersByKey[a];if(!u)return;var c=t[a],l=c;if(c){var d=e.isServer?l:n.processResultsForTests(l);u.next(d)}else{if((n.getLocation().search||"").includes("builder.preview="+s.model)){u.next([{id:"preview",name:"Preview",data:{}}])}u.next([])}}}},function(e){for(var t=0,i=r;t<i.length;t++){var o=i[t],s=n.observersByKey[o.key];if(!s)return;s.error(e)}})}},e.prototype.processResultsForTests=function(e){var t,i=this,n=e.map(function(e){if(!e.variations)return e;var t=i.getTestCookie(e.id),n=t===e.id?e:e.variations[t];if(n)return __assign(__assign({},e),{data:n.data,variationId:t,testVariationId:t,testVariationName:n.name});if(i.canTrack&&e.variations&&size(e.variations)){var r=0,o=Math.random();for(var s in e.variations){var a=e.variations[s];if(o<(r+=a.testRatio)){i.setTestCookie(e.id,a.id);var u=a.name||(a.id===e.id?"Default variation":"");return __assign(__assign({},e),{data:a.data,variationId:a.id,testVariationId:a.id,variationName:u,testVariationName:u})}}i.setTestCookie(e.id,e.id)}return __assign(__assign(__assign({},e),{variationId:e.id}),e.variations&&size(e.variations)&&{testVariationId:e.id,testVariationName:"Default variation"})});return isIframe&&(null===(t=window.parent)||void 0===t||t.postMessage({type:"builder.contentResults",data:{results:n}},"*")),n},e.prototype.getTestCookie=function(e){return this.getCookie("".concat(this.testCookiePrefix,".").concat(e))},e.prototype.setTestCookie=function(e,t){if(this.canTrack){var i=new Date;return i.setDate(i.getDate()+30),this.setCookie("".concat(this.testCookiePrefix,".").concat(e),t,i)}this.cookieQueue.push([e,t])},e.prototype.getCookie=function(t){return this.cookies?this.cookies.get(t):e.isBrowser&&getCookie(t)},e.prototype.setCookie=function(t,i,n){return!this.cookies||e.isServer&&e.isStatic?e.isBrowser&&setCookie(t,i,n):this.cookies.set(t,i,{expires:n,secure:"https:"===this.getLocation().protocol})},e.prototype.getContent=function(e,t){if(void 0===t&&(t={}),!this.apiKey)throw new Error("Fetching content from model ".concat(e," failed, expected apiKey to be defined instead got: ").concat(this.apiKey));return this.queueGetContent(e,t)},e.prototype.getAll=function(t,i){void 0===i&&(i={});var n=this;return e.isBrowser?(i.apiKey&&!this.apiKey&&(this.apiKey=i.apiKey),i.apiVersion&&!this.apiVersion&&(this.apiVersion=i.apiVersion)):(n=new e(i.apiKey||this.apiKey,i.req,i.res,!1,null,i.apiVersion||this.apiVersion)).setUserAttributes(this.getUserAttributes()),n.getContent(t,__assign(__assign({limit:30},i),{key:i.key||e.isBrowser?"".concat(t,":").concat(hashSum(omit(i,"initialContent","req","res"))):void 0})).promise()},e.VERSION=version,e.components=[],e.isStatic=!0,e.animator=new Animator,e.nextTick=nextTick,e.throttle=throttle,e.editors=[],e.trustedHosts=["builder.io","localhost"],e.plugins=[],e.actions=[],e.registry={},e.registryChange=new BehaviorSubject({}),e._editingPage=!1,e.isIframe=isIframe,e.isBrowser=isBrowser,e.isReactNative=isReactNative,e.isServer=!isBrowser&&!isReactNative,e.previewingModel=e.isBrowser&&getQueryParam(location.href,"builder.preview"),e.settings={},e.settingsChange=new BehaviorSubject({}),e.isEditing=Boolean(isIframe&&(document.referrer&&document.referrer.match(/builder\.io|localhost:1234/)||-1!==location.search.indexOf("builder.frameEditing="))),e.isPreviewing=Boolean(isBrowser&&(-1!==location.search.indexOf("builder.preview=")||-1!==location.search.indexOf("builder.frameEditing="))),e.isReact=!1,e.overrideUserAttributes={},e}(),builder=new Builder(null,void 0,void 0,!0);Builder.singletonInstance=builder,exports.Builder=Builder,exports.BuilderComponent=BuilderComponent,exports.isBrowser=isBrowser,exports.BehaviorSubject=BehaviorSubject,exports.Subscription=Subscription,exports.builder=builder,Object.defineProperty(exports,"__esModule",{value:!0})});
|
|
1
|
+
(function (global, factory) {
|
|
2
|
+
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
|
|
3
|
+
typeof define === 'function' && define.amd ? define('@builder.io/sdk', ['exports'], factory) :
|
|
4
|
+
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.BuilderIO = {}));
|
|
5
|
+
})(this, (function (exports) { 'use strict';
|
|
6
|
+
|
|
7
|
+
/******************************************************************************
|
|
8
|
+
Copyright (c) Microsoft Corporation.
|
|
9
|
+
|
|
10
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
11
|
+
purpose with or without fee is hereby granted.
|
|
12
|
+
|
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
14
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
15
|
+
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
16
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
17
|
+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
18
|
+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
19
|
+
PERFORMANCE OF THIS SOFTWARE.
|
|
20
|
+
***************************************************************************** */
|
|
21
|
+
|
|
22
|
+
var __assign = function() {
|
|
23
|
+
__assign = Object.assign || function __assign(t) {
|
|
24
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
25
|
+
s = arguments[i];
|
|
26
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
|
|
27
|
+
}
|
|
28
|
+
return t;
|
|
29
|
+
};
|
|
30
|
+
return __assign.apply(this, arguments);
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
34
|
+
var e = new Error(message);
|
|
35
|
+
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
(function () {
|
|
39
|
+
if (typeof window === 'undefined' || typeof window.CustomEvent === 'function') return false;
|
|
40
|
+
|
|
41
|
+
function CustomEvent(event, params) {
|
|
42
|
+
params = params || { bubbles: false, cancelable: false, detail: null };
|
|
43
|
+
var evt = document.createEvent('CustomEvent');
|
|
44
|
+
evt.initCustomEvent(event, params.bubbles, params.cancelable, params.detail);
|
|
45
|
+
return evt;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
window.CustomEvent = CustomEvent;
|
|
49
|
+
})();
|
|
50
|
+
|
|
51
|
+
var isSafari = typeof window !== 'undefined' &&
|
|
52
|
+
/^((?!chrome|android).)*safari/i.test(window.navigator.userAgent);
|
|
53
|
+
// TODO: queue all of these in a debounceNextTick
|
|
54
|
+
function nextTick(fn) {
|
|
55
|
+
// React native
|
|
56
|
+
if (typeof setImmediate === 'function' && typeof window === 'undefined') {
|
|
57
|
+
return setImmediate(fn);
|
|
58
|
+
}
|
|
59
|
+
// TODO: should this be setImmediate instead? Forgot if that is micro or macro task
|
|
60
|
+
// TODO: detect specifically if is server
|
|
61
|
+
// if (typeof process !== 'undefined' && process.nextTick) {
|
|
62
|
+
// console.log('process.nextTick?');
|
|
63
|
+
// process.nextTick(fn);
|
|
64
|
+
// return;
|
|
65
|
+
// }
|
|
66
|
+
// FIXME: fix the real safari issue of this randomly not working
|
|
67
|
+
if (isSafari || typeof MutationObserver === 'undefined') {
|
|
68
|
+
setTimeout(fn);
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
var called = 0;
|
|
72
|
+
var observer = new MutationObserver(function () { return fn(); });
|
|
73
|
+
var element = document.createTextNode('');
|
|
74
|
+
observer.observe(element, {
|
|
75
|
+
characterData: true,
|
|
76
|
+
});
|
|
77
|
+
// tslint:disable-next-line
|
|
78
|
+
element.data = String((called = ++called));
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
var PROPERTY_NAME_DENY_LIST = Object.freeze(['__proto__', 'prototype', 'constructor']);
|
|
82
|
+
// TODO: unit tests
|
|
83
|
+
var QueryString = /** @class */ (function () {
|
|
84
|
+
function QueryString() {
|
|
85
|
+
}
|
|
86
|
+
QueryString.parseDeep = function (queryString) {
|
|
87
|
+
var obj = this.parse(queryString);
|
|
88
|
+
return this.deepen(obj);
|
|
89
|
+
};
|
|
90
|
+
QueryString.stringifyDeep = function (obj) {
|
|
91
|
+
var map = this.flatten(obj);
|
|
92
|
+
return this.stringify(map);
|
|
93
|
+
};
|
|
94
|
+
QueryString.parse = function (queryString) {
|
|
95
|
+
var query = {};
|
|
96
|
+
var pairs = (queryString[0] === '?' ? queryString.substr(1) : queryString).split('&');
|
|
97
|
+
for (var i = 0; i < pairs.length; i++) {
|
|
98
|
+
var pair = pairs[i].split('=');
|
|
99
|
+
// TODO: node support?
|
|
100
|
+
try {
|
|
101
|
+
query[decodeURIComponent(pair[0])] = decodeURIComponent(pair[1] || '');
|
|
102
|
+
}
|
|
103
|
+
catch (error) {
|
|
104
|
+
// Ignore malformed URI components
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
return query;
|
|
108
|
+
};
|
|
109
|
+
QueryString.stringify = function (map) {
|
|
110
|
+
var str = '';
|
|
111
|
+
for (var key in map) {
|
|
112
|
+
if (map.hasOwnProperty(key)) {
|
|
113
|
+
var value = map[key];
|
|
114
|
+
if (str) {
|
|
115
|
+
str += '&';
|
|
116
|
+
}
|
|
117
|
+
str += encodeURIComponent(key) + '=' + encodeURIComponent(value);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
return str;
|
|
121
|
+
};
|
|
122
|
+
QueryString.deepen = function (map) {
|
|
123
|
+
// FIXME; Should be type Tree = Record<string, string | Tree>
|
|
124
|
+
// requires a typescript upgrade.
|
|
125
|
+
var output = {};
|
|
126
|
+
for (var k in map) {
|
|
127
|
+
var t = output;
|
|
128
|
+
var parts = k.split('.');
|
|
129
|
+
var key = parts.pop();
|
|
130
|
+
for (var _i = 0, parts_1 = parts; _i < parts_1.length; _i++) {
|
|
131
|
+
var part = parts_1[_i];
|
|
132
|
+
assertAllowedPropertyName(part);
|
|
133
|
+
t = t[part] = t[part] || {};
|
|
134
|
+
}
|
|
135
|
+
t[key] = map[k];
|
|
136
|
+
}
|
|
137
|
+
return output;
|
|
138
|
+
};
|
|
139
|
+
QueryString.flatten = function (obj, _current, _res) {
|
|
140
|
+
if (_res === void 0) { _res = {}; }
|
|
141
|
+
for (var key in obj) {
|
|
142
|
+
var value = obj[key];
|
|
143
|
+
var newKey = _current ? _current + '.' + key : key;
|
|
144
|
+
if (value && typeof value === 'object') {
|
|
145
|
+
this.flatten(value, newKey, _res);
|
|
146
|
+
}
|
|
147
|
+
else {
|
|
148
|
+
_res[newKey] = value;
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
return _res;
|
|
152
|
+
};
|
|
153
|
+
return QueryString;
|
|
154
|
+
}());
|
|
155
|
+
function assertAllowedPropertyName(name) {
|
|
156
|
+
if (PROPERTY_NAME_DENY_LIST.indexOf(name) >= 0)
|
|
157
|
+
throw new Error("Property name \"".concat(name, "\" is not allowed"));
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
var version = "2.0.6";
|
|
161
|
+
|
|
162
|
+
var Subscription = /** @class */ (function () {
|
|
163
|
+
function Subscription(listeners, listener) {
|
|
164
|
+
this.listeners = listeners;
|
|
165
|
+
this.listener = listener;
|
|
166
|
+
this.unsubscribed = false;
|
|
167
|
+
this.otherSubscriptions = [];
|
|
168
|
+
}
|
|
169
|
+
Object.defineProperty(Subscription.prototype, "closed", {
|
|
170
|
+
get: function () {
|
|
171
|
+
return this.unsubscribed;
|
|
172
|
+
},
|
|
173
|
+
enumerable: false,
|
|
174
|
+
configurable: true
|
|
175
|
+
});
|
|
176
|
+
Subscription.prototype.add = function (subscription) {
|
|
177
|
+
this.otherSubscriptions.push(subscription);
|
|
178
|
+
};
|
|
179
|
+
Subscription.prototype.unsubscribe = function () {
|
|
180
|
+
if (this.unsubscribed) {
|
|
181
|
+
return;
|
|
182
|
+
}
|
|
183
|
+
if (this.listener && this.listeners) {
|
|
184
|
+
var index = this.listeners.indexOf(this.listener);
|
|
185
|
+
if (index > -1) {
|
|
186
|
+
this.listeners.splice(index, 1);
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
this.otherSubscriptions.forEach(function (sub) { return sub.unsubscribe(); });
|
|
190
|
+
this.unsubscribed = true;
|
|
191
|
+
};
|
|
192
|
+
return Subscription;
|
|
193
|
+
}());
|
|
194
|
+
// TODO: follow minimal basic spec: https://github.com/tc39/proposal-observable
|
|
195
|
+
var BehaviorSubject = /** @class */ (function () {
|
|
196
|
+
function BehaviorSubject(value) {
|
|
197
|
+
var _this = this;
|
|
198
|
+
this.value = value;
|
|
199
|
+
this.listeners = [];
|
|
200
|
+
this.errorListeners = [];
|
|
201
|
+
this.then = function () {
|
|
202
|
+
var _a;
|
|
203
|
+
var args = [];
|
|
204
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
205
|
+
args[_i] = arguments[_i];
|
|
206
|
+
}
|
|
207
|
+
return (_a = _this.toPromise()).then.apply(_a, args);
|
|
208
|
+
};
|
|
209
|
+
}
|
|
210
|
+
BehaviorSubject.prototype.next = function (value) {
|
|
211
|
+
this.value = value;
|
|
212
|
+
for (var _i = 0, _a = this.listeners; _i < _a.length; _i++) {
|
|
213
|
+
var listener = _a[_i];
|
|
214
|
+
listener(value);
|
|
215
|
+
}
|
|
216
|
+
};
|
|
217
|
+
// TODO: implement this as PIPE instead
|
|
218
|
+
BehaviorSubject.prototype.map = function (fn) {
|
|
219
|
+
var newSubject = new BehaviorSubject(fn(this.value));
|
|
220
|
+
// TODO: on destroy delete these
|
|
221
|
+
this.subscribe(function (val) {
|
|
222
|
+
newSubject.next(fn(val));
|
|
223
|
+
});
|
|
224
|
+
this.catch(function (err) {
|
|
225
|
+
newSubject.error(err);
|
|
226
|
+
});
|
|
227
|
+
return newSubject;
|
|
228
|
+
};
|
|
229
|
+
BehaviorSubject.prototype.catch = function (errorListener) {
|
|
230
|
+
this.errorListeners.push(errorListener);
|
|
231
|
+
return new Subscription(this.errorListeners, errorListener);
|
|
232
|
+
};
|
|
233
|
+
BehaviorSubject.prototype.error = function (error) {
|
|
234
|
+
for (var _i = 0, _a = this.errorListeners; _i < _a.length; _i++) {
|
|
235
|
+
var listener = _a[_i];
|
|
236
|
+
listener(error);
|
|
237
|
+
}
|
|
238
|
+
};
|
|
239
|
+
BehaviorSubject.prototype.subscribe = function (listener, errorListener) {
|
|
240
|
+
this.listeners.push(listener);
|
|
241
|
+
if (errorListener) {
|
|
242
|
+
this.errorListeners.push(errorListener);
|
|
243
|
+
}
|
|
244
|
+
return new Subscription(this.listeners, listener);
|
|
245
|
+
};
|
|
246
|
+
BehaviorSubject.prototype.toPromise = function () {
|
|
247
|
+
var _this = this;
|
|
248
|
+
return new Promise(function (resolve, reject) {
|
|
249
|
+
var subscription = _this.subscribe(function (value) {
|
|
250
|
+
resolve(value);
|
|
251
|
+
subscription.unsubscribe();
|
|
252
|
+
}, function (err) {
|
|
253
|
+
reject(err);
|
|
254
|
+
subscription.unsubscribe();
|
|
255
|
+
});
|
|
256
|
+
});
|
|
257
|
+
};
|
|
258
|
+
BehaviorSubject.prototype.promise = function () {
|
|
259
|
+
return this.toPromise();
|
|
260
|
+
};
|
|
261
|
+
return BehaviorSubject;
|
|
262
|
+
}());
|
|
263
|
+
|
|
264
|
+
var State = {
|
|
265
|
+
Pending: 'Pending',
|
|
266
|
+
Fulfilled: 'Fulfilled',
|
|
267
|
+
Rejected: 'Rejected',
|
|
268
|
+
};
|
|
269
|
+
function isFunction(val) {
|
|
270
|
+
return val && typeof val === 'function';
|
|
271
|
+
}
|
|
272
|
+
function isObject(val) {
|
|
273
|
+
return val && typeof val === 'object';
|
|
274
|
+
}
|
|
275
|
+
var TinyPromise = /** @class */ (function () {
|
|
276
|
+
function TinyPromise(executor) {
|
|
277
|
+
this._state = State.Pending;
|
|
278
|
+
this._handlers = [];
|
|
279
|
+
this._value = null;
|
|
280
|
+
executor(this._resolve.bind(this), this._reject.bind(this));
|
|
281
|
+
}
|
|
282
|
+
TinyPromise.prototype._resolve = function (x) {
|
|
283
|
+
var _this = this;
|
|
284
|
+
if (x instanceof TinyPromise) {
|
|
285
|
+
x.then(this._resolve.bind(this), this._reject.bind(this));
|
|
286
|
+
}
|
|
287
|
+
else if (isObject(x) || isFunction(x)) {
|
|
288
|
+
var called_1 = false;
|
|
289
|
+
try {
|
|
290
|
+
var thenable = x.then;
|
|
291
|
+
if (isFunction(thenable)) {
|
|
292
|
+
thenable.call(x, function (result) {
|
|
293
|
+
if (!called_1)
|
|
294
|
+
_this._resolve(result);
|
|
295
|
+
called_1 = true;
|
|
296
|
+
return undefined;
|
|
297
|
+
}, function (error) {
|
|
298
|
+
if (!called_1)
|
|
299
|
+
_this._reject(error);
|
|
300
|
+
called_1 = true;
|
|
301
|
+
return undefined;
|
|
302
|
+
});
|
|
303
|
+
}
|
|
304
|
+
else {
|
|
305
|
+
this._fulfill(x);
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
catch (ex) {
|
|
309
|
+
if (!called_1) {
|
|
310
|
+
this._reject(ex);
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
else {
|
|
315
|
+
this._fulfill(x);
|
|
316
|
+
}
|
|
317
|
+
};
|
|
318
|
+
TinyPromise.prototype._fulfill = function (result) {
|
|
319
|
+
var _this = this;
|
|
320
|
+
this._state = State.Fulfilled;
|
|
321
|
+
this._value = result;
|
|
322
|
+
this._handlers.forEach(function (handler) { return _this._callHandler(handler); });
|
|
323
|
+
};
|
|
324
|
+
TinyPromise.prototype._reject = function (error) {
|
|
325
|
+
var _this = this;
|
|
326
|
+
this._state = State.Rejected;
|
|
327
|
+
this._value = error;
|
|
328
|
+
this._handlers.forEach(function (handler) { return _this._callHandler(handler); });
|
|
329
|
+
};
|
|
330
|
+
TinyPromise.prototype._isPending = function () {
|
|
331
|
+
return this._state === State.Pending;
|
|
332
|
+
};
|
|
333
|
+
TinyPromise.prototype._isFulfilled = function () {
|
|
334
|
+
return this._state === State.Fulfilled;
|
|
335
|
+
};
|
|
336
|
+
TinyPromise.prototype._isRejected = function () {
|
|
337
|
+
return this._state === State.Rejected;
|
|
338
|
+
};
|
|
339
|
+
TinyPromise.prototype._addHandler = function (onFulfilled, onRejected) {
|
|
340
|
+
this._handlers.push({
|
|
341
|
+
onFulfilled: onFulfilled,
|
|
342
|
+
onRejected: onRejected,
|
|
343
|
+
});
|
|
344
|
+
};
|
|
345
|
+
TinyPromise.prototype._callHandler = function (handler) {
|
|
346
|
+
if (this._isFulfilled() && isFunction(handler.onFulfilled)) {
|
|
347
|
+
handler.onFulfilled(this._value);
|
|
348
|
+
}
|
|
349
|
+
else if (this._isRejected() && isFunction(handler.onRejected)) {
|
|
350
|
+
handler.onRejected(this._value);
|
|
351
|
+
}
|
|
352
|
+
};
|
|
353
|
+
TinyPromise.prototype.then = function (onFulfilled, onRejected) {
|
|
354
|
+
var _this = this;
|
|
355
|
+
switch (this._state) {
|
|
356
|
+
case State.Pending: {
|
|
357
|
+
return new TinyPromise(function (resolve, reject) {
|
|
358
|
+
_this._addHandler(function (value) {
|
|
359
|
+
nextTick(function () {
|
|
360
|
+
try {
|
|
361
|
+
if (isFunction(onFulfilled)) {
|
|
362
|
+
resolve(onFulfilled(value));
|
|
363
|
+
}
|
|
364
|
+
else {
|
|
365
|
+
resolve(value);
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
catch (ex) {
|
|
369
|
+
reject(ex);
|
|
370
|
+
}
|
|
371
|
+
});
|
|
372
|
+
}, function (error) {
|
|
373
|
+
nextTick(function () {
|
|
374
|
+
try {
|
|
375
|
+
if (isFunction(onRejected)) {
|
|
376
|
+
resolve(onRejected(error));
|
|
377
|
+
}
|
|
378
|
+
else {
|
|
379
|
+
reject(error);
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
catch (ex) {
|
|
383
|
+
reject(ex);
|
|
384
|
+
}
|
|
385
|
+
});
|
|
386
|
+
});
|
|
387
|
+
});
|
|
388
|
+
}
|
|
389
|
+
case State.Fulfilled: {
|
|
390
|
+
return new TinyPromise(function (resolve, reject) {
|
|
391
|
+
nextTick(function () {
|
|
392
|
+
try {
|
|
393
|
+
if (isFunction(onFulfilled)) {
|
|
394
|
+
resolve(onFulfilled(_this._value));
|
|
395
|
+
}
|
|
396
|
+
else {
|
|
397
|
+
resolve(_this._value);
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
catch (ex) {
|
|
401
|
+
reject(ex);
|
|
402
|
+
}
|
|
403
|
+
});
|
|
404
|
+
});
|
|
405
|
+
}
|
|
406
|
+
case State.Rejected: {
|
|
407
|
+
return new TinyPromise(function (resolve, reject) {
|
|
408
|
+
nextTick(function () {
|
|
409
|
+
try {
|
|
410
|
+
if (isFunction(onRejected)) {
|
|
411
|
+
resolve(onRejected(_this._value));
|
|
412
|
+
}
|
|
413
|
+
else {
|
|
414
|
+
reject(_this._value);
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
catch (ex) {
|
|
418
|
+
reject(ex);
|
|
419
|
+
}
|
|
420
|
+
});
|
|
421
|
+
});
|
|
422
|
+
}
|
|
423
|
+
}
|
|
424
|
+
};
|
|
425
|
+
return TinyPromise;
|
|
426
|
+
}());
|
|
427
|
+
var Promise$1 = (typeof Promise !== 'undefined' ? Promise : TinyPromise);
|
|
428
|
+
|
|
429
|
+
// Webpack workaround to conditionally require certain external modules
|
|
430
|
+
// only on the server and not bundle them on the client
|
|
431
|
+
var serverOnlyRequire;
|
|
432
|
+
try {
|
|
433
|
+
// tslint:disable-next-line:no-eval
|
|
434
|
+
serverOnlyRequire = eval('require');
|
|
435
|
+
}
|
|
436
|
+
catch (err) {
|
|
437
|
+
// all good
|
|
438
|
+
serverOnlyRequire = (function () { return null; });
|
|
439
|
+
}
|
|
440
|
+
var serverOnlyRequire$1 = serverOnlyRequire;
|
|
441
|
+
|
|
442
|
+
function promiseResolve(value) {
|
|
443
|
+
return new Promise$1(function (resolve) { return resolve(value); });
|
|
444
|
+
}
|
|
445
|
+
// Adapted from https://raw.githubusercontent.com/developit/unfetch/master/src/index.mjs
|
|
446
|
+
function tinyFetch(url, options) {
|
|
447
|
+
if (options === void 0) { options = {}; }
|
|
448
|
+
return new Promise$1(function (resolve, reject) {
|
|
449
|
+
var request = new XMLHttpRequest();
|
|
450
|
+
request.open(options.method || 'get', url, true);
|
|
451
|
+
if (options.headers) {
|
|
452
|
+
for (var i in options.headers) {
|
|
453
|
+
request.setRequestHeader(i, options.headers[i]);
|
|
454
|
+
}
|
|
455
|
+
}
|
|
456
|
+
request.withCredentials = options.credentials === 'include';
|
|
457
|
+
request.onload = function () {
|
|
458
|
+
resolve(response());
|
|
459
|
+
};
|
|
460
|
+
request.onerror = reject;
|
|
461
|
+
request.send(options.body);
|
|
462
|
+
function response() {
|
|
463
|
+
var keys = [];
|
|
464
|
+
var all = [];
|
|
465
|
+
var headers = {};
|
|
466
|
+
var header = undefined;
|
|
467
|
+
request
|
|
468
|
+
.getAllResponseHeaders()
|
|
469
|
+
.replace(/^(.*?):[^\S\n]*([\s\S]*?)$/gm, function (_match, _key, value) {
|
|
470
|
+
var key = _key;
|
|
471
|
+
keys.push((key = key.toLowerCase()));
|
|
472
|
+
all.push([key, value]);
|
|
473
|
+
header = headers[key];
|
|
474
|
+
headers[key] = header ? "".concat(header, ",").concat(value) : value;
|
|
475
|
+
return '';
|
|
476
|
+
});
|
|
477
|
+
return {
|
|
478
|
+
ok: ((request.status / 100) | 0) === 2,
|
|
479
|
+
status: request.status,
|
|
480
|
+
statusText: request.statusText,
|
|
481
|
+
url: request.responseURL,
|
|
482
|
+
clone: response,
|
|
483
|
+
text: function () { return promiseResolve(request.responseText); },
|
|
484
|
+
json: function () { return promiseResolve(request.responseText).then(JSON.parse); },
|
|
485
|
+
blob: function () { return promiseResolve(new Blob([request.response])); },
|
|
486
|
+
headers: {
|
|
487
|
+
keys: function () { return keys; },
|
|
488
|
+
entries: function () { return all; },
|
|
489
|
+
get: function (n) { return headers[n.toLowerCase()]; },
|
|
490
|
+
has: function (n) { return n.toLowerCase() in headers; },
|
|
491
|
+
},
|
|
492
|
+
};
|
|
493
|
+
}
|
|
494
|
+
});
|
|
495
|
+
}
|
|
496
|
+
function getFetch() {
|
|
497
|
+
// If fetch is defined, in the browser, via polyfill, or in a Cloudflare worker, use it.
|
|
498
|
+
var _fetch = undefined;
|
|
499
|
+
if (globalThis.fetch) {
|
|
500
|
+
_fetch !== null && _fetch !== void 0 ? _fetch : (_fetch = globalThis.fetch);
|
|
501
|
+
}
|
|
502
|
+
else if (typeof window === 'undefined') {
|
|
503
|
+
// If fetch is not defined, in a Node.js environment, use node-fetch.
|
|
504
|
+
try {
|
|
505
|
+
// node-fetch@^3 is ESM only, and will throw error on require.
|
|
506
|
+
_fetch !== null && _fetch !== void 0 ? _fetch : (_fetch = serverOnlyRequire$1('node-fetch'));
|
|
507
|
+
}
|
|
508
|
+
catch (e) {
|
|
509
|
+
// If node-fetch is not installed, use tiny-fetch.
|
|
510
|
+
console.warn('node-fetch is not installed. consider polyfilling fetch or installing node-fetch.');
|
|
511
|
+
console.warn(e);
|
|
512
|
+
}
|
|
513
|
+
}
|
|
514
|
+
// Otherwise, use tiny-fetch.
|
|
515
|
+
return _fetch !== null && _fetch !== void 0 ? _fetch : tinyFetch;
|
|
516
|
+
}
|
|
517
|
+
|
|
518
|
+
function assign(target) {
|
|
519
|
+
var to = Object(target);
|
|
520
|
+
for (var index = 1; index < arguments.length; index++) {
|
|
521
|
+
var nextSource = arguments[index];
|
|
522
|
+
if (nextSource != null) {
|
|
523
|
+
// Skip over if undefined or null
|
|
524
|
+
for (var nextKey in nextSource) {
|
|
525
|
+
// Avoid bugs when hasOwnProperty is shadowed
|
|
526
|
+
if (Object.prototype.hasOwnProperty.call(nextSource, nextKey)) {
|
|
527
|
+
to[nextKey] = nextSource[nextKey];
|
|
528
|
+
}
|
|
529
|
+
}
|
|
530
|
+
}
|
|
531
|
+
}
|
|
532
|
+
return to;
|
|
533
|
+
}
|
|
534
|
+
|
|
535
|
+
function throttle(func, wait, options) {
|
|
536
|
+
if (options === void 0) { options = {}; }
|
|
537
|
+
var context;
|
|
538
|
+
var args;
|
|
539
|
+
var result;
|
|
540
|
+
var timeout = null;
|
|
541
|
+
var previous = 0;
|
|
542
|
+
var later = function () {
|
|
543
|
+
previous = options.leading === false ? 0 : Date.now();
|
|
544
|
+
timeout = null;
|
|
545
|
+
result = func.apply(context, args);
|
|
546
|
+
if (!timeout)
|
|
547
|
+
context = args = null;
|
|
548
|
+
};
|
|
549
|
+
return function () {
|
|
550
|
+
var now = Date.now();
|
|
551
|
+
if (!previous && options.leading === false)
|
|
552
|
+
previous = now;
|
|
553
|
+
var remaining = wait - (now - previous);
|
|
554
|
+
context = this;
|
|
555
|
+
args = arguments;
|
|
556
|
+
if (remaining <= 0 || remaining > wait) {
|
|
557
|
+
if (timeout) {
|
|
558
|
+
clearTimeout(timeout);
|
|
559
|
+
timeout = null;
|
|
560
|
+
}
|
|
561
|
+
previous = now;
|
|
562
|
+
result = func.apply(context, args);
|
|
563
|
+
if (!timeout)
|
|
564
|
+
context = args = null;
|
|
565
|
+
}
|
|
566
|
+
else if (!timeout && options.trailing !== false) {
|
|
567
|
+
timeout = setTimeout(later, remaining);
|
|
568
|
+
}
|
|
569
|
+
return result;
|
|
570
|
+
};
|
|
571
|
+
}
|
|
572
|
+
|
|
573
|
+
var camelCaseToKebabCase = function (str) {
|
|
574
|
+
return str ? str.replace(/([A-Z])/g, function (g) { return "-".concat(g[0].toLowerCase()); }) : '';
|
|
575
|
+
};
|
|
576
|
+
var Animator = /** @class */ (function () {
|
|
577
|
+
function Animator() {
|
|
578
|
+
}
|
|
579
|
+
Animator.prototype.bindAnimations = function (animations) {
|
|
580
|
+
for (var _i = 0, animations_1 = animations; _i < animations_1.length; _i++) {
|
|
581
|
+
var animation = animations_1[_i];
|
|
582
|
+
switch (animation.trigger) {
|
|
583
|
+
case 'pageLoad':
|
|
584
|
+
this.triggerAnimation(animation);
|
|
585
|
+
break;
|
|
586
|
+
case 'hover':
|
|
587
|
+
this.bindHoverAnimation(animation);
|
|
588
|
+
break;
|
|
589
|
+
case 'scrollInView':
|
|
590
|
+
this.bindScrollInViewAnimation(animation);
|
|
591
|
+
break;
|
|
592
|
+
}
|
|
593
|
+
}
|
|
594
|
+
};
|
|
595
|
+
Animator.prototype.warnElementNotPresent = function (id) {
|
|
596
|
+
console.warn("Cannot animate element: element with ID ".concat(id, " not found!"));
|
|
597
|
+
};
|
|
598
|
+
Animator.prototype.augmentAnimation = function (animation, element) {
|
|
599
|
+
var stylesUsed = this.getAllStylesUsed(animation);
|
|
600
|
+
var computedStyle = getComputedStyle(element);
|
|
601
|
+
// const computedStyle = getComputedStyle(element);
|
|
602
|
+
// // FIXME: this will break if original load is in one reponsive size then resize to another hmmm
|
|
603
|
+
// Need to use transform instead of left since left can change on screen sizes
|
|
604
|
+
var firstStyles = animation.steps[0].styles;
|
|
605
|
+
var lastStyles = animation.steps[animation.steps.length - 1].styles;
|
|
606
|
+
var bothStyles = [firstStyles, lastStyles];
|
|
607
|
+
// FIXME: this won't work as expected for augmented animations - may need the editor itself to manage this
|
|
608
|
+
for (var _i = 0, bothStyles_1 = bothStyles; _i < bothStyles_1.length; _i++) {
|
|
609
|
+
var styles = bothStyles_1[_i];
|
|
610
|
+
for (var _a = 0, stylesUsed_1 = stylesUsed; _a < stylesUsed_1.length; _a++) {
|
|
611
|
+
var style = stylesUsed_1[_a];
|
|
612
|
+
if (!(style in styles)) {
|
|
613
|
+
styles[style] = computedStyle[style];
|
|
614
|
+
}
|
|
615
|
+
}
|
|
616
|
+
}
|
|
617
|
+
};
|
|
618
|
+
Animator.prototype.getAllStylesUsed = function (animation) {
|
|
619
|
+
var properties = [];
|
|
620
|
+
for (var _i = 0, _a = animation.steps; _i < _a.length; _i++) {
|
|
621
|
+
var step = _a[_i];
|
|
622
|
+
for (var key in step.styles) {
|
|
623
|
+
if (properties.indexOf(key) === -1) {
|
|
624
|
+
properties.push(key);
|
|
625
|
+
}
|
|
626
|
+
}
|
|
627
|
+
}
|
|
628
|
+
return properties;
|
|
629
|
+
};
|
|
630
|
+
Animator.prototype.triggerAnimation = function (animation) {
|
|
631
|
+
var _this = this;
|
|
632
|
+
// TODO: do for ALL elements
|
|
633
|
+
var elements = Array.prototype.slice.call(document.getElementsByClassName(animation.elementId || animation.id || ''));
|
|
634
|
+
if (!elements.length) {
|
|
635
|
+
this.warnElementNotPresent(animation.elementId || animation.id || '');
|
|
636
|
+
return;
|
|
637
|
+
}
|
|
638
|
+
Array.from(elements).forEach(function (element) {
|
|
639
|
+
_this.augmentAnimation(animation, element);
|
|
640
|
+
// TODO: do this properly, may have other animations of different properties
|
|
641
|
+
// TODO: only override the properties
|
|
642
|
+
// TODO: if there is an entrance and hover animation, the transition duration will get effed
|
|
643
|
+
// element.setAttribute('style', '');
|
|
644
|
+
// const styledUsed = this.getAllStylesUsed(animation);
|
|
645
|
+
element.style.transition = 'none';
|
|
646
|
+
element.style.transitionDelay = '0';
|
|
647
|
+
assign(element.style, animation.steps[0].styles);
|
|
648
|
+
// TODO: queue/batch these timeouts
|
|
649
|
+
// TODO: only include properties explicitly set in the animation
|
|
650
|
+
// using Object.keys(styles)
|
|
651
|
+
setTimeout(function () {
|
|
652
|
+
element.style.transition = "all ".concat(animation.duration, "s ").concat(camelCaseToKebabCase(animation.easing));
|
|
653
|
+
if (animation.delay) {
|
|
654
|
+
element.style.transitionDelay = animation.delay + 's';
|
|
655
|
+
}
|
|
656
|
+
assign(element.style, animation.steps[1].styles);
|
|
657
|
+
// TODO: maybe remove/reset transitoin property after animation duration
|
|
658
|
+
// TODO: queue timers
|
|
659
|
+
setTimeout(function () {
|
|
660
|
+
// TODO: what if has other transition (reset back to what it was)
|
|
661
|
+
element.style.transition = '';
|
|
662
|
+
element.style.transitionDelay = '';
|
|
663
|
+
}, (animation.delay || 0) * 1000 + animation.duration * 1000 + 100);
|
|
664
|
+
});
|
|
665
|
+
});
|
|
666
|
+
};
|
|
667
|
+
Animator.prototype.bindHoverAnimation = function (animation) {
|
|
668
|
+
var _this = this;
|
|
669
|
+
// TODO: is it multiple binding when editing...?
|
|
670
|
+
// TODO: unbind on element remove
|
|
671
|
+
// TODO: apply to ALL elements
|
|
672
|
+
var elements = Array.prototype.slice.call(document.getElementsByClassName(animation.elementId || animation.id || ''));
|
|
673
|
+
if (!elements.length) {
|
|
674
|
+
this.warnElementNotPresent(animation.elementId || animation.id || '');
|
|
675
|
+
return;
|
|
676
|
+
}
|
|
677
|
+
Array.from(elements).forEach(function (element) {
|
|
678
|
+
_this.augmentAnimation(animation, element);
|
|
679
|
+
var defaultState = animation.steps[0].styles;
|
|
680
|
+
var hoverState = animation.steps[1].styles;
|
|
681
|
+
function attachDefaultState() {
|
|
682
|
+
assign(element.style, defaultState);
|
|
683
|
+
}
|
|
684
|
+
function attachHoverState() {
|
|
685
|
+
assign(element.style, hoverState);
|
|
686
|
+
}
|
|
687
|
+
attachDefaultState();
|
|
688
|
+
element.addEventListener('mouseenter', attachHoverState);
|
|
689
|
+
element.addEventListener('mouseleave', attachDefaultState);
|
|
690
|
+
// TODO: queue/batch these timeouts
|
|
691
|
+
setTimeout(function () {
|
|
692
|
+
element.style.transition = "all ".concat(animation.duration, "s ").concat(camelCaseToKebabCase(animation.easing));
|
|
693
|
+
if (animation.delay) {
|
|
694
|
+
element.style.transitionDelay = animation.delay + 's';
|
|
695
|
+
}
|
|
696
|
+
});
|
|
697
|
+
});
|
|
698
|
+
};
|
|
699
|
+
// TODO: unbind on element remove
|
|
700
|
+
Animator.prototype.bindScrollInViewAnimation = function (animation) {
|
|
701
|
+
var _this = this;
|
|
702
|
+
// TODO: apply to ALL matching elements
|
|
703
|
+
var elements = Array.prototype.slice.call(document.getElementsByClassName(animation.elementId || animation.id || ''));
|
|
704
|
+
if (!elements.length) {
|
|
705
|
+
this.warnElementNotPresent(animation.elementId || animation.id || '');
|
|
706
|
+
return;
|
|
707
|
+
}
|
|
708
|
+
// TODO: if server side rendered and scrolled into view don't animate...
|
|
709
|
+
Array.from(elements).forEach(function (element) {
|
|
710
|
+
_this.augmentAnimation(animation, element);
|
|
711
|
+
var triggered = false;
|
|
712
|
+
var pendingAnimation = false;
|
|
713
|
+
function immediateOnScroll() {
|
|
714
|
+
if (!triggered && isScrolledIntoView(element)) {
|
|
715
|
+
triggered = true;
|
|
716
|
+
pendingAnimation = true;
|
|
717
|
+
setTimeout(function () {
|
|
718
|
+
assign(element.style, animation.steps[1].styles);
|
|
719
|
+
if (!animation.repeat) {
|
|
720
|
+
document.removeEventListener('scroll', onScroll);
|
|
721
|
+
}
|
|
722
|
+
setTimeout(function () {
|
|
723
|
+
pendingAnimation = false;
|
|
724
|
+
if (!animation.repeat) {
|
|
725
|
+
element.style.transition = '';
|
|
726
|
+
element.style.transitionDelay = '';
|
|
727
|
+
}
|
|
728
|
+
}, (animation.duration + (animation.delay || 0)) * 1000 + 100);
|
|
729
|
+
});
|
|
730
|
+
}
|
|
731
|
+
else if (animation.repeat &&
|
|
732
|
+
triggered &&
|
|
733
|
+
!pendingAnimation &&
|
|
734
|
+
!isScrolledIntoView(element)) {
|
|
735
|
+
// we want to repeat the animation every time the the element is out of view and back again
|
|
736
|
+
triggered = false;
|
|
737
|
+
assign(element.style, animation.steps[0].styles);
|
|
738
|
+
}
|
|
739
|
+
}
|
|
740
|
+
// TODO: roll all of these in one for more efficiency of checking all the rects
|
|
741
|
+
var onScroll = throttle(immediateOnScroll, 200, { leading: false });
|
|
742
|
+
// TODO: fully in view or partially
|
|
743
|
+
function isScrolledIntoView(elem) {
|
|
744
|
+
var rect = elem.getBoundingClientRect();
|
|
745
|
+
var windowHeight = window.innerHeight;
|
|
746
|
+
var thresholdPercent = (animation.thresholdPercent || 0) / 100;
|
|
747
|
+
var threshold = thresholdPercent * windowHeight;
|
|
748
|
+
// TODO: partial in view? or what if element is larger than screen itself
|
|
749
|
+
return (rect.bottom > threshold && rect.top < windowHeight - threshold // Element is peeking top or bottom
|
|
750
|
+
// (rect.top > 0 && rect.bottom < window.innerHeight) || // element fits within the screen and is fully on screen (not hanging off at all)
|
|
751
|
+
// (rect.top < 0 && rect.bottom > window.innerHeight) // element is larger than the screen and hangs over the top and bottom
|
|
752
|
+
);
|
|
753
|
+
}
|
|
754
|
+
var defaultState = animation.steps[0].styles;
|
|
755
|
+
function attachDefaultState() {
|
|
756
|
+
assign(element.style, defaultState);
|
|
757
|
+
}
|
|
758
|
+
attachDefaultState();
|
|
759
|
+
// TODO: queue/batch these timeouts!
|
|
760
|
+
setTimeout(function () {
|
|
761
|
+
element.style.transition = "all ".concat(animation.duration, "s ").concat(camelCaseToKebabCase(animation.easing));
|
|
762
|
+
if (animation.delay) {
|
|
763
|
+
element.style.transitionDelay = animation.delay + 's';
|
|
764
|
+
}
|
|
765
|
+
});
|
|
766
|
+
// TODO: one listener for everything
|
|
767
|
+
document.addEventListener('scroll', onScroll, { capture: true, passive: true });
|
|
768
|
+
// Do an initial check
|
|
769
|
+
immediateOnScroll();
|
|
770
|
+
});
|
|
771
|
+
};
|
|
772
|
+
return Animator;
|
|
773
|
+
}());
|
|
774
|
+
|
|
775
|
+
/**
|
|
776
|
+
* Only gets one level up from hostname
|
|
777
|
+
* wwww.example.com -> example.com
|
|
778
|
+
* www.example.co.uk -> example.co.uk
|
|
779
|
+
*/
|
|
780
|
+
function getTopLevelDomain(host) {
|
|
781
|
+
var parts = host.split('.');
|
|
782
|
+
if (parts.length > 2) {
|
|
783
|
+
return parts.slice(1).join('.');
|
|
784
|
+
}
|
|
785
|
+
return host;
|
|
786
|
+
}
|
|
787
|
+
|
|
788
|
+
/**
|
|
789
|
+
* RegExp to match field-content in RFC 7230 sec 3.2
|
|
790
|
+
*
|
|
791
|
+
* field-content = field-vchar [ 1*( SP / HTAB ) field-vchar ]
|
|
792
|
+
* field-vchar = VCHAR / obs-text
|
|
793
|
+
* obs-text = %x80-FF
|
|
794
|
+
*/
|
|
795
|
+
var fieldContentRegExp = /^[\u0009\u0020-\u007e\u0080-\u00ff]+$/;
|
|
796
|
+
var Cookies = /** @class */ (function () {
|
|
797
|
+
function Cookies(request, response) {
|
|
798
|
+
this.request = request;
|
|
799
|
+
this.response = response;
|
|
800
|
+
}
|
|
801
|
+
Cookies.prototype.get = function (name) {
|
|
802
|
+
var header = this.request.headers['cookie'];
|
|
803
|
+
if (!header) {
|
|
804
|
+
return;
|
|
805
|
+
}
|
|
806
|
+
var match = header.match(getPattern(name));
|
|
807
|
+
if (!match) {
|
|
808
|
+
return;
|
|
809
|
+
}
|
|
810
|
+
var value = match[1];
|
|
811
|
+
return value;
|
|
812
|
+
};
|
|
813
|
+
Cookies.prototype.set = function (name, value, opts) {
|
|
814
|
+
var res = this.response;
|
|
815
|
+
var req = this.request;
|
|
816
|
+
var headers = res.getHeader('Set-Cookie') || [];
|
|
817
|
+
// TODO: just make this always true
|
|
818
|
+
var secure = this.secure !== undefined
|
|
819
|
+
? !!this.secure
|
|
820
|
+
: req.protocol === 'https' || req.connection.encrypted;
|
|
821
|
+
var cookie = new Cookie(name, value, opts);
|
|
822
|
+
if (typeof headers === 'string') {
|
|
823
|
+
headers = [headers];
|
|
824
|
+
}
|
|
825
|
+
if (!secure && opts && opts.secure) {
|
|
826
|
+
throw new Error('Cannot send secure cookie over unencrypted connection');
|
|
827
|
+
}
|
|
828
|
+
cookie.secure = secure;
|
|
829
|
+
if (opts && 'secure' in opts) {
|
|
830
|
+
cookie.secure = !!opts.secure;
|
|
831
|
+
}
|
|
832
|
+
cookie.domain = req.headers.host && getTopLevelDomain(req.headers.host);
|
|
833
|
+
pushCookie(headers, cookie);
|
|
834
|
+
var setHeader = res.setHeader;
|
|
835
|
+
setHeader.call(res, 'Set-Cookie', headers);
|
|
836
|
+
return this;
|
|
837
|
+
};
|
|
838
|
+
return Cookies;
|
|
839
|
+
}());
|
|
840
|
+
var Cookie = /** @class */ (function () {
|
|
841
|
+
function Cookie(name, value, attrs) {
|
|
842
|
+
this.path = '/';
|
|
843
|
+
this.domain = undefined;
|
|
844
|
+
this.httpOnly = true;
|
|
845
|
+
this.sameSite = false;
|
|
846
|
+
this.secure = false;
|
|
847
|
+
this.overwrite = false;
|
|
848
|
+
this.name = '';
|
|
849
|
+
this.value = '';
|
|
850
|
+
if (!fieldContentRegExp.test(name)) {
|
|
851
|
+
throw new TypeError('argument name is invalid');
|
|
852
|
+
}
|
|
853
|
+
if (value && !fieldContentRegExp.test(value)) {
|
|
854
|
+
throw new TypeError('argument value is invalid');
|
|
855
|
+
}
|
|
856
|
+
if (!value) {
|
|
857
|
+
this.expires = new Date(0);
|
|
858
|
+
}
|
|
859
|
+
this.name = name;
|
|
860
|
+
this.value = value || '';
|
|
861
|
+
if (attrs.expires) {
|
|
862
|
+
this.expires = attrs.expires;
|
|
863
|
+
}
|
|
864
|
+
if (attrs.secure) {
|
|
865
|
+
this.secure = attrs.secure;
|
|
866
|
+
}
|
|
867
|
+
}
|
|
868
|
+
Cookie.prototype.toString = function () {
|
|
869
|
+
return "".concat(this.name, "=").concat(this.value);
|
|
870
|
+
};
|
|
871
|
+
Cookie.prototype.toHeader = function () {
|
|
872
|
+
var header = this.toString();
|
|
873
|
+
if (this.maxAge) {
|
|
874
|
+
this.expires = new Date(Date.now() + this.maxAge);
|
|
875
|
+
}
|
|
876
|
+
if (this.path) {
|
|
877
|
+
header += "; path=".concat(this.path);
|
|
878
|
+
}
|
|
879
|
+
if (this.expires) {
|
|
880
|
+
header += "; expires=".concat(this.expires.toUTCString());
|
|
881
|
+
}
|
|
882
|
+
if (this.domain) {
|
|
883
|
+
header += "; domain=".concat(this.domain);
|
|
884
|
+
}
|
|
885
|
+
// TODO: samesite=none by default (?)
|
|
886
|
+
header += "; SameSite=".concat(this.sameSite === true ? 'strict' : 'None');
|
|
887
|
+
// TODO: On by default
|
|
888
|
+
if (this.secure) {
|
|
889
|
+
header += '; secure';
|
|
890
|
+
}
|
|
891
|
+
if (this.httpOnly) {
|
|
892
|
+
header += '; httponly';
|
|
893
|
+
}
|
|
894
|
+
return header;
|
|
895
|
+
};
|
|
896
|
+
return Cookie;
|
|
897
|
+
}());
|
|
898
|
+
function getPattern(name) {
|
|
899
|
+
return new RegExp("(?:^|;) *".concat(name.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, '\\$&'), "=([^;]*)"));
|
|
900
|
+
}
|
|
901
|
+
function pushCookie(headers, cookie) {
|
|
902
|
+
if (cookie.overwrite) {
|
|
903
|
+
for (var i = headers.length - 1; i >= 0; i--) {
|
|
904
|
+
if (headers[i].indexOf("".concat(cookie.name, "=")) === 0) {
|
|
905
|
+
headers.splice(i, 1);
|
|
906
|
+
}
|
|
907
|
+
}
|
|
908
|
+
}
|
|
909
|
+
headers.push(cookie.toHeader());
|
|
910
|
+
}
|
|
911
|
+
|
|
912
|
+
function omit(obj) {
|
|
913
|
+
var values = [];
|
|
914
|
+
for (var _i = 1; _i < arguments.length; _i++) {
|
|
915
|
+
values[_i - 1] = arguments[_i];
|
|
916
|
+
}
|
|
917
|
+
var newObject = Object.assign({}, obj);
|
|
918
|
+
for (var _a = 0, values_1 = values; _a < values_1.length; _a++) {
|
|
919
|
+
var key = values_1[_a];
|
|
920
|
+
delete newObject[key];
|
|
921
|
+
}
|
|
922
|
+
return newObject;
|
|
923
|
+
}
|
|
924
|
+
|
|
925
|
+
/**
|
|
926
|
+
* @credit https://stackoverflow.com/a/2117523
|
|
927
|
+
*/
|
|
928
|
+
function uuidv4() {
|
|
929
|
+
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
|
|
930
|
+
var r = (Math.random() * 16) | 0, v = c == 'x' ? r : (r & 0x3) | 0x8;
|
|
931
|
+
return v.toString(16);
|
|
932
|
+
});
|
|
933
|
+
}
|
|
934
|
+
/**
|
|
935
|
+
* Slightly cleaner and smaller UUIDs
|
|
936
|
+
*/
|
|
937
|
+
function uuid() {
|
|
938
|
+
return uuidv4().replace(/-/g, '');
|
|
939
|
+
}
|
|
940
|
+
|
|
941
|
+
function emptyUrl() {
|
|
942
|
+
return {
|
|
943
|
+
query: null,
|
|
944
|
+
port: null,
|
|
945
|
+
auth: null,
|
|
946
|
+
hash: null,
|
|
947
|
+
host: null,
|
|
948
|
+
hostname: null,
|
|
949
|
+
href: null,
|
|
950
|
+
path: null,
|
|
951
|
+
pathname: null,
|
|
952
|
+
protocol: null,
|
|
953
|
+
search: null,
|
|
954
|
+
slashes: null,
|
|
955
|
+
};
|
|
956
|
+
}
|
|
957
|
+
// Replacement for `url.parse` using `URL` global object that works with relative paths.
|
|
958
|
+
// Assumptions: this function operates in a NodeJS environment.
|
|
959
|
+
function parse$1(url) {
|
|
960
|
+
var out = emptyUrl();
|
|
961
|
+
var u;
|
|
962
|
+
var pathOnly = url === '' || url[0] === '/';
|
|
963
|
+
if (pathOnly) {
|
|
964
|
+
u = new URL(url, 'http://0.0.0.0/');
|
|
965
|
+
out.href = u.href;
|
|
966
|
+
out.href = out.href.slice(14); // remove 'http://0.0.0.0/'
|
|
967
|
+
}
|
|
968
|
+
else {
|
|
969
|
+
u = new URL(url);
|
|
970
|
+
out.href = u.href;
|
|
971
|
+
out.port = u.port === '' ? null : u.port;
|
|
972
|
+
out.hash = u.hash === '' ? null : u.hash;
|
|
973
|
+
out.host = u.host;
|
|
974
|
+
out.hostname = u.hostname;
|
|
975
|
+
out.href = u.href;
|
|
976
|
+
out.pathname = u.pathname;
|
|
977
|
+
out.protocol = u.protocol;
|
|
978
|
+
out.slashes = url[u.protocol.length] === '/'; // check if the mimetype is proceeded by a slash
|
|
979
|
+
}
|
|
980
|
+
out.search = u.search;
|
|
981
|
+
out.query = u.search.slice(1); // remove '?'
|
|
982
|
+
out.path = "".concat(u.pathname).concat(u.search);
|
|
983
|
+
out.pathname = u.pathname;
|
|
984
|
+
return out;
|
|
985
|
+
}
|
|
986
|
+
|
|
987
|
+
function pad (hash, len) {
|
|
988
|
+
while (hash.length < len) {
|
|
989
|
+
hash = '0' + hash;
|
|
990
|
+
}
|
|
991
|
+
return hash;
|
|
992
|
+
}
|
|
993
|
+
|
|
994
|
+
function fold (hash, text) {
|
|
995
|
+
var i;
|
|
996
|
+
var chr;
|
|
997
|
+
var len;
|
|
998
|
+
if (text.length === 0) {
|
|
999
|
+
return hash;
|
|
1000
|
+
}
|
|
1001
|
+
for (i = 0, len = text.length; i < len; i++) {
|
|
1002
|
+
chr = text.charCodeAt(i);
|
|
1003
|
+
hash = ((hash << 5) - hash) + chr;
|
|
1004
|
+
hash |= 0;
|
|
1005
|
+
}
|
|
1006
|
+
return hash < 0 ? hash * -2 : hash;
|
|
1007
|
+
}
|
|
1008
|
+
|
|
1009
|
+
function foldObject (hash, o, seen) {
|
|
1010
|
+
return Object.keys(o).sort().reduce(foldKey, hash);
|
|
1011
|
+
function foldKey (hash, key) {
|
|
1012
|
+
return foldValue(hash, o[key], key, seen);
|
|
1013
|
+
}
|
|
1014
|
+
}
|
|
1015
|
+
|
|
1016
|
+
function foldValue (input, value, key, seen) {
|
|
1017
|
+
var hash = fold(fold(fold(input, key), toString(value)), typeof value);
|
|
1018
|
+
if (value === null) {
|
|
1019
|
+
return fold(hash, 'null');
|
|
1020
|
+
}
|
|
1021
|
+
if (value === undefined) {
|
|
1022
|
+
return fold(hash, 'undefined');
|
|
1023
|
+
}
|
|
1024
|
+
if (typeof value === 'object' || typeof value === 'function') {
|
|
1025
|
+
if (seen.indexOf(value) !== -1) {
|
|
1026
|
+
return fold(hash, '[Circular]' + key);
|
|
1027
|
+
}
|
|
1028
|
+
seen.push(value);
|
|
1029
|
+
|
|
1030
|
+
var objHash = foldObject(hash, value, seen);
|
|
1031
|
+
|
|
1032
|
+
if (!('valueOf' in value) || typeof value.valueOf !== 'function') {
|
|
1033
|
+
return objHash;
|
|
1034
|
+
}
|
|
1035
|
+
|
|
1036
|
+
try {
|
|
1037
|
+
return fold(objHash, String(value.valueOf()))
|
|
1038
|
+
} catch (err) {
|
|
1039
|
+
return fold(objHash, '[valueOf exception]' + (err.stack || err.message))
|
|
1040
|
+
}
|
|
1041
|
+
}
|
|
1042
|
+
return fold(hash, value.toString());
|
|
1043
|
+
}
|
|
1044
|
+
|
|
1045
|
+
function toString (o) {
|
|
1046
|
+
return Object.prototype.toString.call(o);
|
|
1047
|
+
}
|
|
1048
|
+
|
|
1049
|
+
function sum (o) {
|
|
1050
|
+
return pad(foldValue(0, o, '', []).toString(16), 8);
|
|
1051
|
+
}
|
|
1052
|
+
|
|
1053
|
+
var hashSum = sum;
|
|
1054
|
+
|
|
1055
|
+
/**
|
|
1056
|
+
* Safe conversion to error type. Intended to be used in catch blocks where the
|
|
1057
|
+
* value is not guaranteed to be an error.
|
|
1058
|
+
*
|
|
1059
|
+
* @example
|
|
1060
|
+
* try {
|
|
1061
|
+
* throw new Error('Something went wrong')
|
|
1062
|
+
* }
|
|
1063
|
+
* catch (err: unknown) {
|
|
1064
|
+
* const error: Error = toError(err)
|
|
1065
|
+
* }
|
|
1066
|
+
*/
|
|
1067
|
+
function toError(err) {
|
|
1068
|
+
if (err instanceof Error)
|
|
1069
|
+
return err;
|
|
1070
|
+
return new Error(String(err));
|
|
1071
|
+
}
|
|
1072
|
+
|
|
1073
|
+
var DEFAULT_API_VERSION = 'v3';
|
|
1074
|
+
|
|
1075
|
+
function datePlusMinutes(minutes) {
|
|
1076
|
+
if (minutes === void 0) { minutes = 30; }
|
|
1077
|
+
return new Date(Date.now() + minutes * 60000);
|
|
1078
|
+
}
|
|
1079
|
+
var isPositiveNumber = function (thing) {
|
|
1080
|
+
return typeof thing === 'number' && !isNaN(thing) && thing >= 0;
|
|
1081
|
+
};
|
|
1082
|
+
var isReactNative = typeof navigator === 'object' && navigator.product === 'ReactNative';
|
|
1083
|
+
var validEnvList = [
|
|
1084
|
+
'production',
|
|
1085
|
+
'qa',
|
|
1086
|
+
'test',
|
|
1087
|
+
'development',
|
|
1088
|
+
'dev',
|
|
1089
|
+
'cdn-qa',
|
|
1090
|
+
'cloud',
|
|
1091
|
+
'fast',
|
|
1092
|
+
'cdn2',
|
|
1093
|
+
'cdn-prod',
|
|
1094
|
+
];
|
|
1095
|
+
function getQueryParam(url, variable) {
|
|
1096
|
+
var query = url.split('?')[1] || '';
|
|
1097
|
+
var vars = query.split('&');
|
|
1098
|
+
for (var i = 0; i < vars.length; i++) {
|
|
1099
|
+
var pair = vars[i].split('=');
|
|
1100
|
+
if (decodeURIComponent(pair[0]) === variable) {
|
|
1101
|
+
return decodeURIComponent(pair[1]);
|
|
1102
|
+
}
|
|
1103
|
+
}
|
|
1104
|
+
return null;
|
|
1105
|
+
}
|
|
1106
|
+
var urlParser = {
|
|
1107
|
+
parse: function (url) {
|
|
1108
|
+
var el = document.createElement('a');
|
|
1109
|
+
el.href = url;
|
|
1110
|
+
var out = {};
|
|
1111
|
+
var props = [
|
|
1112
|
+
'username',
|
|
1113
|
+
'password',
|
|
1114
|
+
'host',
|
|
1115
|
+
'hostname',
|
|
1116
|
+
'port',
|
|
1117
|
+
'protocol',
|
|
1118
|
+
'origin',
|
|
1119
|
+
'pathname',
|
|
1120
|
+
'search',
|
|
1121
|
+
'hash',
|
|
1122
|
+
];
|
|
1123
|
+
for (var _i = 0, props_1 = props; _i < props_1.length; _i++) {
|
|
1124
|
+
var prop = props_1[_i];
|
|
1125
|
+
out[prop] = el[prop];
|
|
1126
|
+
}
|
|
1127
|
+
// IE 11 pathname handling workaround
|
|
1128
|
+
// (IE omits preceeding '/', unlike other browsers)
|
|
1129
|
+
if ((out.pathname || out.pathname === '') &&
|
|
1130
|
+
typeof out.pathname === 'string' &&
|
|
1131
|
+
out.pathname.indexOf('/') !== 0) {
|
|
1132
|
+
out.pathname = '/' + out.pathname;
|
|
1133
|
+
}
|
|
1134
|
+
return out;
|
|
1135
|
+
},
|
|
1136
|
+
};
|
|
1137
|
+
var parse = isReactNative
|
|
1138
|
+
? function () { return emptyUrl(); }
|
|
1139
|
+
: typeof window === 'object'
|
|
1140
|
+
? urlParser.parse
|
|
1141
|
+
: parse$1;
|
|
1142
|
+
function setCookie(name, value, expires) {
|
|
1143
|
+
try {
|
|
1144
|
+
var expiresString = '';
|
|
1145
|
+
// TODO: need to know if secure server side
|
|
1146
|
+
if (expires) {
|
|
1147
|
+
expiresString = '; expires=' + expires.toUTCString();
|
|
1148
|
+
}
|
|
1149
|
+
var secure = isBrowser ? location.protocol === 'https:' : true;
|
|
1150
|
+
document.cookie =
|
|
1151
|
+
name +
|
|
1152
|
+
'=' +
|
|
1153
|
+
(value || '') +
|
|
1154
|
+
expiresString +
|
|
1155
|
+
'; path=/' +
|
|
1156
|
+
"; domain=".concat(getTopLevelDomain(location.hostname)) +
|
|
1157
|
+
(secure ? ';secure ; SameSite=None' : '');
|
|
1158
|
+
}
|
|
1159
|
+
catch (err) {
|
|
1160
|
+
console.warn('Could not set cookie', err);
|
|
1161
|
+
}
|
|
1162
|
+
}
|
|
1163
|
+
function getCookie(name) {
|
|
1164
|
+
try {
|
|
1165
|
+
return (decodeURIComponent(document.cookie.replace(new RegExp('(?:(?:^|.*;)\\s*' +
|
|
1166
|
+
encodeURIComponent(name).replace(/[\-\.\+\*]/g, '\\$&') +
|
|
1167
|
+
'\\s*\\=\\s*([^;]*).*$)|^.*$'), '$1')) || null);
|
|
1168
|
+
}
|
|
1169
|
+
catch (err) {
|
|
1170
|
+
console.warn('Could not get cookie', err);
|
|
1171
|
+
}
|
|
1172
|
+
}
|
|
1173
|
+
function size(object) {
|
|
1174
|
+
return Object.keys(object).length;
|
|
1175
|
+
}
|
|
1176
|
+
function find(target, callback) {
|
|
1177
|
+
var list = target;
|
|
1178
|
+
// Makes sures is always has an positive integer as length.
|
|
1179
|
+
var length = list.length >>> 0;
|
|
1180
|
+
var thisArg = arguments[1];
|
|
1181
|
+
for (var i = 0; i < length; i++) {
|
|
1182
|
+
var element = list[i];
|
|
1183
|
+
if (callback.call(thisArg, element, i, list)) {
|
|
1184
|
+
return element;
|
|
1185
|
+
}
|
|
1186
|
+
}
|
|
1187
|
+
}
|
|
1188
|
+
var sessionStorageKey = 'builderSessionId';
|
|
1189
|
+
var localStorageKey = 'builderVisitorId';
|
|
1190
|
+
var isBrowser = typeof window !== 'undefined' && !isReactNative;
|
|
1191
|
+
var isIframe = isBrowser && window.top !== window.self;
|
|
1192
|
+
function BuilderComponent(info) {
|
|
1193
|
+
if (info === void 0) { info = {}; }
|
|
1194
|
+
return Builder.Component(info);
|
|
1195
|
+
}
|
|
1196
|
+
var Builder = /** @class */ (function () {
|
|
1197
|
+
function Builder(apiKey, request, response, forceNewInstance, authToken, apiVersion) {
|
|
1198
|
+
if (apiKey === void 0) { apiKey = null; }
|
|
1199
|
+
if (forceNewInstance === void 0) { forceNewInstance = false; }
|
|
1200
|
+
if (authToken === void 0) { authToken = null; }
|
|
1201
|
+
var _this = this;
|
|
1202
|
+
this.request = request;
|
|
1203
|
+
this.response = response;
|
|
1204
|
+
this.eventsQueue = [];
|
|
1205
|
+
this.throttledClearEventsQueue = throttle(function () {
|
|
1206
|
+
_this.processEventsQueue();
|
|
1207
|
+
// Extend the session cookie
|
|
1208
|
+
_this.setCookie(sessionStorageKey, _this.sessionId, datePlusMinutes(30));
|
|
1209
|
+
}, 5);
|
|
1210
|
+
this.env = 'production';
|
|
1211
|
+
this.sessionId = this.getSessionId();
|
|
1212
|
+
this.targetContent = true;
|
|
1213
|
+
this.contentPerRequest = 1;
|
|
1214
|
+
// TODO: make array or function
|
|
1215
|
+
this.allowCustomFonts = true;
|
|
1216
|
+
this.cookies = null;
|
|
1217
|
+
// TODO: api options object
|
|
1218
|
+
this.cachebust = false;
|
|
1219
|
+
this.overrideParams = '';
|
|
1220
|
+
this.noCache = false;
|
|
1221
|
+
this.preview = false;
|
|
1222
|
+
this.apiVersion$ = new BehaviorSubject(undefined);
|
|
1223
|
+
this.canTrack$ = new BehaviorSubject(!this.browserTrackingDisabled);
|
|
1224
|
+
this.apiKey$ = new BehaviorSubject(null);
|
|
1225
|
+
this.authToken$ = new BehaviorSubject(null);
|
|
1226
|
+
this.userAttributesChanged = new BehaviorSubject(null);
|
|
1227
|
+
this.editingMode$ = new BehaviorSubject(isIframe);
|
|
1228
|
+
// TODO: decorator to do this stuff with the get/set (how do with typing too? compiler?)
|
|
1229
|
+
this.editingModel$ = new BehaviorSubject(null);
|
|
1230
|
+
this.userAgent = (typeof navigator === 'object' && navigator.userAgent) || '';
|
|
1231
|
+
this.trackingHooks = [];
|
|
1232
|
+
// Set this to control the userId
|
|
1233
|
+
// TODO: allow changing it mid session and updating existing data to be associated
|
|
1234
|
+
// e.g. for when a user navigates and then logs in
|
|
1235
|
+
this.visitorId = this.getVisitorId();
|
|
1236
|
+
this.autoTrack = !Builder.isBrowser
|
|
1237
|
+
? false
|
|
1238
|
+
: !this.isDevelopmentEnv &&
|
|
1239
|
+
!(Builder.isBrowser && location.search.indexOf('builder.preview=') !== -1);
|
|
1240
|
+
this.trackingUserAttributes = {};
|
|
1241
|
+
this.blockContentLoading = '';
|
|
1242
|
+
this.observersByKey = {};
|
|
1243
|
+
this.noEditorUpdates = {};
|
|
1244
|
+
this.overrides = {};
|
|
1245
|
+
this.queryOptions = {};
|
|
1246
|
+
this.getContentQueue = null;
|
|
1247
|
+
this.priorContentQueue = null;
|
|
1248
|
+
this.testCookiePrefix = 'builder.tests';
|
|
1249
|
+
this.cookieQueue = [];
|
|
1250
|
+
// TODO: use a window variable for this perhaps, e.g. bc webcomponents may be loading builder twice
|
|
1251
|
+
// with it's and react (use rollup build to fix)
|
|
1252
|
+
if (Builder.isBrowser && !forceNewInstance && Builder.singletonInstance) {
|
|
1253
|
+
return Builder.singletonInstance;
|
|
1254
|
+
}
|
|
1255
|
+
if (this.request && this.response) {
|
|
1256
|
+
this.setUserAgent(this.request.headers['user-agent'] || '');
|
|
1257
|
+
this.cookies = new Cookies(this.request, this.response);
|
|
1258
|
+
}
|
|
1259
|
+
if (apiKey) {
|
|
1260
|
+
this.apiKey = apiKey;
|
|
1261
|
+
}
|
|
1262
|
+
if (apiVersion) {
|
|
1263
|
+
this.apiVersion = apiVersion;
|
|
1264
|
+
}
|
|
1265
|
+
if (authToken) {
|
|
1266
|
+
this.authToken = authToken;
|
|
1267
|
+
}
|
|
1268
|
+
if (isBrowser) {
|
|
1269
|
+
this.bindMessageListeners();
|
|
1270
|
+
if (Builder.isEditing) {
|
|
1271
|
+
parent.postMessage({
|
|
1272
|
+
type: 'builder.animatorOptions',
|
|
1273
|
+
data: {
|
|
1274
|
+
options: {
|
|
1275
|
+
version: 2,
|
|
1276
|
+
},
|
|
1277
|
+
},
|
|
1278
|
+
}, '*');
|
|
1279
|
+
}
|
|
1280
|
+
// TODO: postmessage to parent the builder info for every package
|
|
1281
|
+
// type: 'builder.sdk', data: { name: '@builder.io/react', version: '0.1.23' }
|
|
1282
|
+
// (window as any).BUILDER_VERSION = Builder.VERSION;
|
|
1283
|
+
// Ensure always one Builder global singleton
|
|
1284
|
+
// TODO: some people won't want this, e.g. rakuten
|
|
1285
|
+
// Maybe hide this behind symbol or on document, etc
|
|
1286
|
+
// if ((window as any).Builder) {
|
|
1287
|
+
// Builder.components = (window as any).Builder.components;
|
|
1288
|
+
// } else {
|
|
1289
|
+
// (window as any).Builder = Builder;
|
|
1290
|
+
// }
|
|
1291
|
+
}
|
|
1292
|
+
if (isIframe) {
|
|
1293
|
+
this.messageFrameLoaded();
|
|
1294
|
+
}
|
|
1295
|
+
// TODO: on destroy clear subscription
|
|
1296
|
+
this.canTrack$.subscribe(function (value) {
|
|
1297
|
+
if (value) {
|
|
1298
|
+
if (typeof sessionStorage !== 'undefined') {
|
|
1299
|
+
try {
|
|
1300
|
+
if (!sessionStorage.getItem(sessionStorageKey)) {
|
|
1301
|
+
sessionStorage.setItem(sessionStorageKey, _this.sessionId);
|
|
1302
|
+
}
|
|
1303
|
+
}
|
|
1304
|
+
catch (err) {
|
|
1305
|
+
console.debug('Session storage error', err);
|
|
1306
|
+
}
|
|
1307
|
+
}
|
|
1308
|
+
if (_this.eventsQueue.length) {
|
|
1309
|
+
_this.throttledClearEventsQueue();
|
|
1310
|
+
}
|
|
1311
|
+
if (_this.cookieQueue.length) {
|
|
1312
|
+
_this.cookieQueue.forEach(function (item) {
|
|
1313
|
+
_this.setCookie(item[0], item[1]);
|
|
1314
|
+
});
|
|
1315
|
+
_this.cookieQueue.length = 0;
|
|
1316
|
+
}
|
|
1317
|
+
}
|
|
1318
|
+
});
|
|
1319
|
+
if (isBrowser) {
|
|
1320
|
+
// TODO: defer so subclass constructor runs and injects location service
|
|
1321
|
+
this.setTestsFromUrl();
|
|
1322
|
+
// TODO: do this on every request send?
|
|
1323
|
+
this.getOverridesFromQueryString();
|
|
1324
|
+
}
|
|
1325
|
+
}
|
|
1326
|
+
Builder.register = function (type, info) {
|
|
1327
|
+
// TODO: all must have name and can't conflict?
|
|
1328
|
+
var typeList = this.registry[type];
|
|
1329
|
+
if (!typeList) {
|
|
1330
|
+
typeList = this.registry[type] = [];
|
|
1331
|
+
}
|
|
1332
|
+
typeList.push(info);
|
|
1333
|
+
if (Builder.isBrowser) {
|
|
1334
|
+
var message = {
|
|
1335
|
+
type: 'builder.register',
|
|
1336
|
+
data: {
|
|
1337
|
+
type: type,
|
|
1338
|
+
info: info,
|
|
1339
|
+
},
|
|
1340
|
+
};
|
|
1341
|
+
try {
|
|
1342
|
+
parent.postMessage(message, '*');
|
|
1343
|
+
if (parent !== window) {
|
|
1344
|
+
window.postMessage(message, '*');
|
|
1345
|
+
}
|
|
1346
|
+
}
|
|
1347
|
+
catch (err) {
|
|
1348
|
+
console.debug('Could not postmessage', err);
|
|
1349
|
+
}
|
|
1350
|
+
}
|
|
1351
|
+
this.registryChange.next(this.registry);
|
|
1352
|
+
};
|
|
1353
|
+
Builder.registerEditor = function (info) {
|
|
1354
|
+
if (Builder.isBrowser) {
|
|
1355
|
+
window.postMessage({
|
|
1356
|
+
type: 'builder.registerEditor',
|
|
1357
|
+
data: omit(info, 'component'),
|
|
1358
|
+
}, '*');
|
|
1359
|
+
var hostname = location.hostname;
|
|
1360
|
+
if (!Builder.isTrustedHost(hostname)) {
|
|
1361
|
+
console.error('Builder.registerEditor() called in the wrong environment! You cannot load custom editors from your app, they must be loaded through the Builder.io app itself. Follow the readme here for more details: https://github.com/builderio/builder/tree/master/plugins/cloudinary or contact chat us in our Spectrum community for help: https://spectrum.chat/builder');
|
|
1362
|
+
}
|
|
1363
|
+
}
|
|
1364
|
+
this.editors.push(info);
|
|
1365
|
+
};
|
|
1366
|
+
Builder.registerPlugin = function (info) {
|
|
1367
|
+
this.plugins.push(info);
|
|
1368
|
+
};
|
|
1369
|
+
Builder.registerAction = function (action) {
|
|
1370
|
+
this.actions.push(action);
|
|
1371
|
+
};
|
|
1372
|
+
Builder.registerTrustedHost = function (host) {
|
|
1373
|
+
this.trustedHosts.push(host);
|
|
1374
|
+
};
|
|
1375
|
+
/**
|
|
1376
|
+
* @param context @type {import('isolated-vm').Context}
|
|
1377
|
+
* Use this function to control the execution context of custom code on the server.
|
|
1378
|
+
* const ivm = require('isolated-vm');
|
|
1379
|
+
* const isolate = new ivm.Isolate({ memoryLimit: 128 });
|
|
1380
|
+
* const context = isolate.createContextSync();
|
|
1381
|
+
* Builder.setServerContext(context);
|
|
1382
|
+
*/
|
|
1383
|
+
Builder.setServerContext = function (context) {
|
|
1384
|
+
this.serverContext = context;
|
|
1385
|
+
};
|
|
1386
|
+
Builder.isTrustedHost = function (hostname) {
|
|
1387
|
+
return (this.trustedHosts.findIndex(function (trustedHost) { return trustedHost === hostname || hostname.endsWith(".".concat(trustedHost)); }) > -1);
|
|
1388
|
+
};
|
|
1389
|
+
Builder.runAction = function (action) {
|
|
1390
|
+
// TODO
|
|
1391
|
+
var actionObject = typeof action === 'string' ? find(this.actions, function (item) { return item.name === action; }) : action;
|
|
1392
|
+
if (!actionObject) {
|
|
1393
|
+
throw new Error("Action not found: ".concat(action));
|
|
1394
|
+
}
|
|
1395
|
+
};
|
|
1396
|
+
Builder.fields = function (name, fields) {
|
|
1397
|
+
var _a;
|
|
1398
|
+
(_a = window.parent) === null || _a === void 0 ? void 0 : _a.postMessage({
|
|
1399
|
+
type: 'builder.fields',
|
|
1400
|
+
data: { name: name, fields: fields },
|
|
1401
|
+
}, '*');
|
|
1402
|
+
};
|
|
1403
|
+
/**
|
|
1404
|
+
* @deprecated
|
|
1405
|
+
* @hidden
|
|
1406
|
+
*
|
|
1407
|
+
* Use Builder.register('editor.settings', {}) instead.
|
|
1408
|
+
*/
|
|
1409
|
+
Builder.set = function (settings) {
|
|
1410
|
+
Builder.register('editor.settings', settings);
|
|
1411
|
+
};
|
|
1412
|
+
Builder.import = function (packageName) {
|
|
1413
|
+
if (!Builder.isBrowser) {
|
|
1414
|
+
// TODO: server side support *maybe*
|
|
1415
|
+
console.warn('Builder.import used on the server - this should only be used in the browser');
|
|
1416
|
+
return;
|
|
1417
|
+
}
|
|
1418
|
+
var System = window.System;
|
|
1419
|
+
if (!System) {
|
|
1420
|
+
console.warn('System.js not available. Please include System.js when using Builder.import');
|
|
1421
|
+
return;
|
|
1422
|
+
}
|
|
1423
|
+
return System.import("https://cdn.builder.io/systemjs/".concat(packageName));
|
|
1424
|
+
};
|
|
1425
|
+
Object.defineProperty(Builder, "editingPage", {
|
|
1426
|
+
// useCdnApi = false;
|
|
1427
|
+
get: function () {
|
|
1428
|
+
return this._editingPage;
|
|
1429
|
+
},
|
|
1430
|
+
set: function (editingPage) {
|
|
1431
|
+
this._editingPage = editingPage;
|
|
1432
|
+
if (isBrowser && isIframe) {
|
|
1433
|
+
if (editingPage) {
|
|
1434
|
+
document.body.classList.add('builder-editing-page');
|
|
1435
|
+
}
|
|
1436
|
+
else {
|
|
1437
|
+
document.body.classList.remove('builder-editing-page');
|
|
1438
|
+
}
|
|
1439
|
+
}
|
|
1440
|
+
},
|
|
1441
|
+
enumerable: false,
|
|
1442
|
+
configurable: true
|
|
1443
|
+
});
|
|
1444
|
+
Builder.prepareComponentSpecToSend = function (spec) {
|
|
1445
|
+
return __assign(__assign(__assign({}, spec), (spec.inputs && {
|
|
1446
|
+
inputs: spec.inputs.map(function (input) {
|
|
1447
|
+
var _a;
|
|
1448
|
+
// TODO: do for nexted fields too
|
|
1449
|
+
// TODO: probably just convert all functions, not just
|
|
1450
|
+
// TODO: put this in input hooks: { onChange: ..., showIf: ... }
|
|
1451
|
+
var keysToConvertFnToString = ['onChange', 'showIf'];
|
|
1452
|
+
for (var _i = 0, keysToConvertFnToString_1 = keysToConvertFnToString; _i < keysToConvertFnToString_1.length; _i++) {
|
|
1453
|
+
var key = keysToConvertFnToString_1[_i];
|
|
1454
|
+
if (input[key] && typeof input[key] === 'function') {
|
|
1455
|
+
var fn = input[key];
|
|
1456
|
+
input = __assign(__assign({}, input), (_a = {}, _a[key] = "return (".concat(fn.toString(), ").apply(this, arguments)"), _a));
|
|
1457
|
+
}
|
|
1458
|
+
}
|
|
1459
|
+
return input;
|
|
1460
|
+
}),
|
|
1461
|
+
})), { hooks: Object.keys(spec.hooks || {}).reduce(function (memo, key) {
|
|
1462
|
+
var value = spec.hooks && spec.hooks[key];
|
|
1463
|
+
if (!value) {
|
|
1464
|
+
return memo;
|
|
1465
|
+
}
|
|
1466
|
+
if (typeof value === 'string') {
|
|
1467
|
+
memo[key] = value;
|
|
1468
|
+
}
|
|
1469
|
+
else {
|
|
1470
|
+
memo[key] = "return (".concat(value.toString(), ").apply(this, arguments)");
|
|
1471
|
+
}
|
|
1472
|
+
return memo;
|
|
1473
|
+
}, {}), class: undefined });
|
|
1474
|
+
};
|
|
1475
|
+
Builder.registerBlock = function (component, options) {
|
|
1476
|
+
this.registerComponent(component, options);
|
|
1477
|
+
};
|
|
1478
|
+
Builder.registerComponent = function (component, options) {
|
|
1479
|
+
var _a;
|
|
1480
|
+
var spec = __assign(__assign({ class: component }, component.builderOptions), options);
|
|
1481
|
+
this.addComponent(spec);
|
|
1482
|
+
var editable = options.models && this.singletonInstance.editingModel
|
|
1483
|
+
? isBrowser && options.models.includes(this.singletonInstance.editingModel)
|
|
1484
|
+
: isBrowser;
|
|
1485
|
+
if (editable) {
|
|
1486
|
+
var sendSpec = this.prepareComponentSpecToSend(spec);
|
|
1487
|
+
(_a = window.parent) === null || _a === void 0 ? void 0 : _a.postMessage({
|
|
1488
|
+
type: 'builder.registerComponent',
|
|
1489
|
+
data: sendSpec,
|
|
1490
|
+
}, '*');
|
|
1491
|
+
}
|
|
1492
|
+
};
|
|
1493
|
+
Builder.addComponent = function (component) {
|
|
1494
|
+
var current = find(this.components, function (item) { return item.name === component.name; });
|
|
1495
|
+
if (current) {
|
|
1496
|
+
// FIXME: why does sometimes we get an extra post without class - probably
|
|
1497
|
+
// from postMessage handler wrong in some place
|
|
1498
|
+
if (current.class && !component.class) {
|
|
1499
|
+
return;
|
|
1500
|
+
}
|
|
1501
|
+
this.components.splice(this.components.indexOf(current), 1, component);
|
|
1502
|
+
}
|
|
1503
|
+
else {
|
|
1504
|
+
this.components.push(component);
|
|
1505
|
+
}
|
|
1506
|
+
};
|
|
1507
|
+
// TODO: style guide, etc off this system as well?
|
|
1508
|
+
Builder.component = function (info) {
|
|
1509
|
+
var _this = this;
|
|
1510
|
+
if (info === void 0) { info = {}; }
|
|
1511
|
+
return function (component) {
|
|
1512
|
+
var _a;
|
|
1513
|
+
var spec = __assign(__assign({}, info), { class: component });
|
|
1514
|
+
if (!spec.name) {
|
|
1515
|
+
spec.name = component.name;
|
|
1516
|
+
}
|
|
1517
|
+
_this.addComponent(spec);
|
|
1518
|
+
var sendSpec = _this.prepareComponentSpecToSend(spec);
|
|
1519
|
+
// TODO: serialize component name and inputs
|
|
1520
|
+
if (isBrowser) {
|
|
1521
|
+
(_a = window.parent) === null || _a === void 0 ? void 0 : _a.postMessage({
|
|
1522
|
+
type: 'builder.registerComponent',
|
|
1523
|
+
data: sendSpec,
|
|
1524
|
+
}, '*');
|
|
1525
|
+
}
|
|
1526
|
+
return component;
|
|
1527
|
+
};
|
|
1528
|
+
};
|
|
1529
|
+
Object.defineProperty(Builder, "Component", {
|
|
1530
|
+
get: function () {
|
|
1531
|
+
return this.component;
|
|
1532
|
+
},
|
|
1533
|
+
enumerable: false,
|
|
1534
|
+
configurable: true
|
|
1535
|
+
});
|
|
1536
|
+
Builder.prototype.processEventsQueue = function () {
|
|
1537
|
+
if (!this.eventsQueue.length) {
|
|
1538
|
+
return;
|
|
1539
|
+
}
|
|
1540
|
+
var events = this.eventsQueue;
|
|
1541
|
+
this.eventsQueue = [];
|
|
1542
|
+
var fullUserAttributes = __assign(__assign({}, Builder.overrideUserAttributes), this.trackingUserAttributes);
|
|
1543
|
+
for (var _i = 0, events_1 = events; _i < events_1.length; _i++) {
|
|
1544
|
+
var event_1 = events_1[_i];
|
|
1545
|
+
if (!event_1.data.metadata) {
|
|
1546
|
+
event_1.data.metadata = {};
|
|
1547
|
+
}
|
|
1548
|
+
if (!event_1.data.metadata.user) {
|
|
1549
|
+
event_1.data.metadata.user = {};
|
|
1550
|
+
}
|
|
1551
|
+
Object.assign(event_1.data.metadata.user, fullUserAttributes, event_1.data.metadata.user);
|
|
1552
|
+
}
|
|
1553
|
+
var host = this.host;
|
|
1554
|
+
getFetch()("".concat(host, "/api/v1/track"), {
|
|
1555
|
+
method: 'POST',
|
|
1556
|
+
body: JSON.stringify({ events: events }),
|
|
1557
|
+
headers: {
|
|
1558
|
+
'content-type': 'application/json',
|
|
1559
|
+
},
|
|
1560
|
+
mode: 'cors',
|
|
1561
|
+
}).catch(function () {
|
|
1562
|
+
// Not the end of the world
|
|
1563
|
+
});
|
|
1564
|
+
};
|
|
1565
|
+
Object.defineProperty(Builder.prototype, "browserTrackingDisabled", {
|
|
1566
|
+
get: function () {
|
|
1567
|
+
return Builder.isBrowser && Boolean(window.builderNoTrack || !navigator.cookieEnabled);
|
|
1568
|
+
},
|
|
1569
|
+
enumerable: false,
|
|
1570
|
+
configurable: true
|
|
1571
|
+
});
|
|
1572
|
+
Object.defineProperty(Builder.prototype, "canTrack", {
|
|
1573
|
+
get: function () {
|
|
1574
|
+
return this.canTrack$.value;
|
|
1575
|
+
},
|
|
1576
|
+
set: function (canTrack) {
|
|
1577
|
+
if (this.canTrack !== canTrack) {
|
|
1578
|
+
this.canTrack$.next(canTrack);
|
|
1579
|
+
}
|
|
1580
|
+
},
|
|
1581
|
+
enumerable: false,
|
|
1582
|
+
configurable: true
|
|
1583
|
+
});
|
|
1584
|
+
Object.defineProperty(Builder.prototype, "apiVersion", {
|
|
1585
|
+
get: function () {
|
|
1586
|
+
return this.apiVersion$.value;
|
|
1587
|
+
},
|
|
1588
|
+
set: function (apiVersion) {
|
|
1589
|
+
if (this.apiVersion !== apiVersion) {
|
|
1590
|
+
this.apiVersion$.next(apiVersion);
|
|
1591
|
+
}
|
|
1592
|
+
},
|
|
1593
|
+
enumerable: false,
|
|
1594
|
+
configurable: true
|
|
1595
|
+
});
|
|
1596
|
+
Object.defineProperty(Builder.prototype, "editingMode", {
|
|
1597
|
+
get: function () {
|
|
1598
|
+
return this.editingMode$.value;
|
|
1599
|
+
},
|
|
1600
|
+
set: function (value) {
|
|
1601
|
+
if (value !== this.editingMode) {
|
|
1602
|
+
this.editingMode$.next(value);
|
|
1603
|
+
}
|
|
1604
|
+
},
|
|
1605
|
+
enumerable: false,
|
|
1606
|
+
configurable: true
|
|
1607
|
+
});
|
|
1608
|
+
Object.defineProperty(Builder.prototype, "editingModel", {
|
|
1609
|
+
get: function () {
|
|
1610
|
+
return this.editingModel$.value;
|
|
1611
|
+
},
|
|
1612
|
+
set: function (value) {
|
|
1613
|
+
if (value !== this.editingModel) {
|
|
1614
|
+
this.editingModel$.next(value);
|
|
1615
|
+
}
|
|
1616
|
+
},
|
|
1617
|
+
enumerable: false,
|
|
1618
|
+
configurable: true
|
|
1619
|
+
});
|
|
1620
|
+
Builder.prototype.findParentElement = function (target, callback, checkElement) {
|
|
1621
|
+
if (checkElement === void 0) { checkElement = true; }
|
|
1622
|
+
if (!(target instanceof HTMLElement)) {
|
|
1623
|
+
return null;
|
|
1624
|
+
}
|
|
1625
|
+
var parent = checkElement ? target : target.parentElement;
|
|
1626
|
+
do {
|
|
1627
|
+
if (!parent) {
|
|
1628
|
+
return null;
|
|
1629
|
+
}
|
|
1630
|
+
var matches = callback(parent);
|
|
1631
|
+
if (matches) {
|
|
1632
|
+
return parent;
|
|
1633
|
+
}
|
|
1634
|
+
} while ((parent = parent.parentElement));
|
|
1635
|
+
return null;
|
|
1636
|
+
};
|
|
1637
|
+
Builder.prototype.findBuilderParent = function (target) {
|
|
1638
|
+
return this.findParentElement(target, function (el) {
|
|
1639
|
+
var id = el.getAttribute('builder-id') || el.id;
|
|
1640
|
+
return Boolean(id && id.indexOf('builder-') === 0);
|
|
1641
|
+
});
|
|
1642
|
+
};
|
|
1643
|
+
Builder.prototype.setUserAgent = function (userAgent) {
|
|
1644
|
+
this.userAgent = userAgent || '';
|
|
1645
|
+
};
|
|
1646
|
+
/**
|
|
1647
|
+
* Set a hook to modify events being tracked from builder, such as impressions and clicks
|
|
1648
|
+
*
|
|
1649
|
+
* For example, to track the model ID of each event associated with content for querying
|
|
1650
|
+
* by mode, you can do
|
|
1651
|
+
*
|
|
1652
|
+
* builder.setTrackingHook((event, context) => {
|
|
1653
|
+
* if (context.content) {
|
|
1654
|
+
* event.data.metadata.modelId = context.content.modelId
|
|
1655
|
+
* }
|
|
1656
|
+
* })
|
|
1657
|
+
*/
|
|
1658
|
+
Builder.prototype.setTrackingHook = function (hook) {
|
|
1659
|
+
this.trackingHooks.push(hook);
|
|
1660
|
+
};
|
|
1661
|
+
Builder.prototype.track = function (eventName, properties, context) {
|
|
1662
|
+
if (properties === void 0) { properties = {}; }
|
|
1663
|
+
// TODO: queue up track requests and fire them off when canTrack set to true - otherwise may get lots of clicks with no impressions
|
|
1664
|
+
if (isIframe || !isBrowser || Builder.isPreviewing) {
|
|
1665
|
+
return;
|
|
1666
|
+
}
|
|
1667
|
+
var apiKey = this.apiKey;
|
|
1668
|
+
if (!apiKey) {
|
|
1669
|
+
console.error('Builder integration error: Looks like the Builder SDK has not been initialized properly (your API key has not been set). Make sure you are calling `builder.init("«YOUR-API-KEY»");` as early as possible in your application\'s code.');
|
|
1670
|
+
return;
|
|
1671
|
+
}
|
|
1672
|
+
var eventData = JSON.parse(JSON.stringify({
|
|
1673
|
+
type: eventName,
|
|
1674
|
+
data: __assign(__assign({}, omit(properties, 'meta')), { metadata: __assign(__assign({ sdkVersion: Builder.VERSION, url: location.href }, properties.meta), properties.metadata), ownerId: apiKey, userAttributes: this.getUserAttributes(), sessionId: this.sessionId, visitorId: this.visitorId }),
|
|
1675
|
+
}));
|
|
1676
|
+
for (var _i = 0, _a = this.trackingHooks; _i < _a.length; _i++) {
|
|
1677
|
+
var hook = _a[_i];
|
|
1678
|
+
var returnValue = hook(eventData, context || {});
|
|
1679
|
+
if (returnValue) {
|
|
1680
|
+
eventData = returnValue;
|
|
1681
|
+
}
|
|
1682
|
+
}
|
|
1683
|
+
// batch events
|
|
1684
|
+
this.eventsQueue.push(eventData);
|
|
1685
|
+
if (this.canTrack) {
|
|
1686
|
+
this.throttledClearEventsQueue();
|
|
1687
|
+
}
|
|
1688
|
+
};
|
|
1689
|
+
Builder.prototype.getSessionId = function () {
|
|
1690
|
+
var _this = this;
|
|
1691
|
+
var sessionId = null;
|
|
1692
|
+
try {
|
|
1693
|
+
if (Builder.isBrowser && typeof sessionStorage !== 'undefined') {
|
|
1694
|
+
sessionId = this.getCookie(sessionStorageKey);
|
|
1695
|
+
}
|
|
1696
|
+
}
|
|
1697
|
+
catch (err) {
|
|
1698
|
+
console.debug('Session storage error', err);
|
|
1699
|
+
// It's ok
|
|
1700
|
+
}
|
|
1701
|
+
if (!sessionId) {
|
|
1702
|
+
sessionId = uuid();
|
|
1703
|
+
}
|
|
1704
|
+
// Give the app a second to start up and set canTrack to false if needed
|
|
1705
|
+
if (Builder.isBrowser) {
|
|
1706
|
+
setTimeout(function () {
|
|
1707
|
+
try {
|
|
1708
|
+
if (_this.canTrack) {
|
|
1709
|
+
_this.setCookie(sessionStorageKey, sessionId, datePlusMinutes(30));
|
|
1710
|
+
}
|
|
1711
|
+
}
|
|
1712
|
+
catch (err) {
|
|
1713
|
+
console.debug('Cookie setting error', err);
|
|
1714
|
+
}
|
|
1715
|
+
});
|
|
1716
|
+
}
|
|
1717
|
+
return sessionId;
|
|
1718
|
+
};
|
|
1719
|
+
Builder.prototype.getVisitorId = function () {
|
|
1720
|
+
var _this = this;
|
|
1721
|
+
if (this.visitorId) {
|
|
1722
|
+
return this.visitorId;
|
|
1723
|
+
}
|
|
1724
|
+
var visitorId = null;
|
|
1725
|
+
try {
|
|
1726
|
+
if (Builder.isBrowser && typeof localStorage !== 'undefined') {
|
|
1727
|
+
// TODO: cookie instead?
|
|
1728
|
+
visitorId = localStorage.getItem(localStorageKey);
|
|
1729
|
+
}
|
|
1730
|
+
}
|
|
1731
|
+
catch (err) {
|
|
1732
|
+
console.debug('Local storage error', err);
|
|
1733
|
+
// It's ok
|
|
1734
|
+
}
|
|
1735
|
+
if (!visitorId) {
|
|
1736
|
+
visitorId = uuid();
|
|
1737
|
+
}
|
|
1738
|
+
this.visitorId = visitorId;
|
|
1739
|
+
// Give the app a second to start up and set canTrack to false if needed
|
|
1740
|
+
if (Builder.isBrowser) {
|
|
1741
|
+
setTimeout(function () {
|
|
1742
|
+
try {
|
|
1743
|
+
if (_this.canTrack && typeof localStorage !== 'undefined' && visitorId) {
|
|
1744
|
+
localStorage.setItem(localStorageKey, visitorId);
|
|
1745
|
+
}
|
|
1746
|
+
}
|
|
1747
|
+
catch (err) {
|
|
1748
|
+
console.debug('Session storage error', err);
|
|
1749
|
+
}
|
|
1750
|
+
});
|
|
1751
|
+
}
|
|
1752
|
+
return visitorId;
|
|
1753
|
+
};
|
|
1754
|
+
Builder.prototype.trackImpression = function (contentId, variationId, properties, context) {
|
|
1755
|
+
if (isIframe || !isBrowser || Builder.isPreviewing) {
|
|
1756
|
+
return;
|
|
1757
|
+
}
|
|
1758
|
+
// TODO: use this.track method
|
|
1759
|
+
this.track('impression', {
|
|
1760
|
+
contentId: contentId,
|
|
1761
|
+
variationId: variationId !== contentId ? variationId : undefined,
|
|
1762
|
+
metadata: properties,
|
|
1763
|
+
}, context);
|
|
1764
|
+
};
|
|
1765
|
+
Builder.prototype.trackConversion = function (amount, contentId, variationId, customProperties, context) {
|
|
1766
|
+
if (isIframe || !isBrowser || Builder.isPreviewing) {
|
|
1767
|
+
return;
|
|
1768
|
+
}
|
|
1769
|
+
var meta = typeof contentId === 'object' ? contentId : customProperties;
|
|
1770
|
+
var useContentId = typeof contentId === 'string' ? contentId : undefined;
|
|
1771
|
+
this.track('conversion', { amount: amount, variationId: variationId, meta: meta, contentId: useContentId }, context);
|
|
1772
|
+
};
|
|
1773
|
+
Object.defineProperty(Builder.prototype, "isDevelopmentEnv", {
|
|
1774
|
+
// TODO: set this for QA
|
|
1775
|
+
get: function () {
|
|
1776
|
+
// Automatic determining of development environment
|
|
1777
|
+
return (Builder.isIframe ||
|
|
1778
|
+
(Builder.isBrowser && (location.hostname === 'localhost' || location.port !== '')) ||
|
|
1779
|
+
this.env !== 'production');
|
|
1780
|
+
},
|
|
1781
|
+
enumerable: false,
|
|
1782
|
+
configurable: true
|
|
1783
|
+
});
|
|
1784
|
+
Builder.prototype.trackInteraction = function (contentId, variationId, alreadyTrackedOne, event, context) {
|
|
1785
|
+
if (alreadyTrackedOne === void 0) { alreadyTrackedOne = false; }
|
|
1786
|
+
if (isIframe || !isBrowser || Builder.isPreviewing) {
|
|
1787
|
+
return;
|
|
1788
|
+
}
|
|
1789
|
+
var target = event && event.target;
|
|
1790
|
+
var targetBuilderElement = target && this.findBuilderParent(target);
|
|
1791
|
+
function round(num) {
|
|
1792
|
+
return Math.round(num * 1000) / 1000;
|
|
1793
|
+
}
|
|
1794
|
+
var metadata = {};
|
|
1795
|
+
if (event) {
|
|
1796
|
+
var clientX = event.clientX, clientY = event.clientY;
|
|
1797
|
+
if (target) {
|
|
1798
|
+
var targetRect = target.getBoundingClientRect();
|
|
1799
|
+
var xOffset = clientX - targetRect.left;
|
|
1800
|
+
var yOffset = clientY - targetRect.top;
|
|
1801
|
+
var xRatio = round(xOffset / targetRect.width);
|
|
1802
|
+
var yRatio = round(yOffset / targetRect.height);
|
|
1803
|
+
metadata.targetOffset = {
|
|
1804
|
+
x: xRatio,
|
|
1805
|
+
y: yRatio,
|
|
1806
|
+
};
|
|
1807
|
+
}
|
|
1808
|
+
if (targetBuilderElement) {
|
|
1809
|
+
var targetRect = targetBuilderElement.getBoundingClientRect();
|
|
1810
|
+
var xOffset = clientX - targetRect.left;
|
|
1811
|
+
var yOffset = clientY - targetRect.top;
|
|
1812
|
+
var xRatio = round(xOffset / targetRect.width);
|
|
1813
|
+
var yRatio = round(yOffset / targetRect.height);
|
|
1814
|
+
metadata.builderTargetOffset = {
|
|
1815
|
+
x: xRatio,
|
|
1816
|
+
y: yRatio,
|
|
1817
|
+
};
|
|
1818
|
+
}
|
|
1819
|
+
}
|
|
1820
|
+
var builderId = targetBuilderElement &&
|
|
1821
|
+
(targetBuilderElement.getAttribute('builder-id') || targetBuilderElement.id);
|
|
1822
|
+
if (builderId && targetBuilderElement) {
|
|
1823
|
+
metadata.builderElementIndex = [].slice
|
|
1824
|
+
.call(document.getElementsByClassName(builderId))
|
|
1825
|
+
.indexOf(targetBuilderElement);
|
|
1826
|
+
}
|
|
1827
|
+
this.track('click', {
|
|
1828
|
+
contentId: contentId,
|
|
1829
|
+
metadata: metadata,
|
|
1830
|
+
variationId: variationId !== contentId ? variationId : undefined,
|
|
1831
|
+
unique: !alreadyTrackedOne,
|
|
1832
|
+
targetBuilderElement: builderId || undefined,
|
|
1833
|
+
}, context);
|
|
1834
|
+
};
|
|
1835
|
+
Builder.prototype.component = function (info) {
|
|
1836
|
+
if (info === void 0) { info = {}; }
|
|
1837
|
+
return Builder.component(info);
|
|
1838
|
+
};
|
|
1839
|
+
Object.defineProperty(Builder.prototype, "apiKey", {
|
|
1840
|
+
get: function () {
|
|
1841
|
+
return this.apiKey$.value;
|
|
1842
|
+
},
|
|
1843
|
+
set: function (key) {
|
|
1844
|
+
this.apiKey$.next(key);
|
|
1845
|
+
},
|
|
1846
|
+
enumerable: false,
|
|
1847
|
+
configurable: true
|
|
1848
|
+
});
|
|
1849
|
+
Object.defineProperty(Builder.prototype, "authToken", {
|
|
1850
|
+
get: function () {
|
|
1851
|
+
return this.authToken$.value;
|
|
1852
|
+
},
|
|
1853
|
+
set: function (token) {
|
|
1854
|
+
this.authToken$.next(token);
|
|
1855
|
+
},
|
|
1856
|
+
enumerable: false,
|
|
1857
|
+
configurable: true
|
|
1858
|
+
});
|
|
1859
|
+
Builder.prototype.modifySearch = function (search) {
|
|
1860
|
+
return search.replace(/(^|&|\?)(builder_.*?)=/gi, function (_match, group1, group2) { return group1 + group2.replace(/_/g, '.') + '='; });
|
|
1861
|
+
};
|
|
1862
|
+
Builder.prototype.setTestsFromUrl = function () {
|
|
1863
|
+
var search = this.getLocation().search;
|
|
1864
|
+
var params = QueryString.parseDeep(this.modifySearch(search || '').substr(1));
|
|
1865
|
+
var tests = params.builder && params.builder.tests;
|
|
1866
|
+
if (tests && typeof tests === 'object') {
|
|
1867
|
+
for (var key in tests) {
|
|
1868
|
+
if (tests.hasOwnProperty(key)) {
|
|
1869
|
+
this.setTestCookie(key, tests[key]);
|
|
1870
|
+
}
|
|
1871
|
+
}
|
|
1872
|
+
}
|
|
1873
|
+
};
|
|
1874
|
+
Builder.prototype.resetOverrides = function () {
|
|
1875
|
+
// Ugly - pass down instances per request instead using react context
|
|
1876
|
+
// or use builder.get('foo', { req, res }) in react...........
|
|
1877
|
+
Builder.overrideUserAttributes = {};
|
|
1878
|
+
this.cachebust = false;
|
|
1879
|
+
this.noCache = false;
|
|
1880
|
+
this.preview = false;
|
|
1881
|
+
this.editingModel = null;
|
|
1882
|
+
this.overrides = {};
|
|
1883
|
+
this.env = 'production';
|
|
1884
|
+
this.userAgent = '';
|
|
1885
|
+
this.request = undefined;
|
|
1886
|
+
this.response = undefined;
|
|
1887
|
+
};
|
|
1888
|
+
Builder.prototype.getOverridesFromQueryString = function () {
|
|
1889
|
+
var location = this.getLocation();
|
|
1890
|
+
var params = QueryString.parseDeep(this.modifySearch(location.search || '').substr(1));
|
|
1891
|
+
var builder = params.builder;
|
|
1892
|
+
if (builder) {
|
|
1893
|
+
var userAttributes = builder.userAttributes, overrides = builder.overrides, env = builder.env; builder.host; var api = builder.api, cachebust = builder.cachebust, noCache = builder.noCache, preview = builder.preview, editing = builder.editing, frameEditing = builder.frameEditing, options = builder.options, overrideParams = builder.params;
|
|
1894
|
+
if (userAttributes) {
|
|
1895
|
+
this.setUserAttributes(userAttributes);
|
|
1896
|
+
}
|
|
1897
|
+
if (options) {
|
|
1898
|
+
// picking only locale, includeRefs, and enrich for now
|
|
1899
|
+
this.queryOptions = __assign(__assign(__assign({}, (options.locale && { locale: options.locale })), (options.includeRefs && { includeRefs: options.includeRefs })), (options.enrich && { enrich: options.enrich }));
|
|
1900
|
+
}
|
|
1901
|
+
if (overrides) {
|
|
1902
|
+
this.overrides = overrides;
|
|
1903
|
+
}
|
|
1904
|
+
if (validEnvList.indexOf(env || api) > -1) {
|
|
1905
|
+
this.env = env || api;
|
|
1906
|
+
}
|
|
1907
|
+
if (Builder.isEditing) {
|
|
1908
|
+
var editingModel = frameEditing || editing || preview;
|
|
1909
|
+
if (editingModel && editingModel !== 'true') {
|
|
1910
|
+
this.editingModel = editingModel;
|
|
1911
|
+
}
|
|
1912
|
+
}
|
|
1913
|
+
if (cachebust) {
|
|
1914
|
+
this.cachebust = true;
|
|
1915
|
+
}
|
|
1916
|
+
if (noCache) {
|
|
1917
|
+
this.noCache = true;
|
|
1918
|
+
}
|
|
1919
|
+
if (preview) {
|
|
1920
|
+
this.preview = true;
|
|
1921
|
+
}
|
|
1922
|
+
if (params) {
|
|
1923
|
+
this.overrideParams = overrideParams;
|
|
1924
|
+
}
|
|
1925
|
+
}
|
|
1926
|
+
};
|
|
1927
|
+
Builder.prototype.messageFrameLoaded = function () {
|
|
1928
|
+
var _a;
|
|
1929
|
+
(_a = window.parent) === null || _a === void 0 ? void 0 : _a.postMessage({
|
|
1930
|
+
type: 'builder.loaded',
|
|
1931
|
+
data: {
|
|
1932
|
+
value: true,
|
|
1933
|
+
},
|
|
1934
|
+
}, '*');
|
|
1935
|
+
};
|
|
1936
|
+
Builder.prototype.bindMessageListeners = function () {
|
|
1937
|
+
var _this = this;
|
|
1938
|
+
if (isBrowser) {
|
|
1939
|
+
addEventListener('message', function (event) {
|
|
1940
|
+
var _a, _b, _c, _d, _e;
|
|
1941
|
+
var url = parse(event.origin);
|
|
1942
|
+
var isRestricted = ['builder.register', 'builder.registerComponent'].indexOf((_a = event.data) === null || _a === void 0 ? void 0 : _a.type) === -1;
|
|
1943
|
+
var isTrusted = url.hostname && Builder.isTrustedHost(url.hostname);
|
|
1944
|
+
if (isRestricted && !isTrusted) {
|
|
1945
|
+
return;
|
|
1946
|
+
}
|
|
1947
|
+
var data = event.data;
|
|
1948
|
+
if (data) {
|
|
1949
|
+
switch (data.type) {
|
|
1950
|
+
case 'builder.ping': {
|
|
1951
|
+
(_b = window.parent) === null || _b === void 0 ? void 0 : _b.postMessage({
|
|
1952
|
+
type: 'builder.pong',
|
|
1953
|
+
data: {},
|
|
1954
|
+
}, '*');
|
|
1955
|
+
break;
|
|
1956
|
+
}
|
|
1957
|
+
case 'builder.register': {
|
|
1958
|
+
// TODO: possibly do this for all...
|
|
1959
|
+
if (event.source === window) {
|
|
1960
|
+
break;
|
|
1961
|
+
}
|
|
1962
|
+
var options = data.data;
|
|
1963
|
+
if (!options) {
|
|
1964
|
+
break;
|
|
1965
|
+
}
|
|
1966
|
+
var type = options.type, info = options.info;
|
|
1967
|
+
// TODO: all must have name and can't conflict?
|
|
1968
|
+
var typeList = Builder.registry[type];
|
|
1969
|
+
if (!typeList) {
|
|
1970
|
+
typeList = Builder.registry[type] = [];
|
|
1971
|
+
}
|
|
1972
|
+
typeList.push(info);
|
|
1973
|
+
Builder.registryChange.next(Builder.registry);
|
|
1974
|
+
break;
|
|
1975
|
+
}
|
|
1976
|
+
case 'builder.settingsChange': {
|
|
1977
|
+
// TODO: possibly do this for all...
|
|
1978
|
+
if (event.source === window) {
|
|
1979
|
+
break;
|
|
1980
|
+
}
|
|
1981
|
+
var settings = data.data;
|
|
1982
|
+
if (!settings) {
|
|
1983
|
+
break;
|
|
1984
|
+
}
|
|
1985
|
+
Object.assign(Builder.settings, settings);
|
|
1986
|
+
Builder.settingsChange.next(Builder.settings);
|
|
1987
|
+
break;
|
|
1988
|
+
}
|
|
1989
|
+
case 'builder.registerEditor': {
|
|
1990
|
+
// TODO: possibly do this for all...
|
|
1991
|
+
if (event.source === window) {
|
|
1992
|
+
break;
|
|
1993
|
+
}
|
|
1994
|
+
var info_1 = data.data;
|
|
1995
|
+
if (!info_1) {
|
|
1996
|
+
break;
|
|
1997
|
+
}
|
|
1998
|
+
var hasComponent_1 = !!info_1.component;
|
|
1999
|
+
Builder.editors.every(function (thisInfo, index) {
|
|
2000
|
+
if (info_1.name === thisInfo.name) {
|
|
2001
|
+
if (thisInfo.component && !hasComponent_1) {
|
|
2002
|
+
return false;
|
|
2003
|
+
}
|
|
2004
|
+
else {
|
|
2005
|
+
Builder.editors[index] = thisInfo;
|
|
2006
|
+
}
|
|
2007
|
+
return false;
|
|
2008
|
+
}
|
|
2009
|
+
return true;
|
|
2010
|
+
});
|
|
2011
|
+
break;
|
|
2012
|
+
}
|
|
2013
|
+
case 'builder.triggerAnimation': {
|
|
2014
|
+
Builder.animator.triggerAnimation(data.data);
|
|
2015
|
+
break;
|
|
2016
|
+
}
|
|
2017
|
+
case 'builder.contentUpdate':
|
|
2018
|
+
var key = data.data.key || data.data.alias || data.data.entry || data.data.modelName;
|
|
2019
|
+
var contentData = data.data.data; // hmmm...
|
|
2020
|
+
var observer = _this.observersByKey[key];
|
|
2021
|
+
if (observer && !_this.noEditorUpdates[key]) {
|
|
2022
|
+
observer.next([contentData]);
|
|
2023
|
+
}
|
|
2024
|
+
break;
|
|
2025
|
+
case 'builder.getComponents':
|
|
2026
|
+
(_c = window.parent) === null || _c === void 0 ? void 0 : _c.postMessage({
|
|
2027
|
+
type: 'builder.components',
|
|
2028
|
+
data: Builder.components.map(function (item) { return Builder.prepareComponentSpecToSend(item); }),
|
|
2029
|
+
}, '*');
|
|
2030
|
+
break;
|
|
2031
|
+
case 'builder.editingModel':
|
|
2032
|
+
_this.editingModel = data.data.model;
|
|
2033
|
+
break;
|
|
2034
|
+
case 'builder.registerComponent':
|
|
2035
|
+
var componentData = data.data;
|
|
2036
|
+
Builder.addComponent(componentData);
|
|
2037
|
+
break;
|
|
2038
|
+
case 'builder.blockContentLoading':
|
|
2039
|
+
if (typeof data.data.model === 'string') {
|
|
2040
|
+
_this.blockContentLoading = data.data.model;
|
|
2041
|
+
}
|
|
2042
|
+
break;
|
|
2043
|
+
case 'builder.editingMode':
|
|
2044
|
+
var editingMode = data.data;
|
|
2045
|
+
if (editingMode) {
|
|
2046
|
+
_this.editingMode = true;
|
|
2047
|
+
document.body.classList.add('builder-editing');
|
|
2048
|
+
}
|
|
2049
|
+
else {
|
|
2050
|
+
_this.editingMode = false;
|
|
2051
|
+
document.body.classList.remove('builder-editing');
|
|
2052
|
+
}
|
|
2053
|
+
break;
|
|
2054
|
+
case 'builder.editingPageMode':
|
|
2055
|
+
var editingPageMode = data.data;
|
|
2056
|
+
Builder.editingPage = editingPageMode;
|
|
2057
|
+
break;
|
|
2058
|
+
case 'builder.overrideUserAttributes':
|
|
2059
|
+
var userAttributes = data.data;
|
|
2060
|
+
assign(Builder.overrideUserAttributes, userAttributes);
|
|
2061
|
+
_this.flushGetContentQueue(true);
|
|
2062
|
+
// TODO: refetch too
|
|
2063
|
+
break;
|
|
2064
|
+
case 'builder.overrideTestGroup':
|
|
2065
|
+
var _f = data.data, variationId = _f.variationId, contentId = _f.contentId;
|
|
2066
|
+
if (variationId && contentId) {
|
|
2067
|
+
_this.setTestCookie(contentId, variationId);
|
|
2068
|
+
_this.flushGetContentQueue(true);
|
|
2069
|
+
}
|
|
2070
|
+
break;
|
|
2071
|
+
case 'builder.evaluate': {
|
|
2072
|
+
var text = data.data.text;
|
|
2073
|
+
var args = data.data.arguments || [];
|
|
2074
|
+
var id_1 = data.data.id;
|
|
2075
|
+
// tslint:disable-next-line:no-function-constructor-with-string-args
|
|
2076
|
+
var fn = new Function(text);
|
|
2077
|
+
var result = void 0;
|
|
2078
|
+
var error = null;
|
|
2079
|
+
try {
|
|
2080
|
+
result = fn.apply(_this, args);
|
|
2081
|
+
}
|
|
2082
|
+
catch (err) {
|
|
2083
|
+
error = toError(err);
|
|
2084
|
+
}
|
|
2085
|
+
if (error) {
|
|
2086
|
+
(_d = window.parent) === null || _d === void 0 ? void 0 : _d.postMessage({
|
|
2087
|
+
type: 'builder.evaluateError',
|
|
2088
|
+
data: { id: id_1, error: error.message },
|
|
2089
|
+
}, '*');
|
|
2090
|
+
}
|
|
2091
|
+
else {
|
|
2092
|
+
if (result && typeof result.then === 'function') {
|
|
2093
|
+
result
|
|
2094
|
+
.then(function (finalResult) {
|
|
2095
|
+
var _a;
|
|
2096
|
+
(_a = window.parent) === null || _a === void 0 ? void 0 : _a.postMessage({
|
|
2097
|
+
type: 'builder.evaluateResult',
|
|
2098
|
+
data: { id: id_1, result: finalResult },
|
|
2099
|
+
}, '*');
|
|
2100
|
+
})
|
|
2101
|
+
.catch(console.error);
|
|
2102
|
+
}
|
|
2103
|
+
else {
|
|
2104
|
+
(_e = window.parent) === null || _e === void 0 ? void 0 : _e.postMessage({
|
|
2105
|
+
type: 'builder.evaluateResult',
|
|
2106
|
+
data: { result: result, id: id_1 },
|
|
2107
|
+
}, '*');
|
|
2108
|
+
}
|
|
2109
|
+
}
|
|
2110
|
+
break;
|
|
2111
|
+
}
|
|
2112
|
+
}
|
|
2113
|
+
}
|
|
2114
|
+
});
|
|
2115
|
+
}
|
|
2116
|
+
};
|
|
2117
|
+
Object.defineProperty(Builder.prototype, "defaultCanTrack", {
|
|
2118
|
+
get: function () {
|
|
2119
|
+
return Boolean(Builder.isBrowser &&
|
|
2120
|
+
navigator.userAgent.trim() &&
|
|
2121
|
+
!navigator.userAgent.match(/bot|crawler|spider|robot|crawling|prerender|google|baidu|bing|msn|duckduckbot|teoma|slurp|yandex|phantom|headless|selenium|puppeteer/i) &&
|
|
2122
|
+
!this.browserTrackingDisabled);
|
|
2123
|
+
},
|
|
2124
|
+
enumerable: false,
|
|
2125
|
+
configurable: true
|
|
2126
|
+
});
|
|
2127
|
+
Builder.prototype.init = function (apiKey, canTrack, req, res, authToken, apiVersion) {
|
|
2128
|
+
if (canTrack === void 0) { canTrack = this.defaultCanTrack; }
|
|
2129
|
+
if (req) {
|
|
2130
|
+
this.request = req;
|
|
2131
|
+
}
|
|
2132
|
+
if (res) {
|
|
2133
|
+
this.response = res;
|
|
2134
|
+
}
|
|
2135
|
+
this.canTrack = canTrack;
|
|
2136
|
+
this.apiKey = apiKey;
|
|
2137
|
+
if (authToken) {
|
|
2138
|
+
this.authToken = authToken;
|
|
2139
|
+
}
|
|
2140
|
+
if (apiVersion) {
|
|
2141
|
+
this.apiVersion = apiVersion;
|
|
2142
|
+
}
|
|
2143
|
+
return this;
|
|
2144
|
+
};
|
|
2145
|
+
Object.defineProperty(Builder.prototype, "previewingModel", {
|
|
2146
|
+
get: function () {
|
|
2147
|
+
var search = this.getLocation().search;
|
|
2148
|
+
var params = QueryString.parse((search || '').substr(1));
|
|
2149
|
+
return params['builder.preview'];
|
|
2150
|
+
},
|
|
2151
|
+
enumerable: false,
|
|
2152
|
+
configurable: true
|
|
2153
|
+
});
|
|
2154
|
+
// TODO: allow adding location object as property and/or in constructor
|
|
2155
|
+
Builder.prototype.getLocation = function () {
|
|
2156
|
+
var _a;
|
|
2157
|
+
var parsedLocation = {};
|
|
2158
|
+
// in ssr mode
|
|
2159
|
+
if (this.request) {
|
|
2160
|
+
parsedLocation = parse((_a = this.request.url) !== null && _a !== void 0 ? _a : '');
|
|
2161
|
+
}
|
|
2162
|
+
else if (typeof location === 'object') {
|
|
2163
|
+
// in the browser
|
|
2164
|
+
parsedLocation = parse(location.href);
|
|
2165
|
+
}
|
|
2166
|
+
// IE11 bug with parsed path being empty string
|
|
2167
|
+
// causes issues with our user targeting
|
|
2168
|
+
if (parsedLocation.pathname === '') {
|
|
2169
|
+
parsedLocation.pathname = '/';
|
|
2170
|
+
}
|
|
2171
|
+
return parsedLocation;
|
|
2172
|
+
};
|
|
2173
|
+
Builder.prototype.getUserAttributes = function (userAgent) {
|
|
2174
|
+
if (userAgent === void 0) { userAgent = this.userAgent || ''; }
|
|
2175
|
+
var isMobile = {
|
|
2176
|
+
Android: function () {
|
|
2177
|
+
return userAgent.match(/Android/i);
|
|
2178
|
+
},
|
|
2179
|
+
BlackBerry: function () {
|
|
2180
|
+
return userAgent.match(/BlackBerry/i);
|
|
2181
|
+
},
|
|
2182
|
+
iOS: function () {
|
|
2183
|
+
return userAgent.match(/iPhone|iPod/i);
|
|
2184
|
+
},
|
|
2185
|
+
Opera: function () {
|
|
2186
|
+
return userAgent.match(/Opera Mini/i);
|
|
2187
|
+
},
|
|
2188
|
+
Windows: function () {
|
|
2189
|
+
return userAgent.match(/IEMobile/i) || userAgent.match(/WPDesktop/i);
|
|
2190
|
+
},
|
|
2191
|
+
any: function () {
|
|
2192
|
+
return (isMobile.Android() ||
|
|
2193
|
+
isMobile.BlackBerry() ||
|
|
2194
|
+
isMobile.iOS() ||
|
|
2195
|
+
isMobile.Opera() ||
|
|
2196
|
+
isMobile.Windows());
|
|
2197
|
+
},
|
|
2198
|
+
};
|
|
2199
|
+
var isTablet = userAgent.match(/Tablet|iPad/i);
|
|
2200
|
+
var url = this.getLocation();
|
|
2201
|
+
return __assign({ urlPath: url.pathname, host: url.host || url.hostname,
|
|
2202
|
+
// TODO: maybe an option to choose to target off of mobile/tablet/desktop or just mobile/desktop
|
|
2203
|
+
device: isTablet ? 'tablet' : isMobile.any() ? 'mobile' : 'desktop' }, Builder.overrideUserAttributes);
|
|
2204
|
+
};
|
|
2205
|
+
Builder.prototype.setUserAttributes = function (options) {
|
|
2206
|
+
assign(Builder.overrideUserAttributes, options);
|
|
2207
|
+
this.userAttributesChanged.next(options);
|
|
2208
|
+
};
|
|
2209
|
+
/**
|
|
2210
|
+
* Set user attributes just for tracking purposes.
|
|
2211
|
+
*
|
|
2212
|
+
* Do this so properties exist on event objects for querying insights, but
|
|
2213
|
+
* won't affect targeting
|
|
2214
|
+
*
|
|
2215
|
+
* Use this when you want to track properties but don't need to target off
|
|
2216
|
+
* of them to optimize cache efficiency
|
|
2217
|
+
*/
|
|
2218
|
+
Builder.prototype.setTrackingUserAttributes = function (attributes) {
|
|
2219
|
+
assign(this.trackingUserAttributes, attributes);
|
|
2220
|
+
};
|
|
2221
|
+
Builder.prototype.get = function (modelName, options) {
|
|
2222
|
+
if (options === void 0) { options = {}; }
|
|
2223
|
+
var instance = this;
|
|
2224
|
+
if (!Builder.isBrowser) {
|
|
2225
|
+
instance = new Builder(options.apiKey || this.apiKey, options.req, options.res, undefined, options.authToken || this.authToken, options.apiVersion || this.apiVersion);
|
|
2226
|
+
instance.setUserAttributes(this.getUserAttributes());
|
|
2227
|
+
}
|
|
2228
|
+
else {
|
|
2229
|
+
// NOTE: All these are when .init is not called and the customer
|
|
2230
|
+
// directly calls .get on the singleton instance of Builder
|
|
2231
|
+
if (options.apiKey && !this.apiKey) {
|
|
2232
|
+
this.apiKey = options.apiKey;
|
|
2233
|
+
}
|
|
2234
|
+
if (options.authToken && !this.authToken) {
|
|
2235
|
+
this.authToken = options.authToken;
|
|
2236
|
+
}
|
|
2237
|
+
if (options.apiVersion && !this.apiVersion) {
|
|
2238
|
+
this.apiVersion = options.apiVersion;
|
|
2239
|
+
}
|
|
2240
|
+
}
|
|
2241
|
+
return instance.queueGetContent(modelName, options).map(
|
|
2242
|
+
/* map( */ function (matches) {
|
|
2243
|
+
var match = matches && matches[0];
|
|
2244
|
+
if (Builder.isStatic) {
|
|
2245
|
+
return match;
|
|
2246
|
+
}
|
|
2247
|
+
var matchData = match && match.data;
|
|
2248
|
+
if (!matchData) {
|
|
2249
|
+
return null;
|
|
2250
|
+
}
|
|
2251
|
+
if (typeof matchData.blocksString !== 'undefined') {
|
|
2252
|
+
matchData.blocks = JSON.parse(matchData.blocksString);
|
|
2253
|
+
delete matchData.blocksString;
|
|
2254
|
+
}
|
|
2255
|
+
return {
|
|
2256
|
+
// TODO: add ab test info here and other high level stuff
|
|
2257
|
+
data: matchData,
|
|
2258
|
+
id: match.id,
|
|
2259
|
+
variationId: match.testVariationId || match.variationId || null,
|
|
2260
|
+
testVariationId: match.testVariationId || match.variationId || null,
|
|
2261
|
+
testVariationName: match.testVariationName || null,
|
|
2262
|
+
lastUpdated: match.lastUpdated || null,
|
|
2263
|
+
};
|
|
2264
|
+
});
|
|
2265
|
+
// );
|
|
2266
|
+
};
|
|
2267
|
+
// TODO: entry id in options
|
|
2268
|
+
Builder.prototype.queueGetContent = function (modelName, options) {
|
|
2269
|
+
var _this = this;
|
|
2270
|
+
if (options === void 0) { options = {}; }
|
|
2271
|
+
// TODO: if query do modelName + query
|
|
2272
|
+
var key = options.key ||
|
|
2273
|
+
options.alias ||
|
|
2274
|
+
// TODO: SDKs only pass entry key when given to them, and never when editing...
|
|
2275
|
+
// options.entry ||
|
|
2276
|
+
// TODO: this is ugly - instead of multiple of same model with different options are sent
|
|
2277
|
+
// say requires key/alias. Or if not perhaps make a reliable hash of the options and use that.
|
|
2278
|
+
// TODO: store last user state on last request and if user attributes different now
|
|
2279
|
+
// give a warning that need to use keys to request new contente
|
|
2280
|
+
// (options &&
|
|
2281
|
+
// Object.keys(options).filter(key => key !== 'model').length &&
|
|
2282
|
+
// JSON.stringify({ model: modelName, ...options, initialContent: undefined })) ||
|
|
2283
|
+
modelName;
|
|
2284
|
+
var isEditingThisModel = this.editingModel === modelName;
|
|
2285
|
+
// TODO: include params in this key........
|
|
2286
|
+
var currentObservable = this.observersByKey[key];
|
|
2287
|
+
// if (options.query && options.query._id) {
|
|
2288
|
+
// this.flushGetContentQueue([options])
|
|
2289
|
+
// }
|
|
2290
|
+
if (this.apiKey === 'DEMO' && !this.overrides[key] && !options.initialContent) {
|
|
2291
|
+
options.initialContent = [];
|
|
2292
|
+
}
|
|
2293
|
+
var initialContent = options.initialContent;
|
|
2294
|
+
// TODO: refresh option in options
|
|
2295
|
+
if (currentObservable && (!currentObservable.value || options.cache)) {
|
|
2296
|
+
// TODO: test if this ran, otherwise on 404 some observers may never be called...
|
|
2297
|
+
if (currentObservable.value) {
|
|
2298
|
+
nextTick(function () {
|
|
2299
|
+
// TODO: return a new observable and only that one fires subscribers, don't refire for existing ones
|
|
2300
|
+
currentObservable.next(currentObservable.value);
|
|
2301
|
+
});
|
|
2302
|
+
}
|
|
2303
|
+
return currentObservable;
|
|
2304
|
+
}
|
|
2305
|
+
if (isEditingThisModel) {
|
|
2306
|
+
if (Builder.isBrowser) {
|
|
2307
|
+
parent.postMessage({ type: 'builder.updateContent', data: { options: options } }, '*');
|
|
2308
|
+
}
|
|
2309
|
+
}
|
|
2310
|
+
if (!initialContent /* || isEditingThisModel */) {
|
|
2311
|
+
if (!this.getContentQueue) {
|
|
2312
|
+
this.getContentQueue = [];
|
|
2313
|
+
}
|
|
2314
|
+
this.getContentQueue.push(__assign(__assign({}, options), { model: modelName, key: key }));
|
|
2315
|
+
if (this.getContentQueue && this.getContentQueue.length >= this.contentPerRequest) {
|
|
2316
|
+
var queue_1 = this.getContentQueue.slice();
|
|
2317
|
+
this.getContentQueue = [];
|
|
2318
|
+
nextTick(function () {
|
|
2319
|
+
_this.flushGetContentQueue(false, queue_1);
|
|
2320
|
+
});
|
|
2321
|
+
}
|
|
2322
|
+
else {
|
|
2323
|
+
nextTick(function () {
|
|
2324
|
+
_this.flushGetContentQueue();
|
|
2325
|
+
});
|
|
2326
|
+
}
|
|
2327
|
+
}
|
|
2328
|
+
var observable = new BehaviorSubject(null);
|
|
2329
|
+
this.observersByKey[key] = observable;
|
|
2330
|
+
if (options.noEditorUpdates) {
|
|
2331
|
+
this.noEditorUpdates[key] = true;
|
|
2332
|
+
}
|
|
2333
|
+
if (initialContent) {
|
|
2334
|
+
nextTick(function () {
|
|
2335
|
+
// TODO: need to testModify this I think...?
|
|
2336
|
+
observable.next(initialContent);
|
|
2337
|
+
});
|
|
2338
|
+
}
|
|
2339
|
+
return observable;
|
|
2340
|
+
};
|
|
2341
|
+
// this is needed to satisfy the Angular SDK, which used to rely on the more complex version of `requestUrl`.
|
|
2342
|
+
// even though we only use `fetch()` now, we prefer to keep the old behavior and use the `fetch` that comes from
|
|
2343
|
+
// the core SDK for consistency
|
|
2344
|
+
Builder.prototype.requestUrl = function (url, options) {
|
|
2345
|
+
return getFetch()(url, __assign({ next: __assign({ revalidate: 1 }, options === null || options === void 0 ? void 0 : options.next) }, options)).then(function (res) { return res.json(); });
|
|
2346
|
+
};
|
|
2347
|
+
Object.defineProperty(Builder.prototype, "host", {
|
|
2348
|
+
get: function () {
|
|
2349
|
+
switch (this.env) {
|
|
2350
|
+
case 'qa':
|
|
2351
|
+
return 'https://qa.builder.io';
|
|
2352
|
+
case 'test':
|
|
2353
|
+
return 'https://builder-io-test.web.app';
|
|
2354
|
+
case 'fast':
|
|
2355
|
+
return 'https://fast.builder.io';
|
|
2356
|
+
case 'cloud':
|
|
2357
|
+
return 'https://cloud.builder.io';
|
|
2358
|
+
case 'cdn2':
|
|
2359
|
+
return 'https://cdn2.builder.io';
|
|
2360
|
+
case 'cdn-qa':
|
|
2361
|
+
return 'https://cdn-qa.builder.io';
|
|
2362
|
+
case 'development':
|
|
2363
|
+
case 'dev':
|
|
2364
|
+
return 'http://localhost:5000';
|
|
2365
|
+
case 'cdn-prod':
|
|
2366
|
+
return 'https://cdn.builder.io';
|
|
2367
|
+
default:
|
|
2368
|
+
return Builder.overrideHost || 'https://cdn.builder.io';
|
|
2369
|
+
}
|
|
2370
|
+
},
|
|
2371
|
+
enumerable: false,
|
|
2372
|
+
configurable: true
|
|
2373
|
+
});
|
|
2374
|
+
Builder.prototype.flushGetContentQueue = function (usePastQueue, useQueue) {
|
|
2375
|
+
var _this = this;
|
|
2376
|
+
if (usePastQueue === void 0) { usePastQueue = false; }
|
|
2377
|
+
if (!this.apiKey) {
|
|
2378
|
+
throw new Error("Fetching content failed, expected apiKey to be defined instead got: ".concat(this.apiKey));
|
|
2379
|
+
}
|
|
2380
|
+
if (this.apiVersion) {
|
|
2381
|
+
if (!['v1', 'v3'].includes(this.apiVersion)) {
|
|
2382
|
+
throw new Error("Invalid apiVersion: expected 'v1' or 'v3', received '".concat(this.apiVersion, "'"));
|
|
2383
|
+
}
|
|
2384
|
+
}
|
|
2385
|
+
else {
|
|
2386
|
+
this.apiVersion = DEFAULT_API_VERSION;
|
|
2387
|
+
}
|
|
2388
|
+
if (!usePastQueue && !this.getContentQueue) {
|
|
2389
|
+
return;
|
|
2390
|
+
}
|
|
2391
|
+
var queue = useQueue || (usePastQueue ? this.priorContentQueue : this.getContentQueue) || [];
|
|
2392
|
+
// TODO: do this on every request send?
|
|
2393
|
+
this.getOverridesFromQueryString();
|
|
2394
|
+
var queryParams = __assign(__assign({
|
|
2395
|
+
// TODO: way to force a request to be in a separate queue. or just lower queue limit to be 1 by default
|
|
2396
|
+
omit: queue[0].omit || 'meta.componentsUsed', apiKey: this.apiKey }, queue[0].options), this.queryOptions);
|
|
2397
|
+
if (queue[0].locale) {
|
|
2398
|
+
queryParams.locale = queue[0].locale;
|
|
2399
|
+
}
|
|
2400
|
+
if (queue[0].fields) {
|
|
2401
|
+
queryParams.fields = queue[0].fields;
|
|
2402
|
+
}
|
|
2403
|
+
if (queue[0].format) {
|
|
2404
|
+
queryParams.format = queue[0].format;
|
|
2405
|
+
}
|
|
2406
|
+
var pageQueryParams = typeof location !== 'undefined'
|
|
2407
|
+
? QueryString.parseDeep(location.search.substr(1))
|
|
2408
|
+
: {};
|
|
2409
|
+
var userAttributes =
|
|
2410
|
+
// FIXME: HACK: only checks first in queue for user attributes overrides, should check all
|
|
2411
|
+
// TODO: merge user attributes provided here with defaults and current user attiributes (?)
|
|
2412
|
+
queue && queue[0].userAttributes
|
|
2413
|
+
? queue[0].userAttributes
|
|
2414
|
+
: this.targetContent
|
|
2415
|
+
? this.getUserAttributes()
|
|
2416
|
+
: {
|
|
2417
|
+
urlPath: this.getLocation().pathname,
|
|
2418
|
+
};
|
|
2419
|
+
var fullUrlQueueItem = queue.find(function (item) { return !!item.includeUrl; });
|
|
2420
|
+
if (fullUrlQueueItem) {
|
|
2421
|
+
var location_1 = this.getLocation();
|
|
2422
|
+
if (location_1.origin) {
|
|
2423
|
+
queryParams.url = "".concat(location_1.origin).concat(location_1.pathname).concat(location_1.search);
|
|
2424
|
+
}
|
|
2425
|
+
}
|
|
2426
|
+
var urlQueueItem = useQueue === null || useQueue === void 0 ? void 0 : useQueue.find(function (item) { return item.url; });
|
|
2427
|
+
if (urlQueueItem === null || urlQueueItem === void 0 ? void 0 : urlQueueItem.url) {
|
|
2428
|
+
userAttributes.urlPath = urlQueueItem.url.split('?')[0];
|
|
2429
|
+
}
|
|
2430
|
+
// TODO: merge in the attribute from query string ones
|
|
2431
|
+
// TODO: make this an option per component/request
|
|
2432
|
+
queryParams.userAttributes = userAttributes;
|
|
2433
|
+
if (!usePastQueue && !useQueue) {
|
|
2434
|
+
this.priorContentQueue = queue;
|
|
2435
|
+
this.getContentQueue = null;
|
|
2436
|
+
}
|
|
2437
|
+
var cachebust = this.cachebust ||
|
|
2438
|
+
isIframe ||
|
|
2439
|
+
pageQueryParams.cachebust ||
|
|
2440
|
+
pageQueryParams['builder.cachebust'];
|
|
2441
|
+
if (cachebust || this.env !== 'production') {
|
|
2442
|
+
queryParams.cachebust = true;
|
|
2443
|
+
}
|
|
2444
|
+
if (Builder.isEditing) {
|
|
2445
|
+
queryParams.isEditing = true;
|
|
2446
|
+
}
|
|
2447
|
+
if (this.noCache || this.env !== 'production') {
|
|
2448
|
+
queryParams.noCache = true;
|
|
2449
|
+
}
|
|
2450
|
+
if (size(this.overrides)) {
|
|
2451
|
+
for (var key in this.overrides) {
|
|
2452
|
+
if (this.overrides.hasOwnProperty(key)) {
|
|
2453
|
+
queryParams["overrides.".concat(key)] = this.overrides[key];
|
|
2454
|
+
}
|
|
2455
|
+
}
|
|
2456
|
+
}
|
|
2457
|
+
for (var _i = 0, queue_2 = queue; _i < queue_2.length; _i++) {
|
|
2458
|
+
var options = queue_2[_i];
|
|
2459
|
+
if (options.format) {
|
|
2460
|
+
queryParams.format = options.format;
|
|
2461
|
+
}
|
|
2462
|
+
// TODO: remove me and make permodel
|
|
2463
|
+
if (options.static) {
|
|
2464
|
+
queryParams.static = options.static;
|
|
2465
|
+
}
|
|
2466
|
+
if (options.cachebust) {
|
|
2467
|
+
queryParams.cachebust = options.cachebust;
|
|
2468
|
+
}
|
|
2469
|
+
if (isPositiveNumber(options.cacheSeconds)) {
|
|
2470
|
+
queryParams.cacheSeconds = options.cacheSeconds;
|
|
2471
|
+
}
|
|
2472
|
+
if (isPositiveNumber(options.staleCacheSeconds)) {
|
|
2473
|
+
queryParams.staleCacheSeconds = options.staleCacheSeconds;
|
|
2474
|
+
}
|
|
2475
|
+
var properties = [
|
|
2476
|
+
'prerender',
|
|
2477
|
+
'extractCss',
|
|
2478
|
+
'limit',
|
|
2479
|
+
'offset',
|
|
2480
|
+
'query',
|
|
2481
|
+
'preview',
|
|
2482
|
+
'model',
|
|
2483
|
+
'entry',
|
|
2484
|
+
'rev',
|
|
2485
|
+
'static',
|
|
2486
|
+
];
|
|
2487
|
+
for (var _a = 0, properties_1 = properties; _a < properties_1.length; _a++) {
|
|
2488
|
+
var key = properties_1[_a];
|
|
2489
|
+
var value = options[key];
|
|
2490
|
+
if (value !== undefined) {
|
|
2491
|
+
queryParams.options = queryParams.options || {};
|
|
2492
|
+
queryParams.options[options.key] = queryParams.options[options.key] || {};
|
|
2493
|
+
queryParams.options[options.key][key] = JSON.stringify(value);
|
|
2494
|
+
}
|
|
2495
|
+
}
|
|
2496
|
+
}
|
|
2497
|
+
if (this.preview) {
|
|
2498
|
+
queryParams.preview = 'true';
|
|
2499
|
+
}
|
|
2500
|
+
var hasParams = Object.keys(queryParams).length > 0;
|
|
2501
|
+
// TODO: option to force dev or qa api here
|
|
2502
|
+
var host = this.host;
|
|
2503
|
+
var keyNames = queue.map(function (item) { return encodeURIComponent(item.key); }).join(',');
|
|
2504
|
+
if (this.overrideParams) {
|
|
2505
|
+
var params = omit(QueryString.parse(this.overrideParams), 'apiKey');
|
|
2506
|
+
assign(queryParams, params);
|
|
2507
|
+
}
|
|
2508
|
+
var queryStr = QueryString.stringifyDeep(queryParams);
|
|
2509
|
+
var format = queryParams.format;
|
|
2510
|
+
var requestOptions = { headers: {}, next: { revalidate: 1 } };
|
|
2511
|
+
if (this.authToken) {
|
|
2512
|
+
requestOptions.headers = __assign(__assign({}, requestOptions.headers), { Authorization: "Bearer ".concat(this.authToken) });
|
|
2513
|
+
}
|
|
2514
|
+
var fn = format === 'solid' || format === 'react' ? 'codegen' : 'query';
|
|
2515
|
+
// NOTE: this is a hack to get around the fact that the codegen endpoint is not yet available in v3
|
|
2516
|
+
var apiVersionBasedOnFn = fn === 'query' ? this.apiVersion : 'v1';
|
|
2517
|
+
var url = "".concat(host, "/api/").concat(apiVersionBasedOnFn, "/").concat(fn, "/").concat(this.apiKey, "/").concat(keyNames) +
|
|
2518
|
+
(queryParams && hasParams ? "?".concat(queryStr) : '');
|
|
2519
|
+
var promise = getFetch()(url, requestOptions)
|
|
2520
|
+
.then(function (res) { return res.json(); })
|
|
2521
|
+
.then(function (result) {
|
|
2522
|
+
for (var _i = 0, queue_3 = queue; _i < queue_3.length; _i++) {
|
|
2523
|
+
var options = queue_3[_i];
|
|
2524
|
+
var keyName = options.key;
|
|
2525
|
+
if (options.model === _this.blockContentLoading && !options.noEditorUpdates) {
|
|
2526
|
+
continue;
|
|
2527
|
+
}
|
|
2528
|
+
var isEditingThisModel = _this.editingModel === options.model;
|
|
2529
|
+
if (isEditingThisModel && Builder.isEditing) {
|
|
2530
|
+
parent.postMessage({ type: 'builder.updateContent', data: { options: options } }, '*');
|
|
2531
|
+
// return;
|
|
2532
|
+
}
|
|
2533
|
+
var observer = _this.observersByKey[keyName];
|
|
2534
|
+
if (!observer) {
|
|
2535
|
+
return;
|
|
2536
|
+
}
|
|
2537
|
+
var data = result[keyName];
|
|
2538
|
+
var sorted = data; // sortBy(data, item => item.priority);
|
|
2539
|
+
if (data) {
|
|
2540
|
+
var testModifiedResults = Builder.isServer
|
|
2541
|
+
? sorted
|
|
2542
|
+
: _this.processResultsForTests(sorted);
|
|
2543
|
+
observer.next(testModifiedResults);
|
|
2544
|
+
}
|
|
2545
|
+
else {
|
|
2546
|
+
var search = _this.getLocation().search;
|
|
2547
|
+
if ((search || '').includes('builder.preview=' + options.model)) {
|
|
2548
|
+
var previewData = {
|
|
2549
|
+
id: 'preview',
|
|
2550
|
+
name: 'Preview',
|
|
2551
|
+
data: {},
|
|
2552
|
+
};
|
|
2553
|
+
observer.next([previewData]);
|
|
2554
|
+
}
|
|
2555
|
+
observer.next([]);
|
|
2556
|
+
}
|
|
2557
|
+
}
|
|
2558
|
+
}, function (err) {
|
|
2559
|
+
for (var _i = 0, queue_4 = queue; _i < queue_4.length; _i++) {
|
|
2560
|
+
var options = queue_4[_i];
|
|
2561
|
+
var observer = _this.observersByKey[options.key];
|
|
2562
|
+
if (!observer) {
|
|
2563
|
+
return;
|
|
2564
|
+
}
|
|
2565
|
+
observer.error(err);
|
|
2566
|
+
}
|
|
2567
|
+
});
|
|
2568
|
+
return promise;
|
|
2569
|
+
};
|
|
2570
|
+
Builder.prototype.processResultsForTests = function (results) {
|
|
2571
|
+
var _this = this;
|
|
2572
|
+
var _a;
|
|
2573
|
+
var mappedResults = results.map(function (item) {
|
|
2574
|
+
if (!item.variations) {
|
|
2575
|
+
return item;
|
|
2576
|
+
}
|
|
2577
|
+
var cookieValue = _this.getTestCookie(item.id);
|
|
2578
|
+
var cookieVariation = cookieValue === item.id ? item : item.variations[cookieValue];
|
|
2579
|
+
if (cookieVariation) {
|
|
2580
|
+
return __assign(__assign({}, item), { data: cookieVariation.data, variationId: cookieValue, testVariationId: cookieValue, testVariationName: cookieVariation.name });
|
|
2581
|
+
}
|
|
2582
|
+
if (_this.canTrack && item.variations && size(item.variations)) {
|
|
2583
|
+
var n = 0;
|
|
2584
|
+
var random = Math.random();
|
|
2585
|
+
for (var id in item.variations) {
|
|
2586
|
+
var variation = item.variations[id];
|
|
2587
|
+
var testRatio = variation.testRatio;
|
|
2588
|
+
n += testRatio;
|
|
2589
|
+
if (random < n) {
|
|
2590
|
+
_this.setTestCookie(item.id, variation.id);
|
|
2591
|
+
var variationName = variation.name || (variation.id === item.id ? 'Default variation' : '');
|
|
2592
|
+
return __assign(__assign({}, item), { data: variation.data, variationId: variation.id, testVariationId: variation.id, variationName: variationName, testVariationName: variationName });
|
|
2593
|
+
}
|
|
2594
|
+
}
|
|
2595
|
+
_this.setTestCookie(item.id, item.id);
|
|
2596
|
+
}
|
|
2597
|
+
return __assign(__assign(__assign({}, item), { variationId: item.id }), (item.variations &&
|
|
2598
|
+
size(item.variations) && {
|
|
2599
|
+
testVariationId: item.id,
|
|
2600
|
+
testVariationName: 'Default variation',
|
|
2601
|
+
}));
|
|
2602
|
+
});
|
|
2603
|
+
if (isIframe) {
|
|
2604
|
+
(_a = window.parent) === null || _a === void 0 ? void 0 : _a.postMessage({ type: 'builder.contentResults', data: { results: mappedResults } }, '*');
|
|
2605
|
+
}
|
|
2606
|
+
return mappedResults;
|
|
2607
|
+
};
|
|
2608
|
+
Builder.prototype.getTestCookie = function (contentId) {
|
|
2609
|
+
return this.getCookie("".concat(this.testCookiePrefix, ".").concat(contentId));
|
|
2610
|
+
};
|
|
2611
|
+
Builder.prototype.setTestCookie = function (contentId, variationId) {
|
|
2612
|
+
if (!this.canTrack) {
|
|
2613
|
+
this.cookieQueue.push([contentId, variationId]);
|
|
2614
|
+
return;
|
|
2615
|
+
}
|
|
2616
|
+
// 30 days from now
|
|
2617
|
+
var future = new Date();
|
|
2618
|
+
future.setDate(future.getDate() + 30);
|
|
2619
|
+
return this.setCookie("".concat(this.testCookiePrefix, ".").concat(contentId), variationId, future);
|
|
2620
|
+
};
|
|
2621
|
+
Builder.prototype.getCookie = function (name) {
|
|
2622
|
+
if (this.cookies) {
|
|
2623
|
+
return this.cookies.get(name);
|
|
2624
|
+
}
|
|
2625
|
+
return Builder.isBrowser && getCookie(name);
|
|
2626
|
+
};
|
|
2627
|
+
Builder.prototype.setCookie = function (name, value, expires) {
|
|
2628
|
+
if (this.cookies && !(Builder.isServer && Builder.isStatic)) {
|
|
2629
|
+
return this.cookies.set(name, value, {
|
|
2630
|
+
expires: expires,
|
|
2631
|
+
secure: this.getLocation().protocol === 'https:',
|
|
2632
|
+
});
|
|
2633
|
+
}
|
|
2634
|
+
return Builder.isBrowser && setCookie(name, value, expires);
|
|
2635
|
+
};
|
|
2636
|
+
Builder.prototype.getContent = function (modelName, options) {
|
|
2637
|
+
if (options === void 0) { options = {}; }
|
|
2638
|
+
if (!this.apiKey) {
|
|
2639
|
+
throw new Error("Fetching content from model ".concat(modelName, " failed, expected apiKey to be defined instead got: ").concat(this.apiKey));
|
|
2640
|
+
}
|
|
2641
|
+
return this.queueGetContent(modelName, options);
|
|
2642
|
+
};
|
|
2643
|
+
Builder.prototype.getAll = function (modelName, options) {
|
|
2644
|
+
if (options === void 0) { options = {}; }
|
|
2645
|
+
var instance = this;
|
|
2646
|
+
if (!Builder.isBrowser) {
|
|
2647
|
+
instance = new Builder(options.apiKey || this.apiKey, options.req, options.res, false, null, options.apiVersion || this.apiVersion);
|
|
2648
|
+
instance.setUserAttributes(this.getUserAttributes());
|
|
2649
|
+
}
|
|
2650
|
+
else {
|
|
2651
|
+
// NOTE: All these are when .init is not called and the customer
|
|
2652
|
+
// directly calls .get on the singleton instance of Builder
|
|
2653
|
+
if (options.apiKey && !this.apiKey) {
|
|
2654
|
+
this.apiKey = options.apiKey;
|
|
2655
|
+
}
|
|
2656
|
+
if (options.apiVersion && !this.apiVersion) {
|
|
2657
|
+
this.apiVersion = options.apiVersion;
|
|
2658
|
+
}
|
|
2659
|
+
}
|
|
2660
|
+
return instance
|
|
2661
|
+
.getContent(modelName, __assign(__assign({ limit: 30 }, options), { key: options.key ||
|
|
2662
|
+
// Make the key include all options, so we don't reuse cache for the same content fetched
|
|
2663
|
+
// with different options
|
|
2664
|
+
Builder.isBrowser
|
|
2665
|
+
? "".concat(modelName, ":").concat(hashSum(omit(options, 'initialContent', 'req', 'res')))
|
|
2666
|
+
: undefined }))
|
|
2667
|
+
.promise();
|
|
2668
|
+
};
|
|
2669
|
+
/**
|
|
2670
|
+
* @hidden
|
|
2671
|
+
* @deprecated. This is buggy, and always behind by a version.
|
|
2672
|
+
*/
|
|
2673
|
+
Builder.VERSION = version;
|
|
2674
|
+
Builder.components = [];
|
|
2675
|
+
/**
|
|
2676
|
+
* Makes it so that a/b tests generate code like {@link
|
|
2677
|
+
* https://www.builder.io/blog/high-performance-no-code#__next:~:text=Static%20generated%20A%2FB%20testing}
|
|
2678
|
+
* instead of the old way where we render only one test group at a time on the
|
|
2679
|
+
* server. This is the preferred/better way not and we should ultimately make it
|
|
2680
|
+
* the default
|
|
2681
|
+
*/
|
|
2682
|
+
Builder.isStatic = true;
|
|
2683
|
+
Builder.animator = new Animator();
|
|
2684
|
+
Builder.nextTick = nextTick;
|
|
2685
|
+
Builder.throttle = throttle;
|
|
2686
|
+
Builder.editors = [];
|
|
2687
|
+
Builder.trustedHosts = ['builder.io', 'localhost'];
|
|
2688
|
+
Builder.plugins = [];
|
|
2689
|
+
Builder.actions = [];
|
|
2690
|
+
Builder.registry = {};
|
|
2691
|
+
Builder.registryChange = new BehaviorSubject({});
|
|
2692
|
+
Builder._editingPage = false;
|
|
2693
|
+
Builder.isIframe = isIframe;
|
|
2694
|
+
Builder.isBrowser = isBrowser;
|
|
2695
|
+
Builder.isReactNative = isReactNative;
|
|
2696
|
+
Builder.isServer = !isBrowser && !isReactNative;
|
|
2697
|
+
Builder.previewingModel = Builder.isBrowser && getQueryParam(location.href, 'builder.preview');
|
|
2698
|
+
Builder.settings = {};
|
|
2699
|
+
Builder.settingsChange = new BehaviorSubject({});
|
|
2700
|
+
// TODO: this is quick and dirty, do better implementation later. Also can be unreliable
|
|
2701
|
+
// if page 301s etc. Use a query param instead? also could have issues with redirects. Injecting var could
|
|
2702
|
+
// work but is async...
|
|
2703
|
+
Builder.isEditing = Boolean(isIframe &&
|
|
2704
|
+
((document.referrer && document.referrer.match(/builder\.io|localhost:1234/)) ||
|
|
2705
|
+
location.search.indexOf('builder.frameEditing=') !== -1));
|
|
2706
|
+
Builder.isPreviewing = Boolean(isBrowser &&
|
|
2707
|
+
(location.search.indexOf('builder.preview=') !== -1 ||
|
|
2708
|
+
location.search.indexOf('builder.frameEditing=') !== -1));
|
|
2709
|
+
Builder.isReact = false;
|
|
2710
|
+
Builder.overrideUserAttributes = {};
|
|
2711
|
+
return Builder;
|
|
2712
|
+
}());
|
|
2713
|
+
|
|
2714
|
+
var builder = new Builder(null, undefined, undefined, true);
|
|
2715
|
+
Builder.singletonInstance = builder;
|
|
2716
|
+
|
|
2717
|
+
exports.BehaviorSubject = BehaviorSubject;
|
|
2718
|
+
exports.Builder = Builder;
|
|
2719
|
+
exports.BuilderComponent = BuilderComponent;
|
|
2720
|
+
exports.Subscription = Subscription;
|
|
2721
|
+
exports.builder = builder;
|
|
2722
|
+
exports.isBrowser = isBrowser;
|
|
2723
|
+
|
|
2724
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
2725
|
+
|
|
2726
|
+
}));
|
|
2
2727
|
//# sourceMappingURL=index.browser.js.map
|