@nyaruka/temba-components 0.52.0 → 0.52.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -4,8 +4,14 @@ All notable changes to this project will be documented in this file. Dates are d
4
4
 
5
5
  Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
6
6
 
7
+ #### [v0.52.1](https://github.com/nyaruka/temba-components/compare/v0.52.0...v0.52.1)
8
+
9
+ - Add option to clear cache on store without resetting [`#334`](https://github.com/nyaruka/temba-components/pull/334)
10
+
7
11
  #### [v0.52.0](https://github.com/nyaruka/temba-components/compare/v0.51.1...v0.52.0)
8
12
 
13
+ > 18 May 2023
14
+
9
15
  - Add Resizer [`#333`](https://github.com/nyaruka/temba-components/pull/333)
10
16
  - merge [`0566c26`](https://github.com/nyaruka/temba-components/commit/0566c26af83273e699ea0414291d4436b8c4e54e)
11
17
 
@@ -489,7 +489,7 @@ function t(t,e,i,n){var o,s=arguments.length,r=s<3?e:null===n?n=Object.getOwnPro
489
489
  width: 100%;
490
490
  top: 0.5em;
491
491
  }
492
- `}getLocale(){return this.locale[0]}reset(){this.cache=Se(this.max,this.ttl),this.settings=JSON.parse(fe("settings")||"{}");const t=[];this.completionEndpoint&&t.push(te(this.completionEndpoint).then((t=>{this.schema=t.json.context,this.fnOptions=t.json.functions}))),this.fieldsEndpoint&&t.push(this.refreshFields()),this.globalsEndpoint&&t.push(se(this.globalsEndpoint).then((t=>{this.keyedAssets.globals=t.map((t=>t.key))}))),this.languagesEndpoint&&t.push(se(this.languagesEndpoint).then((t=>{this.languages=t.reduce((function(t,e){return t[e.value]=e.name,t}),{})}))),this.groupsEndpoint&&t.push(se(this.groupsEndpoint).then((t=>{t.forEach((t=>{this.groups[t.uuid]=t}))}))),this.workspaceEndpoint&&t.push(te(this.workspaceEndpoint).then((t=>{this.workspace=t.json;const e=t.headers.get("content-language");e&&(this.locale=[e,...this.locale])}))),this.usersEndpoint&&t.push(se(this.usersEndpoint).then((t=>{this.users=t}))),this.initialHttpComplete=Promise.all(t),this.initialHttpComplete.then((()=>{this.ready=!0}))}getAssignableUsers(){return this.users.filter((t=>["administrator","editor","agent"].includes(t.role)))}firstUpdated(){this.reset()}getLanguageCode(){return this.locale.length>0?this.locale[0].split("-")[0]:"en"}refreshGlobals(){se(this.globalsEndpoint).then((t=>{this.keyedAssets.globals=t.map((t=>t.key))}))}refreshFields(){return se(this.fieldsEndpoint).then((t=>{this.keyedAssets.fields=[],this.featuredFields=[],t.forEach((t=>{this.keyedAssets.fields.push(t.key),this.fields[t.key]=t,t.featured&&this.featuredFields.push(t)})),this.featuredFields.sort(((t,e)=>e.priority-t.priority)),this.keyedAssets.fields.sort(),this.fireCustomEvent(_t.StoreUpdated,{url:this.fieldsEndpoint,data:this.keyedAssets.fields})}))}getShortDuration(t,e=null){const i=e||xs.now();return t.setLocale(this.locale[0]).toRelative({base:i,style:"long"})}getShortDurationFromIso(t,e=null){const i=xs.fromISO(t),n=e?xs.fromISO(e):xs.now();return this.getShortDuration(i,n)}setKeyedAssets(t,e){this.keyedAssets[t]=e}updated(t){super.updated(t)}getCompletionSchema(){return this.schema}getFunctions(){return this.fnOptions}getKeyedAssets(){return this.keyedAssets}getFieldKeys(){return this.keyedAssets.fields||[]}getContactField(t){return this.fields[t]}getFeaturedFields(){return this.featuredFields}getLanguageName(t){return this.languages[t]}isDynamicGroup(t){const e=this.groups[t];return!(e&&!e.query)}getWorkspace(){return this.workspace}formatDate(t){return xs.fromISO(t).setLocale(this.getLocale()).toLocaleString(xs.DATETIME_SHORT)}postJSON(t,e=""){return ae(t,e)}postForm(t,e){return((t,e)=>{const i=new FormData;return Object.keys(e).forEach((t=>{i.append(t,e[t])})),le(t,i)})(t,e)}postUrl(t,e="",i={},n=null){return re(t,e,i,n)}getUrl(t,e){return!(e=e||{}).force&&this.cache.has(t)?new Promise((e=>{e(this.cache.get(t))})):te(t,e.controller,e.headers||{}).then((e=>new Promise(((i,n)=>{e.status>=200&&e.status<=300?(this.cache.set(t,e),i(e)):n("Status: "+e.status)}))))}getResults(t,e){e=e||{};const i="results_"+t,n=this.cache.get(i);return!e.force&&n?new Promise((t=>{t(n)})):new Promise((e=>{const n=this.pendingResolves[t]||[];n.push(e),this.pendingResolves[t]=n,n.length<=1&&ne(t).then((e=>{this.cache.set(i,e);const n=this.pendingResolves[t]||[];for(;n.length>0;){n.pop()(e)}}))}))}updateCache(t,e){this.cache.set(t,e),this.fireCustomEvent(_t.StoreUpdated,{url:t,data:e})}makeRequest(t,e){const i=this.fetching[t],n=(new Date).getTime();if(i&&n-i<500)return;this.fetching[t]=n,e=e||{};const o=this.cache.get(t);o&&!e.force?this.fireCustomEvent(_t.StoreUpdated,{url:t,data:o}):ne(t).then((i=>{i=e.prepareData?e.prepareData(i):i,this.cache.set(t,i),this.fireCustomEvent(_t.StoreUpdated,{url:t,data:i}),delete this.fetching[t]}))}get(t,e=null){return this.settings[t]||e}set(t,e){this.settings[t]=e}render(){if(!this.ready&&this.loader)return D`<temba-loading size="10" units="8"></temba-loading>`}}t([st({type:Number})],ks.prototype,"ttl",void 0),t([st({type:Number})],ks.prototype,"max",void 0),t([st({type:Boolean})],ks.prototype,"ready",void 0),t([st({type:Boolean})],ks.prototype,"loader",void 0),t([st({type:String,attribute:"completion"})],ks.prototype,"completionEndpoint",void 0),t([st({type:String,attribute:"fields"})],ks.prototype,"fieldsEndpoint",void 0),t([st({type:String,attribute:"groups"})],ks.prototype,"groupsEndpoint",void 0),t([st({type:String,attribute:"globals"})],ks.prototype,"globalsEndpoint",void 0),t([st({type:String,attribute:"languages"})],ks.prototype,"languagesEndpoint",void 0),t([st({type:String,attribute:"workspace"})],ks.prototype,"workspaceEndpoint",void 0),t([st({type:String,attribute:"users"})],ks.prototype,"usersEndpoint",void 0),t([st({type:Object,attribute:!1})],ks.prototype,"schema",void 0),t([st({type:Object,attribute:!1})],ks.prototype,"fnOptions",void 0),t([st({type:Object,attribute:!1})],ks.prototype,"keyedAssets",void 0);class Ss extends nt{constructor(){super(...arguments),this.marginHorizontal=0,this.marginVertical=7,this.scrollPct=75,this.cursorIndex=-1,this.nameKey="name",this.loading=!1,this.hideShadow=!1,this.getName=function(t){return t[this.nameKey||"name"]},this.renderInputOption=function(){return null},this.scrollHeight=0,this.triggerScroll=!1,this.scrollParent=null,this.setCursor=de((function(t){t!==this.cursorIndex&&(this.cursorIndex=t)}),50)}static get styles(){return r`
492
+ `}getLocale(){return this.locale[0]}clearCache(){this.cache=Se(this.max,this.ttl)}reset(){this.clearCache(),this.settings=JSON.parse(fe("settings")||"{}");const t=[];this.completionEndpoint&&t.push(te(this.completionEndpoint).then((t=>{this.schema=t.json.context,this.fnOptions=t.json.functions}))),this.fieldsEndpoint&&t.push(this.refreshFields()),this.globalsEndpoint&&t.push(se(this.globalsEndpoint).then((t=>{this.keyedAssets.globals=t.map((t=>t.key))}))),this.languagesEndpoint&&t.push(se(this.languagesEndpoint).then((t=>{this.languages=t.reduce((function(t,e){return t[e.value]=e.name,t}),{})}))),this.groupsEndpoint&&t.push(se(this.groupsEndpoint).then((t=>{t.forEach((t=>{this.groups[t.uuid]=t}))}))),this.workspaceEndpoint&&t.push(te(this.workspaceEndpoint).then((t=>{this.workspace=t.json;const e=t.headers.get("content-language");e&&(this.locale=[e,...this.locale])}))),this.usersEndpoint&&t.push(se(this.usersEndpoint).then((t=>{this.users=t}))),this.initialHttpComplete=Promise.all(t),this.initialHttpComplete.then((()=>{this.ready=!0}))}getAssignableUsers(){return this.users.filter((t=>["administrator","editor","agent"].includes(t.role)))}firstUpdated(){this.reset()}getLanguageCode(){return this.locale.length>0?this.locale[0].split("-")[0]:"en"}refreshGlobals(){se(this.globalsEndpoint).then((t=>{this.keyedAssets.globals=t.map((t=>t.key))}))}refreshFields(){return se(this.fieldsEndpoint).then((t=>{this.keyedAssets.fields=[],this.featuredFields=[],t.forEach((t=>{this.keyedAssets.fields.push(t.key),this.fields[t.key]=t,t.featured&&this.featuredFields.push(t)})),this.featuredFields.sort(((t,e)=>e.priority-t.priority)),this.keyedAssets.fields.sort(),this.fireCustomEvent(_t.StoreUpdated,{url:this.fieldsEndpoint,data:this.keyedAssets.fields})}))}getShortDuration(t,e=null){const i=e||xs.now();return t.setLocale(this.locale[0]).toRelative({base:i,style:"long"})}getShortDurationFromIso(t,e=null){const i=xs.fromISO(t),n=e?xs.fromISO(e):xs.now();return this.getShortDuration(i,n)}setKeyedAssets(t,e){this.keyedAssets[t]=e}updated(t){super.updated(t)}getCompletionSchema(){return this.schema}getFunctions(){return this.fnOptions}getKeyedAssets(){return this.keyedAssets}getFieldKeys(){return this.keyedAssets.fields||[]}getContactField(t){return this.fields[t]}getFeaturedFields(){return this.featuredFields}getLanguageName(t){return this.languages[t]}isDynamicGroup(t){const e=this.groups[t];return!(e&&!e.query)}getWorkspace(){return this.workspace}formatDate(t){return xs.fromISO(t).setLocale(this.getLocale()).toLocaleString(xs.DATETIME_SHORT)}postJSON(t,e=""){return ae(t,e)}postForm(t,e){return((t,e)=>{const i=new FormData;return Object.keys(e).forEach((t=>{i.append(t,e[t])})),le(t,i)})(t,e)}postUrl(t,e="",i={},n=null){return re(t,e,i,n)}getUrl(t,e){return!(e=e||{}).force&&this.cache.has(t)?new Promise((e=>{e(this.cache.get(t))})):te(t,e.controller,e.headers||{}).then((e=>new Promise(((i,n)=>{e.status>=200&&e.status<=300?(this.cache.set(t,e),i(e)):n("Status: "+e.status)}))))}getResults(t,e){e=e||{};const i="results_"+t,n=this.cache.get(i);return!e.force&&n?new Promise((t=>{t(n)})):new Promise((e=>{const n=this.pendingResolves[t]||[];n.push(e),this.pendingResolves[t]=n,n.length<=1&&ne(t).then((e=>{this.cache.set(i,e);const n=this.pendingResolves[t]||[];for(;n.length>0;){n.pop()(e)}}))}))}updateCache(t,e){this.cache.set(t,e),this.fireCustomEvent(_t.StoreUpdated,{url:t,data:e})}makeRequest(t,e){const i=this.fetching[t],n=(new Date).getTime();if(i&&n-i<500)return;this.fetching[t]=n,e=e||{};const o=this.cache.get(t);o&&!e.force?this.fireCustomEvent(_t.StoreUpdated,{url:t,data:o}):ne(t).then((i=>{i=e.prepareData?e.prepareData(i):i,this.cache.set(t,i),this.fireCustomEvent(_t.StoreUpdated,{url:t,data:i}),delete this.fetching[t]}))}get(t,e=null){return this.settings[t]||e}set(t,e){this.settings[t]=e}render(){if(!this.ready&&this.loader)return D`<temba-loading size="10" units="8"></temba-loading>`}}t([st({type:Number})],ks.prototype,"ttl",void 0),t([st({type:Number})],ks.prototype,"max",void 0),t([st({type:Boolean})],ks.prototype,"ready",void 0),t([st({type:Boolean})],ks.prototype,"loader",void 0),t([st({type:String,attribute:"completion"})],ks.prototype,"completionEndpoint",void 0),t([st({type:String,attribute:"fields"})],ks.prototype,"fieldsEndpoint",void 0),t([st({type:String,attribute:"groups"})],ks.prototype,"groupsEndpoint",void 0),t([st({type:String,attribute:"globals"})],ks.prototype,"globalsEndpoint",void 0),t([st({type:String,attribute:"languages"})],ks.prototype,"languagesEndpoint",void 0),t([st({type:String,attribute:"workspace"})],ks.prototype,"workspaceEndpoint",void 0),t([st({type:String,attribute:"users"})],ks.prototype,"usersEndpoint",void 0),t([st({type:Object,attribute:!1})],ks.prototype,"schema",void 0),t([st({type:Object,attribute:!1})],ks.prototype,"fnOptions",void 0),t([st({type:Object,attribute:!1})],ks.prototype,"keyedAssets",void 0);class Ss extends nt{constructor(){super(...arguments),this.marginHorizontal=0,this.marginVertical=7,this.scrollPct=75,this.cursorIndex=-1,this.nameKey="name",this.loading=!1,this.hideShadow=!1,this.getName=function(t){return t[this.nameKey||"name"]},this.renderInputOption=function(){return null},this.scrollHeight=0,this.triggerScroll=!1,this.scrollParent=null,this.setCursor=de((function(t){t!==this.cursorIndex&&(this.cursorIndex=t)}),50)}static get styles(){return r`
493
493
  .options-container {
494
494
  background: var(--color-options-bg);
495
495
  user-select: none;
package/dist/index.js CHANGED
@@ -489,7 +489,7 @@ function t(t,e,i,n){var o,s=arguments.length,r=s<3?e:null===n?n=Object.getOwnPro
489
489
  width: 100%;
490
490
  top: 0.5em;
491
491
  }
492
- `}getLocale(){return this.locale[0]}reset(){this.cache=Se(this.max,this.ttl),this.settings=JSON.parse(fe("settings")||"{}");const t=[];this.completionEndpoint&&t.push(te(this.completionEndpoint).then((t=>{this.schema=t.json.context,this.fnOptions=t.json.functions}))),this.fieldsEndpoint&&t.push(this.refreshFields()),this.globalsEndpoint&&t.push(se(this.globalsEndpoint).then((t=>{this.keyedAssets.globals=t.map((t=>t.key))}))),this.languagesEndpoint&&t.push(se(this.languagesEndpoint).then((t=>{this.languages=t.reduce((function(t,e){return t[e.value]=e.name,t}),{})}))),this.groupsEndpoint&&t.push(se(this.groupsEndpoint).then((t=>{t.forEach((t=>{this.groups[t.uuid]=t}))}))),this.workspaceEndpoint&&t.push(te(this.workspaceEndpoint).then((t=>{this.workspace=t.json;const e=t.headers.get("content-language");e&&(this.locale=[e,...this.locale])}))),this.usersEndpoint&&t.push(se(this.usersEndpoint).then((t=>{this.users=t}))),this.initialHttpComplete=Promise.all(t),this.initialHttpComplete.then((()=>{this.ready=!0}))}getAssignableUsers(){return this.users.filter((t=>["administrator","editor","agent"].includes(t.role)))}firstUpdated(){this.reset()}getLanguageCode(){return this.locale.length>0?this.locale[0].split("-")[0]:"en"}refreshGlobals(){se(this.globalsEndpoint).then((t=>{this.keyedAssets.globals=t.map((t=>t.key))}))}refreshFields(){return se(this.fieldsEndpoint).then((t=>{this.keyedAssets.fields=[],this.featuredFields=[],t.forEach((t=>{this.keyedAssets.fields.push(t.key),this.fields[t.key]=t,t.featured&&this.featuredFields.push(t)})),this.featuredFields.sort(((t,e)=>e.priority-t.priority)),this.keyedAssets.fields.sort(),this.fireCustomEvent(_t.StoreUpdated,{url:this.fieldsEndpoint,data:this.keyedAssets.fields})}))}getShortDuration(t,e=null){const i=e||xs.now();return t.setLocale(this.locale[0]).toRelative({base:i,style:"long"})}getShortDurationFromIso(t,e=null){const i=xs.fromISO(t),n=e?xs.fromISO(e):xs.now();return this.getShortDuration(i,n)}setKeyedAssets(t,e){this.keyedAssets[t]=e}updated(t){super.updated(t)}getCompletionSchema(){return this.schema}getFunctions(){return this.fnOptions}getKeyedAssets(){return this.keyedAssets}getFieldKeys(){return this.keyedAssets.fields||[]}getContactField(t){return this.fields[t]}getFeaturedFields(){return this.featuredFields}getLanguageName(t){return this.languages[t]}isDynamicGroup(t){const e=this.groups[t];return!(e&&!e.query)}getWorkspace(){return this.workspace}formatDate(t){return xs.fromISO(t).setLocale(this.getLocale()).toLocaleString(xs.DATETIME_SHORT)}postJSON(t,e=""){return ae(t,e)}postForm(t,e){return((t,e)=>{const i=new FormData;return Object.keys(e).forEach((t=>{i.append(t,e[t])})),le(t,i)})(t,e)}postUrl(t,e="",i={},n=null){return re(t,e,i,n)}getUrl(t,e){return!(e=e||{}).force&&this.cache.has(t)?new Promise((e=>{e(this.cache.get(t))})):te(t,e.controller,e.headers||{}).then((e=>new Promise(((i,n)=>{e.status>=200&&e.status<=300?(this.cache.set(t,e),i(e)):n("Status: "+e.status)}))))}getResults(t,e){e=e||{};const i="results_"+t,n=this.cache.get(i);return!e.force&&n?new Promise((t=>{t(n)})):new Promise((e=>{const n=this.pendingResolves[t]||[];n.push(e),this.pendingResolves[t]=n,n.length<=1&&ne(t).then((e=>{this.cache.set(i,e);const n=this.pendingResolves[t]||[];for(;n.length>0;){n.pop()(e)}}))}))}updateCache(t,e){this.cache.set(t,e),this.fireCustomEvent(_t.StoreUpdated,{url:t,data:e})}makeRequest(t,e){const i=this.fetching[t],n=(new Date).getTime();if(i&&n-i<500)return;this.fetching[t]=n,e=e||{};const o=this.cache.get(t);o&&!e.force?this.fireCustomEvent(_t.StoreUpdated,{url:t,data:o}):ne(t).then((i=>{i=e.prepareData?e.prepareData(i):i,this.cache.set(t,i),this.fireCustomEvent(_t.StoreUpdated,{url:t,data:i}),delete this.fetching[t]}))}get(t,e=null){return this.settings[t]||e}set(t,e){this.settings[t]=e}render(){if(!this.ready&&this.loader)return D`<temba-loading size="10" units="8"></temba-loading>`}}t([st({type:Number})],ks.prototype,"ttl",void 0),t([st({type:Number})],ks.prototype,"max",void 0),t([st({type:Boolean})],ks.prototype,"ready",void 0),t([st({type:Boolean})],ks.prototype,"loader",void 0),t([st({type:String,attribute:"completion"})],ks.prototype,"completionEndpoint",void 0),t([st({type:String,attribute:"fields"})],ks.prototype,"fieldsEndpoint",void 0),t([st({type:String,attribute:"groups"})],ks.prototype,"groupsEndpoint",void 0),t([st({type:String,attribute:"globals"})],ks.prototype,"globalsEndpoint",void 0),t([st({type:String,attribute:"languages"})],ks.prototype,"languagesEndpoint",void 0),t([st({type:String,attribute:"workspace"})],ks.prototype,"workspaceEndpoint",void 0),t([st({type:String,attribute:"users"})],ks.prototype,"usersEndpoint",void 0),t([st({type:Object,attribute:!1})],ks.prototype,"schema",void 0),t([st({type:Object,attribute:!1})],ks.prototype,"fnOptions",void 0),t([st({type:Object,attribute:!1})],ks.prototype,"keyedAssets",void 0);class Ss extends nt{constructor(){super(...arguments),this.marginHorizontal=0,this.marginVertical=7,this.scrollPct=75,this.cursorIndex=-1,this.nameKey="name",this.loading=!1,this.hideShadow=!1,this.getName=function(t){return t[this.nameKey||"name"]},this.renderInputOption=function(){return null},this.scrollHeight=0,this.triggerScroll=!1,this.scrollParent=null,this.setCursor=de((function(t){t!==this.cursorIndex&&(this.cursorIndex=t)}),50)}static get styles(){return r`
492
+ `}getLocale(){return this.locale[0]}clearCache(){this.cache=Se(this.max,this.ttl)}reset(){this.clearCache(),this.settings=JSON.parse(fe("settings")||"{}");const t=[];this.completionEndpoint&&t.push(te(this.completionEndpoint).then((t=>{this.schema=t.json.context,this.fnOptions=t.json.functions}))),this.fieldsEndpoint&&t.push(this.refreshFields()),this.globalsEndpoint&&t.push(se(this.globalsEndpoint).then((t=>{this.keyedAssets.globals=t.map((t=>t.key))}))),this.languagesEndpoint&&t.push(se(this.languagesEndpoint).then((t=>{this.languages=t.reduce((function(t,e){return t[e.value]=e.name,t}),{})}))),this.groupsEndpoint&&t.push(se(this.groupsEndpoint).then((t=>{t.forEach((t=>{this.groups[t.uuid]=t}))}))),this.workspaceEndpoint&&t.push(te(this.workspaceEndpoint).then((t=>{this.workspace=t.json;const e=t.headers.get("content-language");e&&(this.locale=[e,...this.locale])}))),this.usersEndpoint&&t.push(se(this.usersEndpoint).then((t=>{this.users=t}))),this.initialHttpComplete=Promise.all(t),this.initialHttpComplete.then((()=>{this.ready=!0}))}getAssignableUsers(){return this.users.filter((t=>["administrator","editor","agent"].includes(t.role)))}firstUpdated(){this.reset()}getLanguageCode(){return this.locale.length>0?this.locale[0].split("-")[0]:"en"}refreshGlobals(){se(this.globalsEndpoint).then((t=>{this.keyedAssets.globals=t.map((t=>t.key))}))}refreshFields(){return se(this.fieldsEndpoint).then((t=>{this.keyedAssets.fields=[],this.featuredFields=[],t.forEach((t=>{this.keyedAssets.fields.push(t.key),this.fields[t.key]=t,t.featured&&this.featuredFields.push(t)})),this.featuredFields.sort(((t,e)=>e.priority-t.priority)),this.keyedAssets.fields.sort(),this.fireCustomEvent(_t.StoreUpdated,{url:this.fieldsEndpoint,data:this.keyedAssets.fields})}))}getShortDuration(t,e=null){const i=e||xs.now();return t.setLocale(this.locale[0]).toRelative({base:i,style:"long"})}getShortDurationFromIso(t,e=null){const i=xs.fromISO(t),n=e?xs.fromISO(e):xs.now();return this.getShortDuration(i,n)}setKeyedAssets(t,e){this.keyedAssets[t]=e}updated(t){super.updated(t)}getCompletionSchema(){return this.schema}getFunctions(){return this.fnOptions}getKeyedAssets(){return this.keyedAssets}getFieldKeys(){return this.keyedAssets.fields||[]}getContactField(t){return this.fields[t]}getFeaturedFields(){return this.featuredFields}getLanguageName(t){return this.languages[t]}isDynamicGroup(t){const e=this.groups[t];return!(e&&!e.query)}getWorkspace(){return this.workspace}formatDate(t){return xs.fromISO(t).setLocale(this.getLocale()).toLocaleString(xs.DATETIME_SHORT)}postJSON(t,e=""){return ae(t,e)}postForm(t,e){return((t,e)=>{const i=new FormData;return Object.keys(e).forEach((t=>{i.append(t,e[t])})),le(t,i)})(t,e)}postUrl(t,e="",i={},n=null){return re(t,e,i,n)}getUrl(t,e){return!(e=e||{}).force&&this.cache.has(t)?new Promise((e=>{e(this.cache.get(t))})):te(t,e.controller,e.headers||{}).then((e=>new Promise(((i,n)=>{e.status>=200&&e.status<=300?(this.cache.set(t,e),i(e)):n("Status: "+e.status)}))))}getResults(t,e){e=e||{};const i="results_"+t,n=this.cache.get(i);return!e.force&&n?new Promise((t=>{t(n)})):new Promise((e=>{const n=this.pendingResolves[t]||[];n.push(e),this.pendingResolves[t]=n,n.length<=1&&ne(t).then((e=>{this.cache.set(i,e);const n=this.pendingResolves[t]||[];for(;n.length>0;){n.pop()(e)}}))}))}updateCache(t,e){this.cache.set(t,e),this.fireCustomEvent(_t.StoreUpdated,{url:t,data:e})}makeRequest(t,e){const i=this.fetching[t],n=(new Date).getTime();if(i&&n-i<500)return;this.fetching[t]=n,e=e||{};const o=this.cache.get(t);o&&!e.force?this.fireCustomEvent(_t.StoreUpdated,{url:t,data:o}):ne(t).then((i=>{i=e.prepareData?e.prepareData(i):i,this.cache.set(t,i),this.fireCustomEvent(_t.StoreUpdated,{url:t,data:i}),delete this.fetching[t]}))}get(t,e=null){return this.settings[t]||e}set(t,e){this.settings[t]=e}render(){if(!this.ready&&this.loader)return D`<temba-loading size="10" units="8"></temba-loading>`}}t([st({type:Number})],ks.prototype,"ttl",void 0),t([st({type:Number})],ks.prototype,"max",void 0),t([st({type:Boolean})],ks.prototype,"ready",void 0),t([st({type:Boolean})],ks.prototype,"loader",void 0),t([st({type:String,attribute:"completion"})],ks.prototype,"completionEndpoint",void 0),t([st({type:String,attribute:"fields"})],ks.prototype,"fieldsEndpoint",void 0),t([st({type:String,attribute:"groups"})],ks.prototype,"groupsEndpoint",void 0),t([st({type:String,attribute:"globals"})],ks.prototype,"globalsEndpoint",void 0),t([st({type:String,attribute:"languages"})],ks.prototype,"languagesEndpoint",void 0),t([st({type:String,attribute:"workspace"})],ks.prototype,"workspaceEndpoint",void 0),t([st({type:String,attribute:"users"})],ks.prototype,"usersEndpoint",void 0),t([st({type:Object,attribute:!1})],ks.prototype,"schema",void 0),t([st({type:Object,attribute:!1})],ks.prototype,"fnOptions",void 0),t([st({type:Object,attribute:!1})],ks.prototype,"keyedAssets",void 0);class Ss extends nt{constructor(){super(...arguments),this.marginHorizontal=0,this.marginVertical=7,this.scrollPct=75,this.cursorIndex=-1,this.nameKey="name",this.loading=!1,this.hideShadow=!1,this.getName=function(t){return t[this.nameKey||"name"]},this.renderInputOption=function(){return null},this.scrollHeight=0,this.triggerScroll=!1,this.scrollParent=null,this.setCursor=de((function(t){t!==this.cursorIndex&&(this.cursorIndex=t)}),50)}static get styles(){return r`
493
493
  .options-container {
494
494
  background: var(--color-options-bg);
495
495
  user-select: none;
package/dist/sw.js CHANGED
@@ -1,2 +1,2 @@
1
- if(!self.define){let e,t={};const o=(o,n)=>(o=new URL(o+".js",n).href,t[o]||new Promise((t=>{if("document"in self){const e=document.createElement("script");e.src=o,e.onload=t,document.head.appendChild(e)}else e=o,importScripts(o),t()})).then((()=>{let e=t[o];if(!e)throw new Error(`Module ${o} didn’t register its module`);return e})));self.define=(n,s)=>{const i=e||("document"in self?document.currentScript.src:"")||location.href;if(t[i])return;let r={};const l=e=>o(e,i),c={module:{uri:i},exports:r,require:l};t[i]=Promise.all(n.map((e=>c[e]||l(e)))).then((e=>(s(...e),r)))}}define(["./workbox-919adfb7"],(function(e){"use strict";self.skipWaiting(),e.clientsClaim(),e.precacheAndRoute([{url:"6bba9624.js",revision:"a58c33596e5de9c47b9125fc7b5bdc98"},{url:"templates/components-body.html",revision:"ea15499dbc11ba056021f3f87fdf28e5"},{url:"templates/components-head.html",revision:"47b0010fdb37510a3867ff0d1b420d6c"}],{}),e.registerRoute(new e.NavigationRoute(e.createHandlerBoundToURL("/index.html"))),e.registerRoute("polyfills/*.js",new e.CacheFirst,"GET")}));
1
+ if(!self.define){let e,t={};const o=(o,n)=>(o=new URL(o+".js",n).href,t[o]||new Promise((t=>{if("document"in self){const e=document.createElement("script");e.src=o,e.onload=t,document.head.appendChild(e)}else e=o,importScripts(o),t()})).then((()=>{let e=t[o];if(!e)throw new Error(`Module ${o} didn’t register its module`);return e})));self.define=(n,s)=>{const i=e||("document"in self?document.currentScript.src:"")||location.href;if(t[i])return;let r={};const d=e=>o(e,i),c={module:{uri:i},exports:r,require:d};t[i]=Promise.all(n.map((e=>c[e]||d(e)))).then((e=>(s(...e),r)))}}define(["./workbox-919adfb7"],(function(e){"use strict";self.skipWaiting(),e.clientsClaim(),e.precacheAndRoute([{url:"985d634a.js",revision:"82c23577a5edada7de524234c1bee4ab"},{url:"templates/components-body.html",revision:"71cfca9de7cccddebdf25167e0795149"},{url:"templates/components-head.html",revision:"57dfe4d91e2a2008f5407f8a8324fc31"}],{}),e.registerRoute(new e.NavigationRoute(e.createHandlerBoundToURL("/index.html"))),e.registerRoute("polyfills/*.js",new e.CacheFirst,"GET")}));
2
2
  //# sourceMappingURL=sw.js.map
package/dist/sw.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"sw.js","sources":["../../../../../tmp/eb0f203cc72b8390b5c86e252b01e6ed/sw.js"],"sourcesContent":["import {registerRoute as workbox_routing_registerRoute} from '/home/runner/work/temba-components/temba-components/node_modules/workbox-routing/registerRoute.mjs';\nimport {CacheFirst as workbox_strategies_CacheFirst} from '/home/runner/work/temba-components/temba-components/node_modules/workbox-strategies/CacheFirst.mjs';\nimport {clientsClaim as workbox_core_clientsClaim} from '/home/runner/work/temba-components/temba-components/node_modules/workbox-core/clientsClaim.mjs';\nimport {precacheAndRoute as workbox_precaching_precacheAndRoute} from '/home/runner/work/temba-components/temba-components/node_modules/workbox-precaching/precacheAndRoute.mjs';\nimport {NavigationRoute as workbox_routing_NavigationRoute} from '/home/runner/work/temba-components/temba-components/node_modules/workbox-routing/NavigationRoute.mjs';\nimport {createHandlerBoundToURL as workbox_precaching_createHandlerBoundToURL} from '/home/runner/work/temba-components/temba-components/node_modules/workbox-precaching/createHandlerBoundToURL.mjs';/**\n * Welcome to your Workbox-powered service worker!\n *\n * You'll need to register this file in your web app.\n * See https://goo.gl/nhQhGp\n *\n * The rest of the code is auto-generated. Please don't update this file\n * directly; instead, make changes to your Workbox build configuration\n * and re-run your build process.\n * See https://goo.gl/2aRDsh\n */\n\n\n\n\n\n\n\n\nself.skipWaiting();\n\nworkbox_core_clientsClaim();\n\n\n/**\n * The precacheAndRoute() method efficiently caches and responds to\n * requests for URLs in the manifest.\n * See https://goo.gl/S9QRab\n */\nworkbox_precaching_precacheAndRoute([\n {\n \"url\": \"6bba9624.js\",\n \"revision\": \"a58c33596e5de9c47b9125fc7b5bdc98\"\n },\n {\n \"url\": \"templates/components-body.html\",\n \"revision\": \"ea15499dbc11ba056021f3f87fdf28e5\"\n },\n {\n \"url\": \"templates/components-head.html\",\n \"revision\": \"47b0010fdb37510a3867ff0d1b420d6c\"\n }\n], {});\n\nworkbox_routing_registerRoute(new workbox_routing_NavigationRoute(workbox_precaching_createHandlerBoundToURL(\"/index.html\")));\n\n\nworkbox_routing_registerRoute(\"polyfills/*.js\", new workbox_strategies_CacheFirst(), 'GET');\n\n\n\n\n"],"names":["self","skipWaiting","workbox_core_clientsClaim","workbox_precaching_precacheAndRoute","url","revision","workbox","registerRoute","workbox_routing_NavigationRoute","workbox_precaching_createHandlerBoundToURL","workbox_strategies_CacheFirst"],"mappings":"0nBAwBAA,KAAKC,cAELC,EAAAA,eAQAC,EAAAA,iBAAoC,CAClC,CACEC,IAAO,cACPC,SAAY,oCAEd,CACED,IAAO,iCACPC,SAAY,oCAEd,CACED,IAAO,iCACPC,SAAY,qCAEb,CAAE,GAEwBC,EAAAC,cAAC,IAAIC,EAAAA,gBAAgCC,EAAAA,wBAA2C,iBAGhFH,EAAAC,cAAC,iBAAkB,IAAIG,aAAiC"}
1
+ {"version":3,"file":"sw.js","sources":["../../../../../tmp/63b4620b54bf876e2ce4c08b0c22eed4/sw.js"],"sourcesContent":["import {registerRoute as workbox_routing_registerRoute} from '/home/runner/work/temba-components/temba-components/node_modules/workbox-routing/registerRoute.mjs';\nimport {CacheFirst as workbox_strategies_CacheFirst} from '/home/runner/work/temba-components/temba-components/node_modules/workbox-strategies/CacheFirst.mjs';\nimport {clientsClaim as workbox_core_clientsClaim} from '/home/runner/work/temba-components/temba-components/node_modules/workbox-core/clientsClaim.mjs';\nimport {precacheAndRoute as workbox_precaching_precacheAndRoute} from '/home/runner/work/temba-components/temba-components/node_modules/workbox-precaching/precacheAndRoute.mjs';\nimport {NavigationRoute as workbox_routing_NavigationRoute} from '/home/runner/work/temba-components/temba-components/node_modules/workbox-routing/NavigationRoute.mjs';\nimport {createHandlerBoundToURL as workbox_precaching_createHandlerBoundToURL} from '/home/runner/work/temba-components/temba-components/node_modules/workbox-precaching/createHandlerBoundToURL.mjs';/**\n * Welcome to your Workbox-powered service worker!\n *\n * You'll need to register this file in your web app.\n * See https://goo.gl/nhQhGp\n *\n * The rest of the code is auto-generated. Please don't update this file\n * directly; instead, make changes to your Workbox build configuration\n * and re-run your build process.\n * See https://goo.gl/2aRDsh\n */\n\n\n\n\n\n\n\n\nself.skipWaiting();\n\nworkbox_core_clientsClaim();\n\n\n/**\n * The precacheAndRoute() method efficiently caches and responds to\n * requests for URLs in the manifest.\n * See https://goo.gl/S9QRab\n */\nworkbox_precaching_precacheAndRoute([\n {\n \"url\": \"985d634a.js\",\n \"revision\": \"82c23577a5edada7de524234c1bee4ab\"\n },\n {\n \"url\": \"templates/components-body.html\",\n \"revision\": \"71cfca9de7cccddebdf25167e0795149\"\n },\n {\n \"url\": \"templates/components-head.html\",\n \"revision\": \"57dfe4d91e2a2008f5407f8a8324fc31\"\n }\n], {});\n\nworkbox_routing_registerRoute(new workbox_routing_NavigationRoute(workbox_precaching_createHandlerBoundToURL(\"/index.html\")));\n\n\nworkbox_routing_registerRoute(\"polyfills/*.js\", new workbox_strategies_CacheFirst(), 'GET');\n\n\n\n\n"],"names":["self","skipWaiting","workbox_core_clientsClaim","workbox_precaching_precacheAndRoute","url","revision","workbox","registerRoute","workbox_routing_NavigationRoute","workbox_precaching_createHandlerBoundToURL","workbox_strategies_CacheFirst"],"mappings":"0nBAwBAA,KAAKC,cAELC,EAAAA,eAQAC,EAAAA,iBAAoC,CAClC,CACEC,IAAO,cACPC,SAAY,oCAEd,CACED,IAAO,iCACPC,SAAY,oCAEd,CACED,IAAO,iCACPC,SAAY,qCAEb,CAAE,GAEwBC,EAAAC,cAAC,IAAIC,EAAAA,gBAAgCC,EAAAA,wBAA2C,iBAGhFH,EAAAC,cAAC,iBAAkB,IAAIG,aAAiC"}
@@ -1 +1 @@
1
- <script type="module" src="{{STATIC_URL}}@nyaruka/temba-components/dist/6bba9624.js"></script><script>window.TEMBA_COMPONENTS_VERSION="0.52.0"</script>
1
+ <script type="module" src="{{STATIC_URL}}@nyaruka/temba-components/dist/985d634a.js"></script><script>window.TEMBA_COMPONENTS_VERSION="0.52.1"</script>
@@ -1 +1 @@
1
- <link rel="modulepreload" href="{{STATIC_URL}}@nyaruka/temba-components/dist/6bba9624.js" crossorigin="anonymous">
1
+ <link rel="modulepreload" href="{{STATIC_URL}}@nyaruka/temba-components/dist/985d634a.js" crossorigin="anonymous">
@@ -40,8 +40,11 @@ export class Store extends RapidElement {
40
40
  getLocale() {
41
41
  return this.locale[0];
42
42
  }
43
- reset() {
43
+ clearCache() {
44
44
  this.cache = Lru(this.max, this.ttl);
45
+ }
46
+ reset() {
47
+ this.clearCache();
45
48
  this.settings = JSON.parse(getCookie('settings') || '{}');
46
49
  /*
47
50
  // This will create a shorthand unit
@@ -1 +1 @@
1
- {"version":3,"file":"Store.js","sourceRoot":"","sources":["../../../src/store/Store.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAC7C,OAAO,EACL,YAAY,EACZ,MAAM,EACN,SAAS,EAGT,OA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M,EAAE,SAAS,EAAE,KAAK,EAAE,CAAC;wCACP;AAGtC;IADC,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,KAAK,EAAE,CAAC;0CACP","sourcesContent":["import { property } from 'lit/decorators.js';\nimport {\n fetchResults,\n getUrl,\n getAssets,\n Asset,\n WebResponse,\n postUrl,\n postJSON,\n postForm,\n getCookie,\n setCookie,\n COOKIE_KEYS,\n} from '../utils';\nimport {\n ContactField,\n ContactGroup,\n CompletionOption,\n CompletionSchema,\n KeyedAssets,\n CustomEventType,\n Workspace,\n User,\n} from '../interfaces';\nimport { RapidElement } from '../RapidElement';\nimport Lru from 'tiny-lru';\nimport { DateTime } from 'luxon';\nimport { css, html } from 'lit';\n\nexport class Store extends RapidElement {\n public static get styles() {\n return css`\n :host {\n position: fixed;\n z-index: 1000;\n text-align: center;\n display: flex;\n flex-direction: column;\n align-items: center;\n width: 100%;\n top: 0.5em;\n }\n `;\n }\n\n settings = {};\n\n @property({ type: Number })\n ttl = 60000;\n\n @property({ type: Number })\n max = 20;\n\n @property({ type: Boolean })\n ready = false;\n\n @property({ type: Boolean })\n loader = false;\n\n @property({ type: String, attribute: 'completion' })\n completionEndpoint: string;\n\n @property({ type: String, attribute: 'fields' })\n fieldsEndpoint: string;\n\n @property({ type: String, attribute: 'groups' })\n groupsEndpoint: string;\n\n @property({ type: String, attribute: 'globals' })\n globalsEndpoint: string;\n\n @property({ type: String, attribute: 'languages' })\n languagesEndpoint: string;\n\n @property({ type: String, attribute: 'workspace' })\n workspaceEndpoint: string;\n\n @property({ type: String, attribute: 'users' })\n usersEndpoint: string;\n\n @property({ type: Object, attribute: false })\n private schema: CompletionSchema;\n\n @property({ type: Object, attribute: false })\n private fnOptions: CompletionOption[];\n\n @property({ type: Object, attribute: false })\n private keyedAssets: KeyedAssets = {};\n\n private locale = [...navigator.languages];\n\n private fields: { [key: string]: ContactField } = {};\n private groups: { [uuid: string]: ContactGroup } = {};\n private languages: any = {};\n private users: User[];\n private workspace: Workspace;\n private featuredFields: ContactField[] = [];\n\n // http promise to monitor for completeness\n public initialHttpComplete: Promise<void | WebResponse[]>;\n\n private cache: any;\n\n public getLocale() {\n return this.locale[0];\n }\n\n public reset() {\n this.cache = Lru(this.max, this.ttl);\n this.settings = JSON.parse(getCookie('settings') || '{}');\n\n /* \n // This will create a shorthand unit\n this.humanizer.addLanguage(\"en\", {\n y: () => \"y\",\n mo: () => \"mo\",\n w: () => \"w\",\n d: () => \"d\",\n h: () => \"h\",\n m: () => \"m\",\n s: () => \"s\",\n ms: () => \"ms\",\n decimal: \".\",\n });\n */\n\n const fetches = [];\n if (this.completionEndpoint) {\n fetches.push(\n getUrl(this.completionEndpoint).then(response => {\n this.schema = response.json['context'] as CompletionSchema;\n this.fnOptions = response.json['functions'] as CompletionOption[];\n })\n );\n }\n\n if (this.fieldsEndpoint) {\n fetches.push(this.refreshFields());\n }\n\n if (this.globalsEndpoint) {\n fetches.push(\n getAssets(this.globalsEndpoint).then((assets: Asset[]) => {\n this.keyedAssets['globals'] = assets.map((asset: Asset) => asset.key);\n })\n );\n }\n\n if (this.languagesEndpoint) {\n fetches.push(\n getAssets(this.languagesEndpoint).then((results: any[]) => {\n // convert array of objects to lookup\n this.languages = results.reduce(function (\n languages: any,\n result: any\n ) {\n languages[result.value] = result.name;\n return languages;\n },\n {});\n })\n );\n }\n\n if (this.groupsEndpoint) {\n fetches.push(\n getAssets(this.groupsEndpoint).then((groups: any[]) => {\n groups.forEach((group: any) => {\n this.groups[group.uuid] = group;\n });\n })\n );\n }\n\n if (this.workspaceEndpoint) {\n fetches.push(\n getUrl(this.workspaceEndpoint).then((response: WebResponse) => {\n this.workspace = response.json;\n const lang = response.headers.get('content-language');\n if (lang) {\n this.locale = [lang, ...this.locale];\n }\n })\n );\n }\n\n if (this.usersEndpoint) {\n fetches.push(\n getAssets(this.usersEndpoint).then((users: any[]) => {\n this.users = users;\n })\n );\n }\n\n this.initialHttpComplete = Promise.all(fetches);\n\n this.initialHttpComplete.then(() => {\n this.ready = true;\n });\n }\n\n public getAssignableUsers() {\n return this.users.filter((user: User) =>\n ['administrator', 'editor', 'agent'].includes(user.role)\n );\n }\n\n public firstUpdated() {\n this.reset();\n }\n\n public getLanguageCode() {\n if (this.locale.length > 0) {\n return this.locale[0].split('-')[0];\n }\n return 'en';\n }\n\n public refreshGlobals() {\n getAssets(this.globalsEndpoint).then((assets: Asset[]) => {\n this.keyedAssets['globals'] = assets.map((asset: Asset) => asset.key);\n });\n }\n\n public refreshFields() {\n return getAssets(this.fieldsEndpoint).then((assets: Asset[]) => {\n this.keyedAssets['fields'] = [];\n this.featuredFields = [];\n\n assets.forEach((field: ContactField) => {\n this.keyedAssets['fields'].push(field.key);\n this.fields[field.key] = field;\n if (field.featured) {\n this.featuredFields.push(field);\n }\n });\n\n this.featuredFields.sort((a, b) => {\n return b.priority - a.priority;\n });\n\n this.keyedAssets['fields'].sort();\n\n this.fireCustomEvent(CustomEventType.StoreUpdated, {\n url: this.fieldsEndpoint,\n data: this.keyedAssets['fields'],\n });\n });\n }\n\n public getShortDuration(scheduled: DateTime, compareDate: DateTime = null) {\n const now = compareDate || DateTime.now();\n return scheduled\n .setLocale(this.locale[0])\n .toRelative({ base: now, style: 'long' });\n }\n\n public getShortDurationFromIso(isoDateA: string, isoDateB: string = null) {\n const scheduled = DateTime.fromISO(isoDateA);\n const now = isoDateB ? DateTime.fromISO(isoDateB) : DateTime.now();\n return this.getShortDuration(scheduled, now);\n }\n\n public setKeyedAssets(name: string, values: string[]): void {\n this.keyedAssets[name] = values;\n }\n\n public updated(changedProperties: Map<string, any>) {\n super.updated(changedProperties);\n }\n\n public getCompletionSchema(): CompletionSchema {\n return this.schema;\n }\n\n public getFunctions(): CompletionOption[] {\n return this.fnOptions;\n }\n\n public getKeyedAssets(): KeyedAssets {\n return this.keyedAssets;\n }\n\n public getFieldKeys(): string[] {\n return this.keyedAssets['fields'] || [];\n }\n\n public getContactField(key: string): ContactField {\n return this.fields[key];\n }\n\n public getFeaturedFields(): ContactField[] {\n return this.featuredFields;\n }\n\n public getLanguageName(iso: string) {\n return this.languages[iso];\n }\n\n public isDynamicGroup(uuid: string): boolean {\n const group = this.groups[uuid];\n // we treat missing groups as dynamic since the\n // api excludes initializing groups\n if (!group || group.query) {\n return true;\n }\n return false;\n }\n\n public getWorkspace(): Workspace {\n return this.workspace;\n }\n\n public formatDate(dateString: string) {\n return DateTime.fromISO(dateString)\n .setLocale(this.getLocale())\n .toLocaleString(DateTime.DATETIME_SHORT);\n }\n\n public postJSON(url: string, payload: any = '') {\n return postJSON(url, payload);\n }\n\n public postForm(url: string, payload: any | FormData) {\n return postForm(url, payload);\n }\n\n public postUrl(\n url: string,\n payload: any = '',\n headers: any = {},\n contentType = null\n ) {\n return postUrl(url, payload, headers, contentType);\n }\n\n public getUrl(\n url: string,\n options?: {\n force?: boolean;\n controller?: AbortController;\n headers?: { [key: string]: string };\n }\n ): Promise<WebResponse> {\n options = options || {};\n if (!options.force && this.cache.has(url)) {\n return new Promise<WebResponse>(resolve => {\n resolve(this.cache.get(url));\n });\n }\n\n return getUrl(url, options.controller, options.headers || {}).then(\n (response: WebResponse) => {\n return new Promise<WebResponse>((resolve, reject) => {\n if (response.status >= 200 && response.status <= 300) {\n this.cache.set(url, response);\n resolve(response);\n } else {\n reject('Status: ' + response.status);\n }\n });\n }\n );\n }\n\n private pendingResolves = {};\n\n /**\n * Fetches all of the results for a given API endpoint with caching\n * @param url\n */\n public getResults(\n url: string,\n options?: { force?: boolean }\n ): Promise<any[]> {\n options = options || {};\n const key = 'results_' + url;\n const results = this.cache.get(key);\n\n if (!options.force && results) {\n return new Promise<any[]>(resolve => {\n resolve(results);\n });\n }\n\n return new Promise<any[]>(resolve => {\n const pending = this.pendingResolves[url] || [];\n pending.push(resolve);\n this.pendingResolves[url] = pending;\n if (pending.length <= 1) {\n fetchResults(url).then((results: any[]) => {\n this.cache.set(key, results);\n const pending = this.pendingResolves[url] || [];\n while (pending.length > 0) {\n const resolve = pending.pop();\n resolve(results);\n }\n });\n }\n });\n }\n\n public fetching: { [url: string]: number } = {};\n\n public updateCache(url: string, data: any) {\n this.cache.set(url, data);\n this.fireCustomEvent(CustomEventType.StoreUpdated, { url, data });\n }\n\n public makeRequest(\n url: string,\n options?: { force?: boolean; prepareData?: (data: any) => any }\n ) {\n const previousRequest = this.fetching[url];\n const now = new Date().getTime();\n // if the request was recently made, don't do anything\n if (previousRequest && now - previousRequest < 500) {\n return;\n }\n\n this.fetching[url] = now;\n options = options || {};\n const cached = this.cache.get(url);\n if (cached && !options.force) {\n this.fireCustomEvent(CustomEventType.StoreUpdated, { url, data: cached });\n } else {\n fetchResults(url).then(data => {\n data = options.prepareData ? options.prepareData(data) : data;\n this.cache.set(url, data);\n this.fireCustomEvent(CustomEventType.StoreUpdated, { url, data });\n delete this.fetching[url];\n });\n }\n }\n\n public get(key: string, defaultValue: any = null) {\n return this.settings[key] || defaultValue;\n }\n\n public set(key: string, value: string) {\n this.settings[key] = value;\n // not sure yet if we really want to perist these\n // setCookie(COOKIE_KEYS.SETTINGS, JSON.stringify(this.settings), '/');\n }\n\n public render() {\n if (!this.ready && this.loader) {\n return html`<temba-loading size=\"10\" units=\"8\"></temba-loading>`;\n }\n }\n}\n"]}
1
+ {"version":3,"file":"Store.js","sourceRoot":"","sources":["../../../src/store/Store.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAC7C,OAAO,EACL,YAAY,EACZ,MAAM,EACN,SAAS,EAGT,OAAO,EACP,QAAQ,EACR,QAAQ,EACR,SAAS,GAGV,MAAM,UAAU,CAAC;AAClB,OAAO,EAML,eAAe,GAGhB,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAC/C,OAAO,GAAG,MAAM,UAAU,CAAC;AAC3B,OAAO,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AACjC,OAAO,EAAE,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WebResponse,\n postUrl,\n postJSON,\n postForm,\n getCookie,\n setCookie,\n COOKIE_KEYS,\n} from '../utils';\nimport {\n ContactField,\n ContactGroup,\n CompletionOption,\n CompletionSchema,\n KeyedAssets,\n CustomEventType,\n Workspace,\n User,\n} from '../interfaces';\nimport { RapidElement } from '../RapidElement';\nimport Lru from 'tiny-lru';\nimport { DateTime } from 'luxon';\nimport { css, html } from 'lit';\n\nexport class Store extends RapidElement {\n public static get styles() {\n return css`\n :host {\n position: fixed;\n z-index: 1000;\n text-align: center;\n display: flex;\n flex-direction: column;\n align-items: center;\n width: 100%;\n top: 0.5em;\n }\n `;\n }\n\n settings = {};\n\n @property({ type: Number })\n ttl = 60000;\n\n @property({ type: Number })\n max = 20;\n\n @property({ type: Boolean })\n ready = false;\n\n @property({ type: Boolean })\n loader = false;\n\n @property({ type: String, attribute: 'completion' })\n completionEndpoint: string;\n\n @property({ type: String, attribute: 'fields' })\n fieldsEndpoint: string;\n\n @property({ type: String, attribute: 'groups' })\n groupsEndpoint: string;\n\n @property({ type: String, attribute: 'globals' })\n globalsEndpoint: string;\n\n @property({ type: String, attribute: 'languages' })\n languagesEndpoint: string;\n\n @property({ type: String, attribute: 'workspace' })\n workspaceEndpoint: string;\n\n @property({ type: String, attribute: 'users' })\n usersEndpoint: string;\n\n @property({ type: Object, attribute: false })\n private schema: CompletionSchema;\n\n @property({ type: Object, attribute: false })\n private fnOptions: CompletionOption[];\n\n @property({ type: Object, attribute: false })\n private keyedAssets: KeyedAssets = {};\n\n private locale = [...navigator.languages];\n\n private fields: { [key: string]: ContactField } = {};\n private groups: { [uuid: string]: ContactGroup } = {};\n private languages: any = {};\n private users: User[];\n private workspace: Workspace;\n private featuredFields: ContactField[] = [];\n\n // http promise to monitor for completeness\n public initialHttpComplete: Promise<void | WebResponse[]>;\n\n private cache: any;\n\n public getLocale() {\n return this.locale[0];\n }\n\n public clearCache() {\n this.cache = Lru(this.max, this.ttl);\n }\n\n public reset() {\n this.clearCache();\n this.settings = JSON.parse(getCookie('settings') || '{}');\n\n /* \n // This will create a shorthand unit\n this.humanizer.addLanguage(\"en\", {\n y: () => \"y\",\n mo: () => \"mo\",\n w: () => \"w\",\n d: () => \"d\",\n h: () => \"h\",\n m: () => \"m\",\n s: () => \"s\",\n ms: () => \"ms\",\n decimal: \".\",\n });\n */\n\n const fetches = [];\n if (this.completionEndpoint) {\n fetches.push(\n getUrl(this.completionEndpoint).then(response => {\n this.schema = response.json['context'] as CompletionSchema;\n this.fnOptions = response.json['functions'] as CompletionOption[];\n })\n );\n }\n\n if (this.fieldsEndpoint) {\n fetches.push(this.refreshFields());\n }\n\n if (this.globalsEndpoint) {\n fetches.push(\n getAssets(this.globalsEndpoint).then((assets: Asset[]) => {\n this.keyedAssets['globals'] = assets.map((asset: Asset) => asset.key);\n })\n );\n }\n\n if (this.languagesEndpoint) {\n fetches.push(\n getAssets(this.languagesEndpoint).then((results: any[]) => {\n // convert array of objects to lookup\n this.languages = results.reduce(function (\n languages: any,\n result: any\n ) {\n languages[result.value] = result.name;\n return languages;\n },\n {});\n })\n );\n }\n\n if (this.groupsEndpoint) {\n fetches.push(\n getAssets(this.groupsEndpoint).then((groups: any[]) => {\n groups.forEach((group: any) => {\n this.groups[group.uuid] = group;\n });\n })\n );\n }\n\n if (this.workspaceEndpoint) {\n fetches.push(\n getUrl(this.workspaceEndpoint).then((response: WebResponse) => {\n this.workspace = response.json;\n const lang = response.headers.get('content-language');\n if (lang) {\n this.locale = [lang, ...this.locale];\n }\n })\n );\n }\n\n if (this.usersEndpoint) {\n fetches.push(\n getAssets(this.usersEndpoint).then((users: any[]) => {\n this.users = users;\n })\n );\n }\n\n this.initialHttpComplete = Promise.all(fetches);\n\n this.initialHttpComplete.then(() => {\n this.ready = true;\n });\n }\n\n public getAssignableUsers() {\n return this.users.filter((user: User) =>\n ['administrator', 'editor', 'agent'].includes(user.role)\n );\n }\n\n public firstUpdated() {\n this.reset();\n }\n\n public getLanguageCode() {\n if (this.locale.length > 0) {\n return this.locale[0].split('-')[0];\n }\n return 'en';\n }\n\n public refreshGlobals() {\n getAssets(this.globalsEndpoint).then((assets: Asset[]) => {\n this.keyedAssets['globals'] = assets.map((asset: Asset) => asset.key);\n });\n }\n\n public refreshFields() {\n return getAssets(this.fieldsEndpoint).then((assets: Asset[]) => {\n this.keyedAssets['fields'] = [];\n this.featuredFields = [];\n\n assets.forEach((field: ContactField) => {\n this.keyedAssets['fields'].push(field.key);\n this.fields[field.key] = field;\n if (field.featured) {\n this.featuredFields.push(field);\n }\n });\n\n this.featuredFields.sort((a, b) => {\n return b.priority - a.priority;\n });\n\n this.keyedAssets['fields'].sort();\n\n this.fireCustomEvent(CustomEventType.StoreUpdated, {\n url: this.fieldsEndpoint,\n data: this.keyedAssets['fields'],\n });\n });\n }\n\n public getShortDuration(scheduled: DateTime, compareDate: DateTime = null) {\n const now = compareDate || DateTime.now();\n return scheduled\n .setLocale(this.locale[0])\n .toRelative({ base: now, style: 'long' });\n }\n\n public getShortDurationFromIso(isoDateA: string, isoDateB: string = null) {\n const scheduled = DateTime.fromISO(isoDateA);\n const now = isoDateB ? DateTime.fromISO(isoDateB) : DateTime.now();\n return this.getShortDuration(scheduled, now);\n }\n\n public setKeyedAssets(name: string, values: string[]): void {\n this.keyedAssets[name] = values;\n }\n\n public updated(changedProperties: Map<string, any>) {\n super.updated(changedProperties);\n }\n\n public getCompletionSchema(): CompletionSchema {\n return this.schema;\n }\n\n public getFunctions(): CompletionOption[] {\n return this.fnOptions;\n }\n\n public getKeyedAssets(): KeyedAssets {\n return this.keyedAssets;\n }\n\n public getFieldKeys(): string[] {\n return this.keyedAssets['fields'] || [];\n }\n\n public getContactField(key: string): ContactField {\n return this.fields[key];\n }\n\n public getFeaturedFields(): ContactField[] {\n return this.featuredFields;\n }\n\n public getLanguageName(iso: string) {\n return this.languages[iso];\n }\n\n public isDynamicGroup(uuid: string): boolean {\n const group = this.groups[uuid];\n // we treat missing groups as dynamic since the\n // api excludes initializing groups\n if (!group || group.query) {\n return true;\n }\n return false;\n }\n\n public getWorkspace(): Workspace {\n return this.workspace;\n }\n\n public formatDate(dateString: string) {\n return DateTime.fromISO(dateString)\n .setLocale(this.getLocale())\n .toLocaleString(DateTime.DATETIME_SHORT);\n }\n\n public postJSON(url: string, payload: any = '') {\n return postJSON(url, payload);\n }\n\n public postForm(url: string, payload: any | FormData) {\n return postForm(url, payload);\n }\n\n public postUrl(\n url: string,\n payload: any = '',\n headers: any = {},\n contentType = null\n ) {\n return postUrl(url, payload, headers, contentType);\n }\n\n public getUrl(\n url: string,\n options?: {\n force?: boolean;\n controller?: AbortController;\n headers?: { [key: string]: string };\n }\n ): Promise<WebResponse> {\n options = options || {};\n if (!options.force && this.cache.has(url)) {\n return new Promise<WebResponse>(resolve => {\n resolve(this.cache.get(url));\n });\n }\n\n return getUrl(url, options.controller, options.headers || {}).then(\n (response: WebResponse) => {\n return new Promise<WebResponse>((resolve, reject) => {\n if (response.status >= 200 && response.status <= 300) {\n this.cache.set(url, response);\n resolve(response);\n } else {\n reject('Status: ' + response.status);\n }\n });\n }\n );\n }\n\n private pendingResolves = {};\n\n /**\n * Fetches all of the results for a given API endpoint with caching\n * @param url\n */\n public getResults(\n url: string,\n options?: { force?: boolean }\n ): Promise<any[]> {\n options = options || {};\n const key = 'results_' + url;\n const results = this.cache.get(key);\n\n if (!options.force && results) {\n return new Promise<any[]>(resolve => {\n resolve(results);\n });\n }\n\n return new Promise<any[]>(resolve => {\n const pending = this.pendingResolves[url] || [];\n pending.push(resolve);\n this.pendingResolves[url] = pending;\n if (pending.length <= 1) {\n fetchResults(url).then((results: any[]) => {\n this.cache.set(key, results);\n const pending = this.pendingResolves[url] || [];\n while (pending.length > 0) {\n const resolve = pending.pop();\n resolve(results);\n }\n });\n }\n });\n }\n\n public fetching: { [url: string]: number } = {};\n\n public updateCache(url: string, data: any) {\n this.cache.set(url, data);\n this.fireCustomEvent(CustomEventType.StoreUpdated, { url, data });\n }\n\n public makeRequest(\n url: string,\n options?: { force?: boolean; prepareData?: (data: any) => any }\n ) {\n const previousRequest = this.fetching[url];\n const now = new Date().getTime();\n // if the request was recently made, don't do anything\n if (previousRequest && now - previousRequest < 500) {\n return;\n }\n\n this.fetching[url] = now;\n options = options || {};\n const cached = this.cache.get(url);\n if (cached && !options.force) {\n this.fireCustomEvent(CustomEventType.StoreUpdated, { url, data: cached });\n } else {\n fetchResults(url).then(data => {\n data = options.prepareData ? options.prepareData(data) : data;\n this.cache.set(url, data);\n this.fireCustomEvent(CustomEventType.StoreUpdated, { url, data });\n delete this.fetching[url];\n });\n }\n }\n\n public get(key: string, defaultValue: any = null) {\n return this.settings[key] || defaultValue;\n }\n\n public set(key: string, value: string) {\n this.settings[key] = value;\n // not sure yet if we really want to perist these\n // setCookie(COOKIE_KEYS.SETTINGS, JSON.stringify(this.settings), '/');\n }\n\n public render() {\n if (!this.ready && this.loader) {\n return html`<temba-loading size=\"10\" units=\"8\"></temba-loading>`;\n }\n }\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nyaruka/temba-components",
3
- "version": "0.52.0",
3
+ "version": "0.52.1",
4
4
  "description": "Web components to support rapidpro and related projects",
5
5
  "author": "Nyaruka <code@nyaruka.coim>",
6
6
  "main": "dist/index.js",
@@ -105,8 +105,12 @@ export class Store extends RapidElement {
105
105
  return this.locale[0];
106
106
  }
107
107
 
108
- public reset() {
108
+ public clearCache() {
109
109
  this.cache = Lru(this.max, this.ttl);
110
+ }
111
+
112
+ public reset() {
113
+ this.clearCache();
110
114
  this.settings = JSON.parse(getCookie('settings') || '{}');
111
115
 
112
116
  /*