hart-estate-widget 4.8.26 → 4.8.27
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/build/api.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var t={134:(t,e,n)=>{n.d(e,{A:()=>r});const r={randomUUID:"undefined"!=typeof crypto&&crypto.randomUUID&&crypto.randomUUID.bind(crypto)}},180:(t,e,n)=>{let r;n.d(e,{A:()=>i});const a=new Uint8Array(16);function i(){if(!r){if("undefined"==typeof crypto||!crypto.getRandomValues)throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");r=crypto.getRandomValues.bind(crypto)}return r(a)}},255:(t,e,n)=>{n.d(e,{A:()=>s});var r=n(134),a=n(180),i=n(296);const s=function(t,e,n){return!r.A.randomUUID||e||t?function(t,e,n){const r=(t=t||{}).random??t.rng?.()??(0,a.A)();if(r.length<16)throw new Error("Random bytes length must be >= 16");if(r[6]=15&r[6]|64,r[8]=63&r[8]|128,e){if((n=n||0)<0||n+16>e.length)throw new RangeError(`UUID byte range ${n}:${n+15} is out of buffer bounds`);for(let t=0;t<16;++t)e[n+t]=r[t];return e}return(0,i.k)(r)}(t,e,n):r.A.randomUUID()}},296:(t,e,n)=>{n.d(e,{k:()=>a});const r=[];for(let t=0;t<256;++t)r.push((t+256).toString(16).slice(1));function a(t,e=0){return(r[t[e+0]]+r[t[e+1]]+r[t[e+2]]+r[t[e+3]]+"-"+r[t[e+4]]+r[t[e+5]]+"-"+r[t[e+6]]+r[t[e+7]]+"-"+r[t[e+8]]+r[t[e+9]]+"-"+r[t[e+10]]+r[t[e+11]]+r[t[e+12]]+r[t[e+13]]+r[t[e+14]]+r[t[e+15]]).toLowerCase()}}},e={};function n(r){var a=e[r];if(void 0!==a)return a.exports;var i=e[r]={exports:{}};return t[r](i,i.exports,n),i.exports}n.d=(t,e)=>{for(var r in e)n.o(e,r)&&!n.o(t,r)&&Object.defineProperty(t,r,{enumerable:!0,get:e[r]})},n.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e);var r={};n.d(r,{j:()=>i});var a=n(255);class i{backendUrl="";bestRoute;fallbackConfig;needCache;needBranding=!0;needDomainBrandingFallback=!0;constructor(t,e,n){this.backendUrl=t.endsWith("/")?t.slice(0,t.length-1):t,this.bestRoute=e,this.fallbackConfig=n,this.needCache=!(!n||!e)}get headers(){return{Accept:"application/json;widget-version=4.8.
|
|
1
|
+
var t={134:(t,e,n)=>{n.d(e,{A:()=>r});const r={randomUUID:"undefined"!=typeof crypto&&crypto.randomUUID&&crypto.randomUUID.bind(crypto)}},180:(t,e,n)=>{let r;n.d(e,{A:()=>i});const a=new Uint8Array(16);function i(){if(!r){if("undefined"==typeof crypto||!crypto.getRandomValues)throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");r=crypto.getRandomValues.bind(crypto)}return r(a)}},255:(t,e,n)=>{n.d(e,{A:()=>s});var r=n(134),a=n(180),i=n(296);const s=function(t,e,n){return!r.A.randomUUID||e||t?function(t,e,n){const r=(t=t||{}).random??t.rng?.()??(0,a.A)();if(r.length<16)throw new Error("Random bytes length must be >= 16");if(r[6]=15&r[6]|64,r[8]=63&r[8]|128,e){if((n=n||0)<0||n+16>e.length)throw new RangeError(`UUID byte range ${n}:${n+15} is out of buffer bounds`);for(let t=0;t<16;++t)e[n+t]=r[t];return e}return(0,i.k)(r)}(t,e,n):r.A.randomUUID()}},296:(t,e,n)=>{n.d(e,{k:()=>a});const r=[];for(let t=0;t<256;++t)r.push((t+256).toString(16).slice(1));function a(t,e=0){return(r[t[e+0]]+r[t[e+1]]+r[t[e+2]]+r[t[e+3]]+"-"+r[t[e+4]]+r[t[e+5]]+"-"+r[t[e+6]]+r[t[e+7]]+"-"+r[t[e+8]]+r[t[e+9]]+"-"+r[t[e+10]]+r[t[e+11]]+r[t[e+12]]+r[t[e+13]]+r[t[e+14]]+r[t[e+15]]).toLowerCase()}}},e={};function n(r){var a=e[r];if(void 0!==a)return a.exports;var i=e[r]={exports:{}};return t[r](i,i.exports,n),i.exports}n.d=(t,e)=>{for(var r in e)n.o(e,r)&&!n.o(t,r)&&Object.defineProperty(t,r,{enumerable:!0,get:e[r]})},n.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e);var r={};n.d(r,{j:()=>i});var a=n(255);class i{backendUrl="";bestRoute;fallbackConfig;needCache;needBranding=!0;needDomainBrandingFallback=!0;constructor(t,e,n){this.backendUrl=t.endsWith("/")?t.slice(0,t.length-1):t,this.bestRoute=e,this.fallbackConfig=n,this.needCache=!(!n||!e)}get headers(){return{Accept:"application/json;widget-version=4.8.27"}}get entropySuffix(){return this.bestRoute?.entropy?`?entropy=${(0,a.A)()}`:""}loadCrmWidgetData=async t=>{if(!t)return this.makeError(404,"No crmPlanId!");if(this.bestRoute&&this.fallbackConfig)try{const e=await this.fetchCdn(`/widgets/crm/${t}/v4/plan.json${this.entropySuffix}`);if(e.ok){const n=await e.json();return this.proceedCrmJson(n,t)}}catch{}try{const e=await this.fetchBackend(`/api/crm/plans/${t}/v4/widget?cache=${this.needCache?1:0}`);if(e.ok){const n=await e.json();return this.proceedCrmJson(n,t)}return this.makeErrorFromResponse(e,"Failed to get CRM Plan widget data!")}catch(t){return this.makeError(520,t.message)}};loadWidgetData=async t=>{if(!t)return this.makeError(404,"No planId!");if(this.bestRoute&&this.fallbackConfig)try{const e=await this.fetchCdn(`/widgets/services/${t}/v4/plan.json${this.entropySuffix}`);if(e.ok){const n=await e.json();return this.proceedServiceJson(n,t)}}catch{}try{const e=await this.fetchBackend(`/api/plans/${t}/v4/widget?cache=${this.needCache?1:0}`);if(e.ok){const n=await e.json();return this.proceedServiceJson(n,t)}return this.makeErrorFromResponse(e,"Failed to get Plan widget data!")}catch(t){return this.makeError(520,t.message)}};proceedCrmJson(t,e){return this.proceedJson({...t,is_crm:!0,crm_plan_id:e})}proceedServiceJson(t,e){return this.proceedJson({...t,is_crm:!1,plan_id:e})}async proceedJson(t){return await this.replaceCdnUrls(t),await this.proceedBranding(t),t}async replaceCdnUrls(t){const{bestRoute:e,fallbackConfig:n}=this;if(!e||!n)return t;const r=t=>{if(!t)return"";const r=(t=>{const e=n.keyExtraction?.patterns??[];for(let n=0,r=e.length;n<r;n++){const r=t.match(e[n].re);if(null!=r)return r[1]}return""})(t);return r?e.template.replace(/\{key\}/,r):t??""};t.variants.forEach((t=>{t.assets_path=r(t.assets_path),t.json=r(t.json),t.floors.forEach((t=>{t.original_plan_img=r(t.original_plan_img),t.miniplan_img=r(t.miniplan_img)}))}))}async proceedBranding(t){if(!this.needBranding)return t;const{primary_widget_branding_id:e}=t;if(null!=e){try{const n=await this.fetchCdn(`/widgets/brandings/id/${e}/branding.json${this.entropySuffix}`);n.ok&&(t.widget_branding=await n.json())}catch{}if(null==t.widget_branding)try{const n=await this.fetchBackend(`/api/plans/widget_branding/${e}`);n.ok&&(t.widget_branding=await n.json())}catch{}}if(null==t.widget_branding&&this.needDomainBrandingFallback){const e=window.location.hostname;try{const n=await this.fetchCdn(`/widgets/brandings/domain/${e}/branding.json${this.entropySuffix}`);n.ok&&(t.widget_branding=await n.json())}catch{}if(null==t.widget_branding)try{const e=await this.fetchBackend("/api/plans/widget_branding");e.ok&&(t.widget_branding=await e.json())}catch{}}}fetchCdn=(t,e={headers:this.headers})=>{let n=this.bestRoute?this.bestRoute.template.replace(/\{key\}/,""):"";return n.endsWith("/")&&(n=n.slice(0,n.length-1)),fetch(`${n}${t}`,e)};fetchBackend=(t,e={headers:this.headers})=>fetch(`${this.backendUrl}${t}`,e);makeError(t,e="Unknown error"){return{error:{status:t,message:e}}}async makeErrorFromResponse(t,e){if("application/json"===t.headers.get("Content-Type")){const e=await t.json();if("message"in e&&"string"==typeof e.message)return this.makeError(t.status,e.message)}return this.makeError(t.status,e)}}const s=r.j;export{s as Api};
|