@causalfoundry/js-sdk
Version:
Causal Foundry WEB SDK (JS/TS)
1 lines • 160 kB
JavaScript
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.init=t():e.init=t()}(this,()=>(()=>{var e={7:e=>{"use strict";var t,n="object"==typeof Reflect?Reflect:null,r=n&&"function"==typeof n.apply?n.apply:function(e,t,n){return Function.prototype.apply.call(e,t,n)};t=n&&"function"==typeof n.ownKeys?n.ownKeys:Object.getOwnPropertySymbols?function(e){return Object.getOwnPropertyNames(e).concat(Object.getOwnPropertySymbols(e))}:function(e){return Object.getOwnPropertyNames(e)};var i=Number.isNaN||function(e){return e!=e};function o(){o.init.call(this)}e.exports=o,e.exports.once=function(e,t){return new Promise(function(n,r){function i(n){e.removeListener(t,o),r(n)}function o(){"function"==typeof e.removeListener&&e.removeListener("error",i),n([].slice.call(arguments))}g(e,t,o,{once:!0}),"error"!==t&&function(e,t){"function"==typeof e.on&&g(e,"error",t,{once:!0})}(e,i)})},o.EventEmitter=o,o.prototype._events=void 0,o.prototype._eventsCount=0,o.prototype._maxListeners=void 0;var a=10;function s(e){if("function"!=typeof e)throw new TypeError('The "listener" argument must be of type Function. Received type '+typeof e)}function c(e){return void 0===e._maxListeners?o.defaultMaxListeners:e._maxListeners}function u(e,t,n,r){var i,o,a,u;if(s(n),void 0===(o=e._events)?(o=e._events=Object.create(null),e._eventsCount=0):(void 0!==o.newListener&&(e.emit("newListener",t,n.listener?n.listener:n),o=e._events),a=o[t]),void 0===a)a=o[t]=n,++e._eventsCount;else if("function"==typeof a?a=o[t]=r?[n,a]:[a,n]:r?a.unshift(n):a.push(n),(i=c(e))>0&&a.length>i&&!a.warned){a.warned=!0;var d=new Error("Possible EventEmitter memory leak detected. "+a.length+" "+String(t)+" listeners added. Use emitter.setMaxListeners() to increase limit");d.name="MaxListenersExceededWarning",d.emitter=e,d.type=t,d.count=a.length,u=d,console&&console.warn&&console.warn(u)}return e}function d(){if(!this.fired)return this.target.removeListener(this.type,this.wrapFn),this.fired=!0,0===arguments.length?this.listener.call(this.target):this.listener.apply(this.target,arguments)}function l(e,t,n){var r={fired:!1,wrapFn:void 0,target:e,type:t,listener:n},i=d.bind(r);return i.listener=n,r.wrapFn=i,i}function p(e,t,n){var r=e._events;if(void 0===r)return[];var i=r[t];return void 0===i?[]:"function"==typeof i?n?[i.listener||i]:[i]:n?function(e){for(var t=new Array(e.length),n=0;n<t.length;++n)t[n]=e[n].listener||e[n];return t}(i):m(i,i.length)}function h(e){var t=this._events;if(void 0!==t){var n=t[e];if("function"==typeof n)return 1;if(void 0!==n)return n.length}return 0}function m(e,t){for(var n=new Array(t),r=0;r<t;++r)n[r]=e[r];return n}function g(e,t,n,r){if("function"==typeof e.on)r.once?e.once(t,n):e.on(t,n);else{if("function"!=typeof e.addEventListener)throw new TypeError('The "emitter" argument must be of type EventEmitter. Received type '+typeof e);e.addEventListener(t,function i(o){r.once&&e.removeEventListener(t,i),n(o)})}}Object.defineProperty(o,"defaultMaxListeners",{enumerable:!0,get:function(){return a},set:function(e){if("number"!=typeof e||e<0||i(e))throw new RangeError('The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received '+e+".");a=e}}),o.init=function(){void 0!==this._events&&this._events!==Object.getPrototypeOf(this)._events||(this._events=Object.create(null),this._eventsCount=0),this._maxListeners=this._maxListeners||void 0},o.prototype.setMaxListeners=function(e){if("number"!=typeof e||e<0||i(e))throw new RangeError('The value of "n" is out of range. It must be a non-negative number. Received '+e+".");return this._maxListeners=e,this},o.prototype.getMaxListeners=function(){return c(this)},o.prototype.emit=function(e){for(var t=[],n=1;n<arguments.length;n++)t.push(arguments[n]);var i="error"===e,o=this._events;if(void 0!==o)i=i&&void 0===o.error;else if(!i)return!1;if(i){var a;if(t.length>0&&(a=t[0]),a instanceof Error)throw a;var s=new Error("Unhandled error."+(a?" ("+a.message+")":""));throw s.context=a,s}var c=o[e];if(void 0===c)return!1;if("function"==typeof c)r(c,this,t);else{var u=c.length,d=m(c,u);for(n=0;n<u;++n)r(d[n],this,t)}return!0},o.prototype.addListener=function(e,t){return u(this,e,t,!1)},o.prototype.on=o.prototype.addListener,o.prototype.prependListener=function(e,t){return u(this,e,t,!0)},o.prototype.once=function(e,t){return s(t),this.on(e,l(this,e,t)),this},o.prototype.prependOnceListener=function(e,t){return s(t),this.prependListener(e,l(this,e,t)),this},o.prototype.removeListener=function(e,t){var n,r,i,o,a;if(s(t),void 0===(r=this._events))return this;if(void 0===(n=r[e]))return this;if(n===t||n.listener===t)0===--this._eventsCount?this._events=Object.create(null):(delete r[e],r.removeListener&&this.emit("removeListener",e,n.listener||t));else if("function"!=typeof n){for(i=-1,o=n.length-1;o>=0;o--)if(n[o]===t||n[o].listener===t){a=n[o].listener,i=o;break}if(i<0)return this;0===i?n.shift():function(e,t){for(;t+1<e.length;t++)e[t]=e[t+1];e.pop()}(n,i),1===n.length&&(r[e]=n[0]),void 0!==r.removeListener&&this.emit("removeListener",e,a||t)}return this},o.prototype.off=o.prototype.removeListener,o.prototype.removeAllListeners=function(e){var t,n,r;if(void 0===(n=this._events))return this;if(void 0===n.removeListener)return 0===arguments.length?(this._events=Object.create(null),this._eventsCount=0):void 0!==n[e]&&(0===--this._eventsCount?this._events=Object.create(null):delete n[e]),this;if(0===arguments.length){var i,o=Object.keys(n);for(r=0;r<o.length;++r)"removeListener"!==(i=o[r])&&this.removeAllListeners(i);return this.removeAllListeners("removeListener"),this._events=Object.create(null),this._eventsCount=0,this}if("function"==typeof(t=n[e]))this.removeListener(e,t);else if(void 0!==t)for(r=t.length-1;r>=0;r--)this.removeListener(e,t[r]);return this},o.prototype.listeners=function(e){return p(this,e,!0)},o.prototype.rawListeners=function(e){return p(this,e,!1)},o.listenerCount=function(e,t){return"function"==typeof e.listenerCount?e.listenerCount(t):h.call(e,t)},o.prototype.listenerCount=h,o.prototype.eventNames=function(){return this._eventsCount>0?t(this._events):[]}},12:e=>{"use strict";e.exports=function(e,t){return function(){for(var n=new Array(arguments.length),r=0;r<n.length;r++)n[r]=arguments[r];return e.apply(t,n)}}},15:(e,t,n)=>{"use strict";var r=n(516),i=n(12),o=n(155),a=n(343);function s(e){var t=new o(e),n=i(o.prototype.request,t);return r.extend(n,o.prototype,t),r.extend(n,t),n}var c=s(n(987));c.Axios=o,c.create=function(e){return s(a(c.defaults,e))},c.Cancel=n(928),c.CancelToken=n(191),c.isCancel=n(864),c.all=function(e){return Promise.all(e)},c.spread=n(980),c.isAxiosError=n(19),e.exports=c,e.exports.default=c},18:(e,t,n)=>{"use strict";var r=n(516);e.exports=function(e,t){r.forEach(e,function(n,r){r!==t&&r.toUpperCase()===t.toUpperCase()&&(e[t]=n,delete e[r])})}},19:e=>{"use strict";e.exports=function(e){return"object"==typeof e&&!0===e.isAxiosError}},106:(e,t,n)=>{"use strict";var r=n(516);function i(e){return encodeURIComponent(e).replace(/%3A/gi,":").replace(/%24/g,"$").replace(/%2C/gi,",").replace(/%20/g,"+").replace(/%5B/gi,"[").replace(/%5D/gi,"]")}e.exports=function(e,t,n){if(!t)return e;var o;if(n)o=n(t);else if(r.isURLSearchParams(t))o=t.toString();else{var a=[];r.forEach(t,function(e,t){null!=e&&(r.isArray(e)?t+="[]":e=[e],r.forEach(e,function(e){r.isDate(e)?e=e.toISOString():r.isObject(e)&&(e=JSON.stringify(e)),a.push(i(t)+"="+i(e))}))}),o=a.join("&")}if(o){var s=e.indexOf("#");-1!==s&&(e=e.slice(0,s)),e+=(-1===e.indexOf("?")?"?":"&")+o}return e}},137:e=>{"use strict";e.exports=function(e){return/^([a-z][a-z\d\+\-\.]*:)?\/\//i.test(e)}},149:(e,t,n)=>{"use strict";n.d(t,{CallCenter:()=>_o,CfLog:()=>be,ECommerce:()=>so,ELearning:()=>uo,EmergencyMgmt:()=>Eo,Loyalty:()=>go,Navigation:()=>U,PatientMgmt:()=>po,Payments:()=>yo});var r=n(7),i=n(780);let o=function(e){return e[e.Log=0]="Log",e[e.Info=1]="Info",e[e.Warn=2]="Warn",e[e.Error=3]="Error",e}({});function a(e){return function(t,n){if(e){let e;switch(t){default:e=console.log;break;case o.Info:e=console.info;break;case o.Warn:e=console.warn;break;case o.Error:e=console.error}e(n)}}}let s=function(e){return e.Impression="impression",e}({});const c=e=>{const t=e=>("0"+e).slice(-2);let n=e.getTimezoneOffset();const r=n>0?"-":"+";return n=Math.abs(n),e.getFullYear()+"-"+t(e.getMonth()+1)+"-"+t(e.getDate())+"T"+t(e.getHours())+":"+t(e.getMinutes())+":"+t(e.getSeconds())+"."+("00"+e.getMilliseconds()).slice(-3)+r+t(n/60|0)+":"+t(n%60)},u=e=>{const t=28===e.length||29===e.length,n="string"==typeof e,r=!isNaN(new Date(e).getTime());return t&&n&&r},d=(e,t)=>{for(const n of t)if(Array.isArray(e[n])){if(e[n].length>0&&e[n].some(e=>"string"==typeof e&&0===e.trim().length))throw new Error(`non empty strings in ${n} are mandatory`)}else if("string"==typeof e[n]&&0===e[n].trim().length)throw new Error(`non empty ${n} are mandatory`)};class l{throwAndLogError(e,t){const n=new Error(t),r={title:t,event_type:e,exception_type:n.name,exception_source:"JS-SDK",stack_trace:n.stack||"no stack",ts:c(new Date)};throw x("exception",e,r,!1,""),n}throwAPIError(e,t){const n=new Error(t),r={title:t,event_type:e,exception_type:n.name,exception_source:"JS-SDK",stack_trace:n.stack||"no stack",ts:c(new Date)};x("exception",e,r,!1,"")}throwNudgeFetchError(e,t){const n=new Error(t),r={title:t,event_type:e,exception_type:n.name,exception_source:"JS-SDK",stack_trace:n.stack||"no stack",ts:c(new Date)};x("exception",e,r,!1,"")}}var p,h=n(552),m=new Uint8Array(16);function g(){if(!p&&!(p="undefined"!=typeof crypto&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto)||"undefined"!=typeof msCrypto&&"function"==typeof msCrypto.getRandomValues&&msCrypto.getRandomValues.bind(msCrypto)))throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return p(m)}const f=/^(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|00000000-0000-0000-0000-000000000000)$/i;for(var y=[],v=0;v<256;++v)y.push((v+256).toString(16).substr(1));const _=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,n=(y[e[t+0]]+y[e[t+1]]+y[e[t+2]]+y[e[t+3]]+"-"+y[e[t+4]]+y[e[t+5]]+"-"+y[e[t+6]]+y[e[t+7]]+"-"+y[e[t+8]]+y[e[t+9]]+"-"+y[e[t+10]]+y[e[t+11]]+y[e[t+12]]+y[e[t+13]]+y[e[t+14]]+y[e[t+15]]).toLowerCase();if(!function(e){return"string"==typeof e&&f.test(e)}(n))throw TypeError("Stringified UUID is invalid");return n},w=function(e,t,n){var r=(e=e||{}).random||(e.rng||g)();if(r[6]=15&r[6]|64,r[8]=63&r[8]|128,t){n=n||0;for(var i=0;i<16;++i)t[n+i]=r[i];return t}return _(r)},E=("object"==typeof navigator&&navigator.userAgent&&navigator.userAgent.includes("jsdom"),"object"==typeof process&&!!process.versions&&process.versions.node,"object"==typeof window&&"object"==typeof document&&9===document.nodeType),b="visible",k="CFUserIdStorageKey";let T=!1;function A(){if(E){return localStorage.getItem(k)||""}return""}function S(){if(!E)return`${(0,h.platform)()} -|- ${(0,h.release)()}`;if(!window?.navigator)return"";const e=window.navigator.userAgentData?.platform,t=window.navigator.platform,n=window.navigator?.userAgent||";";return`${e||t} -|- ${n?.match(/(([^)]+))/)?.[1].split(";")[1].trim()}`}class C{impressionsDetectors={};user_id="";constructor(e,t,n,r,i,o){this.sender=e,this.impressionDetectorClass=t,this.deviceId=i,this.defaultBlock=r,this.debug=a(n),this.isUsingAsInternalWrapper=o}static createInstance(e,t,n,r,i,o){return C.instance||(C.instance=new C(e,t,n,r,i,o)),C.instance}static getInstance(){return C.instance||(new l).throwAndLogError("CfLog","CfLog instance not created"),C.instance}login(e){this.user_id=e}resolveModule(e){return e===i.ContentBlock.Core?this.currentBlock?this.currentBlock:this.defaultBlock:e}resolveUserId(e,t,n){return e&&0!==e.length?e:t||A()||n}async trackEvent(e,t,n,r){const i={...e,time:r||(new Date).toISOString()};i.ctx=i.ctx||{},i.ctx.__ol=!E||!("undefined"!=typeof window&&void 0!==window.navigator&&!window.navigator.onLine),this.sender.add(this.resolveUserId(t,this.user_id,this.deviceId),this.deviceId,i,n,this.isUsingAsInternalWrapper)}async trackCatalog(e){this.sender.addCatalogItem(e)}startTrackingImpressions(e,t,n){this.impressionsDetectors[t]=new this.impressionDetectorClass({intersectionThreshold:.5}),this.impressionsDetectors[t].on(s.Impression,e),this.impressionsDetectors[t].start(t,n,{})}stopTrackingImpressions(e){e?this.impressionsDetectors[e]&&this.impressionsDetectors[e].stop():Object.values(this.impressionsDetectors).forEach(e=>e.stop())}restartTrackingImpressions(e){if(!e||!this.impressionsDetectors[e])throw console.error("Impossible to restart impression to unknown containerClassname"),new Error("unknown-container");this.impressionsDetectors[e].restart({})}setCurrentBlock(e){setTimeout(()=>{this.currentBlock=e},15)}}function I(){return C.getInstance()}function L(e){return JSON.parse(JSON.stringify(e))}function N(e){const t={};for(const[n,r]of Object.entries(e)){const e=D(n);if(null!=r)if("string"==typeof r)""!==r&&(t[e]=r);else if(["number","boolean"].includes(typeof r))t[e]=r;else if(Array.isArray(r)){const n=r.filter(e=>null!=e).join(", ");""!==n&&(t[e]=n)}else if("object"==typeof r){const e=N(r);Object.assign(t,e)}else t[e]=String(r)}return t}function P(e){const t={};for(const[n,r]of Object.entries(e)){const e=D(n);if(null!=r)if("string"==typeof r)""!==r&&(t[e]=r);else if(["number","boolean"].includes(typeof r)){const n=String(r);""!==n&&(t[e]=n)}else if(Array.isArray(r)){const n=r.filter(e=>null!=e).map(e=>String(e)).join(", ");""!==n&&(t[e]=n)}else if("object"==typeof r){const e=P(r);Object.assign(t,e)}else{const n=String(r);""!==n&&(t[e]=n)}}return t}const O=e=>P(e?L(e):{}),M=e=>N(e?L(e):{}),D=e=>e.trim().replace(/\s+/g,"_").toLowerCase(),x=(e,t,n,r=!1,i="",o)=>{const a=I(),s={name:e,property:t,ctx:M(n)};a.trackEvent(s,i,r,o)},z=(e,t,n)=>{const r=I(),i={id:e,type:t,kv:O(n)};r.trackCatalog(i)};let R=function(e){return e.Identify="identify",e.Page="page",e.App="app",e.Search="search",e.Media="media",e.ActionResponse="action_response",e.Rate="rate",e.ModuleSelection="module_selection",e.Item="item",e.Delivery="delivery",e.Checkout="checkout",e.Cart="cart",e.CancelCheckout="cancel_checkout",e.ItemReport="item_report",e.ItemRequest="item_request",e.Module="module",e.Exam="exam",e.Question="question",e.Level="level",e.Milestone="milestone",e.Promo="promo",e.Survey="survey",e.Reward="reward",e.Payment="payment",e.Patient="patient",e.Encounter="encounter",e.Appointment="appointment",e.Diagnosis="diagnosis",e}({});async function B(e,t){if(""==e)return void(new l).throwAndLogError("user catalog","invalid user id");const n=(new Date).getTimezoneOffset();t.timezone=(e=>{const t=e=>e<10?`0${e}`:`${e}`;return`${e>0?"-":"+"}${t(Math.floor(Math.abs(e)/60))}:${t(Math.abs(e)%60)}`})(n),null!=t.birth_year&&(t.birth_year<1900||t.birth_year>(new Date).getFullYear())?(new l).throwAndLogError("user catalog","invalid user birth_year"):z(e,i.CoreCatalogType.User,t)}async function j(e,t){""!=e?(d(t,["country"]),z(e,i.CoreCatalogType.Site,t)):(new l).throwAndLogError("site catalog","invalid site id")}const U={logIdentifyEvent:(e,t=!1,n)=>{x(i.NavigationTypes.Identify,e.action,e,t,"",n)},logIngestEvent:(e,t,n=!1,r)=>{let o,a=!0;switch(e){case i.NavigationTypes.App:a=null!=t.action||((new l).throwAndLogError(i.NavigationTypes.App,"app action is required"),!1),a&&(o=t.action);break;case i.NavigationTypes.Page:a=(e=>void 0!==e.duration&&e.duration>=0)(t),a&&(o=t.title);break;case i.NavigationTypes.Media:a=(e=>(e.seek_time=e.type===i.MediaType.Image?0:e.seek_time,""==e.id?((new l).throwAndLogError(i.NavigationTypes.Media,"empty media id"),!1):null==e.type?((new l).throwAndLogError(i.NavigationTypes.Media,"media type is required"),!1):null==e.action?((new l).throwAndLogError(i.NavigationTypes.Media,"media action is required"),!1):!(e.seek_time&&e.seek_time<0&&((new l).throwAndLogError(i.NavigationTypes.Media,"negative media seek time"),1))))(t),a&&(o=t.type);break;case i.NavigationTypes.Search:{const e=t;a=(e=>e.page<0?((new l).throwAndLogError(i.NavigationTypes.Search,"negative search page"),!1):(0!==e.results_list.length&&e.results_list.every(e=>{if(""==e)return(new l).throwAndLogError(i.NavigationTypes.Search,"empty search result item id"),!1}),!0))(e),a&&(o=e.query,Array.isArray(e.results_list)?t.results_list=[...new Set(e.results_list)]:t.results_list=[]);break}case i.NavigationTypes.Rate:a=(e=>e.rate_value<0?((new l).throwAndLogError(i.NavigationTypes.Rate,"negative rate value"),!1):e.rate_value<0||e.rate_value>5?((new l).throwAndLogError(i.NavigationTypes.Rate,"invalid rate range 0-5"),!1):null==e.type?((new l).throwAndLogError(i.NavigationTypes.Rate,"rate type is required"),!1):null!=e.subject_id&&""!=e.subject_id||((new l).throwAndLogError(i.NavigationTypes.Rate,"rate subject id is required"),!1))(t),a&&(o=t.type);break;case i.NavigationTypes.Track:a=(e=>{const t=D(e.name);return e.name&&""!==e.name.trim()?!new Set(Object.values(R)).has(t)||((new l).throwAndLogError(i.NavigationTypes.Track,`The event name "${e.name}" is reserved and cannot be used.`),!1):((new l).throwAndLogError(i.NavigationTypes.Track,"name for track event is required"),!1)})(t),a&&(e=D(t.name),o=t.property,t=t.meta);break;case i.NavigationTypes.ModuleSelection:a=(e=>!!e.type||((new l).throwAndLogError(i.NavigationTypes.ModuleSelection,"module type is required"),!1))(t),a&&(o=t.type)}a&&(e===i.NavigationTypes.Media&&t.type===i.MediaType.Image&&(t.seek_time=0),x(e,o,t,n,"",r))},logCatalogEvent:(e,t,n)=>{switch(t){case i.CoreCatalogType.User:B(e,n);break;case i.CoreCatalogType.Site:j(e,n);break;case i.CoreCatalogType.Media:!async function(e,t){""==e?(new l).throwAndLogError("media catalog","invalid media item id"):null==t.type&&(new l).throwAndLogError("media catalog","invalid media type"),d(t,["type"]),z(e,i.CoreCatalogType.Media,t)}(e,n);case i.CoreCatalogType.Other:}},logPushNotificationEvent:(e,t=!0,n)=>{x(i.NavigationTypes.ActionResponse,e.response,e,t,"",n)},logSearchEvent:(e,t,n=!1)=>{const r={query:(o=e).query,module:o.module||i.SearchModuleType.Core,results_list:o.results_list?.map(e=>e.id)||[],filter:o.filter,page:o.page,meta:o.meta};var o;return U.logIngestEvent(i.NavigationTypes.Search,r,n),"no-search-id"}};class ${flushing=!1;flushIntervalId=0;exceptionsEndPoint="/ingest/sdk/crash";userId="";deviceId="";usingAsInternalWrapper=!1;constructor(e,t){if(this.queue=[],this.catalogQueue=[],this.cfNetwork=e,this.options=t,this.debug=a(this.options.debug),this.options.flushInterval<1e3&&(this.options.flushInterval=1e3),this.options.cacheEventsInLocalstorage&&"undefined"!=typeof Storage)try{this.queue=JSON.parse(localStorage.getItem(this.options.cacheEventsKey)||"[]"),this.catalogQueue=JSON.parse(localStorage.getItem(this.options.cacheCatalogKey)||"[]")}catch(e){this.debug(o.Error,`Error getting queue items from cache ${e.message||""}`)}this.endpointURL=`${this.options.baseUrl}${this.options.ingestPath}`,this.catalogEndpointURL=`${this.options.baseUrl}${this.options.dimensionPath}`,this.updateQueueCache(),this.flushIntervalId=+setInterval(()=>{this.flush()},this.options.flushInterval)}flush(){if(this.options.pauseSDK)return;const e=[...this.queue],t=[...this.catalogQueue];if(0===e.length||0===t.length)return void this.debug(o.Log,"Skip sending empty list of logs ");const n=e.map(e=>e.uuid),r=e.map(e=>e.event),i=t.map(e=>e.uuid),a=t.map(e=>e.catalog);this.flushing=!0,this.send(r,n),this.sendCatalog(a,i)}add(e,t,n,r=!1,i=!1){if(this.options.pauseSDK)return;const o={uuid:w(),event:n,time:+new Date,retries:0};this.userId=e,this.deviceId=t,this.usingAsInternalWrapper=i,this.queue.some(e=>e.event===o.event)||(this.queue.push(o),this.updateQueueCache(),r&&this.send([o.event],[o.uuid]))}addCatalogItem(e,t=!1){if(this.options.pauseSDK)return;const n={uuid:w(),catalog:e,retries:0};this.usingAsInternalWrapper=t,this.catalogQueue.some(e=>e.catalog===n.catalog)||(this.catalogQueue.push(n),this.updateCatalogQueueCache())}removeQueueItemsExceedMaxRetries(){this.queue=this.queue.filter(e=>e.retries<=this.options.flushMaxRetries),this.updateQueueCache()}removeQueueCatalogItemsExceedMaxRetries(){this.catalogQueue=this.catalogQueue.filter(e=>e.retries<=this.options.flushMaxRetries),this.updateCatalogQueueCache()}removeFromQueue(e){this.queue=this.queue.filter(t=>-1===e.indexOf(t.uuid)),this.updateQueueCache()}removeFromCatalogQueue(e){this.catalogQueue=this.catalogQueue.filter(t=>-1===e.indexOf(t.uuid)),this.updateCatalogQueueCache()}removeIndexFromQueue(e){this.queue.splice(e,1),this.updateQueueCache()}removeIndexFromCatalogQueue(e){this.catalogQueue.splice(e,1),this.updateCatalogQueueCache()}updateQueueCache(){this.options.cacheEventsInLocalstorage&&"undefined"!=typeof Storage&&localStorage.setItem(this.options.cacheEventsKey,JSON.stringify(this.queue))}updateCatalogQueueCache(){this.options.cacheEventsInLocalstorage&&"undefined"!=typeof Storage&&localStorage.setItem(this.options.cacheCatalogKey,JSON.stringify(this.catalogQueue))}addRetries(e){const t=+new Date;this.queue.filter(t=>-1!==e.indexOf(t.uuid)).forEach(e=>{e.retries=+e.retries+1,e.lastRetry=t}),this.updateQueueCache()}addCatalogRetries(e){const t=+new Date;this.catalogQueue.filter(t=>-1!==e.indexOf(t.uuid)).forEach(e=>{e.retries=+e.retries+1,e.lastRetry=t}),this.updateCatalogQueueCache()}send(e,t){if(this.options.pauseSDK)return;const n=(e=>{const t=new Set;return e.filter(e=>{const n=(e=>JSON.stringify(e))(e);return!t.has(n)&&(t.add(n),!0)})})(e),r={s_id:this.generateSessionID(this.userId),sdk:"js/0.9.12",app_id:E&&document?.location.host||"NO_URL_FOUND",app_version:E&&window?.navigator&&""!==window.navigator.userAgent?function(){const e=navigator.userAgent;let t,n=e.match(/(opera|chrome|safari|firefox|msie|trident(?=\/))\/?\s*(\d+)/i)||[];return/trident/i.test(n[1])?(t=/\brv[ :]+(\d+)/g.exec(e)||[],"IE "+(t[1]||"")):"Chrome"===n[1]&&(t=e.match(/\b(OPR|Edge)\/(\d+)/),null!=t)?t.slice(1).join(" ").replace("OPR","Opera"):(n=n[2]?[n[1],n[2]]:[navigator.appName,navigator.appVersion,"-?"],null!=(t=e.match(/version\/(\d+)/i))&&n.splice(1,1,t[1]),n.join(" "))}()||"0":"NO_BROWSER",device_id:this.deviceId,device_os:S()};return this.cfNetwork.send(this.endpointURL,{data:n,internal:r,id:this.userId}).then(()=>{this.debug(o.Info,`Flushed ${n.length} events`),this.removeFromQueue(t)}).catch(e=>{e.response.data.data&&this.removeIndexFromQueue(Number(e.response.data.data)),this.addRetries(t),this.debug(o.Error,e.message||"")}).finally(()=>{this.flushing=!1,this.removeQueueItemsExceedMaxRetries()})}sendCatalog(e,t){if(this.options.pauseSDK)return;const n=(e=>{const t=new Set;return e.filter(e=>{const n=(e=>JSON.stringify(e))(e);return!t.has(n)&&(t.add(n),!0)})})(e);return this.cfNetwork.send(this.catalogEndpointURL,{data:n}).then(()=>{this.debug(o.Info,`Flushed ${n.length} events`),this.removeFromCatalogQueue(t)}).catch(e=>{e.response.data.data&&this.removeIndexFromCatalogQueue(Number(e.response.data.data)),this.addCatalogRetries(t),this.debug(o.Error,e.message||"")}).finally(()=>{this.flushing=!1,this.removeQueueCatalogItemsExceedMaxRetries()})}generateSessionID(e){return`${e}_${Date.now()}`}checkDefaultNetworkValue(e){return this.usingAsInternalWrapper?this.getRandomNumberValue(100,1024):e}getRandomNumberValue(e,t){return Math.floor(Math.random()*(t-e)+e)}}let F=null,Z="",q="",G=0;const K=()=>{H(Z,q);const e={action:i.AppAction.Background,start_time:0};U.logIngestEvent(i.NavigationTypes.App,e)},V=()=>{F=new Date;const e={action:i.AppAction.Resume,start_time:0};U.logIngestEvent(i.NavigationTypes.App,e)},H=(e,t)=>{const n=Date.now(),r=Math.round((n-F)/1e3);let o=0;const a=performance.getEntriesByType("navigation"),s=Math.round(void 0===a[0]?0:a[0].duration);G!=s?(o=G=s,o>3e4&&(o=0)):o=0;const c={path:e,title:t,duration:r,render_time:o};F=n,U.logIngestEvent(i.NavigationTypes.Page,c)},W=e=>{if(!E)return;let t="";var n,r;(()=>{F=new Date,Z=window.location.href,q=document.title;const e=performance.getEntriesByType("navigation");let t=Math.round(void 0===e[0]?0:e[0].duration);t>3e4&&(t=0);const n={action:i.AppAction.Open,start_time:t};U.logIngestEvent(i.NavigationTypes.App,n)})(),window.addEventListener("unload",()=>{}),n=V,r=K,document.visibilityState===b&&(T=!0),document.addEventListener("visibilitychange",e=>{if(console.warn("[event] [visibilitychange] ",document.visibilityState),document.visibilityState===b)T=!0,n();else if("hidden"===document.visibilityState){if(!T)return;r()}}),function(e){!function(e){const t=window.history.pushState,n=window.history.replaceState;window.history.pushState=function(n,r,i){let o=i||"";return"/"!=o[0]&&(o=`/${o}`),e(`${window.location.origin}${o}`),t.call(window.history,n,r,i)},window.history.replaceState=function(t,r,i){let o=i||"";return"/"!=o[0]&&(o=`/${o}`),e(`${window.location.origin}${o}`),n.call(window.history,t,r,i)},window.addEventListener("popstate",function(t){e(t.target.location.href)})}(t=>{setTimeout(()=>{e(t,document.title)},10)})}((e,n)=>{t="",H(Z,q),Z=e,q=n})};let Q=function(e){return e.Shown="shown",e.Error="error",e.Block="block",e.Discard="discard",e.Open="open",e.Expired="expired",e}({}),J=function(e){return e.Shown="shown",e.Error="error",e.Block="block",e.Discard="discard",e.Open="open",e.Expired="expired",e}({}),Y=function(e){return e.Shown="shown",e.Error="error",e.Block="block",e.Discard="discard",e.Open="open",e.Expired="expired",e.Action="action",e}({});var X=n(889);class ee extends r.EventEmitter{timersId=[];refreshInterval=3e5;isOneTimeOnly=!1;nudgeScreenType=X.NudgeScreenType.None;indexedNudges={};constructor(e,t,n,r=X.NudgeScreenType.None,i=!1,o=3e5){super(),this.notificationDispatcher=t,this.nudgesRepository=n,this.refreshInterval=o,this.nudgeScreenType=r,this.isOneTimeOnly=i,this.notificationDispatcher.on(J.Open,e=>{if(!e)return;if(U.logPushNotificationEvent({response:Q.Open,details:"",internal:e.internal}),!e.attr?.cta_id)return;const t={type:e.attr?.cta_type.toLowerCase(),cta_resource:{type:"drug",id:e.attr?.cta_id}};this.emit(Y.Action,t)}),this.notificationDispatcher.on(J.Discard,e=>{e&&U.logPushNotificationEvent({response:Q.Discard,details:"",internal:e.internal})}),this.notificationDispatcher.on(J.Block,e=>{e&&U.logPushNotificationEvent({response:Q.Block,details:"",internal:e.internal})}),this.notificationDispatcher.on(J.Shown,e=>{e&&U.logPushNotificationEvent({response:Q.Shown,details:"",internal:e.internal})}),this.fetchNudges(e,this.nudgeScreenType),this.isOneTimeOnly||setInterval(()=>{this.fetchNudges(e,this.nudgeScreenType)},this.refreshInterval)}async fetchNudges(e,t){let n;try{n=await this.nudgesRepository.getNudges(e,t)}catch(e){return void console.error("Error fetching nudges: ",e)}n.forEach((e,t)=>{e.payload.error?U.logPushNotificationEvent({response:Q.Error,details:e.payload.error,internal:e.internal}):(this.indexedNudges[t]=e.payload,this.processNudge(e.payload))})}processNudge(e){e.internal.expired_at||(e.internal.expired_at="0001-01-01T00:00:00Z");const t="0001-01-01T00:00:00Z"===e.internal.expired_at;e.internal.expired_at>(new Date).toISOString()||t?this.notificationDispatcher.show(e):U.logPushNotificationEvent({response:Q.Expired,details:"",internal:e.internal})}}class te{constructor(e,t){this.apiURL=e,this.networkDriver=t}getNudges=async(e,t)=>{const n=new Date,r=new Date,i=n.getSeconds();return n.setSeconds(i+5),r.setSeconds(i+15),[{payload:{type:"message",render_method:"in_app_message",content:{body:"Hello World of Kenkai",title:"Hello World"},attr:{render_page:"home"},internal:{inv_id:9,ref_time:"2025-09-02T16:43:00Z",action_id:2,expired_at:"2025-09-04T16:43:00Z",model_class:"",model_id:0,followup_of:0,followup_of_ref:"0001-01-01T00:00:00Z"}},error:null}]};markNudgeAsShown=e=>{};haveBeenAlreadyShown=e=>!1}class ne{constructor(e,t){this.apiURL=e,this.networkDriver=t}getNudges=async(e,t)=>[];markNudgeAsShown=e=>{};haveBeenAlreadyShown=e=>!1}const re="cfLog-shown-nudges";class ie{constructor(e,t,n){this.apiURL=e,this.networkDriver=t,this.storageDriver=n}markNudgeAsShown=e=>{const t=JSON.parse(this.storageDriver.get(re))||[];t.push(e),this.storageDriver.save(re,JSON.stringify(t))};haveBeenAlreadyShown=e=>(JSON.parse(this.storageDriver.get(re))||[]).includes(e);getNudges=async(e,t)=>{const n=e||A();if(!n)return[];const r={render_method:"in_app_message",type:"message",delivery_mode:"one-off",user_id:n,...t!==X.NudgeScreenType.None?{attr:{render_page:t}}:{}},i=await this.networkDriver.send(`${this.apiURL}`,r);return i&&i.data&&i.data.data?i.data.data:[]}}class oe{static getNudgeRepository(e,t,n){return E?document.location.search.includes("cfenv=dev")?new te(e,t):new ie(e,t,n):new ne(e,t)}}let ae=function(e){return e.View="view",e.Hide="hide",e}({});class se extends r.EventEmitter{mutationObserver=null;intersectionObserver=null;containerSelector="";itemSelector="";constructor(e){super();let t={root:null,rootMargin:"0px",threshold:e};this.intersectionObserver=new IntersectionObserver((e,t)=>this.intersectionHandler(e,t),t)}intersectionHandler(e,t){e.forEach(e=>{e.isIntersecting?this.emit(ae.View,e.target.dataset.logId,e.target.dataset):this.emit(ae.Hide,e.target.dataset.logId)})}start(e,t){this.containerSelector=`.${e}`,this.itemSelector=`.${t}`;const n=()=>{document.querySelectorAll(`${this.containerSelector} ${this.itemSelector}`).forEach(e=>{this.intersectionObserver.observe(e)})},r=document.querySelector(this.containerSelector);if(null===r)throw new Error("container-does-not-exist");n(),this.mutationObserver=new MutationObserver(e=>{this.intersectionObserver.disconnect(),n()}),this.mutationObserver.observe(r,{attributes:!0,childList:!0,characterData:!0})}stop(){this.mutationObserver.disconnect(),document.querySelectorAll(`${this.containerSelector} ${this.itemSelector}`).forEach(e=>this.intersectionObserver.unobserve(e))}}const ce=se;class ue extends r.EventEmitter{impressionObserver=null;appData={};constructor(e,t){super(),this.alreadyVisibleImpressed=new Set,this.pendingImpressions={},this.options=t,this.impressionObserver=e,this.impressionObserver.on(ae.View,(e,t)=>{this.add(e,t)}),this.impressionObserver.on(ae.Hide,e=>{this.remove(e)}),setInterval(()=>this.triggerPendingImpressions(),this.options.triggerInterval)}triggerPendingImpressions(){const e=Date.now(),t=[];for(const[n,{time_in:r}]of Object.entries(this.pendingImpressions))e-r>this.options.keepVisibleTimeout&&t.push(n);t.forEach(e=>{this.alreadyVisibleImpressed.add(e),this.emit(s.Impression,{dataset:this.pendingImpressions[e].data,appData:this.appData}),delete this.pendingImpressions[e]})}start(e,t,n){this.appData=n,this.containerClassname=e,this.itemClassname=t,this.impressionObserver.start(e,t)}stop(){this.triggerPendingImpressions(),this.impressionObserver.stop(),this.alreadyVisibleImpressed.clear(),this.pendingImpressions={}}restart(e){this.triggerPendingImpressions(),this.appData=e,this.alreadyVisibleImpressed.clear(),this.pendingImpressions={},this.impressionObserver.stop(),this.impressionObserver.start(this.containerClassname,this.itemClassname)}add(e,t){this.alreadyVisibleImpressed.has(e)||this.pendingImpressions[e]||(this.pendingImpressions[e]={time_in:Date.now(),appData:this.appData,data:t})}remove(e){this.pendingImpressions[e]&&(Date.now()-this.pendingImpressions[e].time_in>this.options.keepVisibleTimeout&&this.emit(s.Impression,{dataset:this.pendingImpressions[e].data,appData:this.appData}),delete this.pendingImpressions[e])}}const de=ue;class le extends r.EventEmitter{options={triggerInterval:2e3,keepVisibleTimeout:1e3,intersectionThreshold:.9};constructor(e){super(),e&&(this.options=Object.assign(this.options,e)),this.options.intersectionThreshold>1?this.options.intersectionThreshold=1:this.options.intersectionThreshold<.1&&(this.options.intersectionThreshold=.1),this.impressionEngine=new de(new ce(this.options.intersectionThreshold),this.options),this.impressionEngine.on(s.Impression,e=>{this.emit(s.Impression,e)})}start(e,t,n){this.impressionEngine.start(e,t,n)}restart(e){this.impressionEngine.restart(e)}stop(){this.impressionEngine.stop()}}const pe=le;class he extends r.EventEmitter{_createContainer(){const e="cf-notification-container",t=document.getElementsByClassName(e);if(0!==t.length)return t[0];const n=this._createElement("div",document.querySelector("body"),{position:"absolute",pointerEvents:"none",top:"0px",width:"100%",backgroundColor:"#0000",display:"flex",flexDirection:"column",marginTop:"83px",alignItems:"center",zIndex:"1000000"});return n.setAttribute("class",e),n.setAttribute("role","dialog"),n}_createElement(e,t,n){const r=document.createElement(e);return Object.keys(n).forEach(e=>{r.style[e]=n[e]}),t.appendChild(r),r}show(e){const t=this._createContainer(),n=this._createElement("div",t,{display:"flex",pointerEvents:"all",padding:"16px",borderRadius:"3px",backgroundColor:"#FCFCFD",width:"80%",position:"relative",boxShadow:"0 4px 8px 0 rgba(0, 0, 0, 0.2)"}),r=this._createElement("div",n,{paddingRight:"40px",width:"100%"}),i=this._createElement("div",n,{padding:"5px",color:"#667085",position:"absolute",top:"16px",right:"16px"});i.setAttribute("data-testid","close-custom-notification"),i.appendChild(document.createTextNode("X"));const o=this._createElement("div",r,{fontWeight:"700",color:"#1D2939"}),a=this._createElement("div",r,{color:"#667085",fontWeight:"500"});o.appendChild(document.createTextNode(e.content.title)),a.innerHTML=e.content.body,i.onclick=r=>{r.stopPropagation(),t.removeChild(n),U.logPushNotificationEvent({response:Q.Discard,details:"",internal:e.internal})},n.onclick=r=>{r.stopPropagation(),t.removeChild(n),this.emit(Q.Open,e)},U.logPushNotificationEvent({response:Q.Shown,details:"",internal:e.internal})}}const me=he;class ge{static getNotificationEngine(){return new me}}const fe=class{save(e,t){"undefined"!=typeof Storage&&localStorage.setItem(e,t)}get(e){if("undefined"!=typeof Storage)return localStorage.getItem(e)}},ye=class{constructor(e,t){this.bsNetwork=e,this.queue=[],this.options={flushInterval:1e4,maxRetries:10,...t},this.flushIntervalId=+setInterval(()=>{this.flush()},this.options.flushInterval)}removeFromQueue(e){this.queue=this.queue.filter(t=>t.uuid!==e)}removeQueueItemsExceedMaxRetries(){this.queue=this.queue.filter(e=>e.retries<=this.options.maxRetries)}itemInQueue(e){return void 0!==this.queue.find(t=>t.uuid===e)}flush(){this.queue.forEach(e=>this.sendToNetwork(e))}sendToNetwork(e){this.bsNetwork.send(e.url,e.event).then(()=>{this.removeFromQueue(e.uuid)}).catch(()=>{this.itemInQueue(e.uuid)?this.queue.find(t=>t.uuid===e.uuid).retries++:this.queue.push(e)}).finally(()=>{this.removeQueueItemsExceedMaxRetries()})}send(e,t){const n={uuid:w(),event:t,url:e,time:+new Date,retries:0};this.sendToNetwork(n)}get(e){throw new Error("Method not implemented.")}};var ve=n(505),_e=n.n(ve);class we{constructor(e){this.config={headers:{Authorization:`Bearer ${e}`}}}async get(e){try{return(await _e().get(`${e}`,this.config)).data}catch(t){console.error("Error retrieving data: ",t),e.includes("nudge")?(new l).throwNudgeFetchError("nudge fetch API",t.toString()):(new l).throwAndLogError("API Error",t.toString())}}async send(e,t){try{return await _e().post(e,t,this.config)}catch(t){throw e.includes("sdk/crash")||(new l).throwAPIError("API Error",`URL: ${e}\n\nerror.response: ${t.response.toString()}\n\nerror.response.data: ${t.response.data}`),t}}isOnline(){return!E||!("undefined"!=typeof window&&void 0!==window.navigator&&!window.navigator.onLine)}}class Ee{static getNetworkDriver(e){return new we(e)}}class be extends r.EventEmitter{DEFAULT_BASE_URL="https://api.kenkai.io/v1";DEFAULT_INGEST_PATH="/ingest/events";DEFAULT_DIMENSION_PATH="/ingest/dimensions";DEFAULT_NUDGE_FETCH_PATH="/action/sdk/pull";DEFAULT_CATALOG_PATH="/ingest/dimensions";DEFAULT_CDN_URL="https://cdn.causalfoundry.ai/";DEFAULT_FLUSH_INTERVAL=1e4;DEFAULT_FLUSH_MAX_RETRIES=2;DEFAULT_CACHE_EVENTS_KEY="cfEvents";DEFAULT_CACHE_CATALOG_KEY="cfCatalog";options={cdnUrl:this.DEFAULT_CDN_URL,baseUrl:this.DEFAULT_BASE_URL,allowAnonymousUsers:!1,nudgeFetchPath:this.DEFAULT_NUDGE_FETCH_PATH,catalogPath:this.DEFAULT_CATALOG_PATH,activateNudgeMechanism:!0,selfManagedNudges:!1,defaultBlock:i.ContentBlock.Core,debug:!0,isUsingAsInternalWrapper:!1,pauseSDK:!1};constructor(e,t){super(),this.deviceId=function(){const e="deviceIdStorageKey";let t;return E?(t=localStorage.getItem(e)||"",t||(t=w(),localStorage.setItem(e,t))):t=w(),t}(),t&&(this.options=Object.assign(this.options,t)),this.cfNetwork=Ee.getNetworkDriver(e),this.networkQueue=new ye(this.cfNetwork),this.storageDriver=new fe;const n={...{flushInterval:this.DEFAULT_FLUSH_INTERVAL,flushMaxRetries:this.DEFAULT_FLUSH_MAX_RETRIES,ingestPath:this.DEFAULT_INGEST_PATH,dimensionPath:this.DEFAULT_DIMENSION_PATH,cacheEventsInLocalstorage:!0,cacheEventsKey:this.DEFAULT_CACHE_EVENTS_KEY,cacheCatalogKey:this.DEFAULT_CACHE_CATALOG_KEY,...t},baseUrl:this.options.baseUrl||this.DEFAULT_BASE_URL};this.sender=new $(this.cfNetwork,n),this.cfCore=C.createInstance(this.sender,pe,this.options.debug,this.options.defaultBlock,this.deviceId,this.options.isUsingAsInternalWrapper),this.nudgesRepository=oe.getNudgeRepository(`${this.options.baseUrl}${this.options.nudgeFetchPath}`,this.cfNetwork,this.storageDriver),W(),this.options.allowAnonymousUsers&&E&&this.deviceId&&""===A()&&this.fetchNudgesForAnonUsers(this.deviceId)}flush(){this.options.pauseSDK||this.sender.flush()}identify(e,t,n,r){this.options.pauseSDK||(""!=t?(this.cfCore.login(t),e===i.IdentityAction.Logout?E&&localStorage.setItem(k,""):(this.runNudgeManager(t),function(e){e&&E&&localStorage.setItem(k,e)}(t),n&&B(t,n)),U.logIdentifyEvent({action:e,referral_code:r})):(new l).throwAndLogError(i.NavigationTypes.Identify,"invalid-user-id"))}userBlockStatus(e,t,n){if(this.options.pauseSDK)return;null==e?(new l).throwAndLogError(i.NavigationTypes.Identify,"invalid-block-status"):""==t&&(new l).throwAndLogError(i.NavigationTypes.Identify,"invalid-reason");const r={action:e?i.IdentityAction.Blocked:i.IdentityAction.UnBlocked,referral_code:"",blocked:{reason:t,remarks:n}};U.logIdentifyEvent(r)}updateUserCatalog(e,t){this.options.pauseSDK||B(e,t)}updateSiteCatalog(e,t){this.options.pauseSDK||j(e,t)}setUserId(e){this.options.pauseSDK||(e?this.cfCore.login(e):(new l).throwAndLogError(i.NavigationTypes.Identify,"invalid-user-id"))}runNudgeManager(e){this.options.pauseSDK||this.nudgeManager&&!this.options.allowAnonymousUsers||(this.nudgeManager=null,this.options.activateNudgeMechanism&&(this.options.selfManagedNudges||this.setupNudgeManager(e,X.NudgeScreenType.None,!1)))}fetchNudgesForScreen(e,t){this.options.pauseSDK||(this.nudgeManager&&(this.nudgeManager=null),this.options.activateNudgeMechanism&&this.options.selfManagedNudges&&this.setupNudgeManager(e,t,!0))}fetchNudgesForAnonUsers(e){this.options.pauseSDK||(this.nudgeManager&&(this.nudgeManager=null),this.setupNudgeManager(e,X.NudgeScreenType.None,!0))}setupNudgeManager(e,t,n){this.notificationsEngine=ge.getNotificationEngine(),this.nudgeManager=new ee(e,this.notificationsEngine,this.nudgesRepository,t,n),this.nudgeManager.on(Y.Action,e=>{this.emit(X.CfLogEvents.NudgeAction,e.type,e.cta_resource)})}}var ke=n(182);function Te(e,t,n){function r(n,r){var i;Object.defineProperty(n,"_zod",{value:n._zod??{},enumerable:!1}),(i=n._zod).traits??(i.traits=new Set),n._zod.traits.add(e),t(n,r);for(const e in a.prototype)e in n||Object.defineProperty(n,e,{value:a.prototype[e].bind(n)});n._zod.constr=a,n._zod.def=r}const i=n?.Parent??Object;class o extends i{}function a(e){var t;const i=n?.Parent?new o:this;r(i,e),(t=i._zod).deferred??(t.deferred=[]);for(const e of i._zod.deferred)e();return i}return Object.defineProperty(o,"name",{value:e}),Object.defineProperty(a,"init",{value:r}),Object.defineProperty(a,Symbol.hasInstance,{value:t=>!!(n?.Parent&&t instanceof n.Parent)||t?._zod?.traits?.has(e)}),Object.defineProperty(a,"name",{value:e}),a}Object.freeze({status:"aborted"}),Symbol("zod_brand");class Ae extends Error{constructor(){super("Encountered Promise during synchronous parse. Use .parseAsync() instead.")}}class Se extends Error{constructor(e){super(`Encountered unidirectional transform during encode: ${e}`),this.name="ZodEncodeError"}}const Ce={};function Ie(e){return e&&Object.assign(Ce,e),Ce}const Le=/^[cC][^\s-]{8,}$/,Ne=/^[0-9a-z]+$/,Pe=/^[0-9A-HJKMNP-TV-Za-hjkmnp-tv-z]{26}$/,Oe=/^[0-9a-vA-V]{20}$/,Me=/^[A-Za-z0-9]{27}$/,De=/^[a-zA-Z0-9_-]{21}$/,xe=/^P(?:(\d+W)|(?!.*W)(?=\d|T\d)(\d+Y)?(\d+M)?(\d+D)?(T(?=\d)(\d+H)?(\d+M)?(\d+([.,]\d+)?S)?)?)$/,ze=/^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12})$/,Re=e=>e?new RegExp(`^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-${e}[0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12})$`):/^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$/,Be=/^(?!\.)(?!.*\.\.)([A-Za-z0-9_'+\-\.]*)[A-Za-z0-9_+-]@([A-Za-z0-9][A-Za-z0-9\-]*\.)+[A-Za-z]{2,}$/,je=/^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])$/,Ue=/^(([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}|::|([0-9a-fA-F]{1,4})?::([0-9a-fA-F]{1,4}:?){0,6})$/,$e=/^((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\/([0-9]|[1-2][0-9]|3[0-2])$/,Fe=/^(([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}|::|([0-9a-fA-F]{1,4})?::([0-9a-fA-F]{1,4}:?){0,6})\/(12[0-8]|1[01][0-9]|[1-9]?[0-9])$/,Ze=/^$|^(?:[0-9a-zA-Z+/]{4})*(?:(?:[0-9a-zA-Z+/]{2}==)|(?:[0-9a-zA-Z+/]{3}=))?$/,qe=/^[A-Za-z0-9_-]*$/,Ge=/^(?=.{1,253}\.?$)[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[-0-9a-zA-Z]{0,61}[0-9a-zA-Z])?)*\.?$/,Ke=/^\+(?:[0-9]){6,14}[0-9]$/,Ve="(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))",He=new RegExp(`^${Ve}$`);function We(e){const t="(?:[01]\\d|2[0-3]):[0-5]\\d";return"number"==typeof e.precision?-1===e.precision?`${t}`:0===e.precision?`${t}:[0-5]\\d`:`${t}:[0-5]\\d\\.\\d{${e.precision}}`:`${t}(?::[0-5]\\d(?:\\.\\d+)?)?`}const Qe=/^\d+$/,Je=/^-?\d+(?:\.\d+)?/i,Ye=/true|false/i,Xe=/^[^A-Z]*$/,et=/^[^a-z]*$/;function tt(e,t){return"bigint"==typeof t?t.toString():t}function nt(e){return{get value(){{const t=e();return Object.defineProperty(this,"value",{value:t}),t}}}}function rt(e){return null==e}function it(e){const t=e.startsWith("^")?1:0,n=e.endsWith("$")?e.length-1:e.length;return e.slice(t,n)}const ot=Symbol("evaluating");function at(e,t,n){let r;Object.defineProperty(e,t,{get(){if(r!==ot)return void 0===r&&(r=ot,r=n()),r},set(n){Object.defineProperty(e,t,{value:n})},configurable:!0})}function st(e,t,n){Object.defineProperty(e,t,{value:n,writable:!0,enumerable:!0,configurable:!0})}function ct(...e){const t={};for(const n of e){const e=Object.getOwnPropertyDescriptors(n);Object.assign(t,e)}return Object.defineProperties({},t)}function ut(e){return JSON.stringify(e)}const dt="captureStackTrace"in Error?Error.captureStackTrace:(...e)=>{};function lt(e){return"object"==typeof e&&null!==e&&!Array.isArray(e)}const pt=nt(()=>{if("undefined"!=typeof navigator&&navigator?.userAgent?.includes("Cloudflare"))return!1;try{return new Function(""),!0}catch(e){return!1}});function ht(e){if(!1===lt(e))return!1;const t=e.constructor;if(void 0===t)return!0;const n=t.prototype;return!1!==lt(n)&&!1!==Object.prototype.hasOwnProperty.call(n,"isPrototypeOf")}function mt(e){return ht(e)?{...e}:e}const gt=new Set(["string","number","symbol"]);function ft(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function yt(e,t,n){const r=new e._zod.constr(t??e._zod.def);return t&&!n?.parent||(r._zod.parent=e),r}function vt(e){const t=e;if(!t)return{};if("string"==typeof t)return{error:()=>t};if(void 0!==t?.message){if(void 0!==t?.error)throw new Error("Cannot specify both `message` and `error` params");t.error=t.message}return delete t.message,"string"==typeof t.error?{...t,error:()=>t.error}:t}new Set(["string","number","bigint","boolean","symbol","undefined"]);const _t={safeint:[Number.MIN_SAFE_INTEGER,Number.MAX_SAFE_INTEGER],int32:[-2147483648,2147483647],uint32:[0,4294967295],float32:[-34028234663852886e22,34028234663852886e22],float64:[-Number.MAX_VALUE,Number.MAX_VALUE]};function wt(e,t=0){if(!0===e.aborted)return!0;for(let n=t;n<e.issues.length;n++)if(!0!==e.issues[n]?.continue)return!0;return!1}function Et(e,t){return t.map(t=>{var n;return(n=t).path??(n.path=[]),t.path.unshift(e),t})}function bt(e){return"string"==typeof e?e:e?.message}function kt(e,t,n){const r={...e,path:e.path??[]};if(!e.message){const i=bt(e.inst?._zod.def?.error?.(e))??bt(t?.error?.(e))??bt(n.customError?.(e))??bt(n.localeError?.(e))??"Invalid input";r.message=i}return delete r.inst,delete r.continue,t?.reportInput||delete r.input,r}function Tt(e){return Array.isArray(e)?"array":"string"==typeof e?"string":"unknown"}function At(...e){const[t,n,r]=e;return"string"==typeof t?{message:t,code:"custom",input:n,inst:r}:{...t}}const St=Te("$ZodCheck",(e,t)=>{var n;e._zod??(e._zod={}),e._zod.def=t,(n=e._zod).onattach??(n.onattach=[])}),Ct={number:"number",bigint:"bigint",object:"date"},It=Te("$ZodCheckLessThan",(e,t)=>{St.init(e,t);const n=Ct[typeof t.value];e._zod.onattach.push(e=>{const n=e._zod.bag,r=(t.inclusive?n.maximum:n.exclusiveMaximum)??Number.POSITIVE_INFINITY;t.value<r&&(t.inclusive?n.maximum=t.value:n.exclusiveMaximum=t.value)}),e._zod.check=r=>{(t.inclusive?r.value<=t.value:r.value<t.value)||r.issues.push({origin:n,code:"too_big",maximum:t.value,input:r.value,inclusive:t.inclusive,inst:e,continue:!t.abort})}}),Lt=Te("$ZodCheckGreaterThan",(e,t)=>{St.init(e,t);const n=Ct[typeof t.value];e._zod.onattach.push(e=>{const n=e._zod.bag,r=(t.inclusive?n.minimum:n.exclusiveMinimum)??Number.NEGATIVE_INFINITY;t.value>r&&(t.inclusive?n.minimum=t.value:n.exclusiveMinimum=t.value)}),e._zod.check=r=>{(t.inclusive?r.value>=t.value:r.value>t.value)||r.issues.push({origin:n,code:"too_small",minimum:t.value,input:r.value,inclusive:t.inclusive,inst:e,continue:!t.abort})}}),Nt=Te("$ZodCheckMultipleOf",(e,t)=>{St.init(e,t),e._zod.onattach.push(e=>{var n;(n=e._zod.bag).multipleOf??(n.multipleOf=t.value)}),e._zod.check=n=>{if(typeof n.value!=typeof t.value)throw new Error("Cannot mix number and bigint in multiple_of check.");("bigint"==typeof n.value?n.value%t.value===BigInt(0):0===function(e,t){const n=(e.toString().split(".")[1]||"").length,r=t.toString();let i=(r.split(".")[1]||"").length;if(0===i&&/\d?e-\d?/.test(r)){const e=r.match(/\d?e-(\d?)/);e?.[1]&&(i=Number.parseInt(e[1]))}const o=n>i?n:i;return Number.parseInt(e.toFixed(o).replace(".",""))%Number.parseInt(t.toFixed(o).replace(".",""))/10**o}(n.value,t.value))||n.issues.push({origin:typeof n.value,code:"not_multiple_of",divisor:t.value,input:n.value,inst:e,continue:!t.abort})}}),Pt=Te("$ZodCheckNumberFormat",(e,t)=>{St.init(e,t),t.format=t.format||"float64";const n=t.format?.includes("int"),r=n?"int":"number",[i,o]=_t[t.format];e._zod.onattach.push(e=>{const r=e._zod.bag;r.format=t.format,r.minimum=i,r.maximum=o,n&&(r.pattern=Qe)}),e._zod.check=a=>{const s=a.value;if(n){if(!Number.isInteger(s))return void a.issues.push({expected:r,format:t.format,code:"invalid_type",continue:!1,input:s,inst:e});if(!Number.isSafeInteger(s))return void(s>0?a.issues.push({input:s,code:"too_big",maximum:Number.MAX_SAFE_INTEGER,note:"Integers must be within the safe integer range.",inst:e,origin:r,continue:!t.abort}):a.issues.push({input:s,code:"too_small",minimum:Number.MIN_SAFE_INTEGER,note:"Integers must be within the safe integer range.",inst:e,origin:r,continue:!t.abort}))}s<i&&a.issues.push({origin:"number",input:s,code:"too_small",minimum:i,inclusive:!0,inst:e,continue:!t.abort}),s>o&&a.issues.push({origin:"number",input:s,code:"too_big",maximum:o,inst:e})}}),Ot=Te("$ZodCheckMaxLength",(e,t)=>{var n;St.init(e,t),(n=e._zod.def).when??(n.when=e=>{const t=e.value;return!rt(t)&&void 0!==t.length}),e._zod.onattach.push(e=>{const n=e._zod.bag.maximum??Number.POSITIVE_INFINITY;t.maximum<n&&(e._zod.bag.maximum=t.maximum)}),e._zod.check=n=>{const r=n.value;if(r.length<=t.maximum)return;const i=Tt(r);n.issues.push({origin:i,code:"too_big",maximum:t.maximum,inclusive:!0,input:r,inst:e,continue:!t.abort})}}),Mt=Te("$ZodCheckMinLength",(e,t)=>{var n;St.init(e,t),(n=e._zod.def).when??(n.when=e=>{const t=e.value;return!rt(t)&&void 0!==t.length}),e._zod.onattach.push(e=>{const n=e._zod.bag.minimum??Number.NEGATIVE_INFINITY;t.minimum>n&&(e._zod.bag.minimum=t.minimum)}),e._zod.check=n=>{const r=n.value;if(r.length>=t.minimum)return;const i=Tt(r);n.issues.push({origin:i,code:"too_small",minimum:t.minimum,inclusive:!0,input:r,inst:e,continue:!t.abort})}}),Dt=Te("$ZodCheckLengthEquals",(e,t)=>{var n;St.init(e,t),(n=e._zod.def).when??(n.when=e=>{const t=e.value;return!rt(t)&&void 0!==t.length}),e._zod.onattach.push(e=>{const n=e._zod.bag;n.minimum=t.length,n.maximum=t.length,n.length=t.length}),e._zod.check=n=>{const r=n.value,i=r.length;if(i===t.length)return;const o=Tt(r),a=i>t.length;n.issues.push({origin:o,...a?{code:"too_big",maximum:t.length}:{code:"too_small",minimum:t.length},inclusive:!0,exact:!0,input:n.value,inst:e,continue:!t.abort})}}),xt=Te("$ZodCheckStringFormat",(e,t)=>{var n,r;St.init(e,t),e._zod.onattach.push(e=>{const n=e._zod.bag;n.format=t.format,t.pattern&&(n.patterns??(n.patterns=new Set),n.patterns.add(t.pattern))}),t.pattern?(n=e._zod).check??(n.check=n=>{t.pattern.lastIndex=0,t.pattern.test(n.value)||n.issues.push({origin:"string",code:"invalid_format",format:t.format,input:n.value,...t.pattern?{pattern:t.pattern.toString()}:{},inst:e,continue:!t.abort})}):(r=e._zod).check??(r.check=()=>{})}),zt=Te("$ZodCheckRegex",(e,t)=>{xt.init(e,t),e._z