@vizzly/services 0.15.0-dev-bb4061ed3ad2a0224e701421cc1b3d785de99536 → 0.15.0-dev-572b4889849d49b78a4434312ade1b0996a72c7f
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/cjs/index.cjs.js
CHANGED
|
@@ -133,4 +133,4 @@ For example, this should be added within the <head> tag;
|
|
|
133
133
|
<script src="https://static.app.vizzly.co/query-engine/0.8.29/vizzly-in-memory-db.umd.js"><\/script>
|
|
134
134
|
|
|
135
135
|
Note, you can change the version of the in-memory database by changing '0.8.3' to the version you require.
|
|
136
|
-
`);return t},VB=async(t,e)=>{if("measure"in t&&t.measure.length===0)return[[]];const o={id:e.id,fields:e.fields.map(b=>({id:b.id,address:["_",e.id,b.id],dataType:b.dataType})),joins:[]};return(await pO().queryV2(t,o))?.[0]?.values||[]},rf=(t,e)=>`${t}::${e}`,HB=async(t,e,o)=>{const n=[...t].map(async a=>{const[O]=Zd(e,a.dataSetId),A=rf(o,a.dataSetId);return Ua[A]&&O?{content:await VB(a,O),hasMoreResults:!1}:(console.warn("Returning an empty result."),{content:[],hasMoreResults:null})});return{results:await Promise.all(n)}},YB=async(t,e,o,n)=>(await pO().init(e.map(b=>({id:b?.id,fields:b?.fields.map(a=>({id:a.id,dataType:a.dataType}))}))),await Promise.all([...t].flatMap(async b=>{const[a]=Zd(e,b.dataSetId);if(a){const O=await UB(a,o,rf(n,b.dataSetId)),A={id:a?.id,fields:a?.fields.map(c=>({id:c.id,dataType:c.dataType}))};await pO().ingest(A,O||[])}return[]})),await HB(t,e,n)),KB=async(t,e,o)=>{const{queries:n,resultFields:b}=KO(e,rO,o);let a=await QO(n,A=>!0,async A=>await YB(A,o.dataSets,t.loadData,t.cacheKeyNamespace),A=>({query:A,cacheKeyNamespace:t.cacheKeyNamespace}));return a===null&&(a=n.map(()=>null)),[...n].map((A,c)=>{if(a===null)return null;const y=a[c];return y==null?null:{content:y.content,fields:b[c],hasMoreResults:y.hasMoreResults}})},QB=async(t,e,o)=>{const{queries:n,resultFields:b}=KO(e,t.queryEngineConfig,o),a=await QO(n,O=>(O.type=="preparedQuery"&&SA("Custom query engine does not support prepared queries."),O.type=="query"),async O=>{const A=await t.runQueries(O,{...o,dataAccessToken:t.dataAccessToken});return A==null?{results:O.map(()=>null)}:{results:A.map((c,y)=>Array.isArray(c)?{fields:b[y],content:c,hasMoreResults:null}:c)}},O=>({query:O,cacheKeyNamespace:t.cacheKeyNamespace}));return a===null?n.map(()=>null):a};async function Ds(t,e,o){return t.type=="vizzlyQueryEngine"?await MB(t,e,o):t.type=="vizzlyJsQueryEngine"?await KB(t,e,o):t.type=="custom"?await QB(t,e,o):[]}const ZB=(t,e,o,n,b,a,O,A,c)=>{let y=E7(t.dashboardAccess);if(a)return async(v,N)=>await Ds({type:"custom",queryEngineConfig:e,runQueries:a,dataAccessToken:t.dataAccess?.signature,cacheKeyNamespace:y},v,{abortSignal:N.abortSignal,dataSets:N.dataSets,filterConfig:N.filterConfig||{},timeRangeOptions:o,timeZone:c,variables:n,aliasFields:b});if(O)return async(v,N)=>await Ds({type:"vizzlyJsQueryEngine",loadData:O,cacheKeyNamespace:y},v,{abortSignal:N.abortSignal,dataSets:N.dataSets,filterConfig:N.filterConfig||{},timeRangeOptions:o,timeZone:c,variables:n,aliasFields:b});if(A&&t.dataAccess?.signature)return async(v,N)=>await Ds({type:"vizzlyQueryEngine",queryEngineConfig:e,dataAccessToken:t.dataAccess?.signature,queryEngineEndpoint:A,cacheKeyNamespace:y},v,{abortSignal:N.abortSignal,dataSets:N.dataSets,filterConfig:N.filterConfig||{},timeRangeOptions:o,timeZone:c,variables:n,aliasFields:b});throw"Missing required props."},JB=(t,e)=>{const o=new Date(t.getTime()-e*24*60*60*1e3);return new Date(o.getFullYear(),o.getMonth(),o.getDate())},aO=t=>new Date(t.getFullYear(),t.getMonth(),t.getDate()),Is={today:!1,past_1_day:!0,yesterday:!0,past_3_days:!0,past_7_days:!0,past_30_days:!0,past_90_days:!0,past_3_months:!1,past_6_months:!1,past_12_months:!1,past_18_months:!1},eS=(t,e)=>{const o=aO(t),n=new Date(o);return n.setDate(n.getDate()+1),n.setMilliseconds(n.getMilliseconds()-1),{description:e,range:{before:n,after:o}}},tS=(t,e)=>({description:e,range:{before:aO(t),after:aO(JB(t,1))}}),io=(t,e,o)=>{const n=new Date;let b=new Date(n);return e>0&&b.setMonth(n.getMonth()-e),t>0&&(b=new Date(n.getTime()-t*24*60*60*1e3)),{description:o,range:{before:n,after:b}}},oS=t=>({today:eS(new Date,t("filter.today","Today")),past_1_day:io(1,0,t("filter.past_1_day","Last 24 hours")),yesterday:tS(new Date,t("filter.yesterday","Yesterday")),past_3_days:io(3,0,t("filter.past_3_days","Last 3 days")),past_7_days:io(7,0,t("filter.past_7_days","Last 7 days")),past_30_days:io(30,0,t("filter.past_30_days","Last 30 days")),past_90_days:io(90,0,t("filter.past_90_days","Last 90 days")),past_3_months:io(0,3,t("filter.past_3_months","Last 3 months")),past_6_months:io(0,6,t("filter.past_6_months","Last 6 months")),past_12_months:io(0,12,t("filter.past_12_months","Last 12 months")),past_18_months:io(0,18,t("filter.past_18_months","Last 18 months"))}),rS=(t,e)=>{const o=oS(t),n=Object.keys(Is).map(A=>A in o?`_vizzly_${A}`:A),b=n.indexOf("_vizzly_today");b>-1&&(n.splice(b,1),n.unshift("_vizzly_today"));let a={},O={};for(const A of n){const c=A.replace("_vizzly_",""),y=o[c],v=e?.[c];typeof v=="boolean"?v&&(O[A]=y):v!=null?O[A]=v:Is[c]!==!1&&(O[A]=y)}if(e)for(const[A,c]of Object.entries(e))A in Is||(n.push(A),O[A]=c);for(const A of n)A in O&&(a[A]=O[A]);return a},nS=(t,e)=>{const o=q7(t);if(o&&e.dashboardAccess.scope==="read")return{type:"exact",globalLibrary:o};if(o&&e.dashboardAccess.scope==="read_write"&&e.dashboardAccess.accessType!=="admin")return{type:"exact",globalLibrary:f7(t)[0]};if(o&&e.dashboardAccess.accessType==="admin")return{type:"exact",globalLibrary:o};throw"No strategy found."},ji="default";v2.VizzlyApiClientLogger.UserAgentProduct="Services";const iS={apiHost:"https://api.vizzly.co"},bS={...iS};class Vo{static{this._instanceStore={}}static{this.DEFAULT_INSTANCE_ID=ji}static{this.eventBus=[]}constructor(e,o,n,b,a,O){this.programmaticDashboard=a,this.dataSets=n,this.queryEngineConfig=o,this.identityConfig=e,this.vizzlyAPIClient=Rm(e,b,O)}getDataSets(){return this.dataSets}static async load(e,o=bS){G1("Starting load process for the services package.");const{queryEngine:n,dataSets:b,identity:a,programmaticDashboard:O,extraCustomFields:A}=e,c=new H7(n,a,b,A,o),{queryEngineConfig:y,dataSets:v,identityConfig:N,dashboardStorageStrategy:s}=await c.load(),u=new Ie(N,y,v,s,O,{host:o.apiHost});return Ie._instanceStore[ji]=u,Ie.queryEngine=n,G1("Loaded services package and added it to the instance store."),u}static use(e=ji){const o=Ie._instanceStore[e];if(!o)throw new Zu(e);return o}static async waitToUse(e=ji,o=1e4){const n=Vo._instanceStore,b=e;return new Promise((a,O)=>{if(n.hasOwnProperty(b)){a(n[b]);return}const A=setTimeout(()=>{clearTimeout(A),O(new yT(e,o))},o),c=setInterval(()=>{n.hasOwnProperty(b)&&(clearTimeout(A),clearInterval(c),a(n[b]))},10)})}static clearInstances(){Ie._instanceStore={}}async createDashboard(e){RT(e,this.queryEngineConfig);const n=this.vizzlyAPIClient.getDashboardManager(),{dashboard:b}=await n.create({metadata:e.metadata||e.meta,definition:e.definition,parentDashboardId:e.parentDashboardId,permissions:[{scope:"read_write"}],usage_metadata:e.definition?kl(e.definition,this.dataSets):void 0}),a=Ts(b,this.queryEngineConfig);return Pa(a,this.dataSets,b.definition?.customFields||{})}async updateDashboard(e){LT(e,this.queryEngineConfig);const b=await this.vizzlyAPIClient.getDashboardManager().update({dashboardId:e.dashboardId,metadata:e.metadata||e.meta,definition:e.definition,deleted:e.deleted,abortSignal:e.abortSignal,name:e.name,usage_metadata:e.definition?kl(e.definition,this.dataSets):void 0}),a=Ts(b,this.queryEngineConfig);return Pa(a,this.dataSets,b.definition?.customFields||{})}async updateScheduledReport(e,o,n){const a=await this.vizzlyAPIClient.getAPIs().vizzlyApi.saveScheduledReport({scheduledReportId:o,cronSchedule:n,dashboardAccessToken:e});if(a.status===200)return n===null?!0:a.body}async getScheduledReports(e){if(this.vizzlyAPIClient){const n=await this.vizzlyAPIClient.getAPIs().vizzlyApi.getScheduledReports({dashboardAccessToken:e});if(n.status===200)return n.body}return{reports:[]}}async getDashboards(e){const a=(await this.vizzlyAPIClient.getDashboardManager().getDashboards(e?.abortController?{abortSignal:e?.abortController.signal}:{})).flatMap(O=>Vo.upcastDashboard(O,this.dataSets,this.queryEngineConfig));return this.programmaticDashboard?M7(a,b7(await this.programmaticDashboard(this.dataSets),this.dataSets)):a}async createGlobalLibrary(e){return await this.vizzlyAPIClient.getGlobalLibraryManager().create(e)}async getGlobalLibraries(e){const b=await this.vizzlyAPIClient.getGlobalLibraryManager().getGlobalLibraries(e?.abortController?{abortSignal:e?.abortController.signal}:{});this.globalLibraryPermissions=b.permissions;const a=b.global_libraries.map(A=>c7(A));return[nS(a,this.getIdentityConfig()).globalLibrary]}getViewConfiguration(){return{queryEngineConfig:this.queryEngineConfig}}getIdentityConfig(){return this.identityConfig}async query(e,o){G1("[Services] Querying data with queries:",e);let n=ji;o?.instanceId&&(n=o.instanceId);const b=Vo._instanceStore[n],a=ZB(b.identityConfig,b.queryEngineConfig,rS(_N,o?.dateFilterOptions),o?.variables||{},o?.aliasFields||{},o?.runQueries,o?.data,o?.queryEngineEndpoint);return{results:await(async()=>{try{return await a(e,{abortSignal:o?.abortController?.signal,dataSets:this.dataSets,filterConfig:o?.filterConfig})}catch(A){return At("[Services] Error fetching data on query:",A),null}})()}}static upcastDashboard(e,o,n){try{const b=Ts(e,n);return[Pa(b,o,e.definition?.customFields||{})]}catch(b){return At(`Failed to upcast dashboard ${e.id}. This dashboard will not be available for use.`,b),[]}}static filterDashboards(e,o){let n=P0.cloneDeep(e);return o.onlyParentDashboards&&(n=n.filter(b=>b.parentDashboardId===null)),o.onlyChildDashboards&&(n=n.filter(b=>b.parentDashboardId!==null)),o.onlyChildDashboardsForParent&&(n=n.filter(b=>b.parentDashboardId===o.onlyChildDashboardsForParent)),o.onlyAllowScope&&(n=n.filter(b=>b.permission?.scope===o.onlyAllowScope)),o.onlyDashboardsIncludingMetadata&&(n=n.filter(b=>{const a=Object.keys(o.onlyDashboardsIncludingMetadata||{});return P0.every(a,O=>b.metadata[O]===o?.onlyDashboardsIncludingMetadata?.[O])})),n}async updateGlobalLibrary(e){try{return await this.vizzlyAPIClient.getGlobalLibraryManager().update(e)}catch(o){At("Error updating global library:",o)}}static async eventBusController(e,o){try{const n=Vo.use();if((e.action==="addComponentToLibrary"||e.action==="deleteComponentFromLibrary")&&n.globalLibraryPermissions){Ie.publish({data:{action:"updateToGlobalLibraryStatus",state:ja.SAVING}});const[b]=await Promise.all([await n.getGlobalLibraries({abortController:o?.abortController})]);let a=VO(b);e.action==="addComponentToLibrary"&&(a=O7(b,e.component,e.customFields)),e.action==="deleteComponentFromLibrary"&&(a=d7(b,e.component));const O=s7(n.globalLibraryPermissions,[a]);B6("library and tokens for update",{libraryForUpdate:a,tokenForLibrary:O});const A={globalLibraryId:a.id,library:a.library,abortSignal:o?.abortController?.signal,globalLibrarySessionToken:O};if(await n.updateGlobalLibrary(A)){let y=ja.SAVED;e.action==="deleteComponentFromLibrary"&&(y=ja.DELETED),Ie.publish({data:{action:"newViewsInGlobalLibrary"}}),Ie.publish({data:{action:"updateToGlobalLibraryStatus",state:y}})}}}catch(n){At("Error handling event:",n)}}static publish(e){Ie.eventBus.map(o=>{o(e)}),Ie.eventBusController(e.data).catch(o=>{At("Failed to handle event:",o)})}static subscription(e){return Ie.eventBus.push(e),()=>{Ie.eventBus=Ie.eventBus.filter(o=>o!==e)}}static{this.Row=Ku}static{this.Cell=iO}static{this.Dashboard=Q7}static{this.Editor=J7}static{this.Header=Qu}static{this.Library=Z7}static{this.AreaChart=eT}static{this.AreaChartV2=tT}static{this.LineChart=oT}static{this.LineChartV2=rT}static{this.BarChart=nT}static{this.BarChartV2=iT}static{this.PieChart=bT}static{this.BubbleChart=pT}static{this.BubbleChartV2=aT}static{this.ScatterChart=zT}static{this.ComboChart=cT}static{this.ComboChartV2=sT}static{this.PivotTable=OT}static{this.BasicTable=lT}static{this.HorizontalBarChart=AT}static{this.HorizontalBarChartV2=dT}static{this.MercatorMap=uT}static{this.SingleStat=fT}static{this.Progress=qT}static{this.RichText=WT}static{this.WaterfallChart=hT}static{this.FunnelChart=gT}static{this.SunburstChart=MT}static{this.RadarChart=mT}}typeof window<"u"&&!window.Vizzly&&(window.Vizzly=Vo);const Ie=typeof window<"u"&&window.Vizzly||Vo;exports.Vizzly=Ie;exports.VizzlyInstanceNotLoaded=Zu;
|
|
136
|
+
`);return t},VB=async(t,e)=>{if("measure"in t&&t.measure.length===0)return[[]];const o={id:e.id,fields:e.fields.map(b=>({id:b.id,address:["_",e.id,b.id],dataType:b.dataType})),joins:[]};return(await pO().queryV2(t,o))?.[0]?.values||[]},rf=(t,e)=>`${t}::${e}`,HB=async(t,e,o)=>{const n=[...t].map(async a=>{const[O]=Zd(e,a.dataSetId),A=rf(o,a.dataSetId);return Ua[A]&&O?{content:await VB(a,O),hasMoreResults:!1}:(console.warn("Returning an empty result."),{content:[],hasMoreResults:null})});return{results:await Promise.all(n)}},YB=async(t,e,o,n)=>(await pO().init(e.map(b=>({id:b?.id,fields:b?.fields.map(a=>({id:a.id,dataType:a.dataType}))}))),await Promise.all([...t].flatMap(async b=>{const[a]=Zd(e,b.dataSetId);if(a){const O=await UB(a,o,rf(n,b.dataSetId)),A={id:a?.id,fields:a?.fields.map(c=>({id:c.id,dataType:c.dataType}))};await pO().ingest(A,O||[])}return[]})),await HB(t,e,n)),KB=async(t,e,o)=>{const{queries:n,resultFields:b}=KO(e,rO,o);let a=await QO(n,A=>!0,async A=>await YB(A,o.dataSets,t.loadData,t.cacheKeyNamespace),A=>({query:A,cacheKeyNamespace:t.cacheKeyNamespace}));return a===null&&(a=n.map(()=>null)),[...n].map((A,c)=>{if(a===null)return null;const y=a[c];return y==null?null:{content:y.content,fields:b[c],hasMoreResults:y.hasMoreResults}})},QB=async(t,e,o)=>{const{queries:n,resultFields:b}=KO(e,t.queryEngineConfig,o),a=await QO(n,O=>(O.type=="preparedQuery"&&SA("Custom query engine does not support prepared queries."),O.type=="query"),async O=>{const A=await t.runQueries(O,{...o,dataAccessToken:t.dataAccessToken});return A==null?{results:O.map(()=>null)}:{results:A.map((c,y)=>Array.isArray(c)?{fields:b[y],content:c,hasMoreResults:null}:c)}},O=>({query:O,cacheKeyNamespace:t.cacheKeyNamespace}));return a===null?n.map(()=>null):a};async function Ds(t,e,o){return t.type=="vizzlyQueryEngine"?await MB(t,e,o):t.type=="vizzlyJsQueryEngine"?await KB(t,e,o):t.type=="custom"?await QB(t,e,o):[]}const ZB=(t,e,o,n,b,a,O,A,c)=>{let y=E7(t.dashboardAccess);if(a)return async(v,N)=>await Ds({type:"custom",queryEngineConfig:e,runQueries:a,dataAccessToken:t.dataAccess?.signature,cacheKeyNamespace:y},v,{abortSignal:N.abortSignal,dataSets:N.dataSets,filterConfig:N.filterConfig||{},timeRangeOptions:o,timeZone:c,variables:n,aliasFields:b});if(O)return async(v,N)=>await Ds({type:"vizzlyJsQueryEngine",loadData:O,cacheKeyNamespace:y},v,{abortSignal:N.abortSignal,dataSets:N.dataSets,filterConfig:N.filterConfig||{},timeRangeOptions:o,timeZone:c,variables:n,aliasFields:b});if(A&&t.dataAccess?.signature)return async(v,N)=>await Ds({type:"vizzlyQueryEngine",queryEngineConfig:e,dataAccessToken:t.dataAccess?.signature,queryEngineEndpoint:A,cacheKeyNamespace:y},v,{abortSignal:N.abortSignal,dataSets:N.dataSets,filterConfig:N.filterConfig||{},timeRangeOptions:o,timeZone:c,variables:n,aliasFields:b});throw"Missing required props."},JB=(t,e)=>{const o=new Date(t.getTime()-e*24*60*60*1e3);return new Date(o.getFullYear(),o.getMonth(),o.getDate())},aO=t=>new Date(t.getFullYear(),t.getMonth(),t.getDate()),Is={today:!1,past_1_day:!0,yesterday:!0,past_3_days:!0,past_7_days:!0,past_30_days:!0,past_90_days:!0,past_3_months:!1,past_6_months:!1,past_12_months:!1,past_18_months:!1},eS=(t,e)=>{const o=aO(t),n=new Date(o);return n.setDate(n.getDate()+1),n.setMilliseconds(n.getMilliseconds()-1),{description:e,range:{before:n,after:o}}},tS=(t,e)=>({description:e,range:{before:aO(t),after:aO(JB(t,1))}}),io=(t,e,o)=>{const n=new Date;let b=new Date(n);return e>0&&b.setMonth(n.getMonth()-e),t>0&&(b=new Date(n.getTime()-t*24*60*60*1e3)),{description:o,range:{before:n,after:b}}},oS=t=>({today:eS(new Date,t("filter.today","Today")),past_1_day:io(1,0,t("filter.past_1_day","Last 24 hours")),yesterday:tS(new Date,t("filter.yesterday","Yesterday")),past_3_days:io(3,0,t("filter.past_3_days","Last 3 days")),past_7_days:io(7,0,t("filter.past_7_days","Last 7 days")),past_30_days:io(30,0,t("filter.past_30_days","Last 30 days")),past_90_days:io(90,0,t("filter.past_90_days","Last 90 days")),past_3_months:io(0,3,t("filter.past_3_months","Last 3 months")),past_6_months:io(0,6,t("filter.past_6_months","Last 6 months")),past_12_months:io(0,12,t("filter.past_12_months","Last 12 months")),past_18_months:io(0,18,t("filter.past_18_months","Last 18 months"))}),rS=(t,e)=>{const o=oS(t),n=Object.keys(Is).map(A=>A in o?`_vizzly_${A}`:A),b=n.indexOf("_vizzly_today");b>-1&&(n.splice(b,1),n.unshift("_vizzly_today"));let a={},O={};for(const A of n){const c=A.replace("_vizzly_",""),y=o[c],v=e?.[c];typeof v=="boolean"?v&&(O[A]=y):v!=null?O[A]=v:Is[c]!==!1&&(O[A]=y)}if(e)for(const[A,c]of Object.entries(e))A in Is||(n.push(A),O[A]=c);for(const A of n)A in O&&(a[A]=O[A]);return a},nS=(t,e)=>{const o=q7(t);if(o&&e.dashboardAccess.scope==="read")return{type:"exact",globalLibrary:o};if(o&&e.dashboardAccess.scope==="read_write"&&e.dashboardAccess.accessType!=="admin")return{type:"exact",globalLibrary:f7(t)[0]};if(o&&e.dashboardAccess.accessType==="admin")return{type:"exact",globalLibrary:o};throw"No strategy found."},ji="default";v2.VizzlyApiClientLogger.UserAgentProduct="Services";const iS={apiHost:"https://api.vizzly.co"};class Vo{static{this._instanceStore={}}static{this.DEFAULT_INSTANCE_ID=ji}static{this.eventBus=[]}constructor(e,o,n,b,a,O){this.programmaticDashboard=a,this.dataSets=n,this.queryEngineConfig=o,this.identityConfig=e,this.vizzlyAPIClient=Rm(e,b,O)}getDataSets(){return this.dataSets}static async load(e,o=iS){G1("Starting load process for the services package.");const{queryEngine:n,dataSets:b,identity:a,programmaticDashboard:O,extraCustomFields:A}=e,c=new H7(n,a,b,A,o),{queryEngineConfig:y,dataSets:v,identityConfig:N,dashboardStorageStrategy:s}=await c.load(),u=new Ie(N,y,v,s,O,{host:o.apiHost});return Ie._instanceStore[o.instanceId||ji]=u,Ie.queryEngine=n,G1("Loaded services package and added it to the instance store."),u}static use(e=ji){const o=Ie._instanceStore[e];if(!o)throw new Zu(e);return o}static async waitToUse(e=ji,o=1e4){const n=Vo._instanceStore,b=e;return new Promise((a,O)=>{if(n.hasOwnProperty(b)){a(n[b]);return}const A=setTimeout(()=>{clearTimeout(A),O(new yT(e,o))},o),c=setInterval(()=>{n.hasOwnProperty(b)&&(clearTimeout(A),clearInterval(c),a(n[b]))},10)})}static clearInstances(){Ie._instanceStore={}}async createDashboard(e){RT(e,this.queryEngineConfig);const n=this.vizzlyAPIClient.getDashboardManager(),{dashboard:b}=await n.create({metadata:e.metadata||e.meta,definition:e.definition,parentDashboardId:e.parentDashboardId,permissions:[{scope:"read_write"}],usage_metadata:e.definition?kl(e.definition,this.dataSets):void 0}),a=Ts(b,this.queryEngineConfig);return Pa(a,this.dataSets,b.definition?.customFields||{})}async updateDashboard(e){LT(e,this.queryEngineConfig);const b=await this.vizzlyAPIClient.getDashboardManager().update({dashboardId:e.dashboardId,metadata:e.metadata||e.meta,definition:e.definition,deleted:e.deleted,abortSignal:e.abortSignal,name:e.name,usage_metadata:e.definition?kl(e.definition,this.dataSets):void 0}),a=Ts(b,this.queryEngineConfig);return Pa(a,this.dataSets,b.definition?.customFields||{})}async updateScheduledReport(e,o,n){const a=await this.vizzlyAPIClient.getAPIs().vizzlyApi.saveScheduledReport({scheduledReportId:o,cronSchedule:n,dashboardAccessToken:e});if(a.status===200)return n===null?!0:a.body}async getScheduledReports(e){if(this.vizzlyAPIClient){const n=await this.vizzlyAPIClient.getAPIs().vizzlyApi.getScheduledReports({dashboardAccessToken:e});if(n.status===200)return n.body}return{reports:[]}}async getDashboards(e){const a=(await this.vizzlyAPIClient.getDashboardManager().getDashboards(e?.abortController?{abortSignal:e?.abortController.signal}:{})).flatMap(O=>Vo.upcastDashboard(O,this.dataSets,this.queryEngineConfig));return this.programmaticDashboard?M7(a,b7(await this.programmaticDashboard(this.dataSets),this.dataSets)):a}async createGlobalLibrary(e){return await this.vizzlyAPIClient.getGlobalLibraryManager().create(e)}async getGlobalLibraries(e){const b=await this.vizzlyAPIClient.getGlobalLibraryManager().getGlobalLibraries(e?.abortController?{abortSignal:e?.abortController.signal}:{});this.globalLibraryPermissions=b.permissions;const a=b.global_libraries.map(A=>c7(A));return[nS(a,this.getIdentityConfig()).globalLibrary]}getViewConfiguration(){return{queryEngineConfig:this.queryEngineConfig}}getIdentityConfig(){return this.identityConfig}async query(e,o){G1("[Services] Querying data with queries:",e);let n=ji;o?.instanceId&&(n=o.instanceId);const b=Vo._instanceStore[n],a=ZB(b.identityConfig,b.queryEngineConfig,rS(_N,o?.dateFilterOptions),o?.variables||{},o?.aliasFields||{},o?.runQueries,o?.data,o?.queryEngineEndpoint);return{results:await(async()=>{try{return await a(e,{abortSignal:o?.abortController?.signal,dataSets:this.dataSets,filterConfig:o?.filterConfig})}catch(A){return At("[Services] Error fetching data on query:",A),null}})()}}static upcastDashboard(e,o,n){try{const b=Ts(e,n);return[Pa(b,o,e.definition?.customFields||{})]}catch(b){return At(`Failed to upcast dashboard ${e.id}. This dashboard will not be available for use.`,b),[]}}static filterDashboards(e,o){let n=P0.cloneDeep(e);return o.onlyParentDashboards&&(n=n.filter(b=>b.parentDashboardId===null)),o.onlyChildDashboards&&(n=n.filter(b=>b.parentDashboardId!==null)),o.onlyChildDashboardsForParent&&(n=n.filter(b=>b.parentDashboardId===o.onlyChildDashboardsForParent)),o.onlyAllowScope&&(n=n.filter(b=>b.permission?.scope===o.onlyAllowScope)),o.onlyDashboardsIncludingMetadata&&(n=n.filter(b=>{const a=Object.keys(o.onlyDashboardsIncludingMetadata||{});return P0.every(a,O=>b.metadata[O]===o?.onlyDashboardsIncludingMetadata?.[O])})),n}async updateGlobalLibrary(e){try{return await this.vizzlyAPIClient.getGlobalLibraryManager().update(e)}catch(o){At("Error updating global library:",o)}}static async eventBusController(e,o){try{const n=Vo.use();if((e.action==="addComponentToLibrary"||e.action==="deleteComponentFromLibrary")&&n.globalLibraryPermissions){Ie.publish({data:{action:"updateToGlobalLibraryStatus",state:ja.SAVING}});const[b]=await Promise.all([await n.getGlobalLibraries({abortController:o?.abortController})]);let a=VO(b);e.action==="addComponentToLibrary"&&(a=O7(b,e.component,e.customFields)),e.action==="deleteComponentFromLibrary"&&(a=d7(b,e.component));const O=s7(n.globalLibraryPermissions,[a]);B6("library and tokens for update",{libraryForUpdate:a,tokenForLibrary:O});const A={globalLibraryId:a.id,library:a.library,abortSignal:o?.abortController?.signal,globalLibrarySessionToken:O};if(await n.updateGlobalLibrary(A)){let y=ja.SAVED;e.action==="deleteComponentFromLibrary"&&(y=ja.DELETED),Ie.publish({data:{action:"newViewsInGlobalLibrary"}}),Ie.publish({data:{action:"updateToGlobalLibraryStatus",state:y}})}}}catch(n){At("Error handling event:",n)}}static publish(e){Ie.eventBus.map(o=>{o(e)}),Ie.eventBusController(e.data).catch(o=>{At("Failed to handle event:",o)})}static subscription(e){return Ie.eventBus.push(e),()=>{Ie.eventBus=Ie.eventBus.filter(o=>o!==e)}}static{this.Row=Ku}static{this.Cell=iO}static{this.Dashboard=Q7}static{this.Editor=J7}static{this.Header=Qu}static{this.Library=Z7}static{this.AreaChart=eT}static{this.AreaChartV2=tT}static{this.LineChart=oT}static{this.LineChartV2=rT}static{this.BarChart=nT}static{this.BarChartV2=iT}static{this.PieChart=bT}static{this.BubbleChart=pT}static{this.BubbleChartV2=aT}static{this.ScatterChart=zT}static{this.ComboChart=cT}static{this.ComboChartV2=sT}static{this.PivotTable=OT}static{this.BasicTable=lT}static{this.HorizontalBarChart=AT}static{this.HorizontalBarChartV2=dT}static{this.MercatorMap=uT}static{this.SingleStat=fT}static{this.Progress=qT}static{this.RichText=WT}static{this.WaterfallChart=hT}static{this.FunnelChart=gT}static{this.SunburstChart=MT}static{this.RadarChart=mT}}typeof window<"u"&&!window.Vizzly&&(window.Vizzly=Vo);const Ie=typeof window<"u"&&window.Vizzly||Vo;exports.Vizzly=Ie;exports.VizzlyInstanceNotLoaded=Zu;
|
package/dist/esm/index.esm.js
CHANGED
|
@@ -29295,8 +29295,6 @@ const ZB = (t, e, o, n, b, a, O, A, c) => {
|
|
|
29295
29295
|
v2.VizzlyApiClientLogger.UserAgentProduct = "Services";
|
|
29296
29296
|
const iS = {
|
|
29297
29297
|
apiHost: "https://api.vizzly.co"
|
|
29298
|
-
}, bS = {
|
|
29299
|
-
...iS
|
|
29300
29298
|
};
|
|
29301
29299
|
class Vo {
|
|
29302
29300
|
static {
|
|
@@ -29319,7 +29317,7 @@ class Vo {
|
|
|
29319
29317
|
* @param options
|
|
29320
29318
|
* @returns Vizzly instance for programmatically managing dashboards.
|
|
29321
29319
|
*/
|
|
29322
|
-
static async load(e, o =
|
|
29320
|
+
static async load(e, o = iS) {
|
|
29323
29321
|
G1("Starting load process for the services package.");
|
|
29324
29322
|
const {
|
|
29325
29323
|
queryEngine: n,
|
|
@@ -29337,7 +29335,7 @@ class Vo {
|
|
|
29337
29335
|
host: o.apiHost
|
|
29338
29336
|
}
|
|
29339
29337
|
);
|
|
29340
|
-
return $e._instanceStore[ji] = u, $e.queryEngine = n, G1("Loaded services package and added it to the instance store."), u;
|
|
29338
|
+
return $e._instanceStore[o.instanceId || ji] = u, $e.queryEngine = n, G1("Loaded services package and added it to the instance store."), u;
|
|
29341
29339
|
}
|
|
29342
29340
|
static use(e = ji) {
|
|
29343
29341
|
const o = $e._instanceStore[e];
|
|
@@ -22,9 +22,6 @@ export type { ViewConfiguration } from 'shared-logic/src/ViewConfiguration/types
|
|
|
22
22
|
export { VizzlyInstanceNotLoaded } from './errors/VizzlyInstanceNotLoaded';
|
|
23
23
|
import { CustomField } from '../../shared-logic/src/CustomField/types';
|
|
24
24
|
import { AliasFields } from 'shared-logic/src/AliasFields/types';
|
|
25
|
-
export type Options = {
|
|
26
|
-
apiHost: string;
|
|
27
|
-
};
|
|
28
25
|
export type FilterDashboardOptions = {
|
|
29
26
|
onlyAllowScope?: 'read' | 'read_write';
|
|
30
27
|
onlyChildDashboardsForParent?: string;
|
package/package.json
CHANGED
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
"fix-type-alias": "tsc-alias -p tsconfig.types.json",
|
|
32
32
|
"prepare": "yarn build"
|
|
33
33
|
},
|
|
34
|
-
"version": "0.15.0-dev-
|
|
34
|
+
"version": "0.15.0-dev-572b4889849d49b78a4434312ade1b0996a72c7f",
|
|
35
35
|
"dependencies": {
|
|
36
36
|
"@vizzly/api-client": "0.0.57",
|
|
37
37
|
"@vizzly/joi": "^17.11.0",
|