@nizza/core 0.4.0-alpha.10 → 0.4.0-alpha.11
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/dist/index.cjs +1 -1
- package/dist/index.mjs +2 -9
- package/dist/package.json +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -20,7 +20,7 @@ In order to be iterable, non-array objects must have a [Symbol.iterator]() metho
|
|
|
20
20
|
account: env.account,
|
|
21
21
|
...
|
|
22
22
|
});
|
|
23
|
-
`)}}const As=["account"];function $e(){As.forEach(e=>{if(e===void 0)throw new Pa(e)})}class Fs{constructor(){C(this,"_config",null);C(this,"_account");fs(this,{},{name:"NizzaConfigManager",autoBind:!0})}async configure(t){var i;if(this._config=t,((i=this.account)==null?void 0:i.account)!==t.account){const n=await er(t.account);this.setAccount(n)}}get config(){return $e(),this._config}get account(){return $e(),this._account}get ok(){var t;return $e(),!!((t=this._account)!=null&&t.account)}get accountName(){var t;return $e(),(t=this._account)==null?void 0:t.account}setAccount(t){this._account=t}}class Cs{constructor(){C(this,"channel");C(this,"listeners",new Map);C(this,"eventQueue",new Map);try{this.channel=new BroadcastChannel("nizza"),this.channel.onmessage=t=>this.handleMessage(t),this.channel.onmessageerror=t=>Ke.error("NizzaBroadcastChannel:",t)}catch(t){throw Ke.error("Failed to create NizzaBroadcastChannel:",t),t}}on(t,i){return this.subscribeToEvent(t,i),{off:()=>this.unsubscribeFromEvent(t,i)}}emit(t,i,n={}){this.emitEvent(t,i,n)}handleMessage(t){console.log("🚀 ~ file: BroadcastChannelEventBus.ts:75 ~ BroadcastChannelEventBus ~ handleMessage ");const i=t.data,{name:n}=i;for(const[a,r]of this.listeners.entries())this.matchWildcard(a,n)&&r.forEach(o=>o({...i,wildcard:a}))}subscribeToEvent(t,i){if(typeof t!="string"||typeof i!="function"){const n=new Error("Invalid arguments");throw Ke.error(n),n}for(const[n,a]of this.listeners.entries())if(this.matchWildcard(n,t)){a.add(i);const r=this.eventQueue.get(n);r&&(console.log("🚀 ~ file: BroadcastChannelEventBus.ts:111 ~ BroadcastChannelEventBus ~ subscribeToEvent ~ pendingEvents:"),r.forEach(o=>{i({...o,wildcard:n})}),this.eventQueue.delete(n));return}this.listeners.set(t,new Set([i]))}emitEvent(t,i,n){if(typeof t!="string"){const o=new Error("Invalid arguments");throw Ke.error(o),o}const a={name:t,data:i,attrs:n},r=Array.from(this.getMatchingListeners(t));if(r.length)for(const[o,s]of r)console.log("🚀 ~ file: BroadcastChannelEventBus.ts:150 ~ BroadcastChannelEventBus ~ emitEvent ~ listener"),s({...a,wildcard:o});else this.eventQueue.has(t)||this.eventQueue.set(t,[]),this.eventQueue.get(t).push(a);this.channel.postMessage(a)}*getMatchingListeners(t){for(const[i,n]of this.listeners.entries())if(this.matchWildcard(i,t))for(const a of n)yield[i,a]}unsubscribeFromEvent(t,i){if(this.listeners.has(t)){const n=this.listeners.get(t);n.delete(i),n.size===0&&this.listeners.delete(t)}}matchWildcard(t,i){const n=t.replace(/\*/g,"[^:]*").replace(/\*\*/g,".*");return new RegExp(`^${n}$`).test(i)}}const ae=class{constructor(){C(this,"_productDataSource",null);C(this,"_configManager",new Fs);C(this,"_eventBus",new Cs);C(this,"instanceId",Ai());C(this,"log",Br);cs(this,{config:fe,account:fe,ok:fe,accountName:fe,configure:me},{name:"NizzaStore",autoBind:!0})}static instance(){return ae._instance||(ae._instance=new ae),window!=null&&window.nizza?ae._instance=window==null?void 0:window.nizza:(window.nizza=ae._instance,window.nz=ae._instance),ae._instance}async configure(t){return await this._configManager.configure(t),this}get config(){return this._configManager.config}get account(){return this._configManager.account}get ok(){return this._configManager.ok}get accountName(){return this._configManager.accountName}get productDataSource(){return $e(),this._productDataSource}get eventBus(){return this._eventBus}setProductDataSource(t){this._productDataSource=t}};let Je=ae;C(Je,"_instance");const En=Je.instance(),vt=En.log,La=vt.levels.INFO;vt.setDefaultLevel(La);Ti.reg(vt);Ti.apply(vt,{template:"[%t] %l (%n)",nameFormatter:e=>{var t;return(t=e==null?void 0:e.toLowerCase())!=null?t:""},timestampFormatter:()=>new Date().toTimeString().slice(0,8)});const Ia={},Rs=wn("main"),Ke=wn("core");function Va(e){const t=vt.getLogger(e);return t.setLevel(La),t}function ja(e,t){Ia[e]=t}function Ua(e){return Ia[e]}function wn(e){const t=Va(e);return ja(e,t),Ua(e)}class Ma{constructor(t){C(this,"aggregate");C(this,"_numSetPropsApplied",0);this.aggregate=t}setProps(t){for(const[i,n]of Object.entries(t))i in this.aggregate&&(this.aggregate[i]=n);this._numSetPropsApplied++}get isFirstSetProps(){return this._numSetPropsApplied===1}}function Ba(e){return new Ma(e)}class Ts{}class xs{constructor(t){C(this,"_value");t!==void 0&&(this._value=t)}get value(){return this._value}}var An=(e=>(e.VTEX="VTEX",e.VTEX_IO="VTEX-IO",e.VTEX_CMS="PORTAL-VTEX",e.PLATFORM="PLATFORM",e.UNKNOWN="UNKNOWN",e))(An||{}),za=(e=>(e.PLATFORM="platform_module",e.ADENDA="subscription_module",e.APP_STORE="app_store",e))(za||{}),Fn=(e=>(e.ACTIVE="active_contract",e.INACTIVE="inactive_contract",e))(Fn||{}),Ga=(e=>(e.LITE="lite",e.STANDARD="standard",e.PRO="pro",e))(Ga||{}),$a=(e=>(e.LITE="PLAN_LITE",e.STANDARD="PLAN_ESTANDAR",e.PRO="PLAN_PRO",e.NONE="NO_PLAN",e))($a||{}),Ka=(e=>(e.PAST="past",e.LIVE="live",e.FUTURE="future",e))(Ka||{});class Bt{constructor(t){C(this,"root",Ba(this));C(this,"id");C(this,"account");C(this,"accountType",An.UNKNOWN);C(this,"username");C(this,"currencyConfig");C(this,"contractType");C(this,"nextDateMetricRecord");C(this,"spendedMinutes",0);C(this,"unlimitedService",!1);C(this,"hoursAvailable",0);C(this,"contractStatus",Fn.ACTIVE);C(this,"createdAt");C(this,"installationDateApp");C(this,"cxAccount");C(this,"freeService",!1);C(this,"subscriptionType",null);C(this,"minutesAvailable",0);C(this,"globalPage");C(this,"stripe");C(this,"descriptionPlan");C(this,"planType");C(this,"selectFreeTrial");C(this,"exceededFeatures");C(this,"host",null);this.root.setProps(t)}static toDomain(t){const{createdAt:i,...n}=t,a={...n,createdAt:new Date(Number(i))};return new Bt(a)}toPrimitives(){const{root:t,createdAt:i,...n}=this;return{...n,created:i.toISOString()}}}const Ds=`${Dr.apiUrls.restV1}/accounts/v2`;class Qa{async get(t){const i=`${Ds}/${t}`,{data:n}=await hn({url:i});return n?Bt.toDomain(n):null}}class Wa{constructor(t){this.accountRepository=t}async get(t){try{const i=await this.accountRepository.get(t);if(!i)throw new xa(t);return i}catch(i){throw new Da(i)}}}const Ps=new Qa,Cn=new Wa(Ps);class Rn{constructor(){this.listeners=[],this.subscribe=this.subscribe.bind(this)}subscribe(t){return this.listeners.push(t),this.onSubscribe(),()=>{this.listeners=this.listeners.filter(i=>i!==t),this.onUnsubscribe()}}hasListeners(){return this.listeners.length>0}onSubscribe(){}onUnsubscribe(){}}const xt=typeof window=="undefined"||"Deno"in window;function Ls(){}function ti(e){return typeof e=="number"&&e>=0&&e!==1/0}function Is(e,t){return Math.max(e+(t||0)-Date.now(),0)}function Vs(e,t,i){return js(e)?typeof t=="function"?{...i,queryKey:e,queryFn:t}:{...t,queryKey:e}:e}function qa(e,t){if(e===t)return e;const i=ii(e)&&ii(t);if(i||ai(e)&&ai(t)){const n=i?e.length:Object.keys(e).length,a=i?t:Object.keys(t),r=a.length,o=i?[]:{};let s=0;for(let u=0;u<r;u++){const l=i?u:a[u];o[l]=qa(e[l],t[l]),o[l]===e[l]&&s++}return n===r&&s===n?e:o}return t}function ni(e,t){if(e&&!t||t&&!e)return!1;for(const i in e)if(e[i]!==t[i])return!1;return!0}function ii(e){return Array.isArray(e)&&e.length===Object.keys(e).length}function ai(e){if(!ri(e))return!1;const t=e.constructor;if(typeof t=="undefined")return!0;const i=t.prototype;return!(!ri(i)||!i.hasOwnProperty("isPrototypeOf"))}function ri(e){return Object.prototype.toString.call(e)==="[object Object]"}function js(e){return Array.isArray(e)}function Us(e){return new Promise(t=>{setTimeout(t,e)})}function oi(e){Us(0).then(e)}function si(e,t,i){return i.isDataEqual!=null&&i.isDataEqual(e,t)?e:typeof i.structuralSharing=="function"?i.structuralSharing(e,t):i.structuralSharing!==!1?qa(e,t):t}class Ms extends Rn{constructor(){super(),this.setup=t=>{if(!xt&&window.addEventListener){const i=()=>t();return window.addEventListener("visibilitychange",i,!1),window.addEventListener("focus",i,!1),()=>{window.removeEventListener("visibilitychange",i),window.removeEventListener("focus",i)}}}}onSubscribe(){this.cleanup||this.setEventListener(this.setup)}onUnsubscribe(){if(!this.hasListeners()){var t;(t=this.cleanup)==null||t.call(this),this.cleanup=void 0}}setEventListener(t){var i;this.setup=t,(i=this.cleanup)==null||i.call(this),this.cleanup=t(n=>{typeof n=="boolean"?this.setFocused(n):this.onFocus()})}setFocused(t){this.focused=t,t&&this.onFocus()}onFocus(){this.listeners.forEach(t=>{t()})}isFocused(){return typeof this.focused=="boolean"?this.focused:typeof document=="undefined"?!0:[void 0,"visible","prerender"].includes(document.visibilityState)}}const Bs=new Ms;class zs extends Rn{constructor(){super(),this.setup=t=>{if(!xt&&window.addEventListener){const i=()=>t();return window.addEventListener("online",i,!1),window.addEventListener("offline",i,!1),()=>{window.removeEventListener("online",i),window.removeEventListener("offline",i)}}}}onSubscribe(){this.cleanup||this.setEventListener(this.setup)}onUnsubscribe(){if(!this.hasListeners()){var t;(t=this.cleanup)==null||t.call(this),this.cleanup=void 0}}setEventListener(t){var i;this.setup=t,(i=this.cleanup)==null||i.call(this),this.cleanup=t(n=>{typeof n=="boolean"?this.setOnline(n):this.onOnline()})}setOnline(t){this.online=t,t&&this.onOnline()}onOnline(){this.listeners.forEach(t=>{t()})}isOnline(){return typeof this.online=="boolean"?this.online:typeof navigator=="undefined"||typeof navigator.onLine=="undefined"?!0:navigator.onLine}}const Gs=new zs;function $s(e){return(e!=null?e:"online")==="online"?Gs.isOnline():!0}class Ks{constructor(t){this.revert=t==null?void 0:t.revert,this.silent=t==null?void 0:t.silent}}function Qs(e){return e instanceof Ks}function Ws(){let e=[],t=0,i=d=>{d()},n=d=>{d()};const a=d=>{let c;t++;try{c=d()}finally{t--,t||s()}return c},r=d=>{t?e.push(d):oi(()=>{i(d)})},o=d=>(...c)=>{r(()=>{d(...c)})},s=()=>{const d=e;e=[],d.length&&oi(()=>{n(()=>{d.forEach(c=>{i(c)})})})};return{batch:a,batchCalls:o,schedule:r,setNotifyFunction:d=>{i=d},setBatchNotifyFunction:d=>{n=d}}}const Qe=Ws();class qs extends Rn{constructor(t,i){super(),this.client=t,this.options=i,this.trackedProps=new Set,this.selectError=null,this.bindMethods(),this.setOptions(i)}bindMethods(){this.remove=this.remove.bind(this),this.refetch=this.refetch.bind(this)}onSubscribe(){this.listeners.length===1&&(this.currentQuery.addObserver(this),ui(this.currentQuery,this.options)&&this.executeFetch(),this.updateTimers())}onUnsubscribe(){this.listeners.length||this.destroy()}shouldFetchOnReconnect(){return cn(this.currentQuery,this.options,this.options.refetchOnReconnect)}shouldFetchOnWindowFocus(){return cn(this.currentQuery,this.options,this.options.refetchOnWindowFocus)}destroy(){this.listeners=[],this.clearStaleTimeout(),this.clearRefetchInterval(),this.currentQuery.removeObserver(this)}setOptions(t,i){const n=this.options,a=this.currentQuery;if(this.options=this.client.defaultQueryOptions(t),ni(n,this.options)||this.client.getQueryCache().notify({type:"observerOptionsUpdated",query:this.currentQuery,observer:this}),typeof this.options.enabled!="undefined"&&typeof this.options.enabled!="boolean")throw new Error("Expected enabled to be a boolean");this.options.queryKey||(this.options.queryKey=n.queryKey),this.updateQuery();const r=this.hasListeners();r&&li(this.currentQuery,a,this.options,n)&&this.executeFetch(),this.updateResult(i),r&&(this.currentQuery!==a||this.options.enabled!==n.enabled||this.options.staleTime!==n.staleTime)&&this.updateStaleTimeout();const o=this.computeRefetchInterval();r&&(this.currentQuery!==a||this.options.enabled!==n.enabled||o!==this.currentRefetchInterval)&&this.updateRefetchInterval(o)}getOptimisticResult(t){const i=this.client.getQueryCache().build(this.client,t);return this.createResult(i,t)}getCurrentResult(){return this.currentResult}trackResult(t){const i={};return Object.keys(t).forEach(n=>{Object.defineProperty(i,n,{configurable:!1,enumerable:!0,get:()=>(this.trackedProps.add(n),t[n])})}),i}getCurrentQuery(){return this.currentQuery}remove(){this.client.getQueryCache().remove(this.currentQuery)}refetch({refetchPage:t,...i}={}){return this.fetch({...i,meta:{refetchPage:t}})}fetchOptimistic(t){const i=this.client.defaultQueryOptions(t),n=this.client.getQueryCache().build(this.client,i);return n.isFetchingOptimistic=!0,n.fetch().then(()=>this.createResult(n,i))}fetch(t){var i;return this.executeFetch({...t,cancelRefetch:(i=t.cancelRefetch)!=null?i:!0}).then(()=>(this.updateResult(),this.currentResult))}executeFetch(t){this.updateQuery();let i=this.currentQuery.fetch(this.options,t);return t!=null&&t.throwOnError||(i=i.catch(Ls)),i}updateStaleTimeout(){if(this.clearStaleTimeout(),xt||this.currentResult.isStale||!ti(this.options.staleTime))return;const i=Is(this.currentResult.dataUpdatedAt,this.options.staleTime)+1;this.staleTimeoutId=setTimeout(()=>{this.currentResult.isStale||this.updateResult()},i)}computeRefetchInterval(){var t;return typeof this.options.refetchInterval=="function"?this.options.refetchInterval(this.currentResult.data,this.currentQuery):(t=this.options.refetchInterval)!=null?t:!1}updateRefetchInterval(t){this.clearRefetchInterval(),this.currentRefetchInterval=t,!(xt||this.options.enabled===!1||!ti(this.currentRefetchInterval)||this.currentRefetchInterval===0)&&(this.refetchIntervalId=setInterval(()=>{(this.options.refetchIntervalInBackground||Bs.isFocused())&&this.executeFetch()},this.currentRefetchInterval))}updateTimers(){this.updateStaleTimeout(),this.updateRefetchInterval(this.computeRefetchInterval())}clearStaleTimeout(){this.staleTimeoutId&&(clearTimeout(this.staleTimeoutId),this.staleTimeoutId=void 0)}clearRefetchInterval(){this.refetchIntervalId&&(clearInterval(this.refetchIntervalId),this.refetchIntervalId=void 0)}createResult(t,i){const n=this.currentQuery,a=this.options,r=this.currentResult,o=this.currentResultState,s=this.currentResultOptions,u=t!==n,l=u?t.state:this.currentQueryInitialState,d=u?this.currentResult:this.previousQueryResult,{state:c}=t;let{dataUpdatedAt:p,error:g,errorUpdatedAt:b,fetchStatus:v,status:m}=c,y=!1,N=!1,A;if(i._optimisticResults){const f=this.hasListeners(),h=!f&&ui(t,i),k=f&&li(t,n,i,a);(h||k)&&(v=$s(t.options.networkMode)?"fetching":"paused",p||(m="loading")),i._optimisticResults==="isRestoring"&&(v="idle")}if(i.keepPreviousData&&!c.dataUpdatedAt&&d!=null&&d.isSuccess&&m!=="error")A=d.data,p=d.dataUpdatedAt,m=d.status,y=!0;else if(i.select&&typeof c.data!="undefined")if(r&&c.data===(o==null?void 0:o.data)&&i.select===this.selectFn)A=this.selectResult;else try{this.selectFn=i.select,A=i.select(c.data),A=si(r==null?void 0:r.data,A,i),this.selectResult=A,this.selectError=null}catch(f){this.selectError=f}else A=c.data;if(typeof i.placeholderData!="undefined"&&typeof A=="undefined"&&m==="loading"){let f;if(r!=null&&r.isPlaceholderData&&i.placeholderData===(s==null?void 0:s.placeholderData))f=r.data;else if(f=typeof i.placeholderData=="function"?i.placeholderData():i.placeholderData,i.select&&typeof f!="undefined")try{f=i.select(f),this.selectError=null}catch(h){this.selectError=h}typeof f!="undefined"&&(m="success",A=si(r==null?void 0:r.data,f,i),N=!0)}this.selectError&&(g=this.selectError,A=this.selectResult,b=Date.now(),m="error");const O=v==="fetching",T=m==="loading",L=m==="error";return{status:m,fetchStatus:v,isLoading:T,isSuccess:m==="success",isError:L,isInitialLoading:T&&O,data:A,dataUpdatedAt:p,error:g,errorUpdatedAt:b,failureCount:c.fetchFailureCount,failureReason:c.fetchFailureReason,errorUpdateCount:c.errorUpdateCount,isFetched:c.dataUpdateCount>0||c.errorUpdateCount>0,isFetchedAfterMount:c.dataUpdateCount>l.dataUpdateCount||c.errorUpdateCount>l.errorUpdateCount,isFetching:O,isRefetching:O&&!T,isLoadingError:L&&c.dataUpdatedAt===0,isPaused:v==="paused",isPlaceholderData:N,isPreviousData:y,isRefetchError:L&&c.dataUpdatedAt!==0,isStale:Tn(t,i),refetch:this.refetch,remove:this.remove}}updateResult(t){const i=this.currentResult,n=this.createResult(this.currentQuery,this.options);if(this.currentResultState=this.currentQuery.state,this.currentResultOptions=this.options,ni(n,i))return;this.currentResult=n;const a={cache:!0},r=()=>{if(!i)return!0;const{notifyOnChangeProps:o}=this.options;if(o==="all"||!o&&!this.trackedProps.size)return!0;const s=new Set(o!=null?o:this.trackedProps);return this.options.useErrorBoundary&&s.add("error"),Object.keys(this.currentResult).some(u=>{const l=u;return this.currentResult[l]!==i[l]&&s.has(l)})};(t==null?void 0:t.listeners)!==!1&&r()&&(a.listeners=!0),this.notify({...a,...t})}updateQuery(){const t=this.client.getQueryCache().build(this.client,this.options);if(t===this.currentQuery)return;const i=this.currentQuery;this.currentQuery=t,this.currentQueryInitialState=t.state,this.previousQueryResult=this.currentResult,this.hasListeners()&&(i==null||i.removeObserver(this),t.addObserver(this))}onQueryUpdate(t){const i={};t.type==="success"?i.onSuccess=!t.manual:t.type==="error"&&!Qs(t.error)&&(i.onError=!0),this.updateResult(i),this.hasListeners()&&this.updateTimers()}notify(t){Qe.batch(()=>{if(t.onSuccess){var i,n,a,r;(i=(n=this.options).onSuccess)==null||i.call(n,this.currentResult.data),(a=(r=this.options).onSettled)==null||a.call(r,this.currentResult.data,null)}else if(t.onError){var o,s,u,l;(o=(s=this.options).onError)==null||o.call(s,this.currentResult.error),(u=(l=this.options).onSettled)==null||u.call(l,void 0,this.currentResult.error)}t.listeners&&this.listeners.forEach(d=>{d(this.currentResult)}),t.cache&&this.client.getQueryCache().notify({query:this.currentQuery,type:"observerResultsUpdated"})})}}function Js(e,t){return t.enabled!==!1&&!e.state.dataUpdatedAt&&!(e.state.status==="error"&&t.retryOnMount===!1)}function ui(e,t){return Js(e,t)||e.state.dataUpdatedAt>0&&cn(e,t,t.refetchOnMount)}function cn(e,t,i){if(t.enabled!==!1){const n=typeof i=="function"?i(e):i;return n==="always"||n!==!1&&Tn(e,t)}return!1}function li(e,t,i,n){return i.enabled!==!1&&(e!==t||n.enabled===!1)&&(!i.suspense||e.state.status!=="error")&&Tn(e,i)}function Tn(e,t){return e.isStaleByTime(t.staleTime)}var Ja={exports:{}},Ha={};/**
|
|
23
|
+
`)}}const As=["account"];function $e(){As.forEach(e=>{if(e===void 0)throw new Pa(e)})}class Fs{constructor(){C(this,"_config",null);C(this,"_account");fs(this,{},{name:"NizzaConfigManager",autoBind:!0})}async configure(t){var i;if(this._config=t,((i=this.account)==null?void 0:i.account)!==t.account){const n=await er(t.account);this.setAccount(n)}}get config(){return $e(),this._config}get account(){return $e(),this._account}get ok(){var t;return $e(),!!((t=this._account)!=null&&t.account)}get accountName(){var t;return $e(),(t=this._account)==null?void 0:t.account}setAccount(t){this._account=t}}class Cs{constructor(){C(this,"channel");C(this,"listeners",new Map);C(this,"eventQueue",new Map);try{this.channel=new BroadcastChannel("nizza"),this.channel.onmessage=t=>this.handleMessage(t),this.channel.onmessageerror=t=>Ke.error("NizzaBroadcastChannel:",t)}catch(t){throw Ke.error("Failed to create NizzaBroadcastChannel:",t),t}}on(t,i){return this.subscribeToEvent(t,i),{off:()=>this.unsubscribeFromEvent(t,i)}}emit(t,i,n={}){this.emitEvent(t,i,n)}handleMessage(t){const i=t.data,{name:n}=i;for(const[a,r]of this.listeners.entries())this.matchWildcard(a,n)&&r.forEach(o=>o({...i,wildcard:a}))}subscribeToEvent(t,i){if(typeof t!="string"||typeof i!="function"){const n=new Error("Invalid arguments");throw Ke.error(n),n}for(const[n,a]of this.listeners.entries())if(this.matchWildcard(n,t)){a.add(i);const r=this.eventQueue.get(n);r&&(r.forEach(o=>{i({...o,wildcard:n})}),this.eventQueue.delete(n));return}this.listeners.set(t,new Set([i]))}emitEvent(t,i,n){if(typeof t!="string"){const o=new Error("Invalid arguments");throw Ke.error(o),o}const a={name:t,data:i,attrs:n},r=Array.from(this.getMatchingListeners(t));if(r.length)for(const[o,s]of r)s({...a,wildcard:o});else this.eventQueue.has(t)||this.eventQueue.set(t,[]),this.eventQueue.get(t).push(a);this.channel.postMessage(a)}*getMatchingListeners(t){for(const[i,n]of this.listeners.entries())if(this.matchWildcard(i,t))for(const a of n)yield[i,a]}unsubscribeFromEvent(t,i){if(this.listeners.has(t)){const n=this.listeners.get(t);n.delete(i),n.size===0&&this.listeners.delete(t)}}matchWildcard(t,i){const n=t.replace(/\*/g,"[^:]*").replace(/\*\*/g,".*");return new RegExp(`^${n}$`).test(i)}}const ae=class{constructor(){C(this,"_productDataSource",null);C(this,"_configManager",new Fs);C(this,"_eventBus",new Cs);C(this,"instanceId",Ai());C(this,"log",Br);cs(this,{config:fe,account:fe,ok:fe,accountName:fe,configure:me},{name:"NizzaStore",autoBind:!0})}static instance(){return ae._instance||(ae._instance=new ae),window!=null&&window.nizza?ae._instance=window==null?void 0:window.nizza:(window.nizza=ae._instance,window.nz=ae._instance),ae._instance}async configure(t){return await this._configManager.configure(t),this}get config(){return this._configManager.config}get account(){return this._configManager.account}get ok(){return this._configManager.ok}get accountName(){return this._configManager.accountName}get productDataSource(){return $e(),this._productDataSource}get eventBus(){return this._eventBus}setProductDataSource(t){this._productDataSource=t}};let Je=ae;C(Je,"_instance");const En=Je.instance(),vt=En.log,La=vt.levels.INFO;vt.setDefaultLevel(La);Ti.reg(vt);Ti.apply(vt,{template:"[%t] %l (%n)",nameFormatter:e=>{var t;return(t=e==null?void 0:e.toLowerCase())!=null?t:""},timestampFormatter:()=>new Date().toTimeString().slice(0,8)});const Ia={},Rs=wn("main"),Ke=wn("core");function Va(e){const t=vt.getLogger(e);return t.setLevel(La),t}function ja(e,t){Ia[e]=t}function Ua(e){return Ia[e]}function wn(e){const t=Va(e);return ja(e,t),Ua(e)}class Ma{constructor(t){C(this,"aggregate");C(this,"_numSetPropsApplied",0);this.aggregate=t}setProps(t){for(const[i,n]of Object.entries(t))i in this.aggregate&&(this.aggregate[i]=n);this._numSetPropsApplied++}get isFirstSetProps(){return this._numSetPropsApplied===1}}function Ba(e){return new Ma(e)}class Ts{}class xs{constructor(t){C(this,"_value");t!==void 0&&(this._value=t)}get value(){return this._value}}var An=(e=>(e.VTEX="VTEX",e.VTEX_IO="VTEX-IO",e.VTEX_CMS="PORTAL-VTEX",e.PLATFORM="PLATFORM",e.UNKNOWN="UNKNOWN",e))(An||{}),za=(e=>(e.PLATFORM="platform_module",e.ADENDA="subscription_module",e.APP_STORE="app_store",e))(za||{}),Fn=(e=>(e.ACTIVE="active_contract",e.INACTIVE="inactive_contract",e))(Fn||{}),Ga=(e=>(e.LITE="lite",e.STANDARD="standard",e.PRO="pro",e))(Ga||{}),$a=(e=>(e.LITE="PLAN_LITE",e.STANDARD="PLAN_ESTANDAR",e.PRO="PLAN_PRO",e.NONE="NO_PLAN",e))($a||{}),Ka=(e=>(e.PAST="past",e.LIVE="live",e.FUTURE="future",e))(Ka||{});class Bt{constructor(t){C(this,"root",Ba(this));C(this,"id");C(this,"account");C(this,"accountType",An.UNKNOWN);C(this,"username");C(this,"currencyConfig");C(this,"contractType");C(this,"nextDateMetricRecord");C(this,"spendedMinutes",0);C(this,"unlimitedService",!1);C(this,"hoursAvailable",0);C(this,"contractStatus",Fn.ACTIVE);C(this,"createdAt");C(this,"installationDateApp");C(this,"cxAccount");C(this,"freeService",!1);C(this,"subscriptionType",null);C(this,"minutesAvailable",0);C(this,"globalPage");C(this,"stripe");C(this,"descriptionPlan");C(this,"planType");C(this,"selectFreeTrial");C(this,"exceededFeatures");C(this,"host",null);this.root.setProps(t)}static toDomain(t){const{createdAt:i,...n}=t,a={...n,createdAt:new Date(Number(i))};return new Bt(a)}toPrimitives(){const{root:t,createdAt:i,...n}=this;return{...n,created:i.toISOString()}}}const Ds=`${Dr.apiUrls.restV1}/accounts/v2`;class Qa{async get(t){const i=`${Ds}/${t}`,{data:n}=await hn({url:i});return n?Bt.toDomain(n):null}}class Wa{constructor(t){this.accountRepository=t}async get(t){try{const i=await this.accountRepository.get(t);if(!i)throw new xa(t);return i}catch(i){throw new Da(i)}}}const Ps=new Qa,Cn=new Wa(Ps);class Rn{constructor(){this.listeners=[],this.subscribe=this.subscribe.bind(this)}subscribe(t){return this.listeners.push(t),this.onSubscribe(),()=>{this.listeners=this.listeners.filter(i=>i!==t),this.onUnsubscribe()}}hasListeners(){return this.listeners.length>0}onSubscribe(){}onUnsubscribe(){}}const xt=typeof window=="undefined"||"Deno"in window;function Ls(){}function ti(e){return typeof e=="number"&&e>=0&&e!==1/0}function Is(e,t){return Math.max(e+(t||0)-Date.now(),0)}function Vs(e,t,i){return js(e)?typeof t=="function"?{...i,queryKey:e,queryFn:t}:{...t,queryKey:e}:e}function qa(e,t){if(e===t)return e;const i=ii(e)&&ii(t);if(i||ai(e)&&ai(t)){const n=i?e.length:Object.keys(e).length,a=i?t:Object.keys(t),r=a.length,o=i?[]:{};let s=0;for(let u=0;u<r;u++){const l=i?u:a[u];o[l]=qa(e[l],t[l]),o[l]===e[l]&&s++}return n===r&&s===n?e:o}return t}function ni(e,t){if(e&&!t||t&&!e)return!1;for(const i in e)if(e[i]!==t[i])return!1;return!0}function ii(e){return Array.isArray(e)&&e.length===Object.keys(e).length}function ai(e){if(!ri(e))return!1;const t=e.constructor;if(typeof t=="undefined")return!0;const i=t.prototype;return!(!ri(i)||!i.hasOwnProperty("isPrototypeOf"))}function ri(e){return Object.prototype.toString.call(e)==="[object Object]"}function js(e){return Array.isArray(e)}function Us(e){return new Promise(t=>{setTimeout(t,e)})}function oi(e){Us(0).then(e)}function si(e,t,i){return i.isDataEqual!=null&&i.isDataEqual(e,t)?e:typeof i.structuralSharing=="function"?i.structuralSharing(e,t):i.structuralSharing!==!1?qa(e,t):t}class Ms extends Rn{constructor(){super(),this.setup=t=>{if(!xt&&window.addEventListener){const i=()=>t();return window.addEventListener("visibilitychange",i,!1),window.addEventListener("focus",i,!1),()=>{window.removeEventListener("visibilitychange",i),window.removeEventListener("focus",i)}}}}onSubscribe(){this.cleanup||this.setEventListener(this.setup)}onUnsubscribe(){if(!this.hasListeners()){var t;(t=this.cleanup)==null||t.call(this),this.cleanup=void 0}}setEventListener(t){var i;this.setup=t,(i=this.cleanup)==null||i.call(this),this.cleanup=t(n=>{typeof n=="boolean"?this.setFocused(n):this.onFocus()})}setFocused(t){this.focused=t,t&&this.onFocus()}onFocus(){this.listeners.forEach(t=>{t()})}isFocused(){return typeof this.focused=="boolean"?this.focused:typeof document=="undefined"?!0:[void 0,"visible","prerender"].includes(document.visibilityState)}}const Bs=new Ms;class zs extends Rn{constructor(){super(),this.setup=t=>{if(!xt&&window.addEventListener){const i=()=>t();return window.addEventListener("online",i,!1),window.addEventListener("offline",i,!1),()=>{window.removeEventListener("online",i),window.removeEventListener("offline",i)}}}}onSubscribe(){this.cleanup||this.setEventListener(this.setup)}onUnsubscribe(){if(!this.hasListeners()){var t;(t=this.cleanup)==null||t.call(this),this.cleanup=void 0}}setEventListener(t){var i;this.setup=t,(i=this.cleanup)==null||i.call(this),this.cleanup=t(n=>{typeof n=="boolean"?this.setOnline(n):this.onOnline()})}setOnline(t){this.online=t,t&&this.onOnline()}onOnline(){this.listeners.forEach(t=>{t()})}isOnline(){return typeof this.online=="boolean"?this.online:typeof navigator=="undefined"||typeof navigator.onLine=="undefined"?!0:navigator.onLine}}const Gs=new zs;function $s(e){return(e!=null?e:"online")==="online"?Gs.isOnline():!0}class Ks{constructor(t){this.revert=t==null?void 0:t.revert,this.silent=t==null?void 0:t.silent}}function Qs(e){return e instanceof Ks}function Ws(){let e=[],t=0,i=d=>{d()},n=d=>{d()};const a=d=>{let c;t++;try{c=d()}finally{t--,t||s()}return c},r=d=>{t?e.push(d):oi(()=>{i(d)})},o=d=>(...c)=>{r(()=>{d(...c)})},s=()=>{const d=e;e=[],d.length&&oi(()=>{n(()=>{d.forEach(c=>{i(c)})})})};return{batch:a,batchCalls:o,schedule:r,setNotifyFunction:d=>{i=d},setBatchNotifyFunction:d=>{n=d}}}const Qe=Ws();class qs extends Rn{constructor(t,i){super(),this.client=t,this.options=i,this.trackedProps=new Set,this.selectError=null,this.bindMethods(),this.setOptions(i)}bindMethods(){this.remove=this.remove.bind(this),this.refetch=this.refetch.bind(this)}onSubscribe(){this.listeners.length===1&&(this.currentQuery.addObserver(this),ui(this.currentQuery,this.options)&&this.executeFetch(),this.updateTimers())}onUnsubscribe(){this.listeners.length||this.destroy()}shouldFetchOnReconnect(){return cn(this.currentQuery,this.options,this.options.refetchOnReconnect)}shouldFetchOnWindowFocus(){return cn(this.currentQuery,this.options,this.options.refetchOnWindowFocus)}destroy(){this.listeners=[],this.clearStaleTimeout(),this.clearRefetchInterval(),this.currentQuery.removeObserver(this)}setOptions(t,i){const n=this.options,a=this.currentQuery;if(this.options=this.client.defaultQueryOptions(t),ni(n,this.options)||this.client.getQueryCache().notify({type:"observerOptionsUpdated",query:this.currentQuery,observer:this}),typeof this.options.enabled!="undefined"&&typeof this.options.enabled!="boolean")throw new Error("Expected enabled to be a boolean");this.options.queryKey||(this.options.queryKey=n.queryKey),this.updateQuery();const r=this.hasListeners();r&&li(this.currentQuery,a,this.options,n)&&this.executeFetch(),this.updateResult(i),r&&(this.currentQuery!==a||this.options.enabled!==n.enabled||this.options.staleTime!==n.staleTime)&&this.updateStaleTimeout();const o=this.computeRefetchInterval();r&&(this.currentQuery!==a||this.options.enabled!==n.enabled||o!==this.currentRefetchInterval)&&this.updateRefetchInterval(o)}getOptimisticResult(t){const i=this.client.getQueryCache().build(this.client,t);return this.createResult(i,t)}getCurrentResult(){return this.currentResult}trackResult(t){const i={};return Object.keys(t).forEach(n=>{Object.defineProperty(i,n,{configurable:!1,enumerable:!0,get:()=>(this.trackedProps.add(n),t[n])})}),i}getCurrentQuery(){return this.currentQuery}remove(){this.client.getQueryCache().remove(this.currentQuery)}refetch({refetchPage:t,...i}={}){return this.fetch({...i,meta:{refetchPage:t}})}fetchOptimistic(t){const i=this.client.defaultQueryOptions(t),n=this.client.getQueryCache().build(this.client,i);return n.isFetchingOptimistic=!0,n.fetch().then(()=>this.createResult(n,i))}fetch(t){var i;return this.executeFetch({...t,cancelRefetch:(i=t.cancelRefetch)!=null?i:!0}).then(()=>(this.updateResult(),this.currentResult))}executeFetch(t){this.updateQuery();let i=this.currentQuery.fetch(this.options,t);return t!=null&&t.throwOnError||(i=i.catch(Ls)),i}updateStaleTimeout(){if(this.clearStaleTimeout(),xt||this.currentResult.isStale||!ti(this.options.staleTime))return;const i=Is(this.currentResult.dataUpdatedAt,this.options.staleTime)+1;this.staleTimeoutId=setTimeout(()=>{this.currentResult.isStale||this.updateResult()},i)}computeRefetchInterval(){var t;return typeof this.options.refetchInterval=="function"?this.options.refetchInterval(this.currentResult.data,this.currentQuery):(t=this.options.refetchInterval)!=null?t:!1}updateRefetchInterval(t){this.clearRefetchInterval(),this.currentRefetchInterval=t,!(xt||this.options.enabled===!1||!ti(this.currentRefetchInterval)||this.currentRefetchInterval===0)&&(this.refetchIntervalId=setInterval(()=>{(this.options.refetchIntervalInBackground||Bs.isFocused())&&this.executeFetch()},this.currentRefetchInterval))}updateTimers(){this.updateStaleTimeout(),this.updateRefetchInterval(this.computeRefetchInterval())}clearStaleTimeout(){this.staleTimeoutId&&(clearTimeout(this.staleTimeoutId),this.staleTimeoutId=void 0)}clearRefetchInterval(){this.refetchIntervalId&&(clearInterval(this.refetchIntervalId),this.refetchIntervalId=void 0)}createResult(t,i){const n=this.currentQuery,a=this.options,r=this.currentResult,o=this.currentResultState,s=this.currentResultOptions,u=t!==n,l=u?t.state:this.currentQueryInitialState,d=u?this.currentResult:this.previousQueryResult,{state:c}=t;let{dataUpdatedAt:p,error:g,errorUpdatedAt:b,fetchStatus:v,status:m}=c,y=!1,N=!1,A;if(i._optimisticResults){const f=this.hasListeners(),h=!f&&ui(t,i),k=f&&li(t,n,i,a);(h||k)&&(v=$s(t.options.networkMode)?"fetching":"paused",p||(m="loading")),i._optimisticResults==="isRestoring"&&(v="idle")}if(i.keepPreviousData&&!c.dataUpdatedAt&&d!=null&&d.isSuccess&&m!=="error")A=d.data,p=d.dataUpdatedAt,m=d.status,y=!0;else if(i.select&&typeof c.data!="undefined")if(r&&c.data===(o==null?void 0:o.data)&&i.select===this.selectFn)A=this.selectResult;else try{this.selectFn=i.select,A=i.select(c.data),A=si(r==null?void 0:r.data,A,i),this.selectResult=A,this.selectError=null}catch(f){this.selectError=f}else A=c.data;if(typeof i.placeholderData!="undefined"&&typeof A=="undefined"&&m==="loading"){let f;if(r!=null&&r.isPlaceholderData&&i.placeholderData===(s==null?void 0:s.placeholderData))f=r.data;else if(f=typeof i.placeholderData=="function"?i.placeholderData():i.placeholderData,i.select&&typeof f!="undefined")try{f=i.select(f),this.selectError=null}catch(h){this.selectError=h}typeof f!="undefined"&&(m="success",A=si(r==null?void 0:r.data,f,i),N=!0)}this.selectError&&(g=this.selectError,A=this.selectResult,b=Date.now(),m="error");const O=v==="fetching",T=m==="loading",L=m==="error";return{status:m,fetchStatus:v,isLoading:T,isSuccess:m==="success",isError:L,isInitialLoading:T&&O,data:A,dataUpdatedAt:p,error:g,errorUpdatedAt:b,failureCount:c.fetchFailureCount,failureReason:c.fetchFailureReason,errorUpdateCount:c.errorUpdateCount,isFetched:c.dataUpdateCount>0||c.errorUpdateCount>0,isFetchedAfterMount:c.dataUpdateCount>l.dataUpdateCount||c.errorUpdateCount>l.errorUpdateCount,isFetching:O,isRefetching:O&&!T,isLoadingError:L&&c.dataUpdatedAt===0,isPaused:v==="paused",isPlaceholderData:N,isPreviousData:y,isRefetchError:L&&c.dataUpdatedAt!==0,isStale:Tn(t,i),refetch:this.refetch,remove:this.remove}}updateResult(t){const i=this.currentResult,n=this.createResult(this.currentQuery,this.options);if(this.currentResultState=this.currentQuery.state,this.currentResultOptions=this.options,ni(n,i))return;this.currentResult=n;const a={cache:!0},r=()=>{if(!i)return!0;const{notifyOnChangeProps:o}=this.options;if(o==="all"||!o&&!this.trackedProps.size)return!0;const s=new Set(o!=null?o:this.trackedProps);return this.options.useErrorBoundary&&s.add("error"),Object.keys(this.currentResult).some(u=>{const l=u;return this.currentResult[l]!==i[l]&&s.has(l)})};(t==null?void 0:t.listeners)!==!1&&r()&&(a.listeners=!0),this.notify({...a,...t})}updateQuery(){const t=this.client.getQueryCache().build(this.client,this.options);if(t===this.currentQuery)return;const i=this.currentQuery;this.currentQuery=t,this.currentQueryInitialState=t.state,this.previousQueryResult=this.currentResult,this.hasListeners()&&(i==null||i.removeObserver(this),t.addObserver(this))}onQueryUpdate(t){const i={};t.type==="success"?i.onSuccess=!t.manual:t.type==="error"&&!Qs(t.error)&&(i.onError=!0),this.updateResult(i),this.hasListeners()&&this.updateTimers()}notify(t){Qe.batch(()=>{if(t.onSuccess){var i,n,a,r;(i=(n=this.options).onSuccess)==null||i.call(n,this.currentResult.data),(a=(r=this.options).onSettled)==null||a.call(r,this.currentResult.data,null)}else if(t.onError){var o,s,u,l;(o=(s=this.options).onError)==null||o.call(s,this.currentResult.error),(u=(l=this.options).onSettled)==null||u.call(l,void 0,this.currentResult.error)}t.listeners&&this.listeners.forEach(d=>{d(this.currentResult)}),t.cache&&this.client.getQueryCache().notify({query:this.currentQuery,type:"observerResultsUpdated"})})}}function Js(e,t){return t.enabled!==!1&&!e.state.dataUpdatedAt&&!(e.state.status==="error"&&t.retryOnMount===!1)}function ui(e,t){return Js(e,t)||e.state.dataUpdatedAt>0&&cn(e,t,t.refetchOnMount)}function cn(e,t,i){if(t.enabled!==!1){const n=typeof i=="function"?i(e):i;return n==="always"||n!==!1&&Tn(e,t)}return!1}function li(e,t,i,n){return i.enabled!==!1&&(e!==t||n.enabled===!1)&&(!i.suspense||e.state.status!=="error")&&Tn(e,i)}function Tn(e,t){return e.isStaleByTime(t.staleTime)}var Ja={exports:{}},Ha={};/**
|
|
24
24
|
* @license React
|
|
25
25
|
* use-sync-external-store-shim.production.min.js
|
|
26
26
|
*
|
package/dist/index.mjs
CHANGED
|
@@ -3210,9 +3210,6 @@ class ms {
|
|
|
3210
3210
|
* @param {MessageEvent} event - The received message event.
|
|
3211
3211
|
*/
|
|
3212
3212
|
handleMessage(t) {
|
|
3213
|
-
console.log(
|
|
3214
|
-
"🚀 ~ file: BroadcastChannelEventBus.ts:75 ~ BroadcastChannelEventBus ~ handleMessage "
|
|
3215
|
-
);
|
|
3216
3213
|
const i = t.data, { name: n } = i;
|
|
3217
3214
|
for (const [a, r] of this.listeners.entries())
|
|
3218
3215
|
this.matchWildcard(a, n) && r.forEach(
|
|
@@ -3235,9 +3232,7 @@ class ms {
|
|
|
3235
3232
|
if (this.matchWildcard(n, t)) {
|
|
3236
3233
|
a.add(i);
|
|
3237
3234
|
const r = this.eventQueue.get(n);
|
|
3238
|
-
r && (
|
|
3239
|
-
"🚀 ~ file: BroadcastChannelEventBus.ts:111 ~ BroadcastChannelEventBus ~ subscribeToEvent ~ pendingEvents:"
|
|
3240
|
-
), r.forEach((o) => {
|
|
3235
|
+
r && (r.forEach((o) => {
|
|
3241
3236
|
i({ ...o, wildcard: n });
|
|
3242
3237
|
}), this.eventQueue.delete(n));
|
|
3243
3238
|
return;
|
|
@@ -3264,9 +3259,7 @@ class ms {
|
|
|
3264
3259
|
}, r = Array.from(this.getMatchingListeners(t));
|
|
3265
3260
|
if (r.length)
|
|
3266
3261
|
for (const [o, s] of r)
|
|
3267
|
-
|
|
3268
|
-
"🚀 ~ file: BroadcastChannelEventBus.ts:150 ~ BroadcastChannelEventBus ~ emitEvent ~ listener"
|
|
3269
|
-
), s({ ...a, wildcard: o });
|
|
3262
|
+
s({ ...a, wildcard: o });
|
|
3270
3263
|
else
|
|
3271
3264
|
this.eventQueue.has(t) || this.eventQueue.set(t, []), this.eventQueue.get(t).push(a);
|
|
3272
3265
|
this.channel.postMessage(a);
|
package/dist/package.json
CHANGED