@uniformdev/context 17.3.0 → 17.3.1-alpha.146

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/api/api.mjs CHANGED
@@ -1,2 +1,2 @@
1
1
  var _=Object.defineProperty;var ee=(r,e,t)=>e in r?_(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t;var m=(r,e,t)=>(ee(r,typeof e!="symbol"?e+"":e,t),t),te=(r,e,t)=>{if(!e.has(r))throw TypeError("Cannot "+t)};var i=(r,e,t)=>(te(r,e,"read from private field"),t?t.call(r):e.get(r)),c=(r,e,t)=>{if(e.has(r))throw TypeError("Cannot add the same private member more than once");e instanceof WeakSet?e.add(r):e.set(r,t)};var J=async r=>await r(),C=class extends Error{constructor(t,s,a,o,p,l){super(`${t}
2
- ${o}${p?" "+p:""} (${s} ${a}${l?` Request ID: ${l}`:""})`);this.errorMessage=t;this.fetchMethod=s;this.fetchUri=a;this.statusCode=o;this.statusText=p;this.requestId=l;Object.setPrototypeOf(this,C.prototype)}};var n=class{constructor(e){m(this,"options");var s,a,o,p,l,u;if(!e.apiKey&&!e.bearerToken)throw new Error("You must provide an API key or a bearer token");let t=e.fetch;if(!t)if(typeof window!="undefined")t=window.fetch.bind(window);else if(typeof fetch!="undefined")t=fetch;else throw new Error("You must provide or polyfill a fetch implementation when not in a browser");this.options={...e,fetch:t,apiHost:(s=e.apiHost)!=null?s:"https://uniform.app",apiKey:(a=e.apiKey)!=null?a:null,projectId:(o=e.projectId)!=null?o:null,bearerToken:(p=e.bearerToken)!=null?p:null,limitPolicy:(l=e.limitPolicy)!=null?l:J,bypassCache:(u=e.bypassCache)!=null?u:!1}}async apiClient(e,t){return this.options.limitPolicy(async()=>{var o;let s=this.options.apiKey?{"x-api-key":this.options.apiKey}:{Authorization:`Bearer ${this.options.bearerToken}`};this.options.bypassCache&&(s["x-bypass-cache"]="true");let a=await this.options.fetch(e.toString(),{...t,headers:{...t==null?void 0:t.headers,...s}});if(!a.ok){let p="";try{let l=await a.text();try{let u=JSON.parse(l);u.errorMessage?p=Array.isArray(u.errorMessage)?u.errorMessage.join(", "):u.errorMessage:p=l}catch(u){p=l}}catch(l){p="General error"}throw new C(p,(o=t==null?void 0:t.method)!=null?o:"GET",e.toString(),a.status,a.statusText,n.getRequestId(a))}return t!=null&&t.expectNoContent?null:await a.json()})}createUrl(e,t){let s=new URL(`${this.options.apiHost}${e}`);return Object.entries(t!=null?t:{}).forEach(([a,o])=>{var p;typeof o!="undefined"&&o!==null&&s.searchParams.append(a,Array.isArray(o)?o.join(","):(p=o==null?void 0:o.toString())!=null?p:"")}),s}static getRequestId(e){let t=e.headers.get("apigw-requestid");if(t)return t}};var b,U=class extends n{constructor(e){super(e)}async get(e){let{projectId:t}=this.options,s=this.createUrl(i(U,b),{...e,projectId:t});return await this.apiClient(s)}async upsert(e){let t=this.createUrl(i(U,b));await this.apiClient(t,{method:"PUT",body:JSON.stringify({...e,projectId:this.options.projectId}),expectNoContent:!0})}async remove(e){let t=this.createUrl(i(U,b));await this.apiClient(t,{method:"DELETE",body:JSON.stringify({...e,projectId:this.options.projectId}),expectNoContent:!0})}},y=U;b=new WeakMap,c(y,b,"/api/v2/aggregate");var $=class extends y{constructor(e){super({...e,bypassCache:!0})}},V=class extends y{constructor(e){super({...e,bypassCache:!1})}};var N,k=class extends n{constructor(e){super(e)}async get(e){let{projectId:t}=this.options,s=this.createUrl(i(k,N),{...e,projectId:t});return await this.apiClient(s)}},f=k;N=new WeakMap,c(f,N,"/api/v2/dimension");var M=class extends f{constructor(e){super({...e,bypassCache:!0})}},Q=class extends f{constructor(e){super({...e,bypassCache:!1})}};var O,w,x=class extends n{constructor(e){super(e)}async get(e){let{projectId:t}=this.options,s=this.createUrl(i(x,O),{...e,projectId:t});return await this.apiClient(s)}async upsertCategory(e){let t=this.createUrl(i(x,O));await this.apiClient(t,{method:"PUT",body:JSON.stringify({...e,projectId:this.options.projectId}),expectNoContent:!0})}async removeCategory(e){let t=this.createUrl(i(x,O));await this.apiClient(t,{method:"DELETE",body:JSON.stringify({...e,projectId:this.options.projectId}),expectNoContent:!0})}async upsertValue(e){let t=this.createUrl(i(x,w));await this.apiClient(t,{method:"PUT",body:JSON.stringify({...e,projectId:this.options.projectId}),expectNoContent:!0})}async removeValue(e){let t=this.createUrl(i(x,w));await this.apiClient(t,{method:"DELETE",body:JSON.stringify({...e,projectId:this.options.projectId}),expectNoContent:!0})}},h=x;O=new WeakMap,w=new WeakMap,c(h,O,"/api/v1/enrichments"),c(h,w,"/api/v1/enrichment-values");var H=class extends h{constructor(e){super({...e,bypassCache:!0})}},K=class extends h{constructor(e){super({...e,bypassCache:!1})}};var S,v=class extends n{constructor(e){super(e)}async get(e){let{projectId:t}=this.options,s=this.createUrl(i(v,S),{...e,projectId:t});return await this.apiClient(s)}async publish(){let{projectId:e}=this.options,t=this.createUrl("/api/v1/publish",{siteId:e});await this.apiClient(t,{method:"POST",expectNoContent:!0})}},g=v;S=new WeakMap,c(g,S,"/api/v2/manifest");var q=class extends g{constructor(e){super({...e,bypassCache:!0})}},z=class extends g{constructor(e){super({...e,bypassCache:!1})}};var j,R=class extends n{constructor(e){super(e)}async get(e){let{projectId:t}=this.options,s=this.createUrl(i(R,j),{...e,projectId:t});return await this.apiClient(s)}async upsert(e){let t=this.createUrl(i(R,j));await this.apiClient(t,{method:"PUT",body:JSON.stringify({...e,projectId:this.options.projectId}),expectNoContent:!0})}async remove(e){let t=this.createUrl(i(R,j));await this.apiClient(t,{method:"DELETE",body:JSON.stringify({...e,projectId:this.options.projectId}),expectNoContent:!0})}},d=R;j=new WeakMap,c(d,j,"/api/v2/quirk");var Y=class extends d{constructor(e){super({...e,bypassCache:!0})}},B=class extends d{constructor(e){super({...e,bypassCache:!1})}};var E,I=class extends n{constructor(e){super(e)}async get(e){let{projectId:t}=this.options,s=this.createUrl(i(I,E),{...e,projectId:t});return await this.apiClient(s)}async upsert(e){let t=this.createUrl(i(I,E));await this.apiClient(t,{method:"PUT",body:JSON.stringify({...e,projectId:this.options.projectId}),expectNoContent:!0})}async remove(e){let t=this.createUrl(i(I,E));await this.apiClient(t,{method:"DELETE",body:JSON.stringify({...e,projectId:this.options.projectId}),expectNoContent:!0})}},P=I;E=new WeakMap,c(P,E,"/api/v2/signal");var F=class extends P{constructor(e){super({...e,bypassCache:!0})}},W=class extends P{constructor(e){super({...e,bypassCache:!1})}};var D,G=class extends n{constructor(e){super(e)}async get(e){let{projectId:t}=this.options,s=this.createUrl(i(G,D),{...e,projectId:t});return await this.apiClient(s)}async upsert(e){let t=this.createUrl(i(G,D));await this.apiClient(t,{method:"PUT",body:JSON.stringify({...e,projectId:this.options.projectId}),expectNoContent:!0})}async remove(e){let t=this.createUrl(i(G,D));await this.apiClient(t,{method:"DELETE",body:JSON.stringify({...e,projectId:this.options.projectId}),expectNoContent:!0})}},T=G;D=new WeakMap,c(T,D,"/api/v2/test");var A=class{constructor(e){m(this,"enrichments");m(this,"aggregates");m(this,"dimensions");m(this,"manifest");m(this,"quirks");m(this,"signals");m(this,"tests");this.enrichments=new h(e),this.aggregates=new y(e),this.dimensions=new f(e),this.manifest=new g(e),this.quirks=new d(e),this.signals=new P(e),this.tests=new T(e)}},X=class extends A{constructor(e){super({...e,bypassCache:!0})}},Z=class extends A{constructor(e){super({...e,bypassCache:!1})}};var L="_";function re(r){let e=r.category==="ENR"?"Enrichment":r.category==="SIG"?"Signal":r.subcategory==="1"?"Intent":r.subcategory==="0"?"Audience":"Aggregate";return{dim:r.dim,name:r.name,type:e,category:r.category==="ENR"?r.subcategory:void 0}}function Ne(r,e){var t,s,a,o;if((s=(t=e.project.pz)==null?void 0:t.agg)!=null&&s[r])return{dim:r,name:r,type:"Aggregate"};if((o=(a=e.project.pz)==null?void 0:a.sig)!=null&&o[r])return{dim:r,name:r,type:"Signal"};if(r.indexOf(L)>=0){let[p,l]=r.split(L);return{dim:r,name:l,type:"Enrichment",category:p}}}function Se(r){let{type:e,name:t}=re(r);return`${e}: ${t}`}export{y as AggregateClient,n as ApiClient,C as ApiClientError,V as CachedAggregateClient,Z as CachedContextClient,Q as CachedDimensionClient,K as CachedEnrichmentClient,z as CachedManifestClient,B as CachedQuirkClient,W as CachedSignalClient,A as ContextClient,f as DimensionClient,h as EnrichmentClient,g as ManifestClient,d as QuirkClient,P as SignalClient,$ as UncachedAggregateClient,X as UncachedContextClient,M as UncachedDimensionClient,H as UncachedEnrichmentClient,q as UncachedManifestClient,Y as UncachedQuirkClient,F as UncachedSignalClient,re as computeDimensionDefinitionDisplayData,Ne as computeDimensionDisplayData,Se as computeDimensionDisplayName,J as nullLimitPolicy};
2
+ ${o}${p?" "+p:""} (${s} ${a}${l?` Request ID: ${l}`:""})`);this.errorMessage=t;this.fetchMethod=s;this.fetchUri=a;this.statusCode=o;this.statusText=p;this.requestId=l;Object.setPrototypeOf(this,C.prototype)}};var n=class{constructor(e){m(this,"options");var s,a,o,p,l,u;if(!e.apiKey&&!e.bearerToken)throw new Error("You must provide an API key or a bearer token");let t=e.fetch;if(!t)if(typeof window!="undefined")t=window.fetch.bind(window);else if(typeof fetch!="undefined")t=fetch;else throw new Error("You must provide or polyfill a fetch implementation when not in a browser");this.options={...e,fetch:t,apiHost:(s=e.apiHost)!=null?s:"https://uniform.app",apiKey:(a=e.apiKey)!=null?a:null,projectId:(o=e.projectId)!=null?o:null,bearerToken:(p=e.bearerToken)!=null?p:null,limitPolicy:(l=e.limitPolicy)!=null?l:J,bypassCache:(u=e.bypassCache)!=null?u:!1}}async apiClient(e,t){return this.options.limitPolicy(async()=>{var o;let s=this.options.apiKey?{"x-api-key":this.options.apiKey}:{Authorization:`Bearer ${this.options.bearerToken}`};this.options.bypassCache&&(s["x-bypass-cache"]="true");let a=await this.options.fetch(e.toString(),{...t,headers:{...t==null?void 0:t.headers,...s}});if(!a.ok){let p="";try{let l=await a.text();try{let u=JSON.parse(l);u.errorMessage?p=Array.isArray(u.errorMessage)?u.errorMessage.join(", "):u.errorMessage:p=l}catch(u){p=l}}catch(l){p="General error"}throw new C(p,(o=t==null?void 0:t.method)!=null?o:"GET",e.toString(),a.status,a.statusText,n.getRequestId(a))}return t!=null&&t.expectNoContent?null:await a.json()})}createUrl(e,t){let s=new URL(`${this.options.apiHost}${e}`);return Object.entries(t!=null?t:{}).forEach(([a,o])=>{var p;typeof o!="undefined"&&o!==null&&s.searchParams.append(a,Array.isArray(o)?o.join(","):(p=o==null?void 0:o.toString())!=null?p:"")}),s}static getRequestId(e){let t=e.headers.get("apigw-requestid");if(t)return t}};var b,U=class extends n{constructor(e){super(e)}async get(e){let{projectId:t}=this.options,s=this.createUrl(i(U,b),{...e,projectId:t});return await this.apiClient(s)}async upsert(e){let t=this.createUrl(i(U,b));await this.apiClient(t,{method:"PUT",body:JSON.stringify({...e,projectId:this.options.projectId}),expectNoContent:!0})}async remove(e){let t=this.createUrl(i(U,b));await this.apiClient(t,{method:"DELETE",body:JSON.stringify({...e,projectId:this.options.projectId}),expectNoContent:!0})}},y=U;b=new WeakMap,c(y,b,"/api/v2/aggregate");var $=class extends y{constructor(e){super({...e,bypassCache:!0})}},V=class extends y{constructor(e){super({...e,bypassCache:!1})}};var N,k=class extends n{constructor(e){super(e)}async get(e){let{projectId:t}=this.options,s=this.createUrl(i(k,N),{...e,projectId:t});return await this.apiClient(s)}},f=k;N=new WeakMap,c(f,N,"/api/v2/dimension");var M=class extends f{constructor(e){super({...e,bypassCache:!0})}},Q=class extends f{constructor(e){super({...e,bypassCache:!1})}};var O,w,x=class extends n{constructor(e){super(e)}async get(e){let{projectId:t}=this.options,s=this.createUrl(i(x,O),{...e,projectId:t});return await this.apiClient(s)}async upsertCategory(e){let t=this.createUrl(i(x,O));await this.apiClient(t,{method:"PUT",body:JSON.stringify({...e,projectId:this.options.projectId}),expectNoContent:!0})}async removeCategory(e){let t=this.createUrl(i(x,O));await this.apiClient(t,{method:"DELETE",body:JSON.stringify({...e,projectId:this.options.projectId}),expectNoContent:!0})}async upsertValue(e){let t=this.createUrl(i(x,w));await this.apiClient(t,{method:"PUT",body:JSON.stringify({...e,projectId:this.options.projectId}),expectNoContent:!0})}async removeValue(e){let t=this.createUrl(i(x,w));await this.apiClient(t,{method:"DELETE",body:JSON.stringify({...e,projectId:this.options.projectId}),expectNoContent:!0})}},h=x;O=new WeakMap,w=new WeakMap,c(h,O,"/api/v1/enrichments"),c(h,w,"/api/v1/enrichment-values");var H=class extends h{constructor(e){super({...e,bypassCache:!0})}},K=class extends h{constructor(e){super({...e,bypassCache:!1})}};var S,v=class extends n{constructor(e){super(e)}async get(e){let{projectId:t}=this.options,s=this.createUrl(i(v,S),{...e,projectId:t});return await this.apiClient(s)}async publish(){let{projectId:e}=this.options,t=this.createUrl("/api/v1/publish",{siteId:e});await this.apiClient(t,{method:"POST",expectNoContent:!0})}},g=v;S=new WeakMap,c(g,S,"/api/v2/manifest");var q=class extends g{constructor(e){super({...e,bypassCache:!0})}},z=class extends g{constructor(e){super({...e,bypassCache:!1})}};var j,R=class extends n{constructor(e){super(e)}async get(e){let{projectId:t}=this.options,s=this.createUrl(i(R,j),{...e,projectId:t});return await this.apiClient(s)}async upsert(e){let t=this.createUrl(i(R,j));await this.apiClient(t,{method:"PUT",body:JSON.stringify({...e,projectId:this.options.projectId}),expectNoContent:!0})}async remove(e){let t=this.createUrl(i(R,j));await this.apiClient(t,{method:"DELETE",body:JSON.stringify({...e,projectId:this.options.projectId}),expectNoContent:!0})}},d=R;j=new WeakMap,c(d,j,"/api/v2/quirk");var Y=class extends d{constructor(e){super({...e,bypassCache:!0})}},B=class extends d{constructor(e){super({...e,bypassCache:!1})}};var E,I=class extends n{constructor(e){super(e)}async get(e){let{projectId:t}=this.options,s=this.createUrl(i(I,E),{...e,projectId:t});return await this.apiClient(s)}async upsert(e){let t=this.createUrl(i(I,E));await this.apiClient(t,{method:"PUT",body:JSON.stringify({...e,projectId:this.options.projectId}),expectNoContent:!0})}async remove(e){let t=this.createUrl(i(I,E));await this.apiClient(t,{method:"DELETE",body:JSON.stringify({...e,projectId:this.options.projectId}),expectNoContent:!0})}},P=I;E=new WeakMap,c(P,E,"/api/v2/signal");var F=class extends P{constructor(e){super({...e,bypassCache:!0})}},W=class extends P{constructor(e){super({...e,bypassCache:!1})}};var D,G=class extends n{constructor(e){super(e)}async get(e){let{projectId:t}=this.options,s=this.createUrl(i(G,D),{...e,projectId:t});return await this.apiClient(s)}async upsert(e){let t=this.createUrl(i(G,D));await this.apiClient(t,{method:"PUT",body:JSON.stringify({...e,projectId:this.options.projectId}),expectNoContent:!0})}async remove(e){let t=this.createUrl(i(G,D));await this.apiClient(t,{method:"DELETE",body:JSON.stringify({...e,projectId:this.options.projectId}),expectNoContent:!0})}},T=G;D=new WeakMap,c(T,D,"/api/v2/test");var A=class{constructor(e){m(this,"enrichments");m(this,"aggregates");m(this,"dimensions");m(this,"manifest");m(this,"quirks");m(this,"signals");m(this,"tests");this.enrichments=new h(e),this.aggregates=new y(e),this.dimensions=new f(e),this.manifest=new g(e),this.quirks=new d(e),this.signals=new P(e),this.tests=new T(e)}},X=class extends A{constructor(e){super({...e,bypassCache:!0})}},Z=class extends A{constructor(e){super({...e,bypassCache:!1})}};var L="_";function re(r){let e=r.category==="ENR"?"Enrichment":r.category==="SIG"?"Signal":r.subcategory==="1"?"Intent":r.subcategory==="0"?"Audience":"Aggregate";return{dim:r.dim,name:r.name,type:e,category:r.category==="ENR"?r.subcategory:void 0}}function Me(r,e){var t,s,a,o;if((s=(t=e.project.pz)==null?void 0:t.agg)!=null&&s[r])return{dim:r,name:r,type:"Aggregate"};if((o=(a=e.project.pz)==null?void 0:a.sig)!=null&&o[r])return{dim:r,name:r,type:"Signal"};if(r.indexOf(L)>=0){let[p,l]=r.split(L);return{dim:r,name:l,type:"Enrichment",category:p}}}function Qe(r){let{type:e,name:t}=re(r);return`${e}: ${t}`}export{y as AggregateClient,n as ApiClient,C as ApiClientError,V as CachedAggregateClient,Z as CachedContextClient,Q as CachedDimensionClient,K as CachedEnrichmentClient,z as CachedManifestClient,B as CachedQuirkClient,W as CachedSignalClient,A as ContextClient,f as DimensionClient,h as EnrichmentClient,g as ManifestClient,d as QuirkClient,P as SignalClient,$ as UncachedAggregateClient,X as UncachedContextClient,M as UncachedDimensionClient,H as UncachedEnrichmentClient,q as UncachedManifestClient,Y as UncachedQuirkClient,F as UncachedSignalClient,re as computeDimensionDefinitionDisplayData,Me as computeDimensionDisplayData,Qe as computeDimensionDisplayName,J as nullLimitPolicy};